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/hwregs.c11
-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/apei/erst.c31
-rw-r--r--drivers/acpi/atomicio.c4
-rw-r--r--drivers/acpi/blacklist.c1
-rw-r--r--drivers/acpi/bus.c8
-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/processor_driver.c20
-rw-r--r--drivers/acpi/processor_idle.c254
-rw-r--r--drivers/acpi/sbshc.c1
-rw-r--r--drivers/acpi/scan.c3
-rw-r--r--drivers/acpi/sleep.c8
-rw-r--r--drivers/acpi/sysfs.c14
-rw-r--r--drivers/acpi/video_detect.c1
-rw-r--r--drivers/ata/ahci.c3
-rw-r--r--drivers/ata/ahci_platform.c13
-rw-r--r--drivers/ata/libata-eh.c13
-rw-r--r--drivers/ata/libata-pmp.c8
-rw-r--r--drivers/ata/libata-scsi.c5
-rw-r--r--drivers/ata/libata-sff.c5
-rw-r--r--drivers/ata/pata_of_platform.c2
-rw-r--r--drivers/ata/sata_sis.c2
-rw-r--r--drivers/base/base.h1
-rw-r--r--drivers/base/core.c3
-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/node.c14
-rw-r--r--drivers/base/power/clock_ops.c3
-rw-r--r--drivers/base/power/common.c2
-rw-r--r--drivers/base/power/generic_ops.c1
-rw-r--r--drivers/base/power/main.c4
-rw-r--r--drivers/base/power/opp.c2
-rw-r--r--drivers/base/power/qos.c19
-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.c82
-rw-r--r--drivers/block/cciss.h1
-rw-r--r--drivers/block/cciss_scsi.c1
-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.c298
-rw-r--r--drivers/block/nbd.c69
-rw-r--r--drivers/block/paride/pg.c1
-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.c1
-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/ath3k.c4
-rw-r--r--drivers/bluetooth/bcm203x.c12
-rw-r--r--drivers/bluetooth/bfusb.c13
-rw-r--r--drivers/bluetooth/btmrvl_main.c2
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c1
-rw-r--r--drivers/bluetooth/btusb.c3
-rw-r--r--drivers/bluetooth/btwilink.c1
-rw-r--r--drivers/char/agp/intel-gtt.c7
-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/random.c2
-rw-r--r--drivers/char/ttyprintk.c1
-rw-r--r--drivers/char/virtio_console.c1
-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.c40
-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.c87
-rw-r--r--drivers/cpuidle/driver.c25
-rw-r--r--drivers/cpuidle/governors/ladder.c43
-rw-r--r--drivers/cpuidle/governors/menu.c30
-rw-r--r--drivers/cpuidle/sysfs.c22
-rw-r--r--drivers/crypto/mv_cesa.c13
-rw-r--r--drivers/dca/dca-core.c1
-rw-r--r--drivers/dca/dca-sysfs.c1
-rw-r--r--drivers/devfreq/Kconfig41
-rw-r--r--drivers/devfreq/devfreq.c10
-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/Kconfig2
-rw-r--r--drivers/edac/cpc925_edac.c67
-rw-r--r--drivers/edac/mce_amd_inj.c1
-rw-r--r--drivers/edac/mpc85xx_edac.c2
-rw-r--r--drivers/edac/ppc4xx_edac.c2
-rw-r--r--drivers/firewire/core-iso.c1
-rw-r--r--drivers/firmware/dmi_scan.c6
-rw-r--r--drivers/firmware/edd.c6
-rw-r--r--drivers/firmware/efivars.c12
-rw-r--r--drivers/firmware/google/gsmi.c1
-rw-r--r--drivers/firmware/sigma.c81
-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-omap.c59
-rw-r--r--drivers/gpio/gpio-pca953x.c15
-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/Kconfig2
-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.c17
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c43
-rw-r--r--drivers/gpu/drm/drm_debugfs.c13
-rw-r--r--drivers/gpu/drm/drm_dma.c1
-rw-r--r--drivers/gpu/drm/drm_drv.c3
-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.c32
-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/exynos/exynos_drm_buf.c62
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_buf.h21
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_connector.c78
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_crtc.c76
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_crtc.h25
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c5
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.h13
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_encoder.c83
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_encoder.h1
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fb.c66
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fbdev.c44
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fimd.c71
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.c89
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.h28
-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.c63
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c1
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c11
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h19
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c14
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c1
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h21
-rw-r--r--drivers/gpu/drm/i915/i915_suspend.c2
-rw-r--r--drivers/gpu/drm/i915/intel_display.c33
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c412
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c1
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c3
-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_bios.c22
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_channel.c1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c45
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.c5
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fbcon.c11
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fence.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.c4
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_object.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_perf.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_sgdma.c3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_state.c13
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_temp.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv40_pm.c20
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c4
-rw-r--r--drivers/gpu/drm/nouveau/nv50_graph.c4
-rw-r--r--drivers/gpu/drm/nouveau/nv50_grctx.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv50_vram.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_graph.c44
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_grctx.c31
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_vram.c16
-rw-r--r--drivers/gpu/drm/nouveau/nvd0_display.c2
-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/Makefile2
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c97
-rw-r--r--drivers/gpu/drm/radeon/atombios_dp.c22
-rw-r--r--drivers/gpu/drm/radeon/atombios_encoders.c2369
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c78
-rw-r--r--drivers/gpu/drm/radeon/evergreen_blit_kms.c20
-rw-r--r--drivers/gpu/drm/radeon/evergreen_cs.c195
-rw-r--r--drivers/gpu/drm/radeon/evergreen_reg.h29
-rw-r--r--drivers/gpu/drm/radeon/evergreend.h31
-rw-r--r--drivers/gpu/drm/radeon/ni.c26
-rw-r--r--drivers/gpu/drm/radeon/r100.c15
-rw-r--r--drivers/gpu/drm/radeon/r300.c110
-rw-r--r--drivers/gpu/drm/radeon/r600.c225
-rw-r--r--drivers/gpu/drm/radeon/r600_blit_kms.c14
-rw-r--r--drivers/gpu/drm/radeon/r600_cp.c2
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c26
-rw-r--r--drivers/gpu/drm/radeon/radeon.h110
-rw-r--r--drivers/gpu/drm/radeon/radeon_acpi.c11
-rw-r--r--drivers/gpu/drm/radeon/radeon_asic.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_asic.h1
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c304
-rw-r--r--drivers/gpu/drm/radeon/radeon_benchmark.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c27
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c90
-rw-r--r--drivers/gpu/drm/radeon/radeon_cp.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c25
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c16
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c36
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c8
-rw-r--r--drivers/gpu/drm/radeon/radeon_encoders.c2151
-rw-r--r--drivers/gpu/drm/radeon/radeon_gart.c71
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c30
-rw-r--r--drivers/gpu/drm/radeon/radeon_irq_kms.c60
-rw-r--r--drivers/gpu/drm/radeon/radeon_legacy_crtc.c6
-rw-r--r--drivers/gpu/drm/radeon/radeon_mode.h14
-rw-r--r--drivers/gpu/drm/radeon/radeon_pm.c18
-rw-r--r--drivers/gpu/drm/radeon/rs400.c5
-rw-r--r--drivers/gpu/drm/radeon/rs600.c24
-rw-r--r--drivers/gpu/drm/radeon/rv770.c80
-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_bo.c8
-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.c7
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h6
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fb.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c166
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.h10
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c5
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c94
-rw-r--r--drivers/gpu/vga/vgaarb.c62
-rw-r--r--drivers/hid/Kconfig33
-rw-r--r--drivers/hid/Makefile11
-rw-r--r--drivers/hid/hid-apple.c3
-rw-r--r--drivers/hid/hid-axff.c1
-rw-r--r--drivers/hid/hid-core.c29
-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-hyperv.c (renamed from drivers/staging/hv/hv_mouse.c)303
-rw-r--r--drivers/hid/hid-ids.h44
-rw-r--r--drivers/hid/hid-multitouch.c211
-rw-r--r--drivers/hid/hid-picolcd.c1
-rw-r--r--drivers/hid/hid-pl.c1
-rw-r--r--drivers/hid/hid-quanta.c261
-rw-r--r--drivers/hid/hid-roccat-common.c1
-rw-r--r--drivers/hid/hid-roccat-isku.c487
-rw-r--r--drivers/hid/hid-roccat-isku.h147
-rw-r--r--drivers/hid/hid-roccat.c1
-rw-r--r--drivers/hid/hid-sjoy.c1
-rw-r--r--drivers/hid/hid-tmff.c1
-rw-r--r--drivers/hid/hid-wacom.c179
-rw-r--r--drivers/hid/hid-wiimote-core.c (renamed from drivers/hid/hid-wiimote.c)246
-rw-r--r--drivers/hid/hid-wiimote-debug.c227
-rw-r--r--drivers/hid/hid-wiimote-ext.c752
-rw-r--r--drivers/hid/hid-wiimote.h208
-rw-r--r--drivers/hid/hid-zpff.c1
-rw-r--r--drivers/hid/usbhid/hid-quirks.c5
-rw-r--r--drivers/hwmon/Kconfig22
-rw-r--r--drivers/hwmon/ad7314.c1
-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/ads7871.c1
-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/exynos4_tmu.c12
-rw-r--r--drivers/hwmon/gl518sm.c4
-rw-r--r--drivers/hwmon/gl520sm.c4
-rw-r--r--drivers/hwmon/gpio-fan.c13
-rw-r--r--drivers/hwmon/ibmaem.c60
-rw-r--r--drivers/hwmon/jc42.c52
-rw-r--r--drivers/hwmon/jz4740-hwmon.c12
-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/ntc_thermistor.c14
-rw-r--r--drivers/hwmon/s3c-hwmon.c13
-rw-r--r--drivers/hwmon/sch5627.c13
-rw-r--r--drivers/hwmon/sch5636.c13
-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/twl4030-madc-hwmon.c14
-rw-r--r--drivers/hwmon/ultra45_env.c14
-rw-r--r--drivers/hwmon/w83627ehf.c213
-rw-r--r--drivers/hwmon/w83781d.c10
-rw-r--r--drivers/hwmon/wm831x-hwmon.c12
-rw-r--r--drivers/hwmon/wm8350-hwmon.c12
-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.c197
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/i2c-au1550.c2
-rw-r--r--drivers/i2c/busses/i2c-nuc900.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/i2c/i2c-core.c4
-rw-r--r--drivers/i2c/i2c-dev.c2
-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/cy82c693.c6
-rw-r--r--drivers/ide/icside.c2
-rw-r--r--drivers/ide/ide-acpi.c1
-rw-r--r--drivers/ide/ide-atapi.c1
-rw-r--r--drivers/ide/ide-cd.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.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-tape.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/piix.c18
-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/ide/triflex.c16
-rw-r--r--drivers/idle/intel_idle.c131
-rw-r--r--drivers/infiniband/core/addr.c10
-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/cxgb3/iwch_cm.c4
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c10
-rw-r--r--drivers/infiniband/hw/cxgb4/cq.c2
-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/nes/nes_cm.c6
-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.c19
-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_qsfp.c12
-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.c14
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c20
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c14
-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/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/mouse/elantech.c26
-rw-r--r--drivers/input/serio/ams_delta_serio.c1
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h14
-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/iommu/omap-iommu-debug.c1
-rw-r--r--drivers/iommu/omap-iovmm.c1
-rw-r--r--drivers/isdn/capi/kcapi_proc.c1
-rw-r--r--drivers/isdn/divert/divert_procfs.c6
-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_net.c3
-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/led-class.c5
-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/macintosh/via-macii.c2
-rw-r--r--drivers/macintosh/via-maciisi.c4
-rw-r--r--drivers/md/dm-bufio.c1
-rw-r--r--drivers/md/dm-exception-store.c1
-rw-r--r--drivers/md/dm-log-userspace-base.c1
-rw-r--r--drivers/md/dm-path-selector.c1
-rw-r--r--drivers/md/dm-raid.c1
-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-uevent.c1
-rw-r--r--drivers/md/dm.c25
-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/dm-btree-remove.c2
-rw-r--r--drivers/md/persistent-data/dm-btree.c2
-rw-r--r--drivers/md/persistent-data/dm-space-map-checker.c1
-rw-r--r--drivers/md/persistent-data/dm-space-map-disk.c2
-rw-r--r--drivers/md/persistent-data/dm-transaction-manager.c2
-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.c25
-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-i2c.c3
-rw-r--r--drivers/media/dvb/dvb-usb/mxl111sf-phy.c7
-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.c1681
-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.c11
-rw-r--r--drivers/media/video/s5p-mfc/s5p_mfc_enc.c9
-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/uvc/uvc_ctrl.c6
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c76
-rw-r--r--drivers/media/video/v4l2-ctrls.c7
-rw-r--r--drivers/media/video/v4l2-device.c37
-rw-r--r--drivers/media/video/v4l2-event.c11
-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.c397
-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.c1440
-rw-r--r--drivers/mfd/ab5500-core.h87
-rw-r--r--drivers/mfd/ab5500-debugfs.c807
-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/Kconfig15
-rw-r--r--drivers/misc/ab8500-pwm.c1
-rw-r--r--drivers/misc/ad525x_dpot.h2
-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/carma/carma-fpga-program.c9
-rw-r--r--drivers/misc/carma/carma-fpga.c9
-rw-r--r--drivers/misc/eeprom/Kconfig2
-rw-r--r--drivers/misc/kgdbts.c1
-rw-r--r--drivers/misc/pch_phub.c81
-rw-r--r--drivers/misc/sgi-gru/grukservices.c1
-rw-r--r--drivers/misc/spear13xx_pcie_gadget.c2
-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/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-esdhc-imx.c8
-rw-r--r--drivers/mmc/host/sdhci-tegra.c1
-rw-r--r--drivers/mtd/Kconfig21
-rw-r--r--drivers/mtd/Makefile2
-rw-r--r--drivers/mtd/afs.c4
-rw-r--r--drivers/mtd/ar7part.c3
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c31
-rw-r--r--drivers/mtd/chips/fwh_lock.h3
-rw-r--r--drivers/mtd/chips/jedec_probe.c34
-rw-r--r--drivers/mtd/cmdlinepart.c8
-rw-r--r--drivers/mtd/devices/Kconfig13
-rw-r--r--drivers/mtd/devices/Makefile3
-rw-r--r--drivers/mtd/devices/doc2000.c17
-rw-r--r--drivers/mtd/devices/doc2001.c11
-rw-r--r--drivers/mtd/devices/doc2001plus.c11
-rw-r--r--drivers/mtd/devices/docecc.c2
-rw-r--r--drivers/mtd/devices/docg3.c1114
-rw-r--r--drivers/mtd/devices/docg3.h297
-rw-r--r--drivers/mtd/devices/docprobe.c5
-rw-r--r--drivers/mtd/devices/lart.c18
-rw-r--r--drivers/mtd/devices/m25p80.c92
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c91
-rw-r--r--drivers/mtd/devices/sst25l.c42
-rw-r--r--drivers/mtd/ftl.c40
-rw-r--r--drivers/mtd/inftlcore.c69
-rw-r--r--drivers/mtd/inftlmount.c116
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c1
-rw-r--r--drivers/mtd/maps/Kconfig26
-rw-r--r--drivers/mtd/maps/Makefile2
-rw-r--r--drivers/mtd/maps/bcm963xx-flash.c1
-rw-r--r--drivers/mtd/maps/bfin-async-flash.c16
-rw-r--r--drivers/mtd/maps/ceiva.c341
-rw-r--r--drivers/mtd/maps/dc21285.c9
-rw-r--r--drivers/mtd/maps/edb7312.c134
-rw-r--r--drivers/mtd/maps/gpio-addr-flash.c16
-rw-r--r--drivers/mtd/maps/h720x-flash.c23
-rw-r--r--drivers/mtd/maps/impa7.c28
-rw-r--r--drivers/mtd/maps/intel_vr_nor.c7
-rw-r--r--drivers/mtd/maps/ixp2000.c11
-rw-r--r--drivers/mtd/maps/ixp4xx.c29
-rw-r--r--drivers/mtd/maps/lantiq-flash.c19
-rw-r--r--drivers/mtd/maps/latch-addr-flash.c24
-rw-r--r--drivers/mtd/maps/pcmciamtd.c124
-rw-r--r--drivers/mtd/maps/physmap.c38
-rw-r--r--drivers/mtd/maps/physmap_of.c80
-rw-r--r--drivers/mtd/maps/plat-ram.c23
-rw-r--r--drivers/mtd/maps/pxa2xx-flash.c20
-rw-r--r--drivers/mtd/maps/rbtx4939-flash.c24
-rw-r--r--drivers/mtd/maps/sa1100-flash.c30
-rw-r--r--drivers/mtd/maps/solutionengine.c30
-rw-r--r--drivers/mtd/maps/wr_sbc82xx_flash.c33
-rw-r--r--drivers/mtd/mtd_blkdevs.c2
-rw-r--r--drivers/mtd/mtdblock.c18
-rw-r--r--drivers/mtd/mtdblock_ro.c1
-rw-r--r--drivers/mtd/mtdchar.c162
-rw-r--r--drivers/mtd/mtdconcat.c10
-rw-r--r--drivers/mtd/mtdcore.c70
-rw-r--r--drivers/mtd/mtdcore.h3
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/mtdpart.c62
-rw-r--r--drivers/mtd/mtdsuper.c21
-rw-r--r--drivers/mtd/mtdswap.c31
-rw-r--r--drivers/mtd/nand/Kconfig31
-rw-r--r--drivers/mtd/nand/Makefile2
-rw-r--r--drivers/mtd/nand/atmel_nand.c74
-rw-r--r--drivers/mtd/nand/au1550nd.c35
-rw-r--r--drivers/mtd/nand/autcpu12.c4
-rw-r--r--drivers/mtd/nand/bcm_umi_nand.c57
-rw-r--r--drivers/mtd/nand/cafe_nand.c22
-rw-r--r--drivers/mtd/nand/cmx270_nand.c24
-rw-r--r--drivers/mtd/nand/cs553x_nand.c15
-rw-r--r--drivers/mtd/nand/davinci_nand.c39
-rw-r--r--drivers/mtd/nand/denali.c6
-rw-r--r--drivers/mtd/nand/diskonchip.c9
-rw-r--r--drivers/mtd/nand/edb7312.c203
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c75
-rw-r--r--drivers/mtd/nand/fsl_upm.c16
-rw-r--r--drivers/mtd/nand/fsmc_nand.c77
-rw-r--r--drivers/mtd/nand/gpmi-nand/Makefile3
-rw-r--r--drivers/mtd/nand/gpmi-nand/bch-regs.h84
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-lib.c1057
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.c1619
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.h273
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-regs.h172
-rw-r--r--drivers/mtd/nand/h1910.c19
-rw-r--r--drivers/mtd/nand/jz4740_nand.c18
-rw-r--r--drivers/mtd/nand/mpc5121_nfc.c22
-rw-r--r--drivers/mtd/nand/mxc_nand.c37
-rw-r--r--drivers/mtd/nand/nand_base.c1109
-rw-r--r--drivers/mtd/nand/nand_bbt.c693
-rw-r--r--drivers/mtd/nand/nand_bch.c4
-rw-r--r--drivers/mtd/nand/nand_ecc.c10
-rw-r--r--drivers/mtd/nand/nandsim.c4
-rw-r--r--drivers/mtd/nand/ndfc.c22
-rw-r--r--drivers/mtd/nand/nomadik_nand.c1
-rw-r--r--drivers/mtd/nand/nuc900_nand.c1
-rw-r--r--drivers/mtd/nand/omap2.c23
-rw-r--r--drivers/mtd/nand/orion_nand.c16
-rw-r--r--drivers/mtd/nand/pasemi_nand.c3
-rw-r--r--drivers/mtd/nand/plat_nand.c25
-rw-r--r--drivers/mtd/nand/ppchameleonevb.c47
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c471
-rw-r--r--drivers/mtd/nand/r852.c6
-rw-r--r--drivers/mtd/nand/rtc_from4.c5
-rw-r--r--drivers/mtd/nand/s3c2410.c27
-rw-r--r--drivers/mtd/nand/sharpsl.c13
-rw-r--r--drivers/mtd/nand/sm_common.c3
-rw-r--r--drivers/mtd/nand/socrates_nand.c28
-rw-r--r--drivers/mtd/nand/tmio_nand.c17
-rw-r--r--drivers/mtd/nand/txx9ndfmc.c8
-rw-r--r--drivers/mtd/nftlcore.c37
-rw-r--r--drivers/mtd/nftlmount.c26
-rw-r--r--drivers/mtd/ofpart.c112
-rw-r--r--drivers/mtd/onenand/generic.c14
-rw-r--r--drivers/mtd/onenand/omap2.c16
-rw-r--r--drivers/mtd/onenand/onenand_base.c114
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c9
-rw-r--r--drivers/mtd/onenand/samsung.c13
-rw-r--r--drivers/mtd/redboot.c17
-rw-r--r--drivers/mtd/rfd_ftl.c1
-rw-r--r--drivers/mtd/sm_ftl.c26
-rw-r--r--drivers/mtd/ssfdc.c46
-rw-r--r--drivers/mtd/tests/mtd_oobtest.c33
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c37
-rw-r--r--drivers/mtd/tests/mtd_readtest.c13
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c17
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c11
-rw-r--r--drivers/mtd/tests/mtd_subpagetest.c17
-rw-r--r--drivers/mtd/tests/mtd_torturetest.c11
-rw-r--r--drivers/mtd/ubi/eba.c2
-rw-r--r--drivers/mtd/ubi/io.c24
-rw-r--r--drivers/mtd/ubi/kapi.c2
-rw-r--r--drivers/mtd/ubi/misc.c2
-rw-r--r--drivers/mtd/ubi/scan.c4
-rw-r--r--drivers/mtd/ubi/vmt.c1
-rw-r--r--drivers/mtd/ubi/vtbl.c2
-rw-r--r--drivers/net/Kconfig2
-rw-r--r--drivers/net/arcnet/Kconfig2
-rw-r--r--drivers/net/bonding/bond_main.c70
-rw-r--r--drivers/net/bonding/bond_procfs.c13
-rw-r--r--drivers/net/bonding/bond_sysfs.c7
-rw-r--r--drivers/net/can/sja1000/peak_pci.c1
-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/broadcom/b44.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c39
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c50
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h1
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c15
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c195
-rw-r--r--drivers/net/ethernet/broadcom/tg3.h21
-rw-r--r--drivers/net/ethernet/brocade/bna/bnad.c1
-rw-r--r--drivers/net/ethernet/cadence/Kconfig1
-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/davicom/dm9000.c2
-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/Kconfig4
-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/ibm/ehea/ehea.h4
-rw-r--r--drivers/net/ethernet/ibm/ehea/ehea_main.c6
-rw-r--r--drivers/net/ethernet/ibm/iseries_veth.c2
-rw-r--r--drivers/net/ethernet/intel/Kconfig6
-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.c2
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h4
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c2
-rw-r--r--drivers/net/ethernet/jme.c113
-rw-r--r--drivers/net/ethernet/jme.h19
-rw-r--r--drivers/net/ethernet/lantiq_etop.c2
-rw-r--r--drivers/net/ethernet/marvell/sky2.c117
-rw-r--r--drivers/net/ethernet/marvell/sky2.h1
-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_rx.c6
-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/mlx4_en.h1
-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/natsemi/Kconfig5
-rw-r--r--drivers/net/ethernet/neterion/vxge/vxge-main.c1
-rw-r--r--drivers/net/ethernet/nvidia/forcedeth.c104
-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/qlogic/qlge/qlge.h8
-rw-r--r--drivers/net/ethernet/rdc/r6040.c2
-rw-r--r--drivers/net/ethernet/realtek/Kconfig12
-rw-r--r--drivers/net/ethernet/realtek/Makefile1
-rw-r--r--drivers/net/ethernet/realtek/r8169.c2
-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/smsc911x.c12
-rw-r--r--drivers/net/ethernet/smsc/smsc9420.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/Kconfig9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac.h2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c6
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c131
-rw-r--r--drivers/net/ethernet/sun/sunhme.c2
-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.c11
-rw-r--r--drivers/net/ethernet/xscale/ixp4xx_eth.c1
-rw-r--r--drivers/net/hippi/Kconfig2
-rw-r--r--drivers/net/irda/Kconfig2
-rw-r--r--drivers/net/macvlan.c7
-rw-r--r--drivers/net/phy/Kconfig2
-rw-r--r--drivers/net/phy/realtek.c1
-rw-r--r--drivers/net/usb/asix.c68
-rw-r--r--drivers/net/usb/cdc_ether.c2
-rw-r--r--drivers/net/usb/lg-vl600.c26
-rw-r--r--drivers/net/usb/smsc75xx.c7
-rw-r--r--drivers/net/usb/usbnet.c3
-rw-r--r--drivers/net/veth.c1
-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/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_calib.c4
-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_calib.c11
-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/ar9003_phy.h34
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9485_initvals.h10
-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.c7
-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/carl9170/tx.c11
-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.c3
-rw-r--r--drivers/net/wireless/b43/main.c2
-rw-r--r--drivers/net/wireless/b43/pcmcia.c1
-rw-r--r--drivers/net/wireless/b43/xmit.c16
-rw-r--r--drivers/net/wireless/b43/xmit.h16
-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/dma.c5
-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-core.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-pci.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans-pcie.c45
-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/cfg.c27
-rw-r--r--drivers/net/wireless/libertas/cfg.h1
-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.c3
-rw-r--r--drivers/net/wireless/libertas/if_usb.c2
-rw-r--r--drivers/net/wireless/libertas/main.c8
-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/mwifiex/scan.c9
-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/p54spi.c5
-rw-r--r--drivers/net/wireless/p54/p54usb.c1
-rw-r--r--drivers/net/wireless/p54/txrx.c1
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h1
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c22
-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/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.c18
-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/wl12xx/scan.c2
-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.c82
-rw-r--r--drivers/nfc/nfcwilink.c1
-rw-r--r--drivers/of/fdt.c7
-rw-r--r--drivers/of/irq.c16
-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/Kconfig12
-rw-r--r--drivers/pci/ats.c1
-rw-r--r--drivers/pci/hotplug-pci.c1
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c29
-rw-r--r--drivers/pci/hotplug/pciehp_acpi.c1
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c3
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c27
-rw-r--r--drivers/pci/hotplug/pcihp_slot.c1
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c1
-rw-r--r--drivers/pci/hotplug/shpchp_core.c4
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c4
-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/Kconfig22
-rw-r--r--drivers/pinctrl/core.c1
-rw-r--r--drivers/platform/x86/Kconfig4
-rw-r--r--drivers/platform/x86/dell-laptop.c4
-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/pnp/pnpacpi/rsparser.c62
-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/ps3/ps3-vuart.c2
-rw-r--r--drivers/ps3/ps3stor_lib.c3
-rw-r--r--drivers/ps3/sys-manager-core.c1
-rw-r--r--drivers/rapidio/switches/idt_gen2.c1
-rw-r--r--drivers/regulator/88pm8607.c1
-rw-r--r--drivers/regulator/aat2870-regulator.c2
-rw-r--r--drivers/regulator/ab8500.c1
-rw-r--r--drivers/regulator/bq24022.c1
-rw-r--r--drivers/regulator/core.c3
-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/tps65910-regulator.c14
-rw-r--r--drivers/regulator/twl-regulator.c46
-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/interface.c1
-rw-r--r--drivers/rtc/rtc-dm355evm.c1
-rw-r--r--drivers/rtc/rtc-ds1305.c1
-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-mrst.c19
-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-puv3.c4
-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/char/zcore.c2
-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/crypto/ap_bus.c23
-rw-r--r--drivers/s390/kvm/kvm_virtio.c1
-rw-r--r--drivers/s390/net/Kconfig2
-rw-r--r--drivers/s390/net/lcs.c6
-rw-r--r--drivers/s390/net/netiucv.c2
-rw-r--r--drivers/s390/net/qeth_core.h3
-rw-r--r--drivers/s390/net/qeth_core_main.c1
-rw-r--r--drivers/s390/net/qeth_l3_main.c7
-rw-r--r--drivers/s390/net/qeth_l3_sys.c4
-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/aacraid/linit.c4
-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.c233
-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.c639
-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.c13
-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.c5
-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/Makefile8
-rw-r--r--drivers/sh/clk/core.c107
-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/sh/pm_runtime.c65
-rw-r--r--drivers/spi/Kconfig2
-rw-r--r--drivers/spi/spi-altera.c1
-rw-r--r--drivers/spi/spi-atmel.c5
-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-nuc900.c2
-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-pl022.c8
-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/comedi/comedi_fops.c96
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c7
-rw-r--r--drivers/staging/cx25821/README6
-rw-r--r--drivers/staging/cxt1e1/linux.c1
-rw-r--r--drivers/staging/et131x/Kconfig3
-rw-r--r--drivers/staging/et131x/et131x.c12
-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/hv/Kconfig6
-rw-r--r--drivers/staging/hv/Makefile1
-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/industrialio-core.c25
-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.h142
-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/octeon/ethernet-tx.c2
-rw-r--r--drivers/staging/rts5139/rts51x_scsi.c1
-rw-r--r--drivers/staging/rts_pstor/rtsx.c1
-rw-r--r--drivers/staging/slicoss/Kconfig2
-rw-r--r--drivers/staging/spectra/lld_mtd.c6
-rw-r--r--drivers/staging/usbip/usbip_common.c1
-rw-r--r--drivers/staging/usbip/usbip_event.c1
-rw-r--r--drivers/staging/usbip/vhci_rx.c10
-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/thermal/thermal_sys.c4
-rw-r--r--drivers/tty/hvc/Kconfig9
-rw-r--r--drivers/tty/hvc/Makefile1
-rw-r--r--drivers/tty/hvc/hvc_console.c7
-rw-r--r--drivers/tty/hvc/hvc_dcc.c2
-rw-r--r--drivers/tty/hvc/hvc_iseries.c1
-rw-r--r--drivers/tty/hvc/hvc_opal.c425
-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/n_gsm.c12
-rw-r--r--drivers/tty/serial/8250.c23
-rw-r--r--drivers/tty/serial/Kconfig14
-rw-r--r--drivers/tty/serial/atmel_serial.c16
-rw-r--r--drivers/tty/serial/crisv10.c10
-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/mfd.c4
-rw-r--r--drivers/tty/serial/nwpserial.c1
-rw-r--r--drivers/tty/serial/pch_uart.c19
-rw-r--r--drivers/tty/serial/sh-sci.c44
-rw-r--r--drivers/tty/serial/timbuart.c1
-rw-r--r--drivers/tty/serial/xilinx_uartps.c1
-rw-r--r--drivers/tty/tty_ldisc.c30
-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/class/cdc-acm.c8
-rw-r--r--drivers/usb/core/driver.c6
-rw-r--r--drivers/usb/core/hub.c6
-rw-r--r--drivers/usb/core/notify.c1
-rw-r--r--drivers/usb/core/quirks.c27
-rw-r--r--drivers/usb/dwc3/gadget.c1
-rw-r--r--drivers/usb/gadget/Kconfig9
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/cdc2.c1
-rw-r--r--drivers/usb/gadget/ci13xxx_msm.c2
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c21
-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_mass_storage.c6
-rw-r--r--drivers/usb/gadget/f_midi.c138
-rw-r--r--drivers/usb/gadget/f_obex.c1
-rw-r--r--drivers/usb/gadget/f_phonet.c2
-rw-r--r--drivers/usb/gadget/f_serial.c4
-rw-r--r--drivers/usb/gadget/f_sourcesink.c1
-rw-r--r--drivers/usb/gadget/file_storage.c5
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c3
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c3
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c80
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.h10
-rw-r--r--drivers/usb/gadget/fusb300_udc.c1
-rw-r--r--drivers/usb/gadget/gmidi.c1
-rw-r--r--drivers/usb/gadget/inode.c5
-rw-r--r--drivers/usb/gadget/m66592-udc.c2
-rw-r--r--drivers/usb/gadget/net2280.c2
-rw-r--r--drivers/usb/gadget/pch_udc.c10
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c32
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c4
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c3
-rw-r--r--drivers/usb/gadget/u_serial.c1
-rw-r--r--drivers/usb/gadget/udc-core.c10
-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/ehci-sched.c22
-rw-r--r--drivers/usb/host/ehci-xls.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-at91.c6
-rw-r--r--drivers/usb/host/ohci-au1xxx.c110
-rw-r--r--drivers/usb/host/ohci-hcd.c15
-rw-r--r--drivers/usb/host/ohci-pci.c26
-rw-r--r--drivers/usb/host/ohci.h1
-rw-r--r--drivers/usb/host/pci-quirks.c58
-rw-r--r--drivers/usb/host/whci/debug.c1
-rw-r--r--drivers/usb/host/whci/hcd.c1
-rw-r--r--drivers/usb/host/whci/qset.c2
-rw-r--r--drivers/usb/host/xhci-hub.c1
-rw-r--r--drivers/usb/host/xhci-mem.c5
-rw-r--r--drivers/usb/host/xhci-pci.c1
-rw-r--r--drivers/usb/host/xhci-ring.c13
-rw-r--r--drivers/usb/host/xhci.c39
-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/musb/Kconfig3
-rw-r--r--drivers/usb/musb/am35x.c1
-rw-r--r--drivers/usb/musb/da8xx.c1
-rw-r--r--drivers/usb/musb/musb_core.c9
-rw-r--r--drivers/usb/musb/musb_gadget.c6
-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/renesas_usbhs/common.c2
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c4
-rw-r--r--drivers/usb/renesas_usbhs/mod.h8
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c51
-rw-r--r--drivers/usb/renesas_usbhs/mod_host.c63
-rw-r--r--drivers/usb/serial/aircable.c1
-rw-r--r--drivers/usb/serial/ark3116.c10
-rw-r--r--drivers/usb/serial/ftdi_sio.c15
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h1
-rw-r--r--drivers/usb/serial/option.c32
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/qcserial.c1
-rw-r--r--drivers/usb/storage/ene_ub6250.c3
-rw-r--r--drivers/usb/storage/option_ms.c1
-rw-r--r--drivers/usb/storage/protocol.c8
-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/storage/unusual_devs.h7
-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/da8xx-fb.c15
-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/dispc.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.c12
-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/hdmi.c2
-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/share.h4
-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/Kconfig2
-rw-r--r--drivers/virtio/virtio.c1
-rw-r--r--drivers/virtio/virtio_balloon.c1
-rw-r--r--drivers/virtio/virtio_mmio.c2
-rw-r--r--drivers/virtio/virtio_pci.c29
-rw-r--r--drivers/virtio/virtio_ring.c1
-rw-r--r--drivers/w1/w1_family.c1
-rw-r--r--drivers/w1/w1_int.c2
-rw-r--r--drivers/watchdog/Kconfig9
-rw-r--r--drivers/watchdog/Makefile1
-rw-r--r--drivers/watchdog/adx_wdt.c355
-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.c180
-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.c18
-rw-r--r--drivers/xen/events.c9
-rw-r--r--drivers/xen/gntalloc.c4
-rw-r--r--drivers/xen/gntdev.c13
-rw-r--r--drivers/xen/grant-table.c2
-rw-r--r--drivers/xen/manage.c1
-rw-r--r--drivers/xen/pci.c2
-rw-r--r--drivers/xen/swiotlb-xen.c1
-rw-r--r--drivers/xen/xen-balloon.c17
-rw-r--r--drivers/xen/xen-pciback/conf_space.c1
-rw-r--r--drivers/xen/xenbus/xenbus_client.c16
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c8
-rw-r--r--drivers/xen/xenbus/xenbus_probe.h3
-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
1887 files changed, 42242 insertions, 21315 deletions
diff --git a/drivers/acpi/acpica/evxface.c b/drivers/acpi/acpica/evxface.c
index e1141402dbe..f4f523bf593 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 c57b5c707a7..20516e59947 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 52aaff3df56..f06a3ee356b 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 00cd95692a9..aee887e3ca5 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/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 55accb7018b..cc70f3fdcdd 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -269,16 +269,17 @@ acpi_status acpi_hw_clear_acpi_status(void)
269 269
270 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, 270 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
271 ACPI_BITMASK_ALL_FIXED_STATUS); 271 ACPI_BITMASK_ALL_FIXED_STATUS);
272 if (ACPI_FAILURE(status)) { 272
273 goto unlock_and_exit; 273 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
274 } 274
275 if (ACPI_FAILURE(status))
276 goto exit;
275 277
276 /* Clear the GPE Bits in all GPE registers in all GPE blocks */ 278 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
277 279
278 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); 280 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
279 281
280 unlock_and_exit: 282exit:
281 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
282 return_ACPI_STATUS(status); 283 return_ACPI_STATUS(status);
283} 284}
284 285
diff --git a/drivers/acpi/acpica/hwsleep.c b/drivers/acpi/acpica/hwsleep.c
index 2ac28bbe882..d52da307365 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 9c8eb71a12f..50d21c40b5c 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 f75f81ad15c..c2793a82f12 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 c53f0040e49..e7f016d1b22 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 3fd4526f3db..83bf9302430 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 db7660f8b86..57e6d825ed8 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 2ff657a28f2..fe86b37b16c 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 4b7085dfc68..e7d13f5d3f2 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 a9bcd816dc2..a1f8d7509e6 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 97cb36f85ce..8b087e2d64f 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 833a38a9c90..ffba0a39c3e 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 98ad125e14f..420ebfe08c7 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 916ae097c43..8d0245ec431 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/apei/erst.c b/drivers/acpi/apei/erst.c
index 127408069ca..631b9477b99 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -932,7 +932,8 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)
932static int erst_open_pstore(struct pstore_info *psi); 932static int erst_open_pstore(struct pstore_info *psi);
933static int erst_close_pstore(struct pstore_info *psi); 933static int erst_close_pstore(struct pstore_info *psi);
934static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, 934static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
935 struct timespec *time, struct pstore_info *psi); 935 struct timespec *time, char **buf,
936 struct pstore_info *psi);
936static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part, 937static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
937 size_t size, struct pstore_info *psi); 938 size_t size, struct pstore_info *psi);
938static int erst_clearer(enum pstore_type_id type, u64 id, 939static int erst_clearer(enum pstore_type_id type, u64 id,
@@ -986,17 +987,23 @@ static int erst_close_pstore(struct pstore_info *psi)
986} 987}
987 988
988static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, 989static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
989 struct timespec *time, struct pstore_info *psi) 990 struct timespec *time, char **buf,
991 struct pstore_info *psi)
990{ 992{
991 int rc; 993 int rc;
992 ssize_t len = 0; 994 ssize_t len = 0;
993 u64 record_id; 995 u64 record_id;
994 struct cper_pstore_record *rcd = (struct cper_pstore_record *) 996 struct cper_pstore_record *rcd;
995 (erst_info.buf - sizeof(*rcd)); 997 size_t rcd_len = sizeof(*rcd) + erst_info.bufsize;
996 998
997 if (erst_disable) 999 if (erst_disable)
998 return -ENODEV; 1000 return -ENODEV;
999 1001
1002 rcd = kmalloc(rcd_len, GFP_KERNEL);
1003 if (!rcd) {
1004 rc = -ENOMEM;
1005 goto out;
1006 }
1000skip: 1007skip:
1001 rc = erst_get_record_id_next(&reader_pos, &record_id); 1008 rc = erst_get_record_id_next(&reader_pos, &record_id);
1002 if (rc) 1009 if (rc)
@@ -1004,22 +1011,27 @@ skip:
1004 1011
1005 /* no more record */ 1012 /* no more record */
1006 if (record_id == APEI_ERST_INVALID_RECORD_ID) { 1013 if (record_id == APEI_ERST_INVALID_RECORD_ID) {
1007 rc = -1; 1014 rc = -EINVAL;
1008 goto out; 1015 goto out;
1009 } 1016 }
1010 1017
1011 len = erst_read(record_id, &rcd->hdr, sizeof(*rcd) + 1018 len = erst_read(record_id, &rcd->hdr, rcd_len);
1012 erst_info.bufsize);
1013 /* The record may be cleared by others, try read next record */ 1019 /* The record may be cleared by others, try read next record */
1014 if (len == -ENOENT) 1020 if (len == -ENOENT)
1015 goto skip; 1021 goto skip;
1016 else if (len < 0) { 1022 else if (len < sizeof(*rcd)) {
1017 rc = -1; 1023 rc = -EIO;
1018 goto out; 1024 goto out;
1019 } 1025 }
1020 if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0) 1026 if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0)
1021 goto skip; 1027 goto skip;
1022 1028
1029 *buf = kmalloc(len, GFP_KERNEL);
1030 if (*buf == NULL) {
1031 rc = -ENOMEM;
1032 goto out;
1033 }
1034 memcpy(*buf, rcd->data, len - sizeof(*rcd));
1023 *id = record_id; 1035 *id = record_id;
1024 if (uuid_le_cmp(rcd->sec_hdr.section_type, 1036 if (uuid_le_cmp(rcd->sec_hdr.section_type,
1025 CPER_SECTION_TYPE_DMESG) == 0) 1037 CPER_SECTION_TYPE_DMESG) == 0)
@@ -1037,6 +1049,7 @@ skip:
1037 time->tv_nsec = 0; 1049 time->tv_nsec = 0;
1038 1050
1039out: 1051out:
1052 kfree(rcd);
1040 return (rc < 0) ? rc : (len - sizeof(*rcd)); 1053 return (rc < 0) ? rc : (len - sizeof(*rcd));
1041} 1054}
1042 1055
diff --git a/drivers/acpi/atomicio.c b/drivers/acpi/atomicio.c
index 7489b89c300..cfc0cc10af3 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>
@@ -76,7 +76,7 @@ static void __iomem *__acpi_ioremap_fast(phys_addr_t paddr,
76{ 76{
77 struct acpi_iomap *map; 77 struct acpi_iomap *map;
78 78
79 map = __acpi_find_iomap(paddr, size); 79 map = __acpi_find_iomap(paddr, size/8);
80 if (map) 80 if (map)
81 return map->vaddr + (paddr - map->paddr); 81 return map->vaddr + (paddr - map->paddr);
82 else 82 else
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index af308d03f49..cb9629638de 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/bus.c b/drivers/acpi/bus.c
index 437ddbf0c49..9ecec98bc76 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -911,10 +911,7 @@ void __init acpi_early_init(void)
911 } 911 }
912#endif 912#endif
913 913
914 status = 914 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
915 acpi_enable_subsystem(~
916 (ACPI_NO_HARDWARE_INIT |
917 ACPI_NO_ACPI_ENABLE));
918 if (ACPI_FAILURE(status)) { 915 if (ACPI_FAILURE(status)) {
919 printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); 916 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
920 goto error0; 917 goto error0;
@@ -935,8 +932,7 @@ static int __init acpi_bus_init(void)
935 932
936 acpi_os_initialize1(); 933 acpi_os_initialize1();
937 934
938 status = 935 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
939 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
940 if (ACPI_FAILURE(status)) { 936 if (ACPI_FAILURE(status)) {
941 printk(KERN_ERR PREFIX 937 printk(KERN_ERR PREFIX
942 "Unable to start the ACPI Interpreter\n"); 938 "Unable to start the ACPI Interpreter\n");
diff --git a/drivers/acpi/debugfs.c b/drivers/acpi/debugfs.c
index 182a9fc3635..b55d6a20dc0 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 22f918bacd3..6c47ae9793a 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 85d90899380..1442737cede 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 7c47ed55e52..29a4a5c8ee0 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 f5f986991b5..251c7b6273a 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 02d2a4c9084..3a0428e8435 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/processor_driver.c b/drivers/acpi/processor_driver.c
index a4e0f1ba604..9d7bc9f6b6c 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -426,7 +426,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
426 426
427 if (action == CPU_ONLINE && pr) { 427 if (action == CPU_ONLINE && pr) {
428 acpi_processor_ppc_has_changed(pr, 0); 428 acpi_processor_ppc_has_changed(pr, 0);
429 acpi_processor_cst_has_changed(pr); 429 acpi_processor_hotplug(pr);
430 acpi_processor_reevaluate_tstate(pr, action); 430 acpi_processor_reevaluate_tstate(pr, action);
431 acpi_processor_tstate_has_changed(pr); 431 acpi_processor_tstate_has_changed(pr);
432 } 432 }
@@ -503,8 +503,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
503 acpi_processor_get_throttling_info(pr); 503 acpi_processor_get_throttling_info(pr);
504 acpi_processor_get_limit_info(pr); 504 acpi_processor_get_limit_info(pr);
505 505
506 506 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
507 if (cpuidle_get_driver() == &acpi_idle_driver)
508 acpi_processor_power_init(pr, device); 507 acpi_processor_power_init(pr, device);
509 508
510 pr->cdev = thermal_cooling_device_register("Processor", device, 509 pr->cdev = thermal_cooling_device_register("Processor", device,
@@ -800,17 +799,9 @@ static int __init acpi_processor_init(void)
800 799
801 memset(&errata, 0, sizeof(errata)); 800 memset(&errata, 0, sizeof(errata));
802 801
803 if (!cpuidle_register_driver(&acpi_idle_driver)) {
804 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
805 acpi_idle_driver.name);
806 } else {
807 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
808 cpuidle_get_driver()->name);
809 }
810
811 result = acpi_bus_register_driver(&acpi_processor_driver); 802 result = acpi_bus_register_driver(&acpi_processor_driver);
812 if (result < 0) 803 if (result < 0)
813 goto out_cpuidle; 804 return result;
814 805
815 acpi_processor_install_hotplug_notify(); 806 acpi_processor_install_hotplug_notify();
816 807
@@ -821,11 +812,6 @@ static int __init acpi_processor_init(void)
821 acpi_processor_throttling_init(); 812 acpi_processor_throttling_init();
822 813
823 return 0; 814 return 0;
824
825out_cpuidle:
826 cpuidle_unregister_driver(&acpi_idle_driver);
827
828 return result;
829} 815}
830 816
831static void __exit acpi_processor_exit(void) 817static void __exit acpi_processor_exit(void)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 9b88f9828d8..0e8e2de2ed3 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -224,7 +224,6 @@ static void lapic_timer_state_broadcast(struct acpi_processor *pr,
224/* 224/*
225 * Suspend / resume control 225 * Suspend / resume control
226 */ 226 */
227static int acpi_idle_suspend;
228static u32 saved_bm_rld; 227static u32 saved_bm_rld;
229 228
230static void acpi_idle_bm_rld_save(void) 229static void acpi_idle_bm_rld_save(void)
@@ -243,21 +242,13 @@ static void acpi_idle_bm_rld_restore(void)
243 242
244int acpi_processor_suspend(struct acpi_device * device, pm_message_t state) 243int acpi_processor_suspend(struct acpi_device * device, pm_message_t state)
245{ 244{
246 if (acpi_idle_suspend == 1)
247 return 0;
248
249 acpi_idle_bm_rld_save(); 245 acpi_idle_bm_rld_save();
250 acpi_idle_suspend = 1;
251 return 0; 246 return 0;
252} 247}
253 248
254int acpi_processor_resume(struct acpi_device * device) 249int acpi_processor_resume(struct acpi_device * device)
255{ 250{
256 if (acpi_idle_suspend == 0)
257 return 0;
258
259 acpi_idle_bm_rld_restore(); 251 acpi_idle_bm_rld_restore();
260 acpi_idle_suspend = 0;
261 return 0; 252 return 0;
262} 253}
263 254
@@ -741,66 +732,65 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
741/** 732/**
742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type 733 * acpi_idle_enter_c1 - enters an ACPI C1 state-type
743 * @dev: the target CPU 734 * @dev: the target CPU
744 * @state: the state data 735 * @drv: cpuidle driver containing cpuidle state info
736 * @index: index of target state
745 * 737 *
746 * This is equivalent to the HALT instruction. 738 * This is equivalent to the HALT instruction.
747 */ 739 */
748static int acpi_idle_enter_c1(struct cpuidle_device *dev, 740static int acpi_idle_enter_c1(struct cpuidle_device *dev,
749 struct cpuidle_state *state) 741 struct cpuidle_driver *drv, int index)
750{ 742{
751 ktime_t kt1, kt2; 743 ktime_t kt1, kt2;
752 s64 idle_time; 744 s64 idle_time;
753 struct acpi_processor *pr; 745 struct acpi_processor *pr;
754 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 746 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
747 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
755 748
756 pr = __this_cpu_read(processors); 749 pr = __this_cpu_read(processors);
750 dev->last_residency = 0;
757 751
758 if (unlikely(!pr)) 752 if (unlikely(!pr))
759 return 0; 753 return -EINVAL;
760 754
761 local_irq_disable(); 755 local_irq_disable();
762 756
763 /* Do not access any ACPI IO ports in suspend path */
764 if (acpi_idle_suspend) {
765 local_irq_enable();
766 cpu_relax();
767 return 0;
768 }
769
770 lapic_timer_state_broadcast(pr, cx, 1); 757 lapic_timer_state_broadcast(pr, cx, 1);
771 kt1 = ktime_get_real(); 758 kt1 = ktime_get_real();
772 acpi_idle_do_entry(cx); 759 acpi_idle_do_entry(cx);
773 kt2 = ktime_get_real(); 760 kt2 = ktime_get_real();
774 idle_time = ktime_to_us(ktime_sub(kt2, kt1)); 761 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
775 762
763 /* Update device last_residency*/
764 dev->last_residency = (int)idle_time;
765
776 local_irq_enable(); 766 local_irq_enable();
777 cx->usage++; 767 cx->usage++;
778 lapic_timer_state_broadcast(pr, cx, 0); 768 lapic_timer_state_broadcast(pr, cx, 0);
779 769
780 return idle_time; 770 return index;
781} 771}
782 772
783/** 773/**
784 * acpi_idle_enter_simple - enters an ACPI state without BM handling 774 * acpi_idle_enter_simple - enters an ACPI state without BM handling
785 * @dev: the target CPU 775 * @dev: the target CPU
786 * @state: the state data 776 * @drv: cpuidle driver with cpuidle state information
777 * @index: the index of suggested state
787 */ 778 */
788static int acpi_idle_enter_simple(struct cpuidle_device *dev, 779static int acpi_idle_enter_simple(struct cpuidle_device *dev,
789 struct cpuidle_state *state) 780 struct cpuidle_driver *drv, int index)
790{ 781{
791 struct acpi_processor *pr; 782 struct acpi_processor *pr;
792 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 783 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
784 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
793 ktime_t kt1, kt2; 785 ktime_t kt1, kt2;
794 s64 idle_time_ns; 786 s64 idle_time_ns;
795 s64 idle_time; 787 s64 idle_time;
796 788
797 pr = __this_cpu_read(processors); 789 pr = __this_cpu_read(processors);
790 dev->last_residency = 0;
798 791
799 if (unlikely(!pr)) 792 if (unlikely(!pr))
800 return 0; 793 return -EINVAL;
801
802 if (acpi_idle_suspend)
803 return(acpi_idle_enter_c1(dev, state));
804 794
805 local_irq_disable(); 795 local_irq_disable();
806 796
@@ -815,7 +805,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
815 if (unlikely(need_resched())) { 805 if (unlikely(need_resched())) {
816 current_thread_info()->status |= TS_POLLING; 806 current_thread_info()->status |= TS_POLLING;
817 local_irq_enable(); 807 local_irq_enable();
818 return 0; 808 return -EINVAL;
819 } 809 }
820 } 810 }
821 811
@@ -837,6 +827,9 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
837 idle_time = idle_time_ns; 827 idle_time = idle_time_ns;
838 do_div(idle_time, NSEC_PER_USEC); 828 do_div(idle_time, NSEC_PER_USEC);
839 829
830 /* Update device last_residency*/
831 dev->last_residency = (int)idle_time;
832
840 /* Tell the scheduler how much we idled: */ 833 /* Tell the scheduler how much we idled: */
841 sched_clock_idle_wakeup_event(idle_time_ns); 834 sched_clock_idle_wakeup_event(idle_time_ns);
842 835
@@ -848,7 +841,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
848 841
849 lapic_timer_state_broadcast(pr, cx, 0); 842 lapic_timer_state_broadcast(pr, cx, 0);
850 cx->time += idle_time; 843 cx->time += idle_time;
851 return idle_time; 844 return index;
852} 845}
853 846
854static int c3_cpu_count; 847static int c3_cpu_count;
@@ -857,37 +850,37 @@ static DEFINE_RAW_SPINLOCK(c3_lock);
857/** 850/**
858 * acpi_idle_enter_bm - enters C3 with proper BM handling 851 * acpi_idle_enter_bm - enters C3 with proper BM handling
859 * @dev: the target CPU 852 * @dev: the target CPU
860 * @state: the state data 853 * @drv: cpuidle driver containing state data
854 * @index: the index of suggested state
861 * 855 *
862 * If BM is detected, the deepest non-C3 idle state is entered instead. 856 * If BM is detected, the deepest non-C3 idle state is entered instead.
863 */ 857 */
864static int acpi_idle_enter_bm(struct cpuidle_device *dev, 858static int acpi_idle_enter_bm(struct cpuidle_device *dev,
865 struct cpuidle_state *state) 859 struct cpuidle_driver *drv, int index)
866{ 860{
867 struct acpi_processor *pr; 861 struct acpi_processor *pr;
868 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 862 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
863 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
869 ktime_t kt1, kt2; 864 ktime_t kt1, kt2;
870 s64 idle_time_ns; 865 s64 idle_time_ns;
871 s64 idle_time; 866 s64 idle_time;
872 867
873 868
874 pr = __this_cpu_read(processors); 869 pr = __this_cpu_read(processors);
870 dev->last_residency = 0;
875 871
876 if (unlikely(!pr)) 872 if (unlikely(!pr))
877 return 0; 873 return -EINVAL;
878
879 if (acpi_idle_suspend)
880 return(acpi_idle_enter_c1(dev, state));
881 874
882 if (!cx->bm_sts_skip && acpi_idle_bm_check()) { 875 if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
883 if (dev->safe_state) { 876 if (drv->safe_state_index >= 0) {
884 dev->last_state = dev->safe_state; 877 return drv->states[drv->safe_state_index].enter(dev,
885 return dev->safe_state->enter(dev, dev->safe_state); 878 drv, drv->safe_state_index);
886 } else { 879 } else {
887 local_irq_disable(); 880 local_irq_disable();
888 acpi_safe_halt(); 881 acpi_safe_halt();
889 local_irq_enable(); 882 local_irq_enable();
890 return 0; 883 return -EINVAL;
891 } 884 }
892 } 885 }
893 886
@@ -904,7 +897,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
904 if (unlikely(need_resched())) { 897 if (unlikely(need_resched())) {
905 current_thread_info()->status |= TS_POLLING; 898 current_thread_info()->status |= TS_POLLING;
906 local_irq_enable(); 899 local_irq_enable();
907 return 0; 900 return -EINVAL;
908 } 901 }
909 } 902 }
910 903
@@ -954,6 +947,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
954 idle_time = idle_time_ns; 947 idle_time = idle_time_ns;
955 do_div(idle_time, NSEC_PER_USEC); 948 do_div(idle_time, NSEC_PER_USEC);
956 949
950 /* Update device last_residency*/
951 dev->last_residency = (int)idle_time;
952
957 /* Tell the scheduler how much we idled: */ 953 /* Tell the scheduler how much we idled: */
958 sched_clock_idle_wakeup_event(idle_time_ns); 954 sched_clock_idle_wakeup_event(idle_time_ns);
959 955
@@ -965,7 +961,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
965 961
966 lapic_timer_state_broadcast(pr, cx, 0); 962 lapic_timer_state_broadcast(pr, cx, 0);
967 cx->time += idle_time; 963 cx->time += idle_time;
968 return idle_time; 964 return index;
969} 965}
970 966
971struct cpuidle_driver acpi_idle_driver = { 967struct cpuidle_driver acpi_idle_driver = {
@@ -974,14 +970,16 @@ struct cpuidle_driver acpi_idle_driver = {
974}; 970};
975 971
976/** 972/**
977 * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE 973 * acpi_processor_setup_cpuidle_cx - prepares and configures CPUIDLE
974 * device i.e. per-cpu data
975 *
978 * @pr: the ACPI processor 976 * @pr: the ACPI processor
979 */ 977 */
980static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) 978static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr)
981{ 979{
982 int i, count = CPUIDLE_DRIVER_STATE_START; 980 int i, count = CPUIDLE_DRIVER_STATE_START;
983 struct acpi_processor_cx *cx; 981 struct acpi_processor_cx *cx;
984 struct cpuidle_state *state; 982 struct cpuidle_state_usage *state_usage;
985 struct cpuidle_device *dev = &pr->power.dev; 983 struct cpuidle_device *dev = &pr->power.dev;
986 984
987 if (!pr->flags.power_setup_done) 985 if (!pr->flags.power_setup_done)
@@ -992,9 +990,62 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
992 } 990 }
993 991
994 dev->cpu = pr->id; 992 dev->cpu = pr->id;
993
994 if (max_cstate == 0)
995 max_cstate = 1;
996
997 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
998 cx = &pr->power.states[i];
999 state_usage = &dev->states_usage[count];
1000
1001 if (!cx->valid)
1002 continue;
1003
1004#ifdef CONFIG_HOTPLUG_CPU
1005 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1006 !pr->flags.has_cst &&
1007 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1008 continue;
1009#endif
1010
1011 cpuidle_set_statedata(state_usage, cx);
1012
1013 count++;
1014 if (count == CPUIDLE_STATE_MAX)
1015 break;
1016 }
1017
1018 dev->state_count = count;
1019
1020 if (!count)
1021 return -EINVAL;
1022
1023 return 0;
1024}
1025
1026/**
1027 * acpi_processor_setup_cpuidle states- prepares and configures cpuidle
1028 * global state data i.e. idle routines
1029 *
1030 * @pr: the ACPI processor
1031 */
1032static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
1033{
1034 int i, count = CPUIDLE_DRIVER_STATE_START;
1035 struct acpi_processor_cx *cx;
1036 struct cpuidle_state *state;
1037 struct cpuidle_driver *drv = &acpi_idle_driver;
1038
1039 if (!pr->flags.power_setup_done)
1040 return -EINVAL;
1041
1042 if (pr->flags.power == 0)
1043 return -EINVAL;
1044
1045 drv->safe_state_index = -1;
995 for (i = 0; i < CPUIDLE_STATE_MAX; i++) { 1046 for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
996 dev->states[i].name[0] = '\0'; 1047 drv->states[i].name[0] = '\0';
997 dev->states[i].desc[0] = '\0'; 1048 drv->states[i].desc[0] = '\0';
998 } 1049 }
999 1050
1000 if (max_cstate == 0) 1051 if (max_cstate == 0)
@@ -1002,7 +1053,6 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1002 1053
1003 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { 1054 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1004 cx = &pr->power.states[i]; 1055 cx = &pr->power.states[i];
1005 state = &dev->states[count];
1006 1056
1007 if (!cx->valid) 1057 if (!cx->valid)
1008 continue; 1058 continue;
@@ -1013,8 +1063,8 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1013 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) 1063 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1014 continue; 1064 continue;
1015#endif 1065#endif
1016 cpuidle_set_statedata(state, cx);
1017 1066
1067 state = &drv->states[count];
1018 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); 1068 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1019 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); 1069 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1020 state->exit_latency = cx->latency; 1070 state->exit_latency = cx->latency;
@@ -1027,13 +1077,13 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1027 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1077 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1028 1078
1029 state->enter = acpi_idle_enter_c1; 1079 state->enter = acpi_idle_enter_c1;
1030 dev->safe_state = state; 1080 drv->safe_state_index = count;
1031 break; 1081 break;
1032 1082
1033 case ACPI_STATE_C2: 1083 case ACPI_STATE_C2:
1034 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1084 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1035 state->enter = acpi_idle_enter_simple; 1085 state->enter = acpi_idle_enter_simple;
1036 dev->safe_state = state; 1086 drv->safe_state_index = count;
1037 break; 1087 break;
1038 1088
1039 case ACPI_STATE_C3: 1089 case ACPI_STATE_C3:
@@ -1049,7 +1099,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1049 break; 1099 break;
1050 } 1100 }
1051 1101
1052 dev->state_count = count; 1102 drv->state_count = count;
1053 1103
1054 if (!count) 1104 if (!count)
1055 return -EINVAL; 1105 return -EINVAL;
@@ -1057,7 +1107,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1057 return 0; 1107 return 0;
1058} 1108}
1059 1109
1060int acpi_processor_cst_has_changed(struct acpi_processor *pr) 1110int acpi_processor_hotplug(struct acpi_processor *pr)
1061{ 1111{
1062 int ret = 0; 1112 int ret = 0;
1063 1113
@@ -1078,7 +1128,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1078 cpuidle_disable_device(&pr->power.dev); 1128 cpuidle_disable_device(&pr->power.dev);
1079 acpi_processor_get_power_info(pr); 1129 acpi_processor_get_power_info(pr);
1080 if (pr->flags.power) { 1130 if (pr->flags.power) {
1081 acpi_processor_setup_cpuidle(pr); 1131 acpi_processor_setup_cpuidle_cx(pr);
1082 ret = cpuidle_enable_device(&pr->power.dev); 1132 ret = cpuidle_enable_device(&pr->power.dev);
1083 } 1133 }
1084 cpuidle_resume_and_unlock(); 1134 cpuidle_resume_and_unlock();
@@ -1086,10 +1136,72 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1086 return ret; 1136 return ret;
1087} 1137}
1088 1138
1139int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1140{
1141 int cpu;
1142 struct acpi_processor *_pr;
1143
1144 if (disabled_by_idle_boot_param())
1145 return 0;
1146
1147 if (!pr)
1148 return -EINVAL;
1149
1150 if (nocst)
1151 return -ENODEV;
1152
1153 if (!pr->flags.power_setup_done)
1154 return -ENODEV;
1155
1156 /*
1157 * FIXME: Design the ACPI notification to make it once per
1158 * system instead of once per-cpu. This condition is a hack
1159 * to make the code that updates C-States be called once.
1160 */
1161
1162 if (smp_processor_id() == 0 &&
1163 cpuidle_get_driver() == &acpi_idle_driver) {
1164
1165 cpuidle_pause_and_lock();
1166 /* Protect against cpu-hotplug */
1167 get_online_cpus();
1168
1169 /* Disable all cpuidle devices */
1170 for_each_online_cpu(cpu) {
1171 _pr = per_cpu(processors, cpu);
1172 if (!_pr || !_pr->flags.power_setup_done)
1173 continue;
1174 cpuidle_disable_device(&_pr->power.dev);
1175 }
1176
1177 /* Populate Updated C-state information */
1178 acpi_processor_setup_cpuidle_states(pr);
1179
1180 /* Enable all cpuidle devices */
1181 for_each_online_cpu(cpu) {
1182 _pr = per_cpu(processors, cpu);
1183 if (!_pr || !_pr->flags.power_setup_done)
1184 continue;
1185 acpi_processor_get_power_info(_pr);
1186 if (_pr->flags.power) {
1187 acpi_processor_setup_cpuidle_cx(_pr);
1188 cpuidle_enable_device(&_pr->power.dev);
1189 }
1190 }
1191 put_online_cpus();
1192 cpuidle_resume_and_unlock();
1193 }
1194
1195 return 0;
1196}
1197
1198static int acpi_processor_registered;
1199
1089int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, 1200int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1090 struct acpi_device *device) 1201 struct acpi_device *device)
1091{ 1202{
1092 acpi_status status = 0; 1203 acpi_status status = 0;
1204 int retval;
1093 static int first_run; 1205 static int first_run;
1094 1206
1095 if (disabled_by_idle_boot_param()) 1207 if (disabled_by_idle_boot_param())
@@ -1126,9 +1238,26 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1126 * platforms that only support C1. 1238 * platforms that only support C1.
1127 */ 1239 */
1128 if (pr->flags.power) { 1240 if (pr->flags.power) {
1129 acpi_processor_setup_cpuidle(pr); 1241 /* Register acpi_idle_driver if not already registered */
1130 if (cpuidle_register_device(&pr->power.dev)) 1242 if (!acpi_processor_registered) {
1131 return -EIO; 1243 acpi_processor_setup_cpuidle_states(pr);
1244 retval = cpuidle_register_driver(&acpi_idle_driver);
1245 if (retval)
1246 return retval;
1247 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
1248 acpi_idle_driver.name);
1249 }
1250 /* Register per-cpu cpuidle_device. Cpuidle driver
1251 * must already be registered before registering device
1252 */
1253 acpi_processor_setup_cpuidle_cx(pr);
1254 retval = cpuidle_register_device(&pr->power.dev);
1255 if (retval) {
1256 if (acpi_processor_registered == 0)
1257 cpuidle_unregister_driver(&acpi_idle_driver);
1258 return retval;
1259 }
1260 acpi_processor_registered++;
1132 } 1261 }
1133 return 0; 1262 return 0;
1134} 1263}
@@ -1139,8 +1268,13 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1139 if (disabled_by_idle_boot_param()) 1268 if (disabled_by_idle_boot_param())
1140 return 0; 1269 return 0;
1141 1270
1142 cpuidle_unregister_device(&pr->power.dev); 1271 if (pr->flags.power) {
1143 pr->flags.power_setup_done = 0; 1272 cpuidle_unregister_device(&pr->power.dev);
1273 acpi_processor_registered--;
1274 if (acpi_processor_registered == 0)
1275 cpuidle_unregister_driver(&acpi_idle_driver);
1276 }
1144 1277
1278 pr->flags.power_setup_done = 0;
1145 return 0; 1279 return 0;
1146} 1280}
diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
index f8be23b6c12..f8d2a472795 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/scan.c b/drivers/acpi/scan.c
index 449c556274c..8ab80bafe3f 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1062,13 +1062,12 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id)
1062 if (!id) 1062 if (!id)
1063 return; 1063 return;
1064 1064
1065 id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL); 1065 id->id = kstrdup(dev_id, GFP_KERNEL);
1066 if (!id->id) { 1066 if (!id->id) {
1067 kfree(id); 1067 kfree(id);
1068 return; 1068 return;
1069 } 1069 }
1070 1070
1071 strcpy(id->id, dev_id);
1072 list_add_tail(&id->list, &device->pnp.ids); 1071 list_add_tail(&id->list, &device->pnp.ids);
1073} 1072}
1074 1073
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 0e46faef1d3..6d9a3ab58db 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/sysfs.c b/drivers/acpi/sysfs.c
index c538d0ef10f..9f66181c814 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -706,11 +706,23 @@ static void __exit interrupt_stats_exit(void)
706 return; 706 return;
707} 707}
708 708
709static ssize_t
710acpi_show_profile(struct device *dev, struct device_attribute *attr,
711 char *buf)
712{
713 return sprintf(buf, "%d\n", acpi_gbl_FADT.preferred_profile);
714}
715
716static const struct device_attribute pm_profile_attr =
717 __ATTR(pm_profile, S_IRUGO, acpi_show_profile, NULL);
718
709int __init acpi_sysfs_init(void) 719int __init acpi_sysfs_init(void)
710{ 720{
711 int result; 721 int result;
712 722
713 result = acpi_tables_sysfs_init(); 723 result = acpi_tables_sysfs_init();
714 724 if (result)
725 return result;
726 result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr);
715 return result; 727 return result;
716} 728}
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index 5af3479714f..f3f0fe7e255 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.c b/drivers/ata/ahci.c
index fb7b90b0592..cf26222a93c 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -390,6 +390,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
390 /* Promise */ 390 /* Promise */
391 { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */ 391 { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */
392 392
393 /* Asmedia */
394 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1061 */
395
393 /* Generic, PCI class code for AHCI */ 396 /* Generic, PCI class code for AHCI */
394 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 397 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
395 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci }, 398 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index c03277d3774..43b875810d1 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -65,9 +65,9 @@ static struct scsi_host_template ahci_platform_sht = {
65static int __init ahci_probe(struct platform_device *pdev) 65static int __init ahci_probe(struct platform_device *pdev)
66{ 66{
67 struct device *dev = &pdev->dev; 67 struct device *dev = &pdev->dev;
68 struct ahci_platform_data *pdata = dev->platform_data; 68 struct ahci_platform_data *pdata = dev_get_platdata(dev);
69 const struct platform_device_id *id = platform_get_device_id(pdev); 69 const struct platform_device_id *id = platform_get_device_id(pdev);
70 struct ata_port_info pi = ahci_port_info[id->driver_data]; 70 struct ata_port_info pi = ahci_port_info[id ? id->driver_data : 0];
71 const struct ata_port_info *ppi[] = { &pi, NULL }; 71 const struct ata_port_info *ppi[] = { &pi, NULL };
72 struct ahci_host_priv *hpriv; 72 struct ahci_host_priv *hpriv;
73 struct ata_host *host; 73 struct ata_host *host;
@@ -191,7 +191,7 @@ err0:
191static int __devexit ahci_remove(struct platform_device *pdev) 191static int __devexit ahci_remove(struct platform_device *pdev)
192{ 192{
193 struct device *dev = &pdev->dev; 193 struct device *dev = &pdev->dev;
194 struct ahci_platform_data *pdata = dev->platform_data; 194 struct ahci_platform_data *pdata = dev_get_platdata(dev);
195 struct ata_host *host = dev_get_drvdata(dev); 195 struct ata_host *host = dev_get_drvdata(dev);
196 196
197 ata_host_detach(host); 197 ata_host_detach(host);
@@ -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 c021186736e..a9b28203800 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>
@@ -2882,7 +2883,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2882 sata_scr_read(link, SCR_STATUS, &sstatus)) 2883 sata_scr_read(link, SCR_STATUS, &sstatus))
2883 rc = -ERESTART; 2884 rc = -ERESTART;
2884 2885
2885 if (rc == -ERESTART || try >= max_tries) { 2886 if (try >= max_tries) {
2886 /* 2887 /*
2887 * Thaw host port even if reset failed, so that the port 2888 * Thaw host port even if reset failed, so that the port
2888 * can be retried on the next phy event. This risks 2889 * can be retried on the next phy event. This risks
@@ -2908,6 +2909,16 @@ int ata_eh_reset(struct ata_link *link, int classify,
2908 ata_eh_acquire(ap); 2909 ata_eh_acquire(ap);
2909 } 2910 }
2910 2911
2912 /*
2913 * While disks spinup behind PMP, some controllers fail sending SRST.
2914 * They need to be reset - as well as the PMP - before retrying.
2915 */
2916 if (rc == -ERESTART) {
2917 if (ata_is_host_link(link))
2918 ata_eh_thaw_port(ap);
2919 goto out;
2920 }
2921
2911 if (try == max_tries - 1) { 2922 if (try == max_tries - 1) {
2912 sata_down_spd_limit(link, 0); 2923 sata_down_spd_limit(link, 0);
2913 if (slave) 2924 if (slave)
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index 3eb2b816eb2..21b80c555c6 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"
@@ -388,12 +389,9 @@ static void sata_pmp_quirks(struct ata_port *ap)
388 /* link reports offline after LPM */ 389 /* link reports offline after LPM */
389 link->flags |= ATA_LFLAG_NO_LPM; 390 link->flags |= ATA_LFLAG_NO_LPM;
390 391
391 /* Class code report is unreliable and SRST 392 /* Class code report is unreliable. */
392 * times out under certain configurations.
393 */
394 if (link->pmp < 5) 393 if (link->pmp < 5)
395 link->flags |= ATA_LFLAG_NO_SRST | 394 link->flags |= ATA_LFLAG_ASSUME_ATA;
396 ATA_LFLAG_ASSUME_ATA;
397 395
398 /* port 5 is for SEMB device and it doesn't like SRST */ 396 /* port 5 is for SEMB device and it doesn't like SRST */
399 if (link->pmp == 5) 397 if (link->pmp == 5)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 19ba77032ac..2a5412e7e9c 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>
@@ -1216,6 +1217,10 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev)
1216 1217
1217/** 1218/**
1218 * __ata_change_queue_depth - helper for ata_scsi_change_queue_depth 1219 * __ata_change_queue_depth - helper for ata_scsi_change_queue_depth
1220 * @ap: ATA port to which the device change the queue depth
1221 * @sdev: SCSI device to configure queue depth for
1222 * @queue_depth: new queue depth
1223 * @reason: calling context
1219 * 1224 *
1220 * libsas and libata have different approaches for associating a sdev to 1225 * libsas and libata have different approaches for associating a sdev to
1221 * its ata_port. 1226 * its ata_port.
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 239bfa67d03..4cadfa28f94 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
@@ -2532,10 +2533,12 @@ static int ata_pci_init_one(struct pci_dev *pdev,
2532 if (rc) 2533 if (rc)
2533 goto out; 2534 goto out;
2534 2535
2536#ifdef CONFIG_ATA_BMDMA
2535 if (bmdma) 2537 if (bmdma)
2536 /* prepare and activate BMDMA host */ 2538 /* prepare and activate BMDMA host */
2537 rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host); 2539 rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
2538 else 2540 else
2541#endif
2539 /* prepare and activate SFF host */ 2542 /* prepare and activate SFF host */
2540 rc = ata_pci_sff_prepare_host(pdev, ppi, &host); 2543 rc = ata_pci_sff_prepare_host(pdev, ppi, &host);
2541 if (rc) 2544 if (rc)
@@ -2543,10 +2546,12 @@ static int ata_pci_init_one(struct pci_dev *pdev,
2543 host->private_data = host_priv; 2546 host->private_data = host_priv;
2544 host->flags |= hflags; 2547 host->flags |= hflags;
2545 2548
2549#ifdef CONFIG_ATA_BMDMA
2546 if (bmdma) { 2550 if (bmdma) {
2547 pci_set_master(pdev); 2551 pci_set_master(pdev);
2548 rc = ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht); 2552 rc = ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
2549 } else 2553 } else
2554#endif
2550 rc = ata_pci_sff_activate_host(host, ata_sff_interrupt, sht); 2555 rc = ata_pci_sff_activate_host(host, ata_sff_interrupt, sht);
2551out: 2556out:
2552 if (rc == 0) 2557 if (rc == 0)
diff --git a/drivers/ata/pata_of_platform.c b/drivers/ata/pata_of_platform.c
index a72ab0dde4e..2a472c5bb7d 100644
--- a/drivers/ata/pata_of_platform.c
+++ b/drivers/ata/pata_of_platform.c
@@ -52,7 +52,7 @@ static int __devinit pata_of_platform_probe(struct platform_device *ofdev)
52 } 52 }
53 53
54 ret = of_irq_to_resource(dn, 0, &irq_res); 54 ret = of_irq_to_resource(dn, 0, &irq_res);
55 if (ret == NO_IRQ) 55 if (!ret)
56 irq_res.start = irq_res.end = 0; 56 irq_res.start = irq_res.end = 0;
57 else 57 else
58 irq_res.flags = 0; 58 irq_res.flags = 0;
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 447d9c05fb5..95ec435f0eb 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -104,7 +104,7 @@ static const struct ata_port_info sis_port_info = {
104}; 104};
105 105
106MODULE_AUTHOR("Uwe Koziolek"); 106MODULE_AUTHOR("Uwe Koziolek");
107MODULE_DESCRIPTION("low-level driver for Silicon Integratad Systems SATA controller"); 107MODULE_DESCRIPTION("low-level driver for Silicon Integrated Systems SATA controller");
108MODULE_LICENSE("GPL"); 108MODULE_LICENSE("GPL");
109MODULE_DEVICE_TABLE(pci, sis_pci_tbl); 109MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
110MODULE_VERSION(DRV_VERSION); 110MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/base/base.h b/drivers/base/base.h
index a34dca0ad04..21c1b96c34c 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/core.c b/drivers/base/core.c
index 82c865452c7..d8b3d89db04 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -22,6 +22,7 @@
22#include <linux/kallsyms.h> 22#include <linux/kallsyms.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/async.h> 24#include <linux/async.h>
25#include <linux/pm_runtime.h>
25 26
26#include "base.h" 27#include "base.h"
27#include "power/power.h" 28#include "power/power.h"
@@ -1742,6 +1743,8 @@ void device_shutdown(void)
1742 */ 1743 */
1743 list_del_init(&dev->kobj.entry); 1744 list_del_init(&dev->kobj.entry);
1744 spin_unlock(&devices_kset->list_lock); 1745 spin_unlock(&devices_kset->list_lock);
1746 /* Disable all device's runtime power management */
1747 pm_runtime_disable(dev);
1745 1748
1746 if (dev->bus && dev->bus->shutdown) { 1749 if (dev->bus && dev->bus->shutdown) {
1747 dev_dbg(dev, "shutdown\n"); 1750 dev_dbg(dev, "shutdown\n");
diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index f369e279598..bb0025c510b 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 763d59c1eb6..6f3676f1559 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 6428cba3aad..4f8b741f461 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/node.c b/drivers/base/node.c
index 793f796c4da..5693ecee9a4 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -127,12 +127,13 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
127 nid, K(node_page_state(nid, NR_WRITEBACK)), 127 nid, K(node_page_state(nid, NR_WRITEBACK)),
128 nid, K(node_page_state(nid, NR_FILE_PAGES)), 128 nid, K(node_page_state(nid, NR_FILE_PAGES)),
129 nid, K(node_page_state(nid, NR_FILE_MAPPED)), 129 nid, K(node_page_state(nid, NR_FILE_MAPPED)),
130 nid, K(node_page_state(nid, NR_ANON_PAGES)
131#ifdef CONFIG_TRANSPARENT_HUGEPAGE 130#ifdef CONFIG_TRANSPARENT_HUGEPAGE
131 nid, K(node_page_state(nid, NR_ANON_PAGES)
132 + node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * 132 + node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) *
133 HPAGE_PMD_NR 133 HPAGE_PMD_NR),
134#else
135 nid, K(node_page_state(nid, NR_ANON_PAGES)),
134#endif 136#endif
135 ),
136 nid, K(node_page_state(nid, NR_SHMEM)), 137 nid, K(node_page_state(nid, NR_SHMEM)),
137 nid, node_page_state(nid, NR_KERNEL_STACK) * 138 nid, node_page_state(nid, NR_KERNEL_STACK) *
138 THREAD_SIZE / 1024, 139 THREAD_SIZE / 1024,
@@ -143,13 +144,14 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
143 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) + 144 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
144 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), 145 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
145 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), 146 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
146 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))
147#ifdef CONFIG_TRANSPARENT_HUGEPAGE 147#ifdef CONFIG_TRANSPARENT_HUGEPAGE
148 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))
148 , nid, 149 , nid,
149 K(node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * 150 K(node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) *
150 HPAGE_PMD_NR) 151 HPAGE_PMD_NR));
152#else
153 nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
151#endif 154#endif
152 );
153 n += hugetlb_report_node_meminfo(nid, buf + n); 155 n += hugetlb_report_node_meminfo(nid, buf + n);
154 return n; 156 return n;
155} 157}
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index 5f0f85d5c57..428e55e012d 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -229,7 +229,8 @@ int pm_clk_suspend(struct device *dev)
229 229
230 list_for_each_entry_reverse(ce, &psd->clock_list, node) { 230 list_for_each_entry_reverse(ce, &psd->clock_list, node) {
231 if (ce->status < PCE_STATUS_ERROR) { 231 if (ce->status < PCE_STATUS_ERROR) {
232 clk_disable(ce->clk); 232 if (ce->status == PCE_STATUS_ENABLED)
233 clk_disable(ce->clk);
233 ce->status = PCE_STATUS_ACQUIRED; 234 ce->status = PCE_STATUS_ACQUIRED;
234 } 235 }
235 } 236 }
diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 29820c39618..4af7c1cbf90 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 9508df71274..265a0ee3b49 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 59f8ab23548..c3d2dfcf438 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>
@@ -919,7 +920,8 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
919 End: 920 End:
920 if (!error) { 921 if (!error) {
921 dev->power.is_suspended = true; 922 dev->power.is_suspended = true;
922 if (dev->power.wakeup_path && dev->parent) 923 if (dev->power.wakeup_path
924 && dev->parent && !dev->parent->power.ignore_children)
923 dev->parent->power.wakeup_path = true; 925 dev->parent->power.wakeup_path = true;
924 } 926 }
925 927
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 434a6c01167..95706fa24c7 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -669,7 +669,7 @@ struct srcu_notifier_head *opp_get_notifier(struct device *dev)
669 struct device_opp *dev_opp = find_device_opp(dev); 669 struct device_opp *dev_opp = find_device_opp(dev);
670 670
671 if (IS_ERR(dev_opp)) 671 if (IS_ERR(dev_opp))
672 return ERR_PTR(PTR_ERR(dev_opp)); /* matching type */ 672 return ERR_CAST(dev_opp); /* matching type */
673 673
674 return &dev_opp->head; 674 return &dev_opp->head;
675} 675}
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
index 91e06141738..86de6c50fc4 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);
@@ -211,11 +212,9 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
211 if (!dev || !req) /*guard against callers passing in null */ 212 if (!dev || !req) /*guard against callers passing in null */
212 return -EINVAL; 213 return -EINVAL;
213 214
214 if (dev_pm_qos_request_active(req)) { 215 if (WARN(dev_pm_qos_request_active(req),
215 WARN(1, KERN_ERR "dev_pm_qos_add_request() called for already " 216 "%s() called for already added request\n", __func__))
216 "added request\n");
217 return -EINVAL; 217 return -EINVAL;
218 }
219 218
220 req->dev = dev; 219 req->dev = dev;
221 220
@@ -270,11 +269,9 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
270 if (!req) /*guard against callers passing in null */ 269 if (!req) /*guard against callers passing in null */
271 return -EINVAL; 270 return -EINVAL;
272 271
273 if (!dev_pm_qos_request_active(req)) { 272 if (WARN(!dev_pm_qos_request_active(req),
274 WARN(1, KERN_ERR "dev_pm_qos_update_request() called for " 273 "%s() called for unknown object\n", __func__))
275 "unknown object\n");
276 return -EINVAL; 274 return -EINVAL;
277 }
278 275
279 mutex_lock(&dev_pm_qos_mtx); 276 mutex_lock(&dev_pm_qos_mtx);
280 277
@@ -311,11 +308,9 @@ int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
311 if (!req) /*guard against callers passing in null */ 308 if (!req) /*guard against callers passing in null */
312 return -EINVAL; 309 return -EINVAL;
313 310
314 if (!dev_pm_qos_request_active(req)) { 311 if (WARN(!dev_pm_qos_request_active(req),
315 WARN(1, KERN_ERR "dev_pm_qos_remove_request() called for " 312 "%s() called for unknown object\n", __func__))
316 "unknown object\n");
317 return -EINVAL; 313 return -EINVAL;
318 }
319 314
320 mutex_lock(&dev_pm_qos_mtx); 315 mutex_lock(&dev_pm_qos_mtx);
321 316
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 6bb3aafa85e..8c78443bca8 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 17b7934f31c..adf41be0ea6 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 af10abecb99..d94a1f5121c 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 14ee07e9cc4..caf995fb774 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 afcfef83826..666f6f5011d 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 84997efdb23..f6c453c3816 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 189a97b51be..893f6e0c759 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 47cce9d6963..e9f1b3fd252 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 2968d809d49..800163c8c2e 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 81f3d0a4b85..4fde6254f04 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 ac4bc626c14..1b51d8b7ac8 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 8c09c3e547c..70c84b95109 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 528f6318ded..321de7b6c44 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 146296ca496..5f8e39c43ae 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 dba1c32e1dd..d22119d49e5 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 8f4ef656a1a..8004ac30a7a 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -24,6 +24,7 @@
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/pci-aspm.h>
27#include <linux/kernel.h> 28#include <linux/kernel.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <linux/delay.h> 30#include <linux/delay.h>
@@ -68,6 +69,10 @@ static int cciss_tape_cmds = 6;
68module_param(cciss_tape_cmds, int, 0644); 69module_param(cciss_tape_cmds, int, 0644);
69MODULE_PARM_DESC(cciss_tape_cmds, 70MODULE_PARM_DESC(cciss_tape_cmds,
70 "number of commands to allocate for tape devices (default: 6)"); 71 "number of commands to allocate for tape devices (default: 6)");
72static int cciss_simple_mode;
73module_param(cciss_simple_mode, int, S_IRUGO|S_IWUSR);
74MODULE_PARM_DESC(cciss_simple_mode,
75 "Use 'simple mode' rather than 'performant mode'");
71 76
72static DEFINE_MUTEX(cciss_mutex); 77static DEFINE_MUTEX(cciss_mutex);
73static struct proc_dir_entry *proc_cciss; 78static struct proc_dir_entry *proc_cciss;
@@ -176,6 +181,7 @@ static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol,
176 unsigned int block_size, InquiryData_struct *inq_buff, 181 unsigned int block_size, InquiryData_struct *inq_buff,
177 drive_info_struct *drv); 182 drive_info_struct *drv);
178static void __devinit cciss_interrupt_mode(ctlr_info_t *); 183static void __devinit cciss_interrupt_mode(ctlr_info_t *);
184static int __devinit cciss_enter_simple_mode(struct ctlr_info *h);
179static void start_io(ctlr_info_t *h); 185static void start_io(ctlr_info_t *h);
180static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size, 186static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
181 __u8 page_code, unsigned char scsi3addr[], 187 __u8 page_code, unsigned char scsi3addr[],
@@ -388,7 +394,7 @@ static void cciss_seq_show_header(struct seq_file *seq)
388 h->product_name, 394 h->product_name,
389 (unsigned long)h->board_id, 395 (unsigned long)h->board_id,
390 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], 396 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
391 h->firm_ver[3], (unsigned int)h->intr[PERF_MODE_INT], 397 h->firm_ver[3], (unsigned int)h->intr[h->intr_mode],
392 h->num_luns, 398 h->num_luns,
393 h->Qdepth, h->commands_outstanding, 399 h->Qdepth, h->commands_outstanding,
394 h->maxQsinceinit, h->max_outstanding, h->maxSG); 400 h->maxQsinceinit, h->max_outstanding, h->maxSG);
@@ -636,6 +642,18 @@ static ssize_t host_store_rescan(struct device *dev,
636} 642}
637static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); 643static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
638 644
645static ssize_t host_show_transport_mode(struct device *dev,
646 struct device_attribute *attr,
647 char *buf)
648{
649 struct ctlr_info *h = to_hba(dev);
650
651 return snprintf(buf, 20, "%s\n",
652 h->transMethod & CFGTBL_Trans_Performant ?
653 "performant" : "simple");
654}
655static DEVICE_ATTR(transport_mode, S_IRUGO, host_show_transport_mode, NULL);
656
639static ssize_t dev_show_unique_id(struct device *dev, 657static ssize_t dev_show_unique_id(struct device *dev,
640 struct device_attribute *attr, 658 struct device_attribute *attr,
641 char *buf) 659 char *buf)
@@ -808,6 +826,7 @@ static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL);
808static struct attribute *cciss_host_attrs[] = { 826static struct attribute *cciss_host_attrs[] = {
809 &dev_attr_rescan.attr, 827 &dev_attr_rescan.attr,
810 &dev_attr_resettable.attr, 828 &dev_attr_resettable.attr,
829 &dev_attr_transport_mode.attr,
811 NULL 830 NULL
812}; 831};
813 832
@@ -3984,6 +4003,9 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
3984{ 4003{
3985 __u32 trans_support; 4004 __u32 trans_support;
3986 4005
4006 if (cciss_simple_mode)
4007 return;
4008
3987 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n"); 4009 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n");
3988 /* Attempt to put controller into performant mode if supported */ 4010 /* Attempt to put controller into performant mode if supported */
3989 /* Does board support performant mode? */ 4011 /* Does board support performant mode? */
@@ -4081,7 +4103,7 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *h)
4081default_int_mode: 4103default_int_mode:
4082#endif /* CONFIG_PCI_MSI */ 4104#endif /* CONFIG_PCI_MSI */
4083 /* if we get here we're going to use the default interrupt mode */ 4105 /* if we get here we're going to use the default interrupt mode */
4084 h->intr[PERF_MODE_INT] = h->pdev->irq; 4106 h->intr[h->intr_mode] = h->pdev->irq;
4085 return; 4107 return;
4086} 4108}
4087 4109
@@ -4298,6 +4320,10 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
4298 dev_warn(&h->pdev->dev, "controller appears to be disabled\n"); 4320 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
4299 return -ENODEV; 4321 return -ENODEV;
4300 } 4322 }
4323
4324 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
4325 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
4326
4301 err = pci_enable_device(h->pdev); 4327 err = pci_enable_device(h->pdev);
4302 if (err) { 4328 if (err) {
4303 dev_warn(&h->pdev->dev, "Unable to Enable PCI device\n"); 4329 dev_warn(&h->pdev->dev, "Unable to Enable PCI device\n");
@@ -4341,6 +4367,9 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
4341 } 4367 }
4342 cciss_enable_scsi_prefetch(h); 4368 cciss_enable_scsi_prefetch(h);
4343 cciss_p600_dma_prefetch_quirk(h); 4369 cciss_p600_dma_prefetch_quirk(h);
4370 err = cciss_enter_simple_mode(h);
4371 if (err)
4372 goto err_out_free_res;
4344 cciss_put_controller_into_performant_mode(h); 4373 cciss_put_controller_into_performant_mode(h);
4345 return 0; 4374 return 0;
4346 4375
@@ -4533,6 +4562,13 @@ static int cciss_controller_hard_reset(struct pci_dev *pdev,
4533 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 4562 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4534 pmcsr |= PCI_D0; 4563 pmcsr |= PCI_D0;
4535 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); 4564 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4565
4566 /*
4567 * The P600 requires a small delay when changing states.
4568 * Otherwise we may think the board did not reset and we bail.
4569 * This for kdump only and is particular to the P600.
4570 */
4571 msleep(500);
4536 } 4572 }
4537 return 0; 4573 return 0;
4538} 4574}
@@ -4843,20 +4879,20 @@ static int cciss_request_irq(ctlr_info_t *h,
4843 irqreturn_t (*intxhandler)(int, void *)) 4879 irqreturn_t (*intxhandler)(int, void *))
4844{ 4880{
4845 if (h->msix_vector || h->msi_vector) { 4881 if (h->msix_vector || h->msi_vector) {
4846 if (!request_irq(h->intr[PERF_MODE_INT], msixhandler, 4882 if (!request_irq(h->intr[h->intr_mode], msixhandler,
4847 IRQF_DISABLED, h->devname, h)) 4883 IRQF_DISABLED, h->devname, h))
4848 return 0; 4884 return 0;
4849 dev_err(&h->pdev->dev, "Unable to get msi irq %d" 4885 dev_err(&h->pdev->dev, "Unable to get msi irq %d"
4850 " for %s\n", h->intr[PERF_MODE_INT], 4886 " for %s\n", h->intr[h->intr_mode],
4851 h->devname); 4887 h->devname);
4852 return -1; 4888 return -1;
4853 } 4889 }
4854 4890
4855 if (!request_irq(h->intr[PERF_MODE_INT], intxhandler, 4891 if (!request_irq(h->intr[h->intr_mode], intxhandler,
4856 IRQF_DISABLED, h->devname, h)) 4892 IRQF_DISABLED, h->devname, h))
4857 return 0; 4893 return 0;
4858 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n", 4894 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4859 h->intr[PERF_MODE_INT], h->devname); 4895 h->intr[h->intr_mode], h->devname);
4860 return -1; 4896 return -1;
4861} 4897}
4862 4898
@@ -4887,7 +4923,7 @@ static void cciss_undo_allocations_after_kdump_soft_reset(ctlr_info_t *h)
4887{ 4923{
4888 int ctlr = h->ctlr; 4924 int ctlr = h->ctlr;
4889 4925
4890 free_irq(h->intr[PERF_MODE_INT], h); 4926 free_irq(h->intr[h->intr_mode], h);
4891#ifdef CONFIG_PCI_MSI 4927#ifdef CONFIG_PCI_MSI
4892 if (h->msix_vector) 4928 if (h->msix_vector)
4893 pci_disable_msix(h->pdev); 4929 pci_disable_msix(h->pdev);
@@ -4953,6 +4989,7 @@ reinit_after_soft_reset:
4953 h = hba[i]; 4989 h = hba[i];
4954 h->pdev = pdev; 4990 h->pdev = pdev;
4955 h->busy_initializing = 1; 4991 h->busy_initializing = 1;
4992 h->intr_mode = cciss_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
4956 INIT_LIST_HEAD(&h->cmpQ); 4993 INIT_LIST_HEAD(&h->cmpQ);
4957 INIT_LIST_HEAD(&h->reqQ); 4994 INIT_LIST_HEAD(&h->reqQ);
4958 mutex_init(&h->busy_shutting_down); 4995 mutex_init(&h->busy_shutting_down);
@@ -5009,7 +5046,7 @@ reinit_after_soft_reset:
5009 5046
5010 dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n", 5047 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), 5048 h->devname, pdev->device, pci_name(pdev),
5012 h->intr[PERF_MODE_INT], dac ? "" : " not"); 5049 h->intr[h->intr_mode], dac ? "" : " not");
5013 5050
5014 if (cciss_allocate_cmd_pool(h)) 5051 if (cciss_allocate_cmd_pool(h))
5015 goto clean4; 5052 goto clean4;
@@ -5056,7 +5093,7 @@ reinit_after_soft_reset:
5056 spin_lock_irqsave(&h->lock, flags); 5093 spin_lock_irqsave(&h->lock, flags);
5057 h->access.set_intr_mask(h, CCISS_INTR_OFF); 5094 h->access.set_intr_mask(h, CCISS_INTR_OFF);
5058 spin_unlock_irqrestore(&h->lock, flags); 5095 spin_unlock_irqrestore(&h->lock, flags);
5059 free_irq(h->intr[PERF_MODE_INT], h); 5096 free_irq(h->intr[h->intr_mode], h);
5060 rc = cciss_request_irq(h, cciss_msix_discard_completions, 5097 rc = cciss_request_irq(h, cciss_msix_discard_completions,
5061 cciss_intx_discard_completions); 5098 cciss_intx_discard_completions);
5062 if (rc) { 5099 if (rc) {
@@ -5126,6 +5163,7 @@ reinit_after_soft_reset:
5126 h->cciss_max_sectors = 8192; 5163 h->cciss_max_sectors = 8192;
5127 5164
5128 rebuild_lun_table(h, 1, 0); 5165 rebuild_lun_table(h, 1, 0);
5166 cciss_engage_scsi(h);
5129 h->busy_initializing = 0; 5167 h->busy_initializing = 0;
5130 return 1; 5168 return 1;
5131 5169
@@ -5133,7 +5171,7 @@ clean4:
5133 cciss_free_cmd_pool(h); 5171 cciss_free_cmd_pool(h);
5134 cciss_free_scatterlists(h); 5172 cciss_free_scatterlists(h);
5135 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); 5173 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
5136 free_irq(h->intr[PERF_MODE_INT], h); 5174 free_irq(h->intr[h->intr_mode], h);
5137clean2: 5175clean2:
5138 unregister_blkdev(h->major, h->devname); 5176 unregister_blkdev(h->major, h->devname);
5139clean1: 5177clean1:
@@ -5172,9 +5210,31 @@ static void cciss_shutdown(struct pci_dev *pdev)
5172 if (return_code != IO_OK) 5210 if (return_code != IO_OK)
5173 dev_warn(&h->pdev->dev, "Error flushing cache\n"); 5211 dev_warn(&h->pdev->dev, "Error flushing cache\n");
5174 h->access.set_intr_mask(h, CCISS_INTR_OFF); 5212 h->access.set_intr_mask(h, CCISS_INTR_OFF);
5175 free_irq(h->intr[PERF_MODE_INT], h); 5213 free_irq(h->intr[h->intr_mode], h);
5176} 5214}
5177 5215
5216static int __devinit cciss_enter_simple_mode(struct ctlr_info *h)
5217{
5218 u32 trans_support;
5219
5220 trans_support = readl(&(h->cfgtable->TransportSupport));
5221 if (!(trans_support & SIMPLE_MODE))
5222 return -ENOTSUPP;
5223
5224 h->max_commands = readl(&(h->cfgtable->CmdsOutMax));
5225 writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest));
5226 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
5227 cciss_wait_for_mode_change_ack(h);
5228 print_cfg_table(h);
5229 if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
5230 dev_warn(&h->pdev->dev, "unable to get board into simple mode\n");
5231 return -ENODEV;
5232 }
5233 h->transMethod = CFGTBL_Trans_Simple;
5234 return 0;
5235}
5236
5237
5178static void __devexit cciss_remove_one(struct pci_dev *pdev) 5238static void __devexit cciss_remove_one(struct pci_dev *pdev)
5179{ 5239{
5180 ctlr_info_t *h; 5240 ctlr_info_t *h;
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index c049548e68b..7fda30e4a24 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/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 951a4e33b92..e820b68d2f6 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -1720,5 +1720,6 @@ static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
1720/* If no tape support, then these become defined out of existence */ 1720/* If no tape support, then these become defined out of existence */
1721 1721
1722#define cciss_scsi_setup(cntl_num) 1722#define cciss_scsi_setup(cntl_num)
1723#define cciss_engage_scsi(h)
1723 1724
1724#endif /* CONFIG_CISS_SCSI_TAPE */ 1725#endif /* CONFIG_CISS_SCSI_TAPE */
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index b2fceb53e80..9125bbeacd4 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 1706d60b8c9..9cf20355cee 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 3424d675b76..4a0f314086e 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 4720c7ade0a..68b205a9338 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);
@@ -159,17 +161,19 @@ static struct loop_func_table *xfer_funcs[MAX_LO_CRYPT] = {
159 &xor_funcs 161 &xor_funcs
160}; 162};
161 163
162static loff_t get_loop_size(struct loop_device *lo, struct file *file) 164static loff_t get_size(loff_t offset, loff_t sizelimit, struct file *file)
163{ 165{
164 loff_t size, offset, loopsize; 166 loff_t size, loopsize;
165 167
166 /* Compute loopsize in bytes */ 168 /* Compute loopsize in bytes */
167 size = i_size_read(file->f_mapping->host); 169 size = i_size_read(file->f_mapping->host);
168 offset = lo->lo_offset;
169 loopsize = size - offset; 170 loopsize = size - offset;
170 if (lo->lo_sizelimit > 0 && lo->lo_sizelimit < loopsize) 171 /* offset is beyond i_size, wierd but possible */
171 loopsize = lo->lo_sizelimit; 172 if (loopsize < 0)
173 return 0;
172 174
175 if (sizelimit > 0 && sizelimit < loopsize)
176 loopsize = sizelimit;
173 /* 177 /*
174 * Unfortunately, if we want to do I/O on the device, 178 * Unfortunately, if we want to do I/O on the device,
175 * the number of 512-byte sectors has to fit into a sector_t. 179 * the number of 512-byte sectors has to fit into a sector_t.
@@ -177,17 +181,25 @@ static loff_t get_loop_size(struct loop_device *lo, struct file *file)
177 return loopsize >> 9; 181 return loopsize >> 9;
178} 182}
179 183
184static loff_t get_loop_size(struct loop_device *lo, struct file *file)
185{
186 return get_size(lo->lo_offset, lo->lo_sizelimit, file);
187}
188
180static int 189static int
181figure_loop_size(struct loop_device *lo) 190figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit)
182{ 191{
183 loff_t size = get_loop_size(lo, lo->lo_backing_file); 192 loff_t size = get_size(offset, sizelimit, lo->lo_backing_file);
184 sector_t x = (sector_t)size; 193 sector_t x = (sector_t)size;
185 194
186 if (unlikely((loff_t)x != size)) 195 if (unlikely((loff_t)x != size))
187 return -EFBIG; 196 return -EFBIG;
188 197 if (lo->lo_offset != offset)
198 lo->lo_offset = offset;
199 if (lo->lo_sizelimit != sizelimit)
200 lo->lo_sizelimit = sizelimit;
189 set_capacity(lo->lo_disk, x); 201 set_capacity(lo->lo_disk, x);
190 return 0; 202 return 0;
191} 203}
192 204
193static inline int 205static inline int
@@ -203,74 +215,6 @@ lo_do_transfer(struct loop_device *lo, int cmd,
203} 215}
204 216
205/** 217/**
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 218 * __do_lo_send_write - helper for writing data to a loop device
275 * 219 *
276 * This helper just factors out common code between do_lo_send_direct_write() 220 * This helper just factors out common code between do_lo_send_direct_write()
@@ -297,10 +241,8 @@ static int __do_lo_send_write(struct file *file,
297/** 241/**
298 * do_lo_send_direct_write - helper for writing data to a loop device 242 * do_lo_send_direct_write - helper for writing data to a loop device
299 * 243 *
300 * This is the fast, non-transforming version for backing filesystems which do 244 * This is the fast, non-transforming version that does not need double
301 * not implement the address space operations write_begin and write_end. 245 * buffering.
302 * It uses the write file operation which should be present on all writeable
303 * filesystems.
304 */ 246 */
305static int do_lo_send_direct_write(struct loop_device *lo, 247static int do_lo_send_direct_write(struct loop_device *lo,
306 struct bio_vec *bvec, loff_t pos, struct page *page) 248 struct bio_vec *bvec, loff_t pos, struct page *page)
@@ -316,15 +258,9 @@ static int do_lo_send_direct_write(struct loop_device *lo,
316/** 258/**
317 * do_lo_send_write - helper for writing data to a loop device 259 * do_lo_send_write - helper for writing data to a loop device
318 * 260 *
319 * This is the slow, transforming version for filesystems which do not 261 * This is the slow, transforming version that needs to double buffer the
320 * implement the address space operations write_begin and write_end. It 262 * 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 263 * 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 */ 264 */
329static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec, 265static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec,
330 loff_t pos, struct page *page) 266 loff_t pos, struct page *page)
@@ -350,17 +286,16 @@ static int lo_send(struct loop_device *lo, struct bio *bio, loff_t pos)
350 struct page *page = NULL; 286 struct page *page = NULL;
351 int i, ret = 0; 287 int i, ret = 0;
352 288
353 do_lo_send = do_lo_send_aops; 289 if (lo->transfer != transfer_none) {
354 if (!(lo->lo_flags & LO_FLAGS_USE_AOPS)) { 290 page = alloc_page(GFP_NOIO | __GFP_HIGHMEM);
291 if (unlikely(!page))
292 goto fail;
293 kmap(page);
294 do_lo_send = do_lo_send_write;
295 } else {
355 do_lo_send = do_lo_send_direct_write; 296 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 } 297 }
298
364 bio_for_each_segment(bvec, bio, i) { 299 bio_for_each_segment(bvec, bio, i) {
365 ret = do_lo_send(lo, bvec, pos, page); 300 ret = do_lo_send(lo, bvec, pos, page);
366 if (ret < 0) 301 if (ret < 0)
@@ -447,7 +382,8 @@ do_lo_receive(struct loop_device *lo,
447 382
448 if (retval < 0) 383 if (retval < 0)
449 return retval; 384 return retval;
450 385 if (retval != bvec->bv_len)
386 return -EIO;
451 return 0; 387 return 0;
452} 388}
453 389
@@ -484,6 +420,29 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
484 } 420 }
485 } 421 }
486 422
423 /*
424 * We use punch hole to reclaim the free space used by the
425 * image a.k.a. discard. However we do support discard if
426 * encryption is enabled, because it may give an attacker
427 * useful information.
428 */
429 if (bio->bi_rw & REQ_DISCARD) {
430 struct file *file = lo->lo_backing_file;
431 int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
432
433 if ((!file->f_op->fallocate) ||
434 lo->lo_encrypt_key_size) {
435 ret = -EOPNOTSUPP;
436 goto out;
437 }
438 ret = file->f_op->fallocate(file, mode, pos,
439 bio->bi_size);
440 if (unlikely(ret && ret != -EINVAL &&
441 ret != -EOPNOTSUPP))
442 ret = -EIO;
443 goto out;
444 }
445
487 ret = lo_send(lo, bio, pos); 446 ret = lo_send(lo, bio, pos);
488 447
489 if ((bio->bi_rw & REQ_FUA) && !ret) { 448 if ((bio->bi_rw & REQ_FUA) && !ret) {
@@ -514,7 +473,7 @@ static struct bio *loop_get_bio(struct loop_device *lo)
514 return bio_list_pop(&lo->lo_bio_list); 473 return bio_list_pop(&lo->lo_bio_list);
515} 474}
516 475
517static int loop_make_request(struct request_queue *q, struct bio *old_bio) 476static void loop_make_request(struct request_queue *q, struct bio *old_bio)
518{ 477{
519 struct loop_device *lo = q->queuedata; 478 struct loop_device *lo = q->queuedata;
520 int rw = bio_rw(old_bio); 479 int rw = bio_rw(old_bio);
@@ -532,12 +491,11 @@ static int loop_make_request(struct request_queue *q, struct bio *old_bio)
532 loop_add_bio(lo, old_bio); 491 loop_add_bio(lo, old_bio);
533 wake_up(&lo->lo_event); 492 wake_up(&lo->lo_event);
534 spin_unlock_irq(&lo->lo_lock); 493 spin_unlock_irq(&lo->lo_lock);
535 return 0; 494 return;
536 495
537out: 496out:
538 spin_unlock_irq(&lo->lo_lock); 497 spin_unlock_irq(&lo->lo_lock);
539 bio_io_error(old_bio); 498 bio_io_error(old_bio);
540 return 0;
541} 499}
542 500
543struct switch_request { 501struct switch_request {
@@ -700,7 +658,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
700 goto out_putf; 658 goto out_putf;
701 659
702 fput(old_file); 660 fput(old_file);
703 if (max_part > 0) 661 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
704 ioctl_by_bdev(bdev, BLKRRPART, 0); 662 ioctl_by_bdev(bdev, BLKRRPART, 0);
705 return 0; 663 return 0;
706 664
@@ -777,16 +735,25 @@ static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf)
777 return sprintf(buf, "%s\n", autoclear ? "1" : "0"); 735 return sprintf(buf, "%s\n", autoclear ? "1" : "0");
778} 736}
779 737
738static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf)
739{
740 int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN);
741
742 return sprintf(buf, "%s\n", partscan ? "1" : "0");
743}
744
780LOOP_ATTR_RO(backing_file); 745LOOP_ATTR_RO(backing_file);
781LOOP_ATTR_RO(offset); 746LOOP_ATTR_RO(offset);
782LOOP_ATTR_RO(sizelimit); 747LOOP_ATTR_RO(sizelimit);
783LOOP_ATTR_RO(autoclear); 748LOOP_ATTR_RO(autoclear);
749LOOP_ATTR_RO(partscan);
784 750
785static struct attribute *loop_attrs[] = { 751static struct attribute *loop_attrs[] = {
786 &loop_attr_backing_file.attr, 752 &loop_attr_backing_file.attr,
787 &loop_attr_offset.attr, 753 &loop_attr_offset.attr,
788 &loop_attr_sizelimit.attr, 754 &loop_attr_sizelimit.attr,
789 &loop_attr_autoclear.attr, 755 &loop_attr_autoclear.attr,
756 &loop_attr_partscan.attr,
790 NULL, 757 NULL,
791}; 758};
792 759
@@ -807,6 +774,35 @@ static void loop_sysfs_exit(struct loop_device *lo)
807 &loop_attribute_group); 774 &loop_attribute_group);
808} 775}
809 776
777static void loop_config_discard(struct loop_device *lo)
778{
779 struct file *file = lo->lo_backing_file;
780 struct inode *inode = file->f_mapping->host;
781 struct request_queue *q = lo->lo_queue;
782
783 /*
784 * We use punch hole to reclaim the free space used by the
785 * image a.k.a. discard. However we do support discard if
786 * encryption is enabled, because it may give an attacker
787 * useful information.
788 */
789 if ((!file->f_op->fallocate) ||
790 lo->lo_encrypt_key_size) {
791 q->limits.discard_granularity = 0;
792 q->limits.discard_alignment = 0;
793 q->limits.max_discard_sectors = 0;
794 q->limits.discard_zeroes_data = 0;
795 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
796 return;
797 }
798
799 q->limits.discard_granularity = inode->i_sb->s_blocksize;
800 q->limits.discard_alignment = inode->i_sb->s_blocksize;
801 q->limits.max_discard_sectors = UINT_MAX >> 9;
802 q->limits.discard_zeroes_data = 1;
803 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
804}
805
810static int loop_set_fd(struct loop_device *lo, fmode_t mode, 806static int loop_set_fd(struct loop_device *lo, fmode_t mode,
811 struct block_device *bdev, unsigned int arg) 807 struct block_device *bdev, unsigned int arg)
812{ 808{
@@ -849,35 +845,23 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
849 mapping = file->f_mapping; 845 mapping = file->f_mapping;
850 inode = mapping->host; 846 inode = mapping->host;
851 847
852 if (!(file->f_mode & FMODE_WRITE))
853 lo_flags |= LO_FLAGS_READ_ONLY;
854
855 error = -EINVAL; 848 error = -EINVAL;
856 if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) { 849 if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
857 const struct address_space_operations *aops = mapping->a_ops; 850 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 851
864 lo_blocksize = S_ISBLK(inode->i_mode) ? 852 if (!(file->f_mode & FMODE_WRITE) || !(mode & FMODE_WRITE) ||
865 inode->i_bdev->bd_block_size : PAGE_SIZE; 853 !file->f_op->write)
854 lo_flags |= LO_FLAGS_READ_ONLY;
866 855
867 error = 0; 856 lo_blocksize = S_ISBLK(inode->i_mode) ?
868 } else { 857 inode->i_bdev->bd_block_size : PAGE_SIZE;
869 goto out_putf;
870 }
871 858
859 error = -EFBIG;
872 size = get_loop_size(lo, file); 860 size = get_loop_size(lo, file);
873 861 if ((loff_t)(sector_t)size != size)
874 if ((loff_t)(sector_t)size != size) {
875 error = -EFBIG;
876 goto out_putf; 862 goto out_putf;
877 }
878 863
879 if (!(mode & FMODE_WRITE)) 864 error = 0;
880 lo_flags |= LO_FLAGS_READ_ONLY;
881 865
882 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0); 866 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0);
883 867
@@ -919,7 +903,9 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
919 } 903 }
920 lo->lo_state = Lo_bound; 904 lo->lo_state = Lo_bound;
921 wake_up_process(lo->lo_thread); 905 wake_up_process(lo->lo_thread);
922 if (max_part > 0) 906 if (part_shift)
907 lo->lo_flags |= LO_FLAGS_PARTSCAN;
908 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
923 ioctl_by_bdev(bdev, BLKRRPART, 0); 909 ioctl_by_bdev(bdev, BLKRRPART, 0);
924 return 0; 910 return 0;
925 911
@@ -980,10 +966,11 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
980 return err; 966 return err;
981} 967}
982 968
983static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) 969static int loop_clr_fd(struct loop_device *lo)
984{ 970{
985 struct file *filp = lo->lo_backing_file; 971 struct file *filp = lo->lo_backing_file;
986 gfp_t gfp = lo->old_gfp_mask; 972 gfp_t gfp = lo->old_gfp_mask;
973 struct block_device *bdev = lo->lo_device;
987 974
988 if (lo->lo_state != Lo_bound) 975 if (lo->lo_state != Lo_bound)
989 return -ENXIO; 976 return -ENXIO;
@@ -1012,7 +999,6 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
1012 lo->lo_offset = 0; 999 lo->lo_offset = 0;
1013 lo->lo_sizelimit = 0; 1000 lo->lo_sizelimit = 0;
1014 lo->lo_encrypt_key_size = 0; 1001 lo->lo_encrypt_key_size = 0;
1015 lo->lo_flags = 0;
1016 lo->lo_thread = NULL; 1002 lo->lo_thread = NULL;
1017 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); 1003 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1018 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); 1004 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
@@ -1030,8 +1016,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
1030 lo->lo_state = Lo_unbound; 1016 lo->lo_state = Lo_unbound;
1031 /* This is safe: open() is still holding a reference. */ 1017 /* This is safe: open() is still holding a reference. */
1032 module_put(THIS_MODULE); 1018 module_put(THIS_MODULE);
1033 if (max_part > 0 && bdev) 1019 if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev)
1034 ioctl_by_bdev(bdev, BLKRRPART, 0); 1020 ioctl_by_bdev(bdev, BLKRRPART, 0);
1021 lo->lo_flags = 0;
1022 if (!part_shift)
1023 lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;
1035 mutex_unlock(&lo->lo_ctl_mutex); 1024 mutex_unlock(&lo->lo_ctl_mutex);
1036 /* 1025 /*
1037 * Need not hold lo_ctl_mutex to fput backing file. 1026 * Need not hold lo_ctl_mutex to fput backing file.
@@ -1080,11 +1069,10 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
1080 1069
1081 if (lo->lo_offset != info->lo_offset || 1070 if (lo->lo_offset != info->lo_offset ||
1082 lo->lo_sizelimit != info->lo_sizelimit) { 1071 lo->lo_sizelimit != info->lo_sizelimit) {
1083 lo->lo_offset = info->lo_offset; 1072 if (figure_loop_size(lo, info->lo_offset, info->lo_sizelimit))
1084 lo->lo_sizelimit = info->lo_sizelimit;
1085 if (figure_loop_size(lo))
1086 return -EFBIG; 1073 return -EFBIG;
1087 } 1074 }
1075 loop_config_discard(lo);
1088 1076
1089 memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); 1077 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); 1078 memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE);
@@ -1100,6 +1088,13 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
1100 (info->lo_flags & LO_FLAGS_AUTOCLEAR)) 1088 (info->lo_flags & LO_FLAGS_AUTOCLEAR))
1101 lo->lo_flags ^= LO_FLAGS_AUTOCLEAR; 1089 lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
1102 1090
1091 if ((info->lo_flags & LO_FLAGS_PARTSCAN) &&
1092 !(lo->lo_flags & LO_FLAGS_PARTSCAN)) {
1093 lo->lo_flags |= LO_FLAGS_PARTSCAN;
1094 lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN;
1095 ioctl_by_bdev(lo->lo_device, BLKRRPART, 0);
1096 }
1097
1103 lo->lo_encrypt_key_size = info->lo_encrypt_key_size; 1098 lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
1104 lo->lo_init[0] = info->lo_init[0]; 1099 lo->lo_init[0] = info->lo_init[0];
1105 lo->lo_init[1] = info->lo_init[1]; 1100 lo->lo_init[1] = info->lo_init[1];
@@ -1260,7 +1255,7 @@ static int loop_set_capacity(struct loop_device *lo, struct block_device *bdev)
1260 err = -ENXIO; 1255 err = -ENXIO;
1261 if (unlikely(lo->lo_state != Lo_bound)) 1256 if (unlikely(lo->lo_state != Lo_bound))
1262 goto out; 1257 goto out;
1263 err = figure_loop_size(lo); 1258 err = figure_loop_size(lo, lo->lo_offset, lo->lo_sizelimit);
1264 if (unlikely(err)) 1259 if (unlikely(err))
1265 goto out; 1260 goto out;
1266 sec = get_capacity(lo->lo_disk); 1261 sec = get_capacity(lo->lo_disk);
@@ -1293,18 +1288,24 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
1293 break; 1288 break;
1294 case LOOP_CLR_FD: 1289 case LOOP_CLR_FD:
1295 /* loop_clr_fd would have unlocked lo_ctl_mutex on success */ 1290 /* loop_clr_fd would have unlocked lo_ctl_mutex on success */
1296 err = loop_clr_fd(lo, bdev); 1291 err = loop_clr_fd(lo);
1297 if (!err) 1292 if (!err)
1298 goto out_unlocked; 1293 goto out_unlocked;
1299 break; 1294 break;
1300 case LOOP_SET_STATUS: 1295 case LOOP_SET_STATUS:
1301 err = loop_set_status_old(lo, (struct loop_info __user *) arg); 1296 err = -EPERM;
1297 if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN))
1298 err = loop_set_status_old(lo,
1299 (struct loop_info __user *)arg);
1302 break; 1300 break;
1303 case LOOP_GET_STATUS: 1301 case LOOP_GET_STATUS:
1304 err = loop_get_status_old(lo, (struct loop_info __user *) arg); 1302 err = loop_get_status_old(lo, (struct loop_info __user *) arg);
1305 break; 1303 break;
1306 case LOOP_SET_STATUS64: 1304 case LOOP_SET_STATUS64:
1307 err = loop_set_status64(lo, (struct loop_info64 __user *) arg); 1305 err = -EPERM;
1306 if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN))
1307 err = loop_set_status64(lo,
1308 (struct loop_info64 __user *) arg);
1308 break; 1309 break;
1309 case LOOP_GET_STATUS64: 1310 case LOOP_GET_STATUS64:
1310 err = loop_get_status64(lo, (struct loop_info64 __user *) arg); 1311 err = loop_get_status64(lo, (struct loop_info64 __user *) arg);
@@ -1513,7 +1514,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1513 * In autoclear mode, stop the loop thread 1514 * In autoclear mode, stop the loop thread
1514 * and remove configuration after last close. 1515 * and remove configuration after last close.
1515 */ 1516 */
1516 err = loop_clr_fd(lo, NULL); 1517 err = loop_clr_fd(lo);
1517 if (!err) 1518 if (!err)
1518 goto out_unlocked; 1519 goto out_unlocked;
1519 } else { 1520 } else {
@@ -1635,6 +1636,27 @@ static int loop_add(struct loop_device **l, int i)
1635 if (!disk) 1636 if (!disk)
1636 goto out_free_queue; 1637 goto out_free_queue;
1637 1638
1639 /*
1640 * Disable partition scanning by default. The in-kernel partition
1641 * scanning can be requested individually per-device during its
1642 * setup. Userspace can always add and remove partitions from all
1643 * devices. The needed partition minors are allocated from the
1644 * extended minor space, the main loop device numbers will continue
1645 * to match the loop minors, regardless of the number of partitions
1646 * used.
1647 *
1648 * If max_part is given, partition scanning is globally enabled for
1649 * all loop devices. The minors for the main loop devices will be
1650 * multiples of max_part.
1651 *
1652 * Note: Global-for-all-devices, set-only-at-init, read-only module
1653 * parameteters like 'max_loop' and 'max_part' make things needlessly
1654 * complicated, are too static, inflexible and may surprise
1655 * userspace tools. Parameters like this in general should be avoided.
1656 */
1657 if (!part_shift)
1658 disk->flags |= GENHD_FL_NO_PART_SCAN;
1659 disk->flags |= GENHD_FL_EXT_DEVT;
1638 mutex_init(&lo->lo_ctl_mutex); 1660 mutex_init(&lo->lo_ctl_mutex);
1639 lo->lo_number = i; 1661 lo->lo_number = i;
1640 lo->lo_thread = NULL; 1662 lo->lo_thread = NULL;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index f533f3375e2..c3f0ee16594 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/paride/pg.c b/drivers/block/paride/pg.c
index 6b9a2000d56..a79fb4f7ff6 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -630,6 +630,7 @@ static ssize_t pg_read(struct file *filp, char __user *buf, size_t count, loff_t
630 if (dev->status & 0x10) 630 if (dev->status & 0x10)
631 return -ETIME; 631 return -ETIME;
632 632
633 memset(&hdr, 0, sizeof(hdr));
633 hdr.magic = PG_MAGIC; 634 hdr.magic = PG_MAGIC;
634 hdr.dlen = dev->dlen; 635 hdr.dlen = dev->dlen;
635 copy = 0; 636 copy = 0;
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index e133f094ab0..a63b0a2b780 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 8e1ce2e2916..da0abc1838c 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 b3bdb8af89c..f58cdcfb305 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 031ca720d92..aa2712060bf 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 e7a5750a93d..4d0b70adf5f 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -3,6 +3,7 @@
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>
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 1540792b1e5..15ec4db194d 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 c4bd34063ec..dfb1b3a43a5 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 5fd2010f7d2..f759ad4584c 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 9ea8c2576c7..7b2ec590841 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/ath3k.c b/drivers/bluetooth/ath3k.c
index db7cb8111fb..106beb194f3 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -105,7 +105,7 @@ static int ath3k_load_firmware(struct usb_device *udev,
105 105
106 pipe = usb_sndctrlpipe(udev, 0); 106 pipe = usb_sndctrlpipe(udev, 0);
107 107
108 send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC); 108 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
109 if (!send_buf) { 109 if (!send_buf) {
110 BT_ERR("Can't allocate memory chunk for firmware"); 110 BT_ERR("Can't allocate memory chunk for firmware");
111 return -ENOMEM; 111 return -ENOMEM;
@@ -176,7 +176,7 @@ static int ath3k_load_fwfile(struct usb_device *udev,
176 176
177 count = firmware->size; 177 count = firmware->size;
178 178
179 send_buf = kmalloc(BULK_SIZE, GFP_ATOMIC); 179 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
180 if (!send_buf) { 180 if (!send_buf) {
181 BT_ERR("Can't allocate memory chunk for firmware"); 181 BT_ERR("Can't allocate memory chunk for firmware");
182 return -ENOMEM; 182 return -ENOMEM;
diff --git a/drivers/bluetooth/bcm203x.c b/drivers/bluetooth/bcm203x.c
index 8b1b643a519..54952ab800b 100644
--- a/drivers/bluetooth/bcm203x.c
+++ b/drivers/bluetooth/bcm203x.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/module.h> 25#include <linux/module.h>
26 26
27#include <linux/atomic.h>
27#include <linux/kernel.h> 28#include <linux/kernel.h>
28#include <linux/init.h> 29#include <linux/init.h>
29#include <linux/slab.h> 30#include <linux/slab.h>
@@ -65,6 +66,7 @@ struct bcm203x_data {
65 unsigned long state; 66 unsigned long state;
66 67
67 struct work_struct work; 68 struct work_struct work;
69 atomic_t shutdown;
68 70
69 struct urb *urb; 71 struct urb *urb;
70 unsigned char *buffer; 72 unsigned char *buffer;
@@ -97,6 +99,7 @@ static void bcm203x_complete(struct urb *urb)
97 99
98 data->state = BCM203X_SELECT_MEMORY; 100 data->state = BCM203X_SELECT_MEMORY;
99 101
102 /* use workqueue to have a small delay */
100 schedule_work(&data->work); 103 schedule_work(&data->work);
101 break; 104 break;
102 105
@@ -155,7 +158,10 @@ static void bcm203x_work(struct work_struct *work)
155 struct bcm203x_data *data = 158 struct bcm203x_data *data =
156 container_of(work, struct bcm203x_data, work); 159 container_of(work, struct bcm203x_data, work);
157 160
158 if (usb_submit_urb(data->urb, GFP_ATOMIC) < 0) 161 if (atomic_read(&data->shutdown))
162 return;
163
164 if (usb_submit_urb(data->urb, GFP_KERNEL) < 0)
159 BT_ERR("Can't submit URB"); 165 BT_ERR("Can't submit URB");
160} 166}
161 167
@@ -243,6 +249,7 @@ static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id
243 249
244 usb_set_intfdata(intf, data); 250 usb_set_intfdata(intf, data);
245 251
252 /* use workqueue to have a small delay */
246 schedule_work(&data->work); 253 schedule_work(&data->work);
247 254
248 return 0; 255 return 0;
@@ -254,6 +261,9 @@ static void bcm203x_disconnect(struct usb_interface *intf)
254 261
255 BT_DBG("intf %p", intf); 262 BT_DBG("intf %p", intf);
256 263
264 atomic_inc(&data->shutdown);
265 cancel_work_sync(&data->work);
266
257 usb_kill_urb(data->urb); 267 usb_kill_urb(data->urb);
258 268
259 usb_set_intfdata(intf, NULL); 269 usb_set_intfdata(intf, NULL);
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 005919ab043..61b591470a9 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -568,22 +568,23 @@ static int bfusb_load_firmware(struct bfusb_data *data,
568 568
569 BT_INFO("BlueFRITZ! USB loading firmware"); 569 BT_INFO("BlueFRITZ! USB loading firmware");
570 570
571 buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_KERNEL);
572 if (!buf) {
573 BT_ERR("Can't allocate memory chunk for firmware");
574 return -ENOMEM;
575 }
576
571 pipe = usb_sndctrlpipe(data->udev, 0); 577 pipe = usb_sndctrlpipe(data->udev, 0);
572 578
573 if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION, 579 if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
574 0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) { 580 0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {
575 BT_ERR("Can't change to loading configuration"); 581 BT_ERR("Can't change to loading configuration");
582 kfree(buf);
576 return -EBUSY; 583 return -EBUSY;
577 } 584 }
578 585
579 data->udev->toggle[0] = data->udev->toggle[1] = 0; 586 data->udev->toggle[0] = data->udev->toggle[1] = 0;
580 587
581 buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC);
582 if (!buf) {
583 BT_ERR("Can't allocate memory chunk for firmware");
584 return -ENOMEM;
585 }
586
587 pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep); 588 pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
588 589
589 while (count) { 590 while (count) {
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 548d1d9e4dd..a88a78c8616 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 c827d737cce..9ef48167e2c 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/btusb.c b/drivers/bluetooth/btusb.c
index f9b726091ad..fe4ebc375b3 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -100,6 +100,9 @@ static struct usb_device_id btusb_table[] = {
100 /* Canyon CN-BTU1 with HID interfaces */ 100 /* Canyon CN-BTU1 with HID interfaces */
101 { USB_DEVICE(0x0c10, 0x0000) }, 101 { USB_DEVICE(0x0c10, 0x0000) },
102 102
103 /* Broadcom BCM20702A0 */
104 { USB_DEVICE(0x413c, 0x8197) },
105
103 { } /* Terminating entry */ 106 { } /* Terminating entry */
104}; 107};
105 108
diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
index 04d353f58d7..b5f83b44a0c 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/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index 66cd0b8096c..c92424ca1a5 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -1186,10 +1186,11 @@ static void gen6_cleanup(void)
1186/* Certain Gen5 chipsets require require idling the GPU before 1186/* Certain Gen5 chipsets require require idling the GPU before
1187 * unmapping anything from the GTT when VT-d is enabled. 1187 * unmapping anything from the GTT when VT-d is enabled.
1188 */ 1188 */
1189extern int intel_iommu_gfx_mapped;
1190static inline int needs_idle_maps(void) 1189static inline int needs_idle_maps(void)
1191{ 1190{
1191#ifdef CONFIG_INTEL_IOMMU
1192 const unsigned short gpu_devid = intel_private.pcidev->device; 1192 const unsigned short gpu_devid = intel_private.pcidev->device;
1193 extern int intel_iommu_gfx_mapped;
1193 1194
1194 /* Query intel_iommu to see if we need the workaround. Presumably that 1195 /* Query intel_iommu to see if we need the workaround. Presumably that
1195 * was loaded first. 1196 * was loaded first.
@@ -1198,7 +1199,7 @@ static inline int needs_idle_maps(void)
1198 gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && 1199 gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) &&
1199 intel_iommu_gfx_mapped) 1200 intel_iommu_gfx_mapped)
1200 return 1; 1201 return 1;
1201 1202#endif
1202 return 0; 1203 return 0;
1203} 1204}
1204 1205
@@ -1236,7 +1237,7 @@ static int i9xx_setup(void)
1236 intel_private.gtt_bus_addr = reg_addr + gtt_offset; 1237 intel_private.gtt_bus_addr = reg_addr + gtt_offset;
1237 } 1238 }
1238 1239
1239 if (needs_idle_maps()); 1240 if (needs_idle_maps())
1240 intel_private.base.do_idle_maps = 1; 1241 intel_private.base.do_idle_maps = 1;
1241 1242
1242 intel_i9xx_setup_flush(); 1243 intel_i9xx_setup_flush();
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 75f1cbd61c1..fd699ccecf5 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 8fc04b4f311..14517903371 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 d0c57c2e290..6abdde4da2b 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 810aff9e750..7c7f42a1f88 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/random.c b/drivers/char/random.c
index 63e19ba56bb..6035ab8d5ef 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -941,7 +941,7 @@ void get_random_bytes(void *buf, int nbytes)
941 if (!arch_get_random_long(&v)) 941 if (!arch_get_random_long(&v))
942 break; 942 break;
943 943
944 memcpy(buf, &v, chunk); 944 memcpy(p, &v, chunk);
945 p += chunk; 945 p += chunk;
946 nbytes -= chunk; 946 nbytes -= chunk;
947 } 947 }
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index f2286151190..eedd5474850 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;
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 4ca181f1378..8e3c46d67cb 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -34,6 +34,7 @@
34#include <linux/virtio_console.h> 34#include <linux/virtio_console.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <linux/module.h>
37#include "../tty/hvc/hvc_console.h" 38#include "../tty/hvc/hvc_console.h"
38 39
39/* 40/*
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index 32a77becc09..ca09bc421dd 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 40630cb9823..db8d5955bad 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 80813576861..079e96ad44e 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 faf7c521784..c5072a91e84 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 d90456a809f..f5002015d82 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}
@@ -103,17 +109,19 @@ static unsigned int db8500_cpufreq_getspeed(unsigned int cpu)
103 109
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 i, 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 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++)
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 35a257dd4bb..4bd6815d317 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 b7c3a84c4cf..ab9741fab92 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 b8d1d205e1e..3475f65aeec 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 0df01411009..06ce2680d00 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"
@@ -61,8 +62,9 @@ static int __cpuidle_register_device(struct cpuidle_device *dev);
61int cpuidle_idle_call(void) 62int cpuidle_idle_call(void)
62{ 63{
63 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); 64 struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
65 struct cpuidle_driver *drv = cpuidle_get_driver();
64 struct cpuidle_state *target_state; 66 struct cpuidle_state *target_state;
65 int next_state; 67 int next_state, entered_state;
66 68
67 if (off) 69 if (off)
68 return -ENODEV; 70 return -ENODEV;
@@ -83,45 +85,36 @@ int cpuidle_idle_call(void)
83 hrtimer_peek_ahead_timers(); 85 hrtimer_peek_ahead_timers();
84#endif 86#endif
85 87
86 /*
87 * Call the device's prepare function before calling the
88 * governor's select function. ->prepare gives the device's
89 * cpuidle driver a chance to update any dynamic information
90 * of its cpuidle states for the current idle period, e.g.
91 * state availability, latencies, residencies, etc.
92 */
93 if (dev->prepare)
94 dev->prepare(dev);
95
96 /* ask the governor for the next state */ 88 /* ask the governor for the next state */
97 next_state = cpuidle_curr_governor->select(dev); 89 next_state = cpuidle_curr_governor->select(drv, dev);
98 if (need_resched()) { 90 if (need_resched()) {
99 local_irq_enable(); 91 local_irq_enable();
100 return 0; 92 return 0;
101 } 93 }
102 94
103 target_state = &dev->states[next_state]; 95 target_state = &drv->states[next_state];
104
105 /* enter the state and update stats */
106 dev->last_state = target_state;
107 96
108 trace_power_start(POWER_CSTATE, next_state, dev->cpu); 97 trace_power_start(POWER_CSTATE, next_state, dev->cpu);
109 trace_cpu_idle(next_state, dev->cpu); 98 trace_cpu_idle(next_state, dev->cpu);
110 99
111 dev->last_residency = target_state->enter(dev, target_state); 100 entered_state = target_state->enter(dev, drv, next_state);
112 101
113 trace_power_end(dev->cpu); 102 trace_power_end(dev->cpu);
114 trace_cpu_idle(PWR_EVENT_EXIT, dev->cpu); 103 trace_cpu_idle(PWR_EVENT_EXIT, dev->cpu);
115 104
116 if (dev->last_state) 105 if (entered_state >= 0) {
117 target_state = dev->last_state; 106 /* Update cpuidle counters */
118 107 /* This can be moved to within driver enter routine
119 target_state->time += (unsigned long long)dev->last_residency; 108 * but that results in multiple copies of same code.
120 target_state->usage++; 109 */
110 dev->states_usage[entered_state].time +=
111 (unsigned long long)dev->last_residency;
112 dev->states_usage[entered_state].usage++;
113 }
121 114
122 /* give the governor an opportunity to reflect on the outcome */ 115 /* give the governor an opportunity to reflect on the outcome */
123 if (cpuidle_curr_governor->reflect) 116 if (cpuidle_curr_governor->reflect)
124 cpuidle_curr_governor->reflect(dev); 117 cpuidle_curr_governor->reflect(dev, entered_state);
125 118
126 return 0; 119 return 0;
127} 120}
@@ -172,11 +165,11 @@ void cpuidle_resume_and_unlock(void)
172EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock); 165EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
173 166
174#ifdef CONFIG_ARCH_HAS_CPU_RELAX 167#ifdef CONFIG_ARCH_HAS_CPU_RELAX
175static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st) 168static int poll_idle(struct cpuidle_device *dev,
169 struct cpuidle_driver *drv, int index)
176{ 170{
177 ktime_t t1, t2; 171 ktime_t t1, t2;
178 s64 diff; 172 s64 diff;
179 int ret;
180 173
181 t1 = ktime_get(); 174 t1 = ktime_get();
182 local_irq_enable(); 175 local_irq_enable();
@@ -188,15 +181,14 @@ static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st)
188 if (diff > INT_MAX) 181 if (diff > INT_MAX)
189 diff = INT_MAX; 182 diff = INT_MAX;
190 183
191 ret = (int) diff; 184 dev->last_residency = (int) diff;
192 return ret; 185
186 return index;
193} 187}
194 188
195static void poll_idle_init(struct cpuidle_device *dev) 189static void poll_idle_init(struct cpuidle_driver *drv)
196{ 190{
197 struct cpuidle_state *state = &dev->states[0]; 191 struct cpuidle_state *state = &drv->states[0];
198
199 cpuidle_set_statedata(state, NULL);
200 192
201 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL"); 193 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
202 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); 194 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
@@ -207,7 +199,7 @@ static void poll_idle_init(struct cpuidle_device *dev)
207 state->enter = poll_idle; 199 state->enter = poll_idle;
208} 200}
209#else 201#else
210static void poll_idle_init(struct cpuidle_device *dev) {} 202static void poll_idle_init(struct cpuidle_driver *drv) {}
211#endif /* CONFIG_ARCH_HAS_CPU_RELAX */ 203#endif /* CONFIG_ARCH_HAS_CPU_RELAX */
212 204
213/** 205/**
@@ -234,21 +226,20 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
234 return ret; 226 return ret;
235 } 227 }
236 228
237 poll_idle_init(dev); 229 poll_idle_init(cpuidle_get_driver());
238 230
239 if ((ret = cpuidle_add_state_sysfs(dev))) 231 if ((ret = cpuidle_add_state_sysfs(dev)))
240 return ret; 232 return ret;
241 233
242 if (cpuidle_curr_governor->enable && 234 if (cpuidle_curr_governor->enable &&
243 (ret = cpuidle_curr_governor->enable(dev))) 235 (ret = cpuidle_curr_governor->enable(cpuidle_get_driver(), dev)))
244 goto fail_sysfs; 236 goto fail_sysfs;
245 237
246 for (i = 0; i < dev->state_count; i++) { 238 for (i = 0; i < dev->state_count; i++) {
247 dev->states[i].usage = 0; 239 dev->states_usage[i].usage = 0;
248 dev->states[i].time = 0; 240 dev->states_usage[i].time = 0;
249 } 241 }
250 dev->last_residency = 0; 242 dev->last_residency = 0;
251 dev->last_state = NULL;
252 243
253 smp_wmb(); 244 smp_wmb();
254 245
@@ -282,7 +273,7 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
282 dev->enabled = 0; 273 dev->enabled = 0;
283 274
284 if (cpuidle_curr_governor->disable) 275 if (cpuidle_curr_governor->disable)
285 cpuidle_curr_governor->disable(dev); 276 cpuidle_curr_governor->disable(cpuidle_get_driver(), dev);
286 277
287 cpuidle_remove_state_sysfs(dev); 278 cpuidle_remove_state_sysfs(dev);
288 enabled_devices--; 279 enabled_devices--;
@@ -310,26 +301,6 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
310 301
311 init_completion(&dev->kobj_unregister); 302 init_completion(&dev->kobj_unregister);
312 303
313 /*
314 * cpuidle driver should set the dev->power_specified bit
315 * before registering the device if the driver provides
316 * power_usage numbers.
317 *
318 * For those devices whose ->power_specified is not set,
319 * we fill in power_usage with decreasing values as the
320 * cpuidle code has an implicit assumption that state Cn
321 * uses less power than C(n-1).
322 *
323 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
324 * an power value of -1. So we use -2, -3, etc, for other
325 * c-states.
326 */
327 if (!dev->power_specified) {
328 int i;
329 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++)
330 dev->states[i].power_usage = -1 - i;
331 }
332
333 per_cpu(cpuidle_devices, dev->cpu) = dev; 304 per_cpu(cpuidle_devices, dev->cpu) = dev;
334 list_add(&dev->device_list, &cpuidle_detected_devices); 305 list_add(&dev->device_list, &cpuidle_detected_devices);
335 if ((ret = cpuidle_add_sysfs(sys_dev))) { 306 if ((ret = cpuidle_add_sysfs(sys_dev))) {
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 3f7e3cedd13..284d7af5a9c 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -17,6 +17,30 @@
17static struct cpuidle_driver *cpuidle_curr_driver; 17static struct cpuidle_driver *cpuidle_curr_driver;
18DEFINE_SPINLOCK(cpuidle_driver_lock); 18DEFINE_SPINLOCK(cpuidle_driver_lock);
19 19
20static void __cpuidle_register_driver(struct cpuidle_driver *drv)
21{
22 int i;
23 /*
24 * cpuidle driver should set the drv->power_specified bit
25 * before registering if the driver provides
26 * power_usage numbers.
27 *
28 * If power_specified is not set,
29 * we fill in power_usage with decreasing values as the
30 * cpuidle code has an implicit assumption that state Cn
31 * uses less power than C(n-1).
32 *
33 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
34 * an power value of -1. So we use -2, -3, etc, for other
35 * c-states.
36 */
37 if (!drv->power_specified) {
38 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++)
39 drv->states[i].power_usage = -1 - i;
40 }
41}
42
43
20/** 44/**
21 * cpuidle_register_driver - registers a driver 45 * cpuidle_register_driver - registers a driver
22 * @drv: the driver 46 * @drv: the driver
@@ -34,6 +58,7 @@ int cpuidle_register_driver(struct cpuidle_driver *drv)
34 spin_unlock(&cpuidle_driver_lock); 58 spin_unlock(&cpuidle_driver_lock);
35 return -EBUSY; 59 return -EBUSY;
36 } 60 }
61 __cpuidle_register_driver(drv);
37 cpuidle_curr_driver = drv; 62 cpuidle_curr_driver = drv;
38 spin_unlock(&cpuidle_driver_lock); 63 spin_unlock(&cpuidle_driver_lock);
39 64
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
index f62fde21e96..b6a09ea859b 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>
@@ -60,9 +60,11 @@ static inline void ladder_do_selection(struct ladder_device *ldev,
60 60
61/** 61/**
62 * ladder_select_state - selects the next state to enter 62 * ladder_select_state - selects the next state to enter
63 * @drv: cpuidle driver
63 * @dev: the CPU 64 * @dev: the CPU
64 */ 65 */
65static int ladder_select_state(struct cpuidle_device *dev) 66static int ladder_select_state(struct cpuidle_driver *drv,
67 struct cpuidle_device *dev)
66{ 68{
67 struct ladder_device *ldev = &__get_cpu_var(ladder_devices); 69 struct ladder_device *ldev = &__get_cpu_var(ladder_devices);
68 struct ladder_device_state *last_state; 70 struct ladder_device_state *last_state;
@@ -77,15 +79,17 @@ static int ladder_select_state(struct cpuidle_device *dev)
77 79
78 last_state = &ldev->states[last_idx]; 80 last_state = &ldev->states[last_idx];
79 81
80 if (dev->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID) 82 if (drv->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID) {
81 last_residency = cpuidle_get_last_residency(dev) - dev->states[last_idx].exit_latency; 83 last_residency = cpuidle_get_last_residency(dev) - \
84 drv->states[last_idx].exit_latency;
85 }
82 else 86 else
83 last_residency = last_state->threshold.promotion_time + 1; 87 last_residency = last_state->threshold.promotion_time + 1;
84 88
85 /* consider promotion */ 89 /* consider promotion */
86 if (last_idx < dev->state_count - 1 && 90 if (last_idx < drv->state_count - 1 &&
87 last_residency > last_state->threshold.promotion_time && 91 last_residency > last_state->threshold.promotion_time &&
88 dev->states[last_idx + 1].exit_latency <= latency_req) { 92 drv->states[last_idx + 1].exit_latency <= latency_req) {
89 last_state->stats.promotion_count++; 93 last_state->stats.promotion_count++;
90 last_state->stats.demotion_count = 0; 94 last_state->stats.demotion_count = 0;
91 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) { 95 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
@@ -96,11 +100,11 @@ static int ladder_select_state(struct cpuidle_device *dev)
96 100
97 /* consider demotion */ 101 /* consider demotion */
98 if (last_idx > CPUIDLE_DRIVER_STATE_START && 102 if (last_idx > CPUIDLE_DRIVER_STATE_START &&
99 dev->states[last_idx].exit_latency > latency_req) { 103 drv->states[last_idx].exit_latency > latency_req) {
100 int i; 104 int i;
101 105
102 for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) { 106 for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) {
103 if (dev->states[i].exit_latency <= latency_req) 107 if (drv->states[i].exit_latency <= latency_req)
104 break; 108 break;
105 } 109 }
106 ladder_do_selection(ldev, last_idx, i); 110 ladder_do_selection(ldev, last_idx, i);
@@ -123,9 +127,11 @@ static int ladder_select_state(struct cpuidle_device *dev)
123 127
124/** 128/**
125 * ladder_enable_device - setup for the governor 129 * ladder_enable_device - setup for the governor
130 * @drv: cpuidle driver
126 * @dev: the CPU 131 * @dev: the CPU
127 */ 132 */
128static int ladder_enable_device(struct cpuidle_device *dev) 133static int ladder_enable_device(struct cpuidle_driver *drv,
134 struct cpuidle_device *dev)
129{ 135{
130 int i; 136 int i;
131 struct ladder_device *ldev = &per_cpu(ladder_devices, dev->cpu); 137 struct ladder_device *ldev = &per_cpu(ladder_devices, dev->cpu);
@@ -134,8 +140,8 @@ static int ladder_enable_device(struct cpuidle_device *dev)
134 140
135 ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START; 141 ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START;
136 142
137 for (i = 0; i < dev->state_count; i++) { 143 for (i = 0; i < drv->state_count; i++) {
138 state = &dev->states[i]; 144 state = &drv->states[i];
139 lstate = &ldev->states[i]; 145 lstate = &ldev->states[i];
140 146
141 lstate->stats.promotion_count = 0; 147 lstate->stats.promotion_count = 0;
@@ -144,7 +150,7 @@ static int ladder_enable_device(struct cpuidle_device *dev)
144 lstate->threshold.promotion_count = PROMOTION_COUNT; 150 lstate->threshold.promotion_count = PROMOTION_COUNT;
145 lstate->threshold.demotion_count = DEMOTION_COUNT; 151 lstate->threshold.demotion_count = DEMOTION_COUNT;
146 152
147 if (i < dev->state_count - 1) 153 if (i < drv->state_count - 1)
148 lstate->threshold.promotion_time = state->exit_latency; 154 lstate->threshold.promotion_time = state->exit_latency;
149 if (i > 0) 155 if (i > 0)
150 lstate->threshold.demotion_time = state->exit_latency; 156 lstate->threshold.demotion_time = state->exit_latency;
@@ -153,11 +159,24 @@ static int ladder_enable_device(struct cpuidle_device *dev)
153 return 0; 159 return 0;
154} 160}
155 161
162/**
163 * ladder_reflect - update the correct last_state_idx
164 * @dev: the CPU
165 * @index: the index of actual state entered
166 */
167static void ladder_reflect(struct cpuidle_device *dev, int index)
168{
169 struct ladder_device *ldev = &__get_cpu_var(ladder_devices);
170 if (index > 0)
171 ldev->last_state_idx = index;
172}
173
156static struct cpuidle_governor ladder_governor = { 174static struct cpuidle_governor ladder_governor = {
157 .name = "ladder", 175 .name = "ladder",
158 .rating = 10, 176 .rating = 10,
159 .enable = ladder_enable_device, 177 .enable = ladder_enable_device,
160 .select = ladder_select_state, 178 .select = ladder_select_state,
179 .reflect = ladder_reflect,
161 .owner = THIS_MODULE, 180 .owner = THIS_MODULE,
162}; 181};
163 182
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 3600f1955e4..ad0952601ae 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
@@ -182,7 +183,7 @@ static inline int performance_multiplier(void)
182 183
183static DEFINE_PER_CPU(struct menu_device, menu_devices); 184static DEFINE_PER_CPU(struct menu_device, menu_devices);
184 185
185static void menu_update(struct cpuidle_device *dev); 186static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
186 187
187/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */ 188/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */
188static u64 div_round64(u64 dividend, u32 divisor) 189static u64 div_round64(u64 dividend, u32 divisor)
@@ -228,9 +229,10 @@ static void detect_repeating_patterns(struct menu_device *data)
228 229
229/** 230/**
230 * menu_select - selects the next idle state to enter 231 * menu_select - selects the next idle state to enter
232 * @drv: cpuidle driver containing state data
231 * @dev: the CPU 233 * @dev: the CPU
232 */ 234 */
233static int menu_select(struct cpuidle_device *dev) 235static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
234{ 236{
235 struct menu_device *data = &__get_cpu_var(menu_devices); 237 struct menu_device *data = &__get_cpu_var(menu_devices);
236 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); 238 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
@@ -240,7 +242,7 @@ static int menu_select(struct cpuidle_device *dev)
240 struct timespec t; 242 struct timespec t;
241 243
242 if (data->needs_update) { 244 if (data->needs_update) {
243 menu_update(dev); 245 menu_update(drv, dev);
244 data->needs_update = 0; 246 data->needs_update = 0;
245 } 247 }
246 248
@@ -285,11 +287,9 @@ static int menu_select(struct cpuidle_device *dev)
285 * Find the idle state with the lowest power while satisfying 287 * Find the idle state with the lowest power while satisfying
286 * our constraints. 288 * our constraints.
287 */ 289 */
288 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) { 290 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
289 struct cpuidle_state *s = &dev->states[i]; 291 struct cpuidle_state *s = &drv->states[i];
290 292
291 if (s->flags & CPUIDLE_FLAG_IGNORE)
292 continue;
293 if (s->target_residency > data->predicted_us) 293 if (s->target_residency > data->predicted_us)
294 continue; 294 continue;
295 if (s->exit_latency > latency_req) 295 if (s->exit_latency > latency_req)
@@ -310,26 +310,30 @@ static int menu_select(struct cpuidle_device *dev)
310/** 310/**
311 * menu_reflect - records that data structures need update 311 * menu_reflect - records that data structures need update
312 * @dev: the CPU 312 * @dev: the CPU
313 * @index: the index of actual entered state
313 * 314 *
314 * NOTE: it's important to be fast here because this operation will add to 315 * NOTE: it's important to be fast here because this operation will add to
315 * the overall exit latency. 316 * the overall exit latency.
316 */ 317 */
317static void menu_reflect(struct cpuidle_device *dev) 318static void menu_reflect(struct cpuidle_device *dev, int index)
318{ 319{
319 struct menu_device *data = &__get_cpu_var(menu_devices); 320 struct menu_device *data = &__get_cpu_var(menu_devices);
320 data->needs_update = 1; 321 data->last_state_idx = index;
322 if (index >= 0)
323 data->needs_update = 1;
321} 324}
322 325
323/** 326/**
324 * menu_update - attempts to guess what happened after entry 327 * menu_update - attempts to guess what happened after entry
328 * @drv: cpuidle driver containing state data
325 * @dev: the CPU 329 * @dev: the CPU
326 */ 330 */
327static void menu_update(struct cpuidle_device *dev) 331static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
328{ 332{
329 struct menu_device *data = &__get_cpu_var(menu_devices); 333 struct menu_device *data = &__get_cpu_var(menu_devices);
330 int last_idx = data->last_state_idx; 334 int last_idx = data->last_state_idx;
331 unsigned int last_idle_us = cpuidle_get_last_residency(dev); 335 unsigned int last_idle_us = cpuidle_get_last_residency(dev);
332 struct cpuidle_state *target = &dev->states[last_idx]; 336 struct cpuidle_state *target = &drv->states[last_idx];
333 unsigned int measured_us; 337 unsigned int measured_us;
334 u64 new_factor; 338 u64 new_factor;
335 339
@@ -383,9 +387,11 @@ static void menu_update(struct cpuidle_device *dev)
383 387
384/** 388/**
385 * menu_enable_device - scans a CPU's states and does setup 389 * menu_enable_device - scans a CPU's states and does setup
390 * @drv: cpuidle driver
386 * @dev: the CPU 391 * @dev: the CPU
387 */ 392 */
388static int menu_enable_device(struct cpuidle_device *dev) 393static int menu_enable_device(struct cpuidle_driver *drv,
394 struct cpuidle_device *dev)
389{ 395{
390 struct menu_device *data = &per_cpu(menu_devices, dev->cpu); 396 struct menu_device *data = &per_cpu(menu_devices, dev->cpu);
391 397
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index be7917ec40c..1e756e160dc 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -216,7 +216,8 @@ static struct kobj_type ktype_cpuidle = {
216 216
217struct cpuidle_state_attr { 217struct cpuidle_state_attr {
218 struct attribute attr; 218 struct attribute attr;
219 ssize_t (*show)(struct cpuidle_state *, char *); 219 ssize_t (*show)(struct cpuidle_state *, \
220 struct cpuidle_state_usage *, char *);
220 ssize_t (*store)(struct cpuidle_state *, const char *, size_t); 221 ssize_t (*store)(struct cpuidle_state *, const char *, size_t);
221}; 222};
222 223
@@ -224,19 +225,22 @@ struct cpuidle_state_attr {
224static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL) 225static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
225 226
226#define define_show_state_function(_name) \ 227#define define_show_state_function(_name) \
227static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \ 228static ssize_t show_state_##_name(struct cpuidle_state *state, \
229 struct cpuidle_state_usage *state_usage, char *buf) \
228{ \ 230{ \
229 return sprintf(buf, "%u\n", state->_name);\ 231 return sprintf(buf, "%u\n", state->_name);\
230} 232}
231 233
232#define define_show_state_ull_function(_name) \ 234#define define_show_state_ull_function(_name) \
233static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \ 235static ssize_t show_state_##_name(struct cpuidle_state *state, \
236 struct cpuidle_state_usage *state_usage, char *buf) \
234{ \ 237{ \
235 return sprintf(buf, "%llu\n", state->_name);\ 238 return sprintf(buf, "%llu\n", state_usage->_name);\
236} 239}
237 240
238#define define_show_state_str_function(_name) \ 241#define define_show_state_str_function(_name) \
239static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \ 242static ssize_t show_state_##_name(struct cpuidle_state *state, \
243 struct cpuidle_state_usage *state_usage, char *buf) \
240{ \ 244{ \
241 if (state->_name[0] == '\0')\ 245 if (state->_name[0] == '\0')\
242 return sprintf(buf, "<null>\n");\ 246 return sprintf(buf, "<null>\n");\
@@ -269,16 +273,18 @@ static struct attribute *cpuidle_state_default_attrs[] = {
269 273
270#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj) 274#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
271#define kobj_to_state(k) (kobj_to_state_obj(k)->state) 275#define kobj_to_state(k) (kobj_to_state_obj(k)->state)
276#define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage)
272#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr) 277#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr)
273static ssize_t cpuidle_state_show(struct kobject * kobj, 278static ssize_t cpuidle_state_show(struct kobject * kobj,
274 struct attribute * attr ,char * buf) 279 struct attribute * attr ,char * buf)
275{ 280{
276 int ret = -EIO; 281 int ret = -EIO;
277 struct cpuidle_state *state = kobj_to_state(kobj); 282 struct cpuidle_state *state = kobj_to_state(kobj);
283 struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
278 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr); 284 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr);
279 285
280 if (cattr->show) 286 if (cattr->show)
281 ret = cattr->show(state, buf); 287 ret = cattr->show(state, state_usage, buf);
282 288
283 return ret; 289 return ret;
284} 290}
@@ -316,13 +322,15 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device)
316{ 322{
317 int i, ret = -ENOMEM; 323 int i, ret = -ENOMEM;
318 struct cpuidle_state_kobj *kobj; 324 struct cpuidle_state_kobj *kobj;
325 struct cpuidle_driver *drv = cpuidle_get_driver();
319 326
320 /* state statistics */ 327 /* state statistics */
321 for (i = 0; i < device->state_count; i++) { 328 for (i = 0; i < device->state_count; i++) {
322 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL); 329 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
323 if (!kobj) 330 if (!kobj)
324 goto error_state; 331 goto error_state;
325 kobj->state = &device->states[i]; 332 kobj->state = &drv->states[i];
333 kobj->state_usage = &device->states_usage[i];
326 init_completion(&kobj->kobj_unregister); 334 init_completion(&kobj->kobj_unregister);
327 335
328 ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj, 336 ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,
diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c
index 3cf303ee3fe..dcd8babae9e 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
@@ -342,11 +343,13 @@ static void mv_process_hash_current(int first_block)
342 else 343 else
343 op.config |= CFG_MID_FRAG; 344 op.config |= CFG_MID_FRAG;
344 345
345 writel(req_ctx->state[0], cpg->reg + DIGEST_INITIAL_VAL_A); 346 if (first_block) {
346 writel(req_ctx->state[1], cpg->reg + DIGEST_INITIAL_VAL_B); 347 writel(req_ctx->state[0], cpg->reg + DIGEST_INITIAL_VAL_A);
347 writel(req_ctx->state[2], cpg->reg + DIGEST_INITIAL_VAL_C); 348 writel(req_ctx->state[1], cpg->reg + DIGEST_INITIAL_VAL_B);
348 writel(req_ctx->state[3], cpg->reg + DIGEST_INITIAL_VAL_D); 349 writel(req_ctx->state[2], cpg->reg + DIGEST_INITIAL_VAL_C);
349 writel(req_ctx->state[4], cpg->reg + DIGEST_INITIAL_VAL_E); 350 writel(req_ctx->state[3], cpg->reg + DIGEST_INITIAL_VAL_D);
351 writel(req_ctx->state[4], cpg->reg + DIGEST_INITIAL_VAL_E);
352 }
350 } 353 }
351 354
352 memcpy(cpg->sram + SRAM_CONFIG, &op, sizeof(struct sec_accel_config)); 355 memcpy(cpg->sram + SRAM_CONFIG, &op, sizeof(struct sec_accel_config));
diff --git a/drivers/dca/dca-core.c b/drivers/dca/dca-core.c
index 25ec0bb0519..bc6f5faa1e9 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 5e8f335e6f6..591b6597c00 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/devfreq/Kconfig b/drivers/devfreq/Kconfig
index 643b055ed3c..8f049103708 100644
--- a/drivers/devfreq/Kconfig
+++ b/drivers/devfreq/Kconfig
@@ -1,36 +1,29 @@
1config ARCH_HAS_DEVFREQ
2 bool
3 depends on ARCH_HAS_OPP
4 help
5 Denotes that the architecture supports DEVFREQ. If the architecture
6 supports multiple OPP entries per device and the frequency of the
7 devices with OPPs may be altered dynamically, the architecture
8 supports DEVFREQ.
9
10menuconfig PM_DEVFREQ 1menuconfig PM_DEVFREQ
11 bool "Generic Dynamic Voltage and Frequency Scaling (DVFS) support" 2 bool "Generic Dynamic Voltage and Frequency Scaling (DVFS) support"
12 depends on PM_OPP && ARCH_HAS_DEVFREQ
13 help 3 help
14 With OPP support, a device may have a list of frequencies and 4 A device may have a list of frequencies and voltages available.
15 voltages available. DEVFREQ, a generic DVFS framework can be 5 devfreq, a generic DVFS framework can be registered for a device
16 registered for a device with OPP support in order to let the 6 in order to let the governor provided to devfreq choose an
17 governor provided to DEVFREQ choose an operating frequency 7 operating frequency based on the device driver's policy.
18 based on the OPP's list and the policy given with DEVFREQ.
19 8
20 Each device may have its own governor and policy. DEVFREQ can 9 Each device may have its own governor and policy. Devfreq can
21 reevaluate the device state periodically and/or based on the 10 reevaluate the device state periodically and/or based on the
22 OPP list changes (each frequency/voltage pair in OPP may be 11 notification to "nb", a notifier block, of devfreq.
23 disabled or enabled).
24 12
25 Like some CPUs with CPUFREQ, a device may have multiple clocks. 13 Like some CPUs with CPUfreq, a device may have multiple clocks.
26 However, because the clock frequencies of a single device are 14 However, because the clock frequencies of a single device are
27 determined by the single device's state, an instance of DEVFREQ 15 determined by the single device's state, an instance of devfreq
28 is attached to a single device and returns a "representative" 16 is attached to a single device and returns a "representative"
29 clock frequency from the OPP of the device, which is also attached 17 clock frequency of the device, which is also attached
30 to a device by 1-to-1. The device registering DEVFREQ takes the 18 to a device by 1-to-1. The device registering devfreq takes the
31 responsiblity to "interpret" the frequency listed in OPP and 19 responsiblity to "interpret" the representative frequency and
32 to set its every clock accordingly with the "target" callback 20 to set its every clock accordingly with the "target" callback
33 given to DEVFREQ. 21 given to devfreq.
22
23 When OPP is used with the devfreq device, it is recommended to
24 register devfreq's nb to the OPP's notifier head. If OPP is
25 used with the devfreq device, you may use OPP helper
26 functions defined in devfreq.h.
34 27
35if PM_DEVFREQ 28if PM_DEVFREQ
36 29
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 5d15b812377..59d24e9cb8c 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -15,7 +15,9 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/module.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/stat.h>
19#include <linux/opp.h> 21#include <linux/opp.h>
20#include <linux/devfreq.h> 22#include <linux/devfreq.h>
21#include <linux/workqueue.h> 23#include <linux/workqueue.h>
@@ -416,10 +418,14 @@ out:
416 */ 418 */
417int devfreq_remove_device(struct devfreq *devfreq) 419int devfreq_remove_device(struct devfreq *devfreq)
418{ 420{
421 bool central_polling;
422
419 if (!devfreq) 423 if (!devfreq)
420 return -EINVAL; 424 return -EINVAL;
421 425
422 if (!devfreq->governor->no_central_polling) { 426 central_polling = !devfreq->governor->no_central_polling;
427
428 if (central_polling) {
423 mutex_lock(&devfreq_list_lock); 429 mutex_lock(&devfreq_list_lock);
424 while (wait_remove_device == devfreq) { 430 while (wait_remove_device == devfreq) {
425 mutex_unlock(&devfreq_list_lock); 431 mutex_unlock(&devfreq_list_lock);
@@ -431,7 +437,7 @@ int devfreq_remove_device(struct devfreq *devfreq)
431 mutex_lock(&devfreq->lock); 437 mutex_lock(&devfreq->lock);
432 _remove_devfreq(devfreq, false); /* it unlocks devfreq->lock */ 438 _remove_devfreq(devfreq, false); /* it unlocks devfreq->lock */
433 439
434 if (!devfreq->governor->no_central_polling) 440 if (central_polling)
435 mutex_unlock(&devfreq_list_lock); 441 mutex_unlock(&devfreq_list_lock);
436 442
437 return 0; 443 return 0;
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 2e3b3d38c46..ab8f469f5cf 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 be21e3f138a..b7cbd1ab1db 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 6a483eac7b3..fcfa0a8b5c5 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 087dbf1dd39..aa4c9aebab7 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 765f5ff2230..eb1d8641cf5 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 4d180ca9a1d..9bfd6d36071 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 5d7a49bd7c2..b47e2b803fa 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 d99f71c356b..4be55f9bb6c 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 7bd7e98548c..f993955a640 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 8a3fdd87db9..19a0c64d45d 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 6815905a772..0e5ef33f90a 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 b9bae94f201..8ba4edc6185 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 be641cbd36f..b4588bdd98b 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 1ac8d4b580b..a6d0e3dbed0 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 00eee59e8b3..571041477ab 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 7f49235d14b..81809c2b46a 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 dc56576f9fd..2b55a276dc5 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 467e4dcb20a..13259cad0ce 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 f69f90a6187..a4a398f2ef6 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 203361e4ef9..5948a2194f5 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -214,7 +214,7 @@ config EDAC_I7300
214 214
215config EDAC_SBRIDGE 215config EDAC_SBRIDGE
216 tristate "Intel Sandy-Bridge Integrated MC" 216 tristate "Intel Sandy-Bridge Integrated MC"
217 depends on EDAC_MM_EDAC && PCI && X86 && X86_MCE_INTEL 217 depends on EDAC_MM_EDAC && PCI && X86_64 && X86_MCE_INTEL
218 depends on EXPERIMENTAL 218 depends on EXPERIMENTAL
219 help 219 help
220 Support for error detection and correction the Intel 220 Support for error detection and correction the Intel
diff --git a/drivers/edac/cpc925_edac.c b/drivers/edac/cpc925_edac.c
index a687a0d1696..a774c0ddaf5 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/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c
index a4987e03f59..73c3e26a0bc 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/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 8af8e864a9c..73464a62adf 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -1128,7 +1128,7 @@ static struct of_device_id mpc85xx_mc_err_of_match[] = {
1128 { .compatible = "fsl,p1020-memory-controller", }, 1128 { .compatible = "fsl,p1020-memory-controller", },
1129 { .compatible = "fsl,p1021-memory-controller", }, 1129 { .compatible = "fsl,p1021-memory-controller", },
1130 { .compatible = "fsl,p2020-memory-controller", }, 1130 { .compatible = "fsl,p2020-memory-controller", },
1131 { .compatible = "fsl,p4080-memory-controller", }, 1131 { .compatible = "fsl,qoriq-memory-controller", },
1132 {}, 1132 {},
1133}; 1133};
1134MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match); 1134MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match);
diff --git a/drivers/edac/ppc4xx_edac.c b/drivers/edac/ppc4xx_edac.c
index 0de7d877089..38400963e24 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/firewire/core-iso.c b/drivers/firewire/core-iso.c
index 57c3973093a..0f90e007187 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/dmi_scan.c b/drivers/firmware/dmi_scan.c
index bcb1126e3d0..153980be4ee 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -585,14 +585,12 @@ int dmi_name_in_serial(const char *str)
585} 585}
586 586
587/** 587/**
588 * dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information. 588 * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
589 * @str: Case sensitive Name 589 * @str: Case sensitive Name
590 */ 590 */
591int dmi_name_in_vendors(const char *str) 591int dmi_name_in_vendors(const char *str)
592{ 592{
593 static int fields[] = { DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_SYS_VENDOR, 593 static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
594 DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR,
595 DMI_BOARD_NAME, DMI_BOARD_VERSION, DMI_NONE };
596 int i; 594 int i;
597 for (i = 0; fields[i] != DMI_NONE; i++) { 595 for (i = 0; fields[i] != DMI_NONE; i++) {
598 int f = fields[i]; 596 int f = fields[i];
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index f1b7f659d3c..e2295766580 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/efivars.c b/drivers/firmware/efivars.c
index 8370f72d87f..b0a81173a26 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -457,7 +457,8 @@ static int efi_pstore_close(struct pstore_info *psi)
457} 457}
458 458
459static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, 459static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
460 struct timespec *timespec, struct pstore_info *psi) 460 struct timespec *timespec,
461 char **buf, struct pstore_info *psi)
461{ 462{
462 efi_guid_t vendor = LINUX_EFI_CRASH_GUID; 463 efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
463 struct efivars *efivars = psi->data; 464 struct efivars *efivars = psi->data;
@@ -478,7 +479,11 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
478 timespec->tv_nsec = 0; 479 timespec->tv_nsec = 0;
479 get_var_data_locked(efivars, &efivars->walk_entry->var); 480 get_var_data_locked(efivars, &efivars->walk_entry->var);
480 size = efivars->walk_entry->var.DataSize; 481 size = efivars->walk_entry->var.DataSize;
481 memcpy(psi->buf, efivars->walk_entry->var.Data, size); 482 *buf = kmalloc(size, GFP_KERNEL);
483 if (*buf == NULL)
484 return -ENOMEM;
485 memcpy(*buf, efivars->walk_entry->var.Data,
486 size);
482 efivars->walk_entry = list_entry(efivars->walk_entry->list.next, 487 efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
483 struct efivar_entry, list); 488 struct efivar_entry, list);
484 return size; 489 return size;
@@ -576,7 +581,8 @@ static int efi_pstore_close(struct pstore_info *psi)
576} 581}
577 582
578static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, 583static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
579 struct timespec *time, struct pstore_info *psi) 584 struct timespec *timespec,
585 char **buf, struct pstore_info *psi)
580{ 586{
581 return -1; 587 return -1;
582} 588}
diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c
index aa83de9db1b..c4e7c59d1c6 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/firmware/sigma.c b/drivers/firmware/sigma.c
index f10fc521951..1eedb6f7fda 100644
--- a/drivers/firmware/sigma.c
+++ b/drivers/firmware/sigma.c
@@ -14,13 +14,34 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/sigma.h> 15#include <linux/sigma.h>
16 16
17/* Return: 0==OK, <0==error, =1 ==no more actions */ 17static size_t sigma_action_size(struct sigma_action *sa)
18{
19 size_t payload = 0;
20
21 switch (sa->instr) {
22 case SIGMA_ACTION_WRITEXBYTES:
23 case SIGMA_ACTION_WRITESINGLE:
24 case SIGMA_ACTION_WRITESAFELOAD:
25 payload = sigma_action_len(sa);
26 break;
27 default:
28 break;
29 }
30
31 payload = ALIGN(payload, 2);
32
33 return payload + sizeof(struct sigma_action);
34}
35
36/*
37 * Returns a negative error value in case of an error, 0 if processing of
38 * the firmware should be stopped after this action, 1 otherwise.
39 */
18static int 40static int
19process_sigma_action(struct i2c_client *client, struct sigma_firmware *ssfw) 41process_sigma_action(struct i2c_client *client, struct sigma_action *sa)
20{ 42{
21 struct sigma_action *sa = (void *)(ssfw->fw->data + ssfw->pos);
22 size_t len = sigma_action_len(sa); 43 size_t len = sigma_action_len(sa);
23 int ret = 0; 44 int ret;
24 45
25 pr_debug("%s: instr:%i addr:%#x len:%zu\n", __func__, 46 pr_debug("%s: instr:%i addr:%#x len:%zu\n", __func__,
26 sa->instr, sa->addr, len); 47 sa->instr, sa->addr, len);
@@ -29,44 +50,50 @@ process_sigma_action(struct i2c_client *client, struct sigma_firmware *ssfw)
29 case SIGMA_ACTION_WRITEXBYTES: 50 case SIGMA_ACTION_WRITEXBYTES:
30 case SIGMA_ACTION_WRITESINGLE: 51 case SIGMA_ACTION_WRITESINGLE:
31 case SIGMA_ACTION_WRITESAFELOAD: 52 case SIGMA_ACTION_WRITESAFELOAD:
32 if (ssfw->fw->size < ssfw->pos + len)
33 return -EINVAL;
34 ret = i2c_master_send(client, (void *)&sa->addr, len); 53 ret = i2c_master_send(client, (void *)&sa->addr, len);
35 if (ret < 0) 54 if (ret < 0)
36 return -EINVAL; 55 return -EINVAL;
37 break; 56 break;
38
39 case SIGMA_ACTION_DELAY: 57 case SIGMA_ACTION_DELAY:
40 ret = 0;
41 udelay(len); 58 udelay(len);
42 len = 0; 59 len = 0;
43 break; 60 break;
44
45 case SIGMA_ACTION_END: 61 case SIGMA_ACTION_END:
46 return 1; 62 return 0;
47
48 default: 63 default:
49 return -EINVAL; 64 return -EINVAL;
50 } 65 }
51 66
52 /* when arrive here ret=0 or sent data */ 67 return 1;
53 ssfw->pos += sigma_action_size(sa, len);
54 return ssfw->pos == ssfw->fw->size;
55} 68}
56 69
57static int 70static int
58process_sigma_actions(struct i2c_client *client, struct sigma_firmware *ssfw) 71process_sigma_actions(struct i2c_client *client, struct sigma_firmware *ssfw)
59{ 72{
60 pr_debug("%s: processing %p\n", __func__, ssfw); 73 struct sigma_action *sa;
74 size_t size;
75 int ret;
76
77 while (ssfw->pos + sizeof(*sa) <= ssfw->fw->size) {
78 sa = (struct sigma_action *)(ssfw->fw->data + ssfw->pos);
79
80 size = sigma_action_size(sa);
81 ssfw->pos += size;
82 if (ssfw->pos > ssfw->fw->size || size == 0)
83 break;
84
85 ret = process_sigma_action(client, sa);
61 86
62 while (1) {
63 int ret = process_sigma_action(client, ssfw);
64 pr_debug("%s: action returned %i\n", __func__, ret); 87 pr_debug("%s: action returned %i\n", __func__, ret);
65 if (ret == 1) 88
66 return 0; 89 if (ret <= 0)
67 else if (ret)
68 return ret; 90 return ret;
69 } 91 }
92
93 if (ssfw->pos != ssfw->fw->size)
94 return -EINVAL;
95
96 return 0;
70} 97}
71 98
72int process_sigma_firmware(struct i2c_client *client, const char *name) 99int process_sigma_firmware(struct i2c_client *client, const char *name)
@@ -89,16 +116,24 @@ int process_sigma_firmware(struct i2c_client *client, const char *name)
89 116
90 /* then verify the header */ 117 /* then verify the header */
91 ret = -EINVAL; 118 ret = -EINVAL;
92 if (fw->size < sizeof(*ssfw_head)) 119
120 /*
121 * Reject too small or unreasonable large files. The upper limit has been
122 * chosen a bit arbitrarily, but it should be enough for all practical
123 * purposes and having the limit makes it easier to avoid integer
124 * overflows later in the loading process.
125 */
126 if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000)
93 goto done; 127 goto done;
94 128
95 ssfw_head = (void *)fw->data; 129 ssfw_head = (void *)fw->data;
96 if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) 130 if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic)))
97 goto done; 131 goto done;
98 132
99 crc = crc32(0, fw->data, fw->size); 133 crc = crc32(0, fw->data + sizeof(*ssfw_head),
134 fw->size - sizeof(*ssfw_head));
100 pr_debug("%s: crc=%x\n", __func__, crc); 135 pr_debug("%s: crc=%x\n", __func__, crc);
101 if (crc != ssfw_head->crc) 136 if (crc != le32_to_cpu(ssfw_head->crc))
102 goto done; 137 goto done;
103 138
104 ssfw.pos = sizeof(*ssfw_head); 139 ssfw.pos = sizeof(*ssfw_head);
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index cb0bd078efc..8482a23887d 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 19c5d27b6d2..dbcb0bcfd8d 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 ff525c0958d..a31ad6f5d91 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 7aafbb43733..1c0fc3756cb 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 d24b337cf1a..00000000000
--- 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 b3b4652e89e..2de57ce5feb 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 1ef46e6c2a2..c5d83a8a91c 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 3aa6beec8c1..ea8e7386925 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 52d3ed20810..2c7cef367fc 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 00000000000..ec3fcf0a7e1
--- /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 b81c9899211..e7914763457 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 292b50481db..385c58e8405 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-omap.c b/drivers/gpio/gpio-omap.c
index 0e49d87f6c6..0b056297917 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -148,13 +148,17 @@ static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
148 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0; 148 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
149} 149}
150 150
151#define MOD_REG_BIT(reg, bit_mask, set) \ 151static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
152do { \ 152{
153 int l = __raw_readl(base + reg); \ 153 int l = __raw_readl(base + reg);
154 if (set) l |= bit_mask; \ 154
155 else l &= ~bit_mask; \ 155 if (set)
156 __raw_writel(l, base + reg); \ 156 l |= mask;
157} while(0) 157 else
158 l &= ~mask;
159
160 __raw_writel(l, base + reg);
161}
158 162
159/** 163/**
160 * _set_gpio_debounce - low level gpio debounce time 164 * _set_gpio_debounce - low level gpio debounce time
@@ -210,28 +214,28 @@ static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
210 u32 gpio_bit = 1 << gpio; 214 u32 gpio_bit = 1 << gpio;
211 215
212 if (cpu_is_omap44xx()) { 216 if (cpu_is_omap44xx()) {
213 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit, 217 _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT0, gpio_bit,
214 trigger & IRQ_TYPE_LEVEL_LOW); 218 trigger & IRQ_TYPE_LEVEL_LOW);
215 MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit, 219 _gpio_rmw(base, OMAP4_GPIO_LEVELDETECT1, gpio_bit,
216 trigger & IRQ_TYPE_LEVEL_HIGH); 220 trigger & IRQ_TYPE_LEVEL_HIGH);
217 MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit, 221 _gpio_rmw(base, OMAP4_GPIO_RISINGDETECT, gpio_bit,
218 trigger & IRQ_TYPE_EDGE_RISING); 222 trigger & IRQ_TYPE_EDGE_RISING);
219 MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit, 223 _gpio_rmw(base, OMAP4_GPIO_FALLINGDETECT, gpio_bit,
220 trigger & IRQ_TYPE_EDGE_FALLING); 224 trigger & IRQ_TYPE_EDGE_FALLING);
221 } else { 225 } else {
222 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT0, gpio_bit, 226 _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT0, gpio_bit,
223 trigger & IRQ_TYPE_LEVEL_LOW); 227 trigger & IRQ_TYPE_LEVEL_LOW);
224 MOD_REG_BIT(OMAP24XX_GPIO_LEVELDETECT1, gpio_bit, 228 _gpio_rmw(base, OMAP24XX_GPIO_LEVELDETECT1, gpio_bit,
225 trigger & IRQ_TYPE_LEVEL_HIGH); 229 trigger & IRQ_TYPE_LEVEL_HIGH);
226 MOD_REG_BIT(OMAP24XX_GPIO_RISINGDETECT, gpio_bit, 230 _gpio_rmw(base, OMAP24XX_GPIO_RISINGDETECT, gpio_bit,
227 trigger & IRQ_TYPE_EDGE_RISING); 231 trigger & IRQ_TYPE_EDGE_RISING);
228 MOD_REG_BIT(OMAP24XX_GPIO_FALLINGDETECT, gpio_bit, 232 _gpio_rmw(base, OMAP24XX_GPIO_FALLINGDETECT, gpio_bit,
229 trigger & IRQ_TYPE_EDGE_FALLING); 233 trigger & IRQ_TYPE_EDGE_FALLING);
230 } 234 }
231 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) { 235 if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
232 if (cpu_is_omap44xx()) { 236 if (cpu_is_omap44xx()) {
233 MOD_REG_BIT(OMAP4_GPIO_IRQWAKEN0, gpio_bit, 237 _gpio_rmw(base, OMAP4_GPIO_IRQWAKEN0, gpio_bit,
234 trigger != 0); 238 trigger != 0);
235 } else { 239 } else {
236 /* 240 /*
237 * GPIO wakeup request can only be generated on edge 241 * GPIO wakeup request can only be generated on edge
@@ -1086,6 +1090,11 @@ omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1086 1090
1087 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base, 1091 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1088 handle_simple_irq); 1092 handle_simple_irq);
1093 if (!gc) {
1094 dev_err(bank->dev, "Memory alloc failed for gc\n");
1095 return;
1096 }
1097
1089 ct = gc->chip_types; 1098 ct = gc->chip_types;
1090 1099
1091 /* NOTE: No ack required, reading IRQ status clears it. */ 1100 /* NOTE: No ack required, reading IRQ status clears it. */
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 0550dcb8581..d3f3e8f5456 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -546,7 +546,7 @@ static void pca953x_irq_teardown(struct pca953x_chip *chip)
546 * Translate OpenFirmware node properties into platform_data 546 * Translate OpenFirmware node properties into platform_data
547 * WARNING: This is DEPRECATED and will be removed eventually! 547 * WARNING: This is DEPRECATED and will be removed eventually!
548 */ 548 */
549void 549static void
550pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) 550pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert)
551{ 551{
552 struct device_node *node; 552 struct device_node *node;
@@ -574,7 +574,7 @@ pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert)
574 *invert = *val; 574 *invert = *val;
575} 575}
576#else 576#else
577void 577static void
578pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) 578pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert)
579{ 579{
580 *gpio_base = -1; 580 *gpio_base = -1;
@@ -596,9 +596,6 @@ static int __devinit device_pca953x_init(struct pca953x_chip *chip, int invert)
596 596
597 /* set platform specific polarity inversion */ 597 /* set platform specific polarity inversion */
598 ret = pca953x_write_reg(chip, PCA953X_INVERT, invert); 598 ret = pca953x_write_reg(chip, PCA953X_INVERT, invert);
599 if (ret)
600 goto out;
601 return 0;
602out: 599out:
603 return ret; 600 return ret;
604} 601}
@@ -640,7 +637,7 @@ static int __devinit pca953x_probe(struct i2c_client *client,
640 struct pca953x_platform_data *pdata; 637 struct pca953x_platform_data *pdata;
641 struct pca953x_chip *chip; 638 struct pca953x_chip *chip;
642 int irq_base=0, invert=0; 639 int irq_base=0, invert=0;
643 int ret = 0; 640 int ret;
644 641
645 chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); 642 chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
646 if (chip == NULL) 643 if (chip == NULL)
@@ -673,10 +670,10 @@ static int __devinit pca953x_probe(struct i2c_client *client,
673 pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK); 670 pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK);
674 671
675 if (chip->chip_type == PCA953X_TYPE) 672 if (chip->chip_type == PCA953X_TYPE)
676 device_pca953x_init(chip, invert); 673 ret = device_pca953x_init(chip, invert);
677 else if (chip->chip_type == PCA957X_TYPE)
678 device_pca957x_init(chip, invert);
679 else 674 else
675 ret = device_pca957x_init(chip, invert);
676 if (ret)
680 goto out_failed; 677 goto out_failed;
681 678
682 ret = pca953x_irq_setup(chip, id, irq_base); 679 ret = pca953x_irq_setup(chip, id, irq_base);
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 7369fdda92b..3e1f1ecd07b 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 1e8a4a53881..a6008e123d0 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 ef67f1952a7..00000000000
--- 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 7f87b0c76e0..00000000000
--- 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 eb12f1602de..00000000000
--- 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 00000000000..86625185271
--- /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 846fbd5e31b..0ce6ac9898b 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/Kconfig b/drivers/gpu/drm/Kconfig
index 785127cb281..1368826ef28 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -9,7 +9,6 @@ menuconfig DRM
9 depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU 9 depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU
10 select I2C 10 select I2C
11 select I2C_ALGOBIT 11 select I2C_ALGOBIT
12 select SLOW_WORK
13 help 12 help
14 Kernel-level support for the Direct Rendering Infrastructure (DRI) 13 Kernel-level support for the Direct Rendering Infrastructure (DRI)
15 introduced in XFree86 4.0. If you say Y here, you need to select 14 introduced in XFree86 4.0. If you say Y here, you need to select
@@ -96,6 +95,7 @@ config DRM_I915
96 select FB_CFB_IMAGEBLIT 95 select FB_CFB_IMAGEBLIT
97 # i915 depends on ACPI_VIDEO when ACPI is enabled 96 # i915 depends on ACPI_VIDEO when ACPI is enabled
98 # but for select to work, need to select ACPI_VIDEO's dependencies, ick 97 # but for select to work, need to select ACPI_VIDEO's dependencies, ick
98 select BACKLIGHT_LCD_SUPPORT if ACPI
99 select BACKLIGHT_CLASS_DEVICE if ACPI 99 select BACKLIGHT_CLASS_DEVICE if ACPI
100 select VIDEO_OUTPUT_CONTROL if ACPI 100 select VIDEO_OUTPUT_CONTROL if ACPI
101 select INPUT if ACPI 101 select INPUT if ACPI
diff --git a/drivers/gpu/drm/ati_pcigart.c b/drivers/gpu/drm/ati_pcigart.c
index 1c364924220..9afe495c12c 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 529a0dbe9fc..08ccefedb32 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 61e1ef90d4e..30372f7b2d4 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 0e3bd5b54b7..592865381c6 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 fe738f05309..8323fc38984 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"
@@ -162,6 +163,7 @@ static struct drm_conn_prop_enum_list drm_connector_enum_list[] =
162 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 }, 163 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 },
163 { DRM_MODE_CONNECTOR_TV, "TV", 0 }, 164 { DRM_MODE_CONNECTOR_TV, "TV", 0 },
164 { DRM_MODE_CONNECTOR_eDP, "eDP", 0 }, 165 { DRM_MODE_CONNECTOR_eDP, "eDP", 0 },
166 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual", 0},
165}; 167};
166 168
167static struct drm_prop_enum_list drm_encoder_enum_list[] = 169static struct drm_prop_enum_list drm_encoder_enum_list[] =
@@ -170,6 +172,7 @@ static struct drm_prop_enum_list drm_encoder_enum_list[] =
170 { DRM_MODE_ENCODER_TMDS, "TMDS" }, 172 { DRM_MODE_ENCODER_TMDS, "TMDS" },
171 { DRM_MODE_ENCODER_LVDS, "LVDS" }, 173 { DRM_MODE_ENCODER_LVDS, "LVDS" },
172 { DRM_MODE_ENCODER_TVDAC, "TV" }, 174 { DRM_MODE_ENCODER_TVDAC, "TV" },
175 { DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
173}; 176};
174 177
175char *drm_get_encoder_name(struct drm_encoder *encoder) 178char *drm_get_encoder_name(struct drm_encoder *encoder)
@@ -463,8 +466,10 @@ void drm_connector_init(struct drm_device *dev,
463 list_add_tail(&connector->head, &dev->mode_config.connector_list); 466 list_add_tail(&connector->head, &dev->mode_config.connector_list);
464 dev->mode_config.num_connector++; 467 dev->mode_config.num_connector++;
465 468
466 drm_connector_attach_property(connector, 469 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
467 dev->mode_config.edid_property, 0); 470 drm_connector_attach_property(connector,
471 dev->mode_config.edid_property,
472 0);
468 473
469 drm_connector_attach_property(connector, 474 drm_connector_attach_property(connector,
470 dev->mode_config.dpms_property, 0); 475 dev->mode_config.dpms_property, 0);
@@ -1868,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1868 } 1873 }
1869 1874
1870 if (num_clips && clips_ptr) { 1875 if (num_clips && clips_ptr) {
1876 if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
1877 ret = -EINVAL;
1878 goto out_err1;
1879 }
1871 clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL); 1880 clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
1872 if (!clips) { 1881 if (!clips) {
1873 ret = -ENOMEM; 1882 ret = -ENOMEM;
@@ -2113,8 +2122,10 @@ struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2113 property->num_values = num_values; 2122 property->num_values = num_values;
2114 INIT_LIST_HEAD(&property->enum_blob_list); 2123 INIT_LIST_HEAD(&property->enum_blob_list);
2115 2124
2116 if (name) 2125 if (name) {
2117 strncpy(property->name, name, DRM_PROP_NAME_LEN); 2126 strncpy(property->name, name, DRM_PROP_NAME_LEN);
2127 property->name[DRM_PROP_NAME_LEN-1] = '\0';
2128 }
2118 2129
2119 list_add_tail(&property->head, &dev->mode_config.property_list); 2130 list_add_tail(&property->head, &dev->mode_config.property_list);
2120 return property; 2131 return property;
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index f2366440b73..d2619d72cec 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"
@@ -453,6 +456,30 @@ done:
453EXPORT_SYMBOL(drm_crtc_helper_set_mode); 456EXPORT_SYMBOL(drm_crtc_helper_set_mode);
454 457
455 458
459static int
460drm_crtc_helper_disable(struct drm_crtc *crtc)
461{
462 struct drm_device *dev = crtc->dev;
463 struct drm_connector *connector;
464 struct drm_encoder *encoder;
465
466 /* Decouple all encoders and their attached connectors from this crtc */
467 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
468 if (encoder->crtc != crtc)
469 continue;
470
471 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
472 if (connector->encoder != encoder)
473 continue;
474
475 connector->encoder = NULL;
476 }
477 }
478
479 drm_helper_disable_unused_functions(dev);
480 return 0;
481}
482
456/** 483/**
457 * drm_crtc_helper_set_config - set a new config from userspace 484 * drm_crtc_helper_set_config - set a new config from userspace
458 * @crtc: CRTC to setup 485 * @crtc: CRTC to setup
@@ -481,6 +508,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
481 struct drm_connector *save_connectors, *connector; 508 struct drm_connector *save_connectors, *connector;
482 int count = 0, ro, fail = 0; 509 int count = 0, ro, fail = 0;
483 struct drm_crtc_helper_funcs *crtc_funcs; 510 struct drm_crtc_helper_funcs *crtc_funcs;
511 struct drm_mode_set save_set;
484 int ret = 0; 512 int ret = 0;
485 int i; 513 int i;
486 514
@@ -506,8 +534,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
506 (int)set->num_connectors, set->x, set->y); 534 (int)set->num_connectors, set->x, set->y);
507 } else { 535 } else {
508 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); 536 DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
509 set->mode = NULL; 537 return drm_crtc_helper_disable(set->crtc);
510 set->num_connectors = 0;
511 } 538 }
512 539
513 dev = set->crtc->dev; 540 dev = set->crtc->dev;
@@ -553,6 +580,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
553 save_connectors[count++] = *connector; 580 save_connectors[count++] = *connector;
554 } 581 }
555 582
583 save_set.crtc = set->crtc;
584 save_set.mode = &set->crtc->mode;
585 save_set.x = set->crtc->x;
586 save_set.y = set->crtc->y;
587 save_set.fb = set->crtc->fb;
588
556 /* We should be able to check here if the fb has the same properties 589 /* We should be able to check here if the fb has the same properties
557 * and then just flip_or_move it */ 590 * and then just flip_or_move it */
558 if (set->crtc->fb != set->fb) { 591 if (set->crtc->fb != set->fb) {
@@ -718,6 +751,12 @@ fail:
718 *connector = save_connectors[count++]; 751 *connector = save_connectors[count++];
719 } 752 }
720 753
754 /* Try to restore the config */
755 if (mode_changed &&
756 !drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x,
757 save_set.y, save_set.fb))
758 DRM_ERROR("failed to restore config after modeset failure\n");
759
721 kfree(save_connectors); 760 kfree(save_connectors);
722 kfree(save_encoders); 761 kfree(save_encoders);
723 kfree(save_crtcs); 762 kfree(save_crtcs);
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index b9dc2629ea9..1c7a1c0d3ed 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)
@@ -117,7 +118,10 @@ int drm_debugfs_create_files(struct drm_info_list *files, int count,
117 tmp->minor = minor; 118 tmp->minor = minor;
118 tmp->dent = ent; 119 tmp->dent = ent;
119 tmp->info_ent = &files[i]; 120 tmp->info_ent = &files[i];
120 list_add(&(tmp->list), &(minor->debugfs_nodes.list)); 121
122 mutex_lock(&minor->debugfs_lock);
123 list_add(&tmp->list, &minor->debugfs_list);
124 mutex_unlock(&minor->debugfs_lock);
121 } 125 }
122 return 0; 126 return 0;
123 127
@@ -145,7 +149,8 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
145 char name[64]; 149 char name[64];
146 int ret; 150 int ret;
147 151
148 INIT_LIST_HEAD(&minor->debugfs_nodes.list); 152 INIT_LIST_HEAD(&minor->debugfs_list);
153 mutex_init(&minor->debugfs_lock);
149 sprintf(name, "%d", minor_id); 154 sprintf(name, "%d", minor_id);
150 minor->debugfs_root = debugfs_create_dir(name, root); 155 minor->debugfs_root = debugfs_create_dir(name, root);
151 if (!minor->debugfs_root) { 156 if (!minor->debugfs_root) {
@@ -191,8 +196,9 @@ int drm_debugfs_remove_files(struct drm_info_list *files, int count,
191 struct drm_info_node *tmp; 196 struct drm_info_node *tmp;
192 int i; 197 int i;
193 198
199 mutex_lock(&minor->debugfs_lock);
194 for (i = 0; i < count; i++) { 200 for (i = 0; i < count; i++) {
195 list_for_each_safe(pos, q, &minor->debugfs_nodes.list) { 201 list_for_each_safe(pos, q, &minor->debugfs_list) {
196 tmp = list_entry(pos, struct drm_info_node, list); 202 tmp = list_entry(pos, struct drm_info_node, list);
197 if (tmp->info_ent == &files[i]) { 203 if (tmp->info_ent == &files[i]) {
198 debugfs_remove(tmp->dent); 204 debugfs_remove(tmp->dent);
@@ -201,6 +207,7 @@ int drm_debugfs_remove_files(struct drm_info_list *files, int count,
201 } 207 }
202 } 208 }
203 } 209 }
210 mutex_unlock(&minor->debugfs_lock);
204 return 0; 211 return 0;
205} 212}
206EXPORT_SYMBOL(drm_debugfs_remove_files); 213EXPORT_SYMBOL(drm_debugfs_remove_files);
diff --git a/drivers/gpu/drm/drm_dma.c b/drivers/gpu/drm/drm_dma.c
index 252cbd74df0..cfb4e333ec0 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 7a87e0878f3..40c187c60f4 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
@@ -124,7 +125,7 @@ static struct drm_ioctl_desc drm_ioctls[] = {
124 DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 125 DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
125 DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 126 DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
126 127
127 DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, 0), 128 DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, DRM_UNLOCKED),
128 129
129 DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_modeset_ctl, 0), 130 DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_modeset_ctl, 0),
130 131
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index fe39c357053..3e927ce7557 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 d62c064fbaa..fb943551060 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 f7c6854eb4d..80fe39d98b0 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 2ec7d48fc4a..4911e1d1dcf 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 e3a75688f3c..68dc8744b63 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 4a058c7af6c..ddd70db45f7 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 3830e9e478c..44a5d0ad8b7 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) ( \
@@ -109,10 +110,7 @@ static void vblank_disable_and_save(struct drm_device *dev, int crtc)
109 /* Prevent vblank irq processing while disabling vblank irqs, 110 /* Prevent vblank irq processing while disabling vblank irqs,
110 * so no updates of timestamps or count can happen after we've 111 * so no updates of timestamps or count can happen after we've
111 * disabled. Needed to prevent races in case of delayed irq's. 112 * disabled. Needed to prevent races in case of delayed irq's.
112 * Disable preemption, so vblank_time_lock is held as short as
113 * possible, even under a kernel with PREEMPT_RT patches.
114 */ 113 */
115 preempt_disable();
116 spin_lock_irqsave(&dev->vblank_time_lock, irqflags); 114 spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
117 115
118 dev->driver->disable_vblank(dev, crtc); 116 dev->driver->disable_vblank(dev, crtc);
@@ -163,7 +161,6 @@ static void vblank_disable_and_save(struct drm_device *dev, int crtc)
163 clear_vblank_timestamps(dev, crtc); 161 clear_vblank_timestamps(dev, crtc);
164 162
165 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags); 163 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
166 preempt_enable();
167} 164}
168 165
169static void vblank_disable_fn(unsigned long arg) 166static void vblank_disable_fn(unsigned long arg)
@@ -406,13 +403,16 @@ int drm_irq_uninstall(struct drm_device *dev)
406 /* 403 /*
407 * Wake up any waiters so they don't hang. 404 * Wake up any waiters so they don't hang.
408 */ 405 */
409 spin_lock_irqsave(&dev->vbl_lock, irqflags); 406 if (dev->num_crtcs) {
410 for (i = 0; i < dev->num_crtcs; i++) { 407 spin_lock_irqsave(&dev->vbl_lock, irqflags);
411 DRM_WAKEUP(&dev->vbl_queue[i]); 408 for (i = 0; i < dev->num_crtcs; i++) {
412 dev->vblank_enabled[i] = 0; 409 DRM_WAKEUP(&dev->vbl_queue[i]);
413 dev->last_vblank[i] = dev->driver->get_vblank_counter(dev, i); 410 dev->vblank_enabled[i] = 0;
411 dev->last_vblank[i] =
412 dev->driver->get_vblank_counter(dev, i);
413 }
414 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
414 } 415 }
415 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
416 416
417 if (!irq_enabled) 417 if (!irq_enabled)
418 return -EINVAL; 418 return -EINVAL;
@@ -885,10 +885,6 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
885 spin_lock_irqsave(&dev->vbl_lock, irqflags); 885 spin_lock_irqsave(&dev->vbl_lock, irqflags);
886 /* Going from 0->1 means we have to enable interrupts again */ 886 /* Going from 0->1 means we have to enable interrupts again */
887 if (atomic_add_return(1, &dev->vblank_refcount[crtc]) == 1) { 887 if (atomic_add_return(1, &dev->vblank_refcount[crtc]) == 1) {
888 /* Disable preemption while holding vblank_time_lock. Do
889 * it explicitely to guard against PREEMPT_RT kernel.
890 */
891 preempt_disable();
892 spin_lock_irqsave(&dev->vblank_time_lock, irqflags2); 888 spin_lock_irqsave(&dev->vblank_time_lock, irqflags2);
893 if (!dev->vblank_enabled[crtc]) { 889 if (!dev->vblank_enabled[crtc]) {
894 /* Enable vblank irqs under vblank_time_lock protection. 890 /* Enable vblank irqs under vblank_time_lock protection.
@@ -908,7 +904,6 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
908 } 904 }
909 } 905 }
910 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags2); 906 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags2);
911 preempt_enable();
912 } else { 907 } else {
913 if (!dev->vblank_enabled[crtc]) { 908 if (!dev->vblank_enabled[crtc]) {
914 atomic_dec(&dev->vblank_refcount[crtc]); 909 atomic_dec(&dev->vblank_refcount[crtc]);
@@ -1124,6 +1119,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
1124 trace_drm_vblank_event_delivered(current->pid, pipe, 1119 trace_drm_vblank_event_delivered(current->pid, pipe,
1125 vblwait->request.sequence); 1120 vblwait->request.sequence);
1126 } else { 1121 } else {
1122 /* drm_handle_vblank_events will call drm_vblank_put */
1127 list_add_tail(&e->base.link, &dev->vblank_event_list); 1123 list_add_tail(&e->base.link, &dev->vblank_event_list);
1128 vblwait->reply.sequence = vblwait->request.sequence; 1124 vblwait->reply.sequence = vblwait->request.sequence;
1129 } 1125 }
@@ -1204,8 +1200,12 @@ int drm_wait_vblank(struct drm_device *dev, void *data,
1204 goto done; 1200 goto done;
1205 } 1201 }
1206 1202
1207 if (flags & _DRM_VBLANK_EVENT) 1203 if (flags & _DRM_VBLANK_EVENT) {
1204 /* must hold on to the vblank ref until the event fires
1205 * drm_vblank_put will be called asynchronously
1206 */
1208 return drm_queue_vblank_event(dev, crtc, vblwait, file_priv); 1207 return drm_queue_vblank_event(dev, crtc, vblwait, file_priv);
1208 }
1209 1209
1210 if ((flags & _DRM_VBLANK_NEXTONMISS) && 1210 if ((flags & _DRM_VBLANK_NEXTONMISS) &&
1211 (seq - vblwait->request.sequence) <= (1<<23)) { 1211 (seq - vblwait->request.sequence) <= (1<<23)) {
diff --git a/drivers/gpu/drm/drm_memory.c b/drivers/gpu/drm/drm_memory.c
index c9b805000a1..c8b6b66d428 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 959186cbf32..961fb54f426 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 ad74fb4dc54..fb8e46b4e8b 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 b6a19cb07ca..d4d10b7880c 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 2a8b6265ad3..ae9db5e2b27 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 0f3c4e3cafc..fff87221f9e 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 34664587a74..cebce45f442 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 2eee8e016b3..0f9ef9bf673 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 206d2300d87..445003f4dc9 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 5db96d45fc7..8c03eaf4144 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/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c
index 6f8afea94fc..2bb07bca511 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_buf.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c
@@ -27,82 +27,84 @@
27#include "drm.h" 27#include "drm.h"
28 28
29#include "exynos_drm_drv.h" 29#include "exynos_drm_drv.h"
30#include "exynos_drm_gem.h"
30#include "exynos_drm_buf.h" 31#include "exynos_drm_buf.h"
31 32
32static DEFINE_MUTEX(exynos_drm_buf_lock);
33
34static int lowlevel_buffer_allocate(struct drm_device *dev, 33static int lowlevel_buffer_allocate(struct drm_device *dev,
35 struct exynos_drm_buf_entry *entry) 34 struct exynos_drm_gem_buf *buffer)
36{ 35{
37 DRM_DEBUG_KMS("%s\n", __FILE__); 36 DRM_DEBUG_KMS("%s\n", __FILE__);
38 37
39 entry->vaddr = dma_alloc_writecombine(dev->dev, entry->size, 38 buffer->kvaddr = dma_alloc_writecombine(dev->dev, buffer->size,
40 (dma_addr_t *)&entry->paddr, GFP_KERNEL); 39 &buffer->dma_addr, GFP_KERNEL);
41 if (!entry->paddr) { 40 if (!buffer->kvaddr) {
42 DRM_ERROR("failed to allocate buffer.\n"); 41 DRM_ERROR("failed to allocate buffer.\n");
43 return -ENOMEM; 42 return -ENOMEM;
44 } 43 }
45 44
46 DRM_DEBUG_KMS("allocated : vaddr(0x%x), paddr(0x%x), size(0x%x)\n", 45 DRM_DEBUG_KMS("vaddr(0x%lx), dma_addr(0x%lx), size(0x%lx)\n",
47 (unsigned int)entry->vaddr, entry->paddr, entry->size); 46 (unsigned long)buffer->kvaddr,
47 (unsigned long)buffer->dma_addr,
48 buffer->size);
48 49
49 return 0; 50 return 0;
50} 51}
51 52
52static void lowlevel_buffer_deallocate(struct drm_device *dev, 53static void lowlevel_buffer_deallocate(struct drm_device *dev,
53 struct exynos_drm_buf_entry *entry) 54 struct exynos_drm_gem_buf *buffer)
54{ 55{
55 DRM_DEBUG_KMS("%s.\n", __FILE__); 56 DRM_DEBUG_KMS("%s.\n", __FILE__);
56 57
57 if (entry->paddr && entry->vaddr && entry->size) 58 if (buffer->dma_addr && buffer->size)
58 dma_free_writecombine(dev->dev, entry->size, entry->vaddr, 59 dma_free_writecombine(dev->dev, buffer->size, buffer->kvaddr,
59 entry->paddr); 60 (dma_addr_t)buffer->dma_addr);
60 else 61 else
61 DRM_DEBUG_KMS("entry data is null.\n"); 62 DRM_DEBUG_KMS("buffer data are invalid.\n");
62} 63}
63 64
64struct exynos_drm_buf_entry *exynos_drm_buf_create(struct drm_device *dev, 65struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev,
65 unsigned int size) 66 unsigned int size)
66{ 67{
67 struct exynos_drm_buf_entry *entry; 68 struct exynos_drm_gem_buf *buffer;
68 69
69 DRM_DEBUG_KMS("%s.\n", __FILE__); 70 DRM_DEBUG_KMS("%s.\n", __FILE__);
71 DRM_DEBUG_KMS("desired size = 0x%x\n", size);
70 72
71 entry = kzalloc(sizeof(*entry), GFP_KERNEL); 73 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
72 if (!entry) { 74 if (!buffer) {
73 DRM_ERROR("failed to allocate exynos_drm_buf_entry.\n"); 75 DRM_ERROR("failed to allocate exynos_drm_gem_buf.\n");
74 return ERR_PTR(-ENOMEM); 76 return ERR_PTR(-ENOMEM);
75 } 77 }
76 78
77 entry->size = size; 79 buffer->size = size;
78 80
79 /* 81 /*
80 * allocate memory region with size and set the memory information 82 * allocate memory region with size and set the memory information
81 * to vaddr and paddr of a entry object. 83 * to vaddr and dma_addr of a buffer object.
82 */ 84 */
83 if (lowlevel_buffer_allocate(dev, entry) < 0) { 85 if (lowlevel_buffer_allocate(dev, buffer) < 0) {
84 kfree(entry); 86 kfree(buffer);
85 entry = NULL; 87 buffer = NULL;
86 return ERR_PTR(-ENOMEM); 88 return ERR_PTR(-ENOMEM);
87 } 89 }
88 90
89 return entry; 91 return buffer;
90} 92}
91 93
92void exynos_drm_buf_destroy(struct drm_device *dev, 94void exynos_drm_buf_destroy(struct drm_device *dev,
93 struct exynos_drm_buf_entry *entry) 95 struct exynos_drm_gem_buf *buffer)
94{ 96{
95 DRM_DEBUG_KMS("%s.\n", __FILE__); 97 DRM_DEBUG_KMS("%s.\n", __FILE__);
96 98
97 if (!entry) { 99 if (!buffer) {
98 DRM_DEBUG_KMS("entry is null.\n"); 100 DRM_DEBUG_KMS("buffer is null.\n");
99 return; 101 return;
100 } 102 }
101 103
102 lowlevel_buffer_deallocate(dev, entry); 104 lowlevel_buffer_deallocate(dev, buffer);
103 105
104 kfree(entry); 106 kfree(buffer);
105 entry = NULL; 107 buffer = NULL;
106} 108}
107 109
108MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); 110MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.h b/drivers/gpu/drm/exynos/exynos_drm_buf.h
index 045d59eab01..6e91f9caa5d 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_buf.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_buf.h
@@ -26,28 +26,15 @@
26#ifndef _EXYNOS_DRM_BUF_H_ 26#ifndef _EXYNOS_DRM_BUF_H_
27#define _EXYNOS_DRM_BUF_H_ 27#define _EXYNOS_DRM_BUF_H_
28 28
29/*
30 * exynos drm buffer entry structure.
31 *
32 * @paddr: physical address of allocated memory.
33 * @vaddr: kernel virtual address of allocated memory.
34 * @size: size of allocated memory.
35 */
36struct exynos_drm_buf_entry {
37 dma_addr_t paddr;
38 void __iomem *vaddr;
39 unsigned int size;
40};
41
42/* allocate physical memory. */ 29/* allocate physical memory. */
43struct exynos_drm_buf_entry *exynos_drm_buf_create(struct drm_device *dev, 30struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev,
44 unsigned int size); 31 unsigned int size);
45 32
46/* get physical memory information of a drm framebuffer. */ 33/* get memory information of a drm framebuffer. */
47struct exynos_drm_buf_entry *exynos_drm_fb_get_buf(struct drm_framebuffer *fb); 34struct exynos_drm_gem_buf *exynos_drm_fb_get_buf(struct drm_framebuffer *fb);
48 35
49/* remove allocated physical memory. */ 36/* remove allocated physical memory. */
50void exynos_drm_buf_destroy(struct drm_device *dev, 37void exynos_drm_buf_destroy(struct drm_device *dev,
51 struct exynos_drm_buf_entry *entry); 38 struct exynos_drm_gem_buf *buffer);
52 39
53#endif 40#endif
diff --git a/drivers/gpu/drm/exynos/exynos_drm_connector.c b/drivers/gpu/drm/exynos/exynos_drm_connector.c
index 985d9e76872..d620b078425 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_connector.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_connector.c
@@ -37,6 +37,8 @@
37 37
38struct exynos_drm_connector { 38struct exynos_drm_connector {
39 struct drm_connector drm_connector; 39 struct drm_connector drm_connector;
40 uint32_t encoder_id;
41 struct exynos_drm_manager *manager;
40}; 42};
41 43
42/* convert exynos_video_timings to drm_display_mode */ 44/* convert exynos_video_timings to drm_display_mode */
@@ -47,6 +49,7 @@ convert_to_display_mode(struct drm_display_mode *mode,
47 DRM_DEBUG_KMS("%s\n", __FILE__); 49 DRM_DEBUG_KMS("%s\n", __FILE__);
48 50
49 mode->clock = timing->pixclock / 1000; 51 mode->clock = timing->pixclock / 1000;
52 mode->vrefresh = timing->refresh;
50 53
51 mode->hdisplay = timing->xres; 54 mode->hdisplay = timing->xres;
52 mode->hsync_start = mode->hdisplay + timing->left_margin; 55 mode->hsync_start = mode->hdisplay + timing->left_margin;
@@ -57,6 +60,12 @@ convert_to_display_mode(struct drm_display_mode *mode,
57 mode->vsync_start = mode->vdisplay + timing->upper_margin; 60 mode->vsync_start = mode->vdisplay + timing->upper_margin;
58 mode->vsync_end = mode->vsync_start + timing->vsync_len; 61 mode->vsync_end = mode->vsync_start + timing->vsync_len;
59 mode->vtotal = mode->vsync_end + timing->lower_margin; 62 mode->vtotal = mode->vsync_end + timing->lower_margin;
63
64 if (timing->vmode & FB_VMODE_INTERLACED)
65 mode->flags |= DRM_MODE_FLAG_INTERLACE;
66
67 if (timing->vmode & FB_VMODE_DOUBLE)
68 mode->flags |= DRM_MODE_FLAG_DBLSCAN;
60} 69}
61 70
62/* convert drm_display_mode to exynos_video_timings */ 71/* convert drm_display_mode to exynos_video_timings */
@@ -69,7 +78,7 @@ convert_to_video_timing(struct fb_videomode *timing,
69 memset(timing, 0, sizeof(*timing)); 78 memset(timing, 0, sizeof(*timing));
70 79
71 timing->pixclock = mode->clock * 1000; 80 timing->pixclock = mode->clock * 1000;
72 timing->refresh = mode->vrefresh; 81 timing->refresh = drm_mode_vrefresh(mode);
73 82
74 timing->xres = mode->hdisplay; 83 timing->xres = mode->hdisplay;
75 timing->left_margin = mode->hsync_start - mode->hdisplay; 84 timing->left_margin = mode->hsync_start - mode->hdisplay;
@@ -92,15 +101,16 @@ convert_to_video_timing(struct fb_videomode *timing,
92 101
93static int exynos_drm_connector_get_modes(struct drm_connector *connector) 102static int exynos_drm_connector_get_modes(struct drm_connector *connector)
94{ 103{
95 struct exynos_drm_manager *manager = 104 struct exynos_drm_connector *exynos_connector =
96 exynos_drm_get_manager(connector->encoder); 105 to_exynos_connector(connector);
97 struct exynos_drm_display *display = manager->display; 106 struct exynos_drm_manager *manager = exynos_connector->manager;
107 struct exynos_drm_display_ops *display_ops = manager->display_ops;
98 unsigned int count; 108 unsigned int count;
99 109
100 DRM_DEBUG_KMS("%s\n", __FILE__); 110 DRM_DEBUG_KMS("%s\n", __FILE__);
101 111
102 if (!display) { 112 if (!display_ops) {
103 DRM_DEBUG_KMS("display is null.\n"); 113 DRM_DEBUG_KMS("display_ops is null.\n");
104 return 0; 114 return 0;
105 } 115 }
106 116
@@ -112,7 +122,7 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector)
112 * P.S. in case of lcd panel, count is always 1 if success 122 * P.S. in case of lcd panel, count is always 1 if success
113 * because lcd panel has only one mode. 123 * because lcd panel has only one mode.
114 */ 124 */
115 if (display->get_edid) { 125 if (display_ops->get_edid) {
116 int ret; 126 int ret;
117 void *edid; 127 void *edid;
118 128
@@ -122,7 +132,7 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector)
122 return 0; 132 return 0;
123 } 133 }
124 134
125 ret = display->get_edid(manager->dev, connector, 135 ret = display_ops->get_edid(manager->dev, connector,
126 edid, MAX_EDID); 136 edid, MAX_EDID);
127 if (ret < 0) { 137 if (ret < 0) {
128 DRM_ERROR("failed to get edid data.\n"); 138 DRM_ERROR("failed to get edid data.\n");
@@ -140,8 +150,8 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector)
140 struct drm_display_mode *mode = drm_mode_create(connector->dev); 150 struct drm_display_mode *mode = drm_mode_create(connector->dev);
141 struct fb_videomode *timing; 151 struct fb_videomode *timing;
142 152
143 if (display->get_timing) 153 if (display_ops->get_timing)
144 timing = display->get_timing(manager->dev); 154 timing = display_ops->get_timing(manager->dev);
145 else { 155 else {
146 drm_mode_destroy(connector->dev, mode); 156 drm_mode_destroy(connector->dev, mode);
147 return 0; 157 return 0;
@@ -162,9 +172,10 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector)
162static int exynos_drm_connector_mode_valid(struct drm_connector *connector, 172static int exynos_drm_connector_mode_valid(struct drm_connector *connector,
163 struct drm_display_mode *mode) 173 struct drm_display_mode *mode)
164{ 174{
165 struct exynos_drm_manager *manager = 175 struct exynos_drm_connector *exynos_connector =
166 exynos_drm_get_manager(connector->encoder); 176 to_exynos_connector(connector);
167 struct exynos_drm_display *display = manager->display; 177 struct exynos_drm_manager *manager = exynos_connector->manager;
178 struct exynos_drm_display_ops *display_ops = manager->display_ops;
168 struct fb_videomode timing; 179 struct fb_videomode timing;
169 int ret = MODE_BAD; 180 int ret = MODE_BAD;
170 181
@@ -172,8 +183,8 @@ static int exynos_drm_connector_mode_valid(struct drm_connector *connector,
172 183
173 convert_to_video_timing(&timing, mode); 184 convert_to_video_timing(&timing, mode);
174 185
175 if (display && display->check_timing) 186 if (display_ops && display_ops->check_timing)
176 if (!display->check_timing(manager->dev, (void *)&timing)) 187 if (!display_ops->check_timing(manager->dev, (void *)&timing))
177 ret = MODE_OK; 188 ret = MODE_OK;
178 189
179 return ret; 190 return ret;
@@ -181,9 +192,25 @@ static int exynos_drm_connector_mode_valid(struct drm_connector *connector,
181 192
182struct drm_encoder *exynos_drm_best_encoder(struct drm_connector *connector) 193struct drm_encoder *exynos_drm_best_encoder(struct drm_connector *connector)
183{ 194{
195 struct drm_device *dev = connector->dev;
196 struct exynos_drm_connector *exynos_connector =
197 to_exynos_connector(connector);
198 struct drm_mode_object *obj;
199 struct drm_encoder *encoder;
200
184 DRM_DEBUG_KMS("%s\n", __FILE__); 201 DRM_DEBUG_KMS("%s\n", __FILE__);
185 202
186 return connector->encoder; 203 obj = drm_mode_object_find(dev, exynos_connector->encoder_id,
204 DRM_MODE_OBJECT_ENCODER);
205 if (!obj) {
206 DRM_DEBUG_KMS("Unknown ENCODER ID %d\n",
207 exynos_connector->encoder_id);
208 return NULL;
209 }
210
211 encoder = obj_to_encoder(obj);
212
213 return encoder;
187} 214}
188 215
189static struct drm_connector_helper_funcs exynos_connector_helper_funcs = { 216static struct drm_connector_helper_funcs exynos_connector_helper_funcs = {
@@ -196,15 +223,17 @@ static struct drm_connector_helper_funcs exynos_connector_helper_funcs = {
196static enum drm_connector_status 223static enum drm_connector_status
197exynos_drm_connector_detect(struct drm_connector *connector, bool force) 224exynos_drm_connector_detect(struct drm_connector *connector, bool force)
198{ 225{
199 struct exynos_drm_manager *manager = 226 struct exynos_drm_connector *exynos_connector =
200 exynos_drm_get_manager(connector->encoder); 227 to_exynos_connector(connector);
201 struct exynos_drm_display *display = manager->display; 228 struct exynos_drm_manager *manager = exynos_connector->manager;
229 struct exynos_drm_display_ops *display_ops =
230 manager->display_ops;
202 enum drm_connector_status status = connector_status_disconnected; 231 enum drm_connector_status status = connector_status_disconnected;
203 232
204 DRM_DEBUG_KMS("%s\n", __FILE__); 233 DRM_DEBUG_KMS("%s\n", __FILE__);
205 234
206 if (display && display->is_connected) { 235 if (display_ops && display_ops->is_connected) {
207 if (display->is_connected(manager->dev)) 236 if (display_ops->is_connected(manager->dev))
208 status = connector_status_connected; 237 status = connector_status_connected;
209 else 238 else
210 status = connector_status_disconnected; 239 status = connector_status_disconnected;
@@ -251,9 +280,11 @@ struct drm_connector *exynos_drm_connector_create(struct drm_device *dev,
251 280
252 connector = &exynos_connector->drm_connector; 281 connector = &exynos_connector->drm_connector;
253 282
254 switch (manager->display->type) { 283 switch (manager->display_ops->type) {
255 case EXYNOS_DISPLAY_TYPE_HDMI: 284 case EXYNOS_DISPLAY_TYPE_HDMI:
256 type = DRM_MODE_CONNECTOR_HDMIA; 285 type = DRM_MODE_CONNECTOR_HDMIA;
286 connector->interlace_allowed = true;
287 connector->polled = DRM_CONNECTOR_POLL_HPD;
257 break; 288 break;
258 default: 289 default:
259 type = DRM_MODE_CONNECTOR_Unknown; 290 type = DRM_MODE_CONNECTOR_Unknown;
@@ -267,7 +298,10 @@ struct drm_connector *exynos_drm_connector_create(struct drm_device *dev,
267 if (err) 298 if (err)
268 goto err_connector; 299 goto err_connector;
269 300
301 exynos_connector->encoder_id = encoder->base.id;
302 exynos_connector->manager = manager;
270 connector->encoder = encoder; 303 connector->encoder = encoder;
304
271 err = drm_mode_connector_attach_encoder(connector, encoder); 305 err = drm_mode_connector_attach_encoder(connector, encoder);
272 if (err) { 306 if (err) {
273 DRM_ERROR("failed to attach a connector to a encoder\n"); 307 DRM_ERROR("failed to attach a connector to a encoder\n");
diff --git a/drivers/gpu/drm/exynos/exynos_drm_crtc.c b/drivers/gpu/drm/exynos/exynos_drm_crtc.c
index 9337e5e2dbb..ee43cc22085 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_crtc.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_crtc.c
@@ -29,36 +29,17 @@
29#include "drmP.h" 29#include "drmP.h"
30#include "drm_crtc_helper.h" 30#include "drm_crtc_helper.h"
31 31
32#include "exynos_drm_crtc.h"
32#include "exynos_drm_drv.h" 33#include "exynos_drm_drv.h"
33#include "exynos_drm_fb.h" 34#include "exynos_drm_fb.h"
34#include "exynos_drm_encoder.h" 35#include "exynos_drm_encoder.h"
36#include "exynos_drm_gem.h"
35#include "exynos_drm_buf.h" 37#include "exynos_drm_buf.h"
36 38
37#define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\ 39#define to_exynos_crtc(x) container_of(x, struct exynos_drm_crtc,\
38 drm_crtc) 40 drm_crtc)
39 41
40/* 42/*
41 * Exynos specific crtc postion structure.
42 *
43 * @fb_x: offset x on a framebuffer to be displyed
44 * - the unit is screen coordinates.
45 * @fb_y: offset y on a framebuffer to be displayed
46 * - the unit is screen coordinates.
47 * @crtc_x: offset x on hardware screen.
48 * @crtc_y: offset y on hardware screen.
49 * @crtc_w: width of hardware screen.
50 * @crtc_h: height of hardware screen.
51 */
52struct exynos_drm_crtc_pos {
53 unsigned int fb_x;
54 unsigned int fb_y;
55 unsigned int crtc_x;
56 unsigned int crtc_y;
57 unsigned int crtc_w;
58 unsigned int crtc_h;
59};
60
61/*
62 * Exynos specific crtc structure. 43 * Exynos specific crtc structure.
63 * 44 *
64 * @drm_crtc: crtc object. 45 * @drm_crtc: crtc object.
@@ -85,30 +66,31 @@ static void exynos_drm_crtc_apply(struct drm_crtc *crtc)
85 66
86 exynos_drm_fn_encoder(crtc, overlay, 67 exynos_drm_fn_encoder(crtc, overlay,
87 exynos_drm_encoder_crtc_mode_set); 68 exynos_drm_encoder_crtc_mode_set);
88 exynos_drm_fn_encoder(crtc, NULL, exynos_drm_encoder_crtc_commit); 69 exynos_drm_fn_encoder(crtc, &exynos_crtc->pipe,
70 exynos_drm_encoder_crtc_commit);
89} 71}
90 72
91static int exynos_drm_overlay_update(struct exynos_drm_overlay *overlay, 73int exynos_drm_overlay_update(struct exynos_drm_overlay *overlay,
92 struct drm_framebuffer *fb, 74 struct drm_framebuffer *fb,
93 struct drm_display_mode *mode, 75 struct drm_display_mode *mode,
94 struct exynos_drm_crtc_pos *pos) 76 struct exynos_drm_crtc_pos *pos)
95{ 77{
96 struct exynos_drm_buf_entry *entry; 78 struct exynos_drm_gem_buf *buffer;
97 unsigned int actual_w; 79 unsigned int actual_w;
98 unsigned int actual_h; 80 unsigned int actual_h;
99 81
100 entry = exynos_drm_fb_get_buf(fb); 82 buffer = exynos_drm_fb_get_buf(fb);
101 if (!entry) { 83 if (!buffer) {
102 DRM_LOG_KMS("entry is null.\n"); 84 DRM_LOG_KMS("buffer is null.\n");
103 return -EFAULT; 85 return -EFAULT;
104 } 86 }
105 87
106 overlay->paddr = entry->paddr; 88 overlay->dma_addr = buffer->dma_addr;
107 overlay->vaddr = entry->vaddr; 89 overlay->vaddr = buffer->kvaddr;
108 90
109 DRM_DEBUG_KMS("vaddr = 0x%lx, paddr = 0x%lx\n", 91 DRM_DEBUG_KMS("vaddr = 0x%lx, dma_addr = 0x%lx\n",
110 (unsigned long)overlay->vaddr, 92 (unsigned long)overlay->vaddr,
111 (unsigned long)overlay->paddr); 93 (unsigned long)overlay->dma_addr);
112 94
113 actual_w = min((mode->hdisplay - pos->crtc_x), pos->crtc_w); 95 actual_w = min((mode->hdisplay - pos->crtc_x), pos->crtc_w);
114 actual_h = min((mode->vdisplay - pos->crtc_y), pos->crtc_h); 96 actual_h = min((mode->vdisplay - pos->crtc_y), pos->crtc_h);
@@ -171,9 +153,26 @@ static int exynos_drm_crtc_update(struct drm_crtc *crtc)
171 153
172static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode) 154static void exynos_drm_crtc_dpms(struct drm_crtc *crtc, int mode)
173{ 155{
174 DRM_DEBUG_KMS("%s\n", __FILE__); 156 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
175 157
176 /* TODO */ 158 DRM_DEBUG_KMS("crtc[%d] mode[%d]\n", crtc->base.id, mode);
159
160 switch (mode) {
161 case DRM_MODE_DPMS_ON:
162 exynos_drm_fn_encoder(crtc, &exynos_crtc->pipe,
163 exynos_drm_encoder_crtc_commit);
164 break;
165 case DRM_MODE_DPMS_STANDBY:
166 case DRM_MODE_DPMS_SUSPEND:
167 case DRM_MODE_DPMS_OFF:
168 /* TODO */
169 exynos_drm_fn_encoder(crtc, NULL,
170 exynos_drm_encoder_crtc_disable);
171 break;
172 default:
173 DRM_DEBUG_KMS("unspecified mode %d\n", mode);
174 break;
175 }
177} 176}
178 177
179static void exynos_drm_crtc_prepare(struct drm_crtc *crtc) 178static void exynos_drm_crtc_prepare(struct drm_crtc *crtc)
@@ -185,9 +184,12 @@ static void exynos_drm_crtc_prepare(struct drm_crtc *crtc)
185 184
186static void exynos_drm_crtc_commit(struct drm_crtc *crtc) 185static void exynos_drm_crtc_commit(struct drm_crtc *crtc)
187{ 186{
187 struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
188
188 DRM_DEBUG_KMS("%s\n", __FILE__); 189 DRM_DEBUG_KMS("%s\n", __FILE__);
189 190
190 /* drm framework doesn't check NULL. */ 191 exynos_drm_fn_encoder(crtc, &exynos_crtc->pipe,
192 exynos_drm_encoder_crtc_commit);
191} 193}
192 194
193static bool 195static bool
diff --git a/drivers/gpu/drm/exynos/exynos_drm_crtc.h b/drivers/gpu/drm/exynos/exynos_drm_crtc.h
index c584042d6d2..25f72a62cb8 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_crtc.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_crtc.h
@@ -35,4 +35,29 @@ int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr);
35int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc); 35int exynos_drm_crtc_enable_vblank(struct drm_device *dev, int crtc);
36void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc); 36void exynos_drm_crtc_disable_vblank(struct drm_device *dev, int crtc);
37 37
38/*
39 * Exynos specific crtc postion structure.
40 *
41 * @fb_x: offset x on a framebuffer to be displyed
42 * - the unit is screen coordinates.
43 * @fb_y: offset y on a framebuffer to be displayed
44 * - the unit is screen coordinates.
45 * @crtc_x: offset x on hardware screen.
46 * @crtc_y: offset y on hardware screen.
47 * @crtc_w: width of hardware screen.
48 * @crtc_h: height of hardware screen.
49 */
50struct exynos_drm_crtc_pos {
51 unsigned int fb_x;
52 unsigned int fb_y;
53 unsigned int crtc_x;
54 unsigned int crtc_y;
55 unsigned int crtc_w;
56 unsigned int crtc_h;
57};
58
59int exynos_drm_overlay_update(struct exynos_drm_overlay *overlay,
60 struct drm_framebuffer *fb,
61 struct drm_display_mode *mode,
62 struct exynos_drm_crtc_pos *pos);
38#endif 63#endif
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 83810cbe3c1..53e2216de61 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -27,6 +27,7 @@
27 27
28#include "drmP.h" 28#include "drmP.h"
29#include "drm.h" 29#include "drm.h"
30#include "drm_crtc_helper.h"
30 31
31#include <drm/exynos_drm.h> 32#include <drm/exynos_drm.h>
32 33
@@ -61,6 +62,9 @@ static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
61 62
62 drm_mode_config_init(dev); 63 drm_mode_config_init(dev);
63 64
65 /* init kms poll for handling hpd */
66 drm_kms_helper_poll_init(dev);
67
64 exynos_drm_mode_config_init(dev); 68 exynos_drm_mode_config_init(dev);
65 69
66 /* 70 /*
@@ -116,6 +120,7 @@ static int exynos_drm_unload(struct drm_device *dev)
116 exynos_drm_fbdev_fini(dev); 120 exynos_drm_fbdev_fini(dev);
117 exynos_drm_device_unregister(dev); 121 exynos_drm_device_unregister(dev);
118 drm_vblank_cleanup(dev); 122 drm_vblank_cleanup(dev);
123 drm_kms_helper_poll_fini(dev);
119 drm_mode_config_cleanup(dev); 124 drm_mode_config_cleanup(dev);
120 kfree(dev->dev_private); 125 kfree(dev->dev_private);
121 126
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h
index c03683f2ae7..5e02e6ecc2e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h
@@ -29,6 +29,7 @@
29#ifndef _EXYNOS_DRM_DRV_H_ 29#ifndef _EXYNOS_DRM_DRV_H_
30#define _EXYNOS_DRM_DRV_H_ 30#define _EXYNOS_DRM_DRV_H_
31 31
32#include <linux/module.h>
32#include "drm.h" 33#include "drm.h"
33 34
34#define MAX_CRTC 2 35#define MAX_CRTC 2
@@ -79,8 +80,8 @@ struct exynos_drm_overlay_ops {
79 * @scan_flag: interlace or progressive way. 80 * @scan_flag: interlace or progressive way.
80 * (it could be DRM_MODE_FLAG_*) 81 * (it could be DRM_MODE_FLAG_*)
81 * @bpp: pixel size.(in bit) 82 * @bpp: pixel size.(in bit)
82 * @paddr: bus(accessed by dma) physical memory address to this overlay 83 * @dma_addr: bus(accessed by dma) address to the memory region allocated
83 * and this is physically continuous. 84 * for a overlay.
84 * @vaddr: virtual memory addresss to this overlay. 85 * @vaddr: virtual memory addresss to this overlay.
85 * @default_win: a window to be enabled. 86 * @default_win: a window to be enabled.
86 * @color_key: color key on or off. 87 * @color_key: color key on or off.
@@ -108,7 +109,7 @@ struct exynos_drm_overlay {
108 unsigned int scan_flag; 109 unsigned int scan_flag;
109 unsigned int bpp; 110 unsigned int bpp;
110 unsigned int pitch; 111 unsigned int pitch;
111 dma_addr_t paddr; 112 dma_addr_t dma_addr;
112 void __iomem *vaddr; 113 void __iomem *vaddr;
113 114
114 bool default_win; 115 bool default_win;
@@ -130,7 +131,7 @@ struct exynos_drm_overlay {
130 * @check_timing: check if timing is valid or not. 131 * @check_timing: check if timing is valid or not.
131 * @power_on: display device on or off. 132 * @power_on: display device on or off.
132 */ 133 */
133struct exynos_drm_display { 134struct exynos_drm_display_ops {
134 enum exynos_drm_output_type type; 135 enum exynos_drm_output_type type;
135 bool (*is_connected)(struct device *dev); 136 bool (*is_connected)(struct device *dev);
136 int (*get_edid)(struct device *dev, struct drm_connector *connector, 137 int (*get_edid)(struct device *dev, struct drm_connector *connector,
@@ -146,12 +147,14 @@ struct exynos_drm_display {
146 * @mode_set: convert drm_display_mode to hw specific display mode and 147 * @mode_set: convert drm_display_mode to hw specific display mode and
147 * would be called by encoder->mode_set(). 148 * would be called by encoder->mode_set().
148 * @commit: set current hw specific display mode to hw. 149 * @commit: set current hw specific display mode to hw.
150 * @disable: disable hardware specific display mode.
149 * @enable_vblank: specific driver callback for enabling vblank interrupt. 151 * @enable_vblank: specific driver callback for enabling vblank interrupt.
150 * @disable_vblank: specific driver callback for disabling vblank interrupt. 152 * @disable_vblank: specific driver callback for disabling vblank interrupt.
151 */ 153 */
152struct exynos_drm_manager_ops { 154struct exynos_drm_manager_ops {
153 void (*mode_set)(struct device *subdrv_dev, void *mode); 155 void (*mode_set)(struct device *subdrv_dev, void *mode);
154 void (*commit)(struct device *subdrv_dev); 156 void (*commit)(struct device *subdrv_dev);
157 void (*disable)(struct device *subdrv_dev);
155 int (*enable_vblank)(struct device *subdrv_dev); 158 int (*enable_vblank)(struct device *subdrv_dev);
156 void (*disable_vblank)(struct device *subdrv_dev); 159 void (*disable_vblank)(struct device *subdrv_dev);
157}; 160};
@@ -178,7 +181,7 @@ struct exynos_drm_manager {
178 int pipe; 181 int pipe;
179 struct exynos_drm_manager_ops *ops; 182 struct exynos_drm_manager_ops *ops;
180 struct exynos_drm_overlay_ops *overlay_ops; 183 struct exynos_drm_overlay_ops *overlay_ops;
181 struct exynos_drm_display *display; 184 struct exynos_drm_display_ops *display_ops;
182}; 185};
183 186
184/* 187/*
diff --git a/drivers/gpu/drm/exynos/exynos_drm_encoder.c b/drivers/gpu/drm/exynos/exynos_drm_encoder.c
index 7cf6fa86a67..153061415ba 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_encoder.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_encoder.c
@@ -53,15 +53,36 @@ static void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode)
53 struct drm_device *dev = encoder->dev; 53 struct drm_device *dev = encoder->dev;
54 struct drm_connector *connector; 54 struct drm_connector *connector;
55 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); 55 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
56 struct exynos_drm_manager_ops *manager_ops = manager->ops;
56 57
57 DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode); 58 DRM_DEBUG_KMS("%s, encoder dpms: %d\n", __FILE__, mode);
58 59
60 switch (mode) {
61 case DRM_MODE_DPMS_ON:
62 if (manager_ops && manager_ops->commit)
63 manager_ops->commit(manager->dev);
64 break;
65 case DRM_MODE_DPMS_STANDBY:
66 case DRM_MODE_DPMS_SUSPEND:
67 case DRM_MODE_DPMS_OFF:
68 /* TODO */
69 if (manager_ops && manager_ops->disable)
70 manager_ops->disable(manager->dev);
71 break;
72 default:
73 DRM_ERROR("unspecified mode %d\n", mode);
74 break;
75 }
76
59 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 77 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
60 if (connector->encoder == encoder) { 78 if (connector->encoder == encoder) {
61 struct exynos_drm_display *display = manager->display; 79 struct exynos_drm_display_ops *display_ops =
80 manager->display_ops;
62 81
63 if (display && display->power_on) 82 DRM_DEBUG_KMS("connector[%d] dpms[%d]\n",
64 display->power_on(manager->dev, mode); 83 connector->base.id, mode);
84 if (display_ops && display_ops->power_on)
85 display_ops->power_on(manager->dev, mode);
65 } 86 }
66 } 87 }
67} 88}
@@ -116,15 +137,11 @@ static void exynos_drm_encoder_commit(struct drm_encoder *encoder)
116{ 137{
117 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder); 138 struct exynos_drm_manager *manager = exynos_drm_get_manager(encoder);
118 struct exynos_drm_manager_ops *manager_ops = manager->ops; 139 struct exynos_drm_manager_ops *manager_ops = manager->ops;
119 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
120 140
121 DRM_DEBUG_KMS("%s\n", __FILE__); 141 DRM_DEBUG_KMS("%s\n", __FILE__);
122 142
123 if (manager_ops && manager_ops->commit) 143 if (manager_ops && manager_ops->commit)
124 manager_ops->commit(manager->dev); 144 manager_ops->commit(manager->dev);
125
126 if (overlay_ops && overlay_ops->commit)
127 overlay_ops->commit(manager->dev);
128} 145}
129 146
130static struct drm_crtc * 147static struct drm_crtc *
@@ -208,10 +225,23 @@ void exynos_drm_fn_encoder(struct drm_crtc *crtc, void *data,
208{ 225{
209 struct drm_device *dev = crtc->dev; 226 struct drm_device *dev = crtc->dev;
210 struct drm_encoder *encoder; 227 struct drm_encoder *encoder;
228 struct exynos_drm_private *private = dev->dev_private;
229 struct exynos_drm_manager *manager;
211 230
212 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 231 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
213 if (encoder->crtc != crtc) 232 /*
214 continue; 233 * if crtc is detached from encoder, check pipe,
234 * otherwise check crtc attached to encoder
235 */
236 if (!encoder->crtc) {
237 manager = to_exynos_encoder(encoder)->manager;
238 if (manager->pipe < 0 ||
239 private->crtc[manager->pipe] != crtc)
240 continue;
241 } else {
242 if (encoder->crtc != crtc)
243 continue;
244 }
215 245
216 fn(encoder, data); 246 fn(encoder, data);
217 } 247 }
@@ -250,8 +280,18 @@ void exynos_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data)
250 struct exynos_drm_manager *manager = 280 struct exynos_drm_manager *manager =
251 to_exynos_encoder(encoder)->manager; 281 to_exynos_encoder(encoder)->manager;
252 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops; 282 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
283 int crtc = *(int *)data;
284
285 DRM_DEBUG_KMS("%s\n", __FILE__);
286
287 /*
288 * when crtc is detached from encoder, this pipe is used
289 * to select manager operation
290 */
291 manager->pipe = crtc;
253 292
254 overlay_ops->commit(manager->dev); 293 if (overlay_ops && overlay_ops->commit)
294 overlay_ops->commit(manager->dev);
255} 295}
256 296
257void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data) 297void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data)
@@ -261,7 +301,28 @@ void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data)
261 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops; 301 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
262 struct exynos_drm_overlay *overlay = data; 302 struct exynos_drm_overlay *overlay = data;
263 303
264 overlay_ops->mode_set(manager->dev, overlay); 304 if (overlay_ops && overlay_ops->mode_set)
305 overlay_ops->mode_set(manager->dev, overlay);
306}
307
308void exynos_drm_encoder_crtc_disable(struct drm_encoder *encoder, void *data)
309{
310 struct exynos_drm_manager *manager =
311 to_exynos_encoder(encoder)->manager;
312 struct exynos_drm_overlay_ops *overlay_ops = manager->overlay_ops;
313
314 DRM_DEBUG_KMS("\n");
315
316 if (overlay_ops && overlay_ops->disable)
317 overlay_ops->disable(manager->dev);
318
319 /*
320 * crtc is already detached from encoder and last
321 * function for detaching is properly done, so
322 * clear pipe from manager to prevent repeated call
323 */
324 if (!encoder->crtc)
325 manager->pipe = -1;
265} 326}
266 327
267MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); 328MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
diff --git a/drivers/gpu/drm/exynos/exynos_drm_encoder.h b/drivers/gpu/drm/exynos/exynos_drm_encoder.h
index 5ecd645d06a..a22acfbf0e4 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_encoder.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_encoder.h
@@ -41,5 +41,6 @@ void exynos_drm_enable_vblank(struct drm_encoder *encoder, void *data);
41void exynos_drm_disable_vblank(struct drm_encoder *encoder, void *data); 41void exynos_drm_disable_vblank(struct drm_encoder *encoder, void *data);
42void exynos_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data); 42void exynos_drm_encoder_crtc_commit(struct drm_encoder *encoder, void *data);
43void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data); 43void exynos_drm_encoder_crtc_mode_set(struct drm_encoder *encoder, void *data);
44void exynos_drm_encoder_crtc_disable(struct drm_encoder *encoder, void *data);
44 45
45#endif 46#endif
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c b/drivers/gpu/drm/exynos/exynos_drm_fb.c
index 48d29cfd524..5bf4a1ac7f8 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fb.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c
@@ -29,7 +29,9 @@
29#include "drmP.h" 29#include "drmP.h"
30#include "drm_crtc.h" 30#include "drm_crtc.h"
31#include "drm_crtc_helper.h" 31#include "drm_crtc_helper.h"
32#include "drm_fb_helper.h"
32 33
34#include "exynos_drm_drv.h"
33#include "exynos_drm_fb.h" 35#include "exynos_drm_fb.h"
34#include "exynos_drm_buf.h" 36#include "exynos_drm_buf.h"
35#include "exynos_drm_gem.h" 37#include "exynos_drm_gem.h"
@@ -41,14 +43,14 @@
41 * 43 *
42 * @fb: drm framebuffer obejct. 44 * @fb: drm framebuffer obejct.
43 * @exynos_gem_obj: exynos specific gem object containing a gem object. 45 * @exynos_gem_obj: exynos specific gem object containing a gem object.
44 * @entry: pointer to exynos drm buffer entry object. 46 * @buffer: pointer to exynos_drm_gem_buffer object.
45 * - containing only the information to physically continuous memory 47 * - contain the memory information to memory region allocated
46 * region allocated at default framebuffer creation. 48 * at default framebuffer creation.
47 */ 49 */
48struct exynos_drm_fb { 50struct exynos_drm_fb {
49 struct drm_framebuffer fb; 51 struct drm_framebuffer fb;
50 struct exynos_drm_gem_obj *exynos_gem_obj; 52 struct exynos_drm_gem_obj *exynos_gem_obj;
51 struct exynos_drm_buf_entry *entry; 53 struct exynos_drm_gem_buf *buffer;
52}; 54};
53 55
54static void exynos_drm_fb_destroy(struct drm_framebuffer *fb) 56static void exynos_drm_fb_destroy(struct drm_framebuffer *fb)
@@ -63,8 +65,8 @@ static void exynos_drm_fb_destroy(struct drm_framebuffer *fb)
63 * default framebuffer has no gem object so 65 * default framebuffer has no gem object so
64 * a buffer of the default framebuffer should be released at here. 66 * a buffer of the default framebuffer should be released at here.
65 */ 67 */
66 if (!exynos_fb->exynos_gem_obj && exynos_fb->entry) 68 if (!exynos_fb->exynos_gem_obj && exynos_fb->buffer)
67 exynos_drm_buf_destroy(fb->dev, exynos_fb->entry); 69 exynos_drm_buf_destroy(fb->dev, exynos_fb->buffer);
68 70
69 kfree(exynos_fb); 71 kfree(exynos_fb);
70 exynos_fb = NULL; 72 exynos_fb = NULL;
@@ -143,29 +145,29 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
143 */ 145 */
144 if (!mode_cmd->handle) { 146 if (!mode_cmd->handle) {
145 if (!file_priv) { 147 if (!file_priv) {
146 struct exynos_drm_buf_entry *entry; 148 struct exynos_drm_gem_buf *buffer;
147 149
148 /* 150 /*
149 * in case that file_priv is NULL, it allocates 151 * in case that file_priv is NULL, it allocates
150 * only buffer and this buffer would be used 152 * only buffer and this buffer would be used
151 * for default framebuffer. 153 * for default framebuffer.
152 */ 154 */
153 entry = exynos_drm_buf_create(dev, size); 155 buffer = exynos_drm_buf_create(dev, size);
154 if (IS_ERR(entry)) { 156 if (IS_ERR(buffer)) {
155 ret = PTR_ERR(entry); 157 ret = PTR_ERR(buffer);
156 goto err_buffer; 158 goto err_buffer;
157 } 159 }
158 160
159 exynos_fb->entry = entry; 161 exynos_fb->buffer = buffer;
160 162
161 DRM_LOG_KMS("default fb: paddr = 0x%lx, size = 0x%x\n", 163 DRM_LOG_KMS("default: dma_addr = 0x%lx, size = 0x%x\n",
162 (unsigned long)entry->paddr, size); 164 (unsigned long)buffer->dma_addr, size);
163 165
164 goto out; 166 goto out;
165 } else { 167 } else {
166 exynos_gem_obj = exynos_drm_gem_create(file_priv, dev, 168 exynos_gem_obj = exynos_drm_gem_create(dev, file_priv,
167 size, 169 &mode_cmd->handle,
168 &mode_cmd->handle); 170 size);
169 if (IS_ERR(exynos_gem_obj)) { 171 if (IS_ERR(exynos_gem_obj)) {
170 ret = PTR_ERR(exynos_gem_obj); 172 ret = PTR_ERR(exynos_gem_obj);
171 goto err_buffer; 173 goto err_buffer;
@@ -189,10 +191,10 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
189 * so that default framebuffer has no its own gem object, 191 * so that default framebuffer has no its own gem object,
190 * only its own buffer object. 192 * only its own buffer object.
191 */ 193 */
192 exynos_fb->entry = exynos_gem_obj->entry; 194 exynos_fb->buffer = exynos_gem_obj->buffer;
193 195
194 DRM_LOG_KMS("paddr = 0x%lx, size = 0x%x, gem object = 0x%x\n", 196 DRM_LOG_KMS("dma_addr = 0x%lx, size = 0x%x, gem object = 0x%x\n",
195 (unsigned long)exynos_fb->entry->paddr, size, 197 (unsigned long)exynos_fb->buffer->dma_addr, size,
196 (unsigned int)&exynos_gem_obj->base); 198 (unsigned int)&exynos_gem_obj->base);
197 199
198out: 200out:
@@ -220,26 +222,36 @@ struct drm_framebuffer *exynos_drm_fb_create(struct drm_device *dev,
220 return exynos_drm_fb_init(file_priv, dev, mode_cmd); 222 return exynos_drm_fb_init(file_priv, dev, mode_cmd);
221} 223}
222 224
223struct exynos_drm_buf_entry *exynos_drm_fb_get_buf(struct drm_framebuffer *fb) 225struct exynos_drm_gem_buf *exynos_drm_fb_get_buf(struct drm_framebuffer *fb)
224{ 226{
225 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); 227 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
226 struct exynos_drm_buf_entry *entry; 228 struct exynos_drm_gem_buf *buffer;
227 229
228 DRM_DEBUG_KMS("%s\n", __FILE__); 230 DRM_DEBUG_KMS("%s\n", __FILE__);
229 231
230 entry = exynos_fb->entry; 232 buffer = exynos_fb->buffer;
231 if (!entry) 233 if (!buffer)
232 return NULL; 234 return NULL;
233 235
234 DRM_DEBUG_KMS("vaddr = 0x%lx, paddr = 0x%lx\n", 236 DRM_DEBUG_KMS("vaddr = 0x%lx, dma_addr = 0x%lx\n",
235 (unsigned long)entry->vaddr, 237 (unsigned long)buffer->kvaddr,
236 (unsigned long)entry->paddr); 238 (unsigned long)buffer->dma_addr);
237 239
238 return entry; 240 return buffer;
241}
242
243static void exynos_drm_output_poll_changed(struct drm_device *dev)
244{
245 struct exynos_drm_private *private = dev->dev_private;
246 struct drm_fb_helper *fb_helper = private->fb_helper;
247
248 if (fb_helper)
249 drm_fb_helper_hotplug_event(fb_helper);
239} 250}
240 251
241static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = { 252static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
242 .fb_create = exynos_drm_fb_create, 253 .fb_create = exynos_drm_fb_create,
254 .output_poll_changed = exynos_drm_output_poll_changed,
243}; 255};
244 256
245void exynos_drm_mode_config_init(struct drm_device *dev) 257void exynos_drm_mode_config_init(struct drm_device *dev)
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
index 1f4b3d1a771..836f4100818 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fbdev.c
@@ -33,6 +33,7 @@
33 33
34#include "exynos_drm_drv.h" 34#include "exynos_drm_drv.h"
35#include "exynos_drm_fb.h" 35#include "exynos_drm_fb.h"
36#include "exynos_drm_gem.h"
36#include "exynos_drm_buf.h" 37#include "exynos_drm_buf.h"
37 38
38#define MAX_CONNECTOR 4 39#define MAX_CONNECTOR 4
@@ -85,15 +86,13 @@ static struct fb_ops exynos_drm_fb_ops = {
85}; 86};
86 87
87static int exynos_drm_fbdev_update(struct drm_fb_helper *helper, 88static int exynos_drm_fbdev_update(struct drm_fb_helper *helper,
88 struct drm_framebuffer *fb, 89 struct drm_framebuffer *fb)
89 unsigned int fb_width,
90 unsigned int fb_height)
91{ 90{
92 struct fb_info *fbi = helper->fbdev; 91 struct fb_info *fbi = helper->fbdev;
93 struct drm_device *dev = helper->dev; 92 struct drm_device *dev = helper->dev;
94 struct exynos_drm_fbdev *exynos_fb = to_exynos_fbdev(helper); 93 struct exynos_drm_fbdev *exynos_fb = to_exynos_fbdev(helper);
95 struct exynos_drm_buf_entry *entry; 94 struct exynos_drm_gem_buf *buffer;
96 unsigned int size = fb_width * fb_height * (fb->bits_per_pixel >> 3); 95 unsigned int size = fb->width * fb->height * (fb->bits_per_pixel >> 3);
97 unsigned long offset; 96 unsigned long offset;
98 97
99 DRM_DEBUG_KMS("%s\n", __FILE__); 98 DRM_DEBUG_KMS("%s\n", __FILE__);
@@ -101,20 +100,20 @@ static int exynos_drm_fbdev_update(struct drm_fb_helper *helper,
101 exynos_fb->fb = fb; 100 exynos_fb->fb = fb;
102 101
103 drm_fb_helper_fill_fix(fbi, fb->pitch, fb->depth); 102 drm_fb_helper_fill_fix(fbi, fb->pitch, fb->depth);
104 drm_fb_helper_fill_var(fbi, helper, fb_width, fb_height); 103 drm_fb_helper_fill_var(fbi, helper, fb->width, fb->height);
105 104
106 entry = exynos_drm_fb_get_buf(fb); 105 buffer = exynos_drm_fb_get_buf(fb);
107 if (!entry) { 106 if (!buffer) {
108 DRM_LOG_KMS("entry is null.\n"); 107 DRM_LOG_KMS("buffer is null.\n");
109 return -EFAULT; 108 return -EFAULT;
110 } 109 }
111 110
112 offset = fbi->var.xoffset * (fb->bits_per_pixel >> 3); 111 offset = fbi->var.xoffset * (fb->bits_per_pixel >> 3);
113 offset += fbi->var.yoffset * fb->pitch; 112 offset += fbi->var.yoffset * fb->pitch;
114 113
115 dev->mode_config.fb_base = entry->paddr; 114 dev->mode_config.fb_base = (resource_size_t)buffer->dma_addr;
116 fbi->screen_base = entry->vaddr + offset; 115 fbi->screen_base = buffer->kvaddr + offset;
117 fbi->fix.smem_start = entry->paddr + offset; 116 fbi->fix.smem_start = (unsigned long)(buffer->dma_addr + offset);
118 fbi->screen_size = size; 117 fbi->screen_size = size;
119 fbi->fix.smem_len = size; 118 fbi->fix.smem_len = size;
120 119
@@ -171,8 +170,7 @@ static int exynos_drm_fbdev_create(struct drm_fb_helper *helper,
171 goto out; 170 goto out;
172 } 171 }
173 172
174 ret = exynos_drm_fbdev_update(helper, helper->fb, sizes->fb_width, 173 ret = exynos_drm_fbdev_update(helper, helper->fb);
175 sizes->fb_height);
176 if (ret < 0) 174 if (ret < 0)
177 fb_dealloc_cmap(&fbi->cmap); 175 fb_dealloc_cmap(&fbi->cmap);
178 176
@@ -235,8 +233,7 @@ static int exynos_drm_fbdev_recreate(struct drm_fb_helper *helper,
235 } 233 }
236 234
237 helper->fb = exynos_fbdev->fb; 235 helper->fb = exynos_fbdev->fb;
238 return exynos_drm_fbdev_update(helper, helper->fb, sizes->fb_width, 236 return exynos_drm_fbdev_update(helper, helper->fb);
239 sizes->fb_height);
240} 237}
241 238
242static int exynos_drm_fbdev_probe(struct drm_fb_helper *helper, 239static int exynos_drm_fbdev_probe(struct drm_fb_helper *helper,
@@ -405,6 +402,18 @@ int exynos_drm_fbdev_reinit(struct drm_device *dev)
405 fb_helper = private->fb_helper; 402 fb_helper = private->fb_helper;
406 403
407 if (fb_helper) { 404 if (fb_helper) {
405 struct list_head temp_list;
406
407 INIT_LIST_HEAD(&temp_list);
408
409 /*
410 * fb_helper is reintialized but kernel fb is reused
411 * so kernel_fb_list need to be backuped and restored
412 */
413 if (!list_empty(&fb_helper->kernel_fb_list))
414 list_replace_init(&fb_helper->kernel_fb_list,
415 &temp_list);
416
408 drm_fb_helper_fini(fb_helper); 417 drm_fb_helper_fini(fb_helper);
409 418
410 ret = drm_fb_helper_init(dev, fb_helper, 419 ret = drm_fb_helper_init(dev, fb_helper,
@@ -414,6 +423,9 @@ int exynos_drm_fbdev_reinit(struct drm_device *dev)
414 return ret; 423 return ret;
415 } 424 }
416 425
426 if (!list_empty(&temp_list))
427 list_replace(&temp_list, &fb_helper->kernel_fb_list);
428
417 ret = drm_fb_helper_single_add_all_connectors(fb_helper); 429 ret = drm_fb_helper_single_add_all_connectors(fb_helper);
418 if (ret < 0) { 430 if (ret < 0) {
419 DRM_ERROR("failed to add fb helper to connectors\n"); 431 DRM_ERROR("failed to add fb helper to connectors\n");
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
index 4659c88cdd9..db3b3d9e731 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
@@ -64,7 +64,7 @@ struct fimd_win_data {
64 unsigned int fb_width; 64 unsigned int fb_width;
65 unsigned int fb_height; 65 unsigned int fb_height;
66 unsigned int bpp; 66 unsigned int bpp;
67 dma_addr_t paddr; 67 dma_addr_t dma_addr;
68 void __iomem *vaddr; 68 void __iomem *vaddr;
69 unsigned int buf_offsize; 69 unsigned int buf_offsize;
70 unsigned int line_size; /* bytes */ 70 unsigned int line_size; /* bytes */
@@ -124,7 +124,7 @@ static int fimd_display_power_on(struct device *dev, int mode)
124 return 0; 124 return 0;
125} 125}
126 126
127static struct exynos_drm_display fimd_display = { 127static struct exynos_drm_display_ops fimd_display_ops = {
128 .type = EXYNOS_DISPLAY_TYPE_LCD, 128 .type = EXYNOS_DISPLAY_TYPE_LCD,
129 .is_connected = fimd_display_is_connected, 129 .is_connected = fimd_display_is_connected,
130 .get_timing = fimd_get_timing, 130 .get_timing = fimd_get_timing,
@@ -177,6 +177,40 @@ static void fimd_commit(struct device *dev)
177 writel(val, ctx->regs + VIDCON0); 177 writel(val, ctx->regs + VIDCON0);
178} 178}
179 179
180static void fimd_disable(struct device *dev)
181{
182 struct fimd_context *ctx = get_fimd_context(dev);
183 struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
184 struct drm_device *drm_dev = subdrv->drm_dev;
185 struct exynos_drm_manager *manager = &subdrv->manager;
186 u32 val;
187
188 DRM_DEBUG_KMS("%s\n", __FILE__);
189
190 /* fimd dma off */
191 val = readl(ctx->regs + VIDCON0);
192 val &= ~(VIDCON0_ENVID | VIDCON0_ENVID_F);
193 writel(val, ctx->regs + VIDCON0);
194
195 /*
196 * if vblank is enabled status with dma off then
197 * it disables vsync interrupt.
198 */
199 if (drm_dev->vblank_enabled[manager->pipe] &&
200 atomic_read(&drm_dev->vblank_refcount[manager->pipe])) {
201 drm_vblank_put(drm_dev, manager->pipe);
202
203 /*
204 * if vblank_disable_allowed is 0 then disable
205 * vsync interrupt right now else the vsync interrupt
206 * would be disabled by drm timer once a current process
207 * gives up ownershop of vblank event.
208 */
209 if (!drm_dev->vblank_disable_allowed)
210 drm_vblank_off(drm_dev, manager->pipe);
211 }
212}
213
180static int fimd_enable_vblank(struct device *dev) 214static int fimd_enable_vblank(struct device *dev)
181{ 215{
182 struct fimd_context *ctx = get_fimd_context(dev); 216 struct fimd_context *ctx = get_fimd_context(dev);
@@ -220,6 +254,7 @@ static void fimd_disable_vblank(struct device *dev)
220 254
221static struct exynos_drm_manager_ops fimd_manager_ops = { 255static struct exynos_drm_manager_ops fimd_manager_ops = {
222 .commit = fimd_commit, 256 .commit = fimd_commit,
257 .disable = fimd_disable,
223 .enable_vblank = fimd_enable_vblank, 258 .enable_vblank = fimd_enable_vblank,
224 .disable_vblank = fimd_disable_vblank, 259 .disable_vblank = fimd_disable_vblank,
225}; 260};
@@ -251,7 +286,7 @@ static void fimd_win_mode_set(struct device *dev,
251 win_data->ovl_height = overlay->crtc_height; 286 win_data->ovl_height = overlay->crtc_height;
252 win_data->fb_width = overlay->fb_width; 287 win_data->fb_width = overlay->fb_width;
253 win_data->fb_height = overlay->fb_height; 288 win_data->fb_height = overlay->fb_height;
254 win_data->paddr = overlay->paddr + offset; 289 win_data->dma_addr = overlay->dma_addr + offset;
255 win_data->vaddr = overlay->vaddr + offset; 290 win_data->vaddr = overlay->vaddr + offset;
256 win_data->bpp = overlay->bpp; 291 win_data->bpp = overlay->bpp;
257 win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) * 292 win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) *
@@ -263,7 +298,7 @@ static void fimd_win_mode_set(struct device *dev,
263 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", 298 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
264 win_data->ovl_width, win_data->ovl_height); 299 win_data->ovl_width, win_data->ovl_height);
265 DRM_DEBUG_KMS("paddr = 0x%lx, vaddr = 0x%lx\n", 300 DRM_DEBUG_KMS("paddr = 0x%lx, vaddr = 0x%lx\n",
266 (unsigned long)win_data->paddr, 301 (unsigned long)win_data->dma_addr,
267 (unsigned long)win_data->vaddr); 302 (unsigned long)win_data->vaddr);
268 DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n", 303 DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n",
269 overlay->fb_width, overlay->crtc_width); 304 overlay->fb_width, overlay->crtc_width);
@@ -376,16 +411,16 @@ static void fimd_win_commit(struct device *dev)
376 writel(val, ctx->regs + SHADOWCON); 411 writel(val, ctx->regs + SHADOWCON);
377 412
378 /* buffer start address */ 413 /* buffer start address */
379 val = win_data->paddr; 414 val = (unsigned long)win_data->dma_addr;
380 writel(val, ctx->regs + VIDWx_BUF_START(win, 0)); 415 writel(val, ctx->regs + VIDWx_BUF_START(win, 0));
381 416
382 /* buffer end address */ 417 /* buffer end address */
383 size = win_data->fb_width * win_data->ovl_height * (win_data->bpp >> 3); 418 size = win_data->fb_width * win_data->ovl_height * (win_data->bpp >> 3);
384 val = win_data->paddr + size; 419 val = (unsigned long)(win_data->dma_addr + size);
385 writel(val, ctx->regs + VIDWx_BUF_END(win, 0)); 420 writel(val, ctx->regs + VIDWx_BUF_END(win, 0));
386 421
387 DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n", 422 DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n",
388 (unsigned long)win_data->paddr, val, size); 423 (unsigned long)win_data->dma_addr, val, size);
389 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", 424 DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n",
390 win_data->ovl_width, win_data->ovl_height); 425 win_data->ovl_width, win_data->ovl_height);
391 426
@@ -447,7 +482,6 @@ static void fimd_win_commit(struct device *dev)
447static void fimd_win_disable(struct device *dev) 482static void fimd_win_disable(struct device *dev)
448{ 483{
449 struct fimd_context *ctx = get_fimd_context(dev); 484 struct fimd_context *ctx = get_fimd_context(dev);
450 struct fimd_win_data *win_data;
451 int win = ctx->default_win; 485 int win = ctx->default_win;
452 u32 val; 486 u32 val;
453 487
@@ -456,8 +490,6 @@ static void fimd_win_disable(struct device *dev)
456 if (win < 0 || win > WINDOWS_NR) 490 if (win < 0 || win > WINDOWS_NR)
457 return; 491 return;
458 492
459 win_data = &ctx->win_data[win];
460
461 /* protect windows */ 493 /* protect windows */
462 val = readl(ctx->regs + SHADOWCON); 494 val = readl(ctx->regs + SHADOWCON);
463 val |= SHADOWCON_WINx_PROTECT(win); 495 val |= SHADOWCON_WINx_PROTECT(win);
@@ -528,6 +560,16 @@ static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
528 /* VSYNC interrupt */ 560 /* VSYNC interrupt */
529 writel(VIDINTCON1_INT_FRAME, ctx->regs + VIDINTCON1); 561 writel(VIDINTCON1_INT_FRAME, ctx->regs + VIDINTCON1);
530 562
563 /*
564 * in case that vblank_disable_allowed is 1, it could induce
565 * the problem that manager->pipe could be -1 because with
566 * disable callback, vsync interrupt isn't disabled and at this moment,
567 * vsync interrupt could occur. the vsync interrupt would be disabled
568 * by timer handler later.
569 */
570 if (manager->pipe == -1)
571 return IRQ_HANDLED;
572
531 drm_handle_vblank(drm_dev, manager->pipe); 573 drm_handle_vblank(drm_dev, manager->pipe);
532 fimd_finish_pageflip(drm_dev, manager->pipe); 574 fimd_finish_pageflip(drm_dev, manager->pipe);
533 575
@@ -548,13 +590,6 @@ static int fimd_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
548 */ 590 */
549 drm_dev->irq_enabled = 1; 591 drm_dev->irq_enabled = 1;
550 592
551 /*
552 * with vblank_disable_allowed = 1, vblank interrupt will be disabled
553 * by drm timer once a current process gives up ownership of
554 * vblank event.(drm_vblank_put function was called)
555 */
556 drm_dev->vblank_disable_allowed = 1;
557
558 return 0; 593 return 0;
559} 594}
560 595
@@ -731,7 +766,7 @@ static int __devinit fimd_probe(struct platform_device *pdev)
731 subdrv->manager.pipe = -1; 766 subdrv->manager.pipe = -1;
732 subdrv->manager.ops = &fimd_manager_ops; 767 subdrv->manager.ops = &fimd_manager_ops;
733 subdrv->manager.overlay_ops = &fimd_overlay_ops; 768 subdrv->manager.overlay_ops = &fimd_overlay_ops;
734 subdrv->manager.display = &fimd_display; 769 subdrv->manager.display_ops = &fimd_display_ops;
735 subdrv->manager.dev = dev; 770 subdrv->manager.dev = dev;
736 771
737 platform_set_drvdata(pdev, ctx); 772 platform_set_drvdata(pdev, ctx);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index a8e7a88906e..aba0fe47f7e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -62,40 +62,28 @@ static unsigned int get_gem_mmap_offset(struct drm_gem_object *obj)
62 return (unsigned int)obj->map_list.hash.key << PAGE_SHIFT; 62 return (unsigned int)obj->map_list.hash.key << PAGE_SHIFT;
63} 63}
64 64
65struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_file *file_priv, 65static struct exynos_drm_gem_obj
66 struct drm_device *dev, unsigned int size, 66 *exynos_drm_gem_init(struct drm_device *drm_dev,
67 unsigned int *handle) 67 struct drm_file *file_priv, unsigned int *handle,
68 unsigned int size)
68{ 69{
69 struct exynos_drm_gem_obj *exynos_gem_obj; 70 struct exynos_drm_gem_obj *exynos_gem_obj;
70 struct exynos_drm_buf_entry *entry;
71 struct drm_gem_object *obj; 71 struct drm_gem_object *obj;
72 int ret; 72 int ret;
73 73
74 DRM_DEBUG_KMS("%s\n", __FILE__);
75
76 size = roundup(size, PAGE_SIZE);
77
78 exynos_gem_obj = kzalloc(sizeof(*exynos_gem_obj), GFP_KERNEL); 74 exynos_gem_obj = kzalloc(sizeof(*exynos_gem_obj), GFP_KERNEL);
79 if (!exynos_gem_obj) { 75 if (!exynos_gem_obj) {
80 DRM_ERROR("failed to allocate exynos gem object.\n"); 76 DRM_ERROR("failed to allocate exynos gem object.\n");
81 return ERR_PTR(-ENOMEM); 77 return ERR_PTR(-ENOMEM);
82 } 78 }
83 79
84 /* allocate the new buffer object and memory region. */
85 entry = exynos_drm_buf_create(dev, size);
86 if (!entry) {
87 kfree(exynos_gem_obj);
88 return ERR_PTR(-ENOMEM);
89 }
90
91 exynos_gem_obj->entry = entry;
92
93 obj = &exynos_gem_obj->base; 80 obj = &exynos_gem_obj->base;
94 81
95 ret = drm_gem_object_init(dev, obj, size); 82 ret = drm_gem_object_init(drm_dev, obj, size);
96 if (ret < 0) { 83 if (ret < 0) {
97 DRM_ERROR("failed to initailize gem object.\n"); 84 DRM_ERROR("failed to initialize gem object.\n");
98 goto err_obj_init; 85 ret = -EINVAL;
86 goto err_object_init;
99 } 87 }
100 88
101 DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj->filp); 89 DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj->filp);
@@ -127,24 +115,50 @@ err_handle_create:
127err_create_mmap_offset: 115err_create_mmap_offset:
128 drm_gem_object_release(obj); 116 drm_gem_object_release(obj);
129 117
130err_obj_init: 118err_object_init:
131 exynos_drm_buf_destroy(dev, exynos_gem_obj->entry);
132
133 kfree(exynos_gem_obj); 119 kfree(exynos_gem_obj);
134 120
135 return ERR_PTR(ret); 121 return ERR_PTR(ret);
136} 122}
137 123
124struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
125 struct drm_file *file_priv,
126 unsigned int *handle, unsigned long size)
127{
128
129 struct exynos_drm_gem_obj *exynos_gem_obj = NULL;
130 struct exynos_drm_gem_buf *buffer;
131
132 size = roundup(size, PAGE_SIZE);
133
134 DRM_DEBUG_KMS("%s: size = 0x%lx\n", __FILE__, size);
135
136 buffer = exynos_drm_buf_create(dev, size);
137 if (IS_ERR(buffer)) {
138 return ERR_CAST(buffer);
139 }
140
141 exynos_gem_obj = exynos_drm_gem_init(dev, file_priv, handle, size);
142 if (IS_ERR(exynos_gem_obj)) {
143 exynos_drm_buf_destroy(dev, buffer);
144 return exynos_gem_obj;
145 }
146
147 exynos_gem_obj->buffer = buffer;
148
149 return exynos_gem_obj;
150}
151
138int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, 152int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
139 struct drm_file *file_priv) 153 struct drm_file *file_priv)
140{ 154{
141 struct drm_exynos_gem_create *args = data; 155 struct drm_exynos_gem_create *args = data;
142 struct exynos_drm_gem_obj *exynos_gem_obj; 156 struct exynos_drm_gem_obj *exynos_gem_obj = NULL;
143 157
144 DRM_DEBUG_KMS("%s : size = 0x%x\n", __FILE__, args->size); 158 DRM_DEBUG_KMS("%s\n", __FILE__);
145 159
146 exynos_gem_obj = exynos_drm_gem_create(file_priv, dev, args->size, 160 exynos_gem_obj = exynos_drm_gem_create(dev, file_priv,
147 &args->handle); 161 &args->handle, args->size);
148 if (IS_ERR(exynos_gem_obj)) 162 if (IS_ERR(exynos_gem_obj))
149 return PTR_ERR(exynos_gem_obj); 163 return PTR_ERR(exynos_gem_obj);
150 164
@@ -175,7 +189,7 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
175{ 189{
176 struct drm_gem_object *obj = filp->private_data; 190 struct drm_gem_object *obj = filp->private_data;
177 struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj); 191 struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
178 struct exynos_drm_buf_entry *entry; 192 struct exynos_drm_gem_buf *buffer;
179 unsigned long pfn, vm_size; 193 unsigned long pfn, vm_size;
180 194
181 DRM_DEBUG_KMS("%s\n", __FILE__); 195 DRM_DEBUG_KMS("%s\n", __FILE__);
@@ -187,20 +201,20 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
187 201
188 vm_size = vma->vm_end - vma->vm_start; 202 vm_size = vma->vm_end - vma->vm_start;
189 /* 203 /*
190 * a entry contains information to physically continuous memory 204 * a buffer contains information to physically continuous memory
191 * allocated by user request or at framebuffer creation. 205 * allocated by user request or at framebuffer creation.
192 */ 206 */
193 entry = exynos_gem_obj->entry; 207 buffer = exynos_gem_obj->buffer;
194 208
195 /* check if user-requested size is valid. */ 209 /* check if user-requested size is valid. */
196 if (vm_size > entry->size) 210 if (vm_size > buffer->size)
197 return -EINVAL; 211 return -EINVAL;
198 212
199 /* 213 /*
200 * get page frame number to physical memory to be mapped 214 * get page frame number to physical memory to be mapped
201 * to user space. 215 * to user space.
202 */ 216 */
203 pfn = exynos_gem_obj->entry->paddr >> PAGE_SHIFT; 217 pfn = ((unsigned long)exynos_gem_obj->buffer->dma_addr) >> PAGE_SHIFT;
204 218
205 DRM_DEBUG_KMS("pfn = 0x%lx\n", pfn); 219 DRM_DEBUG_KMS("pfn = 0x%lx\n", pfn);
206 220
@@ -281,7 +295,7 @@ void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj)
281 295
282 exynos_gem_obj = to_exynos_gem_obj(gem_obj); 296 exynos_gem_obj = to_exynos_gem_obj(gem_obj);
283 297
284 exynos_drm_buf_destroy(gem_obj->dev, exynos_gem_obj->entry); 298 exynos_drm_buf_destroy(gem_obj->dev, exynos_gem_obj->buffer);
285 299
286 kfree(exynos_gem_obj); 300 kfree(exynos_gem_obj);
287} 301}
@@ -302,8 +316,8 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
302 args->pitch = args->width * args->bpp >> 3; 316 args->pitch = args->width * args->bpp >> 3;
303 args->size = args->pitch * args->height; 317 args->size = args->pitch * args->height;
304 318
305 exynos_gem_obj = exynos_drm_gem_create(file_priv, dev, args->size, 319 exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, &args->handle,
306 &args->handle); 320 args->size);
307 if (IS_ERR(exynos_gem_obj)) 321 if (IS_ERR(exynos_gem_obj))
308 return PTR_ERR(exynos_gem_obj); 322 return PTR_ERR(exynos_gem_obj);
309 323
@@ -360,7 +374,8 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
360 374
361 mutex_lock(&dev->struct_mutex); 375 mutex_lock(&dev->struct_mutex);
362 376
363 pfn = (exynos_gem_obj->entry->paddr >> PAGE_SHIFT) + page_offset; 377 pfn = (((unsigned long)exynos_gem_obj->buffer->dma_addr) >>
378 PAGE_SHIFT) + page_offset;
364 379
365 ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, pfn); 380 ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, pfn);
366 381
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.h b/drivers/gpu/drm/exynos/exynos_drm_gem.h
index e5fc0148277..ef8797334e6 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.h
@@ -30,13 +30,29 @@
30 struct exynos_drm_gem_obj, base) 30 struct exynos_drm_gem_obj, base)
31 31
32/* 32/*
33 * exynos drm gem buffer structure.
34 *
35 * @kvaddr: kernel virtual address to allocated memory region.
36 * @dma_addr: bus address(accessed by dma) to allocated memory region.
37 * - this address could be physical address without IOMMU and
38 * device address with IOMMU.
39 * @size: size of allocated memory region.
40 */
41struct exynos_drm_gem_buf {
42 void __iomem *kvaddr;
43 dma_addr_t dma_addr;
44 unsigned long size;
45};
46
47/*
33 * exynos drm buffer structure. 48 * exynos drm buffer structure.
34 * 49 *
35 * @base: a gem object. 50 * @base: a gem object.
36 * - a new handle to this gem object would be created 51 * - a new handle to this gem object would be created
37 * by drm_gem_handle_create(). 52 * by drm_gem_handle_create().
38 * @entry: pointer to exynos drm buffer entry object. 53 * @buffer: a pointer to exynos_drm_gem_buffer object.
39 * - containing the information to physically 54 * - contain the information to memory region allocated
55 * by user request or at framebuffer creation.
40 * continuous memory region allocated by user request 56 * continuous memory region allocated by user request
41 * or at framebuffer creation. 57 * or at framebuffer creation.
42 * 58 *
@@ -45,13 +61,13 @@
45 */ 61 */
46struct exynos_drm_gem_obj { 62struct exynos_drm_gem_obj {
47 struct drm_gem_object base; 63 struct drm_gem_object base;
48 struct exynos_drm_buf_entry *entry; 64 struct exynos_drm_gem_buf *buffer;
49}; 65};
50 66
51/* create a new buffer and get a new gem handle. */ 67/* create a new buffer and get a new gem handle. */
52struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_file *file_priv, 68struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
53 struct drm_device *dev, unsigned int size, 69 struct drm_file *file_priv,
54 unsigned int *handle); 70 unsigned int *handle, unsigned long size);
55 71
56/* 72/*
57 * request gem object creation and buffer allocation as the size 73 * request gem object creation and buffer allocation as the size
diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 08792a740f1..07d55df6623 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 0b6773290c0..b7d45ab4ba6 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 6f98d059f68..d4266bdf6fb 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 8e95d66800b..d09a6e02dc9 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"
@@ -635,11 +636,16 @@ static int i915_ringbuffer_info(struct seq_file *m, void *data)
635 struct drm_device *dev = node->minor->dev; 636 struct drm_device *dev = node->minor->dev;
636 drm_i915_private_t *dev_priv = dev->dev_private; 637 drm_i915_private_t *dev_priv = dev->dev_private;
637 struct intel_ring_buffer *ring; 638 struct intel_ring_buffer *ring;
639 int ret;
638 640
639 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data]; 641 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
640 if (ring->size == 0) 642 if (ring->size == 0)
641 return 0; 643 return 0;
642 644
645 ret = mutex_lock_interruptible(&dev->struct_mutex);
646 if (ret)
647 return ret;
648
643 seq_printf(m, "Ring %s:\n", ring->name); 649 seq_printf(m, "Ring %s:\n", ring->name);
644 seq_printf(m, " Head : %08x\n", I915_READ_HEAD(ring) & HEAD_ADDR); 650 seq_printf(m, " Head : %08x\n", I915_READ_HEAD(ring) & HEAD_ADDR);
645 seq_printf(m, " Tail : %08x\n", I915_READ_TAIL(ring) & TAIL_ADDR); 651 seq_printf(m, " Tail : %08x\n", I915_READ_TAIL(ring) & TAIL_ADDR);
@@ -653,6 +659,8 @@ static int i915_ringbuffer_info(struct seq_file *m, void *data)
653 seq_printf(m, " Control : %08x\n", I915_READ_CTL(ring)); 659 seq_printf(m, " Control : %08x\n", I915_READ_CTL(ring));
654 seq_printf(m, " Start : %08x\n", I915_READ_START(ring)); 660 seq_printf(m, " Start : %08x\n", I915_READ_START(ring));
655 661
662 mutex_unlock(&dev->struct_mutex);
663
656 return 0; 664 return 0;
657} 665}
658 666
@@ -841,7 +849,16 @@ static int i915_rstdby_delays(struct seq_file *m, void *unused)
841 struct drm_info_node *node = (struct drm_info_node *) m->private; 849 struct drm_info_node *node = (struct drm_info_node *) m->private;
842 struct drm_device *dev = node->minor->dev; 850 struct drm_device *dev = node->minor->dev;
843 drm_i915_private_t *dev_priv = dev->dev_private; 851 drm_i915_private_t *dev_priv = dev->dev_private;
844 u16 crstanddelay = I915_READ16(CRSTANDVID); 852 u16 crstanddelay;
853 int ret;
854
855 ret = mutex_lock_interruptible(&dev->struct_mutex);
856 if (ret)
857 return ret;
858
859 crstanddelay = I915_READ16(CRSTANDVID);
860
861 mutex_unlock(&dev->struct_mutex);
845 862
846 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f)); 863 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
847 864
@@ -939,7 +956,11 @@ static int i915_delayfreq_table(struct seq_file *m, void *unused)
939 struct drm_device *dev = node->minor->dev; 956 struct drm_device *dev = node->minor->dev;
940 drm_i915_private_t *dev_priv = dev->dev_private; 957 drm_i915_private_t *dev_priv = dev->dev_private;
941 u32 delayfreq; 958 u32 delayfreq;
942 int i; 959 int ret, i;
960
961 ret = mutex_lock_interruptible(&dev->struct_mutex);
962 if (ret)
963 return ret;
943 964
944 for (i = 0; i < 16; i++) { 965 for (i = 0; i < 16; i++) {
945 delayfreq = I915_READ(PXVFREQ_BASE + i * 4); 966 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
@@ -947,6 +968,8 @@ static int i915_delayfreq_table(struct seq_file *m, void *unused)
947 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT); 968 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
948 } 969 }
949 970
971 mutex_unlock(&dev->struct_mutex);
972
950 return 0; 973 return 0;
951} 974}
952 975
@@ -961,13 +984,19 @@ static int i915_inttoext_table(struct seq_file *m, void *unused)
961 struct drm_device *dev = node->minor->dev; 984 struct drm_device *dev = node->minor->dev;
962 drm_i915_private_t *dev_priv = dev->dev_private; 985 drm_i915_private_t *dev_priv = dev->dev_private;
963 u32 inttoext; 986 u32 inttoext;
964 int i; 987 int ret, i;
988
989 ret = mutex_lock_interruptible(&dev->struct_mutex);
990 if (ret)
991 return ret;
965 992
966 for (i = 1; i <= 32; i++) { 993 for (i = 1; i <= 32; i++) {
967 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4); 994 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
968 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext); 995 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
969 } 996 }
970 997
998 mutex_unlock(&dev->struct_mutex);
999
971 return 0; 1000 return 0;
972} 1001}
973 1002
@@ -976,9 +1005,19 @@ static int i915_drpc_info(struct seq_file *m, void *unused)
976 struct drm_info_node *node = (struct drm_info_node *) m->private; 1005 struct drm_info_node *node = (struct drm_info_node *) m->private;
977 struct drm_device *dev = node->minor->dev; 1006 struct drm_device *dev = node->minor->dev;
978 drm_i915_private_t *dev_priv = dev->dev_private; 1007 drm_i915_private_t *dev_priv = dev->dev_private;
979 u32 rgvmodectl = I915_READ(MEMMODECTL); 1008 u32 rgvmodectl, rstdbyctl;
980 u32 rstdbyctl = I915_READ(RSTDBYCTL); 1009 u16 crstandvid;
981 u16 crstandvid = I915_READ16(CRSTANDVID); 1010 int ret;
1011
1012 ret = mutex_lock_interruptible(&dev->struct_mutex);
1013 if (ret)
1014 return ret;
1015
1016 rgvmodectl = I915_READ(MEMMODECTL);
1017 rstdbyctl = I915_READ(RSTDBYCTL);
1018 crstandvid = I915_READ16(CRSTANDVID);
1019
1020 mutex_unlock(&dev->struct_mutex);
982 1021
983 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ? 1022 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
984 "yes" : "no"); 1023 "yes" : "no");
@@ -1166,9 +1205,16 @@ static int i915_gfxec(struct seq_file *m, void *unused)
1166 struct drm_info_node *node = (struct drm_info_node *) m->private; 1205 struct drm_info_node *node = (struct drm_info_node *) m->private;
1167 struct drm_device *dev = node->minor->dev; 1206 struct drm_device *dev = node->minor->dev;
1168 drm_i915_private_t *dev_priv = dev->dev_private; 1207 drm_i915_private_t *dev_priv = dev->dev_private;
1208 int ret;
1209
1210 ret = mutex_lock_interruptible(&dev->struct_mutex);
1211 if (ret)
1212 return ret;
1169 1213
1170 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4)); 1214 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1171 1215
1216 mutex_unlock(&dev->struct_mutex);
1217
1172 return 0; 1218 return 0;
1173} 1219}
1174 1220
@@ -1505,7 +1551,10 @@ drm_add_fake_info_node(struct drm_minor *minor,
1505 node->minor = minor; 1551 node->minor = minor;
1506 node->dent = ent; 1552 node->dent = ent;
1507 node->info_ent = (void *) key; 1553 node->info_ent = (void *) key;
1508 list_add(&node->list, &minor->debugfs_nodes.list); 1554
1555 mutex_lock(&minor->debugfs_lock);
1556 list_add(&node->list, &minor->debugfs_list);
1557 mutex_unlock(&minor->debugfs_lock);
1509 1558
1510 return 0; 1559 return 0;
1511} 1560}
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 2eac955dee1..a9533c54c93 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 4c8d681c215..15bfa9145d2 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;
@@ -67,7 +68,7 @@ module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0600);
67MODULE_PARM_DESC(i915_enable_rc6, 68MODULE_PARM_DESC(i915_enable_rc6,
68 "Enable power-saving render C-state 6 (default: true)"); 69 "Enable power-saving render C-state 6 (default: true)");
69 70
70unsigned int i915_enable_fbc __read_mostly = -1; 71int i915_enable_fbc __read_mostly = -1;
71module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600); 72module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600);
72MODULE_PARM_DESC(i915_enable_fbc, 73MODULE_PARM_DESC(i915_enable_fbc,
73 "Enable frame buffer compression for power savings " 74 "Enable frame buffer compression for power savings "
@@ -79,7 +80,7 @@ MODULE_PARM_DESC(lvds_downclock,
79 "Use panel (LVDS/eDP) downclocking for power savings " 80 "Use panel (LVDS/eDP) downclocking for power savings "
80 "(default: false)"); 81 "(default: false)");
81 82
82unsigned int i915_panel_use_ssc __read_mostly = -1; 83int i915_panel_use_ssc __read_mostly = -1;
83module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600); 84module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600);
84MODULE_PARM_DESC(lvds_use_ssc, 85MODULE_PARM_DESC(lvds_use_ssc,
85 "Use Spread Spectrum Clock with panels [LVDS/eDP] " 86 "Use Spread Spectrum Clock with panels [LVDS/eDP] "
@@ -106,7 +107,7 @@ static struct drm_driver driver;
106extern int intel_agp_enabled; 107extern int intel_agp_enabled;
107 108
108#define INTEL_VGA_DEVICE(id, info) { \ 109#define INTEL_VGA_DEVICE(id, info) { \
109 .class = PCI_CLASS_DISPLAY_VGA << 8, \ 110 .class = PCI_BASE_CLASS_DISPLAY << 16, \
110 .class_mask = 0xff0000, \ 111 .class_mask = 0xff0000, \
111 .vendor = 0x8086, \ 112 .vendor = 0x8086, \
112 .device = id, \ 113 .device = id, \
@@ -788,8 +789,8 @@ static struct vm_operations_struct i915_gem_vm_ops = {
788}; 789};
789 790
790static struct drm_driver driver = { 791static struct drm_driver driver = {
791 /* don't use mtrr's here, the Xserver or user space app should 792 /* Don't use MTRRs here; the Xserver or userspace app should
792 * deal with them for intel hardware. 793 * deal with them for Intel hardware.
793 */ 794 */
794 .driver_features = 795 .driver_features =
795 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/ 796 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 06a37f4fd74..4a9c1b97980 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -126,6 +126,9 @@ struct drm_i915_master_private {
126 struct _drm_i915_sarea *sarea_priv; 126 struct _drm_i915_sarea *sarea_priv;
127}; 127};
128#define I915_FENCE_REG_NONE -1 128#define I915_FENCE_REG_NONE -1
129#define I915_MAX_NUM_FENCES 16
130/* 16 fences + sign bit for FENCE_REG_NONE */
131#define I915_MAX_NUM_FENCE_BITS 5
129 132
130struct drm_i915_fence_reg { 133struct drm_i915_fence_reg {
131 struct list_head lru_list; 134 struct list_head lru_list;
@@ -168,7 +171,7 @@ struct drm_i915_error_state {
168 u32 instdone1; 171 u32 instdone1;
169 u32 seqno; 172 u32 seqno;
170 u64 bbaddr; 173 u64 bbaddr;
171 u64 fence[16]; 174 u64 fence[I915_MAX_NUM_FENCES];
172 struct timeval time; 175 struct timeval time;
173 struct drm_i915_error_object { 176 struct drm_i915_error_object {
174 int page_count; 177 int page_count;
@@ -182,7 +185,7 @@ struct drm_i915_error_state {
182 u32 gtt_offset; 185 u32 gtt_offset;
183 u32 read_domains; 186 u32 read_domains;
184 u32 write_domain; 187 u32 write_domain;
185 s32 fence_reg:5; 188 s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
186 s32 pinned:2; 189 s32 pinned:2;
187 u32 tiling:2; 190 u32 tiling:2;
188 u32 dirty:1; 191 u32 dirty:1;
@@ -375,7 +378,7 @@ typedef struct drm_i915_private {
375 struct notifier_block lid_notifier; 378 struct notifier_block lid_notifier;
376 379
377 int crt_ddc_pin; 380 int crt_ddc_pin;
378 struct drm_i915_fence_reg fence_regs[16]; /* assume 965 */ 381 struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
379 int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */ 382 int fence_reg_start; /* 4 if userland hasn't ioctl'd us yet */
380 int num_fence_regs; /* 8 on pre-965, 16 otherwise */ 383 int num_fence_regs; /* 8 on pre-965, 16 otherwise */
381 384
@@ -506,7 +509,7 @@ typedef struct drm_i915_private {
506 u8 saveAR[21]; 509 u8 saveAR[21];
507 u8 saveDACMASK; 510 u8 saveDACMASK;
508 u8 saveCR[37]; 511 u8 saveCR[37];
509 uint64_t saveFENCE[16]; 512 uint64_t saveFENCE[I915_MAX_NUM_FENCES];
510 u32 saveCURACNTR; 513 u32 saveCURACNTR;
511 u32 saveCURAPOS; 514 u32 saveCURAPOS;
512 u32 saveCURABASE; 515 u32 saveCURABASE;
@@ -777,10 +780,8 @@ struct drm_i915_gem_object {
777 * Fence register bits (if any) for this object. Will be set 780 * Fence register bits (if any) for this object. Will be set
778 * as needed when mapped into the GTT. 781 * as needed when mapped into the GTT.
779 * Protected by dev->struct_mutex. 782 * Protected by dev->struct_mutex.
780 *
781 * Size: 4 bits for 16 fences + sign (for FENCE_REG_NONE)
782 */ 783 */
783 signed int fence_reg:5; 784 signed int fence_reg:I915_MAX_NUM_FENCE_BITS;
784 785
785 /** 786 /**
786 * Advice: are the backing pages purgeable? 787 * Advice: are the backing pages purgeable?
@@ -999,10 +1000,10 @@ extern int i915_panel_ignore_lid __read_mostly;
999extern unsigned int i915_powersave __read_mostly; 1000extern unsigned int i915_powersave __read_mostly;
1000extern unsigned int i915_semaphores __read_mostly; 1001extern unsigned int i915_semaphores __read_mostly;
1001extern unsigned int i915_lvds_downclock __read_mostly; 1002extern unsigned int i915_lvds_downclock __read_mostly;
1002extern unsigned int i915_panel_use_ssc __read_mostly; 1003extern int i915_panel_use_ssc __read_mostly;
1003extern int i915_vbt_sdvo_panel_type __read_mostly; 1004extern int i915_vbt_sdvo_panel_type __read_mostly;
1004extern unsigned int i915_enable_rc6 __read_mostly; 1005extern unsigned int i915_enable_rc6 __read_mostly;
1005extern unsigned int i915_enable_fbc __read_mostly; 1006extern int i915_enable_fbc __read_mostly;
1006extern bool i915_enable_hangcheck __read_mostly; 1007extern bool i915_enable_hangcheck __read_mostly;
1007 1008
1008extern int i915_suspend(struct drm_device *dev, pm_message_t state); 1009extern int i915_suspend(struct drm_device *dev, pm_message_t state);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 6651c36b6e8..8359dc77704 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1396,7 +1396,7 @@ i915_gem_mmap_gtt(struct drm_file *file,
1396 1396
1397 if (obj->base.size > dev_priv->mm.gtt_mappable_end) { 1397 if (obj->base.size > dev_priv->mm.gtt_mappable_end) {
1398 ret = -E2BIG; 1398 ret = -E2BIG;
1399 goto unlock; 1399 goto out;
1400 } 1400 }
1401 1401
1402 if (obj->madv != I915_MADV_WILLNEED) { 1402 if (obj->madv != I915_MADV_WILLNEED) {
@@ -1745,7 +1745,7 @@ static void i915_gem_reset_fences(struct drm_device *dev)
1745 struct drm_i915_private *dev_priv = dev->dev_private; 1745 struct drm_i915_private *dev_priv = dev->dev_private;
1746 int i; 1746 int i;
1747 1747
1748 for (i = 0; i < 16; i++) { 1748 for (i = 0; i < dev_priv->num_fence_regs; i++) {
1749 struct drm_i915_fence_reg *reg = &dev_priv->fence_regs[i]; 1749 struct drm_i915_fence_reg *reg = &dev_priv->fence_regs[i];
1750 struct drm_i915_gem_object *obj = reg->obj; 1750 struct drm_i915_gem_object *obj = reg->obj;
1751 1751
@@ -3512,9 +3512,11 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
3512 * so emit a request to do so. 3512 * so emit a request to do so.
3513 */ 3513 */
3514 request = kzalloc(sizeof(*request), GFP_KERNEL); 3514 request = kzalloc(sizeof(*request), GFP_KERNEL);
3515 if (request) 3515 if (request) {
3516 ret = i915_add_request(obj->ring, NULL, request); 3516 ret = i915_add_request(obj->ring, NULL, request);
3517 else 3517 if (ret)
3518 kfree(request);
3519 } else
3518 ret = -ENOMEM; 3520 ret = -ENOMEM;
3519 } 3521 }
3520 3522
@@ -3613,7 +3615,7 @@ struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
3613 obj->base.write_domain = I915_GEM_DOMAIN_CPU; 3615 obj->base.write_domain = I915_GEM_DOMAIN_CPU;
3614 obj->base.read_domains = I915_GEM_DOMAIN_CPU; 3616 obj->base.read_domains = I915_GEM_DOMAIN_CPU;
3615 3617
3616 if (IS_GEN6(dev)) { 3618 if (IS_GEN6(dev) || IS_GEN7(dev)) {
3617 /* On Gen6, we can have the GPU use the LLC (the CPU 3619 /* On Gen6, we can have the GPU use the LLC (the CPU
3618 * cache) for about a 10% performance improvement 3620 * cache) for about a 10% performance improvement
3619 * compared to uncached. Graphics requests other than 3621 * compared to uncached. Graphics requests other than
@@ -3877,7 +3879,7 @@ i915_gem_load(struct drm_device *dev)
3877 INIT_LIST_HEAD(&dev_priv->mm.gtt_list); 3879 INIT_LIST_HEAD(&dev_priv->mm.gtt_list);
3878 for (i = 0; i < I915_NUM_RINGS; i++) 3880 for (i = 0; i < I915_NUM_RINGS; i++)
3879 init_ring_lists(&dev_priv->ring[i]); 3881 init_ring_lists(&dev_priv->ring[i]);
3880 for (i = 0; i < 16; i++) 3882 for (i = 0; i < I915_MAX_NUM_FENCES; i++)
3881 INIT_LIST_HEAD(&dev_priv->fence_regs[i].lru_list); 3883 INIT_LIST_HEAD(&dev_priv->fence_regs[i].lru_list);
3882 INIT_DELAYED_WORK(&dev_priv->mm.retire_work, 3884 INIT_DELAYED_WORK(&dev_priv->mm.retire_work,
3883 i915_gem_retire_work_handler); 3885 i915_gem_retire_work_handler);
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 9ee2729fe5c..b40004b5597 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -824,6 +824,7 @@ static void i915_gem_record_fences(struct drm_device *dev,
824 824
825 /* Fences */ 825 /* Fences */
826 switch (INTEL_INFO(dev)->gen) { 826 switch (INTEL_INFO(dev)->gen) {
827 case 7:
827 case 6: 828 case 6:
828 for (i = 0; i < 16; i++) 829 for (i = 0; i < 16; i++)
829 error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8)); 830 error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 5a09416e611..b080cc82400 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -1553,12 +1553,21 @@
1553 */ 1553 */
1554#define PP_READY (1 << 30) 1554#define PP_READY (1 << 30)
1555#define PP_SEQUENCE_NONE (0 << 28) 1555#define PP_SEQUENCE_NONE (0 << 28)
1556#define PP_SEQUENCE_ON (1 << 28) 1556#define PP_SEQUENCE_POWER_UP (1 << 28)
1557#define PP_SEQUENCE_OFF (2 << 28) 1557#define PP_SEQUENCE_POWER_DOWN (2 << 28)
1558#define PP_SEQUENCE_MASK 0x30000000 1558#define PP_SEQUENCE_MASK (3 << 28)
1559#define PP_SEQUENCE_SHIFT 28
1559#define PP_CYCLE_DELAY_ACTIVE (1 << 27) 1560#define PP_CYCLE_DELAY_ACTIVE (1 << 27)
1560#define PP_SEQUENCE_STATE_ON_IDLE (1 << 3)
1561#define PP_SEQUENCE_STATE_MASK 0x0000000f 1561#define PP_SEQUENCE_STATE_MASK 0x0000000f
1562#define PP_SEQUENCE_STATE_OFF_IDLE (0x0 << 0)
1563#define PP_SEQUENCE_STATE_OFF_S0_1 (0x1 << 0)
1564#define PP_SEQUENCE_STATE_OFF_S0_2 (0x2 << 0)
1565#define PP_SEQUENCE_STATE_OFF_S0_3 (0x3 << 0)
1566#define PP_SEQUENCE_STATE_ON_IDLE (0x8 << 0)
1567#define PP_SEQUENCE_STATE_ON_S1_0 (0x9 << 0)
1568#define PP_SEQUENCE_STATE_ON_S1_2 (0xa << 0)
1569#define PP_SEQUENCE_STATE_ON_S1_3 (0xb << 0)
1570#define PP_SEQUENCE_STATE_RESET (0xf << 0)
1562#define PP_CONTROL 0x61204 1571#define PP_CONTROL 0x61204
1563#define POWER_TARGET_ON (1 << 0) 1572#define POWER_TARGET_ON (1 << 0)
1564#define PP_ON_DELAYS 0x61208 1573#define PP_ON_DELAYS 0x61208
@@ -3444,6 +3453,10 @@
3444#define GT_FIFO_FREE_ENTRIES 0x120008 3453#define GT_FIFO_FREE_ENTRIES 0x120008
3445#define GT_FIFO_NUM_RESERVED_ENTRIES 20 3454#define GT_FIFO_NUM_RESERVED_ENTRIES 20
3446 3455
3456#define GEN6_UCGCTL2 0x9404
3457# define GEN6_RCPBUNIT_CLOCK_GATE_DISABLE (1 << 12)
3458# define GEN6_RCCUNIT_CLOCK_GATE_DISABLE (1 << 11)
3459
3447#define GEN6_RPNSWREQ 0xA008 3460#define GEN6_RPNSWREQ 0xA008
3448#define GEN6_TURBO_DISABLE (1<<31) 3461#define GEN6_TURBO_DISABLE (1<<31)
3449#define GEN6_FREQUENCY(x) ((x)<<25) 3462#define GEN6_FREQUENCY(x) ((x)<<25)
diff --git a/drivers/gpu/drm/i915/i915_suspend.c b/drivers/gpu/drm/i915/i915_suspend.c
index f8f602d7665..7886e4fb60e 100644
--- a/drivers/gpu/drm/i915/i915_suspend.c
+++ b/drivers/gpu/drm/i915/i915_suspend.c
@@ -370,6 +370,7 @@ static void i915_save_modeset_reg(struct drm_device *dev)
370 370
371 /* Fences */ 371 /* Fences */
372 switch (INTEL_INFO(dev)->gen) { 372 switch (INTEL_INFO(dev)->gen) {
373 case 7:
373 case 6: 374 case 6:
374 for (i = 0; i < 16; i++) 375 for (i = 0; i < 16; i++)
375 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8)); 376 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
@@ -404,6 +405,7 @@ static void i915_restore_modeset_reg(struct drm_device *dev)
404 405
405 /* Fences */ 406 /* Fences */
406 switch (INTEL_INFO(dev)->gen) { 407 switch (INTEL_INFO(dev)->gen) {
408 case 7:
407 case 6: 409 case 6:
408 for (i = 0; i < 16; i++) 410 for (i = 0; i < 16; i++)
409 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (i * 8), dev_priv->saveFENCE[i]); 411 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (i * 8), dev_priv->saveFENCE[i]);
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 981b1f1c04d..e77a863a383 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2933,7 +2933,8 @@ static void ironlake_pch_enable(struct drm_crtc *crtc)
2933 2933
2934 /* For PCH DP, enable TRANS_DP_CTL */ 2934 /* For PCH DP, enable TRANS_DP_CTL */
2935 if (HAS_PCH_CPT(dev) && 2935 if (HAS_PCH_CPT(dev) &&
2936 intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { 2936 (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
2937 intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
2937 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) >> 5; 2938 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) >> 5;
2938 reg = TRANS_DP_CTL(pipe); 2939 reg = TRANS_DP_CTL(pipe);
2939 temp = I915_READ(reg); 2940 temp = I915_READ(reg);
@@ -4711,7 +4712,7 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4711 lvds_bpc = 6; 4712 lvds_bpc = 6;
4712 4713
4713 if (lvds_bpc < display_bpc) { 4714 if (lvds_bpc < display_bpc) {
4714 DRM_DEBUG_DRIVER("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc); 4715 DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
4715 display_bpc = lvds_bpc; 4716 display_bpc = lvds_bpc;
4716 } 4717 }
4717 continue; 4718 continue;
@@ -4722,7 +4723,7 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4722 unsigned int edp_bpc = dev_priv->edp.bpp / 3; 4723 unsigned int edp_bpc = dev_priv->edp.bpp / 3;
4723 4724
4724 if (edp_bpc < display_bpc) { 4725 if (edp_bpc < display_bpc) {
4725 DRM_DEBUG_DRIVER("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc); 4726 DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
4726 display_bpc = edp_bpc; 4727 display_bpc = edp_bpc;
4727 } 4728 }
4728 continue; 4729 continue;
@@ -4737,7 +4738,7 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4737 /* Don't use an invalid EDID bpc value */ 4738 /* Don't use an invalid EDID bpc value */
4738 if (connector->display_info.bpc && 4739 if (connector->display_info.bpc &&
4739 connector->display_info.bpc < display_bpc) { 4740 connector->display_info.bpc < display_bpc) {
4740 DRM_DEBUG_DRIVER("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc); 4741 DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
4741 display_bpc = connector->display_info.bpc; 4742 display_bpc = connector->display_info.bpc;
4742 } 4743 }
4743 } 4744 }
@@ -4748,10 +4749,10 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4748 */ 4749 */
4749 if (intel_encoder->type == INTEL_OUTPUT_HDMI) { 4750 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
4750 if (display_bpc > 8 && display_bpc < 12) { 4751 if (display_bpc > 8 && display_bpc < 12) {
4751 DRM_DEBUG_DRIVER("forcing bpc to 12 for HDMI\n"); 4752 DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
4752 display_bpc = 12; 4753 display_bpc = 12;
4753 } else { 4754 } else {
4754 DRM_DEBUG_DRIVER("forcing bpc to 8 for HDMI\n"); 4755 DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
4755 display_bpc = 8; 4756 display_bpc = 8;
4756 } 4757 }
4757 } 4758 }
@@ -4789,8 +4790,8 @@ static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
4789 4790
4790 display_bpc = min(display_bpc, bpc); 4791 display_bpc = min(display_bpc, bpc);
4791 4792
4792 DRM_DEBUG_DRIVER("setting pipe bpc to %d (max display bpc %d)\n", 4793 DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
4793 bpc, display_bpc); 4794 bpc, display_bpc);
4794 4795
4795 *pipe_bpp = display_bpc * 3; 4796 *pipe_bpp = display_bpc * 3;
4796 4797
@@ -5671,7 +5672,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5671 pipeconf &= ~PIPECONF_DITHER_TYPE_MASK; 5672 pipeconf &= ~PIPECONF_DITHER_TYPE_MASK;
5672 if ((is_lvds && dev_priv->lvds_dither) || dither) { 5673 if ((is_lvds && dev_priv->lvds_dither) || dither) {
5673 pipeconf |= PIPECONF_DITHER_EN; 5674 pipeconf |= PIPECONF_DITHER_EN;
5674 pipeconf |= PIPECONF_DITHER_TYPE_ST1; 5675 pipeconf |= PIPECONF_DITHER_TYPE_SP;
5675 } 5676 }
5676 if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) { 5677 if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
5677 intel_dp_set_m_n(crtc, mode, adjusted_mode); 5678 intel_dp_set_m_n(crtc, mode, adjusted_mode);
@@ -8148,6 +8149,20 @@ static void gen6_init_clock_gating(struct drm_device *dev)
8148 I915_WRITE(WM2_LP_ILK, 0); 8149 I915_WRITE(WM2_LP_ILK, 0);
8149 I915_WRITE(WM1_LP_ILK, 0); 8150 I915_WRITE(WM1_LP_ILK, 0);
8150 8151
8152 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
8153 * gating disable must be set. Failure to set it results in
8154 * flickering pixels due to Z write ordering failures after
8155 * some amount of runtime in the Mesa "fire" demo, and Unigine
8156 * Sanctuary and Tropics, and apparently anything else with
8157 * alpha test or pixel discard.
8158 *
8159 * According to the spec, bit 11 (RCCUNIT) must also be set,
8160 * but we didn't debug actual testcases to find it out.
8161 */
8162 I915_WRITE(GEN6_UCGCTL2,
8163 GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
8164 GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
8165
8151 /* 8166 /*
8152 * According to the spec the following bits should be 8167 * According to the spec the following bits should be
8153 * set in order to enable memory self-refresh and fbc: 8168 * set in order to enable memory self-refresh and fbc:
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index fc1a0832af4..4d0358fad93 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"
@@ -58,7 +59,6 @@ struct intel_dp {
58 struct i2c_algo_dp_aux_data algo; 59 struct i2c_algo_dp_aux_data algo;
59 bool is_pch_edp; 60 bool is_pch_edp;
60 uint8_t train_set[4]; 61 uint8_t train_set[4];
61 uint8_t link_status[DP_LINK_STATUS_SIZE];
62 int panel_power_up_delay; 62 int panel_power_up_delay;
63 int panel_power_down_delay; 63 int panel_power_down_delay;
64 int panel_power_cycle_delay; 64 int panel_power_cycle_delay;
@@ -67,7 +67,6 @@ struct intel_dp {
67 struct drm_display_mode *panel_fixed_mode; /* for eDP */ 67 struct drm_display_mode *panel_fixed_mode; /* for eDP */
68 struct delayed_work panel_vdd_work; 68 struct delayed_work panel_vdd_work;
69 bool want_panel_vdd; 69 bool want_panel_vdd;
70 unsigned long panel_off_jiffies;
71}; 70};
72 71
73/** 72/**
@@ -156,16 +155,12 @@ intel_edp_link_config(struct intel_encoder *intel_encoder,
156static int 155static int
157intel_dp_max_lane_count(struct intel_dp *intel_dp) 156intel_dp_max_lane_count(struct intel_dp *intel_dp)
158{ 157{
159 int max_lane_count = 4; 158 int max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
160 159 switch (max_lane_count) {
161 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { 160 case 1: case 2: case 4:
162 max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f; 161 break;
163 switch (max_lane_count) { 162 default:
164 case 1: case 2: case 4: 163 max_lane_count = 4;
165 break;
166 default:
167 max_lane_count = 4;
168 }
169 } 164 }
170 return max_lane_count; 165 return max_lane_count;
171} 166}
@@ -767,12 +762,11 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
767 continue; 762 continue;
768 763
769 intel_dp = enc_to_intel_dp(encoder); 764 intel_dp = enc_to_intel_dp(encoder);
770 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) { 765 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
766 intel_dp->base.type == INTEL_OUTPUT_EDP)
767 {
771 lane_count = intel_dp->lane_count; 768 lane_count = intel_dp->lane_count;
772 break; 769 break;
773 } else if (is_edp(intel_dp)) {
774 lane_count = dev_priv->edp.lanes;
775 break;
776 } 770 }
777 } 771 }
778 772
@@ -809,6 +803,7 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
809 struct drm_display_mode *adjusted_mode) 803 struct drm_display_mode *adjusted_mode)
810{ 804{
811 struct drm_device *dev = encoder->dev; 805 struct drm_device *dev = encoder->dev;
806 struct drm_i915_private *dev_priv = dev->dev_private;
812 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 807 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
813 struct drm_crtc *crtc = intel_dp->base.base.crtc; 808 struct drm_crtc *crtc = intel_dp->base.base.crtc;
814 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 809 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
@@ -821,18 +816,31 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
821 ironlake_edp_pll_off(encoder); 816 ironlake_edp_pll_off(encoder);
822 } 817 }
823 818
824 intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; 819 /*
825 intel_dp->DP |= intel_dp->color_range; 820 * There are three kinds of DP registers:
821 *
822 * IBX PCH
823 * CPU
824 * CPT PCH
825 *
826 * IBX PCH and CPU are the same for almost everything,
827 * except that the CPU DP PLL is configured in this
828 * register
829 *
830 * CPT PCH is quite different, having many bits moved
831 * to the TRANS_DP_CTL register instead. That
832 * configuration happens (oddly) in ironlake_pch_enable
833 */
826 834
827 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 835 /* Preserve the BIOS-computed detected bit. This is
828 intel_dp->DP |= DP_SYNC_HS_HIGH; 836 * supposed to be read-only.
829 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 837 */
830 intel_dp->DP |= DP_SYNC_VS_HIGH; 838 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
839 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
831 840
832 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp)) 841 /* Handle DP bits in common between all three register formats */
833 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; 842
834 else 843 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
835 intel_dp->DP |= DP_LINK_TRAIN_OFF;
836 844
837 switch (intel_dp->lane_count) { 845 switch (intel_dp->lane_count) {
838 case 1: 846 case 1:
@@ -851,59 +859,106 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
851 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; 859 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
852 intel_write_eld(encoder, adjusted_mode); 860 intel_write_eld(encoder, adjusted_mode);
853 } 861 }
854
855 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE); 862 memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
856 intel_dp->link_configuration[0] = intel_dp->link_bw; 863 intel_dp->link_configuration[0] = intel_dp->link_bw;
857 intel_dp->link_configuration[1] = intel_dp->lane_count; 864 intel_dp->link_configuration[1] = intel_dp->lane_count;
858 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B; 865 intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
859
860 /* 866 /*
861 * Check for DPCD version > 1.1 and enhanced framing support 867 * Check for DPCD version > 1.1 and enhanced framing support
862 */ 868 */
863 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 && 869 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
864 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) { 870 (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
865 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; 871 intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
866 intel_dp->DP |= DP_ENHANCED_FRAMING;
867 } 872 }
868 873
869 /* CPT DP's pipe select is decided in TRANS_DP_CTL */ 874 /* Split out the IBX/CPU vs CPT settings */
870 if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
871 intel_dp->DP |= DP_PIPEB_SELECT;
872 875
873 if (is_cpu_edp(intel_dp)) { 876 if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
874 /* don't miss out required setting for eDP */ 877 intel_dp->DP |= intel_dp->color_range;
875 intel_dp->DP |= DP_PLL_ENABLE; 878
876 if (adjusted_mode->clock < 200000) 879 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
877 intel_dp->DP |= DP_PLL_FREQ_160MHZ; 880 intel_dp->DP |= DP_SYNC_HS_HIGH;
878 else 881 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
879 intel_dp->DP |= DP_PLL_FREQ_270MHZ; 882 intel_dp->DP |= DP_SYNC_VS_HIGH;
883 intel_dp->DP |= DP_LINK_TRAIN_OFF;
884
885 if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
886 intel_dp->DP |= DP_ENHANCED_FRAMING;
887
888 if (intel_crtc->pipe == 1)
889 intel_dp->DP |= DP_PIPEB_SELECT;
890
891 if (is_cpu_edp(intel_dp)) {
892 /* don't miss out required setting for eDP */
893 intel_dp->DP |= DP_PLL_ENABLE;
894 if (adjusted_mode->clock < 200000)
895 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
896 else
897 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
898 }
899 } else {
900 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
880 } 901 }
881} 902}
882 903
883static void ironlake_wait_panel_off(struct intel_dp *intel_dp) 904#define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
905#define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
906
907#define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
908#define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
909
910#define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
911#define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
912
913static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
914 u32 mask,
915 u32 value)
884{ 916{
885 unsigned long off_time; 917 struct drm_device *dev = intel_dp->base.base.dev;
886 unsigned long delay; 918 struct drm_i915_private *dev_priv = dev->dev_private;
887 919
888 DRM_DEBUG_KMS("Wait for panel power off time\n"); 920 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
921 mask, value,
922 I915_READ(PCH_PP_STATUS),
923 I915_READ(PCH_PP_CONTROL));
889 924
890 if (ironlake_edp_have_panel_power(intel_dp) || 925 if (_wait_for((I915_READ(PCH_PP_STATUS) & mask) == value, 5000, 10)) {
891 ironlake_edp_have_panel_vdd(intel_dp)) 926 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
892 { 927 I915_READ(PCH_PP_STATUS),
893 DRM_DEBUG_KMS("Panel still on, no delay needed\n"); 928 I915_READ(PCH_PP_CONTROL));
894 return;
895 } 929 }
930}
896 931
897 off_time = intel_dp->panel_off_jiffies + msecs_to_jiffies(intel_dp->panel_power_down_delay); 932static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
898 if (time_after(jiffies, off_time)) { 933{
899 DRM_DEBUG_KMS("Time already passed"); 934 DRM_DEBUG_KMS("Wait for panel power on\n");
900 return; 935 ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
901 } 936}
902 delay = jiffies_to_msecs(off_time - jiffies); 937
903 if (delay > intel_dp->panel_power_down_delay) 938static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
904 delay = intel_dp->panel_power_down_delay; 939{
905 DRM_DEBUG_KMS("Waiting an additional %ld ms\n", delay); 940 DRM_DEBUG_KMS("Wait for panel power off time\n");
906 msleep(delay); 941 ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
942}
943
944static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
945{
946 DRM_DEBUG_KMS("Wait for panel power cycle\n");
947 ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
948}
949
950
951/* Read the current pp_control value, unlocking the register if it
952 * is locked
953 */
954
955static u32 ironlake_get_pp_control(struct drm_i915_private *dev_priv)
956{
957 u32 control = I915_READ(PCH_PP_CONTROL);
958
959 control &= ~PANEL_UNLOCK_MASK;
960 control |= PANEL_UNLOCK_REGS;
961 return control;
907} 962}
908 963
909static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp) 964static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
@@ -920,15 +975,16 @@ static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
920 "eDP VDD already requested on\n"); 975 "eDP VDD already requested on\n");
921 976
922 intel_dp->want_panel_vdd = true; 977 intel_dp->want_panel_vdd = true;
978
923 if (ironlake_edp_have_panel_vdd(intel_dp)) { 979 if (ironlake_edp_have_panel_vdd(intel_dp)) {
924 DRM_DEBUG_KMS("eDP VDD already on\n"); 980 DRM_DEBUG_KMS("eDP VDD already on\n");
925 return; 981 return;
926 } 982 }
927 983
928 ironlake_wait_panel_off(intel_dp); 984 if (!ironlake_edp_have_panel_power(intel_dp))
929 pp = I915_READ(PCH_PP_CONTROL); 985 ironlake_wait_panel_power_cycle(intel_dp);
930 pp &= ~PANEL_UNLOCK_MASK; 986
931 pp |= PANEL_UNLOCK_REGS; 987 pp = ironlake_get_pp_control(dev_priv);
932 pp |= EDP_FORCE_VDD; 988 pp |= EDP_FORCE_VDD;
933 I915_WRITE(PCH_PP_CONTROL, pp); 989 I915_WRITE(PCH_PP_CONTROL, pp);
934 POSTING_READ(PCH_PP_CONTROL); 990 POSTING_READ(PCH_PP_CONTROL);
@@ -951,9 +1007,7 @@ static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
951 u32 pp; 1007 u32 pp;
952 1008
953 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) { 1009 if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
954 pp = I915_READ(PCH_PP_CONTROL); 1010 pp = ironlake_get_pp_control(dev_priv);
955 pp &= ~PANEL_UNLOCK_MASK;
956 pp |= PANEL_UNLOCK_REGS;
957 pp &= ~EDP_FORCE_VDD; 1011 pp &= ~EDP_FORCE_VDD;
958 I915_WRITE(PCH_PP_CONTROL, pp); 1012 I915_WRITE(PCH_PP_CONTROL, pp);
959 POSTING_READ(PCH_PP_CONTROL); 1013 POSTING_READ(PCH_PP_CONTROL);
@@ -961,7 +1015,8 @@ static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
961 /* Make sure sequencer is idle before allowing subsequent activity */ 1015 /* Make sure sequencer is idle before allowing subsequent activity */
962 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n", 1016 DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
963 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL)); 1017 I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
964 intel_dp->panel_off_jiffies = jiffies; 1018
1019 msleep(intel_dp->panel_power_down_delay);
965 } 1020 }
966} 1021}
967 1022
@@ -971,9 +1026,9 @@ static void ironlake_panel_vdd_work(struct work_struct *__work)
971 struct intel_dp, panel_vdd_work); 1026 struct intel_dp, panel_vdd_work);
972 struct drm_device *dev = intel_dp->base.base.dev; 1027 struct drm_device *dev = intel_dp->base.base.dev;
973 1028
974 mutex_lock(&dev->struct_mutex); 1029 mutex_lock(&dev->mode_config.mutex);
975 ironlake_panel_vdd_off_sync(intel_dp); 1030 ironlake_panel_vdd_off_sync(intel_dp);
976 mutex_unlock(&dev->struct_mutex); 1031 mutex_unlock(&dev->mode_config.mutex);
977} 1032}
978 1033
979static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync) 1034static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
@@ -983,7 +1038,7 @@ static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
983 1038
984 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd); 1039 DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
985 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on"); 1040 WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
986 1041
987 intel_dp->want_panel_vdd = false; 1042 intel_dp->want_panel_vdd = false;
988 1043
989 if (sync) { 1044 if (sync) {
@@ -999,23 +1054,25 @@ static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
999 } 1054 }
1000} 1055}
1001 1056
1002/* Returns true if the panel was already on when called */
1003static void ironlake_edp_panel_on(struct intel_dp *intel_dp) 1057static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
1004{ 1058{
1005 struct drm_device *dev = intel_dp->base.base.dev; 1059 struct drm_device *dev = intel_dp->base.base.dev;
1006 struct drm_i915_private *dev_priv = dev->dev_private; 1060 struct drm_i915_private *dev_priv = dev->dev_private;
1007 u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE; 1061 u32 pp;
1008 1062
1009 if (!is_edp(intel_dp)) 1063 if (!is_edp(intel_dp))
1010 return; 1064 return;
1011 if (ironlake_edp_have_panel_power(intel_dp)) 1065
1066 DRM_DEBUG_KMS("Turn eDP power on\n");
1067
1068 if (ironlake_edp_have_panel_power(intel_dp)) {
1069 DRM_DEBUG_KMS("eDP power already on\n");
1012 return; 1070 return;
1071 }
1013 1072
1014 ironlake_wait_panel_off(intel_dp); 1073 ironlake_wait_panel_power_cycle(intel_dp);
1015 pp = I915_READ(PCH_PP_CONTROL);
1016 pp &= ~PANEL_UNLOCK_MASK;
1017 pp |= PANEL_UNLOCK_REGS;
1018 1074
1075 pp = ironlake_get_pp_control(dev_priv);
1019 if (IS_GEN5(dev)) { 1076 if (IS_GEN5(dev)) {
1020 /* ILK workaround: disable reset around power sequence */ 1077 /* ILK workaround: disable reset around power sequence */
1021 pp &= ~PANEL_POWER_RESET; 1078 pp &= ~PANEL_POWER_RESET;
@@ -1024,13 +1081,13 @@ static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
1024 } 1081 }
1025 1082
1026 pp |= POWER_TARGET_ON; 1083 pp |= POWER_TARGET_ON;
1084 if (!IS_GEN5(dev))
1085 pp |= PANEL_POWER_RESET;
1086
1027 I915_WRITE(PCH_PP_CONTROL, pp); 1087 I915_WRITE(PCH_PP_CONTROL, pp);
1028 POSTING_READ(PCH_PP_CONTROL); 1088 POSTING_READ(PCH_PP_CONTROL);
1029 1089
1030 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask, 1090 ironlake_wait_panel_on(intel_dp);
1031 5000))
1032 DRM_ERROR("panel on wait timed out: 0x%08x\n",
1033 I915_READ(PCH_PP_STATUS));
1034 1091
1035 if (IS_GEN5(dev)) { 1092 if (IS_GEN5(dev)) {
1036 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 1093 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
@@ -1039,46 +1096,25 @@ static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
1039 } 1096 }
1040} 1097}
1041 1098
1042static void ironlake_edp_panel_off(struct drm_encoder *encoder) 1099static void ironlake_edp_panel_off(struct intel_dp *intel_dp)
1043{ 1100{
1044 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1101 struct drm_device *dev = intel_dp->base.base.dev;
1045 struct drm_device *dev = encoder->dev;
1046 struct drm_i915_private *dev_priv = dev->dev_private; 1102 struct drm_i915_private *dev_priv = dev->dev_private;
1047 u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK | 1103 u32 pp;
1048 PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
1049 1104
1050 if (!is_edp(intel_dp)) 1105 if (!is_edp(intel_dp))
1051 return; 1106 return;
1052 pp = I915_READ(PCH_PP_CONTROL);
1053 pp &= ~PANEL_UNLOCK_MASK;
1054 pp |= PANEL_UNLOCK_REGS;
1055 1107
1056 if (IS_GEN5(dev)) { 1108 DRM_DEBUG_KMS("Turn eDP power off\n");
1057 /* ILK workaround: disable reset around power sequence */
1058 pp &= ~PANEL_POWER_RESET;
1059 I915_WRITE(PCH_PP_CONTROL, pp);
1060 POSTING_READ(PCH_PP_CONTROL);
1061 }
1062 1109
1063 intel_dp->panel_off_jiffies = jiffies; 1110 WARN(intel_dp->want_panel_vdd, "Cannot turn power off while VDD is on\n");
1064 1111
1065 if (IS_GEN5(dev)) { 1112 pp = ironlake_get_pp_control(dev_priv);
1066 pp &= ~POWER_TARGET_ON; 1113 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
1067 I915_WRITE(PCH_PP_CONTROL, pp); 1114 I915_WRITE(PCH_PP_CONTROL, pp);
1068 POSTING_READ(PCH_PP_CONTROL); 1115 POSTING_READ(PCH_PP_CONTROL);
1069 pp &= ~POWER_TARGET_ON;
1070 I915_WRITE(PCH_PP_CONTROL, pp);
1071 POSTING_READ(PCH_PP_CONTROL);
1072 msleep(intel_dp->panel_power_cycle_delay);
1073
1074 if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
1075 DRM_ERROR("panel off wait timed out: 0x%08x\n",
1076 I915_READ(PCH_PP_STATUS));
1077 1116
1078 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 1117 ironlake_wait_panel_off(intel_dp);
1079 I915_WRITE(PCH_PP_CONTROL, pp);
1080 POSTING_READ(PCH_PP_CONTROL);
1081 }
1082} 1118}
1083 1119
1084static void ironlake_edp_backlight_on(struct intel_dp *intel_dp) 1120static void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
@@ -1098,9 +1134,7 @@ static void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
1098 * allowing it to appear. 1134 * allowing it to appear.
1099 */ 1135 */
1100 msleep(intel_dp->backlight_on_delay); 1136 msleep(intel_dp->backlight_on_delay);
1101 pp = I915_READ(PCH_PP_CONTROL); 1137 pp = ironlake_get_pp_control(dev_priv);
1102 pp &= ~PANEL_UNLOCK_MASK;
1103 pp |= PANEL_UNLOCK_REGS;
1104 pp |= EDP_BLC_ENABLE; 1138 pp |= EDP_BLC_ENABLE;
1105 I915_WRITE(PCH_PP_CONTROL, pp); 1139 I915_WRITE(PCH_PP_CONTROL, pp);
1106 POSTING_READ(PCH_PP_CONTROL); 1140 POSTING_READ(PCH_PP_CONTROL);
@@ -1116,9 +1150,7 @@ static void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
1116 return; 1150 return;
1117 1151
1118 DRM_DEBUG_KMS("\n"); 1152 DRM_DEBUG_KMS("\n");
1119 pp = I915_READ(PCH_PP_CONTROL); 1153 pp = ironlake_get_pp_control(dev_priv);
1120 pp &= ~PANEL_UNLOCK_MASK;
1121 pp |= PANEL_UNLOCK_REGS;
1122 pp &= ~EDP_BLC_ENABLE; 1154 pp &= ~EDP_BLC_ENABLE;
1123 I915_WRITE(PCH_PP_CONTROL, pp); 1155 I915_WRITE(PCH_PP_CONTROL, pp);
1124 POSTING_READ(PCH_PP_CONTROL); 1156 POSTING_READ(PCH_PP_CONTROL);
@@ -1186,17 +1218,18 @@ static void intel_dp_prepare(struct drm_encoder *encoder)
1186{ 1218{
1187 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1219 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1188 1220
1221 ironlake_edp_backlight_off(intel_dp);
1222 ironlake_edp_panel_off(intel_dp);
1223
1189 /* Wake up the sink first */ 1224 /* Wake up the sink first */
1190 ironlake_edp_panel_vdd_on(intel_dp); 1225 ironlake_edp_panel_vdd_on(intel_dp);
1191 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 1226 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1227 intel_dp_link_down(intel_dp);
1192 ironlake_edp_panel_vdd_off(intel_dp, false); 1228 ironlake_edp_panel_vdd_off(intel_dp, false);
1193 1229
1194 /* Make sure the panel is off before trying to 1230 /* Make sure the panel is off before trying to
1195 * change the mode 1231 * change the mode
1196 */ 1232 */
1197 ironlake_edp_backlight_off(intel_dp);
1198 intel_dp_link_down(intel_dp);
1199 ironlake_edp_panel_off(encoder);
1200} 1233}
1201 1234
1202static void intel_dp_commit(struct drm_encoder *encoder) 1235static void intel_dp_commit(struct drm_encoder *encoder)
@@ -1210,7 +1243,6 @@ static void intel_dp_commit(struct drm_encoder *encoder)
1210 intel_dp_start_link_train(intel_dp); 1243 intel_dp_start_link_train(intel_dp);
1211 ironlake_edp_panel_on(intel_dp); 1244 ironlake_edp_panel_on(intel_dp);
1212 ironlake_edp_panel_vdd_off(intel_dp, true); 1245 ironlake_edp_panel_vdd_off(intel_dp, true);
1213
1214 intel_dp_complete_link_train(intel_dp); 1246 intel_dp_complete_link_train(intel_dp);
1215 ironlake_edp_backlight_on(intel_dp); 1247 ironlake_edp_backlight_on(intel_dp);
1216 1248
@@ -1229,16 +1261,20 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode)
1229 uint32_t dp_reg = I915_READ(intel_dp->output_reg); 1261 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1230 1262
1231 if (mode != DRM_MODE_DPMS_ON) { 1263 if (mode != DRM_MODE_DPMS_ON) {
1264 ironlake_edp_backlight_off(intel_dp);
1265 ironlake_edp_panel_off(intel_dp);
1266
1232 ironlake_edp_panel_vdd_on(intel_dp); 1267 ironlake_edp_panel_vdd_on(intel_dp);
1233 if (is_edp(intel_dp))
1234 ironlake_edp_backlight_off(intel_dp);
1235 intel_dp_sink_dpms(intel_dp, mode); 1268 intel_dp_sink_dpms(intel_dp, mode);
1236 intel_dp_link_down(intel_dp); 1269 intel_dp_link_down(intel_dp);
1237 ironlake_edp_panel_off(encoder);
1238 if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
1239 ironlake_edp_pll_off(encoder);
1240 ironlake_edp_panel_vdd_off(intel_dp, false); 1270 ironlake_edp_panel_vdd_off(intel_dp, false);
1271
1272 if (is_cpu_edp(intel_dp))
1273 ironlake_edp_pll_off(encoder);
1241 } else { 1274 } else {
1275 if (is_cpu_edp(intel_dp))
1276 ironlake_edp_pll_on(encoder);
1277
1242 ironlake_edp_panel_vdd_on(intel_dp); 1278 ironlake_edp_panel_vdd_on(intel_dp);
1243 intel_dp_sink_dpms(intel_dp, mode); 1279 intel_dp_sink_dpms(intel_dp, mode);
1244 if (!(dp_reg & DP_PORT_EN)) { 1280 if (!(dp_reg & DP_PORT_EN)) {
@@ -1246,7 +1282,6 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode)
1246 ironlake_edp_panel_on(intel_dp); 1282 ironlake_edp_panel_on(intel_dp);
1247 ironlake_edp_panel_vdd_off(intel_dp, true); 1283 ironlake_edp_panel_vdd_off(intel_dp, true);
1248 intel_dp_complete_link_train(intel_dp); 1284 intel_dp_complete_link_train(intel_dp);
1249 ironlake_edp_backlight_on(intel_dp);
1250 } else 1285 } else
1251 ironlake_edp_panel_vdd_off(intel_dp, false); 1286 ironlake_edp_panel_vdd_off(intel_dp, false);
1252 ironlake_edp_backlight_on(intel_dp); 1287 ironlake_edp_backlight_on(intel_dp);
@@ -1284,11 +1319,11 @@ intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
1284 * link status information 1319 * link status information
1285 */ 1320 */
1286static bool 1321static bool
1287intel_dp_get_link_status(struct intel_dp *intel_dp) 1322intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
1288{ 1323{
1289 return intel_dp_aux_native_read_retry(intel_dp, 1324 return intel_dp_aux_native_read_retry(intel_dp,
1290 DP_LANE0_1_STATUS, 1325 DP_LANE0_1_STATUS,
1291 intel_dp->link_status, 1326 link_status,
1292 DP_LINK_STATUS_SIZE); 1327 DP_LINK_STATUS_SIZE);
1293} 1328}
1294 1329
@@ -1300,27 +1335,25 @@ intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1300} 1335}
1301 1336
1302static uint8_t 1337static uint8_t
1303intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE], 1338intel_get_adjust_request_voltage(uint8_t adjust_request[2],
1304 int lane) 1339 int lane)
1305{ 1340{
1306 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1307 int s = ((lane & 1) ? 1341 int s = ((lane & 1) ?
1308 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT : 1342 DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
1309 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT); 1343 DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
1310 uint8_t l = intel_dp_link_status(link_status, i); 1344 uint8_t l = adjust_request[lane>>1];
1311 1345
1312 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT; 1346 return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
1313} 1347}
1314 1348
1315static uint8_t 1349static uint8_t
1316intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE], 1350intel_get_adjust_request_pre_emphasis(uint8_t adjust_request[2],
1317 int lane) 1351 int lane)
1318{ 1352{
1319 int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
1320 int s = ((lane & 1) ? 1353 int s = ((lane & 1) ?
1321 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT : 1354 DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
1322 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT); 1355 DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
1323 uint8_t l = intel_dp_link_status(link_status, i); 1356 uint8_t l = adjust_request[lane>>1];
1324 1357
1325 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT; 1358 return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
1326} 1359}
@@ -1343,6 +1376,7 @@ static char *link_train_names[] = {
1343 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB 1376 * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
1344 */ 1377 */
1345#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800 1378#define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
1379#define I830_DP_VOLTAGE_MAX_CPT DP_TRAIN_VOLTAGE_SWING_1200
1346 1380
1347static uint8_t 1381static uint8_t
1348intel_dp_pre_emphasis_max(uint8_t voltage_swing) 1382intel_dp_pre_emphasis_max(uint8_t voltage_swing)
@@ -1361,15 +1395,18 @@ intel_dp_pre_emphasis_max(uint8_t voltage_swing)
1361} 1395}
1362 1396
1363static void 1397static void
1364intel_get_adjust_train(struct intel_dp *intel_dp) 1398intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
1365{ 1399{
1400 struct drm_device *dev = intel_dp->base.base.dev;
1366 uint8_t v = 0; 1401 uint8_t v = 0;
1367 uint8_t p = 0; 1402 uint8_t p = 0;
1368 int lane; 1403 int lane;
1404 uint8_t *adjust_request = link_status + (DP_ADJUST_REQUEST_LANE0_1 - DP_LANE0_1_STATUS);
1405 int voltage_max;
1369 1406
1370 for (lane = 0; lane < intel_dp->lane_count; lane++) { 1407 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1371 uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane); 1408 uint8_t this_v = intel_get_adjust_request_voltage(adjust_request, lane);
1372 uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane); 1409 uint8_t this_p = intel_get_adjust_request_pre_emphasis(adjust_request, lane);
1373 1410
1374 if (this_v > v) 1411 if (this_v > v)
1375 v = this_v; 1412 v = this_v;
@@ -1377,8 +1414,12 @@ intel_get_adjust_train(struct intel_dp *intel_dp)
1377 p = this_p; 1414 p = this_p;
1378 } 1415 }
1379 1416
1380 if (v >= I830_DP_VOLTAGE_MAX) 1417 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
1381 v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED; 1418 voltage_max = I830_DP_VOLTAGE_MAX_CPT;
1419 else
1420 voltage_max = I830_DP_VOLTAGE_MAX;
1421 if (v >= voltage_max)
1422 v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
1382 1423
1383 if (p >= intel_dp_pre_emphasis_max(v)) 1424 if (p >= intel_dp_pre_emphasis_max(v))
1384 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED; 1425 p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
@@ -1388,7 +1429,7 @@ intel_get_adjust_train(struct intel_dp *intel_dp)
1388} 1429}
1389 1430
1390static uint32_t 1431static uint32_t
1391intel_dp_signal_levels(uint8_t train_set, int lane_count) 1432intel_dp_signal_levels(uint8_t train_set)
1392{ 1433{
1393 uint32_t signal_levels = 0; 1434 uint32_t signal_levels = 0;
1394 1435
@@ -1457,9 +1498,8 @@ static uint8_t
1457intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE], 1498intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
1458 int lane) 1499 int lane)
1459{ 1500{
1460 int i = DP_LANE0_1_STATUS + (lane >> 1);
1461 int s = (lane & 1) * 4; 1501 int s = (lane & 1) * 4;
1462 uint8_t l = intel_dp_link_status(link_status, i); 1502 uint8_t l = link_status[lane>>1];
1463 1503
1464 return (l >> s) & 0xf; 1504 return (l >> s) & 0xf;
1465} 1505}
@@ -1484,18 +1524,18 @@ intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count
1484 DP_LANE_CHANNEL_EQ_DONE|\ 1524 DP_LANE_CHANNEL_EQ_DONE|\
1485 DP_LANE_SYMBOL_LOCKED) 1525 DP_LANE_SYMBOL_LOCKED)
1486static bool 1526static bool
1487intel_channel_eq_ok(struct intel_dp *intel_dp) 1527intel_channel_eq_ok(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
1488{ 1528{
1489 uint8_t lane_align; 1529 uint8_t lane_align;
1490 uint8_t lane_status; 1530 uint8_t lane_status;
1491 int lane; 1531 int lane;
1492 1532
1493 lane_align = intel_dp_link_status(intel_dp->link_status, 1533 lane_align = intel_dp_link_status(link_status,
1494 DP_LANE_ALIGN_STATUS_UPDATED); 1534 DP_LANE_ALIGN_STATUS_UPDATED);
1495 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0) 1535 if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
1496 return false; 1536 return false;
1497 for (lane = 0; lane < intel_dp->lane_count; lane++) { 1537 for (lane = 0; lane < intel_dp->lane_count; lane++) {
1498 lane_status = intel_get_lane_status(intel_dp->link_status, lane); 1538 lane_status = intel_get_lane_status(link_status, lane);
1499 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS) 1539 if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
1500 return false; 1540 return false;
1501 } 1541 }
@@ -1520,8 +1560,9 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
1520 1560
1521 ret = intel_dp_aux_native_write(intel_dp, 1561 ret = intel_dp_aux_native_write(intel_dp,
1522 DP_TRAINING_LANE0_SET, 1562 DP_TRAINING_LANE0_SET,
1523 intel_dp->train_set, 4); 1563 intel_dp->train_set,
1524 if (ret != 4) 1564 intel_dp->lane_count);
1565 if (ret != intel_dp->lane_count)
1525 return false; 1566 return false;
1526 1567
1527 return true; 1568 return true;
@@ -1537,7 +1578,7 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1537 int i; 1578 int i;
1538 uint8_t voltage; 1579 uint8_t voltage;
1539 bool clock_recovery = false; 1580 bool clock_recovery = false;
1540 int tries; 1581 int voltage_tries, loop_tries;
1541 u32 reg; 1582 u32 reg;
1542 uint32_t DP = intel_dp->DP; 1583 uint32_t DP = intel_dp->DP;
1543 1584
@@ -1564,16 +1605,20 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1564 DP &= ~DP_LINK_TRAIN_MASK; 1605 DP &= ~DP_LINK_TRAIN_MASK;
1565 memset(intel_dp->train_set, 0, 4); 1606 memset(intel_dp->train_set, 0, 4);
1566 voltage = 0xff; 1607 voltage = 0xff;
1567 tries = 0; 1608 voltage_tries = 0;
1609 loop_tries = 0;
1568 clock_recovery = false; 1610 clock_recovery = false;
1569 for (;;) { 1611 for (;;) {
1570 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */ 1612 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
1613 uint8_t link_status[DP_LINK_STATUS_SIZE];
1571 uint32_t signal_levels; 1614 uint32_t signal_levels;
1572 if (IS_GEN6(dev) && is_edp(intel_dp)) { 1615
1616 if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
1573 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); 1617 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
1574 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; 1618 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1575 } else { 1619 } else {
1576 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count); 1620 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
1621 DRM_DEBUG_KMS("training pattern 1 signal levels %08x\n", signal_levels);
1577 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1622 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1578 } 1623 }
1579 1624
@@ -1589,10 +1634,13 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1589 /* Set training pattern 1 */ 1634 /* Set training pattern 1 */
1590 1635
1591 udelay(100); 1636 udelay(100);
1592 if (!intel_dp_get_link_status(intel_dp)) 1637 if (!intel_dp_get_link_status(intel_dp, link_status)) {
1638 DRM_ERROR("failed to get link status\n");
1593 break; 1639 break;
1640 }
1594 1641
1595 if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) { 1642 if (intel_clock_recovery_ok(link_status, intel_dp->lane_count)) {
1643 DRM_DEBUG_KMS("clock recovery OK\n");
1596 clock_recovery = true; 1644 clock_recovery = true;
1597 break; 1645 break;
1598 } 1646 }
@@ -1601,20 +1649,30 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1601 for (i = 0; i < intel_dp->lane_count; i++) 1649 for (i = 0; i < intel_dp->lane_count; i++)
1602 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0) 1650 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1603 break; 1651 break;
1604 if (i == intel_dp->lane_count) 1652 if (i == intel_dp->lane_count) {
1605 break; 1653 ++loop_tries;
1654 if (loop_tries == 5) {
1655 DRM_DEBUG_KMS("too many full retries, give up\n");
1656 break;
1657 }
1658 memset(intel_dp->train_set, 0, 4);
1659 voltage_tries = 0;
1660 continue;
1661 }
1606 1662
1607 /* Check to see if we've tried the same voltage 5 times */ 1663 /* Check to see if we've tried the same voltage 5 times */
1608 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) { 1664 if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
1609 ++tries; 1665 ++voltage_tries;
1610 if (tries == 5) 1666 if (voltage_tries == 5) {
1667 DRM_DEBUG_KMS("too many voltage retries, give up\n");
1611 break; 1668 break;
1669 }
1612 } else 1670 } else
1613 tries = 0; 1671 voltage_tries = 0;
1614 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK; 1672 voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
1615 1673
1616 /* Compute new intel_dp->train_set as requested by target */ 1674 /* Compute new intel_dp->train_set as requested by target */
1617 intel_get_adjust_train(intel_dp); 1675 intel_get_adjust_train(intel_dp, link_status);
1618 } 1676 }
1619 1677
1620 intel_dp->DP = DP; 1678 intel_dp->DP = DP;
@@ -1637,6 +1695,7 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1637 for (;;) { 1695 for (;;) {
1638 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */ 1696 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
1639 uint32_t signal_levels; 1697 uint32_t signal_levels;
1698 uint8_t link_status[DP_LINK_STATUS_SIZE];
1640 1699
1641 if (cr_tries > 5) { 1700 if (cr_tries > 5) {
1642 DRM_ERROR("failed to train DP, aborting\n"); 1701 DRM_ERROR("failed to train DP, aborting\n");
@@ -1644,11 +1703,11 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1644 break; 1703 break;
1645 } 1704 }
1646 1705
1647 if (IS_GEN6(dev) && is_edp(intel_dp)) { 1706 if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
1648 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]); 1707 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
1649 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; 1708 DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
1650 } else { 1709 } else {
1651 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count); 1710 signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
1652 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1711 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1653 } 1712 }
1654 1713
@@ -1664,17 +1723,17 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1664 break; 1723 break;
1665 1724
1666 udelay(400); 1725 udelay(400);
1667 if (!intel_dp_get_link_status(intel_dp)) 1726 if (!intel_dp_get_link_status(intel_dp, link_status))
1668 break; 1727 break;
1669 1728
1670 /* Make sure clock is still ok */ 1729 /* Make sure clock is still ok */
1671 if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) { 1730 if (!intel_clock_recovery_ok(link_status, intel_dp->lane_count)) {
1672 intel_dp_start_link_train(intel_dp); 1731 intel_dp_start_link_train(intel_dp);
1673 cr_tries++; 1732 cr_tries++;
1674 continue; 1733 continue;
1675 } 1734 }
1676 1735
1677 if (intel_channel_eq_ok(intel_dp)) { 1736 if (intel_channel_eq_ok(intel_dp, link_status)) {
1678 channel_eq = true; 1737 channel_eq = true;
1679 break; 1738 break;
1680 } 1739 }
@@ -1689,7 +1748,7 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1689 } 1748 }
1690 1749
1691 /* Compute new intel_dp->train_set as requested by target */ 1750 /* Compute new intel_dp->train_set as requested by target */
1692 intel_get_adjust_train(intel_dp); 1751 intel_get_adjust_train(intel_dp, link_status);
1693 ++tries; 1752 ++tries;
1694 } 1753 }
1695 1754
@@ -1734,8 +1793,12 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1734 1793
1735 msleep(17); 1794 msleep(17);
1736 1795
1737 if (is_edp(intel_dp)) 1796 if (is_edp(intel_dp)) {
1738 DP |= DP_LINK_TRAIN_OFF; 1797 if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
1798 DP |= DP_LINK_TRAIN_OFF_CPT;
1799 else
1800 DP |= DP_LINK_TRAIN_OFF;
1801 }
1739 1802
1740 if (!HAS_PCH_CPT(dev) && 1803 if (!HAS_PCH_CPT(dev) &&
1741 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) { 1804 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
@@ -1821,6 +1884,7 @@ static void
1821intel_dp_check_link_status(struct intel_dp *intel_dp) 1884intel_dp_check_link_status(struct intel_dp *intel_dp)
1822{ 1885{
1823 u8 sink_irq_vector; 1886 u8 sink_irq_vector;
1887 u8 link_status[DP_LINK_STATUS_SIZE];
1824 1888
1825 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON) 1889 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON)
1826 return; 1890 return;
@@ -1829,7 +1893,7 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
1829 return; 1893 return;
1830 1894
1831 /* Try to read receiver status if the link appears to be up */ 1895 /* Try to read receiver status if the link appears to be up */
1832 if (!intel_dp_get_link_status(intel_dp)) { 1896 if (!intel_dp_get_link_status(intel_dp, link_status)) {
1833 intel_dp_link_down(intel_dp); 1897 intel_dp_link_down(intel_dp);
1834 return; 1898 return;
1835 } 1899 }
@@ -1854,7 +1918,7 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
1854 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n"); 1918 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
1855 } 1919 }
1856 1920
1857 if (!intel_channel_eq_ok(intel_dp)) { 1921 if (!intel_channel_eq_ok(intel_dp, link_status)) {
1858 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n", 1922 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
1859 drm_get_encoder_name(&intel_dp->base.base)); 1923 drm_get_encoder_name(&intel_dp->base.base));
1860 intel_dp_start_link_train(intel_dp); 1924 intel_dp_start_link_train(intel_dp);
@@ -2178,7 +2242,8 @@ intel_trans_dp_port_sel(struct drm_crtc *crtc)
2178 continue; 2242 continue;
2179 2243
2180 intel_dp = enc_to_intel_dp(encoder); 2244 intel_dp = enc_to_intel_dp(encoder);
2181 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) 2245 if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
2246 intel_dp->base.type == INTEL_OUTPUT_EDP)
2182 return intel_dp->output_reg; 2247 return intel_dp->output_reg;
2183 } 2248 }
2184 2249
@@ -2320,7 +2385,7 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2320 2385
2321 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >> 2386 cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
2322 PANEL_LIGHT_ON_DELAY_SHIFT; 2387 PANEL_LIGHT_ON_DELAY_SHIFT;
2323 2388
2324 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >> 2389 cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
2325 PANEL_LIGHT_OFF_DELAY_SHIFT; 2390 PANEL_LIGHT_OFF_DELAY_SHIFT;
2326 2391
@@ -2353,11 +2418,10 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2353 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n", 2418 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
2354 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay); 2419 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
2355 2420
2356 intel_dp->panel_off_jiffies = jiffies - intel_dp->panel_power_down_delay;
2357
2358 ironlake_edp_panel_vdd_on(intel_dp); 2421 ironlake_edp_panel_vdd_on(intel_dp);
2359 ret = intel_dp_get_dpcd(intel_dp); 2422 ret = intel_dp_get_dpcd(intel_dp);
2360 ironlake_edp_panel_vdd_off(intel_dp, false); 2423 ironlake_edp_panel_vdd_off(intel_dp, false);
2424
2361 if (ret) { 2425 if (ret) {
2362 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) 2426 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
2363 dev_priv->no_aux_handshake = 2427 dev_priv->no_aux_handshake =
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index 9ed5380e5a5..d30ccccb9d7 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_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 499d4c0dbee..21f60b7d69a 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -326,7 +326,8 @@ static int intel_panel_update_status(struct backlight_device *bd)
326static int intel_panel_get_brightness(struct backlight_device *bd) 326static int intel_panel_get_brightness(struct backlight_device *bd)
327{ 327{
328 struct drm_device *dev = bl_get_data(bd); 328 struct drm_device *dev = bl_get_data(bd);
329 return intel_panel_get_backlight(dev); 329 struct drm_i915_private *dev_priv = dev->dev_private;
330 return dev_priv->backlight_level;
330} 331}
331 332
332static const struct backlight_ops intel_panel_bl_ops = { 333static const struct backlight_ops intel_panel_bl_ops = {
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 6db3b1ccb6e..3003fb25aef 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 42d31874edf..33daa29eea6 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 f172bd5c257..722a91b69b0 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_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 032a8209813..5fc201b49d3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -640,10 +640,9 @@ static int
640nv50_pll_set(struct drm_device *dev, uint32_t reg, uint32_t clk) 640nv50_pll_set(struct drm_device *dev, uint32_t reg, uint32_t clk)
641{ 641{
642 struct drm_nouveau_private *dev_priv = dev->dev_private; 642 struct drm_nouveau_private *dev_priv = dev->dev_private;
643 uint32_t reg0 = nv_rd32(dev, reg + 0);
644 uint32_t reg1 = nv_rd32(dev, reg + 4);
645 struct nouveau_pll_vals pll; 643 struct nouveau_pll_vals pll;
646 struct pll_lims pll_limits; 644 struct pll_lims pll_limits;
645 u32 ctrl, mask, coef;
647 int ret; 646 int ret;
648 647
649 ret = get_pll_limits(dev, reg, &pll_limits); 648 ret = get_pll_limits(dev, reg, &pll_limits);
@@ -654,15 +653,20 @@ nv50_pll_set(struct drm_device *dev, uint32_t reg, uint32_t clk)
654 if (!clk) 653 if (!clk)
655 return -ERANGE; 654 return -ERANGE;
656 655
657 reg0 = (reg0 & 0xfff8ffff) | (pll.log2P << 16); 656 coef = pll.N1 << 8 | pll.M1;
658 reg1 = (reg1 & 0xffff0000) | (pll.N1 << 8) | pll.M1; 657 ctrl = pll.log2P << 16;
659 658 mask = 0x00070000;
660 if (dev_priv->vbios.execute) { 659 if (reg == 0x004008) {
661 still_alive(); 660 mask |= 0x01f80000;
662 nv_wr32(dev, reg + 4, reg1); 661 ctrl |= (pll_limits.log2p_bias << 19);
663 nv_wr32(dev, reg + 0, reg0); 662 ctrl |= (pll.log2P << 22);
664 } 663 }
665 664
665 if (!dev_priv->vbios.execute)
666 return 0;
667
668 nv_mask(dev, reg + 0, mask, ctrl);
669 nv_wr32(dev, reg + 4, coef);
666 return 0; 670 return 0;
667} 671}
668 672
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 7226f419e17..7cc37e69086 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -148,7 +148,7 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
148 148
149 if (dev_priv->card_type == NV_10 && 149 if (dev_priv->card_type == NV_10 &&
150 nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) && 150 nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) &&
151 nvbo->bo.mem.num_pages < vram_pages / 2) { 151 nvbo->bo.mem.num_pages < vram_pages / 4) {
152 /* 152 /*
153 * Make sure that the color and depth buffers are handled 153 * Make sure that the color and depth buffers are handled
154 * by independent memory controller units. Up to a 9x 154 * by independent memory controller units. Up to a 9x
diff --git a/drivers/gpu/drm/nouveau/nouveau_channel.c b/drivers/gpu/drm/nouveau/nouveau_channel.c
index a319d5646ea..bb6ec9ef867 100644
--- a/drivers/gpu/drm/nouveau/nouveau_channel.c
+++ b/drivers/gpu/drm/nouveau/nouveau_channel.c
@@ -158,6 +158,7 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,
158 INIT_LIST_HEAD(&chan->nvsw.vbl_wait); 158 INIT_LIST_HEAD(&chan->nvsw.vbl_wait);
159 INIT_LIST_HEAD(&chan->nvsw.flip); 159 INIT_LIST_HEAD(&chan->nvsw.flip);
160 INIT_LIST_HEAD(&chan->fence.pending); 160 INIT_LIST_HEAD(&chan->fence.pending);
161 spin_lock_init(&chan->fence.lock);
161 162
162 /* setup channel's memory and vm */ 163 /* setup channel's memory and vm */
163 ret = nouveau_gpuobj_channel_init(chan, vram_handle, gart_handle); 164 ret = nouveau_gpuobj_channel_init(chan, vram_handle, gart_handle);
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index e0d275e1c96..cea6696b190 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -710,7 +710,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
710 case OUTPUT_DP: 710 case OUTPUT_DP:
711 max_clock = nv_encoder->dp.link_nr; 711 max_clock = nv_encoder->dp.link_nr;
712 max_clock *= nv_encoder->dp.link_bw; 712 max_clock *= nv_encoder->dp.link_bw;
713 clock = clock * nouveau_connector_bpp(connector) / 8; 713 clock = clock * nouveau_connector_bpp(connector) / 10;
714 break; 714 break;
715 default: 715 default:
716 BUG_ON(1); 716 BUG_ON(1);
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index ddbabefb427..b12fd2c8081 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -369,3 +369,48 @@ nouveau_finish_page_flip(struct nouveau_channel *chan,
369 spin_unlock_irqrestore(&dev->event_lock, flags); 369 spin_unlock_irqrestore(&dev->event_lock, flags);
370 return 0; 370 return 0;
371} 371}
372
373int
374nouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
375 struct drm_mode_create_dumb *args)
376{
377 struct nouveau_bo *bo;
378 int ret;
379
380 args->pitch = roundup(args->width * (args->bpp / 8), 256);
381 args->size = args->pitch * args->height;
382 args->size = roundup(args->size, PAGE_SIZE);
383
384 ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo);
385 if (ret)
386 return ret;
387
388 ret = drm_gem_handle_create(file_priv, bo->gem, &args->handle);
389 drm_gem_object_unreference_unlocked(bo->gem);
390 return ret;
391}
392
393int
394nouveau_display_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev,
395 uint32_t handle)
396{
397 return drm_gem_handle_delete(file_priv, handle);
398}
399
400int
401nouveau_display_dumb_map_offset(struct drm_file *file_priv,
402 struct drm_device *dev,
403 uint32_t handle, uint64_t *poffset)
404{
405 struct drm_gem_object *gem;
406
407 gem = drm_gem_object_lookup(dev, file_priv, handle);
408 if (gem) {
409 struct nouveau_bo *bo = gem->driver_private;
410 *poffset = bo->bo.addr_space_offset;
411 drm_gem_object_unreference_unlocked(gem);
412 return 0;
413 }
414
415 return -ENOENT;
416}
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.c b/drivers/gpu/drm/nouveau/nouveau_drv.c
index c1e01f37b9d..9791d13c9e3 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"
@@ -432,6 +433,10 @@ static struct drm_driver driver = {
432 .gem_open_object = nouveau_gem_object_open, 433 .gem_open_object = nouveau_gem_object_open,
433 .gem_close_object = nouveau_gem_object_close, 434 .gem_close_object = nouveau_gem_object_close,
434 435
436 .dumb_create = nouveau_display_dumb_create,
437 .dumb_map_offset = nouveau_display_dumb_map_offset,
438 .dumb_destroy = nouveau_display_dumb_destroy,
439
435 .name = DRIVER_NAME, 440 .name = DRIVER_NAME,
436 .desc = DRIVER_DESC, 441 .desc = DRIVER_DESC,
437#ifdef GIT_REVISION 442#ifdef GIT_REVISION
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index 29837da1098..4c0be3a4ed8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -1418,6 +1418,12 @@ int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
1418 struct drm_pending_vblank_event *event); 1418 struct drm_pending_vblank_event *event);
1419int nouveau_finish_page_flip(struct nouveau_channel *, 1419int nouveau_finish_page_flip(struct nouveau_channel *,
1420 struct nouveau_page_flip_state *); 1420 struct nouveau_page_flip_state *);
1421int nouveau_display_dumb_create(struct drm_file *, struct drm_device *,
1422 struct drm_mode_create_dumb *args);
1423int nouveau_display_dumb_map_offset(struct drm_file *, struct drm_device *,
1424 uint32_t handle, uint64_t *offset);
1425int nouveau_display_dumb_destroy(struct drm_file *, struct drm_device *,
1426 uint32_t handle);
1421 1427
1422/* nv10_gpio.c */ 1428/* nv10_gpio.c */
1423int nv10_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag); 1429int nv10_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
index 14a8627efe4..3a4cc32b9e4 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
@@ -487,6 +487,7 @@ int nouveau_fbcon_init(struct drm_device *dev)
487{ 487{
488 struct drm_nouveau_private *dev_priv = dev->dev_private; 488 struct drm_nouveau_private *dev_priv = dev->dev_private;
489 struct nouveau_fbdev *nfbdev; 489 struct nouveau_fbdev *nfbdev;
490 int preferred_bpp;
490 int ret; 491 int ret;
491 492
492 nfbdev = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL); 493 nfbdev = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL);
@@ -505,7 +506,15 @@ int nouveau_fbcon_init(struct drm_device *dev)
505 } 506 }
506 507
507 drm_fb_helper_single_add_all_connectors(&nfbdev->helper); 508 drm_fb_helper_single_add_all_connectors(&nfbdev->helper);
508 drm_fb_helper_initial_config(&nfbdev->helper, 32); 509
510 if (dev_priv->vram_size <= 32 * 1024 * 1024)
511 preferred_bpp = 8;
512 else if (dev_priv->vram_size <= 64 * 1024 * 1024)
513 preferred_bpp = 16;
514 else
515 preferred_bpp = 32;
516
517 drm_fb_helper_initial_config(&nfbdev->helper, preferred_bpp);
509 return 0; 518 return 0;
510} 519}
511 520
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index 81116cfea27..2f6daae68b9 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -539,8 +539,6 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
539 return ret; 539 return ret;
540 } 540 }
541 541
542 INIT_LIST_HEAD(&chan->fence.pending);
543 spin_lock_init(&chan->fence.lock);
544 atomic_set(&chan->fence.last_sequence_irq, 0); 542 atomic_set(&chan->fence.last_sequence_irq, 0);
545 return 0; 543 return 0;
546} 544}
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c
index f6a27fabcfe..d39b2202b19 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"
@@ -331,7 +333,7 @@ nouveau_i2c_identify(struct drm_device *dev, const char *what,
331 333
332 NV_DEBUG(dev, "Probing %ss on I2C bus: %d\n", what, index); 334 NV_DEBUG(dev, "Probing %ss on I2C bus: %d\n", what, index);
333 335
334 for (i = 0; info[i].addr; i++) { 336 for (i = 0; i2c && info[i].addr; i++) {
335 if (nouveau_probe_i2c_addr(i2c, info[i].addr) && 337 if (nouveau_probe_i2c_addr(i2c, info[i].addr) &&
336 (!match || match(i2c, &info[i]))) { 338 (!match || match(i2c, &info[i]))) {
337 NV_INFO(dev, "Detected %s: %s\n", what, info[i].type); 339 NV_INFO(dev, "Detected %s: %s\n", what, info[i].type);
diff --git a/drivers/gpu/drm/nouveau/nouveau_object.c b/drivers/gpu/drm/nouveau/nouveau_object.c
index 02222c540ae..960c0ae0c0c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_object.c
+++ b/drivers/gpu/drm/nouveau/nouveau_object.c
@@ -680,7 +680,7 @@ nouveau_gpuobj_channel_init_pramin(struct nouveau_channel *chan)
680 return ret; 680 return ret;
681 } 681 }
682 682
683 ret = drm_mm_init(&chan->ramin_heap, base, size); 683 ret = drm_mm_init(&chan->ramin_heap, base, size - base);
684 if (ret) { 684 if (ret) {
685 NV_ERROR(dev, "Error creating PRAMIN heap: %d\n", ret); 685 NV_ERROR(dev, "Error creating PRAMIN heap: %d\n", ret);
686 nouveau_gpuobj_ref(NULL, &chan->ramin); 686 nouveau_gpuobj_ref(NULL, &chan->ramin);
diff --git a/drivers/gpu/drm/nouveau/nouveau_perf.c b/drivers/gpu/drm/nouveau/nouveau_perf.c
index 9f178aa9416..33d03fbf00d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_perf.c
+++ b/drivers/gpu/drm/nouveau/nouveau_perf.c
@@ -239,7 +239,7 @@ nouveau_perf_init(struct drm_device *dev)
239 if(version == 0x15) { 239 if(version == 0x15) {
240 memtimings->timing = 240 memtimings->timing =
241 kcalloc(entries, sizeof(*memtimings->timing), GFP_KERNEL); 241 kcalloc(entries, sizeof(*memtimings->timing), GFP_KERNEL);
242 if(!memtimings) { 242 if (!memtimings->timing) {
243 NV_WARN(dev,"Could not allocate memtiming table\n"); 243 NV_WARN(dev,"Could not allocate memtiming table\n");
244 return; 244 return;
245 } 245 }
diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
index b75258a9fe4..c8a463b76c8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_sgdma.c
+++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
@@ -67,7 +67,10 @@ nouveau_sgdma_clear(struct ttm_backend *be)
67 pci_unmap_page(dev->pdev, nvbe->pages[nvbe->nr_pages], 67 pci_unmap_page(dev->pdev, nvbe->pages[nvbe->nr_pages],
68 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 68 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
69 } 69 }
70 nvbe->unmap_pages = false;
70 } 71 }
72
73 nvbe->pages = NULL;
71} 74}
72 75
73static void 76static void
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
index 82478e0998e..d8831ab42bb 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -579,6 +579,14 @@ nouveau_card_init(struct drm_device *dev)
579 if (ret) 579 if (ret)
580 goto out_display_early; 580 goto out_display_early;
581 581
582 /* workaround an odd issue on nvc1 by disabling the device's
583 * nosnoop capability. hopefully won't cause issues until a
584 * better fix is found - assuming there is one...
585 */
586 if (dev_priv->chipset == 0xc1) {
587 nv_mask(dev, 0x00088080, 0x00000800, 0x00000000);
588 }
589
582 nouveau_pm_init(dev); 590 nouveau_pm_init(dev);
583 591
584 ret = engine->vram.init(dev); 592 ret = engine->vram.init(dev);
@@ -1102,12 +1110,13 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
1102 dev_priv->noaccel = !!nouveau_noaccel; 1110 dev_priv->noaccel = !!nouveau_noaccel;
1103 if (nouveau_noaccel == -1) { 1111 if (nouveau_noaccel == -1) {
1104 switch (dev_priv->chipset) { 1112 switch (dev_priv->chipset) {
1105 case 0xc1: /* known broken */ 1113#if 0
1106 case 0xc8: /* never tested */ 1114 case 0xXX: /* known broken */
1107 NV_INFO(dev, "acceleration disabled by default, pass " 1115 NV_INFO(dev, "acceleration disabled by default, pass "
1108 "noaccel=0 to force enable\n"); 1116 "noaccel=0 to force enable\n");
1109 dev_priv->noaccel = true; 1117 dev_priv->noaccel = true;
1110 break; 1118 break;
1119#endif
1111 default: 1120 default:
1112 dev_priv->noaccel = false; 1121 dev_priv->noaccel = false;
1113 break; 1122 break;
diff --git a/drivers/gpu/drm/nouveau/nouveau_temp.c b/drivers/gpu/drm/nouveau/nouveau_temp.c
index 081ca7b03e8..5a46446dd5a 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/nv40_pm.c b/drivers/gpu/drm/nouveau/nv40_pm.c
index bbc0b9c7e1f..e676b0d5347 100644
--- a/drivers/gpu/drm/nouveau/nv40_pm.c
+++ b/drivers/gpu/drm/nouveau/nv40_pm.c
@@ -57,12 +57,14 @@ read_pll_2(struct drm_device *dev, u32 reg)
57 int P = (ctrl & 0x00070000) >> 16; 57 int P = (ctrl & 0x00070000) >> 16;
58 u32 ref = 27000, clk = 0; 58 u32 ref = 27000, clk = 0;
59 59
60 if (ctrl & 0x80000000) 60 if ((ctrl & 0x80000000) && M1) {
61 clk = ref * N1 / M1; 61 clk = ref * N1 / M1;
62 62 if ((ctrl & 0x40000100) == 0x40000000) {
63 if (!(ctrl & 0x00000100)) { 63 if (M2)
64 if (ctrl & 0x40000000) 64 clk = clk * N2 / M2;
65 clk = clk * N2 / M2; 65 else
66 clk = 0;
67 }
66 } 68 }
67 69
68 return clk >> P; 70 return clk >> P;
@@ -177,6 +179,11 @@ nv40_pm_clocks_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl)
177 } 179 }
178 180
179 /* memory clock */ 181 /* memory clock */
182 if (!perflvl->memory) {
183 info->mpll_ctrl = 0x00000000;
184 goto out;
185 }
186
180 ret = nv40_calc_pll(dev, 0x004020, &pll, perflvl->memory, 187 ret = nv40_calc_pll(dev, 0x004020, &pll, perflvl->memory,
181 &N1, &M1, &N2, &M2, &log2P); 188 &N1, &M1, &N2, &M2, &log2P);
182 if (ret < 0) 189 if (ret < 0)
@@ -264,6 +271,9 @@ nv40_pm_clocks_set(struct drm_device *dev, void *pre_state)
264 mdelay(5); 271 mdelay(5);
265 nv_mask(dev, 0x00c040, 0x00000333, info->ctrl); 272 nv_mask(dev, 0x00c040, 0x00000333, info->ctrl);
266 273
274 if (!info->mpll_ctrl)
275 goto resume;
276
267 /* wait for vblank start on active crtcs, disable memory access */ 277 /* wait for vblank start on active crtcs, disable memory access */
268 for (i = 0; i < 2; i++) { 278 for (i = 0; i < 2; i++) {
269 if (!(crtc_mask & (1 << i))) 279 if (!(crtc_mask & (1 << i)))
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index d23ca00e7d6..06de250fe61 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -616,7 +616,7 @@ nv50_display_unk10_handler(struct drm_device *dev)
616 struct drm_nouveau_private *dev_priv = dev->dev_private; 616 struct drm_nouveau_private *dev_priv = dev->dev_private;
617 struct nv50_display *disp = nv50_display(dev); 617 struct nv50_display *disp = nv50_display(dev);
618 u32 unk30 = nv_rd32(dev, 0x610030), mc; 618 u32 unk30 = nv_rd32(dev, 0x610030), mc;
619 int i, crtc, or, type = OUTPUT_ANY; 619 int i, crtc, or = 0, type = OUTPUT_ANY;
620 620
621 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); 621 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
622 disp->irq.dcb = NULL; 622 disp->irq.dcb = NULL;
@@ -708,7 +708,7 @@ nv50_display_unk20_handler(struct drm_device *dev)
708 struct nv50_display *disp = nv50_display(dev); 708 struct nv50_display *disp = nv50_display(dev);
709 u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0; 709 u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0;
710 struct dcb_entry *dcb; 710 struct dcb_entry *dcb;
711 int i, crtc, or, type = OUTPUT_ANY; 711 int i, crtc, or = 0, type = OUTPUT_ANY;
712 712
713 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30); 713 NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
714 dcb = disp->irq.dcb; 714 dcb = disp->irq.dcb;
diff --git a/drivers/gpu/drm/nouveau/nv50_graph.c b/drivers/gpu/drm/nouveau/nv50_graph.c
index 8c979b31ff6..ac601f7c4e1 100644
--- a/drivers/gpu/drm/nouveau/nv50_graph.c
+++ b/drivers/gpu/drm/nouveau/nv50_graph.c
@@ -131,8 +131,8 @@ nv50_graph_init(struct drm_device *dev, int engine)
131 NV_DEBUG(dev, "\n"); 131 NV_DEBUG(dev, "\n");
132 132
133 /* master reset */ 133 /* master reset */
134 nv_mask(dev, 0x000200, 0x00200100, 0x00000000); 134 nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
135 nv_mask(dev, 0x000200, 0x00200100, 0x00200100); 135 nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
136 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */ 136 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
137 137
138 /* reset/enable traps and interrupts */ 138 /* reset/enable traps and interrupts */
diff --git a/drivers/gpu/drm/nouveau/nv50_grctx.c b/drivers/gpu/drm/nouveau/nv50_grctx.c
index d05c2c3b244..4b46d696856 100644
--- a/drivers/gpu/drm/nouveau/nv50_grctx.c
+++ b/drivers/gpu/drm/nouveau/nv50_grctx.c
@@ -601,7 +601,7 @@ nv50_graph_construct_mmio(struct nouveau_grctx *ctx)
601 gr_def(ctx, offset + 0x1c, 0x00880000); 601 gr_def(ctx, offset + 0x1c, 0x00880000);
602 break; 602 break;
603 case 0x86: 603 case 0x86:
604 gr_def(ctx, offset + 0x1c, 0x008c0000); 604 gr_def(ctx, offset + 0x1c, 0x018c0000);
605 break; 605 break;
606 case 0x92: 606 case 0x92:
607 case 0x96: 607 case 0x96:
diff --git a/drivers/gpu/drm/nouveau/nv50_vram.c b/drivers/gpu/drm/nouveau/nv50_vram.c
index 9da23838e63..2e45e57fd86 100644
--- a/drivers/gpu/drm/nouveau/nv50_vram.c
+++ b/drivers/gpu/drm/nouveau/nv50_vram.c
@@ -160,7 +160,7 @@ nv50_vram_rblock(struct drm_device *dev)
160 colbits = (r4 & 0x0000f000) >> 12; 160 colbits = (r4 & 0x0000f000) >> 12;
161 rowbitsa = ((r4 & 0x000f0000) >> 16) + 8; 161 rowbitsa = ((r4 & 0x000f0000) >> 16) + 8;
162 rowbitsb = ((r4 & 0x00f00000) >> 20) + 8; 162 rowbitsb = ((r4 & 0x00f00000) >> 20) + 8;
163 banks = ((r4 & 0x01000000) ? 8 : 4); 163 banks = 1 << (((r4 & 0x03000000) >> 24) + 2);
164 164
165 rowsize = parts * banks * (1 << colbits) * 8; 165 rowsize = parts * banks * (1 << colbits) * 8;
166 predicted = rowsize << rowbitsa; 166 predicted = rowsize << rowbitsa;
diff --git a/drivers/gpu/drm/nouveau/nvc0_graph.c b/drivers/gpu/drm/nouveau/nvc0_graph.c
index 4b8d0b3f7d2..ecfafd70cf0 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
@@ -156,8 +157,8 @@ nvc0_graph_create_context_mmio_list(struct nouveau_channel *chan)
156 struct nvc0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR); 157 struct nvc0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
157 struct nvc0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR]; 158 struct nvc0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
158 struct drm_device *dev = chan->dev; 159 struct drm_device *dev = chan->dev;
160 struct drm_nouveau_private *dev_priv = dev->dev_private;
159 int i = 0, gpc, tp, ret; 161 int i = 0, gpc, tp, ret;
160 u32 magic;
161 162
162 ret = nouveau_gpuobj_new(dev, chan, 0x2000, 256, NVOBJ_FLAG_VM, 163 ret = nouveau_gpuobj_new(dev, chan, 0x2000, 256, NVOBJ_FLAG_VM,
163 &grch->unk408004); 164 &grch->unk408004);
@@ -206,14 +207,37 @@ nvc0_graph_create_context_mmio_list(struct nouveau_channel *chan)
206 nv_wo32(grch->mmio, i++ * 4, 0x0041880c); 207 nv_wo32(grch->mmio, i++ * 4, 0x0041880c);
207 nv_wo32(grch->mmio, i++ * 4, 0x80000018); 208 nv_wo32(grch->mmio, i++ * 4, 0x80000018);
208 209
209 magic = 0x02180000; 210 if (dev_priv->chipset != 0xc1) {
210 nv_wo32(grch->mmio, i++ * 4, 0x00405830); 211 u32 magic = 0x02180000;
211 nv_wo32(grch->mmio, i++ * 4, magic); 212 nv_wo32(grch->mmio, i++ * 4, 0x00405830);
212 for (gpc = 0; gpc < priv->gpc_nr; gpc++) { 213 nv_wo32(grch->mmio, i++ * 4, magic);
213 for (tp = 0; tp < priv->tp_nr[gpc]; tp++, magic += 0x0324) { 214 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
214 u32 reg = 0x504520 + (gpc * 0x8000) + (tp * 0x0800); 215 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
215 nv_wo32(grch->mmio, i++ * 4, reg); 216 u32 reg = TP_UNIT(gpc, tp, 0x520);
216 nv_wo32(grch->mmio, i++ * 4, magic); 217 nv_wo32(grch->mmio, i++ * 4, reg);
218 nv_wo32(grch->mmio, i++ * 4, magic);
219 magic += 0x0324;
220 }
221 }
222 } else {
223 u32 magic = 0x02180000;
224 nv_wo32(grch->mmio, i++ * 4, 0x00405830);
225 nv_wo32(grch->mmio, i++ * 4, magic | 0x0000218);
226 nv_wo32(grch->mmio, i++ * 4, 0x004064c4);
227 nv_wo32(grch->mmio, i++ * 4, 0x0086ffff);
228 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
229 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
230 u32 reg = TP_UNIT(gpc, tp, 0x520);
231 nv_wo32(grch->mmio, i++ * 4, reg);
232 nv_wo32(grch->mmio, i++ * 4, (1 << 28) | magic);
233 magic += 0x0324;
234 }
235 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
236 u32 reg = TP_UNIT(gpc, tp, 0x544);
237 nv_wo32(grch->mmio, i++ * 4, reg);
238 nv_wo32(grch->mmio, i++ * 4, magic);
239 magic += 0x0324;
240 }
217 } 241 }
218 } 242 }
219 243
@@ -357,6 +381,8 @@ nvc0_graph_init_gpc_0(struct drm_device *dev)
357 u8 tpnr[GPC_MAX]; 381 u8 tpnr[GPC_MAX];
358 int i, gpc, tpc; 382 int i, gpc, tpc;
359 383
384 nv_wr32(dev, TP_UNIT(0, 0, 0x5c), 1); /* affects TFB offset queries */
385
360 /* 386 /*
361 * TP ROP UNKVAL(magic_not_rop_nr) 387 * TP ROP UNKVAL(magic_not_rop_nr)
362 * 450: 4/0/0/0 2 3 388 * 450: 4/0/0/0 2 3
diff --git a/drivers/gpu/drm/nouveau/nvc0_grctx.c b/drivers/gpu/drm/nouveau/nvc0_grctx.c
index dd0e6a736b3..96b0b93d94c 100644
--- a/drivers/gpu/drm/nouveau/nvc0_grctx.c
+++ b/drivers/gpu/drm/nouveau/nvc0_grctx.c
@@ -1812,6 +1812,7 @@ nvc0_grctx_generate(struct nouveau_channel *chan)
1812 /* calculate first set of magics */ 1812 /* calculate first set of magics */
1813 memcpy(tpnr, priv->tp_nr, sizeof(priv->tp_nr)); 1813 memcpy(tpnr, priv->tp_nr, sizeof(priv->tp_nr));
1814 1814
1815 gpc = -1;
1815 for (tp = 0; tp < priv->tp_total; tp++) { 1816 for (tp = 0; tp < priv->tp_total; tp++) {
1816 do { 1817 do {
1817 gpc = (gpc + 1) % priv->gpc_nr; 1818 gpc = (gpc + 1) % priv->gpc_nr;
@@ -1861,30 +1862,26 @@ nvc0_grctx_generate(struct nouveau_channel *chan)
1861 1862
1862 if (1) { 1863 if (1) {
1863 u32 tp_mask = 0, tp_set = 0; 1864 u32 tp_mask = 0, tp_set = 0;
1864 u8 tpnr[GPC_MAX]; 1865 u8 tpnr[GPC_MAX], a, b;
1865 1866
1866 memcpy(tpnr, priv->tp_nr, sizeof(priv->tp_nr)); 1867 memcpy(tpnr, priv->tp_nr, sizeof(priv->tp_nr));
1867 for (gpc = 0; gpc < priv->gpc_nr; gpc++) 1868 for (gpc = 0; gpc < priv->gpc_nr; gpc++)
1868 tp_mask |= ((1 << priv->tp_nr[gpc]) - 1) << (gpc * 8); 1869 tp_mask |= ((1 << priv->tp_nr[gpc]) - 1) << (gpc * 8);
1869 1870
1870 gpc = -1; 1871 for (i = 0, gpc = -1, b = -1; i < 32; i++) {
1871 for (i = 0, gpc = -1; i < 32; i++) { 1872 a = (i * (priv->tp_total - 1)) / 32;
1872 int ltp = i * (priv->tp_total - 1) / 32; 1873 if (a != b) {
1873 1874 b = a;
1874 do { 1875 do {
1875 gpc = (gpc + 1) % priv->gpc_nr; 1876 gpc = (gpc + 1) % priv->gpc_nr;
1876 } while (!tpnr[gpc]); 1877 } while (!tpnr[gpc]);
1877 tp = priv->tp_nr[gpc] - tpnr[gpc]--; 1878 tp = priv->tp_nr[gpc] - tpnr[gpc]--;
1878 1879
1879 tp_set |= 1 << ((gpc * 8) + tp); 1880 tp_set |= 1 << ((gpc * 8) + tp);
1881 }
1880 1882
1881 do { 1883 nv_wr32(dev, 0x406800 + (i * 0x20), tp_set);
1882 nv_wr32(dev, 0x406800 + (i * 0x20), tp_set); 1884 nv_wr32(dev, 0x406c00 + (i * 0x20), tp_set ^ tp_mask);
1883 tp_set ^= tp_mask;
1884 nv_wr32(dev, 0x406c00 + (i * 0x20), tp_set);
1885 tp_set ^= tp_mask;
1886 } while (ltp == (++i * (priv->tp_total - 1) / 32));
1887 i--;
1888 } 1885 }
1889 } 1886 }
1890 1887
diff --git a/drivers/gpu/drm/nouveau/nvc0_vram.c b/drivers/gpu/drm/nouveau/nvc0_vram.c
index edbfe9360ae..ce984d573a5 100644
--- a/drivers/gpu/drm/nouveau/nvc0_vram.c
+++ b/drivers/gpu/drm/nouveau/nvc0_vram.c
@@ -43,7 +43,7 @@ static const u8 types[256] = {
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0, 44 0, 0, 0, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
46 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 46 3, 3, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3,
47 3, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 3, 0, 3, 47 3, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 3, 0, 3,
48 3, 0, 3, 3, 3, 3, 3, 0, 0, 3, 0, 3, 0, 3, 3, 0, 48 3, 0, 3, 3, 3, 3, 3, 0, 0, 3, 0, 3, 0, 3, 3, 0,
49 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 0 49 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 0
@@ -110,22 +110,26 @@ nvc0_vram_init(struct drm_device *dev)
110 u32 bsize = nv_rd32(dev, 0x10f20c); 110 u32 bsize = nv_rd32(dev, 0x10f20c);
111 u32 offset, length; 111 u32 offset, length;
112 bool uniform = true; 112 bool uniform = true;
113 int ret, i; 113 int ret, part;
114 114
115 NV_DEBUG(dev, "0x100800: 0x%08x\n", nv_rd32(dev, 0x100800)); 115 NV_DEBUG(dev, "0x100800: 0x%08x\n", nv_rd32(dev, 0x100800));
116 NV_DEBUG(dev, "parts 0x%08x bcast_mem_amount 0x%08x\n", parts, bsize); 116 NV_DEBUG(dev, "parts 0x%08x bcast_mem_amount 0x%08x\n", parts, bsize);
117 117
118 /* read amount of vram attached to each memory controller */ 118 /* read amount of vram attached to each memory controller */
119 for (i = 0; i < parts; i++) { 119 part = 0;
120 u32 psize = nv_rd32(dev, 0x11020c + (i * 0x1000)); 120 while (parts) {
121 u32 psize = nv_rd32(dev, 0x11020c + (part++ * 0x1000));
122 if (psize == 0)
123 continue;
124 parts--;
125
121 if (psize != bsize) { 126 if (psize != bsize) {
122 if (psize < bsize) 127 if (psize < bsize)
123 bsize = psize; 128 bsize = psize;
124 uniform = false; 129 uniform = false;
125 } 130 }
126 131
127 NV_DEBUG(dev, "%d: mem_amount 0x%08x\n", i, psize); 132 NV_DEBUG(dev, "%d: mem_amount 0x%08x\n", part, psize);
128
129 dev_priv->vram_size += (u64)psize << 20; 133 dev_priv->vram_size += (u64)psize << 20;
130 } 134 }
131 135
diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
index 23d63b4b3d7..cb006a718e7 100644
--- a/drivers/gpu/drm/nouveau/nvd0_display.c
+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
@@ -780,7 +780,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
780 continue; 780 continue;
781 781
782 if (nv_partner != nv_encoder && 782 if (nv_partner != nv_encoder &&
783 nv_partner->dcb->or == nv_encoder->or) { 783 nv_partner->dcb->or == nv_encoder->dcb->or) {
784 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON) 784 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
785 return; 785 return;
786 break; 786 break;
diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
index 570e190710b..bcac90b543a 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 b9e8efd2b75..4c8796ba6dd 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/Makefile b/drivers/gpu/drm/radeon/Makefile
index 9f363e0c4b6..cf8b4bc3e73 100644
--- a/drivers/gpu/drm/radeon/Makefile
+++ b/drivers/gpu/drm/radeon/Makefile
@@ -70,7 +70,7 @@ radeon-y += radeon_device.o radeon_asic.o radeon_kms.o \
70 r200.o radeon_legacy_tv.o r600_cs.o r600_blit.o r600_blit_shaders.o \ 70 r200.o radeon_legacy_tv.o r600_cs.o r600_blit.o r600_blit_shaders.o \
71 r600_blit_kms.o radeon_pm.o atombios_dp.o r600_audio.o r600_hdmi.o \ 71 r600_blit_kms.o radeon_pm.o atombios_dp.o r600_audio.o r600_hdmi.o \
72 evergreen.o evergreen_cs.o evergreen_blit_shaders.o evergreen_blit_kms.o \ 72 evergreen.o evergreen_cs.o evergreen_blit_shaders.o evergreen_blit_kms.o \
73 radeon_trace_points.o ni.o cayman_blit_shaders.o 73 radeon_trace_points.o ni.o cayman_blit_shaders.o atombios_encoders.o
74 74
75radeon-$(CONFIG_COMPAT) += radeon_ioc32.o 75radeon-$(CONFIG_COMPAT) += radeon_ioc32.o
76radeon-$(CONFIG_VGA_SWITCHEROO) += radeon_atpx_handler.o 76radeon-$(CONFIG_VGA_SWITCHEROO) += radeon_atpx_handler.o
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index a515b2a09d8..2b97262e3ab 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -558,7 +558,7 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
558 bpc = connector->display_info.bpc; 558 bpc = connector->display_info.bpc;
559 encoder_mode = atombios_get_encoder_mode(encoder); 559 encoder_mode = atombios_get_encoder_mode(encoder);
560 if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || 560 if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) ||
561 radeon_encoder_is_dp_bridge(encoder)) { 561 (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) {
562 if (connector) { 562 if (connector) {
563 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 563 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
564 struct radeon_connector_atom_dig *dig_connector = 564 struct radeon_connector_atom_dig *dig_connector =
@@ -638,44 +638,29 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
638 if (ss_enabled && ss->percentage) 638 if (ss_enabled && ss->percentage)
639 args.v3.sInput.ucDispPllConfig |= 639 args.v3.sInput.ucDispPllConfig |=
640 DISPPLL_CONFIG_SS_ENABLE; 640 DISPPLL_CONFIG_SS_ENABLE;
641 if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT) || 641 if (ENCODER_MODE_IS_DP(encoder_mode)) {
642 radeon_encoder_is_dp_bridge(encoder)) { 642 args.v3.sInput.ucDispPllConfig |=
643 DISPPLL_CONFIG_COHERENT_MODE;
644 /* 16200 or 27000 */
645 args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10);
646 } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
643 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 647 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
644 if (encoder_mode == ATOM_ENCODER_MODE_DP) { 648 if (encoder_mode == ATOM_ENCODER_MODE_HDMI)
649 /* deep color support */
650 args.v3.sInput.usPixelClock =
651 cpu_to_le16((mode->clock * bpc / 8) / 10);
652 if (dig->coherent_mode)
645 args.v3.sInput.ucDispPllConfig |= 653 args.v3.sInput.ucDispPllConfig |=
646 DISPPLL_CONFIG_COHERENT_MODE; 654 DISPPLL_CONFIG_COHERENT_MODE;
647 /* 16200 or 27000 */ 655 if (mode->clock > 165000)
648 args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10);
649 } else {
650 if (encoder_mode == ATOM_ENCODER_MODE_HDMI) {
651 /* deep color support */
652 args.v3.sInput.usPixelClock =
653 cpu_to_le16((mode->clock * bpc / 8) / 10);
654 }
655 if (dig->coherent_mode)
656 args.v3.sInput.ucDispPllConfig |=
657 DISPPLL_CONFIG_COHERENT_MODE;
658 if (mode->clock > 165000)
659 args.v3.sInput.ucDispPllConfig |=
660 DISPPLL_CONFIG_DUAL_LINK;
661 }
662 } else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
663 if (encoder_mode == ATOM_ENCODER_MODE_DP) {
664 args.v3.sInput.ucDispPllConfig |= 656 args.v3.sInput.ucDispPllConfig |=
665 DISPPLL_CONFIG_COHERENT_MODE; 657 DISPPLL_CONFIG_DUAL_LINK;
666 /* 16200 or 27000 */
667 args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10);
668 } else if (encoder_mode != ATOM_ENCODER_MODE_LVDS) {
669 if (mode->clock > 165000)
670 args.v3.sInput.ucDispPllConfig |=
671 DISPPLL_CONFIG_DUAL_LINK;
672 }
673 } 658 }
674 if (radeon_encoder_is_dp_bridge(encoder)) { 659 if (radeon_encoder_get_dp_bridge_encoder_id(encoder) !=
675 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder); 660 ENCODER_OBJECT_ID_NONE)
676 struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder); 661 args.v3.sInput.ucExtTransmitterID =
677 args.v3.sInput.ucExtTransmitterID = ext_radeon_encoder->encoder_id; 662 radeon_encoder_get_dp_bridge_encoder_id(encoder);
678 } else 663 else
679 args.v3.sInput.ucExtTransmitterID = 0; 664 args.v3.sInput.ucExtTransmitterID = 0;
680 665
681 atom_execute_table(rdev->mode_info.atom_context, 666 atom_execute_table(rdev->mode_info.atom_context,
@@ -945,6 +930,7 @@ static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode
945 bpc = connector->display_info.bpc; 930 bpc = connector->display_info.bpc;
946 931
947 switch (encoder_mode) { 932 switch (encoder_mode) {
933 case ATOM_ENCODER_MODE_DP_MST:
948 case ATOM_ENCODER_MODE_DP: 934 case ATOM_ENCODER_MODE_DP:
949 /* DP/eDP */ 935 /* DP/eDP */
950 dp_clock = dig_connector->dp_clock / 10; 936 dp_clock = dig_connector->dp_clock / 10;
@@ -1121,9 +1107,40 @@ static int dce4_crtc_do_set_base(struct drm_crtc *crtc,
1121 return -EINVAL; 1107 return -EINVAL;
1122 } 1108 }
1123 1109
1124 if (tiling_flags & RADEON_TILING_MACRO) 1110 if (tiling_flags & RADEON_TILING_MACRO) {
1111 if (rdev->family >= CHIP_CAYMAN)
1112 tmp = rdev->config.cayman.tile_config;
1113 else
1114 tmp = rdev->config.evergreen.tile_config;
1115
1116 switch ((tmp & 0xf0) >> 4) {
1117 case 0: /* 4 banks */
1118 fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_4_BANK);
1119 break;
1120 case 1: /* 8 banks */
1121 default:
1122 fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_8_BANK);
1123 break;
1124 case 2: /* 16 banks */
1125 fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_16_BANK);
1126 break;
1127 }
1128
1129 switch ((tmp & 0xf000) >> 12) {
1130 case 0: /* 1KB rows */
1131 default:
1132 fb_format |= EVERGREEN_GRPH_TILE_SPLIT(EVERGREEN_ADDR_SURF_TILE_SPLIT_1KB);
1133 break;
1134 case 1: /* 2KB rows */
1135 fb_format |= EVERGREEN_GRPH_TILE_SPLIT(EVERGREEN_ADDR_SURF_TILE_SPLIT_2KB);
1136 break;
1137 case 2: /* 4KB rows */
1138 fb_format |= EVERGREEN_GRPH_TILE_SPLIT(EVERGREEN_ADDR_SURF_TILE_SPLIT_4KB);
1139 break;
1140 }
1141
1125 fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_2D_TILED_THIN1); 1142 fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_2D_TILED_THIN1);
1126 else if (tiling_flags & RADEON_TILING_MICRO) 1143 } else if (tiling_flags & RADEON_TILING_MICRO)
1127 fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_1D_TILED_THIN1); 1144 fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_1D_TILED_THIN1);
1128 1145
1129 switch (radeon_crtc->crtc_id) { 1146 switch (radeon_crtc->crtc_id) {
@@ -1450,7 +1467,7 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1450 * PPLL/DCPLL programming and only program the DP DTO for the 1467 * PPLL/DCPLL programming and only program the DP DTO for the
1451 * crtc virtual pixel clock. 1468 * crtc virtual pixel clock.
1452 */ 1469 */
1453 if (atombios_get_encoder_mode(test_encoder) == ATOM_ENCODER_MODE_DP) { 1470 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_encoder))) {
1454 if (ASIC_IS_DCE5(rdev) || rdev->clock.dp_extclk) 1471 if (ASIC_IS_DCE5(rdev) || rdev->clock.dp_extclk)
1455 return ATOM_PPLL_INVALID; 1472 return ATOM_PPLL_INVALID;
1456 } 1473 }
@@ -1536,12 +1553,6 @@ static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc,
1536 struct drm_display_mode *mode, 1553 struct drm_display_mode *mode,
1537 struct drm_display_mode *adjusted_mode) 1554 struct drm_display_mode *adjusted_mode)
1538{ 1555{
1539 struct drm_device *dev = crtc->dev;
1540 struct radeon_device *rdev = dev->dev_private;
1541
1542 /* adjust pm to upcoming mode change */
1543 radeon_pm_compute_clocks(rdev);
1544
1545 if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) 1556 if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
1546 return false; 1557 return false;
1547 return true; 1558 return true;
diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c
index 79e8ebc0530..6fb335a4fdd 100644
--- a/drivers/gpu/drm/radeon/atombios_dp.c
+++ b/drivers/gpu/drm/radeon/atombios_dp.c
@@ -283,7 +283,7 @@ int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
283 } 283 }
284 } 284 }
285 285
286 DRM_ERROR("aux i2c too many retries, giving up\n"); 286 DRM_DEBUG_KMS("aux i2c too many retries, giving up\n");
287 return -EREMOTEIO; 287 return -EREMOTEIO;
288} 288}
289 289
@@ -482,7 +482,8 @@ static int radeon_dp_get_dp_link_clock(struct drm_connector *connector,
482 int bpp = convert_bpc_to_bpp(connector->display_info.bpc); 482 int bpp = convert_bpc_to_bpp(connector->display_info.bpc);
483 int lane_num, max_pix_clock; 483 int lane_num, max_pix_clock;
484 484
485 if (radeon_connector_encoder_is_dp_bridge(connector)) 485 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) ==
486 ENCODER_OBJECT_ID_NUTMEG)
486 return 270000; 487 return 270000;
487 488
488 lane_num = radeon_dp_get_dp_lane_number(connector, dpcd, pix_clock); 489 lane_num = radeon_dp_get_dp_lane_number(connector, dpcd, pix_clock);
@@ -553,17 +554,32 @@ static void radeon_dp_set_panel_mode(struct drm_encoder *encoder,
553{ 554{
554 struct drm_device *dev = encoder->dev; 555 struct drm_device *dev = encoder->dev;
555 struct radeon_device *rdev = dev->dev_private; 556 struct radeon_device *rdev = dev->dev_private;
557 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
556 int panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE; 558 int panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE;
557 559
558 if (!ASIC_IS_DCE4(rdev)) 560 if (!ASIC_IS_DCE4(rdev))
559 return; 561 return;
560 562
561 if (radeon_connector_encoder_is_dp_bridge(connector)) 563 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) ==
564 ENCODER_OBJECT_ID_NUTMEG)
562 panel_mode = DP_PANEL_MODE_INTERNAL_DP1_MODE; 565 panel_mode = DP_PANEL_MODE_INTERNAL_DP1_MODE;
566 else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) ==
567 ENCODER_OBJECT_ID_TRAVIS)
568 panel_mode = DP_PANEL_MODE_INTERNAL_DP2_MODE;
569 else if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
570 u8 tmp = radeon_read_dpcd_reg(radeon_connector, DP_EDP_CONFIGURATION_CAP);
571 if (tmp & 1)
572 panel_mode = DP_PANEL_MODE_INTERNAL_DP2_MODE;
573 }
563 574
564 atombios_dig_encoder_setup(encoder, 575 atombios_dig_encoder_setup(encoder,
565 ATOM_ENCODER_CMD_SETUP_PANEL_MODE, 576 ATOM_ENCODER_CMD_SETUP_PANEL_MODE,
566 panel_mode); 577 panel_mode);
578
579 if ((connector->connector_type == DRM_MODE_CONNECTOR_eDP) &&
580 (panel_mode == DP_PANEL_MODE_INTERNAL_DP2_MODE)) {
581 radeon_write_dpcd_reg(radeon_connector, DP_EDP_CONFIGURATION_SET, 1);
582 }
567} 583}
568 584
569void radeon_dp_set_link_config(struct drm_connector *connector, 585void radeon_dp_set_link_config(struct drm_connector *connector,
diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
new file mode 100644
index 00000000000..39c04c1b847
--- /dev/null
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -0,0 +1,2369 @@
1/*
2 * Copyright 2007-11 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "drm_crtc_helper.h"
28#include "radeon_drm.h"
29#include "radeon.h"
30#include "atom.h"
31
32extern int atom_debug;
33
34/* evil but including atombios.h is much worse */
35bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
36 struct drm_display_mode *mode);
37
38
39static inline bool radeon_encoder_is_digital(struct drm_encoder *encoder)
40{
41 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
42 switch (radeon_encoder->encoder_id) {
43 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
44 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
45 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
46 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
47 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
48 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
49 case ENCODER_OBJECT_ID_INTERNAL_DDI:
50 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
51 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
52 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
53 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
54 return true;
55 default:
56 return false;
57 }
58}
59
60static struct drm_connector *
61radeon_get_connector_for_encoder_init(struct drm_encoder *encoder)
62{
63 struct drm_device *dev = encoder->dev;
64 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
65 struct drm_connector *connector;
66 struct radeon_connector *radeon_connector;
67
68 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
69 radeon_connector = to_radeon_connector(connector);
70 if (radeon_encoder->devices & radeon_connector->devices)
71 return connector;
72 }
73 return NULL;
74}
75
76static bool radeon_atom_mode_fixup(struct drm_encoder *encoder,
77 struct drm_display_mode *mode,
78 struct drm_display_mode *adjusted_mode)
79{
80 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
81 struct drm_device *dev = encoder->dev;
82 struct radeon_device *rdev = dev->dev_private;
83
84 /* set the active encoder to connector routing */
85 radeon_encoder_set_active_device(encoder);
86 drm_mode_set_crtcinfo(adjusted_mode, 0);
87
88 /* hw bug */
89 if ((mode->flags & DRM_MODE_FLAG_INTERLACE)
90 && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2)))
91 adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2;
92
93 /* get the native mode for LVDS */
94 if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT))
95 radeon_panel_mode_fixup(encoder, adjusted_mode);
96
97 /* get the native mode for TV */
98 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) {
99 struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
100 if (tv_dac) {
101 if (tv_dac->tv_std == TV_STD_NTSC ||
102 tv_dac->tv_std == TV_STD_NTSC_J ||
103 tv_dac->tv_std == TV_STD_PAL_M)
104 radeon_atom_get_tv_timings(rdev, 0, adjusted_mode);
105 else
106 radeon_atom_get_tv_timings(rdev, 1, adjusted_mode);
107 }
108 }
109
110 if (ASIC_IS_DCE3(rdev) &&
111 ((radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
112 (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE))) {
113 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
114 radeon_dp_set_link_config(connector, mode);
115 }
116
117 return true;
118}
119
120static void
121atombios_dac_setup(struct drm_encoder *encoder, int action)
122{
123 struct drm_device *dev = encoder->dev;
124 struct radeon_device *rdev = dev->dev_private;
125 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
126 DAC_ENCODER_CONTROL_PS_ALLOCATION args;
127 int index = 0;
128 struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
129
130 memset(&args, 0, sizeof(args));
131
132 switch (radeon_encoder->encoder_id) {
133 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
134 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
135 index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl);
136 break;
137 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
138 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
139 index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl);
140 break;
141 }
142
143 args.ucAction = action;
144
145 if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT))
146 args.ucDacStandard = ATOM_DAC1_PS2;
147 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
148 args.ucDacStandard = ATOM_DAC1_CV;
149 else {
150 switch (dac_info->tv_std) {
151 case TV_STD_PAL:
152 case TV_STD_PAL_M:
153 case TV_STD_SCART_PAL:
154 case TV_STD_SECAM:
155 case TV_STD_PAL_CN:
156 args.ucDacStandard = ATOM_DAC1_PAL;
157 break;
158 case TV_STD_NTSC:
159 case TV_STD_NTSC_J:
160 case TV_STD_PAL_60:
161 default:
162 args.ucDacStandard = ATOM_DAC1_NTSC;
163 break;
164 }
165 }
166 args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
167
168 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
169
170}
171
172static void
173atombios_tv_setup(struct drm_encoder *encoder, int action)
174{
175 struct drm_device *dev = encoder->dev;
176 struct radeon_device *rdev = dev->dev_private;
177 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
178 TV_ENCODER_CONTROL_PS_ALLOCATION args;
179 int index = 0;
180 struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
181
182 memset(&args, 0, sizeof(args));
183
184 index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl);
185
186 args.sTVEncoder.ucAction = action;
187
188 if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
189 args.sTVEncoder.ucTvStandard = ATOM_TV_CV;
190 else {
191 switch (dac_info->tv_std) {
192 case TV_STD_NTSC:
193 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
194 break;
195 case TV_STD_PAL:
196 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL;
197 break;
198 case TV_STD_PAL_M:
199 args.sTVEncoder.ucTvStandard = ATOM_TV_PALM;
200 break;
201 case TV_STD_PAL_60:
202 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60;
203 break;
204 case TV_STD_NTSC_J:
205 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ;
206 break;
207 case TV_STD_SCART_PAL:
208 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */
209 break;
210 case TV_STD_SECAM:
211 args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM;
212 break;
213 case TV_STD_PAL_CN:
214 args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN;
215 break;
216 default:
217 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
218 break;
219 }
220 }
221
222 args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
223
224 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
225
226}
227
228union dvo_encoder_control {
229 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds;
230 DVO_ENCODER_CONTROL_PS_ALLOCATION dvo;
231 DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3;
232};
233
234void
235atombios_dvo_setup(struct drm_encoder *encoder, int action)
236{
237 struct drm_device *dev = encoder->dev;
238 struct radeon_device *rdev = dev->dev_private;
239 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
240 union dvo_encoder_control args;
241 int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
242 uint8_t frev, crev;
243
244 memset(&args, 0, sizeof(args));
245
246 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
247 return;
248
249 switch (frev) {
250 case 1:
251 switch (crev) {
252 case 1:
253 /* R4xx, R5xx */
254 args.ext_tmds.sXTmdsEncoder.ucEnable = action;
255
256 if (radeon_encoder->pixel_clock > 165000)
257 args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL;
258
259 args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB;
260 break;
261 case 2:
262 /* RS600/690/740 */
263 args.dvo.sDVOEncoder.ucAction = action;
264 args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
265 /* DFP1, CRT1, TV1 depending on the type of port */
266 args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX;
267
268 if (radeon_encoder->pixel_clock > 165000)
269 args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL;
270 break;
271 case 3:
272 /* R6xx */
273 args.dvo_v3.ucAction = action;
274 args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
275 args.dvo_v3.ucDVOConfig = 0; /* XXX */
276 break;
277 default:
278 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
279 break;
280 }
281 break;
282 default:
283 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
284 break;
285 }
286
287 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
288}
289
290union lvds_encoder_control {
291 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1;
292 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2;
293};
294
295void
296atombios_digital_setup(struct drm_encoder *encoder, int action)
297{
298 struct drm_device *dev = encoder->dev;
299 struct radeon_device *rdev = dev->dev_private;
300 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
301 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
302 union lvds_encoder_control args;
303 int index = 0;
304 int hdmi_detected = 0;
305 uint8_t frev, crev;
306
307 if (!dig)
308 return;
309
310 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
311 hdmi_detected = 1;
312
313 memset(&args, 0, sizeof(args));
314
315 switch (radeon_encoder->encoder_id) {
316 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
317 index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
318 break;
319 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
320 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
321 index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl);
322 break;
323 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
324 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
325 index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
326 else
327 index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl);
328 break;
329 }
330
331 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
332 return;
333
334 switch (frev) {
335 case 1:
336 case 2:
337 switch (crev) {
338 case 1:
339 args.v1.ucMisc = 0;
340 args.v1.ucAction = action;
341 if (hdmi_detected)
342 args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
343 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
344 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
345 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
346 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
347 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
348 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
349 } else {
350 if (dig->linkb)
351 args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
352 if (radeon_encoder->pixel_clock > 165000)
353 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
354 /*if (pScrn->rgbBits == 8) */
355 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
356 }
357 break;
358 case 2:
359 case 3:
360 args.v2.ucMisc = 0;
361 args.v2.ucAction = action;
362 if (crev == 3) {
363 if (dig->coherent_mode)
364 args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT;
365 }
366 if (hdmi_detected)
367 args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
368 args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
369 args.v2.ucTruncate = 0;
370 args.v2.ucSpatial = 0;
371 args.v2.ucTemporal = 0;
372 args.v2.ucFRC = 0;
373 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
374 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
375 args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
376 if (dig->lcd_misc & ATOM_PANEL_MISC_SPATIAL) {
377 args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN;
378 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
379 args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH;
380 }
381 if (dig->lcd_misc & ATOM_PANEL_MISC_TEMPORAL) {
382 args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN;
383 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
384 args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH;
385 if (((dig->lcd_misc >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT) & 0x3) == 2)
386 args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4;
387 }
388 } else {
389 if (dig->linkb)
390 args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
391 if (radeon_encoder->pixel_clock > 165000)
392 args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
393 }
394 break;
395 default:
396 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
397 break;
398 }
399 break;
400 default:
401 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
402 break;
403 }
404
405 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
406}
407
408int
409atombios_get_encoder_mode(struct drm_encoder *encoder)
410{
411 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
412 struct drm_device *dev = encoder->dev;
413 struct radeon_device *rdev = dev->dev_private;
414 struct drm_connector *connector;
415 struct radeon_connector *radeon_connector;
416 struct radeon_connector_atom_dig *dig_connector;
417
418 /* dp bridges are always DP */
419 if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)
420 return ATOM_ENCODER_MODE_DP;
421
422 /* DVO is always DVO */
423 if (radeon_encoder->encoder_id == ATOM_ENCODER_MODE_DVO)
424 return ATOM_ENCODER_MODE_DVO;
425
426 connector = radeon_get_connector_for_encoder(encoder);
427 /* if we don't have an active device yet, just use one of
428 * the connectors tied to the encoder.
429 */
430 if (!connector)
431 connector = radeon_get_connector_for_encoder_init(encoder);
432 radeon_connector = to_radeon_connector(connector);
433
434 switch (connector->connector_type) {
435 case DRM_MODE_CONNECTOR_DVII:
436 case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
437 if (drm_detect_monitor_audio(radeon_connector->edid) && radeon_audio) {
438 /* fix me */
439 if (ASIC_IS_DCE4(rdev))
440 return ATOM_ENCODER_MODE_DVI;
441 else
442 return ATOM_ENCODER_MODE_HDMI;
443 } else if (radeon_connector->use_digital)
444 return ATOM_ENCODER_MODE_DVI;
445 else
446 return ATOM_ENCODER_MODE_CRT;
447 break;
448 case DRM_MODE_CONNECTOR_DVID:
449 case DRM_MODE_CONNECTOR_HDMIA:
450 default:
451 if (drm_detect_monitor_audio(radeon_connector->edid) && radeon_audio) {
452 /* fix me */
453 if (ASIC_IS_DCE4(rdev))
454 return ATOM_ENCODER_MODE_DVI;
455 else
456 return ATOM_ENCODER_MODE_HDMI;
457 } else
458 return ATOM_ENCODER_MODE_DVI;
459 break;
460 case DRM_MODE_CONNECTOR_LVDS:
461 return ATOM_ENCODER_MODE_LVDS;
462 break;
463 case DRM_MODE_CONNECTOR_DisplayPort:
464 dig_connector = radeon_connector->con_priv;
465 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
466 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
467 return ATOM_ENCODER_MODE_DP;
468 else if (drm_detect_monitor_audio(radeon_connector->edid) && radeon_audio) {
469 /* fix me */
470 if (ASIC_IS_DCE4(rdev))
471 return ATOM_ENCODER_MODE_DVI;
472 else
473 return ATOM_ENCODER_MODE_HDMI;
474 } else
475 return ATOM_ENCODER_MODE_DVI;
476 break;
477 case DRM_MODE_CONNECTOR_eDP:
478 return ATOM_ENCODER_MODE_DP;
479 case DRM_MODE_CONNECTOR_DVIA:
480 case DRM_MODE_CONNECTOR_VGA:
481 return ATOM_ENCODER_MODE_CRT;
482 break;
483 case DRM_MODE_CONNECTOR_Composite:
484 case DRM_MODE_CONNECTOR_SVIDEO:
485 case DRM_MODE_CONNECTOR_9PinDIN:
486 /* fix me */
487 return ATOM_ENCODER_MODE_TV;
488 /*return ATOM_ENCODER_MODE_CV;*/
489 break;
490 }
491}
492
493/*
494 * DIG Encoder/Transmitter Setup
495 *
496 * DCE 3.0/3.1
497 * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
498 * Supports up to 3 digital outputs
499 * - 2 DIG encoder blocks.
500 * DIG1 can drive UNIPHY link A or link B
501 * DIG2 can drive UNIPHY link B or LVTMA
502 *
503 * DCE 3.2
504 * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
505 * Supports up to 5 digital outputs
506 * - 2 DIG encoder blocks.
507 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
508 *
509 * DCE 4.0/5.0
510 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
511 * Supports up to 6 digital outputs
512 * - 6 DIG encoder blocks.
513 * - DIG to PHY mapping is hardcoded
514 * DIG1 drives UNIPHY0 link A, A+B
515 * DIG2 drives UNIPHY0 link B
516 * DIG3 drives UNIPHY1 link A, A+B
517 * DIG4 drives UNIPHY1 link B
518 * DIG5 drives UNIPHY2 link A, A+B
519 * DIG6 drives UNIPHY2 link B
520 *
521 * DCE 4.1
522 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
523 * Supports up to 6 digital outputs
524 * - 2 DIG encoder blocks.
525 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
526 *
527 * Routing
528 * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
529 * Examples:
530 * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
531 * crtc1 -> dig1 -> UNIPHY0 link B -> DP
532 * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
533 * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
534 */
535
536union dig_encoder_control {
537 DIG_ENCODER_CONTROL_PS_ALLOCATION v1;
538 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2;
539 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3;
540 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4;
541};
542
543void
544atombios_dig_encoder_setup(struct drm_encoder *encoder, int action, int panel_mode)
545{
546 struct drm_device *dev = encoder->dev;
547 struct radeon_device *rdev = dev->dev_private;
548 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
549 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
550 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
551 union dig_encoder_control args;
552 int index = 0;
553 uint8_t frev, crev;
554 int dp_clock = 0;
555 int dp_lane_count = 0;
556 int hpd_id = RADEON_HPD_NONE;
557 int bpc = 8;
558
559 if (connector) {
560 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
561 struct radeon_connector_atom_dig *dig_connector =
562 radeon_connector->con_priv;
563
564 dp_clock = dig_connector->dp_clock;
565 dp_lane_count = dig_connector->dp_lane_count;
566 hpd_id = radeon_connector->hpd.hpd;
567 bpc = connector->display_info.bpc;
568 }
569
570 /* no dig encoder assigned */
571 if (dig->dig_encoder == -1)
572 return;
573
574 memset(&args, 0, sizeof(args));
575
576 if (ASIC_IS_DCE4(rdev))
577 index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl);
578 else {
579 if (dig->dig_encoder)
580 index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
581 else
582 index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
583 }
584
585 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
586 return;
587
588 switch (frev) {
589 case 1:
590 switch (crev) {
591 case 1:
592 args.v1.ucAction = action;
593 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
594 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
595 args.v3.ucPanelMode = panel_mode;
596 else
597 args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder);
598
599 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
600 args.v1.ucLaneNum = dp_lane_count;
601 else if (radeon_encoder->pixel_clock > 165000)
602 args.v1.ucLaneNum = 8;
603 else
604 args.v1.ucLaneNum = 4;
605
606 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000))
607 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
608 switch (radeon_encoder->encoder_id) {
609 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
610 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1;
611 break;
612 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
613 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
614 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2;
615 break;
616 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
617 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3;
618 break;
619 }
620 if (dig->linkb)
621 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
622 else
623 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
624 break;
625 case 2:
626 case 3:
627 args.v3.ucAction = action;
628 args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
629 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
630 args.v3.ucPanelMode = panel_mode;
631 else
632 args.v3.ucEncoderMode = atombios_get_encoder_mode(encoder);
633
634 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
635 args.v3.ucLaneNum = dp_lane_count;
636 else if (radeon_encoder->pixel_clock > 165000)
637 args.v3.ucLaneNum = 8;
638 else
639 args.v3.ucLaneNum = 4;
640
641 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000))
642 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
643 args.v3.acConfig.ucDigSel = dig->dig_encoder;
644 switch (bpc) {
645 case 0:
646 args.v3.ucBitPerColor = PANEL_BPC_UNDEFINE;
647 break;
648 case 6:
649 args.v3.ucBitPerColor = PANEL_6BIT_PER_COLOR;
650 break;
651 case 8:
652 default:
653 args.v3.ucBitPerColor = PANEL_8BIT_PER_COLOR;
654 break;
655 case 10:
656 args.v3.ucBitPerColor = PANEL_10BIT_PER_COLOR;
657 break;
658 case 12:
659 args.v3.ucBitPerColor = PANEL_12BIT_PER_COLOR;
660 break;
661 case 16:
662 args.v3.ucBitPerColor = PANEL_16BIT_PER_COLOR;
663 break;
664 }
665 break;
666 case 4:
667 args.v4.ucAction = action;
668 args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
669 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
670 args.v4.ucPanelMode = panel_mode;
671 else
672 args.v4.ucEncoderMode = atombios_get_encoder_mode(encoder);
673
674 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
675 args.v4.ucLaneNum = dp_lane_count;
676 else if (radeon_encoder->pixel_clock > 165000)
677 args.v4.ucLaneNum = 8;
678 else
679 args.v4.ucLaneNum = 4;
680
681 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode)) {
682 if (dp_clock == 270000)
683 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ;
684 else if (dp_clock == 540000)
685 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ;
686 }
687 args.v4.acConfig.ucDigSel = dig->dig_encoder;
688 switch (bpc) {
689 case 0:
690 args.v4.ucBitPerColor = PANEL_BPC_UNDEFINE;
691 break;
692 case 6:
693 args.v4.ucBitPerColor = PANEL_6BIT_PER_COLOR;
694 break;
695 case 8:
696 default:
697 args.v4.ucBitPerColor = PANEL_8BIT_PER_COLOR;
698 break;
699 case 10:
700 args.v4.ucBitPerColor = PANEL_10BIT_PER_COLOR;
701 break;
702 case 12:
703 args.v4.ucBitPerColor = PANEL_12BIT_PER_COLOR;
704 break;
705 case 16:
706 args.v4.ucBitPerColor = PANEL_16BIT_PER_COLOR;
707 break;
708 }
709 if (hpd_id == RADEON_HPD_NONE)
710 args.v4.ucHPD_ID = 0;
711 else
712 args.v4.ucHPD_ID = hpd_id + 1;
713 break;
714 default:
715 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
716 break;
717 }
718 break;
719 default:
720 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
721 break;
722 }
723
724 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
725
726}
727
728union dig_transmitter_control {
729 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1;
730 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
731 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3;
732 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4;
733};
734
735void
736atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set)
737{
738 struct drm_device *dev = encoder->dev;
739 struct radeon_device *rdev = dev->dev_private;
740 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
741 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
742 struct drm_connector *connector;
743 union dig_transmitter_control args;
744 int index = 0;
745 uint8_t frev, crev;
746 bool is_dp = false;
747 int pll_id = 0;
748 int dp_clock = 0;
749 int dp_lane_count = 0;
750 int connector_object_id = 0;
751 int igp_lane_info = 0;
752 int dig_encoder = dig->dig_encoder;
753
754 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
755 connector = radeon_get_connector_for_encoder_init(encoder);
756 /* just needed to avoid bailing in the encoder check. the encoder
757 * isn't used for init
758 */
759 dig_encoder = 0;
760 } else
761 connector = radeon_get_connector_for_encoder(encoder);
762
763 if (connector) {
764 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
765 struct radeon_connector_atom_dig *dig_connector =
766 radeon_connector->con_priv;
767
768 dp_clock = dig_connector->dp_clock;
769 dp_lane_count = dig_connector->dp_lane_count;
770 connector_object_id =
771 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
772 igp_lane_info = dig_connector->igp_lane_info;
773 }
774
775 if (encoder->crtc) {
776 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
777 pll_id = radeon_crtc->pll_id;
778 }
779
780 /* no dig encoder assigned */
781 if (dig_encoder == -1)
782 return;
783
784 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)))
785 is_dp = true;
786
787 memset(&args, 0, sizeof(args));
788
789 switch (radeon_encoder->encoder_id) {
790 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
791 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
792 break;
793 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
794 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
795 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
796 index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
797 break;
798 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
799 index = GetIndexIntoMasterTable(COMMAND, LVTMATransmitterControl);
800 break;
801 }
802
803 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
804 return;
805
806 switch (frev) {
807 case 1:
808 switch (crev) {
809 case 1:
810 args.v1.ucAction = action;
811 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
812 args.v1.usInitInfo = cpu_to_le16(connector_object_id);
813 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
814 args.v1.asMode.ucLaneSel = lane_num;
815 args.v1.asMode.ucLaneSet = lane_set;
816 } else {
817 if (is_dp)
818 args.v1.usPixelClock =
819 cpu_to_le16(dp_clock / 10);
820 else if (radeon_encoder->pixel_clock > 165000)
821 args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
822 else
823 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
824 }
825
826 args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL;
827
828 if (dig_encoder)
829 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
830 else
831 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
832
833 if ((rdev->flags & RADEON_IS_IGP) &&
834 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) {
835 if (is_dp || (radeon_encoder->pixel_clock <= 165000)) {
836 if (igp_lane_info & 0x1)
837 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3;
838 else if (igp_lane_info & 0x2)
839 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7;
840 else if (igp_lane_info & 0x4)
841 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11;
842 else if (igp_lane_info & 0x8)
843 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15;
844 } else {
845 if (igp_lane_info & 0x3)
846 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7;
847 else if (igp_lane_info & 0xc)
848 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15;
849 }
850 }
851
852 if (dig->linkb)
853 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB;
854 else
855 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
856
857 if (is_dp)
858 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
859 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
860 if (dig->coherent_mode)
861 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
862 if (radeon_encoder->pixel_clock > 165000)
863 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK;
864 }
865 break;
866 case 2:
867 args.v2.ucAction = action;
868 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
869 args.v2.usInitInfo = cpu_to_le16(connector_object_id);
870 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
871 args.v2.asMode.ucLaneSel = lane_num;
872 args.v2.asMode.ucLaneSet = lane_set;
873 } else {
874 if (is_dp)
875 args.v2.usPixelClock =
876 cpu_to_le16(dp_clock / 10);
877 else if (radeon_encoder->pixel_clock > 165000)
878 args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
879 else
880 args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
881 }
882
883 args.v2.acConfig.ucEncoderSel = dig_encoder;
884 if (dig->linkb)
885 args.v2.acConfig.ucLinkSel = 1;
886
887 switch (radeon_encoder->encoder_id) {
888 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
889 args.v2.acConfig.ucTransmitterSel = 0;
890 break;
891 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
892 args.v2.acConfig.ucTransmitterSel = 1;
893 break;
894 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
895 args.v2.acConfig.ucTransmitterSel = 2;
896 break;
897 }
898
899 if (is_dp) {
900 args.v2.acConfig.fCoherentMode = 1;
901 args.v2.acConfig.fDPConnector = 1;
902 } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
903 if (dig->coherent_mode)
904 args.v2.acConfig.fCoherentMode = 1;
905 if (radeon_encoder->pixel_clock > 165000)
906 args.v2.acConfig.fDualLinkConnector = 1;
907 }
908 break;
909 case 3:
910 args.v3.ucAction = action;
911 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
912 args.v3.usInitInfo = cpu_to_le16(connector_object_id);
913 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
914 args.v3.asMode.ucLaneSel = lane_num;
915 args.v3.asMode.ucLaneSet = lane_set;
916 } else {
917 if (is_dp)
918 args.v3.usPixelClock =
919 cpu_to_le16(dp_clock / 10);
920 else if (radeon_encoder->pixel_clock > 165000)
921 args.v3.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
922 else
923 args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
924 }
925
926 if (is_dp)
927 args.v3.ucLaneNum = dp_lane_count;
928 else if (radeon_encoder->pixel_clock > 165000)
929 args.v3.ucLaneNum = 8;
930 else
931 args.v3.ucLaneNum = 4;
932
933 if (dig->linkb)
934 args.v3.acConfig.ucLinkSel = 1;
935 if (dig_encoder & 1)
936 args.v3.acConfig.ucEncoderSel = 1;
937
938 /* Select the PLL for the PHY
939 * DP PHY should be clocked from external src if there is
940 * one.
941 */
942 /* On DCE4, if there is an external clock, it generates the DP ref clock */
943 if (is_dp && rdev->clock.dp_extclk)
944 args.v3.acConfig.ucRefClkSource = 2; /* external src */
945 else
946 args.v3.acConfig.ucRefClkSource = pll_id;
947
948 switch (radeon_encoder->encoder_id) {
949 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
950 args.v3.acConfig.ucTransmitterSel = 0;
951 break;
952 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
953 args.v3.acConfig.ucTransmitterSel = 1;
954 break;
955 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
956 args.v3.acConfig.ucTransmitterSel = 2;
957 break;
958 }
959
960 if (is_dp)
961 args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */
962 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
963 if (dig->coherent_mode)
964 args.v3.acConfig.fCoherentMode = 1;
965 if (radeon_encoder->pixel_clock > 165000)
966 args.v3.acConfig.fDualLinkConnector = 1;
967 }
968 break;
969 case 4:
970 args.v4.ucAction = action;
971 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
972 args.v4.usInitInfo = cpu_to_le16(connector_object_id);
973 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
974 args.v4.asMode.ucLaneSel = lane_num;
975 args.v4.asMode.ucLaneSet = lane_set;
976 } else {
977 if (is_dp)
978 args.v4.usPixelClock =
979 cpu_to_le16(dp_clock / 10);
980 else if (radeon_encoder->pixel_clock > 165000)
981 args.v4.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
982 else
983 args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
984 }
985
986 if (is_dp)
987 args.v4.ucLaneNum = dp_lane_count;
988 else if (radeon_encoder->pixel_clock > 165000)
989 args.v4.ucLaneNum = 8;
990 else
991 args.v4.ucLaneNum = 4;
992
993 if (dig->linkb)
994 args.v4.acConfig.ucLinkSel = 1;
995 if (dig_encoder & 1)
996 args.v4.acConfig.ucEncoderSel = 1;
997
998 /* Select the PLL for the PHY
999 * DP PHY should be clocked from external src if there is
1000 * one.
1001 */
1002 /* On DCE5 DCPLL usually generates the DP ref clock */
1003 if (is_dp) {
1004 if (rdev->clock.dp_extclk)
1005 args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_EXTCLK;
1006 else
1007 args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_DCPLL;
1008 } else
1009 args.v4.acConfig.ucRefClkSource = pll_id;
1010
1011 switch (radeon_encoder->encoder_id) {
1012 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1013 args.v4.acConfig.ucTransmitterSel = 0;
1014 break;
1015 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1016 args.v4.acConfig.ucTransmitterSel = 1;
1017 break;
1018 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1019 args.v4.acConfig.ucTransmitterSel = 2;
1020 break;
1021 }
1022
1023 if (is_dp)
1024 args.v4.acConfig.fCoherentMode = 1; /* DP requires coherent */
1025 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1026 if (dig->coherent_mode)
1027 args.v4.acConfig.fCoherentMode = 1;
1028 if (radeon_encoder->pixel_clock > 165000)
1029 args.v4.acConfig.fDualLinkConnector = 1;
1030 }
1031 break;
1032 default:
1033 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1034 break;
1035 }
1036 break;
1037 default:
1038 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1039 break;
1040 }
1041
1042 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1043}
1044
1045bool
1046atombios_set_edp_panel_power(struct drm_connector *connector, int action)
1047{
1048 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1049 struct drm_device *dev = radeon_connector->base.dev;
1050 struct radeon_device *rdev = dev->dev_private;
1051 union dig_transmitter_control args;
1052 int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
1053 uint8_t frev, crev;
1054
1055 if (connector->connector_type != DRM_MODE_CONNECTOR_eDP)
1056 goto done;
1057
1058 if (!ASIC_IS_DCE4(rdev))
1059 goto done;
1060
1061 if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) &&
1062 (action != ATOM_TRANSMITTER_ACTION_POWER_OFF))
1063 goto done;
1064
1065 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1066 goto done;
1067
1068 memset(&args, 0, sizeof(args));
1069
1070 args.v1.ucAction = action;
1071
1072 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1073
1074 /* wait for the panel to power up */
1075 if (action == ATOM_TRANSMITTER_ACTION_POWER_ON) {
1076 int i;
1077
1078 for (i = 0; i < 300; i++) {
1079 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1080 return true;
1081 mdelay(1);
1082 }
1083 return false;
1084 }
1085done:
1086 return true;
1087}
1088
1089union external_encoder_control {
1090 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1;
1091 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3;
1092};
1093
1094static void
1095atombios_external_encoder_setup(struct drm_encoder *encoder,
1096 struct drm_encoder *ext_encoder,
1097 int action)
1098{
1099 struct drm_device *dev = encoder->dev;
1100 struct radeon_device *rdev = dev->dev_private;
1101 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1102 struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder);
1103 union external_encoder_control args;
1104 struct drm_connector *connector;
1105 int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl);
1106 u8 frev, crev;
1107 int dp_clock = 0;
1108 int dp_lane_count = 0;
1109 int connector_object_id = 0;
1110 u32 ext_enum = (ext_radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
1111 int bpc = 8;
1112
1113 if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
1114 connector = radeon_get_connector_for_encoder_init(encoder);
1115 else
1116 connector = radeon_get_connector_for_encoder(encoder);
1117
1118 if (connector) {
1119 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1120 struct radeon_connector_atom_dig *dig_connector =
1121 radeon_connector->con_priv;
1122
1123 dp_clock = dig_connector->dp_clock;
1124 dp_lane_count = dig_connector->dp_lane_count;
1125 connector_object_id =
1126 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
1127 bpc = connector->display_info.bpc;
1128 }
1129
1130 memset(&args, 0, sizeof(args));
1131
1132 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1133 return;
1134
1135 switch (frev) {
1136 case 1:
1137 /* no params on frev 1 */
1138 break;
1139 case 2:
1140 switch (crev) {
1141 case 1:
1142 case 2:
1143 args.v1.sDigEncoder.ucAction = action;
1144 args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1145 args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1146
1147 if (ENCODER_MODE_IS_DP(args.v1.sDigEncoder.ucEncoderMode)) {
1148 if (dp_clock == 270000)
1149 args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
1150 args.v1.sDigEncoder.ucLaneNum = dp_lane_count;
1151 } else if (radeon_encoder->pixel_clock > 165000)
1152 args.v1.sDigEncoder.ucLaneNum = 8;
1153 else
1154 args.v1.sDigEncoder.ucLaneNum = 4;
1155 break;
1156 case 3:
1157 args.v3.sExtEncoder.ucAction = action;
1158 if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
1159 args.v3.sExtEncoder.usConnectorId = cpu_to_le16(connector_object_id);
1160 else
1161 args.v3.sExtEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1162 args.v3.sExtEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1163
1164 if (ENCODER_MODE_IS_DP(args.v3.sExtEncoder.ucEncoderMode)) {
1165 if (dp_clock == 270000)
1166 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
1167 else if (dp_clock == 540000)
1168 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ;
1169 args.v3.sExtEncoder.ucLaneNum = dp_lane_count;
1170 } else if (radeon_encoder->pixel_clock > 165000)
1171 args.v3.sExtEncoder.ucLaneNum = 8;
1172 else
1173 args.v3.sExtEncoder.ucLaneNum = 4;
1174 switch (ext_enum) {
1175 case GRAPH_OBJECT_ENUM_ID1:
1176 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1;
1177 break;
1178 case GRAPH_OBJECT_ENUM_ID2:
1179 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2;
1180 break;
1181 case GRAPH_OBJECT_ENUM_ID3:
1182 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3;
1183 break;
1184 }
1185 switch (bpc) {
1186 case 0:
1187 args.v3.sExtEncoder.ucBitPerColor = PANEL_BPC_UNDEFINE;
1188 break;
1189 case 6:
1190 args.v3.sExtEncoder.ucBitPerColor = PANEL_6BIT_PER_COLOR;
1191 break;
1192 case 8:
1193 default:
1194 args.v3.sExtEncoder.ucBitPerColor = PANEL_8BIT_PER_COLOR;
1195 break;
1196 case 10:
1197 args.v3.sExtEncoder.ucBitPerColor = PANEL_10BIT_PER_COLOR;
1198 break;
1199 case 12:
1200 args.v3.sExtEncoder.ucBitPerColor = PANEL_12BIT_PER_COLOR;
1201 break;
1202 case 16:
1203 args.v3.sExtEncoder.ucBitPerColor = PANEL_16BIT_PER_COLOR;
1204 break;
1205 }
1206 break;
1207 default:
1208 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1209 return;
1210 }
1211 break;
1212 default:
1213 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1214 return;
1215 }
1216 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1217}
1218
1219static void
1220atombios_yuv_setup(struct drm_encoder *encoder, bool enable)
1221{
1222 struct drm_device *dev = encoder->dev;
1223 struct radeon_device *rdev = dev->dev_private;
1224 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1225 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1226 ENABLE_YUV_PS_ALLOCATION args;
1227 int index = GetIndexIntoMasterTable(COMMAND, EnableYUV);
1228 uint32_t temp, reg;
1229
1230 memset(&args, 0, sizeof(args));
1231
1232 if (rdev->family >= CHIP_R600)
1233 reg = R600_BIOS_3_SCRATCH;
1234 else
1235 reg = RADEON_BIOS_3_SCRATCH;
1236
1237 /* XXX: fix up scratch reg handling */
1238 temp = RREG32(reg);
1239 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1240 WREG32(reg, (ATOM_S3_TV1_ACTIVE |
1241 (radeon_crtc->crtc_id << 18)));
1242 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1243 WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24)));
1244 else
1245 WREG32(reg, 0);
1246
1247 if (enable)
1248 args.ucEnable = ATOM_ENABLE;
1249 args.ucCRTC = radeon_crtc->crtc_id;
1250
1251 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1252
1253 WREG32(reg, temp);
1254}
1255
1256static void
1257radeon_atom_encoder_dpms_avivo(struct drm_encoder *encoder, int mode)
1258{
1259 struct drm_device *dev = encoder->dev;
1260 struct radeon_device *rdev = dev->dev_private;
1261 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1262 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
1263 int index = 0;
1264
1265 memset(&args, 0, sizeof(args));
1266
1267 switch (radeon_encoder->encoder_id) {
1268 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1269 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1270 index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl);
1271 break;
1272 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1273 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1274 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1275 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
1276 break;
1277 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1278 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1279 break;
1280 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1281 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1282 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1283 else
1284 index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl);
1285 break;
1286 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1287 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1288 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1289 index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
1290 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1291 index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
1292 else
1293 index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl);
1294 break;
1295 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1296 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1297 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1298 index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
1299 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1300 index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
1301 else
1302 index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl);
1303 break;
1304 default:
1305 return;
1306 }
1307
1308 switch (mode) {
1309 case DRM_MODE_DPMS_ON:
1310 args.ucAction = ATOM_ENABLE;
1311 /* workaround for DVOOutputControl on some RS690 systems */
1312 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DDI) {
1313 u32 reg = RREG32(RADEON_BIOS_3_SCRATCH);
1314 WREG32(RADEON_BIOS_3_SCRATCH, reg & ~ATOM_S3_DFP2I_ACTIVE);
1315 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1316 WREG32(RADEON_BIOS_3_SCRATCH, reg);
1317 } else
1318 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1319 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1320 args.ucAction = ATOM_LCD_BLON;
1321 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1322 }
1323 break;
1324 case DRM_MODE_DPMS_STANDBY:
1325 case DRM_MODE_DPMS_SUSPEND:
1326 case DRM_MODE_DPMS_OFF:
1327 args.ucAction = ATOM_DISABLE;
1328 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1329 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1330 args.ucAction = ATOM_LCD_BLOFF;
1331 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1332 }
1333 break;
1334 }
1335}
1336
1337static void
1338radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode)
1339{
1340 struct drm_device *dev = encoder->dev;
1341 struct radeon_device *rdev = dev->dev_private;
1342 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1343 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1344 struct radeon_connector *radeon_connector = NULL;
1345 struct radeon_connector_atom_dig *radeon_dig_connector = NULL;
1346
1347 if (connector) {
1348 radeon_connector = to_radeon_connector(connector);
1349 radeon_dig_connector = radeon_connector->con_priv;
1350 }
1351
1352 switch (mode) {
1353 case DRM_MODE_DPMS_ON:
1354 /* some early dce3.2 boards have a bug in their transmitter control table */
1355 if ((rdev->family == CHIP_RV710) || (rdev->family == CHIP_RV730))
1356 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1357 else
1358 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
1359 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
1360 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1361 atombios_set_edp_panel_power(connector,
1362 ATOM_TRANSMITTER_ACTION_POWER_ON);
1363 radeon_dig_connector->edp_on = true;
1364 }
1365 if (ASIC_IS_DCE4(rdev))
1366 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
1367 radeon_dp_link_train(encoder, connector);
1368 if (ASIC_IS_DCE4(rdev))
1369 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0);
1370 }
1371 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1372 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
1373 break;
1374 case DRM_MODE_DPMS_STANDBY:
1375 case DRM_MODE_DPMS_SUSPEND:
1376 case DRM_MODE_DPMS_OFF:
1377 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
1378 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
1379 if (ASIC_IS_DCE4(rdev))
1380 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
1381 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1382 atombios_set_edp_panel_power(connector,
1383 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1384 radeon_dig_connector->edp_on = false;
1385 }
1386 }
1387 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1388 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
1389 break;
1390 }
1391}
1392
1393static void
1394radeon_atom_encoder_dpms_ext(struct drm_encoder *encoder,
1395 struct drm_encoder *ext_encoder,
1396 int mode)
1397{
1398 struct drm_device *dev = encoder->dev;
1399 struct radeon_device *rdev = dev->dev_private;
1400
1401 switch (mode) {
1402 case DRM_MODE_DPMS_ON:
1403 default:
1404 if (ASIC_IS_DCE41(rdev)) {
1405 atombios_external_encoder_setup(encoder, ext_encoder,
1406 EXTERNAL_ENCODER_ACTION_V3_ENABLE_OUTPUT);
1407 atombios_external_encoder_setup(encoder, ext_encoder,
1408 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING_OFF);
1409 } else
1410 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
1411 break;
1412 case DRM_MODE_DPMS_STANDBY:
1413 case DRM_MODE_DPMS_SUSPEND:
1414 case DRM_MODE_DPMS_OFF:
1415 if (ASIC_IS_DCE41(rdev)) {
1416 atombios_external_encoder_setup(encoder, ext_encoder,
1417 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING);
1418 atombios_external_encoder_setup(encoder, ext_encoder,
1419 EXTERNAL_ENCODER_ACTION_V3_DISABLE_OUTPUT);
1420 } else
1421 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_DISABLE);
1422 break;
1423 }
1424}
1425
1426static void
1427radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1428{
1429 struct drm_device *dev = encoder->dev;
1430 struct radeon_device *rdev = dev->dev_private;
1431 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1432 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
1433
1434 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
1435 radeon_encoder->encoder_id, mode, radeon_encoder->devices,
1436 radeon_encoder->active_device);
1437 switch (radeon_encoder->encoder_id) {
1438 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1439 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1440 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1441 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1442 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1443 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1444 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1445 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1446 radeon_atom_encoder_dpms_avivo(encoder, mode);
1447 break;
1448 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1449 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1450 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1451 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1452 radeon_atom_encoder_dpms_dig(encoder, mode);
1453 break;
1454 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1455 if (ASIC_IS_DCE5(rdev)) {
1456 switch (mode) {
1457 case DRM_MODE_DPMS_ON:
1458 atombios_dvo_setup(encoder, ATOM_ENABLE);
1459 break;
1460 case DRM_MODE_DPMS_STANDBY:
1461 case DRM_MODE_DPMS_SUSPEND:
1462 case DRM_MODE_DPMS_OFF:
1463 atombios_dvo_setup(encoder, ATOM_DISABLE);
1464 break;
1465 }
1466 } else if (ASIC_IS_DCE3(rdev))
1467 radeon_atom_encoder_dpms_dig(encoder, mode);
1468 else
1469 radeon_atom_encoder_dpms_avivo(encoder, mode);
1470 break;
1471 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1472 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1473 if (ASIC_IS_DCE5(rdev)) {
1474 switch (mode) {
1475 case DRM_MODE_DPMS_ON:
1476 atombios_dac_setup(encoder, ATOM_ENABLE);
1477 break;
1478 case DRM_MODE_DPMS_STANDBY:
1479 case DRM_MODE_DPMS_SUSPEND:
1480 case DRM_MODE_DPMS_OFF:
1481 atombios_dac_setup(encoder, ATOM_DISABLE);
1482 break;
1483 }
1484 } else
1485 radeon_atom_encoder_dpms_avivo(encoder, mode);
1486 break;
1487 default:
1488 return;
1489 }
1490
1491 if (ext_encoder)
1492 radeon_atom_encoder_dpms_ext(encoder, ext_encoder, mode);
1493
1494 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
1495
1496}
1497
1498union crtc_source_param {
1499 SELECT_CRTC_SOURCE_PS_ALLOCATION v1;
1500 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2;
1501};
1502
1503static void
1504atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
1505{
1506 struct drm_device *dev = encoder->dev;
1507 struct radeon_device *rdev = dev->dev_private;
1508 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1509 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1510 union crtc_source_param args;
1511 int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source);
1512 uint8_t frev, crev;
1513 struct radeon_encoder_atom_dig *dig;
1514
1515 memset(&args, 0, sizeof(args));
1516
1517 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1518 return;
1519
1520 switch (frev) {
1521 case 1:
1522 switch (crev) {
1523 case 1:
1524 default:
1525 if (ASIC_IS_AVIVO(rdev))
1526 args.v1.ucCRTC = radeon_crtc->crtc_id;
1527 else {
1528 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) {
1529 args.v1.ucCRTC = radeon_crtc->crtc_id;
1530 } else {
1531 args.v1.ucCRTC = radeon_crtc->crtc_id << 2;
1532 }
1533 }
1534 switch (radeon_encoder->encoder_id) {
1535 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1536 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1537 args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX;
1538 break;
1539 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1540 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1541 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT)
1542 args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX;
1543 else
1544 args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX;
1545 break;
1546 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1547 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1548 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1549 args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX;
1550 break;
1551 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1552 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1553 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1554 args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
1555 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1556 args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
1557 else
1558 args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX;
1559 break;
1560 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1561 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1562 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1563 args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
1564 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1565 args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
1566 else
1567 args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX;
1568 break;
1569 }
1570 break;
1571 case 2:
1572 args.v2.ucCRTC = radeon_crtc->crtc_id;
1573 if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE) {
1574 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1575
1576 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
1577 args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
1578 else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
1579 args.v2.ucEncodeMode = ATOM_ENCODER_MODE_CRT;
1580 else
1581 args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
1582 } else
1583 args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
1584 switch (radeon_encoder->encoder_id) {
1585 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1586 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1587 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1588 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1589 dig = radeon_encoder->enc_priv;
1590 switch (dig->dig_encoder) {
1591 case 0:
1592 args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
1593 break;
1594 case 1:
1595 args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
1596 break;
1597 case 2:
1598 args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID;
1599 break;
1600 case 3:
1601 args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID;
1602 break;
1603 case 4:
1604 args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID;
1605 break;
1606 case 5:
1607 args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID;
1608 break;
1609 }
1610 break;
1611 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1612 args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID;
1613 break;
1614 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1615 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1616 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1617 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1618 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1619 else
1620 args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID;
1621 break;
1622 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1623 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1624 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1625 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1626 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1627 else
1628 args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID;
1629 break;
1630 }
1631 break;
1632 }
1633 break;
1634 default:
1635 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1636 return;
1637 }
1638
1639 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1640
1641 /* update scratch regs with new routing */
1642 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1643}
1644
1645static void
1646atombios_apply_encoder_quirks(struct drm_encoder *encoder,
1647 struct drm_display_mode *mode)
1648{
1649 struct drm_device *dev = encoder->dev;
1650 struct radeon_device *rdev = dev->dev_private;
1651 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1652 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1653
1654 /* Funky macbooks */
1655 if ((dev->pdev->device == 0x71C5) &&
1656 (dev->pdev->subsystem_vendor == 0x106b) &&
1657 (dev->pdev->subsystem_device == 0x0080)) {
1658 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1659 uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL);
1660
1661 lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN;
1662 lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN;
1663
1664 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control);
1665 }
1666 }
1667
1668 /* set scaler clears this on some chips */
1669 if (ASIC_IS_AVIVO(rdev) &&
1670 (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)))) {
1671 if (ASIC_IS_DCE4(rdev)) {
1672 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1673 WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset,
1674 EVERGREEN_INTERLEAVE_EN);
1675 else
1676 WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1677 } else {
1678 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1679 WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset,
1680 AVIVO_D1MODE_INTERLEAVE_EN);
1681 else
1682 WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1683 }
1684 }
1685}
1686
1687static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder)
1688{
1689 struct drm_device *dev = encoder->dev;
1690 struct radeon_device *rdev = dev->dev_private;
1691 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1692 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1693 struct drm_encoder *test_encoder;
1694 struct radeon_encoder_atom_dig *dig;
1695 uint32_t dig_enc_in_use = 0;
1696
1697 /* DCE4/5 */
1698 if (ASIC_IS_DCE4(rdev)) {
1699 dig = radeon_encoder->enc_priv;
1700 if (ASIC_IS_DCE41(rdev)) {
1701 /* ontario follows DCE4 */
1702 if (rdev->family == CHIP_PALM) {
1703 if (dig->linkb)
1704 return 1;
1705 else
1706 return 0;
1707 } else
1708 /* llano follows DCE3.2 */
1709 return radeon_crtc->crtc_id;
1710 } else {
1711 switch (radeon_encoder->encoder_id) {
1712 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1713 if (dig->linkb)
1714 return 1;
1715 else
1716 return 0;
1717 break;
1718 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1719 if (dig->linkb)
1720 return 3;
1721 else
1722 return 2;
1723 break;
1724 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1725 if (dig->linkb)
1726 return 5;
1727 else
1728 return 4;
1729 break;
1730 }
1731 }
1732 }
1733
1734 /* on DCE32 and encoder can driver any block so just crtc id */
1735 if (ASIC_IS_DCE32(rdev)) {
1736 return radeon_crtc->crtc_id;
1737 }
1738
1739 /* on DCE3 - LVTMA can only be driven by DIGB */
1740 list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
1741 struct radeon_encoder *radeon_test_encoder;
1742
1743 if (encoder == test_encoder)
1744 continue;
1745
1746 if (!radeon_encoder_is_digital(test_encoder))
1747 continue;
1748
1749 radeon_test_encoder = to_radeon_encoder(test_encoder);
1750 dig = radeon_test_encoder->enc_priv;
1751
1752 if (dig->dig_encoder >= 0)
1753 dig_enc_in_use |= (1 << dig->dig_encoder);
1754 }
1755
1756 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA) {
1757 if (dig_enc_in_use & 0x2)
1758 DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
1759 return 1;
1760 }
1761 if (!(dig_enc_in_use & 1))
1762 return 0;
1763 return 1;
1764}
1765
1766/* This only needs to be called once at startup */
1767void
1768radeon_atom_encoder_init(struct radeon_device *rdev)
1769{
1770 struct drm_device *dev = rdev->ddev;
1771 struct drm_encoder *encoder;
1772
1773 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1774 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1775 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
1776
1777 switch (radeon_encoder->encoder_id) {
1778 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1779 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1780 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1781 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1782 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0);
1783 break;
1784 default:
1785 break;
1786 }
1787
1788 if (ext_encoder && ASIC_IS_DCE41(rdev))
1789 atombios_external_encoder_setup(encoder, ext_encoder,
1790 EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT);
1791 }
1792}
1793
1794static void
1795radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
1796 struct drm_display_mode *mode,
1797 struct drm_display_mode *adjusted_mode)
1798{
1799 struct drm_device *dev = encoder->dev;
1800 struct radeon_device *rdev = dev->dev_private;
1801 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1802 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
1803
1804 radeon_encoder->pixel_clock = adjusted_mode->clock;
1805
1806 if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) {
1807 if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT))
1808 atombios_yuv_setup(encoder, true);
1809 else
1810 atombios_yuv_setup(encoder, false);
1811 }
1812
1813 switch (radeon_encoder->encoder_id) {
1814 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1815 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1816 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1817 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1818 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
1819 break;
1820 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1821 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1822 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1823 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1824 if (ASIC_IS_DCE4(rdev)) {
1825 /* disable the transmitter */
1826 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
1827 /* setup and enable the encoder */
1828 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
1829
1830 /* enable the transmitter */
1831 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1832 } else {
1833 /* disable the encoder and transmitter */
1834 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
1835 atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
1836
1837 /* setup and enable the encoder and transmitter */
1838 atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0);
1839 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0);
1840 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1841 }
1842 break;
1843 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1844 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1845 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1846 atombios_dvo_setup(encoder, ATOM_ENABLE);
1847 break;
1848 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1849 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1850 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1851 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1852 atombios_dac_setup(encoder, ATOM_ENABLE);
1853 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) {
1854 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
1855 atombios_tv_setup(encoder, ATOM_ENABLE);
1856 else
1857 atombios_tv_setup(encoder, ATOM_DISABLE);
1858 }
1859 break;
1860 }
1861
1862 if (ext_encoder) {
1863 if (ASIC_IS_DCE41(rdev))
1864 atombios_external_encoder_setup(encoder, ext_encoder,
1865 EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP);
1866 else
1867 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
1868 }
1869
1870 atombios_apply_encoder_quirks(encoder, adjusted_mode);
1871
1872 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
1873 r600_hdmi_enable(encoder);
1874 r600_hdmi_setmode(encoder, adjusted_mode);
1875 }
1876}
1877
1878static bool
1879atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector)
1880{
1881 struct drm_device *dev = encoder->dev;
1882 struct radeon_device *rdev = dev->dev_private;
1883 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1884 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1885
1886 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT |
1887 ATOM_DEVICE_CV_SUPPORT |
1888 ATOM_DEVICE_CRT_SUPPORT)) {
1889 DAC_LOAD_DETECTION_PS_ALLOCATION args;
1890 int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection);
1891 uint8_t frev, crev;
1892
1893 memset(&args, 0, sizeof(args));
1894
1895 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1896 return false;
1897
1898 args.sDacload.ucMisc = 0;
1899
1900 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) ||
1901 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1))
1902 args.sDacload.ucDacType = ATOM_DAC_A;
1903 else
1904 args.sDacload.ucDacType = ATOM_DAC_B;
1905
1906 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)
1907 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT);
1908 else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)
1909 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT);
1910 else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
1911 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT);
1912 if (crev >= 3)
1913 args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
1914 } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
1915 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT);
1916 if (crev >= 3)
1917 args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
1918 }
1919
1920 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1921
1922 return true;
1923 } else
1924 return false;
1925}
1926
1927static enum drm_connector_status
1928radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
1929{
1930 struct drm_device *dev = encoder->dev;
1931 struct radeon_device *rdev = dev->dev_private;
1932 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1933 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1934 uint32_t bios_0_scratch;
1935
1936 if (!atombios_dac_load_detect(encoder, connector)) {
1937 DRM_DEBUG_KMS("detect returned false \n");
1938 return connector_status_unknown;
1939 }
1940
1941 if (rdev->family >= CHIP_R600)
1942 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1943 else
1944 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
1945
1946 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
1947 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1948 if (bios_0_scratch & ATOM_S0_CRT1_MASK)
1949 return connector_status_connected;
1950 }
1951 if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1952 if (bios_0_scratch & ATOM_S0_CRT2_MASK)
1953 return connector_status_connected;
1954 }
1955 if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
1956 if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
1957 return connector_status_connected;
1958 }
1959 if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
1960 if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
1961 return connector_status_connected; /* CTV */
1962 else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
1963 return connector_status_connected; /* STV */
1964 }
1965 return connector_status_disconnected;
1966}
1967
1968static enum drm_connector_status
1969radeon_atom_dig_detect(struct drm_encoder *encoder, struct drm_connector *connector)
1970{
1971 struct drm_device *dev = encoder->dev;
1972 struct radeon_device *rdev = dev->dev_private;
1973 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1974 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1975 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
1976 u32 bios_0_scratch;
1977
1978 if (!ASIC_IS_DCE4(rdev))
1979 return connector_status_unknown;
1980
1981 if (!ext_encoder)
1982 return connector_status_unknown;
1983
1984 if ((radeon_connector->devices & ATOM_DEVICE_CRT_SUPPORT) == 0)
1985 return connector_status_unknown;
1986
1987 /* load detect on the dp bridge */
1988 atombios_external_encoder_setup(encoder, ext_encoder,
1989 EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION);
1990
1991 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
1992
1993 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
1994 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
1995 if (bios_0_scratch & ATOM_S0_CRT1_MASK)
1996 return connector_status_connected;
1997 }
1998 if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
1999 if (bios_0_scratch & ATOM_S0_CRT2_MASK)
2000 return connector_status_connected;
2001 }
2002 if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
2003 if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
2004 return connector_status_connected;
2005 }
2006 if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
2007 if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
2008 return connector_status_connected; /* CTV */
2009 else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
2010 return connector_status_connected; /* STV */
2011 }
2012 return connector_status_disconnected;
2013}
2014
2015void
2016radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder)
2017{
2018 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
2019
2020 if (ext_encoder)
2021 /* ddc_setup on the dp bridge */
2022 atombios_external_encoder_setup(encoder, ext_encoder,
2023 EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP);
2024
2025}
2026
2027static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
2028{
2029 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2030 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
2031
2032 if ((radeon_encoder->active_device &
2033 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
2034 (radeon_encoder_get_dp_bridge_encoder_id(encoder) !=
2035 ENCODER_OBJECT_ID_NONE)) {
2036 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
2037 if (dig)
2038 dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder);
2039 }
2040
2041 radeon_atom_output_lock(encoder, true);
2042 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2043
2044 if (connector) {
2045 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2046
2047 /* select the clock/data port if it uses a router */
2048 if (radeon_connector->router.cd_valid)
2049 radeon_router_select_cd_port(radeon_connector);
2050
2051 /* turn eDP panel on for mode set */
2052 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
2053 atombios_set_edp_panel_power(connector,
2054 ATOM_TRANSMITTER_ACTION_POWER_ON);
2055 }
2056
2057 /* this is needed for the pll/ss setup to work correctly in some cases */
2058 atombios_set_encoder_crtc_source(encoder);
2059}
2060
2061static void radeon_atom_encoder_commit(struct drm_encoder *encoder)
2062{
2063 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
2064 radeon_atom_output_lock(encoder, false);
2065}
2066
2067static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
2068{
2069 struct drm_device *dev = encoder->dev;
2070 struct radeon_device *rdev = dev->dev_private;
2071 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2072 struct radeon_encoder_atom_dig *dig;
2073
2074 /* check for pre-DCE3 cards with shared encoders;
2075 * can't really use the links individually, so don't disable
2076 * the encoder if it's in use by another connector
2077 */
2078 if (!ASIC_IS_DCE3(rdev)) {
2079 struct drm_encoder *other_encoder;
2080 struct radeon_encoder *other_radeon_encoder;
2081
2082 list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
2083 other_radeon_encoder = to_radeon_encoder(other_encoder);
2084 if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) &&
2085 drm_helper_encoder_in_use(other_encoder))
2086 goto disable_done;
2087 }
2088 }
2089
2090 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2091
2092 switch (radeon_encoder->encoder_id) {
2093 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2094 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2095 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2096 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2097 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_DISABLE);
2098 break;
2099 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2100 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2101 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2102 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
2103 if (ASIC_IS_DCE4(rdev))
2104 /* disable the transmitter */
2105 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
2106 else {
2107 /* disable the encoder and transmitter */
2108 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
2109 atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
2110 }
2111 break;
2112 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2113 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2114 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2115 atombios_dvo_setup(encoder, ATOM_DISABLE);
2116 break;
2117 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2118 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2119 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2120 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2121 atombios_dac_setup(encoder, ATOM_DISABLE);
2122 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
2123 atombios_tv_setup(encoder, ATOM_DISABLE);
2124 break;
2125 }
2126
2127disable_done:
2128 if (radeon_encoder_is_digital(encoder)) {
2129 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
2130 r600_hdmi_disable(encoder);
2131 dig = radeon_encoder->enc_priv;
2132 dig->dig_encoder = -1;
2133 }
2134 radeon_encoder->active_device = 0;
2135}
2136
2137/* these are handled by the primary encoders */
2138static void radeon_atom_ext_prepare(struct drm_encoder *encoder)
2139{
2140
2141}
2142
2143static void radeon_atom_ext_commit(struct drm_encoder *encoder)
2144{
2145
2146}
2147
2148static void
2149radeon_atom_ext_mode_set(struct drm_encoder *encoder,
2150 struct drm_display_mode *mode,
2151 struct drm_display_mode *adjusted_mode)
2152{
2153
2154}
2155
2156static void radeon_atom_ext_disable(struct drm_encoder *encoder)
2157{
2158
2159}
2160
2161static void
2162radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode)
2163{
2164
2165}
2166
2167static bool radeon_atom_ext_mode_fixup(struct drm_encoder *encoder,
2168 struct drm_display_mode *mode,
2169 struct drm_display_mode *adjusted_mode)
2170{
2171 return true;
2172}
2173
2174static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = {
2175 .dpms = radeon_atom_ext_dpms,
2176 .mode_fixup = radeon_atom_ext_mode_fixup,
2177 .prepare = radeon_atom_ext_prepare,
2178 .mode_set = radeon_atom_ext_mode_set,
2179 .commit = radeon_atom_ext_commit,
2180 .disable = radeon_atom_ext_disable,
2181 /* no detect for TMDS/LVDS yet */
2182};
2183
2184static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = {
2185 .dpms = radeon_atom_encoder_dpms,
2186 .mode_fixup = radeon_atom_mode_fixup,
2187 .prepare = radeon_atom_encoder_prepare,
2188 .mode_set = radeon_atom_encoder_mode_set,
2189 .commit = radeon_atom_encoder_commit,
2190 .disable = radeon_atom_encoder_disable,
2191 .detect = radeon_atom_dig_detect,
2192};
2193
2194static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = {
2195 .dpms = radeon_atom_encoder_dpms,
2196 .mode_fixup = radeon_atom_mode_fixup,
2197 .prepare = radeon_atom_encoder_prepare,
2198 .mode_set = radeon_atom_encoder_mode_set,
2199 .commit = radeon_atom_encoder_commit,
2200 .detect = radeon_atom_dac_detect,
2201};
2202
2203void radeon_enc_destroy(struct drm_encoder *encoder)
2204{
2205 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2206 kfree(radeon_encoder->enc_priv);
2207 drm_encoder_cleanup(encoder);
2208 kfree(radeon_encoder);
2209}
2210
2211static const struct drm_encoder_funcs radeon_atom_enc_funcs = {
2212 .destroy = radeon_enc_destroy,
2213};
2214
2215struct radeon_encoder_atom_dac *
2216radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder)
2217{
2218 struct drm_device *dev = radeon_encoder->base.dev;
2219 struct radeon_device *rdev = dev->dev_private;
2220 struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL);
2221
2222 if (!dac)
2223 return NULL;
2224
2225 dac->tv_std = radeon_atombios_get_tv_info(rdev);
2226 return dac;
2227}
2228
2229struct radeon_encoder_atom_dig *
2230radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder)
2231{
2232 int encoder_enum = (radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
2233 struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
2234
2235 if (!dig)
2236 return NULL;
2237
2238 /* coherent mode by default */
2239 dig->coherent_mode = true;
2240 dig->dig_encoder = -1;
2241
2242 if (encoder_enum == 2)
2243 dig->linkb = true;
2244 else
2245 dig->linkb = false;
2246
2247 return dig;
2248}
2249
2250void
2251radeon_add_atom_encoder(struct drm_device *dev,
2252 uint32_t encoder_enum,
2253 uint32_t supported_device,
2254 u16 caps)
2255{
2256 struct radeon_device *rdev = dev->dev_private;
2257 struct drm_encoder *encoder;
2258 struct radeon_encoder *radeon_encoder;
2259
2260 /* see if we already added it */
2261 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2262 radeon_encoder = to_radeon_encoder(encoder);
2263 if (radeon_encoder->encoder_enum == encoder_enum) {
2264 radeon_encoder->devices |= supported_device;
2265 return;
2266 }
2267
2268 }
2269
2270 /* add a new one */
2271 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
2272 if (!radeon_encoder)
2273 return;
2274
2275 encoder = &radeon_encoder->base;
2276 switch (rdev->num_crtc) {
2277 case 1:
2278 encoder->possible_crtcs = 0x1;
2279 break;
2280 case 2:
2281 default:
2282 encoder->possible_crtcs = 0x3;
2283 break;
2284 case 4:
2285 encoder->possible_crtcs = 0xf;
2286 break;
2287 case 6:
2288 encoder->possible_crtcs = 0x3f;
2289 break;
2290 }
2291
2292 radeon_encoder->enc_priv = NULL;
2293
2294 radeon_encoder->encoder_enum = encoder_enum;
2295 radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
2296 radeon_encoder->devices = supported_device;
2297 radeon_encoder->rmx_type = RMX_OFF;
2298 radeon_encoder->underscan_type = UNDERSCAN_OFF;
2299 radeon_encoder->is_ext_encoder = false;
2300 radeon_encoder->caps = caps;
2301
2302 switch (radeon_encoder->encoder_id) {
2303 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2304 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2305 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2306 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2307 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2308 radeon_encoder->rmx_type = RMX_FULL;
2309 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2310 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2311 } else {
2312 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2313 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2314 }
2315 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
2316 break;
2317 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2318 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2319 radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
2320 drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
2321 break;
2322 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2323 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2324 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2325 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC);
2326 radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
2327 drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
2328 break;
2329 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2330 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2331 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2332 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2333 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
2334 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2335 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2336 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2337 radeon_encoder->rmx_type = RMX_FULL;
2338 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2339 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2340 } else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
2341 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2342 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2343 } else {
2344 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2345 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2346 }
2347 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
2348 break;
2349 case ENCODER_OBJECT_ID_SI170B:
2350 case ENCODER_OBJECT_ID_CH7303:
2351 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
2352 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
2353 case ENCODER_OBJECT_ID_TITFP513:
2354 case ENCODER_OBJECT_ID_VT1623:
2355 case ENCODER_OBJECT_ID_HDMI_SI1930:
2356 case ENCODER_OBJECT_ID_TRAVIS:
2357 case ENCODER_OBJECT_ID_NUTMEG:
2358 /* these are handled by the primary encoders */
2359 radeon_encoder->is_ext_encoder = true;
2360 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2361 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2362 else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
2363 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2364 else
2365 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2366 drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs);
2367 break;
2368 }
2369}
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index ed406e8404a..5e00d1670aa 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -82,6 +82,7 @@ u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
82{ 82{
83 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; 83 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
84 u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset); 84 u32 tmp = RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset);
85 int i;
85 86
86 /* Lock the graphics update lock */ 87 /* Lock the graphics update lock */
87 tmp |= EVERGREEN_GRPH_UPDATE_LOCK; 88 tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
@@ -99,7 +100,11 @@ u32 evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
99 (u32)crtc_base); 100 (u32)crtc_base);
100 101
101 /* Wait for update_pending to go high. */ 102 /* Wait for update_pending to go high. */
102 while (!(RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)); 103 for (i = 0; i < rdev->usec_timeout; i++) {
104 if (RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING)
105 break;
106 udelay(1);
107 }
103 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); 108 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
104 109
105 /* Unlock the lock, so double-buffering can take place inside vblank */ 110 /* Unlock the lock, so double-buffering can take place inside vblank */
@@ -157,6 +162,57 @@ int sumo_get_temp(struct radeon_device *rdev)
157 return actual_temp * 1000; 162 return actual_temp * 1000;
158} 163}
159 164
165void sumo_pm_init_profile(struct radeon_device *rdev)
166{
167 int idx;
168
169 /* default */
170 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
171 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
172 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
173 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
174
175 /* low,mid sh/mh */
176 if (rdev->flags & RADEON_IS_MOBILITY)
177 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
178 else
179 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
180
181 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
182 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
183 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
184 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
185
186 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
187 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
188 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
189 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
190
191 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
192 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
193 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
194 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
195
196 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
197 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
198 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
199 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
200
201 /* high sh/mh */
202 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
203 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
204 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
205 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
206 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
207 rdev->pm.power_state[idx].num_clock_modes - 1;
208
209 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
210 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
211 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
212 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
213 rdev->pm.power_state[idx].num_clock_modes - 1;
214}
215
160void evergreen_pm_misc(struct radeon_device *rdev) 216void evergreen_pm_misc(struct radeon_device *rdev)
161{ 217{
162 int req_ps_idx = rdev->pm.requested_power_state_index; 218 int req_ps_idx = rdev->pm.requested_power_state_index;
@@ -353,6 +409,7 @@ void evergreen_hpd_init(struct radeon_device *rdev)
353 default: 409 default:
354 break; 410 break;
355 } 411 }
412 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
356 } 413 }
357 if (rdev->irq.installed) 414 if (rdev->irq.installed)
358 evergreen_irq_set(rdev); 415 evergreen_irq_set(rdev);
@@ -893,7 +950,7 @@ int evergreen_pcie_gart_enable(struct radeon_device *rdev)
893 u32 tmp; 950 u32 tmp;
894 int r; 951 int r;
895 952
896 if (rdev->gart.table.vram.robj == NULL) { 953 if (rdev->gart.robj == NULL) {
897 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); 954 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
898 return -EINVAL; 955 return -EINVAL;
899 } 956 }
@@ -945,7 +1002,6 @@ int evergreen_pcie_gart_enable(struct radeon_device *rdev)
945void evergreen_pcie_gart_disable(struct radeon_device *rdev) 1002void evergreen_pcie_gart_disable(struct radeon_device *rdev)
946{ 1003{
947 u32 tmp; 1004 u32 tmp;
948 int r;
949 1005
950 /* Disable all tables */ 1006 /* Disable all tables */
951 WREG32(VM_CONTEXT0_CNTL, 0); 1007 WREG32(VM_CONTEXT0_CNTL, 0);
@@ -965,14 +1021,7 @@ void evergreen_pcie_gart_disable(struct radeon_device *rdev)
965 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); 1021 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
966 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); 1022 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
967 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); 1023 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
968 if (rdev->gart.table.vram.robj) { 1024 radeon_gart_table_vram_unpin(rdev);
969 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
970 if (likely(r == 0)) {
971 radeon_bo_kunmap(rdev->gart.table.vram.robj);
972 radeon_bo_unpin(rdev->gart.table.vram.robj);
973 radeon_bo_unreserve(rdev->gart.table.vram.robj);
974 }
975 }
976} 1025}
977 1026
978void evergreen_pcie_gart_fini(struct radeon_device *rdev) 1027void evergreen_pcie_gart_fini(struct radeon_device *rdev)
@@ -1226,7 +1275,7 @@ void evergreen_mc_program(struct radeon_device *rdev)
1226 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, 1275 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
1227 rdev->mc.vram_end >> 12); 1276 rdev->mc.vram_end >> 12);
1228 } 1277 }
1229 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0); 1278 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
1230 if (rdev->flags & RADEON_IS_IGP) { 1279 if (rdev->flags & RADEON_IS_IGP) {
1231 tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF; 1280 tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
1232 tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24; 1281 tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
@@ -3031,6 +3080,10 @@ static int evergreen_startup(struct radeon_device *rdev)
3031 } 3080 }
3032 } 3081 }
3033 3082
3083 r = r600_vram_scratch_init(rdev);
3084 if (r)
3085 return r;
3086
3034 evergreen_mc_program(rdev); 3087 evergreen_mc_program(rdev);
3035 if (rdev->flags & RADEON_IS_AGP) { 3088 if (rdev->flags & RADEON_IS_AGP) {
3036 evergreen_agp_enable(rdev); 3089 evergreen_agp_enable(rdev);
@@ -3235,6 +3288,7 @@ void evergreen_fini(struct radeon_device *rdev)
3235 radeon_ib_pool_fini(rdev); 3288 radeon_ib_pool_fini(rdev);
3236 radeon_irq_kms_fini(rdev); 3289 radeon_irq_kms_fini(rdev);
3237 evergreen_pcie_gart_fini(rdev); 3290 evergreen_pcie_gart_fini(rdev);
3291 r600_vram_scratch_fini(rdev);
3238 radeon_gem_fini(rdev); 3292 radeon_gem_fini(rdev);
3239 radeon_fence_driver_fini(rdev); 3293 radeon_fence_driver_fini(rdev);
3240 radeon_agp_fini(rdev); 3294 radeon_agp_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/evergreen_blit_kms.c b/drivers/gpu/drm/radeon/evergreen_blit_kms.c
index dcf11bbc06d..914e5af8416 100644
--- a/drivers/gpu/drm/radeon/evergreen_blit_kms.c
+++ b/drivers/gpu/drm/radeon/evergreen_blit_kms.c
@@ -94,6 +94,15 @@ cp_set_surface_sync(struct radeon_device *rdev,
94 else 94 else
95 cp_coher_size = ((size + 255) >> 8); 95 cp_coher_size = ((size + 255) >> 8);
96 96
97 if (rdev->family >= CHIP_CAYMAN) {
98 /* CP_COHER_CNTL2 has to be set manually when submitting a surface_sync
99 * to the RB directly. For IBs, the CP programs this as part of the
100 * surface_sync packet.
101 */
102 radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
103 radeon_ring_write(rdev, (0x85e8 - PACKET3_SET_CONFIG_REG_START) >> 2);
104 radeon_ring_write(rdev, 0); /* CP_COHER_CNTL2 */
105 }
97 radeon_ring_write(rdev, PACKET3(PACKET3_SURFACE_SYNC, 3)); 106 radeon_ring_write(rdev, PACKET3(PACKET3_SURFACE_SYNC, 3));
98 radeon_ring_write(rdev, sync_type); 107 radeon_ring_write(rdev, sync_type);
99 radeon_ring_write(rdev, cp_coher_size); 108 radeon_ring_write(rdev, cp_coher_size);
@@ -174,7 +183,7 @@ set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr)
174static void 183static void
175set_tex_resource(struct radeon_device *rdev, 184set_tex_resource(struct radeon_device *rdev,
176 int format, int w, int h, int pitch, 185 int format, int w, int h, int pitch,
177 u64 gpu_addr) 186 u64 gpu_addr, u32 size)
178{ 187{
179 u32 sq_tex_resource_word0, sq_tex_resource_word1; 188 u32 sq_tex_resource_word0, sq_tex_resource_word1;
180 u32 sq_tex_resource_word4, sq_tex_resource_word7; 189 u32 sq_tex_resource_word4, sq_tex_resource_word7;
@@ -196,6 +205,9 @@ set_tex_resource(struct radeon_device *rdev,
196 sq_tex_resource_word7 = format | 205 sq_tex_resource_word7 = format |
197 S__SQ_CONSTANT_TYPE(SQ_TEX_VTX_VALID_TEXTURE); 206 S__SQ_CONSTANT_TYPE(SQ_TEX_VTX_VALID_TEXTURE);
198 207
208 cp_set_surface_sync(rdev,
209 PACKET3_TC_ACTION_ENA, size, gpu_addr);
210
199 radeon_ring_write(rdev, PACKET3(PACKET3_SET_RESOURCE, 8)); 211 radeon_ring_write(rdev, PACKET3(PACKET3_SET_RESOURCE, 8));
200 radeon_ring_write(rdev, 0); 212 radeon_ring_write(rdev, 0);
201 radeon_ring_write(rdev, sq_tex_resource_word0); 213 radeon_ring_write(rdev, sq_tex_resource_word0);
@@ -613,11 +625,13 @@ int evergreen_blit_init(struct radeon_device *rdev)
613 rdev->r600_blit.primitives.set_default_state = set_default_state; 625 rdev->r600_blit.primitives.set_default_state = set_default_state;
614 626
615 rdev->r600_blit.ring_size_common = 55; /* shaders + def state */ 627 rdev->r600_blit.ring_size_common = 55; /* shaders + def state */
616 rdev->r600_blit.ring_size_common += 10; /* fence emit for VB IB */ 628 rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */
617 rdev->r600_blit.ring_size_common += 5; /* done copy */ 629 rdev->r600_blit.ring_size_common += 5; /* done copy */
618 rdev->r600_blit.ring_size_common += 10; /* fence emit for done copy */ 630 rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
619 631
620 rdev->r600_blit.ring_size_per_loop = 74; 632 rdev->r600_blit.ring_size_per_loop = 74;
633 if (rdev->family >= CHIP_CAYMAN)
634 rdev->r600_blit.ring_size_per_loop += 9; /* additional DWs for surface sync */
621 635
622 rdev->r600_blit.max_dim = 16384; 636 rdev->r600_blit.max_dim = 16384;
623 637
diff --git a/drivers/gpu/drm/radeon/evergreen_cs.c b/drivers/gpu/drm/radeon/evergreen_cs.c
index 7fdfa8ea757..cd4590aae15 100644
--- a/drivers/gpu/drm/radeon/evergreen_cs.c
+++ b/drivers/gpu/drm/radeon/evergreen_cs.c
@@ -38,6 +38,7 @@ struct evergreen_cs_track {
38 u32 group_size; 38 u32 group_size;
39 u32 nbanks; 39 u32 nbanks;
40 u32 npipes; 40 u32 npipes;
41 u32 row_size;
41 /* value we track */ 42 /* value we track */
42 u32 nsamples; 43 u32 nsamples;
43 u32 cb_color_base_last[12]; 44 u32 cb_color_base_last[12];
@@ -77,6 +78,44 @@ struct evergreen_cs_track {
77 struct radeon_bo *db_s_write_bo; 78 struct radeon_bo *db_s_write_bo;
78}; 79};
79 80
81static u32 evergreen_cs_get_aray_mode(u32 tiling_flags)
82{
83 if (tiling_flags & RADEON_TILING_MACRO)
84 return ARRAY_2D_TILED_THIN1;
85 else if (tiling_flags & RADEON_TILING_MICRO)
86 return ARRAY_1D_TILED_THIN1;
87 else
88 return ARRAY_LINEAR_GENERAL;
89}
90
91static u32 evergreen_cs_get_num_banks(u32 nbanks)
92{
93 switch (nbanks) {
94 case 2:
95 return ADDR_SURF_2_BANK;
96 case 4:
97 return ADDR_SURF_4_BANK;
98 case 8:
99 default:
100 return ADDR_SURF_8_BANK;
101 case 16:
102 return ADDR_SURF_16_BANK;
103 }
104}
105
106static u32 evergreen_cs_get_tile_split(u32 row_size)
107{
108 switch (row_size) {
109 case 1:
110 default:
111 return ADDR_SURF_TILE_SPLIT_1KB;
112 case 2:
113 return ADDR_SURF_TILE_SPLIT_2KB;
114 case 4:
115 return ADDR_SURF_TILE_SPLIT_4KB;
116 }
117}
118
80static void evergreen_cs_track_init(struct evergreen_cs_track *track) 119static void evergreen_cs_track_init(struct evergreen_cs_track *track)
81{ 120{
82 int i; 121 int i;
@@ -480,21 +519,22 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
480 } 519 }
481 break; 520 break;
482 case DB_Z_INFO: 521 case DB_Z_INFO:
483 r = evergreen_cs_packet_next_reloc(p, &reloc);
484 if (r) {
485 dev_warn(p->dev, "bad SET_CONTEXT_REG "
486 "0x%04X\n", reg);
487 return -EINVAL;
488 }
489 track->db_z_info = radeon_get_ib_value(p, idx); 522 track->db_z_info = radeon_get_ib_value(p, idx);
490 ib[idx] &= ~Z_ARRAY_MODE(0xf); 523 if (!p->keep_tiling_flags) {
491 track->db_z_info &= ~Z_ARRAY_MODE(0xf); 524 r = evergreen_cs_packet_next_reloc(p, &reloc);
492 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) { 525 if (r) {
493 ib[idx] |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 526 dev_warn(p->dev, "bad SET_CONTEXT_REG "
494 track->db_z_info |= Z_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 527 "0x%04X\n", reg);
495 } else { 528 return -EINVAL;
496 ib[idx] |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 529 }
497 track->db_z_info |= Z_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 530 ib[idx] &= ~Z_ARRAY_MODE(0xf);
531 track->db_z_info &= ~Z_ARRAY_MODE(0xf);
532 ib[idx] |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
533 track->db_z_info |= Z_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
534 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
535 ib[idx] |= DB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
536 ib[idx] |= DB_TILE_SPLIT(evergreen_cs_get_tile_split(track->row_size));
537 }
498 } 538 }
499 break; 539 break;
500 case DB_STENCIL_INFO: 540 case DB_STENCIL_INFO:
@@ -607,40 +647,34 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
607 case CB_COLOR5_INFO: 647 case CB_COLOR5_INFO:
608 case CB_COLOR6_INFO: 648 case CB_COLOR6_INFO:
609 case CB_COLOR7_INFO: 649 case CB_COLOR7_INFO:
610 r = evergreen_cs_packet_next_reloc(p, &reloc);
611 if (r) {
612 dev_warn(p->dev, "bad SET_CONTEXT_REG "
613 "0x%04X\n", reg);
614 return -EINVAL;
615 }
616 tmp = (reg - CB_COLOR0_INFO) / 0x3c; 650 tmp = (reg - CB_COLOR0_INFO) / 0x3c;
617 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx); 651 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
618 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) { 652 if (!p->keep_tiling_flags) {
619 ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 653 r = evergreen_cs_packet_next_reloc(p, &reloc);
620 track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 654 if (r) {
621 } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) { 655 dev_warn(p->dev, "bad SET_CONTEXT_REG "
622 ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 656 "0x%04X\n", reg);
623 track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 657 return -EINVAL;
658 }
659 ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
660 track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
624 } 661 }
625 break; 662 break;
626 case CB_COLOR8_INFO: 663 case CB_COLOR8_INFO:
627 case CB_COLOR9_INFO: 664 case CB_COLOR9_INFO:
628 case CB_COLOR10_INFO: 665 case CB_COLOR10_INFO:
629 case CB_COLOR11_INFO: 666 case CB_COLOR11_INFO:
630 r = evergreen_cs_packet_next_reloc(p, &reloc);
631 if (r) {
632 dev_warn(p->dev, "bad SET_CONTEXT_REG "
633 "0x%04X\n", reg);
634 return -EINVAL;
635 }
636 tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8; 667 tmp = ((reg - CB_COLOR8_INFO) / 0x1c) + 8;
637 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx); 668 track->cb_color_info[tmp] = radeon_get_ib_value(p, idx);
638 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) { 669 if (!p->keep_tiling_flags) {
639 ib[idx] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 670 r = evergreen_cs_packet_next_reloc(p, &reloc);
640 track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 671 if (r) {
641 } else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) { 672 dev_warn(p->dev, "bad SET_CONTEXT_REG "
642 ib[idx] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 673 "0x%04X\n", reg);
643 track->cb_color_info[tmp] |= CB_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 674 return -EINVAL;
675 }
676 ib[idx] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
677 track->cb_color_info[tmp] |= CB_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
644 } 678 }
645 break; 679 break;
646 case CB_COLOR0_PITCH: 680 case CB_COLOR0_PITCH:
@@ -695,6 +729,16 @@ static int evergreen_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
695 case CB_COLOR9_ATTRIB: 729 case CB_COLOR9_ATTRIB:
696 case CB_COLOR10_ATTRIB: 730 case CB_COLOR10_ATTRIB:
697 case CB_COLOR11_ATTRIB: 731 case CB_COLOR11_ATTRIB:
732 r = evergreen_cs_packet_next_reloc(p, &reloc);
733 if (r) {
734 dev_warn(p->dev, "bad SET_CONTEXT_REG "
735 "0x%04X\n", reg);
736 return -EINVAL;
737 }
738 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
739 ib[idx] |= CB_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
740 ib[idx] |= CB_TILE_SPLIT(evergreen_cs_get_tile_split(track->row_size));
741 }
698 break; 742 break;
699 case CB_COLOR0_DIM: 743 case CB_COLOR0_DIM:
700 case CB_COLOR1_DIM: 744 case CB_COLOR1_DIM:
@@ -1311,10 +1355,16 @@ static int evergreen_packet3_check(struct radeon_cs_parser *p,
1311 return -EINVAL; 1355 return -EINVAL;
1312 } 1356 }
1313 ib[idx+1+(i*8)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1357 ib[idx+1+(i*8)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1314 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 1358 if (!p->keep_tiling_flags) {
1315 ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_2D_TILED_THIN1); 1359 ib[idx+1+(i*8)+1] |=
1316 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 1360 TEX_ARRAY_MODE(evergreen_cs_get_aray_mode(reloc->lobj.tiling_flags));
1317 ib[idx+1+(i*8)+1] |= TEX_ARRAY_MODE(ARRAY_1D_TILED_THIN1); 1361 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) {
1362 ib[idx+1+(i*8)+6] |=
1363 TEX_TILE_SPLIT(evergreen_cs_get_tile_split(track->row_size));
1364 ib[idx+1+(i*8)+7] |=
1365 TEX_NUM_BANKS(evergreen_cs_get_num_banks(track->nbanks));
1366 }
1367 }
1318 texture = reloc->robj; 1368 texture = reloc->robj;
1319 /* tex mip base */ 1369 /* tex mip base */
1320 r = evergreen_cs_packet_next_reloc(p, &reloc); 1370 r = evergreen_cs_packet_next_reloc(p, &reloc);
@@ -1414,6 +1464,7 @@ int evergreen_cs_parse(struct radeon_cs_parser *p)
1414{ 1464{
1415 struct radeon_cs_packet pkt; 1465 struct radeon_cs_packet pkt;
1416 struct evergreen_cs_track *track; 1466 struct evergreen_cs_track *track;
1467 u32 tmp;
1417 int r; 1468 int r;
1418 1469
1419 if (p->track == NULL) { 1470 if (p->track == NULL) {
@@ -1422,9 +1473,63 @@ int evergreen_cs_parse(struct radeon_cs_parser *p)
1422 if (track == NULL) 1473 if (track == NULL)
1423 return -ENOMEM; 1474 return -ENOMEM;
1424 evergreen_cs_track_init(track); 1475 evergreen_cs_track_init(track);
1425 track->npipes = p->rdev->config.evergreen.tiling_npipes; 1476 if (p->rdev->family >= CHIP_CAYMAN)
1426 track->nbanks = p->rdev->config.evergreen.tiling_nbanks; 1477 tmp = p->rdev->config.cayman.tile_config;
1427 track->group_size = p->rdev->config.evergreen.tiling_group_size; 1478 else
1479 tmp = p->rdev->config.evergreen.tile_config;
1480
1481 switch (tmp & 0xf) {
1482 case 0:
1483 track->npipes = 1;
1484 break;
1485 case 1:
1486 default:
1487 track->npipes = 2;
1488 break;
1489 case 2:
1490 track->npipes = 4;
1491 break;
1492 case 3:
1493 track->npipes = 8;
1494 break;
1495 }
1496
1497 switch ((tmp & 0xf0) >> 4) {
1498 case 0:
1499 track->nbanks = 4;
1500 break;
1501 case 1:
1502 default:
1503 track->nbanks = 8;
1504 break;
1505 case 2:
1506 track->nbanks = 16;
1507 break;
1508 }
1509
1510 switch ((tmp & 0xf00) >> 8) {
1511 case 0:
1512 track->group_size = 256;
1513 break;
1514 case 1:
1515 default:
1516 track->group_size = 512;
1517 break;
1518 }
1519
1520 switch ((tmp & 0xf000) >> 12) {
1521 case 0:
1522 track->row_size = 1;
1523 break;
1524 case 1:
1525 default:
1526 track->row_size = 2;
1527 break;
1528 case 2:
1529 track->row_size = 4;
1530 break;
1531 }
1532
1428 p->track = track; 1533 p->track = track;
1429 } 1534 }
1430 do { 1535 do {
diff --git a/drivers/gpu/drm/radeon/evergreen_reg.h b/drivers/gpu/drm/radeon/evergreen_reg.h
index c781c92c345..7d7f2155e34 100644
--- a/drivers/gpu/drm/radeon/evergreen_reg.h
+++ b/drivers/gpu/drm/radeon/evergreen_reg.h
@@ -42,6 +42,17 @@
42# define EVERGREEN_GRPH_DEPTH_8BPP 0 42# define EVERGREEN_GRPH_DEPTH_8BPP 0
43# define EVERGREEN_GRPH_DEPTH_16BPP 1 43# define EVERGREEN_GRPH_DEPTH_16BPP 1
44# define EVERGREEN_GRPH_DEPTH_32BPP 2 44# define EVERGREEN_GRPH_DEPTH_32BPP 2
45# define EVERGREEN_GRPH_NUM_BANKS(x) (((x) & 0x3) << 2)
46# define EVERGREEN_ADDR_SURF_2_BANK 0
47# define EVERGREEN_ADDR_SURF_4_BANK 1
48# define EVERGREEN_ADDR_SURF_8_BANK 2
49# define EVERGREEN_ADDR_SURF_16_BANK 3
50# define EVERGREEN_GRPH_Z(x) (((x) & 0x3) << 4)
51# define EVERGREEN_GRPH_BANK_WIDTH(x) (((x) & 0x3) << 6)
52# define EVERGREEN_ADDR_SURF_BANK_WIDTH_1 0
53# define EVERGREEN_ADDR_SURF_BANK_WIDTH_2 1
54# define EVERGREEN_ADDR_SURF_BANK_WIDTH_4 2
55# define EVERGREEN_ADDR_SURF_BANK_WIDTH_8 3
45# define EVERGREEN_GRPH_FORMAT(x) (((x) & 0x7) << 8) 56# define EVERGREEN_GRPH_FORMAT(x) (((x) & 0x7) << 8)
46/* 8 BPP */ 57/* 8 BPP */
47# define EVERGREEN_GRPH_FORMAT_INDEXED 0 58# define EVERGREEN_GRPH_FORMAT_INDEXED 0
@@ -61,6 +72,24 @@
61# define EVERGREEN_GRPH_FORMAT_8B_BGRA1010102 5 72# define EVERGREEN_GRPH_FORMAT_8B_BGRA1010102 5
62# define EVERGREEN_GRPH_FORMAT_RGB111110 6 73# define EVERGREEN_GRPH_FORMAT_RGB111110 6
63# define EVERGREEN_GRPH_FORMAT_BGR101111 7 74# define EVERGREEN_GRPH_FORMAT_BGR101111 7
75# define EVERGREEN_GRPH_BANK_HEIGHT(x) (((x) & 0x3) << 11)
76# define EVERGREEN_ADDR_SURF_BANK_HEIGHT_1 0
77# define EVERGREEN_ADDR_SURF_BANK_HEIGHT_2 1
78# define EVERGREEN_ADDR_SURF_BANK_HEIGHT_4 2
79# define EVERGREEN_ADDR_SURF_BANK_HEIGHT_8 3
80# define EVERGREEN_GRPH_TILE_SPLIT(x) (((x) & 0x7) << 13)
81# define EVERGREEN_ADDR_SURF_TILE_SPLIT_64B 0
82# define EVERGREEN_ADDR_SURF_TILE_SPLIT_128B 1
83# define EVERGREEN_ADDR_SURF_TILE_SPLIT_256B 2
84# define EVERGREEN_ADDR_SURF_TILE_SPLIT_512B 3
85# define EVERGREEN_ADDR_SURF_TILE_SPLIT_1KB 4
86# define EVERGREEN_ADDR_SURF_TILE_SPLIT_2KB 5
87# define EVERGREEN_ADDR_SURF_TILE_SPLIT_4KB 6
88# define EVERGREEN_GRPH_MACRO_TILE_ASPECT(x) (((x) & 0x3) << 18)
89# define EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1 0
90# define EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2 1
91# define EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4 2
92# define EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8 3
64# define EVERGREEN_GRPH_ARRAY_MODE(x) (((x) & 0x7) << 20) 93# define EVERGREEN_GRPH_ARRAY_MODE(x) (((x) & 0x7) << 20)
65# define EVERGREEN_GRPH_ARRAY_LINEAR_GENERAL 0 94# define EVERGREEN_GRPH_ARRAY_LINEAR_GENERAL 0
66# define EVERGREEN_GRPH_ARRAY_LINEAR_ALIGNED 1 95# define EVERGREEN_GRPH_ARRAY_LINEAR_ALIGNED 1
diff --git a/drivers/gpu/drm/radeon/evergreend.h b/drivers/gpu/drm/radeon/evergreend.h
index b937c49054d..e00039e59a7 100644
--- a/drivers/gpu/drm/radeon/evergreend.h
+++ b/drivers/gpu/drm/radeon/evergreend.h
@@ -899,6 +899,10 @@
899#define DB_HTILE_DATA_BASE 0x28014 899#define DB_HTILE_DATA_BASE 0x28014
900#define DB_Z_INFO 0x28040 900#define DB_Z_INFO 0x28040
901# define Z_ARRAY_MODE(x) ((x) << 4) 901# define Z_ARRAY_MODE(x) ((x) << 4)
902# define DB_TILE_SPLIT(x) (((x) & 0x7) << 8)
903# define DB_NUM_BANKS(x) (((x) & 0x3) << 12)
904# define DB_BANK_WIDTH(x) (((x) & 0x3) << 16)
905# define DB_BANK_HEIGHT(x) (((x) & 0x3) << 20)
902#define DB_STENCIL_INFO 0x28044 906#define DB_STENCIL_INFO 0x28044
903#define DB_Z_READ_BASE 0x28048 907#define DB_Z_READ_BASE 0x28048
904#define DB_STENCIL_READ_BASE 0x2804c 908#define DB_STENCIL_READ_BASE 0x2804c
@@ -951,6 +955,29 @@
951# define CB_SF_EXPORT_FULL 0 955# define CB_SF_EXPORT_FULL 0
952# define CB_SF_EXPORT_NORM 1 956# define CB_SF_EXPORT_NORM 1
953#define CB_COLOR0_ATTRIB 0x28c74 957#define CB_COLOR0_ATTRIB 0x28c74
958# define CB_TILE_SPLIT(x) (((x) & 0x7) << 5)
959# define ADDR_SURF_TILE_SPLIT_64B 0
960# define ADDR_SURF_TILE_SPLIT_128B 1
961# define ADDR_SURF_TILE_SPLIT_256B 2
962# define ADDR_SURF_TILE_SPLIT_512B 3
963# define ADDR_SURF_TILE_SPLIT_1KB 4
964# define ADDR_SURF_TILE_SPLIT_2KB 5
965# define ADDR_SURF_TILE_SPLIT_4KB 6
966# define CB_NUM_BANKS(x) (((x) & 0x3) << 10)
967# define ADDR_SURF_2_BANK 0
968# define ADDR_SURF_4_BANK 1
969# define ADDR_SURF_8_BANK 2
970# define ADDR_SURF_16_BANK 3
971# define CB_BANK_WIDTH(x) (((x) & 0x3) << 13)
972# define ADDR_SURF_BANK_WIDTH_1 0
973# define ADDR_SURF_BANK_WIDTH_2 1
974# define ADDR_SURF_BANK_WIDTH_4 2
975# define ADDR_SURF_BANK_WIDTH_8 3
976# define CB_BANK_HEIGHT(x) (((x) & 0x3) << 16)
977# define ADDR_SURF_BANK_HEIGHT_1 0
978# define ADDR_SURF_BANK_HEIGHT_2 1
979# define ADDR_SURF_BANK_HEIGHT_4 2
980# define ADDR_SURF_BANK_HEIGHT_8 3
954#define CB_COLOR0_DIM 0x28c78 981#define CB_COLOR0_DIM 0x28c78
955/* only CB0-7 blocks have these regs */ 982/* only CB0-7 blocks have these regs */
956#define CB_COLOR0_CMASK 0x28c7c 983#define CB_COLOR0_CMASK 0x28c7c
@@ -1137,7 +1164,11 @@
1137# define SQ_SEL_1 5 1164# define SQ_SEL_1 5
1138#define SQ_TEX_RESOURCE_WORD5_0 0x30014 1165#define SQ_TEX_RESOURCE_WORD5_0 0x30014
1139#define SQ_TEX_RESOURCE_WORD6_0 0x30018 1166#define SQ_TEX_RESOURCE_WORD6_0 0x30018
1167# define TEX_TILE_SPLIT(x) (((x) & 0x7) << 29)
1140#define SQ_TEX_RESOURCE_WORD7_0 0x3001c 1168#define SQ_TEX_RESOURCE_WORD7_0 0x3001c
1169# define TEX_BANK_WIDTH(x) (((x) & 0x3) << 8)
1170# define TEX_BANK_HEIGHT(x) (((x) & 0x3) << 10)
1171# define TEX_NUM_BANKS(x) (((x) & 0x3) << 16)
1141 1172
1142#define SQ_VTX_CONSTANT_WORD0_0 0x30000 1173#define SQ_VTX_CONSTANT_WORD0_0 0x30000
1143#define SQ_VTX_CONSTANT_WORD1_0 0x30004 1174#define SQ_VTX_CONSTANT_WORD1_0 0x30004
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index 556b7bc3418..0e579985746 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"
@@ -261,8 +262,11 @@ int ni_mc_load_microcode(struct radeon_device *rdev)
261 WREG32(MC_SEQ_SUP_CNTL, 0x00000001); 262 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
262 263
263 /* wait for training to complete */ 264 /* wait for training to complete */
264 while (!(RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)) 265 for (i = 0; i < rdev->usec_timeout; i++) {
265 udelay(10); 266 if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)
267 break;
268 udelay(1);
269 }
266 270
267 if (running) 271 if (running)
268 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout); 272 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
@@ -932,7 +936,7 @@ int cayman_pcie_gart_enable(struct radeon_device *rdev)
932{ 936{
933 int r; 937 int r;
934 938
935 if (rdev->gart.table.vram.robj == NULL) { 939 if (rdev->gart.robj == NULL) {
936 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); 940 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
937 return -EINVAL; 941 return -EINVAL;
938 } 942 }
@@ -977,8 +981,6 @@ int cayman_pcie_gart_enable(struct radeon_device *rdev)
977 981
978void cayman_pcie_gart_disable(struct radeon_device *rdev) 982void cayman_pcie_gart_disable(struct radeon_device *rdev)
979{ 983{
980 int r;
981
982 /* Disable all tables */ 984 /* Disable all tables */
983 WREG32(VM_CONTEXT0_CNTL, 0); 985 WREG32(VM_CONTEXT0_CNTL, 0);
984 WREG32(VM_CONTEXT1_CNTL, 0); 986 WREG32(VM_CONTEXT1_CNTL, 0);
@@ -994,14 +996,7 @@ void cayman_pcie_gart_disable(struct radeon_device *rdev)
994 WREG32(VM_L2_CNTL2, 0); 996 WREG32(VM_L2_CNTL2, 0);
995 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY | 997 WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
996 L2_CACHE_BIGK_FRAGMENT_SIZE(6)); 998 L2_CACHE_BIGK_FRAGMENT_SIZE(6));
997 if (rdev->gart.table.vram.robj) { 999 radeon_gart_table_vram_unpin(rdev);
998 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
999 if (likely(r == 0)) {
1000 radeon_bo_kunmap(rdev->gart.table.vram.robj);
1001 radeon_bo_unpin(rdev->gart.table.vram.robj);
1002 radeon_bo_unreserve(rdev->gart.table.vram.robj);
1003 }
1004 }
1005} 1000}
1006 1001
1007void cayman_pcie_gart_fini(struct radeon_device *rdev) 1002void cayman_pcie_gart_fini(struct radeon_device *rdev)
@@ -1361,6 +1356,10 @@ static int cayman_startup(struct radeon_device *rdev)
1361 return r; 1356 return r;
1362 } 1357 }
1363 1358
1359 r = r600_vram_scratch_init(rdev);
1360 if (r)
1361 return r;
1362
1364 evergreen_mc_program(rdev); 1363 evergreen_mc_program(rdev);
1365 r = cayman_pcie_gart_enable(rdev); 1364 r = cayman_pcie_gart_enable(rdev);
1366 if (r) 1365 if (r)
@@ -1556,6 +1555,7 @@ void cayman_fini(struct radeon_device *rdev)
1556 radeon_ib_pool_fini(rdev); 1555 radeon_ib_pool_fini(rdev);
1557 radeon_irq_kms_fini(rdev); 1556 radeon_irq_kms_fini(rdev);
1558 cayman_pcie_gart_fini(rdev); 1557 cayman_pcie_gart_fini(rdev);
1558 r600_vram_scratch_fini(rdev);
1559 radeon_gem_fini(rdev); 1559 radeon_gem_fini(rdev);
1560 radeon_fence_driver_fini(rdev); 1560 radeon_fence_driver_fini(rdev);
1561 radeon_bo_fini(rdev); 1561 radeon_bo_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 8f8b8fa1435..bfc08f6320f 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"
@@ -186,13 +187,18 @@ u32 r100_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
186{ 187{
187 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; 188 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
188 u32 tmp = ((u32)crtc_base) | RADEON_CRTC_OFFSET__OFFSET_LOCK; 189 u32 tmp = ((u32)crtc_base) | RADEON_CRTC_OFFSET__OFFSET_LOCK;
190 int i;
189 191
190 /* Lock the graphics update lock */ 192 /* Lock the graphics update lock */
191 /* update the scanout addresses */ 193 /* update the scanout addresses */
192 WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, tmp); 194 WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, tmp);
193 195
194 /* Wait for update_pending to go high. */ 196 /* Wait for update_pending to go high. */
195 while (!(RREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset) & RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET)); 197 for (i = 0; i < rdev->usec_timeout; i++) {
198 if (RREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset) & RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET)
199 break;
200 udelay(1);
201 }
196 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); 202 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
197 203
198 /* Unlock the lock, so double-buffering can take place inside vblank */ 204 /* Unlock the lock, so double-buffering can take place inside vblank */
@@ -536,6 +542,7 @@ void r100_hpd_init(struct radeon_device *rdev)
536 default: 542 default:
537 break; 543 break;
538 } 544 }
545 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
539 } 546 }
540 if (rdev->irq.installed) 547 if (rdev->irq.installed)
541 r100_irq_set(rdev); 548 r100_irq_set(rdev);
@@ -576,7 +583,7 @@ int r100_pci_gart_init(struct radeon_device *rdev)
576{ 583{
577 int r; 584 int r;
578 585
579 if (rdev->gart.table.ram.ptr) { 586 if (rdev->gart.ptr) {
580 WARN(1, "R100 PCI GART already initialized\n"); 587 WARN(1, "R100 PCI GART already initialized\n");
581 return 0; 588 return 0;
582 } 589 }
@@ -635,10 +642,12 @@ void r100_pci_gart_disable(struct radeon_device *rdev)
635 642
636int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) 643int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
637{ 644{
645 u32 *gtt = rdev->gart.ptr;
646
638 if (i < 0 || i > rdev->gart.num_gpu_pages) { 647 if (i < 0 || i > rdev->gart.num_gpu_pages) {
639 return -EINVAL; 648 return -EINVAL;
640 } 649 }
641 rdev->gart.table.ram.ptr[i] = cpu_to_le32(lower_32_bits(addr)); 650 gtt[i] = cpu_to_le32(lower_32_bits(addr));
642 return 0; 651 return 0;
643} 652}
644 653
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index 33f2b68c680..c93bc64707e 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -74,7 +74,7 @@ void rv370_pcie_gart_tlb_flush(struct radeon_device *rdev)
74 74
75int rv370_pcie_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) 75int rv370_pcie_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
76{ 76{
77 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr; 77 void __iomem *ptr = rdev->gart.ptr;
78 78
79 if (i < 0 || i > rdev->gart.num_gpu_pages) { 79 if (i < 0 || i > rdev->gart.num_gpu_pages) {
80 return -EINVAL; 80 return -EINVAL;
@@ -93,7 +93,7 @@ int rv370_pcie_gart_init(struct radeon_device *rdev)
93{ 93{
94 int r; 94 int r;
95 95
96 if (rdev->gart.table.vram.robj) { 96 if (rdev->gart.robj) {
97 WARN(1, "RV370 PCIE GART already initialized\n"); 97 WARN(1, "RV370 PCIE GART already initialized\n");
98 return 0; 98 return 0;
99 } 99 }
@@ -116,7 +116,7 @@ int rv370_pcie_gart_enable(struct radeon_device *rdev)
116 uint32_t tmp; 116 uint32_t tmp;
117 int r; 117 int r;
118 118
119 if (rdev->gart.table.vram.robj == NULL) { 119 if (rdev->gart.robj == NULL) {
120 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); 120 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
121 return -EINVAL; 121 return -EINVAL;
122 } 122 }
@@ -154,7 +154,6 @@ int rv370_pcie_gart_enable(struct radeon_device *rdev)
154void rv370_pcie_gart_disable(struct radeon_device *rdev) 154void rv370_pcie_gart_disable(struct radeon_device *rdev)
155{ 155{
156 u32 tmp; 156 u32 tmp;
157 int r;
158 157
159 WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO, 0); 158 WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO, 0);
160 WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO, 0); 159 WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO, 0);
@@ -163,14 +162,7 @@ void rv370_pcie_gart_disable(struct radeon_device *rdev)
163 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL); 162 tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
164 tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD; 163 tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
165 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp & ~RADEON_PCIE_TX_GART_EN); 164 WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp & ~RADEON_PCIE_TX_GART_EN);
166 if (rdev->gart.table.vram.robj) { 165 radeon_gart_table_vram_unpin(rdev);
167 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
168 if (likely(r == 0)) {
169 radeon_bo_kunmap(rdev->gart.table.vram.robj);
170 radeon_bo_unpin(rdev->gart.table.vram.robj);
171 radeon_bo_unreserve(rdev->gart.table.vram.robj);
172 }
173 }
174} 166}
175 167
176void rv370_pcie_gart_fini(struct radeon_device *rdev) 168void rv370_pcie_gart_fini(struct radeon_device *rdev)
@@ -709,16 +701,21 @@ static int r300_packet0_check(struct radeon_cs_parser *p,
709 return r; 701 return r;
710 } 702 }
711 703
712 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 704 if (p->keep_tiling_flags) {
713 tile_flags |= R300_TXO_MACRO_TILE; 705 ib[idx] = (idx_value & 31) | /* keep the 1st 5 bits */
714 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 706 ((idx_value & ~31) + (u32)reloc->lobj.gpu_offset);
715 tile_flags |= R300_TXO_MICRO_TILE; 707 } else {
716 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO_SQUARE) 708 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
717 tile_flags |= R300_TXO_MICRO_TILE_SQUARE; 709 tile_flags |= R300_TXO_MACRO_TILE;
718 710 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
719 tmp = idx_value + ((u32)reloc->lobj.gpu_offset); 711 tile_flags |= R300_TXO_MICRO_TILE;
720 tmp |= tile_flags; 712 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO_SQUARE)
721 ib[idx] = tmp; 713 tile_flags |= R300_TXO_MICRO_TILE_SQUARE;
714
715 tmp = idx_value + ((u32)reloc->lobj.gpu_offset);
716 tmp |= tile_flags;
717 ib[idx] = tmp;
718 }
722 track->textures[i].robj = reloc->robj; 719 track->textures[i].robj = reloc->robj;
723 track->tex_dirty = true; 720 track->tex_dirty = true;
724 break; 721 break;
@@ -768,24 +765,26 @@ static int r300_packet0_check(struct radeon_cs_parser *p,
768 /* RB3D_COLORPITCH1 */ 765 /* RB3D_COLORPITCH1 */
769 /* RB3D_COLORPITCH2 */ 766 /* RB3D_COLORPITCH2 */
770 /* RB3D_COLORPITCH3 */ 767 /* RB3D_COLORPITCH3 */
771 r = r100_cs_packet_next_reloc(p, &reloc); 768 if (!p->keep_tiling_flags) {
772 if (r) { 769 r = r100_cs_packet_next_reloc(p, &reloc);
773 DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 770 if (r) {
774 idx, reg); 771 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
775 r100_cs_dump_packet(p, pkt); 772 idx, reg);
776 return r; 773 r100_cs_dump_packet(p, pkt);
777 } 774 return r;
775 }
778 776
779 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 777 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
780 tile_flags |= R300_COLOR_TILE_ENABLE; 778 tile_flags |= R300_COLOR_TILE_ENABLE;
781 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 779 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
782 tile_flags |= R300_COLOR_MICROTILE_ENABLE; 780 tile_flags |= R300_COLOR_MICROTILE_ENABLE;
783 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO_SQUARE) 781 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO_SQUARE)
784 tile_flags |= R300_COLOR_MICROTILE_SQUARE_ENABLE; 782 tile_flags |= R300_COLOR_MICROTILE_SQUARE_ENABLE;
785 783
786 tmp = idx_value & ~(0x7 << 16); 784 tmp = idx_value & ~(0x7 << 16);
787 tmp |= tile_flags; 785 tmp |= tile_flags;
788 ib[idx] = tmp; 786 ib[idx] = tmp;
787 }
789 i = (reg - 0x4E38) >> 2; 788 i = (reg - 0x4E38) >> 2;
790 track->cb[i].pitch = idx_value & 0x3FFE; 789 track->cb[i].pitch = idx_value & 0x3FFE;
791 switch (((idx_value >> 21) & 0xF)) { 790 switch (((idx_value >> 21) & 0xF)) {
@@ -851,25 +850,26 @@ static int r300_packet0_check(struct radeon_cs_parser *p,
851 break; 850 break;
852 case 0x4F24: 851 case 0x4F24:
853 /* ZB_DEPTHPITCH */ 852 /* ZB_DEPTHPITCH */
854 r = r100_cs_packet_next_reloc(p, &reloc); 853 if (!p->keep_tiling_flags) {
855 if (r) { 854 r = r100_cs_packet_next_reloc(p, &reloc);
856 DRM_ERROR("No reloc for ib[%d]=0x%04X\n", 855 if (r) {
857 idx, reg); 856 DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
858 r100_cs_dump_packet(p, pkt); 857 idx, reg);
859 return r; 858 r100_cs_dump_packet(p, pkt);
860 } 859 return r;
861 860 }
862 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
863 tile_flags |= R300_DEPTHMACROTILE_ENABLE;
864 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
865 tile_flags |= R300_DEPTHMICROTILE_TILED;
866 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO_SQUARE)
867 tile_flags |= R300_DEPTHMICROTILE_TILED_SQUARE;
868 861
869 tmp = idx_value & ~(0x7 << 16); 862 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
870 tmp |= tile_flags; 863 tile_flags |= R300_DEPTHMACROTILE_ENABLE;
871 ib[idx] = tmp; 864 if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
865 tile_flags |= R300_DEPTHMICROTILE_TILED;
866 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO_SQUARE)
867 tile_flags |= R300_DEPTHMICROTILE_TILED_SQUARE;
872 868
869 tmp = idx_value & ~(0x7 << 16);
870 tmp |= tile_flags;
871 ib[idx] = tmp;
872 }
873 track->zb.pitch = idx_value & 0x3FFC; 873 track->zb.pitch = idx_value & 0x3FFC;
874 track->zb_dirty = true; 874 track->zb_dirty = true;
875 break; 875 break;
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 12470b090dd..9cdda0b3b08 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"
@@ -287,24 +288,6 @@ void r600_pm_get_dynpm_state(struct radeon_device *rdev)
287 pcie_lanes); 288 pcie_lanes);
288} 289}
289 290
290static int r600_pm_get_type_index(struct radeon_device *rdev,
291 enum radeon_pm_state_type ps_type,
292 int instance)
293{
294 int i;
295 int found_instance = -1;
296
297 for (i = 0; i < rdev->pm.num_power_states; i++) {
298 if (rdev->pm.power_state[i].type == ps_type) {
299 found_instance++;
300 if (found_instance == instance)
301 return i;
302 }
303 }
304 /* return default if no match */
305 return rdev->pm.default_power_state_index;
306}
307
308void rs780_pm_init_profile(struct radeon_device *rdev) 291void rs780_pm_init_profile(struct radeon_device *rdev)
309{ 292{
310 if (rdev->pm.num_power_states == 2) { 293 if (rdev->pm.num_power_states == 2) {
@@ -420,6 +403,8 @@ void rs780_pm_init_profile(struct radeon_device *rdev)
420 403
421void r600_pm_init_profile(struct radeon_device *rdev) 404void r600_pm_init_profile(struct radeon_device *rdev)
422{ 405{
406 int idx;
407
423 if (rdev->family == CHIP_R600) { 408 if (rdev->family == CHIP_R600) {
424 /* XXX */ 409 /* XXX */
425 /* default */ 410 /* default */
@@ -501,81 +486,43 @@ void r600_pm_init_profile(struct radeon_device *rdev)
501 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0; 486 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
502 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2; 487 rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
503 /* low sh */ 488 /* low sh */
504 if (rdev->flags & RADEON_IS_MOBILITY) { 489 if (rdev->flags & RADEON_IS_MOBILITY)
505 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 490 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
506 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0); 491 else
507 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 492 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
508 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0); 493 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
509 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0; 494 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
510 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0; 495 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
511 } else { 496 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
512 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx =
513 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
514 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx =
515 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
516 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
517 rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
518 }
519 /* mid sh */ 497 /* mid sh */
520 if (rdev->flags & RADEON_IS_MOBILITY) { 498 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
521 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 499 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
522 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0); 500 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
523 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 501 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
524 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
525 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
526 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
527 } else {
528 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx =
529 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
530 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx =
531 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
532 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
533 rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
534 }
535 /* high sh */ 502 /* high sh */
536 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 503 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
537 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0); 504 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
538 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = 505 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
539 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
540 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0; 506 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
541 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2; 507 rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
542 /* low mh */ 508 /* low mh */
543 if (rdev->flags & RADEON_IS_MOBILITY) { 509 if (rdev->flags & RADEON_IS_MOBILITY)
544 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 510 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
545 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1); 511 else
546 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = 512 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
547 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1); 513 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
548 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0; 514 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
549 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0; 515 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
550 } else { 516 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
551 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx =
552 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
553 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx =
554 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
555 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
556 rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
557 }
558 /* mid mh */ 517 /* mid mh */
559 if (rdev->flags & RADEON_IS_MOBILITY) { 518 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
560 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 519 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
561 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1); 520 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
562 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = 521 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
563 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 1);
564 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
565 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
566 } else {
567 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx =
568 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
569 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx =
570 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
571 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
572 rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
573 }
574 /* high mh */ 522 /* high mh */
575 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 523 idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
576 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1); 524 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
577 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = 525 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
578 r600_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 1);
579 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0; 526 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
580 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2; 527 rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
581 } 528 }
@@ -762,13 +709,14 @@ void r600_hpd_init(struct radeon_device *rdev)
762 struct drm_device *dev = rdev->ddev; 709 struct drm_device *dev = rdev->ddev;
763 struct drm_connector *connector; 710 struct drm_connector *connector;
764 711
765 if (ASIC_IS_DCE3(rdev)) { 712 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
766 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa); 713 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
767 if (ASIC_IS_DCE32(rdev)) 714
768 tmp |= DC_HPDx_EN; 715 if (ASIC_IS_DCE3(rdev)) {
716 u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
717 if (ASIC_IS_DCE32(rdev))
718 tmp |= DC_HPDx_EN;
769 719
770 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
771 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
772 switch (radeon_connector->hpd.hpd) { 720 switch (radeon_connector->hpd.hpd) {
773 case RADEON_HPD_1: 721 case RADEON_HPD_1:
774 WREG32(DC_HPD1_CONTROL, tmp); 722 WREG32(DC_HPD1_CONTROL, tmp);
@@ -798,10 +746,7 @@ void r600_hpd_init(struct radeon_device *rdev)
798 default: 746 default:
799 break; 747 break;
800 } 748 }
801 } 749 } else {
802 } else {
803 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
804 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
805 switch (radeon_connector->hpd.hpd) { 750 switch (radeon_connector->hpd.hpd) {
806 case RADEON_HPD_1: 751 case RADEON_HPD_1:
807 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN); 752 WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
@@ -819,6 +764,7 @@ void r600_hpd_init(struct radeon_device *rdev)
819 break; 764 break;
820 } 765 }
821 } 766 }
767 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
822 } 768 }
823 if (rdev->irq.installed) 769 if (rdev->irq.installed)
824 r600_irq_set(rdev); 770 r600_irq_set(rdev);
@@ -896,7 +842,7 @@ void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
896 /* flush hdp cache so updates hit vram */ 842 /* flush hdp cache so updates hit vram */
897 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) && 843 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
898 !(rdev->flags & RADEON_IS_AGP)) { 844 !(rdev->flags & RADEON_IS_AGP)) {
899 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr; 845 void __iomem *ptr = (void *)rdev->gart.ptr;
900 u32 tmp; 846 u32 tmp;
901 847
902 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read 848 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
@@ -931,7 +877,7 @@ int r600_pcie_gart_init(struct radeon_device *rdev)
931{ 877{
932 int r; 878 int r;
933 879
934 if (rdev->gart.table.vram.robj) { 880 if (rdev->gart.robj) {
935 WARN(1, "R600 PCIE GART already initialized\n"); 881 WARN(1, "R600 PCIE GART already initialized\n");
936 return 0; 882 return 0;
937 } 883 }
@@ -948,7 +894,7 @@ int r600_pcie_gart_enable(struct radeon_device *rdev)
948 u32 tmp; 894 u32 tmp;
949 int r, i; 895 int r, i;
950 896
951 if (rdev->gart.table.vram.robj == NULL) { 897 if (rdev->gart.robj == NULL) {
952 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); 898 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
953 return -EINVAL; 899 return -EINVAL;
954 } 900 }
@@ -1003,7 +949,7 @@ int r600_pcie_gart_enable(struct radeon_device *rdev)
1003void r600_pcie_gart_disable(struct radeon_device *rdev) 949void r600_pcie_gart_disable(struct radeon_device *rdev)
1004{ 950{
1005 u32 tmp; 951 u32 tmp;
1006 int i, r; 952 int i;
1007 953
1008 /* Disable all tables */ 954 /* Disable all tables */
1009 for (i = 0; i < 7; i++) 955 for (i = 0; i < 7; i++)
@@ -1030,14 +976,7 @@ void r600_pcie_gart_disable(struct radeon_device *rdev)
1030 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp); 976 WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
1031 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp); 977 WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
1032 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp); 978 WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
1033 if (rdev->gart.table.vram.robj) { 979 radeon_gart_table_vram_unpin(rdev);
1034 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
1035 if (likely(r == 0)) {
1036 radeon_bo_kunmap(rdev->gart.table.vram.robj);
1037 radeon_bo_unpin(rdev->gart.table.vram.robj);
1038 radeon_bo_unreserve(rdev->gart.table.vram.robj);
1039 }
1040 }
1041} 980}
1042 981
1043void r600_pcie_gart_fini(struct radeon_device *rdev) 982void r600_pcie_gart_fini(struct radeon_device *rdev)
@@ -1137,7 +1076,7 @@ static void r600_mc_program(struct radeon_device *rdev)
1137 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12); 1076 WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
1138 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12); 1077 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
1139 } 1078 }
1140 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0); 1079 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
1141 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16; 1080 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
1142 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF); 1081 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
1143 WREG32(MC_VM_FB_LOCATION, tmp); 1082 WREG32(MC_VM_FB_LOCATION, tmp);
@@ -1276,6 +1215,53 @@ int r600_mc_init(struct radeon_device *rdev)
1276 return 0; 1215 return 0;
1277} 1216}
1278 1217
1218int r600_vram_scratch_init(struct radeon_device *rdev)
1219{
1220 int r;
1221
1222 if (rdev->vram_scratch.robj == NULL) {
1223 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
1224 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
1225 &rdev->vram_scratch.robj);
1226 if (r) {
1227 return r;
1228 }
1229 }
1230
1231 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1232 if (unlikely(r != 0))
1233 return r;
1234 r = radeon_bo_pin(rdev->vram_scratch.robj,
1235 RADEON_GEM_DOMAIN_VRAM, &rdev->vram_scratch.gpu_addr);
1236 if (r) {
1237 radeon_bo_unreserve(rdev->vram_scratch.robj);
1238 return r;
1239 }
1240 r = radeon_bo_kmap(rdev->vram_scratch.robj,
1241 (void **)&rdev->vram_scratch.ptr);
1242 if (r)
1243 radeon_bo_unpin(rdev->vram_scratch.robj);
1244 radeon_bo_unreserve(rdev->vram_scratch.robj);
1245
1246 return r;
1247}
1248
1249void r600_vram_scratch_fini(struct radeon_device *rdev)
1250{
1251 int r;
1252
1253 if (rdev->vram_scratch.robj == NULL) {
1254 return;
1255 }
1256 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1257 if (likely(r == 0)) {
1258 radeon_bo_kunmap(rdev->vram_scratch.robj);
1259 radeon_bo_unpin(rdev->vram_scratch.robj);
1260 radeon_bo_unreserve(rdev->vram_scratch.robj);
1261 }
1262 radeon_bo_unref(&rdev->vram_scratch.robj);
1263}
1264
1279/* We doesn't check that the GPU really needs a reset we simply do the 1265/* We doesn't check that the GPU really needs a reset we simply do the
1280 * reset, it's up to the caller to determine if the GPU needs one. We 1266 * reset, it's up to the caller to determine if the GPU needs one. We
1281 * might add an helper function to check that. 1267 * might add an helper function to check that.
@@ -2331,6 +2317,14 @@ void r600_fence_ring_emit(struct radeon_device *rdev,
2331 if (rdev->wb.use_event) { 2317 if (rdev->wb.use_event) {
2332 u64 addr = rdev->wb.gpu_addr + R600_WB_EVENT_OFFSET + 2318 u64 addr = rdev->wb.gpu_addr + R600_WB_EVENT_OFFSET +
2333 (u64)(rdev->fence_drv.scratch_reg - rdev->scratch.reg_base); 2319 (u64)(rdev->fence_drv.scratch_reg - rdev->scratch.reg_base);
2320 /* flush read cache over gart */
2321 radeon_ring_write(rdev, PACKET3(PACKET3_SURFACE_SYNC, 3));
2322 radeon_ring_write(rdev, PACKET3_TC_ACTION_ENA |
2323 PACKET3_VC_ACTION_ENA |
2324 PACKET3_SH_ACTION_ENA);
2325 radeon_ring_write(rdev, 0xFFFFFFFF);
2326 radeon_ring_write(rdev, 0);
2327 radeon_ring_write(rdev, 10); /* poll interval */
2334 /* EVENT_WRITE_EOP - flush caches, send int */ 2328 /* EVENT_WRITE_EOP - flush caches, send int */
2335 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE_EOP, 4)); 2329 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
2336 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5)); 2330 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
@@ -2339,6 +2333,14 @@ void r600_fence_ring_emit(struct radeon_device *rdev,
2339 radeon_ring_write(rdev, fence->seq); 2333 radeon_ring_write(rdev, fence->seq);
2340 radeon_ring_write(rdev, 0); 2334 radeon_ring_write(rdev, 0);
2341 } else { 2335 } else {
2336 /* flush read cache over gart */
2337 radeon_ring_write(rdev, PACKET3(PACKET3_SURFACE_SYNC, 3));
2338 radeon_ring_write(rdev, PACKET3_TC_ACTION_ENA |
2339 PACKET3_VC_ACTION_ENA |
2340 PACKET3_SH_ACTION_ENA);
2341 radeon_ring_write(rdev, 0xFFFFFFFF);
2342 radeon_ring_write(rdev, 0);
2343 radeon_ring_write(rdev, 10); /* poll interval */
2342 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0)); 2344 radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
2343 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0)); 2345 radeon_ring_write(rdev, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0));
2344 /* wait for 3D idle clean */ 2346 /* wait for 3D idle clean */
@@ -2420,6 +2422,10 @@ int r600_startup(struct radeon_device *rdev)
2420 } 2422 }
2421 } 2423 }
2422 2424
2425 r = r600_vram_scratch_init(rdev);
2426 if (r)
2427 return r;
2428
2423 r600_mc_program(rdev); 2429 r600_mc_program(rdev);
2424 if (rdev->flags & RADEON_IS_AGP) { 2430 if (rdev->flags & RADEON_IS_AGP) {
2425 r600_agp_enable(rdev); 2431 r600_agp_enable(rdev);
@@ -2640,6 +2646,7 @@ void r600_fini(struct radeon_device *rdev)
2640 radeon_ib_pool_fini(rdev); 2646 radeon_ib_pool_fini(rdev);
2641 radeon_irq_kms_fini(rdev); 2647 radeon_irq_kms_fini(rdev);
2642 r600_pcie_gart_fini(rdev); 2648 r600_pcie_gart_fini(rdev);
2649 r600_vram_scratch_fini(rdev);
2643 radeon_agp_fini(rdev); 2650 radeon_agp_fini(rdev);
2644 radeon_gem_fini(rdev); 2651 radeon_gem_fini(rdev);
2645 radeon_fence_driver_fini(rdev); 2652 radeon_fence_driver_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/r600_blit_kms.c b/drivers/gpu/drm/radeon/r600_blit_kms.c
index c4cf1308d4a..e09d2818f94 100644
--- a/drivers/gpu/drm/radeon/r600_blit_kms.c
+++ b/drivers/gpu/drm/radeon/r600_blit_kms.c
@@ -201,7 +201,7 @@ set_vtx_resource(struct radeon_device *rdev, u64 gpu_addr)
201static void 201static void
202set_tex_resource(struct radeon_device *rdev, 202set_tex_resource(struct radeon_device *rdev,
203 int format, int w, int h, int pitch, 203 int format, int w, int h, int pitch,
204 u64 gpu_addr) 204 u64 gpu_addr, u32 size)
205{ 205{
206 uint32_t sq_tex_resource_word0, sq_tex_resource_word1, sq_tex_resource_word4; 206 uint32_t sq_tex_resource_word0, sq_tex_resource_word1, sq_tex_resource_word4;
207 207
@@ -222,6 +222,9 @@ set_tex_resource(struct radeon_device *rdev,
222 S_038010_DST_SEL_Z(SQ_SEL_Z) | 222 S_038010_DST_SEL_Z(SQ_SEL_Z) |
223 S_038010_DST_SEL_W(SQ_SEL_W); 223 S_038010_DST_SEL_W(SQ_SEL_W);
224 224
225 cp_set_surface_sync(rdev,
226 PACKET3_TC_ACTION_ENA, size, gpu_addr);
227
225 radeon_ring_write(rdev, PACKET3(PACKET3_SET_RESOURCE, 7)); 228 radeon_ring_write(rdev, PACKET3(PACKET3_SET_RESOURCE, 7));
226 radeon_ring_write(rdev, 0); 229 radeon_ring_write(rdev, 0);
227 radeon_ring_write(rdev, sq_tex_resource_word0); 230 radeon_ring_write(rdev, sq_tex_resource_word0);
@@ -500,9 +503,9 @@ int r600_blit_init(struct radeon_device *rdev)
500 rdev->r600_blit.primitives.set_default_state = set_default_state; 503 rdev->r600_blit.primitives.set_default_state = set_default_state;
501 504
502 rdev->r600_blit.ring_size_common = 40; /* shaders + def state */ 505 rdev->r600_blit.ring_size_common = 40; /* shaders + def state */
503 rdev->r600_blit.ring_size_common += 10; /* fence emit for VB IB */ 506 rdev->r600_blit.ring_size_common += 16; /* fence emit for VB IB */
504 rdev->r600_blit.ring_size_common += 5; /* done copy */ 507 rdev->r600_blit.ring_size_common += 5; /* done copy */
505 rdev->r600_blit.ring_size_common += 10; /* fence emit for done copy */ 508 rdev->r600_blit.ring_size_common += 16; /* fence emit for done copy */
506 509
507 rdev->r600_blit.ring_size_per_loop = 76; 510 rdev->r600_blit.ring_size_per_loop = 76;
508 /* set_render_target emits 2 extra dwords on rv6xx */ 511 /* set_render_target emits 2 extra dwords on rv6xx */
@@ -760,10 +763,7 @@ void r600_kms_blit_copy(struct radeon_device *rdev,
760 vb[11] = i2f(h); 763 vb[11] = i2f(h);
761 764
762 rdev->r600_blit.primitives.set_tex_resource(rdev, FMT_8_8_8_8, 765 rdev->r600_blit.primitives.set_tex_resource(rdev, FMT_8_8_8_8,
763 w, h, w, src_gpu_addr); 766 w, h, w, src_gpu_addr, size_in_bytes);
764 rdev->r600_blit.primitives.cp_set_surface_sync(rdev,
765 PACKET3_TC_ACTION_ENA,
766 size_in_bytes, src_gpu_addr);
767 rdev->r600_blit.primitives.set_render_target(rdev, COLOR_8_8_8_8, 767 rdev->r600_blit.primitives.set_render_target(rdev, COLOR_8_8_8_8,
768 w, h, dst_gpu_addr); 768 w, h, dst_gpu_addr);
769 rdev->r600_blit.primitives.set_scissors(rdev, 0, 0, w, h); 769 rdev->r600_blit.primitives.set_scissors(rdev, 0, 0, w, h);
diff --git a/drivers/gpu/drm/radeon/r600_cp.c b/drivers/gpu/drm/radeon/r600_cp.c
index 45fd592f960..c9db4931913 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/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index 0a2e023c155..cb1acffd243 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -941,7 +941,8 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
941 track->db_depth_control = radeon_get_ib_value(p, idx); 941 track->db_depth_control = radeon_get_ib_value(p, idx);
942 break; 942 break;
943 case R_028010_DB_DEPTH_INFO: 943 case R_028010_DB_DEPTH_INFO:
944 if (r600_cs_packet_next_is_pkt3_nop(p)) { 944 if (!p->keep_tiling_flags &&
945 r600_cs_packet_next_is_pkt3_nop(p)) {
945 r = r600_cs_packet_next_reloc(p, &reloc); 946 r = r600_cs_packet_next_reloc(p, &reloc);
946 if (r) { 947 if (r) {
947 dev_warn(p->dev, "bad SET_CONTEXT_REG " 948 dev_warn(p->dev, "bad SET_CONTEXT_REG "
@@ -992,7 +993,8 @@ static int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx)
992 case R_0280B4_CB_COLOR5_INFO: 993 case R_0280B4_CB_COLOR5_INFO:
993 case R_0280B8_CB_COLOR6_INFO: 994 case R_0280B8_CB_COLOR6_INFO:
994 case R_0280BC_CB_COLOR7_INFO: 995 case R_0280BC_CB_COLOR7_INFO:
995 if (r600_cs_packet_next_is_pkt3_nop(p)) { 996 if (!p->keep_tiling_flags &&
997 r600_cs_packet_next_is_pkt3_nop(p)) {
996 r = r600_cs_packet_next_reloc(p, &reloc); 998 r = r600_cs_packet_next_reloc(p, &reloc);
997 if (r) { 999 if (r) {
998 dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg); 1000 dev_err(p->dev, "bad SET_CONTEXT_REG 0x%04X\n", reg);
@@ -1291,10 +1293,12 @@ static int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
1291 mip_offset <<= 8; 1293 mip_offset <<= 8;
1292 1294
1293 word0 = radeon_get_ib_value(p, idx + 0); 1295 word0 = radeon_get_ib_value(p, idx + 0);
1294 if (tiling_flags & RADEON_TILING_MACRO) 1296 if (!p->keep_tiling_flags) {
1295 word0 |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1); 1297 if (tiling_flags & RADEON_TILING_MACRO)
1296 else if (tiling_flags & RADEON_TILING_MICRO) 1298 word0 |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1);
1297 word0 |= S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1); 1299 else if (tiling_flags & RADEON_TILING_MICRO)
1300 word0 |= S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1);
1301 }
1298 word1 = radeon_get_ib_value(p, idx + 1); 1302 word1 = radeon_get_ib_value(p, idx + 1);
1299 w0 = G_038000_TEX_WIDTH(word0) + 1; 1303 w0 = G_038000_TEX_WIDTH(word0) + 1;
1300 h0 = G_038004_TEX_HEIGHT(word1) + 1; 1304 h0 = G_038004_TEX_HEIGHT(word1) + 1;
@@ -1621,10 +1625,12 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1621 return -EINVAL; 1625 return -EINVAL;
1622 } 1626 }
1623 base_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1627 base_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1624 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 1628 if (!p->keep_tiling_flags) {
1625 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1); 1629 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
1626 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 1630 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1);
1627 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1); 1631 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
1632 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_1D_TILED_THIN1);
1633 }
1628 texture = reloc->robj; 1634 texture = reloc->robj;
1629 /* tex mip base */ 1635 /* tex mip base */
1630 r = r600_cs_packet_next_reloc(p, &reloc); 1636 r = r600_cs_packet_next_reloc(p, &reloc);
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index e3170c794c1..8227e76b5c7 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -93,6 +93,7 @@ extern int radeon_audio;
93extern int radeon_disp_priority; 93extern int radeon_disp_priority;
94extern int radeon_hw_i2c; 94extern int radeon_hw_i2c;
95extern int radeon_pcie_gen2; 95extern int radeon_pcie_gen2;
96extern int radeon_msi;
96 97
97/* 98/*
98 * Copy from radeon_drv.h so we don't have to include both and have conflicting 99 * Copy from radeon_drv.h so we don't have to include both and have conflicting
@@ -306,30 +307,17 @@ int radeon_mode_dumb_destroy(struct drm_file *file_priv,
306 */ 307 */
307struct radeon_mc; 308struct radeon_mc;
308 309
309struct radeon_gart_table_ram {
310 volatile uint32_t *ptr;
311};
312
313struct radeon_gart_table_vram {
314 struct radeon_bo *robj;
315 volatile uint32_t *ptr;
316};
317
318union radeon_gart_table {
319 struct radeon_gart_table_ram ram;
320 struct radeon_gart_table_vram vram;
321};
322
323#define RADEON_GPU_PAGE_SIZE 4096 310#define RADEON_GPU_PAGE_SIZE 4096
324#define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1) 311#define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
325#define RADEON_GPU_PAGE_SHIFT 12 312#define RADEON_GPU_PAGE_SHIFT 12
326 313
327struct radeon_gart { 314struct radeon_gart {
328 dma_addr_t table_addr; 315 dma_addr_t table_addr;
316 struct radeon_bo *robj;
317 void *ptr;
329 unsigned num_gpu_pages; 318 unsigned num_gpu_pages;
330 unsigned num_cpu_pages; 319 unsigned num_cpu_pages;
331 unsigned table_size; 320 unsigned table_size;
332 union radeon_gart_table table;
333 struct page **pages; 321 struct page **pages;
334 dma_addr_t *pages_addr; 322 dma_addr_t *pages_addr;
335 bool *ttm_alloced; 323 bool *ttm_alloced;
@@ -340,6 +328,8 @@ int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
340void radeon_gart_table_ram_free(struct radeon_device *rdev); 328void radeon_gart_table_ram_free(struct radeon_device *rdev);
341int radeon_gart_table_vram_alloc(struct radeon_device *rdev); 329int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
342void radeon_gart_table_vram_free(struct radeon_device *rdev); 330void radeon_gart_table_vram_free(struct radeon_device *rdev);
331int radeon_gart_table_vram_pin(struct radeon_device *rdev);
332void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
343int radeon_gart_init(struct radeon_device *rdev); 333int radeon_gart_init(struct radeon_device *rdev);
344void radeon_gart_fini(struct radeon_device *rdev); 334void radeon_gart_fini(struct radeon_device *rdev);
345void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset, 335void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
@@ -347,6 +337,7 @@ void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
347int radeon_gart_bind(struct radeon_device *rdev, unsigned offset, 337int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
348 int pages, struct page **pagelist, 338 int pages, struct page **pagelist,
349 dma_addr_t *dma_addr); 339 dma_addr_t *dma_addr);
340void radeon_gart_restore(struct radeon_device *rdev);
350 341
351 342
352/* 343/*
@@ -437,25 +428,26 @@ union radeon_irq_stat_regs {
437 struct evergreen_irq_stat_regs evergreen; 428 struct evergreen_irq_stat_regs evergreen;
438}; 429};
439 430
431#define RADEON_MAX_HPD_PINS 6
432#define RADEON_MAX_CRTCS 6
433#define RADEON_MAX_HDMI_BLOCKS 2
434
440struct radeon_irq { 435struct radeon_irq {
441 bool installed; 436 bool installed;
442 bool sw_int; 437 bool sw_int;
443 /* FIXME: use a define max crtc rather than hardcode it */ 438 bool crtc_vblank_int[RADEON_MAX_CRTCS];
444 bool crtc_vblank_int[6]; 439 bool pflip[RADEON_MAX_CRTCS];
445 bool pflip[6];
446 wait_queue_head_t vblank_queue; 440 wait_queue_head_t vblank_queue;
447 /* FIXME: use defines for max hpd/dacs */ 441 bool hpd[RADEON_MAX_HPD_PINS];
448 bool hpd[6];
449 bool gui_idle; 442 bool gui_idle;
450 bool gui_idle_acked; 443 bool gui_idle_acked;
451 wait_queue_head_t idle_queue; 444 wait_queue_head_t idle_queue;
452 /* FIXME: use defines for max HDMI blocks */ 445 bool hdmi[RADEON_MAX_HDMI_BLOCKS];
453 bool hdmi[2];
454 spinlock_t sw_lock; 446 spinlock_t sw_lock;
455 int sw_refcount; 447 int sw_refcount;
456 union radeon_irq_stat_regs stat_regs; 448 union radeon_irq_stat_regs stat_regs;
457 spinlock_t pflip_lock[6]; 449 spinlock_t pflip_lock[RADEON_MAX_CRTCS];
458 int pflip_refcount[6]; 450 int pflip_refcount[RADEON_MAX_CRTCS];
459}; 451};
460 452
461int radeon_irq_kms_init(struct radeon_device *rdev); 453int radeon_irq_kms_init(struct radeon_device *rdev);
@@ -533,7 +525,7 @@ struct r600_blit_cp_primitives {
533 void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr); 525 void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
534 void (*set_tex_resource)(struct radeon_device *rdev, 526 void (*set_tex_resource)(struct radeon_device *rdev,
535 int format, int w, int h, int pitch, 527 int format, int w, int h, int pitch,
536 u64 gpu_addr); 528 u64 gpu_addr, u32 size);
537 void (*set_scissors)(struct radeon_device *rdev, int x1, int y1, 529 void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
538 int x2, int y2); 530 int x2, int y2);
539 void (*draw_auto)(struct radeon_device *rdev); 531 void (*draw_auto)(struct radeon_device *rdev);
@@ -619,7 +611,8 @@ struct radeon_cs_parser {
619 struct radeon_ib *ib; 611 struct radeon_ib *ib;
620 void *track; 612 void *track;
621 unsigned family; 613 unsigned family;
622 int parser_error; 614 int parser_error;
615 bool keep_tiling_flags;
623}; 616};
624 617
625extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx); 618extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
@@ -792,8 +785,7 @@ struct radeon_pm_clock_info {
792 785
793struct radeon_power_state { 786struct radeon_power_state {
794 enum radeon_pm_state_type type; 787 enum radeon_pm_state_type type;
795 /* XXX: use a define for num clock modes */ 788 struct radeon_pm_clock_info *clock_info;
796 struct radeon_pm_clock_info clock_info[8];
797 /* number of valid clock modes in this power state */ 789 /* number of valid clock modes in this power state */
798 int num_clock_modes; 790 int num_clock_modes;
799 struct radeon_pm_clock_info *default_clock_mode; 791 struct radeon_pm_clock_info *default_clock_mode;
@@ -863,6 +855,9 @@ struct radeon_pm {
863 struct device *int_hwmon_dev; 855 struct device *int_hwmon_dev;
864}; 856};
865 857
858int radeon_pm_get_type_index(struct radeon_device *rdev,
859 enum radeon_pm_state_type ps_type,
860 int instance);
866 861
867/* 862/*
868 * Benchmarking 863 * Benchmarking
@@ -1143,12 +1138,55 @@ int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
1143int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data, 1138int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
1144 struct drm_file *filp); 1139 struct drm_file *filp);
1145 1140
1146/* VRAM scratch page for HDP bug */ 1141/* VRAM scratch page for HDP bug, default vram page */
1147struct r700_vram_scratch { 1142struct r600_vram_scratch {
1148 struct radeon_bo *robj; 1143 struct radeon_bo *robj;
1149 volatile uint32_t *ptr; 1144 volatile uint32_t *ptr;
1145 u64 gpu_addr;
1150}; 1146};
1151 1147
1148
1149/*
1150 * Mutex which allows recursive locking from the same process.
1151 */
1152struct radeon_mutex {
1153 struct mutex mutex;
1154 struct task_struct *owner;
1155 int level;
1156};
1157
1158static inline void radeon_mutex_init(struct radeon_mutex *mutex)
1159{
1160 mutex_init(&mutex->mutex);
1161 mutex->owner = NULL;
1162 mutex->level = 0;
1163}
1164
1165static inline void radeon_mutex_lock(struct radeon_mutex *mutex)
1166{
1167 if (mutex_trylock(&mutex->mutex)) {
1168 /* The mutex was unlocked before, so it's ours now */
1169 mutex->owner = current;
1170 } else if (mutex->owner != current) {
1171 /* Another process locked the mutex, take it */
1172 mutex_lock(&mutex->mutex);
1173 mutex->owner = current;
1174 }
1175 /* Otherwise the mutex was already locked by this process */
1176
1177 mutex->level++;
1178}
1179
1180static inline void radeon_mutex_unlock(struct radeon_mutex *mutex)
1181{
1182 if (--mutex->level > 0)
1183 return;
1184
1185 mutex->owner = NULL;
1186 mutex_unlock(&mutex->mutex);
1187}
1188
1189
1152/* 1190/*
1153 * Core structure, functions and helpers. 1191 * Core structure, functions and helpers.
1154 */ 1192 */
@@ -1204,7 +1242,7 @@ struct radeon_device {
1204 struct radeon_gem gem; 1242 struct radeon_gem gem;
1205 struct radeon_pm pm; 1243 struct radeon_pm pm;
1206 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH]; 1244 uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
1207 struct mutex cs_mutex; 1245 struct radeon_mutex cs_mutex;
1208 struct radeon_wb wb; 1246 struct radeon_wb wb;
1209 struct radeon_dummy_page dummy_page; 1247 struct radeon_dummy_page dummy_page;
1210 bool gpu_lockup; 1248 bool gpu_lockup;
@@ -1218,7 +1256,7 @@ struct radeon_device {
1218 const struct firmware *rlc_fw; /* r6/700 RLC firmware */ 1256 const struct firmware *rlc_fw; /* r6/700 RLC firmware */
1219 const struct firmware *mc_fw; /* NI MC firmware */ 1257 const struct firmware *mc_fw; /* NI MC firmware */
1220 struct r600_blit r600_blit; 1258 struct r600_blit r600_blit;
1221 struct r700_vram_scratch vram_scratch; 1259 struct r600_vram_scratch vram_scratch;
1222 int msi_enabled; /* msi enabled */ 1260 int msi_enabled; /* msi enabled */
1223 struct r600_ih ih; /* r6/700 interrupt ring */ 1261 struct r600_ih ih; /* r6/700 interrupt ring */
1224 struct work_struct hotplug_work; 1262 struct work_struct hotplug_work;
@@ -1442,8 +1480,6 @@ void radeon_ring_write(struct radeon_device *rdev, uint32_t v);
1442/* AGP */ 1480/* AGP */
1443extern int radeon_gpu_reset(struct radeon_device *rdev); 1481extern int radeon_gpu_reset(struct radeon_device *rdev);
1444extern void radeon_agp_disable(struct radeon_device *rdev); 1482extern void radeon_agp_disable(struct radeon_device *rdev);
1445extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
1446extern void radeon_gart_restore(struct radeon_device *rdev);
1447extern int radeon_modeset_init(struct radeon_device *rdev); 1483extern int radeon_modeset_init(struct radeon_device *rdev);
1448extern void radeon_modeset_fini(struct radeon_device *rdev); 1484extern void radeon_modeset_fini(struct radeon_device *rdev);
1449extern bool radeon_card_posted(struct radeon_device *rdev); 1485extern bool radeon_card_posted(struct radeon_device *rdev);
@@ -1467,6 +1503,12 @@ extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
1467extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size); 1503extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
1468 1504
1469/* 1505/*
1506 * R600 vram scratch functions
1507 */
1508int r600_vram_scratch_init(struct radeon_device *rdev);
1509void r600_vram_scratch_fini(struct radeon_device *rdev);
1510
1511/*
1470 * r600 functions used by radeon_encoder.c 1512 * r600 functions used by radeon_encoder.c
1471 */ 1513 */
1472extern void r600_hdmi_enable(struct drm_encoder *encoder); 1514extern void r600_hdmi_enable(struct drm_encoder *encoder);
diff --git a/drivers/gpu/drm/radeon/radeon_acpi.c b/drivers/gpu/drm/radeon/radeon_acpi.c
index 3f6636bb2d7..3516a6081dc 100644
--- a/drivers/gpu/drm/radeon/radeon_acpi.c
+++ b/drivers/gpu/drm/radeon/radeon_acpi.c
@@ -35,7 +35,8 @@ static int radeon_atif_call(acpi_handle handle)
35 35
36 /* Fail only if calling the method fails and ATIF is supported */ 36 /* Fail only if calling the method fails and ATIF is supported */
37 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 37 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
38 printk(KERN_DEBUG "failed to evaluate ATIF got %s\n", acpi_format_exception(status)); 38 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
39 acpi_format_exception(status));
39 kfree(buffer.pointer); 40 kfree(buffer.pointer);
40 return 1; 41 return 1;
41 } 42 }
@@ -50,13 +51,13 @@ int radeon_acpi_init(struct radeon_device *rdev)
50 acpi_handle handle; 51 acpi_handle handle;
51 int ret; 52 int ret;
52 53
53 /* No need to proceed if we're sure that ATIF is not supported */
54 if (!ASIC_IS_AVIVO(rdev) || !rdev->bios)
55 return 0;
56
57 /* Get the device handle */ 54 /* Get the device handle */
58 handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev); 55 handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
59 56
57 /* No need to proceed if we're sure that ATIF is not supported */
58 if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle)
59 return 0;
60
60 /* Call the ATIF method */ 61 /* Call the ATIF method */
61 ret = radeon_atif_call(handle); 62 ret = radeon_atif_call(handle);
62 if (ret) 63 if (ret)
diff --git a/drivers/gpu/drm/radeon/radeon_asic.c b/drivers/gpu/drm/radeon/radeon_asic.c
index e2944566ffe..a2e1eae114e 100644
--- a/drivers/gpu/drm/radeon/radeon_asic.c
+++ b/drivers/gpu/drm/radeon/radeon_asic.c
@@ -834,7 +834,7 @@ static struct radeon_asic sumo_asic = {
834 .pm_misc = &evergreen_pm_misc, 834 .pm_misc = &evergreen_pm_misc,
835 .pm_prepare = &evergreen_pm_prepare, 835 .pm_prepare = &evergreen_pm_prepare,
836 .pm_finish = &evergreen_pm_finish, 836 .pm_finish = &evergreen_pm_finish,
837 .pm_init_profile = &rs780_pm_init_profile, 837 .pm_init_profile = &sumo_pm_init_profile,
838 .pm_get_dynpm_state = &r600_pm_get_dynpm_state, 838 .pm_get_dynpm_state = &r600_pm_get_dynpm_state,
839 .pre_page_flip = &evergreen_pre_page_flip, 839 .pre_page_flip = &evergreen_pre_page_flip,
840 .page_flip = &evergreen_page_flip, 840 .page_flip = &evergreen_page_flip,
diff --git a/drivers/gpu/drm/radeon/radeon_asic.h b/drivers/gpu/drm/radeon/radeon_asic.h
index 85f14f0337e..59914842a72 100644
--- a/drivers/gpu/drm/radeon/radeon_asic.h
+++ b/drivers/gpu/drm/radeon/radeon_asic.h
@@ -413,6 +413,7 @@ extern int evergreen_cs_parse(struct radeon_cs_parser *p);
413extern void evergreen_pm_misc(struct radeon_device *rdev); 413extern void evergreen_pm_misc(struct radeon_device *rdev);
414extern void evergreen_pm_prepare(struct radeon_device *rdev); 414extern void evergreen_pm_prepare(struct radeon_device *rdev);
415extern void evergreen_pm_finish(struct radeon_device *rdev); 415extern void evergreen_pm_finish(struct radeon_device *rdev);
416extern void sumo_pm_init_profile(struct radeon_device *rdev);
416extern void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc); 417extern void evergreen_pre_page_flip(struct radeon_device *rdev, int crtc);
417extern u32 evergreen_page_flip(struct radeon_device *rdev, int crtc, u64 crtc_base); 418extern u32 evergreen_page_flip(struct radeon_device *rdev, int crtc, u64 crtc_base);
418extern void evergreen_post_page_flip(struct radeon_device *rdev, int crtc); 419extern void evergreen_post_page_flip(struct radeon_device *rdev, int crtc);
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 08d0b94332e..d24baf30efc 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -62,6 +62,87 @@ union atom_supported_devices {
62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1; 62 struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
63}; 63};
64 64
65static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
66 ATOM_GPIO_I2C_ASSIGMENT *gpio,
67 u8 index)
68{
69 /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
70 if ((rdev->family == CHIP_R420) ||
71 (rdev->family == CHIP_R423) ||
72 (rdev->family == CHIP_RV410)) {
73 if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
74 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
75 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
76 gpio->ucClkMaskShift = 0x19;
77 gpio->ucDataMaskShift = 0x18;
78 }
79 }
80
81 /* some evergreen boards have bad data for this entry */
82 if (ASIC_IS_DCE4(rdev)) {
83 if ((index == 7) &&
84 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
85 (gpio->sucI2cId.ucAccess == 0)) {
86 gpio->sucI2cId.ucAccess = 0x97;
87 gpio->ucDataMaskShift = 8;
88 gpio->ucDataEnShift = 8;
89 gpio->ucDataY_Shift = 8;
90 gpio->ucDataA_Shift = 8;
91 }
92 }
93
94 /* some DCE3 boards have bad data for this entry */
95 if (ASIC_IS_DCE3(rdev)) {
96 if ((index == 4) &&
97 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
98 (gpio->sucI2cId.ucAccess == 0x94))
99 gpio->sucI2cId.ucAccess = 0x14;
100 }
101}
102
103static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
104{
105 struct radeon_i2c_bus_rec i2c;
106
107 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
108
109 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
110 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
111 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
112 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
113 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
114 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
115 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
116 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
117 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
118 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
119 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
120 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
121 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
122 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
123 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
124 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
125
126 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
127 i2c.hw_capable = true;
128 else
129 i2c.hw_capable = false;
130
131 if (gpio->sucI2cId.ucAccess == 0xa0)
132 i2c.mm_i2c = true;
133 else
134 i2c.mm_i2c = false;
135
136 i2c.i2c_id = gpio->sucI2cId.ucAccess;
137
138 if (i2c.mask_clk_reg)
139 i2c.valid = true;
140 else
141 i2c.valid = false;
142
143 return i2c;
144}
145
65static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev, 146static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
66 uint8_t id) 147 uint8_t id)
67{ 148{
@@ -85,59 +166,10 @@ static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rd
85 for (i = 0; i < num_indices; i++) { 166 for (i = 0; i < num_indices; i++) {
86 gpio = &i2c_info->asGPIO_Info[i]; 167 gpio = &i2c_info->asGPIO_Info[i];
87 168
88 /* some evergreen boards have bad data for this entry */ 169 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
89 if (ASIC_IS_DCE4(rdev)) {
90 if ((i == 7) &&
91 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
92 (gpio->sucI2cId.ucAccess == 0)) {
93 gpio->sucI2cId.ucAccess = 0x97;
94 gpio->ucDataMaskShift = 8;
95 gpio->ucDataEnShift = 8;
96 gpio->ucDataY_Shift = 8;
97 gpio->ucDataA_Shift = 8;
98 }
99 }
100
101 /* some DCE3 boards have bad data for this entry */
102 if (ASIC_IS_DCE3(rdev)) {
103 if ((i == 4) &&
104 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
105 (gpio->sucI2cId.ucAccess == 0x94))
106 gpio->sucI2cId.ucAccess = 0x14;
107 }
108 170
109 if (gpio->sucI2cId.ucAccess == id) { 171 if (gpio->sucI2cId.ucAccess == id) {
110 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4; 172 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
111 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
112 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
113 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
114 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
115 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
116 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
117 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
118 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
119 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
120 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
121 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
122 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
123 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
124 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
125 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
126
127 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
128 i2c.hw_capable = true;
129 else
130 i2c.hw_capable = false;
131
132 if (gpio->sucI2cId.ucAccess == 0xa0)
133 i2c.mm_i2c = true;
134 else
135 i2c.mm_i2c = false;
136
137 i2c.i2c_id = gpio->sucI2cId.ucAccess;
138
139 if (i2c.mask_clk_reg)
140 i2c.valid = true;
141 break; 173 break;
142 } 174 }
143 } 175 }
@@ -157,8 +189,6 @@ void radeon_atombios_i2c_init(struct radeon_device *rdev)
157 int i, num_indices; 189 int i, num_indices;
158 char stmp[32]; 190 char stmp[32];
159 191
160 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
161
162 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) { 192 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
163 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); 193 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
164 194
@@ -167,60 +197,12 @@ void radeon_atombios_i2c_init(struct radeon_device *rdev)
167 197
168 for (i = 0; i < num_indices; i++) { 198 for (i = 0; i < num_indices; i++) {
169 gpio = &i2c_info->asGPIO_Info[i]; 199 gpio = &i2c_info->asGPIO_Info[i];
170 i2c.valid = false;
171
172 /* some evergreen boards have bad data for this entry */
173 if (ASIC_IS_DCE4(rdev)) {
174 if ((i == 7) &&
175 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
176 (gpio->sucI2cId.ucAccess == 0)) {
177 gpio->sucI2cId.ucAccess = 0x97;
178 gpio->ucDataMaskShift = 8;
179 gpio->ucDataEnShift = 8;
180 gpio->ucDataY_Shift = 8;
181 gpio->ucDataA_Shift = 8;
182 }
183 }
184 200
185 /* some DCE3 boards have bad data for this entry */ 201 radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
186 if (ASIC_IS_DCE3(rdev)) {
187 if ((i == 4) &&
188 (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
189 (gpio->sucI2cId.ucAccess == 0x94))
190 gpio->sucI2cId.ucAccess = 0x14;
191 }
192 202
193 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4; 203 i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
194 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
195 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
196 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
197 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
198 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
199 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
200 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
201 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
202 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
203 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
204 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
205 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
206 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
207 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
208 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
209
210 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
211 i2c.hw_capable = true;
212 else
213 i2c.hw_capable = false;
214
215 if (gpio->sucI2cId.ucAccess == 0xa0)
216 i2c.mm_i2c = true;
217 else
218 i2c.mm_i2c = false;
219 204
220 i2c.i2c_id = gpio->sucI2cId.ucAccess; 205 if (i2c.valid) {
221
222 if (i2c.mask_clk_reg) {
223 i2c.valid = true;
224 sprintf(stmp, "0x%x", i2c.i2c_id); 206 sprintf(stmp, "0x%x", i2c.i2c_id);
225 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp); 207 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
226 } 208 }
@@ -1996,10 +1978,14 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
1996 return state_index; 1978 return state_index;
1997 /* last mode is usually default, array is low to high */ 1979 /* last mode is usually default, array is low to high */
1998 for (i = 0; i < num_modes; i++) { 1980 for (i = 0; i < num_modes; i++) {
1981 rdev->pm.power_state[state_index].clock_info =
1982 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
1983 if (!rdev->pm.power_state[state_index].clock_info)
1984 return state_index;
1985 rdev->pm.power_state[state_index].num_clock_modes = 1;
1999 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE; 1986 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2000 switch (frev) { 1987 switch (frev) {
2001 case 1: 1988 case 1:
2002 rdev->pm.power_state[state_index].num_clock_modes = 1;
2003 rdev->pm.power_state[state_index].clock_info[0].mclk = 1989 rdev->pm.power_state[state_index].clock_info[0].mclk =
2004 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock); 1990 le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2005 rdev->pm.power_state[state_index].clock_info[0].sclk = 1991 rdev->pm.power_state[state_index].clock_info[0].sclk =
@@ -2035,7 +2021,6 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
2035 state_index++; 2021 state_index++;
2036 break; 2022 break;
2037 case 2: 2023 case 2:
2038 rdev->pm.power_state[state_index].num_clock_modes = 1;
2039 rdev->pm.power_state[state_index].clock_info[0].mclk = 2024 rdev->pm.power_state[state_index].clock_info[0].mclk =
2040 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock); 2025 le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2041 rdev->pm.power_state[state_index].clock_info[0].sclk = 2026 rdev->pm.power_state[state_index].clock_info[0].sclk =
@@ -2072,7 +2057,6 @@ static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
2072 state_index++; 2057 state_index++;
2073 break; 2058 break;
2074 case 3: 2059 case 3:
2075 rdev->pm.power_state[state_index].num_clock_modes = 1;
2076 rdev->pm.power_state[state_index].clock_info[0].mclk = 2060 rdev->pm.power_state[state_index].clock_info[0].mclk =
2077 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock); 2061 le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2078 rdev->pm.power_state[state_index].clock_info[0].sclk = 2062 rdev->pm.power_state[state_index].clock_info[0].sclk =
@@ -2257,7 +2241,7 @@ static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rde
2257 rdev->pm.default_power_state_index = state_index; 2241 rdev->pm.default_power_state_index = state_index;
2258 rdev->pm.power_state[state_index].default_clock_mode = 2242 rdev->pm.power_state[state_index].default_clock_mode =
2259 &rdev->pm.power_state[state_index].clock_info[mode_index - 1]; 2243 &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2260 if (ASIC_IS_DCE5(rdev)) { 2244 if (ASIC_IS_DCE5(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
2261 /* NI chips post without MC ucode, so default clocks are strobe mode only */ 2245 /* NI chips post without MC ucode, so default clocks are strobe mode only */
2262 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk; 2246 rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2263 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk; 2247 rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
@@ -2377,17 +2361,31 @@ static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
2377 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) + 2361 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2378 (power_state->v1.ucNonClockStateIndex * 2362 (power_state->v1.ucNonClockStateIndex *
2379 power_info->pplib.ucNonClockSize)); 2363 power_info->pplib.ucNonClockSize));
2380 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) { 2364 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2381 clock_info = (union pplib_clock_info *) 2365 ((power_info->pplib.ucStateEntrySize - 1) ?
2382 (mode_info->atom_context->bios + data_offset + 2366 (power_info->pplib.ucStateEntrySize - 1) : 1),
2383 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) + 2367 GFP_KERNEL);
2384 (power_state->v1.ucClockStateIndices[j] * 2368 if (!rdev->pm.power_state[i].clock_info)
2385 power_info->pplib.ucClockInfoSize)); 2369 return state_index;
2386 valid = radeon_atombios_parse_pplib_clock_info(rdev, 2370 if (power_info->pplib.ucStateEntrySize - 1) {
2387 state_index, mode_index, 2371 for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2388 clock_info); 2372 clock_info = (union pplib_clock_info *)
2389 if (valid) 2373 (mode_info->atom_context->bios + data_offset +
2390 mode_index++; 2374 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2375 (power_state->v1.ucClockStateIndices[j] *
2376 power_info->pplib.ucClockInfoSize));
2377 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2378 state_index, mode_index,
2379 clock_info);
2380 if (valid)
2381 mode_index++;
2382 }
2383 } else {
2384 rdev->pm.power_state[state_index].clock_info[0].mclk =
2385 rdev->clock.default_mclk;
2386 rdev->pm.power_state[state_index].clock_info[0].sclk =
2387 rdev->clock.default_sclk;
2388 mode_index++;
2391 } 2389 }
2392 rdev->pm.power_state[state_index].num_clock_modes = mode_index; 2390 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2393 if (mode_index) { 2391 if (mode_index) {
@@ -2456,18 +2454,32 @@ static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
2456 non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */ 2454 non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2457 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) 2455 non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2458 &non_clock_info_array->nonClockInfo[non_clock_array_index]; 2456 &non_clock_info_array->nonClockInfo[non_clock_array_index];
2459 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) { 2457 rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
2460 clock_array_index = power_state->v2.clockInfoIndex[j]; 2458 (power_state->v2.ucNumDPMLevels ?
2461 /* XXX this might be an inagua bug... */ 2459 power_state->v2.ucNumDPMLevels : 1),
2462 if (clock_array_index >= clock_info_array->ucNumEntries) 2460 GFP_KERNEL);
2463 continue; 2461 if (!rdev->pm.power_state[i].clock_info)
2464 clock_info = (union pplib_clock_info *) 2462 return state_index;
2465 &clock_info_array->clockInfo[clock_array_index]; 2463 if (power_state->v2.ucNumDPMLevels) {
2466 valid = radeon_atombios_parse_pplib_clock_info(rdev, 2464 for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2467 state_index, mode_index, 2465 clock_array_index = power_state->v2.clockInfoIndex[j];
2468 clock_info); 2466 /* XXX this might be an inagua bug... */
2469 if (valid) 2467 if (clock_array_index >= clock_info_array->ucNumEntries)
2470 mode_index++; 2468 continue;
2469 clock_info = (union pplib_clock_info *)
2470 &clock_info_array->clockInfo[clock_array_index];
2471 valid = radeon_atombios_parse_pplib_clock_info(rdev,
2472 state_index, mode_index,
2473 clock_info);
2474 if (valid)
2475 mode_index++;
2476 }
2477 } else {
2478 rdev->pm.power_state[state_index].clock_info[0].mclk =
2479 rdev->clock.default_mclk;
2480 rdev->pm.power_state[state_index].clock_info[0].sclk =
2481 rdev->clock.default_sclk;
2482 mode_index++;
2471 } 2483 }
2472 rdev->pm.power_state[state_index].num_clock_modes = mode_index; 2484 rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2473 if (mode_index) { 2485 if (mode_index) {
@@ -2524,19 +2536,23 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
2524 } else { 2536 } else {
2525 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL); 2537 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2526 if (rdev->pm.power_state) { 2538 if (rdev->pm.power_state) {
2527 /* add the default mode */ 2539 rdev->pm.power_state[0].clock_info =
2528 rdev->pm.power_state[state_index].type = 2540 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2529 POWER_STATE_TYPE_DEFAULT; 2541 if (rdev->pm.power_state[0].clock_info) {
2530 rdev->pm.power_state[state_index].num_clock_modes = 1; 2542 /* add the default mode */
2531 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk; 2543 rdev->pm.power_state[state_index].type =
2532 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk; 2544 POWER_STATE_TYPE_DEFAULT;
2533 rdev->pm.power_state[state_index].default_clock_mode = 2545 rdev->pm.power_state[state_index].num_clock_modes = 1;
2534 &rdev->pm.power_state[state_index].clock_info[0]; 2546 rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2535 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE; 2547 rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
2536 rdev->pm.power_state[state_index].pcie_lanes = 16; 2548 rdev->pm.power_state[state_index].default_clock_mode =
2537 rdev->pm.default_power_state_index = state_index; 2549 &rdev->pm.power_state[state_index].clock_info[0];
2538 rdev->pm.power_state[state_index].flags = 0; 2550 rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2539 state_index++; 2551 rdev->pm.power_state[state_index].pcie_lanes = 16;
2552 rdev->pm.default_power_state_index = state_index;
2553 rdev->pm.power_state[state_index].flags = 0;
2554 state_index++;
2555 }
2540 } 2556 }
2541 } 2557 }
2542 2558
diff --git a/drivers/gpu/drm/radeon/radeon_benchmark.c b/drivers/gpu/drm/radeon/radeon_benchmark.c
index 5cafc90de7f..17e1a9b2d8f 100644
--- a/drivers/gpu/drm/radeon/radeon_benchmark.c
+++ b/drivers/gpu/drm/radeon/radeon_benchmark.c
@@ -98,7 +98,7 @@ static void radeon_benchmark_move(struct radeon_device *rdev, unsigned size,
98 struct radeon_bo *sobj = NULL; 98 struct radeon_bo *sobj = NULL;
99 uint64_t saddr, daddr; 99 uint64_t saddr, daddr;
100 int r, n; 100 int r, n;
101 unsigned int time; 101 int time;
102 102
103 n = RADEON_BENCHMARK_ITERATIONS; 103 n = RADEON_BENCHMARK_ITERATIONS;
104 r = radeon_bo_create(rdev, size, PAGE_SIZE, true, sdomain, &sobj); 104 r = radeon_bo_create(rdev, size, PAGE_SIZE, true, sdomain, &sobj);
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 8bf83c4b414..81fc100be7e 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -2563,14 +2563,17 @@ void radeon_combios_get_power_modes(struct radeon_device *rdev)
2563 2563
2564 /* allocate 2 power states */ 2564 /* allocate 2 power states */
2565 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL); 2565 rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * 2, GFP_KERNEL);
2566 if (!rdev->pm.power_state) { 2566 if (rdev->pm.power_state) {
2567 rdev->pm.default_power_state_index = state_index; 2567 /* allocate 1 clock mode per state */
2568 rdev->pm.num_power_states = 0; 2568 rdev->pm.power_state[0].clock_info =
2569 2569 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2570 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; 2570 rdev->pm.power_state[1].clock_info =
2571 rdev->pm.current_clock_mode_index = 0; 2571 kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
2572 return; 2572 if (!rdev->pm.power_state[0].clock_info ||
2573 } 2573 !rdev->pm.power_state[1].clock_info)
2574 goto pm_failed;
2575 } else
2576 goto pm_failed;
2574 2577
2575 /* check for a thermal chip */ 2578 /* check for a thermal chip */
2576 offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE); 2579 offset = combios_get_table_offset(dev, COMBIOS_OVERDRIVE_INFO_TABLE);
@@ -2735,6 +2738,14 @@ default_mode:
2735 2738
2736 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; 2739 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2737 rdev->pm.current_clock_mode_index = 0; 2740 rdev->pm.current_clock_mode_index = 0;
2741 return;
2742
2743pm_failed:
2744 rdev->pm.default_power_state_index = state_index;
2745 rdev->pm.num_power_states = 0;
2746
2747 rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2748 rdev->pm.current_clock_mode_index = 0;
2738} 2749}
2739 2750
2740void radeon_external_tmds_setup(struct drm_encoder *encoder) 2751void radeon_external_tmds_setup(struct drm_encoder *encoder)
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index dec6cbe6a0a..e7cb3ab0924 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -44,8 +44,6 @@ extern void
44radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder, 44radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
45 struct drm_connector *drm_connector); 45 struct drm_connector *drm_connector);
46 46
47bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector);
48
49void radeon_connector_hotplug(struct drm_connector *connector) 47void radeon_connector_hotplug(struct drm_connector *connector)
50{ 48{
51 struct drm_device *dev = connector->dev; 49 struct drm_device *dev = connector->dev;
@@ -432,55 +430,6 @@ int radeon_connector_set_property(struct drm_connector *connector, struct drm_pr
432 return 0; 430 return 0;
433} 431}
434 432
435/*
436 * Some integrated ATI Radeon chipset implementations (e. g.
437 * Asus M2A-VM HDMI) may indicate the availability of a DDC,
438 * even when there's no monitor connected. For these connectors
439 * following DDC probe extension will be applied: check also for the
440 * availability of EDID with at least a correct EDID header. Only then,
441 * DDC is assumed to be available. This prevents drm_get_edid() and
442 * drm_edid_block_valid() from periodically dumping data and kernel
443 * errors into the logs and onto the terminal.
444 */
445static bool radeon_connector_needs_extended_probe(struct radeon_device *dev,
446 uint32_t supported_device,
447 int connector_type)
448{
449 /* Asus M2A-VM HDMI board sends data to i2c bus even,
450 * if HDMI add-on card is not plugged in or HDMI is disabled in
451 * BIOS. Valid DDC can only be assumed, if also a valid EDID header
452 * can be retrieved via i2c bus during DDC probe */
453 if ((dev->pdev->device == 0x791e) &&
454 (dev->pdev->subsystem_vendor == 0x1043) &&
455 (dev->pdev->subsystem_device == 0x826d)) {
456 if ((connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
457 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
458 return true;
459 }
460 /* ECS A740GM-M with ATI RADEON 2100 sends data to i2c bus
461 * for a DVI connector that is not implemented */
462 if ((dev->pdev->device == 0x796e) &&
463 (dev->pdev->subsystem_vendor == 0x1019) &&
464 (dev->pdev->subsystem_device == 0x2615)) {
465 if ((connector_type == DRM_MODE_CONNECTOR_DVID) &&
466 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
467 return true;
468 }
469 /* TOSHIBA Satellite L300D with ATI Mobility Radeon x1100
470 * (RS690M) sends data to i2c bus for a HDMI connector that
471 * is not implemented */
472 if ((dev->pdev->device == 0x791f) &&
473 (dev->pdev->subsystem_vendor == 0x1179) &&
474 (dev->pdev->subsystem_device == 0xff68)) {
475 if ((connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
476 (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
477 return true;
478 }
479
480 /* Default: no EDID header probe required for DDC probing */
481 return false;
482}
483
484static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder, 433static void radeon_fixup_lvds_native_mode(struct drm_encoder *encoder,
485 struct drm_connector *connector) 434 struct drm_connector *connector)
486{ 435{
@@ -721,8 +670,7 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
721 ret = connector_status_disconnected; 670 ret = connector_status_disconnected;
722 671
723 if (radeon_connector->ddc_bus) 672 if (radeon_connector->ddc_bus)
724 dret = radeon_ddc_probe(radeon_connector, 673 dret = radeon_ddc_probe(radeon_connector);
725 radeon_connector->requires_extended_probe);
726 if (dret) { 674 if (dret) {
727 radeon_connector->detected_by_load = false; 675 radeon_connector->detected_by_load = false;
728 if (radeon_connector->edid) { 676 if (radeon_connector->edid) {
@@ -764,7 +712,7 @@ radeon_vga_detect(struct drm_connector *connector, bool force)
764 if (radeon_connector->dac_load_detect && encoder) { 712 if (radeon_connector->dac_load_detect && encoder) {
765 encoder_funcs = encoder->helper_private; 713 encoder_funcs = encoder->helper_private;
766 ret = encoder_funcs->detect(encoder, connector); 714 ret = encoder_funcs->detect(encoder, connector);
767 if (ret == connector_status_connected) 715 if (ret != connector_status_disconnected)
768 radeon_connector->detected_by_load = true; 716 radeon_connector->detected_by_load = true;
769 } 717 }
770 } 718 }
@@ -904,8 +852,7 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
904 bool dret = false; 852 bool dret = false;
905 853
906 if (radeon_connector->ddc_bus) 854 if (radeon_connector->ddc_bus)
907 dret = radeon_ddc_probe(radeon_connector, 855 dret = radeon_ddc_probe(radeon_connector);
908 radeon_connector->requires_extended_probe);
909 if (dret) { 856 if (dret) {
910 radeon_connector->detected_by_load = false; 857 radeon_connector->detected_by_load = false;
911 if (radeon_connector->edid) { 858 if (radeon_connector->edid) {
@@ -1005,8 +952,9 @@ radeon_dvi_detect(struct drm_connector *connector, bool force)
1005 ret = encoder_funcs->detect(encoder, connector); 952 ret = encoder_funcs->detect(encoder, connector);
1006 if (ret == connector_status_connected) { 953 if (ret == connector_status_connected) {
1007 radeon_connector->use_digital = false; 954 radeon_connector->use_digital = false;
1008 radeon_connector->detected_by_load = true;
1009 } 955 }
956 if (ret != connector_status_disconnected)
957 radeon_connector->detected_by_load = true;
1010 } 958 }
1011 break; 959 break;
1012 } 960 }
@@ -1203,7 +1151,8 @@ static int radeon_dp_get_modes(struct drm_connector *connector)
1203 } 1151 }
1204 } else { 1152 } else {
1205 /* need to setup ddc on the bridge */ 1153 /* need to setup ddc on the bridge */
1206 if (radeon_connector_encoder_is_dp_bridge(connector)) { 1154 if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1155 ENCODER_OBJECT_ID_NONE) {
1207 if (encoder) 1156 if (encoder)
1208 radeon_atom_ext_encoder_setup_ddc(encoder); 1157 radeon_atom_ext_encoder_setup_ddc(encoder);
1209 } 1158 }
@@ -1213,13 +1162,12 @@ static int radeon_dp_get_modes(struct drm_connector *connector)
1213 return ret; 1162 return ret;
1214} 1163}
1215 1164
1216bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector) 1165u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector)
1217{ 1166{
1218 struct drm_mode_object *obj; 1167 struct drm_mode_object *obj;
1219 struct drm_encoder *encoder; 1168 struct drm_encoder *encoder;
1220 struct radeon_encoder *radeon_encoder; 1169 struct radeon_encoder *radeon_encoder;
1221 int i; 1170 int i;
1222 bool found = false;
1223 1171
1224 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { 1172 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1225 if (connector->encoder_ids[i] == 0) 1173 if (connector->encoder_ids[i] == 0)
@@ -1235,14 +1183,13 @@ bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector)
1235 switch (radeon_encoder->encoder_id) { 1183 switch (radeon_encoder->encoder_id) {
1236 case ENCODER_OBJECT_ID_TRAVIS: 1184 case ENCODER_OBJECT_ID_TRAVIS:
1237 case ENCODER_OBJECT_ID_NUTMEG: 1185 case ENCODER_OBJECT_ID_NUTMEG:
1238 found = true; 1186 return radeon_encoder->encoder_id;
1239 break;
1240 default: 1187 default:
1241 break; 1188 break;
1242 } 1189 }
1243 } 1190 }
1244 1191
1245 return found; 1192 return ENCODER_OBJECT_ID_NONE;
1246} 1193}
1247 1194
1248bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector) 1195bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector)
@@ -1319,7 +1266,8 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1319 if (!radeon_dig_connector->edp_on) 1266 if (!radeon_dig_connector->edp_on)
1320 atombios_set_edp_panel_power(connector, 1267 atombios_set_edp_panel_power(connector,
1321 ATOM_TRANSMITTER_ACTION_POWER_OFF); 1268 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1322 } else if (radeon_connector_encoder_is_dp_bridge(connector)) { 1269 } else if (radeon_connector_encoder_get_dp_bridge_encoder_id(connector) !=
1270 ENCODER_OBJECT_ID_NONE) {
1323 /* DP bridges are always DP */ 1271 /* DP bridges are always DP */
1324 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT; 1272 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
1325 /* get the DPCD from the bridge */ 1273 /* get the DPCD from the bridge */
@@ -1328,8 +1276,7 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1328 if (encoder) { 1276 if (encoder) {
1329 /* setup ddc on the bridge */ 1277 /* setup ddc on the bridge */
1330 radeon_atom_ext_encoder_setup_ddc(encoder); 1278 radeon_atom_ext_encoder_setup_ddc(encoder);
1331 if (radeon_ddc_probe(radeon_connector, 1279 if (radeon_ddc_probe(radeon_connector)) /* try DDC */
1332 radeon_connector->requires_extended_probe)) /* try DDC */
1333 ret = connector_status_connected; 1280 ret = connector_status_connected;
1334 else if (radeon_connector->dac_load_detect) { /* try load detection */ 1281 else if (radeon_connector->dac_load_detect) { /* try load detection */
1335 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; 1282 struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
@@ -1347,8 +1294,7 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1347 if (radeon_dp_getdpcd(radeon_connector)) 1294 if (radeon_dp_getdpcd(radeon_connector))
1348 ret = connector_status_connected; 1295 ret = connector_status_connected;
1349 } else { 1296 } else {
1350 if (radeon_ddc_probe(radeon_connector, 1297 if (radeon_ddc_probe(radeon_connector))
1351 radeon_connector->requires_extended_probe))
1352 ret = connector_status_connected; 1298 ret = connector_status_connected;
1353 } 1299 }
1354 } 1300 }
@@ -1493,9 +1439,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1493 radeon_connector->shared_ddc = shared_ddc; 1439 radeon_connector->shared_ddc = shared_ddc;
1494 radeon_connector->connector_object_id = connector_object_id; 1440 radeon_connector->connector_object_id = connector_object_id;
1495 radeon_connector->hpd = *hpd; 1441 radeon_connector->hpd = *hpd;
1496 radeon_connector->requires_extended_probe = 1442
1497 radeon_connector_needs_extended_probe(rdev, supported_device,
1498 connector_type);
1499 radeon_connector->router = *router; 1443 radeon_connector->router = *router;
1500 if (router->ddc_valid || router->cd_valid) { 1444 if (router->ddc_valid || router->cd_valid) {
1501 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info); 1445 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
@@ -1842,9 +1786,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1842 radeon_connector->devices = supported_device; 1786 radeon_connector->devices = supported_device;
1843 radeon_connector->connector_object_id = connector_object_id; 1787 radeon_connector->connector_object_id = connector_object_id;
1844 radeon_connector->hpd = *hpd; 1788 radeon_connector->hpd = *hpd;
1845 radeon_connector->requires_extended_probe = 1789
1846 radeon_connector_needs_extended_probe(rdev, supported_device,
1847 connector_type);
1848 switch (connector_type) { 1790 switch (connector_type) {
1849 case DRM_MODE_CONNECTOR_VGA: 1791 case DRM_MODE_CONNECTOR_VGA:
1850 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1792 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
diff --git a/drivers/gpu/drm/radeon/radeon_cp.c b/drivers/gpu/drm/radeon/radeon_cp.c
index 045ec59478f..72ae8266b8e 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_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index fae00c0d75a..29afd71e084 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -93,7 +93,7 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
93{ 93{
94 struct drm_radeon_cs *cs = data; 94 struct drm_radeon_cs *cs = data;
95 uint64_t *chunk_array_ptr; 95 uint64_t *chunk_array_ptr;
96 unsigned size, i; 96 unsigned size, i, flags = 0;
97 97
98 if (!cs->num_chunks) { 98 if (!cs->num_chunks) {
99 return 0; 99 return 0;
@@ -140,6 +140,10 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
140 if (p->chunks[i].length_dw == 0) 140 if (p->chunks[i].length_dw == 0)
141 return -EINVAL; 141 return -EINVAL;
142 } 142 }
143 if (p->chunks[i].chunk_id == RADEON_CHUNK_ID_FLAGS &&
144 !p->chunks[i].length_dw) {
145 return -EINVAL;
146 }
143 147
144 p->chunks[i].length_dw = user_chunk.length_dw; 148 p->chunks[i].length_dw = user_chunk.length_dw;
145 p->chunks[i].user_ptr = (void __user *)(unsigned long)user_chunk.chunk_data; 149 p->chunks[i].user_ptr = (void __user *)(unsigned long)user_chunk.chunk_data;
@@ -155,6 +159,9 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
155 p->chunks[i].user_ptr, size)) { 159 p->chunks[i].user_ptr, size)) {
156 return -EFAULT; 160 return -EFAULT;
157 } 161 }
162 if (p->chunks[i].chunk_id == RADEON_CHUNK_ID_FLAGS) {
163 flags = p->chunks[i].kdata[0];
164 }
158 } else { 165 } else {
159 p->chunks[i].kpage[0] = kmalloc(PAGE_SIZE, GFP_KERNEL); 166 p->chunks[i].kpage[0] = kmalloc(PAGE_SIZE, GFP_KERNEL);
160 p->chunks[i].kpage[1] = kmalloc(PAGE_SIZE, GFP_KERNEL); 167 p->chunks[i].kpage[1] = kmalloc(PAGE_SIZE, GFP_KERNEL);
@@ -174,6 +181,8 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
174 p->chunks[p->chunk_ib_idx].length_dw); 181 p->chunks[p->chunk_ib_idx].length_dw);
175 return -EINVAL; 182 return -EINVAL;
176 } 183 }
184
185 p->keep_tiling_flags = (flags & RADEON_CS_KEEP_TILING_FLAGS) != 0;
177 return 0; 186 return 0;
178} 187}
179 188
@@ -222,7 +231,7 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
222 struct radeon_cs_chunk *ib_chunk; 231 struct radeon_cs_chunk *ib_chunk;
223 int r; 232 int r;
224 233
225 mutex_lock(&rdev->cs_mutex); 234 radeon_mutex_lock(&rdev->cs_mutex);
226 /* initialize parser */ 235 /* initialize parser */
227 memset(&parser, 0, sizeof(struct radeon_cs_parser)); 236 memset(&parser, 0, sizeof(struct radeon_cs_parser));
228 parser.filp = filp; 237 parser.filp = filp;
@@ -233,14 +242,14 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
233 if (r) { 242 if (r) {
234 DRM_ERROR("Failed to initialize parser !\n"); 243 DRM_ERROR("Failed to initialize parser !\n");
235 radeon_cs_parser_fini(&parser, r); 244 radeon_cs_parser_fini(&parser, r);
236 mutex_unlock(&rdev->cs_mutex); 245 radeon_mutex_unlock(&rdev->cs_mutex);
237 return r; 246 return r;
238 } 247 }
239 r = radeon_ib_get(rdev, &parser.ib); 248 r = radeon_ib_get(rdev, &parser.ib);
240 if (r) { 249 if (r) {
241 DRM_ERROR("Failed to get ib !\n"); 250 DRM_ERROR("Failed to get ib !\n");
242 radeon_cs_parser_fini(&parser, r); 251 radeon_cs_parser_fini(&parser, r);
243 mutex_unlock(&rdev->cs_mutex); 252 radeon_mutex_unlock(&rdev->cs_mutex);
244 return r; 253 return r;
245 } 254 }
246 r = radeon_cs_parser_relocs(&parser); 255 r = radeon_cs_parser_relocs(&parser);
@@ -248,7 +257,7 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
248 if (r != -ERESTARTSYS) 257 if (r != -ERESTARTSYS)
249 DRM_ERROR("Failed to parse relocation %d!\n", r); 258 DRM_ERROR("Failed to parse relocation %d!\n", r);
250 radeon_cs_parser_fini(&parser, r); 259 radeon_cs_parser_fini(&parser, r);
251 mutex_unlock(&rdev->cs_mutex); 260 radeon_mutex_unlock(&rdev->cs_mutex);
252 return r; 261 return r;
253 } 262 }
254 /* Copy the packet into the IB, the parser will read from the 263 /* Copy the packet into the IB, the parser will read from the
@@ -260,14 +269,14 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
260 if (r || parser.parser_error) { 269 if (r || parser.parser_error) {
261 DRM_ERROR("Invalid command stream !\n"); 270 DRM_ERROR("Invalid command stream !\n");
262 radeon_cs_parser_fini(&parser, r); 271 radeon_cs_parser_fini(&parser, r);
263 mutex_unlock(&rdev->cs_mutex); 272 radeon_mutex_unlock(&rdev->cs_mutex);
264 return r; 273 return r;
265 } 274 }
266 r = radeon_cs_finish_pages(&parser); 275 r = radeon_cs_finish_pages(&parser);
267 if (r) { 276 if (r) {
268 DRM_ERROR("Invalid command stream !\n"); 277 DRM_ERROR("Invalid command stream !\n");
269 radeon_cs_parser_fini(&parser, r); 278 radeon_cs_parser_fini(&parser, r);
270 mutex_unlock(&rdev->cs_mutex); 279 radeon_mutex_unlock(&rdev->cs_mutex);
271 return r; 280 return r;
272 } 281 }
273 r = radeon_ib_schedule(rdev, parser.ib); 282 r = radeon_ib_schedule(rdev, parser.ib);
@@ -275,7 +284,7 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
275 DRM_ERROR("Failed to schedule IB !\n"); 284 DRM_ERROR("Failed to schedule IB !\n");
276 } 285 }
277 radeon_cs_parser_fini(&parser, r); 286 radeon_cs_parser_fini(&parser, r);
278 mutex_unlock(&rdev->cs_mutex); 287 radeon_mutex_unlock(&rdev->cs_mutex);
279 return r; 288 return r;
280} 289}
281 290
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index c33bc914d93..c4d00a17141 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -716,7 +716,7 @@ int radeon_device_init(struct radeon_device *rdev,
716 716
717 /* mutex initialization are all done here so we 717 /* mutex initialization are all done here so we
718 * can recall function without having locking issues */ 718 * can recall function without having locking issues */
719 mutex_init(&rdev->cs_mutex); 719 radeon_mutex_init(&rdev->cs_mutex);
720 mutex_init(&rdev->ib_pool.mutex); 720 mutex_init(&rdev->ib_pool.mutex);
721 mutex_init(&rdev->cp.mutex); 721 mutex_init(&rdev->cp.mutex);
722 mutex_init(&rdev->dc_hw_i2c_mutex); 722 mutex_init(&rdev->dc_hw_i2c_mutex);
@@ -955,6 +955,9 @@ int radeon_gpu_reset(struct radeon_device *rdev)
955 int r; 955 int r;
956 int resched; 956 int resched;
957 957
958 /* Prevent CS ioctl from interfering */
959 radeon_mutex_lock(&rdev->cs_mutex);
960
958 radeon_save_bios_scratch_regs(rdev); 961 radeon_save_bios_scratch_regs(rdev);
959 /* block TTM */ 962 /* block TTM */
960 resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); 963 resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev);
@@ -967,10 +970,15 @@ int radeon_gpu_reset(struct radeon_device *rdev)
967 radeon_restore_bios_scratch_regs(rdev); 970 radeon_restore_bios_scratch_regs(rdev);
968 drm_helper_resume_force_mode(rdev->ddev); 971 drm_helper_resume_force_mode(rdev->ddev);
969 ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); 972 ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched);
970 return 0;
971 } 973 }
972 /* bad news, how to tell it to userspace ? */ 974
973 dev_info(rdev->dev, "GPU reset failed\n"); 975 radeon_mutex_unlock(&rdev->cs_mutex);
976
977 if (r) {
978 /* bad news, how to tell it to userspace ? */
979 dev_info(rdev->dev, "GPU reset failed\n");
980 }
981
974 return r; 982 return r;
975} 983}
976 984
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 6adb3e58aff..a22d6e6a49a 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -33,8 +33,6 @@
33#include "drm_crtc_helper.h" 33#include "drm_crtc_helper.h"
34#include "drm_edid.h" 34#include "drm_edid.h"
35 35
36static int radeon_ddc_dump(struct drm_connector *connector);
37
38static void avivo_crtc_load_lut(struct drm_crtc *crtc) 36static void avivo_crtc_load_lut(struct drm_crtc *crtc)
39{ 37{
40 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 38 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
@@ -669,7 +667,6 @@ static void radeon_print_display_setup(struct drm_device *dev)
669static bool radeon_setup_enc_conn(struct drm_device *dev) 667static bool radeon_setup_enc_conn(struct drm_device *dev)
670{ 668{
671 struct radeon_device *rdev = dev->dev_private; 669 struct radeon_device *rdev = dev->dev_private;
672 struct drm_connector *drm_connector;
673 bool ret = false; 670 bool ret = false;
674 671
675 if (rdev->bios) { 672 if (rdev->bios) {
@@ -689,8 +686,6 @@ static bool radeon_setup_enc_conn(struct drm_device *dev)
689 if (ret) { 686 if (ret) {
690 radeon_setup_encoder_clones(dev); 687 radeon_setup_encoder_clones(dev);
691 radeon_print_display_setup(dev); 688 radeon_print_display_setup(dev);
692 list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head)
693 radeon_ddc_dump(drm_connector);
694 } 689 }
695 690
696 return ret; 691 return ret;
@@ -708,7 +703,8 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
708 703
709 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || 704 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
710 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) || 705 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) ||
711 radeon_connector_encoder_is_dp_bridge(&radeon_connector->base)) { 706 (radeon_connector_encoder_get_dp_bridge_encoder_id(&radeon_connector->base) !=
707 ENCODER_OBJECT_ID_NONE)) {
712 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; 708 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
713 709
714 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT || 710 if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
@@ -743,34 +739,6 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
743 return 0; 739 return 0;
744} 740}
745 741
746static int radeon_ddc_dump(struct drm_connector *connector)
747{
748 struct edid *edid;
749 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
750 int ret = 0;
751
752 /* on hw with routers, select right port */
753 if (radeon_connector->router.ddc_valid)
754 radeon_router_select_ddc_port(radeon_connector);
755
756 if (!radeon_connector->ddc_bus)
757 return -1;
758 edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter);
759 /* Log EDID retrieval status here. In particular with regard to
760 * connectors with requires_extended_probe flag set, that will prevent
761 * function radeon_dvi_detect() to fetch EDID on this connector,
762 * as long as there is no valid EDID header found */
763 if (edid) {
764 DRM_INFO("Radeon display connector %s: Found valid EDID",
765 drm_get_connector_name(connector));
766 kfree(edid);
767 } else {
768 DRM_INFO("Radeon display connector %s: No monitor connected or invalid EDID",
769 drm_get_connector_name(connector));
770 }
771 return ret;
772}
773
774/* avivo */ 742/* avivo */
775static void avivo_get_fb_div(struct radeon_pll *pll, 743static void avivo_get_fb_div(struct radeon_pll *pll,
776 u32 target_clock, 744 u32 target_clock,
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index e71d2ed7fa1..71499fc3daf 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/*
@@ -52,9 +53,10 @@
52 * 2.9.0 - r600 tiling (s3tc,rgtc) working, SET_PREDICATION packet 3 on r600 + eg, backend query 53 * 2.9.0 - r600 tiling (s3tc,rgtc) working, SET_PREDICATION packet 3 on r600 + eg, backend query
53 * 2.10.0 - fusion 2D tiling 54 * 2.10.0 - fusion 2D tiling
54 * 2.11.0 - backend map, initial compute support for the CS checker 55 * 2.11.0 - backend map, initial compute support for the CS checker
56 * 2.12.0 - RADEON_CS_KEEP_TILING_FLAGS
55 */ 57 */
56#define KMS_DRIVER_MAJOR 2 58#define KMS_DRIVER_MAJOR 2
57#define KMS_DRIVER_MINOR 11 59#define KMS_DRIVER_MINOR 12
58#define KMS_DRIVER_PATCHLEVEL 0 60#define KMS_DRIVER_PATCHLEVEL 0
59int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags); 61int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
60int radeon_driver_unload_kms(struct drm_device *dev); 62int radeon_driver_unload_kms(struct drm_device *dev);
@@ -118,6 +120,7 @@ int radeon_audio = 0;
118int radeon_disp_priority = 0; 120int radeon_disp_priority = 0;
119int radeon_hw_i2c = 0; 121int radeon_hw_i2c = 0;
120int radeon_pcie_gen2 = 0; 122int radeon_pcie_gen2 = 0;
123int radeon_msi = -1;
121 124
122MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers"); 125MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers");
123module_param_named(no_wb, radeon_no_wb, int, 0444); 126module_param_named(no_wb, radeon_no_wb, int, 0444);
@@ -164,6 +167,9 @@ module_param_named(hw_i2c, radeon_hw_i2c, int, 0444);
164MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (1 = enable)"); 167MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (1 = enable)");
165module_param_named(pcie_gen2, radeon_pcie_gen2, int, 0444); 168module_param_named(pcie_gen2, radeon_pcie_gen2, int, 0444);
166 169
170MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
171module_param_named(msi, radeon_msi, int, 0444);
172
167static int radeon_suspend(struct drm_device *dev, pm_message_t state) 173static int radeon_suspend(struct drm_device *dev, pm_message_t state)
168{ 174{
169 drm_radeon_private_t *dev_priv = dev->dev_private; 175 drm_radeon_private_t *dev_priv = dev->dev_private;
diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c
index eb3f6dc6df8..06e413e6a92 100644
--- a/drivers/gpu/drm/radeon/radeon_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_encoders.c
@@ -29,12 +29,6 @@
29#include "radeon.h" 29#include "radeon.h"
30#include "atom.h" 30#include "atom.h"
31 31
32extern int atom_debug;
33
34/* evil but including atombios.h is much worse */
35bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
36 struct drm_display_mode *mode);
37
38static uint32_t radeon_encoder_clones(struct drm_encoder *encoder) 32static uint32_t radeon_encoder_clones(struct drm_encoder *encoder)
39{ 33{
40 struct drm_device *dev = encoder->dev; 34 struct drm_device *dev = encoder->dev;
@@ -156,27 +150,6 @@ radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device, uint8
156 return ret; 150 return ret;
157} 151}
158 152
159static inline bool radeon_encoder_is_digital(struct drm_encoder *encoder)
160{
161 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
162 switch (radeon_encoder->encoder_id) {
163 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
164 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
165 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
166 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
167 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
168 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
169 case ENCODER_OBJECT_ID_INTERNAL_DDI:
170 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
171 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
172 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
173 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
174 return true;
175 default:
176 return false;
177 }
178}
179
180void 153void
181radeon_link_encoder_connector(struct drm_device *dev) 154radeon_link_encoder_connector(struct drm_device *dev)
182{ 155{
@@ -229,23 +202,7 @@ radeon_get_connector_for_encoder(struct drm_encoder *encoder)
229 return NULL; 202 return NULL;
230} 203}
231 204
232static struct drm_connector * 205struct drm_encoder *radeon_get_external_encoder(struct drm_encoder *encoder)
233radeon_get_connector_for_encoder_init(struct drm_encoder *encoder)
234{
235 struct drm_device *dev = encoder->dev;
236 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
237 struct drm_connector *connector;
238 struct radeon_connector *radeon_connector;
239
240 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
241 radeon_connector = to_radeon_connector(connector);
242 if (radeon_encoder->devices & radeon_connector->devices)
243 return connector;
244 }
245 return NULL;
246}
247
248struct drm_encoder *radeon_atom_get_external_encoder(struct drm_encoder *encoder)
249{ 206{
250 struct drm_device *dev = encoder->dev; 207 struct drm_device *dev = encoder->dev;
251 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 208 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
@@ -266,9 +223,9 @@ struct drm_encoder *radeon_atom_get_external_encoder(struct drm_encoder *encoder
266 return NULL; 223 return NULL;
267} 224}
268 225
269bool radeon_encoder_is_dp_bridge(struct drm_encoder *encoder) 226u16 radeon_encoder_get_dp_bridge_encoder_id(struct drm_encoder *encoder)
270{ 227{
271 struct drm_encoder *other_encoder = radeon_atom_get_external_encoder(encoder); 228 struct drm_encoder *other_encoder = radeon_get_external_encoder(encoder);
272 229
273 if (other_encoder) { 230 if (other_encoder) {
274 struct radeon_encoder *radeon_encoder = to_radeon_encoder(other_encoder); 231 struct radeon_encoder *radeon_encoder = to_radeon_encoder(other_encoder);
@@ -332,2105 +289,3 @@ void radeon_panel_mode_fixup(struct drm_encoder *encoder,
332 289
333} 290}
334 291
335static bool radeon_atom_mode_fixup(struct drm_encoder *encoder,
336 struct drm_display_mode *mode,
337 struct drm_display_mode *adjusted_mode)
338{
339 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
340 struct drm_device *dev = encoder->dev;
341 struct radeon_device *rdev = dev->dev_private;
342
343 /* set the active encoder to connector routing */
344 radeon_encoder_set_active_device(encoder);
345 drm_mode_set_crtcinfo(adjusted_mode, 0);
346
347 /* hw bug */
348 if ((mode->flags & DRM_MODE_FLAG_INTERLACE)
349 && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2)))
350 adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2;
351
352 /* get the native mode for LVDS */
353 if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT))
354 radeon_panel_mode_fixup(encoder, adjusted_mode);
355
356 /* get the native mode for TV */
357 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) {
358 struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
359 if (tv_dac) {
360 if (tv_dac->tv_std == TV_STD_NTSC ||
361 tv_dac->tv_std == TV_STD_NTSC_J ||
362 tv_dac->tv_std == TV_STD_PAL_M)
363 radeon_atom_get_tv_timings(rdev, 0, adjusted_mode);
364 else
365 radeon_atom_get_tv_timings(rdev, 1, adjusted_mode);
366 }
367 }
368
369 if (ASIC_IS_DCE3(rdev) &&
370 ((radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
371 radeon_encoder_is_dp_bridge(encoder))) {
372 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
373 radeon_dp_set_link_config(connector, mode);
374 }
375
376 return true;
377}
378
379static void
380atombios_dac_setup(struct drm_encoder *encoder, int action)
381{
382 struct drm_device *dev = encoder->dev;
383 struct radeon_device *rdev = dev->dev_private;
384 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
385 DAC_ENCODER_CONTROL_PS_ALLOCATION args;
386 int index = 0;
387 struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
388
389 memset(&args, 0, sizeof(args));
390
391 switch (radeon_encoder->encoder_id) {
392 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
393 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
394 index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl);
395 break;
396 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
397 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
398 index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl);
399 break;
400 }
401
402 args.ucAction = action;
403
404 if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT))
405 args.ucDacStandard = ATOM_DAC1_PS2;
406 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
407 args.ucDacStandard = ATOM_DAC1_CV;
408 else {
409 switch (dac_info->tv_std) {
410 case TV_STD_PAL:
411 case TV_STD_PAL_M:
412 case TV_STD_SCART_PAL:
413 case TV_STD_SECAM:
414 case TV_STD_PAL_CN:
415 args.ucDacStandard = ATOM_DAC1_PAL;
416 break;
417 case TV_STD_NTSC:
418 case TV_STD_NTSC_J:
419 case TV_STD_PAL_60:
420 default:
421 args.ucDacStandard = ATOM_DAC1_NTSC;
422 break;
423 }
424 }
425 args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
426
427 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
428
429}
430
431static void
432atombios_tv_setup(struct drm_encoder *encoder, int action)
433{
434 struct drm_device *dev = encoder->dev;
435 struct radeon_device *rdev = dev->dev_private;
436 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
437 TV_ENCODER_CONTROL_PS_ALLOCATION args;
438 int index = 0;
439 struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
440
441 memset(&args, 0, sizeof(args));
442
443 index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl);
444
445 args.sTVEncoder.ucAction = action;
446
447 if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
448 args.sTVEncoder.ucTvStandard = ATOM_TV_CV;
449 else {
450 switch (dac_info->tv_std) {
451 case TV_STD_NTSC:
452 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
453 break;
454 case TV_STD_PAL:
455 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL;
456 break;
457 case TV_STD_PAL_M:
458 args.sTVEncoder.ucTvStandard = ATOM_TV_PALM;
459 break;
460 case TV_STD_PAL_60:
461 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60;
462 break;
463 case TV_STD_NTSC_J:
464 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ;
465 break;
466 case TV_STD_SCART_PAL:
467 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */
468 break;
469 case TV_STD_SECAM:
470 args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM;
471 break;
472 case TV_STD_PAL_CN:
473 args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN;
474 break;
475 default:
476 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
477 break;
478 }
479 }
480
481 args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
482
483 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
484
485}
486
487union dvo_encoder_control {
488 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds;
489 DVO_ENCODER_CONTROL_PS_ALLOCATION dvo;
490 DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3;
491};
492
493void
494atombios_dvo_setup(struct drm_encoder *encoder, int action)
495{
496 struct drm_device *dev = encoder->dev;
497 struct radeon_device *rdev = dev->dev_private;
498 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
499 union dvo_encoder_control args;
500 int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
501
502 memset(&args, 0, sizeof(args));
503
504 if (ASIC_IS_DCE3(rdev)) {
505 /* DCE3+ */
506 args.dvo_v3.ucAction = action;
507 args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
508 args.dvo_v3.ucDVOConfig = 0; /* XXX */
509 } else if (ASIC_IS_DCE2(rdev)) {
510 /* DCE2 (pre-DCE3 R6xx, RS600/690/740 */
511 args.dvo.sDVOEncoder.ucAction = action;
512 args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
513 /* DFP1, CRT1, TV1 depending on the type of port */
514 args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX;
515
516 if (radeon_encoder->pixel_clock > 165000)
517 args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL;
518 } else {
519 /* R4xx, R5xx */
520 args.ext_tmds.sXTmdsEncoder.ucEnable = action;
521
522 if (radeon_encoder->pixel_clock > 165000)
523 args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL;
524
525 /*if (pScrn->rgbBits == 8)*/
526 args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB;
527 }
528
529 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
530}
531
532union lvds_encoder_control {
533 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1;
534 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2;
535};
536
537void
538atombios_digital_setup(struct drm_encoder *encoder, int action)
539{
540 struct drm_device *dev = encoder->dev;
541 struct radeon_device *rdev = dev->dev_private;
542 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
543 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
544 union lvds_encoder_control args;
545 int index = 0;
546 int hdmi_detected = 0;
547 uint8_t frev, crev;
548
549 if (!dig)
550 return;
551
552 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
553 hdmi_detected = 1;
554
555 memset(&args, 0, sizeof(args));
556
557 switch (radeon_encoder->encoder_id) {
558 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
559 index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
560 break;
561 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
562 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
563 index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl);
564 break;
565 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
566 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
567 index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
568 else
569 index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl);
570 break;
571 }
572
573 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
574 return;
575
576 switch (frev) {
577 case 1:
578 case 2:
579 switch (crev) {
580 case 1:
581 args.v1.ucMisc = 0;
582 args.v1.ucAction = action;
583 if (hdmi_detected)
584 args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
585 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
586 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
587 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
588 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
589 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
590 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
591 } else {
592 if (dig->linkb)
593 args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
594 if (radeon_encoder->pixel_clock > 165000)
595 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
596 /*if (pScrn->rgbBits == 8) */
597 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
598 }
599 break;
600 case 2:
601 case 3:
602 args.v2.ucMisc = 0;
603 args.v2.ucAction = action;
604 if (crev == 3) {
605 if (dig->coherent_mode)
606 args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT;
607 }
608 if (hdmi_detected)
609 args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
610 args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
611 args.v2.ucTruncate = 0;
612 args.v2.ucSpatial = 0;
613 args.v2.ucTemporal = 0;
614 args.v2.ucFRC = 0;
615 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
616 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
617 args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
618 if (dig->lcd_misc & ATOM_PANEL_MISC_SPATIAL) {
619 args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN;
620 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
621 args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH;
622 }
623 if (dig->lcd_misc & ATOM_PANEL_MISC_TEMPORAL) {
624 args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN;
625 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
626 args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH;
627 if (((dig->lcd_misc >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT) & 0x3) == 2)
628 args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4;
629 }
630 } else {
631 if (dig->linkb)
632 args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
633 if (radeon_encoder->pixel_clock > 165000)
634 args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
635 }
636 break;
637 default:
638 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
639 break;
640 }
641 break;
642 default:
643 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
644 break;
645 }
646
647 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
648}
649
650int
651atombios_get_encoder_mode(struct drm_encoder *encoder)
652{
653 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
654 struct drm_device *dev = encoder->dev;
655 struct radeon_device *rdev = dev->dev_private;
656 struct drm_connector *connector;
657 struct radeon_connector *radeon_connector;
658 struct radeon_connector_atom_dig *dig_connector;
659
660 /* dp bridges are always DP */
661 if (radeon_encoder_is_dp_bridge(encoder))
662 return ATOM_ENCODER_MODE_DP;
663
664 /* DVO is always DVO */
665 if (radeon_encoder->encoder_id == ATOM_ENCODER_MODE_DVO)
666 return ATOM_ENCODER_MODE_DVO;
667
668 connector = radeon_get_connector_for_encoder(encoder);
669 /* if we don't have an active device yet, just use one of
670 * the connectors tied to the encoder.
671 */
672 if (!connector)
673 connector = radeon_get_connector_for_encoder_init(encoder);
674 radeon_connector = to_radeon_connector(connector);
675
676 switch (connector->connector_type) {
677 case DRM_MODE_CONNECTOR_DVII:
678 case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
679 if (drm_detect_monitor_audio(radeon_connector->edid) && radeon_audio) {
680 /* fix me */
681 if (ASIC_IS_DCE4(rdev))
682 return ATOM_ENCODER_MODE_DVI;
683 else
684 return ATOM_ENCODER_MODE_HDMI;
685 } else if (radeon_connector->use_digital)
686 return ATOM_ENCODER_MODE_DVI;
687 else
688 return ATOM_ENCODER_MODE_CRT;
689 break;
690 case DRM_MODE_CONNECTOR_DVID:
691 case DRM_MODE_CONNECTOR_HDMIA:
692 default:
693 if (drm_detect_monitor_audio(radeon_connector->edid) && radeon_audio) {
694 /* fix me */
695 if (ASIC_IS_DCE4(rdev))
696 return ATOM_ENCODER_MODE_DVI;
697 else
698 return ATOM_ENCODER_MODE_HDMI;
699 } else
700 return ATOM_ENCODER_MODE_DVI;
701 break;
702 case DRM_MODE_CONNECTOR_LVDS:
703 return ATOM_ENCODER_MODE_LVDS;
704 break;
705 case DRM_MODE_CONNECTOR_DisplayPort:
706 dig_connector = radeon_connector->con_priv;
707 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
708 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
709 return ATOM_ENCODER_MODE_DP;
710 else if (drm_detect_monitor_audio(radeon_connector->edid) && radeon_audio) {
711 /* fix me */
712 if (ASIC_IS_DCE4(rdev))
713 return ATOM_ENCODER_MODE_DVI;
714 else
715 return ATOM_ENCODER_MODE_HDMI;
716 } else
717 return ATOM_ENCODER_MODE_DVI;
718 break;
719 case DRM_MODE_CONNECTOR_eDP:
720 return ATOM_ENCODER_MODE_DP;
721 case DRM_MODE_CONNECTOR_DVIA:
722 case DRM_MODE_CONNECTOR_VGA:
723 return ATOM_ENCODER_MODE_CRT;
724 break;
725 case DRM_MODE_CONNECTOR_Composite:
726 case DRM_MODE_CONNECTOR_SVIDEO:
727 case DRM_MODE_CONNECTOR_9PinDIN:
728 /* fix me */
729 return ATOM_ENCODER_MODE_TV;
730 /*return ATOM_ENCODER_MODE_CV;*/
731 break;
732 }
733}
734
735/*
736 * DIG Encoder/Transmitter Setup
737 *
738 * DCE 3.0/3.1
739 * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
740 * Supports up to 3 digital outputs
741 * - 2 DIG encoder blocks.
742 * DIG1 can drive UNIPHY link A or link B
743 * DIG2 can drive UNIPHY link B or LVTMA
744 *
745 * DCE 3.2
746 * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
747 * Supports up to 5 digital outputs
748 * - 2 DIG encoder blocks.
749 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
750 *
751 * DCE 4.0/5.0
752 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
753 * Supports up to 6 digital outputs
754 * - 6 DIG encoder blocks.
755 * - DIG to PHY mapping is hardcoded
756 * DIG1 drives UNIPHY0 link A, A+B
757 * DIG2 drives UNIPHY0 link B
758 * DIG3 drives UNIPHY1 link A, A+B
759 * DIG4 drives UNIPHY1 link B
760 * DIG5 drives UNIPHY2 link A, A+B
761 * DIG6 drives UNIPHY2 link B
762 *
763 * DCE 4.1
764 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
765 * Supports up to 6 digital outputs
766 * - 2 DIG encoder blocks.
767 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
768 *
769 * Routing
770 * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
771 * Examples:
772 * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
773 * crtc1 -> dig1 -> UNIPHY0 link B -> DP
774 * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
775 * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
776 */
777
778union dig_encoder_control {
779 DIG_ENCODER_CONTROL_PS_ALLOCATION v1;
780 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2;
781 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3;
782 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4;
783};
784
785void
786atombios_dig_encoder_setup(struct drm_encoder *encoder, int action, int panel_mode)
787{
788 struct drm_device *dev = encoder->dev;
789 struct radeon_device *rdev = dev->dev_private;
790 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
791 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
792 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
793 union dig_encoder_control args;
794 int index = 0;
795 uint8_t frev, crev;
796 int dp_clock = 0;
797 int dp_lane_count = 0;
798 int hpd_id = RADEON_HPD_NONE;
799 int bpc = 8;
800
801 if (connector) {
802 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
803 struct radeon_connector_atom_dig *dig_connector =
804 radeon_connector->con_priv;
805
806 dp_clock = dig_connector->dp_clock;
807 dp_lane_count = dig_connector->dp_lane_count;
808 hpd_id = radeon_connector->hpd.hpd;
809 bpc = connector->display_info.bpc;
810 }
811
812 /* no dig encoder assigned */
813 if (dig->dig_encoder == -1)
814 return;
815
816 memset(&args, 0, sizeof(args));
817
818 if (ASIC_IS_DCE4(rdev))
819 index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl);
820 else {
821 if (dig->dig_encoder)
822 index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
823 else
824 index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
825 }
826
827 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
828 return;
829
830 args.v1.ucAction = action;
831 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
832 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
833 args.v3.ucPanelMode = panel_mode;
834 else
835 args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder);
836
837 if ((args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP) ||
838 (args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP_MST))
839 args.v1.ucLaneNum = dp_lane_count;
840 else if (radeon_encoder->pixel_clock > 165000)
841 args.v1.ucLaneNum = 8;
842 else
843 args.v1.ucLaneNum = 4;
844
845 if (ASIC_IS_DCE5(rdev)) {
846 if ((args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP) ||
847 (args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP_MST)) {
848 if (dp_clock == 270000)
849 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ;
850 else if (dp_clock == 540000)
851 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ;
852 }
853 args.v4.acConfig.ucDigSel = dig->dig_encoder;
854 switch (bpc) {
855 case 0:
856 args.v4.ucBitPerColor = PANEL_BPC_UNDEFINE;
857 break;
858 case 6:
859 args.v4.ucBitPerColor = PANEL_6BIT_PER_COLOR;
860 break;
861 case 8:
862 default:
863 args.v4.ucBitPerColor = PANEL_8BIT_PER_COLOR;
864 break;
865 case 10:
866 args.v4.ucBitPerColor = PANEL_10BIT_PER_COLOR;
867 break;
868 case 12:
869 args.v4.ucBitPerColor = PANEL_12BIT_PER_COLOR;
870 break;
871 case 16:
872 args.v4.ucBitPerColor = PANEL_16BIT_PER_COLOR;
873 break;
874 }
875 if (hpd_id == RADEON_HPD_NONE)
876 args.v4.ucHPD_ID = 0;
877 else
878 args.v4.ucHPD_ID = hpd_id + 1;
879 } else if (ASIC_IS_DCE4(rdev)) {
880 if ((args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP) && (dp_clock == 270000))
881 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
882 args.v3.acConfig.ucDigSel = dig->dig_encoder;
883 switch (bpc) {
884 case 0:
885 args.v3.ucBitPerColor = PANEL_BPC_UNDEFINE;
886 break;
887 case 6:
888 args.v3.ucBitPerColor = PANEL_6BIT_PER_COLOR;
889 break;
890 case 8:
891 default:
892 args.v3.ucBitPerColor = PANEL_8BIT_PER_COLOR;
893 break;
894 case 10:
895 args.v3.ucBitPerColor = PANEL_10BIT_PER_COLOR;
896 break;
897 case 12:
898 args.v3.ucBitPerColor = PANEL_12BIT_PER_COLOR;
899 break;
900 case 16:
901 args.v3.ucBitPerColor = PANEL_16BIT_PER_COLOR;
902 break;
903 }
904 } else {
905 if ((args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP) && (dp_clock == 270000))
906 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
907 switch (radeon_encoder->encoder_id) {
908 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
909 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1;
910 break;
911 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
912 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
913 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2;
914 break;
915 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
916 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3;
917 break;
918 }
919 if (dig->linkb)
920 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
921 else
922 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
923 }
924
925 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
926
927}
928
929union dig_transmitter_control {
930 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1;
931 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
932 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3;
933 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4;
934};
935
936void
937atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set)
938{
939 struct drm_device *dev = encoder->dev;
940 struct radeon_device *rdev = dev->dev_private;
941 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
942 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
943 struct drm_connector *connector;
944 union dig_transmitter_control args;
945 int index = 0;
946 uint8_t frev, crev;
947 bool is_dp = false;
948 int pll_id = 0;
949 int dp_clock = 0;
950 int dp_lane_count = 0;
951 int connector_object_id = 0;
952 int igp_lane_info = 0;
953 int dig_encoder = dig->dig_encoder;
954
955 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
956 connector = radeon_get_connector_for_encoder_init(encoder);
957 /* just needed to avoid bailing in the encoder check. the encoder
958 * isn't used for init
959 */
960 dig_encoder = 0;
961 } else
962 connector = radeon_get_connector_for_encoder(encoder);
963
964 if (connector) {
965 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
966 struct radeon_connector_atom_dig *dig_connector =
967 radeon_connector->con_priv;
968
969 dp_clock = dig_connector->dp_clock;
970 dp_lane_count = dig_connector->dp_lane_count;
971 connector_object_id =
972 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
973 igp_lane_info = dig_connector->igp_lane_info;
974 }
975
976 /* no dig encoder assigned */
977 if (dig_encoder == -1)
978 return;
979
980 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP)
981 is_dp = true;
982
983 memset(&args, 0, sizeof(args));
984
985 switch (radeon_encoder->encoder_id) {
986 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
987 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
988 break;
989 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
990 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
991 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
992 index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
993 break;
994 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
995 index = GetIndexIntoMasterTable(COMMAND, LVTMATransmitterControl);
996 break;
997 }
998
999 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1000 return;
1001
1002 args.v1.ucAction = action;
1003 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1004 args.v1.usInitInfo = cpu_to_le16(connector_object_id);
1005 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1006 args.v1.asMode.ucLaneSel = lane_num;
1007 args.v1.asMode.ucLaneSet = lane_set;
1008 } else {
1009 if (is_dp)
1010 args.v1.usPixelClock =
1011 cpu_to_le16(dp_clock / 10);
1012 else if (radeon_encoder->pixel_clock > 165000)
1013 args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1014 else
1015 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1016 }
1017 if (ASIC_IS_DCE4(rdev)) {
1018 if (is_dp)
1019 args.v3.ucLaneNum = dp_lane_count;
1020 else if (radeon_encoder->pixel_clock > 165000)
1021 args.v3.ucLaneNum = 8;
1022 else
1023 args.v3.ucLaneNum = 4;
1024
1025 if (dig->linkb)
1026 args.v3.acConfig.ucLinkSel = 1;
1027 if (dig_encoder & 1)
1028 args.v3.acConfig.ucEncoderSel = 1;
1029
1030 /* Select the PLL for the PHY
1031 * DP PHY should be clocked from external src if there is
1032 * one.
1033 */
1034 if (encoder->crtc) {
1035 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1036 pll_id = radeon_crtc->pll_id;
1037 }
1038
1039 if (ASIC_IS_DCE5(rdev)) {
1040 /* On DCE5 DCPLL usually generates the DP ref clock */
1041 if (is_dp) {
1042 if (rdev->clock.dp_extclk)
1043 args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_EXTCLK;
1044 else
1045 args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_DCPLL;
1046 } else
1047 args.v4.acConfig.ucRefClkSource = pll_id;
1048 } else {
1049 /* On DCE4, if there is an external clock, it generates the DP ref clock */
1050 if (is_dp && rdev->clock.dp_extclk)
1051 args.v3.acConfig.ucRefClkSource = 2; /* external src */
1052 else
1053 args.v3.acConfig.ucRefClkSource = pll_id;
1054 }
1055
1056 switch (radeon_encoder->encoder_id) {
1057 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1058 args.v3.acConfig.ucTransmitterSel = 0;
1059 break;
1060 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1061 args.v3.acConfig.ucTransmitterSel = 1;
1062 break;
1063 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1064 args.v3.acConfig.ucTransmitterSel = 2;
1065 break;
1066 }
1067
1068 if (is_dp)
1069 args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */
1070 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1071 if (dig->coherent_mode)
1072 args.v3.acConfig.fCoherentMode = 1;
1073 if (radeon_encoder->pixel_clock > 165000)
1074 args.v3.acConfig.fDualLinkConnector = 1;
1075 }
1076 } else if (ASIC_IS_DCE32(rdev)) {
1077 args.v2.acConfig.ucEncoderSel = dig_encoder;
1078 if (dig->linkb)
1079 args.v2.acConfig.ucLinkSel = 1;
1080
1081 switch (radeon_encoder->encoder_id) {
1082 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1083 args.v2.acConfig.ucTransmitterSel = 0;
1084 break;
1085 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1086 args.v2.acConfig.ucTransmitterSel = 1;
1087 break;
1088 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1089 args.v2.acConfig.ucTransmitterSel = 2;
1090 break;
1091 }
1092
1093 if (is_dp) {
1094 args.v2.acConfig.fCoherentMode = 1;
1095 args.v2.acConfig.fDPConnector = 1;
1096 } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1097 if (dig->coherent_mode)
1098 args.v2.acConfig.fCoherentMode = 1;
1099 if (radeon_encoder->pixel_clock > 165000)
1100 args.v2.acConfig.fDualLinkConnector = 1;
1101 }
1102 } else {
1103 args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL;
1104
1105 if (dig_encoder)
1106 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
1107 else
1108 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
1109
1110 if ((rdev->flags & RADEON_IS_IGP) &&
1111 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) {
1112 if (is_dp || (radeon_encoder->pixel_clock <= 165000)) {
1113 if (igp_lane_info & 0x1)
1114 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3;
1115 else if (igp_lane_info & 0x2)
1116 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7;
1117 else if (igp_lane_info & 0x4)
1118 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11;
1119 else if (igp_lane_info & 0x8)
1120 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15;
1121 } else {
1122 if (igp_lane_info & 0x3)
1123 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7;
1124 else if (igp_lane_info & 0xc)
1125 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15;
1126 }
1127 }
1128
1129 if (dig->linkb)
1130 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB;
1131 else
1132 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
1133
1134 if (is_dp)
1135 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
1136 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1137 if (dig->coherent_mode)
1138 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
1139 if (radeon_encoder->pixel_clock > 165000)
1140 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK;
1141 }
1142 }
1143
1144 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1145}
1146
1147bool
1148atombios_set_edp_panel_power(struct drm_connector *connector, int action)
1149{
1150 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1151 struct drm_device *dev = radeon_connector->base.dev;
1152 struct radeon_device *rdev = dev->dev_private;
1153 union dig_transmitter_control args;
1154 int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
1155 uint8_t frev, crev;
1156
1157 if (connector->connector_type != DRM_MODE_CONNECTOR_eDP)
1158 goto done;
1159
1160 if (!ASIC_IS_DCE4(rdev))
1161 goto done;
1162
1163 if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) &&
1164 (action != ATOM_TRANSMITTER_ACTION_POWER_OFF))
1165 goto done;
1166
1167 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1168 goto done;
1169
1170 memset(&args, 0, sizeof(args));
1171
1172 args.v1.ucAction = action;
1173
1174 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1175
1176 /* wait for the panel to power up */
1177 if (action == ATOM_TRANSMITTER_ACTION_POWER_ON) {
1178 int i;
1179
1180 for (i = 0; i < 300; i++) {
1181 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1182 return true;
1183 mdelay(1);
1184 }
1185 return false;
1186 }
1187done:
1188 return true;
1189}
1190
1191union external_encoder_control {
1192 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1;
1193 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3;
1194};
1195
1196static void
1197atombios_external_encoder_setup(struct drm_encoder *encoder,
1198 struct drm_encoder *ext_encoder,
1199 int action)
1200{
1201 struct drm_device *dev = encoder->dev;
1202 struct radeon_device *rdev = dev->dev_private;
1203 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1204 struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder);
1205 union external_encoder_control args;
1206 struct drm_connector *connector;
1207 int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl);
1208 u8 frev, crev;
1209 int dp_clock = 0;
1210 int dp_lane_count = 0;
1211 int connector_object_id = 0;
1212 u32 ext_enum = (ext_radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
1213 int bpc = 8;
1214
1215 if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
1216 connector = radeon_get_connector_for_encoder_init(encoder);
1217 else
1218 connector = radeon_get_connector_for_encoder(encoder);
1219
1220 if (connector) {
1221 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1222 struct radeon_connector_atom_dig *dig_connector =
1223 radeon_connector->con_priv;
1224
1225 dp_clock = dig_connector->dp_clock;
1226 dp_lane_count = dig_connector->dp_lane_count;
1227 connector_object_id =
1228 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
1229 bpc = connector->display_info.bpc;
1230 }
1231
1232 memset(&args, 0, sizeof(args));
1233
1234 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1235 return;
1236
1237 switch (frev) {
1238 case 1:
1239 /* no params on frev 1 */
1240 break;
1241 case 2:
1242 switch (crev) {
1243 case 1:
1244 case 2:
1245 args.v1.sDigEncoder.ucAction = action;
1246 args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1247 args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1248
1249 if (args.v1.sDigEncoder.ucEncoderMode == ATOM_ENCODER_MODE_DP) {
1250 if (dp_clock == 270000)
1251 args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
1252 args.v1.sDigEncoder.ucLaneNum = dp_lane_count;
1253 } else if (radeon_encoder->pixel_clock > 165000)
1254 args.v1.sDigEncoder.ucLaneNum = 8;
1255 else
1256 args.v1.sDigEncoder.ucLaneNum = 4;
1257 break;
1258 case 3:
1259 args.v3.sExtEncoder.ucAction = action;
1260 if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
1261 args.v3.sExtEncoder.usConnectorId = cpu_to_le16(connector_object_id);
1262 else
1263 args.v3.sExtEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1264 args.v3.sExtEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1265
1266 if (args.v3.sExtEncoder.ucEncoderMode == ATOM_ENCODER_MODE_DP) {
1267 if (dp_clock == 270000)
1268 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
1269 else if (dp_clock == 540000)
1270 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ;
1271 args.v3.sExtEncoder.ucLaneNum = dp_lane_count;
1272 } else if (radeon_encoder->pixel_clock > 165000)
1273 args.v3.sExtEncoder.ucLaneNum = 8;
1274 else
1275 args.v3.sExtEncoder.ucLaneNum = 4;
1276 switch (ext_enum) {
1277 case GRAPH_OBJECT_ENUM_ID1:
1278 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1;
1279 break;
1280 case GRAPH_OBJECT_ENUM_ID2:
1281 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2;
1282 break;
1283 case GRAPH_OBJECT_ENUM_ID3:
1284 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3;
1285 break;
1286 }
1287 switch (bpc) {
1288 case 0:
1289 args.v3.sExtEncoder.ucBitPerColor = PANEL_BPC_UNDEFINE;
1290 break;
1291 case 6:
1292 args.v3.sExtEncoder.ucBitPerColor = PANEL_6BIT_PER_COLOR;
1293 break;
1294 case 8:
1295 default:
1296 args.v3.sExtEncoder.ucBitPerColor = PANEL_8BIT_PER_COLOR;
1297 break;
1298 case 10:
1299 args.v3.sExtEncoder.ucBitPerColor = PANEL_10BIT_PER_COLOR;
1300 break;
1301 case 12:
1302 args.v3.sExtEncoder.ucBitPerColor = PANEL_12BIT_PER_COLOR;
1303 break;
1304 case 16:
1305 args.v3.sExtEncoder.ucBitPerColor = PANEL_16BIT_PER_COLOR;
1306 break;
1307 }
1308 break;
1309 default:
1310 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1311 return;
1312 }
1313 break;
1314 default:
1315 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1316 return;
1317 }
1318 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1319}
1320
1321static void
1322atombios_yuv_setup(struct drm_encoder *encoder, bool enable)
1323{
1324 struct drm_device *dev = encoder->dev;
1325 struct radeon_device *rdev = dev->dev_private;
1326 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1327 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1328 ENABLE_YUV_PS_ALLOCATION args;
1329 int index = GetIndexIntoMasterTable(COMMAND, EnableYUV);
1330 uint32_t temp, reg;
1331
1332 memset(&args, 0, sizeof(args));
1333
1334 if (rdev->family >= CHIP_R600)
1335 reg = R600_BIOS_3_SCRATCH;
1336 else
1337 reg = RADEON_BIOS_3_SCRATCH;
1338
1339 /* XXX: fix up scratch reg handling */
1340 temp = RREG32(reg);
1341 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1342 WREG32(reg, (ATOM_S3_TV1_ACTIVE |
1343 (radeon_crtc->crtc_id << 18)));
1344 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1345 WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24)));
1346 else
1347 WREG32(reg, 0);
1348
1349 if (enable)
1350 args.ucEnable = ATOM_ENABLE;
1351 args.ucCRTC = radeon_crtc->crtc_id;
1352
1353 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1354
1355 WREG32(reg, temp);
1356}
1357
1358static void
1359radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1360{
1361 struct drm_device *dev = encoder->dev;
1362 struct radeon_device *rdev = dev->dev_private;
1363 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1364 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
1365 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
1366 int index = 0;
1367 bool is_dig = false;
1368 bool is_dce5_dac = false;
1369 bool is_dce5_dvo = false;
1370
1371 memset(&args, 0, sizeof(args));
1372
1373 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
1374 radeon_encoder->encoder_id, mode, radeon_encoder->devices,
1375 radeon_encoder->active_device);
1376 switch (radeon_encoder->encoder_id) {
1377 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1378 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1379 index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl);
1380 break;
1381 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1382 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1383 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1384 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1385 is_dig = true;
1386 break;
1387 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1388 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1389 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
1390 break;
1391 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1392 if (ASIC_IS_DCE5(rdev))
1393 is_dce5_dvo = true;
1394 else if (ASIC_IS_DCE3(rdev))
1395 is_dig = true;
1396 else
1397 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
1398 break;
1399 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1400 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1401 break;
1402 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1403 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1404 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1405 else
1406 index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl);
1407 break;
1408 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1409 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1410 if (ASIC_IS_DCE5(rdev))
1411 is_dce5_dac = true;
1412 else {
1413 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1414 index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
1415 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1416 index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
1417 else
1418 index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl);
1419 }
1420 break;
1421 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1422 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1423 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1424 index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
1425 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1426 index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
1427 else
1428 index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl);
1429 break;
1430 }
1431
1432 if (is_dig) {
1433 switch (mode) {
1434 case DRM_MODE_DPMS_ON:
1435 /* some early dce3.2 boards have a bug in their transmitter control table */
1436 if ((rdev->family == CHIP_RV710) || (rdev->family == CHIP_RV730))
1437 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1438 else
1439 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
1440 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) {
1441 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1442
1443 if (connector &&
1444 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
1445 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1446 struct radeon_connector_atom_dig *radeon_dig_connector =
1447 radeon_connector->con_priv;
1448 atombios_set_edp_panel_power(connector,
1449 ATOM_TRANSMITTER_ACTION_POWER_ON);
1450 radeon_dig_connector->edp_on = true;
1451 }
1452 if (ASIC_IS_DCE4(rdev))
1453 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
1454 radeon_dp_link_train(encoder, connector);
1455 if (ASIC_IS_DCE4(rdev))
1456 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0);
1457 }
1458 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1459 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
1460 break;
1461 case DRM_MODE_DPMS_STANDBY:
1462 case DRM_MODE_DPMS_SUSPEND:
1463 case DRM_MODE_DPMS_OFF:
1464 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
1465 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) {
1466 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1467
1468 if (ASIC_IS_DCE4(rdev))
1469 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
1470 if (connector &&
1471 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
1472 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1473 struct radeon_connector_atom_dig *radeon_dig_connector =
1474 radeon_connector->con_priv;
1475 atombios_set_edp_panel_power(connector,
1476 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1477 radeon_dig_connector->edp_on = false;
1478 }
1479 }
1480 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1481 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
1482 break;
1483 }
1484 } else if (is_dce5_dac) {
1485 switch (mode) {
1486 case DRM_MODE_DPMS_ON:
1487 atombios_dac_setup(encoder, ATOM_ENABLE);
1488 break;
1489 case DRM_MODE_DPMS_STANDBY:
1490 case DRM_MODE_DPMS_SUSPEND:
1491 case DRM_MODE_DPMS_OFF:
1492 atombios_dac_setup(encoder, ATOM_DISABLE);
1493 break;
1494 }
1495 } else if (is_dce5_dvo) {
1496 switch (mode) {
1497 case DRM_MODE_DPMS_ON:
1498 atombios_dvo_setup(encoder, ATOM_ENABLE);
1499 break;
1500 case DRM_MODE_DPMS_STANDBY:
1501 case DRM_MODE_DPMS_SUSPEND:
1502 case DRM_MODE_DPMS_OFF:
1503 atombios_dvo_setup(encoder, ATOM_DISABLE);
1504 break;
1505 }
1506 } else {
1507 switch (mode) {
1508 case DRM_MODE_DPMS_ON:
1509 args.ucAction = ATOM_ENABLE;
1510 /* workaround for DVOOutputControl on some RS690 systems */
1511 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DDI) {
1512 u32 reg = RREG32(RADEON_BIOS_3_SCRATCH);
1513 WREG32(RADEON_BIOS_3_SCRATCH, reg & ~ATOM_S3_DFP2I_ACTIVE);
1514 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1515 WREG32(RADEON_BIOS_3_SCRATCH, reg);
1516 } else
1517 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1518 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1519 args.ucAction = ATOM_LCD_BLON;
1520 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1521 }
1522 break;
1523 case DRM_MODE_DPMS_STANDBY:
1524 case DRM_MODE_DPMS_SUSPEND:
1525 case DRM_MODE_DPMS_OFF:
1526 args.ucAction = ATOM_DISABLE;
1527 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1528 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1529 args.ucAction = ATOM_LCD_BLOFF;
1530 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1531 }
1532 break;
1533 }
1534 }
1535
1536 if (ext_encoder) {
1537 switch (mode) {
1538 case DRM_MODE_DPMS_ON:
1539 default:
1540 if (ASIC_IS_DCE41(rdev)) {
1541 atombios_external_encoder_setup(encoder, ext_encoder,
1542 EXTERNAL_ENCODER_ACTION_V3_ENABLE_OUTPUT);
1543 atombios_external_encoder_setup(encoder, ext_encoder,
1544 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING_OFF);
1545 } else
1546 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
1547 break;
1548 case DRM_MODE_DPMS_STANDBY:
1549 case DRM_MODE_DPMS_SUSPEND:
1550 case DRM_MODE_DPMS_OFF:
1551 if (ASIC_IS_DCE41(rdev)) {
1552 atombios_external_encoder_setup(encoder, ext_encoder,
1553 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING);
1554 atombios_external_encoder_setup(encoder, ext_encoder,
1555 EXTERNAL_ENCODER_ACTION_V3_DISABLE_OUTPUT);
1556 } else
1557 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_DISABLE);
1558 break;
1559 }
1560 }
1561
1562 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
1563
1564}
1565
1566union crtc_source_param {
1567 SELECT_CRTC_SOURCE_PS_ALLOCATION v1;
1568 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2;
1569};
1570
1571static void
1572atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
1573{
1574 struct drm_device *dev = encoder->dev;
1575 struct radeon_device *rdev = dev->dev_private;
1576 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1577 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1578 union crtc_source_param args;
1579 int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source);
1580 uint8_t frev, crev;
1581 struct radeon_encoder_atom_dig *dig;
1582
1583 memset(&args, 0, sizeof(args));
1584
1585 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1586 return;
1587
1588 switch (frev) {
1589 case 1:
1590 switch (crev) {
1591 case 1:
1592 default:
1593 if (ASIC_IS_AVIVO(rdev))
1594 args.v1.ucCRTC = radeon_crtc->crtc_id;
1595 else {
1596 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) {
1597 args.v1.ucCRTC = radeon_crtc->crtc_id;
1598 } else {
1599 args.v1.ucCRTC = radeon_crtc->crtc_id << 2;
1600 }
1601 }
1602 switch (radeon_encoder->encoder_id) {
1603 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1604 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1605 args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX;
1606 break;
1607 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1608 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1609 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT)
1610 args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX;
1611 else
1612 args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX;
1613 break;
1614 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1615 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1616 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1617 args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX;
1618 break;
1619 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1620 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1621 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1622 args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
1623 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1624 args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
1625 else
1626 args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX;
1627 break;
1628 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1629 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1630 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1631 args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
1632 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1633 args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
1634 else
1635 args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX;
1636 break;
1637 }
1638 break;
1639 case 2:
1640 args.v2.ucCRTC = radeon_crtc->crtc_id;
1641 if (radeon_encoder_is_dp_bridge(encoder)) {
1642 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1643
1644 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
1645 args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
1646 else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
1647 args.v2.ucEncodeMode = ATOM_ENCODER_MODE_CRT;
1648 else
1649 args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
1650 } else
1651 args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
1652 switch (radeon_encoder->encoder_id) {
1653 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1654 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1655 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1656 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1657 dig = radeon_encoder->enc_priv;
1658 switch (dig->dig_encoder) {
1659 case 0:
1660 args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
1661 break;
1662 case 1:
1663 args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
1664 break;
1665 case 2:
1666 args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID;
1667 break;
1668 case 3:
1669 args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID;
1670 break;
1671 case 4:
1672 args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID;
1673 break;
1674 case 5:
1675 args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID;
1676 break;
1677 }
1678 break;
1679 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1680 args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID;
1681 break;
1682 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1683 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1684 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1685 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1686 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1687 else
1688 args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID;
1689 break;
1690 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1691 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1692 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1693 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1694 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1695 else
1696 args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID;
1697 break;
1698 }
1699 break;
1700 }
1701 break;
1702 default:
1703 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1704 return;
1705 }
1706
1707 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1708
1709 /* update scratch regs with new routing */
1710 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1711}
1712
1713static void
1714atombios_apply_encoder_quirks(struct drm_encoder *encoder,
1715 struct drm_display_mode *mode)
1716{
1717 struct drm_device *dev = encoder->dev;
1718 struct radeon_device *rdev = dev->dev_private;
1719 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1720 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1721
1722 /* Funky macbooks */
1723 if ((dev->pdev->device == 0x71C5) &&
1724 (dev->pdev->subsystem_vendor == 0x106b) &&
1725 (dev->pdev->subsystem_device == 0x0080)) {
1726 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1727 uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL);
1728
1729 lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN;
1730 lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN;
1731
1732 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control);
1733 }
1734 }
1735
1736 /* set scaler clears this on some chips */
1737 if (ASIC_IS_AVIVO(rdev) &&
1738 (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)))) {
1739 if (ASIC_IS_DCE4(rdev)) {
1740 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1741 WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset,
1742 EVERGREEN_INTERLEAVE_EN);
1743 else
1744 WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1745 } else {
1746 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1747 WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset,
1748 AVIVO_D1MODE_INTERLEAVE_EN);
1749 else
1750 WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1751 }
1752 }
1753}
1754
1755static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder)
1756{
1757 struct drm_device *dev = encoder->dev;
1758 struct radeon_device *rdev = dev->dev_private;
1759 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1760 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1761 struct drm_encoder *test_encoder;
1762 struct radeon_encoder_atom_dig *dig;
1763 uint32_t dig_enc_in_use = 0;
1764
1765 /* DCE4/5 */
1766 if (ASIC_IS_DCE4(rdev)) {
1767 dig = radeon_encoder->enc_priv;
1768 if (ASIC_IS_DCE41(rdev)) {
1769 /* ontario follows DCE4 */
1770 if (rdev->family == CHIP_PALM) {
1771 if (dig->linkb)
1772 return 1;
1773 else
1774 return 0;
1775 } else
1776 /* llano follows DCE3.2 */
1777 return radeon_crtc->crtc_id;
1778 } else {
1779 switch (radeon_encoder->encoder_id) {
1780 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1781 if (dig->linkb)
1782 return 1;
1783 else
1784 return 0;
1785 break;
1786 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1787 if (dig->linkb)
1788 return 3;
1789 else
1790 return 2;
1791 break;
1792 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1793 if (dig->linkb)
1794 return 5;
1795 else
1796 return 4;
1797 break;
1798 }
1799 }
1800 }
1801
1802 /* on DCE32 and encoder can driver any block so just crtc id */
1803 if (ASIC_IS_DCE32(rdev)) {
1804 return radeon_crtc->crtc_id;
1805 }
1806
1807 /* on DCE3 - LVTMA can only be driven by DIGB */
1808 list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
1809 struct radeon_encoder *radeon_test_encoder;
1810
1811 if (encoder == test_encoder)
1812 continue;
1813
1814 if (!radeon_encoder_is_digital(test_encoder))
1815 continue;
1816
1817 radeon_test_encoder = to_radeon_encoder(test_encoder);
1818 dig = radeon_test_encoder->enc_priv;
1819
1820 if (dig->dig_encoder >= 0)
1821 dig_enc_in_use |= (1 << dig->dig_encoder);
1822 }
1823
1824 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA) {
1825 if (dig_enc_in_use & 0x2)
1826 DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
1827 return 1;
1828 }
1829 if (!(dig_enc_in_use & 1))
1830 return 0;
1831 return 1;
1832}
1833
1834/* This only needs to be called once at startup */
1835void
1836radeon_atom_encoder_init(struct radeon_device *rdev)
1837{
1838 struct drm_device *dev = rdev->ddev;
1839 struct drm_encoder *encoder;
1840
1841 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1842 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1843 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
1844
1845 switch (radeon_encoder->encoder_id) {
1846 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1847 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1848 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1849 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1850 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0);
1851 break;
1852 default:
1853 break;
1854 }
1855
1856 if (ext_encoder && ASIC_IS_DCE41(rdev))
1857 atombios_external_encoder_setup(encoder, ext_encoder,
1858 EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT);
1859 }
1860}
1861
1862static void
1863radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
1864 struct drm_display_mode *mode,
1865 struct drm_display_mode *adjusted_mode)
1866{
1867 struct drm_device *dev = encoder->dev;
1868 struct radeon_device *rdev = dev->dev_private;
1869 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1870 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
1871
1872 radeon_encoder->pixel_clock = adjusted_mode->clock;
1873
1874 if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) {
1875 if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT))
1876 atombios_yuv_setup(encoder, true);
1877 else
1878 atombios_yuv_setup(encoder, false);
1879 }
1880
1881 switch (radeon_encoder->encoder_id) {
1882 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1883 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1884 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1885 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1886 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
1887 break;
1888 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1889 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1890 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1891 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1892 if (ASIC_IS_DCE4(rdev)) {
1893 /* disable the transmitter */
1894 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
1895 /* setup and enable the encoder */
1896 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
1897
1898 /* enable the transmitter */
1899 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1900 } else {
1901 /* disable the encoder and transmitter */
1902 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
1903 atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
1904
1905 /* setup and enable the encoder and transmitter */
1906 atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0);
1907 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0);
1908 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1909 }
1910 break;
1911 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1912 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1913 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1914 atombios_dvo_setup(encoder, ATOM_ENABLE);
1915 break;
1916 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1917 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1918 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1919 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1920 atombios_dac_setup(encoder, ATOM_ENABLE);
1921 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) {
1922 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
1923 atombios_tv_setup(encoder, ATOM_ENABLE);
1924 else
1925 atombios_tv_setup(encoder, ATOM_DISABLE);
1926 }
1927 break;
1928 }
1929
1930 if (ext_encoder) {
1931 if (ASIC_IS_DCE41(rdev))
1932 atombios_external_encoder_setup(encoder, ext_encoder,
1933 EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP);
1934 else
1935 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
1936 }
1937
1938 atombios_apply_encoder_quirks(encoder, adjusted_mode);
1939
1940 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
1941 r600_hdmi_enable(encoder);
1942 r600_hdmi_setmode(encoder, adjusted_mode);
1943 }
1944}
1945
1946static bool
1947atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector)
1948{
1949 struct drm_device *dev = encoder->dev;
1950 struct radeon_device *rdev = dev->dev_private;
1951 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1952 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1953
1954 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT |
1955 ATOM_DEVICE_CV_SUPPORT |
1956 ATOM_DEVICE_CRT_SUPPORT)) {
1957 DAC_LOAD_DETECTION_PS_ALLOCATION args;
1958 int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection);
1959 uint8_t frev, crev;
1960
1961 memset(&args, 0, sizeof(args));
1962
1963 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1964 return false;
1965
1966 args.sDacload.ucMisc = 0;
1967
1968 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) ||
1969 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1))
1970 args.sDacload.ucDacType = ATOM_DAC_A;
1971 else
1972 args.sDacload.ucDacType = ATOM_DAC_B;
1973
1974 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)
1975 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT);
1976 else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)
1977 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT);
1978 else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
1979 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT);
1980 if (crev >= 3)
1981 args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
1982 } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
1983 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT);
1984 if (crev >= 3)
1985 args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
1986 }
1987
1988 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1989
1990 return true;
1991 } else
1992 return false;
1993}
1994
1995static enum drm_connector_status
1996radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
1997{
1998 struct drm_device *dev = encoder->dev;
1999 struct radeon_device *rdev = dev->dev_private;
2000 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2001 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2002 uint32_t bios_0_scratch;
2003
2004 if (!atombios_dac_load_detect(encoder, connector)) {
2005 DRM_DEBUG_KMS("detect returned false \n");
2006 return connector_status_unknown;
2007 }
2008
2009 if (rdev->family >= CHIP_R600)
2010 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2011 else
2012 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2013
2014 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
2015 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2016 if (bios_0_scratch & ATOM_S0_CRT1_MASK)
2017 return connector_status_connected;
2018 }
2019 if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2020 if (bios_0_scratch & ATOM_S0_CRT2_MASK)
2021 return connector_status_connected;
2022 }
2023 if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
2024 if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
2025 return connector_status_connected;
2026 }
2027 if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
2028 if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
2029 return connector_status_connected; /* CTV */
2030 else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
2031 return connector_status_connected; /* STV */
2032 }
2033 return connector_status_disconnected;
2034}
2035
2036static enum drm_connector_status
2037radeon_atom_dig_detect(struct drm_encoder *encoder, struct drm_connector *connector)
2038{
2039 struct drm_device *dev = encoder->dev;
2040 struct radeon_device *rdev = dev->dev_private;
2041 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2042 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2043 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
2044 u32 bios_0_scratch;
2045
2046 if (!ASIC_IS_DCE4(rdev))
2047 return connector_status_unknown;
2048
2049 if (!ext_encoder)
2050 return connector_status_unknown;
2051
2052 if ((radeon_connector->devices & ATOM_DEVICE_CRT_SUPPORT) == 0)
2053 return connector_status_unknown;
2054
2055 /* load detect on the dp bridge */
2056 atombios_external_encoder_setup(encoder, ext_encoder,
2057 EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION);
2058
2059 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2060
2061 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
2062 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2063 if (bios_0_scratch & ATOM_S0_CRT1_MASK)
2064 return connector_status_connected;
2065 }
2066 if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2067 if (bios_0_scratch & ATOM_S0_CRT2_MASK)
2068 return connector_status_connected;
2069 }
2070 if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
2071 if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
2072 return connector_status_connected;
2073 }
2074 if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
2075 if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
2076 return connector_status_connected; /* CTV */
2077 else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
2078 return connector_status_connected; /* STV */
2079 }
2080 return connector_status_disconnected;
2081}
2082
2083void
2084radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder)
2085{
2086 struct drm_encoder *ext_encoder = radeon_atom_get_external_encoder(encoder);
2087
2088 if (ext_encoder)
2089 /* ddc_setup on the dp bridge */
2090 atombios_external_encoder_setup(encoder, ext_encoder,
2091 EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP);
2092
2093}
2094
2095static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
2096{
2097 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2098 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
2099
2100 if ((radeon_encoder->active_device &
2101 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
2102 radeon_encoder_is_dp_bridge(encoder)) {
2103 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
2104 if (dig)
2105 dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder);
2106 }
2107
2108 radeon_atom_output_lock(encoder, true);
2109 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2110
2111 if (connector) {
2112 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2113
2114 /* select the clock/data port if it uses a router */
2115 if (radeon_connector->router.cd_valid)
2116 radeon_router_select_cd_port(radeon_connector);
2117
2118 /* turn eDP panel on for mode set */
2119 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
2120 atombios_set_edp_panel_power(connector,
2121 ATOM_TRANSMITTER_ACTION_POWER_ON);
2122 }
2123
2124 /* this is needed for the pll/ss setup to work correctly in some cases */
2125 atombios_set_encoder_crtc_source(encoder);
2126}
2127
2128static void radeon_atom_encoder_commit(struct drm_encoder *encoder)
2129{
2130 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
2131 radeon_atom_output_lock(encoder, false);
2132}
2133
2134static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
2135{
2136 struct drm_device *dev = encoder->dev;
2137 struct radeon_device *rdev = dev->dev_private;
2138 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2139 struct radeon_encoder_atom_dig *dig;
2140
2141 /* check for pre-DCE3 cards with shared encoders;
2142 * can't really use the links individually, so don't disable
2143 * the encoder if it's in use by another connector
2144 */
2145 if (!ASIC_IS_DCE3(rdev)) {
2146 struct drm_encoder *other_encoder;
2147 struct radeon_encoder *other_radeon_encoder;
2148
2149 list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
2150 other_radeon_encoder = to_radeon_encoder(other_encoder);
2151 if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) &&
2152 drm_helper_encoder_in_use(other_encoder))
2153 goto disable_done;
2154 }
2155 }
2156
2157 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2158
2159 switch (radeon_encoder->encoder_id) {
2160 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2161 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2162 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2163 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2164 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_DISABLE);
2165 break;
2166 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2167 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2168 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2169 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
2170 if (ASIC_IS_DCE4(rdev))
2171 /* disable the transmitter */
2172 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
2173 else {
2174 /* disable the encoder and transmitter */
2175 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
2176 atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
2177 }
2178 break;
2179 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2180 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2181 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2182 atombios_dvo_setup(encoder, ATOM_DISABLE);
2183 break;
2184 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2185 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2186 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2187 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2188 atombios_dac_setup(encoder, ATOM_DISABLE);
2189 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
2190 atombios_tv_setup(encoder, ATOM_DISABLE);
2191 break;
2192 }
2193
2194disable_done:
2195 if (radeon_encoder_is_digital(encoder)) {
2196 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
2197 r600_hdmi_disable(encoder);
2198 dig = radeon_encoder->enc_priv;
2199 dig->dig_encoder = -1;
2200 }
2201 radeon_encoder->active_device = 0;
2202}
2203
2204/* these are handled by the primary encoders */
2205static void radeon_atom_ext_prepare(struct drm_encoder *encoder)
2206{
2207
2208}
2209
2210static void radeon_atom_ext_commit(struct drm_encoder *encoder)
2211{
2212
2213}
2214
2215static void
2216radeon_atom_ext_mode_set(struct drm_encoder *encoder,
2217 struct drm_display_mode *mode,
2218 struct drm_display_mode *adjusted_mode)
2219{
2220
2221}
2222
2223static void radeon_atom_ext_disable(struct drm_encoder *encoder)
2224{
2225
2226}
2227
2228static void
2229radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode)
2230{
2231
2232}
2233
2234static bool radeon_atom_ext_mode_fixup(struct drm_encoder *encoder,
2235 struct drm_display_mode *mode,
2236 struct drm_display_mode *adjusted_mode)
2237{
2238 return true;
2239}
2240
2241static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = {
2242 .dpms = radeon_atom_ext_dpms,
2243 .mode_fixup = radeon_atom_ext_mode_fixup,
2244 .prepare = radeon_atom_ext_prepare,
2245 .mode_set = radeon_atom_ext_mode_set,
2246 .commit = radeon_atom_ext_commit,
2247 .disable = radeon_atom_ext_disable,
2248 /* no detect for TMDS/LVDS yet */
2249};
2250
2251static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = {
2252 .dpms = radeon_atom_encoder_dpms,
2253 .mode_fixup = radeon_atom_mode_fixup,
2254 .prepare = radeon_atom_encoder_prepare,
2255 .mode_set = radeon_atom_encoder_mode_set,
2256 .commit = radeon_atom_encoder_commit,
2257 .disable = radeon_atom_encoder_disable,
2258 .detect = radeon_atom_dig_detect,
2259};
2260
2261static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = {
2262 .dpms = radeon_atom_encoder_dpms,
2263 .mode_fixup = radeon_atom_mode_fixup,
2264 .prepare = radeon_atom_encoder_prepare,
2265 .mode_set = radeon_atom_encoder_mode_set,
2266 .commit = radeon_atom_encoder_commit,
2267 .detect = radeon_atom_dac_detect,
2268};
2269
2270void radeon_enc_destroy(struct drm_encoder *encoder)
2271{
2272 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2273 kfree(radeon_encoder->enc_priv);
2274 drm_encoder_cleanup(encoder);
2275 kfree(radeon_encoder);
2276}
2277
2278static const struct drm_encoder_funcs radeon_atom_enc_funcs = {
2279 .destroy = radeon_enc_destroy,
2280};
2281
2282struct radeon_encoder_atom_dac *
2283radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder)
2284{
2285 struct drm_device *dev = radeon_encoder->base.dev;
2286 struct radeon_device *rdev = dev->dev_private;
2287 struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL);
2288
2289 if (!dac)
2290 return NULL;
2291
2292 dac->tv_std = radeon_atombios_get_tv_info(rdev);
2293 return dac;
2294}
2295
2296struct radeon_encoder_atom_dig *
2297radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder)
2298{
2299 int encoder_enum = (radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
2300 struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
2301
2302 if (!dig)
2303 return NULL;
2304
2305 /* coherent mode by default */
2306 dig->coherent_mode = true;
2307 dig->dig_encoder = -1;
2308
2309 if (encoder_enum == 2)
2310 dig->linkb = true;
2311 else
2312 dig->linkb = false;
2313
2314 return dig;
2315}
2316
2317void
2318radeon_add_atom_encoder(struct drm_device *dev,
2319 uint32_t encoder_enum,
2320 uint32_t supported_device,
2321 u16 caps)
2322{
2323 struct radeon_device *rdev = dev->dev_private;
2324 struct drm_encoder *encoder;
2325 struct radeon_encoder *radeon_encoder;
2326
2327 /* see if we already added it */
2328 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2329 radeon_encoder = to_radeon_encoder(encoder);
2330 if (radeon_encoder->encoder_enum == encoder_enum) {
2331 radeon_encoder->devices |= supported_device;
2332 return;
2333 }
2334
2335 }
2336
2337 /* add a new one */
2338 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
2339 if (!radeon_encoder)
2340 return;
2341
2342 encoder = &radeon_encoder->base;
2343 switch (rdev->num_crtc) {
2344 case 1:
2345 encoder->possible_crtcs = 0x1;
2346 break;
2347 case 2:
2348 default:
2349 encoder->possible_crtcs = 0x3;
2350 break;
2351 case 4:
2352 encoder->possible_crtcs = 0xf;
2353 break;
2354 case 6:
2355 encoder->possible_crtcs = 0x3f;
2356 break;
2357 }
2358
2359 radeon_encoder->enc_priv = NULL;
2360
2361 radeon_encoder->encoder_enum = encoder_enum;
2362 radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
2363 radeon_encoder->devices = supported_device;
2364 radeon_encoder->rmx_type = RMX_OFF;
2365 radeon_encoder->underscan_type = UNDERSCAN_OFF;
2366 radeon_encoder->is_ext_encoder = false;
2367 radeon_encoder->caps = caps;
2368
2369 switch (radeon_encoder->encoder_id) {
2370 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2371 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2372 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2373 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2374 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2375 radeon_encoder->rmx_type = RMX_FULL;
2376 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2377 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2378 } else {
2379 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2380 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2381 }
2382 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
2383 break;
2384 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2385 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2386 radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
2387 drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
2388 break;
2389 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2390 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2391 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2392 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC);
2393 radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
2394 drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
2395 break;
2396 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2397 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2398 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2399 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2400 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
2401 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2402 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2403 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2404 radeon_encoder->rmx_type = RMX_FULL;
2405 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2406 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2407 } else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
2408 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2409 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2410 } else {
2411 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2412 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2413 }
2414 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
2415 break;
2416 case ENCODER_OBJECT_ID_SI170B:
2417 case ENCODER_OBJECT_ID_CH7303:
2418 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
2419 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
2420 case ENCODER_OBJECT_ID_TITFP513:
2421 case ENCODER_OBJECT_ID_VT1623:
2422 case ENCODER_OBJECT_ID_HDMI_SI1930:
2423 case ENCODER_OBJECT_ID_TRAVIS:
2424 case ENCODER_OBJECT_ID_NUTMEG:
2425 /* these are handled by the primary encoders */
2426 radeon_encoder->is_ext_encoder = true;
2427 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2428 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2429 else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
2430 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2431 else
2432 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2433 drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs);
2434 break;
2435 }
2436}
diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
index fdc3a9a54bf..ba7ab79e12c 100644
--- a/drivers/gpu/drm/radeon/radeon_gart.c
+++ b/drivers/gpu/drm/radeon/radeon_gart.c
@@ -49,27 +49,27 @@ int radeon_gart_table_ram_alloc(struct radeon_device *rdev)
49 rdev->gart.table_size >> PAGE_SHIFT); 49 rdev->gart.table_size >> PAGE_SHIFT);
50 } 50 }
51#endif 51#endif
52 rdev->gart.table.ram.ptr = ptr; 52 rdev->gart.ptr = ptr;
53 memset((void *)rdev->gart.table.ram.ptr, 0, rdev->gart.table_size); 53 memset((void *)rdev->gart.ptr, 0, rdev->gart.table_size);
54 return 0; 54 return 0;
55} 55}
56 56
57void radeon_gart_table_ram_free(struct radeon_device *rdev) 57void radeon_gart_table_ram_free(struct radeon_device *rdev)
58{ 58{
59 if (rdev->gart.table.ram.ptr == NULL) { 59 if (rdev->gart.ptr == NULL) {
60 return; 60 return;
61 } 61 }
62#ifdef CONFIG_X86 62#ifdef CONFIG_X86
63 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480 || 63 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480 ||
64 rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { 64 rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) {
65 set_memory_wb((unsigned long)rdev->gart.table.ram.ptr, 65 set_memory_wb((unsigned long)rdev->gart.ptr,
66 rdev->gart.table_size >> PAGE_SHIFT); 66 rdev->gart.table_size >> PAGE_SHIFT);
67 } 67 }
68#endif 68#endif
69 pci_free_consistent(rdev->pdev, rdev->gart.table_size, 69 pci_free_consistent(rdev->pdev, rdev->gart.table_size,
70 (void *)rdev->gart.table.ram.ptr, 70 (void *)rdev->gart.ptr,
71 rdev->gart.table_addr); 71 rdev->gart.table_addr);
72 rdev->gart.table.ram.ptr = NULL; 72 rdev->gart.ptr = NULL;
73 rdev->gart.table_addr = 0; 73 rdev->gart.table_addr = 0;
74} 74}
75 75
@@ -77,10 +77,10 @@ int radeon_gart_table_vram_alloc(struct radeon_device *rdev)
77{ 77{
78 int r; 78 int r;
79 79
80 if (rdev->gart.table.vram.robj == NULL) { 80 if (rdev->gart.robj == NULL) {
81 r = radeon_bo_create(rdev, rdev->gart.table_size, 81 r = radeon_bo_create(rdev, rdev->gart.table_size,
82 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM, 82 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
83 &rdev->gart.table.vram.robj); 83 &rdev->gart.robj);
84 if (r) { 84 if (r) {
85 return r; 85 return r;
86 } 86 }
@@ -93,38 +93,46 @@ int radeon_gart_table_vram_pin(struct radeon_device *rdev)
93 uint64_t gpu_addr; 93 uint64_t gpu_addr;
94 int r; 94 int r;
95 95
96 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false); 96 r = radeon_bo_reserve(rdev->gart.robj, false);
97 if (unlikely(r != 0)) 97 if (unlikely(r != 0))
98 return r; 98 return r;
99 r = radeon_bo_pin(rdev->gart.table.vram.robj, 99 r = radeon_bo_pin(rdev->gart.robj,
100 RADEON_GEM_DOMAIN_VRAM, &gpu_addr); 100 RADEON_GEM_DOMAIN_VRAM, &gpu_addr);
101 if (r) { 101 if (r) {
102 radeon_bo_unreserve(rdev->gart.table.vram.robj); 102 radeon_bo_unreserve(rdev->gart.robj);
103 return r; 103 return r;
104 } 104 }
105 r = radeon_bo_kmap(rdev->gart.table.vram.robj, 105 r = radeon_bo_kmap(rdev->gart.robj, &rdev->gart.ptr);
106 (void **)&rdev->gart.table.vram.ptr);
107 if (r) 106 if (r)
108 radeon_bo_unpin(rdev->gart.table.vram.robj); 107 radeon_bo_unpin(rdev->gart.robj);
109 radeon_bo_unreserve(rdev->gart.table.vram.robj); 108 radeon_bo_unreserve(rdev->gart.robj);
110 rdev->gart.table_addr = gpu_addr; 109 rdev->gart.table_addr = gpu_addr;
111 return r; 110 return r;
112} 111}
113 112
114void radeon_gart_table_vram_free(struct radeon_device *rdev) 113void radeon_gart_table_vram_unpin(struct radeon_device *rdev)
115{ 114{
116 int r; 115 int r;
117 116
118 if (rdev->gart.table.vram.robj == NULL) { 117 if (rdev->gart.robj == NULL) {
119 return; 118 return;
120 } 119 }
121 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false); 120 r = radeon_bo_reserve(rdev->gart.robj, false);
122 if (likely(r == 0)) { 121 if (likely(r == 0)) {
123 radeon_bo_kunmap(rdev->gart.table.vram.robj); 122 radeon_bo_kunmap(rdev->gart.robj);
124 radeon_bo_unpin(rdev->gart.table.vram.robj); 123 radeon_bo_unpin(rdev->gart.robj);
125 radeon_bo_unreserve(rdev->gart.table.vram.robj); 124 radeon_bo_unreserve(rdev->gart.robj);
125 rdev->gart.ptr = NULL;
126 } 126 }
127 radeon_bo_unref(&rdev->gart.table.vram.robj); 127}
128
129void radeon_gart_table_vram_free(struct radeon_device *rdev)
130{
131 if (rdev->gart.robj == NULL) {
132 return;
133 }
134 radeon_gart_table_vram_unpin(rdev);
135 radeon_bo_unref(&rdev->gart.robj);
128} 136}
129 137
130 138
@@ -151,12 +159,14 @@ void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
151 if (rdev->gart.pages[p]) { 159 if (rdev->gart.pages[p]) {
152 if (!rdev->gart.ttm_alloced[p]) 160 if (!rdev->gart.ttm_alloced[p])
153 pci_unmap_page(rdev->pdev, rdev->gart.pages_addr[p], 161 pci_unmap_page(rdev->pdev, rdev->gart.pages_addr[p],
154 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 162 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
155 rdev->gart.pages[p] = NULL; 163 rdev->gart.pages[p] = NULL;
156 rdev->gart.pages_addr[p] = rdev->dummy_page.addr; 164 rdev->gart.pages_addr[p] = rdev->dummy_page.addr;
157 page_base = rdev->gart.pages_addr[p]; 165 page_base = rdev->gart.pages_addr[p];
158 for (j = 0; j < (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); j++, t++) { 166 for (j = 0; j < (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); j++, t++) {
159 radeon_gart_set_page(rdev, t, page_base); 167 if (rdev->gart.ptr) {
168 radeon_gart_set_page(rdev, t, page_base);
169 }
160 page_base += RADEON_GPU_PAGE_SIZE; 170 page_base += RADEON_GPU_PAGE_SIZE;
161 } 171 }
162 } 172 }
@@ -199,10 +209,12 @@ int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
199 } 209 }
200 } 210 }
201 rdev->gart.pages[p] = pagelist[i]; 211 rdev->gart.pages[p] = pagelist[i];
202 page_base = rdev->gart.pages_addr[p]; 212 if (rdev->gart.ptr) {
203 for (j = 0; j < (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); j++, t++) { 213 page_base = rdev->gart.pages_addr[p];
204 radeon_gart_set_page(rdev, t, page_base); 214 for (j = 0; j < (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); j++, t++) {
205 page_base += RADEON_GPU_PAGE_SIZE; 215 radeon_gart_set_page(rdev, t, page_base);
216 page_base += RADEON_GPU_PAGE_SIZE;
217 }
206 } 218 }
207 } 219 }
208 mb(); 220 mb();
@@ -215,6 +227,9 @@ void radeon_gart_restore(struct radeon_device *rdev)
215 int i, j, t; 227 int i, j, t;
216 u64 page_base; 228 u64 page_base;
217 229
230 if (!rdev->gart.ptr) {
231 return;
232 }
218 for (i = 0, t = 0; i < rdev->gart.num_cpu_pages; i++) { 233 for (i = 0, t = 0; i < rdev->gart.num_cpu_pages; i++) {
219 page_base = rdev->gart.pages_addr[i]; 234 page_base = rdev->gart.pages_addr[i];
220 for (j = 0; j < (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); j++, t++) { 235 for (j = 0; j < (PAGE_SIZE / RADEON_GPU_PAGE_SIZE); j++, t++) {
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 02cb7da4124..7bb1b079f48 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"
@@ -32,7 +34,7 @@
32 * radeon_ddc_probe 34 * radeon_ddc_probe
33 * 35 *
34 */ 36 */
35bool radeon_ddc_probe(struct radeon_connector *radeon_connector, bool requires_extended_probe) 37bool radeon_ddc_probe(struct radeon_connector *radeon_connector)
36{ 38{
37 u8 out = 0x0; 39 u8 out = 0x0;
38 u8 buf[8]; 40 u8 buf[8];
@@ -47,15 +49,11 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector, bool requires_e
47 { 49 {
48 .addr = 0x50, 50 .addr = 0x50,
49 .flags = I2C_M_RD, 51 .flags = I2C_M_RD,
50 .len = 1, 52 .len = 8,
51 .buf = buf, 53 .buf = buf,
52 } 54 }
53 }; 55 };
54 56
55 /* Read 8 bytes from i2c for extended probe of EDID header */
56 if (requires_extended_probe)
57 msgs[1].len = 8;
58
59 /* on hw with routers, select right port */ 57 /* on hw with routers, select right port */
60 if (radeon_connector->router.ddc_valid) 58 if (radeon_connector->router.ddc_valid)
61 radeon_router_select_ddc_port(radeon_connector); 59 radeon_router_select_ddc_port(radeon_connector);
@@ -64,17 +62,15 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector, bool requires_e
64 if (ret != 2) 62 if (ret != 2)
65 /* Couldn't find an accessible DDC on this connector */ 63 /* Couldn't find an accessible DDC on this connector */
66 return false; 64 return false;
67 if (requires_extended_probe) { 65 /* Probe also for valid EDID header
68 /* Probe also for valid EDID header 66 * EDID header starts with:
69 * EDID header starts with: 67 * 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00.
70 * 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00. 68 * Only the first 6 bytes must be valid as
71 * Only the first 6 bytes must be valid as 69 * drm_edid_block_valid() can fix the last 2 bytes */
72 * drm_edid_block_valid() can fix the last 2 bytes */ 70 if (drm_edid_header_is_valid(buf) < 6) {
73 if (drm_edid_header_is_valid(buf) < 6) { 71 /* Couldn't find an accessible EDID on this
74 /* Couldn't find an accessible EDID on this 72 * connector */
75 * connector */ 73 return false;
76 return false;
77 }
78 } 74 }
79 return true; 75 return true;
80} 76}
diff --git a/drivers/gpu/drm/radeon/radeon_irq_kms.c b/drivers/gpu/drm/radeon/radeon_irq_kms.c
index 9ec830c77af..8f86aeb2669 100644
--- a/drivers/gpu/drm/radeon/radeon_irq_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_irq_kms.c
@@ -67,10 +67,10 @@ void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
67 /* Disable *all* interrupts */ 67 /* Disable *all* interrupts */
68 rdev->irq.sw_int = false; 68 rdev->irq.sw_int = false;
69 rdev->irq.gui_idle = false; 69 rdev->irq.gui_idle = false;
70 for (i = 0; i < rdev->num_crtc; i++) 70 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
71 rdev->irq.crtc_vblank_int[i] = false;
72 for (i = 0; i < 6; i++) {
73 rdev->irq.hpd[i] = false; 71 rdev->irq.hpd[i] = false;
72 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
73 rdev->irq.crtc_vblank_int[i] = false;
74 rdev->irq.pflip[i] = false; 74 rdev->irq.pflip[i] = false;
75 } 75 }
76 radeon_irq_set(rdev); 76 radeon_irq_set(rdev);
@@ -99,15 +99,55 @@ void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
99 /* Disable *all* interrupts */ 99 /* Disable *all* interrupts */
100 rdev->irq.sw_int = false; 100 rdev->irq.sw_int = false;
101 rdev->irq.gui_idle = false; 101 rdev->irq.gui_idle = false;
102 for (i = 0; i < rdev->num_crtc; i++) 102 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
103 rdev->irq.crtc_vblank_int[i] = false;
104 for (i = 0; i < 6; i++) {
105 rdev->irq.hpd[i] = false; 103 rdev->irq.hpd[i] = false;
104 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
105 rdev->irq.crtc_vblank_int[i] = false;
106 rdev->irq.pflip[i] = false; 106 rdev->irq.pflip[i] = false;
107 } 107 }
108 radeon_irq_set(rdev); 108 radeon_irq_set(rdev);
109} 109}
110 110
111static bool radeon_msi_ok(struct radeon_device *rdev)
112{
113 /* RV370/RV380 was first asic with MSI support */
114 if (rdev->family < CHIP_RV380)
115 return false;
116
117 /* MSIs don't work on AGP */
118 if (rdev->flags & RADEON_IS_AGP)
119 return false;
120
121 /* force MSI on */
122 if (radeon_msi == 1)
123 return true;
124 else if (radeon_msi == 0)
125 return false;
126
127 /* Quirks */
128 /* HP RS690 only seems to work with MSIs. */
129 if ((rdev->pdev->device == 0x791f) &&
130 (rdev->pdev->subsystem_vendor == 0x103c) &&
131 (rdev->pdev->subsystem_device == 0x30c2))
132 return true;
133
134 /* Dell RS690 only seems to work with MSIs. */
135 if ((rdev->pdev->device == 0x791f) &&
136 (rdev->pdev->subsystem_vendor == 0x1028) &&
137 (rdev->pdev->subsystem_device == 0x01fd))
138 return true;
139
140 if (rdev->flags & RADEON_IS_IGP) {
141 /* APUs work fine with MSIs */
142 if (rdev->family >= CHIP_PALM)
143 return true;
144 /* lots of IGPs have problems with MSIs */
145 return false;
146 }
147
148 return true;
149}
150
111int radeon_irq_kms_init(struct radeon_device *rdev) 151int radeon_irq_kms_init(struct radeon_device *rdev)
112{ 152{
113 int i; 153 int i;
@@ -124,12 +164,8 @@ int radeon_irq_kms_init(struct radeon_device *rdev)
124 } 164 }
125 /* enable msi */ 165 /* enable msi */
126 rdev->msi_enabled = 0; 166 rdev->msi_enabled = 0;
127 /* MSIs don't seem to work reliably on all IGP 167
128 * chips. Disable MSI on them for now. 168 if (radeon_msi_ok(rdev)) {
129 */
130 if ((rdev->family >= CHIP_RV380) &&
131 ((!(rdev->flags & RADEON_IS_IGP)) || (rdev->family >= CHIP_PALM)) &&
132 (!(rdev->flags & RADEON_IS_AGP))) {
133 int ret = pci_enable_msi(rdev->pdev); 169 int ret = pci_enable_msi(rdev->pdev);
134 if (!ret) { 170 if (!ret) {
135 rdev->msi_enabled = 1; 171 rdev->msi_enabled = 1;
diff --git a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
index 41a5d48e657..daadf211104 100644
--- a/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
+++ b/drivers/gpu/drm/radeon/radeon_legacy_crtc.c
@@ -991,12 +991,6 @@ static bool radeon_crtc_mode_fixup(struct drm_crtc *crtc,
991 struct drm_display_mode *mode, 991 struct drm_display_mode *mode,
992 struct drm_display_mode *adjusted_mode) 992 struct drm_display_mode *adjusted_mode)
993{ 993{
994 struct drm_device *dev = crtc->dev;
995 struct radeon_device *rdev = dev->dev_private;
996
997 /* adjust pm to upcoming mode change */
998 radeon_pm_compute_clocks(rdev);
999
1000 if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) 994 if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
1001 return false; 995 return false;
1002 return true; 996 return true;
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h
index ed0178f0323..2c2e75ef8a3 100644
--- a/drivers/gpu/drm/radeon/radeon_mode.h
+++ b/drivers/gpu/drm/radeon/radeon_mode.h
@@ -438,9 +438,6 @@ struct radeon_connector {
438 struct radeon_i2c_chan *ddc_bus; 438 struct radeon_i2c_chan *ddc_bus;
439 /* some systems have an hdmi and vga port with a shared ddc line */ 439 /* some systems have an hdmi and vga port with a shared ddc line */
440 bool shared_ddc; 440 bool shared_ddc;
441 /* for some Radeon chip families we apply an additional EDID header
442 check as part of the DDC probe */
443 bool requires_extended_probe;
444 bool use_digital; 441 bool use_digital;
445 /* we need to mind the EDID between detect 442 /* we need to mind the EDID between detect
446 and get modes due to analog/digital/tvencoder */ 443 and get modes due to analog/digital/tvencoder */
@@ -459,6 +456,8 @@ struct radeon_framebuffer {
459 struct drm_gem_object *obj; 456 struct drm_gem_object *obj;
460}; 457};
461 458
459#define ENCODER_MODE_IS_DP(em) (((em) == ATOM_ENCODER_MODE_DP) || \
460 ((em) == ATOM_ENCODER_MODE_DP_MST))
462 461
463extern enum radeon_tv_std 462extern enum radeon_tv_std
464radeon_combios_get_tv_info(struct radeon_device *rdev); 463radeon_combios_get_tv_info(struct radeon_device *rdev);
@@ -468,8 +467,8 @@ radeon_atombios_get_tv_info(struct radeon_device *rdev);
468extern struct drm_connector * 467extern struct drm_connector *
469radeon_get_connector_for_encoder(struct drm_encoder *encoder); 468radeon_get_connector_for_encoder(struct drm_encoder *encoder);
470 469
471extern bool radeon_encoder_is_dp_bridge(struct drm_encoder *encoder); 470extern u16 radeon_encoder_get_dp_bridge_encoder_id(struct drm_encoder *encoder);
472extern bool radeon_connector_encoder_is_dp_bridge(struct drm_connector *connector); 471extern u16 radeon_connector_encoder_get_dp_bridge_encoder_id(struct drm_connector *connector);
473extern bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector); 472extern bool radeon_connector_encoder_is_hbr2(struct drm_connector *connector);
474extern bool radeon_connector_is_dp12_capable(struct drm_connector *connector); 473extern bool radeon_connector_is_dp12_capable(struct drm_connector *connector);
475 474
@@ -489,7 +488,7 @@ extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder,
489 int action, uint8_t lane_num, 488 int action, uint8_t lane_num,
490 uint8_t lane_set); 489 uint8_t lane_set);
491extern void radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder); 490extern void radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder);
492extern struct drm_encoder *radeon_atom_get_external_encoder(struct drm_encoder *encoder); 491extern struct drm_encoder *radeon_get_external_encoder(struct drm_encoder *encoder);
493extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, 492extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
494 u8 write_byte, u8 *read_byte); 493 u8 write_byte, u8 *read_byte);
495 494
@@ -519,8 +518,7 @@ extern void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c,
519 u8 val); 518 u8 val);
520extern void radeon_router_select_ddc_port(struct radeon_connector *radeon_connector); 519extern void radeon_router_select_ddc_port(struct radeon_connector *radeon_connector);
521extern void radeon_router_select_cd_port(struct radeon_connector *radeon_connector); 520extern void radeon_router_select_cd_port(struct radeon_connector *radeon_connector);
522extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector, 521extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
523 bool requires_extended_probe);
524extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector); 522extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
525 523
526extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector); 524extern struct drm_encoder *radeon_best_encoder(struct drm_connector *connector);
diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c
index 6fabe89fa6a..78a665bd951 100644
--- a/drivers/gpu/drm/radeon/radeon_pm.c
+++ b/drivers/gpu/drm/radeon/radeon_pm.c
@@ -53,6 +53,24 @@ static void radeon_pm_set_clocks(struct radeon_device *rdev);
53 53
54#define ACPI_AC_CLASS "ac_adapter" 54#define ACPI_AC_CLASS "ac_adapter"
55 55
56int radeon_pm_get_type_index(struct radeon_device *rdev,
57 enum radeon_pm_state_type ps_type,
58 int instance)
59{
60 int i;
61 int found_instance = -1;
62
63 for (i = 0; i < rdev->pm.num_power_states; i++) {
64 if (rdev->pm.power_state[i].type == ps_type) {
65 found_instance++;
66 if (found_instance == instance)
67 return i;
68 }
69 }
70 /* return default if no match */
71 return rdev->pm.default_power_state_index;
72}
73
56#ifdef CONFIG_ACPI 74#ifdef CONFIG_ACPI
57static int radeon_acpi_event(struct notifier_block *nb, 75static int radeon_acpi_event(struct notifier_block *nb,
58 unsigned long val, 76 unsigned long val,
diff --git a/drivers/gpu/drm/radeon/rs400.c b/drivers/gpu/drm/radeon/rs400.c
index 89a6e1ecea8..06b90c87f8f 100644
--- a/drivers/gpu/drm/radeon/rs400.c
+++ b/drivers/gpu/drm/radeon/rs400.c
@@ -77,7 +77,7 @@ int rs400_gart_init(struct radeon_device *rdev)
77{ 77{
78 int r; 78 int r;
79 79
80 if (rdev->gart.table.ram.ptr) { 80 if (rdev->gart.ptr) {
81 WARN(1, "RS400 GART already initialized\n"); 81 WARN(1, "RS400 GART already initialized\n");
82 return 0; 82 return 0;
83 } 83 }
@@ -212,6 +212,7 @@ void rs400_gart_fini(struct radeon_device *rdev)
212int rs400_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) 212int rs400_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
213{ 213{
214 uint32_t entry; 214 uint32_t entry;
215 u32 *gtt = rdev->gart.ptr;
215 216
216 if (i < 0 || i > rdev->gart.num_gpu_pages) { 217 if (i < 0 || i > rdev->gart.num_gpu_pages) {
217 return -EINVAL; 218 return -EINVAL;
@@ -221,7 +222,7 @@ int rs400_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
221 ((upper_32_bits(addr) & 0xff) << 4) | 222 ((upper_32_bits(addr) & 0xff) << 4) |
222 RS400_PTE_WRITEABLE | RS400_PTE_READABLE; 223 RS400_PTE_WRITEABLE | RS400_PTE_READABLE;
223 entry = cpu_to_le32(entry); 224 entry = cpu_to_le32(entry);
224 rdev->gart.table.ram.ptr[i] = entry; 225 gtt[i] = entry;
225 return 0; 226 return 0;
226} 227}
227 228
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index 9320dd6404f..b1053d64042 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -62,6 +62,7 @@ u32 rs600_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
62{ 62{
63 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; 63 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
64 u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset); 64 u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset);
65 int i;
65 66
66 /* Lock the graphics update lock */ 67 /* Lock the graphics update lock */
67 tmp |= AVIVO_D1GRPH_UPDATE_LOCK; 68 tmp |= AVIVO_D1GRPH_UPDATE_LOCK;
@@ -74,7 +75,11 @@ u32 rs600_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
74 (u32)crtc_base); 75 (u32)crtc_base);
75 76
76 /* Wait for update_pending to go high. */ 77 /* Wait for update_pending to go high. */
77 while (!(RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING)); 78 for (i = 0; i < rdev->usec_timeout; i++) {
79 if (RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING)
80 break;
81 udelay(1);
82 }
78 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); 83 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
79 84
80 /* Unlock the lock, so double-buffering can take place inside vblank */ 85 /* Unlock the lock, so double-buffering can take place inside vblank */
@@ -287,6 +292,7 @@ void rs600_hpd_init(struct radeon_device *rdev)
287 default: 292 default:
288 break; 293 break;
289 } 294 }
295 radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
290 } 296 }
291 if (rdev->irq.installed) 297 if (rdev->irq.installed)
292 rs600_irq_set(rdev); 298 rs600_irq_set(rdev);
@@ -413,7 +419,7 @@ int rs600_gart_init(struct radeon_device *rdev)
413{ 419{
414 int r; 420 int r;
415 421
416 if (rdev->gart.table.vram.robj) { 422 if (rdev->gart.robj) {
417 WARN(1, "RS600 GART already initialized\n"); 423 WARN(1, "RS600 GART already initialized\n");
418 return 0; 424 return 0;
419 } 425 }
@@ -431,7 +437,7 @@ static int rs600_gart_enable(struct radeon_device *rdev)
431 u32 tmp; 437 u32 tmp;
432 int r, i; 438 int r, i;
433 439
434 if (rdev->gart.table.vram.robj == NULL) { 440 if (rdev->gart.robj == NULL) {
435 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); 441 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
436 return -EINVAL; 442 return -EINVAL;
437 } 443 }
@@ -494,20 +500,12 @@ static int rs600_gart_enable(struct radeon_device *rdev)
494void rs600_gart_disable(struct radeon_device *rdev) 500void rs600_gart_disable(struct radeon_device *rdev)
495{ 501{
496 u32 tmp; 502 u32 tmp;
497 int r;
498 503
499 /* FIXME: disable out of gart access */ 504 /* FIXME: disable out of gart access */
500 WREG32_MC(R_000100_MC_PT0_CNTL, 0); 505 WREG32_MC(R_000100_MC_PT0_CNTL, 0);
501 tmp = RREG32_MC(R_000009_MC_CNTL1); 506 tmp = RREG32_MC(R_000009_MC_CNTL1);
502 WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES); 507 WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
503 if (rdev->gart.table.vram.robj) { 508 radeon_gart_table_vram_unpin(rdev);
504 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
505 if (r == 0) {
506 radeon_bo_kunmap(rdev->gart.table.vram.robj);
507 radeon_bo_unpin(rdev->gart.table.vram.robj);
508 radeon_bo_unreserve(rdev->gart.table.vram.robj);
509 }
510 }
511} 509}
512 510
513void rs600_gart_fini(struct radeon_device *rdev) 511void rs600_gart_fini(struct radeon_device *rdev)
@@ -525,7 +523,7 @@ void rs600_gart_fini(struct radeon_device *rdev)
525 523
526int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr) 524int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
527{ 525{
528 void __iomem *ptr = (void *)rdev->gart.table.vram.ptr; 526 void __iomem *ptr = (void *)rdev->gart.ptr;
529 527
530 if (i < 0 || i > rdev->gart.num_gpu_pages) { 528 if (i < 0 || i > rdev->gart.num_gpu_pages) {
531 return -EINVAL; 529 return -EINVAL;
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index 87cc1feee3a..23ae1c60ab3 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -47,6 +47,7 @@ u32 rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
47{ 47{
48 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; 48 struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
49 u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset); 49 u32 tmp = RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset);
50 int i;
50 51
51 /* Lock the graphics update lock */ 52 /* Lock the graphics update lock */
52 tmp |= AVIVO_D1GRPH_UPDATE_LOCK; 53 tmp |= AVIVO_D1GRPH_UPDATE_LOCK;
@@ -66,7 +67,11 @@ u32 rv770_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
66 (u32)crtc_base); 67 (u32)crtc_base);
67 68
68 /* Wait for update_pending to go high. */ 69 /* Wait for update_pending to go high. */
69 while (!(RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING)); 70 for (i = 0; i < rdev->usec_timeout; i++) {
71 if (RREG32(AVIVO_D1GRPH_UPDATE + radeon_crtc->crtc_offset) & AVIVO_D1GRPH_SURFACE_UPDATE_PENDING)
72 break;
73 udelay(1);
74 }
70 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n"); 75 DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
71 76
72 /* Unlock the lock, so double-buffering can take place inside vblank */ 77 /* Unlock the lock, so double-buffering can take place inside vblank */
@@ -124,7 +129,7 @@ int rv770_pcie_gart_enable(struct radeon_device *rdev)
124 u32 tmp; 129 u32 tmp;
125 int r, i; 130 int r, i;
126 131
127 if (rdev->gart.table.vram.robj == NULL) { 132 if (rdev->gart.robj == NULL) {
128 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); 133 dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
129 return -EINVAL; 134 return -EINVAL;
130 } 135 }
@@ -171,7 +176,7 @@ int rv770_pcie_gart_enable(struct radeon_device *rdev)
171void rv770_pcie_gart_disable(struct radeon_device *rdev) 176void rv770_pcie_gart_disable(struct radeon_device *rdev)
172{ 177{
173 u32 tmp; 178 u32 tmp;
174 int i, r; 179 int i;
175 180
176 /* Disable all tables */ 181 /* Disable all tables */
177 for (i = 0; i < 7; i++) 182 for (i = 0; i < 7; i++)
@@ -191,14 +196,7 @@ void rv770_pcie_gart_disable(struct radeon_device *rdev)
191 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); 196 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
192 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); 197 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
193 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); 198 WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
194 if (rdev->gart.table.vram.robj) { 199 radeon_gart_table_vram_unpin(rdev);
195 r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
196 if (likely(r == 0)) {
197 radeon_bo_kunmap(rdev->gart.table.vram.robj);
198 radeon_bo_unpin(rdev->gart.table.vram.robj);
199 radeon_bo_unreserve(rdev->gart.table.vram.robj);
200 }
201 }
202} 200}
203 201
204void rv770_pcie_gart_fini(struct radeon_device *rdev) 202void rv770_pcie_gart_fini(struct radeon_device *rdev)
@@ -282,7 +280,7 @@ static void rv770_mc_program(struct radeon_device *rdev)
282 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, 280 WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
283 rdev->mc.vram_end >> 12); 281 rdev->mc.vram_end >> 12);
284 } 282 }
285 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0); 283 WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
286 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16; 284 tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
287 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF); 285 tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
288 WREG32(MC_VM_FB_LOCATION, tmp); 286 WREG32(MC_VM_FB_LOCATION, tmp);
@@ -959,54 +957,6 @@ static void rv770_gpu_init(struct radeon_device *rdev)
959 957
960} 958}
961 959
962static int rv770_vram_scratch_init(struct radeon_device *rdev)
963{
964 int r;
965 u64 gpu_addr;
966
967 if (rdev->vram_scratch.robj == NULL) {
968 r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE,
969 PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
970 &rdev->vram_scratch.robj);
971 if (r) {
972 return r;
973 }
974 }
975
976 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
977 if (unlikely(r != 0))
978 return r;
979 r = radeon_bo_pin(rdev->vram_scratch.robj,
980 RADEON_GEM_DOMAIN_VRAM, &gpu_addr);
981 if (r) {
982 radeon_bo_unreserve(rdev->vram_scratch.robj);
983 return r;
984 }
985 r = radeon_bo_kmap(rdev->vram_scratch.robj,
986 (void **)&rdev->vram_scratch.ptr);
987 if (r)
988 radeon_bo_unpin(rdev->vram_scratch.robj);
989 radeon_bo_unreserve(rdev->vram_scratch.robj);
990
991 return r;
992}
993
994static void rv770_vram_scratch_fini(struct radeon_device *rdev)
995{
996 int r;
997
998 if (rdev->vram_scratch.robj == NULL) {
999 return;
1000 }
1001 r = radeon_bo_reserve(rdev->vram_scratch.robj, false);
1002 if (likely(r == 0)) {
1003 radeon_bo_kunmap(rdev->vram_scratch.robj);
1004 radeon_bo_unpin(rdev->vram_scratch.robj);
1005 radeon_bo_unreserve(rdev->vram_scratch.robj);
1006 }
1007 radeon_bo_unref(&rdev->vram_scratch.robj);
1008}
1009
1010void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) 960void r700_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
1011{ 961{
1012 u64 size_bf, size_af; 962 u64 size_bf, size_af;
@@ -1106,6 +1056,10 @@ static int rv770_startup(struct radeon_device *rdev)
1106 } 1056 }
1107 } 1057 }
1108 1058
1059 r = r600_vram_scratch_init(rdev);
1060 if (r)
1061 return r;
1062
1109 rv770_mc_program(rdev); 1063 rv770_mc_program(rdev);
1110 if (rdev->flags & RADEON_IS_AGP) { 1064 if (rdev->flags & RADEON_IS_AGP) {
1111 rv770_agp_enable(rdev); 1065 rv770_agp_enable(rdev);
@@ -1114,9 +1068,7 @@ static int rv770_startup(struct radeon_device *rdev)
1114 if (r) 1068 if (r)
1115 return r; 1069 return r;
1116 } 1070 }
1117 r = rv770_vram_scratch_init(rdev); 1071
1118 if (r)
1119 return r;
1120 rv770_gpu_init(rdev); 1072 rv770_gpu_init(rdev);
1121 r = r600_blit_init(rdev); 1073 r = r600_blit_init(rdev);
1122 if (r) { 1074 if (r) {
@@ -1316,7 +1268,7 @@ void rv770_fini(struct radeon_device *rdev)
1316 radeon_ib_pool_fini(rdev); 1268 radeon_ib_pool_fini(rdev);
1317 radeon_irq_kms_fini(rdev); 1269 radeon_irq_kms_fini(rdev);
1318 rv770_pcie_gart_fini(rdev); 1270 rv770_pcie_gart_fini(rdev);
1319 rv770_vram_scratch_fini(rdev); 1271 r600_vram_scratch_fini(rdev);
1320 radeon_gem_fini(rdev); 1272 radeon_gem_fini(rdev);
1321 radeon_fence_driver_fini(rdev); 1273 radeon_fence_driver_fini(rdev);
1322 radeon_agp_fini(rdev); 1274 radeon_agp_fini(rdev);
diff --git a/drivers/gpu/drm/savage/savage_drv.c b/drivers/gpu/drm/savage/savage_drv.c
index 6464490b240..5468d1cd329 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 46d5be6e97e..a9c5716bea4 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 8bf98810a8d..cda29911e33 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_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 617b64678fc..0bb0f5f713e 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -574,10 +574,16 @@ retry:
574 return ret; 574 return ret;
575 575
576 spin_lock(&glob->lru_lock); 576 spin_lock(&glob->lru_lock);
577
578 if (unlikely(list_empty(&bo->ddestroy))) {
579 spin_unlock(&glob->lru_lock);
580 return 0;
581 }
582
577 ret = ttm_bo_reserve_locked(bo, interruptible, 583 ret = ttm_bo_reserve_locked(bo, interruptible,
578 no_wait_reserve, false, 0); 584 no_wait_reserve, false, 0);
579 585
580 if (unlikely(ret != 0) || list_empty(&bo->ddestroy)) { 586 if (unlikely(ret != 0)) {
581 spin_unlock(&glob->lru_lock); 587 spin_unlock(&glob->lru_lock);
582 return ret; 588 return ret;
583 } 589 }
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 58c271ebc0f..f9cc548d6d9 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 920a55214bc..a83e86d3956 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 13afddc1f03..dff8fc76715 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"
@@ -103,6 +104,9 @@
103#define DRM_IOCTL_VMW_PRESENT_READBACK \ 104#define DRM_IOCTL_VMW_PRESENT_READBACK \
104 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT_READBACK, \ 105 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_PRESENT_READBACK, \
105 struct drm_vmw_present_readback_arg) 106 struct drm_vmw_present_readback_arg)
107#define DRM_IOCTL_VMW_UPDATE_LAYOUT \
108 DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_UPDATE_LAYOUT, \
109 struct drm_vmw_update_layout_arg)
106 110
107/** 111/**
108 * The core DRM version of this macro doesn't account for 112 * The core DRM version of this macro doesn't account for
@@ -165,6 +169,9 @@ static struct drm_ioctl_desc vmw_ioctls[] = {
165 VMW_IOCTL_DEF(VMW_PRESENT_READBACK, 169 VMW_IOCTL_DEF(VMW_PRESENT_READBACK,
166 vmw_present_readback_ioctl, 170 vmw_present_readback_ioctl,
167 DRM_MASTER | DRM_AUTH | DRM_UNLOCKED), 171 DRM_MASTER | DRM_AUTH | DRM_UNLOCKED),
172 VMW_IOCTL_DEF(VMW_UPDATE_LAYOUT,
173 vmw_kms_update_layout_ioctl,
174 DRM_MASTER | DRM_UNLOCKED),
168}; 175};
169 176
170static struct pci_device_id vmw_pci_id_list[] = { 177static struct pci_device_id vmw_pci_id_list[] = {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 30589d0aecd..8cca91a93bd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -40,9 +40,9 @@
40#include "ttm/ttm_module.h" 40#include "ttm/ttm_module.h"
41#include "vmwgfx_fence.h" 41#include "vmwgfx_fence.h"
42 42
43#define VMWGFX_DRIVER_DATE "20111008" 43#define VMWGFX_DRIVER_DATE "20111025"
44#define VMWGFX_DRIVER_MAJOR 2 44#define VMWGFX_DRIVER_MAJOR 2
45#define VMWGFX_DRIVER_MINOR 2 45#define VMWGFX_DRIVER_MINOR 3
46#define VMWGFX_DRIVER_PATCHLEVEL 0 46#define VMWGFX_DRIVER_PATCHLEVEL 0
47#define VMWGFX_FILE_PAGE_OFFSET 0x00100000 47#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
48#define VMWGFX_FIFO_STATIC_SIZE (1024*1024) 48#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
@@ -633,6 +633,8 @@ int vmw_kms_readback(struct vmw_private *dev_priv,
633 struct drm_vmw_fence_rep __user *user_fence_rep, 633 struct drm_vmw_fence_rep __user *user_fence_rep,
634 struct drm_vmw_rect *clips, 634 struct drm_vmw_rect *clips,
635 uint32_t num_clips); 635 uint32_t num_clips);
636int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
637 struct drm_file *file_priv);
636 638
637/** 639/**
638 * Overlay control - vmwgfx_overlay.c 640 * Overlay control - vmwgfx_overlay.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index 070797b7b03..34e51a1695b 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/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 8b14dfd513a..37d40545ed7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -105,12 +105,17 @@ int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
105 struct vmw_dma_buffer *dmabuf = NULL; 105 struct vmw_dma_buffer *dmabuf = NULL;
106 int ret; 106 int ret;
107 107
108 /* A lot of the code assumes this */
109 if (handle && (width != 64 || height != 64))
110 return -EINVAL;
111
108 if (handle) { 112 if (handle) {
109 ret = vmw_user_surface_lookup_handle(dev_priv, tfile, 113 ret = vmw_user_surface_lookup_handle(dev_priv, tfile,
110 handle, &surface); 114 handle, &surface);
111 if (!ret) { 115 if (!ret) {
112 if (!surface->snooper.image) { 116 if (!surface->snooper.image) {
113 DRM_ERROR("surface not suitable for cursor\n"); 117 DRM_ERROR("surface not suitable for cursor\n");
118 vmw_surface_unreference(&surface);
114 return -EINVAL; 119 return -EINVAL;
115 } 120 }
116 } else { 121 } else {
@@ -176,7 +181,9 @@ err_unreserve:
176 return 0; 181 return 0;
177 } 182 }
178 183
179 vmw_cursor_update_position(dev_priv, true, du->cursor_x, du->cursor_y); 184 vmw_cursor_update_position(dev_priv, true,
185 du->cursor_x + du->hotspot_x,
186 du->cursor_y + du->hotspot_y);
180 187
181 return 0; 188 return 0;
182} 189}
@@ -191,7 +198,8 @@ int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
191 du->cursor_y = y + crtc->y; 198 du->cursor_y = y + crtc->y;
192 199
193 vmw_cursor_update_position(dev_priv, shown, 200 vmw_cursor_update_position(dev_priv, shown,
194 du->cursor_x, du->cursor_y); 201 du->cursor_x + du->hotspot_x,
202 du->cursor_y + du->hotspot_y);
195 203
196 return 0; 204 return 0;
197} 205}
@@ -212,7 +220,7 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
212 SVGA3dCmdHeader header; 220 SVGA3dCmdHeader header;
213 SVGA3dCmdSurfaceDMA dma; 221 SVGA3dCmdSurfaceDMA dma;
214 } *cmd; 222 } *cmd;
215 int ret; 223 int i, ret;
216 224
217 cmd = container_of(header, struct vmw_dma_cmd, header); 225 cmd = container_of(header, struct vmw_dma_cmd, header);
218 226
@@ -234,16 +242,19 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
234 box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) / 242 box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) /
235 sizeof(SVGA3dCopyBox); 243 sizeof(SVGA3dCopyBox);
236 244
237 if (cmd->dma.guest.pitch != (64 * 4) || 245 if (cmd->dma.guest.ptr.offset % PAGE_SIZE ||
238 cmd->dma.guest.ptr.offset % PAGE_SIZE ||
239 box->x != 0 || box->y != 0 || box->z != 0 || 246 box->x != 0 || box->y != 0 || box->z != 0 ||
240 box->srcx != 0 || box->srcy != 0 || box->srcz != 0 || 247 box->srcx != 0 || box->srcy != 0 || box->srcz != 0 ||
241 box->w != 64 || box->h != 64 || box->d != 1 || 248 box->d != 1 || box_count != 1) {
242 box_count != 1) {
243 /* TODO handle none page aligned offsets */ 249 /* TODO handle none page aligned offsets */
244 /* TODO handle partial uploads and pitch != 256 */ 250 /* TODO handle more dst & src != 0 */
245 /* TODO handle more then one copy (size != 64) */ 251 /* TODO handle more then one copy */
246 DRM_ERROR("lazy programmer, can't handle weird stuff\n"); 252 DRM_ERROR("Cant snoop dma request for cursor!\n");
253 DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n",
254 box->srcx, box->srcy, box->srcz,
255 box->x, box->y, box->z,
256 box->w, box->h, box->d, box_count,
257 cmd->dma.guest.ptr.offset);
247 return; 258 return;
248 } 259 }
249 260
@@ -262,7 +273,16 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
262 273
263 virtual = ttm_kmap_obj_virtual(&map, &dummy); 274 virtual = ttm_kmap_obj_virtual(&map, &dummy);
264 275
265 memcpy(srf->snooper.image, virtual, 64*64*4); 276 if (box->w == 64 && cmd->dma.guest.pitch == 64*4) {
277 memcpy(srf->snooper.image, virtual, 64*64*4);
278 } else {
279 /* Image is unsigned pointer. */
280 for (i = 0; i < box->h; i++)
281 memcpy(srf->snooper.image + i * 64,
282 virtual + i * cmd->dma.guest.pitch,
283 box->w * 4);
284 }
285
266 srf->snooper.age++; 286 srf->snooper.age++;
267 287
268 /* we can't call this function from this function since execbuf has 288 /* we can't call this function from this function since execbuf has
@@ -394,8 +414,9 @@ static int do_surface_dirty_sou(struct vmw_private *dev_priv,
394 top = clips->y1; 414 top = clips->y1;
395 bottom = clips->y2; 415 bottom = clips->y2;
396 416
397 clips_ptr = clips; 417 /* skip the first clip rect */
398 for (i = 1; i < num_clips; i++, clips_ptr += inc) { 418 for (i = 1, clips_ptr = clips + inc;
419 i < num_clips; i++, clips_ptr += inc) {
399 left = min_t(int, left, (int)clips_ptr->x1); 420 left = min_t(int, left, (int)clips_ptr->x1);
400 right = max_t(int, right, (int)clips_ptr->x2); 421 right = max_t(int, right, (int)clips_ptr->x2);
401 top = min_t(int, top, (int)clips_ptr->y1); 422 top = min_t(int, top, (int)clips_ptr->y1);
@@ -994,7 +1015,7 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
994 required_size = mode_cmd->pitch * mode_cmd->height; 1015 required_size = mode_cmd->pitch * mode_cmd->height;
995 if (unlikely(required_size > (u64) dev_priv->vram_size)) { 1016 if (unlikely(required_size > (u64) dev_priv->vram_size)) {
996 DRM_ERROR("VRAM size is too small for requested mode.\n"); 1017 DRM_ERROR("VRAM size is too small for requested mode.\n");
997 return NULL; 1018 return ERR_PTR(-ENOMEM);
998 } 1019 }
999 1020
1000 /* 1021 /*
@@ -1307,7 +1328,10 @@ int vmw_kms_close(struct vmw_private *dev_priv)
1307 * drm_encoder_cleanup which takes the lock we deadlock. 1328 * drm_encoder_cleanup which takes the lock we deadlock.
1308 */ 1329 */
1309 drm_mode_config_cleanup(dev_priv->dev); 1330 drm_mode_config_cleanup(dev_priv->dev);
1310 vmw_kms_close_legacy_display_system(dev_priv); 1331 if (dev_priv->sou_priv)
1332 vmw_kms_close_screen_object_display(dev_priv);
1333 else
1334 vmw_kms_close_legacy_display_system(dev_priv);
1311 return 0; 1335 return 0;
1312} 1336}
1313 1337
@@ -1517,6 +1541,8 @@ int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num,
1517 du->pref_width = rects[du->unit].w; 1541 du->pref_width = rects[du->unit].w;
1518 du->pref_height = rects[du->unit].h; 1542 du->pref_height = rects[du->unit].h;
1519 du->pref_active = true; 1543 du->pref_active = true;
1544 du->gui_x = rects[du->unit].x;
1545 du->gui_y = rects[du->unit].y;
1520 } else { 1546 } else {
1521 du->pref_width = 800; 1547 du->pref_width = 800;
1522 du->pref_height = 600; 1548 du->pref_height = 600;
@@ -1572,12 +1598,14 @@ vmw_du_connector_detect(struct drm_connector *connector, bool force)
1572 uint32_t num_displays; 1598 uint32_t num_displays;
1573 struct drm_device *dev = connector->dev; 1599 struct drm_device *dev = connector->dev;
1574 struct vmw_private *dev_priv = vmw_priv(dev); 1600 struct vmw_private *dev_priv = vmw_priv(dev);
1601 struct vmw_display_unit *du = vmw_connector_to_du(connector);
1575 1602
1576 mutex_lock(&dev_priv->hw_mutex); 1603 mutex_lock(&dev_priv->hw_mutex);
1577 num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS); 1604 num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS);
1578 mutex_unlock(&dev_priv->hw_mutex); 1605 mutex_unlock(&dev_priv->hw_mutex);
1579 1606
1580 return ((vmw_connector_to_du(connector)->unit < num_displays) ? 1607 return ((vmw_connector_to_du(connector)->unit < num_displays &&
1608 du->pref_active) ?
1581 connector_status_connected : connector_status_disconnected); 1609 connector_status_connected : connector_status_disconnected);
1582} 1610}
1583 1611
@@ -1658,6 +1686,28 @@ static struct drm_display_mode vmw_kms_connector_builtin[] = {
1658 { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }, 1686 { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) },
1659}; 1687};
1660 1688
1689/**
1690 * vmw_guess_mode_timing - Provide fake timings for a
1691 * 60Hz vrefresh mode.
1692 *
1693 * @mode - Pointer to a struct drm_display_mode with hdisplay and vdisplay
1694 * members filled in.
1695 */
1696static void vmw_guess_mode_timing(struct drm_display_mode *mode)
1697{
1698 mode->hsync_start = mode->hdisplay + 50;
1699 mode->hsync_end = mode->hsync_start + 50;
1700 mode->htotal = mode->hsync_end + 50;
1701
1702 mode->vsync_start = mode->vdisplay + 50;
1703 mode->vsync_end = mode->vsync_start + 50;
1704 mode->vtotal = mode->vsync_end + 50;
1705
1706 mode->clock = (u32)mode->htotal * (u32)mode->vtotal / 100 * 6;
1707 mode->vrefresh = drm_mode_vrefresh(mode);
1708}
1709
1710
1661int vmw_du_connector_fill_modes(struct drm_connector *connector, 1711int vmw_du_connector_fill_modes(struct drm_connector *connector,
1662 uint32_t max_width, uint32_t max_height) 1712 uint32_t max_width, uint32_t max_height)
1663{ 1713{
@@ -1680,18 +1730,23 @@ int vmw_du_connector_fill_modes(struct drm_connector *connector,
1680 return 0; 1730 return 0;
1681 mode->hdisplay = du->pref_width; 1731 mode->hdisplay = du->pref_width;
1682 mode->vdisplay = du->pref_height; 1732 mode->vdisplay = du->pref_height;
1683 mode->vrefresh = drm_mode_vrefresh(mode); 1733 vmw_guess_mode_timing(mode);
1734
1684 if (vmw_kms_validate_mode_vram(dev_priv, mode->hdisplay * 2, 1735 if (vmw_kms_validate_mode_vram(dev_priv, mode->hdisplay * 2,
1685 mode->vdisplay)) { 1736 mode->vdisplay)) {
1686 drm_mode_probed_add(connector, mode); 1737 drm_mode_probed_add(connector, mode);
1738 } else {
1739 drm_mode_destroy(dev, mode);
1740 mode = NULL;
1741 }
1687 1742
1688 if (du->pref_mode) { 1743 if (du->pref_mode) {
1689 list_del_init(&du->pref_mode->head); 1744 list_del_init(&du->pref_mode->head);
1690 drm_mode_destroy(dev, du->pref_mode); 1745 drm_mode_destroy(dev, du->pref_mode);
1691 }
1692
1693 du->pref_mode = mode;
1694 } 1746 }
1747
1748 /* mode might be null here, this is intended */
1749 du->pref_mode = mode;
1695 } 1750 }
1696 1751
1697 for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) { 1752 for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) {
@@ -1712,6 +1767,10 @@ int vmw_du_connector_fill_modes(struct drm_connector *connector,
1712 drm_mode_probed_add(connector, mode); 1767 drm_mode_probed_add(connector, mode);
1713 } 1768 }
1714 1769
1770 /* Move the prefered mode first, help apps pick the right mode. */
1771 if (du->pref_mode)
1772 list_move(&du->pref_mode->head, &connector->probed_modes);
1773
1715 drm_mode_connector_list_update(connector); 1774 drm_mode_connector_list_update(connector);
1716 1775
1717 return 1; 1776 return 1;
@@ -1723,3 +1782,64 @@ int vmw_du_connector_set_property(struct drm_connector *connector,
1723{ 1782{
1724 return 0; 1783 return 0;
1725} 1784}
1785
1786
1787int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
1788 struct drm_file *file_priv)
1789{
1790 struct vmw_private *dev_priv = vmw_priv(dev);
1791 struct drm_vmw_update_layout_arg *arg =
1792 (struct drm_vmw_update_layout_arg *)data;
1793 struct vmw_master *vmaster = vmw_master(file_priv->master);
1794 void __user *user_rects;
1795 struct drm_vmw_rect *rects;
1796 unsigned rects_size;
1797 int ret;
1798 int i;
1799 struct drm_mode_config *mode_config = &dev->mode_config;
1800
1801 ret = ttm_read_lock(&vmaster->lock, true);
1802 if (unlikely(ret != 0))
1803 return ret;
1804
1805 if (!arg->num_outputs) {
1806 struct drm_vmw_rect def_rect = {0, 0, 800, 600};
1807 vmw_du_update_layout(dev_priv, 1, &def_rect);
1808 goto out_unlock;
1809 }
1810
1811 rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect);
1812 rects = kcalloc(arg->num_outputs, sizeof(struct drm_vmw_rect),
1813 GFP_KERNEL);
1814 if (unlikely(!rects)) {
1815 ret = -ENOMEM;
1816 goto out_unlock;
1817 }
1818
1819 user_rects = (void __user *)(unsigned long)arg->rects;
1820 ret = copy_from_user(rects, user_rects, rects_size);
1821 if (unlikely(ret != 0)) {
1822 DRM_ERROR("Failed to get rects.\n");
1823 ret = -EFAULT;
1824 goto out_free;
1825 }
1826
1827 for (i = 0; i < arg->num_outputs; ++i) {
1828 if (rects[i].x < 0 ||
1829 rects[i].y < 0 ||
1830 rects[i].x + rects[i].w > mode_config->max_width ||
1831 rects[i].y + rects[i].h > mode_config->max_height) {
1832 DRM_ERROR("Invalid GUI layout.\n");
1833 ret = -EINVAL;
1834 goto out_free;
1835 }
1836 }
1837
1838 vmw_du_update_layout(dev_priv, arg->num_outputs, rects);
1839
1840out_free:
1841 kfree(rects);
1842out_unlock:
1843 ttm_read_unlock(&vmaster->lock);
1844 return ret;
1845}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
index db0b901f8c3..af8e6e5bd96 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
@@ -96,6 +96,13 @@ struct vmw_display_unit {
96 unsigned pref_height; 96 unsigned pref_height;
97 bool pref_active; 97 bool pref_active;
98 struct drm_display_mode *pref_mode; 98 struct drm_display_mode *pref_mode;
99
100 /*
101 * Gui positioning
102 */
103 int gui_x;
104 int gui_y;
105 bool is_implicit;
99}; 106};
100 107
101#define vmw_crtc_to_du(x) \ 108#define vmw_crtc_to_du(x) \
@@ -126,8 +133,7 @@ int vmw_du_connector_fill_modes(struct drm_connector *connector,
126int vmw_du_connector_set_property(struct drm_connector *connector, 133int vmw_du_connector_set_property(struct drm_connector *connector,
127 struct drm_property *property, 134 struct drm_property *property,
128 uint64_t val); 135 uint64_t val);
129int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num, 136
130 struct drm_vmw_rect *rects);
131 137
132/* 138/*
133 * Legacy display unit functions - vmwgfx_ldu.c 139 * Legacy display unit functions - vmwgfx_ldu.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index 92f56bc594e..90c5e392849 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -337,13 +337,14 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
337 ldu->base.pref_width = 800; 337 ldu->base.pref_width = 800;
338 ldu->base.pref_height = 600; 338 ldu->base.pref_height = 600;
339 ldu->base.pref_mode = NULL; 339 ldu->base.pref_mode = NULL;
340 ldu->base.is_implicit = true;
340 341
341 drm_connector_init(dev, connector, &vmw_legacy_connector_funcs, 342 drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
342 DRM_MODE_CONNECTOR_LVDS); 343 DRM_MODE_CONNECTOR_VIRTUAL);
343 connector->status = vmw_du_connector_detect(connector, true); 344 connector->status = vmw_du_connector_detect(connector, true);
344 345
345 drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs, 346 drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs,
346 DRM_MODE_ENCODER_LVDS); 347 DRM_MODE_ENCODER_VIRTUAL);
347 drm_mode_connector_attach_encoder(connector, encoder); 348 drm_mode_connector_attach_encoder(connector, encoder);
348 encoder->possible_crtcs = (1 << unit); 349 encoder->possible_crtcs = (1 << unit);
349 encoder->possible_clones = 0; 350 encoder->possible_clones = 0;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
index 477b2a9eb3c..4defdcf1c72 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c
@@ -36,12 +36,9 @@
36 container_of(x, struct vmw_screen_object_unit, base.connector) 36 container_of(x, struct vmw_screen_object_unit, base.connector)
37 37
38struct vmw_screen_object_display { 38struct vmw_screen_object_display {
39 struct list_head active; 39 unsigned num_implicit;
40 40
41 unsigned num_active; 41 struct vmw_framebuffer *implicit_fb;
42 unsigned last_num_active;
43
44 struct vmw_framebuffer *fb;
45}; 42};
46 43
47/** 44/**
@@ -54,13 +51,11 @@ struct vmw_screen_object_unit {
54 struct vmw_dma_buffer *buffer; /**< Backing store buffer */ 51 struct vmw_dma_buffer *buffer; /**< Backing store buffer */
55 52
56 bool defined; 53 bool defined;
57 54 bool active_implicit;
58 struct list_head active;
59}; 55};
60 56
61static void vmw_sou_destroy(struct vmw_screen_object_unit *sou) 57static void vmw_sou_destroy(struct vmw_screen_object_unit *sou)
62{ 58{
63 list_del_init(&sou->active);
64 vmw_display_unit_cleanup(&sou->base); 59 vmw_display_unit_cleanup(&sou->base);
65 kfree(sou); 60 kfree(sou);
66} 61}
@@ -75,58 +70,31 @@ static void vmw_sou_crtc_destroy(struct drm_crtc *crtc)
75 vmw_sou_destroy(vmw_crtc_to_sou(crtc)); 70 vmw_sou_destroy(vmw_crtc_to_sou(crtc));
76} 71}
77 72
78static int vmw_sou_del_active(struct vmw_private *vmw_priv, 73static void vmw_sou_del_active(struct vmw_private *vmw_priv,
79 struct vmw_screen_object_unit *sou) 74 struct vmw_screen_object_unit *sou)
80{ 75{
81 struct vmw_screen_object_display *ld = vmw_priv->sou_priv; 76 struct vmw_screen_object_display *ld = vmw_priv->sou_priv;
82 if (list_empty(&sou->active))
83 return 0;
84 77
85 /* Must init otherwise list_empty(&sou->active) will not work. */ 78 if (sou->active_implicit) {
86 list_del_init(&sou->active); 79 if (--(ld->num_implicit) == 0)
87 if (--(ld->num_active) == 0) { 80 ld->implicit_fb = NULL;
88 BUG_ON(!ld->fb); 81 sou->active_implicit = false;
89 if (ld->fb->unpin)
90 ld->fb->unpin(ld->fb);
91 ld->fb = NULL;
92 } 82 }
93
94 return 0;
95} 83}
96 84
97static int vmw_sou_add_active(struct vmw_private *vmw_priv, 85static void vmw_sou_add_active(struct vmw_private *vmw_priv,
98 struct vmw_screen_object_unit *sou, 86 struct vmw_screen_object_unit *sou,
99 struct vmw_framebuffer *vfb) 87 struct vmw_framebuffer *vfb)
100{ 88{
101 struct vmw_screen_object_display *ld = vmw_priv->sou_priv; 89 struct vmw_screen_object_display *ld = vmw_priv->sou_priv;
102 struct vmw_screen_object_unit *entry;
103 struct list_head *at;
104
105 BUG_ON(!ld->num_active && ld->fb);
106 if (vfb != ld->fb) {
107 if (ld->fb && ld->fb->unpin)
108 ld->fb->unpin(ld->fb);
109 if (vfb->pin)
110 vfb->pin(vfb);
111 ld->fb = vfb;
112 }
113
114 if (!list_empty(&sou->active))
115 return 0;
116 90
117 at = &ld->active; 91 BUG_ON(!ld->num_implicit && ld->implicit_fb);
118 list_for_each_entry(entry, &ld->active, active) {
119 if (entry->base.unit > sou->base.unit)
120 break;
121 92
122 at = &entry->active; 93 if (!sou->active_implicit && sou->base.is_implicit) {
94 ld->implicit_fb = vfb;
95 sou->active_implicit = true;
96 ld->num_implicit++;
123 } 97 }
124
125 list_add(&sou->active, at);
126
127 ld->num_active++;
128
129 return 0;
130} 98}
131 99
132/** 100/**
@@ -164,8 +132,13 @@ static int vmw_sou_fifo_create(struct vmw_private *dev_priv,
164 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0); 132 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0);
165 cmd->obj.size.width = mode->hdisplay; 133 cmd->obj.size.width = mode->hdisplay;
166 cmd->obj.size.height = mode->vdisplay; 134 cmd->obj.size.height = mode->vdisplay;
167 cmd->obj.root.x = x; 135 if (sou->base.is_implicit) {
168 cmd->obj.root.y = y; 136 cmd->obj.root.x = x;
137 cmd->obj.root.y = y;
138 } else {
139 cmd->obj.root.x = sou->base.gui_x;
140 cmd->obj.root.y = sou->base.gui_y;
141 }
169 142
170 /* Ok to assume that buffer is pinned in vram */ 143 /* Ok to assume that buffer is pinned in vram */
171 vmw_bo_get_guest_ptr(&sou->buffer->base, &cmd->obj.backingStore.ptr); 144 vmw_bo_get_guest_ptr(&sou->buffer->base, &cmd->obj.backingStore.ptr);
@@ -312,10 +285,11 @@ static int vmw_sou_crtc_set_config(struct drm_mode_set *set)
312 } 285 }
313 286
314 /* sou only supports one fb active at the time */ 287 /* sou only supports one fb active at the time */
315 if (dev_priv->sou_priv->fb && vfb && 288 if (sou->base.is_implicit &&
316 !(dev_priv->sou_priv->num_active == 1 && 289 dev_priv->sou_priv->implicit_fb && vfb &&
317 !list_empty(&sou->active)) && 290 !(dev_priv->sou_priv->num_implicit == 1 &&
318 dev_priv->sou_priv->fb != vfb) { 291 sou->active_implicit) &&
292 dev_priv->sou_priv->implicit_fb != vfb) {
319 DRM_ERROR("Multiple framebuffers not supported\n"); 293 DRM_ERROR("Multiple framebuffers not supported\n");
320 return -EINVAL; 294 return -EINVAL;
321 } 295 }
@@ -471,19 +445,20 @@ static int vmw_sou_init(struct vmw_private *dev_priv, unsigned unit)
471 encoder = &sou->base.encoder; 445 encoder = &sou->base.encoder;
472 connector = &sou->base.connector; 446 connector = &sou->base.connector;
473 447
474 INIT_LIST_HEAD(&sou->active); 448 sou->active_implicit = false;
475 449
476 sou->base.pref_active = (unit == 0); 450 sou->base.pref_active = (unit == 0);
477 sou->base.pref_width = 800; 451 sou->base.pref_width = 800;
478 sou->base.pref_height = 600; 452 sou->base.pref_height = 600;
479 sou->base.pref_mode = NULL; 453 sou->base.pref_mode = NULL;
454 sou->base.is_implicit = true;
480 455
481 drm_connector_init(dev, connector, &vmw_legacy_connector_funcs, 456 drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
482 DRM_MODE_CONNECTOR_LVDS); 457 DRM_MODE_CONNECTOR_VIRTUAL);
483 connector->status = vmw_du_connector_detect(connector, true); 458 connector->status = vmw_du_connector_detect(connector, true);
484 459
485 drm_encoder_init(dev, encoder, &vmw_screen_object_encoder_funcs, 460 drm_encoder_init(dev, encoder, &vmw_screen_object_encoder_funcs,
486 DRM_MODE_ENCODER_LVDS); 461 DRM_MODE_ENCODER_VIRTUAL);
487 drm_mode_connector_attach_encoder(connector, encoder); 462 drm_mode_connector_attach_encoder(connector, encoder);
488 encoder->possible_crtcs = (1 << unit); 463 encoder->possible_crtcs = (1 << unit);
489 encoder->possible_clones = 0; 464 encoder->possible_clones = 0;
@@ -520,10 +495,8 @@ int vmw_kms_init_screen_object_display(struct vmw_private *dev_priv)
520 if (unlikely(!dev_priv->sou_priv)) 495 if (unlikely(!dev_priv->sou_priv))
521 goto err_no_mem; 496 goto err_no_mem;
522 497
523 INIT_LIST_HEAD(&dev_priv->sou_priv->active); 498 dev_priv->sou_priv->num_implicit = 0;
524 dev_priv->sou_priv->num_active = 0; 499 dev_priv->sou_priv->implicit_fb = NULL;
525 dev_priv->sou_priv->last_num_active = 0;
526 dev_priv->sou_priv->fb = NULL;
527 500
528 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS); 501 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
529 if (unlikely(ret != 0)) 502 if (unlikely(ret != 0))
@@ -558,9 +531,6 @@ int vmw_kms_close_screen_object_display(struct vmw_private *dev_priv)
558 531
559 drm_vblank_cleanup(dev); 532 drm_vblank_cleanup(dev);
560 533
561 if (!list_empty(&dev_priv->sou_priv->active))
562 DRM_ERROR("Still have active outputs when unloading driver");
563
564 kfree(dev_priv->sou_priv); 534 kfree(dev_priv->sou_priv);
565 535
566 return 0; 536 return 0;
diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index c72f1c0b5e6..111d956d8e7 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -465,31 +465,29 @@ static void vga_arbiter_check_bridge_sharing(struct vga_device *vgadev)
465 while (new_bus) { 465 while (new_bus) {
466 new_bridge = new_bus->self; 466 new_bridge = new_bus->self;
467 467
468 if (new_bridge) { 468 /* go through list of devices already registered */
469 /* go through list of devices already registered */ 469 list_for_each_entry(same_bridge_vgadev, &vga_list, list) {
470 list_for_each_entry(same_bridge_vgadev, &vga_list, list) { 470 bus = same_bridge_vgadev->pdev->bus;
471 bus = same_bridge_vgadev->pdev->bus; 471 bridge = bus->self;
472 bridge = bus->self; 472
473 473 /* see if the share a bridge with this device */
474 /* see if the share a bridge with this device */ 474 if (new_bridge == bridge) {
475 if (new_bridge == bridge) { 475 /* if their direct parent bridge is the same
476 /* if their direct parent bridge is the same 476 as any bridge of this device then it can't be used
477 as any bridge of this device then it can't be used 477 for that device */
478 for that device */ 478 same_bridge_vgadev->bridge_has_one_vga = false;
479 same_bridge_vgadev->bridge_has_one_vga = false; 479 }
480 }
481 480
482 /* now iterate the previous devices bridge hierarchy */ 481 /* now iterate the previous devices bridge hierarchy */
483 /* if the new devices parent bridge is in the other devices 482 /* if the new devices parent bridge is in the other devices
484 hierarchy then we can't use it to control this device */ 483 hierarchy then we can't use it to control this device */
485 while (bus) { 484 while (bus) {
486 bridge = bus->self; 485 bridge = bus->self;
487 if (bridge) { 486 if (bridge) {
488 if (bridge == vgadev->pdev->bus->self) 487 if (bridge == vgadev->pdev->bus->self)
489 vgadev->bridge_has_one_vga = false; 488 vgadev->bridge_has_one_vga = false;
490 }
491 bus = bus->parent;
492 } 489 }
490 bus = bus->parent;
493 } 491 }
494 } 492 }
495 new_bus = new_bus->parent; 493 new_bus = new_bus->parent;
@@ -993,14 +991,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
993 uc = &priv->cards[i]; 991 uc = &priv->cards[i];
994 } 992 }
995 993
996 if (!uc) 994 if (!uc) {
997 return -EINVAL; 995 ret_val = -EINVAL;
996 goto done;
997 }
998 998
999 if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) 999 if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
1000 return -EINVAL; 1000 ret_val = -EINVAL;
1001 goto done;
1002 }
1001 1003
1002 if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) 1004 if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
1003 return -EINVAL; 1005 ret_val = -EINVAL;
1006 goto done;
1007 }
1004 1008
1005 vga_put(pdev, io_state); 1009 vga_put(pdev, io_state);
1006 1010
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index a4591596131..a421abdd1ab 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -340,6 +340,7 @@ config HID_MULTITOUCH
340 Say Y here if you have one of the following devices: 340 Say Y here if you have one of the following devices:
341 - 3M PCT touch screens 341 - 3M PCT touch screens
342 - ActionStar dual touch panels 342 - ActionStar dual touch panels
343 - Atmel panels
343 - Cando dual touch panels 344 - Cando dual touch panels
344 - Chunghwa panels 345 - Chunghwa panels
345 - CVTouch panels 346 - CVTouch panels
@@ -354,12 +355,15 @@ config HID_MULTITOUCH
354 - Lumio CrystalTouch panels 355 - Lumio CrystalTouch panels
355 - MosArt dual-touch panels 356 - MosArt dual-touch panels
356 - PenMount dual touch panels 357 - PenMount dual touch panels
358 - PixArt optical touch screen
357 - Pixcir dual touch panels 359 - Pixcir dual touch panels
360 - Quanta panels
358 - eGalax dual-touch panels, including the Joojoo and Wetab tablets 361 - eGalax dual-touch panels, including the Joojoo and Wetab tablets
359 - Stantum multitouch panels 362 - Stantum multitouch panels
360 - Touch International Panels 363 - Touch International Panels
361 - Unitec Panels 364 - Unitec Panels
362 - XAT optical touch panels 365 - XAT optical touch panels
366 - Xiroku optical touch panels
363 367
364 If unsure, say N. 368 If unsure, say N.
365 369
@@ -471,12 +475,6 @@ config HID_PRIMAX
471 Support for Primax devices that are not fully compliant with the 475 Support for Primax devices that are not fully compliant with the
472 HID standard. 476 HID standard.
473 477
474config HID_QUANTA
475 tristate "Quanta Optical Touch panels"
476 depends on USB_HID
477 ---help---
478 Support for Quanta Optical Touch dual-touch panels.
479
480config HID_ROCCAT 478config HID_ROCCAT
481 tristate "Roccat special event support" 479 tristate "Roccat special event support"
482 depends on USB_HID 480 depends on USB_HID
@@ -497,6 +495,13 @@ config HID_ROCCAT_ARVO
497 ---help--- 495 ---help---
498 Support for Roccat Arvo keyboard. 496 Support for Roccat Arvo keyboard.
499 497
498config HID_ROCCAT_ISKU
499 tristate "Roccat Isku keyboard support"
500 depends on USB_HID
501 depends on HID_ROCCAT
502 ---help---
503 Support for Roccat Isku keyboard.
504
500config HID_ROCCAT_KONE 505config HID_ROCCAT_KONE
501 tristate "Roccat Kone Mouse support" 506 tristate "Roccat Kone Mouse support"
502 depends on USB_HID 507 depends on USB_HID
@@ -565,6 +570,12 @@ config GREENASIA_FF
565 (like MANTA Warrior MM816 and SpeedLink Strike2 SL-6635) or adapter 570 (like MANTA Warrior MM816 and SpeedLink Strike2 SL-6635) or adapter
566 and want to enable force feedback support for it. 571 and want to enable force feedback support for it.
567 572
573config HID_HYPERV_MOUSE
574 tristate "Microsoft Hyper-V mouse driver"
575 depends on HYPERV
576 ---help---
577 Select this option to enable the Hyper-V mouse driver.
578
568config HID_SMARTJOYPLUS 579config HID_SMARTJOYPLUS
569 tristate "SmartJoy PLUS PS2/USB adapter support" 580 tristate "SmartJoy PLUS PS2/USB adapter support"
570 depends on USB_HID 581 depends on USB_HID
@@ -625,9 +636,19 @@ config HID_WIIMOTE
625 depends on BT_HIDP 636 depends on BT_HIDP
626 depends on LEDS_CLASS 637 depends on LEDS_CLASS
627 select POWER_SUPPLY 638 select POWER_SUPPLY
639 select INPUT_FF_MEMLESS
628 ---help--- 640 ---help---
629 Support for the Nintendo Wii Remote bluetooth device. 641 Support for the Nintendo Wii Remote bluetooth device.
630 642
643config HID_WIIMOTE_EXT
644 bool "Nintendo Wii Remote Extension support"
645 depends on HID_WIIMOTE
646 default HID_WIIMOTE
647 ---help---
648 Support for extension controllers of the Nintendo Wii Remote. Say yes
649 here if you want to use the Nintendo Motion+, Nunchuck or Classic
650 extension controllers with your Wii Remote.
651
631config HID_ZEROPLUS 652config HID_ZEROPLUS
632 tristate "Zeroplus based game controller support" 653 tristate "Zeroplus based game controller support"
633 depends on USB_HID 654 depends on USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 1e0d2a638b2..8aefdc963cc 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -25,6 +25,14 @@ ifdef CONFIG_LOGIWHEELS_FF
25 hid-logitech-y += hid-lg4ff.o 25 hid-logitech-y += hid-lg4ff.o
26endif 26endif
27 27
28hid-wiimote-y := hid-wiimote-core.o
29ifdef CONFIG_HID_WIIMOTE_EXT
30 hid-wiimote-y += hid-wiimote-ext.o
31endif
32ifdef CONFIG_DEBUG_FS
33 hid-wiimote-y += hid-wiimote-debug.o
34endif
35
28obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o 36obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o
29obj-$(CONFIG_HID_ACRUX) += hid-axff.o 37obj-$(CONFIG_HID_ACRUX) += hid-axff.o
30obj-$(CONFIG_HID_APPLE) += hid-apple.o 38obj-$(CONFIG_HID_APPLE) += hid-apple.o
@@ -38,6 +46,7 @@ obj-$(CONFIG_HID_ELECOM) += hid-elecom.o
38obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o 46obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o
39obj-$(CONFIG_HID_GYRATION) += hid-gyration.o 47obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
40obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o 48obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o
49obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o
41obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o 50obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o
42obj-$(CONFIG_HID_KEYTOUCH) += hid-keytouch.o 51obj-$(CONFIG_HID_KEYTOUCH) += hid-keytouch.o
43obj-$(CONFIG_HID_KYE) += hid-kye.o 52obj-$(CONFIG_HID_KYE) += hid-kye.o
@@ -51,7 +60,6 @@ obj-$(CONFIG_HID_MULTITOUCH) += hid-multitouch.o
51obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o 60obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o
52obj-$(CONFIG_HID_ORTEK) += hid-ortek.o 61obj-$(CONFIG_HID_ORTEK) += hid-ortek.o
53obj-$(CONFIG_HID_PRODIKEYS) += hid-prodikeys.o 62obj-$(CONFIG_HID_PRODIKEYS) += hid-prodikeys.o
54obj-$(CONFIG_HID_QUANTA) += hid-quanta.o
55obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o 63obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o
56obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o 64obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o
57obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o 65obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o
@@ -59,6 +67,7 @@ obj-$(CONFIG_HID_PRIMAX) += hid-primax.o
59obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o 67obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o
60obj-$(CONFIG_HID_ROCCAT_COMMON) += hid-roccat-common.o 68obj-$(CONFIG_HID_ROCCAT_COMMON) += hid-roccat-common.o
61obj-$(CONFIG_HID_ROCCAT_ARVO) += hid-roccat-arvo.o 69obj-$(CONFIG_HID_ROCCAT_ARVO) += hid-roccat-arvo.o
70obj-$(CONFIG_HID_ROCCAT_ISKU) += hid-roccat-isku.o
62obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o 71obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o
63obj-$(CONFIG_HID_ROCCAT_KONEPLUS) += hid-roccat-koneplus.o 72obj-$(CONFIG_HID_ROCCAT_KONEPLUS) += hid-roccat-koneplus.o
64obj-$(CONFIG_HID_ROCCAT_KOVAPLUS) += hid-roccat-kovaplus.o 73obj-$(CONFIG_HID_ROCCAT_KOVAPLUS) += hid-roccat-kovaplus.o
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 8cdb4b45b30..299d2387112 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
diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c
index 3bdb4500f95..5be858dd9a1 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 ebcc7a232a0..b88ae113d36 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1406,11 +1406,13 @@ static const struct hid_device_id hid_have_special_driver[] = {
1406 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) }, 1406 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
1407 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) }, 1407 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
1408 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) }, 1408 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
1409 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) }, 1409 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
1410 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) }, 1410 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
1411 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) }, 1411 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) }, 1412 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) }, 1413 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
1414 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
1415 { HID_USB_DEVICE(USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
1414 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, 1416 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
1415 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) }, 1417 { HID_USB_DEVICE(USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2515) },
1416 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) }, 1418 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
@@ -1425,6 +1427,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1425 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) }, 1427 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
1426 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) }, 1428 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
1427 { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) }, 1429 { HID_USB_DEVICE(USB_VENDOR_ID_HANVON, USB_DEVICE_ID_HANVON_MULTITOUCH) },
1430 { HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT, USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
1428 { HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, USB_DEVICE_ID_IDEACOM_IDC6650) }, 1431 { HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, USB_DEVICE_ID_IDEACOM_IDC6650) },
1429 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) }, 1432 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
1430 { HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) }, 1433 { HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
@@ -1500,11 +1503,15 @@ static const struct hid_device_id hid_have_special_driver[] = {
1500 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) }, 1503 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
1501 { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) }, 1504 { HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, USB_DEVICE_ID_PENMOUNT_PCI) },
1502 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 1505 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1506 { HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
1507 { HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
1508 { HID_USB_DEVICE(USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
1503 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) }, 1509 { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
1504 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, 1510 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1505 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) }, 1511 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
1506 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, 1512 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
1507 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) }, 1513 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
1514 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
1508 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, 1515 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
1509 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) }, 1516 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
1510 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 1517 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
@@ -1546,11 +1553,21 @@ static const struct hid_device_id hid_have_special_driver[] = {
1546 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) }, 1553 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
1547 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) }, 1554 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
1548 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 1555 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
1556 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
1549 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) }, 1557 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
1550 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) }, 1558 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
1551 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) }, 1559 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
1552 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, 1560 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1553 { HID_USB_DEVICE(USB_VENDOR_ID_XAT, USB_DEVICE_ID_XAT_CSR) }, 1561 { HID_USB_DEVICE(USB_VENDOR_ID_XAT, USB_DEVICE_ID_XAT_CSR) },
1562 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX) },
1563 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX) },
1564 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR) },
1565 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX1) },
1566 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX1) },
1567 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR1) },
1568 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_SPX2) },
1569 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_MPX2) },
1570 { HID_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR2) },
1554 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) }, 1571 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1555 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, 1572 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1556 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, 1573 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
@@ -1774,8 +1791,8 @@ static const struct hid_device_id hid_ignore_list[] = {
1774 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, 1791 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
1775 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) }, 1792 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
1776 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) }, 1793 { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
1794 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1777 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) }, 1795 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1778 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1779 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) }, 1796 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1780 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) }, 1797 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1781 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) }, 1798 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 940af3c20b5..01dd9a7daf7 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 61eece47204..e832f44ae38 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 4e02ec7a1c4..2630d483d26 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 279ba530003..f1e1bcf6742 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 91e3a032112..4e7542151e2 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/staging/hv/hv_mouse.c b/drivers/hid/hid-hyperv.c
index ccd39c70c52..0c33ae9cf0f 100644
--- a/drivers/staging/hv/hv_mouse.c
+++ b/drivers/hid/hid-hyperv.c
@@ -14,11 +14,8 @@
14 */ 14 */
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/delay.h>
18#include <linux/device.h> 17#include <linux/device.h>
19#include <linux/workqueue.h> 18#include <linux/completion.h>
20#include <linux/sched.h>
21#include <linux/wait.h>
22#include <linux/input.h> 19#include <linux/input.h>
23#include <linux/hid.h> 20#include <linux/hid.h>
24#include <linux/hiddev.h> 21#include <linux/hiddev.h>
@@ -118,7 +115,6 @@ struct synthhid_input_report {
118#define INPUTVSC_SEND_RING_BUFFER_SIZE (10*PAGE_SIZE) 115#define INPUTVSC_SEND_RING_BUFFER_SIZE (10*PAGE_SIZE)
119#define INPUTVSC_RECV_RING_BUFFER_SIZE (10*PAGE_SIZE) 116#define INPUTVSC_RECV_RING_BUFFER_SIZE (10*PAGE_SIZE)
120 117
121#define NBITS(x) (((x)/BITS_PER_LONG)+1)
122 118
123enum pipe_prot_msg_type { 119enum pipe_prot_msg_type {
124 PIPE_MESSAGE_INVALID, 120 PIPE_MESSAGE_INVALID,
@@ -148,7 +144,8 @@ struct mousevsc_prt_msg {
148 */ 144 */
149struct mousevsc_dev { 145struct mousevsc_dev {
150 struct hv_device *device; 146 struct hv_device *device;
151 unsigned char init_complete; 147 bool init_complete;
148 bool connected;
152 struct mousevsc_prt_msg protocol_req; 149 struct mousevsc_prt_msg protocol_req;
153 struct mousevsc_prt_msg protocol_resp; 150 struct mousevsc_prt_msg protocol_resp;
154 /* Synchronize the request/response if needed */ 151 /* Synchronize the request/response if needed */
@@ -159,12 +156,11 @@ struct mousevsc_dev {
159 unsigned char *report_desc; 156 unsigned char *report_desc;
160 u32 report_desc_size; 157 u32 report_desc_size;
161 struct hv_input_dev_info hid_dev_info; 158 struct hv_input_dev_info hid_dev_info;
162 int connected;
163 struct hid_device *hid_device; 159 struct hid_device *hid_device;
164}; 160};
165 161
166 162
167static struct mousevsc_dev *alloc_input_device(struct hv_device *device) 163static struct mousevsc_dev *mousevsc_alloc_device(struct hv_device *device)
168{ 164{
169 struct mousevsc_dev *input_dev; 165 struct mousevsc_dev *input_dev;
170 166
@@ -176,11 +172,12 @@ static struct mousevsc_dev *alloc_input_device(struct hv_device *device)
176 input_dev->device = device; 172 input_dev->device = device;
177 hv_set_drvdata(device, input_dev); 173 hv_set_drvdata(device, input_dev);
178 init_completion(&input_dev->wait_event); 174 init_completion(&input_dev->wait_event);
175 input_dev->init_complete = false;
179 176
180 return input_dev; 177 return input_dev;
181} 178}
182 179
183static void free_input_device(struct mousevsc_dev *device) 180static void mousevsc_free_device(struct mousevsc_dev *device)
184{ 181{
185 kfree(device->hid_desc); 182 kfree(device->hid_desc);
186 kfree(device->report_desc); 183 kfree(device->report_desc);
@@ -188,7 +185,6 @@ static void free_input_device(struct mousevsc_dev *device)
188 kfree(device); 185 kfree(device);
189} 186}
190 187
191
192static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, 188static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
193 struct synthhid_device_info *device_info) 189 struct synthhid_device_info *device_info)
194{ 190{
@@ -196,14 +192,12 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
196 struct hid_descriptor *desc; 192 struct hid_descriptor *desc;
197 struct mousevsc_prt_msg ack; 193 struct mousevsc_prt_msg ack;
198 194
199 /* Assume success for now */ 195 input_device->dev_info_status = -ENOMEM;
200 input_device->dev_info_status = 0;
201
202 memcpy(&input_device->hid_dev_info, &device_info->hid_dev_info,
203 sizeof(struct hv_input_dev_info));
204 196
197 input_device->hid_dev_info = device_info->hid_dev_info;
205 desc = &device_info->hid_descriptor; 198 desc = &device_info->hid_descriptor;
206 WARN_ON(desc->bLength == 0); 199 if (desc->bLength == 0)
200 goto cleanup;
207 201
208 input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC); 202 input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
209 203
@@ -213,13 +207,18 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
213 memcpy(input_device->hid_desc, desc, desc->bLength); 207 memcpy(input_device->hid_desc, desc, desc->bLength);
214 208
215 input_device->report_desc_size = desc->desc[0].wDescriptorLength; 209 input_device->report_desc_size = desc->desc[0].wDescriptorLength;
216 if (input_device->report_desc_size == 0) 210 if (input_device->report_desc_size == 0) {
211 input_device->dev_info_status = -EINVAL;
217 goto cleanup; 212 goto cleanup;
213 }
214
218 input_device->report_desc = kzalloc(input_device->report_desc_size, 215 input_device->report_desc = kzalloc(input_device->report_desc_size,
219 GFP_ATOMIC); 216 GFP_ATOMIC);
220 217
221 if (!input_device->report_desc) 218 if (!input_device->report_desc) {
219 input_device->dev_info_status = -ENOMEM;
222 goto cleanup; 220 goto cleanup;
221 }
223 222
224 memcpy(input_device->report_desc, 223 memcpy(input_device->report_desc,
225 ((unsigned char *)desc) + desc->bLength, 224 ((unsigned char *)desc) + desc->bLength,
@@ -242,22 +241,14 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
242 (unsigned long)&ack, 241 (unsigned long)&ack,
243 VM_PKT_DATA_INBAND, 242 VM_PKT_DATA_INBAND,
244 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 243 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
245 if (ret != 0)
246 goto cleanup;
247
248 complete(&input_device->wait_event);
249 244
250 return; 245 if (!ret)
246 input_device->dev_info_status = 0;
251 247
252cleanup: 248cleanup:
253 kfree(input_device->hid_desc);
254 input_device->hid_desc = NULL;
255
256 kfree(input_device->report_desc);
257 input_device->report_desc = NULL;
258
259 input_device->dev_info_status = -1;
260 complete(&input_device->wait_event); 249 complete(&input_device->wait_event);
250
251 return;
261} 252}
262 253
263static void mousevsc_on_receive(struct hv_device *device, 254static void mousevsc_on_receive(struct hv_device *device,
@@ -274,10 +265,22 @@ static void mousevsc_on_receive(struct hv_device *device,
274 if (pipe_msg->type != PIPE_MESSAGE_DATA) 265 if (pipe_msg->type != PIPE_MESSAGE_DATA)
275 return; 266 return;
276 267
277 hid_msg = (struct synthhid_msg *)&pipe_msg->data[0]; 268 hid_msg = (struct synthhid_msg *)pipe_msg->data;
278 269
279 switch (hid_msg->header.type) { 270 switch (hid_msg->header.type) {
280 case SYNTH_HID_PROTOCOL_RESPONSE: 271 case SYNTH_HID_PROTOCOL_RESPONSE:
272 /*
273 * While it will be impossible for us to protect against
274 * malicious/buggy hypervisor/host, add a check here to
275 * ensure we don't corrupt memory.
276 */
277 if ((pipe_msg->size + sizeof(struct pipe_prt_msg)
278 - sizeof(unsigned char))
279 > sizeof(struct mousevsc_prt_msg)) {
280 WARN_ON(1);
281 break;
282 }
283
281 memcpy(&input_dev->protocol_resp, pipe_msg, 284 memcpy(&input_dev->protocol_resp, pipe_msg,
282 pipe_msg->size + sizeof(struct pipe_prt_msg) - 285 pipe_msg->size + sizeof(struct pipe_prt_msg) -
283 sizeof(unsigned char)); 286 sizeof(unsigned char));
@@ -292,11 +295,11 @@ static void mousevsc_on_receive(struct hv_device *device,
292 * hid desc and report desc 295 * hid desc and report desc
293 */ 296 */
294 mousevsc_on_receive_device_info(input_dev, 297 mousevsc_on_receive_device_info(input_dev,
295 (struct synthhid_device_info *)&pipe_msg->data[0]); 298 (struct synthhid_device_info *)pipe_msg->data);
296 break; 299 break;
297 case SYNTH_HID_INPUT_REPORT: 300 case SYNTH_HID_INPUT_REPORT:
298 input_report = 301 input_report =
299 (struct synthhid_input_report *)&pipe_msg->data[0]; 302 (struct synthhid_input_report *)pipe_msg->data;
300 if (!input_dev->init_complete) 303 if (!input_dev->init_complete)
301 break; 304 break;
302 hid_input_report(input_dev->hid_device, 305 hid_input_report(input_dev->hid_device,
@@ -313,73 +316,60 @@ static void mousevsc_on_receive(struct hv_device *device,
313 316
314static void mousevsc_on_channel_callback(void *context) 317static void mousevsc_on_channel_callback(void *context)
315{ 318{
316 const int packetSize = 0x100; 319 const int packet_size = 0x100;
317 int ret = 0; 320 int ret;
318 struct hv_device *device = (struct hv_device *)context; 321 struct hv_device *device = context;
319
320 u32 bytes_recvd; 322 u32 bytes_recvd;
321 u64 req_id; 323 u64 req_id;
322 unsigned char packet[0x100];
323 struct vmpacket_descriptor *desc; 324 struct vmpacket_descriptor *desc;
324 unsigned char *buffer = packet; 325 unsigned char *buffer;
325 int bufferlen = packetSize; 326 int bufferlen = packet_size;
326 327
328 buffer = kmalloc(bufferlen, GFP_ATOMIC);
329 if (!buffer)
330 return;
327 331
328 do { 332 do {
329 ret = vmbus_recvpacket_raw(device->channel, buffer, 333 ret = vmbus_recvpacket_raw(device->channel, buffer,
330 bufferlen, &bytes_recvd, &req_id); 334 bufferlen, &bytes_recvd, &req_id);
331 335
332 if (ret == 0) { 336 switch (ret) {
333 if (bytes_recvd > 0) { 337 case 0:
334 desc = (struct vmpacket_descriptor *)buffer; 338 if (bytes_recvd <= 0) {
335 339 kfree(buffer);
336 switch (desc->type) { 340 return;
337 case VM_PKT_COMP: 341 }
338 break; 342 desc = (struct vmpacket_descriptor *)buffer;
339 343
340 case VM_PKT_DATA_INBAND: 344 switch (desc->type) {
341 mousevsc_on_receive( 345 case VM_PKT_COMP:
342 device, desc); 346 break;
343 break; 347
344 348 case VM_PKT_DATA_INBAND:
345 default: 349 mousevsc_on_receive(device, desc);
346 pr_err("unhandled packet type %d, tid %llx len %d\n", 350 break;
347 desc->type, 351
348 req_id, 352 default:
349 bytes_recvd); 353 pr_err("unhandled packet type %d, tid %llx len %d\n",
350 break; 354 desc->type, req_id, bytes_recvd);
351 }
352
353 /* reset */
354 if (bufferlen > packetSize) {
355 kfree(buffer);
356
357 buffer = packet;
358 bufferlen = packetSize;
359 }
360 } else {
361 if (bufferlen > packetSize) {
362 kfree(buffer);
363
364 buffer = packet;
365 bufferlen = packetSize;
366 }
367 break; 355 break;
368 } 356 }
369 } else if (ret == -ENOBUFS) { 357
358 break;
359
360 case -ENOBUFS:
361 kfree(buffer);
370 /* Handle large packet */ 362 /* Handle large packet */
371 bufferlen = bytes_recvd; 363 bufferlen = bytes_recvd;
372 buffer = kzalloc(bytes_recvd, GFP_ATOMIC); 364 buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
373 365
374 if (buffer == NULL) { 366 if (!buffer)
375 buffer = packet; 367 return;
376 bufferlen = packetSize; 368
377 break; 369 break;
378 }
379 } 370 }
380 } while (1); 371 } while (1);
381 372
382 return;
383} 373}
384 374
385static int mousevsc_connect_to_vsp(struct hv_device *device) 375static int mousevsc_connect_to_vsp(struct hv_device *device)
@@ -390,19 +380,15 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
390 struct mousevsc_prt_msg *request; 380 struct mousevsc_prt_msg *request;
391 struct mousevsc_prt_msg *response; 381 struct mousevsc_prt_msg *response;
392 382
393
394 request = &input_dev->protocol_req; 383 request = &input_dev->protocol_req;
395
396 memset(request, 0, sizeof(struct mousevsc_prt_msg)); 384 memset(request, 0, sizeof(struct mousevsc_prt_msg));
397 385
398 request->type = PIPE_MESSAGE_DATA; 386 request->type = PIPE_MESSAGE_DATA;
399 request->size = sizeof(struct synthhid_protocol_request); 387 request->size = sizeof(struct synthhid_protocol_request);
400
401 request->request.header.type = SYNTH_HID_PROTOCOL_REQUEST; 388 request->request.header.type = SYNTH_HID_PROTOCOL_REQUEST;
402 request->request.header.size = sizeof(unsigned int); 389 request->request.header.size = sizeof(unsigned int);
403 request->request.version_requested.version = SYNTHHID_INPUT_VERSION; 390 request->request.version_requested.version = SYNTHHID_INPUT_VERSION;
404 391
405
406 ret = vmbus_sendpacket(device->channel, request, 392 ret = vmbus_sendpacket(device->channel, request,
407 sizeof(struct pipe_prt_msg) - 393 sizeof(struct pipe_prt_msg) -
408 sizeof(unsigned char) + 394 sizeof(unsigned char) +
@@ -410,11 +396,11 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
410 (unsigned long)request, 396 (unsigned long)request,
411 VM_PKT_DATA_INBAND, 397 VM_PKT_DATA_INBAND,
412 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 398 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
413 if (ret != 0) 399 if (ret)
414 goto cleanup; 400 goto cleanup;
415 401
416 t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ); 402 t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
417 if (t == 0) { 403 if (!t) {
418 ret = -ETIMEDOUT; 404 ret = -ETIMEDOUT;
419 goto cleanup; 405 goto cleanup;
420 } 406 }
@@ -422,14 +408,14 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
422 response = &input_dev->protocol_resp; 408 response = &input_dev->protocol_resp;
423 409
424 if (!response->response.approved) { 410 if (!response->response.approved) {
425 pr_err("synthhid protocol request failed (version %d)", 411 pr_err("synthhid protocol request failed (version %d)\n",
426 SYNTHHID_INPUT_VERSION); 412 SYNTHHID_INPUT_VERSION);
427 ret = -ENODEV; 413 ret = -ENODEV;
428 goto cleanup; 414 goto cleanup;
429 } 415 }
430 416
431 t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ); 417 t = wait_for_completion_timeout(&input_dev->wait_event, 5*HZ);
432 if (t == 0) { 418 if (!t) {
433 ret = -ETIMEDOUT; 419 ret = -ETIMEDOUT;
434 goto cleanup; 420 goto cleanup;
435 } 421 }
@@ -438,11 +424,9 @@ static int mousevsc_connect_to_vsp(struct hv_device *device)
438 * We should have gotten the device attr, hid desc and report 424 * We should have gotten the device attr, hid desc and report
439 * desc at this point 425 * desc at this point
440 */ 426 */
441 if (input_dev->dev_info_status) 427 ret = input_dev->dev_info_status;
442 ret = -ENOMEM;
443 428
444cleanup: 429cleanup:
445
446 return ret; 430 return ret;
447} 431}
448 432
@@ -451,61 +435,40 @@ static int mousevsc_hid_open(struct hid_device *hid)
451 return 0; 435 return 0;
452} 436}
453 437
438static int mousevsc_hid_start(struct hid_device *hid)
439{
440 return 0;
441}
442
454static void mousevsc_hid_close(struct hid_device *hid) 443static void mousevsc_hid_close(struct hid_device *hid)
455{ 444{
456} 445}
457 446
447static void mousevsc_hid_stop(struct hid_device *hid)
448{
449}
450
458static struct hid_ll_driver mousevsc_ll_driver = { 451static struct hid_ll_driver mousevsc_ll_driver = {
459 .open = mousevsc_hid_open, 452 .open = mousevsc_hid_open,
460 .close = mousevsc_hid_close, 453 .close = mousevsc_hid_close,
454 .start = mousevsc_hid_start,
455 .stop = mousevsc_hid_stop,
461}; 456};
462 457
463static struct hid_driver mousevsc_hid_driver; 458static struct hid_driver mousevsc_hid_driver;
464 459
465static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len) 460static int mousevsc_probe(struct hv_device *device,
466{ 461 const struct hv_vmbus_device_id *dev_id)
467 struct hid_device *hid_dev;
468 struct mousevsc_dev *input_device = hv_get_drvdata(dev);
469
470 hid_dev = hid_allocate_device();
471 if (IS_ERR(hid_dev))
472 return;
473
474 hid_dev->ll_driver = &mousevsc_ll_driver;
475 hid_dev->driver = &mousevsc_hid_driver;
476
477 if (hid_parse_report(hid_dev, packet, len))
478 return;
479
480 hid_dev->bus = BUS_VIRTUAL;
481 hid_dev->vendor = input_device->hid_dev_info.vendor;
482 hid_dev->product = input_device->hid_dev_info.product;
483 hid_dev->version = input_device->hid_dev_info.version;
484
485 sprintf(hid_dev->name, "%s", "Microsoft Vmbus HID-compliant Mouse");
486
487 if (!hidinput_connect(hid_dev, 0)) {
488 hid_dev->claimed |= HID_CLAIMED_INPUT;
489
490 input_device->connected = 1;
491
492 }
493
494 input_device->hid_device = hid_dev;
495}
496
497static int mousevsc_on_device_add(struct hv_device *device)
498{ 462{
499 int ret = 0; 463 int ret;
500 struct mousevsc_dev *input_dev; 464 struct mousevsc_dev *input_dev;
465 struct hid_device *hid_dev;
501 466
502 input_dev = alloc_input_device(device); 467 input_dev = mousevsc_alloc_device(device);
503 468
504 if (!input_dev) 469 if (!input_dev)
505 return -ENOMEM; 470 return -ENOMEM;
506 471
507 input_dev->init_complete = false;
508
509 ret = vmbus_open(device->channel, 472 ret = vmbus_open(device->channel,
510 INPUTVSC_SEND_RING_BUFFER_SIZE, 473 INPUTVSC_SEND_RING_BUFFER_SIZE,
511 INPUTVSC_RECV_RING_BUFFER_SIZE, 474 INPUTVSC_RECV_RING_BUFFER_SIZE,
@@ -515,54 +478,78 @@ static int mousevsc_on_device_add(struct hv_device *device)
515 device 478 device
516 ); 479 );
517 480
518 if (ret != 0) { 481 if (ret)
519 free_input_device(input_dev); 482 goto probe_err0;
520 return ret;
521 }
522
523 483
524 ret = mousevsc_connect_to_vsp(device); 484 ret = mousevsc_connect_to_vsp(device);
525 485
526 if (ret != 0) { 486 if (ret)
527 vmbus_close(device->channel); 487 goto probe_err1;
528 free_input_device(input_dev);
529 return ret;
530 }
531
532 488
533 /* workaround SA-167 */ 489 /* workaround SA-167 */
534 if (input_dev->report_desc[14] == 0x25) 490 if (input_dev->report_desc[14] == 0x25)
535 input_dev->report_desc[14] = 0x29; 491 input_dev->report_desc[14] = 0x29;
536 492
537 reportdesc_callback(device, input_dev->report_desc, 493 hid_dev = hid_allocate_device();
538 input_dev->report_desc_size); 494 if (IS_ERR(hid_dev)) {
495 ret = PTR_ERR(hid_dev);
496 goto probe_err1;
497 }
498
499 hid_dev->ll_driver = &mousevsc_ll_driver;
500 hid_dev->driver = &mousevsc_hid_driver;
501 hid_dev->bus = BUS_VIRTUAL;
502 hid_dev->vendor = input_dev->hid_dev_info.vendor;
503 hid_dev->product = input_dev->hid_dev_info.product;
504 hid_dev->version = input_dev->hid_dev_info.version;
505 input_dev->hid_device = hid_dev;
506
507 sprintf(hid_dev->name, "%s", "Microsoft Vmbus HID-compliant Mouse");
508
509 ret = hid_add_device(hid_dev);
510 if (ret)
511 goto probe_err1;
512
513 ret = hid_parse_report(hid_dev, input_dev->report_desc,
514 input_dev->report_desc_size);
515
516 if (ret) {
517 hid_err(hid_dev, "parse failed\n");
518 goto probe_err2;
519 }
539 520
521 ret = hid_hw_start(hid_dev, HID_CONNECT_HIDINPUT | HID_CONNECT_HIDDEV);
522
523 if (ret) {
524 hid_err(hid_dev, "hw start failed\n");
525 goto probe_err2;
526 }
527
528 input_dev->connected = true;
540 input_dev->init_complete = true; 529 input_dev->init_complete = true;
541 530
542 return ret; 531 return ret;
543}
544 532
545static int mousevsc_probe(struct hv_device *dev, 533probe_err2:
546 const struct hv_vmbus_device_id *dev_id) 534 hid_destroy_device(hid_dev);
547{
548 535
549 return mousevsc_on_device_add(dev); 536probe_err1:
537 vmbus_close(device->channel);
550 538
539probe_err0:
540 mousevsc_free_device(input_dev);
541
542 return ret;
551} 543}
552 544
545
553static int mousevsc_remove(struct hv_device *dev) 546static int mousevsc_remove(struct hv_device *dev)
554{ 547{
555 struct mousevsc_dev *input_dev = hv_get_drvdata(dev); 548 struct mousevsc_dev *input_dev = hv_get_drvdata(dev);
556 549
557 vmbus_close(dev->channel); 550 vmbus_close(dev->channel);
558 551 hid_destroy_device(input_dev->hid_device);
559 if (input_dev->connected) { 552 mousevsc_free_device(input_dev);
560 hidinput_disconnect(input_dev->hid_device);
561 input_dev->connected = 0;
562 hid_destroy_device(input_dev->hid_device);
563 }
564
565 free_input_device(input_dev);
566 553
567 return 0; 554 return 0;
568} 555}
@@ -577,7 +564,7 @@ static const struct hv_vmbus_device_id id_table[] = {
577MODULE_DEVICE_TABLE(vmbus, id_table); 564MODULE_DEVICE_TABLE(vmbus, id_table);
578 565
579static struct hv_driver mousevsc_drv = { 566static struct hv_driver mousevsc_drv = {
580 .name = "mousevsc", 567 .name = KBUILD_MODNAME,
581 .id_table = id_table, 568 .id_table = id_table,
582 .probe = mousevsc_probe, 569 .probe = mousevsc_probe,
583 .remove = mousevsc_remove, 570 .remove = mousevsc_remove,
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 06ce996b8b6..448e9d89f8d 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -21,6 +21,7 @@
21#define USB_VENDOR_ID_3M 0x0596 21#define USB_VENDOR_ID_3M 0x0596
22#define USB_DEVICE_ID_3M1968 0x0500 22#define USB_DEVICE_ID_3M1968 0x0500
23#define USB_DEVICE_ID_3M2256 0x0502 23#define USB_DEVICE_ID_3M2256 0x0502
24#define USB_DEVICE_ID_3M3266 0x0506
24 25
25#define USB_VENDOR_ID_A4TECH 0x09da 26#define USB_VENDOR_ID_A4TECH 0x09da
26#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 27#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
@@ -145,6 +146,9 @@
145#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 146#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
146#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 147#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
147 148
149#define USB_VENDOR_ID_ATMEL 0x03eb
150#define USB_DEVICE_ID_ATMEL_MULTITOUCH 0x211c
151
148#define USB_VENDOR_ID_AVERMEDIA 0x07ca 152#define USB_VENDOR_ID_AVERMEDIA 0x07ca
149#define USB_DEVICE_ID_AVER_FM_MR800 0xb800 153#define USB_DEVICE_ID_AVER_FM_MR800 0xb800
150 154
@@ -230,11 +234,14 @@
230 234
231#define USB_VENDOR_ID_DWAV 0x0eef 235#define USB_VENDOR_ID_DWAV 0x0eef
232#define USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER 0x0001 236#define USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER 0x0001
233#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH 0x480d 237#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D 0x480d
234#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1 0x720c 238#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E 0x480e
235#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2 0x72a1 239#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C 0x720c
236#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3 0x480e 240#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B 0x726b
237#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4 0x726b 241#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1 0x72a1
242#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA 0x72fa
243#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302 0x7302
244#define USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001 0xa001
238 245
239#define USB_VENDOR_ID_ELECOM 0x056e 246#define USB_VENDOR_ID_ELECOM 0x056e
240#define USB_DEVICE_ID_ELECOM_BM084 0x0061 247#define USB_DEVICE_ID_ELECOM_BM084 0x0061
@@ -266,7 +273,7 @@
266#define USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR 0x0002 273#define USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR 0x0002
267 274
268#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc 275#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
269#define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0001 276#define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0003
270 277
271#define USB_VENDOR_ID_GLAB 0x06c2 278#define USB_VENDOR_ID_GLAB 0x06c2
272#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038 279#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
@@ -356,6 +363,9 @@
356#define USB_VENDOR_ID_HANVON 0x20b3 363#define USB_VENDOR_ID_HANVON 0x20b3
357#define USB_DEVICE_ID_HANVON_MULTITOUCH 0x0a18 364#define USB_DEVICE_ID_HANVON_MULTITOUCH 0x0a18
358 365
366#define USB_VENDOR_ID_HANVON_ALT 0x22ed
367#define USB_DEVICE_ID_HANVON_ALT_MULTITOUCH 0x1010
368
359#define USB_VENDOR_ID_HAPP 0x078b 369#define USB_VENDOR_ID_HAPP 0x078b
360#define USB_DEVICE_ID_UGCI_DRIVING 0x0010 370#define USB_DEVICE_ID_UGCI_DRIVING 0x0010
361#define USB_DEVICE_ID_UGCI_FLYING 0x0020 371#define USB_DEVICE_ID_UGCI_FLYING 0x0020
@@ -571,6 +581,11 @@
571#define USB_VENDOR_ID_PI_ENGINEERING 0x05f3 581#define USB_VENDOR_ID_PI_ENGINEERING 0x05f3
572#define USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL 0xff 582#define USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL 0xff
573 583
584#define USB_VENDOR_ID_PIXART 0x093a
585#define USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN 0x8001
586#define USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1 0x8002
587#define USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2 0x8003
588
574#define USB_VENDOR_ID_PLAYDOTCOM 0x0b43 589#define USB_VENDOR_ID_PLAYDOTCOM 0x0b43
575#define USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII 0x0003 590#define USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII 0x0003
576 591
@@ -581,11 +596,14 @@
581#define USB_DEVICE_ID_PRODIGE_CORDLESS 0x3062 596#define USB_DEVICE_ID_PRODIGE_CORDLESS 0x3062
582 597
583#define USB_VENDOR_ID_QUANTA 0x0408 598#define USB_VENDOR_ID_QUANTA 0x0408
584#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH 0x3000 599#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH 0x3000
600#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001 0x3001
601#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008 0x3008
585#define USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN 0x3001 602#define USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN 0x3001
586 603
587#define USB_VENDOR_ID_ROCCAT 0x1e7d 604#define USB_VENDOR_ID_ROCCAT 0x1e7d
588#define USB_DEVICE_ID_ROCCAT_ARVO 0x30d4 605#define USB_DEVICE_ID_ROCCAT_ARVO 0x30d4
606#define USB_DEVICE_ID_ROCCAT_ISKU 0x319c
589#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced 607#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced
590#define USB_DEVICE_ID_ROCCAT_KONEPLUS 0x2d51 608#define USB_DEVICE_ID_ROCCAT_KONEPLUS 0x2d51
591#define USB_DEVICE_ID_ROCCAT_KOVAPLUS 0x2d50 609#define USB_DEVICE_ID_ROCCAT_KOVAPLUS 0x2d50
@@ -679,6 +697,7 @@
679 697
680#define USB_VENDOR_ID_WACOM 0x056a 698#define USB_VENDOR_ID_WACOM 0x056a
681#define USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH 0x81 699#define USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH 0x81
700#define USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH 0x00BD
682 701
683#define USB_VENDOR_ID_WALTOP 0x172f 702#define USB_VENDOR_ID_WALTOP 0x172f
684#define USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH 0x0032 703#define USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH 0x0032
@@ -707,6 +726,17 @@
707#define USB_VENDOR_ID_XAT 0x2505 726#define USB_VENDOR_ID_XAT 0x2505
708#define USB_DEVICE_ID_XAT_CSR 0x0220 727#define USB_DEVICE_ID_XAT_CSR 0x0220
709 728
729#define USB_VENDOR_ID_XIROKU 0x1477
730#define USB_DEVICE_ID_XIROKU_SPX 0x1006
731#define USB_DEVICE_ID_XIROKU_MPX 0x1007
732#define USB_DEVICE_ID_XIROKU_CSR 0x100e
733#define USB_DEVICE_ID_XIROKU_SPX1 0x1021
734#define USB_DEVICE_ID_XIROKU_CSR1 0x1022
735#define USB_DEVICE_ID_XIROKU_MPX1 0x1023
736#define USB_DEVICE_ID_XIROKU_SPX2 0x1024
737#define USB_DEVICE_ID_XIROKU_CSR2 0x1025
738#define USB_DEVICE_ID_XIROKU_MPX2 0x1026
739
710#define USB_VENDOR_ID_YEALINK 0x6993 740#define USB_VENDOR_ID_YEALINK 0x6993
711#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001 741#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
712 742
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index b32beb9d184..24fc4423b93 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -50,7 +50,6 @@ MODULE_LICENSE("GPL");
50#define MT_QUIRK_ALWAYS_VALID (1 << 4) 50#define MT_QUIRK_ALWAYS_VALID (1 << 4)
51#define MT_QUIRK_VALID_IS_INRANGE (1 << 5) 51#define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
52#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6) 52#define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
53#define MT_QUIRK_EGALAX_XYZ_FIXUP (1 << 7)
54#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8) 53#define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
55 54
56struct mt_slot { 55struct mt_slot {
@@ -60,9 +59,19 @@ struct mt_slot {
60 bool seen_in_this_frame;/* has this slot been updated */ 59 bool seen_in_this_frame;/* has this slot been updated */
61}; 60};
62 61
62struct mt_class {
63 __s32 name; /* MT_CLS */
64 __s32 quirks;
65 __s32 sn_move; /* Signal/noise ratio for move events */
66 __s32 sn_width; /* Signal/noise ratio for width events */
67 __s32 sn_height; /* Signal/noise ratio for height events */
68 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
69 __u8 maxcontacts;
70};
71
63struct mt_device { 72struct mt_device {
64 struct mt_slot curdata; /* placeholder of incoming data */ 73 struct mt_slot curdata; /* placeholder of incoming data */
65 struct mt_class *mtclass; /* our mt device class */ 74 struct mt_class mtclass; /* our mt device class */
66 unsigned last_field_index; /* last field index of the report */ 75 unsigned last_field_index; /* last field index of the report */
67 unsigned last_slot_field; /* the last field of a slot */ 76 unsigned last_slot_field; /* the last field of a slot */
68 int last_mt_collection; /* last known mt-related collection */ 77 int last_mt_collection; /* last known mt-related collection */
@@ -74,30 +83,23 @@ struct mt_device {
74 struct mt_slot *slots; 83 struct mt_slot *slots;
75}; 84};
76 85
77struct mt_class {
78 __s32 name; /* MT_CLS */
79 __s32 quirks;
80 __s32 sn_move; /* Signal/noise ratio for move events */
81 __s32 sn_width; /* Signal/noise ratio for width events */
82 __s32 sn_height; /* Signal/noise ratio for height events */
83 __s32 sn_pressure; /* Signal/noise ratio for pressure events */
84 __u8 maxcontacts;
85};
86
87/* classes of device behavior */ 86/* classes of device behavior */
88#define MT_CLS_DEFAULT 0x0001 87#define MT_CLS_DEFAULT 0x0001
89 88
90#define MT_CLS_SERIAL 0x0002 89#define MT_CLS_SERIAL 0x0002
91#define MT_CLS_CONFIDENCE 0x0003 90#define MT_CLS_CONFIDENCE 0x0003
92#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0004 91#define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
93#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0005 92#define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
94#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0006 93#define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
95#define MT_CLS_DUAL_NSMU_CONTACTID 0x0007 94#define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
95#define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
96#define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
96 97
97/* vendor specific classes */ 98/* vendor specific classes */
98#define MT_CLS_3M 0x0101 99#define MT_CLS_3M 0x0101
99#define MT_CLS_CYPRESS 0x0102 100#define MT_CLS_CYPRESS 0x0102
100#define MT_CLS_EGALAX 0x0103 101#define MT_CLS_EGALAX 0x0103
102#define MT_CLS_EGALAX_SERIAL 0x0104
101 103
102#define MT_DEFAULT_MAXCONTACT 10 104#define MT_DEFAULT_MAXCONTACT 10
103 105
@@ -140,6 +142,9 @@ static struct mt_class mt_classes[] = {
140 .quirks = MT_QUIRK_ALWAYS_VALID}, 142 .quirks = MT_QUIRK_ALWAYS_VALID},
141 { .name = MT_CLS_CONFIDENCE, 143 { .name = MT_CLS_CONFIDENCE,
142 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE }, 144 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE },
145 { .name = MT_CLS_CONFIDENCE_CONTACT_ID,
146 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
147 MT_QUIRK_SLOT_IS_CONTACTID },
143 { .name = MT_CLS_CONFIDENCE_MINUS_ONE, 148 { .name = MT_CLS_CONFIDENCE_MINUS_ONE,
144 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE | 149 .quirks = MT_QUIRK_VALID_IS_CONFIDENCE |
145 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE }, 150 MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE },
@@ -155,6 +160,9 @@ static struct mt_class mt_classes[] = {
155 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP | 160 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
156 MT_QUIRK_SLOT_IS_CONTACTID, 161 MT_QUIRK_SLOT_IS_CONTACTID,
157 .maxcontacts = 2 }, 162 .maxcontacts = 2 },
163 { .name = MT_CLS_INRANGE_CONTACTNUMBER,
164 .quirks = MT_QUIRK_VALID_IS_INRANGE |
165 MT_QUIRK_SLOT_IS_CONTACTNUMBER },
158 166
159 /* 167 /*
160 * vendor specific classes 168 * vendor specific classes
@@ -171,9 +179,13 @@ static struct mt_class mt_classes[] = {
171 .maxcontacts = 10 }, 179 .maxcontacts = 10 },
172 { .name = MT_CLS_EGALAX, 180 { .name = MT_CLS_EGALAX,
173 .quirks = MT_QUIRK_SLOT_IS_CONTACTID | 181 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
174 MT_QUIRK_VALID_IS_INRANGE | 182 MT_QUIRK_VALID_IS_INRANGE,
175 MT_QUIRK_EGALAX_XYZ_FIXUP, 183 .sn_move = 4096,
176 .maxcontacts = 2, 184 .sn_pressure = 32,
185 },
186 { .name = MT_CLS_EGALAX_SERIAL,
187 .quirks = MT_QUIRK_SLOT_IS_CONTACTID |
188 MT_QUIRK_ALWAYS_VALID,
177 .sn_move = 4096, 189 .sn_move = 4096,
178 .sn_pressure = 32, 190 .sn_pressure = 32,
179 }, 191 },
@@ -181,6 +193,44 @@ static struct mt_class mt_classes[] = {
181 { } 193 { }
182}; 194};
183 195
196static ssize_t mt_show_quirks(struct device *dev,
197 struct device_attribute *attr,
198 char *buf)
199{
200 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
201 struct mt_device *td = hid_get_drvdata(hdev);
202
203 return sprintf(buf, "%u\n", td->mtclass.quirks);
204}
205
206static ssize_t mt_set_quirks(struct device *dev,
207 struct device_attribute *attr,
208 const char *buf, size_t count)
209{
210 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
211 struct mt_device *td = hid_get_drvdata(hdev);
212
213 unsigned long val;
214
215 if (kstrtoul(buf, 0, &val))
216 return -EINVAL;
217
218 td->mtclass.quirks = val;
219
220 return count;
221}
222
223static DEVICE_ATTR(quirks, S_IWUSR | S_IRUGO, mt_show_quirks, mt_set_quirks);
224
225static struct attribute *sysfs_attrs[] = {
226 &dev_attr_quirks.attr,
227 NULL
228};
229
230static struct attribute_group mt_attribute_group = {
231 .attrs = sysfs_attrs
232};
233
184static void mt_feature_mapping(struct hid_device *hdev, 234static void mt_feature_mapping(struct hid_device *hdev,
185 struct hid_field *field, struct hid_usage *usage) 235 struct hid_field *field, struct hid_usage *usage)
186{ 236{
@@ -192,9 +242,9 @@ static void mt_feature_mapping(struct hid_device *hdev,
192 break; 242 break;
193 case HID_DG_CONTACTMAX: 243 case HID_DG_CONTACTMAX:
194 td->maxcontacts = field->value[0]; 244 td->maxcontacts = field->value[0];
195 if (td->mtclass->maxcontacts) 245 if (td->mtclass.maxcontacts)
196 /* check if the maxcontacts is given by the class */ 246 /* check if the maxcontacts is given by the class */
197 td->maxcontacts = td->mtclass->maxcontacts; 247 td->maxcontacts = td->mtclass.maxcontacts;
198 248
199 break; 249 break;
200 } 250 }
@@ -214,8 +264,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
214 unsigned long **bit, int *max) 264 unsigned long **bit, int *max)
215{ 265{
216 struct mt_device *td = hid_get_drvdata(hdev); 266 struct mt_device *td = hid_get_drvdata(hdev);
217 struct mt_class *cls = td->mtclass; 267 struct mt_class *cls = &td->mtclass;
218 __s32 quirks = cls->quirks;
219 268
220 /* Only map fields from TouchScreen or TouchPad collections. 269 /* Only map fields from TouchScreen or TouchPad collections.
221 * We need to ignore fields that belong to other collections 270 * We need to ignore fields that belong to other collections
@@ -227,13 +276,17 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
227 else 276 else
228 return 0; 277 return 0;
229 278
279 /* eGalax devices provide a Digitizer.Stylus input which overrides
280 * the correct Digitizers.Finger X/Y ranges.
281 * Let's just ignore this input. */
282 if (field->physical == HID_DG_STYLUS)
283 return -1;
284
230 switch (usage->hid & HID_USAGE_PAGE) { 285 switch (usage->hid & HID_USAGE_PAGE) {
231 286
232 case HID_UP_GENDESK: 287 case HID_UP_GENDESK:
233 switch (usage->hid) { 288 switch (usage->hid) {
234 case HID_GD_X: 289 case HID_GD_X:
235 if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
236 field->logical_maximum = 32760;
237 hid_map_usage(hi, usage, bit, max, 290 hid_map_usage(hi, usage, bit, max,
238 EV_ABS, ABS_MT_POSITION_X); 291 EV_ABS, ABS_MT_POSITION_X);
239 set_abs(hi->input, ABS_MT_POSITION_X, field, 292 set_abs(hi->input, ABS_MT_POSITION_X, field,
@@ -246,8 +299,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
246 } 299 }
247 return 1; 300 return 1;
248 case HID_GD_Y: 301 case HID_GD_Y:
249 if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
250 field->logical_maximum = 32760;
251 hid_map_usage(hi, usage, bit, max, 302 hid_map_usage(hi, usage, bit, max,
252 EV_ABS, ABS_MT_POSITION_Y); 303 EV_ABS, ABS_MT_POSITION_Y);
253 set_abs(hi->input, ABS_MT_POSITION_Y, field, 304 set_abs(hi->input, ABS_MT_POSITION_Y, field,
@@ -315,8 +366,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
315 } 366 }
316 return 1; 367 return 1;
317 case HID_DG_TIPPRESSURE: 368 case HID_DG_TIPPRESSURE:
318 if (quirks & MT_QUIRK_EGALAX_XYZ_FIXUP)
319 field->logical_minimum = 0;
320 hid_map_usage(hi, usage, bit, max, 369 hid_map_usage(hi, usage, bit, max,
321 EV_ABS, ABS_MT_PRESSURE); 370 EV_ABS, ABS_MT_PRESSURE);
322 set_abs(hi->input, ABS_MT_PRESSURE, field, 371 set_abs(hi->input, ABS_MT_PRESSURE, field,
@@ -363,7 +412,7 @@ static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
363 412
364static int mt_compute_slot(struct mt_device *td) 413static int mt_compute_slot(struct mt_device *td)
365{ 414{
366 __s32 quirks = td->mtclass->quirks; 415 __s32 quirks = td->mtclass.quirks;
367 416
368 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID) 417 if (quirks & MT_QUIRK_SLOT_IS_CONTACTID)
369 return td->curdata.contactid; 418 return td->curdata.contactid;
@@ -407,7 +456,7 @@ static void mt_emit_event(struct mt_device *td, struct input_dev *input)
407 456
408 for (i = 0; i < td->maxcontacts; ++i) { 457 for (i = 0; i < td->maxcontacts; ++i) {
409 struct mt_slot *s = &(td->slots[i]); 458 struct mt_slot *s = &(td->slots[i]);
410 if ((td->mtclass->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) && 459 if ((td->mtclass.quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) &&
411 !s->seen_in_this_frame) { 460 !s->seen_in_this_frame) {
412 s->touch_state = false; 461 s->touch_state = false;
413 } 462 }
@@ -444,7 +493,7 @@ static int mt_event(struct hid_device *hid, struct hid_field *field,
444 struct hid_usage *usage, __s32 value) 493 struct hid_usage *usage, __s32 value)
445{ 494{
446 struct mt_device *td = hid_get_drvdata(hid); 495 struct mt_device *td = hid_get_drvdata(hid);
447 __s32 quirks = td->mtclass->quirks; 496 __s32 quirks = td->mtclass.quirks;
448 497
449 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) { 498 if (hid->claimed & HID_CLAIMED_INPUT && td->slots) {
450 switch (usage->hid) { 499 switch (usage->hid) {
@@ -552,7 +601,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
552 dev_err(&hdev->dev, "cannot allocate multitouch data\n"); 601 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
553 return -ENOMEM; 602 return -ENOMEM;
554 } 603 }
555 td->mtclass = mtclass; 604 td->mtclass = *mtclass;
556 td->inputmode = -1; 605 td->inputmode = -1;
557 td->last_mt_collection = -1; 606 td->last_mt_collection = -1;
558 hid_set_drvdata(hdev, td); 607 hid_set_drvdata(hdev, td);
@@ -574,6 +623,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
574 goto fail; 623 goto fail;
575 } 624 }
576 625
626 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
627
577 mt_set_input_mode(hdev); 628 mt_set_input_mode(hdev);
578 629
579 return 0; 630 return 0;
@@ -594,6 +645,7 @@ static int mt_reset_resume(struct hid_device *hdev)
594static void mt_remove(struct hid_device *hdev) 645static void mt_remove(struct hid_device *hdev)
595{ 646{
596 struct mt_device *td = hid_get_drvdata(hdev); 647 struct mt_device *td = hid_get_drvdata(hdev);
648 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
597 hid_hw_stop(hdev); 649 hid_hw_stop(hdev);
598 kfree(td->slots); 650 kfree(td->slots);
599 kfree(td); 651 kfree(td);
@@ -609,12 +661,20 @@ static const struct hid_device_id mt_devices[] = {
609 { .driver_data = MT_CLS_3M, 661 { .driver_data = MT_CLS_3M,
610 HID_USB_DEVICE(USB_VENDOR_ID_3M, 662 HID_USB_DEVICE(USB_VENDOR_ID_3M,
611 USB_DEVICE_ID_3M2256) }, 663 USB_DEVICE_ID_3M2256) },
664 { .driver_data = MT_CLS_3M,
665 HID_USB_DEVICE(USB_VENDOR_ID_3M,
666 USB_DEVICE_ID_3M3266) },
612 667
613 /* ActionStar panels */ 668 /* ActionStar panels */
614 { .driver_data = MT_CLS_DEFAULT, 669 { .driver_data = MT_CLS_DEFAULT,
615 HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR, 670 HID_USB_DEVICE(USB_VENDOR_ID_ACTIONSTAR,
616 USB_DEVICE_ID_ACTIONSTAR_1011) }, 671 USB_DEVICE_ID_ACTIONSTAR_1011) },
617 672
673 /* Atmel panels */
674 { .driver_data = MT_CLS_SERIAL,
675 HID_USB_DEVICE(USB_VENDOR_ID_ATMEL,
676 USB_DEVICE_ID_ATMEL_MULTITOUCH) },
677
618 /* Cando panels */ 678 /* Cando panels */
619 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER, 679 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTNUMBER,
620 HID_USB_DEVICE(USB_VENDOR_ID_CANDO, 680 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
@@ -645,23 +705,32 @@ static const struct hid_device_id mt_devices[] = {
645 USB_DEVICE_ID_CYPRESS_TRUETOUCH) }, 705 USB_DEVICE_ID_CYPRESS_TRUETOUCH) },
646 706
647 /* eGalax devices (resistive) */ 707 /* eGalax devices (resistive) */
648 { .driver_data = MT_CLS_EGALAX, 708 { .driver_data = MT_CLS_EGALAX,
649 HID_USB_DEVICE(USB_VENDOR_ID_DWAV, 709 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
650 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH) }, 710 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480D) },
651 { .driver_data = MT_CLS_EGALAX, 711 { .driver_data = MT_CLS_EGALAX,
652 HID_USB_DEVICE(USB_VENDOR_ID_DWAV, 712 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
653 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH3) }, 713 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_480E) },
654 714
655 /* eGalax devices (capacitive) */ 715 /* eGalax devices (capacitive) */
656 { .driver_data = MT_CLS_EGALAX, 716 { .driver_data = MT_CLS_EGALAX,
657 HID_USB_DEVICE(USB_VENDOR_ID_DWAV, 717 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
658 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH1) }, 718 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_720C) },
659 { .driver_data = MT_CLS_EGALAX, 719 { .driver_data = MT_CLS_EGALAX,
660 HID_USB_DEVICE(USB_VENDOR_ID_DWAV, 720 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
661 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH2) }, 721 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_726B) },
662 { .driver_data = MT_CLS_EGALAX, 722 { .driver_data = MT_CLS_EGALAX,
663 HID_USB_DEVICE(USB_VENDOR_ID_DWAV, 723 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
664 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH4) }, 724 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72A1) },
725 { .driver_data = MT_CLS_EGALAX,
726 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
727 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_72FA) },
728 { .driver_data = MT_CLS_EGALAX,
729 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
730 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_7302) },
731 { .driver_data = MT_CLS_EGALAX_SERIAL,
732 HID_USB_DEVICE(USB_VENDOR_ID_DWAV,
733 USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH_A001) },
665 734
666 /* Elo TouchSystems IntelliTouch Plus panel */ 735 /* Elo TouchSystems IntelliTouch Plus panel */
667 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID, 736 { .driver_data = MT_CLS_DUAL_NSMU_CONTACTID,
@@ -678,6 +747,11 @@ static const struct hid_device_id mt_devices[] = {
678 HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH, 747 HID_USB_DEVICE(USB_VENDOR_ID_GOODTOUCH,
679 USB_DEVICE_ID_GOODTOUCH_000f) }, 748 USB_DEVICE_ID_GOODTOUCH_000f) },
680 749
750 /* Hanvon panels */
751 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
752 HID_USB_DEVICE(USB_VENDOR_ID_HANVON_ALT,
753 USB_DEVICE_ID_HANVON_ALT_MULTITOUCH) },
754
681 /* Ideacom panel */ 755 /* Ideacom panel */
682 { .driver_data = MT_CLS_SERIAL, 756 { .driver_data = MT_CLS_SERIAL,
683 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, 757 HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM,
@@ -722,6 +796,17 @@ static const struct hid_device_id mt_devices[] = {
722 HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT, 796 HID_USB_DEVICE(USB_VENDOR_ID_PENMOUNT,
723 USB_DEVICE_ID_PENMOUNT_PCI) }, 797 USB_DEVICE_ID_PENMOUNT_PCI) },
724 798
799 /* PixArt optical touch screen */
800 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
801 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
802 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN) },
803 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
804 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
805 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1) },
806 { .driver_data = MT_CLS_INRANGE_CONTACTNUMBER,
807 HID_USB_DEVICE(USB_VENDOR_ID_PIXART,
808 USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2) },
809
725 /* PixCir-based panels */ 810 /* PixCir-based panels */
726 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID, 811 { .driver_data = MT_CLS_DUAL_INRANGE_CONTACTID,
727 HID_USB_DEVICE(USB_VENDOR_ID_HANVON, 812 HID_USB_DEVICE(USB_VENDOR_ID_HANVON,
@@ -730,6 +815,17 @@ static const struct hid_device_id mt_devices[] = {
730 HID_USB_DEVICE(USB_VENDOR_ID_CANDO, 815 HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
731 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) }, 816 USB_DEVICE_ID_CANDO_PIXCIR_MULTI_TOUCH) },
732 817
818 /* Quanta-based panels */
819 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
820 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
821 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
822 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
823 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
824 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001) },
825 { .driver_data = MT_CLS_CONFIDENCE_CONTACT_ID,
826 HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
827 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
828
733 /* Stantum panels */ 829 /* Stantum panels */
734 { .driver_data = MT_CLS_CONFIDENCE, 830 { .driver_data = MT_CLS_CONFIDENCE,
735 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, 831 HID_USB_DEVICE(USB_VENDOR_ID_STANTUM,
@@ -758,6 +854,35 @@ static const struct hid_device_id mt_devices[] = {
758 HID_USB_DEVICE(USB_VENDOR_ID_XAT, 854 HID_USB_DEVICE(USB_VENDOR_ID_XAT,
759 USB_DEVICE_ID_XAT_CSR) }, 855 USB_DEVICE_ID_XAT_CSR) },
760 856
857 /* Xiroku */
858 { .driver_data = MT_CLS_DEFAULT,
859 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
860 USB_DEVICE_ID_XIROKU_SPX) },
861 { .driver_data = MT_CLS_DEFAULT,
862 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
863 USB_DEVICE_ID_XIROKU_MPX) },
864 { .driver_data = MT_CLS_DEFAULT,
865 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
866 USB_DEVICE_ID_XIROKU_CSR) },
867 { .driver_data = MT_CLS_DEFAULT,
868 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
869 USB_DEVICE_ID_XIROKU_SPX1) },
870 { .driver_data = MT_CLS_DEFAULT,
871 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
872 USB_DEVICE_ID_XIROKU_MPX1) },
873 { .driver_data = MT_CLS_DEFAULT,
874 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
875 USB_DEVICE_ID_XIROKU_CSR1) },
876 { .driver_data = MT_CLS_DEFAULT,
877 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
878 USB_DEVICE_ID_XIROKU_SPX2) },
879 { .driver_data = MT_CLS_DEFAULT,
880 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
881 USB_DEVICE_ID_XIROKU_MPX2) },
882 { .driver_data = MT_CLS_DEFAULT,
883 HID_USB_DEVICE(USB_VENDOR_ID_XIROKU,
884 USB_DEVICE_ID_XIROKU_CSR2) },
885
761 { } 886 { }
762}; 887};
763MODULE_DEVICE_TABLE(hid, mt_devices); 888MODULE_DEVICE_TABLE(hid, mt_devices);
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index 530cd308120..12f9777c385 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 06e5300d43d..070f93a5c11 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-quanta.c b/drivers/hid/hid-quanta.c
deleted file mode 100644
index 87a54df4d4a..00000000000
--- a/drivers/hid/hid-quanta.c
+++ /dev/null
@@ -1,261 +0,0 @@
1/*
2 * HID driver for Quanta Optical Touch dual-touch panels
3 *
4 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
5 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19
20MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
21MODULE_DESCRIPTION("Quanta dual-touch panel");
22MODULE_LICENSE("GPL");
23
24#include "hid-ids.h"
25
26struct quanta_data {
27 __u16 x, y;
28 __u8 id;
29 bool valid; /* valid finger data, or just placeholder? */
30 bool first; /* is this the first finger in this frame? */
31 bool activity_now; /* at least one active finger in this frame? */
32 bool activity; /* at least one active finger previously? */
33};
34
35static int quanta_input_mapping(struct hid_device *hdev, struct hid_input *hi,
36 struct hid_field *field, struct hid_usage *usage,
37 unsigned long **bit, int *max)
38{
39 switch (usage->hid & HID_USAGE_PAGE) {
40
41 case HID_UP_GENDESK:
42 switch (usage->hid) {
43 case HID_GD_X:
44 hid_map_usage(hi, usage, bit, max,
45 EV_ABS, ABS_MT_POSITION_X);
46 /* touchscreen emulation */
47 input_set_abs_params(hi->input, ABS_X,
48 field->logical_minimum,
49 field->logical_maximum, 0, 0);
50 return 1;
51 case HID_GD_Y:
52 hid_map_usage(hi, usage, bit, max,
53 EV_ABS, ABS_MT_POSITION_Y);
54 /* touchscreen emulation */
55 input_set_abs_params(hi->input, ABS_Y,
56 field->logical_minimum,
57 field->logical_maximum, 0, 0);
58 return 1;
59 }
60 return 0;
61
62 case HID_UP_DIGITIZER:
63 switch (usage->hid) {
64 case HID_DG_CONFIDENCE:
65 case HID_DG_TIPSWITCH:
66 case HID_DG_INPUTMODE:
67 case HID_DG_DEVICEINDEX:
68 case HID_DG_CONTACTCOUNT:
69 case HID_DG_CONTACTMAX:
70 case HID_DG_TIPPRESSURE:
71 case HID_DG_WIDTH:
72 case HID_DG_HEIGHT:
73 return -1;
74 case HID_DG_INRANGE:
75 /* touchscreen emulation */
76 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
77 return 1;
78 case HID_DG_CONTACTID:
79 hid_map_usage(hi, usage, bit, max,
80 EV_ABS, ABS_MT_TRACKING_ID);
81 return 1;
82 }
83 return 0;
84
85 case 0xff000000:
86 /* ignore vendor-specific features */
87 return -1;
88 }
89
90 return 0;
91}
92
93static int quanta_input_mapped(struct hid_device *hdev, struct hid_input *hi,
94 struct hid_field *field, struct hid_usage *usage,
95 unsigned long **bit, int *max)
96{
97 if (usage->type == EV_KEY || usage->type == EV_ABS)
98 clear_bit(usage->code, *bit);
99
100 return 0;
101}
102
103/*
104 * this function is called when a whole finger has been parsed,
105 * so that it can decide what to send to the input layer.
106 */
107static void quanta_filter_event(struct quanta_data *td, struct input_dev *input)
108{
109
110 td->first = !td->first; /* touchscreen emulation */
111
112 if (!td->valid) {
113 /*
114 * touchscreen emulation: if no finger in this frame is valid
115 * and there previously was finger activity, this is a release
116 */
117 if (!td->first && !td->activity_now && td->activity) {
118 input_event(input, EV_KEY, BTN_TOUCH, 0);
119 td->activity = false;
120 }
121 return;
122 }
123
124 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id);
125 input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x);
126 input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y);
127
128 input_mt_sync(input);
129 td->valid = false;
130
131 /* touchscreen emulation: if first active finger in this frame... */
132 if (!td->activity_now) {
133 /* if there was no previous activity, emit touch event */
134 if (!td->activity) {
135 input_event(input, EV_KEY, BTN_TOUCH, 1);
136 td->activity = true;
137 }
138 td->activity_now = true;
139 /* and in any case this is our preferred finger */
140 input_event(input, EV_ABS, ABS_X, td->x);
141 input_event(input, EV_ABS, ABS_Y, td->y);
142 }
143}
144
145
146static int quanta_event(struct hid_device *hid, struct hid_field *field,
147 struct hid_usage *usage, __s32 value)
148{
149 struct quanta_data *td = hid_get_drvdata(hid);
150
151 if (hid->claimed & HID_CLAIMED_INPUT) {
152 struct input_dev *input = field->hidinput->input;
153
154 switch (usage->hid) {
155 case HID_DG_INRANGE:
156 td->valid = !!value;
157 break;
158 case HID_GD_X:
159 td->x = value;
160 break;
161 case HID_GD_Y:
162 td->y = value;
163 quanta_filter_event(td, input);
164 break;
165 case HID_DG_CONTACTID:
166 td->id = value;
167 break;
168 case HID_DG_CONTACTCOUNT:
169 /* touch emulation: this is the last field in a frame */
170 td->first = false;
171 td->activity_now = false;
172 break;
173 case HID_DG_CONFIDENCE:
174 case HID_DG_TIPSWITCH:
175 /* avoid interference from generic hidinput handling */
176 break;
177
178 default:
179 /* fallback to the generic hidinput handling */
180 return 0;
181 }
182 }
183
184 /* we have handled the hidinput part, now remains hiddev */
185 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
186 hid->hiddev_hid_event(hid, field, usage, value);
187
188 return 1;
189}
190
191static int quanta_probe(struct hid_device *hdev, const struct hid_device_id *id)
192{
193 int ret;
194 struct quanta_data *td;
195
196 td = kmalloc(sizeof(struct quanta_data), GFP_KERNEL);
197 if (!td) {
198 hid_err(hdev, "cannot allocate Quanta Touch data\n");
199 return -ENOMEM;
200 }
201 td->valid = false;
202 td->activity = false;
203 td->activity_now = false;
204 td->first = false;
205 hid_set_drvdata(hdev, td);
206
207 ret = hid_parse(hdev);
208 if (!ret)
209 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
210
211 if (ret)
212 kfree(td);
213
214 return ret;
215}
216
217static void quanta_remove(struct hid_device *hdev)
218{
219 hid_hw_stop(hdev);
220 kfree(hid_get_drvdata(hdev));
221 hid_set_drvdata(hdev, NULL);
222}
223
224static const struct hid_device_id quanta_devices[] = {
225 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
226 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
227 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
228 USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
229 { }
230};
231MODULE_DEVICE_TABLE(hid, quanta_devices);
232
233static const struct hid_usage_id quanta_grabbed_usages[] = {
234 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
235 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
236};
237
238static struct hid_driver quanta_driver = {
239 .name = "quanta-touch",
240 .id_table = quanta_devices,
241 .probe = quanta_probe,
242 .remove = quanta_remove,
243 .input_mapping = quanta_input_mapping,
244 .input_mapped = quanta_input_mapped,
245 .usage_table = quanta_grabbed_usages,
246 .event = quanta_event,
247};
248
249static int __init quanta_init(void)
250{
251 return hid_register_driver(&quanta_driver);
252}
253
254static void __exit quanta_exit(void)
255{
256 hid_unregister_driver(&quanta_driver);
257}
258
259module_init(quanta_init);
260module_exit(quanta_exit);
261
diff --git a/drivers/hid/hid-roccat-common.c b/drivers/hid/hid-roccat-common.c
index f933221ba52..a6d93992c75 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-isku.c b/drivers/hid/hid-roccat-isku.c
new file mode 100644
index 00000000000..0e4a0ab4714
--- /dev/null
+++ b/drivers/hid/hid-roccat-isku.c
@@ -0,0 +1,487 @@
1/*
2 * Roccat Isku driver for Linux
3 *
4 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
5 */
6
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
14/*
15 * Roccat Isku is a gamer keyboard with macro keys that can be configured in
16 * 5 profiles.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/hid-roccat.h>
25#include "hid-ids.h"
26#include "hid-roccat-common.h"
27#include "hid-roccat-isku.h"
28
29static struct class *isku_class;
30
31static void isku_profile_activated(struct isku_device *isku, uint new_profile)
32{
33 isku->actual_profile = new_profile;
34}
35
36static int isku_receive(struct usb_device *usb_dev, uint command,
37 void *buf, uint size)
38{
39 return roccat_common_receive(usb_dev, command, buf, size);
40}
41
42static int isku_receive_control_status(struct usb_device *usb_dev)
43{
44 int retval;
45 struct isku_control control;
46
47 do {
48 msleep(50);
49 retval = isku_receive(usb_dev, ISKU_COMMAND_CONTROL,
50 &control, sizeof(struct isku_control));
51
52 if (retval)
53 return retval;
54
55 switch (control.value) {
56 case ISKU_CONTROL_VALUE_STATUS_OK:
57 return 0;
58 case ISKU_CONTROL_VALUE_STATUS_WAIT:
59 continue;
60 case ISKU_CONTROL_VALUE_STATUS_INVALID:
61 /* seems to be critical - replug necessary */
62 case ISKU_CONTROL_VALUE_STATUS_OVERLOAD:
63 return -EINVAL;
64 default:
65 hid_err(usb_dev, "isku_receive_control_status: "
66 "unknown response value 0x%x\n",
67 control.value);
68 return -EINVAL;
69 }
70
71 } while (1);
72}
73
74static int isku_send(struct usb_device *usb_dev, uint command,
75 void const *buf, uint size)
76{
77 int retval;
78
79 retval = roccat_common_send(usb_dev, command, buf, size);
80 if (retval)
81 return retval;
82
83 return isku_receive_control_status(usb_dev);
84}
85
86static int isku_get_actual_profile(struct usb_device *usb_dev)
87{
88 struct isku_actual_profile buf;
89 int retval;
90
91 retval = isku_receive(usb_dev, ISKU_COMMAND_ACTUAL_PROFILE,
92 &buf, sizeof(struct isku_actual_profile));
93 return retval ? retval : buf.actual_profile;
94}
95
96static int isku_set_actual_profile(struct usb_device *usb_dev, int new_profile)
97{
98 struct isku_actual_profile buf;
99
100 buf.command = ISKU_COMMAND_ACTUAL_PROFILE;
101 buf.size = sizeof(struct isku_actual_profile);
102 buf.actual_profile = new_profile;
103 return isku_send(usb_dev, ISKU_COMMAND_ACTUAL_PROFILE, &buf,
104 sizeof(struct isku_actual_profile));
105}
106
107static ssize_t isku_sysfs_show_actual_profile(struct device *dev,
108 struct device_attribute *attr, char *buf)
109{
110 struct isku_device *isku =
111 hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
112 return snprintf(buf, PAGE_SIZE, "%d\n", isku->actual_profile);
113}
114
115static ssize_t isku_sysfs_set_actual_profile(struct device *dev,
116 struct device_attribute *attr, char const *buf, size_t size)
117{
118 struct isku_device *isku;
119 struct usb_device *usb_dev;
120 unsigned long profile;
121 int retval;
122 struct isku_roccat_report roccat_report;
123
124 dev = dev->parent->parent;
125 isku = hid_get_drvdata(dev_get_drvdata(dev));
126 usb_dev = interface_to_usbdev(to_usb_interface(dev));
127
128 retval = strict_strtoul(buf, 10, &profile);
129 if (retval)
130 return retval;
131
132 if (profile > 4)
133 return -EINVAL;
134
135 mutex_lock(&isku->isku_lock);
136
137 retval = isku_set_actual_profile(usb_dev, profile);
138 if (retval) {
139 mutex_unlock(&isku->isku_lock);
140 return retval;
141 }
142
143 isku_profile_activated(isku, profile);
144
145 roccat_report.event = ISKU_REPORT_BUTTON_EVENT_PROFILE;
146 roccat_report.data1 = profile + 1;
147 roccat_report.data2 = 0;
148 roccat_report.profile = profile + 1;
149 roccat_report_event(isku->chrdev_minor, (uint8_t const *)&roccat_report);
150
151 mutex_unlock(&isku->isku_lock);
152
153 return size;
154}
155
156static struct device_attribute isku_attributes[] = {
157 __ATTR(actual_profile, 0660,
158 isku_sysfs_show_actual_profile,
159 isku_sysfs_set_actual_profile),
160 __ATTR_NULL
161};
162
163static ssize_t isku_sysfs_read(struct file *fp, struct kobject *kobj,
164 char *buf, loff_t off, size_t count,
165 size_t real_size, uint command)
166{
167 struct device *dev =
168 container_of(kobj, struct device, kobj)->parent->parent;
169 struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev));
170 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
171 int retval;
172
173 if (off >= real_size)
174 return 0;
175
176 if (off != 0 || count != real_size)
177 return -EINVAL;
178
179 mutex_lock(&isku->isku_lock);
180 retval = isku_receive(usb_dev, command, buf, real_size);
181 mutex_unlock(&isku->isku_lock);
182
183 return retval ? retval : real_size;
184}
185
186static ssize_t isku_sysfs_write(struct file *fp, struct kobject *kobj,
187 void const *buf, loff_t off, size_t count,
188 size_t real_size, uint command)
189{
190 struct device *dev =
191 container_of(kobj, struct device, kobj)->parent->parent;
192 struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev));
193 struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
194 int retval;
195
196 if (off != 0 || count != real_size)
197 return -EINVAL;
198
199 mutex_lock(&isku->isku_lock);
200 retval = isku_send(usb_dev, command, (void *)buf, real_size);
201 mutex_unlock(&isku->isku_lock);
202
203 return retval ? retval : real_size;
204}
205
206#define ISKU_SYSFS_W(thingy, THINGY) \
207static ssize_t isku_sysfs_write_ ## thingy(struct file *fp, struct kobject *kobj, \
208 struct bin_attribute *attr, char *buf, \
209 loff_t off, size_t count) \
210{ \
211 return isku_sysfs_write(fp, kobj, buf, off, count, \
212 sizeof(struct isku_ ## thingy), ISKU_COMMAND_ ## THINGY); \
213}
214
215#define ISKU_SYSFS_R(thingy, THINGY) \
216static ssize_t isku_sysfs_read_ ## thingy(struct file *fp, struct kobject *kobj, \
217 struct bin_attribute *attr, char *buf, \
218 loff_t off, size_t count) \
219{ \
220 return isku_sysfs_read(fp, kobj, buf, off, count, \
221 sizeof(struct isku_ ## thingy), ISKU_COMMAND_ ## THINGY); \
222}
223
224#define ISKU_SYSFS_RW(thingy, THINGY) \
225ISKU_SYSFS_R(thingy, THINGY) \
226ISKU_SYSFS_W(thingy, THINGY)
227
228#define ISKU_BIN_ATTR_RW(thingy) \
229{ \
230 .attr = { .name = #thingy, .mode = 0660 }, \
231 .size = sizeof(struct isku_ ## thingy), \
232 .read = isku_sysfs_read_ ## thingy, \
233 .write = isku_sysfs_write_ ## thingy \
234}
235
236#define ISKU_BIN_ATTR_R(thingy) \
237{ \
238 .attr = { .name = #thingy, .mode = 0440 }, \
239 .size = sizeof(struct isku_ ## thingy), \
240 .read = isku_sysfs_read_ ## thingy, \
241}
242
243#define ISKU_BIN_ATTR_W(thingy) \
244{ \
245 .attr = { .name = #thingy, .mode = 0220 }, \
246 .size = sizeof(struct isku_ ## thingy), \
247 .write = isku_sysfs_write_ ## thingy \
248}
249
250ISKU_SYSFS_RW(macro, MACRO)
251ISKU_SYSFS_RW(keys_function, KEYS_FUNCTION)
252ISKU_SYSFS_RW(keys_easyzone, KEYS_EASYZONE)
253ISKU_SYSFS_RW(keys_media, KEYS_MEDIA)
254ISKU_SYSFS_RW(keys_thumbster, KEYS_THUMBSTER)
255ISKU_SYSFS_RW(keys_macro, KEYS_MACRO)
256ISKU_SYSFS_RW(keys_capslock, KEYS_CAPSLOCK)
257ISKU_SYSFS_RW(light, LIGHT)
258ISKU_SYSFS_RW(key_mask, KEY_MASK)
259ISKU_SYSFS_RW(last_set, LAST_SET)
260ISKU_SYSFS_W(talk, TALK)
261ISKU_SYSFS_R(info, INFO)
262ISKU_SYSFS_W(control, CONTROL)
263
264static struct bin_attribute isku_bin_attributes[] = {
265 ISKU_BIN_ATTR_RW(macro),
266 ISKU_BIN_ATTR_RW(keys_function),
267 ISKU_BIN_ATTR_RW(keys_easyzone),
268 ISKU_BIN_ATTR_RW(keys_media),
269 ISKU_BIN_ATTR_RW(keys_thumbster),
270 ISKU_BIN_ATTR_RW(keys_macro),
271 ISKU_BIN_ATTR_RW(keys_capslock),
272 ISKU_BIN_ATTR_RW(light),
273 ISKU_BIN_ATTR_RW(key_mask),
274 ISKU_BIN_ATTR_RW(last_set),
275 ISKU_BIN_ATTR_W(talk),
276 ISKU_BIN_ATTR_R(info),
277 ISKU_BIN_ATTR_W(control),
278 __ATTR_NULL
279};
280
281static int isku_init_isku_device_struct(struct usb_device *usb_dev,
282 struct isku_device *isku)
283{
284 int retval;
285
286 mutex_init(&isku->isku_lock);
287
288 retval = isku_get_actual_profile(usb_dev);
289 if (retval < 0)
290 return retval;
291 isku_profile_activated(isku, retval);
292
293 return 0;
294}
295
296static int isku_init_specials(struct hid_device *hdev)
297{
298 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
299 struct usb_device *usb_dev = interface_to_usbdev(intf);
300 struct isku_device *isku;
301 int retval;
302
303 if (intf->cur_altsetting->desc.bInterfaceProtocol
304 != ISKU_USB_INTERFACE_PROTOCOL) {
305 hid_set_drvdata(hdev, NULL);
306 return 0;
307 }
308
309 isku = kzalloc(sizeof(*isku), GFP_KERNEL);
310 if (!isku) {
311 hid_err(hdev, "can't alloc device descriptor\n");
312 return -ENOMEM;
313 }
314 hid_set_drvdata(hdev, isku);
315
316 retval = isku_init_isku_device_struct(usb_dev, isku);
317 if (retval) {
318 hid_err(hdev, "couldn't init struct isku_device\n");
319 goto exit_free;
320 }
321
322 retval = roccat_connect(isku_class, hdev,
323 sizeof(struct isku_roccat_report));
324 if (retval < 0) {
325 hid_err(hdev, "couldn't init char dev\n");
326 } else {
327 isku->chrdev_minor = retval;
328 isku->roccat_claimed = 1;
329 }
330
331 return 0;
332exit_free:
333 kfree(isku);
334 return retval;
335}
336
337static void isku_remove_specials(struct hid_device *hdev)
338{
339 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
340 struct isku_device *isku;
341
342 if (intf->cur_altsetting->desc.bInterfaceProtocol
343 != ISKU_USB_INTERFACE_PROTOCOL)
344 return;
345
346 isku = hid_get_drvdata(hdev);
347 if (isku->roccat_claimed)
348 roccat_disconnect(isku->chrdev_minor);
349 kfree(isku);
350}
351
352static int isku_probe(struct hid_device *hdev,
353 const struct hid_device_id *id)
354{
355 int retval;
356
357 retval = hid_parse(hdev);
358 if (retval) {
359 hid_err(hdev, "parse failed\n");
360 goto exit;
361 }
362
363 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
364 if (retval) {
365 hid_err(hdev, "hw start failed\n");
366 goto exit;
367 }
368
369 retval = isku_init_specials(hdev);
370 if (retval) {
371 hid_err(hdev, "couldn't install keyboard\n");
372 goto exit_stop;
373 }
374
375 return 0;
376
377exit_stop:
378 hid_hw_stop(hdev);
379exit:
380 return retval;
381}
382
383static void isku_remove(struct hid_device *hdev)
384{
385 isku_remove_specials(hdev);
386 hid_hw_stop(hdev);
387}
388
389static void isku_keep_values_up_to_date(struct isku_device *isku,
390 u8 const *data)
391{
392 struct isku_report_button const *button_report;
393
394 switch (data[0]) {
395 case ISKU_REPORT_NUMBER_BUTTON:
396 button_report = (struct isku_report_button const *)data;
397 switch (button_report->event) {
398 case ISKU_REPORT_BUTTON_EVENT_PROFILE:
399 isku_profile_activated(isku, button_report->data1 - 1);
400 break;
401 }
402 break;
403 }
404}
405
406static void isku_report_to_chrdev(struct isku_device const *isku,
407 u8 const *data)
408{
409 struct isku_roccat_report roccat_report;
410 struct isku_report_button const *button_report;
411
412 if (data[0] != ISKU_REPORT_NUMBER_BUTTON)
413 return;
414
415 button_report = (struct isku_report_button const *)data;
416
417 roccat_report.event = button_report->event;
418 roccat_report.data1 = button_report->data1;
419 roccat_report.data2 = button_report->data2;
420 roccat_report.profile = isku->actual_profile + 1;
421 roccat_report_event(isku->chrdev_minor,
422 (uint8_t const *)&roccat_report);
423}
424
425static int isku_raw_event(struct hid_device *hdev,
426 struct hid_report *report, u8 *data, int size)
427{
428 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
429 struct isku_device *isku = hid_get_drvdata(hdev);
430
431 if (intf->cur_altsetting->desc.bInterfaceProtocol
432 != ISKU_USB_INTERFACE_PROTOCOL)
433 return 0;
434
435 if (isku == NULL)
436 return 0;
437
438 isku_keep_values_up_to_date(isku, data);
439
440 if (isku->roccat_claimed)
441 isku_report_to_chrdev(isku, data);
442
443 return 0;
444}
445
446static const struct hid_device_id isku_devices[] = {
447 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
448 { }
449};
450
451MODULE_DEVICE_TABLE(hid, isku_devices);
452
453static struct hid_driver isku_driver = {
454 .name = "isku",
455 .id_table = isku_devices,
456 .probe = isku_probe,
457 .remove = isku_remove,
458 .raw_event = isku_raw_event
459};
460
461static int __init isku_init(void)
462{
463 int retval;
464 isku_class = class_create(THIS_MODULE, "isku");
465 if (IS_ERR(isku_class))
466 return PTR_ERR(isku_class);
467 isku_class->dev_attrs = isku_attributes;
468 isku_class->dev_bin_attrs = isku_bin_attributes;
469
470 retval = hid_register_driver(&isku_driver);
471 if (retval)
472 class_destroy(isku_class);
473 return retval;
474}
475
476static void __exit isku_exit(void)
477{
478 hid_unregister_driver(&isku_driver);
479 class_destroy(isku_class);
480}
481
482module_init(isku_init);
483module_exit(isku_exit);
484
485MODULE_AUTHOR("Stefan Achatz");
486MODULE_DESCRIPTION("USB Roccat Isku driver");
487MODULE_LICENSE("GPL v2");
diff --git a/drivers/hid/hid-roccat-isku.h b/drivers/hid/hid-roccat-isku.h
new file mode 100644
index 00000000000..075f6efaec5
--- /dev/null
+++ b/drivers/hid/hid-roccat-isku.h
@@ -0,0 +1,147 @@
1#ifndef __HID_ROCCAT_ISKU_H
2#define __HID_ROCCAT_ISKU_H
3
4/*
5 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/types.h>
16
17enum {
18 ISKU_PROFILE_NUM = 5,
19 ISKU_USB_INTERFACE_PROTOCOL = 0,
20};
21
22struct isku_control {
23 uint8_t command; /* ISKU_COMMAND_CONTROL */
24 uint8_t value;
25 uint8_t request;
26} __packed;
27
28enum isku_control_values {
29 ISKU_CONTROL_VALUE_STATUS_OVERLOAD = 0,
30 ISKU_CONTROL_VALUE_STATUS_OK = 1,
31 ISKU_CONTROL_VALUE_STATUS_INVALID = 2,
32 ISKU_CONTROL_VALUE_STATUS_WAIT = 3,
33};
34
35struct isku_actual_profile {
36 uint8_t command; /* ISKU_COMMAND_ACTUAL_PROFILE */
37 uint8_t size; /* always 3 */
38 uint8_t actual_profile;
39} __packed;
40
41struct isku_key_mask {
42 uint8_t command; /* ISKU_COMMAND_KEY_MASK */
43 uint8_t size; /* 6 */
44 uint8_t profile_number; /* 0-4 */
45 uint8_t mask;
46 uint16_t checksum;
47} __packed;
48
49struct isku_keys_function {
50 uint8_t data[0x29];
51} __packed;
52
53struct isku_keys_easyzone {
54 uint8_t data[0x41];
55} __packed;
56
57struct isku_keys_media {
58 uint8_t data[0x1d];
59} __packed;
60
61struct isku_keys_thumbster {
62 uint8_t data[0x17];
63} __packed;
64
65struct isku_keys_macro {
66 uint8_t data[0x23];
67} __packed;
68
69struct isku_keys_capslock {
70 uint8_t data[0x6];
71} __packed;
72
73struct isku_macro {
74 uint8_t data[0x823];
75} __packed;
76
77struct isku_light {
78 uint8_t data[0xa];
79} __packed;
80
81struct isku_info {
82 uint8_t data[2];
83 uint8_t firmware_version;
84 uint8_t unknown[3];
85} __packed;
86
87struct isku_talk {
88 uint8_t data[0x10];
89} __packed;
90
91struct isku_last_set {
92 uint8_t data[0x14];
93} __packed;
94
95enum isku_commands {
96 ISKU_COMMAND_CONTROL = 0x4,
97 ISKU_COMMAND_ACTUAL_PROFILE = 0x5,
98 ISKU_COMMAND_KEY_MASK = 0x7,
99 ISKU_COMMAND_KEYS_FUNCTION = 0x8,
100 ISKU_COMMAND_KEYS_EASYZONE = 0x9,
101 ISKU_COMMAND_KEYS_MEDIA = 0xa,
102 ISKU_COMMAND_KEYS_THUMBSTER = 0xb,
103 ISKU_COMMAND_KEYS_MACRO = 0xd,
104 ISKU_COMMAND_MACRO = 0xe,
105 ISKU_COMMAND_INFO = 0xf,
106 ISKU_COMMAND_LIGHT = 0x10,
107 ISKU_COMMAND_KEYS_CAPSLOCK = 0x13,
108 ISKU_COMMAND_LAST_SET = 0x14,
109 ISKU_COMMAND_15 = 0x15,
110 ISKU_COMMAND_TALK = 0x16,
111 ISKU_COMMAND_FIRMWARE_WRITE = 0x1b,
112 ISKU_COMMAND_FIRMWARE_WRITE_CONTROL = 0x1c,
113};
114
115struct isku_report_button {
116 uint8_t number; /* ISKU_REPORT_NUMBER_BUTTON */
117 uint8_t zero;
118 uint8_t event;
119 uint8_t data1;
120 uint8_t data2;
121};
122
123enum isku_report_numbers {
124 ISKU_REPORT_NUMBER_BUTTON = 3,
125};
126
127enum isku_report_button_events {
128 ISKU_REPORT_BUTTON_EVENT_PROFILE = 0x2,
129};
130
131struct isku_roccat_report {
132 uint8_t event;
133 uint8_t data1;
134 uint8_t data2;
135 uint8_t profile;
136} __packed;
137
138struct isku_device {
139 int roccat_claimed;
140 int chrdev_minor;
141
142 struct mutex isku_lock;
143
144 int actual_profile;
145};
146
147#endif
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 56ce12c23b0..b685b04dbf9 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
diff --git a/drivers/hid/hid-sjoy.c b/drivers/hid/hid-sjoy.c
index 670da9109f8..4b1448613ea 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 575862b0688..83a933b9c2e 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-wacom.c b/drivers/hid/hid-wacom.c
index 17bb88f782b..f2183486a9b 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -9,6 +9,7 @@
9 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> 9 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
10 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru> 10 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
11 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net> 11 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
12 * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
12 */ 13 */
13 14
14/* 15/*
@@ -33,6 +34,7 @@
33struct wacom_data { 34struct wacom_data {
34 __u16 tool; 35 __u16 tool;
35 unsigned char butstate; 36 unsigned char butstate;
37 __u8 features;
36 unsigned char high_speed; 38 unsigned char high_speed;
37#ifdef CONFIG_HID_WACOM_POWER_SUPPLY 39#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
38 int battery_capacity; 40 int battery_capacity;
@@ -107,6 +109,19 @@ static int wacom_ac_get_property(struct power_supply *psy,
107} 109}
108#endif 110#endif
109 111
112static void wacom_set_features(struct hid_device *hdev)
113{
114 int ret;
115 __u8 rep_data[2];
116
117 /*set high speed, tablet mode*/
118 rep_data[0] = 0x03;
119 rep_data[1] = 0x20;
120 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
121 HID_FEATURE_REPORT);
122 return;
123}
124
110static void wacom_poke(struct hid_device *hdev, u8 speed) 125static void wacom_poke(struct hid_device *hdev, u8 speed)
111{ 126{
112 struct wacom_data *wdata = hid_get_drvdata(hdev); 127 struct wacom_data *wdata = hid_get_drvdata(hdev);
@@ -177,26 +192,13 @@ static ssize_t wacom_store_speed(struct device *dev,
177static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, 192static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
178 wacom_show_speed, wacom_store_speed); 193 wacom_show_speed, wacom_store_speed);
179 194
180static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, 195static int wacom_gr_parse_report(struct hid_device *hdev,
181 u8 *raw_data, int size) 196 struct wacom_data *wdata,
197 struct input_dev *input, unsigned char *data)
182{ 198{
183 struct wacom_data *wdata = hid_get_drvdata(hdev);
184 struct hid_input *hidinput;
185 struct input_dev *input;
186 unsigned char *data = (unsigned char *) raw_data;
187 int tool, x, y, rw; 199 int tool, x, y, rw;
188 200
189 if (!(hdev->claimed & HID_CLAIMED_INPUT))
190 return 0;
191
192 tool = 0; 201 tool = 0;
193 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
194 input = hidinput->input;
195
196 /* Check if this is a tablet report */
197 if (data[0] != 0x03)
198 return 0;
199
200 /* Get X & Y positions */ 202 /* Get X & Y positions */
201 x = le16_to_cpu(*(__le16 *) &data[2]); 203 x = le16_to_cpu(*(__le16 *) &data[2]);
202 y = le16_to_cpu(*(__le16 *) &data[4]); 204 y = le16_to_cpu(*(__le16 *) &data[4]);
@@ -304,6 +306,121 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
304 return 1; 306 return 1;
305} 307}
306 308
309static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
310 struct input_dev *input, unsigned char *data)
311{
312 __u16 x, y, pressure;
313 __u32 id;
314
315 switch (data[1]) {
316 case 0x80: /* Out of proximity report */
317 wdata->tool = 0;
318 input_report_key(input, BTN_TOUCH, 0);
319 input_report_abs(input, ABS_PRESSURE, 0);
320 input_report_key(input, wdata->tool, 0);
321 input_sync(input);
322 break;
323 case 0xC2: /* Tool report */
324 id = ((data[2] << 4) | (data[3] >> 4) |
325 ((data[7] & 0x0f) << 20) |
326 ((data[8] & 0xf0) << 12)) & 0xfffff;
327
328 switch (id) {
329 case 0x802:
330 wdata->tool = BTN_TOOL_PEN;
331 break;
332 case 0x80A:
333 wdata->tool = BTN_TOOL_RUBBER;
334 break;
335 }
336 break;
337 default: /* Position/pressure report */
338 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
339 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
340 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
341 | (data[1] & 0x01);
342
343 input_report_key(input, BTN_TOUCH, pressure > 1);
344
345 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
346 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
347 input_report_key(input, wdata->tool, 1);
348 input_report_abs(input, ABS_X, x);
349 input_report_abs(input, ABS_Y, y);
350 input_report_abs(input, ABS_PRESSURE, pressure);
351 input_sync(input);
352 break;
353 }
354
355 return;
356}
357
358static void wacom_i4_parse_report(struct hid_device *hdev,
359 struct wacom_data *wdata,
360 struct input_dev *input, unsigned char *data)
361{
362 switch (data[0]) {
363 case 0x00: /* Empty report */
364 break;
365 case 0x02: /* Pen report */
366 wacom_i4_parse_pen_report(wdata, input, data);
367 break;
368 case 0x03: /* Features Report */
369 wdata->features = data[2];
370 break;
371 case 0x0C: /* Button report */
372 break;
373 default:
374 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
375 break;
376 }
377}
378
379static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
380 u8 *raw_data, int size)
381{
382 struct wacom_data *wdata = hid_get_drvdata(hdev);
383 struct hid_input *hidinput;
384 struct input_dev *input;
385 unsigned char *data = (unsigned char *) raw_data;
386 int i;
387
388 if (!(hdev->claimed & HID_CLAIMED_INPUT))
389 return 0;
390
391 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
392 input = hidinput->input;
393
394 /* Check if this is a tablet report */
395 if (data[0] != 0x03)
396 return 0;
397
398 switch (hdev->product) {
399 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
400 return wacom_gr_parse_report(hdev, wdata, input, data);
401 break;
402 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
403 i = 1;
404
405 switch (data[0]) {
406 case 0x04:
407 wacom_i4_parse_report(hdev, wdata, input, data + i);
408 i += 10;
409 /* fall through */
410 case 0x03:
411 wacom_i4_parse_report(hdev, wdata, input, data + i);
412 i += 10;
413 wacom_i4_parse_report(hdev, wdata, input, data + i);
414 break;
415 default:
416 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
417 data[0], data[1], size);
418 return 0;
419 }
420 }
421 return 1;
422}
423
307static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi, 424static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
308 struct hid_field *field, struct hid_usage *usage, unsigned long **bit, 425 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
309 int *max) 426 int *max)
@@ -338,10 +455,19 @@ static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
338 __set_bit(BTN_TOOL_RUBBER, input->keybit); 455 __set_bit(BTN_TOOL_RUBBER, input->keybit);
339 __set_bit(BTN_TOOL_MOUSE, input->keybit); 456 __set_bit(BTN_TOOL_MOUSE, input->keybit);
340 457
341 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0); 458 switch (hdev->product) {
342 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0); 459 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
343 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0); 460 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
344 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0); 461 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
462 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
463 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
464 break;
465 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
466 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
467 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
468 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
469 break;
470 }
345 471
346 return 0; 472 return 0;
347} 473}
@@ -378,8 +504,16 @@ static int wacom_probe(struct hid_device *hdev,
378 hid_warn(hdev, 504 hid_warn(hdev,
379 "can't create sysfs speed attribute err: %d\n", ret); 505 "can't create sysfs speed attribute err: %d\n", ret);
380 506
381 /* Set Wacom mode 2 with high reporting speed */ 507 switch (hdev->product) {
382 wacom_poke(hdev, 1); 508 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
509 /* Set Wacom mode 2 with high reporting speed */
510 wacom_poke(hdev, 1);
511 break;
512 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
513 wdata->features = 0;
514 wacom_set_features(hdev);
515 break;
516 }
383 517
384#ifdef CONFIG_HID_WACOM_POWER_SUPPLY 518#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
385 wdata->battery.properties = wacom_battery_props; 519 wdata->battery.properties = wacom_battery_props;
@@ -441,6 +575,7 @@ static void wacom_remove(struct hid_device *hdev)
441 575
442static const struct hid_device_id wacom_devices[] = { 576static const struct hid_device_id wacom_devices[] = {
443 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 577 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
578 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
444 579
445 { } 580 { }
446}; 581};
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote-core.c
index 76739c07fa3..61881b35c67 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote-core.c
@@ -20,91 +20,7 @@
20#include <linux/power_supply.h> 20#include <linux/power_supply.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include "hid-ids.h" 22#include "hid-ids.h"
23 23#include "hid-wiimote.h"
24#define WIIMOTE_VERSION "0.2"
25#define WIIMOTE_NAME "Nintendo Wii Remote"
26#define WIIMOTE_BUFSIZE 32
27
28struct wiimote_buf {
29 __u8 data[HID_MAX_BUFFER_SIZE];
30 size_t size;
31};
32
33struct wiimote_state {
34 spinlock_t lock;
35 __u8 flags;
36 __u8 accel_split[2];
37
38 /* synchronous cmd requests */
39 struct mutex sync;
40 struct completion ready;
41 int cmd;
42 __u32 opt;
43
44 /* results of synchronous requests */
45 __u8 cmd_battery;
46 __u8 cmd_err;
47};
48
49struct wiimote_data {
50 struct hid_device *hdev;
51 struct input_dev *input;
52 struct led_classdev *leds[4];
53 struct input_dev *accel;
54 struct input_dev *ir;
55 struct power_supply battery;
56
57 spinlock_t qlock;
58 __u8 head;
59 __u8 tail;
60 struct wiimote_buf outq[WIIMOTE_BUFSIZE];
61 struct work_struct worker;
62
63 struct wiimote_state state;
64};
65
66#define WIIPROTO_FLAG_LED1 0x01
67#define WIIPROTO_FLAG_LED2 0x02
68#define WIIPROTO_FLAG_LED3 0x04
69#define WIIPROTO_FLAG_LED4 0x08
70#define WIIPROTO_FLAG_RUMBLE 0x10
71#define WIIPROTO_FLAG_ACCEL 0x20
72#define WIIPROTO_FLAG_IR_BASIC 0x40
73#define WIIPROTO_FLAG_IR_EXT 0x80
74#define WIIPROTO_FLAG_IR_FULL 0xc0 /* IR_BASIC | IR_EXT */
75#define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \
76 WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4)
77#define WIIPROTO_FLAGS_IR (WIIPROTO_FLAG_IR_BASIC | WIIPROTO_FLAG_IR_EXT | \
78 WIIPROTO_FLAG_IR_FULL)
79
80/* return flag for led \num */
81#define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1))
82
83enum wiiproto_reqs {
84 WIIPROTO_REQ_NULL = 0x0,
85 WIIPROTO_REQ_RUMBLE = 0x10,
86 WIIPROTO_REQ_LED = 0x11,
87 WIIPROTO_REQ_DRM = 0x12,
88 WIIPROTO_REQ_IR1 = 0x13,
89 WIIPROTO_REQ_SREQ = 0x15,
90 WIIPROTO_REQ_WMEM = 0x16,
91 WIIPROTO_REQ_RMEM = 0x17,
92 WIIPROTO_REQ_IR2 = 0x1a,
93 WIIPROTO_REQ_STATUS = 0x20,
94 WIIPROTO_REQ_DATA = 0x21,
95 WIIPROTO_REQ_RETURN = 0x22,
96 WIIPROTO_REQ_DRM_K = 0x30,
97 WIIPROTO_REQ_DRM_KA = 0x31,
98 WIIPROTO_REQ_DRM_KE = 0x32,
99 WIIPROTO_REQ_DRM_KAI = 0x33,
100 WIIPROTO_REQ_DRM_KEE = 0x34,
101 WIIPROTO_REQ_DRM_KAE = 0x35,
102 WIIPROTO_REQ_DRM_KIE = 0x36,
103 WIIPROTO_REQ_DRM_KAIE = 0x37,
104 WIIPROTO_REQ_DRM_E = 0x3d,
105 WIIPROTO_REQ_DRM_SKAI1 = 0x3e,
106 WIIPROTO_REQ_DRM_SKAI2 = 0x3f,
107};
108 24
109enum wiiproto_keys { 25enum wiiproto_keys {
110 WIIPROTO_KEY_LEFT, 26 WIIPROTO_KEY_LEFT,
@@ -139,52 +55,6 @@ static enum power_supply_property wiimote_battery_props[] = {
139 POWER_SUPPLY_PROP_CAPACITY 55 POWER_SUPPLY_PROP_CAPACITY
140}; 56};
141 57
142/* requires the state.lock spinlock to be held */
143static inline bool wiimote_cmd_pending(struct wiimote_data *wdata, int cmd,
144 __u32 opt)
145{
146 return wdata->state.cmd == cmd && wdata->state.opt == opt;
147}
148
149/* requires the state.lock spinlock to be held */
150static inline void wiimote_cmd_complete(struct wiimote_data *wdata)
151{
152 wdata->state.cmd = WIIPROTO_REQ_NULL;
153 complete(&wdata->state.ready);
154}
155
156static inline int wiimote_cmd_acquire(struct wiimote_data *wdata)
157{
158 return mutex_lock_interruptible(&wdata->state.sync) ? -ERESTARTSYS : 0;
159}
160
161/* requires the state.lock spinlock to be held */
162static inline void wiimote_cmd_set(struct wiimote_data *wdata, int cmd,
163 __u32 opt)
164{
165 INIT_COMPLETION(wdata->state.ready);
166 wdata->state.cmd = cmd;
167 wdata->state.opt = opt;
168}
169
170static inline void wiimote_cmd_release(struct wiimote_data *wdata)
171{
172 mutex_unlock(&wdata->state.sync);
173}
174
175static inline int wiimote_cmd_wait(struct wiimote_data *wdata)
176{
177 int ret;
178
179 ret = wait_for_completion_interruptible_timeout(&wdata->state.ready, HZ);
180 if (ret < 0)
181 return -ERESTARTSYS;
182 else if (ret == 0)
183 return -EIO;
184 else
185 return 0;
186}
187
188static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, 58static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer,
189 size_t count) 59 size_t count)
190{ 60{
@@ -329,6 +199,7 @@ static void wiiproto_req_leds(struct wiimote_data *wdata, int leds)
329static __u8 select_drm(struct wiimote_data *wdata) 199static __u8 select_drm(struct wiimote_data *wdata)
330{ 200{
331 __u8 ir = wdata->state.flags & WIIPROTO_FLAGS_IR; 201 __u8 ir = wdata->state.flags & WIIPROTO_FLAGS_IR;
202 bool ext = wiiext_active(wdata);
332 203
333 if (ir == WIIPROTO_FLAG_IR_BASIC) { 204 if (ir == WIIPROTO_FLAG_IR_BASIC) {
334 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) 205 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL)
@@ -340,14 +211,21 @@ static __u8 select_drm(struct wiimote_data *wdata)
340 } else if (ir == WIIPROTO_FLAG_IR_FULL) { 211 } else if (ir == WIIPROTO_FLAG_IR_FULL) {
341 return WIIPROTO_REQ_DRM_SKAI1; 212 return WIIPROTO_REQ_DRM_SKAI1;
342 } else { 213 } else {
343 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) 214 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) {
344 return WIIPROTO_REQ_DRM_KA; 215 if (ext)
345 else 216 return WIIPROTO_REQ_DRM_KAE;
346 return WIIPROTO_REQ_DRM_K; 217 else
218 return WIIPROTO_REQ_DRM_KA;
219 } else {
220 if (ext)
221 return WIIPROTO_REQ_DRM_KE;
222 else
223 return WIIPROTO_REQ_DRM_K;
224 }
347 } 225 }
348} 226}
349 227
350static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) 228void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm)
351{ 229{
352 __u8 cmd[3]; 230 __u8 cmd[3];
353 231
@@ -358,6 +236,7 @@ static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm)
358 cmd[1] = 0; 236 cmd[1] = 0;
359 cmd[2] = drm; 237 cmd[2] = drm;
360 238
239 wdata->state.drm = drm;
361 wiiproto_keep_rumble(wdata, &cmd[1]); 240 wiiproto_keep_rumble(wdata, &cmd[1]);
362 wiimote_queue(wdata, cmd, sizeof(cmd)); 241 wiimote_queue(wdata, cmd, sizeof(cmd));
363} 242}
@@ -440,8 +319,33 @@ static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom,
440 wiimote_queue(wdata, cmd, sizeof(cmd)); 319 wiimote_queue(wdata, cmd, sizeof(cmd));
441} 320}
442 321
322void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom, __u32 offset,
323 __u16 size)
324{
325 __u8 cmd[7];
326
327 if (size == 0) {
328 hid_warn(wdata->hdev, "Invalid length %d rmem request\n", size);
329 return;
330 }
331
332 cmd[0] = WIIPROTO_REQ_RMEM;
333 cmd[1] = 0;
334 cmd[2] = (offset >> 16) & 0xff;
335 cmd[3] = (offset >> 8) & 0xff;
336 cmd[4] = offset & 0xff;
337 cmd[5] = (size >> 8) & 0xff;
338 cmd[6] = size & 0xff;
339
340 if (!eeprom)
341 cmd[1] |= 0x04;
342
343 wiiproto_keep_rumble(wdata, &cmd[1]);
344 wiimote_queue(wdata, cmd, sizeof(cmd));
345}
346
443/* requries the cmd-mutex to be held */ 347/* requries the cmd-mutex to be held */
444static int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset, 348int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset,
445 const __u8 *wmem, __u8 size) 349 const __u8 *wmem, __u8 size)
446{ 350{
447 unsigned long flags; 351 unsigned long flags;
@@ -459,6 +363,36 @@ static int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset,
459 return ret; 363 return ret;
460} 364}
461 365
366/* requries the cmd-mutex to be held */
367ssize_t wiimote_cmd_read(struct wiimote_data *wdata, __u32 offset, __u8 *rmem,
368 __u8 size)
369{
370 unsigned long flags;
371 ssize_t ret;
372
373 spin_lock_irqsave(&wdata->state.lock, flags);
374 wdata->state.cmd_read_size = size;
375 wdata->state.cmd_read_buf = rmem;
376 wiimote_cmd_set(wdata, WIIPROTO_REQ_RMEM, offset & 0xffff);
377 wiiproto_req_rreg(wdata, offset, size);
378 spin_unlock_irqrestore(&wdata->state.lock, flags);
379
380 ret = wiimote_cmd_wait(wdata);
381
382 spin_lock_irqsave(&wdata->state.lock, flags);
383 wdata->state.cmd_read_buf = NULL;
384 spin_unlock_irqrestore(&wdata->state.lock, flags);
385
386 if (!ret) {
387 if (wdata->state.cmd_read_size == 0)
388 ret = -EIO;
389 else
390 ret = wdata->state.cmd_read_size;
391 }
392
393 return ret;
394}
395
462static int wiimote_battery_get_property(struct power_supply *psy, 396static int wiimote_battery_get_property(struct power_supply *psy,
463 enum power_supply_property psp, 397 enum power_supply_property psp,
464 union power_supply_propval *val) 398 union power_supply_propval *val)
@@ -862,6 +796,8 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload)
862 /* on status reports the drm is reset so we need to resend the drm */ 796 /* on status reports the drm is reset so we need to resend the drm */
863 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); 797 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
864 798
799 wiiext_event(wdata, payload[2] & 0x02);
800
865 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) { 801 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) {
866 wdata->state.cmd_battery = payload[5]; 802 wdata->state.cmd_battery = payload[5];
867 wiimote_cmd_complete(wdata); 803 wiimote_cmd_complete(wdata);
@@ -870,7 +806,23 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload)
870 806
871static void handler_data(struct wiimote_data *wdata, const __u8 *payload) 807static void handler_data(struct wiimote_data *wdata, const __u8 *payload)
872{ 808{
809 __u16 offset = payload[3] << 8 | payload[4];
810 __u8 size = (payload[2] >> 4) + 1;
811 __u8 err = payload[2] & 0x0f;
812
873 handler_keys(wdata, payload); 813 handler_keys(wdata, payload);
814
815 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_RMEM, offset)) {
816 if (err)
817 size = 0;
818 else if (size > wdata->state.cmd_read_size)
819 size = wdata->state.cmd_read_size;
820
821 wdata->state.cmd_read_size = size;
822 if (wdata->state.cmd_read_buf)
823 memcpy(wdata->state.cmd_read_buf, &payload[5], size);
824 wiimote_cmd_complete(wdata);
825 }
874} 826}
875 827
876static void handler_return(struct wiimote_data *wdata, const __u8 *payload) 828static void handler_return(struct wiimote_data *wdata, const __u8 *payload)
@@ -898,6 +850,7 @@ static void handler_drm_KA(struct wiimote_data *wdata, const __u8 *payload)
898static void handler_drm_KE(struct wiimote_data *wdata, const __u8 *payload) 850static void handler_drm_KE(struct wiimote_data *wdata, const __u8 *payload)
899{ 851{
900 handler_keys(wdata, payload); 852 handler_keys(wdata, payload);
853 wiiext_handle(wdata, &payload[2]);
901} 854}
902 855
903static void handler_drm_KAI(struct wiimote_data *wdata, const __u8 *payload) 856static void handler_drm_KAI(struct wiimote_data *wdata, const __u8 *payload)
@@ -914,6 +867,7 @@ static void handler_drm_KAI(struct wiimote_data *wdata, const __u8 *payload)
914static void handler_drm_KEE(struct wiimote_data *wdata, const __u8 *payload) 867static void handler_drm_KEE(struct wiimote_data *wdata, const __u8 *payload)
915{ 868{
916 handler_keys(wdata, payload); 869 handler_keys(wdata, payload);
870 wiiext_handle(wdata, &payload[2]);
917} 871}
918 872
919static void handler_drm_KIE(struct wiimote_data *wdata, const __u8 *payload) 873static void handler_drm_KIE(struct wiimote_data *wdata, const __u8 *payload)
@@ -924,12 +878,14 @@ static void handler_drm_KIE(struct wiimote_data *wdata, const __u8 *payload)
924 ir_to_input2(wdata, &payload[7], false); 878 ir_to_input2(wdata, &payload[7], false);
925 ir_to_input3(wdata, &payload[9], true); 879 ir_to_input3(wdata, &payload[9], true);
926 input_sync(wdata->ir); 880 input_sync(wdata->ir);
881 wiiext_handle(wdata, &payload[12]);
927} 882}
928 883
929static void handler_drm_KAE(struct wiimote_data *wdata, const __u8 *payload) 884static void handler_drm_KAE(struct wiimote_data *wdata, const __u8 *payload)
930{ 885{
931 handler_keys(wdata, payload); 886 handler_keys(wdata, payload);
932 handler_accel(wdata, payload); 887 handler_accel(wdata, payload);
888 wiiext_handle(wdata, &payload[5]);
933} 889}
934 890
935static void handler_drm_KAIE(struct wiimote_data *wdata, const __u8 *payload) 891static void handler_drm_KAIE(struct wiimote_data *wdata, const __u8 *payload)
@@ -941,10 +897,12 @@ static void handler_drm_KAIE(struct wiimote_data *wdata, const __u8 *payload)
941 ir_to_input2(wdata, &payload[10], false); 897 ir_to_input2(wdata, &payload[10], false);
942 ir_to_input3(wdata, &payload[12], true); 898 ir_to_input3(wdata, &payload[12], true);
943 input_sync(wdata->ir); 899 input_sync(wdata->ir);
900 wiiext_handle(wdata, &payload[15]);
944} 901}
945 902
946static void handler_drm_E(struct wiimote_data *wdata, const __u8 *payload) 903static void handler_drm_E(struct wiimote_data *wdata, const __u8 *payload)
947{ 904{
905 wiiext_handle(wdata, payload);
948} 906}
949 907
950static void handler_drm_SKAI1(struct wiimote_data *wdata, const __u8 *payload) 908static void handler_drm_SKAI1(struct wiimote_data *wdata, const __u8 *payload)
@@ -1182,6 +1140,7 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev)
1182 spin_lock_init(&wdata->state.lock); 1140 spin_lock_init(&wdata->state.lock);
1183 init_completion(&wdata->state.ready); 1141 init_completion(&wdata->state.ready);
1184 mutex_init(&wdata->state.sync); 1142 mutex_init(&wdata->state.sync);
1143 wdata->state.drm = WIIPROTO_REQ_DRM_K;
1185 1144
1186 return wdata; 1145 return wdata;
1187 1146
@@ -1196,6 +1155,8 @@ err:
1196 1155
1197static void wiimote_destroy(struct wiimote_data *wdata) 1156static void wiimote_destroy(struct wiimote_data *wdata)
1198{ 1157{
1158 wiidebug_deinit(wdata);
1159 wiiext_deinit(wdata);
1199 wiimote_leds_destroy(wdata); 1160 wiimote_leds_destroy(wdata);
1200 1161
1201 power_supply_unregister(&wdata->battery); 1162 power_supply_unregister(&wdata->battery);
@@ -1214,6 +1175,8 @@ static int wiimote_hid_probe(struct hid_device *hdev,
1214 struct wiimote_data *wdata; 1175 struct wiimote_data *wdata;
1215 int ret; 1176 int ret;
1216 1177
1178 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1179
1217 wdata = wiimote_create(hdev); 1180 wdata = wiimote_create(hdev);
1218 if (!wdata) { 1181 if (!wdata) {
1219 hid_err(hdev, "Can't alloc device\n"); 1182 hid_err(hdev, "Can't alloc device\n");
@@ -1267,6 +1230,14 @@ static int wiimote_hid_probe(struct hid_device *hdev,
1267 if (ret) 1230 if (ret)
1268 goto err_free; 1231 goto err_free;
1269 1232
1233 ret = wiiext_init(wdata);
1234 if (ret)
1235 goto err_free;
1236
1237 ret = wiidebug_init(wdata);
1238 if (ret)
1239 goto err_free;
1240
1270 hid_info(hdev, "New device registered\n"); 1241 hid_info(hdev, "New device registered\n");
1271 1242
1272 /* by default set led1 after device initialization */ 1243 /* by default set led1 after device initialization */
@@ -1343,4 +1314,3 @@ module_exit(wiimote_exit);
1343MODULE_LICENSE("GPL"); 1314MODULE_LICENSE("GPL");
1344MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>"); 1315MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
1345MODULE_DESCRIPTION(WIIMOTE_NAME " Device Driver"); 1316MODULE_DESCRIPTION(WIIMOTE_NAME " Device Driver");
1346MODULE_VERSION(WIIMOTE_VERSION);
diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
new file mode 100644
index 00000000000..17dabc1f339
--- /dev/null
+++ b/drivers/hid/hid-wiimote-debug.c
@@ -0,0 +1,227 @@
1/*
2 * Debug support for HID Nintendo Wiimote devices
3 * Copyright (c) 2011 David Herrmann
4 */
5
6/*
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 */
12
13#include <linux/debugfs.h>
14#include <linux/module.h>
15#include <linux/seq_file.h>
16#include <linux/spinlock.h>
17#include <linux/uaccess.h>
18#include "hid-wiimote.h"
19
20struct wiimote_debug {
21 struct wiimote_data *wdata;
22 struct dentry *eeprom;
23 struct dentry *drm;
24};
25
26static int wiidebug_eeprom_open(struct inode *i, struct file *f)
27{
28 f->private_data = i->i_private;
29 return 0;
30}
31
32static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33 loff_t *off)
34{
35 struct wiimote_debug *dbg = f->private_data;
36 struct wiimote_data *wdata = dbg->wdata;
37 unsigned long flags;
38 ssize_t ret;
39 char buf[16];
40 __u16 size;
41
42 if (s == 0)
43 return -EINVAL;
44 if (*off > 0xffffff)
45 return 0;
46 if (s > 16)
47 s = 16;
48
49 ret = wiimote_cmd_acquire(wdata);
50 if (ret)
51 return ret;
52
53 spin_lock_irqsave(&wdata->state.lock, flags);
54 wdata->state.cmd_read_size = s;
55 wdata->state.cmd_read_buf = buf;
56 wiimote_cmd_set(wdata, WIIPROTO_REQ_RMEM, *off & 0xffff);
57 wiiproto_req_reeprom(wdata, *off, s);
58 spin_unlock_irqrestore(&wdata->state.lock, flags);
59
60 ret = wiimote_cmd_wait(wdata);
61 if (!ret)
62 size = wdata->state.cmd_read_size;
63
64 spin_lock_irqsave(&wdata->state.lock, flags);
65 wdata->state.cmd_read_buf = NULL;
66 spin_unlock_irqrestore(&wdata->state.lock, flags);
67
68 wiimote_cmd_release(wdata);
69
70 if (ret)
71 return ret;
72 else if (size == 0)
73 return -EIO;
74
75 if (copy_to_user(u, buf, size))
76 return -EFAULT;
77
78 *off += size;
79 ret = size;
80
81 return ret;
82}
83
84static const struct file_operations wiidebug_eeprom_fops = {
85 .owner = THIS_MODULE,
86 .open = wiidebug_eeprom_open,
87 .read = wiidebug_eeprom_read,
88 .llseek = generic_file_llseek,
89};
90
91static const char *wiidebug_drmmap[] = {
92 [WIIPROTO_REQ_NULL] = "NULL",
93 [WIIPROTO_REQ_DRM_K] = "K",
94 [WIIPROTO_REQ_DRM_KA] = "KA",
95 [WIIPROTO_REQ_DRM_KE] = "KE",
96 [WIIPROTO_REQ_DRM_KAI] = "KAI",
97 [WIIPROTO_REQ_DRM_KEE] = "KEE",
98 [WIIPROTO_REQ_DRM_KAE] = "KAE",
99 [WIIPROTO_REQ_DRM_KIE] = "KIE",
100 [WIIPROTO_REQ_DRM_KAIE] = "KAIE",
101 [WIIPROTO_REQ_DRM_E] = "E",
102 [WIIPROTO_REQ_DRM_SKAI1] = "SKAI1",
103 [WIIPROTO_REQ_DRM_SKAI2] = "SKAI2",
104 [WIIPROTO_REQ_MAX] = NULL
105};
106
107static int wiidebug_drm_show(struct seq_file *f, void *p)
108{
109 struct wiimote_debug *dbg = f->private;
110 const char *str = NULL;
111 unsigned long flags;
112 __u8 drm;
113
114 spin_lock_irqsave(&dbg->wdata->state.lock, flags);
115 drm = dbg->wdata->state.drm;
116 spin_unlock_irqrestore(&dbg->wdata->state.lock, flags);
117
118 if (drm < WIIPROTO_REQ_MAX)
119 str = wiidebug_drmmap[drm];
120 if (!str)
121 str = "unknown";
122
123 seq_printf(f, "%s\n", str);
124
125 return 0;
126}
127
128static int wiidebug_drm_open(struct inode *i, struct file *f)
129{
130 return single_open(f, wiidebug_drm_show, i->i_private);
131}
132
133static ssize_t wiidebug_drm_write(struct file *f, const char __user *u,
134 size_t s, loff_t *off)
135{
136 struct wiimote_debug *dbg = f->private_data;
137 unsigned long flags;
138 char buf[16];
139 ssize_t len;
140 int i;
141
142 if (s == 0)
143 return -EINVAL;
144
145 len = min((size_t) 15, s);
146 if (copy_from_user(buf, u, len))
147 return -EFAULT;
148
149 buf[15] = 0;
150
151 for (i = 0; i < WIIPROTO_REQ_MAX; ++i) {
152 if (!wiidebug_drmmap[i])
153 continue;
154 if (!strcasecmp(buf, wiidebug_drmmap[i]))
155 break;
156 }
157
158 if (i == WIIPROTO_REQ_MAX)
159 i = simple_strtoul(buf, NULL, 10);
160
161 spin_lock_irqsave(&dbg->wdata->state.lock, flags);
162 wiiproto_req_drm(dbg->wdata, (__u8) i);
163 spin_unlock_irqrestore(&dbg->wdata->state.lock, flags);
164
165 return len;
166}
167
168static const struct file_operations wiidebug_drm_fops = {
169 .owner = THIS_MODULE,
170 .open = wiidebug_drm_open,
171 .read = seq_read,
172 .llseek = seq_lseek,
173 .write = wiidebug_drm_write,
174 .release = single_release,
175};
176
177int wiidebug_init(struct wiimote_data *wdata)
178{
179 struct wiimote_debug *dbg;
180 unsigned long flags;
181 int ret = -ENOMEM;
182
183 dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
184 if (!dbg)
185 return -ENOMEM;
186
187 dbg->wdata = wdata;
188
189 dbg->eeprom = debugfs_create_file("eeprom", S_IRUSR,
190 dbg->wdata->hdev->debug_dir, dbg, &wiidebug_eeprom_fops);
191 if (!dbg->eeprom)
192 goto err;
193
194 dbg->drm = debugfs_create_file("drm", S_IRUSR,
195 dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops);
196 if (!dbg->drm)
197 goto err_drm;
198
199 spin_lock_irqsave(&wdata->state.lock, flags);
200 wdata->debug = dbg;
201 spin_unlock_irqrestore(&wdata->state.lock, flags);
202
203 return 0;
204
205err_drm:
206 debugfs_remove(dbg->eeprom);
207err:
208 kfree(dbg);
209 return ret;
210}
211
212void wiidebug_deinit(struct wiimote_data *wdata)
213{
214 struct wiimote_debug *dbg = wdata->debug;
215 unsigned long flags;
216
217 if (!dbg)
218 return;
219
220 spin_lock_irqsave(&wdata->state.lock, flags);
221 wdata->debug = NULL;
222 spin_unlock_irqrestore(&wdata->state.lock, flags);
223
224 debugfs_remove(dbg->drm);
225 debugfs_remove(dbg->eeprom);
226 kfree(dbg);
227}
diff --git a/drivers/hid/hid-wiimote-ext.c b/drivers/hid/hid-wiimote-ext.c
new file mode 100644
index 00000000000..aa958706c0e
--- /dev/null
+++ b/drivers/hid/hid-wiimote-ext.c
@@ -0,0 +1,752 @@
1/*
2 * HID driver for Nintendo Wiimote extension devices
3 * Copyright (c) 2011 David Herrmann
4 */
5
6/*
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 */
12
13#include <linux/atomic.h>
14#include <linux/module.h>
15#include <linux/spinlock.h>
16#include <linux/workqueue.h>
17#include "hid-wiimote.h"
18
19struct wiimote_ext {
20 struct wiimote_data *wdata;
21 struct work_struct worker;
22 struct input_dev *input;
23 struct input_dev *mp_input;
24
25 atomic_t opened;
26 atomic_t mp_opened;
27 bool plugged;
28 bool mp_plugged;
29 bool motionp;
30 __u8 ext_type;
31};
32
33enum wiiext_type {
34 WIIEXT_NONE, /* placeholder */
35 WIIEXT_CLASSIC, /* Nintendo classic controller */
36 WIIEXT_NUNCHUCK, /* Nintendo nunchuck controller */
37};
38
39enum wiiext_keys {
40 WIIEXT_KEY_C,
41 WIIEXT_KEY_Z,
42 WIIEXT_KEY_A,
43 WIIEXT_KEY_B,
44 WIIEXT_KEY_X,
45 WIIEXT_KEY_Y,
46 WIIEXT_KEY_ZL,
47 WIIEXT_KEY_ZR,
48 WIIEXT_KEY_PLUS,
49 WIIEXT_KEY_MINUS,
50 WIIEXT_KEY_HOME,
51 WIIEXT_KEY_LEFT,
52 WIIEXT_KEY_RIGHT,
53 WIIEXT_KEY_UP,
54 WIIEXT_KEY_DOWN,
55 WIIEXT_KEY_LT,
56 WIIEXT_KEY_RT,
57 WIIEXT_KEY_COUNT
58};
59
60static __u16 wiiext_keymap[] = {
61 BTN_C, /* WIIEXT_KEY_C */
62 BTN_Z, /* WIIEXT_KEY_Z */
63 BTN_A, /* WIIEXT_KEY_A */
64 BTN_B, /* WIIEXT_KEY_B */
65 BTN_X, /* WIIEXT_KEY_X */
66 BTN_Y, /* WIIEXT_KEY_Y */
67 BTN_TL2, /* WIIEXT_KEY_ZL */
68 BTN_TR2, /* WIIEXT_KEY_ZR */
69 KEY_NEXT, /* WIIEXT_KEY_PLUS */
70 KEY_PREVIOUS, /* WIIEXT_KEY_MINUS */
71 BTN_MODE, /* WIIEXT_KEY_HOME */
72 KEY_LEFT, /* WIIEXT_KEY_LEFT */
73 KEY_RIGHT, /* WIIEXT_KEY_RIGHT */
74 KEY_UP, /* WIIEXT_KEY_UP */
75 KEY_DOWN, /* WIIEXT_KEY_DOWN */
76 BTN_TL, /* WIIEXT_KEY_LT */
77 BTN_TR, /* WIIEXT_KEY_RT */
78};
79
80/* diable all extensions */
81static void ext_disable(struct wiimote_ext *ext)
82{
83 unsigned long flags;
84 __u8 wmem = 0x55;
85
86 if (!wiimote_cmd_acquire(ext->wdata)) {
87 wiimote_cmd_write(ext->wdata, 0xa400f0, &wmem, sizeof(wmem));
88 wiimote_cmd_release(ext->wdata);
89 }
90
91 spin_lock_irqsave(&ext->wdata->state.lock, flags);
92 ext->motionp = false;
93 ext->ext_type = WIIEXT_NONE;
94 wiiproto_req_drm(ext->wdata, WIIPROTO_REQ_NULL);
95 spin_unlock_irqrestore(&ext->wdata->state.lock, flags);
96}
97
98static bool motionp_read(struct wiimote_ext *ext)
99{
100 __u8 rmem[2], wmem;
101 ssize_t ret;
102 bool avail = false;
103
104 if (!atomic_read(&ext->mp_opened))
105 return false;
106
107 if (wiimote_cmd_acquire(ext->wdata))
108 return false;
109
110 /* initialize motion plus */
111 wmem = 0x55;
112 ret = wiimote_cmd_write(ext->wdata, 0xa600f0, &wmem, sizeof(wmem));
113 if (ret)
114 goto error;
115
116 /* read motion plus ID */
117 ret = wiimote_cmd_read(ext->wdata, 0xa600fe, rmem, 2);
118 if (ret == 2 || rmem[1] == 0x5)
119 avail = true;
120
121error:
122 wiimote_cmd_release(ext->wdata);
123 return avail;
124}
125
126static __u8 ext_read(struct wiimote_ext *ext)
127{
128 ssize_t ret;
129 __u8 rmem[2], wmem;
130 __u8 type = WIIEXT_NONE;
131
132 if (!ext->plugged || !atomic_read(&ext->opened))
133 return WIIEXT_NONE;
134
135 if (wiimote_cmd_acquire(ext->wdata))
136 return WIIEXT_NONE;
137
138 /* initialize extension */
139 wmem = 0x55;
140 ret = wiimote_cmd_write(ext->wdata, 0xa400f0, &wmem, sizeof(wmem));
141 if (!ret) {
142 /* disable encryption */
143 wmem = 0x0;
144 wiimote_cmd_write(ext->wdata, 0xa400fb, &wmem, sizeof(wmem));
145 }
146
147 /* read extension ID */
148 ret = wiimote_cmd_read(ext->wdata, 0xa400fe, rmem, 2);
149 if (ret == 2) {
150 if (rmem[0] == 0 && rmem[1] == 0)
151 type = WIIEXT_NUNCHUCK;
152 else if (rmem[0] == 0x01 && rmem[1] == 0x01)
153 type = WIIEXT_CLASSIC;
154 }
155
156 wiimote_cmd_release(ext->wdata);
157
158 return type;
159}
160
161static void ext_enable(struct wiimote_ext *ext, bool motionp, __u8 ext_type)
162{
163 unsigned long flags;
164 __u8 wmem;
165 int ret;
166
167 if (motionp) {
168 if (wiimote_cmd_acquire(ext->wdata))
169 return;
170
171 if (ext_type == WIIEXT_CLASSIC)
172 wmem = 0x07;
173 else if (ext_type == WIIEXT_NUNCHUCK)
174 wmem = 0x05;
175 else
176 wmem = 0x04;
177
178 ret = wiimote_cmd_write(ext->wdata, 0xa600fe, &wmem, sizeof(wmem));
179 wiimote_cmd_release(ext->wdata);
180 if (ret)
181 return;
182 }
183
184 spin_lock_irqsave(&ext->wdata->state.lock, flags);
185 ext->motionp = motionp;
186 ext->ext_type = ext_type;
187 wiiproto_req_drm(ext->wdata, WIIPROTO_REQ_NULL);
188 spin_unlock_irqrestore(&ext->wdata->state.lock, flags);
189}
190
191static void wiiext_worker(struct work_struct *work)
192{
193 struct wiimote_ext *ext = container_of(work, struct wiimote_ext,
194 worker);
195 bool motionp;
196 __u8 ext_type;
197
198 ext_disable(ext);
199 motionp = motionp_read(ext);
200 ext_type = ext_read(ext);
201 ext_enable(ext, motionp, ext_type);
202}
203
204/* schedule work only once, otherwise mark for reschedule */
205static void wiiext_schedule(struct wiimote_ext *ext)
206{
207 queue_work(system_nrt_wq, &ext->worker);
208}
209
210/*
211 * Reacts on extension port events
212 * Whenever the driver gets an event from the wiimote that an extension has been
213 * plugged or unplugged, this funtion shall be called. It checks what extensions
214 * are connected and initializes and activates them.
215 * This can be called in atomic context. The initialization is done in a
216 * separate worker thread. The state.lock spinlock must be held by the caller.
217 */
218void wiiext_event(struct wiimote_data *wdata, bool plugged)
219{
220 if (!wdata->ext)
221 return;
222
223 if (wdata->ext->plugged == plugged)
224 return;
225
226 wdata->ext->plugged = plugged;
227
228 if (!plugged)
229 wdata->ext->mp_plugged = false;
230
231 /*
232 * We need to call wiiext_schedule(wdata->ext) here, however, the
233 * extension initialization logic is not fully understood and so
234 * automatic initialization is not supported, yet.
235 */
236}
237
238/*
239 * Returns true if the current DRM mode should contain extension data and false
240 * if there is no interest in extension data.
241 * All supported extensions send 6 byte extension data so any DRM that contains
242 * extension bytes is fine.
243 * The caller must hold the state.lock spinlock.
244 */
245bool wiiext_active(struct wiimote_data *wdata)
246{
247 if (!wdata->ext)
248 return false;
249
250 return wdata->ext->motionp || wdata->ext->ext_type;
251}
252
253static void handler_motionp(struct wiimote_ext *ext, const __u8 *payload)
254{
255 __s32 x, y, z;
256 bool plugged;
257
258 /* | 8 7 6 5 4 3 | 2 | 1 |
259 * -----+------------------------------+-----+-----+
260 * 1 | Yaw Speed <7:0> |
261 * 2 | Roll Speed <7:0> |
262 * 3 | Pitch Speed <7:0> |
263 * -----+------------------------------+-----+-----+
264 * 4 | Yaw Speed <13:8> | Yaw |Pitch|
265 * -----+------------------------------+-----+-----+
266 * 5 | Roll Speed <13:8> |Roll | Ext |
267 * -----+------------------------------+-----+-----+
268 * 6 | Pitch Speed <13:8> | 1 | 0 |
269 * -----+------------------------------+-----+-----+
270 * The single bits Yaw, Roll, Pitch in the lower right corner specify
271 * whether the wiimote is rotating fast (0) or slow (1). Speed for slow
272 * roation is 440 deg/s and for fast rotation 2000 deg/s. To get a
273 * linear scale we multiply by 2000/440 = ~4.5454 which is 18 for fast
274 * and 9 for slow.
275 * If the wiimote is not rotating the sensor reports 2^13 = 8192.
276 * Ext specifies whether an extension is connected to the motionp.
277 */
278
279 x = payload[0];
280 y = payload[1];
281 z = payload[2];
282
283 x |= (((__u16)payload[3]) << 6) & 0xff00;
284 y |= (((__u16)payload[4]) << 6) & 0xff00;
285 z |= (((__u16)payload[5]) << 6) & 0xff00;
286
287 x -= 8192;
288 y -= 8192;
289 z -= 8192;
290
291 if (!(payload[3] & 0x02))
292 x *= 18;
293 else
294 x *= 9;
295 if (!(payload[4] & 0x02))
296 y *= 18;
297 else
298 y *= 9;
299 if (!(payload[3] & 0x01))
300 z *= 18;
301 else
302 z *= 9;
303
304 input_report_abs(ext->mp_input, ABS_RX, x);
305 input_report_abs(ext->mp_input, ABS_RY, y);
306 input_report_abs(ext->mp_input, ABS_RZ, z);
307 input_sync(ext->mp_input);
308
309 plugged = payload[5] & 0x01;
310 if (plugged != ext->mp_plugged)
311 ext->mp_plugged = plugged;
312}
313
314static void handler_nunchuck(struct wiimote_ext *ext, const __u8 *payload)
315{
316 __s16 x, y, z, bx, by;
317
318 /* Byte | 8 7 | 6 5 | 4 3 | 2 | 1 |
319 * -----+----------+---------+---------+----+-----+
320 * 1 | Button X <7:0> |
321 * 2 | Button Y <7:0> |
322 * -----+----------+---------+---------+----+-----+
323 * 3 | Speed X <9:2> |
324 * 4 | Speed Y <9:2> |
325 * 5 | Speed Z <9:2> |
326 * -----+----------+---------+---------+----+-----+
327 * 6 | Z <1:0> | Y <1:0> | X <1:0> | BC | BZ |
328 * -----+----------+---------+---------+----+-----+
329 * Button X/Y is the analog stick. Speed X, Y and Z are the
330 * accelerometer data in the same format as the wiimote's accelerometer.
331 * The 6th byte contains the LSBs of the accelerometer data.
332 * BC and BZ are the C and Z buttons: 0 means pressed
333 *
334 * If reported interleaved with motionp, then the layout changes. The
335 * 5th and 6th byte changes to:
336 * -----+-----------------------------------+-----+
337 * 5 | Speed Z <9:3> | EXT |
338 * -----+--------+-----+-----+----+----+----+-----+
339 * 6 |Z <2:1> |Y <1>|X <1>| BC | BZ | 0 | 0 |
340 * -----+--------+-----+-----+----+----+----+-----+
341 * All three accelerometer values lose their LSB. The other data is
342 * still available but slightly moved.
343 *
344 * Center data for button values is 128. Center value for accelerometer
345 * values it 512 / 0x200
346 */
347
348 bx = payload[0];
349 by = payload[1];
350 bx -= 128;
351 by -= 128;
352
353 x = payload[2] << 2;
354 y = payload[3] << 2;
355 z = payload[4] << 2;
356
357 if (ext->motionp) {
358 x |= (payload[5] >> 3) & 0x02;
359 y |= (payload[5] >> 4) & 0x02;
360 z &= ~0x4;
361 z |= (payload[5] >> 5) & 0x06;
362 } else {
363 x |= (payload[5] >> 2) & 0x03;
364 y |= (payload[5] >> 4) & 0x03;
365 z |= (payload[5] >> 6) & 0x03;
366 }
367
368 x -= 0x200;
369 y -= 0x200;
370 z -= 0x200;
371
372 input_report_abs(ext->input, ABS_HAT0X, bx);
373 input_report_abs(ext->input, ABS_HAT0Y, by);
374
375 input_report_abs(ext->input, ABS_RX, x);
376 input_report_abs(ext->input, ABS_RY, y);
377 input_report_abs(ext->input, ABS_RZ, z);
378
379 if (ext->motionp) {
380 input_report_key(ext->input,
381 wiiext_keymap[WIIEXT_KEY_Z], !!(payload[5] & 0x04));
382 input_report_key(ext->input,
383 wiiext_keymap[WIIEXT_KEY_C], !!(payload[5] & 0x08));
384 } else {
385 input_report_key(ext->input,
386 wiiext_keymap[WIIEXT_KEY_Z], !!(payload[5] & 0x01));
387 input_report_key(ext->input,
388 wiiext_keymap[WIIEXT_KEY_C], !!(payload[5] & 0x02));
389 }
390
391 input_sync(ext->input);
392}
393
394static void handler_classic(struct wiimote_ext *ext, const __u8 *payload)
395{
396 __s8 rx, ry, lx, ly, lt, rt;
397
398 /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
399 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
400 * 1 | RX <5:4> | LX <5:0> |
401 * 2 | RX <3:2> | LY <5:0> |
402 * -----+-----+-----+-----+-----------------------------+
403 * 3 |RX<1>| LT <5:4> | RY <5:1> |
404 * -----+-----+-----------+-----------------------------+
405 * 4 | LT <3:1> | RT <5:1> |
406 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
407 * 5 | BDR | BDD | BLT | B- | BH | B+ | BRT | 1 |
408 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
409 * 6 | BZL | BB | BY | BA | BX | BZR | BDL | BDU |
410 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
411 * All buttons are 0 if pressed
412 * RX and RY are right analog stick
413 * LX and LY are left analog stick
414 * LT is left trigger, RT is right trigger
415 * BLT is 0 if left trigger is fully pressed
416 * BRT is 0 if right trigger is fully pressed
417 * BDR, BDD, BDL, BDU form the D-Pad with right, down, left, up buttons
418 * BZL is left Z button and BZR is right Z button
419 * B-, BH, B+ are +, HOME and - buttons
420 * BB, BY, BA, BX are A, B, X, Y buttons
421 * LSB of RX, RY, LT, and RT are not transmitted and always 0.
422 *
423 * With motionp enabled it changes slightly to this:
424 * Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
425 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
426 * 1 | RX <4:3> | LX <5:1> | BDU |
427 * 2 | RX <2:1> | LY <5:1> | BDL |
428 * -----+-----+-----+-----+-----------------------+-----+
429 * 3 |RX<0>| LT <4:3> | RY <4:0> |
430 * -----+-----+-----------+-----------------------------+
431 * 4 | LT <2:0> | RT <4:0> |
432 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
433 * 5 | BDR | BDD | BLT | B- | BH | B+ | BRT | EXT |
434 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
435 * 6 | BZL | BB | BY | BA | BX | BZR | 0 | 0 |
436 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
437 * Only the LSBs of LX and LY are lost. BDU and BDL are moved, the rest
438 * is the same as before.
439 */
440
441 if (ext->motionp) {
442 lx = payload[0] & 0x3e;
443 ly = payload[0] & 0x3e;
444 } else {
445 lx = payload[0] & 0x3f;
446 ly = payload[0] & 0x3f;
447 }
448
449 rx = (payload[0] >> 3) & 0x14;
450 rx |= (payload[1] >> 5) & 0x06;
451 rx |= (payload[2] >> 7) & 0x01;
452 ry = payload[2] & 0x1f;
453
454 rt = payload[3] & 0x1f;
455 lt = (payload[2] >> 2) & 0x18;
456 lt |= (payload[3] >> 5) & 0x07;
457
458 rx <<= 1;
459 ry <<= 1;
460 rt <<= 1;
461 lt <<= 1;
462
463 input_report_abs(ext->input, ABS_HAT1X, lx - 0x20);
464 input_report_abs(ext->input, ABS_HAT1Y, ly - 0x20);
465 input_report_abs(ext->input, ABS_HAT2X, rx - 0x20);
466 input_report_abs(ext->input, ABS_HAT2Y, ry - 0x20);
467 input_report_abs(ext->input, ABS_HAT3X, rt - 0x20);
468 input_report_abs(ext->input, ABS_HAT3Y, lt - 0x20);
469
470 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_RIGHT],
471 !!(payload[4] & 0x80));
472 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_DOWN],
473 !!(payload[4] & 0x40));
474 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_LT],
475 !!(payload[4] & 0x20));
476 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_MINUS],
477 !!(payload[4] & 0x10));
478 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_HOME],
479 !!(payload[4] & 0x08));
480 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_PLUS],
481 !!(payload[4] & 0x04));
482 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_RT],
483 !!(payload[4] & 0x02));
484 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_ZL],
485 !!(payload[5] & 0x80));
486 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_B],
487 !!(payload[5] & 0x40));
488 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_Y],
489 !!(payload[5] & 0x20));
490 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_A],
491 !!(payload[5] & 0x10));
492 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_X],
493 !!(payload[5] & 0x08));
494 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_ZR],
495 !!(payload[5] & 0x04));
496
497 if (ext->motionp) {
498 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_UP],
499 !!(payload[0] & 0x01));
500 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_LEFT],
501 !!(payload[1] & 0x01));
502 } else {
503 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_UP],
504 !!(payload[5] & 0x01));
505 input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_LEFT],
506 !!(payload[5] & 0x02));
507 }
508
509 input_sync(ext->input);
510}
511
512/* call this with state.lock spinlock held */
513void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload)
514{
515 struct wiimote_ext *ext = wdata->ext;
516
517 if (!ext)
518 return;
519
520 if (ext->motionp && (payload[5] & 0x02)) {
521 handler_motionp(ext, payload);
522 } else if (ext->ext_type == WIIEXT_NUNCHUCK) {
523 handler_nunchuck(ext, payload);
524 } else if (ext->ext_type == WIIEXT_CLASSIC) {
525 handler_classic(ext, payload);
526 }
527}
528
529static ssize_t wiiext_show(struct device *dev, struct device_attribute *attr,
530 char *buf)
531{
532 struct wiimote_data *wdata = dev_to_wii(dev);
533 __u8 type = WIIEXT_NONE;
534 bool motionp = false;
535 unsigned long flags;
536
537 spin_lock_irqsave(&wdata->state.lock, flags);
538 if (wdata->ext) {
539 motionp = wdata->ext->motionp;
540 type = wdata->ext->ext_type;
541 }
542 spin_unlock_irqrestore(&wdata->state.lock, flags);
543
544 if (type == WIIEXT_NUNCHUCK) {
545 if (motionp)
546 return sprintf(buf, "motionp+nunchuck\n");
547 else
548 return sprintf(buf, "nunchuck\n");
549 } else if (type == WIIEXT_CLASSIC) {
550 if (motionp)
551 return sprintf(buf, "motionp+classic\n");
552 else
553 return sprintf(buf, "classic\n");
554 } else {
555 if (motionp)
556 return sprintf(buf, "motionp\n");
557 else
558 return sprintf(buf, "none\n");
559 }
560}
561
562static DEVICE_ATTR(extension, S_IRUGO, wiiext_show, NULL);
563
564static int wiiext_input_open(struct input_dev *dev)
565{
566 struct wiimote_ext *ext = input_get_drvdata(dev);
567 int ret;
568
569 ret = hid_hw_open(ext->wdata->hdev);
570 if (ret)
571 return ret;
572
573 atomic_inc(&ext->opened);
574 wiiext_schedule(ext);
575
576 return 0;
577}
578
579static void wiiext_input_close(struct input_dev *dev)
580{
581 struct wiimote_ext *ext = input_get_drvdata(dev);
582
583 atomic_dec(&ext->opened);
584 wiiext_schedule(ext);
585 hid_hw_close(ext->wdata->hdev);
586}
587
588static int wiiext_mp_open(struct input_dev *dev)
589{
590 struct wiimote_ext *ext = input_get_drvdata(dev);
591 int ret;
592
593 ret = hid_hw_open(ext->wdata->hdev);
594 if (ret)
595 return ret;
596
597 atomic_inc(&ext->mp_opened);
598 wiiext_schedule(ext);
599
600 return 0;
601}
602
603static void wiiext_mp_close(struct input_dev *dev)
604{
605 struct wiimote_ext *ext = input_get_drvdata(dev);
606
607 atomic_dec(&ext->mp_opened);
608 wiiext_schedule(ext);
609 hid_hw_close(ext->wdata->hdev);
610}
611
612/* Initializes the extension driver of a wiimote */
613int wiiext_init(struct wiimote_data *wdata)
614{
615 struct wiimote_ext *ext;
616 unsigned long flags;
617 int ret, i;
618
619 ext = kzalloc(sizeof(*ext), GFP_KERNEL);
620 if (!ext)
621 return -ENOMEM;
622
623 ext->wdata = wdata;
624 INIT_WORK(&ext->worker, wiiext_worker);
625
626 ext->input = input_allocate_device();
627 if (!ext->input) {
628 ret = -ENOMEM;
629 goto err_input;
630 }
631
632 input_set_drvdata(ext->input, ext);
633 ext->input->open = wiiext_input_open;
634 ext->input->close = wiiext_input_close;
635 ext->input->dev.parent = &wdata->hdev->dev;
636 ext->input->id.bustype = wdata->hdev->bus;
637 ext->input->id.vendor = wdata->hdev->vendor;
638 ext->input->id.product = wdata->hdev->product;
639 ext->input->id.version = wdata->hdev->version;
640 ext->input->name = WIIMOTE_NAME " Extension";
641
642 set_bit(EV_KEY, ext->input->evbit);
643 for (i = 0; i < WIIEXT_KEY_COUNT; ++i)
644 set_bit(wiiext_keymap[i], ext->input->keybit);
645
646 set_bit(EV_ABS, ext->input->evbit);
647 set_bit(ABS_HAT0X, ext->input->absbit);
648 set_bit(ABS_HAT0Y, ext->input->absbit);
649 set_bit(ABS_HAT1X, ext->input->absbit);
650 set_bit(ABS_HAT1Y, ext->input->absbit);
651 set_bit(ABS_HAT2X, ext->input->absbit);
652 set_bit(ABS_HAT2Y, ext->input->absbit);
653 set_bit(ABS_HAT3X, ext->input->absbit);
654 set_bit(ABS_HAT3Y, ext->input->absbit);
655 input_set_abs_params(ext->input, ABS_HAT0X, -120, 120, 2, 4);
656 input_set_abs_params(ext->input, ABS_HAT0Y, -120, 120, 2, 4);
657 input_set_abs_params(ext->input, ABS_HAT1X, -30, 30, 1, 1);
658 input_set_abs_params(ext->input, ABS_HAT1Y, -30, 30, 1, 1);
659 input_set_abs_params(ext->input, ABS_HAT2X, -30, 30, 1, 1);
660 input_set_abs_params(ext->input, ABS_HAT2Y, -30, 30, 1, 1);
661 input_set_abs_params(ext->input, ABS_HAT3X, -30, 30, 1, 1);
662 input_set_abs_params(ext->input, ABS_HAT3Y, -30, 30, 1, 1);
663 set_bit(ABS_RX, ext->input->absbit);
664 set_bit(ABS_RY, ext->input->absbit);
665 set_bit(ABS_RZ, ext->input->absbit);
666 input_set_abs_params(ext->input, ABS_RX, -500, 500, 2, 4);
667 input_set_abs_params(ext->input, ABS_RY, -500, 500, 2, 4);
668 input_set_abs_params(ext->input, ABS_RZ, -500, 500, 2, 4);
669
670 ret = input_register_device(ext->input);
671 if (ret) {
672 input_free_device(ext->input);
673 goto err_input;
674 }
675
676 ext->mp_input = input_allocate_device();
677 if (!ext->mp_input) {
678 ret = -ENOMEM;
679 goto err_mp;
680 }
681
682 input_set_drvdata(ext->mp_input, ext);
683 ext->mp_input->open = wiiext_mp_open;
684 ext->mp_input->close = wiiext_mp_close;
685 ext->mp_input->dev.parent = &wdata->hdev->dev;
686 ext->mp_input->id.bustype = wdata->hdev->bus;
687 ext->mp_input->id.vendor = wdata->hdev->vendor;
688 ext->mp_input->id.product = wdata->hdev->product;
689 ext->mp_input->id.version = wdata->hdev->version;
690 ext->mp_input->name = WIIMOTE_NAME " Motion+";
691
692 set_bit(EV_ABS, ext->mp_input->evbit);
693 set_bit(ABS_RX, ext->mp_input->absbit);
694 set_bit(ABS_RY, ext->mp_input->absbit);
695 set_bit(ABS_RZ, ext->mp_input->absbit);
696 input_set_abs_params(ext->mp_input, ABS_RX, -160000, 160000, 4, 8);
697 input_set_abs_params(ext->mp_input, ABS_RY, -160000, 160000, 4, 8);
698 input_set_abs_params(ext->mp_input, ABS_RZ, -160000, 160000, 4, 8);
699
700 ret = input_register_device(ext->mp_input);
701 if (ret) {
702 input_free_device(ext->mp_input);
703 goto err_mp;
704 }
705
706 ret = device_create_file(&wdata->hdev->dev, &dev_attr_extension);
707 if (ret)
708 goto err_dev;
709
710 spin_lock_irqsave(&wdata->state.lock, flags);
711 wdata->ext = ext;
712 spin_unlock_irqrestore(&wdata->state.lock, flags);
713
714 return 0;
715
716err_dev:
717 input_unregister_device(ext->mp_input);
718err_mp:
719 input_unregister_device(ext->input);
720err_input:
721 kfree(ext);
722 return ret;
723}
724
725/* Deinitializes the extension driver of a wiimote */
726void wiiext_deinit(struct wiimote_data *wdata)
727{
728 struct wiimote_ext *ext = wdata->ext;
729 unsigned long flags;
730
731 if (!ext)
732 return;
733
734 /*
735 * We first unset wdata->ext to avoid further input from the wiimote
736 * core. The worker thread does not access this pointer so it is not
737 * affected by this.
738 * We kill the worker after this so it does not get respawned during
739 * deinitialization.
740 */
741
742 spin_lock_irqsave(&wdata->state.lock, flags);
743 wdata->ext = NULL;
744 spin_unlock_irqrestore(&wdata->state.lock, flags);
745
746 device_remove_file(&wdata->hdev->dev, &dev_attr_extension);
747 input_unregister_device(ext->mp_input);
748 input_unregister_device(ext->input);
749
750 cancel_work_sync(&ext->worker);
751 kfree(ext);
752}
diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h
new file mode 100644
index 00000000000..c81dbeb086c
--- /dev/null
+++ b/drivers/hid/hid-wiimote.h
@@ -0,0 +1,208 @@
1#ifndef __HID_WIIMOTE_H
2#define __HID_WIIMOTE_H
3
4/*
5 * HID driver for Nintendo Wiimote devices
6 * Copyright (c) 2011 David Herrmann
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16#include <linux/completion.h>
17#include <linux/device.h>
18#include <linux/hid.h>
19#include <linux/input.h>
20#include <linux/leds.h>
21#include <linux/module.h>
22#include <linux/mutex.h>
23#include <linux/power_supply.h>
24#include <linux/spinlock.h>
25
26#define WIIMOTE_NAME "Nintendo Wii Remote"
27#define WIIMOTE_BUFSIZE 32
28
29#define WIIPROTO_FLAG_LED1 0x01
30#define WIIPROTO_FLAG_LED2 0x02
31#define WIIPROTO_FLAG_LED3 0x04
32#define WIIPROTO_FLAG_LED4 0x08
33#define WIIPROTO_FLAG_RUMBLE 0x10
34#define WIIPROTO_FLAG_ACCEL 0x20
35#define WIIPROTO_FLAG_IR_BASIC 0x40
36#define WIIPROTO_FLAG_IR_EXT 0x80
37#define WIIPROTO_FLAG_IR_FULL 0xc0 /* IR_BASIC | IR_EXT */
38#define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \
39 WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4)
40#define WIIPROTO_FLAGS_IR (WIIPROTO_FLAG_IR_BASIC | WIIPROTO_FLAG_IR_EXT | \
41 WIIPROTO_FLAG_IR_FULL)
42
43/* return flag for led \num */
44#define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1))
45
46struct wiimote_buf {
47 __u8 data[HID_MAX_BUFFER_SIZE];
48 size_t size;
49};
50
51struct wiimote_state {
52 spinlock_t lock;
53 __u8 flags;
54 __u8 accel_split[2];
55 __u8 drm;
56
57 /* synchronous cmd requests */
58 struct mutex sync;
59 struct completion ready;
60 int cmd;
61 __u32 opt;
62
63 /* results of synchronous requests */
64 __u8 cmd_battery;
65 __u8 cmd_err;
66 __u8 *cmd_read_buf;
67 __u8 cmd_read_size;
68};
69
70struct wiimote_data {
71 struct hid_device *hdev;
72 struct input_dev *input;
73 struct led_classdev *leds[4];
74 struct input_dev *accel;
75 struct input_dev *ir;
76 struct power_supply battery;
77 struct wiimote_ext *ext;
78 struct wiimote_debug *debug;
79
80 spinlock_t qlock;
81 __u8 head;
82 __u8 tail;
83 struct wiimote_buf outq[WIIMOTE_BUFSIZE];
84 struct work_struct worker;
85
86 struct wiimote_state state;
87};
88
89enum wiiproto_reqs {
90 WIIPROTO_REQ_NULL = 0x0,
91 WIIPROTO_REQ_RUMBLE = 0x10,
92 WIIPROTO_REQ_LED = 0x11,
93 WIIPROTO_REQ_DRM = 0x12,
94 WIIPROTO_REQ_IR1 = 0x13,
95 WIIPROTO_REQ_SREQ = 0x15,
96 WIIPROTO_REQ_WMEM = 0x16,
97 WIIPROTO_REQ_RMEM = 0x17,
98 WIIPROTO_REQ_IR2 = 0x1a,
99 WIIPROTO_REQ_STATUS = 0x20,
100 WIIPROTO_REQ_DATA = 0x21,
101 WIIPROTO_REQ_RETURN = 0x22,
102 WIIPROTO_REQ_DRM_K = 0x30,
103 WIIPROTO_REQ_DRM_KA = 0x31,
104 WIIPROTO_REQ_DRM_KE = 0x32,
105 WIIPROTO_REQ_DRM_KAI = 0x33,
106 WIIPROTO_REQ_DRM_KEE = 0x34,
107 WIIPROTO_REQ_DRM_KAE = 0x35,
108 WIIPROTO_REQ_DRM_KIE = 0x36,
109 WIIPROTO_REQ_DRM_KAIE = 0x37,
110 WIIPROTO_REQ_DRM_E = 0x3d,
111 WIIPROTO_REQ_DRM_SKAI1 = 0x3e,
112 WIIPROTO_REQ_DRM_SKAI2 = 0x3f,
113 WIIPROTO_REQ_MAX
114};
115
116#define dev_to_wii(pdev) hid_get_drvdata(container_of(pdev, struct hid_device, \
117 dev))
118
119extern void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm);
120extern int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset,
121 const __u8 *wmem, __u8 size);
122extern ssize_t wiimote_cmd_read(struct wiimote_data *wdata, __u32 offset,
123 __u8 *rmem, __u8 size);
124
125#define wiiproto_req_rreg(wdata, os, sz) \
126 wiiproto_req_rmem((wdata), false, (os), (sz))
127#define wiiproto_req_reeprom(wdata, os, sz) \
128 wiiproto_req_rmem((wdata), true, (os), (sz))
129extern void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom,
130 __u32 offset, __u16 size);
131
132#ifdef CONFIG_HID_WIIMOTE_EXT
133
134extern int wiiext_init(struct wiimote_data *wdata);
135extern void wiiext_deinit(struct wiimote_data *wdata);
136extern void wiiext_event(struct wiimote_data *wdata, bool plugged);
137extern bool wiiext_active(struct wiimote_data *wdata);
138extern void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload);
139
140#else
141
142static inline int wiiext_init(void *u) { return 0; }
143static inline void wiiext_deinit(void *u) { }
144static inline void wiiext_event(void *u, bool p) { }
145static inline bool wiiext_active(void *u) { return false; }
146static inline void wiiext_handle(void *u, const __u8 *p) { }
147
148#endif
149
150#ifdef CONFIG_DEBUG_FS
151
152extern int wiidebug_init(struct wiimote_data *wdata);
153extern void wiidebug_deinit(struct wiimote_data *wdata);
154
155#else
156
157static inline int wiidebug_init(void *u) { return 0; }
158static inline void wiidebug_deinit(void *u) { }
159
160#endif
161
162/* requires the state.lock spinlock to be held */
163static inline bool wiimote_cmd_pending(struct wiimote_data *wdata, int cmd,
164 __u32 opt)
165{
166 return wdata->state.cmd == cmd && wdata->state.opt == opt;
167}
168
169/* requires the state.lock spinlock to be held */
170static inline void wiimote_cmd_complete(struct wiimote_data *wdata)
171{
172 wdata->state.cmd = WIIPROTO_REQ_NULL;
173 complete(&wdata->state.ready);
174}
175
176static inline int wiimote_cmd_acquire(struct wiimote_data *wdata)
177{
178 return mutex_lock_interruptible(&wdata->state.sync) ? -ERESTARTSYS : 0;
179}
180
181/* requires the state.lock spinlock to be held */
182static inline void wiimote_cmd_set(struct wiimote_data *wdata, int cmd,
183 __u32 opt)
184{
185 INIT_COMPLETION(wdata->state.ready);
186 wdata->state.cmd = cmd;
187 wdata->state.opt = opt;
188}
189
190static inline void wiimote_cmd_release(struct wiimote_data *wdata)
191{
192 mutex_unlock(&wdata->state.sync);
193}
194
195static inline int wiimote_cmd_wait(struct wiimote_data *wdata)
196{
197 int ret;
198
199 ret = wait_for_completion_interruptible_timeout(&wdata->state.ready, HZ);
200 if (ret < 0)
201 return -ERESTARTSYS;
202 else if (ret == 0)
203 return -EIO;
204 else
205 return 0;
206}
207
208#endif
diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
index f31fab012f2..f6ba81df71b 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 4ea464151c3..c831af93748 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"
@@ -46,6 +47,7 @@ static const struct hid_blacklist {
46 47
47 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL }, 48 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL },
48 49
50 { USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II, HID_QUIRK_MULTI_INPUT },
49 { USB_VENDOR_ID_ETURBOTOUCH, USB_DEVICE_ID_ETURBOTOUCH, HID_QUIRK_MULTI_INPUT }, 51 { USB_VENDOR_ID_ETURBOTOUCH, USB_DEVICE_ID_ETURBOTOUCH, HID_QUIRK_MULTI_INPUT },
50 { USB_VENDOR_ID_GREENASIA, USB_DEVICE_ID_GREENASIA_DUAL_USB_JOYPAD, HID_QUIRK_MULTI_INPUT }, 52 { USB_VENDOR_ID_GREENASIA, USB_DEVICE_ID_GREENASIA_DUAL_USB_JOYPAD, HID_QUIRK_MULTI_INPUT },
51 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, 53 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
@@ -66,6 +68,9 @@ static const struct hid_blacklist {
66 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_AXIS_295, HID_QUIRK_NOGET }, 68 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_AXIS_295, HID_QUIRK_NOGET },
67 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, 69 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
68 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 70 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
71 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS },
72 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS },
73 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2, HID_QUIRK_NO_INIT_REPORTS },
69 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET }, 74 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET },
70 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NOGET }, 75 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NOGET },
71 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 76 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9b347acf155..91be41f6080 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -315,7 +315,7 @@ config SENSORS_DS1621
315 315
316config SENSORS_EXYNOS4_TMU 316config SENSORS_EXYNOS4_TMU
317 tristate "Temperature sensor on Samsung EXYNOS4" 317 tristate "Temperature sensor on Samsung EXYNOS4"
318 depends on EXYNOS4_DEV_TMU 318 depends on ARCH_EXYNOS4
319 help 319 help
320 If you say yes here you get support for TMU (Thermal Managment 320 If you say yes here you get support for TMU (Thermal Managment
321 Unit) on SAMSUNG EXYNOS4 series of SoC. 321 Unit) on SAMSUNG EXYNOS4 series of SoC.
@@ -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/ad7314.c b/drivers/hwmon/ad7314.c
index 318e38e8537..5d760f3d21c 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -160,7 +160,6 @@ MODULE_DEVICE_TABLE(spi, ad7314_id);
160static struct spi_driver ad7314_driver = { 160static struct spi_driver ad7314_driver = {
161 .driver = { 161 .driver = {
162 .name = "ad7314", 162 .name = "ad7314",
163 .bus = &spi_bus_type,
164 .owner = THIS_MODULE, 163 .owner = THIS_MODULE,
165 }, 164 },
166 .probe = ad7314_probe, 165 .probe = ad7314_probe,
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index d46c0c758dd..df29a7fff9e 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 ffc781fec18..8cb718ce823 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 e9beeda4cbe..eedca3cf996 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 c42c5a69a66..cfcc3b6fb6b 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/ads7871.c b/drivers/hwmon/ads7871.c
index 52319340e18..04450f8bf5d 100644
--- a/drivers/hwmon/ads7871.c
+++ b/drivers/hwmon/ads7871.c
@@ -227,7 +227,6 @@ static int __devexit ads7871_remove(struct spi_device *spi)
227static struct spi_driver ads7871_driver = { 227static struct spi_driver ads7871_driver = {
228 .driver = { 228 .driver = {
229 .name = DEVICE_NAME, 229 .name = DEVICE_NAME,
230 .bus = &spi_bus_type,
231 .owner = THIS_MODULE, 230 .owner = THIS_MODULE,
232 }, 231 },
233 232
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index c02a052d308..d7bd1f3f2a3 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 ce18c046f72..104b3767516 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 e11363467a8..ef1ac996752 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 4f7c3fc40a8..225ae4f3658 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/exynos4_tmu.c b/drivers/hwmon/exynos4_tmu.c
index faa0884f61f..f2359a0093b 100644
--- a/drivers/hwmon/exynos4_tmu.c
+++ b/drivers/hwmon/exynos4_tmu.c
@@ -506,17 +506,7 @@ static struct platform_driver exynos4_tmu_driver = {
506 .resume = exynos4_tmu_resume, 506 .resume = exynos4_tmu_resume,
507}; 507};
508 508
509static int __init exynos4_tmu_driver_init(void) 509module_platform_driver(exynos4_tmu_driver);
510{
511 return platform_driver_register(&exynos4_tmu_driver);
512}
513module_init(exynos4_tmu_driver_init);
514
515static void __exit exynos4_tmu_driver_exit(void)
516{
517 platform_driver_unregister(&exynos4_tmu_driver);
518}
519module_exit(exynos4_tmu_driver_exit);
520 510
521MODULE_DESCRIPTION("EXYNOS4 TMU Driver"); 511MODULE_DESCRIPTION("EXYNOS4 TMU Driver");
522MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 512MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index e7ae5743e18..a13e2da97e3 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 131ea8625f0..cd6085bbfba 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/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 89aa9fb743a..9ba38f318ff 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -539,18 +539,7 @@ static struct platform_driver gpio_fan_driver = {
539 }, 539 },
540}; 540};
541 541
542static int __init gpio_fan_init(void) 542module_platform_driver(gpio_fan_driver);
543{
544 return platform_driver_register(&gpio_fan_driver);
545}
546
547static void __exit gpio_fan_exit(void)
548{
549 platform_driver_unregister(&gpio_fan_driver);
550}
551
552module_init(gpio_fan_init);
553module_exit(gpio_fan_exit);
554 543
555MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>"); 544MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>");
556MODULE_DESCRIPTION("GPIO FAN driver"); 545MODULE_DESCRIPTION("GPIO FAN driver");
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index 783d0c17b76..6a967d7dbde 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 02cebb74e20..2d3d72805ff 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/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
index fea292d4340..7a48b1eb423 100644
--- a/drivers/hwmon/jz4740-hwmon.c
+++ b/drivers/hwmon/jz4740-hwmon.c
@@ -212,17 +212,7 @@ struct platform_driver jz4740_hwmon_driver = {
212 }, 212 },
213}; 213};
214 214
215static int __init jz4740_hwmon_init(void) 215module_platform_driver(jz4740_hwmon_driver);
216{
217 return platform_driver_register(&jz4740_hwmon_driver);
218}
219module_init(jz4740_hwmon_init);
220
221static void __exit jz4740_hwmon_exit(void)
222{
223 platform_driver_unregister(&jz4740_hwmon_driver);
224}
225module_exit(jz4740_hwmon_exit);
226 216
227MODULE_DESCRIPTION("JZ4740 SoC HWMON driver"); 217MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
228MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 218MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
index 29b9030d42c..9e64d96620d 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 90126a2a1e4..1888dd0fc05 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 b28a297be50..8dfc6782d59 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 90ddb877421..615bc4f4e53 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 7c31e6205f8..8fcbd4d422c 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 dd2d7b9620c..385886a4f22 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 d5226c9e120..ef65ab56b09 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/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index eab11615dce..9b382ec2c3b 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -432,19 +432,7 @@ static struct platform_driver ntc_thermistor_driver = {
432 .id_table = ntc_thermistor_id, 432 .id_table = ntc_thermistor_id,
433}; 433};
434 434
435static int __init ntc_thermistor_init(void) 435module_platform_driver(ntc_thermistor_driver);
436{
437 return platform_driver_register(&ntc_thermistor_driver);
438}
439
440module_init(ntc_thermistor_init);
441
442static void __exit ntc_thermistor_cleanup(void)
443{
444 platform_driver_unregister(&ntc_thermistor_driver);
445}
446
447module_exit(ntc_thermistor_cleanup);
448 436
449MODULE_DESCRIPTION("NTC Thermistor Driver"); 437MODULE_DESCRIPTION("NTC Thermistor Driver");
450MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); 438MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
diff --git a/drivers/hwmon/s3c-hwmon.c b/drivers/hwmon/s3c-hwmon.c
index b39f52e2752..f6c26d19f52 100644
--- a/drivers/hwmon/s3c-hwmon.c
+++ b/drivers/hwmon/s3c-hwmon.c
@@ -393,18 +393,7 @@ static struct platform_driver s3c_hwmon_driver = {
393 .remove = __devexit_p(s3c_hwmon_remove), 393 .remove = __devexit_p(s3c_hwmon_remove),
394}; 394};
395 395
396static int __init s3c_hwmon_init(void) 396module_platform_driver(s3c_hwmon_driver);
397{
398 return platform_driver_register(&s3c_hwmon_driver);
399}
400
401static void __exit s3c_hwmon_exit(void)
402{
403 platform_driver_unregister(&s3c_hwmon_driver);
404}
405
406module_init(s3c_hwmon_init);
407module_exit(s3c_hwmon_exit);
408 397
409MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 398MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
410MODULE_DESCRIPTION("S3C ADC HWMon driver"); 399MODULE_DESCRIPTION("S3C ADC HWMon driver");
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
index e3b5c6039c2..79b6dabe316 100644
--- a/drivers/hwmon/sch5627.c
+++ b/drivers/hwmon/sch5627.c
@@ -590,19 +590,8 @@ static struct platform_driver sch5627_driver = {
590 .remove = sch5627_remove, 590 .remove = sch5627_remove,
591}; 591};
592 592
593static int __init sch5627_init(void) 593module_platform_driver(sch5627_driver);
594{
595 return platform_driver_register(&sch5627_driver);
596}
597
598static void __exit sch5627_exit(void)
599{
600 platform_driver_unregister(&sch5627_driver);
601}
602 594
603MODULE_DESCRIPTION("SMSC SCH5627 Hardware Monitoring Driver"); 595MODULE_DESCRIPTION("SMSC SCH5627 Hardware Monitoring Driver");
604MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 596MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
605MODULE_LICENSE("GPL"); 597MODULE_LICENSE("GPL");
606
607module_init(sch5627_init);
608module_exit(sch5627_exit);
diff --git a/drivers/hwmon/sch5636.c b/drivers/hwmon/sch5636.c
index 244407aa79f..9d5236fb09b 100644
--- a/drivers/hwmon/sch5636.c
+++ b/drivers/hwmon/sch5636.c
@@ -521,19 +521,8 @@ static struct platform_driver sch5636_driver = {
521 .remove = sch5636_remove, 521 .remove = sch5636_remove,
522}; 522};
523 523
524static int __init sch5636_init(void) 524module_platform_driver(sch5636_driver);
525{
526 return platform_driver_register(&sch5636_driver);
527}
528
529static void __exit sch5636_exit(void)
530{
531 platform_driver_unregister(&sch5636_driver);
532}
533 525
534MODULE_DESCRIPTION("SMSC SCH5636 Hardware Monitoring Driver"); 526MODULE_DESCRIPTION("SMSC SCH5636 Hardware Monitoring Driver");
535MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 527MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
536MODULE_LICENSE("GPL"); 528MODULE_LICENSE("GPL");
537
538module_init(sch5636_init);
539module_exit(sch5636_exit);
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 1c8c9812f24..15398780cc0 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 425df5bccd4..411638181fd 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 9fb7516e6f4..65c88ff5645 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 5bd19496880..643aa8c9453 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/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c
index 57240740b16..0018c7dd009 100644
--- a/drivers/hwmon/twl4030-madc-hwmon.c
+++ b/drivers/hwmon/twl4030-madc-hwmon.c
@@ -136,19 +136,7 @@ static struct platform_driver twl4030_madc_hwmon_driver = {
136 }, 136 },
137}; 137};
138 138
139static int __init twl4030_madc_hwmon_init(void) 139module_platform_driver(twl4030_madc_hwmon_driver);
140{
141 return platform_driver_register(&twl4030_madc_hwmon_driver);
142}
143
144module_init(twl4030_madc_hwmon_init);
145
146static void __exit twl4030_madc_hwmon_exit(void)
147{
148 platform_driver_unregister(&twl4030_madc_hwmon_driver);
149}
150
151module_exit(twl4030_madc_hwmon_exit);
152 140
153MODULE_DESCRIPTION("TWL4030 ADC Hwmon driver"); 141MODULE_DESCRIPTION("TWL4030 ADC Hwmon driver");
154MODULE_LICENSE("GPL"); 142MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index 27a62711e0a..b9a87e89bab 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>
@@ -308,15 +309,4 @@ static struct platform_driver env_driver = {
308 .remove = __devexit_p(env_remove), 309 .remove = __devexit_p(env_remove),
309}; 310};
310 311
311static int __init env_init(void) 312module_platform_driver(env_driver);
312{
313 return platform_driver_register(&env_driver);
314}
315
316static void __exit env_exit(void)
317{
318 platform_driver_unregister(&env_driver);
319}
320
321module_init(env_init);
322module_exit(env_exit);
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 98aab4bea34..93f5fc7d605 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 eed43a008be..65b685e2c7b 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/hwmon/wm831x-hwmon.c b/drivers/hwmon/wm831x-hwmon.c
index 97b1f834a47..9b598ed2602 100644
--- a/drivers/hwmon/wm831x-hwmon.c
+++ b/drivers/hwmon/wm831x-hwmon.c
@@ -209,17 +209,7 @@ static struct platform_driver wm831x_hwmon_driver = {
209 }, 209 },
210}; 210};
211 211
212static int __init wm831x_hwmon_init(void) 212module_platform_driver(wm831x_hwmon_driver);
213{
214 return platform_driver_register(&wm831x_hwmon_driver);
215}
216module_init(wm831x_hwmon_init);
217
218static void __exit wm831x_hwmon_exit(void)
219{
220 platform_driver_unregister(&wm831x_hwmon_driver);
221}
222module_exit(wm831x_hwmon_exit);
223 213
224MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 214MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
225MODULE_DESCRIPTION("WM831x Hardware Monitoring"); 215MODULE_DESCRIPTION("WM831x Hardware Monitoring");
diff --git a/drivers/hwmon/wm8350-hwmon.c b/drivers/hwmon/wm8350-hwmon.c
index 13290595ca8..3ff67edbdc4 100644
--- a/drivers/hwmon/wm8350-hwmon.c
+++ b/drivers/hwmon/wm8350-hwmon.c
@@ -133,17 +133,7 @@ static struct platform_driver wm8350_hwmon_driver = {
133 }, 133 },
134}; 134};
135 135
136static int __init wm8350_hwmon_init(void) 136module_platform_driver(wm8350_hwmon_driver);
137{
138 return platform_driver_register(&wm8350_hwmon_driver);
139}
140module_init(wm8350_hwmon_init);
141
142static void __exit wm8350_hwmon_exit(void)
143{
144 platform_driver_unregister(&wm8350_hwmon_driver);
145}
146module_exit(wm8350_hwmon_exit);
147 137
148MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 138MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
149MODULE_DESCRIPTION("WM8350 Hardware Monitoring"); 139MODULE_DESCRIPTION("WM8350 Hardware Monitoring");
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 1f29bab6b3e..c7c3128393d 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 5729a3f7ed3..93eb64b6648 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 43a62714b4f..61c9cf15fa5 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 69935e6b93e..d26f78b8f21 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 a8f02734c02..887d34effb3 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 00000000000..86980fe0411
--- /dev/null
+++ b/drivers/hwspinlock/u8500_hsem.c
@@ -0,0 +1,197 @@
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/module.h>
25#include <linux/delay.h>
26#include <linux/io.h>
27#include <linux/pm_runtime.h>
28#include <linux/slab.h>
29#include <linux/spinlock.h>
30#include <linux/hwspinlock.h>
31#include <linux/platform_device.h>
32
33#include "hwspinlock_internal.h"
34
35/*
36 * Implementation of STE's HSem protocol 1 without interrutps.
37 * The only masterID we allow is '0x01' to force people to use
38 * HSems for synchronisation between processors rather than processes
39 * on the ARM core.
40 */
41
42#define U8500_MAX_SEMAPHORE 32 /* a total of 32 semaphore */
43#define RESET_SEMAPHORE (0) /* free */
44
45/*
46 * CPU ID for master running u8500 kernel.
47 * Hswpinlocks should only be used to synchonise operations
48 * between the Cortex A9 core and the other CPUs. Hence
49 * forcing the masterID to a preset value.
50 */
51#define HSEM_MASTER_ID 0x01
52
53#define HSEM_REGISTER_OFFSET 0x08
54
55#define HSEM_CTRL_REG 0x00
56#define HSEM_ICRALL 0x90
57#define HSEM_PROTOCOL_1 0x01
58
59static int u8500_hsem_trylock(struct hwspinlock *lock)
60{
61 void __iomem *lock_addr = lock->priv;
62
63 writel(HSEM_MASTER_ID, lock_addr);
64
65 /* get only first 4 bit and compare to masterID.
66 * if equal, we have the semaphore, otherwise
67 * someone else has it.
68 */
69 return (HSEM_MASTER_ID == (0x0F & readl(lock_addr)));
70}
71
72static void u8500_hsem_unlock(struct hwspinlock *lock)
73{
74 void __iomem *lock_addr = lock->priv;
75
76 /* release the lock by writing 0 to it */
77 writel(RESET_SEMAPHORE, lock_addr);
78}
79
80/*
81 * u8500: what value is recommended here ?
82 */
83static void u8500_hsem_relax(struct hwspinlock *lock)
84{
85 ndelay(50);
86}
87
88static const struct hwspinlock_ops u8500_hwspinlock_ops = {
89 .trylock = u8500_hsem_trylock,
90 .unlock = u8500_hsem_unlock,
91 .relax = u8500_hsem_relax,
92};
93
94static int __devinit u8500_hsem_probe(struct platform_device *pdev)
95{
96 struct hwspinlock_pdata *pdata = pdev->dev.platform_data;
97 struct hwspinlock_device *bank;
98 struct hwspinlock *hwlock;
99 struct resource *res;
100 void __iomem *io_base;
101 int i, ret, num_locks = U8500_MAX_SEMAPHORE;
102 ulong val;
103
104 if (!pdata)
105 return -ENODEV;
106
107 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
108 if (!res)
109 return -ENODEV;
110
111 io_base = ioremap(res->start, resource_size(res));
112 if (!io_base)
113 return -ENOMEM;
114
115 /* make sure protocol 1 is selected */
116 val = readl(io_base + HSEM_CTRL_REG);
117 writel((val & ~HSEM_PROTOCOL_1), io_base + HSEM_CTRL_REG);
118
119 /* clear all interrupts */
120 writel(0xFFFF, io_base + HSEM_ICRALL);
121
122 bank = kzalloc(sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
123 if (!bank) {
124 ret = -ENOMEM;
125 goto iounmap_base;
126 }
127
128 platform_set_drvdata(pdev, bank);
129
130 for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
131 hwlock->priv = io_base + HSEM_REGISTER_OFFSET + sizeof(u32) * i;
132
133 /* no pm needed for HSem but required to comply with hwspilock core */
134 pm_runtime_enable(&pdev->dev);
135
136 ret = hwspin_lock_register(bank, &pdev->dev, &u8500_hwspinlock_ops,
137 pdata->base_id, num_locks);
138 if (ret)
139 goto reg_fail;
140
141 return 0;
142
143reg_fail:
144 pm_runtime_disable(&pdev->dev);
145 kfree(bank);
146iounmap_base:
147 iounmap(io_base);
148 return ret;
149}
150
151static int __devexit u8500_hsem_remove(struct platform_device *pdev)
152{
153 struct hwspinlock_device *bank = platform_get_drvdata(pdev);
154 void __iomem *io_base = bank->lock[0].priv - HSEM_REGISTER_OFFSET;
155 int ret;
156
157 /* clear all interrupts */
158 writel(0xFFFF, io_base + HSEM_ICRALL);
159
160 ret = hwspin_lock_unregister(bank);
161 if (ret) {
162 dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
163 return ret;
164 }
165
166 pm_runtime_disable(&pdev->dev);
167 iounmap(io_base);
168 kfree(bank);
169
170 return 0;
171}
172
173static struct platform_driver u8500_hsem_driver = {
174 .probe = u8500_hsem_probe,
175 .remove = __devexit_p(u8500_hsem_remove),
176 .driver = {
177 .name = "u8500_hsem",
178 .owner = THIS_MODULE,
179 },
180};
181
182static int __init u8500_hsem_init(void)
183{
184 return platform_driver_register(&u8500_hsem_driver);
185}
186/* board init code might need to reserve hwspinlocks for predefined purposes */
187postcore_initcall(u8500_hsem_init);
188
189static void __exit u8500_hsem_exit(void)
190{
191 platform_driver_unregister(&u8500_hsem_driver);
192}
193module_exit(u8500_hsem_exit);
194
195MODULE_LICENSE("GPL v2");
196MODULE_DESCRIPTION("Hardware Spinlock driver for u8500");
197MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 85584a547c2..525c7345fa0 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -488,7 +488,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
488 488
489 if (flags & I2C_M_TEN) { 489 if (flags & I2C_M_TEN) {
490 /* a ten bit address */ 490 /* a ten bit address */
491 addr = 0xf0 | ((msg->addr >> 7) & 0x03); 491 addr = 0xf0 | ((msg->addr >> 7) & 0x06);
492 bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); 492 bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr);
493 /* try extended address code...*/ 493 /* try extended address code...*/
494 ret = try_address(i2c_adap, addr, retries); 494 ret = try_address(i2c_adap, addr, retries);
@@ -498,7 +498,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
498 return -ENXIO; 498 return -ENXIO;
499 } 499 }
500 /* the remaining 8 bit address */ 500 /* the remaining 8 bit address */
501 ret = i2c_outb(i2c_adap, msg->addr & 0x7f); 501 ret = i2c_outb(i2c_adap, msg->addr & 0xff);
502 if ((ret != 1) && !nak_ok) { 502 if ((ret != 1) && !nak_ok) {
503 /* the chip did not ack / xmission error occurred */ 503 /* the chip did not ack / xmission error occurred */
504 dev_err(&i2c_adap->dev, "died at 2nd address code\n"); 504 dev_err(&i2c_adap->dev, "died at 2nd address code\n");
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index b2b85629d07..a3afac4be73 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 4f757a2da8c..f314d7f433d 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-nuc900.c b/drivers/i2c/busses/i2c-nuc900.c
index 835e47b39bc..03b61577888 100644
--- a/drivers/i2c/busses/i2c-nuc900.c
+++ b/drivers/i2c/busses/i2c-nuc900.c
@@ -593,7 +593,7 @@ static int __devinit nuc900_i2c_probe(struct platform_device *pdev)
593 i2c->adap.algo_data = i2c; 593 i2c->adap.algo_data = i2c;
594 i2c->adap.dev.parent = &pdev->dev; 594 i2c->adap.dev.parent = &pdev->dev;
595 595
596 mfp_set_groupg(&pdev->dev); 596 mfp_set_groupg(&pdev->dev, NULL);
597 597
598 clk_get_rate(i2c->clk); 598 clk_get_rate(i2c->clk);
599 599
diff --git a/drivers/i2c/busses/i2c-pxa-pci.c b/drivers/i2c/busses/i2c-pxa-pci.c
index b73da6cd6f9..632e088760a 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 c418c41eff3..a67132b2e09 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 b0505309faa..46b6500c547 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 3ca2e012e78..10274ffb66d 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/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 131079a3e29..1e5606185b4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -539,8 +539,10 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
539 client->dev.type = &i2c_client_type; 539 client->dev.type = &i2c_client_type;
540 client->dev.of_node = info->of_node; 540 client->dev.of_node = info->of_node;
541 541
542 /* For 10-bit clients, add an arbitrary offset to avoid collisions */
542 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), 543 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
543 client->addr); 544 client->addr | ((client->flags & I2C_CLIENT_TEN)
545 ? 0xa000 : 0));
544 status = device_register(&client->dev); 546 status = device_register(&client->dev);
545 if (status) 547 if (status)
546 goto out_err; 548 goto out_err;
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index c90ce50b619..57a45ce84b2 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -579,7 +579,7 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
579 return 0; 579 return 0;
580} 580}
581 581
582int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action, 582static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action,
583 void *data) 583 void *data)
584{ 584{
585 struct device *dev = data; 585 struct device *dev = data;
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 76b6d98bd29..5a26584934c 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 b26c23416fa..259786ca8b7 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 ab4f169d083..b1d38590ac0 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 cb10201a15e..a81bd757579 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/cy82c693.c b/drivers/ide/cy82c693.c
index 67cbcfa3512..847553fd8b9 100644
--- a/drivers/ide/cy82c693.c
+++ b/drivers/ide/cy82c693.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer 2 * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer
3 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator 3 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator
4 * Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz 4 * Copyright (C) 2007-2011 Bartlomiej Zolnierkiewicz
5 * 5 *
6 * CYPRESS CY82C693 chipset IDE controller 6 * CYPRESS CY82C693 chipset IDE controller
7 * 7 *
@@ -90,7 +90,7 @@ static void cy82c693_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
90 u8 time_16, time_8; 90 u8 time_16, time_8;
91 91
92 /* select primary or secondary channel */ 92 /* select primary or secondary channel */
93 if (hwif->index > 0) { /* drive is on the secondary channel */ 93 if (drive->dn > 1) { /* drive is on the secondary channel */
94 dev = pci_get_slot(dev->bus, dev->devfn+1); 94 dev = pci_get_slot(dev->bus, dev->devfn+1);
95 if (!dev) { 95 if (!dev) {
96 printk(KERN_ERR "%s: tune_drive: " 96 printk(KERN_ERR "%s: tune_drive: "
@@ -141,7 +141,7 @@ static void cy82c693_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
141 pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, time_16); 141 pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, time_16);
142 pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, time_8); 142 pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, time_8);
143 } 143 }
144 if (hwif->index > 0) 144 if (drive->dn > 1)
145 pci_dev_put(dev); 145 pci_dev_put(dev);
146} 146}
147 147
diff --git a/drivers/ide/icside.c b/drivers/ide/icside.c
index 4a697a238e2..8716066a2f2 100644
--- a/drivers/ide/icside.c
+++ b/drivers/ide/icside.c
@@ -521,8 +521,8 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
521 if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) { 521 if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) {
522 d.init_dma = icside_dma_init; 522 d.init_dma = icside_dma_init;
523 d.port_ops = &icside_v6_port_ops; 523 d.port_ops = &icside_v6_port_ops;
524 } else
524 d.dma_ops = NULL; 525 d.dma_ops = NULL;
525 }
526 526
527 ret = ide_host_register(host, &d, hws); 527 ret = ide_host_register(host, &d, hws);
528 if (ret) 528 if (ret)
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 2af8cb460a3..f22edc66b03 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 6f218e014e9..fac3d9da2e0 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-cd.c b/drivers/ide/ide-cd.c
index 04b09564bfa..8126824dacc 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -43,7 +43,6 @@
43/* For SCSI -> ATAPI command conversion */ 43/* For SCSI -> ATAPI command conversion */
44#include <scsi/scsi.h> 44#include <scsi/scsi.h>
45 45
46#include <linux/irq.h>
47#include <linux/io.h> 46#include <linux/io.h>
48#include <asm/byteorder.h> 47#include <asm/byteorder.h>
49#include <linux/uaccess.h> 48#include <linux/uaccess.h>
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
index f9bbd904eae..8b570a17bcd 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 e4cdf78cc3e..289d16c87b8 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 d4136908f91..17a65ac5649 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 c0aa93fb7a6..32970664c27 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.c b/drivers/ide/ide-floppy.c
index 61fdf544fbd..3d42043fec5 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -35,7 +35,6 @@
35#include <scsi/scsi_ioctl.h> 35#include <scsi/scsi_ioctl.h>
36 36
37#include <asm/byteorder.h> 37#include <asm/byteorder.h>
38#include <linux/irq.h>
39#include <linux/uaccess.h> 38#include <linux/uaccess.h>
40#include <linux/io.h> 39#include <linux/io.h>
41#include <asm/unaligned.h> 40#include <asm/unaligned.h>
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
index d711d9b883d..1600720f3e8 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 46721c45451..19763977568 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 9965ecd5078..4d19eb9772a 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 b9654a7bb7b..30fe3630734 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 e386a32dc9b..d9c9829c8b2 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 017b1df3b80..e5f3db83137 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-tape.c b/drivers/ide/ide-tape.c
index 7ecb1ade887..ce8237d3615 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -41,7 +41,6 @@
41#include <scsi/scsi.h> 41#include <scsi/scsi.h>
42 42
43#include <asm/byteorder.h> 43#include <asm/byteorder.h>
44#include <linux/irq.h>
45#include <linux/uaccess.h> 44#include <linux/uaccess.h>
46#include <linux/io.h> 45#include <linux/io.h>
47#include <asm/unaligned.h> 46#include <asm/unaligned.h>
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 600c89a3d13..5bc2839ebcf 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 5fc8d5c17de..eb421883c16 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 505ec43e560..adc5fe9daaf 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/piix.c b/drivers/ide/piix.c
index b59d04c7205..1892e81fb00 100644
--- a/drivers/ide/piix.c
+++ b/drivers/ide/piix.c
@@ -331,7 +331,7 @@ static const struct ide_port_ops ich_port_ops = {
331 .udma_mask = udma, \ 331 .udma_mask = udma, \
332 } 332 }
333 333
334#define DECLARE_ICH_DEV(udma) \ 334#define DECLARE_ICH_DEV(mwdma, udma) \
335 { \ 335 { \
336 .name = DRV_NAME, \ 336 .name = DRV_NAME, \
337 .init_chipset = init_chipset_ich, \ 337 .init_chipset = init_chipset_ich, \
@@ -340,7 +340,7 @@ static const struct ide_port_ops ich_port_ops = {
340 .port_ops = &ich_port_ops, \ 340 .port_ops = &ich_port_ops, \
341 .pio_mask = ATA_PIO4, \ 341 .pio_mask = ATA_PIO4, \
342 .swdma_mask = ATA_SWDMA2_ONLY, \ 342 .swdma_mask = ATA_SWDMA2_ONLY, \
343 .mwdma_mask = ATA_MWDMA12_ONLY, \ 343 .mwdma_mask = mwdma, \
344 .udma_mask = udma, \ 344 .udma_mask = udma, \
345 } 345 }
346 346
@@ -362,13 +362,15 @@ static const struct ide_port_info piix_pci_info[] __devinitdata = {
362 /* 2: PIIX4 */ 362 /* 2: PIIX4 */
363 DECLARE_PIIX_DEV(ATA_UDMA2), 363 DECLARE_PIIX_DEV(ATA_UDMA2),
364 /* 3: ICH0 */ 364 /* 3: ICH0 */
365 DECLARE_ICH_DEV(ATA_UDMA2), 365 DECLARE_ICH_DEV(ATA_MWDMA12_ONLY, ATA_UDMA2),
366 /* 4: ICH */ 366 /* 4: ICH */
367 DECLARE_ICH_DEV(ATA_UDMA4), 367 DECLARE_ICH_DEV(ATA_MWDMA12_ONLY, ATA_UDMA4),
368 /* 5: PIIX4 */ 368 /* 5: PIIX4 */
369 DECLARE_PIIX_DEV(ATA_UDMA4), 369 DECLARE_PIIX_DEV(ATA_UDMA4),
370 /* 6: ICH[2-7]/ICH[2-3]M/C-ICH/ICH5-SATA/ESB2/ICH8M */ 370 /* 6: ICH[2-6]/ICH[2-3]M/C-ICH/ICH5-SATA/ESB2/ICH8M */
371 DECLARE_ICH_DEV(ATA_UDMA5), 371 DECLARE_ICH_DEV(ATA_MWDMA12_ONLY, ATA_UDMA5),
372 /* 7: ICH7/7-R, no MWDMA1 */
373 DECLARE_ICH_DEV(ATA_MWDMA2_ONLY, ATA_UDMA5),
372}; 374};
373 375
374/** 376/**
@@ -438,9 +440,9 @@ static const struct pci_device_id piix_pci_tbl[] = {
438#endif 440#endif
439 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB_2), 6 }, 441 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB_2), 6 },
440 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH6_19), 6 }, 442 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH6_19), 6 },
441 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH7_21), 6 }, 443 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH7_21), 7 },
442 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_1), 6 }, 444 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82801DB_1), 6 },
443 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB2_18), 6 }, 445 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ESB2_18), 7 },
444 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH8_6), 6 }, 446 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICH8_6), 6 },
445 { 0, }, 447 { 0, },
446}; 448};
diff --git a/drivers/ide/pmac.c b/drivers/ide/pmac.c
index 1db7c4368db..e944c7f705f 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 90786083b43..ecd0a69245f 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 ab3db61d2ba..34a5e5223d5 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 e444d24934b..4799d5c384e 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/ide/triflex.c b/drivers/ide/triflex.c
index e53a1b78378..281c9142634 100644
--- a/drivers/ide/triflex.c
+++ b/drivers/ide/triflex.c
@@ -113,12 +113,26 @@ static const struct pci_device_id triflex_pci_tbl[] = {
113}; 113};
114MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); 114MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
115 115
116#ifdef CONFIG_PM
117static int triflex_ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
118{
119 /*
120 * We must not disable or powerdown the device.
121 * APM bios refuses to suspend if IDE is not accessible.
122 */
123 pci_save_state(dev);
124 return 0;
125}
126#else
127#define triflex_ide_pci_suspend NULL
128#endif
129
116static struct pci_driver triflex_pci_driver = { 130static struct pci_driver triflex_pci_driver = {
117 .name = "TRIFLEX_IDE", 131 .name = "TRIFLEX_IDE",
118 .id_table = triflex_pci_tbl, 132 .id_table = triflex_pci_tbl,
119 .probe = triflex_init_one, 133 .probe = triflex_init_one,
120 .remove = ide_pci_remove, 134 .remove = ide_pci_remove,
121 .suspend = ide_pci_suspend, 135 .suspend = triflex_ide_pci_suspend,
122 .resume = ide_pci_resume, 136 .resume = ide_pci_resume,
123}; 137};
124 138
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index a46dddf6107..5d2f8e13cf0 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
@@ -81,7 +82,8 @@ static unsigned int mwait_substates;
81static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */ 82static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
82 83
83static struct cpuidle_device __percpu *intel_idle_cpuidle_devices; 84static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
84static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state); 85static int intel_idle(struct cpuidle_device *dev,
86 struct cpuidle_driver *drv, int index);
85 87
86static struct cpuidle_state *cpuidle_state_table; 88static struct cpuidle_state *cpuidle_state_table;
87 89
@@ -109,7 +111,6 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
109 { /* MWAIT C1 */ 111 { /* MWAIT C1 */
110 .name = "C1-NHM", 112 .name = "C1-NHM",
111 .desc = "MWAIT 0x00", 113 .desc = "MWAIT 0x00",
112 .driver_data = (void *) 0x00,
113 .flags = CPUIDLE_FLAG_TIME_VALID, 114 .flags = CPUIDLE_FLAG_TIME_VALID,
114 .exit_latency = 3, 115 .exit_latency = 3,
115 .target_residency = 6, 116 .target_residency = 6,
@@ -117,7 +118,6 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
117 { /* MWAIT C2 */ 118 { /* MWAIT C2 */
118 .name = "C3-NHM", 119 .name = "C3-NHM",
119 .desc = "MWAIT 0x10", 120 .desc = "MWAIT 0x10",
120 .driver_data = (void *) 0x10,
121 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 121 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
122 .exit_latency = 20, 122 .exit_latency = 20,
123 .target_residency = 80, 123 .target_residency = 80,
@@ -125,7 +125,6 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
125 { /* MWAIT C3 */ 125 { /* MWAIT C3 */
126 .name = "C6-NHM", 126 .name = "C6-NHM",
127 .desc = "MWAIT 0x20", 127 .desc = "MWAIT 0x20",
128 .driver_data = (void *) 0x20,
129 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 128 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
130 .exit_latency = 200, 129 .exit_latency = 200,
131 .target_residency = 800, 130 .target_residency = 800,
@@ -137,7 +136,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
137 { /* MWAIT C1 */ 136 { /* MWAIT C1 */
138 .name = "C1-SNB", 137 .name = "C1-SNB",
139 .desc = "MWAIT 0x00", 138 .desc = "MWAIT 0x00",
140 .driver_data = (void *) 0x00,
141 .flags = CPUIDLE_FLAG_TIME_VALID, 139 .flags = CPUIDLE_FLAG_TIME_VALID,
142 .exit_latency = 1, 140 .exit_latency = 1,
143 .target_residency = 1, 141 .target_residency = 1,
@@ -145,7 +143,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
145 { /* MWAIT C2 */ 143 { /* MWAIT C2 */
146 .name = "C3-SNB", 144 .name = "C3-SNB",
147 .desc = "MWAIT 0x10", 145 .desc = "MWAIT 0x10",
148 .driver_data = (void *) 0x10,
149 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 146 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
150 .exit_latency = 80, 147 .exit_latency = 80,
151 .target_residency = 211, 148 .target_residency = 211,
@@ -153,7 +150,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
153 { /* MWAIT C3 */ 150 { /* MWAIT C3 */
154 .name = "C6-SNB", 151 .name = "C6-SNB",
155 .desc = "MWAIT 0x20", 152 .desc = "MWAIT 0x20",
156 .driver_data = (void *) 0x20,
157 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 153 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
158 .exit_latency = 104, 154 .exit_latency = 104,
159 .target_residency = 345, 155 .target_residency = 345,
@@ -161,7 +157,6 @@ static struct cpuidle_state snb_cstates[MWAIT_MAX_NUM_CSTATES] = {
161 { /* MWAIT C4 */ 157 { /* MWAIT C4 */
162 .name = "C7-SNB", 158 .name = "C7-SNB",
163 .desc = "MWAIT 0x30", 159 .desc = "MWAIT 0x30",
164 .driver_data = (void *) 0x30,
165 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 160 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
166 .exit_latency = 109, 161 .exit_latency = 109,
167 .target_residency = 345, 162 .target_residency = 345,
@@ -173,7 +168,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
173 { /* MWAIT C1 */ 168 { /* MWAIT C1 */
174 .name = "C1-ATM", 169 .name = "C1-ATM",
175 .desc = "MWAIT 0x00", 170 .desc = "MWAIT 0x00",
176 .driver_data = (void *) 0x00,
177 .flags = CPUIDLE_FLAG_TIME_VALID, 171 .flags = CPUIDLE_FLAG_TIME_VALID,
178 .exit_latency = 1, 172 .exit_latency = 1,
179 .target_residency = 4, 173 .target_residency = 4,
@@ -181,7 +175,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
181 { /* MWAIT C2 */ 175 { /* MWAIT C2 */
182 .name = "C2-ATM", 176 .name = "C2-ATM",
183 .desc = "MWAIT 0x10", 177 .desc = "MWAIT 0x10",
184 .driver_data = (void *) 0x10,
185 .flags = CPUIDLE_FLAG_TIME_VALID, 178 .flags = CPUIDLE_FLAG_TIME_VALID,
186 .exit_latency = 20, 179 .exit_latency = 20,
187 .target_residency = 80, 180 .target_residency = 80,
@@ -190,7 +183,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
190 { /* MWAIT C4 */ 183 { /* MWAIT C4 */
191 .name = "C4-ATM", 184 .name = "C4-ATM",
192 .desc = "MWAIT 0x30", 185 .desc = "MWAIT 0x30",
193 .driver_data = (void *) 0x30,
194 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 186 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
195 .exit_latency = 100, 187 .exit_latency = 100,
196 .target_residency = 400, 188 .target_residency = 400,
@@ -199,23 +191,55 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
199 { /* MWAIT C6 */ 191 { /* MWAIT C6 */
200 .name = "C6-ATM", 192 .name = "C6-ATM",
201 .desc = "MWAIT 0x52", 193 .desc = "MWAIT 0x52",
202 .driver_data = (void *) 0x52,
203 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED, 194 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
204 .exit_latency = 140, 195 .exit_latency = 140,
205 .target_residency = 560, 196 .target_residency = 560,
206 .enter = &intel_idle }, 197 .enter = &intel_idle },
207}; 198};
208 199
200static int get_driver_data(int cstate)
201{
202 int driver_data;
203 switch (cstate) {
204
205 case 1: /* MWAIT C1 */
206 driver_data = 0x00;
207 break;
208 case 2: /* MWAIT C2 */
209 driver_data = 0x10;
210 break;
211 case 3: /* MWAIT C3 */
212 driver_data = 0x20;
213 break;
214 case 4: /* MWAIT C4 */
215 driver_data = 0x30;
216 break;
217 case 5: /* MWAIT C5 */
218 driver_data = 0x40;
219 break;
220 case 6: /* MWAIT C6 */
221 driver_data = 0x52;
222 break;
223 default:
224 driver_data = 0x00;
225 }
226 return driver_data;
227}
228
209/** 229/**
210 * intel_idle 230 * intel_idle
211 * @dev: cpuidle_device 231 * @dev: cpuidle_device
212 * @state: cpuidle state 232 * @drv: cpuidle driver
233 * @index: index of cpuidle state
213 * 234 *
214 */ 235 */
215static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state) 236static int intel_idle(struct cpuidle_device *dev,
237 struct cpuidle_driver *drv, int index)
216{ 238{
217 unsigned long ecx = 1; /* break on interrupt flag */ 239 unsigned long ecx = 1; /* break on interrupt flag */
218 unsigned long eax = (unsigned long)cpuidle_get_statedata(state); 240 struct cpuidle_state *state = &drv->states[index];
241 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
242 unsigned long eax = (unsigned long)cpuidle_get_statedata(state_usage);
219 unsigned int cstate; 243 unsigned int cstate;
220 ktime_t kt_before, kt_after; 244 ktime_t kt_before, kt_after;
221 s64 usec_delta; 245 s64 usec_delta;
@@ -256,7 +280,10 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
256 if (!(lapic_timer_reliable_states & (1 << (cstate)))) 280 if (!(lapic_timer_reliable_states & (1 << (cstate))))
257 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu); 281 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
258 282
259 return usec_delta; 283 /* Update cpuidle counters */
284 dev->last_residency = (int)usec_delta;
285
286 return index;
260} 287}
261 288
262static void __setup_broadcast_timer(void *arg) 289static void __setup_broadcast_timer(void *arg)
@@ -397,6 +424,60 @@ static void intel_idle_cpuidle_devices_uninit(void)
397 return; 424 return;
398} 425}
399/* 426/*
427 * intel_idle_cpuidle_driver_init()
428 * allocate, initialize cpuidle_states
429 */
430static int intel_idle_cpuidle_driver_init(void)
431{
432 int cstate;
433 struct cpuidle_driver *drv = &intel_idle_driver;
434
435 drv->state_count = 1;
436
437 for (cstate = 1; cstate < MWAIT_MAX_NUM_CSTATES; ++cstate) {
438 int num_substates;
439
440 if (cstate > max_cstate) {
441 printk(PREFIX "max_cstate %d reached\n",
442 max_cstate);
443 break;
444 }
445
446 /* does the state exist in CPUID.MWAIT? */
447 num_substates = (mwait_substates >> ((cstate) * 4))
448 & MWAIT_SUBSTATE_MASK;
449 if (num_substates == 0)
450 continue;
451 /* is the state not enabled? */
452 if (cpuidle_state_table[cstate].enter == NULL) {
453 /* does the driver not know about the state? */
454 if (*cpuidle_state_table[cstate].name == '\0')
455 pr_debug(PREFIX "unaware of model 0x%x"
456 " MWAIT %d please"
457 " contact lenb@kernel.org",
458 boot_cpu_data.x86_model, cstate);
459 continue;
460 }
461
462 if ((cstate > 2) &&
463 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
464 mark_tsc_unstable("TSC halts in idle"
465 " states deeper than C2");
466
467 drv->states[drv->state_count] = /* structure copy */
468 cpuidle_state_table[cstate];
469
470 drv->state_count += 1;
471 }
472
473 if (auto_demotion_disable_flags)
474 smp_call_function(auto_demotion_disable, NULL, 1);
475
476 return 0;
477}
478
479
480/*
400 * intel_idle_cpuidle_devices_init() 481 * intel_idle_cpuidle_devices_init()
401 * allocate, initialize, register cpuidle_devices 482 * allocate, initialize, register cpuidle_devices
402 */ 483 */
@@ -430,22 +511,11 @@ static int intel_idle_cpuidle_devices_init(void)
430 continue; 511 continue;
431 /* is the state not enabled? */ 512 /* is the state not enabled? */
432 if (cpuidle_state_table[cstate].enter == NULL) { 513 if (cpuidle_state_table[cstate].enter == NULL) {
433 /* does the driver not know about the state? */
434 if (*cpuidle_state_table[cstate].name == '\0')
435 pr_debug(PREFIX "unaware of model 0x%x"
436 " MWAIT %d please"
437 " contact lenb@kernel.org",
438 boot_cpu_data.x86_model, cstate);
439 continue; 514 continue;
440 } 515 }
441 516
442 if ((cstate > 2) && 517 dev->states_usage[dev->state_count].driver_data =
443 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC)) 518 (void *)get_driver_data(cstate);
444 mark_tsc_unstable("TSC halts in idle"
445 " states deeper than C2");
446
447 dev->states[dev->state_count] = /* structure copy */
448 cpuidle_state_table[cstate];
449 519
450 dev->state_count += 1; 520 dev->state_count += 1;
451 } 521 }
@@ -458,8 +528,6 @@ static int intel_idle_cpuidle_devices_init(void)
458 return -EIO; 528 return -EIO;
459 } 529 }
460 } 530 }
461 if (auto_demotion_disable_flags)
462 smp_call_function(auto_demotion_disable, NULL, 1);
463 531
464 return 0; 532 return 0;
465} 533}
@@ -477,6 +545,7 @@ static int __init intel_idle_init(void)
477 if (retval) 545 if (retval)
478 return retval; 546 return retval;
479 547
548 intel_idle_cpuidle_driver_init();
480 retval = cpuidle_register_driver(&intel_idle_driver); 549 retval = cpuidle_register_driver(&intel_idle_driver);
481 if (retval) { 550 if (retval) {
482 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s", 551 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 236ad9a89c0..e9cf51b1343 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>
@@ -215,7 +216,9 @@ static int addr4_resolve(struct sockaddr_in *src_in,
215 216
216 neigh = neigh_lookup(&arp_tbl, &rt->rt_gateway, rt->dst.dev); 217 neigh = neigh_lookup(&arp_tbl, &rt->rt_gateway, rt->dst.dev);
217 if (!neigh || !(neigh->nud_state & NUD_VALID)) { 218 if (!neigh || !(neigh->nud_state & NUD_VALID)) {
219 rcu_read_lock();
218 neigh_event_send(dst_get_neighbour(&rt->dst), NULL); 220 neigh_event_send(dst_get_neighbour(&rt->dst), NULL);
221 rcu_read_unlock();
219 ret = -ENODATA; 222 ret = -ENODATA;
220 if (neigh) 223 if (neigh)
221 goto release; 224 goto release;
@@ -273,15 +276,16 @@ static int addr6_resolve(struct sockaddr_in6 *src_in,
273 goto put; 276 goto put;
274 } 277 }
275 278
279 rcu_read_lock();
276 neigh = dst_get_neighbour(dst); 280 neigh = dst_get_neighbour(dst);
277 if (!neigh || !(neigh->nud_state & NUD_VALID)) { 281 if (!neigh || !(neigh->nud_state & NUD_VALID)) {
278 if (neigh) 282 if (neigh)
279 neigh_event_send(neigh, NULL); 283 neigh_event_send(neigh, NULL);
280 ret = -ENODATA; 284 ret = -ENODATA;
281 goto put; 285 } else {
286 ret = rdma_copy_addr(addr, dst->dev, neigh->ha);
282 } 287 }
283 288 rcu_read_unlock();
284 ret = rdma_copy_addr(addr, dst->dev, neigh->ha);
285put: 289put:
286 dst_release(dst); 290 dst_release(dst);
287 return ret; 291 return ret;
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 4104ea2427c..8b72f39202f 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 872b1842598..75ff821c0af 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 4507043d24c..176c8f90f2b 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 a9c042345c6..1a696f76b61 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 056389229ea..2fe428bba54 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 68b4162fd9d..d2360a8ef0b 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 9227f4acd79..d1c8196d15d 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 019bd4b0863..1b65986c0be 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 2b59b72b57f..c61bca30fd2 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 b69307f4f6d..b37b0c02a7b 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 9b737ff133e..72feee620eb 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 9155f91d66b..71f0c0f7df9 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 1b1146f8712..e7bee46868d 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 42517500b22..602b1bd723a 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/cxgb3/iwch_cm.c b/drivers/infiniband/hw/cxgb3/iwch_cm.c
index de6d0774e60..c88b12beef2 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.c
@@ -1375,8 +1375,10 @@ static int pass_accept_req(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1375 goto reject; 1375 goto reject;
1376 } 1376 }
1377 dst = &rt->dst; 1377 dst = &rt->dst;
1378 rcu_read_lock();
1378 neigh = dst_get_neighbour(dst); 1379 neigh = dst_get_neighbour(dst);
1379 l2t = t3_l2t_get(tdev, neigh, neigh->dev); 1380 l2t = t3_l2t_get(tdev, neigh, neigh->dev);
1381 rcu_read_unlock();
1380 if (!l2t) { 1382 if (!l2t) {
1381 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n", 1383 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1382 __func__); 1384 __func__);
@@ -1946,10 +1948,12 @@ int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
1946 } 1948 }
1947 ep->dst = &rt->dst; 1949 ep->dst = &rt->dst;
1948 1950
1951 rcu_read_lock();
1949 neigh = dst_get_neighbour(ep->dst); 1952 neigh = dst_get_neighbour(ep->dst);
1950 1953
1951 /* get a l2t entry */ 1954 /* get a l2t entry */
1952 ep->l2t = t3_l2t_get(ep->com.tdev, neigh, neigh->dev); 1955 ep->l2t = t3_l2t_get(ep->com.tdev, neigh, neigh->dev);
1956 rcu_read_unlock();
1953 if (!ep->l2t) { 1957 if (!ep->l2t) {
1954 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); 1958 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
1955 err = -ENOMEM; 1959 err = -ENOMEM;
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index b36cdac9c55..0747004313a 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -542,8 +542,10 @@ static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
542 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0); 542 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
543 mpa->private_data_size = htons(ep->plen); 543 mpa->private_data_size = htons(ep->plen);
544 mpa->revision = mpa_rev_to_use; 544 mpa->revision = mpa_rev_to_use;
545 if (mpa_rev_to_use == 1) 545 if (mpa_rev_to_use == 1) {
546 ep->tried_with_mpa_v1 = 1; 546 ep->tried_with_mpa_v1 = 1;
547 ep->retry_with_mpa_v1 = 0;
548 }
547 549
548 if (mpa_rev_to_use == 2) { 550 if (mpa_rev_to_use == 2) {
549 mpa->private_data_size += 551 mpa->private_data_size +=
@@ -1594,6 +1596,7 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1594 goto reject; 1596 goto reject;
1595 } 1597 }
1596 dst = &rt->dst; 1598 dst = &rt->dst;
1599 rcu_read_lock();
1597 neigh = dst_get_neighbour(dst); 1600 neigh = dst_get_neighbour(dst);
1598 if (neigh->dev->flags & IFF_LOOPBACK) { 1601 if (neigh->dev->flags & IFF_LOOPBACK) {
1599 pdev = ip_dev_find(&init_net, peer_ip); 1602 pdev = ip_dev_find(&init_net, peer_ip);
@@ -1620,6 +1623,7 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1620 rss_qid = dev->rdev.lldi.rxq_ids[ 1623 rss_qid = dev->rdev.lldi.rxq_ids[
1621 cxgb4_port_idx(neigh->dev) * step]; 1624 cxgb4_port_idx(neigh->dev) * step];
1622 } 1625 }
1626 rcu_read_unlock();
1623 if (!l2t) { 1627 if (!l2t) {
1624 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n", 1628 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1625 __func__); 1629 __func__);
@@ -1820,6 +1824,7 @@ static int c4iw_reconnect(struct c4iw_ep *ep)
1820 } 1824 }
1821 ep->dst = &rt->dst; 1825 ep->dst = &rt->dst;
1822 1826
1827 rcu_read_lock();
1823 neigh = dst_get_neighbour(ep->dst); 1828 neigh = dst_get_neighbour(ep->dst);
1824 1829
1825 /* get a l2t entry */ 1830 /* get a l2t entry */
@@ -1856,6 +1861,7 @@ static int c4iw_reconnect(struct c4iw_ep *ep)
1856 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[ 1861 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1857 cxgb4_port_idx(neigh->dev) * step]; 1862 cxgb4_port_idx(neigh->dev) * step];
1858 } 1863 }
1864 rcu_read_unlock();
1859 if (!ep->l2t) { 1865 if (!ep->l2t) {
1860 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); 1866 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
1861 err = -ENOMEM; 1867 err = -ENOMEM;
@@ -2301,6 +2307,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2301 } 2307 }
2302 ep->dst = &rt->dst; 2308 ep->dst = &rt->dst;
2303 2309
2310 rcu_read_lock();
2304 neigh = dst_get_neighbour(ep->dst); 2311 neigh = dst_get_neighbour(ep->dst);
2305 2312
2306 /* get a l2t entry */ 2313 /* get a l2t entry */
@@ -2339,6 +2346,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2339 ep->retry_with_mpa_v1 = 0; 2346 ep->retry_with_mpa_v1 = 0;
2340 ep->tried_with_mpa_v1 = 0; 2347 ep->tried_with_mpa_v1 = 0;
2341 } 2348 }
2349 rcu_read_unlock();
2342 if (!ep->l2t) { 2350 if (!ep->l2t) {
2343 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); 2351 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2344 err = -ENOMEM; 2352 err = -ENOMEM;
diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
index f35a935267e..0f1607c8325 100644
--- a/drivers/infiniband/hw/cxgb4/cq.c
+++ b/drivers/infiniband/hw/cxgb4/cq.c
@@ -311,7 +311,7 @@ void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count)
311 while (ptr != cq->sw_pidx) { 311 while (ptr != cq->sw_pidx) {
312 cqe = &cq->sw_queue[ptr]; 312 cqe = &cq->sw_queue[ptr];
313 if (RQ_TYPE(cqe) && (CQE_OPCODE(cqe) != FW_RI_READ_RESP) && 313 if (RQ_TYPE(cqe) && (CQE_OPCODE(cqe) != FW_RI_READ_RESP) &&
314 (CQE_QPID(cqe) == wq->rq.qid) && cqe_completes_wr(cqe, wq)) 314 (CQE_QPID(cqe) == wq->sq.qid) && cqe_completes_wr(cqe, wq))
315 (*count)++; 315 (*count)++;
316 if (++ptr == cq->size) 316 if (++ptr == cq->size)
317 ptr = 0; 317 ptr = 0;
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index d6ccc7e8480..5f940aeaab1 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 daef61d5e5b..714293b7851 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 be24ac72611..bfca37b2432 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 8697eca1435..736d9edbdbe 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 824a4d50883..49b09c697c7 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 8991677e9a0..75558f33f1c 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 dd7f26d04d4..439c35d4a66 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 e4a08c2819e..712d2a30fbe 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 3082b3b3d62..9d3e5c1ac60 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 ab876f928a1..ed9a989e501 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 cb9a0b97680..5b71d43bd89 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/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
index dfce9ea98a3..0a52d72371e 100644
--- a/drivers/infiniband/hw/nes/nes_cm.c
+++ b/drivers/infiniband/hw/nes/nes_cm.c
@@ -1377,9 +1377,11 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
1377 neigh_release(neigh); 1377 neigh_release(neigh);
1378 } 1378 }
1379 1379
1380 if ((neigh == NULL) || (!(neigh->nud_state & NUD_VALID))) 1380 if ((neigh == NULL) || (!(neigh->nud_state & NUD_VALID))) {
1381 rcu_read_lock();
1381 neigh_event_send(dst_get_neighbour(&rt->dst), NULL); 1382 neigh_event_send(dst_get_neighbour(&rt->dst), NULL);
1382 1383 rcu_read_unlock();
1384 }
1383 ip_rt_put(rt); 1385 ip_rt_put(rt);
1384 return rc; 1386 return rc;
1385} 1387}
diff --git a/drivers/infiniband/hw/qib/qib_diag.c b/drivers/infiniband/hw/qib/qib_diag.c
index 204c4dd9dce..9892456a434 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 9a9047f385a..c90a55f4120 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 77633666f81..574600ef5b4 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 3f1d562ba89..439d3c503cd 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 efd0a110091..1d5895941e1 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
@@ -2306,19 +2307,11 @@ static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2306 SYM_LSB(IBCCtrlA_0, MaxPktLen); 2307 SYM_LSB(IBCCtrlA_0, MaxPktLen);
2307 ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */ 2308 ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
2308 2309
2309 /* initially come up waiting for TS1, without sending anything. */
2310 val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
2311 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2312
2313 ppd->cpspec->ibcctrl_a = val;
2314 /* 2310 /*
2315 * Reset the PCS interface to the serdes (and also ibc, which is still 2311 * Reset the PCS interface to the serdes (and also ibc, which is still
2316 * in reset from above). Writes new value of ibcctrl_a as last step. 2312 * in reset from above). Writes new value of ibcctrl_a as last step.
2317 */ 2313 */
2318 qib_7322_mini_pcs_reset(ppd); 2314 qib_7322_mini_pcs_reset(ppd);
2319 qib_write_kreg(dd, kr_scratch, 0ULL);
2320 /* clear the linkinit cmds */
2321 ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
2322 2315
2323 if (!ppd->cpspec->ibcctrl_b) { 2316 if (!ppd->cpspec->ibcctrl_b) {
2324 unsigned lse = ppd->link_speed_enabled; 2317 unsigned lse = ppd->link_speed_enabled;
@@ -2384,6 +2377,14 @@ static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
2384 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn); 2377 ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
2385 set_vls(ppd); 2378 set_vls(ppd);
2386 2379
2380 /* initially come up DISABLED, without sending anything. */
2381 val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
2382 QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
2383 qib_write_kreg_port(ppd, krp_ibcctrl_a, val);
2384 qib_write_kreg(dd, kr_scratch, 0ULL);
2385 /* clear the linkinit cmds */
2386 ppd->cpspec->ibcctrl_a = val & ~SYM_MASK(IBCCtrlA_0, LinkInitCmd);
2387
2387 /* be paranoid against later code motion, etc. */ 2388 /* be paranoid against later code motion, etc. */
2388 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags); 2389 spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
2389 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable); 2390 ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
@@ -5240,7 +5241,7 @@ static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
5240 off */ 5241 off */
5241 if (ppd->dd->flags & QIB_HAS_QSFP) { 5242 if (ppd->dd->flags & QIB_HAS_QSFP) {
5242 qd->t_insert = get_jiffies_64(); 5243 qd->t_insert = get_jiffies_64();
5243 schedule_work(&qd->work); 5244 queue_work(ib_wq, &qd->work);
5244 } 5245 }
5245 spin_lock_irqsave(&ppd->sdma_lock, flags); 5246 spin_lock_irqsave(&ppd->sdma_lock, flags);
5246 if (__qib_sdma_running(ppd)) 5247 if (__qib_sdma_running(ppd))
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index b093a0b53b2..58b0f8ad4a2 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 4426782ad28..97a8bdf68e6 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_qsfp.c b/drivers/infiniband/hw/qib/qib_qsfp.c
index e06c4ed383f..fa71b1e666c 100644
--- a/drivers/infiniband/hw/qib/qib_qsfp.c
+++ b/drivers/infiniband/hw/qib/qib_qsfp.c
@@ -480,18 +480,6 @@ void qib_qsfp_init(struct qib_qsfp_data *qd,
480 udelay(20); /* Generous RST dwell */ 480 udelay(20); /* Generous RST dwell */
481 481
482 dd->f_gpio_mod(dd, mask, mask, mask); 482 dd->f_gpio_mod(dd, mask, mask, mask);
483 /* Spec says module can take up to two seconds! */
484 mask = QSFP_GPIO_MOD_PRS_N;
485 if (qd->ppd->hw_pidx)
486 mask <<= QSFP_GPIO_PORT2_SHIFT;
487
488 /* Do not try to wait here. Better to let event handle it */
489 if (!qib_qsfp_mod_present(qd->ppd))
490 goto bail;
491 /* We see a module, but it may be unwise to look yet. Just schedule */
492 qd->t_insert = get_jiffies_64();
493 queue_work(ib_wq, &qd->work);
494bail:
495 return; 483 return;
496} 484}
497 485
diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
index afaf4ac79f4..894afac26f3 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 e9f9f8bc320..de1a4b2f33c 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 cad44491320..12a9604310d 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 7f36454c225..1bf626c4017 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 9627cb73712..a894762da46 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 231c2f2f52f..014504d8e43 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 0e2fe4631ba..50061854616 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 2b060f45bec..4115be54ba3 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
@@ -56,21 +57,24 @@ struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
56 struct ib_pd *pd, struct ib_ah_attr *attr) 57 struct ib_pd *pd, struct ib_ah_attr *attr)
57{ 58{
58 struct ipoib_ah *ah; 59 struct ipoib_ah *ah;
60 struct ib_ah *vah;
59 61
60 ah = kmalloc(sizeof *ah, GFP_KERNEL); 62 ah = kmalloc(sizeof *ah, GFP_KERNEL);
61 if (!ah) 63 if (!ah)
62 return NULL; 64 return ERR_PTR(-ENOMEM);
63 65
64 ah->dev = dev; 66 ah->dev = dev;
65 ah->last_send = 0; 67 ah->last_send = 0;
66 kref_init(&ah->ref); 68 kref_init(&ah->ref);
67 69
68 ah->ah = ib_create_ah(pd, attr); 70 vah = ib_create_ah(pd, attr);
69 if (IS_ERR(ah->ah)) { 71 if (IS_ERR(vah)) {
70 kfree(ah); 72 kfree(ah);
71 ah = NULL; 73 ah = (struct ipoib_ah *)vah;
72 } else 74 } else {
75 ah->ah = vah;
73 ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah); 76 ipoib_dbg(netdev_priv(dev), "Created ah %p\n", ah->ah);
77 }
74 78
75 return ah; 79 return ah;
76} 80}
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 7567b600023..83695b48b01 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -432,7 +432,7 @@ static void path_rec_completion(int status,
432 432
433 spin_lock_irqsave(&priv->lock, flags); 433 spin_lock_irqsave(&priv->lock, flags);
434 434
435 if (ah) { 435 if (!IS_ERR_OR_NULL(ah)) {
436 path->pathrec = *pathrec; 436 path->pathrec = *pathrec;
437 437
438 old_ah = path->ah; 438 old_ah = path->ah;
@@ -555,6 +555,7 @@ static int path_rec_start(struct net_device *dev,
555 return 0; 555 return 0;
556} 556}
557 557
558/* called with rcu_read_lock */
558static void neigh_add_path(struct sk_buff *skb, struct net_device *dev) 559static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
559{ 560{
560 struct ipoib_dev_priv *priv = netdev_priv(dev); 561 struct ipoib_dev_priv *priv = netdev_priv(dev);
@@ -636,6 +637,7 @@ err_drop:
636 spin_unlock_irqrestore(&priv->lock, flags); 637 spin_unlock_irqrestore(&priv->lock, flags);
637} 638}
638 639
640/* called with rcu_read_lock */
639static void ipoib_path_lookup(struct sk_buff *skb, struct net_device *dev) 641static void ipoib_path_lookup(struct sk_buff *skb, struct net_device *dev)
640{ 642{
641 struct ipoib_dev_priv *priv = netdev_priv(skb->dev); 643 struct ipoib_dev_priv *priv = netdev_priv(skb->dev);
@@ -720,13 +722,14 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
720 struct neighbour *n = NULL; 722 struct neighbour *n = NULL;
721 unsigned long flags; 723 unsigned long flags;
722 724
725 rcu_read_lock();
723 if (likely(skb_dst(skb))) 726 if (likely(skb_dst(skb)))
724 n = dst_get_neighbour(skb_dst(skb)); 727 n = dst_get_neighbour(skb_dst(skb));
725 728
726 if (likely(n)) { 729 if (likely(n)) {
727 if (unlikely(!*to_ipoib_neigh(n))) { 730 if (unlikely(!*to_ipoib_neigh(n))) {
728 ipoib_path_lookup(skb, dev); 731 ipoib_path_lookup(skb, dev);
729 return NETDEV_TX_OK; 732 goto unlock;
730 } 733 }
731 734
732 neigh = *to_ipoib_neigh(n); 735 neigh = *to_ipoib_neigh(n);
@@ -749,17 +752,17 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
749 ipoib_neigh_free(dev, neigh); 752 ipoib_neigh_free(dev, neigh);
750 spin_unlock_irqrestore(&priv->lock, flags); 753 spin_unlock_irqrestore(&priv->lock, flags);
751 ipoib_path_lookup(skb, dev); 754 ipoib_path_lookup(skb, dev);
752 return NETDEV_TX_OK; 755 goto unlock;
753 } 756 }
754 757
755 if (ipoib_cm_get(neigh)) { 758 if (ipoib_cm_get(neigh)) {
756 if (ipoib_cm_up(neigh)) { 759 if (ipoib_cm_up(neigh)) {
757 ipoib_cm_send(dev, skb, ipoib_cm_get(neigh)); 760 ipoib_cm_send(dev, skb, ipoib_cm_get(neigh));
758 return NETDEV_TX_OK; 761 goto unlock;
759 } 762 }
760 } else if (neigh->ah) { 763 } else if (neigh->ah) {
761 ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(n->ha)); 764 ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(n->ha));
762 return NETDEV_TX_OK; 765 goto unlock;
763 } 766 }
764 767
765 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { 768 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
@@ -793,13 +796,14 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
793 phdr->hwaddr + 4); 796 phdr->hwaddr + 4);
794 dev_kfree_skb_any(skb); 797 dev_kfree_skb_any(skb);
795 ++dev->stats.tx_dropped; 798 ++dev->stats.tx_dropped;
796 return NETDEV_TX_OK; 799 goto unlock;
797 } 800 }
798 801
799 unicast_arp_send(skb, dev, phdr); 802 unicast_arp_send(skb, dev, phdr);
800 } 803 }
801 } 804 }
802 805unlock:
806 rcu_read_unlock();
803 return NETDEV_TX_OK; 807 return NETDEV_TX_OK;
804} 808}
805 809
@@ -837,7 +841,7 @@ static int ipoib_hard_header(struct sk_buff *skb,
837 dst = skb_dst(skb); 841 dst = skb_dst(skb);
838 n = NULL; 842 n = NULL;
839 if (dst) 843 if (dst)
840 n = dst_get_neighbour(dst); 844 n = dst_get_neighbour_raw(dst);
841 if ((!dst || !n) && daddr) { 845 if ((!dst || !n) && daddr) {
842 struct ipoib_pseudoheader *phdr = 846 struct ipoib_pseudoheader *phdr =
843 (struct ipoib_pseudoheader *) skb_push(skb, sizeof *phdr); 847 (struct ipoib_pseudoheader *) skb_push(skb, sizeof *phdr);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index ecea4fe1ed0..873bff97e69 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>
@@ -239,8 +240,11 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
239 av.grh.dgid = mcast->mcmember.mgid; 240 av.grh.dgid = mcast->mcmember.mgid;
240 241
241 ah = ipoib_create_ah(dev, priv->pd, &av); 242 ah = ipoib_create_ah(dev, priv->pd, &av);
242 if (!ah) { 243 if (IS_ERR(ah)) {
243 ipoib_warn(priv, "ib_address_create failed\n"); 244 ipoib_warn(priv, "ib_address_create failed %ld\n",
245 -PTR_ERR(ah));
246 /* use original error */
247 return PTR_ERR(ah);
244 } else { 248 } else {
245 spin_lock_irq(&priv->lock); 249 spin_lock_irq(&priv->lock);
246 mcast->ah = ah; 250 mcast->ah = ah;
@@ -265,7 +269,7 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
265 269
266 skb->dev = dev; 270 skb->dev = dev;
267 if (dst) 271 if (dst)
268 n = dst_get_neighbour(dst); 272 n = dst_get_neighbour_raw(dst);
269 if (!dst || !n) { 273 if (!dst || !n) {
270 /* put pseudoheader back on for next time */ 274 /* put pseudoheader back on for next time */
271 skb_push(skb, sizeof (struct ipoib_pseudoheader)); 275 skb_push(skb, sizeof (struct ipoib_pseudoheader));
@@ -721,6 +725,8 @@ out:
721 if (mcast && mcast->ah) { 725 if (mcast && mcast->ah) {
722 struct dst_entry *dst = skb_dst(skb); 726 struct dst_entry *dst = skb_dst(skb);
723 struct neighbour *n = NULL; 727 struct neighbour *n = NULL;
728
729 rcu_read_lock();
724 if (dst) 730 if (dst)
725 n = dst_get_neighbour(dst); 731 n = dst_get_neighbour(dst);
726 if (n && !*to_ipoib_neigh(n)) { 732 if (n && !*to_ipoib_neigh(n)) {
@@ -733,7 +739,7 @@ out:
733 list_add_tail(&neigh->list, &mcast->neigh_list); 739 list_add_tail(&neigh->list, &mcast->neigh_list);
734 } 740 }
735 } 741 }
736 742 rcu_read_unlock();
737 spin_unlock_irqrestore(&priv->lock, flags); 743 spin_unlock_irqrestore(&priv->lock, flags);
738 ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN); 744 ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN);
739 return; 745 return;
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 84e8c293a71..7e7373a700e 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 db6f3ce9f3b..db7ea3704da 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 f299de6b419..a607542fc79 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 ede1475bee0..e28877c4ce1 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/input-compat.c b/drivers/input/input-compat.c
index 1accb89ae66..e46a86776a6 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 9150ee78e00..f658086fbbe 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 b253973881b..7dfe1009fae 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 f6732b57ca0..6d6e7418dc2 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 6e0f2309136..fcdec5e2b29 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 1c58681de81..66e55e5cfdd 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 56aa465d1b9..22d875fde53 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 62dcd79d548..a244fc6a781 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 ca42c7d2a3c..0ac75bbad4d 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 144ddbdeb9b..09244804fb9 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 1de58e8a1b7..8d345e87075 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 1633b634226..80793f1608e 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 19af682c24f..7283dd2a1ad 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 00000000000..09b05228865
--- /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/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 09b93b11a27..e2a9867c19d 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1210,18 +1210,28 @@ static int elantech_reconnect(struct psmouse *psmouse)
1210 */ 1210 */
1211static int elantech_set_properties(struct elantech_data *etd) 1211static int elantech_set_properties(struct elantech_data *etd)
1212{ 1212{
1213 /* This represents the version of IC body. */
1213 int ver = (etd->fw_version & 0x0f0000) >> 16; 1214 int ver = (etd->fw_version & 0x0f0000) >> 16;
1214 1215
1216 /* Early version of Elan touchpads doesn't obey the rule. */
1215 if (etd->fw_version < 0x020030 || etd->fw_version == 0x020600) 1217 if (etd->fw_version < 0x020030 || etd->fw_version == 0x020600)
1216 etd->hw_version = 1; 1218 etd->hw_version = 1;
1217 else if (etd->fw_version < 0x150600) 1219 else {
1218 etd->hw_version = 2; 1220 switch (ver) {
1219 else if (ver == 5) 1221 case 2:
1220 etd->hw_version = 3; 1222 case 4:
1221 else if (ver == 6) 1223 etd->hw_version = 2;
1222 etd->hw_version = 4; 1224 break;
1223 else 1225 case 5:
1224 return -1; 1226 etd->hw_version = 3;
1227 break;
1228 case 6:
1229 etd->hw_version = 4;
1230 break;
1231 default:
1232 return -1;
1233 }
1234 }
1225 1235
1226 /* 1236 /*
1227 * Turn on packet checking by default. 1237 * Turn on packet checking by default.
diff --git a/drivers/input/serio/ams_delta_serio.c b/drivers/input/serio/ams_delta_serio.c
index 4b2a42f9f0b..d4d08bd9205 100644
--- a/drivers/input/serio/ams_delta_serio.c
+++ b/drivers/input/serio/ams_delta_serio.c
@@ -24,6 +24,7 @@
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/serio.h> 25#include <linux/serio.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/module.h>
27 28
28#include <asm/mach-types.h> 29#include <asm/mach-types.h>
29#include <plat/board-ams-delta.h> 30#include <plat/board-ams-delta.h>
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index bb9f5d31f0d..b4cfc6c8be8 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -431,6 +431,13 @@ static const struct dmi_system_id __initconst i8042_dmi_nomux_table[] = {
431 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V13"), 431 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V13"),
432 }, 432 },
433 }, 433 },
434 {
435 /* Newer HP Pavilion dv4 models */
436 .matches = {
437 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv4 Notebook PC"),
439 },
440 },
434 { } 441 { }
435}; 442};
436 443
@@ -560,6 +567,13 @@ static const struct dmi_system_id __initconst i8042_dmi_notimeout_table[] = {
560 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V13"), 567 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V13"),
561 }, 568 },
562 }, 569 },
570 {
571 /* Newer HP Pavilion dv4 models */
572 .matches = {
573 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
574 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dv4 Notebook PC"),
575 },
576 },
563 { } 577 { }
564}; 578};
565 579
diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c
index fdb6a3976f9..75fb040a343 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 714d4e0f9f9..400131df677 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 ddf732f3caf..b1643c8fa7c 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 131f9d1c921..3b2e9ed2aee 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 d507b9b6780..de31ec6fe9e 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 1507ce108d5..902c7214e88 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 c5bc62d85bb..ede02743eac 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 bb161d2fa03..c0c7820d4c4 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/iommu/omap-iommu-debug.c b/drivers/iommu/omap-iommu-debug.c
index 9c192e79f80..288da5c1499 100644
--- a/drivers/iommu/omap-iommu-debug.c
+++ b/drivers/iommu/omap-iommu-debug.c
@@ -10,6 +10,7 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/module.h>
13#include <linux/err.h> 14#include <linux/err.h>
14#include <linux/clk.h> 15#include <linux/clk.h>
15#include <linux/io.h> 16#include <linux/io.h>
diff --git a/drivers/iommu/omap-iovmm.c b/drivers/iommu/omap-iovmm.c
index e8fdb8830f6..46be456fcc0 100644
--- a/drivers/iommu/omap-iovmm.c
+++ b/drivers/iommu/omap-iovmm.c
@@ -10,6 +10,7 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/module.h>
13#include <linux/err.h> 14#include <linux/err.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15#include <linux/vmalloc.h> 16#include <linux/vmalloc.h>
diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c
index ea2dff602e4..8d51cd1bf67 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/divert/divert_procfs.c b/drivers/isdn/divert/divert_procfs.c
index 33ec9e46777..9021182c4b7 100644
--- a/drivers/isdn/divert/divert_procfs.c
+++ b/drivers/isdn/divert/divert_procfs.c
@@ -242,6 +242,12 @@ static int isdn_divert_ioctl_unlocked(struct file *file, uint cmd, ulong arg)
242 case IIOCDOCFINT: 242 case IIOCDOCFINT:
243 if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid)) 243 if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
244 return (-EINVAL); /* invalid driver */ 244 return (-EINVAL); /* invalid driver */
245 if (strnlen(dioctl.cf_ctrl.msn, sizeof(dioctl.cf_ctrl.msn)) ==
246 sizeof(dioctl.cf_ctrl.msn))
247 return -EINVAL;
248 if (strnlen(dioctl.cf_ctrl.fwd_nr, sizeof(dioctl.cf_ctrl.fwd_nr)) ==
249 sizeof(dioctl.cf_ctrl.fwd_nr))
250 return -EINVAL;
245 if ((i = cf_command(dioctl.cf_ctrl.drvid, 251 if ((i = cf_command(dioctl.cf_ctrl.drvid,
246 (cmd == IIOCDOCFACT) ? 1 : (cmd == IIOCDOCFDIS) ? 0 : 2, 252 (cmd == IIOCDOCFACT) ? 1 : (cmd == IIOCDOCFDIS) ? 0 : 2,
247 dioctl.cf_ctrl.cfproc, 253 dioctl.cf_ctrl.cfproc,
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index c3b1dc3a13a..fddae72e3f9 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 658e75f18d0..6d5ceeece9f 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 bd0b1eaa757..19b1c779d50 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 ba74646cf0e..6d12623c1db 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 9bec8b96996..04231cb2f03 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 e35058bcd7b..ee0a549a933 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 d13fa5b119f..7034af28d46 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 b0d9ab1f21c..6a8acf65777 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_net.c b/drivers/isdn/i4l/isdn_net.c
index 1f73d7f7e02..2339d7396b9 100644
--- a/drivers/isdn/i4l/isdn_net.c
+++ b/drivers/isdn/i4l/isdn_net.c
@@ -2756,6 +2756,9 @@ isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
2756 char *c, 2756 char *c,
2757 *e; 2757 *e;
2758 2758
2759 if (strnlen(cfg->drvid, sizeof(cfg->drvid)) ==
2760 sizeof(cfg->drvid))
2761 return -EINVAL;
2759 drvidx = -1; 2762 drvidx = -1;
2760 chidx = -1; 2763 chidx = -1;
2761 strcpy(drvid, cfg->drvid); 2764 strcpy(drvid, cfg->drvid);
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index e5546cb3ac6..2c26b64ebbe 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 1fa629b3b94..7418f2d811d 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 9c7c6451bf3..b8f18bd09e4 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 621f3100709..b6c9a588934 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 8e325227b4c..738ea8dd0ad 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 52590296af3..e5c57389efd 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/led-class.c b/drivers/leds/led-class.c
index 661b692573e..6d5628bb060 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -270,11 +270,8 @@ void led_blink_set(struct led_classdev *led_cdev,
270 del_timer_sync(&led_cdev->blink_timer); 270 del_timer_sync(&led_cdev->blink_timer);
271 271
272 if (led_cdev->blink_set && 272 if (led_cdev->blink_set &&
273 !led_cdev->blink_set(led_cdev, delay_on, delay_off)) { 273 !led_cdev->blink_set(led_cdev, delay_on, delay_off))
274 led_cdev->blink_delay_on = *delay_on;
275 led_cdev->blink_delay_off = *delay_off;
276 return; 274 return;
277 }
278 275
279 /* blink with 1 Hz as default if nothing specified */ 276 /* blink with 1 Hz as default if nothing specified */
280 if (!*delay_on && !*delay_off) 277 if (!*delay_on && !*delay_off)
diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index 0d4c16678ac..0810604dc70 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 22f847c890c..48d9fe61bdf 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 c941d906bba..109c875ea23 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 438d4838463..aac1c073fe7 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 d11d05be0de..49aceffaa5b 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 504cc26c7e4..399a86f2013 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 4dc510fdfa0..0630e4f4b28 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 1f7c10f6b7f..80ba048889d 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 2579678f97a..53f67b8ce55 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 f369e56d654..b3393a9f213 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 93987a12da4..f117f7326c5 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 7e764b8365e..0555d4709a7 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 f77d48d0b3e..37b7d0cfe58 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 a77771dc2e9..29f8b0f0e2c 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 ef5c24140a4..b1eb34c3e81 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 f14edd82cb0..4a127657835 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 2982c86ac4c..6e21e654bb0 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 5289ffa2e50..0dc30ffde5a 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 f97e625241a..ff4a0bc9904 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/macintosh/via-macii.c b/drivers/macintosh/via-macii.c
index 817f37a875c..c9570fcf1cc 100644
--- a/drivers/macintosh/via-macii.c
+++ b/drivers/macintosh/via-macii.c
@@ -159,7 +159,7 @@ int macii_init(void)
159 err = macii_init_via(); 159 err = macii_init_via();
160 if (err) goto out; 160 if (err) goto out;
161 161
162 err = request_irq(IRQ_MAC_ADB, macii_interrupt, IRQ_FLG_LOCK, "ADB", 162 err = request_irq(IRQ_MAC_ADB, macii_interrupt, 0, "ADB",
163 macii_interrupt); 163 macii_interrupt);
164 if (err) goto out; 164 if (err) goto out;
165 165
diff --git a/drivers/macintosh/via-maciisi.c b/drivers/macintosh/via-maciisi.c
index 9ab5b0c34f0..34d02a91b29 100644
--- a/drivers/macintosh/via-maciisi.c
+++ b/drivers/macintosh/via-maciisi.c
@@ -122,8 +122,8 @@ maciisi_init(void)
122 return err; 122 return err;
123 } 123 }
124 124
125 if (request_irq(IRQ_MAC_ADB, maciisi_interrupt, IRQ_FLG_LOCK | IRQ_FLG_FAST, 125 if (request_irq(IRQ_MAC_ADB, maciisi_interrupt, 0, "ADB",
126 "ADB", maciisi_interrupt)) { 126 maciisi_interrupt)) {
127 printk(KERN_ERR "maciisi_init: can't get irq %d\n", IRQ_MAC_ADB); 127 printk(KERN_ERR "maciisi_init: can't get irq %d\n", IRQ_MAC_ADB);
128 return -EAGAIN; 128 return -EAGAIN;
129 } 129 }
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index cb246667dd5..0a6806f80ab 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -14,6 +14,7 @@
14#include <linux/vmalloc.h> 14#include <linux/vmalloc.h>
15#include <linux/version.h> 15#include <linux/version.h>
16#include <linux/shrinker.h> 16#include <linux/shrinker.h>
17#include <linux/module.h>
17 18
18#define DM_MSG_PREFIX "bufio" 19#define DM_MSG_PREFIX "bufio"
19 20
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 0bdb201c2c2..042e7199656 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-log-userspace-base.c b/drivers/md/dm-log-userspace-base.c
index 8db3862dade..9429159d9ee 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
diff --git a/drivers/md/dm-path-selector.c b/drivers/md/dm-path-selector.c
index 42c04f04a0c..fa0ccc585cb 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 11fa96df4b0..c2907d836e4 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"
diff --git a/drivers/md/dm-round-robin.c b/drivers/md/dm-round-robin.c
index 24752f449be..27f1d423b76 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 9c6c2e47ad6..59883bd7821 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 d1f1d701710..3ac415675b6 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 a0898a66a2f..1ce9a2586e4 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-uevent.c b/drivers/md/dm-uevent.c
index 6b1e3b61b25..8efe033bab5 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 6b6616a41ba..4720f68f817 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -192,9 +192,6 @@ struct mapped_device {
192 /* forced geometry settings */ 192 /* forced geometry settings */
193 struct hd_geometry geometry; 193 struct hd_geometry geometry;
194 194
195 /* For saving the address of __make_request for request based dm */
196 make_request_fn *saved_make_request_fn;
197
198 /* sysfs handle */ 195 /* sysfs handle */
199 struct kobject kobj; 196 struct kobject kobj;
200 197
@@ -1403,7 +1400,7 @@ out:
1403 * The request function that just remaps the bio built up by 1400 * The request function that just remaps the bio built up by
1404 * dm_merge_bvec. 1401 * dm_merge_bvec.
1405 */ 1402 */
1406static int _dm_request(struct request_queue *q, struct bio *bio) 1403static void _dm_request(struct request_queue *q, struct bio *bio)
1407{ 1404{
1408 int rw = bio_data_dir(bio); 1405 int rw = bio_data_dir(bio);
1409 struct mapped_device *md = q->queuedata; 1406 struct mapped_device *md = q->queuedata;
@@ -1424,19 +1421,12 @@ static int _dm_request(struct request_queue *q, struct bio *bio)
1424 queue_io(md, bio); 1421 queue_io(md, bio);
1425 else 1422 else
1426 bio_io_error(bio); 1423 bio_io_error(bio);
1427 return 0; 1424 return;
1428 } 1425 }
1429 1426
1430 __split_and_process_bio(md, bio); 1427 __split_and_process_bio(md, bio);
1431 up_read(&md->io_lock); 1428 up_read(&md->io_lock);
1432 return 0; 1429 return;
1433}
1434
1435static int dm_make_request(struct request_queue *q, struct bio *bio)
1436{
1437 struct mapped_device *md = q->queuedata;
1438
1439 return md->saved_make_request_fn(q, bio); /* call __make_request() */
1440} 1430}
1441 1431
1442static int dm_request_based(struct mapped_device *md) 1432static int dm_request_based(struct mapped_device *md)
@@ -1444,14 +1434,14 @@ static int dm_request_based(struct mapped_device *md)
1444 return blk_queue_stackable(md->queue); 1434 return blk_queue_stackable(md->queue);
1445} 1435}
1446 1436
1447static int dm_request(struct request_queue *q, struct bio *bio) 1437static void dm_request(struct request_queue *q, struct bio *bio)
1448{ 1438{
1449 struct mapped_device *md = q->queuedata; 1439 struct mapped_device *md = q->queuedata;
1450 1440
1451 if (dm_request_based(md)) 1441 if (dm_request_based(md))
1452 return dm_make_request(q, bio); 1442 blk_queue_bio(q, bio);
1453 1443 else
1454 return _dm_request(q, bio); 1444 _dm_request(q, bio);
1455} 1445}
1456 1446
1457void dm_dispatch_request(struct request *rq) 1447void dm_dispatch_request(struct request *rq)
@@ -2191,7 +2181,6 @@ static int dm_init_request_based_queue(struct mapped_device *md)
2191 return 0; 2181 return 0;
2192 2182
2193 md->queue = q; 2183 md->queue = q;
2194 md->saved_make_request_fn = md->queue->make_request_fn;
2195 dm_init_md_queue(md); 2184 dm_init_md_queue(md);
2196 blk_queue_softirq_done(md->queue, dm_softirq_done); 2185 blk_queue_softirq_done(md->queue, dm_softirq_done);
2197 blk_queue_prep_rq(md->queue, dm_prep_fn); 2186 blk_queue_prep_rq(md->queue, dm_prep_fn);
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index 60816b132c2..feb2c3c7bb4 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 10c5844460c..c3273efd08c 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 266e82ebaf1..84acfe7d10e 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 51c1d91557e..cf742d9306e 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 d32c785e17d..5899246fa37 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/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
index 65fd85ec651..023fbc2d389 100644
--- a/drivers/md/persistent-data/dm-btree-remove.c
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -8,7 +8,7 @@
8#include "dm-btree-internal.h" 8#include "dm-btree-internal.h"
9#include "dm-transaction-manager.h" 9#include "dm-transaction-manager.h"
10 10
11#include <linux/module.h> 11#include <linux/export.h>
12 12
13/* 13/*
14 * Removing an entry from a btree 14 * Removing an entry from a btree
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
index e0638be53ea..bd1e7ffbe26 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -8,7 +8,7 @@
8#include "dm-space-map.h" 8#include "dm-space-map.h"
9#include "dm-transaction-manager.h" 9#include "dm-transaction-manager.h"
10 10
11#include <linux/module.h> 11#include <linux/export.h>
12#include <linux/device-mapper.h> 12#include <linux/device-mapper.h>
13 13
14#define DM_MSG_PREFIX "btree" 14#define DM_MSG_PREFIX "btree"
diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
index bb44a937fe6..50ed53bf4aa 100644
--- a/drivers/md/persistent-data/dm-space-map-checker.c
+++ b/drivers/md/persistent-data/dm-space-map-checker.c
@@ -7,6 +7,7 @@
7#include "dm-space-map-checker.h" 7#include "dm-space-map-checker.h"
8 8
9#include <linux/device-mapper.h> 9#include <linux/device-mapper.h>
10#include <linux/export.h>
10 11
11#ifdef CONFIG_DM_DEBUG_SPACE_MAPS 12#ifdef CONFIG_DM_DEBUG_SPACE_MAPS
12 13
diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
index aeff7852cf7..fc469ba9f62 100644
--- a/drivers/md/persistent-data/dm-space-map-disk.c
+++ b/drivers/md/persistent-data/dm-space-map-disk.c
@@ -12,7 +12,7 @@
12 12
13#include <linux/list.h> 13#include <linux/list.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/module.h> 15#include <linux/export.h>
16#include <linux/device-mapper.h> 16#include <linux/device-mapper.h>
17 17
18#define DM_MSG_PREFIX "space map disk" 18#define DM_MSG_PREFIX "space map disk"
diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
index 728e89a3f97..6f8d38747d7 100644
--- a/drivers/md/persistent-data/dm-transaction-manager.c
+++ b/drivers/md/persistent-data/dm-transaction-manager.c
@@ -10,7 +10,7 @@
10#include "dm-space-map-metadata.h" 10#include "dm-space-map-metadata.h"
11#include "dm-persistent-data-internal.h" 11#include "dm-persistent-data-internal.h"
12 12
13#include <linux/module.h> 13#include <linux/export.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/device-mapper.h> 15#include <linux/device-mapper.h>
16 16
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 0eb08a4df75..7294bd115e3 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 4602fc57c96..ede2461e79c 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 c025a8276dc..685ddf325ee 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 f6fe053a5be..297e2609217 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>
@@ -3109,7 +3110,7 @@ static void handle_stripe(struct stripe_head *sh)
3109 struct r5dev *pdev, *qdev; 3110 struct r5dev *pdev, *qdev;
3110 3111
3111 clear_bit(STRIPE_HANDLE, &sh->state); 3112 clear_bit(STRIPE_HANDLE, &sh->state);
3112 if (test_and_set_bit(STRIPE_ACTIVE, &sh->state)) { 3113 if (test_and_set_bit_lock(STRIPE_ACTIVE, &sh->state)) {
3113 /* already being handled, ensure it gets handled 3114 /* already being handled, ensure it gets handled
3114 * again when current action finishes */ 3115 * again when current action finishes */
3115 set_bit(STRIPE_HANDLE, &sh->state); 3116 set_bit(STRIPE_HANDLE, &sh->state);
@@ -3158,10 +3159,14 @@ static void handle_stripe(struct stripe_head *sh)
3158 /* check if the array has lost more than max_degraded devices and, 3159 /* check if the array has lost more than max_degraded devices and,
3159 * if so, some requests might need to be failed. 3160 * if so, some requests might need to be failed.
3160 */ 3161 */
3161 if (s.failed > conf->max_degraded && s.to_read+s.to_write+s.written) 3162 if (s.failed > conf->max_degraded) {
3162 handle_failed_stripe(conf, sh, &s, disks, &s.return_bi); 3163 sh->check_state = 0;
3163 if (s.failed > conf->max_degraded && s.syncing) 3164 sh->reconstruct_state = 0;
3164 handle_failed_sync(conf, sh, &s); 3165 if (s.to_read+s.to_write+s.written)
3166 handle_failed_stripe(conf, sh, &s, disks, &s.return_bi);
3167 if (s.syncing)
3168 handle_failed_sync(conf, sh, &s);
3169 }
3165 3170
3166 /* 3171 /*
3167 * might be able to return some write requests if the parity blocks 3172 * might be able to return some write requests if the parity blocks
@@ -3370,7 +3375,7 @@ finish:
3370 3375
3371 return_io(s.return_bi); 3376 return_io(s.return_bi);
3372 3377
3373 clear_bit(STRIPE_ACTIVE, &sh->state); 3378 clear_bit_unlock(STRIPE_ACTIVE, &sh->state);
3374} 3379}
3375 3380
3376static void raid5_activate_delayed(struct r5conf *conf) 3381static void raid5_activate_delayed(struct r5conf *conf)
@@ -3688,7 +3693,7 @@ static struct stripe_head *__get_priority_stripe(struct r5conf *conf)
3688 return sh; 3693 return sh;
3689} 3694}
3690 3695
3691static int make_request(struct mddev *mddev, struct bio * bi) 3696static void make_request(struct mddev *mddev, struct bio * bi)
3692{ 3697{
3693 struct r5conf *conf = mddev->private; 3698 struct r5conf *conf = mddev->private;
3694 int dd_idx; 3699 int dd_idx;
@@ -3701,7 +3706,7 @@ static int make_request(struct mddev *mddev, struct bio * bi)
3701 3706
3702 if (unlikely(bi->bi_rw & REQ_FLUSH)) { 3707 if (unlikely(bi->bi_rw & REQ_FLUSH)) {
3703 md_flush_request(mddev, bi); 3708 md_flush_request(mddev, bi);
3704 return 0; 3709 return;
3705 } 3710 }
3706 3711
3707 md_write_start(mddev, bi); 3712 md_write_start(mddev, bi);
@@ -3709,7 +3714,7 @@ static int make_request(struct mddev *mddev, struct bio * bi)
3709 if (rw == READ && 3714 if (rw == READ &&
3710 mddev->reshape_position == MaxSector && 3715 mddev->reshape_position == MaxSector &&
3711 chunk_aligned_read(mddev,bi)) 3716 chunk_aligned_read(mddev,bi))
3712 return 0; 3717 return;
3713 3718
3714 logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); 3719 logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
3715 last_sector = bi->bi_sector + (bi->bi_size>>9); 3720 last_sector = bi->bi_sector + (bi->bi_size>>9);
@@ -3844,8 +3849,6 @@ static int make_request(struct mddev *mddev, struct bio * bi)
3844 3849
3845 bio_endio(bi, 0); 3850 bio_endio(bi, 0);
3846 } 3851 }
3847
3848 return 0;
3849} 3852}
3850 3853
3851static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks); 3854static 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 f5d53a20234..d6b1cf66042 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 a92546144ea..71f8e018e56 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 79ad73accb2..bc1f545c95c 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 384b358d303..ce30533fd97 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 94a603a6084..e13683bab6b 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 cf7214edf65..38019bafb86 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 7d0710bb197..26c8b9e5705 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 2ad33ba92ba..2d08c9b5128 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 f027a2c1c3e..c4622618714 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 00000000000..d1f58371c71
--- /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 00000000000..432706ae527
--- /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-i2c.c b/drivers/media/dvb/dvb-usb/mxl111sf-i2c.c
index 2e8c288258a..34434557ef6 100644
--- a/drivers/media/dvb/dvb-usb/mxl111sf-i2c.c
+++ b/drivers/media/dvb/dvb-usb/mxl111sf-i2c.c
@@ -398,7 +398,6 @@ static int mxl111sf_i2c_readagain(struct mxl111sf_state *state,
398 u8 i2c_r_data[24]; 398 u8 i2c_r_data[24];
399 u8 i = 0; 399 u8 i = 0;
400 u8 fifo_status = 0; 400 u8 fifo_status = 0;
401 int ret;
402 int status = 0; 401 int status = 0;
403 402
404 mxl_i2c("read %d bytes", count); 403 mxl_i2c("read %d bytes", count);
@@ -418,7 +417,7 @@ static int mxl111sf_i2c_readagain(struct mxl111sf_state *state,
418 i2c_w_data[4+(i*3)] = 0x00; 417 i2c_w_data[4+(i*3)] = 0x00;
419 } 418 }
420 419
421 ret = mxl111sf_i2c_get_data(state, 0, i2c_w_data, i2c_r_data); 420 mxl111sf_i2c_get_data(state, 0, i2c_w_data, i2c_r_data);
422 421
423 /* Check for I2C NACK status */ 422 /* Check for I2C NACK status */
424 if (mxl111sf_i2c_check_status(state) == 1) { 423 if (mxl111sf_i2c_check_status(state) == 1) {
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-phy.c b/drivers/media/dvb/dvb-usb/mxl111sf-phy.c
index 91dc1fc2825..b741b3a7a32 100644
--- a/drivers/media/dvb/dvb-usb/mxl111sf-phy.c
+++ b/drivers/media/dvb/dvb-usb/mxl111sf-phy.c
@@ -296,8 +296,7 @@ int mxl111sf_config_spi(struct mxl111sf_state *state, int onoff)
296 goto fail; 296 goto fail;
297 297
298 ret = mxl111sf_write_reg(state, 0x00, 0x00); 298 ret = mxl111sf_write_reg(state, 0x00, 0x00);
299 if (mxl_fail(ret)) 299 mxl_fail(ret);
300 goto fail;
301fail: 300fail:
302 return ret; 301 return ret;
303} 302}
@@ -328,11 +327,13 @@ int mxl111sf_idac_config(struct mxl111sf_state *state,
328 /* set hysteresis value reg: 0x0B<5:0> */ 327 /* set hysteresis value reg: 0x0B<5:0> */
329 ret = mxl111sf_write_reg(state, V6_IDAC_HYSTERESIS_REG, 328 ret = mxl111sf_write_reg(state, V6_IDAC_HYSTERESIS_REG,
330 (hysteresis_value & 0x3F)); 329 (hysteresis_value & 0x3F));
330 mxl_fail(ret);
331 } 331 }
332 332
333 ret = mxl111sf_write_reg(state, V6_IDAC_SETTINGS_REG, val); 333 ret = mxl111sf_write_reg(state, V6_IDAC_SETTINGS_REG, val);
334 mxl_fail(ret);
334 335
335 return val; 336 return ret;
336} 337}
337 338
338/* 339/*
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf.c b/drivers/media/dvb/dvb-usb/mxl111sf.c
index 546ba5915a5..b5c98da5d9e 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 5a2c7bb386c..364d89f826b 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 774d507b66c..43be7238311 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 89873615e68..13ebeffb705 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 af121db88ea..680c781c8dd 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 457b6d02ef8..e2657c2f010 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 e57d38b0197..91f8c8291e2 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 0c8164a2cc3..51c7121b321 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 16b70b4412f..6edc9ba8120 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 52798a111e1..ccd5f0d8a01 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 95ddcc4845d..db20904d01f 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 f17b540d68a..3e9209f84e0 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 6d1e4e750f6..8aa4968d57b 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 c9f4a8e65dc..27aba936fb2 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 b93d8cf23b0..4f5c43d2566 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 624449afaa6..035668e27f6 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 ec2e67fd236..5faba2a2fdd 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 63ee722dbd0..17f8db00435 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 27808bb59eb..2e5cd3100b6 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 ebdba553991..9ab663a507a 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 90aa8868629..ec8d4a2e2c5 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 755dafa3871..140fb67e2f8 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 a92de80c48d..d5e2b50aff1 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 9a8752fdcca..b0e42df7ff8 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 fe652e928dc..4e6ade8e616 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 884f1b51a8e..c735fe10a39 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 7af188209ff..8c92ff95f94 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 b2481154491..2caf2117759 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 f766b24b015..2031224a202 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 ec9beeebd41..894939ac17f 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 22f54d413a3..d2aaf5b9e39 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 c25809d4c81..dc2baf06239 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 3d2cbe4e5e4..04269d31fa1 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 8cd7f28808b..e83b1a1939b 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 9d68af217d8..8344bcc595b 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 edfa71506d3..c6063dfcd50 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 32e94988dc9..14f78451e64 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 c3f6d62ac89..ea7f2d0f31e 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 8bf058f67f0..086b4b1f19e 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 c909a234c77..0877e348094 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 2f66e4310d2..8311e092c09 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 284534b67e7..0c87fbaf99a 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 cf3a6bfb190..309e9e3fb6f 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 7a5f5300caf..4d13a7f2e5c 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 4af12e45dfb..ba81d9697cf 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 f68b450f559..bed78acb919 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 21d49871f2a..a3b97a1fe22 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 d024fbf88bc..67fc9fb0c00 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 82c0200029a..91ea91de917 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 015e99de06d..fd680d4d3eb 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 269d4299da3..d1fcd64c0f9 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 e388698a069..2fe45e41fe4 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 e56ac6e9670..223de75a6d1 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 b6264f1bc4c..669cbff22b7 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 a2bf24f6dfb..2c647fc2591 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 1e8e5b2d6e3..76921445c1d 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 a8b0f66edaa..3a6bba311b0 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 5bbe6837175..bf9da584643 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 c80b25c65b5..2f0970fe783 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 068c9ead98d..0e98ec467c3 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 cdbbed46792..a2e2faa1d1b 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 a38bdde8c14..864614e1931 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 cd3db777977..e51c6163378 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 0ea2aa190d8..124c7228ba8 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 75d3843fdc3..999c6295c70 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 1f59e163f75..34540dfc3df 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 f31dc5c1ad9..4264a787c15 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 7f33edb4724..e48cd267dda 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 7fa17a369f2..32998d6b787 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 8faa54ff16e..03d762d986e 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 e8e23e233c3..fbf08fa6f46 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 129d3f9a461..51f18bb50a3 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 23b2d04e7a9..e7038bb71bf 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 7b9a01b6e4c..c64e9e30045 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 ae9d06b3915..303a0b73175 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 8e9969d1239..c393d8a50bc 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 fdd213ff1ad..a7003d3a3c8 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 ddae20e9cd9..3f0ddd7afd3 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 26f114c5c0d..f3b86c8db67 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 f9f2fa2819b..9e65f07157a 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 4aa588bf6d6..65d0cfc3c33 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 7cdef6e6cc0..bf2cbdfe2e3 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 23b8c505c6a..b46cd8fe643 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 6ba8c368d10..d525df9ad86 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 31fc64cd17b..a4603d03537 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 e5ab071f635..33eb64333c6 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 125fc3949c1..21f4dd25c2e 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 bd78d6ac1e1..f944ad2cac2 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 06187e7db44..a6020eea7b9 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 5f9d546a86c..e74c571a5e4 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 8a3a643879d..adee8035ce9 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 ef90296bfd6..722597a20e4 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 5e8beee94de..0105d63c07a 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 c3907e211d3..753e43ec787 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 6813d110211..073694d50f4 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 92cc10d2f9c..f9a07578d98 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 7242ee66f6e..5039be782bc 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 4afe5774f19..f9733bb289d 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 bc38e34b9fd..53629fb0151 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 44093918cf0..4c149ef712d 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 1abafa5fd30..3d8a19cdb5a 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 ef5ba3f3273..f2c3b75d858 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 98ad085531f..454e0629569 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 20ac4e19fb3..5b9f9ec1368 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 f8190ead2e3..f9a2e0fabb9 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 295f3738e30..caeff85603e 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 8bf8df64b08..509299b90c9 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 4994d405c0a..3bd1de1f585 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 9e474a6024e..8bfc3e8d909 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 5f2a46e1f8f..390ce9431b3 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 bd8d021f40a..2852bf70506 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 d8a34c14676..2df1cba2360 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 666d4bb5b1f..29f900065d8 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 d285c8c9281..b303a3f8a9f 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 11fff97e719..117f9c4b4cb 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 5914390211f..12eedf4d515 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 b388654d48c..53c496c00fb 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 774715d2f84..8c775c59e12 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 dc5b07a20f6..59c797c1527 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 9e2f870f425..c6ff32a6137 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 5f6b5421371..5f6b5421371 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 aedde18c68f..aedde18c68f 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 09e99de5fd2..09e99de5fd2 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 c20d6dece15..c20d6dece15 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 af2ae7c5815..af2ae7c5815 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 8eb55b7b88c..8eb55b7b88c 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 9326a7c729e..9326a7c729e 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 6ace60313b4..6ace60313b4 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 a7fa38f9594..a7fa38f9594 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 29e43b03c85..29e43b03c85 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 4d3d0ce4078..4d3d0ce4078 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 60d197f5755..60d197f5755 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 1c1c228352d..1c1c228352d 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 fc780d0908d..fc780d0908d 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 6175e096185..6175e096185 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 a3fc25a4dc0..a3fc25a4dc0 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 5f05d153bc4..5f05d153bc4 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 2a724ddfa53..2a724ddfa53 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 d42dab59b66..d42dab59b66 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 c0b80068f46..c0b80068f46 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 268ec8aa6a6..268ec8aa6a6 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 084fc0899e1..4d6907cda75 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 d0d9538ca5b..d0d9538ca5b 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 db2615b2bac..2d2d0093282 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 b718a3a4bed..13c380ebb56 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 c29ac88ffd7..bd443ee76ff 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 c8b32c1c738..8051c295647 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 4240f0b720f..9b747c266af 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 2a1ac287591..82e819fa91c 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 9cb039e593d..a62322d5c0d 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 74861a4b601..23debc967d9 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 0382ea752e6..eec75bb5720 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 0fb75524484..41108a9a195 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 5d21d056d6a..05ab3700647 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 1141b976dff..80ec64d2d6d 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 9594b52f860..12897e8a331 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 4da9cca939c..e2b1029b16c 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 07af26e6beb..cf2c0fb95f2 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 30547cc3f89..0e78477452f 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 d2e0a50063a..32114a3c0ca 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 893a8b8f514..db74dd27c72 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 51b0fccbfe7..690ee0d42ee 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 c64e1dc4cb4..f080c162123 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 087db12a3a6..18e94c7d2be 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 ec2410c0c80..a803d9ea8fd 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 c8e958a07e9..f96f92f00f9 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 f0c3968ac7e..2e413174843 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 6cd21cf91b4..50838bf8420 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 30d8896bb71..9c5c19f142d 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 8a947e603ac..e87ae2f634b 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 eb97bff7116..45522e60318 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 678e1252047..b818cacf420 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 253fdcce2df..b0b0fa5a357 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 fa1d09b0ad9..904ca8c8b17 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 69161a682b3..0c5f1cb9d99 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 8068cefd8d8..a3c76bf1817 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 ba54d0acdec..58e0bc41489 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 1743856b30d..1163907bcdd 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 aba537af87e..ccb876fe023 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 fa943bd05c7..f54e775c2df 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 69f6af6f6b9..084ea77d65a 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 0bb0f8cd36f..50e593bfcfa 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 73290555226..68d539456c5 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 d86da94fa50..9b7c8654dc8 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 0cb8a9f9d67..d1000723c5a 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 53160aa24e6..08cbfa144e6 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 9ce2fa037b9..b5247cb64fd 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 349a4ad3ccc..bb37ec80f27 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 456d9ad9ae5..9f2d26b1d4c 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 397870f076c..9f6ce3d8a29 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 3681a6ff081..a4f99797eb5 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 f8a51b70792..6b33a972c83 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 edd1ffcca30..d9a9f7174f7 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 e799331389b..c6da8f77e1a 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 5a6f24d1246..122b45760f0 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 e72d5103e77..885ce11f222 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 ce7ac459527..6d666174dbb 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 360be226718..01ff643e682 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 d07df22a5ec..79fb22c89ae 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 847ccc067e8..9937386a3ba 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 00000000000..0df7f2a4181
--- /dev/null
+++ b/drivers/media/video/s5k6aa.c
@@ -0,0 +1,1681 @@
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/module.h>
23#include <linux/regulator/consumer.h>
24#include <linux/slab.h>
25
26#include <media/media-entity.h>
27#include <media/v4l2-ctrls.h>
28#include <media/v4l2-device.h>
29#include <media/v4l2-subdev.h>
30#include <media/v4l2-mediabus.h>
31#include <media/s5k6aa.h>
32
33static int debug;
34module_param(debug, int, 0644);
35
36#define DRIVER_NAME "S5K6AA"
37
38/* The token to indicate array termination */
39#define S5K6AA_TERM 0xffff
40#define S5K6AA_OUT_WIDTH_DEF 640
41#define S5K6AA_OUT_HEIGHT_DEF 480
42#define S5K6AA_WIN_WIDTH_MAX 1280
43#define S5K6AA_WIN_HEIGHT_MAX 1024
44#define S5K6AA_WIN_WIDTH_MIN 8
45#define S5K6AA_WIN_HEIGHT_MIN 8
46
47/*
48 * H/W register Interface (0xD0000000 - 0xD0000FFF)
49 */
50#define AHB_MSB_ADDR_PTR 0xfcfc
51#define GEN_REG_OFFSH 0xd000
52#define REG_CMDWR_ADDRH 0x0028
53#define REG_CMDWR_ADDRL 0x002a
54#define REG_CMDRD_ADDRH 0x002c
55#define REG_CMDRD_ADDRL 0x002e
56#define REG_CMDBUF0_ADDR 0x0f12
57#define REG_CMDBUF1_ADDR 0x0f10
58
59/*
60 * Host S/W Register interface (0x70000000 - 0x70002000)
61 * The value of the two most significant address bytes is 0x7000,
62 * (HOST_SWIF_OFFS_H). The register addresses below specify 2 LSBs.
63 */
64#define HOST_SWIF_OFFSH 0x7000
65
66/* Initialization parameters */
67/* Master clock frequency in KHz */
68#define REG_I_INCLK_FREQ_L 0x01b8
69#define REG_I_INCLK_FREQ_H 0x01ba
70#define MIN_MCLK_FREQ_KHZ 6000U
71#define MAX_MCLK_FREQ_KHZ 27000U
72#define REG_I_USE_NPVI_CLOCKS 0x01c6
73#define REG_I_USE_NMIPI_CLOCKS 0x01c8
74
75/* Clock configurations, n = 0..2. REG_I_* frequency unit is 4 kHz. */
76#define REG_I_OPCLK_4KHZ(n) ((n) * 6 + 0x01cc)
77#define REG_I_MIN_OUTRATE_4KHZ(n) ((n) * 6 + 0x01ce)
78#define REG_I_MAX_OUTRATE_4KHZ(n) ((n) * 6 + 0x01d0)
79#define SYS_PLL_OUT_FREQ (48000000 / 4000)
80#define PCLK_FREQ_MIN (24000000 / 4000)
81#define PCLK_FREQ_MAX (48000000 / 4000)
82#define REG_I_INIT_PARAMS_UPDATED 0x01e0
83#define REG_I_ERROR_INFO 0x01e2
84
85/* General purpose parameters */
86#define REG_USER_BRIGHTNESS 0x01e4
87#define REG_USER_CONTRAST 0x01e6
88#define REG_USER_SATURATION 0x01e8
89#define REG_USER_SHARPBLUR 0x01ea
90
91#define REG_G_SPEC_EFFECTS 0x01ee
92#define REG_G_ENABLE_PREV 0x01f0
93#define REG_G_ENABLE_PREV_CHG 0x01f2
94#define REG_G_NEW_CFG_SYNC 0x01f8
95#define REG_G_PREVZOOM_IN_WIDTH 0x020a
96#define REG_G_PREVZOOM_IN_HEIGHT 0x020c
97#define REG_G_PREVZOOM_IN_XOFFS 0x020e
98#define REG_G_PREVZOOM_IN_YOFFS 0x0210
99#define REG_G_INPUTS_CHANGE_REQ 0x021a
100#define REG_G_ACTIVE_PREV_CFG 0x021c
101#define REG_G_PREV_CFG_CHG 0x021e
102#define REG_G_PREV_OPEN_AFTER_CH 0x0220
103#define REG_G_PREV_CFG_ERROR 0x0222
104
105/* Preview control section. n = 0...4. */
106#define PREG(n, x) ((n) * 0x26 + x)
107#define REG_P_OUT_WIDTH(n) PREG(n, 0x0242)
108#define REG_P_OUT_HEIGHT(n) PREG(n, 0x0244)
109#define REG_P_FMT(n) PREG(n, 0x0246)
110#define REG_P_MAX_OUT_RATE(n) PREG(n, 0x0248)
111#define REG_P_MIN_OUT_RATE(n) PREG(n, 0x024a)
112#define REG_P_PVI_MASK(n) PREG(n, 0x024c)
113#define REG_P_CLK_INDEX(n) PREG(n, 0x024e)
114#define REG_P_FR_RATE_TYPE(n) PREG(n, 0x0250)
115#define FR_RATE_DYNAMIC 0
116#define FR_RATE_FIXED 1
117#define FR_RATE_FIXED_ACCURATE 2
118#define REG_P_FR_RATE_Q_TYPE(n) PREG(n, 0x0252)
119#define FR_RATE_Q_BEST_FRRATE 1 /* Binning enabled */
120#define FR_RATE_Q_BEST_QUALITY 2 /* Binning disabled */
121/* Frame period in 0.1 ms units */
122#define REG_P_MAX_FR_TIME(n) PREG(n, 0x0254)
123#define REG_P_MIN_FR_TIME(n) PREG(n, 0x0256)
124/* Conversion to REG_P_[MAX/MIN]_FR_TIME value; __t: time in us */
125#define US_TO_FR_TIME(__t) ((__t) / 100)
126#define S5K6AA_MIN_FR_TIME 33300 /* us */
127#define S5K6AA_MAX_FR_TIME 650000 /* us */
128#define S5K6AA_MAX_HIGHRES_FR_TIME 666 /* x100 us */
129/* The below 5 registers are for "device correction" values */
130#define REG_P_COLORTEMP(n) PREG(n, 0x025e)
131#define REG_P_PREV_MIRROR(n) PREG(n, 0x0262)
132
133/* Extended image property controls */
134/* Exposure time in 10 us units */
135#define REG_SF_USR_EXPOSURE_L 0x03c6
136#define REG_SF_USR_EXPOSURE_H 0x03c8
137#define REG_SF_USR_EXPOSURE_CHG 0x03ca
138#define REG_SF_USR_TOT_GAIN 0x03cc
139#define REG_SF_USR_TOT_GAIN_CHG 0x03ce
140#define REG_SF_RGAIN 0x03d0
141#define REG_SF_RGAIN_CHG 0x03d2
142#define REG_SF_GGAIN 0x03d4
143#define REG_SF_GGAIN_CHG 0x03d6
144#define REG_SF_BGAIN 0x03d8
145#define REG_SF_BGAIN_CHG 0x03da
146#define REG_SF_FLICKER_QUANT 0x03dc
147#define REG_SF_FLICKER_QUANT_CHG 0x03de
148
149/* Output interface (parallel/MIPI) setup */
150#define REG_OIF_EN_MIPI_LANES 0x03fa
151#define REG_OIF_EN_PACKETS 0x03fc
152#define REG_OIF_CFG_CHG 0x03fe
153
154/* Auto-algorithms enable mask */
155#define REG_DBG_AUTOALG_EN 0x0400
156#define AALG_ALL_EN_MASK (1 << 0)
157#define AALG_AE_EN_MASK (1 << 1)
158#define AALG_DIVLEI_EN_MASK (1 << 2)
159#define AALG_WB_EN_MASK (1 << 3)
160#define AALG_FLICKER_EN_MASK (1 << 5)
161#define AALG_FIT_EN_MASK (1 << 6)
162#define AALG_WRHW_EN_MASK (1 << 7)
163
164/* Firmware revision information */
165#define REG_FW_APIVER 0x012e
166#define S5K6AAFX_FW_APIVER 0x0001
167#define REG_FW_REVISION 0x0130
168
169/* For now we use only one user configuration register set */
170#define S5K6AA_MAX_PRESETS 1
171
172static const char * const s5k6aa_supply_names[] = {
173 "vdd_core", /* Digital core supply 1.5V (1.4V to 1.6V) */
174 "vdda", /* Analog power supply 2.8V (2.6V to 3.0V) */
175 "vdd_reg", /* Regulator input power 1.8V (1.7V to 1.9V)
176 or 2.8V (2.6V to 3.0) */
177 "vddio", /* I/O supply 1.8V (1.65V to 1.95V)
178 or 2.8V (2.5V to 3.1V) */
179};
180#define S5K6AA_NUM_SUPPLIES ARRAY_SIZE(s5k6aa_supply_names)
181
182enum s5k6aa_gpio_id {
183 STBY,
184 RST,
185 GPIO_NUM,
186};
187
188struct s5k6aa_regval {
189 u16 addr;
190 u16 val;
191};
192
193struct s5k6aa_pixfmt {
194 enum v4l2_mbus_pixelcode code;
195 u32 colorspace;
196 /* REG_P_FMT(x) register value */
197 u16 reg_p_fmt;
198};
199
200struct s5k6aa_preset {
201 /* output pixel format and resolution */
202 struct v4l2_mbus_framefmt mbus_fmt;
203 u8 clk_id;
204 u8 index;
205};
206
207struct s5k6aa_ctrls {
208 struct v4l2_ctrl_handler handler;
209 /* Auto / manual white balance cluster */
210 struct v4l2_ctrl *awb;
211 struct v4l2_ctrl *gain_red;
212 struct v4l2_ctrl *gain_blue;
213 struct v4l2_ctrl *gain_green;
214 /* Mirror cluster */
215 struct v4l2_ctrl *hflip;
216 struct v4l2_ctrl *vflip;
217 /* Auto exposure / manual exposure and gain cluster */
218 struct v4l2_ctrl *auto_exp;
219 struct v4l2_ctrl *exposure;
220 struct v4l2_ctrl *gain;
221};
222
223struct s5k6aa_interval {
224 u16 reg_fr_time;
225 struct v4l2_fract interval;
226 /* Maximum rectangle for the interval */
227 struct v4l2_frmsize_discrete size;
228};
229
230struct s5k6aa {
231 struct v4l2_subdev sd;
232 struct media_pad pad;
233
234 enum v4l2_mbus_type bus_type;
235 u8 mipi_lanes;
236
237 int (*s_power)(int enable);
238 struct regulator_bulk_data supplies[S5K6AA_NUM_SUPPLIES];
239 struct s5k6aa_gpio gpio[GPIO_NUM];
240
241 /* external master clock frequency */
242 unsigned long mclk_frequency;
243 /* ISP internal master clock frequency */
244 u16 clk_fop;
245 /* output pixel clock frequency range */
246 u16 pclk_fmin;
247 u16 pclk_fmax;
248
249 unsigned int inv_hflip:1;
250 unsigned int inv_vflip:1;
251
252 /* protects the struct members below */
253 struct mutex lock;
254
255 /* sensor matrix scan window */
256 struct v4l2_rect ccd_rect;
257
258 struct s5k6aa_ctrls ctrls;
259 struct s5k6aa_preset presets[S5K6AA_MAX_PRESETS];
260 struct s5k6aa_preset *preset;
261 const struct s5k6aa_interval *fiv;
262
263 unsigned int streaming:1;
264 unsigned int apply_cfg:1;
265 unsigned int apply_crop:1;
266 unsigned int power;
267};
268
269static struct s5k6aa_regval s5k6aa_analog_config[] = {
270 /* Analog settings */
271 { 0x112a, 0x0000 }, { 0x1132, 0x0000 },
272 { 0x113e, 0x0000 }, { 0x115c, 0x0000 },
273 { 0x1164, 0x0000 }, { 0x1174, 0x0000 },
274 { 0x1178, 0x0000 }, { 0x077a, 0x0000 },
275 { 0x077c, 0x0000 }, { 0x077e, 0x0000 },
276 { 0x0780, 0x0000 }, { 0x0782, 0x0000 },
277 { 0x0784, 0x0000 }, { 0x0786, 0x0000 },
278 { 0x0788, 0x0000 }, { 0x07a2, 0x0000 },
279 { 0x07a4, 0x0000 }, { 0x07a6, 0x0000 },
280 { 0x07a8, 0x0000 }, { 0x07b6, 0x0000 },
281 { 0x07b8, 0x0002 }, { 0x07ba, 0x0004 },
282 { 0x07bc, 0x0004 }, { 0x07be, 0x0005 },
283 { 0x07c0, 0x0005 }, { S5K6AA_TERM, 0 },
284};
285
286/* TODO: Add RGB888 and Bayer format */
287static const struct s5k6aa_pixfmt s5k6aa_formats[] = {
288 { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 5 },
289 /* range 16-240 */
290 { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_REC709, 6 },
291 { V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_JPEG, 0 },
292};
293
294static const struct s5k6aa_interval s5k6aa_intervals[] = {
295 { 1000, {10000, 1000000}, {1280, 1024} }, /* 10 fps */
296 { 666, {15000, 1000000}, {1280, 1024} }, /* 15 fps */
297 { 500, {20000, 1000000}, {1280, 720} }, /* 20 fps */
298 { 400, {25000, 1000000}, {640, 480} }, /* 25 fps */
299 { 333, {33300, 1000000}, {640, 480} }, /* 30 fps */
300};
301
302#define S5K6AA_INTERVAL_DEF_INDEX 1 /* 15 fps */
303
304static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
305{
306 return &container_of(ctrl->handler, struct s5k6aa, ctrls.handler)->sd;
307}
308
309static inline struct s5k6aa *to_s5k6aa(struct v4l2_subdev *sd)
310{
311 return container_of(sd, struct s5k6aa, sd);
312}
313
314/* Set initial values for all preview presets */
315static void s5k6aa_presets_data_init(struct s5k6aa *s5k6aa)
316{
317 struct s5k6aa_preset *preset = &s5k6aa->presets[0];
318 int i;
319
320 for (i = 0; i < S5K6AA_MAX_PRESETS; i++) {
321 preset->mbus_fmt.width = S5K6AA_OUT_WIDTH_DEF;
322 preset->mbus_fmt.height = S5K6AA_OUT_HEIGHT_DEF;
323 preset->mbus_fmt.code = s5k6aa_formats[0].code;
324 preset->index = i;
325 preset->clk_id = 0;
326 preset++;
327 }
328
329 s5k6aa->fiv = &s5k6aa_intervals[S5K6AA_INTERVAL_DEF_INDEX];
330 s5k6aa->preset = &s5k6aa->presets[0];
331}
332
333static int s5k6aa_i2c_read(struct i2c_client *client, u16 addr, u16 *val)
334{
335 u8 wbuf[2] = {addr >> 8, addr & 0xFF};
336 struct i2c_msg msg[2];
337 u8 rbuf[2];
338 int ret;
339
340 msg[0].addr = client->addr;
341 msg[0].flags = 0;
342 msg[0].len = 2;
343 msg[0].buf = wbuf;
344
345 msg[1].addr = client->addr;
346 msg[1].flags = I2C_M_RD;
347 msg[1].len = 2;
348 msg[1].buf = rbuf;
349
350 ret = i2c_transfer(client->adapter, msg, 2);
351 *val = be16_to_cpu(*((u16 *)rbuf));
352
353 v4l2_dbg(3, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val);
354
355 return ret == 2 ? 0 : ret;
356}
357
358static int s5k6aa_i2c_write(struct i2c_client *client, u16 addr, u16 val)
359{
360 u8 buf[4] = {addr >> 8, addr & 0xFF, val >> 8, val & 0xFF};
361
362 int ret = i2c_master_send(client, buf, 4);
363 v4l2_dbg(3, debug, client, "i2c_write: 0x%04X : 0x%04x\n", addr, val);
364
365 return ret == 4 ? 0 : ret;
366}
367
368/* The command register write, assumes Command_Wr_addH = 0x7000. */
369static int s5k6aa_write(struct i2c_client *c, u16 addr, u16 val)
370{
371 int ret = s5k6aa_i2c_write(c, REG_CMDWR_ADDRL, addr);
372 if (ret)
373 return ret;
374 return s5k6aa_i2c_write(c, REG_CMDBUF0_ADDR, val);
375}
376
377/* The command register read, assumes Command_Rd_addH = 0x7000. */
378static int s5k6aa_read(struct i2c_client *client, u16 addr, u16 *val)
379{
380 int ret = s5k6aa_i2c_write(client, REG_CMDRD_ADDRL, addr);
381 if (ret)
382 return ret;
383 return s5k6aa_i2c_read(client, REG_CMDBUF0_ADDR, val);
384}
385
386static int s5k6aa_write_array(struct v4l2_subdev *sd,
387 const struct s5k6aa_regval *msg)
388{
389 struct i2c_client *client = v4l2_get_subdevdata(sd);
390 u16 addr_incr = 0;
391 int ret = 0;
392
393 while (msg->addr != S5K6AA_TERM) {
394 if (addr_incr != 2)
395 ret = s5k6aa_i2c_write(client, REG_CMDWR_ADDRL,
396 msg->addr);
397 if (ret)
398 break;
399 ret = s5k6aa_i2c_write(client, REG_CMDBUF0_ADDR, msg->val);
400 if (ret)
401 break;
402 /* Assume that msg->addr is always less than 0xfffc */
403 addr_incr = (msg + 1)->addr - msg->addr;
404 msg++;
405 }
406
407 return ret;
408}
409
410/* Configure the AHB high address bytes for GTG registers access */
411static int s5k6aa_set_ahb_address(struct i2c_client *client)
412{
413 int ret = s5k6aa_i2c_write(client, AHB_MSB_ADDR_PTR, GEN_REG_OFFSH);
414 if (ret)
415 return ret;
416 ret = s5k6aa_i2c_write(client, REG_CMDRD_ADDRH, HOST_SWIF_OFFSH);
417 if (ret)
418 return ret;
419 return s5k6aa_i2c_write(client, REG_CMDWR_ADDRH, HOST_SWIF_OFFSH);
420}
421
422/**
423 * s5k6aa_configure_pixel_clock - apply ISP main clock/PLL configuration
424 *
425 * Configure the internal ISP PLL for the required output frequency.
426 * Locking: called with s5k6aa.lock mutex held.
427 */
428static int s5k6aa_configure_pixel_clocks(struct s5k6aa *s5k6aa)
429{
430 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
431 unsigned long fmclk = s5k6aa->mclk_frequency / 1000;
432 u16 status;
433 int ret;
434
435 if (WARN(fmclk < MIN_MCLK_FREQ_KHZ || fmclk > MAX_MCLK_FREQ_KHZ,
436 "Invalid clock frequency: %ld\n", fmclk))
437 return -EINVAL;
438
439 s5k6aa->pclk_fmin = PCLK_FREQ_MIN;
440 s5k6aa->pclk_fmax = PCLK_FREQ_MAX;
441 s5k6aa->clk_fop = SYS_PLL_OUT_FREQ;
442
443 /* External input clock frequency in kHz */
444 ret = s5k6aa_write(c, REG_I_INCLK_FREQ_H, fmclk >> 16);
445 if (!ret)
446 ret = s5k6aa_write(c, REG_I_INCLK_FREQ_L, fmclk & 0xFFFF);
447 if (!ret)
448 ret = s5k6aa_write(c, REG_I_USE_NPVI_CLOCKS, 1);
449 /* Internal PLL frequency */
450 if (!ret)
451 ret = s5k6aa_write(c, REG_I_OPCLK_4KHZ(0), s5k6aa->clk_fop);
452 if (!ret)
453 ret = s5k6aa_write(c, REG_I_MIN_OUTRATE_4KHZ(0),
454 s5k6aa->pclk_fmin);
455 if (!ret)
456 ret = s5k6aa_write(c, REG_I_MAX_OUTRATE_4KHZ(0),
457 s5k6aa->pclk_fmax);
458 if (!ret)
459 ret = s5k6aa_write(c, REG_I_INIT_PARAMS_UPDATED, 1);
460 if (!ret)
461 ret = s5k6aa_read(c, REG_I_ERROR_INFO, &status);
462
463 return ret ? ret : (status ? -EINVAL : 0);
464}
465
466/* Set horizontal and vertical image flipping */
467static int s5k6aa_set_mirror(struct s5k6aa *s5k6aa, int horiz_flip)
468{
469 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
470 int index = s5k6aa->preset->index;
471
472 unsigned int vflip = s5k6aa->ctrls.vflip->val ^ s5k6aa->inv_vflip;
473 unsigned int flip = (horiz_flip ^ s5k6aa->inv_hflip) | (vflip << 1);
474
475 return s5k6aa_write(client, REG_P_PREV_MIRROR(index), flip);
476}
477
478/* Configure auto/manual white balance and R/G/B gains */
479static int s5k6aa_set_awb(struct s5k6aa *s5k6aa, int awb)
480{
481 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
482 struct s5k6aa_ctrls *ctrls = &s5k6aa->ctrls;
483 u16 reg;
484
485 int ret = s5k6aa_read(c, REG_DBG_AUTOALG_EN, &reg);
486
487 if (!ret && !awb) {
488 ret = s5k6aa_write(c, REG_SF_RGAIN, ctrls->gain_red->val);
489 if (!ret)
490 ret = s5k6aa_write(c, REG_SF_RGAIN_CHG, 1);
491 if (ret)
492 return ret;
493
494 ret = s5k6aa_write(c, REG_SF_GGAIN, ctrls->gain_green->val);
495 if (!ret)
496 ret = s5k6aa_write(c, REG_SF_GGAIN_CHG, 1);
497 if (ret)
498 return ret;
499
500 ret = s5k6aa_write(c, REG_SF_BGAIN, ctrls->gain_blue->val);
501 if (!ret)
502 ret = s5k6aa_write(c, REG_SF_BGAIN_CHG, 1);
503 }
504 if (!ret) {
505 reg = awb ? reg | AALG_WB_EN_MASK : reg & ~AALG_WB_EN_MASK;
506 ret = s5k6aa_write(c, REG_DBG_AUTOALG_EN, reg);
507 }
508
509 return ret;
510}
511
512/* Program FW with exposure time, 'exposure' in us units */
513static int s5k6aa_set_user_exposure(struct i2c_client *client, int exposure)
514{
515 unsigned int time = exposure / 10;
516
517 int ret = s5k6aa_write(client, REG_SF_USR_EXPOSURE_L, time & 0xffff);
518 if (!ret)
519 ret = s5k6aa_write(client, REG_SF_USR_EXPOSURE_H, time >> 16);
520 if (ret)
521 return ret;
522 return s5k6aa_write(client, REG_SF_USR_EXPOSURE_CHG, 1);
523}
524
525static int s5k6aa_set_user_gain(struct i2c_client *client, int gain)
526{
527 int ret = s5k6aa_write(client, REG_SF_USR_TOT_GAIN, gain);
528 if (ret)
529 return ret;
530 return s5k6aa_write(client, REG_SF_USR_TOT_GAIN_CHG, 1);
531}
532
533/* Set auto/manual exposure and total gain */
534static int s5k6aa_set_auto_exposure(struct s5k6aa *s5k6aa, int value)
535{
536 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
537 unsigned int exp_time = s5k6aa->ctrls.exposure->val;
538 u16 auto_alg;
539
540 int ret = s5k6aa_read(c, REG_DBG_AUTOALG_EN, &auto_alg);
541 if (ret)
542 return ret;
543
544 v4l2_dbg(1, debug, c, "man_exp: %d, auto_exp: %d, a_alg: 0x%x\n",
545 exp_time, value, auto_alg);
546
547 if (value == V4L2_EXPOSURE_AUTO) {
548 auto_alg |= AALG_AE_EN_MASK | AALG_DIVLEI_EN_MASK;
549 } else {
550 ret = s5k6aa_set_user_exposure(c, exp_time);
551 if (ret)
552 return ret;
553 ret = s5k6aa_set_user_gain(c, s5k6aa->ctrls.gain->val);
554 if (ret)
555 return ret;
556 auto_alg &= ~(AALG_AE_EN_MASK | AALG_DIVLEI_EN_MASK);
557 }
558
559 return s5k6aa_write(c, REG_DBG_AUTOALG_EN, auto_alg);
560}
561
562static int s5k6aa_set_anti_flicker(struct s5k6aa *s5k6aa, int value)
563{
564 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
565 u16 auto_alg;
566 int ret;
567
568 ret = s5k6aa_read(client, REG_DBG_AUTOALG_EN, &auto_alg);
569 if (ret)
570 return ret;
571
572 if (value == V4L2_CID_POWER_LINE_FREQUENCY_AUTO) {
573 auto_alg |= AALG_FLICKER_EN_MASK;
574 } else {
575 auto_alg &= ~AALG_FLICKER_EN_MASK;
576 /* The V4L2_CID_LINE_FREQUENCY control values match
577 * the register values */
578 ret = s5k6aa_write(client, REG_SF_FLICKER_QUANT, value);
579 if (ret)
580 return ret;
581 ret = s5k6aa_write(client, REG_SF_FLICKER_QUANT_CHG, 1);
582 if (ret)
583 return ret;
584 }
585
586 return s5k6aa_write(client, REG_DBG_AUTOALG_EN, auto_alg);
587}
588
589static int s5k6aa_set_colorfx(struct s5k6aa *s5k6aa, int val)
590{
591 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
592 static const struct v4l2_control colorfx[] = {
593 { V4L2_COLORFX_NONE, 0 },
594 { V4L2_COLORFX_BW, 1 },
595 { V4L2_COLORFX_NEGATIVE, 2 },
596 { V4L2_COLORFX_SEPIA, 3 },
597 { V4L2_COLORFX_SKY_BLUE, 4 },
598 { V4L2_COLORFX_SKETCH, 5 },
599 };
600 int i;
601
602 for (i = 0; i < ARRAY_SIZE(colorfx); i++) {
603 if (colorfx[i].id == val)
604 return s5k6aa_write(client, REG_G_SPEC_EFFECTS,
605 colorfx[i].value);
606 }
607 return -EINVAL;
608}
609
610static int s5k6aa_preview_config_status(struct i2c_client *client)
611{
612 u16 error = 0;
613 int ret = s5k6aa_read(client, REG_G_PREV_CFG_ERROR, &error);
614
615 v4l2_dbg(1, debug, client, "error: 0x%x (%d)\n", error, ret);
616 return ret ? ret : (error ? -EINVAL : 0);
617}
618
619static int s5k6aa_get_pixfmt_index(struct s5k6aa *s5k6aa,
620 struct v4l2_mbus_framefmt *mf)
621{
622 unsigned int i;
623
624 for (i = 0; i < ARRAY_SIZE(s5k6aa_formats); i++)
625 if (mf->colorspace == s5k6aa_formats[i].colorspace &&
626 mf->code == s5k6aa_formats[i].code)
627 return i;
628 return 0;
629}
630
631static int s5k6aa_set_output_framefmt(struct s5k6aa *s5k6aa,
632 struct s5k6aa_preset *preset)
633{
634 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
635 int fmt_index = s5k6aa_get_pixfmt_index(s5k6aa, &preset->mbus_fmt);
636 int ret;
637
638 ret = s5k6aa_write(client, REG_P_OUT_WIDTH(preset->index),
639 preset->mbus_fmt.width);
640 if (!ret)
641 ret = s5k6aa_write(client, REG_P_OUT_HEIGHT(preset->index),
642 preset->mbus_fmt.height);
643 if (!ret)
644 ret = s5k6aa_write(client, REG_P_FMT(preset->index),
645 s5k6aa_formats[fmt_index].reg_p_fmt);
646 return ret;
647}
648
649static int s5k6aa_set_input_params(struct s5k6aa *s5k6aa)
650{
651 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
652 struct v4l2_rect *r = &s5k6aa->ccd_rect;
653 int ret;
654
655 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_WIDTH, r->width);
656 if (!ret)
657 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_HEIGHT, r->height);
658 if (!ret)
659 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_XOFFS, r->left);
660 if (!ret)
661 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_YOFFS, r->top);
662 if (!ret)
663 ret = s5k6aa_write(c, REG_G_INPUTS_CHANGE_REQ, 1);
664 if (!ret)
665 s5k6aa->apply_crop = 0;
666
667 return ret;
668}
669
670/**
671 * s5k6aa_configure_video_bus - configure the video output interface
672 * @bus_type: video bus type: parallel or MIPI-CSI
673 * @nlanes: number of MIPI lanes to be used (MIPI-CSI only)
674 *
675 * Note: Only parallel bus operation has been tested.
676 */
677static int s5k6aa_configure_video_bus(struct s5k6aa *s5k6aa,
678 enum v4l2_mbus_type bus_type, int nlanes)
679{
680 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
681 u16 cfg = 0;
682 int ret;
683
684 /*
685 * TODO: The sensor is supposed to support BT.601 and BT.656
686 * but there is nothing indicating how to switch between both
687 * in the datasheet. For now default BT.601 interface is assumed.
688 */
689 if (bus_type == V4L2_MBUS_CSI2)
690 cfg = nlanes;
691 else if (bus_type != V4L2_MBUS_PARALLEL)
692 return -EINVAL;
693
694 ret = s5k6aa_write(client, REG_OIF_EN_MIPI_LANES, cfg);
695 if (ret)
696 return ret;
697 return s5k6aa_write(client, REG_OIF_CFG_CHG, 1);
698}
699
700/* This function should be called when switching to new user configuration set*/
701static int s5k6aa_new_config_sync(struct i2c_client *client, int timeout,
702 int cid)
703{
704 unsigned long end = jiffies + msecs_to_jiffies(timeout);
705 u16 reg = 1;
706 int ret;
707
708 ret = s5k6aa_write(client, REG_G_ACTIVE_PREV_CFG, cid);
709 if (!ret)
710 ret = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
711 if (!ret)
712 ret = s5k6aa_write(client, REG_G_NEW_CFG_SYNC, 1);
713 if (timeout == 0)
714 return ret;
715
716 while (ret >= 0 && time_is_after_jiffies(end)) {
717 ret = s5k6aa_read(client, REG_G_NEW_CFG_SYNC, &reg);
718 if (!reg)
719 return 0;
720 usleep_range(1000, 5000);
721 }
722 return ret ? ret : -ETIMEDOUT;
723}
724
725/**
726 * s5k6aa_set_prev_config - write user preview register set
727 *
728 * Configure output resolution and color fromat, pixel clock
729 * frequency range, device frame rate type and frame period range.
730 */
731static int s5k6aa_set_prev_config(struct s5k6aa *s5k6aa,
732 struct s5k6aa_preset *preset)
733{
734 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
735 int idx = preset->index;
736 u16 frame_rate_q;
737 int ret;
738
739 if (s5k6aa->fiv->reg_fr_time >= S5K6AA_MAX_HIGHRES_FR_TIME)
740 frame_rate_q = FR_RATE_Q_BEST_FRRATE;
741 else
742 frame_rate_q = FR_RATE_Q_BEST_QUALITY;
743
744 ret = s5k6aa_set_output_framefmt(s5k6aa, preset);
745 if (!ret)
746 ret = s5k6aa_write(client, REG_P_MAX_OUT_RATE(idx),
747 s5k6aa->pclk_fmax);
748 if (!ret)
749 ret = s5k6aa_write(client, REG_P_MIN_OUT_RATE(idx),
750 s5k6aa->pclk_fmin);
751 if (!ret)
752 ret = s5k6aa_write(client, REG_P_CLK_INDEX(idx),
753 preset->clk_id);
754 if (!ret)
755 ret = s5k6aa_write(client, REG_P_FR_RATE_TYPE(idx),
756 FR_RATE_DYNAMIC);
757 if (!ret)
758 ret = s5k6aa_write(client, REG_P_FR_RATE_Q_TYPE(idx),
759 frame_rate_q);
760 if (!ret)
761 ret = s5k6aa_write(client, REG_P_MAX_FR_TIME(idx),
762 s5k6aa->fiv->reg_fr_time + 33);
763 if (!ret)
764 ret = s5k6aa_write(client, REG_P_MIN_FR_TIME(idx),
765 s5k6aa->fiv->reg_fr_time - 33);
766 if (!ret)
767 ret = s5k6aa_new_config_sync(client, 250, idx);
768 if (!ret)
769 ret = s5k6aa_preview_config_status(client);
770 if (!ret)
771 s5k6aa->apply_cfg = 0;
772
773 v4l2_dbg(1, debug, client, "Frame interval: %d +/- 3.3ms. (%d)\n",
774 s5k6aa->fiv->reg_fr_time, ret);
775 return ret;
776}
777
778/**
779 * s5k6aa_initialize_isp - basic ISP MCU initialization
780 *
781 * Configure AHB addresses for registers read/write; configure PLLs for
782 * required output pixel clock. The ISP power supply needs to be already
783 * enabled, with an optional H/W reset.
784 * Locking: called with s5k6aa.lock mutex held.
785 */
786static int s5k6aa_initialize_isp(struct v4l2_subdev *sd)
787{
788 struct i2c_client *client = v4l2_get_subdevdata(sd);
789 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
790 int ret;
791
792 s5k6aa->apply_crop = 1;
793 s5k6aa->apply_cfg = 1;
794 msleep(100);
795
796 ret = s5k6aa_set_ahb_address(client);
797 if (ret)
798 return ret;
799 ret = s5k6aa_configure_video_bus(s5k6aa, s5k6aa->bus_type,
800 s5k6aa->mipi_lanes);
801 if (ret)
802 return ret;
803 ret = s5k6aa_write_array(sd, s5k6aa_analog_config);
804 if (ret)
805 return ret;
806 msleep(20);
807
808 return s5k6aa_configure_pixel_clocks(s5k6aa);
809}
810
811static int s5k6aa_gpio_set_value(struct s5k6aa *priv, int id, u32 val)
812{
813 if (!gpio_is_valid(priv->gpio[id].gpio))
814 return 0;
815 gpio_set_value(priv->gpio[id].gpio, !!val);
816 return 1;
817}
818
819static int s5k6aa_gpio_assert(struct s5k6aa *priv, int id)
820{
821 return s5k6aa_gpio_set_value(priv, id, priv->gpio[id].level);
822}
823
824static int s5k6aa_gpio_deassert(struct s5k6aa *priv, int id)
825{
826 return s5k6aa_gpio_set_value(priv, id, !priv->gpio[id].level);
827}
828
829static int __s5k6aa_power_on(struct s5k6aa *s5k6aa)
830{
831 int ret;
832
833 ret = regulator_bulk_enable(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
834 if (ret)
835 return ret;
836 if (s5k6aa_gpio_deassert(s5k6aa, STBY))
837 usleep_range(150, 200);
838
839 if (s5k6aa->s_power)
840 ret = s5k6aa->s_power(1);
841 usleep_range(4000, 4000);
842
843 if (s5k6aa_gpio_deassert(s5k6aa, RST))
844 msleep(20);
845
846 return ret;
847}
848
849static int __s5k6aa_power_off(struct s5k6aa *s5k6aa)
850{
851 int ret;
852
853 if (s5k6aa_gpio_assert(s5k6aa, RST))
854 usleep_range(100, 150);
855
856 if (s5k6aa->s_power) {
857 ret = s5k6aa->s_power(0);
858 if (ret)
859 return ret;
860 }
861 if (s5k6aa_gpio_assert(s5k6aa, STBY))
862 usleep_range(50, 100);
863 s5k6aa->streaming = 0;
864
865 return regulator_bulk_disable(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
866}
867
868/*
869 * V4L2 subdev core and video operations
870 */
871static int s5k6aa_set_power(struct v4l2_subdev *sd, int on)
872{
873 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
874 int ret = 0;
875
876 mutex_lock(&s5k6aa->lock);
877
878 if (!on == s5k6aa->power) {
879 if (on) {
880 ret = __s5k6aa_power_on(s5k6aa);
881 if (!ret)
882 ret = s5k6aa_initialize_isp(sd);
883 } else {
884 ret = __s5k6aa_power_off(s5k6aa);
885 }
886
887 if (!ret)
888 s5k6aa->power += on ? 1 : -1;
889 }
890
891 mutex_unlock(&s5k6aa->lock);
892
893 if (!on || ret || s5k6aa->power != 1)
894 return ret;
895
896 return v4l2_ctrl_handler_setup(sd->ctrl_handler);
897}
898
899static int __s5k6aa_stream(struct s5k6aa *s5k6aa, int enable)
900{
901 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
902 int ret = 0;
903
904 ret = s5k6aa_write(client, REG_G_ENABLE_PREV, enable);
905 if (!ret)
906 ret = s5k6aa_write(client, REG_G_ENABLE_PREV_CHG, 1);
907 if (!ret)
908 s5k6aa->streaming = enable;
909
910 return ret;
911}
912
913static int s5k6aa_s_stream(struct v4l2_subdev *sd, int on)
914{
915 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
916 int ret = 0;
917
918 mutex_lock(&s5k6aa->lock);
919
920 if (s5k6aa->streaming == !on) {
921 if (!ret && s5k6aa->apply_cfg)
922 ret = s5k6aa_set_prev_config(s5k6aa, s5k6aa->preset);
923 if (s5k6aa->apply_crop)
924 ret = s5k6aa_set_input_params(s5k6aa);
925 if (!ret)
926 ret = __s5k6aa_stream(s5k6aa, !!on);
927 }
928 mutex_unlock(&s5k6aa->lock);
929
930 return ret;
931}
932
933static int s5k6aa_g_frame_interval(struct v4l2_subdev *sd,
934 struct v4l2_subdev_frame_interval *fi)
935{
936 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
937
938 mutex_lock(&s5k6aa->lock);
939 fi->interval = s5k6aa->fiv->interval;
940 mutex_unlock(&s5k6aa->lock);
941
942 return 0;
943}
944
945static int __s5k6aa_set_frame_interval(struct s5k6aa *s5k6aa,
946 struct v4l2_subdev_frame_interval *fi)
947{
948 struct v4l2_mbus_framefmt *mbus_fmt = &s5k6aa->preset->mbus_fmt;
949 const struct s5k6aa_interval *fiv = &s5k6aa_intervals[0];
950 unsigned int err, min_err = UINT_MAX;
951 unsigned int i, fr_time;
952
953 if (fi->interval.denominator == 0)
954 return -EINVAL;
955
956 fr_time = fi->interval.numerator * 10000 / fi->interval.denominator;
957
958 for (i = 0; i < ARRAY_SIZE(s5k6aa_intervals); i++) {
959 const struct s5k6aa_interval *iv = &s5k6aa_intervals[i];
960
961 if (mbus_fmt->width > iv->size.width ||
962 mbus_fmt->height > iv->size.height)
963 continue;
964
965 err = abs(iv->reg_fr_time - fr_time);
966 if (err < min_err) {
967 fiv = iv;
968 min_err = err;
969 }
970 }
971 s5k6aa->fiv = fiv;
972
973 v4l2_dbg(1, debug, &s5k6aa->sd, "Changed frame interval to %d us\n",
974 fiv->reg_fr_time * 100);
975 return 0;
976}
977
978static int s5k6aa_s_frame_interval(struct v4l2_subdev *sd,
979 struct v4l2_subdev_frame_interval *fi)
980{
981 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
982 int ret;
983
984 v4l2_dbg(1, debug, sd, "Setting %d/%d frame interval\n",
985 fi->interval.numerator, fi->interval.denominator);
986
987 mutex_lock(&s5k6aa->lock);
988 ret = __s5k6aa_set_frame_interval(s5k6aa, fi);
989 s5k6aa->apply_cfg = 1;
990
991 mutex_unlock(&s5k6aa->lock);
992 return ret;
993}
994
995/*
996 * V4L2 subdev pad level and video operations
997 */
998static int s5k6aa_enum_frame_interval(struct v4l2_subdev *sd,
999 struct v4l2_subdev_fh *fh,
1000 struct v4l2_subdev_frame_interval_enum *fie)
1001{
1002 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1003 const struct s5k6aa_interval *fi;
1004 int ret = 0;
1005
1006 if (fie->index > ARRAY_SIZE(s5k6aa_intervals))
1007 return -EINVAL;
1008
1009 v4l_bound_align_image(&fie->width, S5K6AA_WIN_WIDTH_MIN,
1010 S5K6AA_WIN_WIDTH_MAX, 1,
1011 &fie->height, S5K6AA_WIN_HEIGHT_MIN,
1012 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1013
1014 mutex_lock(&s5k6aa->lock);
1015 fi = &s5k6aa_intervals[fie->index];
1016 if (fie->width > fi->size.width || fie->height > fi->size.height)
1017 ret = -EINVAL;
1018 else
1019 fie->interval = fi->interval;
1020 mutex_unlock(&s5k6aa->lock);
1021
1022 return ret;
1023}
1024
1025static int s5k6aa_enum_mbus_code(struct v4l2_subdev *sd,
1026 struct v4l2_subdev_fh *fh,
1027 struct v4l2_subdev_mbus_code_enum *code)
1028{
1029 if (code->index >= ARRAY_SIZE(s5k6aa_formats))
1030 return -EINVAL;
1031
1032 code->code = s5k6aa_formats[code->index].code;
1033 return 0;
1034}
1035
1036static int s5k6aa_enum_frame_size(struct v4l2_subdev *sd,
1037 struct v4l2_subdev_fh *fh,
1038 struct v4l2_subdev_frame_size_enum *fse)
1039{
1040 int i = ARRAY_SIZE(s5k6aa_formats);
1041
1042 if (fse->index > 0)
1043 return -EINVAL;
1044
1045 while (--i)
1046 if (fse->code == s5k6aa_formats[i].code)
1047 break;
1048
1049 fse->code = s5k6aa_formats[i].code;
1050 fse->min_width = S5K6AA_WIN_WIDTH_MIN;
1051 fse->max_width = S5K6AA_WIN_WIDTH_MAX;
1052 fse->max_height = S5K6AA_WIN_HEIGHT_MIN;
1053 fse->min_height = S5K6AA_WIN_HEIGHT_MAX;
1054
1055 return 0;
1056}
1057
1058static struct v4l2_rect *
1059__s5k6aa_get_crop_rect(struct s5k6aa *s5k6aa, struct v4l2_subdev_fh *fh,
1060 enum v4l2_subdev_format_whence which)
1061{
1062 if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
1063 return &s5k6aa->ccd_rect;
1064 if (which == V4L2_SUBDEV_FORMAT_TRY)
1065 return v4l2_subdev_get_try_crop(fh, 0);
1066
1067 return NULL;
1068}
1069
1070static void s5k6aa_try_format(struct s5k6aa *s5k6aa,
1071 struct v4l2_mbus_framefmt *mf)
1072{
1073 unsigned int index;
1074
1075 v4l_bound_align_image(&mf->width, S5K6AA_WIN_WIDTH_MIN,
1076 S5K6AA_WIN_WIDTH_MAX, 1,
1077 &mf->height, S5K6AA_WIN_HEIGHT_MIN,
1078 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1079
1080 if (mf->colorspace != V4L2_COLORSPACE_JPEG &&
1081 mf->colorspace != V4L2_COLORSPACE_REC709)
1082 mf->colorspace = V4L2_COLORSPACE_JPEG;
1083
1084 index = s5k6aa_get_pixfmt_index(s5k6aa, mf);
1085
1086 mf->colorspace = s5k6aa_formats[index].colorspace;
1087 mf->code = s5k6aa_formats[index].code;
1088 mf->field = V4L2_FIELD_NONE;
1089}
1090
1091static int s5k6aa_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1092 struct v4l2_subdev_format *fmt)
1093{
1094 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1095 struct v4l2_mbus_framefmt *mf;
1096
1097 memset(fmt->reserved, 0, sizeof(fmt->reserved));
1098
1099 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1100 mf = v4l2_subdev_get_try_format(fh, 0);
1101 fmt->format = *mf;
1102 return 0;
1103 }
1104
1105 mutex_lock(&s5k6aa->lock);
1106 fmt->format = s5k6aa->preset->mbus_fmt;
1107 mutex_unlock(&s5k6aa->lock);
1108
1109 return 0;
1110}
1111
1112static int s5k6aa_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1113 struct v4l2_subdev_format *fmt)
1114{
1115 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1116 struct s5k6aa_preset *preset = s5k6aa->preset;
1117 struct v4l2_mbus_framefmt *mf;
1118 struct v4l2_rect *crop;
1119 int ret = 0;
1120
1121 mutex_lock(&s5k6aa->lock);
1122 s5k6aa_try_format(s5k6aa, &fmt->format);
1123
1124 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1125 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1126 crop = v4l2_subdev_get_try_crop(fh, 0);
1127 } else {
1128 if (s5k6aa->streaming) {
1129 ret = -EBUSY;
1130 } else {
1131 mf = &preset->mbus_fmt;
1132 crop = &s5k6aa->ccd_rect;
1133 s5k6aa->apply_cfg = 1;
1134 }
1135 }
1136
1137 if (ret == 0) {
1138 struct v4l2_subdev_frame_interval fiv = {
1139 .interval = {0, 1}
1140 };
1141
1142 *mf = fmt->format;
1143 /*
1144 * Make sure the crop window is valid, i.e. its size is
1145 * greater than the output window, as the ISP supports
1146 * only down-scaling.
1147 */
1148 crop->width = clamp_t(unsigned int, crop->width, mf->width,
1149 S5K6AA_WIN_WIDTH_MAX);
1150 crop->height = clamp_t(unsigned int, crop->height, mf->height,
1151 S5K6AA_WIN_HEIGHT_MAX);
1152 crop->left = clamp_t(unsigned int, crop->left, 0,
1153 S5K6AA_WIN_WIDTH_MAX - crop->width);
1154 crop->top = clamp_t(unsigned int, crop->top, 0,
1155 S5K6AA_WIN_HEIGHT_MAX - crop->height);
1156
1157 /* Reset to minimum possible frame interval */
1158 ret = __s5k6aa_set_frame_interval(s5k6aa, &fiv);
1159 }
1160 mutex_unlock(&s5k6aa->lock);
1161
1162 return ret;
1163}
1164
1165static int s5k6aa_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1166 struct v4l2_subdev_crop *crop)
1167{
1168 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1169 struct v4l2_rect *rect;
1170
1171 memset(crop->reserved, 0, sizeof(crop->reserved));
1172 mutex_lock(&s5k6aa->lock);
1173
1174 rect = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which);
1175 if (rect)
1176 crop->rect = *rect;
1177
1178 mutex_unlock(&s5k6aa->lock);
1179
1180 v4l2_dbg(1, debug, sd, "Current crop rectangle: (%d,%d)/%dx%d\n",
1181 rect->left, rect->top, rect->width, rect->height);
1182
1183 return 0;
1184}
1185
1186static int s5k6aa_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1187 struct v4l2_subdev_crop *crop)
1188{
1189 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1190 struct v4l2_mbus_framefmt *mf;
1191 unsigned int max_x, max_y;
1192 struct v4l2_rect *crop_r;
1193
1194 mutex_lock(&s5k6aa->lock);
1195 crop_r = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which);
1196
1197 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1198 mf = &s5k6aa->preset->mbus_fmt;
1199 s5k6aa->apply_crop = 1;
1200 } else {
1201 mf = v4l2_subdev_get_try_format(fh, 0);
1202 }
1203 v4l_bound_align_image(&crop->rect.width, mf->width,
1204 S5K6AA_WIN_WIDTH_MAX, 1,
1205 &crop->rect.height, mf->height,
1206 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1207
1208 max_x = (S5K6AA_WIN_WIDTH_MAX - crop->rect.width) & ~1;
1209 max_y = (S5K6AA_WIN_HEIGHT_MAX - crop->rect.height) & ~1;
1210
1211 crop->rect.left = clamp_t(unsigned int, crop->rect.left, 0, max_x);
1212 crop->rect.top = clamp_t(unsigned int, crop->rect.top, 0, max_y);
1213
1214 *crop_r = crop->rect;
1215
1216 mutex_unlock(&s5k6aa->lock);
1217
1218 v4l2_dbg(1, debug, sd, "Set crop rectangle: (%d,%d)/%dx%d\n",
1219 crop_r->left, crop_r->top, crop_r->width, crop_r->height);
1220
1221 return 0;
1222}
1223
1224static const struct v4l2_subdev_pad_ops s5k6aa_pad_ops = {
1225 .enum_mbus_code = s5k6aa_enum_mbus_code,
1226 .enum_frame_size = s5k6aa_enum_frame_size,
1227 .enum_frame_interval = s5k6aa_enum_frame_interval,
1228 .get_fmt = s5k6aa_get_fmt,
1229 .set_fmt = s5k6aa_set_fmt,
1230 .get_crop = s5k6aa_get_crop,
1231 .set_crop = s5k6aa_set_crop,
1232};
1233
1234static const struct v4l2_subdev_video_ops s5k6aa_video_ops = {
1235 .g_frame_interval = s5k6aa_g_frame_interval,
1236 .s_frame_interval = s5k6aa_s_frame_interval,
1237 .s_stream = s5k6aa_s_stream,
1238};
1239
1240/*
1241 * V4L2 subdev controls
1242 */
1243
1244static int s5k6aa_s_ctrl(struct v4l2_ctrl *ctrl)
1245{
1246 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
1247 struct i2c_client *client = v4l2_get_subdevdata(sd);
1248 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1249 int idx, err = 0;
1250
1251 v4l2_dbg(1, debug, sd, "ctrl: 0x%x, value: %d\n", ctrl->id, ctrl->val);
1252
1253 mutex_lock(&s5k6aa->lock);
1254 /*
1255 * If the device is not powered up by the host driver do
1256 * not apply any controls to H/W at this time. Instead
1257 * the controls will be restored right after power-up.
1258 */
1259 if (s5k6aa->power == 0)
1260 goto unlock;
1261 idx = s5k6aa->preset->index;
1262
1263 switch (ctrl->id) {
1264 case V4L2_CID_AUTO_WHITE_BALANCE:
1265 err = s5k6aa_set_awb(s5k6aa, ctrl->val);
1266 break;
1267
1268 case V4L2_CID_BRIGHTNESS:
1269 err = s5k6aa_write(client, REG_USER_BRIGHTNESS, ctrl->val);
1270 break;
1271
1272 case V4L2_CID_COLORFX:
1273 err = s5k6aa_set_colorfx(s5k6aa, ctrl->val);
1274 break;
1275
1276 case V4L2_CID_CONTRAST:
1277 err = s5k6aa_write(client, REG_USER_CONTRAST, ctrl->val);
1278 break;
1279
1280 case V4L2_CID_EXPOSURE_AUTO:
1281 err = s5k6aa_set_auto_exposure(s5k6aa, ctrl->val);
1282 break;
1283
1284 case V4L2_CID_HFLIP:
1285 err = s5k6aa_set_mirror(s5k6aa, ctrl->val);
1286 if (err)
1287 break;
1288 err = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
1289 break;
1290
1291 case V4L2_CID_POWER_LINE_FREQUENCY:
1292 err = s5k6aa_set_anti_flicker(s5k6aa, ctrl->val);
1293 break;
1294
1295 case V4L2_CID_SATURATION:
1296 err = s5k6aa_write(client, REG_USER_SATURATION, ctrl->val);
1297 break;
1298
1299 case V4L2_CID_SHARPNESS:
1300 err = s5k6aa_write(client, REG_USER_SHARPBLUR, ctrl->val);
1301 break;
1302
1303 case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
1304 err = s5k6aa_write(client, REG_P_COLORTEMP(idx), ctrl->val);
1305 if (err)
1306 break;
1307 err = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
1308 break;
1309 }
1310unlock:
1311 mutex_unlock(&s5k6aa->lock);
1312 return err;
1313}
1314
1315static const struct v4l2_ctrl_ops s5k6aa_ctrl_ops = {
1316 .s_ctrl = s5k6aa_s_ctrl,
1317};
1318
1319static int s5k6aa_log_status(struct v4l2_subdev *sd)
1320{
1321 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
1322 return 0;
1323}
1324
1325#define V4L2_CID_RED_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1001)
1326#define V4L2_CID_GREEN_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1002)
1327#define V4L2_CID_BLUE_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1003)
1328
1329static const struct v4l2_ctrl_config s5k6aa_ctrls[] = {
1330 {
1331 .ops = &s5k6aa_ctrl_ops,
1332 .id = V4L2_CID_RED_GAIN,
1333 .type = V4L2_CTRL_TYPE_INTEGER,
1334 .name = "Gain, Red",
1335 .min = 0,
1336 .max = 256,
1337 .def = 127,
1338 .step = 1,
1339 }, {
1340 .ops = &s5k6aa_ctrl_ops,
1341 .id = V4L2_CID_GREEN_GAIN,
1342 .type = V4L2_CTRL_TYPE_INTEGER,
1343 .name = "Gain, Green",
1344 .min = 0,
1345 .max = 256,
1346 .def = 127,
1347 .step = 1,
1348 }, {
1349 .ops = &s5k6aa_ctrl_ops,
1350 .id = V4L2_CID_BLUE_GAIN,
1351 .type = V4L2_CTRL_TYPE_INTEGER,
1352 .name = "Gain, Blue",
1353 .min = 0,
1354 .max = 256,
1355 .def = 127,
1356 .step = 1,
1357 },
1358};
1359
1360static int s5k6aa_initialize_ctrls(struct s5k6aa *s5k6aa)
1361{
1362 const struct v4l2_ctrl_ops *ops = &s5k6aa_ctrl_ops;
1363 struct s5k6aa_ctrls *ctrls = &s5k6aa->ctrls;
1364 struct v4l2_ctrl_handler *hdl = &ctrls->handler;
1365
1366 int ret = v4l2_ctrl_handler_init(hdl, 16);
1367 if (ret)
1368 return ret;
1369 /* Auto white balance cluster */
1370 ctrls->awb = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTO_WHITE_BALANCE,
1371 0, 1, 1, 1);
1372 ctrls->gain_red = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[0], NULL);
1373 ctrls->gain_green = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[1], NULL);
1374 ctrls->gain_blue = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[2], NULL);
1375 v4l2_ctrl_auto_cluster(4, &ctrls->awb, 0, false);
1376
1377 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
1378 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
1379 v4l2_ctrl_cluster(2, &ctrls->hflip);
1380
1381 ctrls->auto_exp = v4l2_ctrl_new_std_menu(hdl, ops,
1382 V4L2_CID_EXPOSURE_AUTO,
1383 V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
1384 /* Exposure time: x 1 us */
1385 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE,
1386 0, 6000000U, 1, 100000U);
1387 /* Total gain: 256 <=> 1x */
1388 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN,
1389 0, 256, 1, 256);
1390 v4l2_ctrl_auto_cluster(3, &ctrls->auto_exp, 0, false);
1391
1392 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_POWER_LINE_FREQUENCY,
1393 V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
1394 V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
1395
1396 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX,
1397 V4L2_COLORFX_SKY_BLUE, ~0x6f, V4L2_COLORFX_NONE);
1398
1399 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_WHITE_BALANCE_TEMPERATURE,
1400 0, 256, 1, 0);
1401
1402 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION, -127, 127, 1, 0);
1403 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, -127, 127, 1, 0);
1404 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, -127, 127, 1, 0);
1405 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SHARPNESS, -127, 127, 1, 0);
1406
1407 if (hdl->error) {
1408 ret = hdl->error;
1409 v4l2_ctrl_handler_free(hdl);
1410 return ret;
1411 }
1412
1413 s5k6aa->sd.ctrl_handler = hdl;
1414 return 0;
1415}
1416
1417/*
1418 * V4L2 subdev internal operations
1419 */
1420static int s5k6aa_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1421{
1422 struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(fh, 0);
1423 struct v4l2_rect *crop = v4l2_subdev_get_try_crop(fh, 0);
1424
1425 format->colorspace = s5k6aa_formats[0].colorspace;
1426 format->code = s5k6aa_formats[0].code;
1427 format->width = S5K6AA_OUT_WIDTH_DEF;
1428 format->height = S5K6AA_OUT_HEIGHT_DEF;
1429 format->field = V4L2_FIELD_NONE;
1430
1431 crop->width = S5K6AA_WIN_WIDTH_MAX;
1432 crop->height = S5K6AA_WIN_HEIGHT_MAX;
1433 crop->left = 0;
1434 crop->top = 0;
1435
1436 return 0;
1437}
1438
1439int s5k6aa_check_fw_revision(struct s5k6aa *s5k6aa)
1440{
1441 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
1442 u16 api_ver = 0, fw_rev = 0;
1443
1444 int ret = s5k6aa_set_ahb_address(client);
1445
1446 if (!ret)
1447 ret = s5k6aa_read(client, REG_FW_APIVER, &api_ver);
1448 if (!ret)
1449 ret = s5k6aa_read(client, REG_FW_REVISION, &fw_rev);
1450 if (ret) {
1451 v4l2_err(&s5k6aa->sd, "FW revision check failed!\n");
1452 return ret;
1453 }
1454
1455 v4l2_info(&s5k6aa->sd, "FW API ver.: 0x%X, FW rev.: 0x%X\n",
1456 api_ver, fw_rev);
1457
1458 return api_ver == S5K6AAFX_FW_APIVER ? 0 : -ENODEV;
1459}
1460
1461static int s5k6aa_registered(struct v4l2_subdev *sd)
1462{
1463 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1464 int ret;
1465
1466 mutex_lock(&s5k6aa->lock);
1467 ret = __s5k6aa_power_on(s5k6aa);
1468 if (!ret) {
1469 msleep(100);
1470 ret = s5k6aa_check_fw_revision(s5k6aa);
1471 __s5k6aa_power_off(s5k6aa);
1472 }
1473 mutex_unlock(&s5k6aa->lock);
1474
1475 return ret;
1476}
1477
1478static const struct v4l2_subdev_internal_ops s5k6aa_subdev_internal_ops = {
1479 .registered = s5k6aa_registered,
1480 .open = s5k6aa_open,
1481};
1482
1483static const struct v4l2_subdev_core_ops s5k6aa_core_ops = {
1484 .s_power = s5k6aa_set_power,
1485 .log_status = s5k6aa_log_status,
1486};
1487
1488static const struct v4l2_subdev_ops s5k6aa_subdev_ops = {
1489 .core = &s5k6aa_core_ops,
1490 .pad = &s5k6aa_pad_ops,
1491 .video = &s5k6aa_video_ops,
1492};
1493
1494/*
1495 * GPIO setup
1496 */
1497static int s5k6aa_configure_gpio(int nr, int val, const char *name)
1498{
1499 unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
1500 int ret;
1501
1502 if (!gpio_is_valid(nr))
1503 return 0;
1504 ret = gpio_request_one(nr, flags, name);
1505 if (!ret)
1506 gpio_export(nr, 0);
1507 return ret;
1508}
1509
1510static void s5k6aa_free_gpios(struct s5k6aa *s5k6aa)
1511{
1512 int i;
1513
1514 for (i = 0; i < ARRAY_SIZE(s5k6aa->gpio); i++) {
1515 if (!gpio_is_valid(s5k6aa->gpio[i].gpio))
1516 continue;
1517 gpio_free(s5k6aa->gpio[i].gpio);
1518 s5k6aa->gpio[i].gpio = -EINVAL;
1519 }
1520}
1521
1522static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa,
1523 const struct s5k6aa_platform_data *pdata)
1524{
1525 const struct s5k6aa_gpio *gpio = &pdata->gpio_stby;
1526 int ret;
1527
1528 s5k6aa->gpio[STBY].gpio = -EINVAL;
1529 s5k6aa->gpio[RST].gpio = -EINVAL;
1530
1531 ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_STBY");
1532 if (ret) {
1533 s5k6aa_free_gpios(s5k6aa);
1534 return ret;
1535 }
1536 s5k6aa->gpio[STBY] = *gpio;
1537 if (gpio_is_valid(gpio->gpio))
1538 gpio_set_value(gpio->gpio, 0);
1539
1540 gpio = &pdata->gpio_reset;
1541 ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_RST");
1542 if (ret) {
1543 s5k6aa_free_gpios(s5k6aa);
1544 return ret;
1545 }
1546 s5k6aa->gpio[RST] = *gpio;
1547 if (gpio_is_valid(gpio->gpio))
1548 gpio_set_value(gpio->gpio, 0);
1549
1550 return 0;
1551}
1552
1553static int s5k6aa_probe(struct i2c_client *client,
1554 const struct i2c_device_id *id)
1555{
1556 const struct s5k6aa_platform_data *pdata = client->dev.platform_data;
1557 struct v4l2_subdev *sd;
1558 struct s5k6aa *s5k6aa;
1559 int i, ret;
1560
1561 if (pdata == NULL) {
1562 dev_err(&client->dev, "Platform data not specified\n");
1563 return -EINVAL;
1564 }
1565
1566 if (pdata->mclk_frequency == 0) {
1567 dev_err(&client->dev, "MCLK frequency not specified\n");
1568 return -EINVAL;
1569 }
1570
1571 s5k6aa = kzalloc(sizeof(*s5k6aa), GFP_KERNEL);
1572 if (!s5k6aa)
1573 return -ENOMEM;
1574
1575 mutex_init(&s5k6aa->lock);
1576
1577 s5k6aa->mclk_frequency = pdata->mclk_frequency;
1578 s5k6aa->bus_type = pdata->bus_type;
1579 s5k6aa->mipi_lanes = pdata->nlanes;
1580 s5k6aa->s_power = pdata->set_power;
1581 s5k6aa->inv_hflip = pdata->horiz_flip;
1582 s5k6aa->inv_vflip = pdata->vert_flip;
1583
1584 sd = &s5k6aa->sd;
1585 strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
1586 v4l2_i2c_subdev_init(sd, client, &s5k6aa_subdev_ops);
1587
1588 sd->internal_ops = &s5k6aa_subdev_internal_ops;
1589 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1590
1591 s5k6aa->pad.flags = MEDIA_PAD_FL_SOURCE;
1592 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
1593 ret = media_entity_init(&sd->entity, 1, &s5k6aa->pad, 0);
1594 if (ret)
1595 goto out_err1;
1596
1597 ret = s5k6aa_configure_gpios(s5k6aa, pdata);
1598 if (ret)
1599 goto out_err2;
1600
1601 for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++)
1602 s5k6aa->supplies[i].supply = s5k6aa_supply_names[i];
1603
1604 ret = regulator_bulk_get(&client->dev, S5K6AA_NUM_SUPPLIES,
1605 s5k6aa->supplies);
1606 if (ret) {
1607 dev_err(&client->dev, "Failed to get regulators\n");
1608 goto out_err3;
1609 }
1610
1611 ret = s5k6aa_initialize_ctrls(s5k6aa);
1612 if (ret)
1613 goto out_err4;
1614
1615 s5k6aa_presets_data_init(s5k6aa);
1616
1617 s5k6aa->ccd_rect.width = S5K6AA_WIN_WIDTH_MAX;
1618 s5k6aa->ccd_rect.height = S5K6AA_WIN_HEIGHT_MAX;
1619 s5k6aa->ccd_rect.left = 0;
1620 s5k6aa->ccd_rect.top = 0;
1621
1622 return 0;
1623
1624out_err4:
1625 regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1626out_err3:
1627 s5k6aa_free_gpios(s5k6aa);
1628out_err2:
1629 media_entity_cleanup(&s5k6aa->sd.entity);
1630out_err1:
1631 kfree(s5k6aa);
1632 return ret;
1633}
1634
1635static int s5k6aa_remove(struct i2c_client *client)
1636{
1637 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1638 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1639
1640 v4l2_device_unregister_subdev(sd);
1641 v4l2_ctrl_handler_free(sd->ctrl_handler);
1642 media_entity_cleanup(&sd->entity);
1643 regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1644 s5k6aa_free_gpios(s5k6aa);
1645 kfree(s5k6aa);
1646
1647 return 0;
1648}
1649
1650static const struct i2c_device_id s5k6aa_id[] = {
1651 { DRIVER_NAME, 0 },
1652 { },
1653};
1654MODULE_DEVICE_TABLE(i2c, s5k6aa_id);
1655
1656
1657static struct i2c_driver s5k6aa_i2c_driver = {
1658 .driver = {
1659 .name = DRIVER_NAME
1660 },
1661 .probe = s5k6aa_probe,
1662 .remove = s5k6aa_remove,
1663 .id_table = s5k6aa_id,
1664};
1665
1666static int __init s5k6aa_init(void)
1667{
1668 return i2c_add_driver(&s5k6aa_i2c_driver);
1669}
1670
1671static void __exit s5k6aa_exit(void)
1672{
1673 i2c_del_driver(&s5k6aa_i2c_driver);
1674}
1675
1676module_init(s5k6aa_init);
1677module_exit(s5k6aa_exit);
1678
1679MODULE_DESCRIPTION("Samsung S5K6AA(FX) SXGA camera driver");
1680MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
1681MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c
index 931f469604b..c8d91b0cd9b 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 6c1c9cb5537..19ca6db38b2 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 5f4da80051b..f2481a85e0a 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 bfbe0843205..844a4d7797b 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
@@ -220,8 +220,8 @@ static int vidioc_querycap(struct file *file, void *priv,
220 strncpy(cap->card, dev->plat_dev->name, sizeof(cap->card) - 1); 220 strncpy(cap->card, dev->plat_dev->name, sizeof(cap->card) - 1);
221 cap->bus_info[0] = 0; 221 cap->bus_info[0] = 0;
222 cap->version = KERNEL_VERSION(1, 0, 0); 222 cap->version = KERNEL_VERSION(1, 0, 0);
223 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT 223 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE_MPLANE |
224 | V4L2_CAP_STREAMING; 224 V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_STREAMING;
225 return 0; 225 return 0;
226} 226}
227 227
@@ -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 4c90e53bd96..1e8cdb77d4b 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
@@ -785,8 +785,8 @@ static int vidioc_querycap(struct file *file, void *priv,
785 strncpy(cap->card, dev->plat_dev->name, sizeof(cap->card) - 1); 785 strncpy(cap->card, dev->plat_dev->name, sizeof(cap->card) - 1);
786 cap->bus_info[0] = 0; 786 cap->bus_info[0] = 0;
787 cap->version = KERNEL_VERSION(1, 0, 0); 787 cap->version = KERNEL_VERSION(1, 0, 0);
788 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE 788 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE_MPLANE
789 | V4L2_CAP_VIDEO_OUTPUT 789 | V4L2_CAP_VIDEO_OUTPUT_MPLANE
790 | V4L2_CAP_STREAMING; 790 | V4L2_CAP_STREAMING;
791 return 0; 791 return 0;
792} 792}
@@ -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 4917e2c2b32..e16d3a4bc1d 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 bc8d6bba8ee..9b550687213 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 8615fb81775..f390682629c 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 2893a0134c7..ea4f0473ed3 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 6a729879d89..9644bd861ab 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 5bdfe7e16bc..b72580c3895 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 8069cd6bc5e..4402a8a74f7 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 bea7c9cf4f8..cf7f2194ded 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 10aff3f943a..d1b07aceaf9 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 b6ee1bd342d..462caa44ae0 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 84cd1b65b76..a0895bf0748 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 9b3e828b077..926f0393115 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 e927d25e0d3..6abaa16ae13 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 2e6059a52e9..7875e80cb2f 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 742482e3001..a514fa61116 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 8f5266157f1..3103d0d020e 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/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index 10c2364f3e8..254d3268884 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -1016,7 +1016,8 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
1016 1016
1017 menu_info = &mapping->menu_info[query_menu->index]; 1017 menu_info = &mapping->menu_info[query_menu->index];
1018 1018
1019 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) { 1019 if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK &&
1020 (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)) {
1020 s32 bitmap; 1021 s32 bitmap;
1021 1022
1022 if (!ctrl->cached) { 1023 if (!ctrl->cached) {
@@ -1225,7 +1226,8 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
1225 /* Valid menu indices are reported by the GET_RES request for 1226 /* Valid menu indices are reported by the GET_RES request for
1226 * UVC controls that support it. 1227 * UVC controls that support it.
1227 */ 1228 */
1228 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) { 1229 if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK &&
1230 (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)) {
1229 if (!ctrl->cached) { 1231 if (!ctrl->cached) {
1230 ret = uvc_ctrl_populate_cache(chain, ctrl); 1232 ret = uvc_ctrl_populate_cache(chain, ctrl);
1231 if (ret < 0) 1233 if (ret < 0)
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index 61979b70f38..c68531b8827 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 fc8666ae408..0f415dade05 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[] = {
@@ -819,8 +821,8 @@ static void send_event(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 changes)
819 fill_event(&ev, ctrl, changes); 821 fill_event(&ev, ctrl, changes);
820 822
821 list_for_each_entry(sev, &ctrl->ev_subs, node) 823 list_for_each_entry(sev, &ctrl->ev_subs, node)
822 if (sev->fh && (sev->fh != fh || 824 if (sev->fh != fh ||
823 (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK))) 825 (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK))
824 v4l2_event_queue_fh(sev->fh, &ev); 826 v4l2_event_queue_fh(sev->fh, &ev);
825} 827}
826 828
@@ -945,6 +947,7 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
945 if (ctrl->cluster[0]->has_volatiles) 947 if (ctrl->cluster[0]->has_volatiles)
946 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; 948 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
947 } 949 }
950 fh = NULL;
948 } 951 }
949 if (changed || update_inactive) { 952 if (changed || update_inactive) {
950 /* If a control was changed that was not one of the controls 953 /* If a control was changed that was not one of the controls
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index e6a2c3b302d..0edd618b9dd 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 53b190cf225..c26ad963714 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{
@@ -215,6 +216,9 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,
215 unsigned long flags; 216 unsigned long flags;
216 unsigned i; 217 unsigned i;
217 218
219 if (sub->type == V4L2_EVENT_ALL)
220 return -EINVAL;
221
218 if (elems < 1) 222 if (elems < 1)
219 elems = 1; 223 elems = 1;
220 if (sub->type == V4L2_EVENT_CTRL) { 224 if (sub->type == V4L2_EVENT_CTRL) {
@@ -282,6 +286,7 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh,
282{ 286{
283 struct v4l2_subscribed_event *sev; 287 struct v4l2_subscribed_event *sev;
284 unsigned long flags; 288 unsigned long flags;
289 int i;
285 290
286 if (sub->type == V4L2_EVENT_ALL) { 291 if (sub->type == V4L2_EVENT_ALL) {
287 v4l2_event_unsubscribe_all(fh); 292 v4l2_event_unsubscribe_all(fh);
@@ -292,8 +297,12 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh,
292 297
293 sev = v4l2_event_subscribed(fh, sub->type, sub->id); 298 sev = v4l2_event_subscribed(fh, sub->type, sub->id);
294 if (sev != NULL) { 299 if (sev != NULL) {
300 /* Remove any pending events for this subscription */
301 for (i = 0; i < sev->in_use; i++) {
302 list_del(&sev->events[sev_pos(sev, i)].list);
303 fh->navailable--;
304 }
295 list_del(&sev->list); 305 list_del(&sev->list);
296 sev->fh = NULL;
297 } 306 }
298 307
299 spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); 308 spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c
index 122822d2b8b..9e3fc040ea2 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 a935bae538e..f4473494af7 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 24fd4332215..e1da8fc9dd2 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 179e20e23fc..65ade5f03c2 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 3f5c7a38e6e..95a3f5e82ae 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,18 +110,28 @@ 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;
122 132
123 for (plane = 0; plane < vb->num_planes; ++plane) { 133 for (plane = 0; plane < vb->num_planes; ++plane) {
134 vb->v4l2_planes[plane].length = q->plane_sizes[plane];
124 vb->v4l2_planes[plane].m.mem_offset = off; 135 vb->v4l2_planes[plane].m.mem_offset = off;
125 136
126 dprintk(3, "Buffer %d, plane %d offset 0x%08lx\n", 137 dprintk(3, "Buffer %d, plane %d offset 0x%08lx\n",
@@ -161,7 +172,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
161 vb->state = VB2_BUF_STATE_DEQUEUED; 172 vb->state = VB2_BUF_STATE_DEQUEUED;
162 vb->vb2_queue = q; 173 vb->vb2_queue = q;
163 vb->num_planes = num_planes; 174 vb->num_planes = num_planes;
164 vb->v4l2_buf.index = buffer; 175 vb->v4l2_buf.index = q->num_buffers + buffer;
165 vb->v4l2_buf.type = q->type; 176 vb->v4l2_buf.type = q->type;
166 vb->v4l2_buf.memory = memory; 177 vb->v4l2_buf.memory = memory;
167 178
@@ -189,15 +200,13 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
189 } 200 }
190 } 201 }
191 202
192 q->bufs[buffer] = vb; 203 q->bufs[q->num_buffers + buffer] = vb;
193 } 204 }
194 205
195 q->num_buffers = buffer; 206 __setup_offsets(q, buffer);
196
197 __setup_offsets(q);
198 207
199 dprintk(1, "Allocated %d buffers, %d plane(s) each\n", 208 dprintk(1, "Allocated %d buffers, %d plane(s) each\n",
200 q->num_buffers, num_planes); 209 buffer, num_planes);
201 210
202 return buffer; 211 return buffer;
203} 212}
@@ -205,12 +214,13 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
205/** 214/**
206 * __vb2_free_mem() - release all video buffer memory for a given queue 215 * __vb2_free_mem() - release all video buffer memory for a given queue
207 */ 216 */
208static void __vb2_free_mem(struct vb2_queue *q) 217static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
209{ 218{
210 unsigned int buffer; 219 unsigned int buffer;
211 struct vb2_buffer *vb; 220 struct vb2_buffer *vb;
212 221
213 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 222 for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
223 ++buffer) {
214 vb = q->bufs[buffer]; 224 vb = q->bufs[buffer];
215 if (!vb) 225 if (!vb)
216 continue; 226 continue;
@@ -224,17 +234,18 @@ static void __vb2_free_mem(struct vb2_queue *q)
224} 234}
225 235
226/** 236/**
227 * __vb2_queue_free() - free the queue - video memory and related information 237 * __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 238 * related information, if no buffers are left return the queue to an
229 * queue has already been freed. 239 * uninitialized state. Might be called even if the queue has already been freed.
230 */ 240 */
231static void __vb2_queue_free(struct vb2_queue *q) 241static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
232{ 242{
233 unsigned int buffer; 243 unsigned int buffer;
234 244
235 /* Call driver-provided cleanup function for each buffer, if provided */ 245 /* Call driver-provided cleanup function for each buffer, if provided */
236 if (q->ops->buf_cleanup) { 246 if (q->ops->buf_cleanup) {
237 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 247 for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
248 ++buffer) {
238 if (NULL == q->bufs[buffer]) 249 if (NULL == q->bufs[buffer])
239 continue; 250 continue;
240 q->ops->buf_cleanup(q->bufs[buffer]); 251 q->ops->buf_cleanup(q->bufs[buffer]);
@@ -242,23 +253,26 @@ static void __vb2_queue_free(struct vb2_queue *q)
242 } 253 }
243 254
244 /* Release video buffer memory */ 255 /* Release video buffer memory */
245 __vb2_free_mem(q); 256 __vb2_free_mem(q, buffers);
246 257
247 /* Free videobuf buffers */ 258 /* Free videobuf buffers */
248 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 259 for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
260 ++buffer) {
249 kfree(q->bufs[buffer]); 261 kfree(q->bufs[buffer]);
250 q->bufs[buffer] = NULL; 262 q->bufs[buffer] = NULL;
251 } 263 }
252 264
253 q->num_buffers = 0; 265 q->num_buffers -= buffers;
254 q->memory = 0; 266 if (!q->num_buffers)
267 q->memory = 0;
268 INIT_LIST_HEAD(&q->queued_list);
255} 269}
256 270
257/** 271/**
258 * __verify_planes_array() - verify that the planes array passed in struct 272 * __verify_planes_array() - verify that the planes array passed in struct
259 * v4l2_buffer from userspace can be safely used 273 * v4l2_buffer from userspace can be safely used
260 */ 274 */
261static int __verify_planes_array(struct vb2_buffer *vb, struct v4l2_buffer *b) 275static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer *b)
262{ 276{
263 /* Is memory for copying plane information present? */ 277 /* Is memory for copying plane information present? */
264 if (NULL == b->m.planes) { 278 if (NULL == b->m.planes) {
@@ -284,14 +298,14 @@ static bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
284{ 298{
285 unsigned int plane; 299 unsigned int plane;
286 for (plane = 0; plane < vb->num_planes; ++plane) { 300 for (plane = 0; plane < vb->num_planes; ++plane) {
301 void *mem_priv = vb->planes[plane].mem_priv;
287 /* 302 /*
288 * If num_users() has not been provided, call_memop 303 * If num_users() has not been provided, call_memop
289 * will return 0, apparently nobody cares about this 304 * will return 0, apparently nobody cares about this
290 * case anyway. If num_users() returns more than 1, 305 * case anyway. If num_users() returns more than 1,
291 * we are not the only user of the plane's memory. 306 * we are not the only user of the plane's memory.
292 */ 307 */
293 if (call_memop(q, plane, num_users, 308 if (mem_priv && call_memop(q, plane, num_users, mem_priv) > 1)
294 vb->planes[plane].mem_priv) > 1)
295 return true; 309 return true;
296 } 310 }
297 return false; 311 return false;
@@ -318,7 +332,7 @@ static bool __buffers_in_use(struct vb2_queue *q)
318static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) 332static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
319{ 333{
320 struct vb2_queue *q = vb->vb2_queue; 334 struct vb2_queue *q = vb->vb2_queue;
321 int ret = 0; 335 int ret;
322 336
323 /* Copy back data such as timestamp, flags, input, etc. */ 337 /* Copy back data such as timestamp, flags, input, etc. */
324 memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m)); 338 memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
@@ -365,6 +379,9 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
365 case VB2_BUF_STATE_DONE: 379 case VB2_BUF_STATE_DONE:
366 b->flags |= V4L2_BUF_FLAG_DONE; 380 b->flags |= V4L2_BUF_FLAG_DONE;
367 break; 381 break;
382 case VB2_BUF_STATE_PREPARED:
383 b->flags |= V4L2_BUF_FLAG_PREPARED;
384 break;
368 case VB2_BUF_STATE_DEQUEUED: 385 case VB2_BUF_STATE_DEQUEUED:
369 /* nothing */ 386 /* nothing */
370 break; 387 break;
@@ -373,7 +390,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
373 if (__buffer_in_use(q, vb)) 390 if (__buffer_in_use(q, vb))
374 b->flags |= V4L2_BUF_FLAG_MAPPED; 391 b->flags |= V4L2_BUF_FLAG_MAPPED;
375 392
376 return ret; 393 return 0;
377} 394}
378 395
379/** 396/**
@@ -459,7 +476,7 @@ static int __verify_mmap_ops(struct vb2_queue *q)
459 */ 476 */
460int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) 477int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
461{ 478{
462 unsigned int num_buffers, num_planes; 479 unsigned int num_buffers, allocated_buffers, num_planes = 0;
463 int ret = 0; 480 int ret = 0;
464 481
465 if (q->fileio) { 482 if (q->fileio) {
@@ -507,7 +524,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
507 return -EBUSY; 524 return -EBUSY;
508 } 525 }
509 526
510 __vb2_queue_free(q); 527 __vb2_queue_free(q, q->num_buffers);
511 528
512 /* 529 /*
513 * In case of REQBUFS(0) return immediately without calling 530 * In case of REQBUFS(0) return immediately without calling
@@ -529,7 +546,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. 546 * Ask the driver how many buffers and planes per buffer it requires.
530 * Driver also sets the size and allocator context for each plane. 547 * Driver also sets the size and allocator context for each plane.
531 */ 548 */
532 ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, 549 ret = call_qop(q, queue_setup, q, NULL, &num_buffers, &num_planes,
533 q->plane_sizes, q->alloc_ctx); 550 q->plane_sizes, q->alloc_ctx);
534 if (ret) 551 if (ret)
535 return ret; 552 return ret;
@@ -541,44 +558,168 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
541 return -ENOMEM; 558 return -ENOMEM;
542 } 559 }
543 560
561 allocated_buffers = ret;
562
544 /* 563 /*
545 * Check if driver can handle the allocated number of buffers. 564 * Check if driver can handle the allocated number of buffers.
546 */ 565 */
547 if (ret < num_buffers) { 566 if (allocated_buffers < num_buffers) {
548 unsigned int orig_num_buffers; 567 num_buffers = allocated_buffers;
549 568
550 orig_num_buffers = num_buffers = ret; 569 ret = call_qop(q, queue_setup, q, NULL, &num_buffers,
551 ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, 570 &num_planes, q->plane_sizes, q->alloc_ctx);
552 q->plane_sizes, q->alloc_ctx);
553 if (ret)
554 goto free_mem;
555 571
556 if (orig_num_buffers < num_buffers) { 572 if (!ret && allocated_buffers < num_buffers)
557 ret = -ENOMEM; 573 ret = -ENOMEM;
558 goto free_mem;
559 }
560 574
561 /* 575 /*
562 * Ok, driver accepted smaller number of buffers. 576 * Either the driver has accepted a smaller number of buffers,
577 * or .queue_setup() returned an error
563 */ 578 */
564 ret = num_buffers; 579 }
580
581 q->num_buffers = allocated_buffers;
582
583 if (ret < 0) {
584 __vb2_queue_free(q, allocated_buffers);
585 return ret;
565 } 586 }
566 587
567 /* 588 /*
568 * Return the number of successfully allocated buffers 589 * Return the number of successfully allocated buffers
569 * to the userspace. 590 * to the userspace.
570 */ 591 */
571 req->count = ret; 592 req->count = allocated_buffers;
572 593
573 return 0; 594 return 0;
574
575free_mem:
576 __vb2_queue_free(q);
577 return ret;
578} 595}
579EXPORT_SYMBOL_GPL(vb2_reqbufs); 596EXPORT_SYMBOL_GPL(vb2_reqbufs);
580 597
581/** 598/**
599 * vb2_create_bufs() - Allocate buffers and any required auxiliary structs
600 * @q: videobuf2 queue
601 * @create: creation parameters, passed from userspace to vidioc_create_bufs
602 * handler in driver
603 *
604 * Should be called from vidioc_create_bufs ioctl handler of a driver.
605 * This function:
606 * 1) verifies parameter sanity
607 * 2) calls the .queue_setup() queue operation
608 * 3) performs any necessary memory allocations
609 *
610 * The return values from this function are intended to be directly returned
611 * from vidioc_create_bufs handler in driver.
612 */
613int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
614{
615 unsigned int num_planes = 0, num_buffers, allocated_buffers;
616 int ret = 0;
617
618 if (q->fileio) {
619 dprintk(1, "%s(): file io in progress\n", __func__);
620 return -EBUSY;
621 }
622
623 if (create->memory != V4L2_MEMORY_MMAP
624 && create->memory != V4L2_MEMORY_USERPTR) {
625 dprintk(1, "%s(): unsupported memory type\n", __func__);
626 return -EINVAL;
627 }
628
629 if (create->format.type != q->type) {
630 dprintk(1, "%s(): requested type is incorrect\n", __func__);
631 return -EINVAL;
632 }
633
634 /*
635 * Make sure all the required memory ops for given memory type
636 * are available.
637 */
638 if (create->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
639 dprintk(1, "%s(): MMAP for current setup unsupported\n", __func__);
640 return -EINVAL;
641 }
642
643 if (create->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
644 dprintk(1, "%s(): USERPTR for current setup unsupported\n", __func__);
645 return -EINVAL;
646 }
647
648 if (q->num_buffers == VIDEO_MAX_FRAME) {
649 dprintk(1, "%s(): maximum number of buffers already allocated\n",
650 __func__);
651 return -ENOBUFS;
652 }
653
654 create->index = q->num_buffers;
655
656 if (!q->num_buffers) {
657 memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
658 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
659 q->memory = create->memory;
660 }
661
662 num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers);
663
664 /*
665 * Ask the driver, whether the requested number of buffers, planes per
666 * buffer and their sizes are acceptable
667 */
668 ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
669 &num_planes, q->plane_sizes, q->alloc_ctx);
670 if (ret)
671 return ret;
672
673 /* Finally, allocate buffers and video memory */
674 ret = __vb2_queue_alloc(q, create->memory, num_buffers,
675 num_planes);
676 if (ret < 0) {
677 dprintk(1, "Memory allocation failed with error: %d\n", ret);
678 return ret;
679 }
680
681 allocated_buffers = ret;
682
683 /*
684 * Check if driver can handle the so far allocated number of buffers.
685 */
686 if (ret < num_buffers) {
687 num_buffers = ret;
688
689 /*
690 * q->num_buffers contains the total number of buffers, that the
691 * queue driver has set up
692 */
693 ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
694 &num_planes, q->plane_sizes, q->alloc_ctx);
695
696 if (!ret && allocated_buffers < num_buffers)
697 ret = -ENOMEM;
698
699 /*
700 * Either the driver has accepted a smaller number of buffers,
701 * or .queue_setup() returned an error
702 */
703 }
704
705 q->num_buffers += allocated_buffers;
706
707 if (ret < 0) {
708 __vb2_queue_free(q, allocated_buffers);
709 return ret;
710 }
711
712 /*
713 * Return the number of successfully allocated buffers
714 * to the userspace.
715 */
716 create->count = allocated_buffers;
717
718 return 0;
719}
720EXPORT_SYMBOL_GPL(vb2_create_bufs);
721
722/**
582 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane 723 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
583 * @vb: vb2_buffer to which the plane in question belongs to 724 * @vb: vb2_buffer to which the plane in question belongs to
584 * @plane_no: plane number for which the address is to be returned 725 * @plane_no: plane number for which the address is to be returned
@@ -662,7 +803,7 @@ EXPORT_SYMBOL_GPL(vb2_buffer_done);
662 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in 803 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in
663 * a v4l2_buffer by the userspace 804 * a v4l2_buffer by the userspace
664 */ 805 */
665static int __fill_vb2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b, 806static int __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b,
666 struct v4l2_plane *v4l2_planes) 807 struct v4l2_plane *v4l2_planes)
667{ 808{
668 unsigned int plane; 809 unsigned int plane;
@@ -726,7 +867,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b,
726/** 867/**
727 * __qbuf_userptr() - handle qbuf of a USERPTR buffer 868 * __qbuf_userptr() - handle qbuf of a USERPTR buffer
728 */ 869 */
729static int __qbuf_userptr(struct vb2_buffer *vb, struct v4l2_buffer *b) 870static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
730{ 871{
731 struct v4l2_plane planes[VIDEO_MAX_PLANES]; 872 struct v4l2_plane planes[VIDEO_MAX_PLANES];
732 struct vb2_queue *q = vb->vb2_queue; 873 struct vb2_queue *q = vb->vb2_queue;
@@ -815,7 +956,7 @@ err:
815/** 956/**
816 * __qbuf_mmap() - handle qbuf of an MMAP buffer 957 * __qbuf_mmap() - handle qbuf of an MMAP buffer
817 */ 958 */
818static int __qbuf_mmap(struct vb2_buffer *vb, struct v4l2_buffer *b) 959static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
819{ 960{
820 return __fill_vb2_buffer(vb, b, vb->v4l2_planes); 961 return __fill_vb2_buffer(vb, b, vb->v4l2_planes);
821} 962}
@@ -832,6 +973,95 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
832 q->ops->buf_queue(vb); 973 q->ops->buf_queue(vb);
833} 974}
834 975
976static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
977{
978 struct vb2_queue *q = vb->vb2_queue;
979 int ret;
980
981 switch (q->memory) {
982 case V4L2_MEMORY_MMAP:
983 ret = __qbuf_mmap(vb, b);
984 break;
985 case V4L2_MEMORY_USERPTR:
986 ret = __qbuf_userptr(vb, b);
987 break;
988 default:
989 WARN(1, "Invalid queue type\n");
990 ret = -EINVAL;
991 }
992
993 if (!ret)
994 ret = call_qop(q, buf_prepare, vb);
995 if (ret)
996 dprintk(1, "qbuf: buffer preparation failed: %d\n", ret);
997 else
998 vb->state = VB2_BUF_STATE_PREPARED;
999
1000 return ret;
1001}
1002
1003/**
1004 * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
1005 * @q: videobuf2 queue
1006 * @b: buffer structure passed from userspace to vidioc_prepare_buf
1007 * handler in driver
1008 *
1009 * Should be called from vidioc_prepare_buf ioctl handler of a driver.
1010 * This function:
1011 * 1) verifies the passed buffer,
1012 * 2) calls buf_prepare callback in the driver (if provided), in which
1013 * driver-specific buffer initialization can be performed,
1014 *
1015 * The return values from this function are intended to be directly returned
1016 * from vidioc_prepare_buf handler in driver.
1017 */
1018int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
1019{
1020 struct vb2_buffer *vb;
1021 int ret;
1022
1023 if (q->fileio) {
1024 dprintk(1, "%s(): file io in progress\n", __func__);
1025 return -EBUSY;
1026 }
1027
1028 if (b->type != q->type) {
1029 dprintk(1, "%s(): invalid buffer type\n", __func__);
1030 return -EINVAL;
1031 }
1032
1033 if (b->index >= q->num_buffers) {
1034 dprintk(1, "%s(): buffer index out of range\n", __func__);
1035 return -EINVAL;
1036 }
1037
1038 vb = q->bufs[b->index];
1039 if (NULL == vb) {
1040 /* Should never happen */
1041 dprintk(1, "%s(): buffer is NULL\n", __func__);
1042 return -EINVAL;
1043 }
1044
1045 if (b->memory != q->memory) {
1046 dprintk(1, "%s(): invalid memory type\n", __func__);
1047 return -EINVAL;
1048 }
1049
1050 if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1051 dprintk(1, "%s(): invalid buffer state %d\n", __func__, vb->state);
1052 return -EINVAL;
1053 }
1054
1055 ret = __buf_prepare(vb, b);
1056 if (ret < 0)
1057 return ret;
1058
1059 __fill_v4l2_buffer(vb, b);
1060
1061 return 0;
1062}
1063EXPORT_SYMBOL_GPL(vb2_prepare_buf);
1064
835/** 1065/**
836 * vb2_qbuf() - Queue a buffer from userspace 1066 * vb2_qbuf() - Queue a buffer from userspace
837 * @q: videobuf2 queue 1067 * @q: videobuf2 queue
@@ -841,8 +1071,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
841 * Should be called from vidioc_qbuf ioctl handler of a driver. 1071 * Should be called from vidioc_qbuf ioctl handler of a driver.
842 * This function: 1072 * This function:
843 * 1) verifies the passed buffer, 1073 * 1) verifies the passed buffer,
844 * 2) calls buf_prepare callback in the driver (if provided), in which 1074 * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
845 * driver-specific buffer initialization can be performed, 1075 * 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 1076 * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
847 * callback for processing. 1077 * callback for processing.
848 * 1078 *
@@ -852,7 +1082,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
852int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) 1082int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
853{ 1083{
854 struct vb2_buffer *vb; 1084 struct vb2_buffer *vb;
855 int ret = 0; 1085 int ret;
856 1086
857 if (q->fileio) { 1087 if (q->fileio) {
858 dprintk(1, "qbuf: file io in progress\n"); 1088 dprintk(1, "qbuf: file io in progress\n");
@@ -881,29 +1111,18 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
881 return -EINVAL; 1111 return -EINVAL;
882 } 1112 }
883 1113
884 if (vb->state != VB2_BUF_STATE_DEQUEUED) { 1114 switch (vb->state) {
1115 case VB2_BUF_STATE_DEQUEUED:
1116 ret = __buf_prepare(vb, b);
1117 if (ret)
1118 return ret;
1119 case VB2_BUF_STATE_PREPARED:
1120 break;
1121 default:
885 dprintk(1, "qbuf: buffer already in use\n"); 1122 dprintk(1, "qbuf: buffer already in use\n");
886 return -EINVAL; 1123 return -EINVAL;
887 } 1124 }
888 1125
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 /* 1126 /*
908 * Add to the queued buffers list, a buffer will stay on it until 1127 * Add to the queued buffers list, a buffer will stay on it until
909 * dequeued in dqbuf. 1128 * dequeued in dqbuf.
@@ -918,6 +1137,9 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
918 if (q->streaming) 1137 if (q->streaming)
919 __enqueue_in_driver(vb); 1138 __enqueue_in_driver(vb);
920 1139
1140 /* Fill buffer information for the userspace */
1141 __fill_v4l2_buffer(vb, b);
1142
921 dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index); 1143 dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index);
922 return 0; 1144 return 0;
923} 1145}
@@ -1347,6 +1569,37 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
1347} 1569}
1348EXPORT_SYMBOL_GPL(vb2_mmap); 1570EXPORT_SYMBOL_GPL(vb2_mmap);
1349 1571
1572#ifndef CONFIG_MMU
1573unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
1574 unsigned long addr,
1575 unsigned long len,
1576 unsigned long pgoff,
1577 unsigned long flags)
1578{
1579 unsigned long off = pgoff << PAGE_SHIFT;
1580 struct vb2_buffer *vb;
1581 unsigned int buffer, plane;
1582 int ret;
1583
1584 if (q->memory != V4L2_MEMORY_MMAP) {
1585 dprintk(1, "Queue is not currently set up for mmap\n");
1586 return -EINVAL;
1587 }
1588
1589 /*
1590 * Find the plane corresponding to the offset passed by userspace.
1591 */
1592 ret = __find_plane_by_offset(q, off, &buffer, &plane);
1593 if (ret)
1594 return ret;
1595
1596 vb = q->bufs[buffer];
1597
1598 return (unsigned long)vb2_plane_vaddr(vb, plane);
1599}
1600EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
1601#endif
1602
1350static int __vb2_init_fileio(struct vb2_queue *q, int read); 1603static int __vb2_init_fileio(struct vb2_queue *q, int read);
1351static int __vb2_cleanup_fileio(struct vb2_queue *q); 1604static int __vb2_cleanup_fileio(struct vb2_queue *q);
1352 1605
@@ -1464,7 +1717,7 @@ void vb2_queue_release(struct vb2_queue *q)
1464{ 1717{
1465 __vb2_cleanup_fileio(q); 1718 __vb2_cleanup_fileio(q);
1466 __vb2_queue_cancel(q); 1719 __vb2_queue_cancel(q);
1467 __vb2_queue_free(q); 1720 __vb2_queue_free(q, q->num_buffers);
1468} 1721}
1469EXPORT_SYMBOL_GPL(vb2_queue_release); 1722EXPORT_SYMBOL_GPL(vb2_queue_release);
1470 1723
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 7cf94c09d99..7d754fbcccb 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 8c1d85e27be..56ff19cdc2a 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 4a1909a32b6..9729b92fbfd 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 d89d925caec..6ce70e9615d 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 03f71a431c8..b7aacf47703 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 73e4658af53..7190d5239b4 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 a67adcbd0fa..f1391c21ef2 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 c58020303d1..b2292eb7524 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 345dc658ef0..02c42015ba5 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 a20e1c41bed..60107ee166f 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 56ba1943c91..00000000000
--- 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 00000000000..ec10629a0b0
--- /dev/null
+++ b/drivers/mfd/ab5500-core.c
@@ -0,0 +1,1440 @@
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/module.h>
17#include <linux/mutex.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21#include <linux/device.h>
22#include <linux/irq.h>
23#include <linux/interrupt.h>
24#include <linux/random.h>
25#include <linux/mfd/ab5500/ab5500.h>
26#include <linux/mfd/abx500.h>
27#include <linux/list.h>
28#include <linux/bitops.h>
29#include <linux/spinlock.h>
30#include <linux/mfd/core.h>
31#include <linux/version.h>
32#include <linux/mfd/db5500-prcmu.h>
33
34#include "ab5500-core.h"
35#include "ab5500-debugfs.h"
36
37#define AB5500_NUM_EVENT_REG 23
38#define AB5500_IT_LATCH0_REG 0x40
39#define AB5500_IT_MASK0_REG 0x60
40
41/*
42 * Permissible register ranges for reading and writing per device and bank.
43 *
44 * The ranges must be listed in increasing address order, and no overlaps are
45 * allowed. It is assumed that write permission implies read permission
46 * (i.e. only RO and RW permissions should be used). Ranges with write
47 * permission must not be split up.
48 */
49
50#define NO_RANGE {.count = 0, .range = NULL,}
51static struct ab5500_i2c_banks ab5500_bank_ranges[AB5500_NUM_DEVICES] = {
52 [AB5500_DEVID_USB] = {
53 .nbanks = 1,
54 .bank = (struct ab5500_i2c_ranges []) {
55 {
56 .bankid = AB5500_BANK_USB,
57 .nranges = 12,
58 .range = (struct ab5500_reg_range[]) {
59 {
60 .first = 0x01,
61 .last = 0x01,
62 .perm = AB5500_PERM_RW,
63 },
64 {
65 .first = 0x80,
66 .last = 0x83,
67 .perm = AB5500_PERM_RW,
68 },
69 {
70 .first = 0x87,
71 .last = 0x8A,
72 .perm = AB5500_PERM_RW,
73 },
74 {
75 .first = 0x8B,
76 .last = 0x8B,
77 .perm = AB5500_PERM_RO,
78 },
79 {
80 .first = 0x91,
81 .last = 0x92,
82 .perm = AB5500_PERM_RO,
83 },
84 {
85 .first = 0x93,
86 .last = 0x93,
87 .perm = AB5500_PERM_RW,
88 },
89 {
90 .first = 0x94,
91 .last = 0x94,
92 .perm = AB5500_PERM_RO,
93 },
94 {
95 .first = 0xA8,
96 .last = 0xB0,
97 .perm = AB5500_PERM_RO,
98 },
99 {
100 .first = 0xB2,
101 .last = 0xB2,
102 .perm = AB5500_PERM_RO,
103 },
104 {
105 .first = 0xB4,
106 .last = 0xBC,
107 .perm = AB5500_PERM_RO,
108 },
109 {
110 .first = 0xBF,
111 .last = 0xBF,
112 .perm = AB5500_PERM_RO,
113 },
114 {
115 .first = 0xC1,
116 .last = 0xC5,
117 .perm = AB5500_PERM_RO,
118 },
119 },
120 },
121 },
122 },
123 [AB5500_DEVID_ADC] = {
124 .nbanks = 1,
125 .bank = (struct ab5500_i2c_ranges []) {
126 {
127 .bankid = AB5500_BANK_ADC,
128 .nranges = 6,
129 .range = (struct ab5500_reg_range[]) {
130 {
131 .first = 0x1F,
132 .last = 0x22,
133 .perm = AB5500_PERM_RO,
134 },
135 {
136 .first = 0x23,
137 .last = 0x24,
138 .perm = AB5500_PERM_RW,
139 },
140 {
141 .first = 0x26,
142 .last = 0x2D,
143 .perm = AB5500_PERM_RO,
144 },
145 {
146 .first = 0x2F,
147 .last = 0x34,
148 .perm = AB5500_PERM_RW,
149 },
150 {
151 .first = 0x37,
152 .last = 0x57,
153 .perm = AB5500_PERM_RW,
154 },
155 {
156 .first = 0x58,
157 .last = 0x58,
158 .perm = AB5500_PERM_RO,
159 },
160 },
161 },
162 },
163 },
164 [AB5500_DEVID_LEDS] = {
165 .nbanks = 1,
166 .bank = (struct ab5500_i2c_ranges []) {
167 {
168 .bankid = AB5500_BANK_LED,
169 .nranges = 1,
170 .range = (struct ab5500_reg_range[]) {
171 {
172 .first = 0x00,
173 .last = 0x0C,
174 .perm = AB5500_PERM_RW,
175 },
176 },
177 },
178 },
179 },
180 [AB5500_DEVID_VIDEO] = {
181 .nbanks = 1,
182 .bank = (struct ab5500_i2c_ranges []) {
183 {
184 .bankid = AB5500_BANK_VDENC,
185 .nranges = 12,
186 .range = (struct ab5500_reg_range[]) {
187 {
188 .first = 0x00,
189 .last = 0x08,
190 .perm = AB5500_PERM_RW,
191 },
192 {
193 .first = 0x09,
194 .last = 0x09,
195 .perm = AB5500_PERM_RO,
196 },
197 {
198 .first = 0x0A,
199 .last = 0x12,
200 .perm = AB5500_PERM_RW,
201 },
202 {
203 .first = 0x15,
204 .last = 0x19,
205 .perm = AB5500_PERM_RW,
206 },
207 {
208 .first = 0x1B,
209 .last = 0x21,
210 .perm = AB5500_PERM_RW,
211 },
212 {
213 .first = 0x27,
214 .last = 0x2C,
215 .perm = AB5500_PERM_RW,
216 },
217 {
218 .first = 0x41,
219 .last = 0x41,
220 .perm = AB5500_PERM_RW,
221 },
222 {
223 .first = 0x45,
224 .last = 0x5B,
225 .perm = AB5500_PERM_RW,
226 },
227 {
228 .first = 0x5D,
229 .last = 0x5D,
230 .perm = AB5500_PERM_RW,
231 },
232 {
233 .first = 0x69,
234 .last = 0x69,
235 .perm = AB5500_PERM_RW,
236 },
237 {
238 .first = 0x6C,
239 .last = 0x6D,
240 .perm = AB5500_PERM_RW,
241 },
242 {
243 .first = 0x80,
244 .last = 0x81,
245 .perm = AB5500_PERM_RW,
246 },
247 },
248 },
249 },
250 },
251 [AB5500_DEVID_REGULATORS] = {
252 .nbanks = 2,
253 .bank = (struct ab5500_i2c_ranges []) {
254 {
255 .bankid = AB5500_BANK_STARTUP,
256 .nranges = 12,
257 .range = (struct ab5500_reg_range[]) {
258 {
259 .first = 0x00,
260 .last = 0x01,
261 .perm = AB5500_PERM_RW,
262 },
263 {
264 .first = 0x1F,
265 .last = 0x1F,
266 .perm = AB5500_PERM_RW,
267 },
268 {
269 .first = 0x2E,
270 .last = 0x2E,
271 .perm = AB5500_PERM_RO,
272 },
273 {
274 .first = 0x2F,
275 .last = 0x30,
276 .perm = AB5500_PERM_RW,
277 },
278 {
279 .first = 0x50,
280 .last = 0x51,
281 .perm = AB5500_PERM_RW,
282 },
283 {
284 .first = 0x60,
285 .last = 0x61,
286 .perm = AB5500_PERM_RW,
287 },
288 {
289 .first = 0x66,
290 .last = 0x8A,
291 .perm = AB5500_PERM_RW,
292 },
293 {
294 .first = 0x8C,
295 .last = 0x96,
296 .perm = AB5500_PERM_RW,
297 },
298 {
299 .first = 0xAA,
300 .last = 0xB4,
301 .perm = AB5500_PERM_RW,
302 },
303 {
304 .first = 0xB7,
305 .last = 0xBF,
306 .perm = AB5500_PERM_RW,
307 },
308 {
309 .first = 0xC1,
310 .last = 0xCA,
311 .perm = AB5500_PERM_RW,
312 },
313 {
314 .first = 0xD3,
315 .last = 0xE0,
316 .perm = AB5500_PERM_RW,
317 },
318 },
319 },
320 {
321 .bankid = AB5500_BANK_SIM_USBSIM,
322 .nranges = 1,
323 .range = (struct ab5500_reg_range[]) {
324 {
325 .first = 0x13,
326 .last = 0x19,
327 .perm = AB5500_PERM_RW,
328 },
329 },
330 },
331 },
332 },
333 [AB5500_DEVID_SIM] = {
334 .nbanks = 1,
335 .bank = (struct ab5500_i2c_ranges []) {
336 {
337 .bankid = AB5500_BANK_SIM_USBSIM,
338 .nranges = 1,
339 .range = (struct ab5500_reg_range[]) {
340 {
341 .first = 0x13,
342 .last = 0x19,
343 .perm = AB5500_PERM_RW,
344 },
345 },
346 },
347 },
348 },
349 [AB5500_DEVID_RTC] = {
350 .nbanks = 1,
351 .bank = (struct ab5500_i2c_ranges []) {
352 {
353 .bankid = AB5500_BANK_RTC,
354 .nranges = 2,
355 .range = (struct ab5500_reg_range[]) {
356 {
357 .first = 0x00,
358 .last = 0x04,
359 .perm = AB5500_PERM_RW,
360 },
361 {
362 .first = 0x06,
363 .last = 0x0C,
364 .perm = AB5500_PERM_RW,
365 },
366 },
367 },
368 },
369 },
370 [AB5500_DEVID_CHARGER] = {
371 .nbanks = 1,
372 .bank = (struct ab5500_i2c_ranges []) {
373 {
374 .bankid = AB5500_BANK_CHG,
375 .nranges = 2,
376 .range = (struct ab5500_reg_range[]) {
377 {
378 .first = 0x11,
379 .last = 0x11,
380 .perm = AB5500_PERM_RO,
381 },
382 {
383 .first = 0x12,
384 .last = 0x1B,
385 .perm = AB5500_PERM_RW,
386 },
387 },
388 },
389 },
390 },
391 [AB5500_DEVID_FUELGAUGE] = {
392 .nbanks = 1,
393 .bank = (struct ab5500_i2c_ranges []) {
394 {
395 .bankid = AB5500_BANK_FG_BATTCOM_ACC,
396 .nranges = 2,
397 .range = (struct ab5500_reg_range[]) {
398 {
399 .first = 0x00,
400 .last = 0x0B,
401 .perm = AB5500_PERM_RO,
402 },
403 {
404 .first = 0x0C,
405 .last = 0x10,
406 .perm = AB5500_PERM_RW,
407 },
408 },
409 },
410 },
411 },
412 [AB5500_DEVID_VIBRATOR] = {
413 .nbanks = 1,
414 .bank = (struct ab5500_i2c_ranges []) {
415 {
416 .bankid = AB5500_BANK_VIBRA,
417 .nranges = 2,
418 .range = (struct ab5500_reg_range[]) {
419 {
420 .first = 0x10,
421 .last = 0x13,
422 .perm = AB5500_PERM_RW,
423 },
424 {
425 .first = 0xFE,
426 .last = 0xFE,
427 .perm = AB5500_PERM_RW,
428 },
429 },
430 },
431 },
432 },
433 [AB5500_DEVID_CODEC] = {
434 .nbanks = 1,
435 .bank = (struct ab5500_i2c_ranges []) {
436 {
437 .bankid = AB5500_BANK_AUDIO_HEADSETUSB,
438 .nranges = 2,
439 .range = (struct ab5500_reg_range[]) {
440 {
441 .first = 0x00,
442 .last = 0x48,
443 .perm = AB5500_PERM_RW,
444 },
445 {
446 .first = 0xEB,
447 .last = 0xFB,
448 .perm = AB5500_PERM_RW,
449 },
450 },
451 },
452 },
453 },
454 [AB5500_DEVID_POWER] = {
455 .nbanks = 2,
456 .bank = (struct ab5500_i2c_ranges []) {
457 {
458 .bankid = AB5500_BANK_STARTUP,
459 .nranges = 1,
460 .range = (struct ab5500_reg_range[]) {
461 {
462 .first = 0x30,
463 .last = 0x30,
464 .perm = AB5500_PERM_RW,
465 },
466 },
467 },
468 {
469 .bankid = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
470 .nranges = 1,
471 .range = (struct ab5500_reg_range[]) {
472 {
473 .first = 0x01,
474 .last = 0x01,
475 .perm = AB5500_PERM_RW,
476 },
477 },
478 },
479 },
480 },
481};
482
483#define AB5500_IRQ(bank, bit) ((bank) * 8 + (bit))
484
485/* I appologize for the resource names beeing a mix of upper case
486 * and lower case but I want them to be exact as the documentation */
487static struct mfd_cell ab5500_devs[AB5500_NUM_DEVICES] = {
488 [AB5500_DEVID_LEDS] = {
489 .name = "ab5500-leds",
490 .id = AB5500_DEVID_LEDS,
491 },
492 [AB5500_DEVID_POWER] = {
493 .name = "ab5500-power",
494 .id = AB5500_DEVID_POWER,
495 },
496 [AB5500_DEVID_REGULATORS] = {
497 .name = "ab5500-regulator",
498 .id = AB5500_DEVID_REGULATORS,
499 },
500 [AB5500_DEVID_SIM] = {
501 .name = "ab5500-sim",
502 .id = AB5500_DEVID_SIM,
503 .num_resources = 1,
504 .resources = (struct resource[]) {
505 {
506 .name = "SIMOFF",
507 .flags = IORESOURCE_IRQ,
508 .start = AB5500_IRQ(2, 0), /*rising*/
509 .end = AB5500_IRQ(2, 1), /*falling*/
510 },
511 },
512 },
513 [AB5500_DEVID_RTC] = {
514 .name = "ab5500-rtc",
515 .id = AB5500_DEVID_RTC,
516 .num_resources = 1,
517 .resources = (struct resource[]) {
518 {
519 .name = "RTC_Alarm",
520 .flags = IORESOURCE_IRQ,
521 .start = AB5500_IRQ(1, 7),
522 .end = AB5500_IRQ(1, 7),
523 }
524 },
525 },
526 [AB5500_DEVID_CHARGER] = {
527 .name = "ab5500-charger",
528 .id = AB5500_DEVID_CHARGER,
529 },
530 [AB5500_DEVID_ADC] = {
531 .name = "ab5500-adc",
532 .id = AB5500_DEVID_ADC,
533 .num_resources = 10,
534 .resources = (struct resource[]) {
535 {
536 .name = "TRIGGER-0",
537 .flags = IORESOURCE_IRQ,
538 .start = AB5500_IRQ(0, 0),
539 .end = AB5500_IRQ(0, 0),
540 },
541 {
542 .name = "TRIGGER-1",
543 .flags = IORESOURCE_IRQ,
544 .start = AB5500_IRQ(0, 1),
545 .end = AB5500_IRQ(0, 1),
546 },
547 {
548 .name = "TRIGGER-2",
549 .flags = IORESOURCE_IRQ,
550 .start = AB5500_IRQ(0, 2),
551 .end = AB5500_IRQ(0, 2),
552 },
553 {
554 .name = "TRIGGER-3",
555 .flags = IORESOURCE_IRQ,
556 .start = AB5500_IRQ(0, 3),
557 .end = AB5500_IRQ(0, 3),
558 },
559 {
560 .name = "TRIGGER-4",
561 .flags = IORESOURCE_IRQ,
562 .start = AB5500_IRQ(0, 4),
563 .end = AB5500_IRQ(0, 4),
564 },
565 {
566 .name = "TRIGGER-5",
567 .flags = IORESOURCE_IRQ,
568 .start = AB5500_IRQ(0, 5),
569 .end = AB5500_IRQ(0, 5),
570 },
571 {
572 .name = "TRIGGER-6",
573 .flags = IORESOURCE_IRQ,
574 .start = AB5500_IRQ(0, 6),
575 .end = AB5500_IRQ(0, 6),
576 },
577 {
578 .name = "TRIGGER-7",
579 .flags = IORESOURCE_IRQ,
580 .start = AB5500_IRQ(0, 7),
581 .end = AB5500_IRQ(0, 7),
582 },
583 {
584 .name = "TRIGGER-VBAT",
585 .flags = IORESOURCE_IRQ,
586 .start = AB5500_IRQ(0, 8),
587 .end = AB5500_IRQ(0, 8),
588 },
589 {
590 .name = "TRIGGER-VBAT-TXON",
591 .flags = IORESOURCE_IRQ,
592 .start = AB5500_IRQ(0, 9),
593 .end = AB5500_IRQ(0, 9),
594 },
595 },
596 },
597 [AB5500_DEVID_FUELGAUGE] = {
598 .name = "ab5500-fuelgauge",
599 .id = AB5500_DEVID_FUELGAUGE,
600 .num_resources = 6,
601 .resources = (struct resource[]) {
602 {
603 .name = "Batt_attach",
604 .flags = IORESOURCE_IRQ,
605 .start = AB5500_IRQ(7, 5),
606 .end = AB5500_IRQ(7, 5),
607 },
608 {
609 .name = "Batt_removal",
610 .flags = IORESOURCE_IRQ,
611 .start = AB5500_IRQ(7, 6),
612 .end = AB5500_IRQ(7, 6),
613 },
614 {
615 .name = "UART_framing",
616 .flags = IORESOURCE_IRQ,
617 .start = AB5500_IRQ(7, 7),
618 .end = AB5500_IRQ(7, 7),
619 },
620 {
621 .name = "UART_overrun",
622 .flags = IORESOURCE_IRQ,
623 .start = AB5500_IRQ(8, 0),
624 .end = AB5500_IRQ(8, 0),
625 },
626 {
627 .name = "UART_Rdy_RX",
628 .flags = IORESOURCE_IRQ,
629 .start = AB5500_IRQ(8, 1),
630 .end = AB5500_IRQ(8, 1),
631 },
632 {
633 .name = "UART_Rdy_TX",
634 .flags = IORESOURCE_IRQ,
635 .start = AB5500_IRQ(8, 2),
636 .end = AB5500_IRQ(8, 2),
637 },
638 },
639 },
640 [AB5500_DEVID_VIBRATOR] = {
641 .name = "ab5500-vibrator",
642 .id = AB5500_DEVID_VIBRATOR,
643 },
644 [AB5500_DEVID_CODEC] = {
645 .name = "ab5500-codec",
646 .id = AB5500_DEVID_CODEC,
647 .num_resources = 3,
648 .resources = (struct resource[]) {
649 {
650 .name = "audio_spkr1_ovc",
651 .flags = IORESOURCE_IRQ,
652 .start = AB5500_IRQ(9, 5),
653 .end = AB5500_IRQ(9, 5),
654 },
655 {
656 .name = "audio_plllocked",
657 .flags = IORESOURCE_IRQ,
658 .start = AB5500_IRQ(9, 6),
659 .end = AB5500_IRQ(9, 6),
660 },
661 {
662 .name = "audio_spkr2_ovc",
663 .flags = IORESOURCE_IRQ,
664 .start = AB5500_IRQ(17, 4),
665 .end = AB5500_IRQ(17, 4),
666 },
667 },
668 },
669 [AB5500_DEVID_USB] = {
670 .name = "ab5500-usb",
671 .id = AB5500_DEVID_USB,
672 .num_resources = 36,
673 .resources = (struct resource[]) {
674 {
675 .name = "Link_Update",
676 .flags = IORESOURCE_IRQ,
677 .start = AB5500_IRQ(22, 1),
678 .end = AB5500_IRQ(22, 1),
679 },
680 {
681 .name = "DCIO",
682 .flags = IORESOURCE_IRQ,
683 .start = AB5500_IRQ(8, 3),
684 .end = AB5500_IRQ(8, 4),
685 },
686 {
687 .name = "VBUS_R",
688 .flags = IORESOURCE_IRQ,
689 .start = AB5500_IRQ(8, 5),
690 .end = AB5500_IRQ(8, 5),
691 },
692 {
693 .name = "VBUS_F",
694 .flags = IORESOURCE_IRQ,
695 .start = AB5500_IRQ(8, 6),
696 .end = AB5500_IRQ(8, 6),
697 },
698 {
699 .name = "CHGstate_10_PCVBUSchg",
700 .flags = IORESOURCE_IRQ,
701 .start = AB5500_IRQ(8, 7),
702 .end = AB5500_IRQ(8, 7),
703 },
704 {
705 .name = "DCIOreverse_ovc",
706 .flags = IORESOURCE_IRQ,
707 .start = AB5500_IRQ(9, 0),
708 .end = AB5500_IRQ(9, 0),
709 },
710 {
711 .name = "USBCharDetDone",
712 .flags = IORESOURCE_IRQ,
713 .start = AB5500_IRQ(9, 1),
714 .end = AB5500_IRQ(9, 1),
715 },
716 {
717 .name = "DCIO_no_limit",
718 .flags = IORESOURCE_IRQ,
719 .start = AB5500_IRQ(9, 2),
720 .end = AB5500_IRQ(9, 2),
721 },
722 {
723 .name = "USB_suspend",
724 .flags = IORESOURCE_IRQ,
725 .start = AB5500_IRQ(9, 3),
726 .end = AB5500_IRQ(9, 3),
727 },
728 {
729 .name = "DCIOreverse_fwdcurrent",
730 .flags = IORESOURCE_IRQ,
731 .start = AB5500_IRQ(9, 4),
732 .end = AB5500_IRQ(9, 4),
733 },
734 {
735 .name = "Vbus_Imeasmax_change",
736 .flags = IORESOURCE_IRQ,
737 .start = AB5500_IRQ(9, 5),
738 .end = AB5500_IRQ(9, 6),
739 },
740 {
741 .name = "OVV",
742 .flags = IORESOURCE_IRQ,
743 .start = AB5500_IRQ(14, 5),
744 .end = AB5500_IRQ(14, 5),
745 },
746 {
747 .name = "USBcharging_NOTok",
748 .flags = IORESOURCE_IRQ,
749 .start = AB5500_IRQ(15, 3),
750 .end = AB5500_IRQ(15, 3),
751 },
752 {
753 .name = "usb_adp_sensoroff",
754 .flags = IORESOURCE_IRQ,
755 .start = AB5500_IRQ(15, 6),
756 .end = AB5500_IRQ(15, 6),
757 },
758 {
759 .name = "usb_adp_probeplug",
760 .flags = IORESOURCE_IRQ,
761 .start = AB5500_IRQ(15, 7),
762 .end = AB5500_IRQ(15, 7),
763 },
764 {
765 .name = "usb_adp_sinkerror",
766 .flags = IORESOURCE_IRQ,
767 .start = AB5500_IRQ(16, 0),
768 .end = AB5500_IRQ(16, 6),
769 },
770 {
771 .name = "usb_adp_sourceerror",
772 .flags = IORESOURCE_IRQ,
773 .start = AB5500_IRQ(16, 1),
774 .end = AB5500_IRQ(16, 1),
775 },
776 {
777 .name = "usb_idgnd_r",
778 .flags = IORESOURCE_IRQ,
779 .start = AB5500_IRQ(16, 2),
780 .end = AB5500_IRQ(16, 2),
781 },
782 {
783 .name = "usb_idgnd_f",
784 .flags = IORESOURCE_IRQ,
785 .start = AB5500_IRQ(16, 3),
786 .end = AB5500_IRQ(16, 3),
787 },
788 {
789 .name = "usb_iddetR1",
790 .flags = IORESOURCE_IRQ,
791 .start = AB5500_IRQ(16, 4),
792 .end = AB5500_IRQ(16, 5),
793 },
794 {
795 .name = "usb_iddetR2",
796 .flags = IORESOURCE_IRQ,
797 .start = AB5500_IRQ(16, 6),
798 .end = AB5500_IRQ(16, 7),
799 },
800 {
801 .name = "usb_iddetR3",
802 .flags = IORESOURCE_IRQ,
803 .start = AB5500_IRQ(17, 0),
804 .end = AB5500_IRQ(17, 1),
805 },
806 {
807 .name = "usb_iddetR4",
808 .flags = IORESOURCE_IRQ,
809 .start = AB5500_IRQ(17, 2),
810 .end = AB5500_IRQ(17, 3),
811 },
812 {
813 .name = "CharTempWindowOk",
814 .flags = IORESOURCE_IRQ,
815 .start = AB5500_IRQ(17, 7),
816 .end = AB5500_IRQ(18, 0),
817 },
818 {
819 .name = "USB_SprDetect",
820 .flags = IORESOURCE_IRQ,
821 .start = AB5500_IRQ(18, 1),
822 .end = AB5500_IRQ(18, 1),
823 },
824 {
825 .name = "usb_adp_probe_unplug",
826 .flags = IORESOURCE_IRQ,
827 .start = AB5500_IRQ(18, 2),
828 .end = AB5500_IRQ(18, 2),
829 },
830 {
831 .name = "VBUSChDrop",
832 .flags = IORESOURCE_IRQ,
833 .start = AB5500_IRQ(18, 3),
834 .end = AB5500_IRQ(18, 4),
835 },
836 {
837 .name = "dcio_char_rec_done",
838 .flags = IORESOURCE_IRQ,
839 .start = AB5500_IRQ(18, 5),
840 .end = AB5500_IRQ(18, 5),
841 },
842 {
843 .name = "Charging_stopped_by_temp",
844 .flags = IORESOURCE_IRQ,
845 .start = AB5500_IRQ(18, 6),
846 .end = AB5500_IRQ(18, 6),
847 },
848 {
849 .name = "CHGstate_11_SafeModeVBUS",
850 .flags = IORESOURCE_IRQ,
851 .start = AB5500_IRQ(21, 1),
852 .end = AB5500_IRQ(21, 2),
853 },
854 {
855 .name = "CHGstate_12_comletedVBUS",
856 .flags = IORESOURCE_IRQ,
857 .start = AB5500_IRQ(21, 2),
858 .end = AB5500_IRQ(21, 2),
859 },
860 {
861 .name = "CHGstate_13_completedVBUS",
862 .flags = IORESOURCE_IRQ,
863 .start = AB5500_IRQ(21, 3),
864 .end = AB5500_IRQ(21, 3),
865 },
866 {
867 .name = "CHGstate_14_FullChgDCIO",
868 .flags = IORESOURCE_IRQ,
869 .start = AB5500_IRQ(21, 4),
870 .end = AB5500_IRQ(21, 4),
871 },
872 {
873 .name = "CHGstate_15_SafeModeDCIO",
874 .flags = IORESOURCE_IRQ,
875 .start = AB5500_IRQ(21, 5),
876 .end = AB5500_IRQ(21, 5),
877 },
878 {
879 .name = "CHGstate_16_OFFsuspendDCIO",
880 .flags = IORESOURCE_IRQ,
881 .start = AB5500_IRQ(21, 6),
882 .end = AB5500_IRQ(21, 6),
883 },
884 {
885 .name = "CHGstate_17_completedDCIO",
886 .flags = IORESOURCE_IRQ,
887 .start = AB5500_IRQ(21, 7),
888 .end = AB5500_IRQ(21, 7),
889 },
890 },
891 },
892 [AB5500_DEVID_OTP] = {
893 .name = "ab5500-otp",
894 .id = AB5500_DEVID_OTP,
895 },
896 [AB5500_DEVID_VIDEO] = {
897 .name = "ab5500-video",
898 .id = AB5500_DEVID_VIDEO,
899 .num_resources = 1,
900 .resources = (struct resource[]) {
901 {
902 .name = "plugTVdet",
903 .flags = IORESOURCE_IRQ,
904 .start = AB5500_IRQ(22, 2),
905 .end = AB5500_IRQ(22, 2),
906 },
907 },
908 },
909 [AB5500_DEVID_DBIECI] = {
910 .name = "ab5500-dbieci",
911 .id = AB5500_DEVID_DBIECI,
912 .num_resources = 10,
913 .resources = (struct resource[]) {
914 {
915 .name = "COLL",
916 .flags = IORESOURCE_IRQ,
917 .start = AB5500_IRQ(14, 0),
918 .end = AB5500_IRQ(14, 0),
919 },
920 {
921 .name = "RESERR",
922 .flags = IORESOURCE_IRQ,
923 .start = AB5500_IRQ(14, 1),
924 .end = AB5500_IRQ(14, 1),
925 },
926 {
927 .name = "FRAERR",
928 .flags = IORESOURCE_IRQ,
929 .start = AB5500_IRQ(14, 2),
930 .end = AB5500_IRQ(14, 2),
931 },
932 {
933 .name = "COMERR",
934 .flags = IORESOURCE_IRQ,
935 .start = AB5500_IRQ(14, 3),
936 .end = AB5500_IRQ(14, 3),
937 },
938 {
939 .name = "BSI_indicator",
940 .flags = IORESOURCE_IRQ,
941 .start = AB5500_IRQ(14, 4),
942 .end = AB5500_IRQ(14, 4),
943 },
944 {
945 .name = "SPDSET",
946 .flags = IORESOURCE_IRQ,
947 .start = AB5500_IRQ(14, 6),
948 .end = AB5500_IRQ(14, 6),
949 },
950 {
951 .name = "DSENT",
952 .flags = IORESOURCE_IRQ,
953 .start = AB5500_IRQ(14, 7),
954 .end = AB5500_IRQ(14, 7),
955 },
956 {
957 .name = "DREC",
958 .flags = IORESOURCE_IRQ,
959 .start = AB5500_IRQ(15, 0),
960 .end = AB5500_IRQ(15, 0),
961 },
962 {
963 .name = "ACCINT",
964 .flags = IORESOURCE_IRQ,
965 .start = AB5500_IRQ(15, 1),
966 .end = AB5500_IRQ(15, 1),
967 },
968 {
969 .name = "NOPINT",
970 .flags = IORESOURCE_IRQ,
971 .start = AB5500_IRQ(15, 2),
972 .end = AB5500_IRQ(15, 2),
973 },
974 },
975 },
976 [AB5500_DEVID_ONSWA] = {
977 .name = "ab5500-onswa",
978 .id = AB5500_DEVID_ONSWA,
979 .num_resources = 2,
980 .resources = (struct resource[]) {
981 {
982 .name = "ONSWAn_rising",
983 .flags = IORESOURCE_IRQ,
984 .start = AB5500_IRQ(1, 3),
985 .end = AB5500_IRQ(1, 3),
986 },
987 {
988 .name = "ONSWAn_falling",
989 .flags = IORESOURCE_IRQ,
990 .start = AB5500_IRQ(1, 4),
991 .end = AB5500_IRQ(1, 4),
992 },
993 },
994 },
995};
996
997/*
998 * Functionality for getting/setting register values.
999 */
1000int ab5500_get_register_interruptible_raw(struct ab5500 *ab,
1001 u8 bank, u8 reg,
1002 u8 *value)
1003{
1004 int err;
1005
1006 if (bank >= AB5500_NUM_BANKS)
1007 return -EINVAL;
1008
1009 err = mutex_lock_interruptible(&ab->access_mutex);
1010 if (err)
1011 return err;
1012 err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr, reg, value, 1);
1013
1014 mutex_unlock(&ab->access_mutex);
1015 return err;
1016}
1017
1018static int get_register_page_interruptible(struct ab5500 *ab, u8 bank,
1019 u8 first_reg, u8 *regvals, u8 numregs)
1020{
1021 int err;
1022
1023 if (bank >= AB5500_NUM_BANKS)
1024 return -EINVAL;
1025
1026 err = mutex_lock_interruptible(&ab->access_mutex);
1027 if (err)
1028 return err;
1029
1030 while (numregs) {
1031 /* The hardware limit for get page is 4 */
1032 u8 curnum = min_t(u8, numregs, 4u);
1033
1034 err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr,
1035 first_reg, regvals, curnum);
1036 if (err)
1037 goto out;
1038
1039 numregs -= curnum;
1040 first_reg += curnum;
1041 regvals += curnum;
1042 }
1043
1044out:
1045 mutex_unlock(&ab->access_mutex);
1046 return err;
1047}
1048
1049int ab5500_mask_and_set_register_interruptible_raw(struct ab5500 *ab, u8 bank,
1050 u8 reg, u8 bitmask, u8 bitvalues)
1051{
1052 int err = 0;
1053
1054 if (bank >= AB5500_NUM_BANKS)
1055 return -EINVAL;
1056
1057 if (bitmask) {
1058 u8 buf;
1059
1060 err = mutex_lock_interruptible(&ab->access_mutex);
1061 if (err)
1062 return err;
1063
1064 if (bitmask == 0xFF) /* No need to read in this case. */
1065 buf = bitvalues;
1066 else { /* Read and modify the register value. */
1067 err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr,
1068 reg, &buf, 1);
1069 if (err)
1070 return err;
1071
1072 buf = ((~bitmask & buf) | (bitmask & bitvalues));
1073 }
1074 /* Write the new value. */
1075 err = db5500_prcmu_abb_write(bankinfo[bank].slave_addr, reg,
1076 &buf, 1);
1077
1078 mutex_unlock(&ab->access_mutex);
1079 }
1080 return err;
1081}
1082
1083static int
1084set_register_interruptible(struct ab5500 *ab, u8 bank, u8 reg, u8 value)
1085{
1086 return ab5500_mask_and_set_register_interruptible_raw(ab, bank, reg,
1087 0xff, value);
1088}
1089
1090/*
1091 * Read/write permission checking functions.
1092 */
1093static const struct ab5500_i2c_ranges *get_bankref(u8 devid, u8 bank)
1094{
1095 u8 i;
1096
1097 if (devid < AB5500_NUM_DEVICES) {
1098 for (i = 0; i < ab5500_bank_ranges[devid].nbanks; i++) {
1099 if (ab5500_bank_ranges[devid].bank[i].bankid == bank)
1100 return &ab5500_bank_ranges[devid].bank[i];
1101 }
1102 }
1103 return NULL;
1104}
1105
1106static bool page_write_allowed(u8 devid, u8 bank, u8 first_reg, u8 last_reg)
1107{
1108 u8 i; /* range loop index */
1109 const struct ab5500_i2c_ranges *bankref;
1110
1111 bankref = get_bankref(devid, bank);
1112 if (bankref == NULL || last_reg < first_reg)
1113 return false;
1114
1115 for (i = 0; i < bankref->nranges; i++) {
1116 if (first_reg < bankref->range[i].first)
1117 break;
1118 if ((last_reg <= bankref->range[i].last) &&
1119 (bankref->range[i].perm & AB5500_PERM_WR))
1120 return true;
1121 }
1122 return false;
1123}
1124
1125static bool reg_write_allowed(u8 devid, u8 bank, u8 reg)
1126{
1127 return page_write_allowed(devid, bank, reg, reg);
1128}
1129
1130static bool page_read_allowed(u8 devid, u8 bank, u8 first_reg, u8 last_reg)
1131{
1132 u8 i;
1133 const struct ab5500_i2c_ranges *bankref;
1134
1135 bankref = get_bankref(devid, bank);
1136 if (bankref == NULL || last_reg < first_reg)
1137 return false;
1138
1139
1140 /* Find the range (if it exists in the list) that includes first_reg. */
1141 for (i = 0; i < bankref->nranges; i++) {
1142 if (first_reg < bankref->range[i].first)
1143 return false;
1144 if (first_reg <= bankref->range[i].last)
1145 break;
1146 }
1147 /* Make sure that the entire range up to and including last_reg is
1148 * readable. This may span several of the ranges in the list.
1149 */
1150 while ((i < bankref->nranges) &&
1151 (bankref->range[i].perm & AB5500_PERM_RD)) {
1152 if (last_reg <= bankref->range[i].last)
1153 return true;
1154 if ((++i >= bankref->nranges) ||
1155 (bankref->range[i].first !=
1156 (bankref->range[i - 1].last + 1))) {
1157 break;
1158 }
1159 }
1160 return false;
1161}
1162
1163static bool reg_read_allowed(u8 devid, u8 bank, u8 reg)
1164{
1165 return page_read_allowed(devid, bank, reg, reg);
1166}
1167
1168
1169/*
1170 * The exported register access functionality.
1171 */
1172static int ab5500_get_chip_id(struct device *dev)
1173{
1174 struct ab5500 *ab = dev_get_drvdata(dev->parent);
1175
1176 return (int)ab->chip_id;
1177}
1178
1179static int ab5500_mask_and_set_register_interruptible(struct device *dev,
1180 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
1181{
1182 struct ab5500 *ab;
1183 struct platform_device *pdev = to_platform_device(dev);
1184
1185 if ((AB5500_NUM_BANKS <= bank) ||
1186 !reg_write_allowed(pdev->id, bank, reg))
1187 return -EINVAL;
1188
1189 ab = dev_get_drvdata(dev->parent);
1190 return ab5500_mask_and_set_register_interruptible_raw(ab, bank, reg,
1191 bitmask, bitvalues);
1192}
1193
1194static int ab5500_set_register_interruptible(struct device *dev, u8 bank,
1195 u8 reg, u8 value)
1196{
1197 return ab5500_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
1198 value);
1199}
1200
1201static int ab5500_get_register_interruptible(struct device *dev, u8 bank,
1202 u8 reg, u8 *value)
1203{
1204 struct ab5500 *ab;
1205 struct platform_device *pdev = to_platform_device(dev);
1206
1207 if ((AB5500_NUM_BANKS <= bank) ||
1208 !reg_read_allowed(pdev->id, bank, reg))
1209 return -EINVAL;
1210
1211 ab = dev_get_drvdata(dev->parent);
1212 return ab5500_get_register_interruptible_raw(ab, bank, reg, value);
1213}
1214
1215static int ab5500_get_register_page_interruptible(struct device *dev, u8 bank,
1216 u8 first_reg, u8 *regvals, u8 numregs)
1217{
1218 struct ab5500 *ab;
1219 struct platform_device *pdev = to_platform_device(dev);
1220
1221 if ((AB5500_NUM_BANKS <= bank) ||
1222 !page_read_allowed(pdev->id, bank,
1223 first_reg, (first_reg + numregs - 1)))
1224 return -EINVAL;
1225
1226 ab = dev_get_drvdata(dev->parent);
1227 return get_register_page_interruptible(ab, bank, first_reg, regvals,
1228 numregs);
1229}
1230
1231static int
1232ab5500_event_registers_startup_state_get(struct device *dev, u8 *event)
1233{
1234 struct ab5500 *ab;
1235
1236 ab = dev_get_drvdata(dev->parent);
1237 if (!ab->startup_events_read)
1238 return -EAGAIN; /* Try again later */
1239
1240 memcpy(event, ab->startup_events, AB5500_NUM_EVENT_REG);
1241 return 0;
1242}
1243
1244static struct abx500_ops ab5500_ops = {
1245 .get_chip_id = ab5500_get_chip_id,
1246 .get_register = ab5500_get_register_interruptible,
1247 .set_register = ab5500_set_register_interruptible,
1248 .get_register_page = ab5500_get_register_page_interruptible,
1249 .set_register_page = NULL,
1250 .mask_and_set_register = ab5500_mask_and_set_register_interruptible,
1251 .event_registers_startup_state_get =
1252 ab5500_event_registers_startup_state_get,
1253 .startup_irq_enabled = NULL,
1254};
1255
1256/*
1257 * ab5500_setup : Basic set-up, datastructure creation/destruction
1258 * and I2C interface.This sets up a default config
1259 * in the AB5500 chip so that it will work as expected.
1260 * @ab : Pointer to ab5500 structure
1261 * @settings : Pointer to struct abx500_init_settings
1262 * @size : Size of init data
1263 */
1264static int __init ab5500_setup(struct ab5500 *ab,
1265 struct abx500_init_settings *settings, unsigned int size)
1266{
1267 int err = 0;
1268 int i;
1269
1270 for (i = 0; i < size; i++) {
1271 err = ab5500_mask_and_set_register_interruptible_raw(ab,
1272 settings[i].bank,
1273 settings[i].reg,
1274 0xFF, settings[i].setting);
1275 if (err)
1276 goto exit_no_setup;
1277
1278 /* If event mask register update the event mask in ab5500 */
1279 if ((settings[i].bank == AB5500_BANK_IT) &&
1280 (AB5500_MASK_BASE <= settings[i].reg) &&
1281 (settings[i].reg <= AB5500_MASK_END)) {
1282 ab->mask[settings[i].reg - AB5500_MASK_BASE] =
1283 settings[i].setting;
1284 }
1285 }
1286exit_no_setup:
1287 return err;
1288}
1289
1290struct ab_family_id {
1291 u8 id;
1292 char *name;
1293};
1294
1295static const struct ab_family_id ids[] __initdata = {
1296 /* AB5500 */
1297 {
1298 .id = AB5500_1_0,
1299 .name = "1.0"
1300 },
1301 {
1302 .id = AB5500_1_1,
1303 .name = "1.1"
1304 },
1305 /* Terminator */
1306 {
1307 .id = 0x00,
1308 }
1309};
1310
1311static int __init ab5500_probe(struct platform_device *pdev)
1312{
1313 struct ab5500 *ab;
1314 struct ab5500_platform_data *ab5500_plf_data =
1315 pdev->dev.platform_data;
1316 int err;
1317 int i;
1318
1319 ab = kzalloc(sizeof(struct ab5500), GFP_KERNEL);
1320 if (!ab) {
1321 dev_err(&pdev->dev,
1322 "could not allocate ab5500 device\n");
1323 return -ENOMEM;
1324 }
1325
1326 /* Initialize data structure */
1327 mutex_init(&ab->access_mutex);
1328 mutex_init(&ab->irq_lock);
1329 ab->dev = &pdev->dev;
1330
1331 platform_set_drvdata(pdev, ab);
1332
1333 /* Read chip ID register */
1334 err = ab5500_get_register_interruptible_raw(ab,
1335 AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
1336 AB5500_CHIP_ID, &ab->chip_id);
1337 if (err) {
1338 dev_err(&pdev->dev, "could not communicate with the analog "
1339 "baseband chip\n");
1340 goto exit_no_detect;
1341 }
1342
1343 for (i = 0; ids[i].id != 0x0; i++) {
1344 if (ids[i].id == ab->chip_id) {
1345 snprintf(&ab->chip_name[0], sizeof(ab->chip_name) - 1,
1346 "AB5500 %s", ids[i].name);
1347 break;
1348 }
1349 }
1350 if (ids[i].id == 0x0) {
1351 dev_err(&pdev->dev, "unknown analog baseband chip id: 0x%x\n",
1352 ab->chip_id);
1353 dev_err(&pdev->dev, "driver not started!\n");
1354 goto exit_no_detect;
1355 }
1356
1357 /* Clear and mask all interrupts */
1358 for (i = 0; i < AB5500_NUM_IRQ_REGS; i++) {
1359 u8 latchreg = AB5500_IT_LATCH0_REG + i;
1360 u8 maskreg = AB5500_IT_MASK0_REG + i;
1361 u8 val;
1362
1363 ab5500_get_register_interruptible_raw(ab, AB5500_BANK_IT,
1364 latchreg, &val);
1365 set_register_interruptible(ab, AB5500_BANK_IT, maskreg, 0xff);
1366 ab->mask[i] = ab->oldmask[i] = 0xff;
1367 }
1368
1369 err = abx500_register_ops(&pdev->dev, &ab5500_ops);
1370 if (err) {
1371 dev_err(&pdev->dev, "ab5500_register ops error\n");
1372 goto exit_no_detect;
1373 }
1374
1375 /* Set up and register the platform devices. */
1376 for (i = 0; i < AB5500_NUM_DEVICES; i++) {
1377 ab5500_devs[i].platform_data = ab5500_plf_data->dev_data[i];
1378 ab5500_devs[i].pdata_size =
1379 sizeof(ab5500_plf_data->dev_data[i]);
1380 }
1381
1382 err = mfd_add_devices(&pdev->dev, 0, ab5500_devs,
1383 ARRAY_SIZE(ab5500_devs), NULL,
1384 ab5500_plf_data->irq.base);
1385 if (err) {
1386 dev_err(&pdev->dev, "ab5500_mfd_add_device error\n");
1387 goto exit_no_detect;
1388 }
1389
1390 err = ab5500_setup(ab, ab5500_plf_data->init_settings,
1391 ab5500_plf_data->init_settings_sz);
1392 if (err) {
1393 dev_err(&pdev->dev, "ab5500_setup error\n");
1394 goto exit_no_detect;
1395 }
1396
1397 ab5500_setup_debugfs(ab);
1398
1399 dev_info(&pdev->dev, "detected AB chip: %s\n", &ab->chip_name[0]);
1400 return 0;
1401
1402exit_no_detect:
1403 kfree(ab);
1404 return err;
1405}
1406
1407static int __exit ab5500_remove(struct platform_device *pdev)
1408{
1409 struct ab5500 *ab = platform_get_drvdata(pdev);
1410
1411 ab5500_remove_debugfs();
1412 mfd_remove_devices(&pdev->dev);
1413 kfree(ab);
1414 return 0;
1415}
1416
1417static struct platform_driver ab5500_driver = {
1418 .driver = {
1419 .name = "ab5500-core",
1420 .owner = THIS_MODULE,
1421 },
1422 .remove = __exit_p(ab5500_remove),
1423};
1424
1425static int __init ab5500_core_init(void)
1426{
1427 return platform_driver_probe(&ab5500_driver, ab5500_probe);
1428}
1429
1430static void __exit ab5500_core_exit(void)
1431{
1432 platform_driver_unregister(&ab5500_driver);
1433}
1434
1435subsys_initcall(ab5500_core_init);
1436module_exit(ab5500_core_exit);
1437
1438MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
1439MODULE_DESCRIPTION("AB5500 core driver");
1440MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ab5500-core.h b/drivers/mfd/ab5500-core.h
new file mode 100644
index 00000000000..63b30b17e4f
--- /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 00000000000..43c0ebb8195
--- /dev/null
+++ b/drivers/mfd/ab5500-debugfs.c
@@ -0,0 +1,807 @@
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/export.h>
8#include <linux/debugfs.h>
9#include <linux/seq_file.h>
10#include <linux/mfd/ab5500/ab5500.h>
11#include <linux/mfd/abx500.h>
12#include <linux/uaccess.h>
13
14#include "ab5500-core.h"
15#include "ab5500-debugfs.h"
16
17static struct ab5500_i2c_ranges ab5500_reg_ranges[AB5500_NUM_BANKS] = {
18 [AB5500_BANK_LED] = {
19 .bankid = AB5500_BANK_LED,
20 .nranges = 1,
21 .range = (struct ab5500_reg_range[]) {
22 {
23 .first = 0x00,
24 .last = 0x0C,
25 .perm = AB5500_PERM_RW,
26 },
27 },
28 },
29 [AB5500_BANK_ADC] = {
30 .bankid = AB5500_BANK_ADC,
31 .nranges = 6,
32 .range = (struct ab5500_reg_range[]) {
33 {
34 .first = 0x1F,
35 .last = 0x22,
36 .perm = AB5500_PERM_RO,
37 },
38 {
39 .first = 0x23,
40 .last = 0x24,
41 .perm = AB5500_PERM_RW,
42 },
43 {
44 .first = 0x26,
45 .last = 0x2D,
46 .perm = AB5500_PERM_RO,
47 },
48 {
49 .first = 0x2F,
50 .last = 0x34,
51 .perm = AB5500_PERM_RW,
52 },
53 {
54 .first = 0x37,
55 .last = 0x57,
56 .perm = AB5500_PERM_RW,
57 },
58 {
59 .first = 0x58,
60 .last = 0x58,
61 .perm = AB5500_PERM_RO,
62 },
63 },
64 },
65 [AB5500_BANK_RTC] = {
66 .bankid = AB5500_BANK_RTC,
67 .nranges = 2,
68 .range = (struct ab5500_reg_range[]) {
69 {
70 .first = 0x00,
71 .last = 0x04,
72 .perm = AB5500_PERM_RW,
73 },
74 {
75 .first = 0x06,
76 .last = 0x0C,
77 .perm = AB5500_PERM_RW,
78 },
79 },
80 },
81 [AB5500_BANK_STARTUP] = {
82 .bankid = AB5500_BANK_STARTUP,
83 .nranges = 12,
84 .range = (struct ab5500_reg_range[]) {
85 {
86 .first = 0x00,
87 .last = 0x01,
88 .perm = AB5500_PERM_RW,
89 },
90 {
91 .first = 0x1F,
92 .last = 0x1F,
93 .perm = AB5500_PERM_RW,
94 },
95 {
96 .first = 0x2E,
97 .last = 0x2E,
98 .perm = AB5500_PERM_RO,
99 },
100 {
101 .first = 0x2F,
102 .last = 0x30,
103 .perm = AB5500_PERM_RW,
104 },
105 {
106 .first = 0x50,
107 .last = 0x51,
108 .perm = AB5500_PERM_RW,
109 },
110 {
111 .first = 0x60,
112 .last = 0x61,
113 .perm = AB5500_PERM_RW,
114 },
115 {
116 .first = 0x66,
117 .last = 0x8A,
118 .perm = AB5500_PERM_RW,
119 },
120 {
121 .first = 0x8C,
122 .last = 0x96,
123 .perm = AB5500_PERM_RW,
124 },
125 {
126 .first = 0xAA,
127 .last = 0xB4,
128 .perm = AB5500_PERM_RW,
129 },
130 {
131 .first = 0xB7,
132 .last = 0xBF,
133 .perm = AB5500_PERM_RW,
134 },
135 {
136 .first = 0xC1,
137 .last = 0xCA,
138 .perm = AB5500_PERM_RW,
139 },
140 {
141 .first = 0xD3,
142 .last = 0xE0,
143 .perm = AB5500_PERM_RW,
144 },
145 },
146 },
147 [AB5500_BANK_DBI_ECI] = {
148 .bankid = AB5500_BANK_DBI_ECI,
149 .nranges = 3,
150 .range = (struct ab5500_reg_range[]) {
151 {
152 .first = 0x00,
153 .last = 0x07,
154 .perm = AB5500_PERM_RW,
155 },
156 {
157 .first = 0x10,
158 .last = 0x10,
159 .perm = AB5500_PERM_RW,
160 },
161 {
162 .first = 0x13,
163 .last = 0x13,
164 .perm = AB5500_PERM_RW,
165 },
166 },
167 },
168 [AB5500_BANK_CHG] = {
169 .bankid = AB5500_BANK_CHG,
170 .nranges = 2,
171 .range = (struct ab5500_reg_range[]) {
172 {
173 .first = 0x11,
174 .last = 0x11,
175 .perm = AB5500_PERM_RO,
176 },
177 {
178 .first = 0x12,
179 .last = 0x1B,
180 .perm = AB5500_PERM_RW,
181 },
182 },
183 },
184 [AB5500_BANK_FG_BATTCOM_ACC] = {
185 .bankid = AB5500_BANK_FG_BATTCOM_ACC,
186 .nranges = 2,
187 .range = (struct ab5500_reg_range[]) {
188 {
189 .first = 0x00,
190 .last = 0x0B,
191 .perm = AB5500_PERM_RO,
192 },
193 {
194 .first = 0x0C,
195 .last = 0x10,
196 .perm = AB5500_PERM_RW,
197 },
198 },
199 },
200 [AB5500_BANK_USB] = {
201 .bankid = AB5500_BANK_USB,
202 .nranges = 12,
203 .range = (struct ab5500_reg_range[]) {
204 {
205 .first = 0x01,
206 .last = 0x01,
207 .perm = AB5500_PERM_RW,
208 },
209 {
210 .first = 0x80,
211 .last = 0x83,
212 .perm = AB5500_PERM_RW,
213 },
214 {
215 .first = 0x87,
216 .last = 0x8A,
217 .perm = AB5500_PERM_RW,
218 },
219 {
220 .first = 0x8B,
221 .last = 0x8B,
222 .perm = AB5500_PERM_RO,
223 },
224 {
225 .first = 0x91,
226 .last = 0x92,
227 .perm = AB5500_PERM_RO,
228 },
229 {
230 .first = 0x93,
231 .last = 0x93,
232 .perm = AB5500_PERM_RW,
233 },
234 {
235 .first = 0x94,
236 .last = 0x94,
237 .perm = AB5500_PERM_RO,
238 },
239 {
240 .first = 0xA8,
241 .last = 0xB0,
242 .perm = AB5500_PERM_RO,
243 },
244 {
245 .first = 0xB2,
246 .last = 0xB2,
247 .perm = AB5500_PERM_RO,
248 },
249 {
250 .first = 0xB4,
251 .last = 0xBC,
252 .perm = AB5500_PERM_RO,
253 },
254 {
255 .first = 0xBF,
256 .last = 0xBF,
257 .perm = AB5500_PERM_RO,
258 },
259 {
260 .first = 0xC1,
261 .last = 0xC5,
262 .perm = AB5500_PERM_RO,
263 },
264 },
265 },
266 [AB5500_BANK_IT] = {
267 .bankid = AB5500_BANK_IT,
268 .nranges = 4,
269 .range = (struct ab5500_reg_range[]) {
270 {
271 .first = 0x00,
272 .last = 0x02,
273 .perm = AB5500_PERM_RO,
274 },
275 {
276 .first = 0x20,
277 .last = 0x36,
278 .perm = AB5500_PERM_RO,
279 },
280 {
281 .first = 0x40,
282 .last = 0x56,
283 .perm = AB5500_PERM_RO,
284 },
285 {
286 .first = 0x60,
287 .last = 0x76,
288 .perm = AB5500_PERM_RO,
289 },
290 },
291 },
292 [AB5500_BANK_VDDDIG_IO_I2C_CLK_TST] = {
293 .bankid = AB5500_BANK_VDDDIG_IO_I2C_CLK_TST,
294 .nranges = 7,
295 .range = (struct ab5500_reg_range[]) {
296 {
297 .first = 0x02,
298 .last = 0x02,
299 .perm = AB5500_PERM_RW,
300 },
301 {
302 .first = 0x12,
303 .last = 0x12,
304 .perm = AB5500_PERM_RW,
305 },
306 {
307 .first = 0x30,
308 .last = 0x34,
309 .perm = AB5500_PERM_RW,
310 },
311 {
312 .first = 0x40,
313 .last = 0x44,
314 .perm = AB5500_PERM_RW,
315 },
316 {
317 .first = 0x50,
318 .last = 0x54,
319 .perm = AB5500_PERM_RW,
320 },
321 {
322 .first = 0x60,
323 .last = 0x64,
324 .perm = AB5500_PERM_RW,
325 },
326 {
327 .first = 0x70,
328 .last = 0x74,
329 .perm = AB5500_PERM_RW,
330 },
331 },
332 },
333 [AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP] = {
334 .bankid = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
335 .nranges = 13,
336 .range = (struct ab5500_reg_range[]) {
337 {
338 .first = 0x01,
339 .last = 0x01,
340 .perm = AB5500_PERM_RW,
341 },
342 {
343 .first = 0x02,
344 .last = 0x02,
345 .perm = AB5500_PERM_RO,
346 },
347 {
348 .first = 0x0D,
349 .last = 0x0F,
350 .perm = AB5500_PERM_RW,
351 },
352 {
353 .first = 0x1C,
354 .last = 0x1C,
355 .perm = AB5500_PERM_RW,
356 },
357 {
358 .first = 0x1E,
359 .last = 0x1E,
360 .perm = AB5500_PERM_RW,
361 },
362 {
363 .first = 0x20,
364 .last = 0x21,
365 .perm = AB5500_PERM_RW,
366 },
367 {
368 .first = 0x25,
369 .last = 0x25,
370 .perm = AB5500_PERM_RW,
371 },
372 {
373 .first = 0x28,
374 .last = 0x2A,
375 .perm = AB5500_PERM_RW,
376 },
377 {
378 .first = 0x30,
379 .last = 0x33,
380 .perm = AB5500_PERM_RW,
381 },
382 {
383 .first = 0x40,
384 .last = 0x43,
385 .perm = AB5500_PERM_RW,
386 },
387 {
388 .first = 0x50,
389 .last = 0x53,
390 .perm = AB5500_PERM_RW,
391 },
392 {
393 .first = 0x60,
394 .last = 0x63,
395 .perm = AB5500_PERM_RW,
396 },
397 {
398 .first = 0x70,
399 .last = 0x73,
400 .perm = AB5500_PERM_RW,
401 },
402 },
403 },
404 [AB5500_BANK_VIBRA] = {
405 .bankid = AB5500_BANK_VIBRA,
406 .nranges = 2,
407 .range = (struct ab5500_reg_range[]) {
408 {
409 .first = 0x10,
410 .last = 0x13,
411 .perm = AB5500_PERM_RW,
412 },
413 {
414 .first = 0xFE,
415 .last = 0xFE,
416 .perm = AB5500_PERM_RW,
417 },
418 },
419 },
420 [AB5500_BANK_AUDIO_HEADSETUSB] = {
421 .bankid = AB5500_BANK_AUDIO_HEADSETUSB,
422 .nranges = 2,
423 .range = (struct ab5500_reg_range[]) {
424 {
425 .first = 0x00,
426 .last = 0x48,
427 .perm = AB5500_PERM_RW,
428 },
429 {
430 .first = 0xEB,
431 .last = 0xFB,
432 .perm = AB5500_PERM_RW,
433 },
434 },
435 },
436 [AB5500_BANK_SIM_USBSIM] = {
437 .bankid = AB5500_BANK_SIM_USBSIM,
438 .nranges = 1,
439 .range = (struct ab5500_reg_range[]) {
440 {
441 .first = 0x13,
442 .last = 0x19,
443 .perm = AB5500_PERM_RW,
444 },
445 },
446 },
447 [AB5500_BANK_VDENC] = {
448 .bankid = AB5500_BANK_VDENC,
449 .nranges = 12,
450 .range = (struct ab5500_reg_range[]) {
451 {
452 .first = 0x00,
453 .last = 0x08,
454 .perm = AB5500_PERM_RW,
455 },
456 {
457 .first = 0x09,
458 .last = 0x09,
459 .perm = AB5500_PERM_RO,
460 },
461 {
462 .first = 0x0A,
463 .last = 0x12,
464 .perm = AB5500_PERM_RW,
465 },
466 {
467 .first = 0x15,
468 .last = 0x19,
469 .perm = AB5500_PERM_RW,
470 },
471 {
472 .first = 0x1B,
473 .last = 0x21,
474 .perm = AB5500_PERM_RW,
475 },
476 {
477 .first = 0x27,
478 .last = 0x2C,
479 .perm = AB5500_PERM_RW,
480 },
481 {
482 .first = 0x41,
483 .last = 0x41,
484 .perm = AB5500_PERM_RW,
485 },
486 {
487 .first = 0x45,
488 .last = 0x5B,
489 .perm = AB5500_PERM_RW,
490 },
491 {
492 .first = 0x5D,
493 .last = 0x5D,
494 .perm = AB5500_PERM_RW,
495 },
496 {
497 .first = 0x69,
498 .last = 0x69,
499 .perm = AB5500_PERM_RW,
500 },
501 {
502 .first = 0x6C,
503 .last = 0x6D,
504 .perm = AB5500_PERM_RW,
505 },
506 {
507 .first = 0x80,
508 .last = 0x81,
509 .perm = AB5500_PERM_RW,
510 },
511 },
512 },
513};
514
515static int ab5500_registers_print(struct seq_file *s, void *p)
516{
517 struct ab5500 *ab = s->private;
518 unsigned int i;
519 u8 bank = (u8)ab->debug_bank;
520
521 seq_printf(s, "ab5500 register values:\n");
522 for (bank = 0; bank < AB5500_NUM_BANKS; bank++) {
523 seq_printf(s, " bank %u, %s (0x%x):\n", bank,
524 bankinfo[bank].name,
525 bankinfo[bank].slave_addr);
526 for (i = 0; i < ab5500_reg_ranges[bank].nranges; i++) {
527 u8 reg;
528 int err;
529
530 for (reg = ab5500_reg_ranges[bank].range[i].first;
531 reg <= ab5500_reg_ranges[bank].range[i].last;
532 reg++) {
533 u8 value;
534
535 err = ab5500_get_register_interruptible_raw(ab,
536 bank, reg,
537 &value);
538 if (err < 0) {
539 dev_err(ab->dev, "get_reg failed %d"
540 "bank 0x%x reg 0x%x\n",
541 err, bank, reg);
542 return err;
543 }
544
545 err = seq_printf(s, "[%d/0x%02X]: 0x%02X\n",
546 bank, reg, value);
547 if (err < 0) {
548 dev_err(ab->dev,
549 "seq_printf overflow\n");
550 /*
551 * Error is not returned here since
552 * the output is wanted in any case
553 */
554 return 0;
555 }
556 }
557 }
558 }
559 return 0;
560}
561
562static int ab5500_registers_open(struct inode *inode, struct file *file)
563{
564 return single_open(file, ab5500_registers_print, inode->i_private);
565}
566
567static const struct file_operations ab5500_registers_fops = {
568 .open = ab5500_registers_open,
569 .read = seq_read,
570 .llseek = seq_lseek,
571 .release = single_release,
572 .owner = THIS_MODULE,
573};
574
575static int ab5500_bank_print(struct seq_file *s, void *p)
576{
577 struct ab5500 *ab = s->private;
578
579 seq_printf(s, "%d\n", ab->debug_bank);
580 return 0;
581}
582
583static int ab5500_bank_open(struct inode *inode, struct file *file)
584{
585 return single_open(file, ab5500_bank_print, inode->i_private);
586}
587
588static ssize_t ab5500_bank_write(struct file *file,
589 const char __user *user_buf,
590 size_t count, loff_t *ppos)
591{
592 struct ab5500 *ab = ((struct seq_file *)(file->private_data))->private;
593 char buf[32];
594 int buf_size;
595 unsigned long user_bank;
596 int err;
597
598 /* Get userspace string and assure termination */
599 buf_size = min(count, (sizeof(buf) - 1));
600 if (copy_from_user(buf, user_buf, buf_size))
601 return -EFAULT;
602 buf[buf_size] = 0;
603
604 err = strict_strtoul(buf, 0, &user_bank);
605 if (err)
606 return -EINVAL;
607
608 if (user_bank >= AB5500_NUM_BANKS) {
609 dev_err(ab->dev,
610 "debugfs error input > number of banks\n");
611 return -EINVAL;
612 }
613
614 ab->debug_bank = user_bank;
615
616 return buf_size;
617}
618
619static int ab5500_address_print(struct seq_file *s, void *p)
620{
621 struct ab5500 *ab = s->private;
622
623 seq_printf(s, "0x%02X\n", ab->debug_address);
624 return 0;
625}
626
627static int ab5500_address_open(struct inode *inode, struct file *file)
628{
629 return single_open(file, ab5500_address_print, inode->i_private);
630}
631
632static ssize_t ab5500_address_write(struct file *file,
633 const char __user *user_buf,
634 size_t count, loff_t *ppos)
635{
636 struct ab5500 *ab = ((struct seq_file *)(file->private_data))->private;
637 char buf[32];
638 int buf_size;
639 unsigned long user_address;
640 int err;
641
642 /* Get userspace string and assure termination */
643 buf_size = min(count, (sizeof(buf) - 1));
644 if (copy_from_user(buf, user_buf, buf_size))
645 return -EFAULT;
646 buf[buf_size] = 0;
647
648 err = strict_strtoul(buf, 0, &user_address);
649 if (err)
650 return -EINVAL;
651 if (user_address > 0xff) {
652 dev_err(ab->dev,
653 "debugfs error input > 0xff\n");
654 return -EINVAL;
655 }
656 ab->debug_address = user_address;
657 return buf_size;
658}
659
660static int ab5500_val_print(struct seq_file *s, void *p)
661{
662 struct ab5500 *ab = s->private;
663 int err;
664 u8 regvalue;
665
666 err = ab5500_get_register_interruptible_raw(ab, (u8)ab->debug_bank,
667 (u8)ab->debug_address, &regvalue);
668 if (err) {
669 dev_err(ab->dev, "get_reg failed %d, bank 0x%x"
670 ", reg 0x%x\n", err, ab->debug_bank,
671 ab->debug_address);
672 return -EINVAL;
673 }
674 seq_printf(s, "0x%02X\n", regvalue);
675
676 return 0;
677}
678
679static int ab5500_val_open(struct inode *inode, struct file *file)
680{
681 return single_open(file, ab5500_val_print, inode->i_private);
682}
683
684static ssize_t ab5500_val_write(struct file *file,
685 const char __user *user_buf,
686 size_t count, loff_t *ppos)
687{
688 struct ab5500 *ab = ((struct seq_file *)(file->private_data))->private;
689 char buf[32];
690 int buf_size;
691 unsigned long user_val;
692 int err;
693 u8 regvalue;
694
695 /* Get userspace string and assure termination */
696 buf_size = min(count, (sizeof(buf)-1));
697 if (copy_from_user(buf, user_buf, buf_size))
698 return -EFAULT;
699 buf[buf_size] = 0;
700
701 err = strict_strtoul(buf, 0, &user_val);
702 if (err)
703 return -EINVAL;
704 if (user_val > 0xff) {
705 dev_err(ab->dev,
706 "debugfs error input > 0xff\n");
707 return -EINVAL;
708 }
709 err = ab5500_mask_and_set_register_interruptible_raw(
710 ab, (u8)ab->debug_bank,
711 (u8)ab->debug_address, 0xFF, (u8)user_val);
712 if (err)
713 return -EINVAL;
714
715 ab5500_get_register_interruptible_raw(ab, (u8)ab->debug_bank,
716 (u8)ab->debug_address, &regvalue);
717 if (err)
718 return -EINVAL;
719
720 return buf_size;
721}
722
723static const struct file_operations ab5500_bank_fops = {
724 .open = ab5500_bank_open,
725 .write = ab5500_bank_write,
726 .read = seq_read,
727 .llseek = seq_lseek,
728 .release = single_release,
729 .owner = THIS_MODULE,
730};
731
732static const struct file_operations ab5500_address_fops = {
733 .open = ab5500_address_open,
734 .write = ab5500_address_write,
735 .read = seq_read,
736 .llseek = seq_lseek,
737 .release = single_release,
738 .owner = THIS_MODULE,
739};
740
741static const struct file_operations ab5500_val_fops = {
742 .open = ab5500_val_open,
743 .write = ab5500_val_write,
744 .read = seq_read,
745 .llseek = seq_lseek,
746 .release = single_release,
747 .owner = THIS_MODULE,
748};
749
750static struct dentry *ab5500_dir;
751static struct dentry *ab5500_reg_file;
752static struct dentry *ab5500_bank_file;
753static struct dentry *ab5500_address_file;
754static struct dentry *ab5500_val_file;
755
756void __init ab5500_setup_debugfs(struct ab5500 *ab)
757{
758 ab->debug_bank = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP;
759 ab->debug_address = AB5500_CHIP_ID;
760
761 ab5500_dir = debugfs_create_dir("ab5500", NULL);
762 if (!ab5500_dir)
763 goto exit_no_debugfs;
764
765 ab5500_reg_file = debugfs_create_file("all-bank-registers",
766 S_IRUGO, ab5500_dir, ab, &ab5500_registers_fops);
767 if (!ab5500_reg_file)
768 goto exit_destroy_dir;
769
770 ab5500_bank_file = debugfs_create_file("register-bank",
771 (S_IRUGO | S_IWUGO), ab5500_dir, ab, &ab5500_bank_fops);
772 if (!ab5500_bank_file)
773 goto exit_destroy_reg;
774
775 ab5500_address_file = debugfs_create_file("register-address",
776 (S_IRUGO | S_IWUGO), ab5500_dir, ab, &ab5500_address_fops);
777 if (!ab5500_address_file)
778 goto exit_destroy_bank;
779
780 ab5500_val_file = debugfs_create_file("register-value",
781 (S_IRUGO | S_IWUGO), ab5500_dir, ab, &ab5500_val_fops);
782 if (!ab5500_val_file)
783 goto exit_destroy_address;
784
785 return;
786
787exit_destroy_address:
788 debugfs_remove(ab5500_address_file);
789exit_destroy_bank:
790 debugfs_remove(ab5500_bank_file);
791exit_destroy_reg:
792 debugfs_remove(ab5500_reg_file);
793exit_destroy_dir:
794 debugfs_remove(ab5500_dir);
795exit_no_debugfs:
796 dev_err(ab->dev, "failed to create debugfs entries.\n");
797 return;
798}
799
800void __exit ab5500_remove_debugfs(void)
801{
802 debugfs_remove(ab5500_val_file);
803 debugfs_remove(ab5500_address_file);
804 debugfs_remove(ab5500_bank_file);
805 debugfs_remove(ab5500_reg_file);
806 debugfs_remove(ab5500_dir);
807}
diff --git a/drivers/mfd/ab5500-debugfs.h b/drivers/mfd/ab5500-debugfs.h
new file mode 100644
index 00000000000..7330a9b6afa
--- /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 387705e494b..1e9173804ed 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 64bdeeb1c11..dedb7f65cea 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 f16afb234ff..e985d1701a8 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 392185965b3..f20feefac19 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 f12720dbe12..7ce65f49480 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 c71ae09430c..b85bbd7f0d1 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 2fadbaeb1cb..1b79c37fd59 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 9dbb3cab4a6..bb115b2f04e 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 3bbf04d5804..00000000000
--- 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 02a15d7cb3b..a25ab9c6b5a 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 9a8e9e4ddd3..ec22e9f15d3 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 3d4a861976c..8ad88da647b 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 00000000000..97c27762174
--- /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 563654c9b19..1e9ee533eac 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 f83103b8970..5be53ae9b61 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 7e4d44bf92a..e9619acc023 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 af5d9d06137..cb4910ac4d1 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 0902523af62..0f5922812bf 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 57868416c76..ff1a7e741ec 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 1b0192f1eff..048a3b903b0 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 c27e515b072..de979742c6f 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 696879e2eef..02d65692ceb 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 eddc19ae464..83af78c1b0e 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 955bc00e4b2..5fec23a9ac0 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 01ecfeee652..bfbd66021af 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 8a7ee3139b8..f062c8cc6c3 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 7cbf2aa9e64..834f824d3c1 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 eb3b5f88e56..3eee45ffb09 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 d97a8694517..f39b756df56 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 ada1835a545..f4747a4a9a9 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 e06ba9440cd..62b4626f456 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 b03be1d4e0c..5d6ba132837 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/Kconfig b/drivers/misc/Kconfig
index d593878d66d..5664696f2d3 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -472,7 +472,7 @@ config BMP085
472 module will be called bmp085. 472 module will be called bmp085.
473 473
474config PCH_PHUB 474config PCH_PHUB
475 tristate "Intel EG20T PCH / OKI SEMICONDUCTOR IOH(ML7213/ML7223) PHUB" 475 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB"
476 depends on PCI 476 depends on PCI
477 help 477 help
478 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of 478 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of
@@ -480,12 +480,13 @@ config PCH_PHUB
480 processor. The Topcliff has MAC address and Option ROM data in SROM. 480 processor. The Topcliff has MAC address and Option ROM data in SROM.
481 This driver can access MAC address and Option ROM data in SROM. 481 This driver can access MAC address and Option ROM data in SROM.
482 482
483 This driver also can be used for OKI SEMICONDUCTOR IOH(Input/ 483 This driver also can be used for LAPIS Semiconductor's IOH,
484 Output Hub), ML7213 and ML7223. 484 ML7213/ML7223/ML7831.
485 ML7213 IOH is for IVI(In-Vehicle Infotainment) use and ML7223 IOH is 485 ML7213 which is for IVI(In-Vehicle Infotainment) use.
486 for MP(Media Phone) use. 486 ML7223 IOH is for MP(Media Phone) use.
487 ML7213/ML7223 is companion chip for Intel Atom E6xx series. 487 ML7831 IOH is for general purpose use.
488 ML7213/ML7223 is completely compatible for Intel EG20T PCH. 488 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series.
489 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH.
489 490
490 To compile this driver as a module, choose M here: the module will 491 To compile this driver as a module, choose M here: the module will
491 be called pch_phub. 492 be called pch_phub.
diff --git a/drivers/misc/ab8500-pwm.c b/drivers/misc/ab8500-pwm.c
index 35903154ca2..2208a9d5262 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/ad525x_dpot.h b/drivers/misc/ad525x_dpot.h
index a662f5987b6..82b2cb77ae1 100644
--- a/drivers/misc/ad525x_dpot.h
+++ b/drivers/misc/ad525x_dpot.h
@@ -100,7 +100,7 @@ enum dpot_devid {
100 AD5293_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 27), 100 AD5293_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 27),
101 AD7376_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT, 101 AD7376_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
102 BRDAC0, 7, 28), 102 BRDAC0, 7, 28),
103 AD8400_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT, 103 AD8400_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
104 BRDAC0, 8, 29), 104 BRDAC0, 8, 29),
105 AD8402_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT, 105 AD8402_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
106 BRDAC0 | BRDAC1, 8, 30), 106 BRDAC0 | BRDAC1, 8, 30),
diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
index 769a4e8e10d..5bb18778107 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 a844810b50f..4bcfc375973 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 82fe2d06782..bfeea9ba702 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/carma/carma-fpga-program.c b/drivers/misc/carma/carma-fpga-program.c
index 7ce6065dc20..eb5cd28bc6d 100644
--- a/drivers/misc/carma/carma-fpga-program.c
+++ b/drivers/misc/carma/carma-fpga-program.c
@@ -945,8 +945,7 @@ static int fpga_of_remove(struct platform_device *op)
945/* CTL-CPLD Version Register */ 945/* CTL-CPLD Version Register */
946#define CTL_CPLD_VERSION 0x2000 946#define CTL_CPLD_VERSION 0x2000
947 947
948static int fpga_of_probe(struct platform_device *op, 948static int fpga_of_probe(struct platform_device *op)
949 const struct of_device_id *match)
950{ 949{
951 struct device_node *of_node = op->dev.of_node; 950 struct device_node *of_node = op->dev.of_node;
952 struct device *this_device; 951 struct device *this_device;
@@ -1107,7 +1106,7 @@ static struct of_device_id fpga_of_match[] = {
1107 {}, 1106 {},
1108}; 1107};
1109 1108
1110static struct of_platform_driver fpga_of_driver = { 1109static struct platform_driver fpga_of_driver = {
1111 .probe = fpga_of_probe, 1110 .probe = fpga_of_probe,
1112 .remove = fpga_of_remove, 1111 .remove = fpga_of_remove,
1113 .driver = { 1112 .driver = {
@@ -1124,12 +1123,12 @@ static struct of_platform_driver fpga_of_driver = {
1124static int __init fpga_init(void) 1123static int __init fpga_init(void)
1125{ 1124{
1126 led_trigger_register_simple("fpga", &ledtrig_fpga); 1125 led_trigger_register_simple("fpga", &ledtrig_fpga);
1127 return of_register_platform_driver(&fpga_of_driver); 1126 return platform_driver_register(&fpga_of_driver);
1128} 1127}
1129 1128
1130static void __exit fpga_exit(void) 1129static void __exit fpga_exit(void)
1131{ 1130{
1132 of_unregister_platform_driver(&fpga_of_driver); 1131 platform_driver_unregister(&fpga_of_driver);
1133 led_trigger_unregister_simple(ledtrig_fpga); 1132 led_trigger_unregister_simple(ledtrig_fpga);
1134} 1133}
1135 1134
diff --git a/drivers/misc/carma/carma-fpga.c b/drivers/misc/carma/carma-fpga.c
index 3965821fef1..14e974b2a78 100644
--- a/drivers/misc/carma/carma-fpga.c
+++ b/drivers/misc/carma/carma-fpga.c
@@ -1249,8 +1249,7 @@ static bool dma_filter(struct dma_chan *chan, void *data)
1249 return true; 1249 return true;
1250} 1250}
1251 1251
1252static int data_of_probe(struct platform_device *op, 1252static int data_of_probe(struct platform_device *op)
1253 const struct of_device_id *match)
1254{ 1253{
1255 struct device_node *of_node = op->dev.of_node; 1254 struct device_node *of_node = op->dev.of_node;
1256 struct device *this_device; 1255 struct device *this_device;
@@ -1401,7 +1400,7 @@ static struct of_device_id data_of_match[] = {
1401 {}, 1400 {},
1402}; 1401};
1403 1402
1404static struct of_platform_driver data_of_driver = { 1403static struct platform_driver data_of_driver = {
1405 .probe = data_of_probe, 1404 .probe = data_of_probe,
1406 .remove = data_of_remove, 1405 .remove = data_of_remove,
1407 .driver = { 1406 .driver = {
@@ -1417,12 +1416,12 @@ static struct of_platform_driver data_of_driver = {
1417 1416
1418static int __init data_init(void) 1417static int __init data_init(void)
1419{ 1418{
1420 return of_register_platform_driver(&data_of_driver); 1419 return platform_driver_register(&data_of_driver);
1421} 1420}
1422 1421
1423static void __exit data_exit(void) 1422static void __exit data_exit(void)
1424{ 1423{
1425 of_unregister_platform_driver(&data_of_driver); 1424 platform_driver_unregister(&data_of_driver);
1426} 1425}
1427 1426
1428MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>"); 1427MODULE_AUTHOR("Ira W. Snyder <iws@ovro.caltech.edu>");
diff --git a/drivers/misc/eeprom/Kconfig b/drivers/misc/eeprom/Kconfig
index 26cf12ca7f5..701edf65897 100644
--- a/drivers/misc/eeprom/Kconfig
+++ b/drivers/misc/eeprom/Kconfig
@@ -85,7 +85,7 @@ config EEPROM_93XX46
85 85
86config EEPROM_DIGSY_MTC_CFG 86config EEPROM_DIGSY_MTC_CFG
87 bool "DigsyMTC display configuration EEPROMs device" 87 bool "DigsyMTC display configuration EEPROMs device"
88 depends on PPC_MPC5200_GPIO && GPIOLIB && SPI_GPIO 88 depends on GPIO_MPC5200 && SPI_GPIO
89 help 89 help
90 This option enables access to display configuration EEPROMs 90 This option enables access to display configuration EEPROMs
91 on digsy_mtc board. You have to additionally select Microwire 91 on digsy_mtc board. You have to additionally select Microwire
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 8cebec5e85e..3f7ad83ed74 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/pch_phub.c b/drivers/misc/pch_phub.c
index dee33addcae..10fc4785dba 100644
--- a/drivers/misc/pch_phub.c
+++ b/drivers/misc/pch_phub.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. 2 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -41,10 +41,10 @@
41#define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset 41#define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset
42 (Intel EG20T PCH)*/ 42 (Intel EG20T PCH)*/
43#define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address 43#define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address
44 offset(OKI SEMICONDUCTOR ML7213) 44 offset(LAPIS Semicon ML7213)
45 */ 45 */
46#define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address 46#define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address
47 offset(OKI SEMICONDUCTOR ML7223) 47 offset(LAPIS Semicon ML7223)
48 */ 48 */
49 49
50/* MAX number of INT_REDUCE_CONTROL registers */ 50/* MAX number of INT_REDUCE_CONTROL registers */
@@ -73,6 +73,9 @@
73#define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */ 73#define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */
74#define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */ 74#define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */
75 75
76/* Macros for ML7831 */
77#define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801
78
76/* SROM ACCESS Macro */ 79/* SROM ACCESS Macro */
77#define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) 80#define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
78 81
@@ -115,6 +118,7 @@
115 * @pch_mac_start_address: MAC address area start address 118 * @pch_mac_start_address: MAC address area start address
116 * @pch_opt_rom_start_address: Option ROM start address 119 * @pch_opt_rom_start_address: Option ROM start address
117 * @ioh_type: Save IOH type 120 * @ioh_type: Save IOH type
121 * @pdev: pointer to pci device struct
118 */ 122 */
119struct pch_phub_reg { 123struct pch_phub_reg {
120 u32 phub_id_reg; 124 u32 phub_id_reg;
@@ -136,6 +140,7 @@ struct pch_phub_reg {
136 u32 pch_mac_start_address; 140 u32 pch_mac_start_address;
137 u32 pch_opt_rom_start_address; 141 u32 pch_opt_rom_start_address;
138 int ioh_type; 142 int ioh_type;
143 struct pci_dev *pdev;
139}; 144};
140 145
141/* SROM SPEC for MAC address assignment offset */ 146/* SROM SPEC for MAC address assignment offset */
@@ -471,7 +476,7 @@ static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
471 int retval; 476 int retval;
472 int i; 477 int i;
473 478
474 if (chip->ioh_type == 1) /* EG20T */ 479 if ((chip->ioh_type == 1) || (chip->ioh_type == 5)) /* EG20T or ML7831*/
475 retval = pch_phub_gbe_serial_rom_conf(chip); 480 retval = pch_phub_gbe_serial_rom_conf(chip);
476 else /* ML7223 */ 481 else /* ML7223 */
477 retval = pch_phub_gbe_serial_rom_conf_mp(chip); 482 retval = pch_phub_gbe_serial_rom_conf_mp(chip);
@@ -498,6 +503,7 @@ static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
498 unsigned int orom_size; 503 unsigned int orom_size;
499 int ret; 504 int ret;
500 int err; 505 int err;
506 ssize_t rom_size;
501 507
502 struct pch_phub_reg *chip = 508 struct pch_phub_reg *chip =
503 dev_get_drvdata(container_of(kobj, struct device, kobj)); 509 dev_get_drvdata(container_of(kobj, struct device, kobj));
@@ -509,6 +515,10 @@ static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
509 } 515 }
510 516
511 /* Get Rom signature */ 517 /* Get Rom signature */
518 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
519 if (!chip->pch_phub_extrom_base_address)
520 goto exrom_map_err;
521
512 pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address, 522 pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address,
513 (unsigned char *)&rom_signature); 523 (unsigned char *)&rom_signature);
514 rom_signature &= 0xff; 524 rom_signature &= 0xff;
@@ -539,10 +549,13 @@ static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
539 goto return_err; 549 goto return_err;
540 } 550 }
541return_ok: 551return_ok:
552 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
542 mutex_unlock(&pch_phub_mutex); 553 mutex_unlock(&pch_phub_mutex);
543 return addr_offset; 554 return addr_offset;
544 555
545return_err: 556return_err:
557 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
558exrom_map_err:
546 mutex_unlock(&pch_phub_mutex); 559 mutex_unlock(&pch_phub_mutex);
547return_err_nomutex: 560return_err_nomutex:
548 return err; 561 return err;
@@ -555,6 +568,7 @@ static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
555 int err; 568 int err;
556 unsigned int addr_offset; 569 unsigned int addr_offset;
557 int ret; 570 int ret;
571 ssize_t rom_size;
558 struct pch_phub_reg *chip = 572 struct pch_phub_reg *chip =
559 dev_get_drvdata(container_of(kobj, struct device, kobj)); 573 dev_get_drvdata(container_of(kobj, struct device, kobj));
560 574
@@ -571,6 +585,12 @@ static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
571 goto return_ok; 585 goto return_ok;
572 } 586 }
573 587
588 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
589 if (!chip->pch_phub_extrom_base_address) {
590 err = -ENOMEM;
591 goto exrom_map_err;
592 }
593
574 for (addr_offset = 0; addr_offset < count; addr_offset++) { 594 for (addr_offset = 0; addr_offset < count; addr_offset++) {
575 if (PCH_PHUB_OROM_SIZE < off + addr_offset) 595 if (PCH_PHUB_OROM_SIZE < off + addr_offset)
576 goto return_ok; 596 goto return_ok;
@@ -585,10 +605,14 @@ static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
585 } 605 }
586 606
587return_ok: 607return_ok:
608 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
588 mutex_unlock(&pch_phub_mutex); 609 mutex_unlock(&pch_phub_mutex);
589 return addr_offset; 610 return addr_offset;
590 611
591return_err: 612return_err:
613 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
614
615exrom_map_err:
592 mutex_unlock(&pch_phub_mutex); 616 mutex_unlock(&pch_phub_mutex);
593 return err; 617 return err;
594} 618}
@@ -598,8 +622,14 @@ static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
598{ 622{
599 u8 mac[8]; 623 u8 mac[8];
600 struct pch_phub_reg *chip = dev_get_drvdata(dev); 624 struct pch_phub_reg *chip = dev_get_drvdata(dev);
625 ssize_t rom_size;
626
627 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
628 if (!chip->pch_phub_extrom_base_address)
629 return -ENOMEM;
601 630
602 pch_phub_read_gbe_mac_addr(chip, mac); 631 pch_phub_read_gbe_mac_addr(chip, mac);
632 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
603 633
604 return sprintf(buf, "%pM\n", mac); 634 return sprintf(buf, "%pM\n", mac);
605} 635}
@@ -608,6 +638,7 @@ static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
608 const char *buf, size_t count) 638 const char *buf, size_t count)
609{ 639{
610 u8 mac[6]; 640 u8 mac[6];
641 ssize_t rom_size;
611 struct pch_phub_reg *chip = dev_get_drvdata(dev); 642 struct pch_phub_reg *chip = dev_get_drvdata(dev);
612 643
613 if (count != 18) 644 if (count != 18)
@@ -617,7 +648,12 @@ static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
617 (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3], 648 (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3],
618 (u32 *)&mac[4], (u32 *)&mac[5]); 649 (u32 *)&mac[4], (u32 *)&mac[5]);
619 650
651 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
652 if (!chip->pch_phub_extrom_base_address)
653 return -ENOMEM;
654
620 pch_phub_write_gbe_mac_addr(chip, mac); 655 pch_phub_write_gbe_mac_addr(chip, mac);
656 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
621 657
622 return count; 658 return count;
623} 659}
@@ -640,7 +676,6 @@ static int __devinit pch_phub_probe(struct pci_dev *pdev,
640 int retval; 676 int retval;
641 677
642 int ret; 678 int ret;
643 ssize_t rom_size;
644 struct pch_phub_reg *chip; 679 struct pch_phub_reg *chip;
645 680
646 chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL); 681 chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL);
@@ -677,19 +712,7 @@ static int __devinit pch_phub_probe(struct pci_dev *pdev,
677 "in pch_phub_base_address variable is %p\n", __func__, 712 "in pch_phub_base_address variable is %p\n", __func__,
678 chip->pch_phub_base_address); 713 chip->pch_phub_base_address);
679 714
680 if (id->driver_data != 3) { 715 chip->pdev = pdev; /* Save pci device struct */
681 chip->pch_phub_extrom_base_address =\
682 pci_map_rom(pdev, &rom_size);
683 if (chip->pch_phub_extrom_base_address == 0) {
684 dev_err(&pdev->dev, "%s: pci_map_rom FAILED", __func__);
685 ret = -ENOMEM;
686 goto err_pci_map;
687 }
688 dev_dbg(&pdev->dev, "%s : "
689 "pci_map_rom SUCCESS and value in "
690 "pch_phub_extrom_base_address variable is %p\n",
691 __func__, chip->pch_phub_extrom_base_address);
692 }
693 716
694 if (id->driver_data == 1) { /* EG20T PCH */ 717 if (id->driver_data == 1) { /* EG20T PCH */
695 const char *board_name; 718 const char *board_name;
@@ -763,6 +786,22 @@ static int __devinit pch_phub_probe(struct pci_dev *pdev,
763 chip->pch_opt_rom_start_address =\ 786 chip->pch_opt_rom_start_address =\
764 PCH_PHUB_ROM_START_ADDR_ML7223; 787 PCH_PHUB_ROM_START_ADDR_ML7223;
765 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223; 788 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
789 } else if (id->driver_data == 5) { /* ML7831 */
790 retval = sysfs_create_file(&pdev->dev.kobj,
791 &dev_attr_pch_mac.attr);
792 if (retval)
793 goto err_sysfs_create;
794
795 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
796 if (retval)
797 goto exit_bin_attr;
798
799 /* set the prefech value */
800 iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
801 /* set the interrupt delay value */
802 iowrite32(0x25, chip->pch_phub_base_address + 0x44);
803 chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
804 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
766 } 805 }
767 806
768 chip->ioh_type = id->driver_data; 807 chip->ioh_type = id->driver_data;
@@ -773,8 +812,6 @@ exit_bin_attr:
773 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 812 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
774 813
775err_sysfs_create: 814err_sysfs_create:
776 pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address);
777err_pci_map:
778 pci_iounmap(pdev, chip->pch_phub_base_address); 815 pci_iounmap(pdev, chip->pch_phub_base_address);
779err_pci_iomap: 816err_pci_iomap:
780 pci_release_regions(pdev); 817 pci_release_regions(pdev);
@@ -792,7 +829,6 @@ static void __devexit pch_phub_remove(struct pci_dev *pdev)
792 829
793 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 830 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
794 sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr); 831 sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr);
795 pci_unmap_rom(pdev, chip->pch_phub_extrom_base_address);
796 pci_iounmap(pdev, chip->pch_phub_base_address); 832 pci_iounmap(pdev, chip->pch_phub_base_address);
797 pci_release_regions(pdev); 833 pci_release_regions(pdev);
798 pci_disable_device(pdev); 834 pci_disable_device(pdev);
@@ -847,6 +883,7 @@ static struct pci_device_id pch_phub_pcidev_id[] = {
847 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, }, 883 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, },
848 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, }, 884 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, },
849 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, }, 885 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, },
886 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7831_PHUB), 5, },
850 { } 887 { }
851}; 888};
852MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id); 889MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id);
@@ -873,5 +910,5 @@ static void __exit pch_phub_pci_exit(void)
873module_init(pch_phub_pci_init); 910module_init(pch_phub_pci_init);
874module_exit(pch_phub_pci_exit); 911module_exit(pch_phub_pci_exit);
875 912
876MODULE_DESCRIPTION("Intel EG20T PCH/OKI SEMICONDUCTOR IOH(ML7213/ML7223) PHUB"); 913MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB");
877MODULE_LICENSE("GPL"); 914MODULE_LICENSE("GPL");
diff --git a/drivers/misc/sgi-gru/grukservices.c b/drivers/misc/sgi-gru/grukservices.c
index 9e9bddaa95a..913de07e577 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/spear13xx_pcie_gadget.c b/drivers/misc/spear13xx_pcie_gadget.c
index cfbddbef11d..43d073bc1d9 100644
--- a/drivers/misc/spear13xx_pcie_gadget.c
+++ b/drivers/misc/spear13xx_pcie_gadget.c
@@ -903,6 +903,6 @@ static void __exit spear_pcie_gadget_exit(void)
903} 903}
904module_exit(spear_pcie_gadget_exit); 904module_exit(spear_pcie_gadget_exit);
905 905
906MODULE_ALIAS("pcie-gadget-spear"); 906MODULE_ALIAS("platform:pcie-gadget-spear");
907MODULE_AUTHOR("Pratyush Anand"); 907MODULE_AUTHOR("Pratyush Anand");
908MODULE_LICENSE("GPL"); 908MODULE_LICENSE("GPL");
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 3a3580566df..43ef8d162f2 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 a6ef18259da..ba247902267 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 44d4475a09d..0bd5349b042 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/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 46b6e84d953..6be49249895 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 6045ea46936..3923880118b 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 ca2e4f50f61..e8a5eb38748 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 36270449dd9..dbf421a6279 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 007863eea4f..4d41fa984c9 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 6c3cf98a62e..06ee1aeaace 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 a230e7f9d77..f2a05ea40f2 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 46a785419fa..274ef00b446 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 c643b2f78bf..40989e6bb53 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 0f687cdeb06..b1f3168f791 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 b644dd59c16..68f81b9ee0f 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 87d5067ba62..cf444b0ca2c 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 707bc7dddd2..5d3b9ae6452 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 e8ff1239668..101cd31c822 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 d2856b6b2a6..720f99334a7 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-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index ae57769ba50..4b976f00ea8 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,7 @@
32/* VENDOR SPEC register */ 32/* VENDOR SPEC register */
33#define SDHCI_VENDOR_SPEC 0xC0 33#define SDHCI_VENDOR_SPEC 0xC0
34#define SDHCI_VENDOR_SPEC_SDIO_QUIRK 0x00000002 34#define SDHCI_VENDOR_SPEC_SDIO_QUIRK 0x00000002
35#define SDHCI_WTMK_LVL 0x44
35#define SDHCI_MIX_CTRL 0x48 36#define SDHCI_MIX_CTRL 0x48
36 37
37/* 38/*
@@ -476,6 +477,13 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
476 if (is_imx53_esdhc(imx_data)) 477 if (is_imx53_esdhc(imx_data))
477 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT; 478 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
478 479
480 /*
481 * The imx6q ROM code will change the default watermark level setting
482 * to something insane. Change it back here.
483 */
484 if (is_imx6q_usdhc(imx_data))
485 writel(0x08100810, host->ioaddr + SDHCI_WTMK_LVL);
486
479 boarddata = &imx_data->boarddata; 487 boarddata = &imx_data->boarddata;
480 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) { 488 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
481 if (!host->mmc->parent->platform_data) { 489 if (!host->mmc->parent->platform_data) {
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index 067a4cded9c..89699e861fc 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/Kconfig b/drivers/mtd/Kconfig
index 66b616ebe53..318a869286a 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -12,27 +12,17 @@ menuconfig MTD
12 12
13if MTD 13if MTD
14 14
15config MTD_DEBUG
16 bool "Debugging"
17 help
18 This turns on low-level debugging for the entire MTD sub-system.
19 Normally, you should say 'N'.
20
21config MTD_DEBUG_VERBOSE
22 int "Debugging verbosity (0 = quiet, 3 = noisy)"
23 depends on MTD_DEBUG
24 default "0"
25 help
26 Determines the verbosity level of the MTD debugging messages.
27
28config MTD_TESTS 15config MTD_TESTS
29 tristate "MTD tests support" 16 tristate "MTD tests support (DANGEROUS)"
30 depends on m 17 depends on m
31 help 18 help
32 This option includes various MTD tests into compilation. The tests 19 This option includes various MTD tests into compilation. The tests
33 should normally be compiled as kernel modules. The modules perform 20 should normally be compiled as kernel modules. The modules perform
34 various checks and verifications when loaded. 21 various checks and verifications when loaded.
35 22
23 WARNING: some of the tests will ERASE entire MTD device which they
24 test. Do not use these tests unless you really know what you do.
25
36config MTD_REDBOOT_PARTS 26config MTD_REDBOOT_PARTS
37 tristate "RedBoot partition table parsing" 27 tristate "RedBoot partition table parsing"
38 ---help--- 28 ---help---
@@ -137,7 +127,8 @@ config MTD_AFS_PARTS
137 'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example. 127 'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example.
138 128
139config MTD_OF_PARTS 129config MTD_OF_PARTS
140 def_bool y 130 tristate "OpenFirmware partitioning information support"
131 default Y
141 depends on OF 132 depends on OF
142 help 133 help
143 This provides a partition parsing function which derives 134 This provides a partition parsing function which derives
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 39664c4229f..9aaac3ac89f 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -5,8 +5,8 @@
5# Core functionality. 5# Core functionality.
6obj-$(CONFIG_MTD) += mtd.o 6obj-$(CONFIG_MTD) += mtd.o
7mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o 7mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o
8mtd-$(CONFIG_MTD_OF_PARTS) += ofpart.o
9 8
9obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
10obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o 10obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
11obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o 11obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
12obj-$(CONFIG_MTD_AFS_PARTS) += afs.o 12obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index 302372c08b5..89a02f6f65d 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -162,8 +162,8 @@ afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr)
162} 162}
163 163
164static int parse_afs_partitions(struct mtd_info *mtd, 164static int parse_afs_partitions(struct mtd_info *mtd,
165 struct mtd_partition **pparts, 165 struct mtd_partition **pparts,
166 unsigned long origin) 166 struct mtd_part_parser_data *data)
167{ 167{
168 struct mtd_partition *parts; 168 struct mtd_partition *parts;
169 u_int mask, off, idx, sz; 169 u_int mask, off, idx, sz;
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c
index 6697a1ec72d..f40ea454755 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
@@ -46,7 +47,7 @@ struct ar7_bin_rec {
46 47
47static int create_mtd_partitions(struct mtd_info *master, 48static int create_mtd_partitions(struct mtd_info *master,
48 struct mtd_partition **pparts, 49 struct mtd_partition **pparts,
49 unsigned long origin) 50 struct mtd_part_parser_data *data)
50{ 51{
51 struct ar7_bin_rec header; 52 struct ar7_bin_rec header;
52 unsigned int offset; 53 unsigned int offset;
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 23175edd563..8d70895a58d 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -145,8 +145,7 @@ static void fixup_amd_bootblock(struct mtd_info *mtd)
145 if (((major << 8) | minor) < 0x3131) { 145 if (((major << 8) | minor) < 0x3131) {
146 /* CFI version 1.0 => don't trust bootloc */ 146 /* CFI version 1.0 => don't trust bootloc */
147 147
148 DEBUG(MTD_DEBUG_LEVEL1, 148 pr_debug("%s: JEDEC Vendor ID is 0x%02X Device ID is 0x%02X\n",
149 "%s: JEDEC Vendor ID is 0x%02X Device ID is 0x%02X\n",
150 map->name, cfi->mfr, cfi->id); 149 map->name, cfi->mfr, cfi->id);
151 150
152 /* AFAICS all 29LV400 with a bottom boot block have a device ID 151 /* AFAICS all 29LV400 with a bottom boot block have a device ID
@@ -166,8 +165,7 @@ static void fixup_amd_bootblock(struct mtd_info *mtd)
166 * the 8-bit device ID. 165 * the 8-bit device ID.
167 */ 166 */
168 (cfi->mfr == CFI_MFR_MACRONIX)) { 167 (cfi->mfr == CFI_MFR_MACRONIX)) {
169 DEBUG(MTD_DEBUG_LEVEL1, 168 pr_debug("%s: Macronix MX29LV400C with bottom boot block"
170 "%s: Macronix MX29LV400C with bottom boot block"
171 " detected\n", map->name); 169 " detected\n", map->name);
172 extp->TopBottom = 2; /* bottom boot */ 170 extp->TopBottom = 2; /* bottom boot */
173 } else 171 } else
@@ -178,8 +176,7 @@ static void fixup_amd_bootblock(struct mtd_info *mtd)
178 extp->TopBottom = 2; /* bottom boot */ 176 extp->TopBottom = 2; /* bottom boot */
179 } 177 }
180 178
181 DEBUG(MTD_DEBUG_LEVEL1, 179 pr_debug("%s: AMD CFI PRI V%c.%c has no boot block field;"
182 "%s: AMD CFI PRI V%c.%c has no boot block field;"
183 " deduced %s from Device ID\n", map->name, major, minor, 180 " deduced %s from Device ID\n", map->name, major, minor,
184 extp->TopBottom == 2 ? "bottom" : "top"); 181 extp->TopBottom == 2 ? "bottom" : "top");
185 } 182 }
@@ -191,7 +188,7 @@ static void fixup_use_write_buffers(struct mtd_info *mtd)
191 struct map_info *map = mtd->priv; 188 struct map_info *map = mtd->priv;
192 struct cfi_private *cfi = map->fldrv_priv; 189 struct cfi_private *cfi = map->fldrv_priv;
193 if (cfi->cfiq->BufWriteTimeoutTyp) { 190 if (cfi->cfiq->BufWriteTimeoutTyp) {
194 DEBUG(MTD_DEBUG_LEVEL1, "Using buffer write method\n" ); 191 pr_debug("Using buffer write method\n" );
195 mtd->write = cfi_amdstd_write_buffers; 192 mtd->write = cfi_amdstd_write_buffers;
196 } 193 }
197} 194}
@@ -443,8 +440,8 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
443 mtd->writesize = 1; 440 mtd->writesize = 1;
444 mtd->writebufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize; 441 mtd->writebufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
445 442
446 DEBUG(MTD_DEBUG_LEVEL3, "MTD %s(): write buffer size %d\n", 443 pr_debug("MTD %s(): write buffer size %d\n", __func__,
447 __func__, mtd->writebufsize); 444 mtd->writebufsize);
448 445
449 mtd->reboot_notifier.notifier_call = cfi_amdstd_reboot; 446 mtd->reboot_notifier.notifier_call = cfi_amdstd_reboot;
450 447
@@ -1163,7 +1160,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1163 return ret; 1160 return ret;
1164 } 1161 }
1165 1162
1166 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", 1163 pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n",
1167 __func__, adr, datum.x[0] ); 1164 __func__, adr, datum.x[0] );
1168 1165
1169 /* 1166 /*
@@ -1174,7 +1171,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
1174 */ 1171 */
1175 oldd = map_read(map, adr); 1172 oldd = map_read(map, adr);
1176 if (map_word_equal(map, oldd, datum)) { 1173 if (map_word_equal(map, oldd, datum)) {
1177 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): NOP\n", 1174 pr_debug("MTD %s(): NOP\n",
1178 __func__); 1175 __func__);
1179 goto op_done; 1176 goto op_done;
1180 } 1177 }
@@ -1400,7 +1397,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
1400 1397
1401 datum = map_word_load(map, buf); 1398 datum = map_word_load(map, buf);
1402 1399
1403 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", 1400 pr_debug("MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n",
1404 __func__, adr, datum.x[0] ); 1401 __func__, adr, datum.x[0] );
1405 1402
1406 XIP_INVAL_CACHED_RANGE(map, adr, len); 1403 XIP_INVAL_CACHED_RANGE(map, adr, len);
@@ -1587,7 +1584,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
1587 return ret; 1584 return ret;
1588 } 1585 }
1589 1586
1590 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n", 1587 pr_debug("MTD %s(): ERASE 0x%.8lx\n",
1591 __func__, chip->start ); 1588 __func__, chip->start );
1592 1589
1593 XIP_INVAL_CACHED_RANGE(map, adr, map->size); 1590 XIP_INVAL_CACHED_RANGE(map, adr, map->size);
@@ -1675,7 +1672,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
1675 return ret; 1672 return ret;
1676 } 1673 }
1677 1674
1678 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n", 1675 pr_debug("MTD %s(): ERASE 0x%.8lx\n",
1679 __func__, adr ); 1676 __func__, adr );
1680 1677
1681 XIP_INVAL_CACHED_RANGE(map, adr, len); 1678 XIP_INVAL_CACHED_RANGE(map, adr, len);
@@ -1801,8 +1798,7 @@ static int do_atmel_lock(struct map_info *map, struct flchip *chip,
1801 goto out_unlock; 1798 goto out_unlock;
1802 chip->state = FL_LOCKING; 1799 chip->state = FL_LOCKING;
1803 1800
1804 DEBUG(MTD_DEBUG_LEVEL3, "MTD %s(): LOCK 0x%08lx len %d\n", 1801 pr_debug("MTD %s(): LOCK 0x%08lx len %d\n", __func__, adr, len);
1805 __func__, adr, len);
1806 1802
1807 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, 1803 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi,
1808 cfi->device_type, NULL); 1804 cfi->device_type, NULL);
@@ -1837,8 +1833,7 @@ static int do_atmel_unlock(struct map_info *map, struct flchip *chip,
1837 goto out_unlock; 1833 goto out_unlock;
1838 chip->state = FL_UNLOCKING; 1834 chip->state = FL_UNLOCKING;
1839 1835
1840 DEBUG(MTD_DEBUG_LEVEL3, "MTD %s(): LOCK 0x%08lx len %d\n", 1836 pr_debug("MTD %s(): LOCK 0x%08lx len %d\n", __func__, adr, len);
1841 __func__, adr, len);
1842 1837
1843 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, 1838 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi,
1844 cfi->device_type, NULL); 1839 cfi->device_type, NULL);
diff --git a/drivers/mtd/chips/fwh_lock.h b/drivers/mtd/chips/fwh_lock.h
index 5e3cc80128a..89c6595454a 100644
--- a/drivers/mtd/chips/fwh_lock.h
+++ b/drivers/mtd/chips/fwh_lock.h
@@ -34,8 +34,7 @@ static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip,
34 34
35 /* Refuse the operation if the we cannot look behind the chip */ 35 /* Refuse the operation if the we cannot look behind the chip */
36 if (chip->start < 0x400000) { 36 if (chip->start < 0x400000) {
37 DEBUG( MTD_DEBUG_LEVEL3, 37 pr_debug( "MTD %s(): chip->start: %lx wanted >= 0x400000\n",
38 "MTD %s(): chip->start: %lx wanted >= 0x400000\n",
39 __func__, chip->start ); 38 __func__, chip->start );
40 return -EIO; 39 return -EIO;
41 } 40 }
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index ea832ea0e4a..c443f527a53 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -1914,11 +1914,10 @@ static void jedec_reset(u32 base, struct map_info *map, struct cfi_private *cfi)
1914 * (oh and incidentaly the jedec spec - 3.5.3.3) the reset 1914 * (oh and incidentaly the jedec spec - 3.5.3.3) the reset
1915 * sequence is *supposed* to be 0xaa at 0x5555, 0x55 at 1915 * sequence is *supposed* to be 0xaa at 0x5555, 0x55 at
1916 * 0x2aaa, 0xF0 at 0x5555 this will not affect the AMD chips 1916 * 0x2aaa, 0xF0 at 0x5555 this will not affect the AMD chips
1917 * as they will ignore the writes and dont care what address 1917 * as they will ignore the writes and don't care what address
1918 * the F0 is written to */ 1918 * the F0 is written to */
1919 if (cfi->addr_unlock1) { 1919 if (cfi->addr_unlock1) {
1920 DEBUG( MTD_DEBUG_LEVEL3, 1920 pr_debug( "reset unlock called %x %x \n",
1921 "reset unlock called %x %x \n",
1922 cfi->addr_unlock1,cfi->addr_unlock2); 1921 cfi->addr_unlock1,cfi->addr_unlock2);
1923 cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL); 1922 cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);
1924 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, cfi->device_type, NULL); 1923 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, cfi->device_type, NULL);
@@ -1941,7 +1940,7 @@ static int cfi_jedec_setup(struct map_info *map, struct cfi_private *cfi, int in
1941 uint8_t uaddr; 1940 uint8_t uaddr;
1942 1941
1943 if (!(jedec_table[index].devtypes & cfi->device_type)) { 1942 if (!(jedec_table[index].devtypes & cfi->device_type)) {
1944 DEBUG(MTD_DEBUG_LEVEL1, "Rejecting potential %s with incompatible %d-bit device type\n", 1943 pr_debug("Rejecting potential %s with incompatible %d-bit device type\n",
1945 jedec_table[index].name, 4 * (1<<cfi->device_type)); 1944 jedec_table[index].name, 4 * (1<<cfi->device_type));
1946 return 0; 1945 return 0;
1947 } 1946 }
@@ -2021,7 +2020,7 @@ static inline int jedec_match( uint32_t base,
2021 * there aren't. 2020 * there aren't.
2022 */ 2021 */
2023 if (finfo->dev_id > 0xff) { 2022 if (finfo->dev_id > 0xff) {
2024 DEBUG( MTD_DEBUG_LEVEL3, "%s(): ID is not 8bit\n", 2023 pr_debug("%s(): ID is not 8bit\n",
2025 __func__); 2024 __func__);
2026 goto match_done; 2025 goto match_done;
2027 } 2026 }
@@ -2045,12 +2044,10 @@ static inline int jedec_match( uint32_t base,
2045 } 2044 }
2046 2045
2047 /* the part size must fit in the memory window */ 2046 /* the part size must fit in the memory window */
2048 DEBUG( MTD_DEBUG_LEVEL3, 2047 pr_debug("MTD %s(): Check fit 0x%.8x + 0x%.8x = 0x%.8x\n",
2049 "MTD %s(): Check fit 0x%.8x + 0x%.8x = 0x%.8x\n",
2050 __func__, base, 1 << finfo->dev_size, base + (1 << finfo->dev_size) ); 2048 __func__, base, 1 << finfo->dev_size, base + (1 << finfo->dev_size) );
2051 if ( base + cfi_interleave(cfi) * ( 1 << finfo->dev_size ) > map->size ) { 2049 if ( base + cfi_interleave(cfi) * ( 1 << finfo->dev_size ) > map->size ) {
2052 DEBUG( MTD_DEBUG_LEVEL3, 2050 pr_debug("MTD %s(): 0x%.4x 0x%.4x %dKiB doesn't fit\n",
2053 "MTD %s(): 0x%.4x 0x%.4x %dKiB doesn't fit\n",
2054 __func__, finfo->mfr_id, finfo->dev_id, 2051 __func__, finfo->mfr_id, finfo->dev_id,
2055 1 << finfo->dev_size ); 2052 1 << finfo->dev_size );
2056 goto match_done; 2053 goto match_done;
@@ -2061,13 +2058,12 @@ static inline int jedec_match( uint32_t base,
2061 2058
2062 uaddr = finfo->uaddr; 2059 uaddr = finfo->uaddr;
2063 2060
2064 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): check unlock addrs 0x%.4x 0x%.4x\n", 2061 pr_debug("MTD %s(): check unlock addrs 0x%.4x 0x%.4x\n",
2065 __func__, cfi->addr_unlock1, cfi->addr_unlock2 ); 2062 __func__, cfi->addr_unlock1, cfi->addr_unlock2 );
2066 if ( MTD_UADDR_UNNECESSARY != uaddr && MTD_UADDR_DONT_CARE != uaddr 2063 if ( MTD_UADDR_UNNECESSARY != uaddr && MTD_UADDR_DONT_CARE != uaddr
2067 && ( unlock_addrs[uaddr].addr1 / cfi->device_type != cfi->addr_unlock1 || 2064 && ( unlock_addrs[uaddr].addr1 / cfi->device_type != cfi->addr_unlock1 ||
2068 unlock_addrs[uaddr].addr2 / cfi->device_type != cfi->addr_unlock2 ) ) { 2065 unlock_addrs[uaddr].addr2 / cfi->device_type != cfi->addr_unlock2 ) ) {
2069 DEBUG( MTD_DEBUG_LEVEL3, 2066 pr_debug("MTD %s(): 0x%.4x 0x%.4x did not match\n",
2070 "MTD %s(): 0x%.4x 0x%.4x did not match\n",
2071 __func__, 2067 __func__,
2072 unlock_addrs[uaddr].addr1, 2068 unlock_addrs[uaddr].addr1,
2073 unlock_addrs[uaddr].addr2); 2069 unlock_addrs[uaddr].addr2);
@@ -2083,15 +2079,13 @@ static inline int jedec_match( uint32_t base,
2083 * FIXME - write a driver that takes all of the chip info as 2079 * FIXME - write a driver that takes all of the chip info as
2084 * module parameters, doesn't probe but forces a load. 2080 * module parameters, doesn't probe but forces a load.
2085 */ 2081 */
2086 DEBUG( MTD_DEBUG_LEVEL3, 2082 pr_debug("MTD %s(): check ID's disappear when not in ID mode\n",
2087 "MTD %s(): check ID's disappear when not in ID mode\n",
2088 __func__ ); 2083 __func__ );
2089 jedec_reset( base, map, cfi ); 2084 jedec_reset( base, map, cfi );
2090 mfr = jedec_read_mfr( map, base, cfi ); 2085 mfr = jedec_read_mfr( map, base, cfi );
2091 id = jedec_read_id( map, base, cfi ); 2086 id = jedec_read_id( map, base, cfi );
2092 if ( mfr == cfi->mfr && id == cfi->id ) { 2087 if ( mfr == cfi->mfr && id == cfi->id ) {
2093 DEBUG( MTD_DEBUG_LEVEL3, 2088 pr_debug("MTD %s(): ID 0x%.2x:0x%.2x did not change after reset:\n"
2094 "MTD %s(): ID 0x%.2x:0x%.2x did not change after reset:\n"
2095 "You might need to manually specify JEDEC parameters.\n", 2089 "You might need to manually specify JEDEC parameters.\n",
2096 __func__, cfi->mfr, cfi->id ); 2090 __func__, cfi->mfr, cfi->id );
2097 goto match_done; 2091 goto match_done;
@@ -2104,7 +2098,7 @@ static inline int jedec_match( uint32_t base,
2104 * Put the device back in ID mode - only need to do this if we 2098 * Put the device back in ID mode - only need to do this if we
2105 * were truly frobbing a real device. 2099 * were truly frobbing a real device.
2106 */ 2100 */
2107 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): return to ID mode\n", __func__ ); 2101 pr_debug("MTD %s(): return to ID mode\n", __func__ );
2108 if (cfi->addr_unlock1) { 2102 if (cfi->addr_unlock1) {
2109 cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL); 2103 cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);
2110 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, cfi->device_type, NULL); 2104 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, cfi->device_type, NULL);
@@ -2167,13 +2161,11 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
2167 2161
2168 cfi->mfr = jedec_read_mfr(map, base, cfi); 2162 cfi->mfr = jedec_read_mfr(map, base, cfi);
2169 cfi->id = jedec_read_id(map, base, cfi); 2163 cfi->id = jedec_read_id(map, base, cfi);
2170 DEBUG(MTD_DEBUG_LEVEL3, 2164 pr_debug("Search for id:(%02x %02x) interleave(%d) type(%d)\n",
2171 "Search for id:(%02x %02x) interleave(%d) type(%d)\n",
2172 cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type); 2165 cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type);
2173 for (i = 0; i < ARRAY_SIZE(jedec_table); i++) { 2166 for (i = 0; i < ARRAY_SIZE(jedec_table); i++) {
2174 if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) { 2167 if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) {
2175 DEBUG( MTD_DEBUG_LEVEL3, 2168 pr_debug("MTD %s(): matched device 0x%x,0x%x unlock_addrs: 0x%.4x 0x%.4x\n",
2176 "MTD %s(): matched device 0x%x,0x%x unlock_addrs: 0x%.4x 0x%.4x\n",
2177 __func__, cfi->mfr, cfi->id, 2169 __func__, cfi->mfr, cfi->id,
2178 cfi->addr_unlock1, cfi->addr_unlock2 ); 2170 cfi->addr_unlock1, cfi->addr_unlock2 );
2179 if (!cfi_jedec_setup(map, cfi, i)) 2171 if (!cfi_jedec_setup(map, cfi, i))
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index e790f38893b..ddf9ec6d916 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: "
@@ -188,10 +189,7 @@ static struct mtd_partition * newpart(char *s,
188 extra_mem_size; 189 extra_mem_size;
189 parts = kzalloc(alloc_size, GFP_KERNEL); 190 parts = kzalloc(alloc_size, GFP_KERNEL);
190 if (!parts) 191 if (!parts)
191 {
192 printk(KERN_ERR ERRP "out of memory\n");
193 return NULL; 192 return NULL;
194 }
195 extra_mem = (unsigned char *)(parts + *num_parts); 193 extra_mem = (unsigned char *)(parts + *num_parts);
196 } 194 }
197 /* enter this partition (offset will be calculated later if it is zero at this point) */ 195 /* enter this partition (offset will be calculated later if it is zero at this point) */
@@ -316,8 +314,8 @@ static int mtdpart_setup_real(char *s)
316 * the first one in the chain if a NULL mtd_id is passed in. 314 * the first one in the chain if a NULL mtd_id is passed in.
317 */ 315 */
318static int parse_cmdline_partitions(struct mtd_info *master, 316static int parse_cmdline_partitions(struct mtd_info *master,
319 struct mtd_partition **pparts, 317 struct mtd_partition **pparts,
320 unsigned long origin) 318 struct mtd_part_parser_data *data)
321{ 319{
322 unsigned long offset; 320 unsigned long offset;
323 int i; 321 int i;
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index 35081ce77fb..283d887f782 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -249,6 +249,16 @@ config MTD_DOC2001PLUS
249 under "NAND Flash Device Drivers" (currently that driver does not 249 under "NAND Flash Device Drivers" (currently that driver does not
250 support all Millennium Plus devices). 250 support all Millennium Plus devices).
251 251
252config MTD_DOCG3
253 tristate "M-Systems Disk-On-Chip G3"
254 ---help---
255 This provides an MTD device driver for the M-Systems DiskOnChip
256 G3 devices.
257
258 The driver provides access to G3 DiskOnChip, distributed by
259 M-Systems and now Sandisk. The support is very experimental,
260 and doesn't give access to any write operations.
261
252config MTD_DOCPROBE 262config MTD_DOCPROBE
253 tristate 263 tristate
254 select MTD_DOCECC 264 select MTD_DOCECC
@@ -268,8 +278,7 @@ config MTD_DOCPROBE_ADVANCED
268config MTD_DOCPROBE_ADDRESS 278config MTD_DOCPROBE_ADDRESS
269 hex "Physical address of DiskOnChip" if MTD_DOCPROBE_ADVANCED 279 hex "Physical address of DiskOnChip" if MTD_DOCPROBE_ADVANCED
270 depends on MTD_DOCPROBE 280 depends on MTD_DOCPROBE
271 default "0x0000" if MTD_DOCPROBE_ADVANCED 281 default "0x0"
272 default "0" if !MTD_DOCPROBE_ADVANCED
273 ---help--- 282 ---help---
274 By default, the probe for DiskOnChip devices will look for a 283 By default, the probe for DiskOnChip devices will look for a
275 DiskOnChip at every multiple of 0x2000 between 0xC8000 and 0xEE000. 284 DiskOnChip at every multiple of 0x2000 between 0xC8000 and 0xEE000.
diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
index f3226b1d38f..56c7cd462f1 100644
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -5,6 +5,7 @@
5obj-$(CONFIG_MTD_DOC2000) += doc2000.o 5obj-$(CONFIG_MTD_DOC2000) += doc2000.o
6obj-$(CONFIG_MTD_DOC2001) += doc2001.o 6obj-$(CONFIG_MTD_DOC2001) += doc2001.o
7obj-$(CONFIG_MTD_DOC2001PLUS) += doc2001plus.o 7obj-$(CONFIG_MTD_DOC2001PLUS) += doc2001plus.o
8obj-$(CONFIG_MTD_DOCG3) += docg3.o
8obj-$(CONFIG_MTD_DOCPROBE) += docprobe.o 9obj-$(CONFIG_MTD_DOCPROBE) += docprobe.o
9obj-$(CONFIG_MTD_DOCECC) += docecc.o 10obj-$(CONFIG_MTD_DOCECC) += docecc.o
10obj-$(CONFIG_MTD_SLRAM) += slram.o 11obj-$(CONFIG_MTD_SLRAM) += slram.o
@@ -17,3 +18,5 @@ obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o
17obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o 18obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
18obj-$(CONFIG_MTD_M25P80) += m25p80.o 19obj-$(CONFIG_MTD_M25P80) += m25p80.o
19obj-$(CONFIG_MTD_SST25L) += sst25l.o 20obj-$(CONFIG_MTD_SST25L) += sst25l.o
21
22CFLAGS_docg3.o += -I$(src) \ No newline at end of file
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index f7fbf6025ef..e9fad915121 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -82,8 +82,7 @@ static int _DoC_WaitReady(struct DiskOnChip *doc)
82 void __iomem *docptr = doc->virtadr; 82 void __iomem *docptr = doc->virtadr;
83 unsigned long timeo = jiffies + (HZ * 10); 83 unsigned long timeo = jiffies + (HZ * 10);
84 84
85 DEBUG(MTD_DEBUG_LEVEL3, 85 pr_debug("_DoC_WaitReady called for out-of-line wait\n");
86 "_DoC_WaitReady called for out-of-line wait\n");
87 86
88 /* Out-of-line routine to wait for chip response */ 87 /* Out-of-line routine to wait for chip response */
89 while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) { 88 while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) {
@@ -92,7 +91,7 @@ static int _DoC_WaitReady(struct DiskOnChip *doc)
92 DoC_Delay(doc, 2); 91 DoC_Delay(doc, 2);
93 92
94 if (time_after(jiffies, timeo)) { 93 if (time_after(jiffies, timeo)) {
95 DEBUG(MTD_DEBUG_LEVEL2, "_DoC_WaitReady timed out.\n"); 94 pr_debug("_DoC_WaitReady timed out.\n");
96 return -EIO; 95 return -EIO;
97 } 96 }
98 udelay(1); 97 udelay(1);
@@ -323,8 +322,7 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
323 322
324 /* Reset the chip */ 323 /* Reset the chip */
325 if (DoC_Command(doc, NAND_CMD_RESET, CDSN_CTRL_WP)) { 324 if (DoC_Command(doc, NAND_CMD_RESET, CDSN_CTRL_WP)) {
326 DEBUG(MTD_DEBUG_LEVEL2, 325 pr_debug("DoC_Command (reset) for %d,%d returned true\n",
327 "DoC_Command (reset) for %d,%d returned true\n",
328 floor, chip); 326 floor, chip);
329 return 0; 327 return 0;
330 } 328 }
@@ -332,8 +330,7 @@ static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip)
332 330
333 /* Read the NAND chip ID: 1. Send ReadID command */ 331 /* Read the NAND chip ID: 1. Send ReadID command */
334 if (DoC_Command(doc, NAND_CMD_READID, CDSN_CTRL_WP)) { 332 if (DoC_Command(doc, NAND_CMD_READID, CDSN_CTRL_WP)) {
335 DEBUG(MTD_DEBUG_LEVEL2, 333 pr_debug("DoC_Command (ReadID) for %d,%d returned true\n",
336 "DoC_Command (ReadID) for %d,%d returned true\n",
337 floor, chip); 334 floor, chip);
338 return 0; 335 return 0;
339 } 336 }
@@ -699,7 +696,7 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
699#ifdef ECC_DEBUG 696#ifdef ECC_DEBUG
700 printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from); 697 printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from);
701#endif 698#endif
702 /* Read the ECC syndrom through the DiskOnChip ECC 699 /* Read the ECC syndrome through the DiskOnChip ECC
703 logic. These syndrome will be all ZERO when there 700 logic. These syndrome will be all ZERO when there
704 is no error */ 701 is no error */
705 for (i = 0; i < 6; i++) { 702 for (i = 0; i < 6; i++) {
@@ -930,7 +927,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
930 uint8_t *buf = ops->oobbuf; 927 uint8_t *buf = ops->oobbuf;
931 size_t len = ops->len; 928 size_t len = ops->len;
932 929
933 BUG_ON(ops->mode != MTD_OOB_PLACE); 930 BUG_ON(ops->mode != MTD_OPS_PLACE_OOB);
934 931
935 ofs += ops->ooboffs; 932 ofs += ops->ooboffs;
936 933
@@ -1094,7 +1091,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
1094 struct DiskOnChip *this = mtd->priv; 1091 struct DiskOnChip *this = mtd->priv;
1095 int ret; 1092 int ret;
1096 1093
1097 BUG_ON(ops->mode != MTD_OOB_PLACE); 1094 BUG_ON(ops->mode != MTD_OPS_PLACE_OOB);
1098 1095
1099 mutex_lock(&this->lock); 1096 mutex_lock(&this->lock);
1100 ret = doc_write_oob_nolock(mtd, ofs + ops->ooboffs, ops->len, 1097 ret = doc_write_oob_nolock(mtd, ofs + ops->ooboffs, ops->len,
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index 241192f05bc..a3f7a27499b 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -55,15 +55,14 @@ static int _DoC_WaitReady(void __iomem * docptr)
55{ 55{
56 unsigned short c = 0xffff; 56 unsigned short c = 0xffff;
57 57
58 DEBUG(MTD_DEBUG_LEVEL3, 58 pr_debug("_DoC_WaitReady called for out-of-line wait\n");
59 "_DoC_WaitReady called for out-of-line wait\n");
60 59
61 /* Out-of-line routine to wait for chip response */ 60 /* Out-of-line routine to wait for chip response */
62 while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B) && --c) 61 while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B) && --c)
63 ; 62 ;
64 63
65 if (c == 0) 64 if (c == 0)
66 DEBUG(MTD_DEBUG_LEVEL2, "_DoC_WaitReady timed out.\n"); 65 pr_debug("_DoC_WaitReady timed out.\n");
67 66
68 return (c == 0); 67 return (c == 0);
69} 68}
@@ -464,7 +463,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
464#ifdef ECC_DEBUG 463#ifdef ECC_DEBUG
465 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from); 464 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from);
466#endif 465#endif
467 /* Read the ECC syndrom through the DiskOnChip ECC logic. 466 /* Read the ECC syndrome through the DiskOnChip ECC logic.
468 These syndrome will be all ZERO when there is no error */ 467 These syndrome will be all ZERO when there is no error */
469 for (i = 0; i < 6; i++) { 468 for (i = 0; i < 6; i++) {
470 syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i); 469 syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i);
@@ -632,7 +631,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
632 uint8_t *buf = ops->oobbuf; 631 uint8_t *buf = ops->oobbuf;
633 size_t len = ops->len; 632 size_t len = ops->len;
634 633
635 BUG_ON(ops->mode != MTD_OOB_PLACE); 634 BUG_ON(ops->mode != MTD_OPS_PLACE_OOB);
636 635
637 ofs += ops->ooboffs; 636 ofs += ops->ooboffs;
638 637
@@ -690,7 +689,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
690 uint8_t *buf = ops->oobbuf; 689 uint8_t *buf = ops->oobbuf;
691 size_t len = ops->len; 690 size_t len = ops->len;
692 691
693 BUG_ON(ops->mode != MTD_OOB_PLACE); 692 BUG_ON(ops->mode != MTD_OPS_PLACE_OOB);
694 693
695 ofs += ops->ooboffs; 694 ofs += ops->ooboffs;
696 695
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index 09ae0adc3ad..99351bc3e0e 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -61,15 +61,14 @@ static int _DoC_WaitReady(void __iomem * docptr)
61{ 61{
62 unsigned int c = 0xffff; 62 unsigned int c = 0xffff;
63 63
64 DEBUG(MTD_DEBUG_LEVEL3, 64 pr_debug("_DoC_WaitReady called for out-of-line wait\n");
65 "_DoC_WaitReady called for out-of-line wait\n");
66 65
67 /* Out-of-line routine to wait for chip response */ 66 /* Out-of-line routine to wait for chip response */
68 while (((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) && --c) 67 while (((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) && --c)
69 ; 68 ;
70 69
71 if (c == 0) 70 if (c == 0)
72 DEBUG(MTD_DEBUG_LEVEL2, "_DoC_WaitReady timed out.\n"); 71 pr_debug("_DoC_WaitReady timed out.\n");
73 72
74 return (c == 0); 73 return (c == 0);
75} 74}
@@ -655,7 +654,7 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
655#ifdef ECC_DEBUG 654#ifdef ECC_DEBUG
656 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from); 655 printk("DiskOnChip ECC Error: Read at %lx\n", (long)from);
657#endif 656#endif
658 /* Read the ECC syndrom through the DiskOnChip ECC logic. 657 /* Read the ECC syndrome through the DiskOnChip ECC logic.
659 These syndrome will be all ZERO when there is no error */ 658 These syndrome will be all ZERO when there is no error */
660 for (i = 0; i < 6; i++) 659 for (i = 0; i < 6; i++)
661 syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i); 660 syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i);
@@ -835,7 +834,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs,
835 uint8_t *buf = ops->oobbuf; 834 uint8_t *buf = ops->oobbuf;
836 size_t len = ops->len; 835 size_t len = ops->len;
837 836
838 BUG_ON(ops->mode != MTD_OOB_PLACE); 837 BUG_ON(ops->mode != MTD_OPS_PLACE_OOB);
839 838
840 ofs += ops->ooboffs; 839 ofs += ops->ooboffs;
841 840
@@ -920,7 +919,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs,
920 uint8_t *buf = ops->oobbuf; 919 uint8_t *buf = ops->oobbuf;
921 size_t len = ops->len; 920 size_t len = ops->len;
922 921
923 BUG_ON(ops->mode != MTD_OOB_PLACE); 922 BUG_ON(ops->mode != MTD_OPS_PLACE_OOB);
924 923
925 ofs += ops->ooboffs; 924 ofs += ops->ooboffs;
926 925
diff --git a/drivers/mtd/devices/docecc.c b/drivers/mtd/devices/docecc.c
index 37ef29a73ee..4a1c39b6f37 100644
--- a/drivers/mtd/devices/docecc.c
+++ b/drivers/mtd/devices/docecc.c
@@ -2,7 +2,7 @@
2 * ECC algorithm for M-systems disk on chip. We use the excellent Reed 2 * ECC algorithm for M-systems disk on chip. We use the excellent Reed
3 * Solmon code of Phil Karn (karn@ka9q.ampr.org) available under the 3 * Solmon code of Phil Karn (karn@ka9q.ampr.org) available under the
4 * GNU GPL License. The rest is simply to convert the disk on chip 4 * GNU GPL License. The rest is simply to convert the disk on chip
5 * syndrom into a standard syndom. 5 * syndrome into a standard syndome.
6 * 6 *
7 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 7 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
8 * Copyright (C) 2000 Netgem S.A. 8 * Copyright (C) 2000 Netgem S.A.
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
new file mode 100644
index 00000000000..bdcf5df982e
--- /dev/null
+++ b/drivers/mtd/devices/docg3.c
@@ -0,0 +1,1114 @@
1/*
2 * Handles the M-Systems DiskOnChip G3 chip
3 *
4 * Copyright (C) 2011 Robert Jarzmik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/platform_device.h>
26#include <linux/string.h>
27#include <linux/slab.h>
28#include <linux/io.h>
29#include <linux/delay.h>
30#include <linux/mtd/mtd.h>
31#include <linux/mtd/partitions.h>
32
33#include <linux/debugfs.h>
34#include <linux/seq_file.h>
35
36#define CREATE_TRACE_POINTS
37#include "docg3.h"
38
39/*
40 * This driver handles the DiskOnChip G3 flash memory.
41 *
42 * As no specification is available from M-Systems/Sandisk, this drivers lacks
43 * several functions available on the chip, as :
44 * - block erase
45 * - page write
46 * - IPL write
47 * - ECC fixing (lack of BCH algorith understanding)
48 * - powerdown / powerup
49 *
50 * The bus data width (8bits versus 16bits) is not handled (if_cfg flag), and
51 * the driver assumes a 16bits data bus.
52 *
53 * DocG3 relies on 2 ECC algorithms, which are handled in hardware :
54 * - a 1 byte Hamming code stored in the OOB for each page
55 * - a 7 bytes BCH code stored in the OOB for each page
56 * The BCH part is only used for check purpose, no correction is available as
57 * some information is missing. What is known is that :
58 * - BCH is in GF(2^14)
59 * - BCH is over data of 520 bytes (512 page + 7 page_info bytes
60 * + 1 hamming byte)
61 * - BCH can correct up to 4 bits (t = 4)
62 * - BCH syndroms are calculated in hardware, and checked in hardware as well
63 *
64 */
65
66static inline u8 doc_readb(struct docg3 *docg3, u16 reg)
67{
68 u8 val = readb(docg3->base + reg);
69
70 trace_docg3_io(0, 8, reg, (int)val);
71 return val;
72}
73
74static inline u16 doc_readw(struct docg3 *docg3, u16 reg)
75{
76 u16 val = readw(docg3->base + reg);
77
78 trace_docg3_io(0, 16, reg, (int)val);
79 return val;
80}
81
82static inline void doc_writeb(struct docg3 *docg3, u8 val, u16 reg)
83{
84 writeb(val, docg3->base + reg);
85 trace_docg3_io(1, 16, reg, val);
86}
87
88static inline void doc_writew(struct docg3 *docg3, u16 val, u16 reg)
89{
90 writew(val, docg3->base + reg);
91 trace_docg3_io(1, 16, reg, val);
92}
93
94static inline void doc_flash_command(struct docg3 *docg3, u8 cmd)
95{
96 doc_writeb(docg3, cmd, DOC_FLASHCOMMAND);
97}
98
99static inline void doc_flash_sequence(struct docg3 *docg3, u8 seq)
100{
101 doc_writeb(docg3, seq, DOC_FLASHSEQUENCE);
102}
103
104static inline void doc_flash_address(struct docg3 *docg3, u8 addr)
105{
106 doc_writeb(docg3, addr, DOC_FLASHADDRESS);
107}
108
109static char const *part_probes[] = { "cmdlinepart", "saftlpart", NULL };
110
111static int doc_register_readb(struct docg3 *docg3, int reg)
112{
113 u8 val;
114
115 doc_writew(docg3, reg, DOC_READADDRESS);
116 val = doc_readb(docg3, reg);
117 doc_vdbg("Read register %04x : %02x\n", reg, val);
118 return val;
119}
120
121static int doc_register_readw(struct docg3 *docg3, int reg)
122{
123 u16 val;
124
125 doc_writew(docg3, reg, DOC_READADDRESS);
126 val = doc_readw(docg3, reg);
127 doc_vdbg("Read register %04x : %04x\n", reg, val);
128 return val;
129}
130
131/**
132 * doc_delay - delay docg3 operations
133 * @docg3: the device
134 * @nbNOPs: the number of NOPs to issue
135 *
136 * As no specification is available, the right timings between chip commands are
137 * unknown. The only available piece of information are the observed nops on a
138 * working docg3 chip.
139 * Therefore, doc_delay relies on a busy loop of NOPs, instead of scheduler
140 * friendlier msleep() functions or blocking mdelay().
141 */
142static void doc_delay(struct docg3 *docg3, int nbNOPs)
143{
144 int i;
145
146 doc_dbg("NOP x %d\n", nbNOPs);
147 for (i = 0; i < nbNOPs; i++)
148 doc_writeb(docg3, 0, DOC_NOP);
149}
150
151static int is_prot_seq_error(struct docg3 *docg3)
152{
153 int ctrl;
154
155 ctrl = doc_register_readb(docg3, DOC_FLASHCONTROL);
156 return ctrl & (DOC_CTRL_PROTECTION_ERROR | DOC_CTRL_SEQUENCE_ERROR);
157}
158
159static int doc_is_ready(struct docg3 *docg3)
160{
161 int ctrl;
162
163 ctrl = doc_register_readb(docg3, DOC_FLASHCONTROL);
164 return ctrl & DOC_CTRL_FLASHREADY;
165}
166
167static int doc_wait_ready(struct docg3 *docg3)
168{
169 int maxWaitCycles = 100;
170
171 do {
172 doc_delay(docg3, 4);
173 cpu_relax();
174 } while (!doc_is_ready(docg3) && maxWaitCycles--);
175 doc_delay(docg3, 2);
176 if (maxWaitCycles > 0)
177 return 0;
178 else
179 return -EIO;
180}
181
182static int doc_reset_seq(struct docg3 *docg3)
183{
184 int ret;
185
186 doc_writeb(docg3, 0x10, DOC_FLASHCONTROL);
187 doc_flash_sequence(docg3, DOC_SEQ_RESET);
188 doc_flash_command(docg3, DOC_CMD_RESET);
189 doc_delay(docg3, 2);
190 ret = doc_wait_ready(docg3);
191
192 doc_dbg("doc_reset_seq() -> isReady=%s\n", ret ? "false" : "true");
193 return ret;
194}
195
196/**
197 * doc_read_data_area - Read data from data area
198 * @docg3: the device
199 * @buf: the buffer to fill in
200 * @len: the lenght to read
201 * @first: first time read, DOC_READADDRESS should be set
202 *
203 * Reads bytes from flash data. Handles the single byte / even bytes reads.
204 */
205static void doc_read_data_area(struct docg3 *docg3, void *buf, int len,
206 int first)
207{
208 int i, cdr, len4;
209 u16 data16, *dst16;
210 u8 data8, *dst8;
211
212 doc_dbg("doc_read_data_area(buf=%p, len=%d)\n", buf, len);
213 cdr = len & 0x3;
214 len4 = len - cdr;
215
216 if (first)
217 doc_writew(docg3, DOC_IOSPACE_DATA, DOC_READADDRESS);
218 dst16 = buf;
219 for (i = 0; i < len4; i += 2) {
220 data16 = doc_readw(docg3, DOC_IOSPACE_DATA);
221 *dst16 = data16;
222 dst16++;
223 }
224
225 if (cdr) {
226 doc_writew(docg3, DOC_IOSPACE_DATA | DOC_READADDR_ONE_BYTE,
227 DOC_READADDRESS);
228 doc_delay(docg3, 1);
229 dst8 = (u8 *)dst16;
230 for (i = 0; i < cdr; i++) {
231 data8 = doc_readb(docg3, DOC_IOSPACE_DATA);
232 *dst8 = data8;
233 dst8++;
234 }
235 }
236}
237
238/**
239 * doc_set_data_mode - Sets the flash to reliable data mode
240 * @docg3: the device
241 *
242 * The reliable data mode is a bit slower than the fast mode, but less errors
243 * occur. Entering the reliable mode cannot be done without entering the fast
244 * mode first.
245 */
246static void doc_set_reliable_mode(struct docg3 *docg3)
247{
248 doc_dbg("doc_set_reliable_mode()\n");
249 doc_flash_sequence(docg3, DOC_SEQ_SET_MODE);
250 doc_flash_command(docg3, DOC_CMD_FAST_MODE);
251 doc_flash_command(docg3, DOC_CMD_RELIABLE_MODE);
252 doc_delay(docg3, 2);
253}
254
255/**
256 * doc_set_asic_mode - Set the ASIC mode
257 * @docg3: the device
258 * @mode: the mode
259 *
260 * The ASIC can work in 3 modes :
261 * - RESET: all registers are zeroed
262 * - NORMAL: receives and handles commands
263 * - POWERDOWN: minimal poweruse, flash parts shut off
264 */
265static void doc_set_asic_mode(struct docg3 *docg3, u8 mode)
266{
267 int i;
268
269 for (i = 0; i < 12; i++)
270 doc_readb(docg3, DOC_IOSPACE_IPL);
271
272 mode |= DOC_ASICMODE_MDWREN;
273 doc_dbg("doc_set_asic_mode(%02x)\n", mode);
274 doc_writeb(docg3, mode, DOC_ASICMODE);
275 doc_writeb(docg3, ~mode, DOC_ASICMODECONFIRM);
276 doc_delay(docg3, 1);
277}
278
279/**
280 * doc_set_device_id - Sets the devices id for cascaded G3 chips
281 * @docg3: the device
282 * @id: the chip to select (amongst 0, 1, 2, 3)
283 *
284 * There can be 4 cascaded G3 chips. This function selects the one which will
285 * should be the active one.
286 */
287static void doc_set_device_id(struct docg3 *docg3, int id)
288{
289 u8 ctrl;
290
291 doc_dbg("doc_set_device_id(%d)\n", id);
292 doc_writeb(docg3, id, DOC_DEVICESELECT);
293 ctrl = doc_register_readb(docg3, DOC_FLASHCONTROL);
294
295 ctrl &= ~DOC_CTRL_VIOLATION;
296 ctrl |= DOC_CTRL_CE;
297 doc_writeb(docg3, ctrl, DOC_FLASHCONTROL);
298}
299
300/**
301 * doc_set_extra_page_mode - Change flash page layout
302 * @docg3: the device
303 *
304 * Normally, the flash page is split into the data (512 bytes) and the out of
305 * band data (16 bytes). For each, 4 more bytes can be accessed, where the wear
306 * leveling counters are stored. To access this last area of 4 bytes, a special
307 * mode must be input to the flash ASIC.
308 *
309 * Returns 0 if no error occured, -EIO else.
310 */
311static int doc_set_extra_page_mode(struct docg3 *docg3)
312{
313 int fctrl;
314
315 doc_dbg("doc_set_extra_page_mode()\n");
316 doc_flash_sequence(docg3, DOC_SEQ_PAGE_SIZE_532);
317 doc_flash_command(docg3, DOC_CMD_PAGE_SIZE_532);
318 doc_delay(docg3, 2);
319
320 fctrl = doc_register_readb(docg3, DOC_FLASHCONTROL);
321 if (fctrl & (DOC_CTRL_PROTECTION_ERROR | DOC_CTRL_SEQUENCE_ERROR))
322 return -EIO;
323 else
324 return 0;
325}
326
327/**
328 * doc_seek - Set both flash planes to the specified block, page for reading
329 * @docg3: the device
330 * @block0: the first plane block index
331 * @block1: the second plane block index
332 * @page: the page index within the block
333 * @wear: if true, read will occur on the 4 extra bytes of the wear area
334 * @ofs: offset in page to read
335 *
336 * Programs the flash even and odd planes to the specific block and page.
337 * Alternatively, programs the flash to the wear area of the specified page.
338 */
339static int doc_read_seek(struct docg3 *docg3, int block0, int block1, int page,
340 int wear, int ofs)
341{
342 int sector, ret = 0;
343
344 doc_dbg("doc_seek(blocks=(%d,%d), page=%d, ofs=%d, wear=%d)\n",
345 block0, block1, page, ofs, wear);
346
347 if (!wear && (ofs < 2 * DOC_LAYOUT_PAGE_SIZE)) {
348 doc_flash_sequence(docg3, DOC_SEQ_SET_PLANE1);
349 doc_flash_command(docg3, DOC_CMD_READ_PLANE1);
350 doc_delay(docg3, 2);
351 } else {
352 doc_flash_sequence(docg3, DOC_SEQ_SET_PLANE2);
353 doc_flash_command(docg3, DOC_CMD_READ_PLANE2);
354 doc_delay(docg3, 2);
355 }
356
357 doc_set_reliable_mode(docg3);
358 if (wear)
359 ret = doc_set_extra_page_mode(docg3);
360 if (ret)
361 goto out;
362
363 sector = (block0 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK);
364 doc_flash_sequence(docg3, DOC_SEQ_READ);
365 doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR);
366 doc_delay(docg3, 1);
367 doc_flash_address(docg3, sector & 0xff);
368 doc_flash_address(docg3, (sector >> 8) & 0xff);
369 doc_flash_address(docg3, (sector >> 16) & 0xff);
370 doc_delay(docg3, 1);
371
372 sector = (block1 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK);
373 doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR);
374 doc_delay(docg3, 1);
375 doc_flash_address(docg3, sector & 0xff);
376 doc_flash_address(docg3, (sector >> 8) & 0xff);
377 doc_flash_address(docg3, (sector >> 16) & 0xff);
378 doc_delay(docg3, 2);
379
380out:
381 return ret;
382}
383
384/**
385 * doc_read_page_ecc_init - Initialize hardware ECC engine
386 * @docg3: the device
387 * @len: the number of bytes covered by the ECC (BCH covered)
388 *
389 * The function does initialize the hardware ECC engine to compute the Hamming
390 * ECC (on 1 byte) and the BCH Syndroms (on 7 bytes).
391 *
392 * Return 0 if succeeded, -EIO on error
393 */
394static int doc_read_page_ecc_init(struct docg3 *docg3, int len)
395{
396 doc_writew(docg3, DOC_ECCCONF0_READ_MODE
397 | DOC_ECCCONF0_BCH_ENABLE | DOC_ECCCONF0_HAMMING_ENABLE
398 | (len & DOC_ECCCONF0_DATA_BYTES_MASK),
399 DOC_ECCCONF0);
400 doc_delay(docg3, 4);
401 doc_register_readb(docg3, DOC_FLASHCONTROL);
402 return doc_wait_ready(docg3);
403}
404
405/**
406 * doc_read_page_prepare - Prepares reading data from a flash page
407 * @docg3: the device
408 * @block0: the first plane block index on flash memory
409 * @block1: the second plane block index on flash memory
410 * @page: the page index in the block
411 * @offset: the offset in the page (must be a multiple of 4)
412 *
413 * Prepares the page to be read in the flash memory :
414 * - tell ASIC to map the flash pages
415 * - tell ASIC to be in read mode
416 *
417 * After a call to this method, a call to doc_read_page_finish is mandatory,
418 * to end the read cycle of the flash.
419 *
420 * Read data from a flash page. The length to be read must be between 0 and
421 * (page_size + oob_size + wear_size), ie. 532, and a multiple of 4 (because
422 * the extra bytes reading is not implemented).
423 *
424 * As pages are grouped by 2 (in 2 planes), reading from a page must be done
425 * in two steps:
426 * - one read of 512 bytes at offset 0
427 * - one read of 512 bytes at offset 512 + 16
428 *
429 * Returns 0 if successful, -EIO if a read error occured.
430 */
431static int doc_read_page_prepare(struct docg3 *docg3, int block0, int block1,
432 int page, int offset)
433{
434 int wear_area = 0, ret = 0;
435
436 doc_dbg("doc_read_page_prepare(blocks=(%d,%d), page=%d, ofsInPage=%d)\n",
437 block0, block1, page, offset);
438 if (offset >= DOC_LAYOUT_WEAR_OFFSET)
439 wear_area = 1;
440 if (!wear_area && offset > (DOC_LAYOUT_PAGE_OOB_SIZE * 2))
441 return -EINVAL;
442
443 doc_set_device_id(docg3, docg3->device_id);
444 ret = doc_reset_seq(docg3);
445 if (ret)
446 goto err;
447
448 /* Program the flash address block and page */
449 ret = doc_read_seek(docg3, block0, block1, page, wear_area, offset);
450 if (ret)
451 goto err;
452
453 doc_flash_command(docg3, DOC_CMD_READ_ALL_PLANES);
454 doc_delay(docg3, 2);
455 doc_wait_ready(docg3);
456
457 doc_flash_command(docg3, DOC_CMD_SET_ADDR_READ);
458 doc_delay(docg3, 1);
459 if (offset >= DOC_LAYOUT_PAGE_SIZE * 2)
460 offset -= 2 * DOC_LAYOUT_PAGE_SIZE;
461 doc_flash_address(docg3, offset >> 2);
462 doc_delay(docg3, 1);
463 doc_wait_ready(docg3);
464
465 doc_flash_command(docg3, DOC_CMD_READ_FLASH);
466
467 return 0;
468err:
469 doc_writeb(docg3, 0, DOC_DATAEND);
470 doc_delay(docg3, 2);
471 return -EIO;
472}
473
474/**
475 * doc_read_page_getbytes - Reads bytes from a prepared page
476 * @docg3: the device
477 * @len: the number of bytes to be read (must be a multiple of 4)
478 * @buf: the buffer to be filled in
479 * @first: 1 if first time read, DOC_READADDRESS should be set
480 *
481 */
482static int doc_read_page_getbytes(struct docg3 *docg3, int len, u_char *buf,
483 int first)
484{
485 doc_read_data_area(docg3, buf, len, first);
486 doc_delay(docg3, 2);
487 return len;
488}
489
490/**
491 * doc_get_hw_bch_syndroms - Get hardware calculated BCH syndroms
492 * @docg3: the device
493 * @syns: the array of 7 integers where the syndroms will be stored
494 */
495static void doc_get_hw_bch_syndroms(struct docg3 *docg3, int *syns)
496{
497 int i;
498
499 for (i = 0; i < DOC_ECC_BCH_SIZE; i++)
500 syns[i] = doc_register_readb(docg3, DOC_BCH_SYNDROM(i));
501}
502
503/**
504 * doc_read_page_finish - Ends reading of a flash page
505 * @docg3: the device
506 *
507 * As a side effect, resets the chip selector to 0. This ensures that after each
508 * read operation, the floor 0 is selected. Therefore, if the systems halts, the
509 * reboot will boot on floor 0, where the IPL is.
510 */
511static void doc_read_page_finish(struct docg3 *docg3)
512{
513 doc_writeb(docg3, 0, DOC_DATAEND);
514 doc_delay(docg3, 2);
515 doc_set_device_id(docg3, 0);
516}
517
518/**
519 * calc_block_sector - Calculate blocks, pages and ofs.
520
521 * @from: offset in flash
522 * @block0: first plane block index calculated
523 * @block1: second plane block index calculated
524 * @page: page calculated
525 * @ofs: offset in page
526 */
527static void calc_block_sector(loff_t from, int *block0, int *block1, int *page,
528 int *ofs)
529{
530 uint sector;
531
532 sector = from / DOC_LAYOUT_PAGE_SIZE;
533 *block0 = sector / (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_NBPLANES)
534 * DOC_LAYOUT_NBPLANES;
535 *block1 = *block0 + 1;
536 *page = sector % (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_NBPLANES);
537 *page /= DOC_LAYOUT_NBPLANES;
538 if (sector % 2)
539 *ofs = DOC_LAYOUT_PAGE_OOB_SIZE;
540 else
541 *ofs = 0;
542}
543
544/**
545 * doc_read - Read bytes from flash
546 * @mtd: the device
547 * @from: the offset from first block and first page, in bytes, aligned on page
548 * size
549 * @len: the number of bytes to read (must be a multiple of 4)
550 * @retlen: the number of bytes actually read
551 * @buf: the filled in buffer
552 *
553 * Reads flash memory pages. This function does not read the OOB chunk, but only
554 * the page data.
555 *
556 * Returns 0 if read successfull, of -EIO, -EINVAL if an error occured
557 */
558static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
559 size_t *retlen, u_char *buf)
560{
561 struct docg3 *docg3 = mtd->priv;
562 int block0, block1, page, readlen, ret, ofs = 0;
563 int syn[DOC_ECC_BCH_SIZE], eccconf1;
564 u8 oob[DOC_LAYOUT_OOB_SIZE];
565
566 ret = -EINVAL;
567 doc_dbg("doc_read(from=%lld, len=%zu, buf=%p)\n", from, len, buf);
568 if (from % DOC_LAYOUT_PAGE_SIZE)
569 goto err;
570 if (len % 4)
571 goto err;
572 calc_block_sector(from, &block0, &block1, &page, &ofs);
573 if (block1 > docg3->max_block)
574 goto err;
575
576 *retlen = 0;
577 ret = 0;
578 readlen = min_t(size_t, len, (size_t)DOC_LAYOUT_PAGE_SIZE);
579 while (!ret && len > 0) {
580 readlen = min_t(size_t, len, (size_t)DOC_LAYOUT_PAGE_SIZE);
581 ret = doc_read_page_prepare(docg3, block0, block1, page, ofs);
582 if (ret < 0)
583 goto err;
584 ret = doc_read_page_ecc_init(docg3, DOC_ECC_BCH_COVERED_BYTES);
585 if (ret < 0)
586 goto err_in_read;
587 ret = doc_read_page_getbytes(docg3, readlen, buf, 1);
588 if (ret < readlen)
589 goto err_in_read;
590 ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE,
591 oob, 0);
592 if (ret < DOC_LAYOUT_OOB_SIZE)
593 goto err_in_read;
594
595 *retlen += readlen;
596 buf += readlen;
597 len -= readlen;
598
599 ofs ^= DOC_LAYOUT_PAGE_OOB_SIZE;
600 if (ofs == 0)
601 page += 2;
602 if (page > DOC_ADDR_PAGE_MASK) {
603 page = 0;
604 block0 += 2;
605 block1 += 2;
606 }
607
608 /*
609 * There should be a BCH bitstream fixing algorithm here ...
610 * By now, a page read failure is triggered by BCH error
611 */
612 doc_get_hw_bch_syndroms(docg3, syn);
613 eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1);
614
615 doc_dbg("OOB - INFO: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
616 oob[0], oob[1], oob[2], oob[3], oob[4],
617 oob[5], oob[6]);
618 doc_dbg("OOB - HAMMING: %02x\n", oob[7]);
619 doc_dbg("OOB - BCH_ECC: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
620 oob[8], oob[9], oob[10], oob[11], oob[12],
621 oob[13], oob[14]);
622 doc_dbg("OOB - UNUSED: %02x\n", oob[15]);
623 doc_dbg("ECC checks: ECCConf1=%x\n", eccconf1);
624 doc_dbg("ECC BCH syndrom: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
625 syn[0], syn[1], syn[2], syn[3], syn[4], syn[5], syn[6]);
626
627 ret = -EBADMSG;
628 if (block0 >= DOC_LAYOUT_BLOCK_FIRST_DATA) {
629 if (eccconf1 & DOC_ECCCONF1_BCH_SYNDROM_ERR)
630 goto err_in_read;
631 if (is_prot_seq_error(docg3))
632 goto err_in_read;
633 }
634 doc_read_page_finish(docg3);
635 }
636
637 return 0;
638err_in_read:
639 doc_read_page_finish(docg3);
640err:
641 return ret;
642}
643
644/**
645 * doc_read_oob - Read out of band bytes from flash
646 * @mtd: the device
647 * @from: the offset from first block and first page, in bytes, aligned on page
648 * size
649 * @ops: the mtd oob structure
650 *
651 * Reads flash memory OOB area of pages.
652 *
653 * Returns 0 if read successfull, of -EIO, -EINVAL if an error occured
654 */
655static int doc_read_oob(struct mtd_info *mtd, loff_t from,
656 struct mtd_oob_ops *ops)
657{
658 struct docg3 *docg3 = mtd->priv;
659 int block0, block1, page, ofs, ret;
660 u8 *buf = ops->oobbuf;
661 size_t len = ops->ooblen;
662
663 doc_dbg("doc_read_oob(from=%lld, buf=%p, len=%zu)\n", from, buf, len);
664 if (len != DOC_LAYOUT_OOB_SIZE)
665 return -EINVAL;
666
667 switch (ops->mode) {
668 case MTD_OPS_PLACE_OOB:
669 buf += ops->ooboffs;
670 break;
671 default:
672 break;
673 }
674
675 calc_block_sector(from, &block0, &block1, &page, &ofs);
676 if (block1 > docg3->max_block)
677 return -EINVAL;
678
679 ret = doc_read_page_prepare(docg3, block0, block1, page,
680 ofs + DOC_LAYOUT_PAGE_SIZE);
681 if (!ret)
682 ret = doc_read_page_ecc_init(docg3, DOC_LAYOUT_OOB_SIZE);
683 if (!ret)
684 ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE,
685 buf, 1);
686 doc_read_page_finish(docg3);
687
688 if (ret > 0)
689 ops->oobretlen = ret;
690 else
691 ops->oobretlen = 0;
692 return (ret > 0) ? 0 : ret;
693}
694
695static int doc_reload_bbt(struct docg3 *docg3)
696{
697 int block = DOC_LAYOUT_BLOCK_BBT;
698 int ret = 0, nbpages, page;
699 u_char *buf = docg3->bbt;
700
701 nbpages = DIV_ROUND_UP(docg3->max_block + 1, 8 * DOC_LAYOUT_PAGE_SIZE);
702 for (page = 0; !ret && (page < nbpages); page++) {
703 ret = doc_read_page_prepare(docg3, block, block + 1,
704 page + DOC_LAYOUT_PAGE_BBT, 0);
705 if (!ret)
706 ret = doc_read_page_ecc_init(docg3,
707 DOC_LAYOUT_PAGE_SIZE);
708 if (!ret)
709 doc_read_page_getbytes(docg3, DOC_LAYOUT_PAGE_SIZE,
710 buf, 1);
711 buf += DOC_LAYOUT_PAGE_SIZE;
712 }
713 doc_read_page_finish(docg3);
714 return ret;
715}
716
717/**
718 * doc_block_isbad - Checks whether a block is good or not
719 * @mtd: the device
720 * @from: the offset to find the correct block
721 *
722 * Returns 1 if block is bad, 0 if block is good
723 */
724static int doc_block_isbad(struct mtd_info *mtd, loff_t from)
725{
726 struct docg3 *docg3 = mtd->priv;
727 int block0, block1, page, ofs, is_good;
728
729 calc_block_sector(from, &block0, &block1, &page, &ofs);
730 doc_dbg("doc_block_isbad(from=%lld) => block=(%d,%d), page=%d, ofs=%d\n",
731 from, block0, block1, page, ofs);
732
733 if (block0 < DOC_LAYOUT_BLOCK_FIRST_DATA)
734 return 0;
735 if (block1 > docg3->max_block)
736 return -EINVAL;
737
738 is_good = docg3->bbt[block0 >> 3] & (1 << (block0 & 0x7));
739 return !is_good;
740}
741
742/**
743 * doc_get_erase_count - Get block erase count
744 * @docg3: the device
745 * @from: the offset in which the block is.
746 *
747 * Get the number of times a block was erased. The number is the maximum of
748 * erase times between first and second plane (which should be equal normally).
749 *
750 * Returns The number of erases, or -EINVAL or -EIO on error.
751 */
752static int doc_get_erase_count(struct docg3 *docg3, loff_t from)
753{
754 u8 buf[DOC_LAYOUT_WEAR_SIZE];
755 int ret, plane1_erase_count, plane2_erase_count;
756 int block0, block1, page, ofs;
757
758 doc_dbg("doc_get_erase_count(from=%lld, buf=%p)\n", from, buf);
759 if (from % DOC_LAYOUT_PAGE_SIZE)
760 return -EINVAL;
761 calc_block_sector(from, &block0, &block1, &page, &ofs);
762 if (block1 > docg3->max_block)
763 return -EINVAL;
764
765 ret = doc_reset_seq(docg3);
766 if (!ret)
767 ret = doc_read_page_prepare(docg3, block0, block1, page,
768 ofs + DOC_LAYOUT_WEAR_OFFSET);
769 if (!ret)
770 ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_WEAR_SIZE,
771 buf, 1);
772 doc_read_page_finish(docg3);
773
774 if (ret || (buf[0] != DOC_ERASE_MARK) || (buf[2] != DOC_ERASE_MARK))
775 return -EIO;
776 plane1_erase_count = (u8)(~buf[1]) | ((u8)(~buf[4]) << 8)
777 | ((u8)(~buf[5]) << 16);
778 plane2_erase_count = (u8)(~buf[3]) | ((u8)(~buf[6]) << 8)
779 | ((u8)(~buf[7]) << 16);
780
781 return max(plane1_erase_count, plane2_erase_count);
782}
783
784/*
785 * Debug sysfs entries
786 */
787static int dbg_flashctrl_show(struct seq_file *s, void *p)
788{
789 struct docg3 *docg3 = (struct docg3 *)s->private;
790
791 int pos = 0;
792 u8 fctrl = doc_register_readb(docg3, DOC_FLASHCONTROL);
793
794 pos += seq_printf(s,
795 "FlashControl : 0x%02x (%s,CE# %s,%s,%s,flash %s)\n",
796 fctrl,
797 fctrl & DOC_CTRL_VIOLATION ? "protocol violation" : "-",
798 fctrl & DOC_CTRL_CE ? "active" : "inactive",
799 fctrl & DOC_CTRL_PROTECTION_ERROR ? "protection error" : "-",
800 fctrl & DOC_CTRL_SEQUENCE_ERROR ? "sequence error" : "-",
801 fctrl & DOC_CTRL_FLASHREADY ? "ready" : "not ready");
802 return pos;
803}
804DEBUGFS_RO_ATTR(flashcontrol, dbg_flashctrl_show);
805
806static int dbg_asicmode_show(struct seq_file *s, void *p)
807{
808 struct docg3 *docg3 = (struct docg3 *)s->private;
809
810 int pos = 0;
811 int pctrl = doc_register_readb(docg3, DOC_ASICMODE);
812 int mode = pctrl & 0x03;
813
814 pos += seq_printf(s,
815 "%04x : RAM_WE=%d,RSTIN_RESET=%d,BDETCT_RESET=%d,WRITE_ENABLE=%d,POWERDOWN=%d,MODE=%d%d (",
816 pctrl,
817 pctrl & DOC_ASICMODE_RAM_WE ? 1 : 0,
818 pctrl & DOC_ASICMODE_RSTIN_RESET ? 1 : 0,
819 pctrl & DOC_ASICMODE_BDETCT_RESET ? 1 : 0,
820 pctrl & DOC_ASICMODE_MDWREN ? 1 : 0,
821 pctrl & DOC_ASICMODE_POWERDOWN ? 1 : 0,
822 mode >> 1, mode & 0x1);
823
824 switch (mode) {
825 case DOC_ASICMODE_RESET:
826 pos += seq_printf(s, "reset");
827 break;
828 case DOC_ASICMODE_NORMAL:
829 pos += seq_printf(s, "normal");
830 break;
831 case DOC_ASICMODE_POWERDOWN:
832 pos += seq_printf(s, "powerdown");
833 break;
834 }
835 pos += seq_printf(s, ")\n");
836 return pos;
837}
838DEBUGFS_RO_ATTR(asic_mode, dbg_asicmode_show);
839
840static int dbg_device_id_show(struct seq_file *s, void *p)
841{
842 struct docg3 *docg3 = (struct docg3 *)s->private;
843 int pos = 0;
844 int id = doc_register_readb(docg3, DOC_DEVICESELECT);
845
846 pos += seq_printf(s, "DeviceId = %d\n", id);
847 return pos;
848}
849DEBUGFS_RO_ATTR(device_id, dbg_device_id_show);
850
851static int dbg_protection_show(struct seq_file *s, void *p)
852{
853 struct docg3 *docg3 = (struct docg3 *)s->private;
854 int pos = 0;
855 int protect = doc_register_readb(docg3, DOC_PROTECTION);
856 int dps0 = doc_register_readb(docg3, DOC_DPS0_STATUS);
857 int dps0_low = doc_register_readb(docg3, DOC_DPS0_ADDRLOW);
858 int dps0_high = doc_register_readb(docg3, DOC_DPS0_ADDRHIGH);
859 int dps1 = doc_register_readb(docg3, DOC_DPS1_STATUS);
860 int dps1_low = doc_register_readb(docg3, DOC_DPS1_ADDRLOW);
861 int dps1_high = doc_register_readb(docg3, DOC_DPS1_ADDRHIGH);
862
863 pos += seq_printf(s, "Protection = 0x%02x (",
864 protect);
865 if (protect & DOC_PROTECT_FOUNDRY_OTP_LOCK)
866 pos += seq_printf(s, "FOUNDRY_OTP_LOCK,");
867 if (protect & DOC_PROTECT_CUSTOMER_OTP_LOCK)
868 pos += seq_printf(s, "CUSTOMER_OTP_LOCK,");
869 if (protect & DOC_PROTECT_LOCK_INPUT)
870 pos += seq_printf(s, "LOCK_INPUT,");
871 if (protect & DOC_PROTECT_STICKY_LOCK)
872 pos += seq_printf(s, "STICKY_LOCK,");
873 if (protect & DOC_PROTECT_PROTECTION_ENABLED)
874 pos += seq_printf(s, "PROTECTION ON,");
875 if (protect & DOC_PROTECT_IPL_DOWNLOAD_LOCK)
876 pos += seq_printf(s, "IPL_DOWNLOAD_LOCK,");
877 if (protect & DOC_PROTECT_PROTECTION_ERROR)
878 pos += seq_printf(s, "PROTECT_ERR,");
879 else
880 pos += seq_printf(s, "NO_PROTECT_ERR");
881 pos += seq_printf(s, ")\n");
882
883 pos += seq_printf(s, "DPS0 = 0x%02x : "
884 "Protected area [0x%x - 0x%x] : OTP=%d, READ=%d, "
885 "WRITE=%d, HW_LOCK=%d, KEY_OK=%d\n",
886 dps0, dps0_low, dps0_high,
887 !!(dps0 & DOC_DPS_OTP_PROTECTED),
888 !!(dps0 & DOC_DPS_READ_PROTECTED),
889 !!(dps0 & DOC_DPS_WRITE_PROTECTED),
890 !!(dps0 & DOC_DPS_HW_LOCK_ENABLED),
891 !!(dps0 & DOC_DPS_KEY_OK));
892 pos += seq_printf(s, "DPS1 = 0x%02x : "
893 "Protected area [0x%x - 0x%x] : OTP=%d, READ=%d, "
894 "WRITE=%d, HW_LOCK=%d, KEY_OK=%d\n",
895 dps1, dps1_low, dps1_high,
896 !!(dps1 & DOC_DPS_OTP_PROTECTED),
897 !!(dps1 & DOC_DPS_READ_PROTECTED),
898 !!(dps1 & DOC_DPS_WRITE_PROTECTED),
899 !!(dps1 & DOC_DPS_HW_LOCK_ENABLED),
900 !!(dps1 & DOC_DPS_KEY_OK));
901 return pos;
902}
903DEBUGFS_RO_ATTR(protection, dbg_protection_show);
904
905static int __init doc_dbg_register(struct docg3 *docg3)
906{
907 struct dentry *root, *entry;
908
909 root = debugfs_create_dir("docg3", NULL);
910 if (!root)
911 return -ENOMEM;
912
913 entry = debugfs_create_file("flashcontrol", S_IRUSR, root, docg3,
914 &flashcontrol_fops);
915 if (entry)
916 entry = debugfs_create_file("asic_mode", S_IRUSR, root,
917 docg3, &asic_mode_fops);
918 if (entry)
919 entry = debugfs_create_file("device_id", S_IRUSR, root,
920 docg3, &device_id_fops);
921 if (entry)
922 entry = debugfs_create_file("protection", S_IRUSR, root,
923 docg3, &protection_fops);
924 if (entry) {
925 docg3->debugfs_root = root;
926 return 0;
927 } else {
928 debugfs_remove_recursive(root);
929 return -ENOMEM;
930 }
931}
932
933static void __exit doc_dbg_unregister(struct docg3 *docg3)
934{
935 debugfs_remove_recursive(docg3->debugfs_root);
936}
937
938/**
939 * doc_set_driver_info - Fill the mtd_info structure and docg3 structure
940 * @chip_id: The chip ID of the supported chip
941 * @mtd: The structure to fill
942 */
943static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)
944{
945 struct docg3 *docg3 = mtd->priv;
946 int cfg;
947
948 cfg = doc_register_readb(docg3, DOC_CONFIGURATION);
949 docg3->if_cfg = (cfg & DOC_CONF_IF_CFG ? 1 : 0);
950
951 switch (chip_id) {
952 case DOC_CHIPID_G3:
953 mtd->name = "DiskOnChip G3";
954 docg3->max_block = 2047;
955 break;
956 }
957 mtd->type = MTD_NANDFLASH;
958 /*
959 * Once write methods are added, the correct flags will be set.
960 * mtd->flags = MTD_CAP_NANDFLASH;
961 */
962 mtd->flags = MTD_CAP_ROM;
963 mtd->size = (docg3->max_block + 1) * DOC_LAYOUT_BLOCK_SIZE;
964 mtd->erasesize = DOC_LAYOUT_BLOCK_SIZE * DOC_LAYOUT_NBPLANES;
965 mtd->writesize = DOC_LAYOUT_PAGE_SIZE;
966 mtd->oobsize = DOC_LAYOUT_OOB_SIZE;
967 mtd->owner = THIS_MODULE;
968 mtd->erase = NULL;
969 mtd->point = NULL;
970 mtd->unpoint = NULL;
971 mtd->read = doc_read;
972 mtd->write = NULL;
973 mtd->read_oob = doc_read_oob;
974 mtd->write_oob = NULL;
975 mtd->sync = NULL;
976 mtd->block_isbad = doc_block_isbad;
977}
978
979/**
980 * doc_probe - Probe the IO space for a DiskOnChip G3 chip
981 * @pdev: platform device
982 *
983 * Probes for a G3 chip at the specified IO space in the platform data
984 * ressources.
985 *
986 * Returns 0 on success, -ENOMEM, -ENXIO on error
987 */
988static int __init docg3_probe(struct platform_device *pdev)
989{
990 struct device *dev = &pdev->dev;
991 struct docg3 *docg3;
992 struct mtd_info *mtd;
993 struct resource *ress;
994 int ret, bbt_nbpages;
995 u16 chip_id, chip_id_inv;
996
997 ret = -ENOMEM;
998 docg3 = kzalloc(sizeof(struct docg3), GFP_KERNEL);
999 if (!docg3)
1000 goto nomem1;
1001 mtd = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
1002 if (!mtd)
1003 goto nomem2;
1004 mtd->priv = docg3;
1005
1006 ret = -ENXIO;
1007 ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1008 if (!ress) {
1009 dev_err(dev, "No I/O memory resource defined\n");
1010 goto noress;
1011 }
1012 docg3->base = ioremap(ress->start, DOC_IOSPACE_SIZE);
1013
1014 docg3->dev = &pdev->dev;
1015 docg3->device_id = 0;
1016 doc_set_device_id(docg3, docg3->device_id);
1017 doc_set_asic_mode(docg3, DOC_ASICMODE_RESET);
1018 doc_set_asic_mode(docg3, DOC_ASICMODE_NORMAL);
1019
1020 chip_id = doc_register_readw(docg3, DOC_CHIPID);
1021 chip_id_inv = doc_register_readw(docg3, DOC_CHIPID_INV);
1022
1023 ret = -ENODEV;
1024 if (chip_id != (u16)(~chip_id_inv)) {
1025 doc_info("No device found at IO addr %p\n",
1026 (void *)ress->start);
1027 goto nochipfound;
1028 }
1029
1030 switch (chip_id) {
1031 case DOC_CHIPID_G3:
1032 doc_info("Found a G3 DiskOnChip at addr %p\n",
1033 (void *)ress->start);
1034 break;
1035 default:
1036 doc_err("Chip id %04x is not a DiskOnChip G3 chip\n", chip_id);
1037 goto nochipfound;
1038 }
1039
1040 doc_set_driver_info(chip_id, mtd);
1041 platform_set_drvdata(pdev, mtd);
1042
1043 ret = -ENOMEM;
1044 bbt_nbpages = DIV_ROUND_UP(docg3->max_block + 1,
1045 8 * DOC_LAYOUT_PAGE_SIZE);
1046 docg3->bbt = kzalloc(bbt_nbpages * DOC_LAYOUT_PAGE_SIZE, GFP_KERNEL);
1047 if (!docg3->bbt)
1048 goto nochipfound;
1049 doc_reload_bbt(docg3);
1050
1051 ret = mtd_device_parse_register(mtd, part_probes,
1052 NULL, NULL, 0);
1053 if (ret)
1054 goto register_error;
1055
1056 doc_dbg_register(docg3);
1057 return 0;
1058
1059register_error:
1060 kfree(docg3->bbt);
1061nochipfound:
1062 iounmap(docg3->base);
1063noress:
1064 kfree(mtd);
1065nomem2:
1066 kfree(docg3);
1067nomem1:
1068 return ret;
1069}
1070
1071/**
1072 * docg3_release - Release the driver
1073 * @pdev: the platform device
1074 *
1075 * Returns 0
1076 */
1077static int __exit docg3_release(struct platform_device *pdev)
1078{
1079 struct mtd_info *mtd = platform_get_drvdata(pdev);
1080 struct docg3 *docg3 = mtd->priv;
1081
1082 doc_dbg_unregister(docg3);
1083 mtd_device_unregister(mtd);
1084 iounmap(docg3->base);
1085 kfree(docg3->bbt);
1086 kfree(docg3);
1087 kfree(mtd);
1088 return 0;
1089}
1090
1091static struct platform_driver g3_driver = {
1092 .driver = {
1093 .name = "docg3",
1094 .owner = THIS_MODULE,
1095 },
1096 .remove = __exit_p(docg3_release),
1097};
1098
1099static int __init docg3_init(void)
1100{
1101 return platform_driver_probe(&g3_driver, docg3_probe);
1102}
1103module_init(docg3_init);
1104
1105
1106static void __exit docg3_exit(void)
1107{
1108 platform_driver_unregister(&g3_driver);
1109}
1110module_exit(docg3_exit);
1111
1112MODULE_LICENSE("GPL");
1113MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
1114MODULE_DESCRIPTION("MTD driver for DiskOnChip G3");
diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h
new file mode 100644
index 00000000000..0d407be2459
--- /dev/null
+++ b/drivers/mtd/devices/docg3.h
@@ -0,0 +1,297 @@
1/*
2 * Handles the M-Systems DiskOnChip G3 chip
3 *
4 * Copyright (C) 2011 Robert Jarzmik
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#ifndef _MTD_DOCG3_H
23#define _MTD_DOCG3_H
24
25/*
26 * Flash memory areas :
27 * - 0x0000 .. 0x07ff : IPL
28 * - 0x0800 .. 0x0fff : Data area
29 * - 0x1000 .. 0x17ff : Registers
30 * - 0x1800 .. 0x1fff : Unknown
31 */
32#define DOC_IOSPACE_IPL 0x0000
33#define DOC_IOSPACE_DATA 0x0800
34#define DOC_IOSPACE_SIZE 0x2000
35
36/*
37 * DOC G3 layout and adressing scheme
38 * A page address for the block "b", plane "P" and page "p":
39 * address = [bbbb bPpp pppp]
40 */
41
42#define DOC_ADDR_PAGE_MASK 0x3f
43#define DOC_ADDR_BLOCK_SHIFT 6
44#define DOC_LAYOUT_NBPLANES 2
45#define DOC_LAYOUT_PAGES_PER_BLOCK 64
46#define DOC_LAYOUT_PAGE_SIZE 512
47#define DOC_LAYOUT_OOB_SIZE 16
48#define DOC_LAYOUT_WEAR_SIZE 8
49#define DOC_LAYOUT_PAGE_OOB_SIZE \
50 (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_SIZE)
51#define DOC_LAYOUT_WEAR_OFFSET (DOC_LAYOUT_PAGE_OOB_SIZE * 2)
52#define DOC_LAYOUT_BLOCK_SIZE \
53 (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE)
54#define DOC_ECC_BCH_SIZE 7
55#define DOC_ECC_BCH_COVERED_BYTES \
56 (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ + \
57 DOC_LAYOUT_OOB_HAMMING_SZ + DOC_LAYOUT_OOB_BCH_SZ)
58
59/*
60 * Blocks distribution
61 */
62#define DOC_LAYOUT_BLOCK_BBT 0
63#define DOC_LAYOUT_BLOCK_OTP 0
64#define DOC_LAYOUT_BLOCK_FIRST_DATA 6
65
66#define DOC_LAYOUT_PAGE_BBT 4
67
68/*
69 * Extra page OOB (16 bytes wide) layout
70 */
71#define DOC_LAYOUT_OOB_PAGEINFO_OFS 0
72#define DOC_LAYOUT_OOB_HAMMING_OFS 7
73#define DOC_LAYOUT_OOB_BCH_OFS 8
74#define DOC_LAYOUT_OOB_UNUSED_OFS 15
75#define DOC_LAYOUT_OOB_PAGEINFO_SZ 7
76#define DOC_LAYOUT_OOB_HAMMING_SZ 1
77#define DOC_LAYOUT_OOB_BCH_SZ 7
78#define DOC_LAYOUT_OOB_UNUSED_SZ 1
79
80
81#define DOC_CHIPID_G3 0x200
82#define DOC_ERASE_MARK 0xaa
83/*
84 * Flash registers
85 */
86#define DOC_CHIPID 0x1000
87#define DOC_TEST 0x1004
88#define DOC_BUSLOCK 0x1006
89#define DOC_ENDIANCONTROL 0x1008
90#define DOC_DEVICESELECT 0x100a
91#define DOC_ASICMODE 0x100c
92#define DOC_CONFIGURATION 0x100e
93#define DOC_INTERRUPTCONTROL 0x1010
94#define DOC_READADDRESS 0x101a
95#define DOC_DATAEND 0x101e
96#define DOC_INTERRUPTSTATUS 0x1020
97
98#define DOC_FLASHSEQUENCE 0x1032
99#define DOC_FLASHCOMMAND 0x1034
100#define DOC_FLASHADDRESS 0x1036
101#define DOC_FLASHCONTROL 0x1038
102#define DOC_NOP 0x103e
103
104#define DOC_ECCCONF0 0x1040
105#define DOC_ECCCONF1 0x1042
106#define DOC_ECCPRESET 0x1044
107#define DOC_HAMMINGPARITY 0x1046
108#define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 1))
109
110#define DOC_PROTECTION 0x1056
111#define DOC_DPS0_ADDRLOW 0x1060
112#define DOC_DPS0_ADDRHIGH 0x1062
113#define DOC_DPS1_ADDRLOW 0x1064
114#define DOC_DPS1_ADDRHIGH 0x1066
115#define DOC_DPS0_STATUS 0x106c
116#define DOC_DPS1_STATUS 0x106e
117
118#define DOC_ASICMODECONFIRM 0x1072
119#define DOC_CHIPID_INV 0x1074
120
121/*
122 * Flash sequences
123 * A sequence is preset before one or more commands are input to the chip.
124 */
125#define DOC_SEQ_RESET 0x00
126#define DOC_SEQ_PAGE_SIZE_532 0x03
127#define DOC_SEQ_SET_MODE 0x09
128#define DOC_SEQ_READ 0x12
129#define DOC_SEQ_SET_PLANE1 0x0e
130#define DOC_SEQ_SET_PLANE2 0x10
131#define DOC_SEQ_PAGE_SETUP 0x1d
132
133/*
134 * Flash commands
135 */
136#define DOC_CMD_READ_PLANE1 0x00
137#define DOC_CMD_SET_ADDR_READ 0x05
138#define DOC_CMD_READ_ALL_PLANES 0x30
139#define DOC_CMD_READ_PLANE2 0x50
140#define DOC_CMD_READ_FLASH 0xe0
141#define DOC_CMD_PAGE_SIZE_532 0x3c
142
143#define DOC_CMD_PROG_BLOCK_ADDR 0x60
144#define DOC_CMD_PROG_CYCLE1 0x80
145#define DOC_CMD_PROG_CYCLE2 0x10
146#define DOC_CMD_ERASECYCLE2 0xd0
147
148#define DOC_CMD_RELIABLE_MODE 0x22
149#define DOC_CMD_FAST_MODE 0xa2
150
151#define DOC_CMD_RESET 0xff
152
153/*
154 * Flash register : DOC_FLASHCONTROL
155 */
156#define DOC_CTRL_VIOLATION 0x20
157#define DOC_CTRL_CE 0x10
158#define DOC_CTRL_UNKNOWN_BITS 0x08
159#define DOC_CTRL_PROTECTION_ERROR 0x04
160#define DOC_CTRL_SEQUENCE_ERROR 0x02
161#define DOC_CTRL_FLASHREADY 0x01
162
163/*
164 * Flash register : DOC_ASICMODE
165 */
166#define DOC_ASICMODE_RESET 0x00
167#define DOC_ASICMODE_NORMAL 0x01
168#define DOC_ASICMODE_POWERDOWN 0x02
169#define DOC_ASICMODE_MDWREN 0x04
170#define DOC_ASICMODE_BDETCT_RESET 0x08
171#define DOC_ASICMODE_RSTIN_RESET 0x10
172#define DOC_ASICMODE_RAM_WE 0x20
173
174/*
175 * Flash register : DOC_ECCCONF0
176 */
177#define DOC_ECCCONF0_READ_MODE 0x8000
178#define DOC_ECCCONF0_AUTO_ECC_ENABLE 0x4000
179#define DOC_ECCCONF0_HAMMING_ENABLE 0x1000
180#define DOC_ECCCONF0_BCH_ENABLE 0x0800
181#define DOC_ECCCONF0_DATA_BYTES_MASK 0x07ff
182
183/*
184 * Flash register : DOC_ECCCONF1
185 */
186#define DOC_ECCCONF1_BCH_SYNDROM_ERR 0x80
187#define DOC_ECCCONF1_UNKOWN1 0x40
188#define DOC_ECCCONF1_UNKOWN2 0x20
189#define DOC_ECCCONF1_UNKOWN3 0x10
190#define DOC_ECCCONF1_HAMMING_BITS_MASK 0x0f
191
192/*
193 * Flash register : DOC_PROTECTION
194 */
195#define DOC_PROTECT_FOUNDRY_OTP_LOCK 0x01
196#define DOC_PROTECT_CUSTOMER_OTP_LOCK 0x02
197#define DOC_PROTECT_LOCK_INPUT 0x04
198#define DOC_PROTECT_STICKY_LOCK 0x08
199#define DOC_PROTECT_PROTECTION_ENABLED 0x10
200#define DOC_PROTECT_IPL_DOWNLOAD_LOCK 0x20
201#define DOC_PROTECT_PROTECTION_ERROR 0x80
202
203/*
204 * Flash register : DOC_DPS0_STATUS and DOC_DPS1_STATUS
205 */
206#define DOC_DPS_OTP_PROTECTED 0x01
207#define DOC_DPS_READ_PROTECTED 0x02
208#define DOC_DPS_WRITE_PROTECTED 0x04
209#define DOC_DPS_HW_LOCK_ENABLED 0x08
210#define DOC_DPS_KEY_OK 0x80
211
212/*
213 * Flash register : DOC_CONFIGURATION
214 */
215#define DOC_CONF_IF_CFG 0x80
216#define DOC_CONF_MAX_ID_MASK 0x30
217#define DOC_CONF_VCCQ_3V 0x01
218
219/*
220 * Flash register : DOC_READADDRESS
221 */
222#define DOC_READADDR_INC 0x8000
223#define DOC_READADDR_ONE_BYTE 0x4000
224#define DOC_READADDR_ADDR_MASK 0x1fff
225
226/**
227 * struct docg3 - DiskOnChip driver private data
228 * @dev: the device currently under control
229 * @base: mapped IO space
230 * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3)
231 * @if_cfg: if true, reads are on 16bits, else reads are on 8bits
232 * @bbt: bad block table cache
233 * @debugfs_root: debugfs root node
234 */
235struct docg3 {
236 struct device *dev;
237 void __iomem *base;
238 unsigned int device_id:4;
239 unsigned int if_cfg:1;
240 int max_block;
241 u8 *bbt;
242 struct dentry *debugfs_root;
243};
244
245#define doc_err(fmt, arg...) dev_err(docg3->dev, (fmt), ## arg)
246#define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg)
247#define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg)
248#define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg)
249
250#define DEBUGFS_RO_ATTR(name, show_fct) \
251 static int name##_open(struct inode *inode, struct file *file) \
252 { return single_open(file, show_fct, inode->i_private); } \
253 static const struct file_operations name##_fops = { \
254 .owner = THIS_MODULE, \
255 .open = name##_open, \
256 .llseek = seq_lseek, \
257 .read = seq_read, \
258 .release = single_release \
259 };
260#endif
261
262/*
263 * Trace events part
264 */
265#undef TRACE_SYSTEM
266#define TRACE_SYSTEM docg3
267
268#if !defined(_MTD_DOCG3_TRACE) || defined(TRACE_HEADER_MULTI_READ)
269#define _MTD_DOCG3_TRACE
270
271#include <linux/tracepoint.h>
272
273TRACE_EVENT(docg3_io,
274 TP_PROTO(int op, int width, u16 reg, int val),
275 TP_ARGS(op, width, reg, val),
276 TP_STRUCT__entry(
277 __field(int, op)
278 __field(unsigned char, width)
279 __field(u16, reg)
280 __field(int, val)),
281 TP_fast_assign(
282 __entry->op = op;
283 __entry->width = width;
284 __entry->reg = reg;
285 __entry->val = val;),
286 TP_printk("docg3: %s%02d reg=%04x, val=%04x",
287 __entry->op ? "write" : "read", __entry->width,
288 __entry->reg, __entry->val)
289 );
290#endif
291
292/* This part must be outside protection */
293#undef TRACE_INCLUDE_PATH
294#undef TRACE_INCLUDE_FILE
295#define TRACE_INCLUDE_PATH .
296#define TRACE_INCLUDE_FILE docg3
297#include <trace/define_trace.h>
diff --git a/drivers/mtd/devices/docprobe.c b/drivers/mtd/devices/docprobe.c
index d374603493a..45116bb3029 100644
--- a/drivers/mtd/devices/docprobe.c
+++ b/drivers/mtd/devices/docprobe.c
@@ -50,11 +50,6 @@
50#include <linux/mtd/nand.h> 50#include <linux/mtd/nand.h>
51#include <linux/mtd/doc2000.h> 51#include <linux/mtd/doc2000.h>
52 52
53/* Where to look for the devices? */
54#ifndef CONFIG_MTD_DOCPROBE_ADDRESS
55#define CONFIG_MTD_DOCPROBE_ADDRESS 0
56#endif
57
58 53
59static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS; 54static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
60module_param(doc_config_location, ulong, 0); 55module_param(doc_config_location, ulong, 0);
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 772a0ff89e0..3a11ea628e5 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -34,9 +34,6 @@
34/* debugging */ 34/* debugging */
35//#define LART_DEBUG 35//#define LART_DEBUG
36 36
37/* partition support */
38#define HAVE_PARTITIONS
39
40#include <linux/kernel.h> 37#include <linux/kernel.h>
41#include <linux/module.h> 38#include <linux/module.h>
42#include <linux/types.h> 39#include <linux/types.h>
@@ -44,9 +41,7 @@
44#include <linux/errno.h> 41#include <linux/errno.h>
45#include <linux/string.h> 42#include <linux/string.h>
46#include <linux/mtd/mtd.h> 43#include <linux/mtd/mtd.h>
47#ifdef HAVE_PARTITIONS
48#include <linux/mtd/partitions.h> 44#include <linux/mtd/partitions.h>
49#endif
50 45
51#ifndef CONFIG_SA1100_LART 46#ifndef CONFIG_SA1100_LART
52#error This is for LART architecture only 47#error This is for LART architecture only
@@ -598,7 +593,6 @@ static struct mtd_erase_region_info erase_regions[] = {
598 } 593 }
599}; 594};
600 595
601#ifdef HAVE_PARTITIONS
602static struct mtd_partition lart_partitions[] = { 596static struct mtd_partition lart_partitions[] = {
603 /* blob */ 597 /* blob */
604 { 598 {
@@ -619,7 +613,7 @@ static struct mtd_partition lart_partitions[] = {
619 .size = INITRD_LEN, /* MTDPART_SIZ_FULL */ 613 .size = INITRD_LEN, /* MTDPART_SIZ_FULL */
620 } 614 }
621}; 615};
622#endif 616#define NUM_PARTITIONS ARRAY_SIZE(lart_partitions)
623 617
624static int __init lart_flash_init (void) 618static int __init lart_flash_init (void)
625{ 619{
@@ -668,7 +662,6 @@ static int __init lart_flash_init (void)
668 result,mtd.eraseregions[result].erasesize,mtd.eraseregions[result].erasesize / 1024, 662 result,mtd.eraseregions[result].erasesize,mtd.eraseregions[result].erasesize / 1024,
669 result,mtd.eraseregions[result].numblocks); 663 result,mtd.eraseregions[result].numblocks);
670 664
671#ifdef HAVE_PARTITIONS
672 printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions)); 665 printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions));
673 666
674 for (result = 0; result < ARRAY_SIZE(lart_partitions); result++) 667 for (result = 0; result < ARRAY_SIZE(lart_partitions); result++)
@@ -681,25 +674,16 @@ static int __init lart_flash_init (void)
681 result,lart_partitions[result].offset, 674 result,lart_partitions[result].offset,
682 result,lart_partitions[result].size,lart_partitions[result].size / 1024); 675 result,lart_partitions[result].size,lart_partitions[result].size / 1024);
683#endif 676#endif
684#endif
685 677
686#ifndef HAVE_PARTITIONS
687 result = mtd_device_register(&mtd, NULL, 0);
688#else
689 result = mtd_device_register(&mtd, lart_partitions, 678 result = mtd_device_register(&mtd, lart_partitions,
690 ARRAY_SIZE(lart_partitions)); 679 ARRAY_SIZE(lart_partitions));
691#endif
692 680
693 return (result); 681 return (result);
694} 682}
695 683
696static void __exit lart_flash_exit (void) 684static void __exit lart_flash_exit (void)
697{ 685{
698#ifndef HAVE_PARTITIONS
699 mtd_device_unregister(&mtd);
700#else
701 mtd_device_unregister(&mtd); 686 mtd_device_unregister(&mtd);
702#endif
703} 687}
704 688
705module_init (lart_flash_init); 689module_init (lart_flash_init);
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 35180e475c4..884904d3f9d 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -30,6 +30,7 @@
30#include <linux/mtd/cfi.h> 30#include <linux/mtd/cfi.h>
31#include <linux/mtd/mtd.h> 31#include <linux/mtd/mtd.h>
32#include <linux/mtd/partitions.h> 32#include <linux/mtd/partitions.h>
33#include <linux/of_platform.h>
33 34
34#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
35#include <linux/spi/flash.h> 36#include <linux/spi/flash.h>
@@ -88,7 +89,6 @@ struct m25p {
88 struct spi_device *spi; 89 struct spi_device *spi;
89 struct mutex lock; 90 struct mutex lock;
90 struct mtd_info mtd; 91 struct mtd_info mtd;
91 unsigned partitioned:1;
92 u16 page_size; 92 u16 page_size;
93 u16 addr_width; 93 u16 addr_width;
94 u8 erase_opcode; 94 u8 erase_opcode;
@@ -209,9 +209,8 @@ static int wait_till_ready(struct m25p *flash)
209 */ 209 */
210static int erase_chip(struct m25p *flash) 210static int erase_chip(struct m25p *flash)
211{ 211{
212 DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %lldKiB\n", 212 pr_debug("%s: %s %lldKiB\n", dev_name(&flash->spi->dev), __func__,
213 dev_name(&flash->spi->dev), __func__, 213 (long long)(flash->mtd.size >> 10));
214 (long long)(flash->mtd.size >> 10));
215 214
216 /* Wait until finished previous write command. */ 215 /* Wait until finished previous write command. */
217 if (wait_till_ready(flash)) 216 if (wait_till_ready(flash))
@@ -250,9 +249,8 @@ static int m25p_cmdsz(struct m25p *flash)
250 */ 249 */
251static int erase_sector(struct m25p *flash, u32 offset) 250static int erase_sector(struct m25p *flash, u32 offset)
252{ 251{
253 DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB at 0x%08x\n", 252 pr_debug("%s: %s %dKiB at 0x%08x\n", dev_name(&flash->spi->dev),
254 dev_name(&flash->spi->dev), __func__, 253 __func__, flash->mtd.erasesize / 1024, offset);
255 flash->mtd.erasesize / 1024, offset);
256 254
257 /* Wait until finished previous write command. */ 255 /* Wait until finished previous write command. */
258 if (wait_till_ready(flash)) 256 if (wait_till_ready(flash))
@@ -286,9 +284,9 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
286 u32 addr,len; 284 u32 addr,len;
287 uint32_t rem; 285 uint32_t rem;
288 286
289 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%llx, len %lld\n", 287 pr_debug("%s: %s at 0x%llx, len %lld\n", dev_name(&flash->spi->dev),
290 dev_name(&flash->spi->dev), __func__, "at", 288 __func__, (long long)instr->addr,
291 (long long)instr->addr, (long long)instr->len); 289 (long long)instr->len);
292 290
293 /* sanity checks */ 291 /* sanity checks */
294 if (instr->addr + instr->len > flash->mtd.size) 292 if (instr->addr + instr->len > flash->mtd.size)
@@ -348,9 +346,8 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
348 struct spi_transfer t[2]; 346 struct spi_transfer t[2];
349 struct spi_message m; 347 struct spi_message m;
350 348
351 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 349 pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
352 dev_name(&flash->spi->dev), __func__, "from", 350 __func__, (u32)from, len);
353 (u32)from, len);
354 351
355 /* sanity checks */ 352 /* sanity checks */
356 if (!len) 353 if (!len)
@@ -417,9 +414,8 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
417 struct spi_transfer t[2]; 414 struct spi_transfer t[2];
418 struct spi_message m; 415 struct spi_message m;
419 416
420 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 417 pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
421 dev_name(&flash->spi->dev), __func__, "to", 418 __func__, (u32)to, len);
422 (u32)to, len);
423 419
424 *retlen = 0; 420 *retlen = 0;
425 421
@@ -510,9 +506,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
510 size_t actual; 506 size_t actual;
511 int cmd_sz, ret; 507 int cmd_sz, ret;
512 508
513 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 509 pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
514 dev_name(&flash->spi->dev), __func__, "to", 510 __func__, (u32)to, len);
515 (u32)to, len);
516 511
517 *retlen = 0; 512 *retlen = 0;
518 513
@@ -661,6 +656,7 @@ static const struct spi_device_id m25p_ids[] = {
661 { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K) }, 656 { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K) },
662 657
663 { "at25df041a", INFO(0x1f4401, 0, 64 * 1024, 8, SECT_4K) }, 658 { "at25df041a", INFO(0x1f4401, 0, 64 * 1024, 8, SECT_4K) },
659 { "at25df321a", INFO(0x1f4701, 0, 64 * 1024, 64, SECT_4K) },
664 { "at25df641", INFO(0x1f4800, 0, 64 * 1024, 128, SECT_4K) }, 660 { "at25df641", INFO(0x1f4800, 0, 64 * 1024, 128, SECT_4K) },
665 661
666 { "at26f004", INFO(0x1f0400, 0, 64 * 1024, 8, SECT_4K) }, 662 { "at26f004", INFO(0x1f0400, 0, 64 * 1024, 8, SECT_4K) },
@@ -671,6 +667,7 @@ static const struct spi_device_id m25p_ids[] = {
671 /* EON -- en25xxx */ 667 /* EON -- en25xxx */
672 { "en25f32", INFO(0x1c3116, 0, 64 * 1024, 64, SECT_4K) }, 668 { "en25f32", INFO(0x1c3116, 0, 64 * 1024, 64, SECT_4K) },
673 { "en25p32", INFO(0x1c2016, 0, 64 * 1024, 64, 0) }, 669 { "en25p32", INFO(0x1c2016, 0, 64 * 1024, 64, 0) },
670 { "en25q32b", INFO(0x1c3016, 0, 64 * 1024, 64, 0) },
674 { "en25p64", INFO(0x1c2017, 0, 64 * 1024, 128, 0) }, 671 { "en25p64", INFO(0x1c2017, 0, 64 * 1024, 128, 0) },
675 672
676 /* Intel/Numonyx -- xxxs33b */ 673 /* Intel/Numonyx -- xxxs33b */
@@ -788,8 +785,8 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi)
788 */ 785 */
789 tmp = spi_write_then_read(spi, &code, 1, id, 5); 786 tmp = spi_write_then_read(spi, &code, 1, id, 5);
790 if (tmp < 0) { 787 if (tmp < 0) {
791 DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n", 788 pr_debug("%s: error %d reading JEDEC ID\n",
792 dev_name(&spi->dev), tmp); 789 dev_name(&spi->dev), tmp);
793 return ERR_PTR(tmp); 790 return ERR_PTR(tmp);
794 } 791 }
795 jedec = id[0]; 792 jedec = id[0];
@@ -825,8 +822,12 @@ static int __devinit m25p_probe(struct spi_device *spi)
825 struct m25p *flash; 822 struct m25p *flash;
826 struct flash_info *info; 823 struct flash_info *info;
827 unsigned i; 824 unsigned i;
828 struct mtd_partition *parts = NULL; 825 struct mtd_part_parser_data ppdata;
829 int nr_parts = 0; 826
827#ifdef CONFIG_MTD_OF_PARTS
828 if (!of_device_is_available(spi->dev.of_node))
829 return -ENODEV;
830#endif
830 831
831 /* Platform data helps sort out which chip type we have, as 832 /* Platform data helps sort out which chip type we have, as
832 * well as how this board partitions it. If we don't have 833 * well as how this board partitions it. If we don't have
@@ -928,6 +929,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
928 if (info->flags & M25P_NO_ERASE) 929 if (info->flags & M25P_NO_ERASE)
929 flash->mtd.flags |= MTD_NO_ERASE; 930 flash->mtd.flags |= MTD_NO_ERASE;
930 931
932 ppdata.of_node = spi->dev.of_node;
931 flash->mtd.dev.parent = &spi->dev; 933 flash->mtd.dev.parent = &spi->dev;
932 flash->page_size = info->page_size; 934 flash->page_size = info->page_size;
933 935
@@ -945,8 +947,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
945 dev_info(&spi->dev, "%s (%lld Kbytes)\n", id->name, 947 dev_info(&spi->dev, "%s (%lld Kbytes)\n", id->name,
946 (long long)flash->mtd.size >> 10); 948 (long long)flash->mtd.size >> 10);
947 949
948 DEBUG(MTD_DEBUG_LEVEL2, 950 pr_debug("mtd .name = %s, .size = 0x%llx (%lldMiB) "
949 "mtd .name = %s, .size = 0x%llx (%lldMiB) "
950 ".erasesize = 0x%.8x (%uKiB) .numeraseregions = %d\n", 951 ".erasesize = 0x%.8x (%uKiB) .numeraseregions = %d\n",
951 flash->mtd.name, 952 flash->mtd.name,
952 (long long)flash->mtd.size, (long long)(flash->mtd.size >> 20), 953 (long long)flash->mtd.size, (long long)(flash->mtd.size >> 20),
@@ -955,8 +956,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
955 956
956 if (flash->mtd.numeraseregions) 957 if (flash->mtd.numeraseregions)
957 for (i = 0; i < flash->mtd.numeraseregions; i++) 958 for (i = 0; i < flash->mtd.numeraseregions; i++)
958 DEBUG(MTD_DEBUG_LEVEL2, 959 pr_debug("mtd.eraseregions[%d] = { .offset = 0x%llx, "
959 "mtd.eraseregions[%d] = { .offset = 0x%llx, "
960 ".erasesize = 0x%.8x (%uKiB), " 960 ".erasesize = 0x%.8x (%uKiB), "
961 ".numblocks = %d }\n", 961 ".numblocks = %d }\n",
962 i, (long long)flash->mtd.eraseregions[i].offset, 962 i, (long long)flash->mtd.eraseregions[i].offset,
@@ -968,41 +968,9 @@ static int __devinit m25p_probe(struct spi_device *spi)
968 /* partitions should match sector boundaries; and it may be good to 968 /* partitions should match sector boundaries; and it may be good to
969 * use readonly partitions for writeprotected sectors (BP2..BP0). 969 * use readonly partitions for writeprotected sectors (BP2..BP0).
970 */ 970 */
971 if (mtd_has_cmdlinepart()) { 971 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
972 static const char *part_probes[] 972 data ? data->parts : NULL,
973 = { "cmdlinepart", NULL, }; 973 data ? data->nr_parts : 0);
974
975 nr_parts = parse_mtd_partitions(&flash->mtd,
976 part_probes, &parts, 0);
977 }
978
979 if (nr_parts <= 0 && data && data->parts) {
980 parts = data->parts;
981 nr_parts = data->nr_parts;
982 }
983
984#ifdef CONFIG_MTD_OF_PARTS
985 if (nr_parts <= 0 && spi->dev.of_node) {
986 nr_parts = of_mtd_parse_partitions(&spi->dev,
987 spi->dev.of_node, &parts);
988 }
989#endif
990
991 if (nr_parts > 0) {
992 for (i = 0; i < nr_parts; i++) {
993 DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = "
994 "{.name = %s, .offset = 0x%llx, "
995 ".size = 0x%llx (%lldKiB) }\n",
996 i, parts[i].name,
997 (long long)parts[i].offset,
998 (long long)parts[i].size,
999 (long long)(parts[i].size >> 10));
1000 }
1001 flash->partitioned = 1;
1002 }
1003
1004 return mtd_device_register(&flash->mtd, parts, nr_parts) == 1 ?
1005 -ENODEV : 0;
1006} 974}
1007 975
1008 976
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index 13749d458a3..d75c7af18a6 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -17,6 +17,8 @@
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/math64.h> 19#include <linux/math64.h>
20#include <linux/of.h>
21#include <linux/of_device.h>
20 22
21#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
22#include <linux/spi/flash.h> 24#include <linux/spi/flash.h>
@@ -24,7 +26,6 @@
24#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
25#include <linux/mtd/partitions.h> 27#include <linux/mtd/partitions.h>
26 28
27
28/* 29/*
29 * DataFlash is a kind of SPI flash. Most AT45 chips have two buffers in 30 * DataFlash is a kind of SPI flash. Most AT45 chips have two buffers in
30 * each chip, which may be used for double buffered I/O; but this driver 31 * each chip, which may be used for double buffered I/O; but this driver
@@ -98,6 +99,16 @@ struct dataflash {
98 struct mtd_info mtd; 99 struct mtd_info mtd;
99}; 100};
100 101
102#ifdef CONFIG_OF
103static const struct of_device_id dataflash_dt_ids[] = {
104 { .compatible = "atmel,at45", },
105 { .compatible = "atmel,dataflash", },
106 { /* sentinel */ }
107};
108#else
109#define dataflash_dt_ids NULL
110#endif
111
101/* ......................................................................... */ 112/* ......................................................................... */
102 113
103/* 114/*
@@ -122,7 +133,7 @@ static int dataflash_waitready(struct spi_device *spi)
122 for (;;) { 133 for (;;) {
123 status = dataflash_status(spi); 134 status = dataflash_status(spi);
124 if (status < 0) { 135 if (status < 0) {
125 DEBUG(MTD_DEBUG_LEVEL1, "%s: status %d?\n", 136 pr_debug("%s: status %d?\n",
126 dev_name(&spi->dev), status); 137 dev_name(&spi->dev), status);
127 status = 0; 138 status = 0;
128 } 139 }
@@ -149,7 +160,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
149 uint8_t *command; 160 uint8_t *command;
150 uint32_t rem; 161 uint32_t rem;
151 162
152 DEBUG(MTD_DEBUG_LEVEL2, "%s: erase addr=0x%llx len 0x%llx\n", 163 pr_debug("%s: erase addr=0x%llx len 0x%llx\n",
153 dev_name(&spi->dev), (long long)instr->addr, 164 dev_name(&spi->dev), (long long)instr->addr,
154 (long long)instr->len); 165 (long long)instr->len);
155 166
@@ -187,7 +198,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
187 command[2] = (uint8_t)(pageaddr >> 8); 198 command[2] = (uint8_t)(pageaddr >> 8);
188 command[3] = 0; 199 command[3] = 0;
189 200
190 DEBUG(MTD_DEBUG_LEVEL3, "ERASE %s: (%x) %x %x %x [%i]\n", 201 pr_debug("ERASE %s: (%x) %x %x %x [%i]\n",
191 do_block ? "block" : "page", 202 do_block ? "block" : "page",
192 command[0], command[1], command[2], command[3], 203 command[0], command[1], command[2], command[3],
193 pageaddr); 204 pageaddr);
@@ -238,8 +249,8 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
238 uint8_t *command; 249 uint8_t *command;
239 int status; 250 int status;
240 251
241 DEBUG(MTD_DEBUG_LEVEL2, "%s: read 0x%x..0x%x\n", 252 pr_debug("%s: read 0x%x..0x%x\n", dev_name(&priv->spi->dev),
242 dev_name(&priv->spi->dev), (unsigned)from, (unsigned)(from + len)); 253 (unsigned)from, (unsigned)(from + len));
243 254
244 *retlen = 0; 255 *retlen = 0;
245 256
@@ -255,7 +266,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
255 266
256 command = priv->command; 267 command = priv->command;
257 268
258 DEBUG(MTD_DEBUG_LEVEL3, "READ: (%x) %x %x %x\n", 269 pr_debug("READ: (%x) %x %x %x\n",
259 command[0], command[1], command[2], command[3]); 270 command[0], command[1], command[2], command[3]);
260 271
261 spi_message_init(&msg); 272 spi_message_init(&msg);
@@ -287,7 +298,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
287 *retlen = msg.actual_length - 8; 298 *retlen = msg.actual_length - 8;
288 status = 0; 299 status = 0;
289 } else 300 } else
290 DEBUG(MTD_DEBUG_LEVEL1, "%s: read %x..%x --> %d\n", 301 pr_debug("%s: read %x..%x --> %d\n",
291 dev_name(&priv->spi->dev), 302 dev_name(&priv->spi->dev),
292 (unsigned)from, (unsigned)(from + len), 303 (unsigned)from, (unsigned)(from + len),
293 status); 304 status);
@@ -314,7 +325,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
314 int status = -EINVAL; 325 int status = -EINVAL;
315 uint8_t *command; 326 uint8_t *command;
316 327
317 DEBUG(MTD_DEBUG_LEVEL2, "%s: write 0x%x..0x%x\n", 328 pr_debug("%s: write 0x%x..0x%x\n",
318 dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len)); 329 dev_name(&spi->dev), (unsigned)to, (unsigned)(to + len));
319 330
320 *retlen = 0; 331 *retlen = 0;
@@ -340,7 +351,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
340 351
341 mutex_lock(&priv->lock); 352 mutex_lock(&priv->lock);
342 while (remaining > 0) { 353 while (remaining > 0) {
343 DEBUG(MTD_DEBUG_LEVEL3, "write @ %i:%i len=%i\n", 354 pr_debug("write @ %i:%i len=%i\n",
344 pageaddr, offset, writelen); 355 pageaddr, offset, writelen);
345 356
346 /* REVISIT: 357 /* REVISIT:
@@ -368,12 +379,12 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
368 command[2] = (addr & 0x0000FF00) >> 8; 379 command[2] = (addr & 0x0000FF00) >> 8;
369 command[3] = 0; 380 command[3] = 0;
370 381
371 DEBUG(MTD_DEBUG_LEVEL3, "TRANSFER: (%x) %x %x %x\n", 382 pr_debug("TRANSFER: (%x) %x %x %x\n",
372 command[0], command[1], command[2], command[3]); 383 command[0], command[1], command[2], command[3]);
373 384
374 status = spi_sync(spi, &msg); 385 status = spi_sync(spi, &msg);
375 if (status < 0) 386 if (status < 0)
376 DEBUG(MTD_DEBUG_LEVEL1, "%s: xfer %u -> %d \n", 387 pr_debug("%s: xfer %u -> %d\n",
377 dev_name(&spi->dev), addr, status); 388 dev_name(&spi->dev), addr, status);
378 389
379 (void) dataflash_waitready(priv->spi); 390 (void) dataflash_waitready(priv->spi);
@@ -386,7 +397,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
386 command[2] = (addr & 0x0000FF00) >> 8; 397 command[2] = (addr & 0x0000FF00) >> 8;
387 command[3] = (addr & 0x000000FF); 398 command[3] = (addr & 0x000000FF);
388 399
389 DEBUG(MTD_DEBUG_LEVEL3, "PROGRAM: (%x) %x %x %x\n", 400 pr_debug("PROGRAM: (%x) %x %x %x\n",
390 command[0], command[1], command[2], command[3]); 401 command[0], command[1], command[2], command[3]);
391 402
392 x[1].tx_buf = writebuf; 403 x[1].tx_buf = writebuf;
@@ -395,7 +406,7 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
395 status = spi_sync(spi, &msg); 406 status = spi_sync(spi, &msg);
396 spi_transfer_del(x + 1); 407 spi_transfer_del(x + 1);
397 if (status < 0) 408 if (status < 0)
398 DEBUG(MTD_DEBUG_LEVEL1, "%s: pgm %u/%u -> %d \n", 409 pr_debug("%s: pgm %u/%u -> %d\n",
399 dev_name(&spi->dev), addr, writelen, status); 410 dev_name(&spi->dev), addr, writelen, status);
400 411
401 (void) dataflash_waitready(priv->spi); 412 (void) dataflash_waitready(priv->spi);
@@ -410,12 +421,12 @@ static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
410 command[2] = (addr & 0x0000FF00) >> 8; 421 command[2] = (addr & 0x0000FF00) >> 8;
411 command[3] = 0; 422 command[3] = 0;
412 423
413 DEBUG(MTD_DEBUG_LEVEL3, "COMPARE: (%x) %x %x %x\n", 424 pr_debug("COMPARE: (%x) %x %x %x\n",
414 command[0], command[1], command[2], command[3]); 425 command[0], command[1], command[2], command[3]);
415 426
416 status = spi_sync(spi, &msg); 427 status = spi_sync(spi, &msg);
417 if (status < 0) 428 if (status < 0)
418 DEBUG(MTD_DEBUG_LEVEL1, "%s: compare %u -> %d \n", 429 pr_debug("%s: compare %u -> %d\n",
419 dev_name(&spi->dev), addr, status); 430 dev_name(&spi->dev), addr, status);
420 431
421 status = dataflash_waitready(priv->spi); 432 status = dataflash_waitready(priv->spi);
@@ -634,11 +645,10 @@ add_dataflash_otp(struct spi_device *spi, char *name,
634{ 645{
635 struct dataflash *priv; 646 struct dataflash *priv;
636 struct mtd_info *device; 647 struct mtd_info *device;
648 struct mtd_part_parser_data ppdata;
637 struct flash_platform_data *pdata = spi->dev.platform_data; 649 struct flash_platform_data *pdata = spi->dev.platform_data;
638 char *otp_tag = ""; 650 char *otp_tag = "";
639 int err = 0; 651 int err = 0;
640 struct mtd_partition *parts;
641 int nr_parts = 0;
642 652
643 priv = kzalloc(sizeof *priv, GFP_KERNEL); 653 priv = kzalloc(sizeof *priv, GFP_KERNEL);
644 if (!priv) 654 if (!priv)
@@ -677,28 +687,11 @@ add_dataflash_otp(struct spi_device *spi, char *name,
677 pagesize, otp_tag); 687 pagesize, otp_tag);
678 dev_set_drvdata(&spi->dev, priv); 688 dev_set_drvdata(&spi->dev, priv);
679 689
680 if (mtd_has_cmdlinepart()) { 690 ppdata.of_node = spi->dev.of_node;
681 static const char *part_probes[] = { "cmdlinepart", NULL, }; 691 err = mtd_device_parse_register(device, NULL, &ppdata,
682 692 pdata ? pdata->parts : NULL,
683 nr_parts = parse_mtd_partitions(device, part_probes, &parts, 693 pdata ? pdata->nr_parts : 0);
684 0);
685 }
686 694
687 if (nr_parts <= 0 && pdata && pdata->parts) {
688 parts = pdata->parts;
689 nr_parts = pdata->nr_parts;
690 }
691
692 if (nr_parts > 0) {
693 priv->partitioned = 1;
694 err = mtd_device_register(device, parts, nr_parts);
695 goto out;
696 }
697
698 if (mtd_device_register(device, NULL, 0) == 1)
699 err = -ENODEV;
700
701out:
702 if (!err) 695 if (!err)
703 return 0; 696 return 0;
704 697
@@ -787,7 +780,7 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi)
787 */ 780 */
788 tmp = spi_write_then_read(spi, &code, 1, id, 3); 781 tmp = spi_write_then_read(spi, &code, 1, id, 3);
789 if (tmp < 0) { 782 if (tmp < 0) {
790 DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n", 783 pr_debug("%s: error %d reading JEDEC ID\n",
791 dev_name(&spi->dev), tmp); 784 dev_name(&spi->dev), tmp);
792 return ERR_PTR(tmp); 785 return ERR_PTR(tmp);
793 } 786 }
@@ -804,7 +797,7 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi)
804 tmp < ARRAY_SIZE(dataflash_data); 797 tmp < ARRAY_SIZE(dataflash_data);
805 tmp++, info++) { 798 tmp++, info++) {
806 if (info->jedec_id == jedec) { 799 if (info->jedec_id == jedec) {
807 DEBUG(MTD_DEBUG_LEVEL1, "%s: OTP, sector protect%s\n", 800 pr_debug("%s: OTP, sector protect%s\n",
808 dev_name(&spi->dev), 801 dev_name(&spi->dev),
809 (info->flags & SUP_POW2PS) 802 (info->flags & SUP_POW2PS)
810 ? ", binary pagesize" : "" 803 ? ", binary pagesize" : ""
@@ -812,8 +805,7 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi)
812 if (info->flags & SUP_POW2PS) { 805 if (info->flags & SUP_POW2PS) {
813 status = dataflash_status(spi); 806 status = dataflash_status(spi);
814 if (status < 0) { 807 if (status < 0) {
815 DEBUG(MTD_DEBUG_LEVEL1, 808 pr_debug("%s: status error %d\n",
816 "%s: status error %d\n",
817 dev_name(&spi->dev), status); 809 dev_name(&spi->dev), status);
818 return ERR_PTR(status); 810 return ERR_PTR(status);
819 } 811 }
@@ -878,7 +870,7 @@ static int __devinit dataflash_probe(struct spi_device *spi)
878 */ 870 */
879 status = dataflash_status(spi); 871 status = dataflash_status(spi);
880 if (status <= 0 || status == 0xff) { 872 if (status <= 0 || status == 0xff) {
881 DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n", 873 pr_debug("%s: status error %d\n",
882 dev_name(&spi->dev), status); 874 dev_name(&spi->dev), status);
883 if (status == 0 || status == 0xff) 875 if (status == 0 || status == 0xff)
884 status = -ENODEV; 876 status = -ENODEV;
@@ -914,14 +906,14 @@ static int __devinit dataflash_probe(struct spi_device *spi)
914 break; 906 break;
915 /* obsolete AT45DB1282 not (yet?) supported */ 907 /* obsolete AT45DB1282 not (yet?) supported */
916 default: 908 default:
917 DEBUG(MTD_DEBUG_LEVEL1, "%s: unsupported device (%x)\n", 909 pr_debug("%s: unsupported device (%x)\n", dev_name(&spi->dev),
918 dev_name(&spi->dev), status & 0x3c); 910 status & 0x3c);
919 status = -ENODEV; 911 status = -ENODEV;
920 } 912 }
921 913
922 if (status < 0) 914 if (status < 0)
923 DEBUG(MTD_DEBUG_LEVEL1, "%s: add_dataflash --> %d\n", 915 pr_debug("%s: add_dataflash --> %d\n", dev_name(&spi->dev),
924 dev_name(&spi->dev), status); 916 status);
925 917
926 return status; 918 return status;
927} 919}
@@ -931,7 +923,7 @@ static int __devexit dataflash_remove(struct spi_device *spi)
931 struct dataflash *flash = dev_get_drvdata(&spi->dev); 923 struct dataflash *flash = dev_get_drvdata(&spi->dev);
932 int status; 924 int status;
933 925
934 DEBUG(MTD_DEBUG_LEVEL1, "%s: remove\n", dev_name(&spi->dev)); 926 pr_debug("%s: remove\n", dev_name(&spi->dev));
935 927
936 status = mtd_device_unregister(&flash->mtd); 928 status = mtd_device_unregister(&flash->mtd);
937 if (status == 0) { 929 if (status == 0) {
@@ -946,6 +938,7 @@ static struct spi_driver dataflash_driver = {
946 .name = "mtd_dataflash", 938 .name = "mtd_dataflash",
947 .bus = &spi_bus_type, 939 .bus = &spi_bus_type,
948 .owner = THIS_MODULE, 940 .owner = THIS_MODULE,
941 .of_match_table = dataflash_dt_ids,
949 }, 942 },
950 943
951 .probe = dataflash_probe, 944 .probe = dataflash_probe,
diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c
index 83e80c65d6e..d38ef3bffe8 100644
--- a/drivers/mtd/devices/sst25l.c
+++ b/drivers/mtd/devices/sst25l.c
@@ -52,8 +52,6 @@ struct sst25l_flash {
52 struct spi_device *spi; 52 struct spi_device *spi;
53 struct mutex lock; 53 struct mutex lock;
54 struct mtd_info mtd; 54 struct mtd_info mtd;
55
56 int partitioned;
57}; 55};
58 56
59struct flash_info { 57struct flash_info {
@@ -381,8 +379,6 @@ static int __devinit sst25l_probe(struct spi_device *spi)
381 struct sst25l_flash *flash; 379 struct sst25l_flash *flash;
382 struct flash_platform_data *data; 380 struct flash_platform_data *data;
383 int ret, i; 381 int ret, i;
384 struct mtd_partition *parts = NULL;
385 int nr_parts = 0;
386 382
387 flash_info = sst25l_match_device(spi); 383 flash_info = sst25l_match_device(spi);
388 if (!flash_info) 384 if (!flash_info)
@@ -414,8 +410,7 @@ static int __devinit sst25l_probe(struct spi_device *spi)
414 dev_info(&spi->dev, "%s (%lld KiB)\n", flash_info->name, 410 dev_info(&spi->dev, "%s (%lld KiB)\n", flash_info->name,
415 (long long)flash->mtd.size >> 10); 411 (long long)flash->mtd.size >> 10);
416 412
417 DEBUG(MTD_DEBUG_LEVEL2, 413 pr_debug("mtd .name = %s, .size = 0x%llx (%lldMiB) "
418 "mtd .name = %s, .size = 0x%llx (%lldMiB) "
419 ".erasesize = 0x%.8x (%uKiB) .numeraseregions = %d\n", 414 ".erasesize = 0x%.8x (%uKiB) .numeraseregions = %d\n",
420 flash->mtd.name, 415 flash->mtd.name,
421 (long long)flash->mtd.size, (long long)(flash->mtd.size >> 20), 416 (long long)flash->mtd.size, (long long)(flash->mtd.size >> 20),
@@ -423,37 +418,10 @@ static int __devinit sst25l_probe(struct spi_device *spi)
423 flash->mtd.numeraseregions); 418 flash->mtd.numeraseregions);
424 419
425 420
426 if (mtd_has_cmdlinepart()) { 421 ret = mtd_device_parse_register(&flash->mtd, NULL, 0,
427 static const char *part_probes[] = {"cmdlinepart", NULL}; 422 data ? data->parts : NULL,
428 423 data ? data->nr_parts : 0);
429 nr_parts = parse_mtd_partitions(&flash->mtd, 424 if (ret) {
430 part_probes,
431 &parts, 0);
432 }
433
434 if (nr_parts <= 0 && data && data->parts) {
435 parts = data->parts;
436 nr_parts = data->nr_parts;
437 }
438
439 if (nr_parts > 0) {
440 for (i = 0; i < nr_parts; i++) {
441 DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = "
442 "{.name = %s, .offset = 0x%llx, "
443 ".size = 0x%llx (%lldKiB) }\n",
444 i, parts[i].name,
445 (long long)parts[i].offset,
446 (long long)parts[i].size,
447 (long long)(parts[i].size >> 10));
448 }
449
450 flash->partitioned = 1;
451 return mtd_device_register(&flash->mtd, parts,
452 nr_parts);
453 }
454
455 ret = mtd_device_register(&flash->mtd, NULL, 0);
456 if (ret == 1) {
457 kfree(flash); 425 kfree(flash);
458 dev_set_drvdata(&spi->dev, NULL); 426 dev_set_drvdata(&spi->dev, NULL);
459 return -ENODEV; 427 return -ENODEV;
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 037b399df3f..c7382bb686c 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -339,7 +339,7 @@ static int erase_xfer(partition_t *part,
339 struct erase_info *erase; 339 struct erase_info *erase;
340 340
341 xfer = &part->XferInfo[xfernum]; 341 xfer = &part->XferInfo[xfernum];
342 DEBUG(1, "ftl_cs: erasing xfer unit at 0x%x\n", xfer->Offset); 342 pr_debug("ftl_cs: erasing xfer unit at 0x%x\n", xfer->Offset);
343 xfer->state = XFER_ERASING; 343 xfer->state = XFER_ERASING;
344 344
345 /* Is there a free erase slot? Always in MTD. */ 345 /* Is there a free erase slot? Always in MTD. */
@@ -415,7 +415,7 @@ static int prepare_xfer(partition_t *part, int i)
415 xfer = &part->XferInfo[i]; 415 xfer = &part->XferInfo[i];
416 xfer->state = XFER_FAILED; 416 xfer->state = XFER_FAILED;
417 417
418 DEBUG(1, "ftl_cs: preparing xfer unit at 0x%x\n", xfer->Offset); 418 pr_debug("ftl_cs: preparing xfer unit at 0x%x\n", xfer->Offset);
419 419
420 /* Write the transfer unit header */ 420 /* Write the transfer unit header */
421 header = part->header; 421 header = part->header;
@@ -476,7 +476,7 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
476 476
477 eun = &part->EUNInfo[srcunit]; 477 eun = &part->EUNInfo[srcunit];
478 xfer = &part->XferInfo[xferunit]; 478 xfer = &part->XferInfo[xferunit];
479 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n", 479 pr_debug("ftl_cs: copying block 0x%x to 0x%x\n",
480 eun->Offset, xfer->Offset); 480 eun->Offset, xfer->Offset);
481 481
482 482
@@ -598,7 +598,7 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
598 unit with the fewest erases, and usually pick the data unit with 598 unit with the fewest erases, and usually pick the data unit with
599 the most deleted blocks. But with a small probability, pick the 599 the most deleted blocks. But with a small probability, pick the
600 oldest data unit instead. This means that we generally postpone 600 oldest data unit instead. This means that we generally postpone
601 the next reclaimation as long as possible, but shuffle static 601 the next reclamation as long as possible, but shuffle static
602 stuff around a bit for wear leveling. 602 stuff around a bit for wear leveling.
603 603
604======================================================================*/ 604======================================================================*/
@@ -609,8 +609,8 @@ static int reclaim_block(partition_t *part)
609 uint32_t best; 609 uint32_t best;
610 int queued, ret; 610 int queued, ret;
611 611
612 DEBUG(0, "ftl_cs: reclaiming space...\n"); 612 pr_debug("ftl_cs: reclaiming space...\n");
613 DEBUG(3, "NumTransferUnits == %x\n", part->header.NumTransferUnits); 613 pr_debug("NumTransferUnits == %x\n", part->header.NumTransferUnits);
614 /* Pick the least erased transfer unit */ 614 /* Pick the least erased transfer unit */
615 best = 0xffffffff; xfer = 0xffff; 615 best = 0xffffffff; xfer = 0xffff;
616 do { 616 do {
@@ -618,22 +618,22 @@ static int reclaim_block(partition_t *part)
618 for (i = 0; i < part->header.NumTransferUnits; i++) { 618 for (i = 0; i < part->header.NumTransferUnits; i++) {
619 int n=0; 619 int n=0;
620 if (part->XferInfo[i].state == XFER_UNKNOWN) { 620 if (part->XferInfo[i].state == XFER_UNKNOWN) {
621 DEBUG(3,"XferInfo[%d].state == XFER_UNKNOWN\n",i); 621 pr_debug("XferInfo[%d].state == XFER_UNKNOWN\n",i);
622 n=1; 622 n=1;
623 erase_xfer(part, i); 623 erase_xfer(part, i);
624 } 624 }
625 if (part->XferInfo[i].state == XFER_ERASING) { 625 if (part->XferInfo[i].state == XFER_ERASING) {
626 DEBUG(3,"XferInfo[%d].state == XFER_ERASING\n",i); 626 pr_debug("XferInfo[%d].state == XFER_ERASING\n",i);
627 n=1; 627 n=1;
628 queued = 1; 628 queued = 1;
629 } 629 }
630 else if (part->XferInfo[i].state == XFER_ERASED) { 630 else if (part->XferInfo[i].state == XFER_ERASED) {
631 DEBUG(3,"XferInfo[%d].state == XFER_ERASED\n",i); 631 pr_debug("XferInfo[%d].state == XFER_ERASED\n",i);
632 n=1; 632 n=1;
633 prepare_xfer(part, i); 633 prepare_xfer(part, i);
634 } 634 }
635 if (part->XferInfo[i].state == XFER_PREPARED) { 635 if (part->XferInfo[i].state == XFER_PREPARED) {
636 DEBUG(3,"XferInfo[%d].state == XFER_PREPARED\n",i); 636 pr_debug("XferInfo[%d].state == XFER_PREPARED\n",i);
637 n=1; 637 n=1;
638 if (part->XferInfo[i].EraseCount <= best) { 638 if (part->XferInfo[i].EraseCount <= best) {
639 best = part->XferInfo[i].EraseCount; 639 best = part->XferInfo[i].EraseCount;
@@ -641,12 +641,12 @@ static int reclaim_block(partition_t *part)
641 } 641 }
642 } 642 }
643 if (!n) 643 if (!n)
644 DEBUG(3,"XferInfo[%d].state == %x\n",i, part->XferInfo[i].state); 644 pr_debug("XferInfo[%d].state == %x\n",i, part->XferInfo[i].state);
645 645
646 } 646 }
647 if (xfer == 0xffff) { 647 if (xfer == 0xffff) {
648 if (queued) { 648 if (queued) {
649 DEBUG(1, "ftl_cs: waiting for transfer " 649 pr_debug("ftl_cs: waiting for transfer "
650 "unit to be prepared...\n"); 650 "unit to be prepared...\n");
651 if (part->mbd.mtd->sync) 651 if (part->mbd.mtd->sync)
652 part->mbd.mtd->sync(part->mbd.mtd); 652 part->mbd.mtd->sync(part->mbd.mtd);
@@ -656,7 +656,7 @@ static int reclaim_block(partition_t *part)
656 printk(KERN_NOTICE "ftl_cs: reclaim failed: no " 656 printk(KERN_NOTICE "ftl_cs: reclaim failed: no "
657 "suitable transfer units!\n"); 657 "suitable transfer units!\n");
658 else 658 else
659 DEBUG(1, "ftl_cs: reclaim failed: no " 659 pr_debug("ftl_cs: reclaim failed: no "
660 "suitable transfer units!\n"); 660 "suitable transfer units!\n");
661 661
662 return -EIO; 662 return -EIO;
@@ -666,7 +666,7 @@ static int reclaim_block(partition_t *part)
666 666
667 eun = 0; 667 eun = 0;
668 if ((jiffies % shuffle_freq) == 0) { 668 if ((jiffies % shuffle_freq) == 0) {
669 DEBUG(1, "ftl_cs: recycling freshest block...\n"); 669 pr_debug("ftl_cs: recycling freshest block...\n");
670 best = 0xffffffff; 670 best = 0xffffffff;
671 for (i = 0; i < part->DataUnits; i++) 671 for (i = 0; i < part->DataUnits; i++)
672 if (part->EUNInfo[i].EraseCount <= best) { 672 if (part->EUNInfo[i].EraseCount <= best) {
@@ -686,7 +686,7 @@ static int reclaim_block(partition_t *part)
686 printk(KERN_NOTICE "ftl_cs: reclaim failed: " 686 printk(KERN_NOTICE "ftl_cs: reclaim failed: "
687 "no free blocks!\n"); 687 "no free blocks!\n");
688 else 688 else
689 DEBUG(1,"ftl_cs: reclaim failed: " 689 pr_debug("ftl_cs: reclaim failed: "
690 "no free blocks!\n"); 690 "no free blocks!\n");
691 691
692 return -EIO; 692 return -EIO;
@@ -771,7 +771,7 @@ static uint32_t find_free(partition_t *part)
771 printk(KERN_NOTICE "ftl_cs: bad free list!\n"); 771 printk(KERN_NOTICE "ftl_cs: bad free list!\n");
772 return 0; 772 return 0;
773 } 773 }
774 DEBUG(2, "ftl_cs: found free block at %d in %d\n", blk, eun); 774 pr_debug("ftl_cs: found free block at %d in %d\n", blk, eun);
775 return blk; 775 return blk;
776 776
777} /* find_free */ 777} /* find_free */
@@ -791,7 +791,7 @@ static int ftl_read(partition_t *part, caddr_t buffer,
791 int ret; 791 int ret;
792 size_t offset, retlen; 792 size_t offset, retlen;
793 793
794 DEBUG(2, "ftl_cs: ftl_read(0x%p, 0x%lx, %ld)\n", 794 pr_debug("ftl_cs: ftl_read(0x%p, 0x%lx, %ld)\n",
795 part, sector, nblocks); 795 part, sector, nblocks);
796 if (!(part->state & FTL_FORMATTED)) { 796 if (!(part->state & FTL_FORMATTED)) {
797 printk(KERN_NOTICE "ftl_cs: bad partition\n"); 797 printk(KERN_NOTICE "ftl_cs: bad partition\n");
@@ -840,7 +840,7 @@ static int set_bam_entry(partition_t *part, uint32_t log_addr,
840 int ret; 840 int ret;
841 size_t retlen, offset; 841 size_t retlen, offset;
842 842
843 DEBUG(2, "ftl_cs: set_bam_entry(0x%p, 0x%x, 0x%x)\n", 843 pr_debug("ftl_cs: set_bam_entry(0x%p, 0x%x, 0x%x)\n",
844 part, log_addr, virt_addr); 844 part, log_addr, virt_addr);
845 bsize = 1 << part->header.EraseUnitSize; 845 bsize = 1 << part->header.EraseUnitSize;
846 eun = log_addr / bsize; 846 eun = log_addr / bsize;
@@ -905,7 +905,7 @@ static int ftl_write(partition_t *part, caddr_t buffer,
905 int ret; 905 int ret;
906 size_t retlen, offset; 906 size_t retlen, offset;
907 907
908 DEBUG(2, "ftl_cs: ftl_write(0x%p, %ld, %ld)\n", 908 pr_debug("ftl_cs: ftl_write(0x%p, %ld, %ld)\n",
909 part, sector, nblocks); 909 part, sector, nblocks);
910 if (!(part->state & FTL_FORMATTED)) { 910 if (!(part->state & FTL_FORMATTED)) {
911 printk(KERN_NOTICE "ftl_cs: bad partition\n"); 911 printk(KERN_NOTICE "ftl_cs: bad partition\n");
@@ -1011,7 +1011,7 @@ static int ftl_discardsect(struct mtd_blktrans_dev *dev,
1011 partition_t *part = (void *)dev; 1011 partition_t *part = (void *)dev;
1012 uint32_t bsize = 1 << part->header.EraseUnitSize; 1012 uint32_t bsize = 1 << part->header.EraseUnitSize;
1013 1013
1014 DEBUG(1, "FTL erase sector %ld for %d sectors\n", 1014 pr_debug("FTL erase sector %ld for %d sectors\n",
1015 sector, nr_sects); 1015 sector, nr_sects);
1016 1016
1017 while (nr_sects) { 1017 while (nr_sects) {
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index d7592e67d04..dd034efd187 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -63,14 +63,12 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
63 return; 63 return;
64 } 64 }
65 65
66 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name); 66 pr_debug("INFTL: add_mtd for %s\n", mtd->name);
67 67
68 inftl = kzalloc(sizeof(*inftl), GFP_KERNEL); 68 inftl = kzalloc(sizeof(*inftl), GFP_KERNEL);
69 69
70 if (!inftl) { 70 if (!inftl)
71 printk(KERN_WARNING "INFTL: Out of memory for data structures\n");
72 return; 71 return;
73 }
74 72
75 inftl->mbd.mtd = mtd; 73 inftl->mbd.mtd = mtd;
76 inftl->mbd.devnum = -1; 74 inftl->mbd.devnum = -1;
@@ -133,7 +131,7 @@ static void inftl_remove_dev(struct mtd_blktrans_dev *dev)
133{ 131{
134 struct INFTLrecord *inftl = (void *)dev; 132 struct INFTLrecord *inftl = (void *)dev;
135 133
136 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: remove_dev (i=%d)\n", dev->devnum); 134 pr_debug("INFTL: remove_dev (i=%d)\n", dev->devnum);
137 135
138 del_mtd_blktrans_dev(dev); 136 del_mtd_blktrans_dev(dev);
139 137
@@ -154,7 +152,7 @@ int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
154 struct mtd_oob_ops ops; 152 struct mtd_oob_ops ops;
155 int res; 153 int res;
156 154
157 ops.mode = MTD_OOB_PLACE; 155 ops.mode = MTD_OPS_PLACE_OOB;
158 ops.ooboffs = offs & (mtd->writesize - 1); 156 ops.ooboffs = offs & (mtd->writesize - 1);
159 ops.ooblen = len; 157 ops.ooblen = len;
160 ops.oobbuf = buf; 158 ops.oobbuf = buf;
@@ -174,7 +172,7 @@ int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
174 struct mtd_oob_ops ops; 172 struct mtd_oob_ops ops;
175 int res; 173 int res;
176 174
177 ops.mode = MTD_OOB_PLACE; 175 ops.mode = MTD_OPS_PLACE_OOB;
178 ops.ooboffs = offs & (mtd->writesize - 1); 176 ops.ooboffs = offs & (mtd->writesize - 1);
179 ops.ooblen = len; 177 ops.ooblen = len;
180 ops.oobbuf = buf; 178 ops.oobbuf = buf;
@@ -194,7 +192,7 @@ static int inftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
194 struct mtd_oob_ops ops; 192 struct mtd_oob_ops ops;
195 int res; 193 int res;
196 194
197 ops.mode = MTD_OOB_PLACE; 195 ops.mode = MTD_OPS_PLACE_OOB;
198 ops.ooboffs = offs; 196 ops.ooboffs = offs;
199 ops.ooblen = mtd->oobsize; 197 ops.ooblen = mtd->oobsize;
200 ops.oobbuf = oob; 198 ops.oobbuf = oob;
@@ -215,16 +213,16 @@ static u16 INFTL_findfreeblock(struct INFTLrecord *inftl, int desperate)
215 u16 pot = inftl->LastFreeEUN; 213 u16 pot = inftl->LastFreeEUN;
216 int silly = inftl->nb_blocks; 214 int silly = inftl->nb_blocks;
217 215
218 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_findfreeblock(inftl=%p," 216 pr_debug("INFTL: INFTL_findfreeblock(inftl=%p,desperate=%d)\n",
219 "desperate=%d)\n", inftl, desperate); 217 inftl, desperate);
220 218
221 /* 219 /*
222 * Normally, we force a fold to happen before we run out of free 220 * Normally, we force a fold to happen before we run out of free
223 * blocks completely. 221 * blocks completely.
224 */ 222 */
225 if (!desperate && inftl->numfreeEUNs < 2) { 223 if (!desperate && inftl->numfreeEUNs < 2) {
226 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: there are too few free " 224 pr_debug("INFTL: there are too few free EUNs (%d)\n",
227 "EUNs (%d)\n", inftl->numfreeEUNs); 225 inftl->numfreeEUNs);
228 return BLOCK_NIL; 226 return BLOCK_NIL;
229 } 227 }
230 228
@@ -259,8 +257,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
259 struct inftl_oob oob; 257 struct inftl_oob oob;
260 size_t retlen; 258 size_t retlen;
261 259
262 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d," 260 pr_debug("INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,pending=%d)\n",
263 "pending=%d)\n", inftl, thisVUC, pendingblock); 261 inftl, thisVUC, pendingblock);
264 262
265 memset(BlockMap, 0xff, sizeof(BlockMap)); 263 memset(BlockMap, 0xff, sizeof(BlockMap));
266 memset(BlockDeleted, 0, sizeof(BlockDeleted)); 264 memset(BlockDeleted, 0, sizeof(BlockDeleted));
@@ -323,8 +321,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
323 * Chain, and the Erase Unit into which we are supposed to be copying. 321 * Chain, and the Erase Unit into which we are supposed to be copying.
324 * Go for it. 322 * Go for it.
325 */ 323 */
326 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: folding chain %d into unit %d\n", 324 pr_debug("INFTL: folding chain %d into unit %d\n", thisVUC, targetEUN);
327 thisVUC, targetEUN);
328 325
329 for (block = 0; block < inftl->EraseSize/SECTORSIZE ; block++) { 326 for (block = 0; block < inftl->EraseSize/SECTORSIZE ; block++) {
330 unsigned char movebuf[SECTORSIZE]; 327 unsigned char movebuf[SECTORSIZE];
@@ -349,14 +346,13 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
349 ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) + 346 ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) +
350 (block * SECTORSIZE), SECTORSIZE, &retlen, 347 (block * SECTORSIZE), SECTORSIZE, &retlen,
351 movebuf); 348 movebuf);
352 if (ret < 0 && ret != -EUCLEAN) { 349 if (ret < 0 && !mtd_is_bitflip(ret)) {
353 ret = mtd->read(mtd, 350 ret = mtd->read(mtd,
354 (inftl->EraseSize * BlockMap[block]) + 351 (inftl->EraseSize * BlockMap[block]) +
355 (block * SECTORSIZE), SECTORSIZE, 352 (block * SECTORSIZE), SECTORSIZE,
356 &retlen, movebuf); 353 &retlen, movebuf);
357 if (ret != -EIO) 354 if (ret != -EIO)
358 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: error went " 355 pr_debug("INFTL: error went away on retry?\n");
359 "away on retry?\n");
360 } 356 }
361 memset(&oob, 0xff, sizeof(struct inftl_oob)); 357 memset(&oob, 0xff, sizeof(struct inftl_oob));
362 oob.b.Status = oob.b.Status1 = SECTOR_USED; 358 oob.b.Status = oob.b.Status1 = SECTOR_USED;
@@ -372,8 +368,7 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
372 * is important, by doing oldest first if we crash/reboot then it 368 * is important, by doing oldest first if we crash/reboot then it
373 * it is relatively simple to clean up the mess). 369 * it is relatively simple to clean up the mess).
374 */ 370 */
375 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: want to erase virtual chain %d\n", 371 pr_debug("INFTL: want to erase virtual chain %d\n", thisVUC);
376 thisVUC);
377 372
378 for (;;) { 373 for (;;) {
379 /* Find oldest unit in chain. */ 374 /* Find oldest unit in chain. */
@@ -421,7 +416,7 @@ static u16 INFTL_makefreeblock(struct INFTLrecord *inftl, unsigned pendingblock)
421 u16 ChainLength = 0, thislen; 416 u16 ChainLength = 0, thislen;
422 u16 chain, EUN; 417 u16 chain, EUN;
423 418
424 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_makefreeblock(inftl=%p," 419 pr_debug("INFTL: INFTL_makefreeblock(inftl=%p,"
425 "pending=%d)\n", inftl, pendingblock); 420 "pending=%d)\n", inftl, pendingblock);
426 421
427 for (chain = 0; chain < inftl->nb_blocks; chain++) { 422 for (chain = 0; chain < inftl->nb_blocks; chain++) {
@@ -484,8 +479,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
484 size_t retlen; 479 size_t retlen;
485 int silly, silly2 = 3; 480 int silly, silly2 = 3;
486 481
487 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_findwriteunit(inftl=%p," 482 pr_debug("INFTL: INFTL_findwriteunit(inftl=%p,block=%d)\n",
488 "block=%d)\n", inftl, block); 483 inftl, block);
489 484
490 do { 485 do {
491 /* 486 /*
@@ -501,8 +496,8 @@ static inline u16 INFTL_findwriteunit(struct INFTLrecord *inftl, unsigned block)
501 blockofs, 8, &retlen, (char *)&bci); 496 blockofs, 8, &retlen, (char *)&bci);
502 497
503 status = bci.Status | bci.Status1; 498 status = bci.Status | bci.Status1;
504 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: status of block %d in " 499 pr_debug("INFTL: status of block %d in EUN %d is %x\n",
505 "EUN %d is %x\n", block , writeEUN, status); 500 block , writeEUN, status);
506 501
507 switch(status) { 502 switch(status) {
508 case SECTOR_FREE: 503 case SECTOR_FREE:
@@ -555,9 +550,9 @@ hitused:
555 * Hopefully we free something, lets try again. 550 * Hopefully we free something, lets try again.
556 * This time we are desperate... 551 * This time we are desperate...
557 */ 552 */
558 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: using desperate==1 " 553 pr_debug("INFTL: using desperate==1 to find free EUN "
559 "to find free EUN to accommodate write to " 554 "to accommodate write to VUC %d\n",
560 "VUC %d\n", thisVUC); 555 thisVUC);
561 writeEUN = INFTL_findfreeblock(inftl, 1); 556 writeEUN = INFTL_findfreeblock(inftl, 1);
562 if (writeEUN == BLOCK_NIL) { 557 if (writeEUN == BLOCK_NIL) {
563 /* 558 /*
@@ -647,7 +642,7 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
647 struct inftl_bci bci; 642 struct inftl_bci bci;
648 size_t retlen; 643 size_t retlen;
649 644
650 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_trydeletechain(inftl=%p," 645 pr_debug("INFTL: INFTL_trydeletechain(inftl=%p,"
651 "thisVUC=%d)\n", inftl, thisVUC); 646 "thisVUC=%d)\n", inftl, thisVUC);
652 647
653 memset(BlockUsed, 0, sizeof(BlockUsed)); 648 memset(BlockUsed, 0, sizeof(BlockUsed));
@@ -711,7 +706,7 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
711 * For each block in the chain free it and make it available 706 * For each block in the chain free it and make it available
712 * for future use. Erase from the oldest unit first. 707 * for future use. Erase from the oldest unit first.
713 */ 708 */
714 DEBUG(MTD_DEBUG_LEVEL1, "INFTL: deleting empty VUC %d\n", thisVUC); 709 pr_debug("INFTL: deleting empty VUC %d\n", thisVUC);
715 710
716 for (;;) { 711 for (;;) {
717 u16 *prevEUN = &inftl->VUtable[thisVUC]; 712 u16 *prevEUN = &inftl->VUtable[thisVUC];
@@ -719,7 +714,7 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
719 714
720 /* If the chain is all gone already, we're done */ 715 /* If the chain is all gone already, we're done */
721 if (thisEUN == BLOCK_NIL) { 716 if (thisEUN == BLOCK_NIL) {
722 DEBUG(MTD_DEBUG_LEVEL2, "INFTL: Empty VUC %d for deletion was already absent\n", thisEUN); 717 pr_debug("INFTL: Empty VUC %d for deletion was already absent\n", thisEUN);
723 return; 718 return;
724 } 719 }
725 720
@@ -731,7 +726,7 @@ static void INFTL_trydeletechain(struct INFTLrecord *inftl, unsigned thisVUC)
731 thisEUN = *prevEUN; 726 thisEUN = *prevEUN;
732 } 727 }
733 728
734 DEBUG(MTD_DEBUG_LEVEL3, "Deleting EUN %d from VUC %d\n", 729 pr_debug("Deleting EUN %d from VUC %d\n",
735 thisEUN, thisVUC); 730 thisEUN, thisVUC);
736 731
737 if (INFTL_formatblock(inftl, thisEUN) < 0) { 732 if (INFTL_formatblock(inftl, thisEUN) < 0) {
@@ -767,7 +762,7 @@ static int INFTL_deleteblock(struct INFTLrecord *inftl, unsigned block)
767 size_t retlen; 762 size_t retlen;
768 struct inftl_bci bci; 763 struct inftl_bci bci;
769 764
770 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_deleteblock(inftl=%p," 765 pr_debug("INFTL: INFTL_deleteblock(inftl=%p,"
771 "block=%d)\n", inftl, block); 766 "block=%d)\n", inftl, block);
772 767
773 while (thisEUN < inftl->nb_blocks) { 768 while (thisEUN < inftl->nb_blocks) {
@@ -826,7 +821,7 @@ static int inftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long block,
826 struct inftl_oob oob; 821 struct inftl_oob oob;
827 char *p, *pend; 822 char *p, *pend;
828 823
829 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: inftl_writeblock(inftl=%p,block=%ld," 824 pr_debug("INFTL: inftl_writeblock(inftl=%p,block=%ld,"
830 "buffer=%p)\n", inftl, block, buffer); 825 "buffer=%p)\n", inftl, block, buffer);
831 826
832 /* Is block all zero? */ 827 /* Is block all zero? */
@@ -876,7 +871,7 @@ static int inftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
876 struct inftl_bci bci; 871 struct inftl_bci bci;
877 size_t retlen; 872 size_t retlen;
878 873
879 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: inftl_readblock(inftl=%p,block=%ld," 874 pr_debug("INFTL: inftl_readblock(inftl=%p,block=%ld,"
880 "buffer=%p)\n", inftl, block, buffer); 875 "buffer=%p)\n", inftl, block, buffer);
881 876
882 while (thisEUN < inftl->nb_blocks) { 877 while (thisEUN < inftl->nb_blocks) {
@@ -922,7 +917,7 @@ foundit:
922 int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer); 917 int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer);
923 918
924 /* Handle corrected bit flips gracefully */ 919 /* Handle corrected bit flips gracefully */
925 if (ret < 0 && ret != -EUCLEAN) 920 if (ret < 0 && !mtd_is_bitflip(ret))
926 return -EIO; 921 return -EIO;
927 } 922 }
928 return 0; 923 return 0;
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index 104052e774b..2ff601f816c 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -53,7 +53,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
53 struct INFTLPartition *ip; 53 struct INFTLPartition *ip;
54 size_t retlen; 54 size_t retlen;
55 55
56 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl); 56 pr_debug("INFTL: find_boot_record(inftl=%p)\n", inftl);
57 57
58 /* 58 /*
59 * Assume logical EraseSize == physical erasesize for starting the 59 * Assume logical EraseSize == physical erasesize for starting the
@@ -139,24 +139,20 @@ static int find_boot_record(struct INFTLrecord *inftl)
139 mh->FormatFlags = le32_to_cpu(mh->FormatFlags); 139 mh->FormatFlags = le32_to_cpu(mh->FormatFlags);
140 mh->PercentUsed = le32_to_cpu(mh->PercentUsed); 140 mh->PercentUsed = le32_to_cpu(mh->PercentUsed);
141 141
142#ifdef CONFIG_MTD_DEBUG_VERBOSE 142 pr_debug("INFTL: Media Header ->\n"
143 if (CONFIG_MTD_DEBUG_VERBOSE >= 2) { 143 " bootRecordID = %s\n"
144 printk("INFTL: Media Header ->\n" 144 " NoOfBootImageBlocks = %d\n"
145 " bootRecordID = %s\n" 145 " NoOfBinaryPartitions = %d\n"
146 " NoOfBootImageBlocks = %d\n" 146 " NoOfBDTLPartitions = %d\n"
147 " NoOfBinaryPartitions = %d\n" 147 " BlockMultiplerBits = %d\n"
148 " NoOfBDTLPartitions = %d\n" 148 " FormatFlgs = %d\n"
149 " BlockMultiplerBits = %d\n" 149 " OsakVersion = 0x%x\n"
150 " FormatFlgs = %d\n" 150 " PercentUsed = %d\n",
151 " OsakVersion = 0x%x\n" 151 mh->bootRecordID, mh->NoOfBootImageBlocks,
152 " PercentUsed = %d\n", 152 mh->NoOfBinaryPartitions,
153 mh->bootRecordID, mh->NoOfBootImageBlocks, 153 mh->NoOfBDTLPartitions,
154 mh->NoOfBinaryPartitions, 154 mh->BlockMultiplierBits, mh->FormatFlags,
155 mh->NoOfBDTLPartitions, 155 mh->OsakVersion, mh->PercentUsed);
156 mh->BlockMultiplierBits, mh->FormatFlags,
157 mh->OsakVersion, mh->PercentUsed);
158 }
159#endif
160 156
161 if (mh->NoOfBDTLPartitions == 0) { 157 if (mh->NoOfBDTLPartitions == 0) {
162 printk(KERN_WARNING "INFTL: Media Header sanity check " 158 printk(KERN_WARNING "INFTL: Media Header sanity check "
@@ -200,19 +196,15 @@ static int find_boot_record(struct INFTLrecord *inftl)
200 ip->spareUnits = le32_to_cpu(ip->spareUnits); 196 ip->spareUnits = le32_to_cpu(ip->spareUnits);
201 ip->Reserved0 = le32_to_cpu(ip->Reserved0); 197 ip->Reserved0 = le32_to_cpu(ip->Reserved0);
202 198
203#ifdef CONFIG_MTD_DEBUG_VERBOSE 199 pr_debug(" PARTITION[%d] ->\n"
204 if (CONFIG_MTD_DEBUG_VERBOSE >= 2) { 200 " virtualUnits = %d\n"
205 printk(" PARTITION[%d] ->\n" 201 " firstUnit = %d\n"
206 " virtualUnits = %d\n" 202 " lastUnit = %d\n"
207 " firstUnit = %d\n" 203 " flags = 0x%x\n"
208 " lastUnit = %d\n" 204 " spareUnits = %d\n",
209 " flags = 0x%x\n" 205 i, ip->virtualUnits, ip->firstUnit,
210 " spareUnits = %d\n", 206 ip->lastUnit, ip->flags,
211 i, ip->virtualUnits, ip->firstUnit, 207 ip->spareUnits);
212 ip->lastUnit, ip->flags,
213 ip->spareUnits);
214 }
215#endif
216 208
217 if (ip->Reserved0 != ip->firstUnit) { 209 if (ip->Reserved0 != ip->firstUnit) {
218 struct erase_info *instr = &inftl->instr; 210 struct erase_info *instr = &inftl->instr;
@@ -375,7 +367,7 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
375 * 367 *
376 * Return: 0 when succeed, -1 on error. 368 * Return: 0 when succeed, -1 on error.
377 * 369 *
378 * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? 370 * ToDo: 1. Is it necessary to check_free_sector after erasing ??
379 */ 371 */
380int INFTL_formatblock(struct INFTLrecord *inftl, int block) 372int INFTL_formatblock(struct INFTLrecord *inftl, int block)
381{ 373{
@@ -385,8 +377,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
385 struct mtd_info *mtd = inftl->mbd.mtd; 377 struct mtd_info *mtd = inftl->mbd.mtd;
386 int physblock; 378 int physblock;
387 379
388 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=%p," 380 pr_debug("INFTL: INFTL_formatblock(inftl=%p,block=%d)\n", inftl, block);
389 "block=%d)\n", inftl, block);
390 381
391 memset(instr, 0, sizeof(struct erase_info)); 382 memset(instr, 0, sizeof(struct erase_info));
392 383
@@ -476,30 +467,30 @@ void INFTL_dumptables(struct INFTLrecord *s)
476{ 467{
477 int i; 468 int i;
478 469
479 printk("-------------------------------------------" 470 pr_debug("-------------------------------------------"
480 "----------------------------------\n"); 471 "----------------------------------\n");
481 472
482 printk("VUtable[%d] ->", s->nb_blocks); 473 pr_debug("VUtable[%d] ->", s->nb_blocks);
483 for (i = 0; i < s->nb_blocks; i++) { 474 for (i = 0; i < s->nb_blocks; i++) {
484 if ((i % 8) == 0) 475 if ((i % 8) == 0)
485 printk("\n%04x: ", i); 476 pr_debug("\n%04x: ", i);
486 printk("%04x ", s->VUtable[i]); 477 pr_debug("%04x ", s->VUtable[i]);
487 } 478 }
488 479
489 printk("\n-------------------------------------------" 480 pr_debug("\n-------------------------------------------"
490 "----------------------------------\n"); 481 "----------------------------------\n");
491 482
492 printk("PUtable[%d-%d=%d] ->", s->firstEUN, s->lastEUN, s->nb_blocks); 483 pr_debug("PUtable[%d-%d=%d] ->", s->firstEUN, s->lastEUN, s->nb_blocks);
493 for (i = 0; i <= s->lastEUN; i++) { 484 for (i = 0; i <= s->lastEUN; i++) {
494 if ((i % 8) == 0) 485 if ((i % 8) == 0)
495 printk("\n%04x: ", i); 486 pr_debug("\n%04x: ", i);
496 printk("%04x ", s->PUtable[i]); 487 pr_debug("%04x ", s->PUtable[i]);
497 } 488 }
498 489
499 printk("\n-------------------------------------------" 490 pr_debug("\n-------------------------------------------"
500 "----------------------------------\n"); 491 "----------------------------------\n");
501 492
502 printk("INFTL ->\n" 493 pr_debug("INFTL ->\n"
503 " EraseSize = %d\n" 494 " EraseSize = %d\n"
504 " h/s/c = %d/%d/%d\n" 495 " h/s/c = %d/%d/%d\n"
505 " numvunits = %d\n" 496 " numvunits = %d\n"
@@ -513,7 +504,7 @@ void INFTL_dumptables(struct INFTLrecord *s)
513 s->numvunits, s->firstEUN, s->lastEUN, s->numfreeEUNs, 504 s->numvunits, s->firstEUN, s->lastEUN, s->numfreeEUNs,
514 s->LastFreeEUN, s->nb_blocks, s->nb_boot_blocks); 505 s->LastFreeEUN, s->nb_blocks, s->nb_boot_blocks);
515 506
516 printk("\n-------------------------------------------" 507 pr_debug("\n-------------------------------------------"
517 "----------------------------------\n"); 508 "----------------------------------\n");
518} 509}
519 510
@@ -521,25 +512,25 @@ void INFTL_dumpVUchains(struct INFTLrecord *s)
521{ 512{
522 int logical, block, i; 513 int logical, block, i;
523 514
524 printk("-------------------------------------------" 515 pr_debug("-------------------------------------------"
525 "----------------------------------\n"); 516 "----------------------------------\n");
526 517
527 printk("INFTL Virtual Unit Chains:\n"); 518 pr_debug("INFTL Virtual Unit Chains:\n");
528 for (logical = 0; logical < s->nb_blocks; logical++) { 519 for (logical = 0; logical < s->nb_blocks; logical++) {
529 block = s->VUtable[logical]; 520 block = s->VUtable[logical];
530 if (block > s->nb_blocks) 521 if (block > s->nb_blocks)
531 continue; 522 continue;
532 printk(" LOGICAL %d --> %d ", logical, block); 523 pr_debug(" LOGICAL %d --> %d ", logical, block);
533 for (i = 0; i < s->nb_blocks; i++) { 524 for (i = 0; i < s->nb_blocks; i++) {
534 if (s->PUtable[block] == BLOCK_NIL) 525 if (s->PUtable[block] == BLOCK_NIL)
535 break; 526 break;
536 block = s->PUtable[block]; 527 block = s->PUtable[block];
537 printk("%d ", block); 528 pr_debug("%d ", block);
538 } 529 }
539 printk("\n"); 530 pr_debug("\n");
540 } 531 }
541 532
542 printk("-------------------------------------------" 533 pr_debug("-------------------------------------------"
543 "----------------------------------\n"); 534 "----------------------------------\n");
544} 535}
545 536
@@ -555,7 +546,7 @@ int INFTL_mount(struct INFTLrecord *s)
555 int i; 546 int i;
556 u8 *ANACtable, ANAC; 547 u8 *ANACtable, ANAC;
557 548
558 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_mount(inftl=%p)\n", s); 549 pr_debug("INFTL: INFTL_mount(inftl=%p)\n", s);
559 550
560 /* Search for INFTL MediaHeader and Spare INFTL Media Header */ 551 /* Search for INFTL MediaHeader and Spare INFTL Media Header */
561 if (find_boot_record(s) < 0) { 552 if (find_boot_record(s) < 0) {
@@ -585,7 +576,7 @@ int INFTL_mount(struct INFTLrecord *s)
585 * NOTEXPLORED state. Then at the end we will try to format it and 576 * NOTEXPLORED state. Then at the end we will try to format it and
586 * mark it as free. 577 * mark it as free.
587 */ 578 */
588 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: pass 1, explore each unit\n"); 579 pr_debug("INFTL: pass 1, explore each unit\n");
589 for (first_block = s->firstEUN; first_block <= s->lastEUN; first_block++) { 580 for (first_block = s->firstEUN; first_block <= s->lastEUN; first_block++) {
590 if (s->PUtable[first_block] != BLOCK_NOTEXPLORED) 581 if (s->PUtable[first_block] != BLOCK_NOTEXPLORED)
591 continue; 582 continue;
@@ -717,17 +708,14 @@ int INFTL_mount(struct INFTLrecord *s)
717 logical_block = BLOCK_NIL; 708 logical_block = BLOCK_NIL;
718 } 709 }
719 710
720#ifdef CONFIG_MTD_DEBUG_VERBOSE 711 INFTL_dumptables(s);
721 if (CONFIG_MTD_DEBUG_VERBOSE >= 2)
722 INFTL_dumptables(s);
723#endif
724 712
725 /* 713 /*
726 * Second pass, check for infinite loops in chains. These are 714 * Second pass, check for infinite loops in chains. These are
727 * possible because we don't update the previous pointers when 715 * possible because we don't update the previous pointers when
728 * we fold chains. No big deal, just fix them up in PUtable. 716 * we fold chains. No big deal, just fix them up in PUtable.
729 */ 717 */
730 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: pass 2, validate virtual chains\n"); 718 pr_debug("INFTL: pass 2, validate virtual chains\n");
731 for (logical_block = 0; logical_block < s->numvunits; logical_block++) { 719 for (logical_block = 0; logical_block < s->numvunits; logical_block++) {
732 block = s->VUtable[logical_block]; 720 block = s->VUtable[logical_block];
733 last_block = BLOCK_NIL; 721 last_block = BLOCK_NIL;
@@ -772,12 +760,8 @@ int INFTL_mount(struct INFTLrecord *s)
772 } 760 }
773 } 761 }
774 762
775#ifdef CONFIG_MTD_DEBUG_VERBOSE 763 INFTL_dumptables(s);
776 if (CONFIG_MTD_DEBUG_VERBOSE >= 2) 764 INFTL_dumpVUchains(s);
777 INFTL_dumptables(s);
778 if (CONFIG_MTD_DEBUG_VERBOSE >= 2)
779 INFTL_dumpVUchains(s);
780#endif
781 765
782 /* 766 /*
783 * Third pass, format unreferenced blocks and init free block count. 767 * Third pass, format unreferenced blocks and init free block count.
@@ -785,7 +769,7 @@ int INFTL_mount(struct INFTLrecord *s)
785 s->numfreeEUNs = 0; 769 s->numfreeEUNs = 0;
786 s->LastFreeEUN = BLOCK_NIL; 770 s->LastFreeEUN = BLOCK_NIL;
787 771
788 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: pass 3, format unused blocks\n"); 772 pr_debug("INFTL: pass 3, format unused blocks\n");
789 for (block = s->firstEUN; block <= s->lastEUN; block++) { 773 for (block = s->firstEUN; block <= s->lastEUN; block++) {
790 if (s->PUtable[block] == BLOCK_NOTEXPLORED) { 774 if (s->PUtable[block] == BLOCK_NOTEXPLORED) {
791 printk("INFTL: unreferenced block %d, formatting it\n", 775 printk("INFTL: unreferenced block %d, formatting it\n",
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index 65655dd59e1..1dca31d9a8b 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/Kconfig b/drivers/mtd/maps/Kconfig
index c0c328c5b13..8e0c4bf9f7f 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -41,8 +41,6 @@ config MTD_PHYSMAP_START
41 are mapped on your particular target board. Refer to the 41 are mapped on your particular target board. Refer to the
42 memory map which should hopefully be in the documentation for 42 memory map which should hopefully be in the documentation for
43 your board. 43 your board.
44 Ignore this option if you use run-time physmap configuration
45 (i.e., run-time calling physmap_configure()).
46 44
47config MTD_PHYSMAP_LEN 45config MTD_PHYSMAP_LEN
48 hex "Physical length of flash mapping" 46 hex "Physical length of flash mapping"
@@ -55,8 +53,6 @@ config MTD_PHYSMAP_LEN
55 than the total amount of flash present. Refer to the memory 53 than the total amount of flash present. Refer to the memory
56 map which should hopefully be in the documentation for your 54 map which should hopefully be in the documentation for your
57 board. 55 board.
58 Ignore this option if you use run-time physmap configuration
59 (i.e., run-time calling physmap_configure()).
60 56
61config MTD_PHYSMAP_BANKWIDTH 57config MTD_PHYSMAP_BANKWIDTH
62 int "Bank width in octets" 58 int "Bank width in octets"
@@ -67,8 +63,6 @@ config MTD_PHYSMAP_BANKWIDTH
67 in octets. For example, if you have a data bus width of 32 63 in octets. For example, if you have a data bus width of 32
68 bits, you would set the bus width octet value to 4. This is 64 bits, you would set the bus width octet value to 4. This is
69 used internally by the CFI drivers. 65 used internally by the CFI drivers.
70 Ignore this option if you use run-time physmap configuration
71 (i.e., run-time calling physmap_configure()).
72 66
73config MTD_PHYSMAP_OF 67config MTD_PHYSMAP_OF
74 tristate "Flash device in physical memory map based on OF description" 68 tristate "Flash device in physical memory map based on OF description"
@@ -260,7 +254,6 @@ config MTD_BCM963XX
260config MTD_LANTIQ 254config MTD_LANTIQ
261 tristate "Lantiq SoC NOR support" 255 tristate "Lantiq SoC NOR support"
262 depends on LANTIQ 256 depends on LANTIQ
263 select MTD_PARTITIONS
264 help 257 help
265 Support for NOR flash attached to the Lantiq SoC's External Bus Unit. 258 Support for NOR flash attached to the Lantiq SoC's External Bus Unit.
266 259
@@ -339,10 +332,6 @@ config MTD_SOLUTIONENGINE
339 This enables access to the flash chips on the Hitachi SolutionEngine and 332 This enables access to the flash chips on the Hitachi SolutionEngine and
340 similar boards. Say 'Y' if you are building a kernel for such a board. 333 similar boards. Say 'Y' if you are building a kernel for such a board.
341 334
342config MTD_ARM_INTEGRATOR
343 tristate "CFI Flash device mapped on ARM Integrator/P720T"
344 depends on ARM && MTD_CFI
345
346config MTD_CDB89712 335config MTD_CDB89712
347 tristate "Cirrus CDB89712 evaluation board mappings" 336 tristate "Cirrus CDB89712 evaluation board mappings"
348 depends on MTD_CFI && ARCH_CDB89712 337 depends on MTD_CFI && ARCH_CDB89712
@@ -398,13 +387,6 @@ config MTD_AUTCPU12
398 This enables access to the NV-RAM on autronix autcpu12 board. 387 This enables access to the NV-RAM on autronix autcpu12 board.
399 If you have such a board, say 'Y'. 388 If you have such a board, say 'Y'.
400 389
401config MTD_EDB7312
402 tristate "CFI Flash device mapped on EDB7312"
403 depends on ARCH_EDB7312 && MTD_CFI
404 help
405 This enables access to the CFI Flash on the Cogent EDB7312 board.
406 If you have such a board, say 'Y' here.
407
408config MTD_IMPA7 390config MTD_IMPA7
409 tristate "JEDEC Flash device mapped on impA7" 391 tristate "JEDEC Flash device mapped on impA7"
410 depends on ARM && MTD_JEDECPROBE 392 depends on ARM && MTD_JEDECPROBE
@@ -412,14 +394,6 @@ config MTD_IMPA7
412 This enables access to the NOR Flash on the impA7 board of 394 This enables access to the NOR Flash on the impA7 board of
413 implementa GmbH. If you have such a board, say 'Y' here. 395 implementa GmbH. If you have such a board, say 'Y' here.
414 396
415config MTD_CEIVA
416 tristate "JEDEC Flash device mapped on Ceiva/Polaroid PhotoMax Digital Picture Frame"
417 depends on MTD_JEDECPROBE && ARCH_CEIVA
418 help
419 This enables access to the flash chips on the Ceiva/Polaroid
420 PhotoMax Digital Picture Frame.
421 If you have such a device, say 'Y'.
422
423config MTD_H720X 397config MTD_H720X
424 tristate "Hynix evaluation board mappings" 398 tristate "Hynix evaluation board mappings"
425 depends on MTD_CFI && ( ARCH_H7201 || ARCH_H7202 ) 399 depends on MTD_CFI && ( ARCH_H7201 || ARCH_H7202 )
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index cb48b11afff..45dcb8b14f2 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -19,7 +19,6 @@ obj-$(CONFIG_MTD_CK804XROM) += ck804xrom.o
19obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o 19obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o
20obj-$(CONFIG_MTD_PXA2XX) += pxa2xx-flash.o 20obj-$(CONFIG_MTD_PXA2XX) += pxa2xx-flash.o
21obj-$(CONFIG_MTD_MBX860) += mbx860.o 21obj-$(CONFIG_MTD_MBX860) += mbx860.o
22obj-$(CONFIG_MTD_CEIVA) += ceiva.o
23obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o 22obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o
24obj-$(CONFIG_MTD_PHYSMAP) += physmap.o 23obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
25obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o 24obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o
@@ -40,7 +39,6 @@ obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o
40obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o 39obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
41obj-$(CONFIG_MTD_PCI) += pci.o 40obj-$(CONFIG_MTD_PCI) += pci.o
42obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o 41obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
43obj-$(CONFIG_MTD_EDB7312) += edb7312.o
44obj-$(CONFIG_MTD_IMPA7) += impa7.o 42obj-$(CONFIG_MTD_IMPA7) += impa7.o
45obj-$(CONFIG_MTD_FORTUNET) += fortunet.o 43obj-$(CONFIG_MTD_FORTUNET) += fortunet.o
46obj-$(CONFIG_MTD_UCLINUX) += uclinux.o 44obj-$(CONFIG_MTD_UCLINUX) += uclinux.o
diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c
index 608967fe74c..736ca10ca9f 100644
--- a/drivers/mtd/maps/bcm963xx-flash.c
+++ b/drivers/mtd/maps/bcm963xx-flash.c
@@ -21,6 +21,7 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h>
24#include <linux/mtd/map.h> 25#include <linux/mtd/map.h>
25#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
26#include <linux/mtd/partitions.h> 27#include <linux/mtd/partitions.h>
diff --git a/drivers/mtd/maps/bfin-async-flash.c b/drivers/mtd/maps/bfin-async-flash.c
index 67815eed2f0..6d6b2b5674e 100644
--- a/drivers/mtd/maps/bfin-async-flash.c
+++ b/drivers/mtd/maps/bfin-async-flash.c
@@ -41,7 +41,6 @@ struct async_state {
41 uint32_t flash_ambctl0, flash_ambctl1; 41 uint32_t flash_ambctl0, flash_ambctl1;
42 uint32_t save_ambctl0, save_ambctl1; 42 uint32_t save_ambctl0, save_ambctl1;
43 unsigned long irq_flags; 43 unsigned long irq_flags;
44 struct mtd_partition *parts;
45}; 44};
46 45
47static void switch_to_flash(struct async_state *state) 46static void switch_to_flash(struct async_state *state)
@@ -165,18 +164,8 @@ static int __devinit bfin_flash_probe(struct platform_device *pdev)
165 return -ENXIO; 164 return -ENXIO;
166 } 165 }
167 166
168 ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0); 167 mtd_device_parse_register(state->mtd, part_probe_types, 0,
169 if (ret > 0) { 168 pdata->parts, pdata->nr_parts);
170 pr_devinit(KERN_NOTICE DRIVER_NAME ": Using commandline partition definition\n");
171 mtd_device_register(state->mtd, pdata->parts, ret);
172 state->parts = pdata->parts;
173 } else if (pdata->nr_parts) {
174 pr_devinit(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n");
175 mtd_device_register(state->mtd, pdata->parts, pdata->nr_parts);
176 } else {
177 pr_devinit(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n");
178 mtd_device_register(state->mtd, NULL, 0);
179 }
180 169
181 platform_set_drvdata(pdev, state); 170 platform_set_drvdata(pdev, state);
182 171
@@ -188,7 +177,6 @@ static int __devexit bfin_flash_remove(struct platform_device *pdev)
188 struct async_state *state = platform_get_drvdata(pdev); 177 struct async_state *state = platform_get_drvdata(pdev);
189 gpio_free(state->enet_flash_pin); 178 gpio_free(state->enet_flash_pin);
190 mtd_device_unregister(state->mtd); 179 mtd_device_unregister(state->mtd);
191 kfree(state->parts);
192 map_destroy(state->mtd); 180 map_destroy(state->mtd);
193 kfree(state); 181 kfree(state);
194 return 0; 182 return 0;
diff --git a/drivers/mtd/maps/ceiva.c b/drivers/mtd/maps/ceiva.c
deleted file mode 100644
index 06f9c981572..00000000000
--- a/drivers/mtd/maps/ceiva.c
+++ /dev/null
@@ -1,341 +0,0 @@
1/*
2 * Ceiva flash memory driver.
3 * Copyright (C) 2002 Rob Scott <rscott@mtrob.fdns.net>
4 *
5 * Note: this driver supports jedec compatible devices. Modification
6 * for CFI compatible devices should be straight forward: change
7 * jedec_probe to cfi_probe.
8 *
9 * Based on: sa1100-flash.c, which has the following copyright:
10 * Flash memory access on SA11x0 based devices
11 *
12 * (C) 2000 Nicolas Pitre <nico@fluxnic.net>
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/ioport.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22
23#include <linux/mtd/mtd.h>
24#include <linux/mtd/map.h>
25#include <linux/mtd/partitions.h>
26#include <linux/mtd/concat.h>
27
28#include <mach/hardware.h>
29#include <asm/mach-types.h>
30#include <asm/io.h>
31#include <asm/sizes.h>
32
33/*
34 * This isn't complete yet, so...
35 */
36#define CONFIG_MTD_CEIVA_STATICMAP
37
38#ifdef CONFIG_MTD_CEIVA_STATICMAP
39/*
40 * See include/linux/mtd/partitions.h for definition of the mtd_partition
41 * structure.
42 *
43 * Please note:
44 * 1. The flash size given should be the largest flash size that can
45 * be accommodated.
46 *
47 * 2. The bus width must defined in clps_setup_flash.
48 *
49 * The MTD layer will detect flash chip aliasing and reduce the size of
50 * the map accordingly.
51 *
52 */
53
54#ifdef CONFIG_ARCH_CEIVA
55/* Flash / Partition sizing */
56/* For the 28F8003, we use the block mapping to calcuate the sizes */
57#define MAX_SIZE_KiB (16 + 8 + 8 + 96 + (7*128))
58#define BOOT_PARTITION_SIZE_KiB (16)
59#define PARAMS_PARTITION_SIZE_KiB (8)
60#define KERNEL_PARTITION_SIZE_KiB (4*128)
61/* Use both remaining portion of first flash, and all of second flash */
62#define ROOT_PARTITION_SIZE_KiB (3*128) + (8*128)
63
64static struct mtd_partition ceiva_partitions[] = {
65 {
66 .name = "Ceiva BOOT partition",
67 .size = BOOT_PARTITION_SIZE_KiB*1024,
68 .offset = 0,
69
70 },{
71 .name = "Ceiva parameters partition",
72 .size = PARAMS_PARTITION_SIZE_KiB*1024,
73 .offset = (16 + 8) * 1024,
74 },{
75 .name = "Ceiva kernel partition",
76 .size = (KERNEL_PARTITION_SIZE_KiB)*1024,
77 .offset = 0x20000,
78
79 },{
80 .name = "Ceiva root filesystem partition",
81 .offset = MTDPART_OFS_APPEND,
82 .size = (ROOT_PARTITION_SIZE_KiB)*1024,
83 }
84};
85#endif
86
87static int __init clps_static_partitions(struct mtd_partition **parts)
88{
89 int nb_parts = 0;
90
91#ifdef CONFIG_ARCH_CEIVA
92 if (machine_is_ceiva()) {
93 *parts = ceiva_partitions;
94 nb_parts = ARRAY_SIZE(ceiva_partitions);
95 }
96#endif
97 return nb_parts;
98}
99#endif
100
101struct clps_info {
102 unsigned long base;
103 unsigned long size;
104 int width;
105 void *vbase;
106 struct map_info *map;
107 struct mtd_info *mtd;
108 struct resource *res;
109};
110
111#define NR_SUBMTD 4
112
113static struct clps_info info[NR_SUBMTD];
114
115static int __init clps_setup_mtd(struct clps_info *clps, int nr, struct mtd_info **rmtd)
116{
117 struct mtd_info *subdev[nr];
118 struct map_info *maps;
119 int i, found = 0, ret = 0;
120
121 /*
122 * Allocate the map_info structs in one go.
123 */
124 maps = kzalloc(sizeof(struct map_info) * nr, GFP_KERNEL);
125 if (!maps)
126 return -ENOMEM;
127 /*
128 * Claim and then map the memory regions.
129 */
130 for (i = 0; i < nr; i++) {
131 if (clps[i].base == (unsigned long)-1)
132 break;
133
134 clps[i].res = request_mem_region(clps[i].base, clps[i].size, "clps flash");
135 if (!clps[i].res) {
136 ret = -EBUSY;
137 break;
138 }
139
140 clps[i].map = maps + i;
141
142 clps[i].map->name = "clps flash";
143 clps[i].map->phys = clps[i].base;
144
145 clps[i].vbase = ioremap(clps[i].base, clps[i].size);
146 if (!clps[i].vbase) {
147 ret = -ENOMEM;
148 break;
149 }
150
151 clps[i].map->virt = (void __iomem *)clps[i].vbase;
152 clps[i].map->bankwidth = clps[i].width;
153 clps[i].map->size = clps[i].size;
154
155 simple_map_init(&clps[i].map);
156
157 clps[i].mtd = do_map_probe("jedec_probe", clps[i].map);
158 if (clps[i].mtd == NULL) {
159 ret = -ENXIO;
160 break;
161 }
162 clps[i].mtd->owner = THIS_MODULE;
163 subdev[i] = clps[i].mtd;
164
165 printk(KERN_INFO "clps flash: JEDEC device at 0x%08lx, %dMiB, "
166 "%d-bit\n", clps[i].base, clps[i].mtd->size >> 20,
167 clps[i].width * 8);
168 found += 1;
169 }
170
171 /*
172 * ENXIO is special. It means we didn't find a chip when
173 * we probed. We need to tear down the mapping, free the
174 * resource and mark it as such.
175 */
176 if (ret == -ENXIO) {
177 iounmap(clps[i].vbase);
178 clps[i].vbase = NULL;
179 release_resource(clps[i].res);
180 clps[i].res = NULL;
181 }
182
183 /*
184 * If we found one device, don't bother with concat support.
185 * If we found multiple devices, use concat if we have it
186 * available, otherwise fail.
187 */
188 if (ret == 0 || ret == -ENXIO) {
189 if (found == 1) {
190 *rmtd = subdev[0];
191 ret = 0;
192 } else if (found > 1) {
193 /*
194 * We detected multiple devices. Concatenate
195 * them together.
196 */
197 *rmtd = mtd_concat_create(subdev, found,
198 "clps flash");
199 if (*rmtd == NULL)
200 ret = -ENXIO;
201 }
202 }
203
204 /*
205 * If we failed, clean up.
206 */
207 if (ret) {
208 do {
209 if (clps[i].mtd)
210 map_destroy(clps[i].mtd);
211 if (clps[i].vbase)
212 iounmap(clps[i].vbase);
213 if (clps[i].res)
214 release_resource(clps[i].res);
215 } while (i--);
216
217 kfree(maps);
218 }
219
220 return ret;
221}
222
223static void __exit clps_destroy_mtd(struct clps_info *clps, struct mtd_info *mtd)
224{
225 int i;
226
227 mtd_device_unregister(mtd);
228
229 if (mtd != clps[0].mtd)
230 mtd_concat_destroy(mtd);
231
232 for (i = NR_SUBMTD; i >= 0; i--) {
233 if (clps[i].mtd)
234 map_destroy(clps[i].mtd);
235 if (clps[i].vbase)
236 iounmap(clps[i].vbase);
237 if (clps[i].res)
238 release_resource(clps[i].res);
239 }
240 kfree(clps[0].map);
241}
242
243/*
244 * We define the memory space, size, and width for the flash memory
245 * space here.
246 */
247
248static int __init clps_setup_flash(void)
249{
250 int nr = 0;
251
252#ifdef CONFIG_ARCH_CEIVA
253 if (machine_is_ceiva()) {
254 info[0].base = CS0_PHYS_BASE;
255 info[0].size = SZ_32M;
256 info[0].width = CEIVA_FLASH_WIDTH;
257 info[1].base = CS1_PHYS_BASE;
258 info[1].size = SZ_32M;
259 info[1].width = CEIVA_FLASH_WIDTH;
260 nr = 2;
261 }
262#endif
263 return nr;
264}
265
266static struct mtd_partition *parsed_parts;
267static const char *probes[] = { "cmdlinepart", "RedBoot", NULL };
268
269static void __init clps_locate_partitions(struct mtd_info *mtd)
270{
271 const char *part_type = NULL;
272 int nr_parts = 0;
273 do {
274 /*
275 * Partition selection stuff.
276 */
277 nr_parts = parse_mtd_partitions(mtd, probes, &parsed_parts, 0);
278 if (nr_parts > 0) {
279 part_type = "command line";
280 break;
281 }
282#ifdef CONFIG_MTD_CEIVA_STATICMAP
283 nr_parts = clps_static_partitions(&parsed_parts);
284 if (nr_parts > 0) {
285 part_type = "static";
286 break;
287 }
288 printk("found: %d partitions\n", nr_parts);
289#endif
290 } while (0);
291
292 if (nr_parts == 0) {
293 printk(KERN_NOTICE "clps flash: no partition info "
294 "available, registering whole flash\n");
295 mtd_device_register(mtd, NULL, 0);
296 } else {
297 printk(KERN_NOTICE "clps flash: using %s partition "
298 "definition\n", part_type);
299 mtd_device_register(mtd, parsed_parts, nr_parts);
300 }
301
302 /* Always succeeds. */
303}
304
305static void __exit clps_destroy_partitions(void)
306{
307 kfree(parsed_parts);
308}
309
310static struct mtd_info *mymtd;
311
312static int __init clps_mtd_init(void)
313{
314 int ret;
315 int nr;
316
317 nr = clps_setup_flash();
318 if (nr < 0)
319 return nr;
320
321 ret = clps_setup_mtd(info, nr, &mymtd);
322 if (ret)
323 return ret;
324
325 clps_locate_partitions(mymtd);
326
327 return 0;
328}
329
330static void __exit clps_mtd_cleanup(void)
331{
332 clps_destroy_mtd(info, mymtd);
333 clps_destroy_partitions();
334}
335
336module_init(clps_mtd_init);
337module_exit(clps_mtd_cleanup);
338
339MODULE_AUTHOR("Rob Scott");
340MODULE_DESCRIPTION("Cirrus Logic JEDEC map driver");
341MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/dc21285.c b/drivers/mtd/maps/dc21285.c
index 7a9e1989c97..f43b365b848 100644
--- a/drivers/mtd/maps/dc21285.c
+++ b/drivers/mtd/maps/dc21285.c
@@ -145,14 +145,10 @@ static struct map_info dc21285_map = {
145 145
146 146
147/* Partition stuff */ 147/* Partition stuff */
148static struct mtd_partition *dc21285_parts;
149static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 148static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
150 149
151static int __init init_dc21285(void) 150static int __init init_dc21285(void)
152{ 151{
153
154 int nrparts;
155
156 /* Determine bankwidth */ 152 /* Determine bankwidth */
157 switch (*CSR_SA110_CNTL & (3<<14)) { 153 switch (*CSR_SA110_CNTL & (3<<14)) {
158 case SA110_CNTL_ROMWIDTH_8: 154 case SA110_CNTL_ROMWIDTH_8:
@@ -200,8 +196,7 @@ static int __init init_dc21285(void)
200 196
201 dc21285_mtd->owner = THIS_MODULE; 197 dc21285_mtd->owner = THIS_MODULE;
202 198
203 nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0); 199 mtd_device_parse_register(dc21285_mtd, probes, 0, NULL, 0);
204 mtd_device_register(dc21285_mtd, dc21285_parts, nrparts);
205 200
206 if(machine_is_ebsa285()) { 201 if(machine_is_ebsa285()) {
207 /* 202 /*
@@ -224,8 +219,6 @@ static int __init init_dc21285(void)
224static void __exit cleanup_dc21285(void) 219static void __exit cleanup_dc21285(void)
225{ 220{
226 mtd_device_unregister(dc21285_mtd); 221 mtd_device_unregister(dc21285_mtd);
227 if (dc21285_parts)
228 kfree(dc21285_parts);
229 map_destroy(dc21285_mtd); 222 map_destroy(dc21285_mtd);
230 iounmap(dc21285_map.virt); 223 iounmap(dc21285_map.virt);
231} 224}
diff --git a/drivers/mtd/maps/edb7312.c b/drivers/mtd/maps/edb7312.c
deleted file mode 100644
index fe42a212bb3..00000000000
--- a/drivers/mtd/maps/edb7312.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/*
2 * Handle mapping of the NOR flash on Cogent EDB7312 boards
3 *
4 * Copyright 2002 SYSGO Real-Time Solutions GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <asm/io.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h>
18#include <linux/mtd/partitions.h>
19
20#define WINDOW_ADDR 0x00000000 /* physical properties of flash */
21#define WINDOW_SIZE 0x01000000
22#define BUSWIDTH 2
23#define FLASH_BLOCKSIZE_MAIN 0x20000
24#define FLASH_NUMBLOCKS_MAIN 128
25/* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
26#define PROBETYPES { "cfi_probe", NULL }
27
28#define MSG_PREFIX "EDB7312-NOR:" /* prefix for our printk()'s */
29#define MTDID "edb7312-nor" /* for mtdparts= partitioning */
30
31static struct mtd_info *mymtd;
32
33struct map_info edb7312nor_map = {
34 .name = "NOR flash on EDB7312",
35 .size = WINDOW_SIZE,
36 .bankwidth = BUSWIDTH,
37 .phys = WINDOW_ADDR,
38};
39
40/*
41 * MTD partitioning stuff
42 */
43static struct mtd_partition static_partitions[3] =
44{
45 {
46 .name = "ARMboot",
47 .size = 0x40000,
48 .offset = 0
49 },
50 {
51 .name = "Kernel",
52 .size = 0x200000,
53 .offset = 0x40000
54 },
55 {
56 .name = "RootFS",
57 .size = 0xDC0000,
58 .offset = 0x240000
59 },
60};
61
62static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
63
64static int mtd_parts_nb = 0;
65static struct mtd_partition *mtd_parts = 0;
66
67static int __init init_edb7312nor(void)
68{
69 static const char *rom_probe_types[] = PROBETYPES;
70 const char **type;
71 const char *part_type = 0;
72
73 printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",
74 WINDOW_SIZE, WINDOW_ADDR);
75 edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
76
77 if (!edb7312nor_map.virt) {
78 printk(MSG_PREFIX "failed to ioremap\n");
79 return -EIO;
80 }
81
82 simple_map_init(&edb7312nor_map);
83
84 mymtd = 0;
85 type = rom_probe_types;
86 for(; !mymtd && *type; type++) {
87 mymtd = do_map_probe(*type, &edb7312nor_map);
88 }
89 if (mymtd) {
90 mymtd->owner = THIS_MODULE;
91
92 mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
93 if (mtd_parts_nb > 0)
94 part_type = "detected";
95
96 if (mtd_parts_nb == 0) {
97 mtd_parts = static_partitions;
98 mtd_parts_nb = ARRAY_SIZE(static_partitions);
99 part_type = "static";
100 }
101
102 if (mtd_parts_nb == 0)
103 printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
104 else
105 printk(KERN_NOTICE MSG_PREFIX
106 "using %s partition definition\n", part_type);
107 /* Register the whole device first. */
108 mtd_device_register(mymtd, NULL, 0);
109 mtd_device_register(mymtd, mtd_parts, mtd_parts_nb);
110 return 0;
111 }
112
113 iounmap((void *)edb7312nor_map.virt);
114 return -ENXIO;
115}
116
117static void __exit cleanup_edb7312nor(void)
118{
119 if (mymtd) {
120 mtd_device_unregister(mymtd);
121 map_destroy(mymtd);
122 }
123 if (edb7312nor_map.virt) {
124 iounmap((void *)edb7312nor_map.virt);
125 edb7312nor_map.virt = 0;
126 }
127}
128
129module_init(init_edb7312nor);
130module_exit(cleanup_edb7312nor);
131
132MODULE_LICENSE("GPL");
133MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
134MODULE_DESCRIPTION("Generic configurable MTD map driver");
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
index 7568c5f8b8a..1ec66f031c5 100644
--- a/drivers/mtd/maps/gpio-addr-flash.c
+++ b/drivers/mtd/maps/gpio-addr-flash.c
@@ -187,7 +187,6 @@ static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
187 */ 187 */
188static int __devinit gpio_flash_probe(struct platform_device *pdev) 188static int __devinit gpio_flash_probe(struct platform_device *pdev)
189{ 189{
190 int nr_parts;
191 size_t i, arr_size; 190 size_t i, arr_size;
192 struct physmap_flash_data *pdata; 191 struct physmap_flash_data *pdata;
193 struct resource *memory; 192 struct resource *memory;
@@ -252,20 +251,9 @@ static int __devinit gpio_flash_probe(struct platform_device *pdev)
252 return -ENXIO; 251 return -ENXIO;
253 } 252 }
254 253
255 nr_parts = parse_mtd_partitions(state->mtd, part_probe_types,
256 &pdata->parts, 0);
257 if (nr_parts > 0) {
258 pr_devinit(KERN_NOTICE PFX "Using commandline partition definition\n");
259 kfree(pdata->parts);
260 } else if (pdata->nr_parts) {
261 pr_devinit(KERN_NOTICE PFX "Using board partition definition\n");
262 nr_parts = pdata->nr_parts;
263 } else {
264 pr_devinit(KERN_NOTICE PFX "no partition info available, registering whole flash at once\n");
265 nr_parts = 0;
266 }
267 254
268 mtd_device_register(state->mtd, pdata->parts, nr_parts); 255 mtd_device_parse_register(state->mtd, part_probe_types, 0,
256 pdata->parts, pdata->nr_parts);
269 257
270 return 0; 258 return 0;
271} 259}
diff --git a/drivers/mtd/maps/h720x-flash.c b/drivers/mtd/maps/h720x-flash.c
index 7f035860a36..49c14187fc6 100644
--- a/drivers/mtd/maps/h720x-flash.c
+++ b/drivers/mtd/maps/h720x-flash.c
@@ -58,18 +58,11 @@ static struct mtd_partition h720x_partitions[] = {
58 58
59#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions) 59#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)
60 60
61static int nr_mtd_parts;
62static struct mtd_partition *mtd_parts;
63static const char *probes[] = { "cmdlinepart", NULL };
64
65/* 61/*
66 * Initialize FLASH support 62 * Initialize FLASH support
67 */ 63 */
68static int __init h720x_mtd_init(void) 64static int __init h720x_mtd_init(void)
69{ 65{
70
71 char *part_type = NULL;
72
73 h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size); 66 h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size);
74 67
75 if (!h720x_map.virt) { 68 if (!h720x_map.virt) {
@@ -92,16 +85,8 @@ static int __init h720x_mtd_init(void)
92 if (mymtd) { 85 if (mymtd) {
93 mymtd->owner = THIS_MODULE; 86 mymtd->owner = THIS_MODULE;
94 87
95 nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0); 88 mtd_device_parse_register(mymtd, NULL, 0,
96 if (nr_mtd_parts > 0) 89 h720x_partitions, NUM_PARTITIONS);
97 part_type = "command line";
98 if (nr_mtd_parts <= 0) {
99 mtd_parts = h720x_partitions;
100 nr_mtd_parts = NUM_PARTITIONS;
101 part_type = "builtin";
102 }
103 printk(KERN_INFO "Using %s partition table\n", part_type);
104 mtd_device_register(mymtd, mtd_parts, nr_mtd_parts);
105 return 0; 90 return 0;
106 } 91 }
107 92
@@ -120,10 +105,6 @@ static void __exit h720x_mtd_cleanup(void)
120 map_destroy(mymtd); 105 map_destroy(mymtd);
121 } 106 }
122 107
123 /* Free partition info, if commandline partition was used */
124 if (mtd_parts && (mtd_parts != h720x_partitions))
125 kfree (mtd_parts);
126
127 if (h720x_map.virt) { 108 if (h720x_map.virt) {
128 iounmap((void *)h720x_map.virt); 109 iounmap((void *)h720x_map.virt);
129 h720x_map.virt = 0; 110 h720x_map.virt = 0;
diff --git a/drivers/mtd/maps/impa7.c b/drivers/mtd/maps/impa7.c
index 404a50cbafa..f47aedb2436 100644
--- a/drivers/mtd/maps/impa7.c
+++ b/drivers/mtd/maps/impa7.c
@@ -49,7 +49,7 @@ static struct map_info impa7_map[NUM_FLASHBANKS] = {
49/* 49/*
50 * MTD partitioning stuff 50 * MTD partitioning stuff
51 */ 51 */
52static struct mtd_partition static_partitions[] = 52static struct mtd_partition partitions[] =
53{ 53{
54 { 54 {
55 .name = "FileSystem", 55 .name = "FileSystem",
@@ -58,16 +58,10 @@ static struct mtd_partition static_partitions[] =
58 }, 58 },
59}; 59};
60 60
61static int mtd_parts_nb[NUM_FLASHBANKS];
62static struct mtd_partition *mtd_parts[NUM_FLASHBANKS];
63
64static const char *probes[] = { "cmdlinepart", NULL };
65
66static int __init init_impa7(void) 61static int __init init_impa7(void)
67{ 62{
68 static const char *rom_probe_types[] = PROBETYPES; 63 static const char *rom_probe_types[] = PROBETYPES;
69 const char **type; 64 const char **type;
70 const char *part_type = 0;
71 int i; 65 int i;
72 static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = { 66 static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
73 { WINDOW_ADDR0, WINDOW_SIZE0 }, 67 { WINDOW_ADDR0, WINDOW_SIZE0 },
@@ -97,23 +91,9 @@ static int __init init_impa7(void)
97 if (impa7_mtd[i]) { 91 if (impa7_mtd[i]) {
98 impa7_mtd[i]->owner = THIS_MODULE; 92 impa7_mtd[i]->owner = THIS_MODULE;
99 devicesfound++; 93 devicesfound++;
100 mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i], 94 mtd_device_parse_register(impa7_mtd[i], NULL, 0,
101 probes, 95 partitions,
102 &mtd_parts[i], 96 ARRAY_SIZE(partitions));
103 0);
104 if (mtd_parts_nb[i] > 0) {
105 part_type = "command line";
106 } else {
107 mtd_parts[i] = static_partitions;
108 mtd_parts_nb[i] = ARRAY_SIZE(static_partitions);
109 part_type = "static";
110 }
111
112 printk(KERN_NOTICE MSG_PREFIX
113 "using %s partition definition\n",
114 part_type);
115 mtd_device_register(impa7_mtd[i],
116 mtd_parts[i], mtd_parts_nb[i]);
117 } 97 }
118 else 98 else
119 iounmap((void *)impa7_map[i].virt); 99 iounmap((void *)impa7_map[i].virt);
diff --git a/drivers/mtd/maps/intel_vr_nor.c b/drivers/mtd/maps/intel_vr_nor.c
index d2f47be8754..08c239604ee 100644
--- a/drivers/mtd/maps/intel_vr_nor.c
+++ b/drivers/mtd/maps/intel_vr_nor.c
@@ -44,7 +44,6 @@ struct vr_nor_mtd {
44 void __iomem *csr_base; 44 void __iomem *csr_base;
45 struct map_info map; 45 struct map_info map;
46 struct mtd_info *info; 46 struct mtd_info *info;
47 int nr_parts;
48 struct pci_dev *dev; 47 struct pci_dev *dev;
49}; 48};
50 49
@@ -71,13 +70,9 @@ static void __devexit vr_nor_destroy_partitions(struct vr_nor_mtd *p)
71 70
72static int __devinit vr_nor_init_partitions(struct vr_nor_mtd *p) 71static int __devinit vr_nor_init_partitions(struct vr_nor_mtd *p)
73{ 72{
74 struct mtd_partition *parts;
75 static const char *part_probes[] = { "cmdlinepart", NULL };
76
77 /* register the flash bank */ 73 /* register the flash bank */
78 /* partition the flash bank */ 74 /* partition the flash bank */
79 p->nr_parts = parse_mtd_partitions(p->info, part_probes, &parts, 0); 75 return mtd_device_parse_register(p->info, NULL, 0, NULL, 0);
80 return mtd_device_register(p->info, parts, p->nr_parts);
81} 76}
82 77
83static void __devexit vr_nor_destroy_mtd_setup(struct vr_nor_mtd *p) 78static void __devexit vr_nor_destroy_mtd_setup(struct vr_nor_mtd *p)
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index 1594a802631..437fcd2f352 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -38,7 +38,6 @@
38struct ixp2000_flash_info { 38struct ixp2000_flash_info {
39 struct mtd_info *mtd; 39 struct mtd_info *mtd;
40 struct map_info map; 40 struct map_info map;
41 struct mtd_partition *partitions;
42 struct resource *res; 41 struct resource *res;
43}; 42};
44 43
@@ -125,8 +124,6 @@ static int ixp2000_flash_remove(struct platform_device *dev)
125 if (info->map.map_priv_1) 124 if (info->map.map_priv_1)
126 iounmap((void *) info->map.map_priv_1); 125 iounmap((void *) info->map.map_priv_1);
127 126
128 kfree(info->partitions);
129
130 if (info->res) { 127 if (info->res) {
131 release_resource(info->res); 128 release_resource(info->res);
132 kfree(info->res); 129 kfree(info->res);
@@ -229,13 +226,7 @@ static int ixp2000_flash_probe(struct platform_device *dev)
229 } 226 }
230 info->mtd->owner = THIS_MODULE; 227 info->mtd->owner = THIS_MODULE;
231 228
232 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0); 229 err = mtd_device_parse_register(info->mtd, probes, 0, NULL, 0);
233 if (err > 0) {
234 err = mtd_device_register(info->mtd, info->partitions, err);
235 if(err)
236 dev_err(&dev->dev, "Could not parse partitions\n");
237 }
238
239 if (err) 230 if (err)
240 goto Error; 231 goto Error;
241 232
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index 155b21942f4..30409015a3d 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -145,7 +145,6 @@ static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
145struct ixp4xx_flash_info { 145struct ixp4xx_flash_info {
146 struct mtd_info *mtd; 146 struct mtd_info *mtd;
147 struct map_info map; 147 struct map_info map;
148 struct mtd_partition *partitions;
149 struct resource *res; 148 struct resource *res;
150}; 149};
151 150
@@ -168,8 +167,6 @@ static int ixp4xx_flash_remove(struct platform_device *dev)
168 if (info->map.virt) 167 if (info->map.virt)
169 iounmap(info->map.virt); 168 iounmap(info->map.virt);
170 169
171 kfree(info->partitions);
172
173 if (info->res) { 170 if (info->res) {
174 release_resource(info->res); 171 release_resource(info->res);
175 kfree(info->res); 172 kfree(info->res);
@@ -185,8 +182,6 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
185{ 182{
186 struct flash_platform_data *plat = dev->dev.platform_data; 183 struct flash_platform_data *plat = dev->dev.platform_data;
187 struct ixp4xx_flash_info *info; 184 struct ixp4xx_flash_info *info;
188 const char *part_type = NULL;
189 int nr_parts = 0;
190 int err = -1; 185 int err = -1;
191 186
192 if (!plat) 187 if (!plat)
@@ -252,28 +247,12 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
252 /* Use the fast version */ 247 /* Use the fast version */
253 info->map.write = ixp4xx_write16; 248 info->map.write = ixp4xx_write16;
254 249
255 nr_parts = parse_mtd_partitions(info->mtd, probes, &info->partitions, 250 err = mtd_device_parse_register(info->mtd, probes, dev->resource->start,
256 dev->resource->start); 251 plat->parts, plat->nr_parts);
257 if (nr_parts > 0) { 252 if (err) {
258 part_type = "dynamic";
259 } else {
260 info->partitions = plat->parts;
261 nr_parts = plat->nr_parts;
262 part_type = "static";
263 }
264 if (nr_parts == 0)
265 printk(KERN_NOTICE "IXP4xx flash: no partition info "
266 "available, registering whole flash\n");
267 else
268 printk(KERN_NOTICE "IXP4xx flash: using %s partition "
269 "definition\n", part_type);
270
271 err = mtd_device_register(info->mtd, info->partitions, nr_parts);
272 if (err)
273 printk(KERN_ERR "Could not parse partitions\n"); 253 printk(KERN_ERR "Could not parse partitions\n");
274
275 if (err)
276 goto Error; 254 goto Error;
255 }
277 256
278 return 0; 257 return 0;
279 258
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index a90cabd7b84..4f10e27ada5 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -107,16 +107,12 @@ ltq_copy_to(struct map_info *map, unsigned long to,
107 spin_unlock_irqrestore(&ebu_lock, flags); 107 spin_unlock_irqrestore(&ebu_lock, flags);
108} 108}
109 109
110static const char const *part_probe_types[] = { "cmdlinepart", NULL };
111
112static int __init 110static int __init
113ltq_mtd_probe(struct platform_device *pdev) 111ltq_mtd_probe(struct platform_device *pdev)
114{ 112{
115 struct physmap_flash_data *ltq_mtd_data = dev_get_platdata(&pdev->dev); 113 struct physmap_flash_data *ltq_mtd_data = dev_get_platdata(&pdev->dev);
116 struct ltq_mtd *ltq_mtd; 114 struct ltq_mtd *ltq_mtd;
117 struct mtd_partition *parts;
118 struct resource *res; 115 struct resource *res;
119 int nr_parts = 0;
120 struct cfi_private *cfi; 116 struct cfi_private *cfi;
121 int err; 117 int err;
122 118
@@ -172,17 +168,8 @@ ltq_mtd_probe(struct platform_device *pdev)
172 cfi->addr_unlock1 ^= 1; 168 cfi->addr_unlock1 ^= 1;
173 cfi->addr_unlock2 ^= 1; 169 cfi->addr_unlock2 ^= 1;
174 170
175 nr_parts = parse_mtd_partitions(ltq_mtd->mtd, 171 err = mtd_device_parse_register(ltq_mtd->mtd, NULL, 0,
176 part_probe_types, &parts, 0); 172 ltq_mtd_data->parts, ltq_mtd_data->nr_parts);
177 if (nr_parts > 0) {
178 dev_info(&pdev->dev,
179 "using %d partitions from cmdline", nr_parts);
180 } else {
181 nr_parts = ltq_mtd_data->nr_parts;
182 parts = ltq_mtd_data->parts;
183 }
184
185 err = add_mtd_partitions(ltq_mtd->mtd, parts, nr_parts);
186 if (err) { 173 if (err) {
187 dev_err(&pdev->dev, "failed to add partitions\n"); 174 dev_err(&pdev->dev, "failed to add partitions\n");
188 goto err_destroy; 175 goto err_destroy;
@@ -208,7 +195,7 @@ ltq_mtd_remove(struct platform_device *pdev)
208 195
209 if (ltq_mtd) { 196 if (ltq_mtd) {
210 if (ltq_mtd->mtd) { 197 if (ltq_mtd->mtd) {
211 del_mtd_partitions(ltq_mtd->mtd); 198 mtd_device_unregister(ltq_mtd->mtd);
212 map_destroy(ltq_mtd->mtd); 199 map_destroy(ltq_mtd->mtd);
213 } 200 }
214 if (ltq_mtd->map->virt) 201 if (ltq_mtd->map->virt)
diff --git a/drivers/mtd/maps/latch-addr-flash.c b/drivers/mtd/maps/latch-addr-flash.c
index 5936c466e90..119baa7d747 100644
--- a/drivers/mtd/maps/latch-addr-flash.c
+++ b/drivers/mtd/maps/latch-addr-flash.c
@@ -33,9 +33,6 @@ struct latch_addr_flash_info {
33 /* cache; could be found out of res */ 33 /* cache; could be found out of res */
34 unsigned long win_mask; 34 unsigned long win_mask;
35 35
36 int nr_parts;
37 struct mtd_partition *parts;
38
39 spinlock_t lock; 36 spinlock_t lock;
40}; 37};
41 38
@@ -97,8 +94,6 @@ static void lf_copy_from(struct map_info *map, void *to,
97 94
98static char *rom_probe_types[] = { "cfi_probe", NULL }; 95static char *rom_probe_types[] = { "cfi_probe", NULL };
99 96
100static char *part_probe_types[] = { "cmdlinepart", NULL };
101
102static int latch_addr_flash_remove(struct platform_device *dev) 97static int latch_addr_flash_remove(struct platform_device *dev)
103{ 98{
104 struct latch_addr_flash_info *info; 99 struct latch_addr_flash_info *info;
@@ -112,8 +107,6 @@ static int latch_addr_flash_remove(struct platform_device *dev)
112 latch_addr_data = dev->dev.platform_data; 107 latch_addr_data = dev->dev.platform_data;
113 108
114 if (info->mtd != NULL) { 109 if (info->mtd != NULL) {
115 if (info->nr_parts)
116 kfree(info->parts);
117 mtd_device_unregister(info->mtd); 110 mtd_device_unregister(info->mtd);
118 map_destroy(info->mtd); 111 map_destroy(info->mtd);
119 } 112 }
@@ -206,21 +199,8 @@ static int __devinit latch_addr_flash_probe(struct platform_device *dev)
206 } 199 }
207 info->mtd->owner = THIS_MODULE; 200 info->mtd->owner = THIS_MODULE;
208 201
209 err = parse_mtd_partitions(info->mtd, (const char **)part_probe_types, 202 mtd_device_parse_register(info->mtd, NULL, 0,
210 &info->parts, 0); 203 latch_addr_data->parts, latch_addr_data->nr_parts);
211 if (err > 0) {
212 mtd_device_register(info->mtd, info->parts, err);
213 return 0;
214 }
215 if (latch_addr_data->nr_parts) {
216 pr_notice("Using latch-addr-flash partition information\n");
217 mtd_device_register(info->mtd,
218 latch_addr_data->parts,
219 latch_addr_data->nr_parts);
220 return 0;
221 }
222
223 mtd_device_register(info->mtd, NULL, 0);
224 return 0; 204 return 0;
225 205
226iounmap: 206iounmap:
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index bbe168b65c2..e8e9fec2355 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -22,22 +22,6 @@
22#include <linux/mtd/map.h> 22#include <linux/mtd/map.h>
23#include <linux/mtd/mtd.h> 23#include <linux/mtd/mtd.h>
24 24
25#ifdef CONFIG_MTD_DEBUG
26static int debug = CONFIG_MTD_DEBUG_VERBOSE;
27module_param(debug, int, 0);
28MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
29#undef DEBUG
30#define DEBUG(n, format, arg...) \
31 if (n <= debug) { \
32 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
33 }
34
35#else
36#undef DEBUG
37#define DEBUG(n, arg...)
38static const int debug = 0;
39#endif
40
41#define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg) 25#define info(format, arg...) printk(KERN_INFO "pcmciamtd: " format "\n" , ## arg)
42 26
43#define DRIVER_DESC "PCMCIA Flash memory card driver" 27#define DRIVER_DESC "PCMCIA Flash memory card driver"
@@ -105,13 +89,13 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
105 int ret; 89 int ret;
106 90
107 if (!pcmcia_dev_present(dev->p_dev)) { 91 if (!pcmcia_dev_present(dev->p_dev)) {
108 DEBUG(1, "device removed"); 92 pr_debug("device removed\n");
109 return 0; 93 return 0;
110 } 94 }
111 95
112 offset = to & ~(dev->win_size-1); 96 offset = to & ~(dev->win_size-1);
113 if (offset != dev->offset) { 97 if (offset != dev->offset) {
114 DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x", 98 pr_debug("Remapping window from 0x%8.8x to 0x%8.8x\n",
115 dev->offset, offset); 99 dev->offset, offset);
116 ret = pcmcia_map_mem_page(dev->p_dev, win, offset); 100 ret = pcmcia_map_mem_page(dev->p_dev, win, offset);
117 if (ret != 0) 101 if (ret != 0)
@@ -132,7 +116,7 @@ static map_word pcmcia_read8_remap(struct map_info *map, unsigned long ofs)
132 return d; 116 return d;
133 117
134 d.x[0] = readb(addr); 118 d.x[0] = readb(addr);
135 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02lx", ofs, addr, d.x[0]); 119 pr_debug("ofs = 0x%08lx (%p) data = 0x%02lx\n", ofs, addr, d.x[0]);
136 return d; 120 return d;
137} 121}
138 122
@@ -147,7 +131,7 @@ static map_word pcmcia_read16_remap(struct map_info *map, unsigned long ofs)
147 return d; 131 return d;
148 132
149 d.x[0] = readw(addr); 133 d.x[0] = readw(addr);
150 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04lx", ofs, addr, d.x[0]); 134 pr_debug("ofs = 0x%08lx (%p) data = 0x%04lx\n", ofs, addr, d.x[0]);
151 return d; 135 return d;
152} 136}
153 137
@@ -157,7 +141,7 @@ static void pcmcia_copy_from_remap(struct map_info *map, void *to, unsigned long
157 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 141 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
158 unsigned long win_size = dev->win_size; 142 unsigned long win_size = dev->win_size;
159 143
160 DEBUG(3, "to = %p from = %lu len = %zd", to, from, len); 144 pr_debug("to = %p from = %lu len = %zd\n", to, from, len);
161 while(len) { 145 while(len) {
162 int toread = win_size - (from & (win_size-1)); 146 int toread = win_size - (from & (win_size-1));
163 caddr_t addr; 147 caddr_t addr;
@@ -169,7 +153,7 @@ static void pcmcia_copy_from_remap(struct map_info *map, void *to, unsigned long
169 if(!addr) 153 if(!addr)
170 return; 154 return;
171 155
172 DEBUG(4, "memcpy from %p to %p len = %d", addr, to, toread); 156 pr_debug("memcpy from %p to %p len = %d\n", addr, to, toread);
173 memcpy_fromio(to, addr, toread); 157 memcpy_fromio(to, addr, toread);
174 len -= toread; 158 len -= toread;
175 to += toread; 159 to += toread;
@@ -185,7 +169,7 @@ static void pcmcia_write8_remap(struct map_info *map, map_word d, unsigned long
185 if(!addr) 169 if(!addr)
186 return; 170 return;
187 171
188 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02lx", adr, addr, d.x[0]); 172 pr_debug("adr = 0x%08lx (%p) data = 0x%02lx\n", adr, addr, d.x[0]);
189 writeb(d.x[0], addr); 173 writeb(d.x[0], addr);
190} 174}
191 175
@@ -196,7 +180,7 @@ static void pcmcia_write16_remap(struct map_info *map, map_word d, unsigned long
196 if(!addr) 180 if(!addr)
197 return; 181 return;
198 182
199 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04lx", adr, addr, d.x[0]); 183 pr_debug("adr = 0x%08lx (%p) data = 0x%04lx\n", adr, addr, d.x[0]);
200 writew(d.x[0], addr); 184 writew(d.x[0], addr);
201} 185}
202 186
@@ -206,7 +190,7 @@ static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const v
206 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 190 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
207 unsigned long win_size = dev->win_size; 191 unsigned long win_size = dev->win_size;
208 192
209 DEBUG(3, "to = %lu from = %p len = %zd", to, from, len); 193 pr_debug("to = %lu from = %p len = %zd\n", to, from, len);
210 while(len) { 194 while(len) {
211 int towrite = win_size - (to & (win_size-1)); 195 int towrite = win_size - (to & (win_size-1));
212 caddr_t addr; 196 caddr_t addr;
@@ -218,7 +202,7 @@ static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const v
218 if(!addr) 202 if(!addr)
219 return; 203 return;
220 204
221 DEBUG(4, "memcpy from %p to %p len = %d", from, addr, towrite); 205 pr_debug("memcpy from %p to %p len = %d\n", from, addr, towrite);
222 memcpy_toio(addr, from, towrite); 206 memcpy_toio(addr, from, towrite);
223 len -= towrite; 207 len -= towrite;
224 to += towrite; 208 to += towrite;
@@ -240,7 +224,7 @@ static map_word pcmcia_read8(struct map_info *map, unsigned long ofs)
240 return d; 224 return d;
241 225
242 d.x[0] = readb(win_base + ofs); 226 d.x[0] = readb(win_base + ofs);
243 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%02lx", 227 pr_debug("ofs = 0x%08lx (%p) data = 0x%02lx\n",
244 ofs, win_base + ofs, d.x[0]); 228 ofs, win_base + ofs, d.x[0]);
245 return d; 229 return d;
246} 230}
@@ -255,7 +239,7 @@ static map_word pcmcia_read16(struct map_info *map, unsigned long ofs)
255 return d; 239 return d;
256 240
257 d.x[0] = readw(win_base + ofs); 241 d.x[0] = readw(win_base + ofs);
258 DEBUG(3, "ofs = 0x%08lx (%p) data = 0x%04lx", 242 pr_debug("ofs = 0x%08lx (%p) data = 0x%04lx\n",
259 ofs, win_base + ofs, d.x[0]); 243 ofs, win_base + ofs, d.x[0]);
260 return d; 244 return d;
261} 245}
@@ -268,7 +252,7 @@ static void pcmcia_copy_from(struct map_info *map, void *to, unsigned long from,
268 if(DEV_REMOVED(map)) 252 if(DEV_REMOVED(map))
269 return; 253 return;
270 254
271 DEBUG(3, "to = %p from = %lu len = %zd", to, from, len); 255 pr_debug("to = %p from = %lu len = %zd\n", to, from, len);
272 memcpy_fromio(to, win_base + from, len); 256 memcpy_fromio(to, win_base + from, len);
273} 257}
274 258
@@ -280,7 +264,7 @@ static void pcmcia_write8(struct map_info *map, map_word d, unsigned long adr)
280 if(DEV_REMOVED(map)) 264 if(DEV_REMOVED(map))
281 return; 265 return;
282 266
283 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%02lx", 267 pr_debug("adr = 0x%08lx (%p) data = 0x%02lx\n",
284 adr, win_base + adr, d.x[0]); 268 adr, win_base + adr, d.x[0]);
285 writeb(d.x[0], win_base + adr); 269 writeb(d.x[0], win_base + adr);
286} 270}
@@ -293,7 +277,7 @@ static void pcmcia_write16(struct map_info *map, map_word d, unsigned long adr)
293 if(DEV_REMOVED(map)) 277 if(DEV_REMOVED(map))
294 return; 278 return;
295 279
296 DEBUG(3, "adr = 0x%08lx (%p) data = 0x%04lx", 280 pr_debug("adr = 0x%08lx (%p) data = 0x%04lx\n",
297 adr, win_base + adr, d.x[0]); 281 adr, win_base + adr, d.x[0]);
298 writew(d.x[0], win_base + adr); 282 writew(d.x[0], win_base + adr);
299} 283}
@@ -306,7 +290,7 @@ static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *f
306 if(DEV_REMOVED(map)) 290 if(DEV_REMOVED(map))
307 return; 291 return;
308 292
309 DEBUG(3, "to = %lu from = %p len = %zd", to, from, len); 293 pr_debug("to = %lu from = %p len = %zd\n", to, from, len);
310 memcpy_toio(win_base + to, from, len); 294 memcpy_toio(win_base + to, from, len);
311} 295}
312 296
@@ -316,7 +300,7 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
316 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 300 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
317 struct pcmcia_device *link = dev->p_dev; 301 struct pcmcia_device *link = dev->p_dev;
318 302
319 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); 303 pr_debug("dev = %p on = %d vpp = %d\n\n", dev, on, dev->vpp);
320 pcmcia_fixup_vpp(link, on ? dev->vpp : 0); 304 pcmcia_fixup_vpp(link, on ? dev->vpp : 0);
321} 305}
322 306
@@ -325,7 +309,7 @@ static void pcmciamtd_release(struct pcmcia_device *link)
325{ 309{
326 struct pcmciamtd_dev *dev = link->priv; 310 struct pcmciamtd_dev *dev = link->priv;
327 311
328 DEBUG(3, "link = 0x%p", link); 312 pr_debug("link = 0x%p\n", link);
329 313
330 if (link->resource[2]->end) { 314 if (link->resource[2]->end) {
331 if(dev->win_base) { 315 if(dev->win_base) {
@@ -337,7 +321,6 @@ static void pcmciamtd_release(struct pcmcia_device *link)
337} 321}
338 322
339 323
340#ifdef CONFIG_MTD_DEBUG
341static int pcmciamtd_cistpl_format(struct pcmcia_device *p_dev, 324static int pcmciamtd_cistpl_format(struct pcmcia_device *p_dev,
342 tuple_t *tuple, 325 tuple_t *tuple,
343 void *priv_data) 326 void *priv_data)
@@ -347,7 +330,7 @@ static int pcmciamtd_cistpl_format(struct pcmcia_device *p_dev,
347 if (!pcmcia_parse_tuple(tuple, &parse)) { 330 if (!pcmcia_parse_tuple(tuple, &parse)) {
348 cistpl_format_t *t = &parse.format; 331 cistpl_format_t *t = &parse.format;
349 (void)t; /* Shut up, gcc */ 332 (void)t; /* Shut up, gcc */
350 DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u", 333 pr_debug("Format type: %u, Error Detection: %u, offset = %u, length =%u\n",
351 t->type, t->edc, t->offset, t->length); 334 t->type, t->edc, t->offset, t->length);
352 } 335 }
353 return -ENOSPC; 336 return -ENOSPC;
@@ -363,12 +346,11 @@ static int pcmciamtd_cistpl_jedec(struct pcmcia_device *p_dev,
363 if (!pcmcia_parse_tuple(tuple, &parse)) { 346 if (!pcmcia_parse_tuple(tuple, &parse)) {
364 cistpl_jedec_t *t = &parse.jedec; 347 cistpl_jedec_t *t = &parse.jedec;
365 for (i = 0; i < t->nid; i++) 348 for (i = 0; i < t->nid; i++)
366 DEBUG(2, "JEDEC: 0x%02x 0x%02x", 349 pr_debug("JEDEC: 0x%02x 0x%02x\n",
367 t->id[i].mfr, t->id[i].info); 350 t->id[i].mfr, t->id[i].info);
368 } 351 }
369 return -ENOSPC; 352 return -ENOSPC;
370} 353}
371#endif
372 354
373static int pcmciamtd_cistpl_device(struct pcmcia_device *p_dev, 355static int pcmciamtd_cistpl_device(struct pcmcia_device *p_dev,
374 tuple_t *tuple, 356 tuple_t *tuple,
@@ -382,14 +364,14 @@ static int pcmciamtd_cistpl_device(struct pcmcia_device *p_dev,
382 if (pcmcia_parse_tuple(tuple, &parse)) 364 if (pcmcia_parse_tuple(tuple, &parse))
383 return -EINVAL; 365 return -EINVAL;
384 366
385 DEBUG(2, "Common memory:"); 367 pr_debug("Common memory:\n");
386 dev->pcmcia_map.size = t->dev[0].size; 368 dev->pcmcia_map.size = t->dev[0].size;
387 /* from here on: DEBUG only */ 369 /* from here on: DEBUG only */
388 for (i = 0; i < t->ndev; i++) { 370 for (i = 0; i < t->ndev; i++) {
389 DEBUG(2, "Region %d, type = %u", i, t->dev[i].type); 371 pr_debug("Region %d, type = %u\n", i, t->dev[i].type);
390 DEBUG(2, "Region %d, wp = %u", i, t->dev[i].wp); 372 pr_debug("Region %d, wp = %u\n", i, t->dev[i].wp);
391 DEBUG(2, "Region %d, speed = %u ns", i, t->dev[i].speed); 373 pr_debug("Region %d, speed = %u ns\n", i, t->dev[i].speed);
392 DEBUG(2, "Region %d, size = %u bytes", i, t->dev[i].size); 374 pr_debug("Region %d, size = %u bytes\n", i, t->dev[i].size);
393 } 375 }
394 return 0; 376 return 0;
395} 377}
@@ -409,12 +391,12 @@ static int pcmciamtd_cistpl_geo(struct pcmcia_device *p_dev,
409 dev->pcmcia_map.bankwidth = t->geo[0].buswidth; 391 dev->pcmcia_map.bankwidth = t->geo[0].buswidth;
410 /* from here on: DEBUG only */ 392 /* from here on: DEBUG only */
411 for (i = 0; i < t->ngeo; i++) { 393 for (i = 0; i < t->ngeo; i++) {
412 DEBUG(2, "region: %d bankwidth = %u", i, t->geo[i].buswidth); 394 pr_debug("region: %d bankwidth = %u\n", i, t->geo[i].buswidth);
413 DEBUG(2, "region: %d erase_block = %u", i, t->geo[i].erase_block); 395 pr_debug("region: %d erase_block = %u\n", i, t->geo[i].erase_block);
414 DEBUG(2, "region: %d read_block = %u", i, t->geo[i].read_block); 396 pr_debug("region: %d read_block = %u\n", i, t->geo[i].read_block);
415 DEBUG(2, "region: %d write_block = %u", i, t->geo[i].write_block); 397 pr_debug("region: %d write_block = %u\n", i, t->geo[i].write_block);
416 DEBUG(2, "region: %d partition = %u", i, t->geo[i].partition); 398 pr_debug("region: %d partition = %u\n", i, t->geo[i].partition);
417 DEBUG(2, "region: %d interleave = %u", i, t->geo[i].interleave); 399 pr_debug("region: %d interleave = %u\n", i, t->geo[i].interleave);
418 } 400 }
419 return 0; 401 return 0;
420} 402}
@@ -432,13 +414,11 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev
432 if (p_dev->prod_id[i]) 414 if (p_dev->prod_id[i])
433 strcat(dev->mtd_name, p_dev->prod_id[i]); 415 strcat(dev->mtd_name, p_dev->prod_id[i]);
434 } 416 }
435 DEBUG(2, "Found name: %s", dev->mtd_name); 417 pr_debug("Found name: %s\n", dev->mtd_name);
436 } 418 }
437 419
438#ifdef CONFIG_MTD_DEBUG
439 pcmcia_loop_tuple(p_dev, CISTPL_FORMAT, pcmciamtd_cistpl_format, NULL); 420 pcmcia_loop_tuple(p_dev, CISTPL_FORMAT, pcmciamtd_cistpl_format, NULL);
440 pcmcia_loop_tuple(p_dev, CISTPL_JEDEC_C, pcmciamtd_cistpl_jedec, NULL); 421 pcmcia_loop_tuple(p_dev, CISTPL_JEDEC_C, pcmciamtd_cistpl_jedec, NULL);
441#endif
442 pcmcia_loop_tuple(p_dev, CISTPL_DEVICE, pcmciamtd_cistpl_device, dev); 422 pcmcia_loop_tuple(p_dev, CISTPL_DEVICE, pcmciamtd_cistpl_device, dev);
443 pcmcia_loop_tuple(p_dev, CISTPL_DEVICE_GEO, pcmciamtd_cistpl_geo, dev); 423 pcmcia_loop_tuple(p_dev, CISTPL_DEVICE_GEO, pcmciamtd_cistpl_geo, dev);
444 424
@@ -450,12 +430,12 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev
450 430
451 if(force_size) { 431 if(force_size) {
452 dev->pcmcia_map.size = force_size << 20; 432 dev->pcmcia_map.size = force_size << 20;
453 DEBUG(2, "size forced to %dM", force_size); 433 pr_debug("size forced to %dM\n", force_size);
454 } 434 }
455 435
456 if(bankwidth) { 436 if(bankwidth) {
457 dev->pcmcia_map.bankwidth = bankwidth; 437 dev->pcmcia_map.bankwidth = bankwidth;
458 DEBUG(2, "bankwidth forced to %d", bankwidth); 438 pr_debug("bankwidth forced to %d\n", bankwidth);
459 } 439 }
460 440
461 dev->pcmcia_map.name = dev->mtd_name; 441 dev->pcmcia_map.name = dev->mtd_name;
@@ -464,7 +444,7 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev
464 *new_name = 1; 444 *new_name = 1;
465 } 445 }
466 446
467 DEBUG(1, "Device: Size: %lu Width:%d Name: %s", 447 pr_debug("Device: Size: %lu Width:%d Name: %s\n",
468 dev->pcmcia_map.size, 448 dev->pcmcia_map.size,
469 dev->pcmcia_map.bankwidth << 3, dev->mtd_name); 449 dev->pcmcia_map.bankwidth << 3, dev->mtd_name);
470} 450}
@@ -479,7 +459,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
479 static char *probes[] = { "jedec_probe", "cfi_probe" }; 459 static char *probes[] = { "jedec_probe", "cfi_probe" };
480 int new_name = 0; 460 int new_name = 0;
481 461
482 DEBUG(3, "link=0x%p", link); 462 pr_debug("link=0x%p\n", link);
483 463
484 card_settings(dev, link, &new_name); 464 card_settings(dev, link, &new_name);
485 465
@@ -512,11 +492,11 @@ static int pcmciamtd_config(struct pcmcia_device *link)
512 492
513 do { 493 do {
514 int ret; 494 int ret;
515 DEBUG(2, "requesting window with size = %luKiB memspeed = %d", 495 pr_debug("requesting window with size = %luKiB memspeed = %d\n",
516 (unsigned long) resource_size(link->resource[2]) >> 10, 496 (unsigned long) resource_size(link->resource[2]) >> 10,
517 mem_speed); 497 mem_speed);
518 ret = pcmcia_request_window(link, link->resource[2], mem_speed); 498 ret = pcmcia_request_window(link, link->resource[2], mem_speed);
519 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); 499 pr_debug("ret = %d dev->win_size = %d\n", ret, dev->win_size);
520 if(ret) { 500 if(ret) {
521 j++; 501 j++;
522 link->resource[2]->start = 0; 502 link->resource[2]->start = 0;
@@ -524,21 +504,21 @@ static int pcmciamtd_config(struct pcmcia_device *link)
524 force_size << 20 : MAX_PCMCIA_ADDR; 504 force_size << 20 : MAX_PCMCIA_ADDR;
525 link->resource[2]->end >>= j; 505 link->resource[2]->end >>= j;
526 } else { 506 } else {
527 DEBUG(2, "Got window of size %luKiB", (unsigned long) 507 pr_debug("Got window of size %luKiB\n", (unsigned long)
528 resource_size(link->resource[2]) >> 10); 508 resource_size(link->resource[2]) >> 10);
529 dev->win_size = resource_size(link->resource[2]); 509 dev->win_size = resource_size(link->resource[2]);
530 break; 510 break;
531 } 511 }
532 } while (link->resource[2]->end >= 0x1000); 512 } while (link->resource[2]->end >= 0x1000);
533 513
534 DEBUG(2, "dev->win_size = %d", dev->win_size); 514 pr_debug("dev->win_size = %d\n", dev->win_size);
535 515
536 if(!dev->win_size) { 516 if(!dev->win_size) {
537 dev_err(&dev->p_dev->dev, "Cannot allocate memory window\n"); 517 dev_err(&dev->p_dev->dev, "Cannot allocate memory window\n");
538 pcmciamtd_release(link); 518 pcmciamtd_release(link);
539 return -ENODEV; 519 return -ENODEV;
540 } 520 }
541 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); 521 pr_debug("Allocated a window of %dKiB\n", dev->win_size >> 10);
542 522
543 /* Get write protect status */ 523 /* Get write protect status */
544 dev->win_base = ioremap(link->resource[2]->start, 524 dev->win_base = ioremap(link->resource[2]->start,
@@ -549,7 +529,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
549 pcmciamtd_release(link); 529 pcmciamtd_release(link);
550 return -ENODEV; 530 return -ENODEV;
551 } 531 }
552 DEBUG(1, "mapped window dev = %p @ %pR, base = %p", 532 pr_debug("mapped window dev = %p @ %pR, base = %p\n",
553 dev, link->resource[2], dev->win_base); 533 dev, link->resource[2], dev->win_base);
554 534
555 dev->offset = 0; 535 dev->offset = 0;
@@ -564,7 +544,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
564 } 544 }
565 545
566 link->config_index = 0; 546 link->config_index = 0;
567 DEBUG(2, "Setting Configuration"); 547 pr_debug("Setting Configuration\n");
568 ret = pcmcia_enable_device(link); 548 ret = pcmcia_enable_device(link);
569 if (ret != 0) { 549 if (ret != 0) {
570 if (dev->win_base) { 550 if (dev->win_base) {
@@ -580,17 +560,17 @@ static int pcmciamtd_config(struct pcmcia_device *link)
580 mtd = do_map_probe("map_rom", &dev->pcmcia_map); 560 mtd = do_map_probe("map_rom", &dev->pcmcia_map);
581 } else { 561 } else {
582 for(i = 0; i < ARRAY_SIZE(probes); i++) { 562 for(i = 0; i < ARRAY_SIZE(probes); i++) {
583 DEBUG(1, "Trying %s", probes[i]); 563 pr_debug("Trying %s\n", probes[i]);
584 mtd = do_map_probe(probes[i], &dev->pcmcia_map); 564 mtd = do_map_probe(probes[i], &dev->pcmcia_map);
585 if(mtd) 565 if(mtd)
586 break; 566 break;
587 567
588 DEBUG(1, "FAILED: %s", probes[i]); 568 pr_debug("FAILED: %s\n", probes[i]);
589 } 569 }
590 } 570 }
591 571
592 if(!mtd) { 572 if(!mtd) {
593 DEBUG(1, "Can not find an MTD"); 573 pr_debug("Can not find an MTD\n");
594 pcmciamtd_release(link); 574 pcmciamtd_release(link);
595 return -ENODEV; 575 return -ENODEV;
596 } 576 }
@@ -617,7 +597,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
617 /* If the memory found is fits completely into the mapped PCMCIA window, 597 /* If the memory found is fits completely into the mapped PCMCIA window,
618 use the faster non-remapping read/write functions */ 598 use the faster non-remapping read/write functions */
619 if(mtd->size <= dev->win_size) { 599 if(mtd->size <= dev->win_size) {
620 DEBUG(1, "Using non remapping memory functions"); 600 pr_debug("Using non remapping memory functions\n");
621 dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base; 601 dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base;
622 if (dev->pcmcia_map.bankwidth == 1) { 602 if (dev->pcmcia_map.bankwidth == 1) {
623 dev->pcmcia_map.read = pcmcia_read8; 603 dev->pcmcia_map.read = pcmcia_read8;
@@ -645,7 +625,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
645 625
646static int pcmciamtd_suspend(struct pcmcia_device *dev) 626static int pcmciamtd_suspend(struct pcmcia_device *dev)
647{ 627{
648 DEBUG(2, "EVENT_PM_RESUME"); 628 pr_debug("EVENT_PM_RESUME\n");
649 629
650 /* get_lock(link); */ 630 /* get_lock(link); */
651 631
@@ -654,7 +634,7 @@ static int pcmciamtd_suspend(struct pcmcia_device *dev)
654 634
655static int pcmciamtd_resume(struct pcmcia_device *dev) 635static int pcmciamtd_resume(struct pcmcia_device *dev)
656{ 636{
657 DEBUG(2, "EVENT_PM_SUSPEND"); 637 pr_debug("EVENT_PM_SUSPEND\n");
658 638
659 /* free_lock(link); */ 639 /* free_lock(link); */
660 640
@@ -666,7 +646,7 @@ static void pcmciamtd_detach(struct pcmcia_device *link)
666{ 646{
667 struct pcmciamtd_dev *dev = link->priv; 647 struct pcmciamtd_dev *dev = link->priv;
668 648
669 DEBUG(3, "link=0x%p", link); 649 pr_debug("link=0x%p\n", link);
670 650
671 if(dev->mtd_info) { 651 if(dev->mtd_info) {
672 mtd_device_unregister(dev->mtd_info); 652 mtd_device_unregister(dev->mtd_info);
@@ -686,7 +666,7 @@ static int pcmciamtd_probe(struct pcmcia_device *link)
686 /* Create new memory card device */ 666 /* Create new memory card device */
687 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 667 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
688 if (!dev) return -ENOMEM; 668 if (!dev) return -ENOMEM;
689 DEBUG(1, "dev=0x%p", dev); 669 pr_debug("dev=0x%p\n", dev);
690 670
691 dev->p_dev = link; 671 dev->p_dev = link;
692 link->priv = dev; 672 link->priv = dev;
@@ -755,7 +735,7 @@ static int __init init_pcmciamtd(void)
755 735
756static void __exit exit_pcmciamtd(void) 736static void __exit exit_pcmciamtd(void)
757{ 737{
758 DEBUG(1, DRIVER_DESC " unloading"); 738 pr_debug(DRIVER_DESC " unloading");
759 pcmcia_unregister_driver(&pcmciamtd_driver); 739 pcmcia_unregister_driver(&pcmciamtd_driver);
760} 740}
761 741
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index f64cee4a3bf..66e8200079c 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -27,8 +27,6 @@ struct physmap_flash_info {
27 struct mtd_info *mtd[MAX_RESOURCES]; 27 struct mtd_info *mtd[MAX_RESOURCES];
28 struct mtd_info *cmtd; 28 struct mtd_info *cmtd;
29 struct map_info map[MAX_RESOURCES]; 29 struct map_info map[MAX_RESOURCES];
30 int nr_parts;
31 struct mtd_partition *parts;
32}; 30};
33 31
34static int physmap_flash_remove(struct platform_device *dev) 32static int physmap_flash_remove(struct platform_device *dev)
@@ -46,8 +44,6 @@ static int physmap_flash_remove(struct platform_device *dev)
46 44
47 if (info->cmtd) { 45 if (info->cmtd) {
48 mtd_device_unregister(info->cmtd); 46 mtd_device_unregister(info->cmtd);
49 if (info->nr_parts)
50 kfree(info->parts);
51 if (info->cmtd != info->mtd[0]) 47 if (info->cmtd != info->mtd[0])
52 mtd_concat_destroy(info->cmtd); 48 mtd_concat_destroy(info->cmtd);
53 } 49 }
@@ -175,23 +171,8 @@ static int physmap_flash_probe(struct platform_device *dev)
175 if (err) 171 if (err)
176 goto err_out; 172 goto err_out;
177 173
178 err = parse_mtd_partitions(info->cmtd, part_probe_types, 174 mtd_device_parse_register(info->cmtd, part_probe_types, 0,
179 &info->parts, 0); 175 physmap_data->parts, physmap_data->nr_parts);
180 if (err > 0) {
181 mtd_device_register(info->cmtd, info->parts, err);
182 info->nr_parts = err;
183 return 0;
184 }
185
186 if (physmap_data->nr_parts) {
187 printk(KERN_NOTICE "Using physmap partition information\n");
188 mtd_device_register(info->cmtd, physmap_data->parts,
189 physmap_data->nr_parts);
190 return 0;
191 }
192
193 mtd_device_register(info->cmtd, NULL, 0);
194
195 return 0; 176 return 0;
196 177
197err_out: 178err_out:
@@ -245,21 +226,6 @@ static struct platform_device physmap_flash = {
245 .num_resources = 1, 226 .num_resources = 1,
246 .resource = &physmap_flash_resource, 227 .resource = &physmap_flash_resource,
247}; 228};
248
249void physmap_configure(unsigned long addr, unsigned long size,
250 int bankwidth, void (*set_vpp)(struct map_info *, int))
251{
252 physmap_flash_resource.start = addr;
253 physmap_flash_resource.end = addr + size - 1;
254 physmap_flash_data.width = bankwidth;
255 physmap_flash_data.set_vpp = set_vpp;
256}
257
258void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
259{
260 physmap_flash_data.nr_parts = num_parts;
261 physmap_flash_data.parts = parts;
262}
263#endif 229#endif
264 230
265static int __init physmap_init(void) 231static int __init physmap_init(void)
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index d251d1db129..7d65f9d3e69 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -34,58 +34,10 @@ struct of_flash_list {
34 34
35struct of_flash { 35struct of_flash {
36 struct mtd_info *cmtd; 36 struct mtd_info *cmtd;
37 struct mtd_partition *parts;
38 int list_size; /* number of elements in of_flash_list */ 37 int list_size; /* number of elements in of_flash_list */
39 struct of_flash_list list[0]; 38 struct of_flash_list list[0];
40}; 39};
41 40
42#define OF_FLASH_PARTS(info) ((info)->parts)
43static int parse_obsolete_partitions(struct platform_device *dev,
44 struct of_flash *info,
45 struct device_node *dp)
46{
47 int i, plen, nr_parts;
48 const struct {
49 __be32 offset, len;
50 } *part;
51 const char *names;
52
53 part = of_get_property(dp, "partitions", &plen);
54 if (!part)
55 return 0; /* No partitions found */
56
57 dev_warn(&dev->dev, "Device tree uses obsolete partition map binding\n");
58
59 nr_parts = plen / sizeof(part[0]);
60
61 info->parts = kzalloc(nr_parts * sizeof(*info->parts), GFP_KERNEL);
62 if (!info->parts)
63 return -ENOMEM;
64
65 names = of_get_property(dp, "partition-names", &plen);
66
67 for (i = 0; i < nr_parts; i++) {
68 info->parts[i].offset = be32_to_cpu(part->offset);
69 info->parts[i].size = be32_to_cpu(part->len) & ~1;
70 if (be32_to_cpu(part->len) & 1) /* bit 0 set signifies read only partition */
71 info->parts[i].mask_flags = MTD_WRITEABLE;
72
73 if (names && (plen > 0)) {
74 int len = strlen(names) + 1;
75
76 info->parts[i].name = (char *)names;
77 plen -= len;
78 names += len;
79 } else {
80 info->parts[i].name = "unnamed";
81 }
82
83 part++;
84 }
85
86 return nr_parts;
87}
88
89static int of_flash_remove(struct platform_device *dev) 41static int of_flash_remove(struct platform_device *dev)
90{ 42{
91 struct of_flash *info; 43 struct of_flash *info;
@@ -101,11 +53,8 @@ static int of_flash_remove(struct platform_device *dev)
101 mtd_concat_destroy(info->cmtd); 53 mtd_concat_destroy(info->cmtd);
102 } 54 }
103 55
104 if (info->cmtd) { 56 if (info->cmtd)
105 if (OF_FLASH_PARTS(info))
106 kfree(OF_FLASH_PARTS(info));
107 mtd_device_unregister(info->cmtd); 57 mtd_device_unregister(info->cmtd);
108 }
109 58
110 for (i = 0; i < info->list_size; i++) { 59 for (i = 0; i < info->list_size; i++) {
111 if (info->list[i].mtd) 60 if (info->list[i].mtd)
@@ -165,7 +114,8 @@ static struct mtd_info * __devinit obsolete_probe(struct platform_device *dev,
165 specifies the list of partition probers to use. If none is given then the 114 specifies the list of partition probers to use. If none is given then the
166 default is use. These take precedence over other device tree 115 default is use. These take precedence over other device tree
167 information. */ 116 information. */
168static const char *part_probe_types_def[] = { "cmdlinepart", "RedBoot", NULL }; 117static const char *part_probe_types_def[] = { "cmdlinepart", "RedBoot",
118 "ofpart", "ofoldpart", NULL };
169static const char ** __devinit of_get_probes(struct device_node *dp) 119static const char ** __devinit of_get_probes(struct device_node *dp)
170{ 120{
171 const char *cp; 121 const char *cp;
@@ -218,6 +168,7 @@ static int __devinit of_flash_probe(struct platform_device *dev)
218 int reg_tuple_size; 168 int reg_tuple_size;
219 struct mtd_info **mtd_list = NULL; 169 struct mtd_info **mtd_list = NULL;
220 resource_size_t res_size; 170 resource_size_t res_size;
171 struct mtd_part_parser_data ppdata;
221 172
222 match = of_match_device(of_flash_match, &dev->dev); 173 match = of_match_device(of_flash_match, &dev->dev);
223 if (!match) 174 if (!match)
@@ -331,29 +282,12 @@ static int __devinit of_flash_probe(struct platform_device *dev)
331 if (err) 282 if (err)
332 goto err_out; 283 goto err_out;
333 284
285 ppdata.of_node = dp;
334 part_probe_types = of_get_probes(dp); 286 part_probe_types = of_get_probes(dp);
335 err = parse_mtd_partitions(info->cmtd, part_probe_types, 287 mtd_device_parse_register(info->cmtd, part_probe_types, &ppdata,
336 &info->parts, 0); 288 NULL, 0);
337 if (err < 0) {
338 of_free_probes(part_probe_types);
339 goto err_out;
340 }
341 of_free_probes(part_probe_types); 289 of_free_probes(part_probe_types);
342 290
343 if (err == 0) {
344 err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts);
345 if (err < 0)
346 goto err_out;
347 }
348
349 if (err == 0) {
350 err = parse_obsolete_partitions(dev, info, dp);
351 if (err < 0)
352 goto err_out;
353 }
354
355 mtd_device_register(info->cmtd, info->parts, err);
356
357 kfree(mtd_list); 291 kfree(mtd_list);
358 292
359 return 0; 293 return 0;
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 9ca1eccba4b..94f55348972 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -44,8 +44,6 @@ struct platram_info {
44 struct device *dev; 44 struct device *dev;
45 struct mtd_info *mtd; 45 struct mtd_info *mtd;
46 struct map_info map; 46 struct map_info map;
47 struct mtd_partition *partitions;
48 bool free_partitions;
49 struct resource *area; 47 struct resource *area;
50 struct platdata_mtd_ram *pdata; 48 struct platdata_mtd_ram *pdata;
51}; 49};
@@ -95,10 +93,6 @@ static int platram_remove(struct platform_device *pdev)
95 93
96 if (info->mtd) { 94 if (info->mtd) {
97 mtd_device_unregister(info->mtd); 95 mtd_device_unregister(info->mtd);
98 if (info->partitions) {
99 if (info->free_partitions)
100 kfree(info->partitions);
101 }
102 map_destroy(info->mtd); 96 map_destroy(info->mtd);
103 } 97 }
104 98
@@ -228,21 +222,8 @@ static int platram_probe(struct platform_device *pdev)
228 /* check to see if there are any available partitions, or wether 222 /* check to see if there are any available partitions, or wether
229 * to add this device whole */ 223 * to add this device whole */
230 224
231 if (!pdata->nr_partitions) { 225 err = mtd_device_parse_register(info->mtd, pdata->probes, 0,
232 /* try to probe using the supplied probe type */ 226 pdata->partitions, pdata->nr_partitions);
233 if (pdata->probes) {
234 err = parse_mtd_partitions(info->mtd, pdata->probes,
235 &info->partitions, 0);
236 info->free_partitions = 1;
237 if (err > 0)
238 err = mtd_device_register(info->mtd,
239 info->partitions, err);
240 }
241 }
242 /* use the static mapping */
243 else
244 err = mtd_device_register(info->mtd, pdata->partitions,
245 pdata->nr_partitions);
246 if (!err) 227 if (!err)
247 dev_info(&pdev->dev, "registered mtd device\n"); 228 dev_info(&pdev->dev, "registered mtd device\n");
248 229
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index 7ae137d4b99..411a17df9fc 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -41,8 +41,6 @@ static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from,
41} 41}
42 42
43struct pxa2xx_flash_info { 43struct pxa2xx_flash_info {
44 struct mtd_partition *parts;
45 int nr_parts;
46 struct mtd_info *mtd; 44 struct mtd_info *mtd;
47 struct map_info map; 45 struct map_info map;
48}; 46};
@@ -55,9 +53,7 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
55{ 53{
56 struct flash_platform_data *flash = pdev->dev.platform_data; 54 struct flash_platform_data *flash = pdev->dev.platform_data;
57 struct pxa2xx_flash_info *info; 55 struct pxa2xx_flash_info *info;
58 struct mtd_partition *parts;
59 struct resource *res; 56 struct resource *res;
60 int ret = 0;
61 57
62 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 58 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
63 if (!res) 59 if (!res)
@@ -71,8 +67,6 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
71 info->map.bankwidth = flash->width; 67 info->map.bankwidth = flash->width;
72 info->map.phys = res->start; 68 info->map.phys = res->start;
73 info->map.size = resource_size(res); 69 info->map.size = resource_size(res);
74 info->parts = flash->parts;
75 info->nr_parts = flash->nr_parts;
76 70
77 info->map.virt = ioremap(info->map.phys, info->map.size); 71 info->map.virt = ioremap(info->map.phys, info->map.size);
78 if (!info->map.virt) { 72 if (!info->map.virt) {
@@ -104,18 +98,7 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
104 } 98 }
105 info->mtd->owner = THIS_MODULE; 99 info->mtd->owner = THIS_MODULE;
106 100
107 ret = parse_mtd_partitions(info->mtd, probes, &parts, 0); 101 mtd_device_parse_register(info->mtd, probes, 0, NULL, 0);
108
109 if (ret > 0) {
110 info->nr_parts = ret;
111 info->parts = parts;
112 }
113
114 if (!info->nr_parts)
115 printk("Registering %s as whole device\n",
116 info->map.name);
117
118 mtd_device_register(info->mtd, info->parts, info->nr_parts);
119 102
120 platform_set_drvdata(pdev, info); 103 platform_set_drvdata(pdev, info);
121 return 0; 104 return 0;
@@ -133,7 +116,6 @@ static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
133 iounmap(info->map.virt); 116 iounmap(info->map.virt);
134 if (info->map.cached) 117 if (info->map.cached)
135 iounmap(info->map.cached); 118 iounmap(info->map.cached);
136 kfree(info->parts);
137 kfree(info); 119 kfree(info);
138 return 0; 120 return 0;
139} 121}
diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c
index 761fb459d2c..0237f197fd1 100644
--- a/drivers/mtd/maps/rbtx4939-flash.c
+++ b/drivers/mtd/maps/rbtx4939-flash.c
@@ -25,8 +25,6 @@
25struct rbtx4939_flash_info { 25struct rbtx4939_flash_info {
26 struct mtd_info *mtd; 26 struct mtd_info *mtd;
27 struct map_info map; 27 struct map_info map;
28 int nr_parts;
29 struct mtd_partition *parts;
30}; 28};
31 29
32static int rbtx4939_flash_remove(struct platform_device *dev) 30static int rbtx4939_flash_remove(struct platform_device *dev)
@@ -41,8 +39,6 @@ static int rbtx4939_flash_remove(struct platform_device *dev)
41 if (info->mtd) { 39 if (info->mtd) {
42 struct rbtx4939_flash_data *pdata = dev->dev.platform_data; 40 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
43 41
44 if (info->nr_parts)
45 kfree(info->parts);
46 mtd_device_unregister(info->mtd); 42 mtd_device_unregister(info->mtd);
47 map_destroy(info->mtd); 43 map_destroy(info->mtd);
48 } 44 }
@@ -50,7 +46,6 @@ static int rbtx4939_flash_remove(struct platform_device *dev)
50} 46}
51 47
52static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 48static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
53static const char *part_probe_types[] = { "cmdlinepart", NULL };
54 49
55static int rbtx4939_flash_probe(struct platform_device *dev) 50static int rbtx4939_flash_probe(struct platform_device *dev)
56{ 51{
@@ -107,22 +102,11 @@ static int rbtx4939_flash_probe(struct platform_device *dev)
107 info->mtd->owner = THIS_MODULE; 102 info->mtd->owner = THIS_MODULE;
108 if (err) 103 if (err)
109 goto err_out; 104 goto err_out;
105 err = mtd_device_parse_register(info->mtd, NULL, 0,
106 pdata->parts, pdata->nr_parts);
110 107
111 err = parse_mtd_partitions(info->mtd, part_probe_types, 108 if (err)
112 &info->parts, 0); 109 goto err_out;
113 if (err > 0) {
114 mtd_device_register(info->mtd, info->parts, err);
115 info->nr_parts = err;
116 return 0;
117 }
118
119 if (pdata->nr_parts) {
120 pr_notice("Using rbtx4939 partition information\n");
121 mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
122 return 0;
123 }
124
125 mtd_device_register(info->mtd, NULL, 0);
126 return 0; 110 return 0;
127 111
128err_out: 112err_out:
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index a9b5e0e5c4c..fa9c0a9670c 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -131,10 +131,8 @@ struct sa_subdev_info {
131}; 131};
132 132
133struct sa_info { 133struct sa_info {
134 struct mtd_partition *parts;
135 struct mtd_info *mtd; 134 struct mtd_info *mtd;
136 int num_subdev; 135 int num_subdev;
137 unsigned int nr_parts;
138 struct sa_subdev_info subdev[0]; 136 struct sa_subdev_info subdev[0];
139}; 137};
140 138
@@ -231,8 +229,6 @@ static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *pla
231 mtd_concat_destroy(info->mtd); 229 mtd_concat_destroy(info->mtd);
232 } 230 }
233 231
234 kfree(info->parts);
235
236 for (i = info->num_subdev - 1; i >= 0; i--) 232 for (i = info->num_subdev - 1; i >= 0; i--)
237 sa1100_destroy_subdev(&info->subdev[i]); 233 sa1100_destroy_subdev(&info->subdev[i]);
238 kfree(info); 234 kfree(info);
@@ -341,10 +337,8 @@ static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
341static int __devinit sa1100_mtd_probe(struct platform_device *pdev) 337static int __devinit sa1100_mtd_probe(struct platform_device *pdev)
342{ 338{
343 struct flash_platform_data *plat = pdev->dev.platform_data; 339 struct flash_platform_data *plat = pdev->dev.platform_data;
344 struct mtd_partition *parts;
345 const char *part_type = NULL;
346 struct sa_info *info; 340 struct sa_info *info;
347 int err, nr_parts = 0; 341 int err;
348 342
349 if (!plat) 343 if (!plat)
350 return -ENODEV; 344 return -ENODEV;
@@ -358,26 +352,8 @@ static int __devinit sa1100_mtd_probe(struct platform_device *pdev)
358 /* 352 /*
359 * Partition selection stuff. 353 * Partition selection stuff.
360 */ 354 */
361 nr_parts = parse_mtd_partitions(info->mtd, part_probes, &parts, 0); 355 mtd_device_parse_register(info->mtd, part_probes, 0,
362 if (nr_parts > 0) { 356 plat->parts, plat->nr_parts);
363 info->parts = parts;
364 part_type = "dynamic";
365 } else {
366 parts = plat->parts;
367 nr_parts = plat->nr_parts;
368 part_type = "static";
369 }
370
371 if (nr_parts == 0)
372 printk(KERN_NOTICE "SA1100 flash: no partition info "
373 "available, registering whole flash\n");
374 else
375 printk(KERN_NOTICE "SA1100 flash: using %s partition "
376 "definition\n", part_type);
377
378 mtd_device_register(info->mtd, parts, nr_parts);
379
380 info->nr_parts = nr_parts;
381 357
382 platform_set_drvdata(pdev, info); 358 platform_set_drvdata(pdev, info);
383 err = 0; 359 err = 0;
diff --git a/drivers/mtd/maps/solutionengine.c b/drivers/mtd/maps/solutionengine.c
index cbf6bade935..496c40704af 100644
--- a/drivers/mtd/maps/solutionengine.c
+++ b/drivers/mtd/maps/solutionengine.c
@@ -19,8 +19,6 @@
19static struct mtd_info *flash_mtd; 19static struct mtd_info *flash_mtd;
20static struct mtd_info *eprom_mtd; 20static struct mtd_info *eprom_mtd;
21 21
22static struct mtd_partition *parsed_parts;
23
24struct map_info soleng_eprom_map = { 22struct map_info soleng_eprom_map = {
25 .name = "Solution Engine EPROM", 23 .name = "Solution Engine EPROM",
26 .size = 0x400000, 24 .size = 0x400000,
@@ -51,12 +49,14 @@ static struct mtd_partition superh_se_partitions[] = {
51 .size = MTDPART_SIZ_FULL, 49 .size = MTDPART_SIZ_FULL,
52 } 50 }
53}; 51};
52#define NUM_PARTITIONS ARRAY_SIZE(superh_se_partitions)
53#else
54#define superh_se_partitions NULL
55#define NUM_PARTITIONS 0
54#endif /* CONFIG_MTD_SUPERH_RESERVE */ 56#endif /* CONFIG_MTD_SUPERH_RESERVE */
55 57
56static int __init init_soleng_maps(void) 58static int __init init_soleng_maps(void)
57{ 59{
58 int nr_parts = 0;
59
60 /* First probe at offset 0 */ 60 /* First probe at offset 0 */
61 soleng_flash_map.phys = 0; 61 soleng_flash_map.phys = 0;
62 soleng_flash_map.virt = (void __iomem *)P2SEGADDR(0); 62 soleng_flash_map.virt = (void __iomem *)P2SEGADDR(0);
@@ -92,21 +92,8 @@ static int __init init_soleng_maps(void)
92 mtd_device_register(eprom_mtd, NULL, 0); 92 mtd_device_register(eprom_mtd, NULL, 0);
93 } 93 }
94 94
95 nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_parts, 0); 95 mtd_device_parse_register(flash_mtd, probes, 0,
96 96 superh_se_partitions, NUM_PARTITIONS);
97#ifdef CONFIG_MTD_SUPERH_RESERVE
98 if (nr_parts <= 0) {
99 printk(KERN_NOTICE "Using configured partition at 0x%08x.\n",
100 CONFIG_MTD_SUPERH_RESERVE);
101 parsed_parts = superh_se_partitions;
102 nr_parts = sizeof(superh_se_partitions)/sizeof(*parsed_parts);
103 }
104#endif /* CONFIG_MTD_SUPERH_RESERVE */
105
106 if (nr_parts > 0)
107 mtd_device_register(flash_mtd, parsed_parts, nr_parts);
108 else
109 mtd_device_register(flash_mtd, NULL, 0);
110 97
111 return 0; 98 return 0;
112} 99}
@@ -118,10 +105,7 @@ static void __exit cleanup_soleng_maps(void)
118 map_destroy(eprom_mtd); 105 map_destroy(eprom_mtd);
119 } 106 }
120 107
121 if (parsed_parts) 108 mtd_device_unregister(flash_mtd);
122 mtd_device_unregister(flash_mtd);
123 else
124 mtd_device_unregister(flash_mtd);
125 map_destroy(flash_mtd); 109 map_destroy(flash_mtd);
126} 110}
127 111
diff --git a/drivers/mtd/maps/wr_sbc82xx_flash.c b/drivers/mtd/maps/wr_sbc82xx_flash.c
index 901ce968efa..aa7e0cb2893 100644
--- a/drivers/mtd/maps/wr_sbc82xx_flash.c
+++ b/drivers/mtd/maps/wr_sbc82xx_flash.c
@@ -20,7 +20,6 @@
20#include <asm/immap_cpm2.h> 20#include <asm/immap_cpm2.h>
21 21
22static struct mtd_info *sbcmtd[3]; 22static struct mtd_info *sbcmtd[3];
23static struct mtd_partition *sbcmtd_parts[3];
24 23
25struct map_info sbc82xx_flash_map[3] = { 24struct map_info sbc82xx_flash_map[3] = {
26 {.name = "Boot flash"}, 25 {.name = "Boot flash"},
@@ -101,6 +100,7 @@ static int __init init_sbc82xx_flash(void)
101 for (i=0; i<3; i++) { 100 for (i=0; i<3; i++) {
102 int8_t flashcs[3] = { 0, 6, 1 }; 101 int8_t flashcs[3] = { 0, 6, 1 };
103 int nr_parts; 102 int nr_parts;
103 struct mtd_partition *defparts;
104 104
105 printk(KERN_NOTICE "PowerQUICC II %s (%ld MiB on CS%d", 105 printk(KERN_NOTICE "PowerQUICC II %s (%ld MiB on CS%d",
106 sbc82xx_flash_map[i].name, 106 sbc82xx_flash_map[i].name,
@@ -113,7 +113,8 @@ static int __init init_sbc82xx_flash(void)
113 } 113 }
114 printk(" at %08lx)\n", sbc82xx_flash_map[i].phys); 114 printk(" at %08lx)\n", sbc82xx_flash_map[i].phys);
115 115
116 sbc82xx_flash_map[i].virt = ioremap(sbc82xx_flash_map[i].phys, sbc82xx_flash_map[i].size); 116 sbc82xx_flash_map[i].virt = ioremap(sbc82xx_flash_map[i].phys,
117 sbc82xx_flash_map[i].size);
117 118
118 if (!sbc82xx_flash_map[i].virt) { 119 if (!sbc82xx_flash_map[i].virt) {
119 printk("Failed to ioremap\n"); 120 printk("Failed to ioremap\n");
@@ -129,24 +130,20 @@ static int __init init_sbc82xx_flash(void)
129 130
130 sbcmtd[i]->owner = THIS_MODULE; 131 sbcmtd[i]->owner = THIS_MODULE;
131 132
132 nr_parts = parse_mtd_partitions(sbcmtd[i], part_probes,
133 &sbcmtd_parts[i], 0);
134 if (nr_parts > 0) {
135 mtd_device_register(sbcmtd[i], sbcmtd_parts[i],
136 nr_parts);
137 continue;
138 }
139
140 /* No partitioning detected. Use default */ 133 /* No partitioning detected. Use default */
141 if (i == 2) { 134 if (i == 2) {
142 mtd_device_register(sbcmtd[i], NULL, 0); 135 defparts = NULL;
136 nr_parts = 0;
143 } else if (i == bigflash) { 137 } else if (i == bigflash) {
144 mtd_device_register(sbcmtd[i], bigflash_parts, 138 defparts = bigflash_parts;
145 ARRAY_SIZE(bigflash_parts)); 139 nr_parts = ARRAY_SIZE(bigflash_parts);
146 } else { 140 } else {
147 mtd_device_register(sbcmtd[i], smallflash_parts, 141 defparts = smallflash_parts;
148 ARRAY_SIZE(smallflash_parts)); 142 nr_parts = ARRAY_SIZE(smallflash_parts);
149 } 143 }
144
145 mtd_device_parse_register(sbcmtd[i], part_probes, 0,
146 defparts, nr_parts);
150 } 147 }
151 return 0; 148 return 0;
152} 149}
@@ -159,12 +156,8 @@ static void __exit cleanup_sbc82xx_flash(void)
159 if (!sbcmtd[i]) 156 if (!sbcmtd[i])
160 continue; 157 continue;
161 158
162 if (i<2 || sbcmtd_parts[i]) 159 mtd_device_unregister(sbcmtd[i]);
163 mtd_device_unregister(sbcmtd[i]);
164 else
165 mtd_device_unregister(sbcmtd[i]);
166 160
167 kfree(sbcmtd_parts[i]);
168 map_destroy(sbcmtd[i]); 161 map_destroy(sbcmtd[i]);
169 162
170 iounmap((void *)sbc82xx_flash_map[i].virt); 163 iounmap((void *)sbc82xx_flash_map[i].virt);
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index ca385697446..ed8b5e744b1 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -426,6 +426,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
426 new->rq->queuedata = new; 426 new->rq->queuedata = new;
427 blk_queue_logical_block_size(new->rq, tr->blksize); 427 blk_queue_logical_block_size(new->rq, tr->blksize);
428 428
429 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, new->rq);
430
429 if (tr->discard) { 431 if (tr->discard) {
430 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, new->rq); 432 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, new->rq);
431 new->rq->limits.max_discard_sectors = UINT_MAX; 433 new->rq->limits.max_discard_sectors = UINT_MAX;
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 3326615ad66..7c1dc908a17 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -44,7 +44,7 @@ struct mtdblk_dev {
44 enum { STATE_EMPTY, STATE_CLEAN, STATE_DIRTY } cache_state; 44 enum { STATE_EMPTY, STATE_CLEAN, STATE_DIRTY } cache_state;
45}; 45};
46 46
47static struct mutex mtdblks_lock; 47static DEFINE_MUTEX(mtdblks_lock);
48 48
49/* 49/*
50 * Cache stuff... 50 * Cache stuff...
@@ -119,7 +119,7 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
119 if (mtdblk->cache_state != STATE_DIRTY) 119 if (mtdblk->cache_state != STATE_DIRTY)
120 return 0; 120 return 0;
121 121
122 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: writing cached data for \"%s\" " 122 pr_debug("mtdblock: writing cached data for \"%s\" "
123 "at 0x%lx, size 0x%x\n", mtd->name, 123 "at 0x%lx, size 0x%x\n", mtd->name,
124 mtdblk->cache_offset, mtdblk->cache_size); 124 mtdblk->cache_offset, mtdblk->cache_size);
125 125
@@ -148,7 +148,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
148 size_t retlen; 148 size_t retlen;
149 int ret; 149 int ret;
150 150
151 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n", 151 pr_debug("mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n",
152 mtd->name, pos, len); 152 mtd->name, pos, len);
153 153
154 if (!sect_size) 154 if (!sect_size)
@@ -218,7 +218,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
218 size_t retlen; 218 size_t retlen;
219 int ret; 219 int ret;
220 220
221 DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n", 221 pr_debug("mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n",
222 mtd->name, pos, len); 222 mtd->name, pos, len);
223 223
224 if (!sect_size) 224 if (!sect_size)
@@ -283,7 +283,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
283{ 283{
284 struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd); 284 struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd);
285 285
286 DEBUG(MTD_DEBUG_LEVEL1,"mtdblock_open\n"); 286 pr_debug("mtdblock_open\n");
287 287
288 mutex_lock(&mtdblks_lock); 288 mutex_lock(&mtdblks_lock);
289 if (mtdblk->count) { 289 if (mtdblk->count) {
@@ -303,7 +303,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
303 303
304 mutex_unlock(&mtdblks_lock); 304 mutex_unlock(&mtdblks_lock);
305 305
306 DEBUG(MTD_DEBUG_LEVEL1, "ok\n"); 306 pr_debug("ok\n");
307 307
308 return 0; 308 return 0;
309} 309}
@@ -312,7 +312,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)
312{ 312{
313 struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd); 313 struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd);
314 314
315 DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n"); 315 pr_debug("mtdblock_release\n");
316 316
317 mutex_lock(&mtdblks_lock); 317 mutex_lock(&mtdblks_lock);
318 318
@@ -329,7 +329,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)
329 329
330 mutex_unlock(&mtdblks_lock); 330 mutex_unlock(&mtdblks_lock);
331 331
332 DEBUG(MTD_DEBUG_LEVEL1, "ok\n"); 332 pr_debug("ok\n");
333 333
334 return 0; 334 return 0;
335} 335}
@@ -389,8 +389,6 @@ static struct mtd_blktrans_ops mtdblock_tr = {
389 389
390static int __init init_mtdblock(void) 390static int __init init_mtdblock(void)
391{ 391{
392 mutex_init(&mtdblks_lock);
393
394 return register_mtd_blktrans(&mtdblock_tr); 392 return register_mtd_blktrans(&mtdblock_tr);
395} 393}
396 394
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 795a8c0a05b..0470a6e8630 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 61086ea3cc6..e7dc732ddab 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -43,7 +43,7 @@ static struct vfsmount *mtd_inode_mnt __read_mostly;
43 43
44/* 44/*
45 * Data structure to hold the pointer to the mtd device as well 45 * Data structure to hold the pointer to the mtd device as well
46 * as mode information ofr various use cases. 46 * as mode information of various use cases.
47 */ 47 */
48struct mtd_file_info { 48struct mtd_file_info {
49 struct mtd_info *mtd; 49 struct mtd_info *mtd;
@@ -86,7 +86,7 @@ static int mtd_open(struct inode *inode, struct file *file)
86 struct mtd_file_info *mfi; 86 struct mtd_file_info *mfi;
87 struct inode *mtd_ino; 87 struct inode *mtd_ino;
88 88
89 DEBUG(MTD_DEBUG_LEVEL0, "MTD_open\n"); 89 pr_debug("MTD_open\n");
90 90
91 /* You can't open the RO devices RW */ 91 /* You can't open the RO devices RW */
92 if ((file->f_mode & FMODE_WRITE) && (minor & 1)) 92 if ((file->f_mode & FMODE_WRITE) && (minor & 1))
@@ -151,7 +151,7 @@ static int mtd_close(struct inode *inode, struct file *file)
151 struct mtd_file_info *mfi = file->private_data; 151 struct mtd_file_info *mfi = file->private_data;
152 struct mtd_info *mtd = mfi->mtd; 152 struct mtd_info *mtd = mfi->mtd;
153 153
154 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); 154 pr_debug("MTD_close\n");
155 155
156 /* Only sync if opened RW */ 156 /* Only sync if opened RW */
157 if ((file->f_mode & FMODE_WRITE) && mtd->sync) 157 if ((file->f_mode & FMODE_WRITE) && mtd->sync)
@@ -195,7 +195,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
195 size_t size = count; 195 size_t size = count;
196 char *kbuf; 196 char *kbuf;
197 197
198 DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n"); 198 pr_debug("MTD_read\n");
199 199
200 if (*ppos + count > mtd->size) 200 if (*ppos + count > mtd->size)
201 count = mtd->size - *ppos; 201 count = mtd->size - *ppos;
@@ -211,17 +211,17 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
211 len = min_t(size_t, count, size); 211 len = min_t(size_t, count, size);
212 212
213 switch (mfi->mode) { 213 switch (mfi->mode) {
214 case MTD_MODE_OTP_FACTORY: 214 case MTD_FILE_MODE_OTP_FACTORY:
215 ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); 215 ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
216 break; 216 break;
217 case MTD_MODE_OTP_USER: 217 case MTD_FILE_MODE_OTP_USER:
218 ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); 218 ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
219 break; 219 break;
220 case MTD_MODE_RAW: 220 case MTD_FILE_MODE_RAW:
221 { 221 {
222 struct mtd_oob_ops ops; 222 struct mtd_oob_ops ops;
223 223
224 ops.mode = MTD_OOB_RAW; 224 ops.mode = MTD_OPS_RAW;
225 ops.datbuf = kbuf; 225 ops.datbuf = kbuf;
226 ops.oobbuf = NULL; 226 ops.oobbuf = NULL;
227 ops.len = len; 227 ops.len = len;
@@ -233,16 +233,16 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
233 default: 233 default:
234 ret = mtd->read(mtd, *ppos, len, &retlen, kbuf); 234 ret = mtd->read(mtd, *ppos, len, &retlen, kbuf);
235 } 235 }
236 /* Nand returns -EBADMSG on ecc errors, but it returns 236 /* Nand returns -EBADMSG on ECC errors, but it returns
237 * the data. For our userspace tools it is important 237 * the data. For our userspace tools it is important
238 * to dump areas with ecc errors ! 238 * to dump areas with ECC errors!
239 * For kernel internal usage it also might return -EUCLEAN 239 * For kernel internal usage it also might return -EUCLEAN
240 * to signal the caller that a bitflip has occurred and has 240 * to signal the caller that a bitflip has occurred and has
241 * been corrected by the ECC algorithm. 241 * been corrected by the ECC algorithm.
242 * Userspace software which accesses NAND this way 242 * Userspace software which accesses NAND this way
243 * must be aware of the fact that it deals with NAND 243 * must be aware of the fact that it deals with NAND
244 */ 244 */
245 if (!ret || (ret == -EUCLEAN) || (ret == -EBADMSG)) { 245 if (!ret || mtd_is_bitflip_or_eccerr(ret)) {
246 *ppos += retlen; 246 *ppos += retlen;
247 if (copy_to_user(buf, kbuf, retlen)) { 247 if (copy_to_user(buf, kbuf, retlen)) {
248 kfree(kbuf); 248 kfree(kbuf);
@@ -278,7 +278,7 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
278 int ret=0; 278 int ret=0;
279 int len; 279 int len;
280 280
281 DEBUG(MTD_DEBUG_LEVEL0,"MTD_write\n"); 281 pr_debug("MTD_write\n");
282 282
283 if (*ppos == mtd->size) 283 if (*ppos == mtd->size)
284 return -ENOSPC; 284 return -ENOSPC;
@@ -302,10 +302,10 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
302 } 302 }
303 303
304 switch (mfi->mode) { 304 switch (mfi->mode) {
305 case MTD_MODE_OTP_FACTORY: 305 case MTD_FILE_MODE_OTP_FACTORY:
306 ret = -EROFS; 306 ret = -EROFS;
307 break; 307 break;
308 case MTD_MODE_OTP_USER: 308 case MTD_FILE_MODE_OTP_USER:
309 if (!mtd->write_user_prot_reg) { 309 if (!mtd->write_user_prot_reg) {
310 ret = -EOPNOTSUPP; 310 ret = -EOPNOTSUPP;
311 break; 311 break;
@@ -313,13 +313,14 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
313 ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); 313 ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
314 break; 314 break;
315 315
316 case MTD_MODE_RAW: 316 case MTD_FILE_MODE_RAW:
317 { 317 {
318 struct mtd_oob_ops ops; 318 struct mtd_oob_ops ops;
319 319
320 ops.mode = MTD_OOB_RAW; 320 ops.mode = MTD_OPS_RAW;
321 ops.datbuf = kbuf; 321 ops.datbuf = kbuf;
322 ops.oobbuf = NULL; 322 ops.oobbuf = NULL;
323 ops.ooboffs = 0;
323 ops.len = len; 324 ops.len = len;
324 325
325 ret = mtd->write_oob(mtd, *ppos, &ops); 326 ret = mtd->write_oob(mtd, *ppos, &ops);
@@ -367,13 +368,13 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
367 if (!mtd->read_fact_prot_reg) 368 if (!mtd->read_fact_prot_reg)
368 ret = -EOPNOTSUPP; 369 ret = -EOPNOTSUPP;
369 else 370 else
370 mfi->mode = MTD_MODE_OTP_FACTORY; 371 mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
371 break; 372 break;
372 case MTD_OTP_USER: 373 case MTD_OTP_USER:
373 if (!mtd->read_fact_prot_reg) 374 if (!mtd->read_fact_prot_reg)
374 ret = -EOPNOTSUPP; 375 ret = -EOPNOTSUPP;
375 else 376 else
376 mfi->mode = MTD_MODE_OTP_USER; 377 mfi->mode = MTD_FILE_MODE_OTP_USER;
377 break; 378 break;
378 default: 379 default:
379 ret = -EINVAL; 380 ret = -EINVAL;
@@ -390,6 +391,7 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
390 uint64_t start, uint32_t length, void __user *ptr, 391 uint64_t start, uint32_t length, void __user *ptr,
391 uint32_t __user *retp) 392 uint32_t __user *retp)
392{ 393{
394 struct mtd_file_info *mfi = file->private_data;
393 struct mtd_oob_ops ops; 395 struct mtd_oob_ops ops;
394 uint32_t retlen; 396 uint32_t retlen;
395 int ret = 0; 397 int ret = 0;
@@ -409,9 +411,10 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
409 return ret; 411 return ret;
410 412
411 ops.ooblen = length; 413 ops.ooblen = length;
412 ops.ooboffs = start & (mtd->oobsize - 1); 414 ops.ooboffs = start & (mtd->writesize - 1);
413 ops.datbuf = NULL; 415 ops.datbuf = NULL;
414 ops.mode = MTD_OOB_PLACE; 416 ops.mode = (mfi->mode == MTD_FILE_MODE_RAW) ? MTD_OPS_RAW :
417 MTD_OPS_PLACE_OOB;
415 418
416 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) 419 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
417 return -EINVAL; 420 return -EINVAL;
@@ -420,7 +423,7 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
420 if (IS_ERR(ops.oobbuf)) 423 if (IS_ERR(ops.oobbuf))
421 return PTR_ERR(ops.oobbuf); 424 return PTR_ERR(ops.oobbuf);
422 425
423 start &= ~((uint64_t)mtd->oobsize - 1); 426 start &= ~((uint64_t)mtd->writesize - 1);
424 ret = mtd->write_oob(mtd, start, &ops); 427 ret = mtd->write_oob(mtd, start, &ops);
425 428
426 if (ops.oobretlen > 0xFFFFFFFFU) 429 if (ops.oobretlen > 0xFFFFFFFFU)
@@ -433,9 +436,11 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd,
433 return ret; 436 return ret;
434} 437}
435 438
436static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start, 439static int mtd_do_readoob(struct file *file, struct mtd_info *mtd,
437 uint32_t length, void __user *ptr, uint32_t __user *retp) 440 uint64_t start, uint32_t length, void __user *ptr,
441 uint32_t __user *retp)
438{ 442{
443 struct mtd_file_info *mfi = file->private_data;
439 struct mtd_oob_ops ops; 444 struct mtd_oob_ops ops;
440 int ret = 0; 445 int ret = 0;
441 446
@@ -451,9 +456,10 @@ static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start,
451 return ret; 456 return ret;
452 457
453 ops.ooblen = length; 458 ops.ooblen = length;
454 ops.ooboffs = start & (mtd->oobsize - 1); 459 ops.ooboffs = start & (mtd->writesize - 1);
455 ops.datbuf = NULL; 460 ops.datbuf = NULL;
456 ops.mode = MTD_OOB_PLACE; 461 ops.mode = (mfi->mode == MTD_FILE_MODE_RAW) ? MTD_OPS_RAW :
462 MTD_OPS_PLACE_OOB;
457 463
458 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs)) 464 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
459 return -EINVAL; 465 return -EINVAL;
@@ -462,7 +468,7 @@ static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start,
462 if (!ops.oobbuf) 468 if (!ops.oobbuf)
463 return -ENOMEM; 469 return -ENOMEM;
464 470
465 start &= ~((uint64_t)mtd->oobsize - 1); 471 start &= ~((uint64_t)mtd->writesize - 1);
466 ret = mtd->read_oob(mtd, start, &ops); 472 ret = mtd->read_oob(mtd, start, &ops);
467 473
468 if (put_user(ops.oobretlen, retp)) 474 if (put_user(ops.oobretlen, retp))
@@ -472,13 +478,29 @@ static int mtd_do_readoob(struct mtd_info *mtd, uint64_t start,
472 ret = -EFAULT; 478 ret = -EFAULT;
473 479
474 kfree(ops.oobbuf); 480 kfree(ops.oobbuf);
481
482 /*
483 * NAND returns -EBADMSG on ECC errors, but it returns the OOB
484 * data. For our userspace tools it is important to dump areas
485 * with ECC errors!
486 * For kernel internal usage it also might return -EUCLEAN
487 * to signal the caller that a bitflip has occured and has
488 * been corrected by the ECC algorithm.
489 *
490 * Note: currently the standard NAND function, nand_read_oob_std,
491 * does not calculate ECC for the OOB area, so do not rely on
492 * this behavior unless you have replaced it with your own.
493 */
494 if (mtd_is_bitflip_or_eccerr(ret))
495 return 0;
496
475 return ret; 497 return ret;
476} 498}
477 499
478/* 500/*
479 * Copies (and truncates, if necessary) data from the larger struct, 501 * Copies (and truncates, if necessary) data from the larger struct,
480 * nand_ecclayout, to the smaller, deprecated layout struct, 502 * nand_ecclayout, to the smaller, deprecated layout struct,
481 * nand_ecclayout_user. This is necessary only to suppport the deprecated 503 * nand_ecclayout_user. This is necessary only to support the deprecated
482 * API ioctl ECCGETLAYOUT while allowing all new functionality to use 504 * API ioctl ECCGETLAYOUT while allowing all new functionality to use
483 * nand_ecclayout flexibly (i.e. the struct may change size in new 505 * nand_ecclayout flexibly (i.e. the struct may change size in new
484 * releases without requiring major rewrites). 506 * releases without requiring major rewrites).
@@ -544,6 +566,55 @@ static int mtd_blkpg_ioctl(struct mtd_info *mtd,
544 } 566 }
545} 567}
546 568
569static int mtd_write_ioctl(struct mtd_info *mtd,
570 struct mtd_write_req __user *argp)
571{
572 struct mtd_write_req req;
573 struct mtd_oob_ops ops;
574 void __user *usr_data, *usr_oob;
575 int ret;
576
577 if (copy_from_user(&req, argp, sizeof(req)) ||
578 !access_ok(VERIFY_READ, req.usr_data, req.len) ||
579 !access_ok(VERIFY_READ, req.usr_oob, req.ooblen))
580 return -EFAULT;
581 if (!mtd->write_oob)
582 return -EOPNOTSUPP;
583
584 ops.mode = req.mode;
585 ops.len = (size_t)req.len;
586 ops.ooblen = (size_t)req.ooblen;
587 ops.ooboffs = 0;
588
589 usr_data = (void __user *)(uintptr_t)req.usr_data;
590 usr_oob = (void __user *)(uintptr_t)req.usr_oob;
591
592 if (req.usr_data) {
593 ops.datbuf = memdup_user(usr_data, ops.len);
594 if (IS_ERR(ops.datbuf))
595 return PTR_ERR(ops.datbuf);
596 } else {
597 ops.datbuf = NULL;
598 }
599
600 if (req.usr_oob) {
601 ops.oobbuf = memdup_user(usr_oob, ops.ooblen);
602 if (IS_ERR(ops.oobbuf)) {
603 kfree(ops.datbuf);
604 return PTR_ERR(ops.oobbuf);
605 }
606 } else {
607 ops.oobbuf = NULL;
608 }
609
610 ret = mtd->write_oob(mtd, (loff_t)req.start, &ops);
611
612 kfree(ops.datbuf);
613 kfree(ops.oobbuf);
614
615 return ret;
616}
617
547static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) 618static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
548{ 619{
549 struct mtd_file_info *mfi = file->private_data; 620 struct mtd_file_info *mfi = file->private_data;
@@ -553,7 +624,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
553 u_long size; 624 u_long size;
554 struct mtd_info_user info; 625 struct mtd_info_user info;
555 626
556 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n"); 627 pr_debug("MTD_ioctl\n");
557 628
558 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT; 629 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
559 if (cmd & IOC_IN) { 630 if (cmd & IOC_IN) {
@@ -601,8 +672,8 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
601 info.erasesize = mtd->erasesize; 672 info.erasesize = mtd->erasesize;
602 info.writesize = mtd->writesize; 673 info.writesize = mtd->writesize;
603 info.oobsize = mtd->oobsize; 674 info.oobsize = mtd->oobsize;
604 /* The below fields are obsolete */ 675 /* The below field is obsolete */
605 info.ecctype = -1; 676 info.padding = 0;
606 if (copy_to_user(argp, &info, sizeof(struct mtd_info_user))) 677 if (copy_to_user(argp, &info, sizeof(struct mtd_info_user)))
607 return -EFAULT; 678 return -EFAULT;
608 break; 679 break;
@@ -698,7 +769,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
698 if (copy_from_user(&buf, argp, sizeof(buf))) 769 if (copy_from_user(&buf, argp, sizeof(buf)))
699 ret = -EFAULT; 770 ret = -EFAULT;
700 else 771 else
701 ret = mtd_do_readoob(mtd, buf.start, buf.length, 772 ret = mtd_do_readoob(file, mtd, buf.start, buf.length,
702 buf.ptr, &buf_user->start); 773 buf.ptr, &buf_user->start);
703 break; 774 break;
704 } 775 }
@@ -725,12 +796,19 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
725 if (copy_from_user(&buf, argp, sizeof(buf))) 796 if (copy_from_user(&buf, argp, sizeof(buf)))
726 ret = -EFAULT; 797 ret = -EFAULT;
727 else 798 else
728 ret = mtd_do_readoob(mtd, buf.start, buf.length, 799 ret = mtd_do_readoob(file, mtd, buf.start, buf.length,
729 (void __user *)(uintptr_t)buf.usr_ptr, 800 (void __user *)(uintptr_t)buf.usr_ptr,
730 &buf_user->length); 801 &buf_user->length);
731 break; 802 break;
732 } 803 }
733 804
805 case MEMWRITE:
806 {
807 ret = mtd_write_ioctl(mtd,
808 (struct mtd_write_req __user *)arg);
809 break;
810 }
811
734 case MEMLOCK: 812 case MEMLOCK:
735 { 813 {
736 struct erase_info_user einfo; 814 struct erase_info_user einfo;
@@ -827,7 +905,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
827 if (copy_from_user(&mode, argp, sizeof(int))) 905 if (copy_from_user(&mode, argp, sizeof(int)))
828 return -EFAULT; 906 return -EFAULT;
829 907
830 mfi->mode = MTD_MODE_NORMAL; 908 mfi->mode = MTD_FILE_MODE_NORMAL;
831 909
832 ret = otp_select_filemode(mfi, mode); 910 ret = otp_select_filemode(mfi, mode);
833 911
@@ -843,11 +921,11 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
843 return -ENOMEM; 921 return -ENOMEM;
844 ret = -EOPNOTSUPP; 922 ret = -EOPNOTSUPP;
845 switch (mfi->mode) { 923 switch (mfi->mode) {
846 case MTD_MODE_OTP_FACTORY: 924 case MTD_FILE_MODE_OTP_FACTORY:
847 if (mtd->get_fact_prot_info) 925 if (mtd->get_fact_prot_info)
848 ret = mtd->get_fact_prot_info(mtd, buf, 4096); 926 ret = mtd->get_fact_prot_info(mtd, buf, 4096);
849 break; 927 break;
850 case MTD_MODE_OTP_USER: 928 case MTD_FILE_MODE_OTP_USER:
851 if (mtd->get_user_prot_info) 929 if (mtd->get_user_prot_info)
852 ret = mtd->get_user_prot_info(mtd, buf, 4096); 930 ret = mtd->get_user_prot_info(mtd, buf, 4096);
853 break; 931 break;
@@ -871,7 +949,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
871 { 949 {
872 struct otp_info oinfo; 950 struct otp_info oinfo;
873 951
874 if (mfi->mode != MTD_MODE_OTP_USER) 952 if (mfi->mode != MTD_FILE_MODE_OTP_USER)
875 return -EINVAL; 953 return -EINVAL;
876 if (copy_from_user(&oinfo, argp, sizeof(oinfo))) 954 if (copy_from_user(&oinfo, argp, sizeof(oinfo)))
877 return -EFAULT; 955 return -EFAULT;
@@ -882,7 +960,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
882 } 960 }
883#endif 961#endif
884 962
885 /* This ioctl is being deprecated - it truncates the ecc layout */ 963 /* This ioctl is being deprecated - it truncates the ECC layout */
886 case ECCGETLAYOUT: 964 case ECCGETLAYOUT:
887 { 965 {
888 struct nand_ecclayout_user *usrlay; 966 struct nand_ecclayout_user *usrlay;
@@ -915,17 +993,17 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
915 mfi->mode = 0; 993 mfi->mode = 0;
916 994
917 switch(arg) { 995 switch(arg) {
918 case MTD_MODE_OTP_FACTORY: 996 case MTD_FILE_MODE_OTP_FACTORY:
919 case MTD_MODE_OTP_USER: 997 case MTD_FILE_MODE_OTP_USER:
920 ret = otp_select_filemode(mfi, arg); 998 ret = otp_select_filemode(mfi, arg);
921 break; 999 break;
922 1000
923 case MTD_MODE_RAW: 1001 case MTD_FILE_MODE_RAW:
924 if (!mtd->read_oob || !mtd->write_oob) 1002 if (!mtd->read_oob || !mtd->write_oob)
925 return -EOPNOTSUPP; 1003 return -EOPNOTSUPP;
926 mfi->mode = arg; 1004 mfi->mode = arg;
927 1005
928 case MTD_MODE_NORMAL: 1006 case MTD_FILE_MODE_NORMAL:
929 break; 1007 break;
930 default: 1008 default:
931 ret = -EINVAL; 1009 ret = -EINVAL;
@@ -1011,7 +1089,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd,
1011 if (copy_from_user(&buf, argp, sizeof(buf))) 1089 if (copy_from_user(&buf, argp, sizeof(buf)))
1012 ret = -EFAULT; 1090 ret = -EFAULT;
1013 else 1091 else
1014 ret = mtd_do_readoob(mtd, buf.start, 1092 ret = mtd_do_readoob(file, mtd, buf.start,
1015 buf.length, compat_ptr(buf.ptr), 1093 buf.length, compat_ptr(buf.ptr),
1016 &buf_user->start); 1094 &buf_user->start);
1017 break; 1095 break;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index e601672a530..6df4d4d4eb9 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -95,10 +95,10 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len,
95 95
96 /* Save information about bitflips! */ 96 /* Save information about bitflips! */
97 if (unlikely(err)) { 97 if (unlikely(err)) {
98 if (err == -EBADMSG) { 98 if (mtd_is_eccerr(err)) {
99 mtd->ecc_stats.failed++; 99 mtd->ecc_stats.failed++;
100 ret = err; 100 ret = err;
101 } else if (err == -EUCLEAN) { 101 } else if (mtd_is_bitflip(err)) {
102 mtd->ecc_stats.corrected++; 102 mtd->ecc_stats.corrected++;
103 /* Do not overwrite -EBADMSG !! */ 103 /* Do not overwrite -EBADMSG !! */
104 if (!ret) 104 if (!ret)
@@ -279,10 +279,10 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
279 279
280 /* Save information about bitflips! */ 280 /* Save information about bitflips! */
281 if (unlikely(err)) { 281 if (unlikely(err)) {
282 if (err == -EBADMSG) { 282 if (mtd_is_eccerr(err)) {
283 mtd->ecc_stats.failed++; 283 mtd->ecc_stats.failed++;
284 ret = err; 284 ret = err;
285 } else if (err == -EUCLEAN) { 285 } else if (mtd_is_bitflip(err)) {
286 mtd->ecc_stats.corrected++; 286 mtd->ecc_stats.corrected++;
287 /* Do not overwrite -EBADMSG !! */ 287 /* Do not overwrite -EBADMSG !! */
288 if (!ret) 288 if (!ret)
@@ -770,7 +770,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
770 770
771 /* 771 /*
772 * Set up the new "super" device's MTD object structure, check for 772 * Set up the new "super" device's MTD object structure, check for
773 * incompatibilites between the subdevices. 773 * incompatibilities between the subdevices.
774 */ 774 */
775 concat->mtd.type = subdev[0]->type; 775 concat->mtd.type = subdev[0]->type;
776 concat->mtd.flags = subdev[0]->flags; 776 concat->mtd.flags = subdev[0]->flags;
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c510aff289a..b01993ea260 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -362,7 +362,7 @@ int add_mtd_device(struct mtd_info *mtd)
362 MTD_DEVT(i) + 1, 362 MTD_DEVT(i) + 1,
363 NULL, "mtd%dro", i); 363 NULL, "mtd%dro", i);
364 364
365 DEBUG(0, "mtd: Giving out device %d to %s\n", i, mtd->name); 365 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
366 /* No need to get a refcount on the module containing 366 /* No need to get a refcount on the module containing
367 the notifier, since we hold the mtd_table_mutex */ 367 the notifier, since we hold the mtd_table_mutex */
368 list_for_each_entry(not, &mtd_notifiers, list) 368 list_for_each_entry(not, &mtd_notifiers, list)
@@ -429,27 +429,63 @@ out_error:
429} 429}
430 430
431/** 431/**
432 * mtd_device_register - register an MTD device. 432 * mtd_device_parse_register - parse partitions and register an MTD device.
433 * 433 *
434 * @master: the MTD device to register 434 * @mtd: the MTD device to register
435 * @parts: the partitions to register - only valid if nr_parts > 0 435 * @types: the list of MTD partition probes to try, see
436 * @nr_parts: the number of partitions in parts. If zero then the full MTD 436 * 'parse_mtd_partitions()' for more information
437 * device is registered 437 * @parser_data: MTD partition parser-specific data
438 * @parts: fallback partition information to register, if parsing fails;
439 * only valid if %nr_parts > %0
440 * @nr_parts: the number of partitions in parts, if zero then the full
441 * MTD device is registered if no partition info is found
438 * 442 *
439 * Register an MTD device with the system and optionally, a number of 443 * This function aggregates MTD partitions parsing (done by
440 * partitions. If nr_parts is 0 then the whole device is registered, otherwise 444 * 'parse_mtd_partitions()') and MTD device and partitions registering. It
441 * only the partitions are registered. To register both the full device *and* 445 * basically follows the most common pattern found in many MTD drivers:
442 * the partitions, call mtd_device_register() twice, once with nr_parts == 0 446 *
443 * and once equal to the number of partitions. 447 * * It first tries to probe partitions on MTD device @mtd using parsers
448 * specified in @types (if @types is %NULL, then the default list of parsers
449 * is used, see 'parse_mtd_partitions()' for more information). If none are
450 * found this functions tries to fallback to information specified in
451 * @parts/@nr_parts.
452 * * If any partitioning info was found, this function registers the found
453 * partitions.
454 * * If no partitions were found this function just registers the MTD device
455 * @mtd and exits.
456 *
457 * Returns zero in case of success and a negative error code in case of failure.
444 */ 458 */
445int mtd_device_register(struct mtd_info *master, 459int mtd_device_parse_register(struct mtd_info *mtd, const char **types,
446 const struct mtd_partition *parts, 460 struct mtd_part_parser_data *parser_data,
447 int nr_parts) 461 const struct mtd_partition *parts,
462 int nr_parts)
448{ 463{
449 return parts ? add_mtd_partitions(master, parts, nr_parts) : 464 int err;
450 add_mtd_device(master); 465 struct mtd_partition *real_parts;
466
467 err = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
468 if (err <= 0 && nr_parts && parts) {
469 real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
470 GFP_KERNEL);
471 if (!real_parts)
472 err = -ENOMEM;
473 else
474 err = nr_parts;
475 }
476
477 if (err > 0) {
478 err = add_mtd_partitions(mtd, real_parts, err);
479 kfree(real_parts);
480 } else if (err == 0) {
481 err = add_mtd_device(mtd);
482 if (err == 1)
483 err = -ENODEV;
484 }
485
486 return err;
451} 487}
452EXPORT_SYMBOL_GPL(mtd_device_register); 488EXPORT_SYMBOL_GPL(mtd_device_parse_register);
453 489
454/** 490/**
455 * mtd_device_unregister - unregister an existing MTD device. 491 * mtd_device_unregister - unregister an existing MTD device.
diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index 0ed6126b4c1..961a3840854 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -15,6 +15,9 @@ extern int del_mtd_device(struct mtd_info *mtd);
15extern int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, 15extern int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *,
16 int); 16 int);
17extern int del_mtd_partitions(struct mtd_info *); 17extern int del_mtd_partitions(struct mtd_info *);
18extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
19 struct mtd_partition **pparts,
20 struct mtd_part_parser_data *data);
18 21
19#define mtd_for_each_device(mtd) \ 22#define mtd_for_each_device(mtd) \
20 for ((mtd) = __mtd_next_device(0); \ 23 for ((mtd) = __mtd_next_device(0); \
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index e3e40f44032..1e2fa623670 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -258,7 +258,7 @@ static void find_next_position(struct mtdoops_context *cxt)
258 ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, 258 ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE,
259 &retlen, (u_char *) &count[0]); 259 &retlen, (u_char *) &count[0]);
260 if (retlen != MTDOOPS_HEADER_SIZE || 260 if (retlen != MTDOOPS_HEADER_SIZE ||
261 (ret < 0 && ret != -EUCLEAN)) { 261 (ret < 0 && !mtd_is_bitflip(ret))) {
262 printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n", 262 printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n",
263 page * record_size, retlen, 263 page * record_size, retlen,
264 MTDOOPS_HEADER_SIZE, ret); 264 MTDOOPS_HEADER_SIZE, ret);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 630be3e7da0..a0bd2de4752 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -73,9 +73,9 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
73 res = part->master->read(part->master, from + part->offset, 73 res = part->master->read(part->master, from + part->offset,
74 len, retlen, buf); 74 len, retlen, buf);
75 if (unlikely(res)) { 75 if (unlikely(res)) {
76 if (res == -EUCLEAN) 76 if (mtd_is_bitflip(res))
77 mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected; 77 mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected;
78 if (res == -EBADMSG) 78 if (mtd_is_eccerr(res))
79 mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed; 79 mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed;
80 } 80 }
81 return res; 81 return res;
@@ -130,7 +130,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
130 if (ops->oobbuf) { 130 if (ops->oobbuf) {
131 size_t len, pages; 131 size_t len, pages;
132 132
133 if (ops->mode == MTD_OOB_AUTO) 133 if (ops->mode == MTD_OPS_AUTO_OOB)
134 len = mtd->oobavail; 134 len = mtd->oobavail;
135 else 135 else
136 len = mtd->oobsize; 136 len = mtd->oobsize;
@@ -142,9 +142,9 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
142 142
143 res = part->master->read_oob(part->master, from + part->offset, ops); 143 res = part->master->read_oob(part->master, from + part->offset, ops);
144 if (unlikely(res)) { 144 if (unlikely(res)) {
145 if (res == -EUCLEAN) 145 if (mtd_is_bitflip(res))
146 mtd->ecc_stats.corrected++; 146 mtd->ecc_stats.corrected++;
147 if (res == -EBADMSG) 147 if (mtd_is_eccerr(res))
148 mtd->ecc_stats.failed++; 148 mtd->ecc_stats.failed++;
149 } 149 }
150 return res; 150 return res;
@@ -479,6 +479,19 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
479 (unsigned long long)cur_offset, (unsigned long long)slave->offset); 479 (unsigned long long)cur_offset, (unsigned long long)slave->offset);
480 } 480 }
481 } 481 }
482 if (slave->offset == MTDPART_OFS_RETAIN) {
483 slave->offset = cur_offset;
484 if (master->size - slave->offset >= slave->mtd.size) {
485 slave->mtd.size = master->size - slave->offset
486 - slave->mtd.size;
487 } else {
488 printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
489 part->name, master->size - slave->offset,
490 slave->mtd.size);
491 /* register to preserve ordering */
492 goto out_register;
493 }
494 }
482 if (slave->mtd.size == MTDPART_SIZ_FULL) 495 if (slave->mtd.size == MTDPART_SIZ_FULL)
483 slave->mtd.size = master->size - slave->offset; 496 slave->mtd.size = master->size - slave->offset;
484 497
@@ -693,6 +706,8 @@ static struct mtd_part_parser *get_partition_parser(const char *name)
693 return ret; 706 return ret;
694} 707}
695 708
709#define put_partition_parser(p) do { module_put((p)->owner); } while (0)
710
696int register_mtd_parser(struct mtd_part_parser *p) 711int register_mtd_parser(struct mtd_part_parser *p)
697{ 712{
698 spin_lock(&part_parser_lock); 713 spin_lock(&part_parser_lock);
@@ -712,19 +727,51 @@ int deregister_mtd_parser(struct mtd_part_parser *p)
712} 727}
713EXPORT_SYMBOL_GPL(deregister_mtd_parser); 728EXPORT_SYMBOL_GPL(deregister_mtd_parser);
714 729
730/*
731 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
732 * are changing this array!
733 */
734static const char *default_mtd_part_types[] = {
735 "cmdlinepart",
736 "ofpart",
737 NULL
738};
739
740/**
741 * parse_mtd_partitions - parse MTD partitions
742 * @master: the master partition (describes whole MTD device)
743 * @types: names of partition parsers to try or %NULL
744 * @pparts: array of partitions found is returned here
745 * @data: MTD partition parser-specific data
746 *
747 * This function tries to find partition on MTD device @master. It uses MTD
748 * partition parsers, specified in @types. However, if @types is %NULL, then
749 * the default list of parsers is used. The default list contains only the
750 * "cmdlinepart" and "ofpart" parsers ATM.
751 *
752 * This function may return:
753 * o a negative error code in case of failure
754 * o zero if no partitions were found
755 * o a positive number of found partitions, in which case on exit @pparts will
756 * point to an array containing this number of &struct mtd_info objects.
757 */
715int parse_mtd_partitions(struct mtd_info *master, const char **types, 758int parse_mtd_partitions(struct mtd_info *master, const char **types,
716 struct mtd_partition **pparts, unsigned long origin) 759 struct mtd_partition **pparts,
760 struct mtd_part_parser_data *data)
717{ 761{
718 struct mtd_part_parser *parser; 762 struct mtd_part_parser *parser;
719 int ret = 0; 763 int ret = 0;
720 764
765 if (!types)
766 types = default_mtd_part_types;
767
721 for ( ; ret <= 0 && *types; types++) { 768 for ( ; ret <= 0 && *types; types++) {
722 parser = get_partition_parser(*types); 769 parser = get_partition_parser(*types);
723 if (!parser && !request_module("%s", *types)) 770 if (!parser && !request_module("%s", *types))
724 parser = get_partition_parser(*types); 771 parser = get_partition_parser(*types);
725 if (!parser) 772 if (!parser)
726 continue; 773 continue;
727 ret = (*parser->parse_fn)(master, pparts, origin); 774 ret = (*parser->parse_fn)(master, pparts, data);
728 if (ret > 0) { 775 if (ret > 0) {
729 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", 776 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
730 ret, parser->name, master->name); 777 ret, parser->name, master->name);
@@ -733,7 +780,6 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types,
733 } 780 }
734 return ret; 781 return ret;
735} 782}
736EXPORT_SYMBOL_GPL(parse_mtd_partitions);
737 783
738int mtd_is_partition(struct mtd_info *mtd) 784int mtd_is_partition(struct mtd_info *mtd)
739{ 785{
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
index 16b02a1fc10..a90bfe79916 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
@@ -26,12 +27,12 @@ static int get_sb_mtd_compare(struct super_block *sb, void *_mtd)
26 struct mtd_info *mtd = _mtd; 27 struct mtd_info *mtd = _mtd;
27 28
28 if (sb->s_mtd == mtd) { 29 if (sb->s_mtd == mtd) {
29 DEBUG(2, "MTDSB: Match on device %d (\"%s\")\n", 30 pr_debug("MTDSB: Match on device %d (\"%s\")\n",
30 mtd->index, mtd->name); 31 mtd->index, mtd->name);
31 return 1; 32 return 1;
32 } 33 }
33 34
34 DEBUG(2, "MTDSB: No match, device %d (\"%s\"), device %d (\"%s\")\n", 35 pr_debug("MTDSB: No match, device %d (\"%s\"), device %d (\"%s\")\n",
35 sb->s_mtd->index, sb->s_mtd->name, mtd->index, mtd->name); 36 sb->s_mtd->index, sb->s_mtd->name, mtd->index, mtd->name);
36 return 0; 37 return 0;
37} 38}
@@ -70,7 +71,7 @@ static struct dentry *mount_mtd_aux(struct file_system_type *fs_type, int flags,
70 goto already_mounted; 71 goto already_mounted;
71 72
72 /* fresh new superblock */ 73 /* fresh new superblock */
73 DEBUG(1, "MTDSB: New superblock for device %d (\"%s\")\n", 74 pr_debug("MTDSB: New superblock for device %d (\"%s\")\n",
74 mtd->index, mtd->name); 75 mtd->index, mtd->name);
75 76
76 sb->s_flags = flags; 77 sb->s_flags = flags;
@@ -87,7 +88,7 @@ static struct dentry *mount_mtd_aux(struct file_system_type *fs_type, int flags,
87 88
88 /* new mountpoint for an already mounted superblock */ 89 /* new mountpoint for an already mounted superblock */
89already_mounted: 90already_mounted:
90 DEBUG(1, "MTDSB: Device %d (\"%s\") is already mounted\n", 91 pr_debug("MTDSB: Device %d (\"%s\") is already mounted\n",
91 mtd->index, mtd->name); 92 mtd->index, mtd->name);
92 put_mtd_device(mtd); 93 put_mtd_device(mtd);
93 return dget(sb->s_root); 94 return dget(sb->s_root);
@@ -108,7 +109,7 @@ static struct dentry *mount_mtd_nr(struct file_system_type *fs_type, int flags,
108 109
109 mtd = get_mtd_device(NULL, mtdnr); 110 mtd = get_mtd_device(NULL, mtdnr);
110 if (IS_ERR(mtd)) { 111 if (IS_ERR(mtd)) {
111 DEBUG(0, "MTDSB: Device #%u doesn't appear to exist\n", mtdnr); 112 pr_debug("MTDSB: Device #%u doesn't appear to exist\n", mtdnr);
112 return ERR_CAST(mtd); 113 return ERR_CAST(mtd);
113 } 114 }
114 115
@@ -131,7 +132,7 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,
131 if (!dev_name) 132 if (!dev_name)
132 return ERR_PTR(-EINVAL); 133 return ERR_PTR(-EINVAL);
133 134
134 DEBUG(2, "MTDSB: dev_name \"%s\"\n", dev_name); 135 pr_debug("MTDSB: dev_name \"%s\"\n", dev_name);
135 136
136 /* the preferred way of mounting in future; especially when 137 /* the preferred way of mounting in future; especially when
137 * CONFIG_BLOCK=n - we specify the underlying MTD device by number or 138 * CONFIG_BLOCK=n - we specify the underlying MTD device by number or
@@ -142,7 +143,7 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,
142 struct mtd_info *mtd; 143 struct mtd_info *mtd;
143 144
144 /* mount by MTD device name */ 145 /* mount by MTD device name */
145 DEBUG(1, "MTDSB: mtd:%%s, name \"%s\"\n", 146 pr_debug("MTDSB: mtd:%%s, name \"%s\"\n",
146 dev_name + 4); 147 dev_name + 4);
147 148
148 mtd = get_mtd_device_nm(dev_name + 4); 149 mtd = get_mtd_device_nm(dev_name + 4);
@@ -163,7 +164,7 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,
163 mtdnr = simple_strtoul(dev_name + 3, &endptr, 0); 164 mtdnr = simple_strtoul(dev_name + 3, &endptr, 0);
164 if (!*endptr) { 165 if (!*endptr) {
165 /* It was a valid number */ 166 /* It was a valid number */
166 DEBUG(1, "MTDSB: mtd%%d, mtdnr %d\n", 167 pr_debug("MTDSB: mtd%%d, mtdnr %d\n",
167 mtdnr); 168 mtdnr);
168 return mount_mtd_nr(fs_type, flags, 169 return mount_mtd_nr(fs_type, flags,
169 dev_name, data, 170 dev_name, data,
@@ -179,10 +180,10 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,
179 bdev = lookup_bdev(dev_name); 180 bdev = lookup_bdev(dev_name);
180 if (IS_ERR(bdev)) { 181 if (IS_ERR(bdev)) {
181 ret = PTR_ERR(bdev); 182 ret = PTR_ERR(bdev);
182 DEBUG(1, "MTDSB: lookup_bdev() returned %d\n", ret); 183 pr_debug("MTDSB: lookup_bdev() returned %d\n", ret);
183 return ERR_PTR(ret); 184 return ERR_PTR(ret);
184 } 185 }
185 DEBUG(1, "MTDSB: lookup_bdev() returned 0\n"); 186 pr_debug("MTDSB: lookup_bdev() returned 0\n");
186 187
187 ret = -EINVAL; 188 ret = -EINVAL;
188 189
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index fd788532761..bd9590c723e 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -86,7 +86,7 @@ struct swap_eb {
86 unsigned int flags; 86 unsigned int flags;
87 unsigned int active_count; 87 unsigned int active_count;
88 unsigned int erase_count; 88 unsigned int erase_count;
89 unsigned int pad; /* speeds up pointer decremtnt */ 89 unsigned int pad; /* speeds up pointer decrement */
90}; 90};
91 91
92#define MTDSWAP_ECNT_MIN(rbroot) (rb_entry(rb_first(rbroot), struct swap_eb, \ 92#define MTDSWAP_ECNT_MIN(rbroot) (rb_entry(rb_first(rbroot), struct swap_eb, \
@@ -314,7 +314,7 @@ static int mtdswap_read_oob(struct mtdswap_dev *d, loff_t from,
314{ 314{
315 int ret = d->mtd->read_oob(d->mtd, from, ops); 315 int ret = d->mtd->read_oob(d->mtd, from, ops);
316 316
317 if (ret == -EUCLEAN) 317 if (mtd_is_bitflip(ret))
318 return ret; 318 return ret;
319 319
320 if (ret) { 320 if (ret) {
@@ -350,11 +350,11 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
350 ops.oobbuf = d->oob_buf; 350 ops.oobbuf = d->oob_buf;
351 ops.ooboffs = 0; 351 ops.ooboffs = 0;
352 ops.datbuf = NULL; 352 ops.datbuf = NULL;
353 ops.mode = MTD_OOB_AUTO; 353 ops.mode = MTD_OPS_AUTO_OOB;
354 354
355 ret = mtdswap_read_oob(d, offset, &ops); 355 ret = mtdswap_read_oob(d, offset, &ops);
356 356
357 if (ret && ret != -EUCLEAN) 357 if (ret && !mtd_is_bitflip(ret))
358 return ret; 358 return ret;
359 359
360 data = (struct mtdswap_oobdata *)d->oob_buf; 360 data = (struct mtdswap_oobdata *)d->oob_buf;
@@ -363,7 +363,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb)
363 363
364 if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) { 364 if (le16_to_cpu(data->magic) == MTDSWAP_MAGIC_CLEAN) {
365 eb->erase_count = le32_to_cpu(data->count); 365 eb->erase_count = le32_to_cpu(data->count);
366 if (ret == -EUCLEAN) 366 if (mtd_is_bitflip(ret))
367 ret = MTDSWAP_SCANNED_BITFLIP; 367 ret = MTDSWAP_SCANNED_BITFLIP;
368 else { 368 else {
369 if (le16_to_cpu(data2->magic) == MTDSWAP_MAGIC_DIRTY) 369 if (le16_to_cpu(data2->magic) == MTDSWAP_MAGIC_DIRTY)
@@ -389,7 +389,7 @@ static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb,
389 389
390 ops.ooboffs = 0; 390 ops.ooboffs = 0;
391 ops.oobbuf = (uint8_t *)&n; 391 ops.oobbuf = (uint8_t *)&n;
392 ops.mode = MTD_OOB_AUTO; 392 ops.mode = MTD_OPS_AUTO_OOB;
393 ops.datbuf = NULL; 393 ops.datbuf = NULL;
394 394
395 if (marker == MTDSWAP_TYPE_CLEAN) { 395 if (marker == MTDSWAP_TYPE_CLEAN) {
@@ -408,7 +408,7 @@ static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb,
408 if (ret) { 408 if (ret) {
409 dev_warn(d->dev, "Write OOB failed for block at %08llx " 409 dev_warn(d->dev, "Write OOB failed for block at %08llx "
410 "error %d\n", offset, ret); 410 "error %d\n", offset, ret);
411 if (ret == -EIO || ret == -EBADMSG) 411 if (ret == -EIO || mtd_is_eccerr(ret))
412 mtdswap_handle_write_error(d, eb); 412 mtdswap_handle_write_error(d, eb);
413 return ret; 413 return ret;
414 } 414 }
@@ -628,7 +628,7 @@ static int mtdswap_map_free_block(struct mtdswap_dev *d, unsigned int page,
628 TREE_COUNT(d, CLEAN)--; 628 TREE_COUNT(d, CLEAN)--;
629 629
630 ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_DIRTY); 630 ret = mtdswap_write_marker(d, eb, MTDSWAP_TYPE_DIRTY);
631 } while (ret == -EIO || ret == -EBADMSG); 631 } while (ret == -EIO || mtd_is_eccerr(ret));
632 632
633 if (ret) 633 if (ret)
634 return ret; 634 return ret;
@@ -678,7 +678,7 @@ retry:
678 ret = mtdswap_map_free_block(d, page, bp); 678 ret = mtdswap_map_free_block(d, page, bp);
679 eb = d->eb_data + (*bp / d->pages_per_eblk); 679 eb = d->eb_data + (*bp / d->pages_per_eblk);
680 680
681 if (ret == -EIO || ret == -EBADMSG) { 681 if (ret == -EIO || mtd_is_eccerr(ret)) {
682 d->curr_write = NULL; 682 d->curr_write = NULL;
683 eb->active_count--; 683 eb->active_count--;
684 d->revmap[*bp] = PAGE_UNDEF; 684 d->revmap[*bp] = PAGE_UNDEF;
@@ -690,7 +690,7 @@ retry:
690 690
691 writepos = (loff_t)*bp << PAGE_SHIFT; 691 writepos = (loff_t)*bp << PAGE_SHIFT;
692 ret = mtd->write(mtd, writepos, PAGE_SIZE, &retlen, buf); 692 ret = mtd->write(mtd, writepos, PAGE_SIZE, &retlen, buf);
693 if (ret == -EIO || ret == -EBADMSG) { 693 if (ret == -EIO || mtd_is_eccerr(ret)) {
694 d->curr_write_pos--; 694 d->curr_write_pos--;
695 eb->active_count--; 695 eb->active_count--;
696 d->revmap[*bp] = PAGE_UNDEF; 696 d->revmap[*bp] = PAGE_UNDEF;
@@ -738,7 +738,7 @@ static int mtdswap_move_block(struct mtdswap_dev *d, unsigned int oldblock,
738retry: 738retry:
739 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf); 739 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf);
740 740
741 if (ret < 0 && ret != -EUCLEAN) { 741 if (ret < 0 && !mtd_is_bitflip(ret)) {
742 oldeb = d->eb_data + oldblock / d->pages_per_eblk; 742 oldeb = d->eb_data + oldblock / d->pages_per_eblk;
743 oldeb->flags |= EBLOCK_READERR; 743 oldeb->flags |= EBLOCK_READERR;
744 744
@@ -931,7 +931,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev *d,
931 struct mtd_oob_ops ops; 931 struct mtd_oob_ops ops;
932 int ret; 932 int ret;
933 933
934 ops.mode = MTD_OOB_AUTO; 934 ops.mode = MTD_OPS_AUTO_OOB;
935 ops.len = mtd->writesize; 935 ops.len = mtd->writesize;
936 ops.ooblen = mtd->ecclayout->oobavail; 936 ops.ooblen = mtd->ecclayout->oobavail;
937 ops.ooboffs = 0; 937 ops.ooboffs = 0;
@@ -1016,7 +1016,7 @@ static int mtdswap_gc(struct mtdswap_dev *d, unsigned int background)
1016 1016
1017 if (ret == 0) 1017 if (ret == 0)
1018 mtdswap_rb_add(d, eb, MTDSWAP_CLEAN); 1018 mtdswap_rb_add(d, eb, MTDSWAP_CLEAN);
1019 else if (ret != -EIO && ret != -EBADMSG) 1019 else if (ret != -EIO && !mtd_is_eccerr(ret))
1020 mtdswap_rb_add(d, eb, MTDSWAP_DIRTY); 1020 mtdswap_rb_add(d, eb, MTDSWAP_DIRTY);
1021 1021
1022 return 0; 1022 return 0;
@@ -1164,7 +1164,7 @@ retry:
1164 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf); 1164 ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf);
1165 1165
1166 d->mtd_read_count++; 1166 d->mtd_read_count++;
1167 if (ret == -EUCLEAN) { 1167 if (mtd_is_bitflip(ret)) {
1168 eb->flags |= EBLOCK_BITFLIP; 1168 eb->flags |= EBLOCK_BITFLIP;
1169 mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP); 1169 mtdswap_rb_add(d, eb, MTDSWAP_BITFLIP);
1170 ret = 0; 1170 ret = 0;
@@ -1374,11 +1374,10 @@ static int mtdswap_init(struct mtdswap_dev *d, unsigned int eblocks,
1374 goto revmap_fail; 1374 goto revmap_fail;
1375 1375
1376 eblk_bytes = sizeof(struct swap_eb)*d->eblks; 1376 eblk_bytes = sizeof(struct swap_eb)*d->eblks;
1377 d->eb_data = vmalloc(eblk_bytes); 1377 d->eb_data = vzalloc(eblk_bytes);
1378 if (!d->eb_data) 1378 if (!d->eb_data)
1379 goto eb_data_fail; 1379 goto eb_data_fail;
1380 1380
1381 memset(d->eb_data, 0, eblk_bytes);
1382 for (i = 0; i < pages; i++) 1381 for (i = 0; i < pages; i++)
1383 d->page_data[i] = BLOCK_UNDEF; 1382 d->page_data[i] = BLOCK_UNDEF;
1384 1383
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 4c3425235ad..cce7b70824c 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -83,16 +83,9 @@ config MTD_NAND_DENALI_SCRATCH_REG_ADDR
83 scratch register here to enable this feature. On Intel Moorestown 83 scratch register here to enable this feature. On Intel Moorestown
84 boards, the scratch register is at 0xFF108018. 84 boards, the scratch register is at 0xFF108018.
85 85
86config MTD_NAND_EDB7312
87 tristate "Support for Cirrus Logic EBD7312 evaluation board"
88 depends on ARCH_EDB7312
89 help
90 This enables the driver for the Cirrus Logic EBD7312 evaluation
91 board to access the onboard NAND Flash.
92
93config MTD_NAND_H1900 86config MTD_NAND_H1900
94 tristate "iPAQ H1900 flash" 87 tristate "iPAQ H1900 flash"
95 depends on ARCH_PXA 88 depends on ARCH_PXA && BROKEN
96 help 89 help
97 This enables the driver for the iPAQ h1900 flash. 90 This enables the driver for the iPAQ h1900 flash.
98 91
@@ -116,10 +109,11 @@ config MTD_NAND_AMS_DELTA
116 Support for NAND flash on Amstrad E3 (Delta). 109 Support for NAND flash on Amstrad E3 (Delta).
117 110
118config MTD_NAND_OMAP2 111config MTD_NAND_OMAP2
119 tristate "NAND Flash device on OMAP2 and OMAP3" 112 tristate "NAND Flash device on OMAP2, OMAP3 and OMAP4"
120 depends on ARM && (ARCH_OMAP2 || ARCH_OMAP3) 113 depends on ARM && (ARCH_OMAP2 || ARCH_OMAP3 || ARCH_OMAP4)
121 help 114 help
122 Support for NAND flash on Texas Instruments OMAP2 and OMAP3 platforms. 115 Support for NAND flash on Texas Instruments OMAP2, OMAP3 and OMAP4
116 platforms.
123 117
124config MTD_NAND_IDS 118config MTD_NAND_IDS
125 tristate 119 tristate
@@ -138,7 +132,7 @@ config MTD_NAND_RICOH
138 132
139config MTD_NAND_AU1550 133config MTD_NAND_AU1550
140 tristate "Au1550/1200 NAND support" 134 tristate "Au1550/1200 NAND support"
141 depends on SOC_AU1200 || SOC_AU1550 135 depends on MIPS_ALCHEMY
142 help 136 help
143 This enables the driver for the NAND flash controller on the 137 This enables the driver for the NAND flash controller on the
144 AMD/Alchemy 1550 SOC. 138 AMD/Alchemy 1550 SOC.
@@ -423,6 +417,19 @@ config MTD_NAND_NANDSIM
423 The simulator may simulate various NAND flash chips for the 417 The simulator may simulate various NAND flash chips for the
424 MTD nand layer. 418 MTD nand layer.
425 419
420config MTD_NAND_GPMI_NAND
421 bool "GPMI NAND Flash Controller driver"
422 depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28)
423 select MTD_PARTITIONS
424 select MTD_CMDLINE_PARTS
425 help
426 Enables NAND Flash support for IMX23 or IMX28.
427 The GPMI controller is very powerful, with the help of BCH
428 module, it can do the hardware ECC. The GPMI supports several
429 NAND flashs at the same time. The GPMI may conflicts with other
430 block, such as SD card. So pay attention to it when you enable
431 the GPMI.
432
426config MTD_NAND_PLATFORM 433config MTD_NAND_PLATFORM
427 tristate "Support for generic platform NAND driver" 434 tristate "Support for generic platform NAND driver"
428 help 435 help
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 5745d831168..618f4ba2369 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -13,7 +13,6 @@ obj-$(CONFIG_MTD_NAND_SPIA) += spia.o
13obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o 13obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o
14obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o 14obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o
15obj-$(CONFIG_MTD_NAND_DENALI) += denali.o 15obj-$(CONFIG_MTD_NAND_DENALI) += denali.o
16obj-$(CONFIG_MTD_NAND_EDB7312) += edb7312.o
17obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o 16obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o
18obj-$(CONFIG_MTD_NAND_BF5XX) += bf5xx_nand.o 17obj-$(CONFIG_MTD_NAND_BF5XX) += bf5xx_nand.o
19obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o 18obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o
@@ -49,5 +48,6 @@ obj-$(CONFIG_MTD_NAND_BCM_UMI) += bcm_umi_nand.o nand_bcm_umi.o
49obj-$(CONFIG_MTD_NAND_MPC5121_NFC) += mpc5121_nfc.o 48obj-$(CONFIG_MTD_NAND_MPC5121_NFC) += mpc5121_nfc.o
50obj-$(CONFIG_MTD_NAND_RICOH) += r852.o 49obj-$(CONFIG_MTD_NAND_RICOH) += r852.o
51obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o 50obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o
51obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/
52 52
53nand-objs := nand_base.o nand_bbt.o 53nand-objs := nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 55da20ccc7a..23e5d77c39f 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -161,37 +161,6 @@ static int atmel_nand_device_ready(struct mtd_info *mtd)
161 !!host->board->rdy_pin_active_low; 161 !!host->board->rdy_pin_active_low;
162} 162}
163 163
164/*
165 * Minimal-overhead PIO for data access.
166 */
167static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len)
168{
169 struct nand_chip *nand_chip = mtd->priv;
170
171 __raw_readsb(nand_chip->IO_ADDR_R, buf, len);
172}
173
174static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
175{
176 struct nand_chip *nand_chip = mtd->priv;
177
178 __raw_readsw(nand_chip->IO_ADDR_R, buf, len / 2);
179}
180
181static void atmel_write_buf8(struct mtd_info *mtd, const u8 *buf, int len)
182{
183 struct nand_chip *nand_chip = mtd->priv;
184
185 __raw_writesb(nand_chip->IO_ADDR_W, buf, len);
186}
187
188static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len)
189{
190 struct nand_chip *nand_chip = mtd->priv;
191
192 __raw_writesw(nand_chip->IO_ADDR_W, buf, len / 2);
193}
194
195static void dma_complete_func(void *completion) 164static void dma_complete_func(void *completion)
196{ 165{
197 complete(completion); 166 complete(completion);
@@ -266,33 +235,27 @@ err_buf:
266static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len) 235static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
267{ 236{
268 struct nand_chip *chip = mtd->priv; 237 struct nand_chip *chip = mtd->priv;
269 struct atmel_nand_host *host = chip->priv;
270 238
271 if (use_dma && len > mtd->oobsize) 239 if (use_dma && len > mtd->oobsize)
272 /* only use DMA for bigger than oob size: better performances */ 240 /* only use DMA for bigger than oob size: better performances */
273 if (atmel_nand_dma_op(mtd, buf, len, 1) == 0) 241 if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
274 return; 242 return;
275 243
276 if (host->board->bus_width_16) 244 /* if no DMA operation possible, use PIO */
277 atmel_read_buf16(mtd, buf, len); 245 memcpy_fromio(buf, chip->IO_ADDR_R, len);
278 else
279 atmel_read_buf8(mtd, buf, len);
280} 246}
281 247
282static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len) 248static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
283{ 249{
284 struct nand_chip *chip = mtd->priv; 250 struct nand_chip *chip = mtd->priv;
285 struct atmel_nand_host *host = chip->priv;
286 251
287 if (use_dma && len > mtd->oobsize) 252 if (use_dma && len > mtd->oobsize)
288 /* only use DMA for bigger than oob size: better performances */ 253 /* only use DMA for bigger than oob size: better performances */
289 if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0) 254 if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
290 return; 255 return;
291 256
292 if (host->board->bus_width_16) 257 /* if no DMA operation possible, use PIO */
293 atmel_write_buf16(mtd, buf, len); 258 memcpy_toio(chip->IO_ADDR_W, buf, len);
294 else
295 atmel_write_buf8(mtd, buf, len);
296} 259}
297 260
298/* 261/*
@@ -481,10 +444,6 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
481 } 444 }
482} 445}
483 446
484#ifdef CONFIG_MTD_CMDLINE_PARTS
485static const char *part_probes[] = { "cmdlinepart", NULL };
486#endif
487
488/* 447/*
489 * Probe for the NAND device. 448 * Probe for the NAND device.
490 */ 449 */
@@ -496,8 +455,6 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
496 struct resource *regs; 455 struct resource *regs;
497 struct resource *mem; 456 struct resource *mem;
498 int res; 457 int res;
499 struct mtd_partition *partitions = NULL;
500 int num_partitions = 0;
501 458
502 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 459 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
503 if (!mem) { 460 if (!mem) {
@@ -583,7 +540,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
583 540
584 if (on_flash_bbt) { 541 if (on_flash_bbt) {
585 printk(KERN_INFO "atmel_nand: Use On Flash BBT\n"); 542 printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
586 nand_chip->options |= NAND_USE_FLASH_BBT; 543 nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
587 } 544 }
588 545
589 if (!cpu_has_dma()) 546 if (!cpu_has_dma())
@@ -594,7 +551,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
594 551
595 dma_cap_zero(mask); 552 dma_cap_zero(mask);
596 dma_cap_set(DMA_MEMCPY, mask); 553 dma_cap_set(DMA_MEMCPY, mask);
597 host->dma_chan = dma_request_channel(mask, 0, NULL); 554 host->dma_chan = dma_request_channel(mask, NULL, NULL);
598 if (!host->dma_chan) { 555 if (!host->dma_chan) {
599 dev_err(host->dev, "Failed to request DMA channel\n"); 556 dev_err(host->dev, "Failed to request DMA channel\n");
600 use_dma = 0; 557 use_dma = 0;
@@ -655,27 +612,12 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
655 goto err_scan_tail; 612 goto err_scan_tail;
656 } 613 }
657 614
658#ifdef CONFIG_MTD_CMDLINE_PARTS
659 mtd->name = "atmel_nand"; 615 mtd->name = "atmel_nand";
660 num_partitions = parse_mtd_partitions(mtd, part_probes, 616 res = mtd_device_parse_register(mtd, NULL, 0,
661 &partitions, 0); 617 host->board->parts, host->board->num_parts);
662#endif
663 if (num_partitions <= 0 && host->board->partition_info)
664 partitions = host->board->partition_info(mtd->size,
665 &num_partitions);
666
667 if ((!partitions) || (num_partitions == 0)) {
668 printk(KERN_ERR "atmel_nand: No partitions defined, or unsupported device.\n");
669 res = -ENXIO;
670 goto err_no_partitions;
671 }
672
673 res = mtd_device_register(mtd, partitions, num_partitions);
674 if (!res) 618 if (!res)
675 return res; 619 return res;
676 620
677err_no_partitions:
678 nand_release(mtd);
679err_scan_tail: 621err_scan_tail:
680err_scan_ident: 622err_scan_ident:
681err_no_card: 623err_no_card:
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index e7767eef450..7dd3700f230 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/*
@@ -48,7 +52,7 @@ static const struct mtd_partition partition_info[] = {
48 * au_read_byte - read one byte from the chip 52 * au_read_byte - read one byte from the chip
49 * @mtd: MTD device structure 53 * @mtd: MTD device structure
50 * 54 *
51 * read function for 8bit buswith 55 * read function for 8bit buswidth
52 */ 56 */
53static u_char au_read_byte(struct mtd_info *mtd) 57static u_char au_read_byte(struct mtd_info *mtd)
54{ 58{
@@ -63,7 +67,7 @@ static u_char au_read_byte(struct mtd_info *mtd)
63 * @mtd: MTD device structure 67 * @mtd: MTD device structure
64 * @byte: pointer to data byte to write 68 * @byte: pointer to data byte to write
65 * 69 *
66 * write function for 8it buswith 70 * write function for 8it buswidth
67 */ 71 */
68static void au_write_byte(struct mtd_info *mtd, u_char byte) 72static void au_write_byte(struct mtd_info *mtd, u_char byte)
69{ 73{
@@ -73,11 +77,10 @@ static void au_write_byte(struct mtd_info *mtd, u_char byte)
73} 77}
74 78
75/** 79/**
76 * au_read_byte16 - read one byte endianess aware from the chip 80 * au_read_byte16 - read one byte endianness aware from the chip
77 * @mtd: MTD device structure 81 * @mtd: MTD device structure
78 * 82 *
79 * read function for 16bit buswith with 83 * read function for 16bit buswidth with endianness conversion
80 * endianess conversion
81 */ 84 */
82static u_char au_read_byte16(struct mtd_info *mtd) 85static u_char au_read_byte16(struct mtd_info *mtd)
83{ 86{
@@ -88,12 +91,11 @@ static u_char au_read_byte16(struct mtd_info *mtd)
88} 91}
89 92
90/** 93/**
91 * au_write_byte16 - write one byte endianess aware to the chip 94 * au_write_byte16 - write one byte endianness aware to the chip
92 * @mtd: MTD device structure 95 * @mtd: MTD device structure
93 * @byte: pointer to data byte to write 96 * @byte: pointer to data byte to write
94 * 97 *
95 * write function for 16bit buswith with 98 * write function for 16bit buswidth with endianness conversion
96 * endianess conversion
97 */ 99 */
98static void au_write_byte16(struct mtd_info *mtd, u_char byte) 100static void au_write_byte16(struct mtd_info *mtd, u_char byte)
99{ 101{
@@ -106,8 +108,7 @@ static void au_write_byte16(struct mtd_info *mtd, u_char byte)
106 * au_read_word - read one word from the chip 108 * au_read_word - read one word from the chip
107 * @mtd: MTD device structure 109 * @mtd: MTD device structure
108 * 110 *
109 * read function for 16bit buswith without 111 * read function for 16bit buswidth without endianness conversion
110 * endianess conversion
111 */ 112 */
112static u16 au_read_word(struct mtd_info *mtd) 113static u16 au_read_word(struct mtd_info *mtd)
113{ 114{
@@ -123,7 +124,7 @@ static u16 au_read_word(struct mtd_info *mtd)
123 * @buf: data buffer 124 * @buf: data buffer
124 * @len: number of bytes to write 125 * @len: number of bytes to write
125 * 126 *
126 * write function for 8bit buswith 127 * write function for 8bit buswidth
127 */ 128 */
128static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 129static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
129{ 130{
@@ -142,7 +143,7 @@ static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
142 * @buf: buffer to store date 143 * @buf: buffer to store date
143 * @len: number of bytes to read 144 * @len: number of bytes to read
144 * 145 *
145 * read function for 8bit buswith 146 * read function for 8bit buswidth
146 */ 147 */
147static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len) 148static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
148{ 149{
@@ -161,7 +162,7 @@ static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
161 * @buf: buffer containing the data to compare 162 * @buf: buffer containing the data to compare
162 * @len: number of bytes to compare 163 * @len: number of bytes to compare
163 * 164 *
164 * verify function for 8bit buswith 165 * verify function for 8bit buswidth
165 */ 166 */
166static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) 167static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
167{ 168{
@@ -183,7 +184,7 @@ static int au_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
183 * @buf: data buffer 184 * @buf: data buffer
184 * @len: number of bytes to write 185 * @len: number of bytes to write
185 * 186 *
186 * write function for 16bit buswith 187 * write function for 16bit buswidth
187 */ 188 */
188static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len) 189static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
189{ 190{
@@ -205,7 +206,7 @@ static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
205 * @buf: buffer to store date 206 * @buf: buffer to store date
206 * @len: number of bytes to read 207 * @len: number of bytes to read
207 * 208 *
208 * read function for 16bit buswith 209 * read function for 16bit buswidth
209 */ 210 */
210static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len) 211static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
211{ 212{
@@ -226,7 +227,7 @@ static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
226 * @buf: buffer containing the data to compare 227 * @buf: buffer containing the data to compare
227 * @len: number of bytes to compare 228 * @len: number of bytes to compare
228 * 229 *
229 * verify function for 16bit buswith 230 * verify function for 16bit buswidth
230 */ 231 */
231static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) 232static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len)
232{ 233{
diff --git a/drivers/mtd/nand/autcpu12.c b/drivers/mtd/nand/autcpu12.c
index eddc9a22498..2e42ec2e8ff 100644
--- a/drivers/mtd/nand/autcpu12.c
+++ b/drivers/mtd/nand/autcpu12.c
@@ -172,9 +172,9 @@ static int __init autcpu12_init(void)
172 172
173 /* Enable the following for a flash based bad block table */ 173 /* Enable the following for a flash based bad block table */
174 /* 174 /*
175 this->options = NAND_USE_FLASH_BBT; 175 this->bbt_options = NAND_BBT_USE_FLASH;
176 */ 176 */
177 this->options = NAND_USE_FLASH_BBT; 177 this->bbt_options = NAND_BBT_USE_FLASH;
178 178
179 /* Scan to find existence of the device */ 179 /* Scan to find existence of the device */
180 if (nand_scan(autcpu12_mtd, 1)) { 180 if (nand_scan(autcpu12_mtd, 1)) {
diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
index 8c569e454dc..46b58d67284 100644
--- a/drivers/mtd/nand/bcm_umi_nand.c
+++ b/drivers/mtd/nand/bcm_umi_nand.c
@@ -52,8 +52,6 @@
52static const __devinitconst char gBanner[] = KERN_INFO \ 52static const __devinitconst char gBanner[] = KERN_INFO \
53 "BCM UMI MTD NAND Driver: 1.00\n"; 53 "BCM UMI MTD NAND Driver: 1.00\n";
54 54
55const char *part_probes[] = { "cmdlinepart", NULL };
56
57#if NAND_ECC_BCH 55#if NAND_ECC_BCH
58static uint8_t scan_ff_pattern[] = { 0xff }; 56static uint8_t scan_ff_pattern[] = { 0xff };
59 57
@@ -376,16 +374,18 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
376 374
377 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 375 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
378 376
379 if (!r) 377 if (!r) {
380 return -ENXIO; 378 err = -ENXIO;
379 goto out_free;
380 }
381 381
382 /* map physical address */ 382 /* map physical address */
383 bcm_umi_io_base = ioremap(r->start, resource_size(r)); 383 bcm_umi_io_base = ioremap(r->start, resource_size(r));
384 384
385 if (!bcm_umi_io_base) { 385 if (!bcm_umi_io_base) {
386 printk(KERN_ERR "ioremap to access BCM UMI NAND chip failed\n"); 386 printk(KERN_ERR "ioremap to access BCM UMI NAND chip failed\n");
387 kfree(board_mtd); 387 err = -EIO;
388 return -EIO; 388 goto out_free;
389 } 389 }
390 390
391 /* Get pointer to private data */ 391 /* Get pointer to private data */
@@ -401,9 +401,8 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
401 /* Initialize the NAND hardware. */ 401 /* Initialize the NAND hardware. */
402 if (bcm_umi_nand_inithw() < 0) { 402 if (bcm_umi_nand_inithw() < 0) {
403 printk(KERN_ERR "BCM UMI NAND chip could not be initialized\n"); 403 printk(KERN_ERR "BCM UMI NAND chip could not be initialized\n");
404 iounmap(bcm_umi_io_base); 404 err = -EIO;
405 kfree(board_mtd); 405 goto out_unmap;
406 return -EIO;
407 } 406 }
408 407
409 /* Set address of NAND IO lines */ 408 /* Set address of NAND IO lines */
@@ -436,7 +435,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
436#if USE_DMA 435#if USE_DMA
437 err = nand_dma_init(); 436 err = nand_dma_init();
438 if (err != 0) 437 if (err != 0)
439 return err; 438 goto out_unmap;
440#endif 439#endif
441 440
442 /* Figure out the size of the device that we have. 441 /* Figure out the size of the device that we have.
@@ -447,9 +446,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
447 err = nand_scan_ident(board_mtd, 1, NULL); 446 err = nand_scan_ident(board_mtd, 1, NULL);
448 if (err) { 447 if (err) {
449 printk(KERN_ERR "nand_scan failed: %d\n", err); 448 printk(KERN_ERR "nand_scan failed: %d\n", err);
450 iounmap(bcm_umi_io_base); 449 goto out_unmap;
451 kfree(board_mtd);
452 return err;
453 } 450 }
454 451
455 /* Now that we know the nand size, we can setup the ECC layout */ 452 /* Now that we know the nand size, we can setup the ECC layout */
@@ -468,13 +465,14 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
468 { 465 {
469 printk(KERN_ERR "NAND - Unrecognized pagesize: %d\n", 466 printk(KERN_ERR "NAND - Unrecognized pagesize: %d\n",
470 board_mtd->writesize); 467 board_mtd->writesize);
471 return -EINVAL; 468 err = -EINVAL;
469 goto out_unmap;
472 } 470 }
473 } 471 }
474 472
475#if NAND_ECC_BCH 473#if NAND_ECC_BCH
476 if (board_mtd->writesize > 512) { 474 if (board_mtd->writesize > 512) {
477 if (this->options & NAND_USE_FLASH_BBT) 475 if (this->bbt_options & NAND_BBT_USE_FLASH)
478 largepage_bbt.options = NAND_BBT_SCAN2NDPAGE; 476 largepage_bbt.options = NAND_BBT_SCAN2NDPAGE;
479 this->badblock_pattern = &largepage_bbt; 477 this->badblock_pattern = &largepage_bbt;
480 } 478 }
@@ -485,33 +483,20 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
485 err = nand_scan_tail(board_mtd); 483 err = nand_scan_tail(board_mtd);
486 if (err) { 484 if (err) {
487 printk(KERN_ERR "nand_scan failed: %d\n", err); 485 printk(KERN_ERR "nand_scan failed: %d\n", err);
488 iounmap(bcm_umi_io_base); 486 goto out_unmap;
489 kfree(board_mtd);
490 return err;
491 } 487 }
492 488
493 /* Register the partitions */ 489 /* Register the partitions */
494 { 490 board_mtd->name = "bcm_umi-nand";
495 int nr_partitions; 491 mtd_device_parse_register(board_mtd, NULL, 0, NULL, 0);
496 struct mtd_partition *partition_info;
497
498 board_mtd->name = "bcm_umi-nand";
499 nr_partitions =
500 parse_mtd_partitions(board_mtd, part_probes,
501 &partition_info, 0);
502
503 if (nr_partitions <= 0) {
504 printk(KERN_ERR "BCM UMI NAND: Too few partitions - %d\n",
505 nr_partitions);
506 iounmap(bcm_umi_io_base);
507 kfree(board_mtd);
508 return -EIO;
509 }
510 mtd_device_register(board_mtd, partition_info, nr_partitions);
511 }
512 492
513 /* Return happy */ 493 /* Return happy */
514 return 0; 494 return 0;
495out_unmap:
496 iounmap(bcm_umi_io_base);
497out_free:
498 kfree(board_mtd);
499 return err;
515} 500}
516 501
517static int bcm_umi_nand_remove(struct platform_device *pdev) 502static int bcm_umi_nand_remove(struct platform_device *pdev)
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 87ebb4e5b0c..72d3f23490c 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
@@ -57,7 +58,6 @@
57 58
58struct cafe_priv { 59struct cafe_priv {
59 struct nand_chip nand; 60 struct nand_chip nand;
60 struct mtd_partition *parts;
61 struct pci_dev *pdev; 61 struct pci_dev *pdev;
62 void __iomem *mmio; 62 void __iomem *mmio;
63 struct rs_control *rs; 63 struct rs_control *rs;
@@ -371,7 +371,7 @@ static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
371 return 1; 371 return 1;
372} 372}
373/** 373/**
374 * cafe_nand_read_page_syndrome - {REPLACABLE] hardware ecc syndrom based page read 374 * cafe_nand_read_page_syndrome - [REPLACEABLE] hardware ecc syndrome based page read
375 * @mtd: mtd info structure 375 * @mtd: mtd info structure
376 * @chip: nand chip info structure 376 * @chip: nand chip info structure
377 * @buf: buffer to store read data 377 * @buf: buffer to store read data
@@ -630,8 +630,6 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
630 struct cafe_priv *cafe; 630 struct cafe_priv *cafe;
631 uint32_t ctrl; 631 uint32_t ctrl;
632 int err = 0; 632 int err = 0;
633 struct mtd_partition *parts;
634 int nr_parts;
635 633
636 /* Very old versions shared the same PCI ident for all three 634 /* Very old versions shared the same PCI ident for all three
637 functions on the chip. Verify the class too... */ 635 functions on the chip. Verify the class too... */
@@ -686,7 +684,8 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
686 cafe->nand.chip_delay = 0; 684 cafe->nand.chip_delay = 0;
687 685
688 /* Enable the following for a flash based bad block table */ 686 /* Enable the following for a flash based bad block table */
689 cafe->nand.options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR | NAND_OWN_BUFFERS; 687 cafe->nand.bbt_options = NAND_BBT_USE_FLASH;
688 cafe->nand.options = NAND_NO_AUTOINCR | NAND_OWN_BUFFERS;
690 689
691 if (skipbbt) { 690 if (skipbbt) {
692 cafe->nand.options |= NAND_SKIP_BBTSCAN; 691 cafe->nand.options |= NAND_SKIP_BBTSCAN;
@@ -799,18 +798,9 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
799 798
800 pci_set_drvdata(pdev, mtd); 799 pci_set_drvdata(pdev, mtd);
801 800
802 /* We register the whole device first, separate from the partitions */
803 mtd_device_register(mtd, NULL, 0);
804
805#ifdef CONFIG_MTD_CMDLINE_PARTS
806 mtd->name = "cafe_nand"; 801 mtd->name = "cafe_nand";
807#endif 802 mtd_device_parse_register(mtd, part_probes, 0, NULL, 0);
808 nr_parts = parse_mtd_partitions(mtd, part_probes, &parts, 0); 803
809 if (nr_parts > 0) {
810 cafe->parts = parts;
811 dev_info(&cafe->pdev->dev, "%d partitions found\n", nr_parts);
812 mtd_device_register(mtd, parts, nr_parts);
813 }
814 goto out; 804 goto out;
815 805
816 out_irq: 806 out_irq:
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 6fc043a30d1..737ef9a04fd 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>
@@ -50,8 +51,6 @@ static struct mtd_partition partition_info[] = {
50}; 51};
51#define NUM_PARTITIONS (ARRAY_SIZE(partition_info)) 52#define NUM_PARTITIONS (ARRAY_SIZE(partition_info))
52 53
53const char *part_probes[] = { "cmdlinepart", NULL };
54
55static u_char cmx270_read_byte(struct mtd_info *mtd) 54static u_char cmx270_read_byte(struct mtd_info *mtd)
56{ 55{
57 struct nand_chip *this = mtd->priv; 56 struct nand_chip *this = mtd->priv;
@@ -151,9 +150,6 @@ static int cmx270_device_ready(struct mtd_info *mtd)
151static int __init cmx270_init(void) 150static int __init cmx270_init(void)
152{ 151{
153 struct nand_chip *this; 152 struct nand_chip *this;
154 const char *part_type;
155 struct mtd_partition *mtd_parts;
156 int mtd_parts_nb = 0;
157 int ret; 153 int ret;
158 154
159 if (!(machine_is_armcore() && cpu_is_pxa27x())) 155 if (!(machine_is_armcore() && cpu_is_pxa27x()))
@@ -222,23 +218,9 @@ static int __init cmx270_init(void)
222 goto err_scan; 218 goto err_scan;
223 } 219 }
224 220
225#ifdef CONFIG_MTD_CMDLINE_PARTS
226 mtd_parts_nb = parse_mtd_partitions(cmx270_nand_mtd, part_probes,
227 &mtd_parts, 0);
228 if (mtd_parts_nb > 0)
229 part_type = "command line";
230 else
231 mtd_parts_nb = 0;
232#endif
233 if (!mtd_parts_nb) {
234 mtd_parts = partition_info;
235 mtd_parts_nb = NUM_PARTITIONS;
236 part_type = "static";
237 }
238
239 /* Register the partitions */ 221 /* Register the partitions */
240 pr_notice("Using %s partition definition\n", part_type); 222 ret = mtd_device_parse_register(cmx270_nand_mtd, NULL, 0,
241 ret = mtd_device_register(cmx270_nand_mtd, mtd_parts, mtd_parts_nb); 223 partition_info, NUM_PARTITIONS);
242 if (ret) 224 if (ret)
243 goto err_scan; 225 goto err_scan;
244 226
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index f59ad1f2d5d..414afa79356 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -239,7 +239,8 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
239 this->ecc.correct = nand_correct_data; 239 this->ecc.correct = nand_correct_data;
240 240
241 /* Enable the following for a flash based bad block table */ 241 /* Enable the following for a flash based bad block table */
242 this->options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR; 242 this->bbt_options = NAND_BBT_USE_FLASH;
243 this->options = NAND_NO_AUTOINCR;
243 244
244 /* Scan to find existence of the device */ 245 /* Scan to find existence of the device */
245 if (nand_scan(new_mtd, 1)) { 246 if (nand_scan(new_mtd, 1)) {
@@ -277,15 +278,11 @@ static int is_geode(void)
277 return 0; 278 return 0;
278} 279}
279 280
280static const char *part_probes[] = { "cmdlinepart", NULL };
281
282static int __init cs553x_init(void) 281static int __init cs553x_init(void)
283{ 282{
284 int err = -ENXIO; 283 int err = -ENXIO;
285 int i; 284 int i;
286 uint64_t val; 285 uint64_t val;
287 int mtd_parts_nb = 0;
288 struct mtd_partition *mtd_parts = NULL;
289 286
290 /* If the CPU isn't a Geode GX or LX, abort */ 287 /* If the CPU isn't a Geode GX or LX, abort */
291 if (!is_geode()) 288 if (!is_geode())
@@ -315,13 +312,9 @@ static int __init cs553x_init(void)
315 do mtdconcat etc. if we want to. */ 312 do mtdconcat etc. if we want to. */
316 for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { 313 for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
317 if (cs553x_mtd[i]) { 314 if (cs553x_mtd[i]) {
318
319 /* If any devices registered, return success. Else the last error. */ 315 /* If any devices registered, return success. Else the last error. */
320 mtd_parts_nb = parse_mtd_partitions(cs553x_mtd[i], part_probes, &mtd_parts, 0); 316 mtd_device_parse_register(cs553x_mtd[i], NULL, 0,
321 if (mtd_parts_nb > 0) 317 NULL, 0);
322 printk(KERN_NOTICE "Using command line partition definition\n");
323 mtd_device_register(cs553x_mtd[i], mtd_parts,
324 mtd_parts_nb);
325 err = 0; 318 err = 0;
326 } 319 }
327 } 320 }
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 1f34951ae1a..c153e1f77f9 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -57,7 +57,6 @@ struct davinci_nand_info {
57 57
58 struct device *dev; 58 struct device *dev;
59 struct clk *clk; 59 struct clk *clk;
60 bool partitioned;
61 60
62 bool is_readmode; 61 bool is_readmode;
63 62
@@ -530,8 +529,6 @@ static int __init nand_davinci_probe(struct platform_device *pdev)
530 int ret; 529 int ret;
531 uint32_t val; 530 uint32_t val;
532 nand_ecc_modes_t ecc_mode; 531 nand_ecc_modes_t ecc_mode;
533 struct mtd_partition *mtd_parts = NULL;
534 int mtd_parts_nb = 0;
535 532
536 /* insist on board-specific configuration */ 533 /* insist on board-specific configuration */
537 if (!pdata) 534 if (!pdata)
@@ -581,7 +578,9 @@ static int __init nand_davinci_probe(struct platform_device *pdev)
581 info->chip.chip_delay = 0; 578 info->chip.chip_delay = 0;
582 info->chip.select_chip = nand_davinci_select_chip; 579 info->chip.select_chip = nand_davinci_select_chip;
583 580
584 /* options such as NAND_USE_FLASH_BBT or 16-bit widths */ 581 /* options such as NAND_BBT_USE_FLASH */
582 info->chip.bbt_options = pdata->bbt_options;
583 /* options such as 16-bit widths */
585 info->chip.options = pdata->options; 584 info->chip.options = pdata->options;
586 info->chip.bbt_td = pdata->bbt_td; 585 info->chip.bbt_td = pdata->bbt_td;
587 info->chip.bbt_md = pdata->bbt_md; 586 info->chip.bbt_md = pdata->bbt_md;
@@ -751,33 +750,8 @@ syndrome_done:
751 if (ret < 0) 750 if (ret < 0)
752 goto err_scan; 751 goto err_scan;
753 752
754 if (mtd_has_cmdlinepart()) { 753 ret = mtd_device_parse_register(&info->mtd, NULL, 0,
755 static const char *probes[] __initconst = { 754 pdata->parts, pdata->nr_parts);
756 "cmdlinepart", NULL
757 };
758
759 mtd_parts_nb = parse_mtd_partitions(&info->mtd, probes,
760 &mtd_parts, 0);
761 }
762
763 if (mtd_parts_nb <= 0) {
764 mtd_parts = pdata->parts;
765 mtd_parts_nb = pdata->nr_parts;
766 }
767
768 /* Register any partitions */
769 if (mtd_parts_nb > 0) {
770 ret = mtd_device_register(&info->mtd, mtd_parts,
771 mtd_parts_nb);
772 if (ret == 0)
773 info->partitioned = true;
774 }
775
776 /* If there's no partition info, just package the whole chip
777 * as a single MTD device.
778 */
779 if (!info->partitioned)
780 ret = mtd_device_register(&info->mtd, NULL, 0) ? -ENODEV : 0;
781 755
782 if (ret < 0) 756 if (ret < 0)
783 goto err_scan; 757 goto err_scan;
@@ -816,9 +790,6 @@ err_nomem:
816static int __exit nand_davinci_remove(struct platform_device *pdev) 790static int __exit nand_davinci_remove(struct platform_device *pdev)
817{ 791{
818 struct davinci_nand_info *info = platform_get_drvdata(pdev); 792 struct davinci_nand_info *info = platform_get_drvdata(pdev);
819 int status;
820
821 status = mtd_device_unregister(&info->mtd);
822 793
823 spin_lock_irq(&davinci_nand_lock); 794 spin_lock_irq(&davinci_nand_lock);
824 if (info->chip.ecc.mode == NAND_ECC_HW_SYNDROME) 795 if (info->chip.ecc.mode == NAND_ECC_HW_SYNDROME)
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index d5276218945..3984d488f9a 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1346,6 +1346,7 @@ static void denali_hw_init(struct denali_nand_info *denali)
1346 * */ 1346 * */
1347 denali->bbtskipbytes = ioread32(denali->flash_reg + 1347 denali->bbtskipbytes = ioread32(denali->flash_reg +
1348 SPARE_AREA_SKIP_BYTES); 1348 SPARE_AREA_SKIP_BYTES);
1349 detect_max_banks(denali);
1349 denali_nand_reset(denali); 1350 denali_nand_reset(denali);
1350 iowrite32(0x0F, denali->flash_reg + RB_PIN_ENABLED); 1351 iowrite32(0x0F, denali->flash_reg + RB_PIN_ENABLED);
1351 iowrite32(CHIP_EN_DONT_CARE__FLAG, 1352 iowrite32(CHIP_EN_DONT_CARE__FLAG,
@@ -1356,7 +1357,6 @@ static void denali_hw_init(struct denali_nand_info *denali)
1356 /* Should set value for these registers when init */ 1357 /* Should set value for these registers when init */
1357 iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES); 1358 iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES);
1358 iowrite32(1, denali->flash_reg + ECC_ENABLE); 1359 iowrite32(1, denali->flash_reg + ECC_ENABLE);
1359 detect_max_banks(denali);
1360 denali_nand_timing_set(denali); 1360 denali_nand_timing_set(denali);
1361 denali_irq_init(denali); 1361 denali_irq_init(denali);
1362} 1362}
@@ -1577,7 +1577,8 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1577 denali->nand.bbt_md = &bbt_mirror_descr; 1577 denali->nand.bbt_md = &bbt_mirror_descr;
1578 1578
1579 /* skip the scan for now until we have OOB read and write support */ 1579 /* skip the scan for now until we have OOB read and write support */
1580 denali->nand.options |= NAND_USE_FLASH_BBT | NAND_SKIP_BBTSCAN; 1580 denali->nand.bbt_options |= NAND_BBT_USE_FLASH;
1581 denali->nand.options |= NAND_SKIP_BBTSCAN;
1581 denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME; 1582 denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
1582 1583
1583 /* Denali Controller only support 15bit and 8bit ECC in MRST, 1584 /* Denali Controller only support 15bit and 8bit ECC in MRST,
@@ -1676,7 +1677,6 @@ static void denali_pci_remove(struct pci_dev *dev)
1676 struct denali_nand_info *denali = pci_get_drvdata(dev); 1677 struct denali_nand_info *denali = pci_get_drvdata(dev);
1677 1678
1678 nand_release(&denali->mtd); 1679 nand_release(&denali->mtd);
1679 mtd_device_unregister(&denali->mtd);
1680 1680
1681 denali_irq_cleanup(dev->irq, denali); 1681 denali_irq_cleanup(dev->irq, denali);
1682 1682
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 7837728d02f..5780dbab611 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
@@ -132,7 +133,7 @@ static struct rs_control *rs_decoder;
132 133
133/* 134/*
134 * The HW decoder in the DoC ASIC's provides us a error syndrome, 135 * The HW decoder in the DoC ASIC's provides us a error syndrome,
135 * which we must convert to a standard syndrom usable by the generic 136 * which we must convert to a standard syndrome usable by the generic
136 * Reed-Solomon library code. 137 * Reed-Solomon library code.
137 * 138 *
138 * Fabrice Bellard figured this out in the old docecc code. I added 139 * Fabrice Bellard figured this out in the old docecc code. I added
@@ -153,7 +154,7 @@ static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc)
153 ds[3] = ((ecc[3] & 0xc0) >> 6) | ((ecc[0] & 0xff) << 2); 154 ds[3] = ((ecc[3] & 0xc0) >> 6) | ((ecc[0] & 0xff) << 2);
154 parity = ecc[1]; 155 parity = ecc[1];
155 156
156 /* Initialize the syndrom buffer */ 157 /* Initialize the syndrome buffer */
157 for (i = 0; i < NROOTS; i++) 158 for (i = 0; i < NROOTS; i++)
158 s[i] = ds[0]; 159 s[i] = ds[0];
159 /* 160 /*
@@ -1031,7 +1032,7 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
1031 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); 1032 WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf);
1032 else 1033 else
1033 WriteDOC(DOC_ECC_DIS, docptr, ECCConf); 1034 WriteDOC(DOC_ECC_DIS, docptr, ECCConf);
1034 if (no_ecc_failures && (ret == -EBADMSG)) { 1035 if (no_ecc_failures && mtd_is_eccerr(ret)) {
1035 printk(KERN_ERR "suppressing ECC failure\n"); 1036 printk(KERN_ERR "suppressing ECC failure\n");
1036 ret = 0; 1037 ret = 0;
1037 } 1038 }
@@ -1652,7 +1653,7 @@ static int __init doc_probe(unsigned long physadr)
1652 nand->ecc.mode = NAND_ECC_HW_SYNDROME; 1653 nand->ecc.mode = NAND_ECC_HW_SYNDROME;
1653 nand->ecc.size = 512; 1654 nand->ecc.size = 512;
1654 nand->ecc.bytes = 6; 1655 nand->ecc.bytes = 6;
1655 nand->options = NAND_USE_FLASH_BBT; 1656 nand->bbt_options = NAND_BBT_USE_FLASH;
1656 1657
1657 doc->physadr = physadr; 1658 doc->physadr = physadr;
1658 doc->virtadr = virtadr; 1659 doc->virtadr = virtadr;
diff --git a/drivers/mtd/nand/edb7312.c b/drivers/mtd/nand/edb7312.c
deleted file mode 100644
index 8400d0f6dad..00000000000
--- a/drivers/mtd/nand/edb7312.c
+++ /dev/null
@@ -1,203 +0,0 @@
1/*
2 * drivers/mtd/nand/edb7312.c
3 *
4 * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
5 *
6 * Derived from drivers/mtd/nand/autcpu12.c
7 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * Overview:
14 * This is a device driver for the NAND flash device found on the
15 * CLEP7312 board which utilizes the Toshiba TC58V64AFT part. This is
16 * a 64Mibit (8MiB x 8 bits) NAND flash device.
17 */
18
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/mtd/mtd.h>
23#include <linux/mtd/nand.h>
24#include <linux/mtd/partitions.h>
25#include <asm/io.h>
26#include <mach/hardware.h> /* for CLPS7111_VIRT_BASE */
27#include <asm/sizes.h>
28#include <asm/hardware/clps7111.h>
29
30/*
31 * MTD structure for EDB7312 board
32 */
33static struct mtd_info *ep7312_mtd = NULL;
34
35/*
36 * Values specific to the EDB7312 board (used with EP7312 processor)
37 */
38#define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */
39#define EP7312_PXDR 0x0001 /*
40 * IO offset to Port B data register
41 * where the CLE, ALE and NCE pins
42 * are wired to.
43 */
44#define EP7312_PXDDR 0x0041 /*
45 * IO offset to Port B data direction
46 * register so we can control the IO
47 * lines.
48 */
49
50/*
51 * Module stuff
52 */
53
54static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE;
55static void __iomem *ep7312_pxdr = (void __iomem *)EP7312_PXDR;
56static void __iomem *ep7312_pxddr = (void __iomem *)EP7312_PXDDR;
57
58/*
59 * Define static partitions for flash device
60 */
61static struct mtd_partition partition_info[] = {
62 {.name = "EP7312 Nand Flash",
63 .offset = 0,
64 .size = 8 * 1024 * 1024}
65};
66
67#define NUM_PARTITIONS 1
68
69/*
70 * hardware specific access to control-lines
71 *
72 * NAND_NCE: bit 0 -> bit 6 (bit 7 = 1)
73 * NAND_CLE: bit 1 -> bit 4
74 * NAND_ALE: bit 2 -> bit 5
75 */
76static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
77{
78 struct nand_chip *chip = mtd->priv;
79
80 if (ctrl & NAND_CTRL_CHANGE) {
81 unsigned char bits = 0x80;
82
83 bits |= (ctrl & (NAND_CLE | NAND_ALE)) << 3;
84 bits |= (ctrl & NAND_NCE) ? 0x00 : 0x40;
85
86 clps_writeb((clps_readb(ep7312_pxdr) & 0xF0) | bits,
87 ep7312_pxdr);
88 }
89 if (cmd != NAND_CMD_NONE)
90 writeb(cmd, chip->IO_ADDR_W);
91}
92
93/*
94 * read device ready pin
95 */
96static int ep7312_device_ready(struct mtd_info *mtd)
97{
98 return 1;
99}
100
101const char *part_probes[] = { "cmdlinepart", NULL };
102
103/*
104 * Main initialization routine
105 */
106static int __init ep7312_init(void)
107{
108 struct nand_chip *this;
109 const char *part_type = 0;
110 int mtd_parts_nb = 0;
111 struct mtd_partition *mtd_parts = 0;
112 void __iomem *ep7312_fio_base;
113
114 /* Allocate memory for MTD device structure and private data */
115 ep7312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
116 if (!ep7312_mtd) {
117 printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
118 return -ENOMEM;
119 }
120
121 /* map physical address */
122 ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
123 if (!ep7312_fio_base) {
124 printk("ioremap EDB7312 NAND flash failed\n");
125 kfree(ep7312_mtd);
126 return -EIO;
127 }
128
129 /* Get pointer to private data */
130 this = (struct nand_chip *)(&ep7312_mtd[1]);
131
132 /* Initialize structures */
133 memset(ep7312_mtd, 0, sizeof(struct mtd_info));
134 memset(this, 0, sizeof(struct nand_chip));
135
136 /* Link the private data with the MTD structure */
137 ep7312_mtd->priv = this;
138 ep7312_mtd->owner = THIS_MODULE;
139
140 /*
141 * Set GPIO Port B control register so that the pins are configured
142 * to be outputs for controlling the NAND flash.
143 */
144 clps_writeb(0xf0, ep7312_pxddr);
145
146 /* insert callbacks */
147 this->IO_ADDR_R = ep7312_fio_base;
148 this->IO_ADDR_W = ep7312_fio_base;
149 this->cmd_ctrl = ep7312_hwcontrol;
150 this->dev_ready = ep7312_device_ready;
151 /* 15 us command delay time */
152 this->chip_delay = 15;
153
154 /* Scan to find existence of the device */
155 if (nand_scan(ep7312_mtd, 1)) {
156 iounmap((void *)ep7312_fio_base);
157 kfree(ep7312_mtd);
158 return -ENXIO;
159 }
160 ep7312_mtd->name = "edb7312-nand";
161 mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
162 if (mtd_parts_nb > 0)
163 part_type = "command line";
164 else
165 mtd_parts_nb = 0;
166 if (mtd_parts_nb == 0) {
167 mtd_parts = partition_info;
168 mtd_parts_nb = NUM_PARTITIONS;
169 part_type = "static";
170 }
171
172 /* Register the partitions */
173 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
174 mtd_device_register(ep7312_mtd, mtd_parts, mtd_parts_nb);
175
176 /* Return happy */
177 return 0;
178}
179
180module_init(ep7312_init);
181
182/*
183 * Clean up routine
184 */
185static void __exit ep7312_cleanup(void)
186{
187 struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1];
188
189 /* Release resources, unregister device */
190 nand_release(ap7312_mtd);
191
192 /* Release io resource */
193 iounmap(this->IO_ADDR_R);
194
195 /* Free the MTD device structure */
196 kfree(ep7312_mtd);
197}
198
199module_exit(ep7312_cleanup);
200
201MODULE_LICENSE("GPL");
202MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
203MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 33d8aad8bba..eedd8ee2c9a 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -75,7 +75,6 @@ struct fsl_elbc_fcm_ctrl {
75 unsigned int use_mdr; /* Non zero if the MDR is to be set */ 75 unsigned int use_mdr; /* Non zero if the MDR is to be set */
76 unsigned int oob; /* Non zero if operating on OOB data */ 76 unsigned int oob; /* Non zero if operating on OOB data */
77 unsigned int counter; /* counter for the initializations */ 77 unsigned int counter; /* counter for the initializations */
78 char *oob_poi; /* Place to write ECC after read back */
79}; 78};
80 79
81/* These map to the positions used by the FCM hardware ECC generator */ 80/* These map to the positions used by the FCM hardware ECC generator */
@@ -244,6 +243,25 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
244 return -EIO; 243 return -EIO;
245 } 244 }
246 245
246 if (chip->ecc.mode != NAND_ECC_HW)
247 return 0;
248
249 if (elbc_fcm_ctrl->read_bytes == mtd->writesize + mtd->oobsize) {
250 uint32_t lteccr = in_be32(&lbc->lteccr);
251 /*
252 * if command was a full page read and the ELBC
253 * has the LTECCR register, then bits 12-15 (ppc order) of
254 * LTECCR indicates which 512 byte sub-pages had fixed errors.
255 * bits 28-31 are uncorrectable errors, marked elsewhere.
256 * for small page nand only 1 bit is used.
257 * if the ELBC doesn't have the lteccr register it reads 0
258 */
259 if (lteccr & 0x000F000F)
260 out_be32(&lbc->lteccr, 0x000F000F); /* clear lteccr */
261 if (lteccr & 0x000F0000)
262 mtd->ecc_stats.corrected++;
263 }
264
247 return 0; 265 return 0;
248} 266}
249 267
@@ -435,7 +453,6 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command,
435 453
436 /* PAGEPROG reuses all of the setup from SEQIN and adds the length */ 454 /* PAGEPROG reuses all of the setup from SEQIN and adds the length */
437 case NAND_CMD_PAGEPROG: { 455 case NAND_CMD_PAGEPROG: {
438 int full_page;
439 dev_vdbg(priv->dev, 456 dev_vdbg(priv->dev,
440 "fsl_elbc_cmdfunc: NAND_CMD_PAGEPROG " 457 "fsl_elbc_cmdfunc: NAND_CMD_PAGEPROG "
441 "writing %d bytes.\n", elbc_fcm_ctrl->index); 458 "writing %d bytes.\n", elbc_fcm_ctrl->index);
@@ -445,34 +462,12 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command,
445 * write so the HW generates the ECC. 462 * write so the HW generates the ECC.
446 */ 463 */
447 if (elbc_fcm_ctrl->oob || elbc_fcm_ctrl->column != 0 || 464 if (elbc_fcm_ctrl->oob || elbc_fcm_ctrl->column != 0 ||
448 elbc_fcm_ctrl->index != mtd->writesize + mtd->oobsize) { 465 elbc_fcm_ctrl->index != mtd->writesize + mtd->oobsize)
449 out_be32(&lbc->fbcr, elbc_fcm_ctrl->index); 466 out_be32(&lbc->fbcr, elbc_fcm_ctrl->index);
450 full_page = 0; 467 else
451 } else {
452 out_be32(&lbc->fbcr, 0); 468 out_be32(&lbc->fbcr, 0);
453 full_page = 1;
454 }
455 469
456 fsl_elbc_run_command(mtd); 470 fsl_elbc_run_command(mtd);
457
458 /* Read back the page in order to fill in the ECC for the
459 * caller. Is this really needed?
460 */
461 if (full_page && elbc_fcm_ctrl->oob_poi) {
462 out_be32(&lbc->fbcr, 3);
463 set_addr(mtd, 6, page_addr, 1);
464
465 elbc_fcm_ctrl->read_bytes = mtd->writesize + 9;
466
467 fsl_elbc_do_read(chip, 1);
468 fsl_elbc_run_command(mtd);
469
470 memcpy_fromio(elbc_fcm_ctrl->oob_poi + 6,
471 &elbc_fcm_ctrl->addr[elbc_fcm_ctrl->index], 3);
472 elbc_fcm_ctrl->index += 3;
473 }
474
475 elbc_fcm_ctrl->oob_poi = NULL;
476 return; 471 return;
477 } 472 }
478 473
@@ -752,13 +747,8 @@ static void fsl_elbc_write_page(struct mtd_info *mtd,
752 struct nand_chip *chip, 747 struct nand_chip *chip,
753 const uint8_t *buf) 748 const uint8_t *buf)
754{ 749{
755 struct fsl_elbc_mtd *priv = chip->priv;
756 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
757
758 fsl_elbc_write_buf(mtd, buf, mtd->writesize); 750 fsl_elbc_write_buf(mtd, buf, mtd->writesize);
759 fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize); 751 fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
760
761 elbc_fcm_ctrl->oob_poi = chip->oob_poi;
762} 752}
763 753
764static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) 754static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
@@ -791,8 +781,8 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
791 chip->bbt_md = &bbt_mirror_descr; 781 chip->bbt_md = &bbt_mirror_descr;
792 782
793 /* set up nand options */ 783 /* set up nand options */
794 chip->options = NAND_NO_READRDY | NAND_NO_AUTOINCR | 784 chip->options = NAND_NO_READRDY | NAND_NO_AUTOINCR;
795 NAND_USE_FLASH_BBT; 785 chip->bbt_options = NAND_BBT_USE_FLASH;
796 786
797 chip->controller = &elbc_fcm_ctrl->controller; 787 chip->controller = &elbc_fcm_ctrl->controller;
798 chip->priv = priv; 788 chip->priv = priv;
@@ -829,7 +819,6 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
829 819
830 elbc_fcm_ctrl->chips[priv->bank] = NULL; 820 elbc_fcm_ctrl->chips[priv->bank] = NULL;
831 kfree(priv); 821 kfree(priv);
832 kfree(elbc_fcm_ctrl);
833 return 0; 822 return 0;
834} 823}
835 824
@@ -842,13 +831,14 @@ static int __devinit fsl_elbc_nand_probe(struct platform_device *pdev)
842 struct resource res; 831 struct resource res;
843 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl; 832 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl;
844 static const char *part_probe_types[] 833 static const char *part_probe_types[]
845 = { "cmdlinepart", "RedBoot", NULL }; 834 = { "cmdlinepart", "RedBoot", "ofpart", NULL };
846 struct mtd_partition *parts;
847 int ret; 835 int ret;
848 int bank; 836 int bank;
849 struct device *dev; 837 struct device *dev;
850 struct device_node *node = pdev->dev.of_node; 838 struct device_node *node = pdev->dev.of_node;
839 struct mtd_part_parser_data ppdata;
851 840
841 ppdata.of_node = pdev->dev.of_node;
852 if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs) 842 if (!fsl_lbc_ctrl_dev || !fsl_lbc_ctrl_dev->regs)
853 return -ENODEV; 843 return -ENODEV;
854 lbc = fsl_lbc_ctrl_dev->regs; 844 lbc = fsl_lbc_ctrl_dev->regs;
@@ -934,17 +924,8 @@ static int __devinit fsl_elbc_nand_probe(struct platform_device *pdev)
934 924
935 /* First look for RedBoot table or partitions on the command 925 /* First look for RedBoot table or partitions on the command
936 * line, these take precedence over device tree information */ 926 * line, these take precedence over device tree information */
937 ret = parse_mtd_partitions(&priv->mtd, part_probe_types, &parts, 0); 927 mtd_device_parse_register(&priv->mtd, part_probe_types, &ppdata,
938 if (ret < 0) 928 NULL, 0);
939 goto err;
940
941 if (ret == 0) {
942 ret = of_mtd_parse_partitions(priv->dev, node, &parts);
943 if (ret < 0)
944 goto err;
945 }
946
947 mtd_device_register(&priv->mtd, parts, ret);
948 929
949 printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n", 930 printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
950 (unsigned long long)res.start, priv->bank); 931 (unsigned long long)res.start, priv->bank);
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 23752fd5bc5..b4f3cc9f32f 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -158,7 +158,7 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
158{ 158{
159 int ret; 159 int ret;
160 struct device_node *flash_np; 160 struct device_node *flash_np;
161 static const char *part_types[] = { "cmdlinepart", NULL, }; 161 struct mtd_part_parser_data ppdata;
162 162
163 fun->chip.IO_ADDR_R = fun->io_base; 163 fun->chip.IO_ADDR_R = fun->io_base;
164 fun->chip.IO_ADDR_W = fun->io_base; 164 fun->chip.IO_ADDR_W = fun->io_base;
@@ -192,18 +192,12 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
192 if (ret) 192 if (ret)
193 goto err; 193 goto err;
194 194
195 ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0); 195 ppdata.of_node = flash_np;
196 196 ret = mtd_device_parse_register(&fun->mtd, NULL, &ppdata, NULL, 0);
197#ifdef CONFIG_MTD_OF_PARTS
198 if (ret == 0) {
199 ret = of_mtd_parse_partitions(fun->dev, flash_np, &fun->parts);
200 if (ret < 0)
201 goto err;
202 }
203#endif
204 ret = mtd_device_register(&fun->mtd, fun->parts, ret);
205err: 197err:
206 of_node_put(flash_np); 198 of_node_put(flash_np);
199 if (ret)
200 kfree(fun->mtd.name);
207 return ret; 201 return ret;
208} 202}
209 203
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index e9b275ac381..e53b7606413 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -146,7 +146,7 @@ static struct mtd_partition partition_info_16KB_blk[] = {
146 { 146 {
147 .name = "Root File System", 147 .name = "Root File System",
148 .offset = 0x460000, 148 .offset = 0x460000,
149 .size = 0, 149 .size = MTDPART_SIZ_FULL,
150 }, 150 },
151}; 151};
152 152
@@ -173,13 +173,10 @@ static struct mtd_partition partition_info_128KB_blk[] = {
173 { 173 {
174 .name = "Root File System", 174 .name = "Root File System",
175 .offset = 0x800000, 175 .offset = 0x800000,
176 .size = 0, 176 .size = MTDPART_SIZ_FULL,
177 }, 177 },
178}; 178};
179 179
180#ifdef CONFIG_MTD_CMDLINE_PARTS
181const char *part_probes[] = { "cmdlinepart", NULL };
182#endif
183 180
184/** 181/**
185 * struct fsmc_nand_data - structure for FSMC NAND device state 182 * struct fsmc_nand_data - structure for FSMC NAND device state
@@ -187,8 +184,6 @@ const char *part_probes[] = { "cmdlinepart", NULL };
187 * @pid: Part ID on the AMBA PrimeCell format 184 * @pid: Part ID on the AMBA PrimeCell format
188 * @mtd: MTD info for a NAND flash. 185 * @mtd: MTD info for a NAND flash.
189 * @nand: Chip related info for a NAND flash. 186 * @nand: Chip related info for a NAND flash.
190 * @partitions: Partition info for a NAND Flash.
191 * @nr_partitions: Total number of partition of a NAND flash.
192 * 187 *
193 * @ecc_place: ECC placing locations in oobfree type format. 188 * @ecc_place: ECC placing locations in oobfree type format.
194 * @bank: Bank number for probed device. 189 * @bank: Bank number for probed device.
@@ -203,8 +198,6 @@ struct fsmc_nand_data {
203 u32 pid; 198 u32 pid;
204 struct mtd_info mtd; 199 struct mtd_info mtd;
205 struct nand_chip nand; 200 struct nand_chip nand;
206 struct mtd_partition *partitions;
207 unsigned int nr_partitions;
208 201
209 struct fsmc_eccplace *ecc_place; 202 struct fsmc_eccplace *ecc_place;
210 unsigned int bank; 203 unsigned int bank;
@@ -716,65 +709,17 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
716 * platform data, 709 * platform data,
717 * default partition information present in driver. 710 * default partition information present in driver.
718 */ 711 */
719#ifdef CONFIG_MTD_CMDLINE_PARTS
720 /* 712 /*
721 * Check if partition info passed via command line 713 * Check for partition info passed
722 */ 714 */
723 host->mtd.name = "nand"; 715 host->mtd.name = "nand";
724 host->nr_partitions = parse_mtd_partitions(&host->mtd, part_probes, 716 ret = mtd_device_parse_register(&host->mtd, NULL, 0,
725 &host->partitions, 0); 717 host->mtd.size <= 0x04000000 ?
726 if (host->nr_partitions <= 0) { 718 partition_info_16KB_blk :
727#endif 719 partition_info_128KB_blk,
728 /* 720 host->mtd.size <= 0x04000000 ?
729 * Check if partition info passed via command line 721 ARRAY_SIZE(partition_info_16KB_blk) :
730 */ 722 ARRAY_SIZE(partition_info_128KB_blk));
731 if (pdata->partitions) {
732 host->partitions = pdata->partitions;
733 host->nr_partitions = pdata->nr_partitions;
734 } else {
735 struct mtd_partition *partition;
736 int i;
737
738 /* Select the default partitions info */
739 switch (host->mtd.size) {
740 case 0x01000000:
741 case 0x02000000:
742 case 0x04000000:
743 host->partitions = partition_info_16KB_blk;
744 host->nr_partitions =
745 sizeof(partition_info_16KB_blk) /
746 sizeof(struct mtd_partition);
747 break;
748 case 0x08000000:
749 case 0x10000000:
750 case 0x20000000:
751 case 0x40000000:
752 host->partitions = partition_info_128KB_blk;
753 host->nr_partitions =
754 sizeof(partition_info_128KB_blk) /
755 sizeof(struct mtd_partition);
756 break;
757 default:
758 ret = -ENXIO;
759 pr_err("Unsupported NAND size\n");
760 goto err_probe;
761 }
762
763 partition = host->partitions;
764 for (i = 0; i < host->nr_partitions; i++, partition++) {
765 if (partition->size == 0) {
766 partition->size = host->mtd.size -
767 partition->offset;
768 break;
769 }
770 }
771 }
772#ifdef CONFIG_MTD_CMDLINE_PARTS
773 }
774#endif
775
776 ret = mtd_device_register(&host->mtd, host->partitions,
777 host->nr_partitions);
778 if (ret) 723 if (ret)
779 goto err_probe; 724 goto err_probe;
780 725
@@ -822,7 +767,7 @@ static int fsmc_nand_remove(struct platform_device *pdev)
822 platform_set_drvdata(pdev, NULL); 767 platform_set_drvdata(pdev, NULL);
823 768
824 if (host) { 769 if (host) {
825 mtd_device_unregister(&host->mtd); 770 nand_release(&host->mtd);
826 clk_disable(host->clk); 771 clk_disable(host->clk);
827 clk_put(host->clk); 772 clk_put(host->clk);
828 773
diff --git a/drivers/mtd/nand/gpmi-nand/Makefile b/drivers/mtd/nand/gpmi-nand/Makefile
new file mode 100644
index 00000000000..3a462487c35
--- /dev/null
+++ b/drivers/mtd/nand/gpmi-nand/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi_nand.o
2gpmi_nand-objs += gpmi-nand.o
3gpmi_nand-objs += gpmi-lib.o
diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h
new file mode 100644
index 00000000000..4effb8c579d
--- /dev/null
+++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h
@@ -0,0 +1,84 @@
1/*
2 * Freescale GPMI NAND Flash Driver
3 *
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 * Copyright 2008 Embedded Alley Solutions, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21#ifndef __GPMI_NAND_BCH_REGS_H
22#define __GPMI_NAND_BCH_REGS_H
23
24#define HW_BCH_CTRL 0x00000000
25#define HW_BCH_CTRL_SET 0x00000004
26#define HW_BCH_CTRL_CLR 0x00000008
27#define HW_BCH_CTRL_TOG 0x0000000c
28
29#define BM_BCH_CTRL_COMPLETE_IRQ_EN (1 << 8)
30#define BM_BCH_CTRL_COMPLETE_IRQ (1 << 0)
31
32#define HW_BCH_STATUS0 0x00000010
33#define HW_BCH_MODE 0x00000020
34#define HW_BCH_ENCODEPTR 0x00000030
35#define HW_BCH_DATAPTR 0x00000040
36#define HW_BCH_METAPTR 0x00000050
37#define HW_BCH_LAYOUTSELECT 0x00000070
38
39#define HW_BCH_FLASH0LAYOUT0 0x00000080
40
41#define BP_BCH_FLASH0LAYOUT0_NBLOCKS 24
42#define BM_BCH_FLASH0LAYOUT0_NBLOCKS (0xff << BP_BCH_FLASH0LAYOUT0_NBLOCKS)
43#define BF_BCH_FLASH0LAYOUT0_NBLOCKS(v) \
44 (((v) << BP_BCH_FLASH0LAYOUT0_NBLOCKS) & BM_BCH_FLASH0LAYOUT0_NBLOCKS)
45
46#define BP_BCH_FLASH0LAYOUT0_META_SIZE 16
47#define BM_BCH_FLASH0LAYOUT0_META_SIZE (0xff << BP_BCH_FLASH0LAYOUT0_META_SIZE)
48#define BF_BCH_FLASH0LAYOUT0_META_SIZE(v) \
49 (((v) << BP_BCH_FLASH0LAYOUT0_META_SIZE)\
50 & BM_BCH_FLASH0LAYOUT0_META_SIZE)
51
52#define BP_BCH_FLASH0LAYOUT0_ECC0 12
53#define BM_BCH_FLASH0LAYOUT0_ECC0 (0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
54#define BF_BCH_FLASH0LAYOUT0_ECC0(v) \
55 (((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0)
56
57#define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE 0
58#define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE \
59 (0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
60#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v) \
61 (((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\
62 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE)
63
64#define HW_BCH_FLASH0LAYOUT1 0x00000090
65
66#define BP_BCH_FLASH0LAYOUT1_PAGE_SIZE 16
67#define BM_BCH_FLASH0LAYOUT1_PAGE_SIZE \
68 (0xffff << BP_BCH_FLASH0LAYOUT1_PAGE_SIZE)
69#define BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(v) \
70 (((v) << BP_BCH_FLASH0LAYOUT1_PAGE_SIZE) \
71 & BM_BCH_FLASH0LAYOUT1_PAGE_SIZE)
72
73#define BP_BCH_FLASH0LAYOUT1_ECCN 12
74#define BM_BCH_FLASH0LAYOUT1_ECCN (0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
75#define BF_BCH_FLASH0LAYOUT1_ECCN(v) \
76 (((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN)
77
78#define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE 0
79#define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE \
80 (0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
81#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v) \
82 (((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
83 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE)
84#endif
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
new file mode 100644
index 00000000000..de4db7604a3
--- /dev/null
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -0,0 +1,1057 @@
1/*
2 * Freescale GPMI NAND Flash Driver
3 *
4 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc.
5 * Copyright (C) 2008 Embedded Alley Solutions, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21#include <linux/mtd/gpmi-nand.h>
22#include <linux/delay.h>
23#include <linux/clk.h>
24#include <mach/mxs.h>
25
26#include "gpmi-nand.h"
27#include "gpmi-regs.h"
28#include "bch-regs.h"
29
30struct timing_threshod timing_default_threshold = {
31 .max_data_setup_cycles = (BM_GPMI_TIMING0_DATA_SETUP >>
32 BP_GPMI_TIMING0_DATA_SETUP),
33 .internal_data_setup_in_ns = 0,
34 .max_sample_delay_factor = (BM_GPMI_CTRL1_RDN_DELAY >>
35 BP_GPMI_CTRL1_RDN_DELAY),
36 .max_dll_clock_period_in_ns = 32,
37 .max_dll_delay_in_ns = 16,
38};
39
40/*
41 * Clear the bit and poll it cleared. This is usually called with
42 * a reset address and mask being either SFTRST(bit 31) or CLKGATE
43 * (bit 30).
44 */
45static int clear_poll_bit(void __iomem *addr, u32 mask)
46{
47 int timeout = 0x400;
48
49 /* clear the bit */
50 __mxs_clrl(mask, addr);
51
52 /*
53 * SFTRST needs 3 GPMI clocks to settle, the reference manual
54 * recommends to wait 1us.
55 */
56 udelay(1);
57
58 /* poll the bit becoming clear */
59 while ((readl(addr) & mask) && --timeout)
60 /* nothing */;
61
62 return !timeout;
63}
64
65#define MODULE_CLKGATE (1 << 30)
66#define MODULE_SFTRST (1 << 31)
67/*
68 * The current mxs_reset_block() will do two things:
69 * [1] enable the module.
70 * [2] reset the module.
71 *
72 * In most of the cases, it's ok. But there is a hardware bug in the BCH block.
73 * If you try to soft reset the BCH block, it becomes unusable until
74 * the next hard reset. This case occurs in the NAND boot mode. When the board
75 * boots by NAND, the ROM of the chip will initialize the BCH blocks itself.
76 * So If the driver tries to reset the BCH again, the BCH will not work anymore.
77 * You will see a DMA timeout in this case.
78 *
79 * To avoid this bug, just add a new parameter `just_enable` for
80 * the mxs_reset_block(), and rewrite it here.
81 */
82int gpmi_reset_block(void __iomem *reset_addr, bool just_enable)
83{
84 int ret;
85 int timeout = 0x400;
86
87 /* clear and poll SFTRST */
88 ret = clear_poll_bit(reset_addr, MODULE_SFTRST);
89 if (unlikely(ret))
90 goto error;
91
92 /* clear CLKGATE */
93 __mxs_clrl(MODULE_CLKGATE, reset_addr);
94
95 if (!just_enable) {
96 /* set SFTRST to reset the block */
97 __mxs_setl(MODULE_SFTRST, reset_addr);
98 udelay(1);
99
100 /* poll CLKGATE becoming set */
101 while ((!(readl(reset_addr) & MODULE_CLKGATE)) && --timeout)
102 /* nothing */;
103 if (unlikely(!timeout))
104 goto error;
105 }
106
107 /* clear and poll SFTRST */
108 ret = clear_poll_bit(reset_addr, MODULE_SFTRST);
109 if (unlikely(ret))
110 goto error;
111
112 /* clear and poll CLKGATE */
113 ret = clear_poll_bit(reset_addr, MODULE_CLKGATE);
114 if (unlikely(ret))
115 goto error;
116
117 return 0;
118
119error:
120 pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
121 return -ETIMEDOUT;
122}
123
124int gpmi_init(struct gpmi_nand_data *this)
125{
126 struct resources *r = &this->resources;
127 int ret;
128
129 ret = clk_enable(r->clock);
130 if (ret)
131 goto err_out;
132 ret = gpmi_reset_block(r->gpmi_regs, false);
133 if (ret)
134 goto err_out;
135
136 /* Choose NAND mode. */
137 writel(BM_GPMI_CTRL1_GPMI_MODE, r->gpmi_regs + HW_GPMI_CTRL1_CLR);
138
139 /* Set the IRQ polarity. */
140 writel(BM_GPMI_CTRL1_ATA_IRQRDY_POLARITY,
141 r->gpmi_regs + HW_GPMI_CTRL1_SET);
142
143 /* Disable Write-Protection. */
144 writel(BM_GPMI_CTRL1_DEV_RESET, r->gpmi_regs + HW_GPMI_CTRL1_SET);
145
146 /* Select BCH ECC. */
147 writel(BM_GPMI_CTRL1_BCH_MODE, r->gpmi_regs + HW_GPMI_CTRL1_SET);
148
149 clk_disable(r->clock);
150 return 0;
151err_out:
152 return ret;
153}
154
155/* This function is very useful. It is called only when the bug occur. */
156void gpmi_dump_info(struct gpmi_nand_data *this)
157{
158 struct resources *r = &this->resources;
159 struct bch_geometry *geo = &this->bch_geometry;
160 u32 reg;
161 int i;
162
163 pr_err("Show GPMI registers :\n");
164 for (i = 0; i <= HW_GPMI_DEBUG / 0x10 + 1; i++) {
165 reg = readl(r->gpmi_regs + i * 0x10);
166 pr_err("offset 0x%.3x : 0x%.8x\n", i * 0x10, reg);
167 }
168
169 /* start to print out the BCH info */
170 pr_err("BCH Geometry :\n");
171 pr_err("GF length : %u\n", geo->gf_len);
172 pr_err("ECC Strength : %u\n", geo->ecc_strength);
173 pr_err("Page Size in Bytes : %u\n", geo->page_size);
174 pr_err("Metadata Size in Bytes : %u\n", geo->metadata_size);
175 pr_err("ECC Chunk Size in Bytes: %u\n", geo->ecc_chunk_size);
176 pr_err("ECC Chunk Count : %u\n", geo->ecc_chunk_count);
177 pr_err("Payload Size in Bytes : %u\n", geo->payload_size);
178 pr_err("Auxiliary Size in Bytes: %u\n", geo->auxiliary_size);
179 pr_err("Auxiliary Status Offset: %u\n", geo->auxiliary_status_offset);
180 pr_err("Block Mark Byte Offset : %u\n", geo->block_mark_byte_offset);
181 pr_err("Block Mark Bit Offset : %u\n", geo->block_mark_bit_offset);
182}
183
184/* Configures the geometry for BCH. */
185int bch_set_geometry(struct gpmi_nand_data *this)
186{
187 struct resources *r = &this->resources;
188 struct bch_geometry *bch_geo = &this->bch_geometry;
189 unsigned int block_count;
190 unsigned int block_size;
191 unsigned int metadata_size;
192 unsigned int ecc_strength;
193 unsigned int page_size;
194 int ret;
195
196 if (common_nfc_set_geometry(this))
197 return !0;
198
199 block_count = bch_geo->ecc_chunk_count - 1;
200 block_size = bch_geo->ecc_chunk_size;
201 metadata_size = bch_geo->metadata_size;
202 ecc_strength = bch_geo->ecc_strength >> 1;
203 page_size = bch_geo->page_size;
204
205 ret = clk_enable(r->clock);
206 if (ret)
207 goto err_out;
208
209 ret = gpmi_reset_block(r->bch_regs, true);
210 if (ret)
211 goto err_out;
212
213 /* Configure layout 0. */
214 writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count)
215 | BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size)
216 | BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength)
217 | BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size),
218 r->bch_regs + HW_BCH_FLASH0LAYOUT0);
219
220 writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size)
221 | BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength)
222 | BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size),
223 r->bch_regs + HW_BCH_FLASH0LAYOUT1);
224
225 /* Set *all* chip selects to use layout 0. */
226 writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT);
227
228 /* Enable interrupts. */
229 writel(BM_BCH_CTRL_COMPLETE_IRQ_EN,
230 r->bch_regs + HW_BCH_CTRL_SET);
231
232 clk_disable(r->clock);
233 return 0;
234err_out:
235 return ret;
236}
237
238/* Converts time in nanoseconds to cycles. */
239static unsigned int ns_to_cycles(unsigned int time,
240 unsigned int period, unsigned int min)
241{
242 unsigned int k;
243
244 k = (time + period - 1) / period;
245 return max(k, min);
246}
247
248/* Apply timing to current hardware conditions. */
249static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
250 struct gpmi_nfc_hardware_timing *hw)
251{
252 struct gpmi_nand_platform_data *pdata = this->pdata;
253 struct timing_threshod *nfc = &timing_default_threshold;
254 struct nand_chip *nand = &this->nand;
255 struct nand_timing target = this->timing;
256 bool improved_timing_is_available;
257 unsigned long clock_frequency_in_hz;
258 unsigned int clock_period_in_ns;
259 bool dll_use_half_periods;
260 unsigned int dll_delay_shift;
261 unsigned int max_sample_delay_in_ns;
262 unsigned int address_setup_in_cycles;
263 unsigned int data_setup_in_ns;
264 unsigned int data_setup_in_cycles;
265 unsigned int data_hold_in_cycles;
266 int ideal_sample_delay_in_ns;
267 unsigned int sample_delay_factor;
268 int tEYE;
269 unsigned int min_prop_delay_in_ns = pdata->min_prop_delay_in_ns;
270 unsigned int max_prop_delay_in_ns = pdata->max_prop_delay_in_ns;
271
272 /*
273 * If there are multiple chips, we need to relax the timings to allow
274 * for signal distortion due to higher capacitance.
275 */
276 if (nand->numchips > 2) {
277 target.data_setup_in_ns += 10;
278 target.data_hold_in_ns += 10;
279 target.address_setup_in_ns += 10;
280 } else if (nand->numchips > 1) {
281 target.data_setup_in_ns += 5;
282 target.data_hold_in_ns += 5;
283 target.address_setup_in_ns += 5;
284 }
285
286 /* Check if improved timing information is available. */
287 improved_timing_is_available =
288 (target.tREA_in_ns >= 0) &&
289 (target.tRLOH_in_ns >= 0) &&
290 (target.tRHOH_in_ns >= 0) ;
291
292 /* Inspect the clock. */
293 clock_frequency_in_hz = nfc->clock_frequency_in_hz;
294 clock_period_in_ns = 1000000000 / clock_frequency_in_hz;
295
296 /*
297 * The NFC quantizes setup and hold parameters in terms of clock cycles.
298 * Here, we quantize the setup and hold timing parameters to the
299 * next-highest clock period to make sure we apply at least the
300 * specified times.
301 *
302 * For data setup and data hold, the hardware interprets a value of zero
303 * as the largest possible delay. This is not what's intended by a zero
304 * in the input parameter, so we impose a minimum of one cycle.
305 */
306 data_setup_in_cycles = ns_to_cycles(target.data_setup_in_ns,
307 clock_period_in_ns, 1);
308 data_hold_in_cycles = ns_to_cycles(target.data_hold_in_ns,
309 clock_period_in_ns, 1);
310 address_setup_in_cycles = ns_to_cycles(target.address_setup_in_ns,
311 clock_period_in_ns, 0);
312
313 /*
314 * The clock's period affects the sample delay in a number of ways:
315 *
316 * (1) The NFC HAL tells us the maximum clock period the sample delay
317 * DLL can tolerate. If the clock period is greater than half that
318 * maximum, we must configure the DLL to be driven by half periods.
319 *
320 * (2) We need to convert from an ideal sample delay, in ns, to a
321 * "sample delay factor," which the NFC uses. This factor depends on
322 * whether we're driving the DLL with full or half periods.
323 * Paraphrasing the reference manual:
324 *
325 * AD = SDF x 0.125 x RP
326 *
327 * where:
328 *
329 * AD is the applied delay, in ns.
330 * SDF is the sample delay factor, which is dimensionless.
331 * RP is the reference period, in ns, which is a full clock period
332 * if the DLL is being driven by full periods, or half that if
333 * the DLL is being driven by half periods.
334 *
335 * Let's re-arrange this in a way that's more useful to us:
336 *
337 * 8
338 * SDF = AD x ----
339 * RP
340 *
341 * The reference period is either the clock period or half that, so this
342 * is:
343 *
344 * 8 AD x DDF
345 * SDF = AD x ----- = --------
346 * f x P P
347 *
348 * where:
349 *
350 * f is 1 or 1/2, depending on how we're driving the DLL.
351 * P is the clock period.
352 * DDF is the DLL Delay Factor, a dimensionless value that
353 * incorporates all the constants in the conversion.
354 *
355 * DDF will be either 8 or 16, both of which are powers of two. We can
356 * reduce the cost of this conversion by using bit shifts instead of
357 * multiplication or division. Thus:
358 *
359 * AD << DDS
360 * SDF = ---------
361 * P
362 *
363 * or
364 *
365 * AD = (SDF >> DDS) x P
366 *
367 * where:
368 *
369 * DDS is the DLL Delay Shift, the logarithm to base 2 of the DDF.
370 */
371 if (clock_period_in_ns > (nfc->max_dll_clock_period_in_ns >> 1)) {
372 dll_use_half_periods = true;
373 dll_delay_shift = 3 + 1;
374 } else {
375 dll_use_half_periods = false;
376 dll_delay_shift = 3;
377 }
378
379 /*
380 * Compute the maximum sample delay the NFC allows, under current
381 * conditions. If the clock is running too slowly, no sample delay is
382 * possible.
383 */
384 if (clock_period_in_ns > nfc->max_dll_clock_period_in_ns)
385 max_sample_delay_in_ns = 0;
386 else {
387 /*
388 * Compute the delay implied by the largest sample delay factor
389 * the NFC allows.
390 */
391 max_sample_delay_in_ns =
392 (nfc->max_sample_delay_factor * clock_period_in_ns) >>
393 dll_delay_shift;
394
395 /*
396 * Check if the implied sample delay larger than the NFC
397 * actually allows.
398 */
399 if (max_sample_delay_in_ns > nfc->max_dll_delay_in_ns)
400 max_sample_delay_in_ns = nfc->max_dll_delay_in_ns;
401 }
402
403 /*
404 * Check if improved timing information is available. If not, we have to
405 * use a less-sophisticated algorithm.
406 */
407 if (!improved_timing_is_available) {
408 /*
409 * Fold the read setup time required by the NFC into the ideal
410 * sample delay.
411 */
412 ideal_sample_delay_in_ns = target.gpmi_sample_delay_in_ns +
413 nfc->internal_data_setup_in_ns;
414
415 /*
416 * The ideal sample delay may be greater than the maximum
417 * allowed by the NFC. If so, we can trade off sample delay time
418 * for more data setup time.
419 *
420 * In each iteration of the following loop, we add a cycle to
421 * the data setup time and subtract a corresponding amount from
422 * the sample delay until we've satisified the constraints or
423 * can't do any better.
424 */
425 while ((ideal_sample_delay_in_ns > max_sample_delay_in_ns) &&
426 (data_setup_in_cycles < nfc->max_data_setup_cycles)) {
427
428 data_setup_in_cycles++;
429 ideal_sample_delay_in_ns -= clock_period_in_ns;
430
431 if (ideal_sample_delay_in_ns < 0)
432 ideal_sample_delay_in_ns = 0;
433
434 }
435
436 /*
437 * Compute the sample delay factor that corresponds most closely
438 * to the ideal sample delay. If the result is too large for the
439 * NFC, use the maximum value.
440 *
441 * Notice that we use the ns_to_cycles function to compute the
442 * sample delay factor. We do this because the form of the
443 * computation is the same as that for calculating cycles.
444 */
445 sample_delay_factor =
446 ns_to_cycles(
447 ideal_sample_delay_in_ns << dll_delay_shift,
448 clock_period_in_ns, 0);
449
450 if (sample_delay_factor > nfc->max_sample_delay_factor)
451 sample_delay_factor = nfc->max_sample_delay_factor;
452
453 /* Skip to the part where we return our results. */
454 goto return_results;
455 }
456
457 /*
458 * If control arrives here, we have more detailed timing information,
459 * so we can use a better algorithm.
460 */
461
462 /*
463 * Fold the read setup time required by the NFC into the maximum
464 * propagation delay.
465 */
466 max_prop_delay_in_ns += nfc->internal_data_setup_in_ns;
467
468 /*
469 * Earlier, we computed the number of clock cycles required to satisfy
470 * the data setup time. Now, we need to know the actual nanoseconds.
471 */
472 data_setup_in_ns = clock_period_in_ns * data_setup_in_cycles;
473
474 /*
475 * Compute tEYE, the width of the data eye when reading from the NAND
476 * Flash. The eye width is fundamentally determined by the data setup
477 * time, perturbed by propagation delays and some characteristics of the
478 * NAND Flash device.
479 *
480 * start of the eye = max_prop_delay + tREA
481 * end of the eye = min_prop_delay + tRHOH + data_setup
482 */
483 tEYE = (int)min_prop_delay_in_ns + (int)target.tRHOH_in_ns +
484 (int)data_setup_in_ns;
485
486 tEYE -= (int)max_prop_delay_in_ns + (int)target.tREA_in_ns;
487
488 /*
489 * The eye must be open. If it's not, we can try to open it by
490 * increasing its main forcer, the data setup time.
491 *
492 * In each iteration of the following loop, we increase the data setup
493 * time by a single clock cycle. We do this until either the eye is
494 * open or we run into NFC limits.
495 */
496 while ((tEYE <= 0) &&
497 (data_setup_in_cycles < nfc->max_data_setup_cycles)) {
498 /* Give a cycle to data setup. */
499 data_setup_in_cycles++;
500 /* Synchronize the data setup time with the cycles. */
501 data_setup_in_ns += clock_period_in_ns;
502 /* Adjust tEYE accordingly. */
503 tEYE += clock_period_in_ns;
504 }
505
506 /*
507 * When control arrives here, the eye is open. The ideal time to sample
508 * the data is in the center of the eye:
509 *
510 * end of the eye + start of the eye
511 * --------------------------------- - data_setup
512 * 2
513 *
514 * After some algebra, this simplifies to the code immediately below.
515 */
516 ideal_sample_delay_in_ns =
517 ((int)max_prop_delay_in_ns +
518 (int)target.tREA_in_ns +
519 (int)min_prop_delay_in_ns +
520 (int)target.tRHOH_in_ns -
521 (int)data_setup_in_ns) >> 1;
522
523 /*
524 * The following figure illustrates some aspects of a NAND Flash read:
525 *
526 *
527 * __ _____________________________________
528 * RDN \_________________/
529 *
530 * <---- tEYE ----->
531 * /-----------------\
532 * Read Data ----------------------------< >---------
533 * \-----------------/
534 * ^ ^ ^ ^
535 * | | | |
536 * |<--Data Setup -->|<--Delay Time -->| |
537 * | | | |
538 * | | |
539 * | |<-- Quantized Delay Time -->|
540 * | | |
541 *
542 *
543 * We have some issues we must now address:
544 *
545 * (1) The *ideal* sample delay time must not be negative. If it is, we
546 * jam it to zero.
547 *
548 * (2) The *ideal* sample delay time must not be greater than that
549 * allowed by the NFC. If it is, we can increase the data setup
550 * time, which will reduce the delay between the end of the data
551 * setup and the center of the eye. It will also make the eye
552 * larger, which might help with the next issue...
553 *
554 * (3) The *quantized* sample delay time must not fall either before the
555 * eye opens or after it closes (the latter is the problem
556 * illustrated in the above figure).
557 */
558
559 /* Jam a negative ideal sample delay to zero. */
560 if (ideal_sample_delay_in_ns < 0)
561 ideal_sample_delay_in_ns = 0;
562
563 /*
564 * Extend the data setup as needed to reduce the ideal sample delay
565 * below the maximum permitted by the NFC.
566 */
567 while ((ideal_sample_delay_in_ns > max_sample_delay_in_ns) &&
568 (data_setup_in_cycles < nfc->max_data_setup_cycles)) {
569
570 /* Give a cycle to data setup. */
571 data_setup_in_cycles++;
572 /* Synchronize the data setup time with the cycles. */
573 data_setup_in_ns += clock_period_in_ns;
574 /* Adjust tEYE accordingly. */
575 tEYE += clock_period_in_ns;
576
577 /*
578 * Decrease the ideal sample delay by one half cycle, to keep it
579 * in the middle of the eye.
580 */
581 ideal_sample_delay_in_ns -= (clock_period_in_ns >> 1);
582
583 /* Jam a negative ideal sample delay to zero. */
584 if (ideal_sample_delay_in_ns < 0)
585 ideal_sample_delay_in_ns = 0;
586 }
587
588 /*
589 * Compute the sample delay factor that corresponds to the ideal sample
590 * delay. If the result is too large, then use the maximum allowed
591 * value.
592 *
593 * Notice that we use the ns_to_cycles function to compute the sample
594 * delay factor. We do this because the form of the computation is the
595 * same as that for calculating cycles.
596 */
597 sample_delay_factor =
598 ns_to_cycles(ideal_sample_delay_in_ns << dll_delay_shift,
599 clock_period_in_ns, 0);
600
601 if (sample_delay_factor > nfc->max_sample_delay_factor)
602 sample_delay_factor = nfc->max_sample_delay_factor;
603
604 /*
605 * These macros conveniently encapsulate a computation we'll use to
606 * continuously evaluate whether or not the data sample delay is inside
607 * the eye.
608 */
609 #define IDEAL_DELAY ((int) ideal_sample_delay_in_ns)
610
611 #define QUANTIZED_DELAY \
612 ((int) ((sample_delay_factor * clock_period_in_ns) >> \
613 dll_delay_shift))
614
615 #define DELAY_ERROR (abs(QUANTIZED_DELAY - IDEAL_DELAY))
616
617 #define SAMPLE_IS_NOT_WITHIN_THE_EYE (DELAY_ERROR > (tEYE >> 1))
618
619 /*
620 * While the quantized sample time falls outside the eye, reduce the
621 * sample delay or extend the data setup to move the sampling point back
622 * toward the eye. Do not allow the number of data setup cycles to
623 * exceed the maximum allowed by the NFC.
624 */
625 while (SAMPLE_IS_NOT_WITHIN_THE_EYE &&
626 (data_setup_in_cycles < nfc->max_data_setup_cycles)) {
627 /*
628 * If control arrives here, the quantized sample delay falls
629 * outside the eye. Check if it's before the eye opens, or after
630 * the eye closes.
631 */
632 if (QUANTIZED_DELAY > IDEAL_DELAY) {
633 /*
634 * If control arrives here, the quantized sample delay
635 * falls after the eye closes. Decrease the quantized
636 * delay time and then go back to re-evaluate.
637 */
638 if (sample_delay_factor != 0)
639 sample_delay_factor--;
640 continue;
641 }
642
643 /*
644 * If control arrives here, the quantized sample delay falls
645 * before the eye opens. Shift the sample point by increasing
646 * data setup time. This will also make the eye larger.
647 */
648
649 /* Give a cycle to data setup. */
650 data_setup_in_cycles++;
651 /* Synchronize the data setup time with the cycles. */
652 data_setup_in_ns += clock_period_in_ns;
653 /* Adjust tEYE accordingly. */
654 tEYE += clock_period_in_ns;
655
656 /*
657 * Decrease the ideal sample delay by one half cycle, to keep it
658 * in the middle of the eye.
659 */
660 ideal_sample_delay_in_ns -= (clock_period_in_ns >> 1);
661
662 /* ...and one less period for the delay time. */
663 ideal_sample_delay_in_ns -= clock_period_in_ns;
664
665 /* Jam a negative ideal sample delay to zero. */
666 if (ideal_sample_delay_in_ns < 0)
667 ideal_sample_delay_in_ns = 0;
668
669 /*
670 * We have a new ideal sample delay, so re-compute the quantized
671 * delay.
672 */
673 sample_delay_factor =
674 ns_to_cycles(
675 ideal_sample_delay_in_ns << dll_delay_shift,
676 clock_period_in_ns, 0);
677
678 if (sample_delay_factor > nfc->max_sample_delay_factor)
679 sample_delay_factor = nfc->max_sample_delay_factor;
680 }
681
682 /* Control arrives here when we're ready to return our results. */
683return_results:
684 hw->data_setup_in_cycles = data_setup_in_cycles;
685 hw->data_hold_in_cycles = data_hold_in_cycles;
686 hw->address_setup_in_cycles = address_setup_in_cycles;
687 hw->use_half_periods = dll_use_half_periods;
688 hw->sample_delay_factor = sample_delay_factor;
689
690 /* Return success. */
691 return 0;
692}
693
694/* Begin the I/O */
695void gpmi_begin(struct gpmi_nand_data *this)
696{
697 struct resources *r = &this->resources;
698 struct timing_threshod *nfc = &timing_default_threshold;
699 unsigned char *gpmi_regs = r->gpmi_regs;
700 unsigned int clock_period_in_ns;
701 uint32_t reg;
702 unsigned int dll_wait_time_in_us;
703 struct gpmi_nfc_hardware_timing hw;
704 int ret;
705
706 /* Enable the clock. */
707 ret = clk_enable(r->clock);
708 if (ret) {
709 pr_err("We failed in enable the clk\n");
710 goto err_out;
711 }
712
713 /* set ready/busy timeout */
714 writel(0x500 << BP_GPMI_TIMING1_BUSY_TIMEOUT,
715 gpmi_regs + HW_GPMI_TIMING1);
716
717 /* Get the timing information we need. */
718 nfc->clock_frequency_in_hz = clk_get_rate(r->clock);
719 clock_period_in_ns = 1000000000 / nfc->clock_frequency_in_hz;
720
721 gpmi_nfc_compute_hardware_timing(this, &hw);
722
723 /* Set up all the simple timing parameters. */
724 reg = BF_GPMI_TIMING0_ADDRESS_SETUP(hw.address_setup_in_cycles) |
725 BF_GPMI_TIMING0_DATA_HOLD(hw.data_hold_in_cycles) |
726 BF_GPMI_TIMING0_DATA_SETUP(hw.data_setup_in_cycles) ;
727
728 writel(reg, gpmi_regs + HW_GPMI_TIMING0);
729
730 /*
731 * DLL_ENABLE must be set to 0 when setting RDN_DELAY or HALF_PERIOD.
732 */
733 writel(BM_GPMI_CTRL1_DLL_ENABLE, gpmi_regs + HW_GPMI_CTRL1_CLR);
734
735 /* Clear out the DLL control fields. */
736 writel(BM_GPMI_CTRL1_RDN_DELAY, gpmi_regs + HW_GPMI_CTRL1_CLR);
737 writel(BM_GPMI_CTRL1_HALF_PERIOD, gpmi_regs + HW_GPMI_CTRL1_CLR);
738
739 /* If no sample delay is called for, return immediately. */
740 if (!hw.sample_delay_factor)
741 return;
742
743 /* Configure the HALF_PERIOD flag. */
744 if (hw.use_half_periods)
745 writel(BM_GPMI_CTRL1_HALF_PERIOD,
746 gpmi_regs + HW_GPMI_CTRL1_SET);
747
748 /* Set the delay factor. */
749 writel(BF_GPMI_CTRL1_RDN_DELAY(hw.sample_delay_factor),
750 gpmi_regs + HW_GPMI_CTRL1_SET);
751
752 /* Enable the DLL. */
753 writel(BM_GPMI_CTRL1_DLL_ENABLE, gpmi_regs + HW_GPMI_CTRL1_SET);
754
755 /*
756 * After we enable the GPMI DLL, we have to wait 64 clock cycles before
757 * we can use the GPMI.
758 *
759 * Calculate the amount of time we need to wait, in microseconds.
760 */
761 dll_wait_time_in_us = (clock_period_in_ns * 64) / 1000;
762
763 if (!dll_wait_time_in_us)
764 dll_wait_time_in_us = 1;
765
766 /* Wait for the DLL to settle. */
767 udelay(dll_wait_time_in_us);
768
769err_out:
770 return;
771}
772
773void gpmi_end(struct gpmi_nand_data *this)
774{
775 struct resources *r = &this->resources;
776 clk_disable(r->clock);
777}
778
779/* Clears a BCH interrupt. */
780void gpmi_clear_bch(struct gpmi_nand_data *this)
781{
782 struct resources *r = &this->resources;
783 writel(BM_BCH_CTRL_COMPLETE_IRQ, r->bch_regs + HW_BCH_CTRL_CLR);
784}
785
786/* Returns the Ready/Busy status of the given chip. */
787int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
788{
789 struct resources *r = &this->resources;
790 uint32_t mask = 0;
791 uint32_t reg = 0;
792
793 if (GPMI_IS_MX23(this)) {
794 mask = MX23_BM_GPMI_DEBUG_READY0 << chip;
795 reg = readl(r->gpmi_regs + HW_GPMI_DEBUG);
796 } else if (GPMI_IS_MX28(this)) {
797 mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip);
798 reg = readl(r->gpmi_regs + HW_GPMI_STAT);
799 } else
800 pr_err("unknow arch.\n");
801 return reg & mask;
802}
803
804static inline void set_dma_type(struct gpmi_nand_data *this,
805 enum dma_ops_type type)
806{
807 this->last_dma_type = this->dma_type;
808 this->dma_type = type;
809}
810
811int gpmi_send_command(struct gpmi_nand_data *this)
812{
813 struct dma_chan *channel = get_dma_chan(this);
814 struct dma_async_tx_descriptor *desc;
815 struct scatterlist *sgl;
816 int chip = this->current_chip;
817 u32 pio[3];
818
819 /* [1] send out the PIO words */
820 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(BV_GPMI_CTRL0_COMMAND_MODE__WRITE)
821 | BM_GPMI_CTRL0_WORD_LENGTH
822 | BF_GPMI_CTRL0_CS(chip, this)
823 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
824 | BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_CLE)
825 | BM_GPMI_CTRL0_ADDRESS_INCREMENT
826 | BF_GPMI_CTRL0_XFER_COUNT(this->command_length);
827 pio[1] = pio[2] = 0;
828 desc = channel->device->device_prep_slave_sg(channel,
829 (struct scatterlist *)pio,
830 ARRAY_SIZE(pio), DMA_NONE, 0);
831 if (!desc) {
832 pr_err("step 1 error\n");
833 return -1;
834 }
835
836 /* [2] send out the COMMAND + ADDRESS string stored in @buffer */
837 sgl = &this->cmd_sgl;
838
839 sg_init_one(sgl, this->cmd_buffer, this->command_length);
840 dma_map_sg(this->dev, sgl, 1, DMA_TO_DEVICE);
841 desc = channel->device->device_prep_slave_sg(channel,
842 sgl, 1, DMA_TO_DEVICE, 1);
843 if (!desc) {
844 pr_err("step 2 error\n");
845 return -1;
846 }
847
848 /* [3] submit the DMA */
849 set_dma_type(this, DMA_FOR_COMMAND);
850 return start_dma_without_bch_irq(this, desc);
851}
852
853int gpmi_send_data(struct gpmi_nand_data *this)
854{
855 struct dma_async_tx_descriptor *desc;
856 struct dma_chan *channel = get_dma_chan(this);
857 int chip = this->current_chip;
858 uint32_t command_mode;
859 uint32_t address;
860 u32 pio[2];
861
862 /* [1] PIO */
863 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WRITE;
864 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
865
866 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
867 | BM_GPMI_CTRL0_WORD_LENGTH
868 | BF_GPMI_CTRL0_CS(chip, this)
869 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
870 | BF_GPMI_CTRL0_ADDRESS(address)
871 | BF_GPMI_CTRL0_XFER_COUNT(this->upper_len);
872 pio[1] = 0;
873 desc = channel->device->device_prep_slave_sg(channel,
874 (struct scatterlist *)pio,
875 ARRAY_SIZE(pio), DMA_NONE, 0);
876 if (!desc) {
877 pr_err("step 1 error\n");
878 return -1;
879 }
880
881 /* [2] send DMA request */
882 prepare_data_dma(this, DMA_TO_DEVICE);
883 desc = channel->device->device_prep_slave_sg(channel, &this->data_sgl,
884 1, DMA_TO_DEVICE, 1);
885 if (!desc) {
886 pr_err("step 2 error\n");
887 return -1;
888 }
889 /* [3] submit the DMA */
890 set_dma_type(this, DMA_FOR_WRITE_DATA);
891 return start_dma_without_bch_irq(this, desc);
892}
893
894int gpmi_read_data(struct gpmi_nand_data *this)
895{
896 struct dma_async_tx_descriptor *desc;
897 struct dma_chan *channel = get_dma_chan(this);
898 int chip = this->current_chip;
899 u32 pio[2];
900
901 /* [1] : send PIO */
902 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(BV_GPMI_CTRL0_COMMAND_MODE__READ)
903 | BM_GPMI_CTRL0_WORD_LENGTH
904 | BF_GPMI_CTRL0_CS(chip, this)
905 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
906 | BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_DATA)
907 | BF_GPMI_CTRL0_XFER_COUNT(this->upper_len);
908 pio[1] = 0;
909 desc = channel->device->device_prep_slave_sg(channel,
910 (struct scatterlist *)pio,
911 ARRAY_SIZE(pio), DMA_NONE, 0);
912 if (!desc) {
913 pr_err("step 1 error\n");
914 return -1;
915 }
916
917 /* [2] : send DMA request */
918 prepare_data_dma(this, DMA_FROM_DEVICE);
919 desc = channel->device->device_prep_slave_sg(channel, &this->data_sgl,
920 1, DMA_FROM_DEVICE, 1);
921 if (!desc) {
922 pr_err("step 2 error\n");
923 return -1;
924 }
925
926 /* [3] : submit the DMA */
927 set_dma_type(this, DMA_FOR_READ_DATA);
928 return start_dma_without_bch_irq(this, desc);
929}
930
931int gpmi_send_page(struct gpmi_nand_data *this,
932 dma_addr_t payload, dma_addr_t auxiliary)
933{
934 struct bch_geometry *geo = &this->bch_geometry;
935 uint32_t command_mode;
936 uint32_t address;
937 uint32_t ecc_command;
938 uint32_t buffer_mask;
939 struct dma_async_tx_descriptor *desc;
940 struct dma_chan *channel = get_dma_chan(this);
941 int chip = this->current_chip;
942 u32 pio[6];
943
944 /* A DMA descriptor that does an ECC page read. */
945 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WRITE;
946 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
947 ecc_command = BV_GPMI_ECCCTRL_ECC_CMD__BCH_ENCODE;
948 buffer_mask = BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_PAGE |
949 BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_AUXONLY;
950
951 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
952 | BM_GPMI_CTRL0_WORD_LENGTH
953 | BF_GPMI_CTRL0_CS(chip, this)
954 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
955 | BF_GPMI_CTRL0_ADDRESS(address)
956 | BF_GPMI_CTRL0_XFER_COUNT(0);
957 pio[1] = 0;
958 pio[2] = BM_GPMI_ECCCTRL_ENABLE_ECC
959 | BF_GPMI_ECCCTRL_ECC_CMD(ecc_command)
960 | BF_GPMI_ECCCTRL_BUFFER_MASK(buffer_mask);
961 pio[3] = geo->page_size;
962 pio[4] = payload;
963 pio[5] = auxiliary;
964
965 desc = channel->device->device_prep_slave_sg(channel,
966 (struct scatterlist *)pio,
967 ARRAY_SIZE(pio), DMA_NONE, 0);
968 if (!desc) {
969 pr_err("step 2 error\n");
970 return -1;
971 }
972 set_dma_type(this, DMA_FOR_WRITE_ECC_PAGE);
973 return start_dma_with_bch_irq(this, desc);
974}
975
976int gpmi_read_page(struct gpmi_nand_data *this,
977 dma_addr_t payload, dma_addr_t auxiliary)
978{
979 struct bch_geometry *geo = &this->bch_geometry;
980 uint32_t command_mode;
981 uint32_t address;
982 uint32_t ecc_command;
983 uint32_t buffer_mask;
984 struct dma_async_tx_descriptor *desc;
985 struct dma_chan *channel = get_dma_chan(this);
986 int chip = this->current_chip;
987 u32 pio[6];
988
989 /* [1] Wait for the chip to report ready. */
990 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WAIT_FOR_READY;
991 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
992
993 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
994 | BM_GPMI_CTRL0_WORD_LENGTH
995 | BF_GPMI_CTRL0_CS(chip, this)
996 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
997 | BF_GPMI_CTRL0_ADDRESS(address)
998 | BF_GPMI_CTRL0_XFER_COUNT(0);
999 pio[1] = 0;
1000 desc = channel->device->device_prep_slave_sg(channel,
1001 (struct scatterlist *)pio, 2, DMA_NONE, 0);
1002 if (!desc) {
1003 pr_err("step 1 error\n");
1004 return -1;
1005 }
1006
1007 /* [2] Enable the BCH block and read. */
1008 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__READ;
1009 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
1010 ecc_command = BV_GPMI_ECCCTRL_ECC_CMD__BCH_DECODE;
1011 buffer_mask = BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_PAGE
1012 | BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_AUXONLY;
1013
1014 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
1015 | BM_GPMI_CTRL0_WORD_LENGTH
1016 | BF_GPMI_CTRL0_CS(chip, this)
1017 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
1018 | BF_GPMI_CTRL0_ADDRESS(address)
1019 | BF_GPMI_CTRL0_XFER_COUNT(geo->page_size);
1020
1021 pio[1] = 0;
1022 pio[2] = BM_GPMI_ECCCTRL_ENABLE_ECC
1023 | BF_GPMI_ECCCTRL_ECC_CMD(ecc_command)
1024 | BF_GPMI_ECCCTRL_BUFFER_MASK(buffer_mask);
1025 pio[3] = geo->page_size;
1026 pio[4] = payload;
1027 pio[5] = auxiliary;
1028 desc = channel->device->device_prep_slave_sg(channel,
1029 (struct scatterlist *)pio,
1030 ARRAY_SIZE(pio), DMA_NONE, 1);
1031 if (!desc) {
1032 pr_err("step 2 error\n");
1033 return -1;
1034 }
1035
1036 /* [3] Disable the BCH block */
1037 command_mode = BV_GPMI_CTRL0_COMMAND_MODE__WAIT_FOR_READY;
1038 address = BV_GPMI_CTRL0_ADDRESS__NAND_DATA;
1039
1040 pio[0] = BF_GPMI_CTRL0_COMMAND_MODE(command_mode)
1041 | BM_GPMI_CTRL0_WORD_LENGTH
1042 | BF_GPMI_CTRL0_CS(chip, this)
1043 | BF_GPMI_CTRL0_LOCK_CS(LOCK_CS_ENABLE, this)
1044 | BF_GPMI_CTRL0_ADDRESS(address)
1045 | BF_GPMI_CTRL0_XFER_COUNT(geo->page_size);
1046 pio[1] = 0;
1047 desc = channel->device->device_prep_slave_sg(channel,
1048 (struct scatterlist *)pio, 2, DMA_NONE, 1);
1049 if (!desc) {
1050 pr_err("step 3 error\n");
1051 return -1;
1052 }
1053
1054 /* [4] submit the DMA */
1055 set_dma_type(this, DMA_FOR_READ_ECC_PAGE);
1056 return start_dma_with_bch_irq(this, desc);
1057}
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
new file mode 100644
index 00000000000..071b63420f0
--- /dev/null
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -0,0 +1,1619 @@
1/*
2 * Freescale GPMI NAND Flash Driver
3 *
4 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
5 * Copyright (C) 2008 Embedded Alley Solutions, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21#include <linux/clk.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/mtd/gpmi-nand.h>
25#include <linux/mtd/partitions.h>
26
27#include "gpmi-nand.h"
28
29/* add our owner bbt descriptor */
30static uint8_t scan_ff_pattern[] = { 0xff };
31static struct nand_bbt_descr gpmi_bbt_descr = {
32 .options = 0,
33 .offs = 0,
34 .len = 1,
35 .pattern = scan_ff_pattern
36};
37
38/* We will use all the (page + OOB). */
39static struct nand_ecclayout gpmi_hw_ecclayout = {
40 .eccbytes = 0,
41 .eccpos = { 0, },
42 .oobfree = { {.offset = 0, .length = 0} }
43};
44
45static irqreturn_t bch_irq(int irq, void *cookie)
46{
47 struct gpmi_nand_data *this = cookie;
48
49 gpmi_clear_bch(this);
50 complete(&this->bch_done);
51 return IRQ_HANDLED;
52}
53
54/*
55 * Calculate the ECC strength by hand:
56 * E : The ECC strength.
57 * G : the length of Galois Field.
58 * N : The chunk count of per page.
59 * O : the oobsize of the NAND chip.
60 * M : the metasize of per page.
61 *
62 * The formula is :
63 * E * G * N
64 * ------------ <= (O - M)
65 * 8
66 *
67 * So, we get E by:
68 * (O - M) * 8
69 * E <= -------------
70 * G * N
71 */
72static inline int get_ecc_strength(struct gpmi_nand_data *this)
73{
74 struct bch_geometry *geo = &this->bch_geometry;
75 struct mtd_info *mtd = &this->mtd;
76 int ecc_strength;
77
78 ecc_strength = ((mtd->oobsize - geo->metadata_size) * 8)
79 / (geo->gf_len * geo->ecc_chunk_count);
80
81 /* We need the minor even number. */
82 return round_down(ecc_strength, 2);
83}
84
85int common_nfc_set_geometry(struct gpmi_nand_data *this)
86{
87 struct bch_geometry *geo = &this->bch_geometry;
88 struct mtd_info *mtd = &this->mtd;
89 unsigned int metadata_size;
90 unsigned int status_size;
91 unsigned int block_mark_bit_offset;
92
93 /*
94 * The size of the metadata can be changed, though we set it to 10
95 * bytes now. But it can't be too large, because we have to save
96 * enough space for BCH.
97 */
98 geo->metadata_size = 10;
99
100 /* The default for the length of Galois Field. */
101 geo->gf_len = 13;
102
103 /* The default for chunk size. There is no oobsize greater then 512. */
104 geo->ecc_chunk_size = 512;
105 while (geo->ecc_chunk_size < mtd->oobsize)
106 geo->ecc_chunk_size *= 2; /* keep C >= O */
107
108 geo->ecc_chunk_count = mtd->writesize / geo->ecc_chunk_size;
109
110 /* We use the same ECC strength for all chunks. */
111 geo->ecc_strength = get_ecc_strength(this);
112 if (!geo->ecc_strength) {
113 pr_err("We get a wrong ECC strength.\n");
114 return -EINVAL;
115 }
116
117 geo->page_size = mtd->writesize + mtd->oobsize;
118 geo->payload_size = mtd->writesize;
119
120 /*
121 * The auxiliary buffer contains the metadata and the ECC status. The
122 * metadata is padded to the nearest 32-bit boundary. The ECC status
123 * contains one byte for every ECC chunk, and is also padded to the
124 * nearest 32-bit boundary.
125 */
126 metadata_size = ALIGN(geo->metadata_size, 4);
127 status_size = ALIGN(geo->ecc_chunk_count, 4);
128
129 geo->auxiliary_size = metadata_size + status_size;
130 geo->auxiliary_status_offset = metadata_size;
131
132 if (!this->swap_block_mark)
133 return 0;
134
135 /*
136 * We need to compute the byte and bit offsets of
137 * the physical block mark within the ECC-based view of the page.
138 *
139 * NAND chip with 2K page shows below:
140 * (Block Mark)
141 * | |
142 * | D |
143 * |<---->|
144 * V V
145 * +---+----------+-+----------+-+----------+-+----------+-+
146 * | M | data |E| data |E| data |E| data |E|
147 * +---+----------+-+----------+-+----------+-+----------+-+
148 *
149 * The position of block mark moves forward in the ECC-based view
150 * of page, and the delta is:
151 *
152 * E * G * (N - 1)
153 * D = (---------------- + M)
154 * 8
155 *
156 * With the formula to compute the ECC strength, and the condition
157 * : C >= O (C is the ecc chunk size)
158 *
159 * It's easy to deduce to the following result:
160 *
161 * E * G (O - M) C - M C - M
162 * ----------- <= ------- <= -------- < ---------
163 * 8 N N (N - 1)
164 *
165 * So, we get:
166 *
167 * E * G * (N - 1)
168 * D = (---------------- + M) < C
169 * 8
170 *
171 * The above inequality means the position of block mark
172 * within the ECC-based view of the page is still in the data chunk,
173 * and it's NOT in the ECC bits of the chunk.
174 *
175 * Use the following to compute the bit position of the
176 * physical block mark within the ECC-based view of the page:
177 * (page_size - D) * 8
178 *
179 * --Huang Shijie
180 */
181 block_mark_bit_offset = mtd->writesize * 8 -
182 (geo->ecc_strength * geo->gf_len * (geo->ecc_chunk_count - 1)
183 + geo->metadata_size * 8);
184
185 geo->block_mark_byte_offset = block_mark_bit_offset / 8;
186 geo->block_mark_bit_offset = block_mark_bit_offset % 8;
187 return 0;
188}
189
190struct dma_chan *get_dma_chan(struct gpmi_nand_data *this)
191{
192 int chipnr = this->current_chip;
193
194 return this->dma_chans[chipnr];
195}
196
197/* Can we use the upper's buffer directly for DMA? */
198void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
199{
200 struct scatterlist *sgl = &this->data_sgl;
201 int ret;
202
203 this->direct_dma_map_ok = true;
204
205 /* first try to map the upper buffer directly */
206 sg_init_one(sgl, this->upper_buf, this->upper_len);
207 ret = dma_map_sg(this->dev, sgl, 1, dr);
208 if (ret == 0) {
209 /* We have to use our own DMA buffer. */
210 sg_init_one(sgl, this->data_buffer_dma, PAGE_SIZE);
211
212 if (dr == DMA_TO_DEVICE)
213 memcpy(this->data_buffer_dma, this->upper_buf,
214 this->upper_len);
215
216 ret = dma_map_sg(this->dev, sgl, 1, dr);
217 if (ret == 0)
218 pr_err("map failed.\n");
219
220 this->direct_dma_map_ok = false;
221 }
222}
223
224/* This will be called after the DMA operation is finished. */
225static void dma_irq_callback(void *param)
226{
227 struct gpmi_nand_data *this = param;
228 struct completion *dma_c = &this->dma_done;
229
230 complete(dma_c);
231
232 switch (this->dma_type) {
233 case DMA_FOR_COMMAND:
234 dma_unmap_sg(this->dev, &this->cmd_sgl, 1, DMA_TO_DEVICE);
235 break;
236
237 case DMA_FOR_READ_DATA:
238 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_FROM_DEVICE);
239 if (this->direct_dma_map_ok == false)
240 memcpy(this->upper_buf, this->data_buffer_dma,
241 this->upper_len);
242 break;
243
244 case DMA_FOR_WRITE_DATA:
245 dma_unmap_sg(this->dev, &this->data_sgl, 1, DMA_TO_DEVICE);
246 break;
247
248 case DMA_FOR_READ_ECC_PAGE:
249 case DMA_FOR_WRITE_ECC_PAGE:
250 /* We have to wait the BCH interrupt to finish. */
251 break;
252
253 default:
254 pr_err("in wrong DMA operation.\n");
255 }
256}
257
258int start_dma_without_bch_irq(struct gpmi_nand_data *this,
259 struct dma_async_tx_descriptor *desc)
260{
261 struct completion *dma_c = &this->dma_done;
262 int err;
263
264 init_completion(dma_c);
265
266 desc->callback = dma_irq_callback;
267 desc->callback_param = this;
268 dmaengine_submit(desc);
269
270 /* Wait for the interrupt from the DMA block. */
271 err = wait_for_completion_timeout(dma_c, msecs_to_jiffies(1000));
272 if (!err) {
273 pr_err("DMA timeout, last DMA :%d\n", this->last_dma_type);
274 gpmi_dump_info(this);
275 return -ETIMEDOUT;
276 }
277 return 0;
278}
279
280/*
281 * This function is used in BCH reading or BCH writing pages.
282 * It will wait for the BCH interrupt as long as ONE second.
283 * Actually, we must wait for two interrupts :
284 * [1] firstly the DMA interrupt and
285 * [2] secondly the BCH interrupt.
286 */
287int start_dma_with_bch_irq(struct gpmi_nand_data *this,
288 struct dma_async_tx_descriptor *desc)
289{
290 struct completion *bch_c = &this->bch_done;
291 int err;
292
293 /* Prepare to receive an interrupt from the BCH block. */
294 init_completion(bch_c);
295
296 /* start the DMA */
297 start_dma_without_bch_irq(this, desc);
298
299 /* Wait for the interrupt from the BCH block. */
300 err = wait_for_completion_timeout(bch_c, msecs_to_jiffies(1000));
301 if (!err) {
302 pr_err("BCH timeout, last DMA :%d\n", this->last_dma_type);
303 gpmi_dump_info(this);
304 return -ETIMEDOUT;
305 }
306 return 0;
307}
308
309static int __devinit
310acquire_register_block(struct gpmi_nand_data *this, const char *res_name)
311{
312 struct platform_device *pdev = this->pdev;
313 struct resources *res = &this->resources;
314 struct resource *r;
315 void *p;
316
317 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name);
318 if (!r) {
319 pr_err("Can't get resource for %s\n", res_name);
320 return -ENXIO;
321 }
322
323 p = ioremap(r->start, resource_size(r));
324 if (!p) {
325 pr_err("Can't remap %s\n", res_name);
326 return -ENOMEM;
327 }
328
329 if (!strcmp(res_name, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME))
330 res->gpmi_regs = p;
331 else if (!strcmp(res_name, GPMI_NAND_BCH_REGS_ADDR_RES_NAME))
332 res->bch_regs = p;
333 else
334 pr_err("unknown resource name : %s\n", res_name);
335
336 return 0;
337}
338
339static void release_register_block(struct gpmi_nand_data *this)
340{
341 struct resources *res = &this->resources;
342 if (res->gpmi_regs)
343 iounmap(res->gpmi_regs);
344 if (res->bch_regs)
345 iounmap(res->bch_regs);
346 res->gpmi_regs = NULL;
347 res->bch_regs = NULL;
348}
349
350static int __devinit
351acquire_bch_irq(struct gpmi_nand_data *this, irq_handler_t irq_h)
352{
353 struct platform_device *pdev = this->pdev;
354 struct resources *res = &this->resources;
355 const char *res_name = GPMI_NAND_BCH_INTERRUPT_RES_NAME;
356 struct resource *r;
357 int err;
358
359 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, res_name);
360 if (!r) {
361 pr_err("Can't get resource for %s\n", res_name);
362 return -ENXIO;
363 }
364
365 err = request_irq(r->start, irq_h, 0, res_name, this);
366 if (err) {
367 pr_err("Can't own %s\n", res_name);
368 return err;
369 }
370
371 res->bch_low_interrupt = r->start;
372 res->bch_high_interrupt = r->end;
373 return 0;
374}
375
376static void release_bch_irq(struct gpmi_nand_data *this)
377{
378 struct resources *res = &this->resources;
379 int i = res->bch_low_interrupt;
380
381 for (; i <= res->bch_high_interrupt; i++)
382 free_irq(i, this);
383}
384
385static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
386{
387 struct gpmi_nand_data *this = param;
388 struct resource *r = this->private;
389
390 if (!mxs_dma_is_apbh(chan))
391 return false;
392 /*
393 * only catch the GPMI dma channels :
394 * for mx23 : MX23_DMA_GPMI0 ~ MX23_DMA_GPMI3
395 * (These four channels share the same IRQ!)
396 *
397 * for mx28 : MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
398 * (These eight channels share the same IRQ!)
399 */
400 if (r->start <= chan->chan_id && chan->chan_id <= r->end) {
401 chan->private = &this->dma_data;
402 return true;
403 }
404 return false;
405}
406
407static void release_dma_channels(struct gpmi_nand_data *this)
408{
409 unsigned int i;
410 for (i = 0; i < DMA_CHANS; i++)
411 if (this->dma_chans[i]) {
412 dma_release_channel(this->dma_chans[i]);
413 this->dma_chans[i] = NULL;
414 }
415}
416
417static int __devinit acquire_dma_channels(struct gpmi_nand_data *this)
418{
419 struct platform_device *pdev = this->pdev;
420 struct gpmi_nand_platform_data *pdata = this->pdata;
421 struct resources *res = &this->resources;
422 struct resource *r, *r_dma;
423 unsigned int i;
424
425 r = platform_get_resource_byname(pdev, IORESOURCE_DMA,
426 GPMI_NAND_DMA_CHANNELS_RES_NAME);
427 r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
428 GPMI_NAND_DMA_INTERRUPT_RES_NAME);
429 if (!r || !r_dma) {
430 pr_err("Can't get resource for DMA\n");
431 return -ENXIO;
432 }
433
434 /* used in gpmi_dma_filter() */
435 this->private = r;
436
437 for (i = r->start; i <= r->end; i++) {
438 struct dma_chan *dma_chan;
439 dma_cap_mask_t mask;
440
441 if (i - r->start >= pdata->max_chip_count)
442 break;
443
444 dma_cap_zero(mask);
445 dma_cap_set(DMA_SLAVE, mask);
446
447 /* get the DMA interrupt */
448 if (r_dma->start == r_dma->end) {
449 /* only register the first. */
450 if (i == r->start)
451 this->dma_data.chan_irq = r_dma->start;
452 else
453 this->dma_data.chan_irq = NO_IRQ;
454 } else
455 this->dma_data.chan_irq = r_dma->start + (i - r->start);
456
457 dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
458 if (!dma_chan)
459 goto acquire_err;
460
461 /* fill the first empty item */
462 this->dma_chans[i - r->start] = dma_chan;
463 }
464
465 res->dma_low_channel = r->start;
466 res->dma_high_channel = i;
467 return 0;
468
469acquire_err:
470 pr_err("Can't acquire DMA channel %u\n", i);
471 release_dma_channels(this);
472 return -EINVAL;
473}
474
475static int __devinit acquire_resources(struct gpmi_nand_data *this)
476{
477 struct resources *res = &this->resources;
478 int ret;
479
480 ret = acquire_register_block(this, GPMI_NAND_GPMI_REGS_ADDR_RES_NAME);
481 if (ret)
482 goto exit_regs;
483
484 ret = acquire_register_block(this, GPMI_NAND_BCH_REGS_ADDR_RES_NAME);
485 if (ret)
486 goto exit_regs;
487
488 ret = acquire_bch_irq(this, bch_irq);
489 if (ret)
490 goto exit_regs;
491
492 ret = acquire_dma_channels(this);
493 if (ret)
494 goto exit_dma_channels;
495
496 res->clock = clk_get(&this->pdev->dev, NULL);
497 if (IS_ERR(res->clock)) {
498 pr_err("can not get the clock\n");
499 ret = -ENOENT;
500 goto exit_clock;
501 }
502 return 0;
503
504exit_clock:
505 release_dma_channels(this);
506exit_dma_channels:
507 release_bch_irq(this);
508exit_regs:
509 release_register_block(this);
510 return ret;
511}
512
513static void release_resources(struct gpmi_nand_data *this)
514{
515 struct resources *r = &this->resources;
516
517 clk_put(r->clock);
518 release_register_block(this);
519 release_bch_irq(this);
520 release_dma_channels(this);
521}
522
523static int __devinit init_hardware(struct gpmi_nand_data *this)
524{
525 int ret;
526
527 /*
528 * This structure contains the "safe" GPMI timing that should succeed
529 * with any NAND Flash device
530 * (although, with less-than-optimal performance).
531 */
532 struct nand_timing safe_timing = {
533 .data_setup_in_ns = 80,
534 .data_hold_in_ns = 60,
535 .address_setup_in_ns = 25,
536 .gpmi_sample_delay_in_ns = 6,
537 .tREA_in_ns = -1,
538 .tRLOH_in_ns = -1,
539 .tRHOH_in_ns = -1,
540 };
541
542 /* Initialize the hardwares. */
543 ret = gpmi_init(this);
544 if (ret)
545 return ret;
546
547 this->timing = safe_timing;
548 return 0;
549}
550
551static int read_page_prepare(struct gpmi_nand_data *this,
552 void *destination, unsigned length,
553 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
554 void **use_virt, dma_addr_t *use_phys)
555{
556 struct device *dev = this->dev;
557
558 if (virt_addr_valid(destination)) {
559 dma_addr_t dest_phys;
560
561 dest_phys = dma_map_single(dev, destination,
562 length, DMA_FROM_DEVICE);
563 if (dma_mapping_error(dev, dest_phys)) {
564 if (alt_size < length) {
565 pr_err("Alternate buffer is too small\n");
566 return -ENOMEM;
567 }
568 goto map_failed;
569 }
570 *use_virt = destination;
571 *use_phys = dest_phys;
572 this->direct_dma_map_ok = true;
573 return 0;
574 }
575
576map_failed:
577 *use_virt = alt_virt;
578 *use_phys = alt_phys;
579 this->direct_dma_map_ok = false;
580 return 0;
581}
582
583static inline void read_page_end(struct gpmi_nand_data *this,
584 void *destination, unsigned length,
585 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
586 void *used_virt, dma_addr_t used_phys)
587{
588 if (this->direct_dma_map_ok)
589 dma_unmap_single(this->dev, used_phys, length, DMA_FROM_DEVICE);
590}
591
592static inline void read_page_swap_end(struct gpmi_nand_data *this,
593 void *destination, unsigned length,
594 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
595 void *used_virt, dma_addr_t used_phys)
596{
597 if (!this->direct_dma_map_ok)
598 memcpy(destination, alt_virt, length);
599}
600
601static int send_page_prepare(struct gpmi_nand_data *this,
602 const void *source, unsigned length,
603 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
604 const void **use_virt, dma_addr_t *use_phys)
605{
606 struct device *dev = this->dev;
607
608 if (virt_addr_valid(source)) {
609 dma_addr_t source_phys;
610
611 source_phys = dma_map_single(dev, (void *)source, length,
612 DMA_TO_DEVICE);
613 if (dma_mapping_error(dev, source_phys)) {
614 if (alt_size < length) {
615 pr_err("Alternate buffer is too small\n");
616 return -ENOMEM;
617 }
618 goto map_failed;
619 }
620 *use_virt = source;
621 *use_phys = source_phys;
622 return 0;
623 }
624map_failed:
625 /*
626 * Copy the content of the source buffer into the alternate
627 * buffer and set up the return values accordingly.
628 */
629 memcpy(alt_virt, source, length);
630
631 *use_virt = alt_virt;
632 *use_phys = alt_phys;
633 return 0;
634}
635
636static void send_page_end(struct gpmi_nand_data *this,
637 const void *source, unsigned length,
638 void *alt_virt, dma_addr_t alt_phys, unsigned alt_size,
639 const void *used_virt, dma_addr_t used_phys)
640{
641 struct device *dev = this->dev;
642 if (used_virt == source)
643 dma_unmap_single(dev, used_phys, length, DMA_TO_DEVICE);
644}
645
646static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
647{
648 struct device *dev = this->dev;
649
650 if (this->page_buffer_virt && virt_addr_valid(this->page_buffer_virt))
651 dma_free_coherent(dev, this->page_buffer_size,
652 this->page_buffer_virt,
653 this->page_buffer_phys);
654 kfree(this->cmd_buffer);
655 kfree(this->data_buffer_dma);
656
657 this->cmd_buffer = NULL;
658 this->data_buffer_dma = NULL;
659 this->page_buffer_virt = NULL;
660 this->page_buffer_size = 0;
661}
662
663/* Allocate the DMA buffers */
664static int gpmi_alloc_dma_buffer(struct gpmi_nand_data *this)
665{
666 struct bch_geometry *geo = &this->bch_geometry;
667 struct device *dev = this->dev;
668
669 /* [1] Allocate a command buffer. PAGE_SIZE is enough. */
670 this->cmd_buffer = kzalloc(PAGE_SIZE, GFP_DMA);
671 if (this->cmd_buffer == NULL)
672 goto error_alloc;
673
674 /* [2] Allocate a read/write data buffer. PAGE_SIZE is enough. */
675 this->data_buffer_dma = kzalloc(PAGE_SIZE, GFP_DMA);
676 if (this->data_buffer_dma == NULL)
677 goto error_alloc;
678
679 /*
680 * [3] Allocate the page buffer.
681 *
682 * Both the payload buffer and the auxiliary buffer must appear on
683 * 32-bit boundaries. We presume the size of the payload buffer is a
684 * power of two and is much larger than four, which guarantees the
685 * auxiliary buffer will appear on a 32-bit boundary.
686 */
687 this->page_buffer_size = geo->payload_size + geo->auxiliary_size;
688 this->page_buffer_virt = dma_alloc_coherent(dev, this->page_buffer_size,
689 &this->page_buffer_phys, GFP_DMA);
690 if (!this->page_buffer_virt)
691 goto error_alloc;
692
693
694 /* Slice up the page buffer. */
695 this->payload_virt = this->page_buffer_virt;
696 this->payload_phys = this->page_buffer_phys;
697 this->auxiliary_virt = this->payload_virt + geo->payload_size;
698 this->auxiliary_phys = this->payload_phys + geo->payload_size;
699 return 0;
700
701error_alloc:
702 gpmi_free_dma_buffer(this);
703 pr_err("allocate DMA buffer ret!!\n");
704 return -ENOMEM;
705}
706
707static void gpmi_cmd_ctrl(struct mtd_info *mtd, int data, unsigned int ctrl)
708{
709 struct nand_chip *chip = mtd->priv;
710 struct gpmi_nand_data *this = chip->priv;
711 int ret;
712
713 /*
714 * Every operation begins with a command byte and a series of zero or
715 * more address bytes. These are distinguished by either the Address
716 * Latch Enable (ALE) or Command Latch Enable (CLE) signals being
717 * asserted. When MTD is ready to execute the command, it will deassert
718 * both latch enables.
719 *
720 * Rather than run a separate DMA operation for every single byte, we
721 * queue them up and run a single DMA operation for the entire series
722 * of command and data bytes. NAND_CMD_NONE means the END of the queue.
723 */
724 if ((ctrl & (NAND_ALE | NAND_CLE))) {
725 if (data != NAND_CMD_NONE)
726 this->cmd_buffer[this->command_length++] = data;
727 return;
728 }
729
730 if (!this->command_length)
731 return;
732
733 ret = gpmi_send_command(this);
734 if (ret)
735 pr_err("Chip: %u, Error %d\n", this->current_chip, ret);
736
737 this->command_length = 0;
738}
739
740static int gpmi_dev_ready(struct mtd_info *mtd)
741{
742 struct nand_chip *chip = mtd->priv;
743 struct gpmi_nand_data *this = chip->priv;
744
745 return gpmi_is_ready(this, this->current_chip);
746}
747
748static void gpmi_select_chip(struct mtd_info *mtd, int chipnr)
749{
750 struct nand_chip *chip = mtd->priv;
751 struct gpmi_nand_data *this = chip->priv;
752
753 if ((this->current_chip < 0) && (chipnr >= 0))
754 gpmi_begin(this);
755 else if ((this->current_chip >= 0) && (chipnr < 0))
756 gpmi_end(this);
757
758 this->current_chip = chipnr;
759}
760
761static void gpmi_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
762{
763 struct nand_chip *chip = mtd->priv;
764 struct gpmi_nand_data *this = chip->priv;
765
766 pr_debug("len is %d\n", len);
767 this->upper_buf = buf;
768 this->upper_len = len;
769
770 gpmi_read_data(this);
771}
772
773static void gpmi_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
774{
775 struct nand_chip *chip = mtd->priv;
776 struct gpmi_nand_data *this = chip->priv;
777
778 pr_debug("len is %d\n", len);
779 this->upper_buf = (uint8_t *)buf;
780 this->upper_len = len;
781
782 gpmi_send_data(this);
783}
784
785static uint8_t gpmi_read_byte(struct mtd_info *mtd)
786{
787 struct nand_chip *chip = mtd->priv;
788 struct gpmi_nand_data *this = chip->priv;
789 uint8_t *buf = this->data_buffer_dma;
790
791 gpmi_read_buf(mtd, buf, 1);
792 return buf[0];
793}
794
795/*
796 * Handles block mark swapping.
797 * It can be called in swapping the block mark, or swapping it back,
798 * because the the operations are the same.
799 */
800static void block_mark_swapping(struct gpmi_nand_data *this,
801 void *payload, void *auxiliary)
802{
803 struct bch_geometry *nfc_geo = &this->bch_geometry;
804 unsigned char *p;
805 unsigned char *a;
806 unsigned int bit;
807 unsigned char mask;
808 unsigned char from_data;
809 unsigned char from_oob;
810
811 if (!this->swap_block_mark)
812 return;
813
814 /*
815 * If control arrives here, we're swapping. Make some convenience
816 * variables.
817 */
818 bit = nfc_geo->block_mark_bit_offset;
819 p = payload + nfc_geo->block_mark_byte_offset;
820 a = auxiliary;
821
822 /*
823 * Get the byte from the data area that overlays the block mark. Since
824 * the ECC engine applies its own view to the bits in the page, the
825 * physical block mark won't (in general) appear on a byte boundary in
826 * the data.
827 */
828 from_data = (p[0] >> bit) | (p[1] << (8 - bit));
829
830 /* Get the byte from the OOB. */
831 from_oob = a[0];
832
833 /* Swap them. */
834 a[0] = from_data;
835
836 mask = (0x1 << bit) - 1;
837 p[0] = (p[0] & mask) | (from_oob << bit);
838
839 mask = ~0 << bit;
840 p[1] = (p[1] & mask) | (from_oob >> (8 - bit));
841}
842
843static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
844 uint8_t *buf, int page)
845{
846 struct gpmi_nand_data *this = chip->priv;
847 struct bch_geometry *nfc_geo = &this->bch_geometry;
848 void *payload_virt;
849 dma_addr_t payload_phys;
850 void *auxiliary_virt;
851 dma_addr_t auxiliary_phys;
852 unsigned int i;
853 unsigned char *status;
854 unsigned int failed;
855 unsigned int corrected;
856 int ret;
857
858 pr_debug("page number is : %d\n", page);
859 ret = read_page_prepare(this, buf, mtd->writesize,
860 this->payload_virt, this->payload_phys,
861 nfc_geo->payload_size,
862 &payload_virt, &payload_phys);
863 if (ret) {
864 pr_err("Inadequate DMA buffer\n");
865 ret = -ENOMEM;
866 return ret;
867 }
868 auxiliary_virt = this->auxiliary_virt;
869 auxiliary_phys = this->auxiliary_phys;
870
871 /* go! */
872 ret = gpmi_read_page(this, payload_phys, auxiliary_phys);
873 read_page_end(this, buf, mtd->writesize,
874 this->payload_virt, this->payload_phys,
875 nfc_geo->payload_size,
876 payload_virt, payload_phys);
877 if (ret) {
878 pr_err("Error in ECC-based read: %d\n", ret);
879 goto exit_nfc;
880 }
881
882 /* handle the block mark swapping */
883 block_mark_swapping(this, payload_virt, auxiliary_virt);
884
885 /* Loop over status bytes, accumulating ECC status. */
886 failed = 0;
887 corrected = 0;
888 status = auxiliary_virt + nfc_geo->auxiliary_status_offset;
889
890 for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) {
891 if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED))
892 continue;
893
894 if (*status == STATUS_UNCORRECTABLE) {
895 failed++;
896 continue;
897 }
898 corrected += *status;
899 }
900
901 /*
902 * Propagate ECC status to the owning MTD only when failed or
903 * corrected times nearly reaches our ECC correction threshold.
904 */
905 if (failed || corrected >= (nfc_geo->ecc_strength - 1)) {
906 mtd->ecc_stats.failed += failed;
907 mtd->ecc_stats.corrected += corrected;
908 }
909
910 /*
911 * It's time to deliver the OOB bytes. See gpmi_ecc_read_oob() for
912 * details about our policy for delivering the OOB.
913 *
914 * We fill the caller's buffer with set bits, and then copy the block
915 * mark to th caller's buffer. Note that, if block mark swapping was
916 * necessary, it has already been done, so we can rely on the first
917 * byte of the auxiliary buffer to contain the block mark.
918 */
919 memset(chip->oob_poi, ~0, mtd->oobsize);
920 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
921
922 read_page_swap_end(this, buf, mtd->writesize,
923 this->payload_virt, this->payload_phys,
924 nfc_geo->payload_size,
925 payload_virt, payload_phys);
926exit_nfc:
927 return ret;
928}
929
930static void gpmi_ecc_write_page(struct mtd_info *mtd,
931 struct nand_chip *chip, const uint8_t *buf)
932{
933 struct gpmi_nand_data *this = chip->priv;
934 struct bch_geometry *nfc_geo = &this->bch_geometry;
935 const void *payload_virt;
936 dma_addr_t payload_phys;
937 const void *auxiliary_virt;
938 dma_addr_t auxiliary_phys;
939 int ret;
940
941 pr_debug("ecc write page.\n");
942 if (this->swap_block_mark) {
943 /*
944 * If control arrives here, we're doing block mark swapping.
945 * Since we can't modify the caller's buffers, we must copy them
946 * into our own.
947 */
948 memcpy(this->payload_virt, buf, mtd->writesize);
949 payload_virt = this->payload_virt;
950 payload_phys = this->payload_phys;
951
952 memcpy(this->auxiliary_virt, chip->oob_poi,
953 nfc_geo->auxiliary_size);
954 auxiliary_virt = this->auxiliary_virt;
955 auxiliary_phys = this->auxiliary_phys;
956
957 /* Handle block mark swapping. */
958 block_mark_swapping(this,
959 (void *) payload_virt, (void *) auxiliary_virt);
960 } else {
961 /*
962 * If control arrives here, we're not doing block mark swapping,
963 * so we can to try and use the caller's buffers.
964 */
965 ret = send_page_prepare(this,
966 buf, mtd->writesize,
967 this->payload_virt, this->payload_phys,
968 nfc_geo->payload_size,
969 &payload_virt, &payload_phys);
970 if (ret) {
971 pr_err("Inadequate payload DMA buffer\n");
972 return;
973 }
974
975 ret = send_page_prepare(this,
976 chip->oob_poi, mtd->oobsize,
977 this->auxiliary_virt, this->auxiliary_phys,
978 nfc_geo->auxiliary_size,
979 &auxiliary_virt, &auxiliary_phys);
980 if (ret) {
981 pr_err("Inadequate auxiliary DMA buffer\n");
982 goto exit_auxiliary;
983 }
984 }
985
986 /* Ask the NFC. */
987 ret = gpmi_send_page(this, payload_phys, auxiliary_phys);
988 if (ret)
989 pr_err("Error in ECC-based write: %d\n", ret);
990
991 if (!this->swap_block_mark) {
992 send_page_end(this, chip->oob_poi, mtd->oobsize,
993 this->auxiliary_virt, this->auxiliary_phys,
994 nfc_geo->auxiliary_size,
995 auxiliary_virt, auxiliary_phys);
996exit_auxiliary:
997 send_page_end(this, buf, mtd->writesize,
998 this->payload_virt, this->payload_phys,
999 nfc_geo->payload_size,
1000 payload_virt, payload_phys);
1001 }
1002}
1003
1004/*
1005 * There are several places in this driver where we have to handle the OOB and
1006 * block marks. This is the function where things are the most complicated, so
1007 * this is where we try to explain it all. All the other places refer back to
1008 * here.
1009 *
1010 * These are the rules, in order of decreasing importance:
1011 *
1012 * 1) Nothing the caller does can be allowed to imperil the block mark.
1013 *
1014 * 2) In read operations, the first byte of the OOB we return must reflect the
1015 * true state of the block mark, no matter where that block mark appears in
1016 * the physical page.
1017 *
1018 * 3) ECC-based read operations return an OOB full of set bits (since we never
1019 * allow ECC-based writes to the OOB, it doesn't matter what ECC-based reads
1020 * return).
1021 *
1022 * 4) "Raw" read operations return a direct view of the physical bytes in the
1023 * page, using the conventional definition of which bytes are data and which
1024 * are OOB. This gives the caller a way to see the actual, physical bytes
1025 * in the page, without the distortions applied by our ECC engine.
1026 *
1027 *
1028 * What we do for this specific read operation depends on two questions:
1029 *
1030 * 1) Are we doing a "raw" read, or an ECC-based read?
1031 *
1032 * 2) Are we using block mark swapping or transcription?
1033 *
1034 * There are four cases, illustrated by the following Karnaugh map:
1035 *
1036 * | Raw | ECC-based |
1037 * -------------+-------------------------+-------------------------+
1038 * | Read the conventional | |
1039 * | OOB at the end of the | |
1040 * Swapping | page and return it. It | |
1041 * | contains exactly what | |
1042 * | we want. | Read the block mark and |
1043 * -------------+-------------------------+ return it in a buffer |
1044 * | Read the conventional | full of set bits. |
1045 * | OOB at the end of the | |
1046 * | page and also the block | |
1047 * Transcribing | mark in the metadata. | |
1048 * | Copy the block mark | |
1049 * | into the first byte of | |
1050 * | the OOB. | |
1051 * -------------+-------------------------+-------------------------+
1052 *
1053 * Note that we break rule #4 in the Transcribing/Raw case because we're not
1054 * giving an accurate view of the actual, physical bytes in the page (we're
1055 * overwriting the block mark). That's OK because it's more important to follow
1056 * rule #2.
1057 *
1058 * It turns out that knowing whether we want an "ECC-based" or "raw" read is not
1059 * easy. When reading a page, for example, the NAND Flash MTD code calls our
1060 * ecc.read_page or ecc.read_page_raw function. Thus, the fact that MTD wants an
1061 * ECC-based or raw view of the page is implicit in which function it calls
1062 * (there is a similar pair of ECC-based/raw functions for writing).
1063 *
1064 * Since MTD assumes the OOB is not covered by ECC, there is no pair of
1065 * ECC-based/raw functions for reading or or writing the OOB. The fact that the
1066 * caller wants an ECC-based or raw view of the page is not propagated down to
1067 * this driver.
1068 */
1069static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
1070 int page, int sndcmd)
1071{
1072 struct gpmi_nand_data *this = chip->priv;
1073
1074 pr_debug("page number is %d\n", page);
1075 /* clear the OOB buffer */
1076 memset(chip->oob_poi, ~0, mtd->oobsize);
1077
1078 /* Read out the conventional OOB. */
1079 chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1080 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
1081
1082 /*
1083 * Now, we want to make sure the block mark is correct. In the
1084 * Swapping/Raw case, we already have it. Otherwise, we need to
1085 * explicitly read it.
1086 */
1087 if (!this->swap_block_mark) {
1088 /* Read the block mark into the first byte of the OOB buffer. */
1089 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
1090 chip->oob_poi[0] = chip->read_byte(mtd);
1091 }
1092
1093 /*
1094 * Return true, indicating that the next call to this function must send
1095 * a command.
1096 */
1097 return true;
1098}
1099
1100static int
1101gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
1102{
1103 /*
1104 * The BCH will use all the (page + oob).
1105 * Our gpmi_hw_ecclayout can only prohibit the JFFS2 to write the oob.
1106 * But it can not stop some ioctls such MEMWRITEOOB which uses
1107 * MTD_OPS_PLACE_OOB. So We have to implement this function to prohibit
1108 * these ioctls too.
1109 */
1110 return -EPERM;
1111}
1112
1113static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
1114{
1115 struct nand_chip *chip = mtd->priv;
1116 struct gpmi_nand_data *this = chip->priv;
1117 int block, ret = 0;
1118 uint8_t *block_mark;
1119 int column, page, status, chipnr;
1120
1121 /* Get block number */
1122 block = (int)(ofs >> chip->bbt_erase_shift);
1123 if (chip->bbt)
1124 chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
1125
1126 /* Do we have a flash based bad block table ? */
1127 if (chip->options & NAND_BBT_USE_FLASH)
1128 ret = nand_update_bbt(mtd, ofs);
1129 else {
1130 chipnr = (int)(ofs >> chip->chip_shift);
1131 chip->select_chip(mtd, chipnr);
1132
1133 column = this->swap_block_mark ? mtd->writesize : 0;
1134
1135 /* Write the block mark. */
1136 block_mark = this->data_buffer_dma;
1137 block_mark[0] = 0; /* bad block marker */
1138
1139 /* Shift to get page */
1140 page = (int)(ofs >> chip->page_shift);
1141
1142 chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page);
1143 chip->write_buf(mtd, block_mark, 1);
1144 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1145
1146 status = chip->waitfunc(mtd, chip);
1147 if (status & NAND_STATUS_FAIL)
1148 ret = -EIO;
1149
1150 chip->select_chip(mtd, -1);
1151 }
1152 if (!ret)
1153 mtd->ecc_stats.badblocks++;
1154
1155 return ret;
1156}
1157
1158static int __devinit nand_boot_set_geometry(struct gpmi_nand_data *this)
1159{
1160 struct boot_rom_geometry *geometry = &this->rom_geometry;
1161
1162 /*
1163 * Set the boot block stride size.
1164 *
1165 * In principle, we should be reading this from the OTP bits, since
1166 * that's where the ROM is going to get it. In fact, we don't have any
1167 * way to read the OTP bits, so we go with the default and hope for the
1168 * best.
1169 */
1170 geometry->stride_size_in_pages = 64;
1171
1172 /*
1173 * Set the search area stride exponent.
1174 *
1175 * In principle, we should be reading this from the OTP bits, since
1176 * that's where the ROM is going to get it. In fact, we don't have any
1177 * way to read the OTP bits, so we go with the default and hope for the
1178 * best.
1179 */
1180 geometry->search_area_stride_exponent = 2;
1181 return 0;
1182}
1183
1184static const char *fingerprint = "STMP";
1185static int __devinit mx23_check_transcription_stamp(struct gpmi_nand_data *this)
1186{
1187 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1188 struct device *dev = this->dev;
1189 struct mtd_info *mtd = &this->mtd;
1190 struct nand_chip *chip = &this->nand;
1191 unsigned int search_area_size_in_strides;
1192 unsigned int stride;
1193 unsigned int page;
1194 loff_t byte;
1195 uint8_t *buffer = chip->buffers->databuf;
1196 int saved_chip_number;
1197 int found_an_ncb_fingerprint = false;
1198
1199 /* Compute the number of strides in a search area. */
1200 search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
1201
1202 saved_chip_number = this->current_chip;
1203 chip->select_chip(mtd, 0);
1204
1205 /*
1206 * Loop through the first search area, looking for the NCB fingerprint.
1207 */
1208 dev_dbg(dev, "Scanning for an NCB fingerprint...\n");
1209
1210 for (stride = 0; stride < search_area_size_in_strides; stride++) {
1211 /* Compute the page and byte addresses. */
1212 page = stride * rom_geo->stride_size_in_pages;
1213 byte = page * mtd->writesize;
1214
1215 dev_dbg(dev, "Looking for a fingerprint in page 0x%x\n", page);
1216
1217 /*
1218 * Read the NCB fingerprint. The fingerprint is four bytes long
1219 * and starts in the 12th byte of the page.
1220 */
1221 chip->cmdfunc(mtd, NAND_CMD_READ0, 12, page);
1222 chip->read_buf(mtd, buffer, strlen(fingerprint));
1223
1224 /* Look for the fingerprint. */
1225 if (!memcmp(buffer, fingerprint, strlen(fingerprint))) {
1226 found_an_ncb_fingerprint = true;
1227 break;
1228 }
1229
1230 }
1231
1232 chip->select_chip(mtd, saved_chip_number);
1233
1234 if (found_an_ncb_fingerprint)
1235 dev_dbg(dev, "\tFound a fingerprint\n");
1236 else
1237 dev_dbg(dev, "\tNo fingerprint found\n");
1238 return found_an_ncb_fingerprint;
1239}
1240
1241/* Writes a transcription stamp. */
1242static int __devinit mx23_write_transcription_stamp(struct gpmi_nand_data *this)
1243{
1244 struct device *dev = this->dev;
1245 struct boot_rom_geometry *rom_geo = &this->rom_geometry;
1246 struct mtd_info *mtd = &this->mtd;
1247 struct nand_chip *chip = &this->nand;
1248 unsigned int block_size_in_pages;
1249 unsigned int search_area_size_in_strides;
1250 unsigned int search_area_size_in_pages;
1251 unsigned int search_area_size_in_blocks;
1252 unsigned int block;
1253 unsigned int stride;
1254 unsigned int page;
1255 loff_t byte;
1256 uint8_t *buffer = chip->buffers->databuf;
1257 int saved_chip_number;
1258 int status;
1259
1260 /* Compute the search area geometry. */
1261 block_size_in_pages = mtd->erasesize / mtd->writesize;
1262 search_area_size_in_strides = 1 << rom_geo->search_area_stride_exponent;
1263 search_area_size_in_pages = search_area_size_in_strides *
1264 rom_geo->stride_size_in_pages;
1265 search_area_size_in_blocks =
1266 (search_area_size_in_pages + (block_size_in_pages - 1)) /
1267 block_size_in_pages;
1268
1269 dev_dbg(dev, "Search Area Geometry :\n");
1270 dev_dbg(dev, "\tin Blocks : %u\n", search_area_size_in_blocks);
1271 dev_dbg(dev, "\tin Strides: %u\n", search_area_size_in_strides);
1272 dev_dbg(dev, "\tin Pages : %u\n", search_area_size_in_pages);
1273
1274 /* Select chip 0. */
1275 saved_chip_number = this->current_chip;
1276 chip->select_chip(mtd, 0);
1277
1278 /* Loop over blocks in the first search area, erasing them. */
1279 dev_dbg(dev, "Erasing the search area...\n");
1280
1281 for (block = 0; block < search_area_size_in_blocks; block++) {
1282 /* Compute the page address. */
1283 page = block * block_size_in_pages;
1284
1285 /* Erase this block. */
1286 dev_dbg(dev, "\tErasing block 0x%x\n", block);
1287 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
1288 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
1289
1290 /* Wait for the erase to finish. */
1291 status = chip->waitfunc(mtd, chip);
1292 if (status & NAND_STATUS_FAIL)
1293 dev_err(dev, "[%s] Erase failed.\n", __func__);
1294 }
1295
1296 /* Write the NCB fingerprint into the page buffer. */
1297 memset(buffer, ~0, mtd->writesize);
1298 memset(chip->oob_poi, ~0, mtd->oobsize);
1299 memcpy(buffer + 12, fingerprint, strlen(fingerprint));
1300
1301 /* Loop through the first search area, writing NCB fingerprints. */
1302 dev_dbg(dev, "Writing NCB fingerprints...\n");
1303 for (stride = 0; stride < search_area_size_in_strides; stride++) {
1304 /* Compute the page and byte addresses. */
1305 page = stride * rom_geo->stride_size_in_pages;
1306 byte = page * mtd->writesize;
1307
1308 /* Write the first page of the current stride. */
1309 dev_dbg(dev, "Writing an NCB fingerprint in page 0x%x\n", page);
1310 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
1311 chip->ecc.write_page_raw(mtd, chip, buffer);
1312 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1313
1314 /* Wait for the write to finish. */
1315 status = chip->waitfunc(mtd, chip);
1316 if (status & NAND_STATUS_FAIL)
1317 dev_err(dev, "[%s] Write failed.\n", __func__);
1318 }
1319
1320 /* Deselect chip 0. */
1321 chip->select_chip(mtd, saved_chip_number);
1322 return 0;
1323}
1324
1325static int __devinit mx23_boot_init(struct gpmi_nand_data *this)
1326{
1327 struct device *dev = this->dev;
1328 struct nand_chip *chip = &this->nand;
1329 struct mtd_info *mtd = &this->mtd;
1330 unsigned int block_count;
1331 unsigned int block;
1332 int chipnr;
1333 int page;
1334 loff_t byte;
1335 uint8_t block_mark;
1336 int ret = 0;
1337
1338 /*
1339 * If control arrives here, we can't use block mark swapping, which
1340 * means we're forced to use transcription. First, scan for the
1341 * transcription stamp. If we find it, then we don't have to do
1342 * anything -- the block marks are already transcribed.
1343 */
1344 if (mx23_check_transcription_stamp(this))
1345 return 0;
1346
1347 /*
1348 * If control arrives here, we couldn't find a transcription stamp, so
1349 * so we presume the block marks are in the conventional location.
1350 */
1351 dev_dbg(dev, "Transcribing bad block marks...\n");
1352
1353 /* Compute the number of blocks in the entire medium. */
1354 block_count = chip->chipsize >> chip->phys_erase_shift;
1355
1356 /*
1357 * Loop over all the blocks in the medium, transcribing block marks as
1358 * we go.
1359 */
1360 for (block = 0; block < block_count; block++) {
1361 /*
1362 * Compute the chip, page and byte addresses for this block's
1363 * conventional mark.
1364 */
1365 chipnr = block >> (chip->chip_shift - chip->phys_erase_shift);
1366 page = block << (chip->phys_erase_shift - chip->page_shift);
1367 byte = block << chip->phys_erase_shift;
1368
1369 /* Send the command to read the conventional block mark. */
1370 chip->select_chip(mtd, chipnr);
1371 chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1372 block_mark = chip->read_byte(mtd);
1373 chip->select_chip(mtd, -1);
1374
1375 /*
1376 * Check if the block is marked bad. If so, we need to mark it
1377 * again, but this time the result will be a mark in the
1378 * location where we transcribe block marks.
1379 */
1380 if (block_mark != 0xff) {
1381 dev_dbg(dev, "Transcribing mark in block %u\n", block);
1382 ret = chip->block_markbad(mtd, byte);
1383 if (ret)
1384 dev_err(dev, "Failed to mark block bad with "
1385 "ret %d\n", ret);
1386 }
1387 }
1388
1389 /* Write the stamp that indicates we've transcribed the block marks. */
1390 mx23_write_transcription_stamp(this);
1391 return 0;
1392}
1393
1394static int __devinit nand_boot_init(struct gpmi_nand_data *this)
1395{
1396 nand_boot_set_geometry(this);
1397
1398 /* This is ROM arch-specific initilization before the BBT scanning. */
1399 if (GPMI_IS_MX23(this))
1400 return mx23_boot_init(this);
1401 return 0;
1402}
1403
1404static int __devinit gpmi_set_geometry(struct gpmi_nand_data *this)
1405{
1406 int ret;
1407
1408 /* Free the temporary DMA memory for reading ID. */
1409 gpmi_free_dma_buffer(this);
1410
1411 /* Set up the NFC geometry which is used by BCH. */
1412 ret = bch_set_geometry(this);
1413 if (ret) {
1414 pr_err("set geometry ret : %d\n", ret);
1415 return ret;
1416 }
1417
1418 /* Alloc the new DMA buffers according to the pagesize and oobsize */
1419 return gpmi_alloc_dma_buffer(this);
1420}
1421
1422static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this)
1423{
1424 int ret;
1425
1426 /* Set up swap_block_mark, must be set before the gpmi_set_geometry() */
1427 if (GPMI_IS_MX23(this))
1428 this->swap_block_mark = false;
1429 else
1430 this->swap_block_mark = true;
1431
1432 /* Set up the medium geometry */
1433 ret = gpmi_set_geometry(this);
1434 if (ret)
1435 return ret;
1436
1437 /* NAND boot init, depends on the gpmi_set_geometry(). */
1438 return nand_boot_init(this);
1439}
1440
1441static int gpmi_scan_bbt(struct mtd_info *mtd)
1442{
1443 struct nand_chip *chip = mtd->priv;
1444 struct gpmi_nand_data *this = chip->priv;
1445 int ret;
1446
1447 /* Prepare for the BBT scan. */
1448 ret = gpmi_pre_bbt_scan(this);
1449 if (ret)
1450 return ret;
1451
1452 /* use the default BBT implementation */
1453 return nand_default_bbt(mtd);
1454}
1455
1456void gpmi_nfc_exit(struct gpmi_nand_data *this)
1457{
1458 nand_release(&this->mtd);
1459 gpmi_free_dma_buffer(this);
1460}
1461
1462static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
1463{
1464 struct gpmi_nand_platform_data *pdata = this->pdata;
1465 struct mtd_info *mtd = &this->mtd;
1466 struct nand_chip *chip = &this->nand;
1467 int ret;
1468
1469 /* init current chip */
1470 this->current_chip = -1;
1471
1472 /* init the MTD data structures */
1473 mtd->priv = chip;
1474 mtd->name = "gpmi-nand";
1475 mtd->owner = THIS_MODULE;
1476
1477 /* init the nand_chip{}, we don't support a 16-bit NAND Flash bus. */
1478 chip->priv = this;
1479 chip->select_chip = gpmi_select_chip;
1480 chip->cmd_ctrl = gpmi_cmd_ctrl;
1481 chip->dev_ready = gpmi_dev_ready;
1482 chip->read_byte = gpmi_read_byte;
1483 chip->read_buf = gpmi_read_buf;
1484 chip->write_buf = gpmi_write_buf;
1485 chip->ecc.read_page = gpmi_ecc_read_page;
1486 chip->ecc.write_page = gpmi_ecc_write_page;
1487 chip->ecc.read_oob = gpmi_ecc_read_oob;
1488 chip->ecc.write_oob = gpmi_ecc_write_oob;
1489 chip->scan_bbt = gpmi_scan_bbt;
1490 chip->badblock_pattern = &gpmi_bbt_descr;
1491 chip->block_markbad = gpmi_block_markbad;
1492 chip->options |= NAND_NO_SUBPAGE_WRITE;
1493 chip->ecc.mode = NAND_ECC_HW;
1494 chip->ecc.size = 1;
1495 chip->ecc.layout = &gpmi_hw_ecclayout;
1496
1497 /* Allocate a temporary DMA buffer for reading ID in the nand_scan() */
1498 this->bch_geometry.payload_size = 1024;
1499 this->bch_geometry.auxiliary_size = 128;
1500 ret = gpmi_alloc_dma_buffer(this);
1501 if (ret)
1502 goto err_out;
1503
1504 ret = nand_scan(mtd, pdata->max_chip_count);
1505 if (ret) {
1506 pr_err("Chip scan failed\n");
1507 goto err_out;
1508 }
1509
1510 ret = mtd_device_parse_register(mtd, NULL, NULL,
1511 pdata->partitions, pdata->partition_count);
1512 if (ret)
1513 goto err_out;
1514 return 0;
1515
1516err_out:
1517 gpmi_nfc_exit(this);
1518 return ret;
1519}
1520
1521static int __devinit gpmi_nand_probe(struct platform_device *pdev)
1522{
1523 struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
1524 struct gpmi_nand_data *this;
1525 int ret;
1526
1527 this = kzalloc(sizeof(*this), GFP_KERNEL);
1528 if (!this) {
1529 pr_err("Failed to allocate per-device memory\n");
1530 return -ENOMEM;
1531 }
1532
1533 platform_set_drvdata(pdev, this);
1534 this->pdev = pdev;
1535 this->dev = &pdev->dev;
1536 this->pdata = pdata;
1537
1538 if (pdata->platform_init) {
1539 ret = pdata->platform_init();
1540 if (ret)
1541 goto platform_init_error;
1542 }
1543
1544 ret = acquire_resources(this);
1545 if (ret)
1546 goto exit_acquire_resources;
1547
1548 ret = init_hardware(this);
1549 if (ret)
1550 goto exit_nfc_init;
1551
1552 ret = gpmi_nfc_init(this);
1553 if (ret)
1554 goto exit_nfc_init;
1555
1556 return 0;
1557
1558exit_nfc_init:
1559 release_resources(this);
1560platform_init_error:
1561exit_acquire_resources:
1562 platform_set_drvdata(pdev, NULL);
1563 kfree(this);
1564 return ret;
1565}
1566
1567static int __exit gpmi_nand_remove(struct platform_device *pdev)
1568{
1569 struct gpmi_nand_data *this = platform_get_drvdata(pdev);
1570
1571 gpmi_nfc_exit(this);
1572 release_resources(this);
1573 platform_set_drvdata(pdev, NULL);
1574 kfree(this);
1575 return 0;
1576}
1577
1578static const struct platform_device_id gpmi_ids[] = {
1579 {
1580 .name = "imx23-gpmi-nand",
1581 .driver_data = IS_MX23,
1582 }, {
1583 .name = "imx28-gpmi-nand",
1584 .driver_data = IS_MX28,
1585 }, {},
1586};
1587
1588static struct platform_driver gpmi_nand_driver = {
1589 .driver = {
1590 .name = "gpmi-nand",
1591 },
1592 .probe = gpmi_nand_probe,
1593 .remove = __exit_p(gpmi_nand_remove),
1594 .id_table = gpmi_ids,
1595};
1596
1597static int __init gpmi_nand_init(void)
1598{
1599 int err;
1600
1601 err = platform_driver_register(&gpmi_nand_driver);
1602 if (err == 0)
1603 printk(KERN_INFO "GPMI NAND driver registered. (IMX)\n");
1604 else
1605 pr_err("i.MX GPMI NAND driver registration failed\n");
1606 return err;
1607}
1608
1609static void __exit gpmi_nand_exit(void)
1610{
1611 platform_driver_unregister(&gpmi_nand_driver);
1612}
1613
1614module_init(gpmi_nand_init);
1615module_exit(gpmi_nand_exit);
1616
1617MODULE_AUTHOR("Freescale Semiconductor, Inc.");
1618MODULE_DESCRIPTION("i.MX GPMI NAND Flash Controller Driver");
1619MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
new file mode 100644
index 00000000000..e023bccb778
--- /dev/null
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
@@ -0,0 +1,273 @@
1/*
2 * Freescale GPMI NAND Flash Driver
3 *
4 * Copyright (C) 2010-2011 Freescale Semiconductor, Inc.
5 * Copyright (C) 2008 Embedded Alley Solutions, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17#ifndef __DRIVERS_MTD_NAND_GPMI_NAND_H
18#define __DRIVERS_MTD_NAND_GPMI_NAND_H
19
20#include <linux/mtd/nand.h>
21#include <linux/platform_device.h>
22#include <linux/dma-mapping.h>
23#include <mach/dma.h>
24
25struct resources {
26 void *gpmi_regs;
27 void *bch_regs;
28 unsigned int bch_low_interrupt;
29 unsigned int bch_high_interrupt;
30 unsigned int dma_low_channel;
31 unsigned int dma_high_channel;
32 struct clk *clock;
33};
34
35/**
36 * struct bch_geometry - BCH geometry description.
37 * @gf_len: The length of Galois Field. (e.g., 13 or 14)
38 * @ecc_strength: A number that describes the strength of the ECC
39 * algorithm.
40 * @page_size: The size, in bytes, of a physical page, including
41 * both data and OOB.
42 * @metadata_size: The size, in bytes, of the metadata.
43 * @ecc_chunk_size: The size, in bytes, of a single ECC chunk. Note
44 * the first chunk in the page includes both data and
45 * metadata, so it's a bit larger than this value.
46 * @ecc_chunk_count: The number of ECC chunks in the page,
47 * @payload_size: The size, in bytes, of the payload buffer.
48 * @auxiliary_size: The size, in bytes, of the auxiliary buffer.
49 * @auxiliary_status_offset: The offset into the auxiliary buffer at which
50 * the ECC status appears.
51 * @block_mark_byte_offset: The byte offset in the ECC-based page view at
52 * which the underlying physical block mark appears.
53 * @block_mark_bit_offset: The bit offset into the ECC-based page view at
54 * which the underlying physical block mark appears.
55 */
56struct bch_geometry {
57 unsigned int gf_len;
58 unsigned int ecc_strength;
59 unsigned int page_size;
60 unsigned int metadata_size;
61 unsigned int ecc_chunk_size;
62 unsigned int ecc_chunk_count;
63 unsigned int payload_size;
64 unsigned int auxiliary_size;
65 unsigned int auxiliary_status_offset;
66 unsigned int block_mark_byte_offset;
67 unsigned int block_mark_bit_offset;
68};
69
70/**
71 * struct boot_rom_geometry - Boot ROM geometry description.
72 * @stride_size_in_pages: The size of a boot block stride, in pages.
73 * @search_area_stride_exponent: The logarithm to base 2 of the size of a
74 * search area in boot block strides.
75 */
76struct boot_rom_geometry {
77 unsigned int stride_size_in_pages;
78 unsigned int search_area_stride_exponent;
79};
80
81/* DMA operations types */
82enum dma_ops_type {
83 DMA_FOR_COMMAND = 1,
84 DMA_FOR_READ_DATA,
85 DMA_FOR_WRITE_DATA,
86 DMA_FOR_READ_ECC_PAGE,
87 DMA_FOR_WRITE_ECC_PAGE
88};
89
90/**
91 * struct nand_timing - Fundamental timing attributes for NAND.
92 * @data_setup_in_ns: The data setup time, in nanoseconds. Usually the
93 * maximum of tDS and tWP. A negative value
94 * indicates this characteristic isn't known.
95 * @data_hold_in_ns: The data hold time, in nanoseconds. Usually the
96 * maximum of tDH, tWH and tREH. A negative value
97 * indicates this characteristic isn't known.
98 * @address_setup_in_ns: The address setup time, in nanoseconds. Usually
99 * the maximum of tCLS, tCS and tALS. A negative
100 * value indicates this characteristic isn't known.
101 * @gpmi_sample_delay_in_ns: A GPMI-specific timing parameter. A negative value
102 * indicates this characteristic isn't known.
103 * @tREA_in_ns: tREA, in nanoseconds, from the data sheet. A
104 * negative value indicates this characteristic isn't
105 * known.
106 * @tRLOH_in_ns: tRLOH, in nanoseconds, from the data sheet. A
107 * negative value indicates this characteristic isn't
108 * known.
109 * @tRHOH_in_ns: tRHOH, in nanoseconds, from the data sheet. A
110 * negative value indicates this characteristic isn't
111 * known.
112 */
113struct nand_timing {
114 int8_t data_setup_in_ns;
115 int8_t data_hold_in_ns;
116 int8_t address_setup_in_ns;
117 int8_t gpmi_sample_delay_in_ns;
118 int8_t tREA_in_ns;
119 int8_t tRLOH_in_ns;
120 int8_t tRHOH_in_ns;
121};
122
123struct gpmi_nand_data {
124 /* System Interface */
125 struct device *dev;
126 struct platform_device *pdev;
127 struct gpmi_nand_platform_data *pdata;
128
129 /* Resources */
130 struct resources resources;
131
132 /* Flash Hardware */
133 struct nand_timing timing;
134
135 /* BCH */
136 struct bch_geometry bch_geometry;
137 struct completion bch_done;
138
139 /* NAND Boot issue */
140 bool swap_block_mark;
141 struct boot_rom_geometry rom_geometry;
142
143 /* MTD / NAND */
144 struct nand_chip nand;
145 struct mtd_info mtd;
146
147 /* General-use Variables */
148 int current_chip;
149 unsigned int command_length;
150
151 /* passed from upper layer */
152 uint8_t *upper_buf;
153 int upper_len;
154
155 /* for DMA operations */
156 bool direct_dma_map_ok;
157
158 struct scatterlist cmd_sgl;
159 char *cmd_buffer;
160
161 struct scatterlist data_sgl;
162 char *data_buffer_dma;
163
164 void *page_buffer_virt;
165 dma_addr_t page_buffer_phys;
166 unsigned int page_buffer_size;
167
168 void *payload_virt;
169 dma_addr_t payload_phys;
170
171 void *auxiliary_virt;
172 dma_addr_t auxiliary_phys;
173
174 /* DMA channels */
175#define DMA_CHANS 8
176 struct dma_chan *dma_chans[DMA_CHANS];
177 struct mxs_dma_data dma_data;
178 enum dma_ops_type last_dma_type;
179 enum dma_ops_type dma_type;
180 struct completion dma_done;
181
182 /* private */
183 void *private;
184};
185
186/**
187 * struct gpmi_nfc_hardware_timing - GPMI hardware timing parameters.
188 * @data_setup_in_cycles: The data setup time, in cycles.
189 * @data_hold_in_cycles: The data hold time, in cycles.
190 * @address_setup_in_cycles: The address setup time, in cycles.
191 * @use_half_periods: Indicates the clock is running slowly, so the
192 * NFC DLL should use half-periods.
193 * @sample_delay_factor: The sample delay factor.
194 */
195struct gpmi_nfc_hardware_timing {
196 uint8_t data_setup_in_cycles;
197 uint8_t data_hold_in_cycles;
198 uint8_t address_setup_in_cycles;
199 bool use_half_periods;
200 uint8_t sample_delay_factor;
201};
202
203/**
204 * struct timing_threshod - Timing threshold
205 * @max_data_setup_cycles: The maximum number of data setup cycles that
206 * can be expressed in the hardware.
207 * @internal_data_setup_in_ns: The time, in ns, that the NFC hardware requires
208 * for data read internal setup. In the Reference
209 * Manual, see the chapter "High-Speed NAND
210 * Timing" for more details.
211 * @max_sample_delay_factor: The maximum sample delay factor that can be
212 * expressed in the hardware.
213 * @max_dll_clock_period_in_ns: The maximum period of the GPMI clock that the
214 * sample delay DLL hardware can possibly work
215 * with (the DLL is unusable with longer periods).
216 * If the full-cycle period is greater than HALF
217 * this value, the DLL must be configured to use
218 * half-periods.
219 * @max_dll_delay_in_ns: The maximum amount of delay, in ns, that the
220 * DLL can implement.
221 * @clock_frequency_in_hz: The clock frequency, in Hz, during the current
222 * I/O transaction. If no I/O transaction is in
223 * progress, this is the clock frequency during
224 * the most recent I/O transaction.
225 */
226struct timing_threshod {
227 const unsigned int max_chip_count;
228 const unsigned int max_data_setup_cycles;
229 const unsigned int internal_data_setup_in_ns;
230 const unsigned int max_sample_delay_factor;
231 const unsigned int max_dll_clock_period_in_ns;
232 const unsigned int max_dll_delay_in_ns;
233 unsigned long clock_frequency_in_hz;
234
235};
236
237/* Common Services */
238extern int common_nfc_set_geometry(struct gpmi_nand_data *);
239extern struct dma_chan *get_dma_chan(struct gpmi_nand_data *);
240extern void prepare_data_dma(struct gpmi_nand_data *,
241 enum dma_data_direction dr);
242extern int start_dma_without_bch_irq(struct gpmi_nand_data *,
243 struct dma_async_tx_descriptor *);
244extern int start_dma_with_bch_irq(struct gpmi_nand_data *,
245 struct dma_async_tx_descriptor *);
246
247/* GPMI-NAND helper function library */
248extern int gpmi_init(struct gpmi_nand_data *);
249extern void gpmi_clear_bch(struct gpmi_nand_data *);
250extern void gpmi_dump_info(struct gpmi_nand_data *);
251extern int bch_set_geometry(struct gpmi_nand_data *);
252extern int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
253extern int gpmi_send_command(struct gpmi_nand_data *);
254extern void gpmi_begin(struct gpmi_nand_data *);
255extern void gpmi_end(struct gpmi_nand_data *);
256extern int gpmi_read_data(struct gpmi_nand_data *);
257extern int gpmi_send_data(struct gpmi_nand_data *);
258extern int gpmi_send_page(struct gpmi_nand_data *,
259 dma_addr_t payload, dma_addr_t auxiliary);
260extern int gpmi_read_page(struct gpmi_nand_data *,
261 dma_addr_t payload, dma_addr_t auxiliary);
262
263/* BCH : Status Block Completion Codes */
264#define STATUS_GOOD 0x00
265#define STATUS_ERASED 0xff
266#define STATUS_UNCORRECTABLE 0xfe
267
268/* Use the platform_id to distinguish different Archs. */
269#define IS_MX23 0x1
270#define IS_MX28 0x2
271#define GPMI_IS_MX23(x) ((x)->pdev->id_entry->driver_data == IS_MX23)
272#define GPMI_IS_MX28(x) ((x)->pdev->id_entry->driver_data == IS_MX28)
273#endif
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-regs.h b/drivers/mtd/nand/gpmi-nand/gpmi-regs.h
new file mode 100644
index 00000000000..83431240e2f
--- /dev/null
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-regs.h
@@ -0,0 +1,172 @@
1/*
2 * Freescale GPMI NAND Flash Driver
3 *
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 * Copyright 2008 Embedded Alley Solutions, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21#ifndef __GPMI_NAND_GPMI_REGS_H
22#define __GPMI_NAND_GPMI_REGS_H
23
24#define HW_GPMI_CTRL0 0x00000000
25#define HW_GPMI_CTRL0_SET 0x00000004
26#define HW_GPMI_CTRL0_CLR 0x00000008
27#define HW_GPMI_CTRL0_TOG 0x0000000c
28
29#define BP_GPMI_CTRL0_COMMAND_MODE 24
30#define BM_GPMI_CTRL0_COMMAND_MODE (3 << BP_GPMI_CTRL0_COMMAND_MODE)
31#define BF_GPMI_CTRL0_COMMAND_MODE(v) \
32 (((v) << BP_GPMI_CTRL0_COMMAND_MODE) & BM_GPMI_CTRL0_COMMAND_MODE)
33#define BV_GPMI_CTRL0_COMMAND_MODE__WRITE 0x0
34#define BV_GPMI_CTRL0_COMMAND_MODE__READ 0x1
35#define BV_GPMI_CTRL0_COMMAND_MODE__READ_AND_COMPARE 0x2
36#define BV_GPMI_CTRL0_COMMAND_MODE__WAIT_FOR_READY 0x3
37
38#define BM_GPMI_CTRL0_WORD_LENGTH (1 << 23)
39#define BV_GPMI_CTRL0_WORD_LENGTH__16_BIT 0x0
40#define BV_GPMI_CTRL0_WORD_LENGTH__8_BIT 0x1
41
42/*
43 * Difference in LOCK_CS between imx23 and imx28 :
44 * This bit may impact the _POWER_ consumption. So some chips
45 * do not set it.
46 */
47#define MX23_BP_GPMI_CTRL0_LOCK_CS 22
48#define MX28_BP_GPMI_CTRL0_LOCK_CS 27
49#define LOCK_CS_ENABLE 0x1
50#define BF_GPMI_CTRL0_LOCK_CS(v, x) 0x0
51
52/* Difference in CS between imx23 and imx28 */
53#define BP_GPMI_CTRL0_CS 20
54#define MX23_BM_GPMI_CTRL0_CS (3 << BP_GPMI_CTRL0_CS)
55#define MX28_BM_GPMI_CTRL0_CS (7 << BP_GPMI_CTRL0_CS)
56#define BF_GPMI_CTRL0_CS(v, x) (((v) << BP_GPMI_CTRL0_CS) & \
57 (GPMI_IS_MX23((x)) \
58 ? MX23_BM_GPMI_CTRL0_CS \
59 : MX28_BM_GPMI_CTRL0_CS))
60
61#define BP_GPMI_CTRL0_ADDRESS 17
62#define BM_GPMI_CTRL0_ADDRESS (3 << BP_GPMI_CTRL0_ADDRESS)
63#define BF_GPMI_CTRL0_ADDRESS(v) \
64 (((v) << BP_GPMI_CTRL0_ADDRESS) & BM_GPMI_CTRL0_ADDRESS)
65#define BV_GPMI_CTRL0_ADDRESS__NAND_DATA 0x0
66#define BV_GPMI_CTRL0_ADDRESS__NAND_CLE 0x1
67#define BV_GPMI_CTRL0_ADDRESS__NAND_ALE 0x2
68
69#define BM_GPMI_CTRL0_ADDRESS_INCREMENT (1 << 16)
70#define BV_GPMI_CTRL0_ADDRESS_INCREMENT__DISABLED 0x0
71#define BV_GPMI_CTRL0_ADDRESS_INCREMENT__ENABLED 0x1
72
73#define BP_GPMI_CTRL0_XFER_COUNT 0
74#define BM_GPMI_CTRL0_XFER_COUNT (0xffff << BP_GPMI_CTRL0_XFER_COUNT)
75#define BF_GPMI_CTRL0_XFER_COUNT(v) \
76 (((v) << BP_GPMI_CTRL0_XFER_COUNT) & BM_GPMI_CTRL0_XFER_COUNT)
77
78#define HW_GPMI_COMPARE 0x00000010
79
80#define HW_GPMI_ECCCTRL 0x00000020
81#define HW_GPMI_ECCCTRL_SET 0x00000024
82#define HW_GPMI_ECCCTRL_CLR 0x00000028
83#define HW_GPMI_ECCCTRL_TOG 0x0000002c
84
85#define BP_GPMI_ECCCTRL_ECC_CMD 13
86#define BM_GPMI_ECCCTRL_ECC_CMD (3 << BP_GPMI_ECCCTRL_ECC_CMD)
87#define BF_GPMI_ECCCTRL_ECC_CMD(v) \
88 (((v) << BP_GPMI_ECCCTRL_ECC_CMD) & BM_GPMI_ECCCTRL_ECC_CMD)
89#define BV_GPMI_ECCCTRL_ECC_CMD__BCH_DECODE 0x0
90#define BV_GPMI_ECCCTRL_ECC_CMD__BCH_ENCODE 0x1
91
92#define BM_GPMI_ECCCTRL_ENABLE_ECC (1 << 12)
93#define BV_GPMI_ECCCTRL_ENABLE_ECC__ENABLE 0x1
94#define BV_GPMI_ECCCTRL_ENABLE_ECC__DISABLE 0x0
95
96#define BP_GPMI_ECCCTRL_BUFFER_MASK 0
97#define BM_GPMI_ECCCTRL_BUFFER_MASK (0x1ff << BP_GPMI_ECCCTRL_BUFFER_MASK)
98#define BF_GPMI_ECCCTRL_BUFFER_MASK(v) \
99 (((v) << BP_GPMI_ECCCTRL_BUFFER_MASK) & BM_GPMI_ECCCTRL_BUFFER_MASK)
100#define BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_AUXONLY 0x100
101#define BV_GPMI_ECCCTRL_BUFFER_MASK__BCH_PAGE 0x1FF
102
103#define HW_GPMI_ECCCOUNT 0x00000030
104#define HW_GPMI_PAYLOAD 0x00000040
105#define HW_GPMI_AUXILIARY 0x00000050
106#define HW_GPMI_CTRL1 0x00000060
107#define HW_GPMI_CTRL1_SET 0x00000064
108#define HW_GPMI_CTRL1_CLR 0x00000068
109#define HW_GPMI_CTRL1_TOG 0x0000006c
110
111#define BM_GPMI_CTRL1_BCH_MODE (1 << 18)
112
113#define BP_GPMI_CTRL1_DLL_ENABLE 17
114#define BM_GPMI_CTRL1_DLL_ENABLE (1 << BP_GPMI_CTRL1_DLL_ENABLE)
115
116#define BP_GPMI_CTRL1_HALF_PERIOD 16
117#define BM_GPMI_CTRL1_HALF_PERIOD (1 << BP_GPMI_CTRL1_HALF_PERIOD)
118
119#define BP_GPMI_CTRL1_RDN_DELAY 12
120#define BM_GPMI_CTRL1_RDN_DELAY (0xf << BP_GPMI_CTRL1_RDN_DELAY)
121#define BF_GPMI_CTRL1_RDN_DELAY(v) \
122 (((v) << BP_GPMI_CTRL1_RDN_DELAY) & BM_GPMI_CTRL1_RDN_DELAY)
123
124#define BM_GPMI_CTRL1_DEV_RESET (1 << 3)
125#define BV_GPMI_CTRL1_DEV_RESET__ENABLED 0x0
126#define BV_GPMI_CTRL1_DEV_RESET__DISABLED 0x1
127
128#define BM_GPMI_CTRL1_ATA_IRQRDY_POLARITY (1 << 2)
129#define BV_GPMI_CTRL1_ATA_IRQRDY_POLARITY__ACTIVELOW 0x0
130#define BV_GPMI_CTRL1_ATA_IRQRDY_POLARITY__ACTIVEHIGH 0x1
131
132#define BM_GPMI_CTRL1_CAMERA_MODE (1 << 1)
133#define BV_GPMI_CTRL1_GPMI_MODE__NAND 0x0
134#define BV_GPMI_CTRL1_GPMI_MODE__ATA 0x1
135
136#define BM_GPMI_CTRL1_GPMI_MODE (1 << 0)
137
138#define HW_GPMI_TIMING0 0x00000070
139
140#define BP_GPMI_TIMING0_ADDRESS_SETUP 16
141#define BM_GPMI_TIMING0_ADDRESS_SETUP (0xff << BP_GPMI_TIMING0_ADDRESS_SETUP)
142#define BF_GPMI_TIMING0_ADDRESS_SETUP(v) \
143 (((v) << BP_GPMI_TIMING0_ADDRESS_SETUP) & BM_GPMI_TIMING0_ADDRESS_SETUP)
144
145#define BP_GPMI_TIMING0_DATA_HOLD 8
146#define BM_GPMI_TIMING0_DATA_HOLD (0xff << BP_GPMI_TIMING0_DATA_HOLD)
147#define BF_GPMI_TIMING0_DATA_HOLD(v) \
148 (((v) << BP_GPMI_TIMING0_DATA_HOLD) & BM_GPMI_TIMING0_DATA_HOLD)
149
150#define BP_GPMI_TIMING0_DATA_SETUP 0
151#define BM_GPMI_TIMING0_DATA_SETUP (0xff << BP_GPMI_TIMING0_DATA_SETUP)
152#define BF_GPMI_TIMING0_DATA_SETUP(v) \
153 (((v) << BP_GPMI_TIMING0_DATA_SETUP) & BM_GPMI_TIMING0_DATA_SETUP)
154
155#define HW_GPMI_TIMING1 0x00000080
156#define BP_GPMI_TIMING1_BUSY_TIMEOUT 16
157
158#define HW_GPMI_TIMING2 0x00000090
159#define HW_GPMI_DATA 0x000000a0
160
161/* MX28 uses this to detect READY. */
162#define HW_GPMI_STAT 0x000000b0
163#define MX28_BP_GPMI_STAT_READY_BUSY 24
164#define MX28_BM_GPMI_STAT_READY_BUSY (0xff << MX28_BP_GPMI_STAT_READY_BUSY)
165#define MX28_BF_GPMI_STAT_READY_BUSY(v) \
166 (((v) << MX28_BP_GPMI_STAT_READY_BUSY) & MX28_BM_GPMI_STAT_READY_BUSY)
167
168/* MX23 uses this to detect READY. */
169#define HW_GPMI_DEBUG 0x000000c0
170#define MX23_BP_GPMI_DEBUG_READY0 28
171#define MX23_BM_GPMI_DEBUG_READY0 (1 << MX23_BP_GPMI_DEBUG_READY0)
172#endif
diff --git a/drivers/mtd/nand/h1910.c b/drivers/mtd/nand/h1910.c
index 02a03e67109..5dc6f0d92f1 100644
--- a/drivers/mtd/nand/h1910.c
+++ b/drivers/mtd/nand/h1910.c
@@ -81,9 +81,6 @@ static int h1910_device_ready(struct mtd_info *mtd)
81static int __init h1910_init(void) 81static int __init h1910_init(void)
82{ 82{
83 struct nand_chip *this; 83 struct nand_chip *this;
84 const char *part_type = 0;
85 int mtd_parts_nb = 0;
86 struct mtd_partition *mtd_parts = 0;
87 void __iomem *nandaddr; 84 void __iomem *nandaddr;
88 85
89 if (!machine_is_h1900()) 86 if (!machine_is_h1900())
@@ -136,22 +133,10 @@ static int __init h1910_init(void)
136 iounmap((void *)nandaddr); 133 iounmap((void *)nandaddr);
137 return -ENXIO; 134 return -ENXIO;
138 } 135 }
139#ifdef CONFIG_MTD_CMDLINE_PARTS
140 mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
141 if (mtd_parts_nb > 0)
142 part_type = "command line";
143 else
144 mtd_parts_nb = 0;
145#endif
146 if (mtd_parts_nb == 0) {
147 mtd_parts = partition_info;
148 mtd_parts_nb = NUM_PARTITIONS;
149 part_type = "static";
150 }
151 136
152 /* Register the partitions */ 137 /* Register the partitions */
153 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 138 mtd_device_parse_register(h1910_nand_mtd, NULL, 0,
154 mtd_device_register(h1910_nand_mtd, mtd_parts, mtd_parts_nb); 139 partition_info, NUM_PARTITIONS);
155 140
156 /* Return happy */ 141 /* Return happy */
157 return 0; 142 return 0;
diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
index 6e813daed06..e2664073a89 100644
--- a/drivers/mtd/nand/jz4740_nand.c
+++ b/drivers/mtd/nand/jz4740_nand.c
@@ -251,10 +251,6 @@ static int jz_nand_correct_ecc_rs(struct mtd_info *mtd, uint8_t *dat,
251 return 0; 251 return 0;
252} 252}
253 253
254#ifdef CONFIG_MTD_CMDLINE_PARTS
255static const char *part_probes[] = {"cmdline", NULL};
256#endif
257
258static int jz_nand_ioremap_resource(struct platform_device *pdev, 254static int jz_nand_ioremap_resource(struct platform_device *pdev,
259 const char *name, struct resource **res, void __iomem **base) 255 const char *name, struct resource **res, void __iomem **base)
260{ 256{
@@ -299,8 +295,6 @@ static int __devinit jz_nand_probe(struct platform_device *pdev)
299 struct nand_chip *chip; 295 struct nand_chip *chip;
300 struct mtd_info *mtd; 296 struct mtd_info *mtd;
301 struct jz_nand_platform_data *pdata = pdev->dev.platform_data; 297 struct jz_nand_platform_data *pdata = pdev->dev.platform_data;
302 struct mtd_partition *partition_info;
303 int num_partitions = 0;
304 298
305 nand = kzalloc(sizeof(*nand), GFP_KERNEL); 299 nand = kzalloc(sizeof(*nand), GFP_KERNEL);
306 if (!nand) { 300 if (!nand) {
@@ -373,15 +367,9 @@ static int __devinit jz_nand_probe(struct platform_device *pdev)
373 goto err_gpio_free; 367 goto err_gpio_free;
374 } 368 }
375 369
376#ifdef CONFIG_MTD_CMDLINE_PARTS 370 ret = mtd_device_parse_register(mtd, NULL, 0,
377 num_partitions = parse_mtd_partitions(mtd, part_probes, 371 pdata ? pdata->partitions : NULL,
378 &partition_info, 0); 372 pdata ? pdata->num_partitions : 0);
379#endif
380 if (num_partitions <= 0 && pdata) {
381 num_partitions = pdata->num_partitions;
382 partition_info = pdata->partitions;
383 }
384 ret = mtd_device_register(mtd, partition_info, num_partitions);
385 373
386 if (ret) { 374 if (ret) {
387 dev_err(&pdev->dev, "Failed to add mtd device\n"); 375 dev_err(&pdev->dev, "Failed to add mtd device\n");
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index eb1fbac63eb..5ede6470634 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -131,8 +131,6 @@ struct mpc5121_nfc_prv {
131 131
132static void mpc5121_nfc_done(struct mtd_info *mtd); 132static void mpc5121_nfc_done(struct mtd_info *mtd);
133 133
134static const char *mpc5121_nfc_pprobes[] = { "cmdlinepart", NULL };
135
136/* Read NFC register */ 134/* Read NFC register */
137static inline u16 nfc_read(struct mtd_info *mtd, uint reg) 135static inline u16 nfc_read(struct mtd_info *mtd, uint reg)
138{ 136{
@@ -656,13 +654,13 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
656 struct mpc5121_nfc_prv *prv; 654 struct mpc5121_nfc_prv *prv;
657 struct resource res; 655 struct resource res;
658 struct mtd_info *mtd; 656 struct mtd_info *mtd;
659 struct mtd_partition *parts;
660 struct nand_chip *chip; 657 struct nand_chip *chip;
661 unsigned long regs_paddr, regs_size; 658 unsigned long regs_paddr, regs_size;
662 const __be32 *chips_no; 659 const __be32 *chips_no;
663 int resettime = 0; 660 int resettime = 0;
664 int retval = 0; 661 int retval = 0;
665 int rev, len; 662 int rev, len;
663 struct mtd_part_parser_data ppdata;
666 664
667 /* 665 /*
668 * Check SoC revision. This driver supports only NFC 666 * Check SoC revision. This driver supports only NFC
@@ -727,6 +725,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
727 } 725 }
728 726
729 mtd->name = "MPC5121 NAND"; 727 mtd->name = "MPC5121 NAND";
728 ppdata.of_node = dn;
730 chip->dev_ready = mpc5121_nfc_dev_ready; 729 chip->dev_ready = mpc5121_nfc_dev_ready;
731 chip->cmdfunc = mpc5121_nfc_command; 730 chip->cmdfunc = mpc5121_nfc_command;
732 chip->read_byte = mpc5121_nfc_read_byte; 731 chip->read_byte = mpc5121_nfc_read_byte;
@@ -735,7 +734,8 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
735 chip->write_buf = mpc5121_nfc_write_buf; 734 chip->write_buf = mpc5121_nfc_write_buf;
736 chip->verify_buf = mpc5121_nfc_verify_buf; 735 chip->verify_buf = mpc5121_nfc_verify_buf;
737 chip->select_chip = mpc5121_nfc_select_chip; 736 chip->select_chip = mpc5121_nfc_select_chip;
738 chip->options = NAND_NO_AUTOINCR | NAND_USE_FLASH_BBT; 737 chip->options = NAND_NO_AUTOINCR;
738 chip->bbt_options = NAND_BBT_USE_FLASH;
739 chip->ecc.mode = NAND_ECC_SOFT; 739 chip->ecc.mode = NAND_ECC_SOFT;
740 740
741 /* Support external chip-select logic on ADS5121 board */ 741 /* Support external chip-select logic on ADS5121 board */
@@ -837,19 +837,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
837 dev_set_drvdata(dev, mtd); 837 dev_set_drvdata(dev, mtd);
838 838
839 /* Register device in MTD */ 839 /* Register device in MTD */
840 retval = parse_mtd_partitions(mtd, mpc5121_nfc_pprobes, &parts, 0); 840 retval = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
841#ifdef CONFIG_MTD_OF_PARTS
842 if (retval == 0)
843 retval = of_mtd_parse_partitions(dev, dn, &parts);
844#endif
845 if (retval < 0) {
846 dev_err(dev, "Error parsing MTD partitions!\n");
847 devm_free_irq(dev, prv->irq, mtd);
848 retval = -EINVAL;
849 goto error;
850 }
851
852 retval = mtd_device_register(mtd, parts, retval);
853 if (retval) { 841 if (retval) {
854 dev_err(dev, "Error adding MTD device!\n"); 842 dev_err(dev, "Error adding MTD device!\n");
855 devm_free_irq(dev, prv->irq, mtd); 843 devm_free_irq(dev, prv->irq, mtd);
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 90df34c4d26..74a43b818d0 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -41,7 +41,7 @@
41 41
42#define nfc_is_v21() (cpu_is_mx25() || cpu_is_mx35()) 42#define nfc_is_v21() (cpu_is_mx25() || cpu_is_mx35())
43#define nfc_is_v1() (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21()) 43#define nfc_is_v1() (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21())
44#define nfc_is_v3_2() cpu_is_mx51() 44#define nfc_is_v3_2() (cpu_is_mx51() || cpu_is_mx53())
45#define nfc_is_v3() nfc_is_v3_2() 45#define nfc_is_v3() nfc_is_v3_2()
46 46
47/* Addresses for NFC registers */ 47/* Addresses for NFC registers */
@@ -143,7 +143,6 @@
143struct mxc_nand_host { 143struct mxc_nand_host {
144 struct mtd_info mtd; 144 struct mtd_info mtd;
145 struct nand_chip nand; 145 struct nand_chip nand;
146 struct mtd_partition *parts;
147 struct device *dev; 146 struct device *dev;
148 147
149 void *spare0; 148 void *spare0;
@@ -350,8 +349,7 @@ static void wait_op_done(struct mxc_nand_host *host, int useirq)
350 udelay(1); 349 udelay(1);
351 } 350 }
352 if (max_retries < 0) 351 if (max_retries < 0)
353 DEBUG(MTD_DEBUG_LEVEL0, "%s: INT not set\n", 352 pr_debug("%s: INT not set\n", __func__);
354 __func__);
355 } 353 }
356} 354}
357 355
@@ -371,7 +369,7 @@ static void send_cmd_v3(struct mxc_nand_host *host, uint16_t cmd, int useirq)
371 * waits for completion. */ 369 * waits for completion. */
372static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq) 370static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
373{ 371{
374 DEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x, %d)\n", cmd, useirq); 372 pr_debug("send_cmd(host, 0x%x, %d)\n", cmd, useirq);
375 373
376 writew(cmd, NFC_V1_V2_FLASH_CMD); 374 writew(cmd, NFC_V1_V2_FLASH_CMD);
377 writew(NFC_CMD, NFC_V1_V2_CONFIG2); 375 writew(NFC_CMD, NFC_V1_V2_CONFIG2);
@@ -387,8 +385,7 @@ static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
387 udelay(1); 385 udelay(1);
388 } 386 }
389 if (max_retries < 0) 387 if (max_retries < 0)
390 DEBUG(MTD_DEBUG_LEVEL0, "%s: RESET failed\n", 388 pr_debug("%s: RESET failed\n", __func__);
391 __func__);
392 } else { 389 } else {
393 /* Wait for operation to complete */ 390 /* Wait for operation to complete */
394 wait_op_done(host, useirq); 391 wait_op_done(host, useirq);
@@ -411,7 +408,7 @@ static void send_addr_v3(struct mxc_nand_host *host, uint16_t addr, int islast)
411 * a NAND command. */ 408 * a NAND command. */
412static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islast) 409static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islast)
413{ 410{
414 DEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x %d)\n", addr, islast); 411 pr_debug("send_addr(host, 0x%x %d)\n", addr, islast);
415 412
416 writew(addr, NFC_V1_V2_FLASH_ADDR); 413 writew(addr, NFC_V1_V2_FLASH_ADDR);
417 writew(NFC_ADDR, NFC_V1_V2_CONFIG2); 414 writew(NFC_ADDR, NFC_V1_V2_CONFIG2);
@@ -561,8 +558,7 @@ static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
561 uint16_t ecc_status = readw(NFC_V1_V2_ECC_STATUS_RESULT); 558 uint16_t ecc_status = readw(NFC_V1_V2_ECC_STATUS_RESULT);
562 559
563 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) { 560 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
564 DEBUG(MTD_DEBUG_LEVEL0, 561 pr_debug("MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
565 "MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
566 return -1; 562 return -1;
567 } 563 }
568 564
@@ -849,7 +845,7 @@ static void preset_v1_v2(struct mtd_info *mtd)
849 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3); 845 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3);
850 } else if (nfc_is_v1()) { 846 } else if (nfc_is_v1()) {
851 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR); 847 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
852 writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR); 848 writew(0xffff, NFC_V1_UNLOCKEND_BLKADDR);
853 } else 849 } else
854 BUG(); 850 BUG();
855 851
@@ -932,8 +928,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
932 struct nand_chip *nand_chip = mtd->priv; 928 struct nand_chip *nand_chip = mtd->priv;
933 struct mxc_nand_host *host = nand_chip->priv; 929 struct mxc_nand_host *host = nand_chip->priv;
934 930
935 DEBUG(MTD_DEBUG_LEVEL3, 931 pr_debug("mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
936 "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
937 command, column, page_addr); 932 command, column, page_addr);
938 933
939 /* Reset command state information */ 934 /* Reset command state information */
@@ -1044,7 +1039,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1044 struct mxc_nand_platform_data *pdata = pdev->dev.platform_data; 1039 struct mxc_nand_platform_data *pdata = pdev->dev.platform_data;
1045 struct mxc_nand_host *host; 1040 struct mxc_nand_host *host;
1046 struct resource *res; 1041 struct resource *res;
1047 int err = 0, __maybe_unused nr_parts = 0; 1042 int err = 0;
1048 struct nand_ecclayout *oob_smallpage, *oob_largepage; 1043 struct nand_ecclayout *oob_smallpage, *oob_largepage;
1049 1044
1050 /* Allocate memory for MTD device structure and private data */ 1045 /* Allocate memory for MTD device structure and private data */
@@ -1179,7 +1174,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1179 this->bbt_td = &bbt_main_descr; 1174 this->bbt_td = &bbt_main_descr;
1180 this->bbt_md = &bbt_mirror_descr; 1175 this->bbt_md = &bbt_mirror_descr;
1181 /* update flash based bbt */ 1176 /* update flash based bbt */
1182 this->options |= NAND_USE_FLASH_BBT; 1177 this->bbt_options |= NAND_BBT_USE_FLASH;
1183 } 1178 }
1184 1179
1185 init_completion(&host->op_completion); 1180 init_completion(&host->op_completion);
@@ -1231,16 +1226,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1231 } 1226 }
1232 1227
1233 /* Register the partitions */ 1228 /* Register the partitions */
1234 nr_parts = 1229 mtd_device_parse_register(mtd, part_probes, 0,
1235 parse_mtd_partitions(mtd, part_probes, &host->parts, 0); 1230 pdata->parts, pdata->nr_parts);
1236 if (nr_parts > 0)
1237 mtd_device_register(mtd, host->parts, nr_parts);
1238 else if (pdata->parts)
1239 mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
1240 else {
1241 pr_info("Registering %s as whole device\n", mtd->name);
1242 mtd_device_register(mtd, NULL, 0);
1243 }
1244 1231
1245 platform_set_drvdata(pdev, host); 1232 platform_set_drvdata(pdev, host);
1246 1233
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index a46e9bb847b..3ed9c5e4d34 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -21,7 +21,7 @@
21 * TODO: 21 * TODO:
22 * Enable cached programming for 2k page size chips 22 * Enable cached programming for 2k page size chips
23 * Check, if mtd->ecctype should be set to MTD_ECC_HW 23 * Check, if mtd->ecctype should be set to MTD_ECC_HW
24 * if we have HW ecc support. 24 * if we have HW ECC support.
25 * The AG-AND chips have nice features for speed improvement, 25 * The AG-AND chips have nice features for speed improvement,
26 * which are not supported yet. Read / program 4 pages in one go. 26 * which are not supported yet. Read / program 4 pages in one go.
27 * BBT table is not serialized, has to be fixed 27 * BBT table is not serialized, has to be fixed
@@ -113,21 +113,19 @@ static int check_offs_len(struct mtd_info *mtd,
113 113
114 /* Start address must align on block boundary */ 114 /* Start address must align on block boundary */
115 if (ofs & ((1 << chip->phys_erase_shift) - 1)) { 115 if (ofs & ((1 << chip->phys_erase_shift) - 1)) {
116 DEBUG(MTD_DEBUG_LEVEL0, "%s: Unaligned address\n", __func__); 116 pr_debug("%s: unaligned address\n", __func__);
117 ret = -EINVAL; 117 ret = -EINVAL;
118 } 118 }
119 119
120 /* Length must align on block boundary */ 120 /* Length must align on block boundary */
121 if (len & ((1 << chip->phys_erase_shift) - 1)) { 121 if (len & ((1 << chip->phys_erase_shift) - 1)) {
122 DEBUG(MTD_DEBUG_LEVEL0, "%s: Length not block aligned\n", 122 pr_debug("%s: length not block aligned\n", __func__);
123 __func__);
124 ret = -EINVAL; 123 ret = -EINVAL;
125 } 124 }
126 125
127 /* Do not allow past end of device */ 126 /* Do not allow past end of device */
128 if (ofs + len > mtd->size) { 127 if (ofs + len > mtd->size) {
129 DEBUG(MTD_DEBUG_LEVEL0, "%s: Past end of device\n", 128 pr_debug("%s: past end of device\n", __func__);
130 __func__);
131 ret = -EINVAL; 129 ret = -EINVAL;
132 } 130 }
133 131
@@ -136,9 +134,9 @@ static int check_offs_len(struct mtd_info *mtd,
136 134
137/** 135/**
138 * nand_release_device - [GENERIC] release chip 136 * nand_release_device - [GENERIC] release chip
139 * @mtd: MTD device structure 137 * @mtd: MTD device structure
140 * 138 *
141 * Deselect, release chip lock and wake up anyone waiting on the device 139 * Deselect, release chip lock and wake up anyone waiting on the device.
142 */ 140 */
143static void nand_release_device(struct mtd_info *mtd) 141static void nand_release_device(struct mtd_info *mtd)
144{ 142{
@@ -157,9 +155,9 @@ static void nand_release_device(struct mtd_info *mtd)
157 155
158/** 156/**
159 * nand_read_byte - [DEFAULT] read one byte from the chip 157 * nand_read_byte - [DEFAULT] read one byte from the chip
160 * @mtd: MTD device structure 158 * @mtd: MTD device structure
161 * 159 *
162 * Default read function for 8bit buswith 160 * Default read function for 8bit buswidth
163 */ 161 */
164static uint8_t nand_read_byte(struct mtd_info *mtd) 162static uint8_t nand_read_byte(struct mtd_info *mtd)
165{ 163{
@@ -169,10 +167,11 @@ static uint8_t nand_read_byte(struct mtd_info *mtd)
169 167
170/** 168/**
171 * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip 169 * nand_read_byte16 - [DEFAULT] read one byte endianess aware from the chip
172 * @mtd: MTD device structure 170 * nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip
171 * @mtd: MTD device structure
172 *
173 * Default read function for 16bit buswidth with endianness conversion.
173 * 174 *
174 * Default read function for 16bit buswith with
175 * endianess conversion
176 */ 175 */
177static uint8_t nand_read_byte16(struct mtd_info *mtd) 176static uint8_t nand_read_byte16(struct mtd_info *mtd)
178{ 177{
@@ -182,10 +181,9 @@ static uint8_t nand_read_byte16(struct mtd_info *mtd)
182 181
183/** 182/**
184 * nand_read_word - [DEFAULT] read one word from the chip 183 * nand_read_word - [DEFAULT] read one word from the chip
185 * @mtd: MTD device structure 184 * @mtd: MTD device structure
186 * 185 *
187 * Default read function for 16bit buswith without 186 * Default read function for 16bit buswidth without endianness conversion.
188 * endianess conversion
189 */ 187 */
190static u16 nand_read_word(struct mtd_info *mtd) 188static u16 nand_read_word(struct mtd_info *mtd)
191{ 189{
@@ -195,8 +193,8 @@ static u16 nand_read_word(struct mtd_info *mtd)
195 193
196/** 194/**
197 * nand_select_chip - [DEFAULT] control CE line 195 * nand_select_chip - [DEFAULT] control CE line
198 * @mtd: MTD device structure 196 * @mtd: MTD device structure
199 * @chipnr: chipnumber to select, -1 for deselect 197 * @chipnr: chipnumber to select, -1 for deselect
200 * 198 *
201 * Default select function for 1 chip devices. 199 * Default select function for 1 chip devices.
202 */ 200 */
@@ -218,11 +216,11 @@ static void nand_select_chip(struct mtd_info *mtd, int chipnr)
218 216
219/** 217/**
220 * nand_write_buf - [DEFAULT] write buffer to chip 218 * nand_write_buf - [DEFAULT] write buffer to chip
221 * @mtd: MTD device structure 219 * @mtd: MTD device structure
222 * @buf: data buffer 220 * @buf: data buffer
223 * @len: number of bytes to write 221 * @len: number of bytes to write
224 * 222 *
225 * Default write function for 8bit buswith 223 * Default write function for 8bit buswidth.
226 */ 224 */
227static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 225static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
228{ 226{
@@ -235,11 +233,11 @@ static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
235 233
236/** 234/**
237 * nand_read_buf - [DEFAULT] read chip data into buffer 235 * nand_read_buf - [DEFAULT] read chip data into buffer
238 * @mtd: MTD device structure 236 * @mtd: MTD device structure
239 * @buf: buffer to store date 237 * @buf: buffer to store date
240 * @len: number of bytes to read 238 * @len: number of bytes to read
241 * 239 *
242 * Default read function for 8bit buswith 240 * Default read function for 8bit buswidth.
243 */ 241 */
244static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 242static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
245{ 243{
@@ -252,11 +250,11 @@ static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
252 250
253/** 251/**
254 * nand_verify_buf - [DEFAULT] Verify chip data against buffer 252 * nand_verify_buf - [DEFAULT] Verify chip data against buffer
255 * @mtd: MTD device structure 253 * @mtd: MTD device structure
256 * @buf: buffer containing the data to compare 254 * @buf: buffer containing the data to compare
257 * @len: number of bytes to compare 255 * @len: number of bytes to compare
258 * 256 *
259 * Default verify function for 8bit buswith 257 * Default verify function for 8bit buswidth.
260 */ 258 */
261static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 259static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
262{ 260{
@@ -271,11 +269,11 @@ static int nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
271 269
272/** 270/**
273 * nand_write_buf16 - [DEFAULT] write buffer to chip 271 * nand_write_buf16 - [DEFAULT] write buffer to chip
274 * @mtd: MTD device structure 272 * @mtd: MTD device structure
275 * @buf: data buffer 273 * @buf: data buffer
276 * @len: number of bytes to write 274 * @len: number of bytes to write
277 * 275 *
278 * Default write function for 16bit buswith 276 * Default write function for 16bit buswidth.
279 */ 277 */
280static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 278static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
281{ 279{
@@ -291,11 +289,11 @@ static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
291 289
292/** 290/**
293 * nand_read_buf16 - [DEFAULT] read chip data into buffer 291 * nand_read_buf16 - [DEFAULT] read chip data into buffer
294 * @mtd: MTD device structure 292 * @mtd: MTD device structure
295 * @buf: buffer to store date 293 * @buf: buffer to store date
296 * @len: number of bytes to read 294 * @len: number of bytes to read
297 * 295 *
298 * Default read function for 16bit buswith 296 * Default read function for 16bit buswidth.
299 */ 297 */
300static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) 298static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
301{ 299{
@@ -310,11 +308,11 @@ static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
310 308
311/** 309/**
312 * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer 310 * nand_verify_buf16 - [DEFAULT] Verify chip data against buffer
313 * @mtd: MTD device structure 311 * @mtd: MTD device structure
314 * @buf: buffer containing the data to compare 312 * @buf: buffer containing the data to compare
315 * @len: number of bytes to compare 313 * @len: number of bytes to compare
316 * 314 *
317 * Default verify function for 16bit buswith 315 * Default verify function for 16bit buswidth.
318 */ 316 */
319static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) 317static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
320{ 318{
@@ -332,9 +330,9 @@ static int nand_verify_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
332 330
333/** 331/**
334 * nand_block_bad - [DEFAULT] Read bad block marker from the chip 332 * nand_block_bad - [DEFAULT] Read bad block marker from the chip
335 * @mtd: MTD device structure 333 * @mtd: MTD device structure
336 * @ofs: offset from device start 334 * @ofs: offset from device start
337 * @getchip: 0, if the chip is already selected 335 * @getchip: 0, if the chip is already selected
338 * 336 *
339 * Check, if the block is bad. 337 * Check, if the block is bad.
340 */ 338 */
@@ -344,7 +342,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
344 struct nand_chip *chip = mtd->priv; 342 struct nand_chip *chip = mtd->priv;
345 u16 bad; 343 u16 bad;
346 344
347 if (chip->options & NAND_BBT_SCANLASTPAGE) 345 if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
348 ofs += mtd->erasesize - mtd->writesize; 346 ofs += mtd->erasesize - mtd->writesize;
349 347
350 page = (int)(ofs >> chip->page_shift) & chip->pagemask; 348 page = (int)(ofs >> chip->page_shift) & chip->pagemask;
@@ -384,11 +382,11 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
384 382
385/** 383/**
386 * nand_default_block_markbad - [DEFAULT] mark a block bad 384 * nand_default_block_markbad - [DEFAULT] mark a block bad
387 * @mtd: MTD device structure 385 * @mtd: MTD device structure
388 * @ofs: offset from device start 386 * @ofs: offset from device start
389 * 387 *
390 * This is the default implementation, which can be overridden by 388 * This is the default implementation, which can be overridden by a hardware
391 * a hardware specific driver. 389 * specific driver.
392*/ 390*/
393static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) 391static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
394{ 392{
@@ -396,7 +394,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
396 uint8_t buf[2] = { 0, 0 }; 394 uint8_t buf[2] = { 0, 0 };
397 int block, ret, i = 0; 395 int block, ret, i = 0;
398 396
399 if (chip->options & NAND_BBT_SCANLASTPAGE) 397 if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
400 ofs += mtd->erasesize - mtd->writesize; 398 ofs += mtd->erasesize - mtd->writesize;
401 399
402 /* Get block number */ 400 /* Get block number */
@@ -404,33 +402,31 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
404 if (chip->bbt) 402 if (chip->bbt)
405 chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 403 chip->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1);
406 404
407 /* Do we have a flash based bad block table ? */ 405 /* Do we have a flash based bad block table? */
408 if (chip->options & NAND_USE_FLASH_BBT) 406 if (chip->bbt_options & NAND_BBT_USE_FLASH)
409 ret = nand_update_bbt(mtd, ofs); 407 ret = nand_update_bbt(mtd, ofs);
410 else { 408 else {
409 struct mtd_oob_ops ops;
410
411 nand_get_device(chip, mtd, FL_WRITING); 411 nand_get_device(chip, mtd, FL_WRITING);
412 412
413 /* Write to first two pages and to byte 1 and 6 if necessary. 413 /*
414 * If we write to more than one location, the first error 414 * Write to first two pages if necessary. If we write to more
415 * encountered quits the procedure. We write two bytes per 415 * than one location, the first error encountered quits the
416 * location, so we dont have to mess with 16 bit access. 416 * procedure. We write two bytes per location, so we dont have
417 * to mess with 16 bit access.
417 */ 418 */
419 ops.len = ops.ooblen = 2;
420 ops.datbuf = NULL;
421 ops.oobbuf = buf;
422 ops.ooboffs = chip->badblockpos & ~0x01;
423 ops.mode = MTD_OPS_PLACE_OOB;
418 do { 424 do {
419 chip->ops.len = chip->ops.ooblen = 2; 425 ret = nand_do_write_oob(mtd, ofs, &ops);
420 chip->ops.datbuf = NULL;
421 chip->ops.oobbuf = buf;
422 chip->ops.ooboffs = chip->badblockpos & ~0x01;
423
424 ret = nand_do_write_oob(mtd, ofs, &chip->ops);
425 426
426 if (!ret && (chip->options & NAND_BBT_SCANBYTE1AND6)) {
427 chip->ops.ooboffs = NAND_SMALL_BADBLOCK_POS
428 & ~0x01;
429 ret = nand_do_write_oob(mtd, ofs, &chip->ops);
430 }
431 i++; 427 i++;
432 ofs += mtd->writesize; 428 ofs += mtd->writesize;
433 } while (!ret && (chip->options & NAND_BBT_SCAN2NDPAGE) && 429 } while (!ret && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE) &&
434 i < 2); 430 i < 2);
435 431
436 nand_release_device(mtd); 432 nand_release_device(mtd);
@@ -443,16 +439,16 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
443 439
444/** 440/**
445 * nand_check_wp - [GENERIC] check if the chip is write protected 441 * nand_check_wp - [GENERIC] check if the chip is write protected
446 * @mtd: MTD device structure 442 * @mtd: MTD device structure
447 * Check, if the device is write protected
448 * 443 *
449 * The function expects, that the device is already selected 444 * Check, if the device is write protected. The function expects, that the
445 * device is already selected.
450 */ 446 */
451static int nand_check_wp(struct mtd_info *mtd) 447static int nand_check_wp(struct mtd_info *mtd)
452{ 448{
453 struct nand_chip *chip = mtd->priv; 449 struct nand_chip *chip = mtd->priv;
454 450
455 /* broken xD cards report WP despite being writable */ 451 /* Broken xD cards report WP despite being writable */
456 if (chip->options & NAND_BROKEN_XD) 452 if (chip->options & NAND_BROKEN_XD)
457 return 0; 453 return 0;
458 454
@@ -463,10 +459,10 @@ static int nand_check_wp(struct mtd_info *mtd)
463 459
464/** 460/**
465 * nand_block_checkbad - [GENERIC] Check if a block is marked bad 461 * nand_block_checkbad - [GENERIC] Check if a block is marked bad
466 * @mtd: MTD device structure 462 * @mtd: MTD device structure
467 * @ofs: offset from device start 463 * @ofs: offset from device start
468 * @getchip: 0, if the chip is already selected 464 * @getchip: 0, if the chip is already selected
469 * @allowbbt: 1, if its allowed to access the bbt area 465 * @allowbbt: 1, if its allowed to access the bbt area
470 * 466 *
471 * Check, if the block is bad. Either by reading the bad block table or 467 * Check, if the block is bad. Either by reading the bad block table or
472 * calling of the scan function. 468 * calling of the scan function.
@@ -485,8 +481,8 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
485 481
486/** 482/**
487 * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands. 483 * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands.
488 * @mtd: MTD device structure 484 * @mtd: MTD device structure
489 * @timeo: Timeout 485 * @timeo: Timeout
490 * 486 *
491 * Helper function for nand_wait_ready used when needing to wait in interrupt 487 * Helper function for nand_wait_ready used when needing to wait in interrupt
492 * context. 488 * context.
@@ -505,10 +501,7 @@ static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)
505 } 501 }
506} 502}
507 503
508/* 504/* Wait for the ready pin, after a command. The timeout is caught later. */
509 * Wait for the ready pin, after a command
510 * The timeout is catched later.
511 */
512void nand_wait_ready(struct mtd_info *mtd) 505void nand_wait_ready(struct mtd_info *mtd)
513{ 506{
514 struct nand_chip *chip = mtd->priv; 507 struct nand_chip *chip = mtd->priv;
@@ -519,7 +512,7 @@ void nand_wait_ready(struct mtd_info *mtd)
519 return panic_nand_wait_ready(mtd, 400); 512 return panic_nand_wait_ready(mtd, 400);
520 513
521 led_trigger_event(nand_led_trigger, LED_FULL); 514 led_trigger_event(nand_led_trigger, LED_FULL);
522 /* wait until command is processed or timeout occures */ 515 /* Wait until command is processed or timeout occurs */
523 do { 516 do {
524 if (chip->dev_ready(mtd)) 517 if (chip->dev_ready(mtd))
525 break; 518 break;
@@ -531,13 +524,13 @@ EXPORT_SYMBOL_GPL(nand_wait_ready);
531 524
532/** 525/**
533 * nand_command - [DEFAULT] Send command to NAND device 526 * nand_command - [DEFAULT] Send command to NAND device
534 * @mtd: MTD device structure 527 * @mtd: MTD device structure
535 * @command: the command to be sent 528 * @command: the command to be sent
536 * @column: the column address for this command, -1 if none 529 * @column: the column address for this command, -1 if none
537 * @page_addr: the page address for this command, -1 if none 530 * @page_addr: the page address for this command, -1 if none
538 * 531 *
539 * Send command to NAND device. This function is used for small page 532 * Send command to NAND device. This function is used for small page devices
540 * devices (256/512 Bytes per page) 533 * (256/512 Bytes per page).
541 */ 534 */
542static void nand_command(struct mtd_info *mtd, unsigned int command, 535static void nand_command(struct mtd_info *mtd, unsigned int command,
543 int column, int page_addr) 536 int column, int page_addr)
@@ -545,9 +538,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
545 register struct nand_chip *chip = mtd->priv; 538 register struct nand_chip *chip = mtd->priv;
546 int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE; 539 int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE;
547 540
548 /* 541 /* Write out the command to the device */
549 * Write out the command to the device.
550 */
551 if (command == NAND_CMD_SEQIN) { 542 if (command == NAND_CMD_SEQIN) {
552 int readcmd; 543 int readcmd;
553 544
@@ -567,9 +558,7 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
567 } 558 }
568 chip->cmd_ctrl(mtd, command, ctrl); 559 chip->cmd_ctrl(mtd, command, ctrl);
569 560
570 /* 561 /* Address cycle, when necessary */
571 * Address cycle, when necessary
572 */
573 ctrl = NAND_CTRL_ALE | NAND_CTRL_CHANGE; 562 ctrl = NAND_CTRL_ALE | NAND_CTRL_CHANGE;
574 /* Serially input address */ 563 /* Serially input address */
575 if (column != -1) { 564 if (column != -1) {
@@ -590,8 +579,8 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
590 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); 579 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
591 580
592 /* 581 /*
593 * program and erase have their own busy handlers 582 * Program and erase have their own busy handlers status and sequential
594 * status and sequential in needs no delay 583 * in needs no delay
595 */ 584 */
596 switch (command) { 585 switch (command) {
597 586
@@ -625,8 +614,10 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
625 return; 614 return;
626 } 615 }
627 } 616 }
628 /* Apply this short delay always to ensure that we do wait tWB in 617 /*
629 * any case on any machine. */ 618 * Apply this short delay always to ensure that we do wait tWB in
619 * any case on any machine.
620 */
630 ndelay(100); 621 ndelay(100);
631 622
632 nand_wait_ready(mtd); 623 nand_wait_ready(mtd);
@@ -634,14 +625,14 @@ static void nand_command(struct mtd_info *mtd, unsigned int command,
634 625
635/** 626/**
636 * nand_command_lp - [DEFAULT] Send command to NAND large page device 627 * nand_command_lp - [DEFAULT] Send command to NAND large page device
637 * @mtd: MTD device structure 628 * @mtd: MTD device structure
638 * @command: the command to be sent 629 * @command: the command to be sent
639 * @column: the column address for this command, -1 if none 630 * @column: the column address for this command, -1 if none
640 * @page_addr: the page address for this command, -1 if none 631 * @page_addr: the page address for this command, -1 if none
641 * 632 *
642 * Send command to NAND device. This is the version for the new large page 633 * Send command to NAND device. This is the version for the new large page
643 * devices We dont have the separate regions as we have in the small page 634 * devices. We don't have the separate regions as we have in the small page
644 * devices. We must emulate NAND_CMD_READOOB to keep the code compatible. 635 * devices. We must emulate NAND_CMD_READOOB to keep the code compatible.
645 */ 636 */
646static void nand_command_lp(struct mtd_info *mtd, unsigned int command, 637static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
647 int column, int page_addr) 638 int column, int page_addr)
@@ -683,8 +674,8 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
683 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); 674 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE);
684 675
685 /* 676 /*
686 * program and erase have their own busy handlers 677 * Program and erase have their own busy handlers status, sequential
687 * status, sequential in, and deplete1 need no delay 678 * in, and deplete1 need no delay.
688 */ 679 */
689 switch (command) { 680 switch (command) {
690 681
@@ -698,14 +689,12 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
698 case NAND_CMD_DEPLETE1: 689 case NAND_CMD_DEPLETE1:
699 return; 690 return;
700 691
701 /*
702 * read error status commands require only a short delay
703 */
704 case NAND_CMD_STATUS_ERROR: 692 case NAND_CMD_STATUS_ERROR:
705 case NAND_CMD_STATUS_ERROR0: 693 case NAND_CMD_STATUS_ERROR0:
706 case NAND_CMD_STATUS_ERROR1: 694 case NAND_CMD_STATUS_ERROR1:
707 case NAND_CMD_STATUS_ERROR2: 695 case NAND_CMD_STATUS_ERROR2:
708 case NAND_CMD_STATUS_ERROR3: 696 case NAND_CMD_STATUS_ERROR3:
697 /* Read error status commands require only a short delay */
709 udelay(chip->chip_delay); 698 udelay(chip->chip_delay);
710 return; 699 return;
711 700
@@ -739,7 +728,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
739 default: 728 default:
740 /* 729 /*
741 * If we don't have access to the busy pin, we apply the given 730 * If we don't have access to the busy pin, we apply the given
742 * command delay 731 * command delay.
743 */ 732 */
744 if (!chip->dev_ready) { 733 if (!chip->dev_ready) {
745 udelay(chip->chip_delay); 734 udelay(chip->chip_delay);
@@ -747,8 +736,10 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
747 } 736 }
748 } 737 }
749 738
750 /* Apply this short delay always to ensure that we do wait tWB in 739 /*
751 * any case on any machine. */ 740 * Apply this short delay always to ensure that we do wait tWB in
741 * any case on any machine.
742 */
752 ndelay(100); 743 ndelay(100);
753 744
754 nand_wait_ready(mtd); 745 nand_wait_ready(mtd);
@@ -756,25 +747,25 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
756 747
757/** 748/**
758 * panic_nand_get_device - [GENERIC] Get chip for selected access 749 * panic_nand_get_device - [GENERIC] Get chip for selected access
759 * @chip: the nand chip descriptor 750 * @chip: the nand chip descriptor
760 * @mtd: MTD device structure 751 * @mtd: MTD device structure
761 * @new_state: the state which is requested 752 * @new_state: the state which is requested
762 * 753 *
763 * Used when in panic, no locks are taken. 754 * Used when in panic, no locks are taken.
764 */ 755 */
765static void panic_nand_get_device(struct nand_chip *chip, 756static void panic_nand_get_device(struct nand_chip *chip,
766 struct mtd_info *mtd, int new_state) 757 struct mtd_info *mtd, int new_state)
767{ 758{
768 /* Hardware controller shared among independend devices */ 759 /* Hardware controller shared among independent devices */
769 chip->controller->active = chip; 760 chip->controller->active = chip;
770 chip->state = new_state; 761 chip->state = new_state;
771} 762}
772 763
773/** 764/**
774 * nand_get_device - [GENERIC] Get chip for selected access 765 * nand_get_device - [GENERIC] Get chip for selected access
775 * @chip: the nand chip descriptor 766 * @chip: the nand chip descriptor
776 * @mtd: MTD device structure 767 * @mtd: MTD device structure
777 * @new_state: the state which is requested 768 * @new_state: the state which is requested
778 * 769 *
779 * Get the device and lock it for exclusive access 770 * Get the device and lock it for exclusive access
780 */ 771 */
@@ -812,10 +803,10 @@ retry:
812} 803}
813 804
814/** 805/**
815 * panic_nand_wait - [GENERIC] wait until the command is done 806 * panic_nand_wait - [GENERIC] wait until the command is done
816 * @mtd: MTD device structure 807 * @mtd: MTD device structure
817 * @chip: NAND chip structure 808 * @chip: NAND chip structure
818 * @timeo: Timeout 809 * @timeo: timeout
819 * 810 *
820 * Wait for command done. This is a helper function for nand_wait used when 811 * Wait for command done. This is a helper function for nand_wait used when
821 * we are in interrupt context. May happen when in panic and trying to write 812 * we are in interrupt context. May happen when in panic and trying to write
@@ -838,13 +829,13 @@ static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,
838} 829}
839 830
840/** 831/**
841 * nand_wait - [DEFAULT] wait until the command is done 832 * nand_wait - [DEFAULT] wait until the command is done
842 * @mtd: MTD device structure 833 * @mtd: MTD device structure
843 * @chip: NAND chip structure 834 * @chip: NAND chip structure
844 * 835 *
845 * Wait for command done. This applies to erase and program only 836 * Wait for command done. This applies to erase and program only. Erase can
846 * Erase can take up to 400ms and program up to 20ms according to 837 * take up to 400ms and program up to 20ms according to general NAND and
847 * general NAND and SmartMedia specs 838 * SmartMedia specs.
848 */ 839 */
849static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) 840static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
850{ 841{
@@ -859,8 +850,10 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
859 850
860 led_trigger_event(nand_led_trigger, LED_FULL); 851 led_trigger_event(nand_led_trigger, LED_FULL);
861 852
862 /* Apply this short delay always to ensure that we do wait tWB in 853 /*
863 * any case on any machine. */ 854 * Apply this short delay always to ensure that we do wait tWB in any
855 * case on any machine.
856 */
864 ndelay(100); 857 ndelay(100);
865 858
866 if ((state == FL_ERASING) && (chip->options & NAND_IS_AND)) 859 if ((state == FL_ERASING) && (chip->options & NAND_IS_AND))
@@ -890,16 +883,15 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
890 883
891/** 884/**
892 * __nand_unlock - [REPLACEABLE] unlocks specified locked blocks 885 * __nand_unlock - [REPLACEABLE] unlocks specified locked blocks
893 *
894 * @mtd: mtd info 886 * @mtd: mtd info
895 * @ofs: offset to start unlock from 887 * @ofs: offset to start unlock from
896 * @len: length to unlock 888 * @len: length to unlock
897 * @invert: when = 0, unlock the range of blocks within the lower and 889 * @invert: when = 0, unlock the range of blocks within the lower and
898 * upper boundary address 890 * upper boundary address
899 * when = 1, unlock the range of blocks outside the boundaries 891 * when = 1, unlock the range of blocks outside the boundaries
900 * of the lower and upper boundary address 892 * of the lower and upper boundary address
901 * 893 *
902 * return - unlock status 894 * Returs unlock status.
903 */ 895 */
904static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, 896static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
905 uint64_t len, int invert) 897 uint64_t len, int invert)
@@ -919,10 +911,9 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
919 911
920 /* Call wait ready function */ 912 /* Call wait ready function */
921 status = chip->waitfunc(mtd, chip); 913 status = chip->waitfunc(mtd, chip);
922 udelay(1000);
923 /* See if device thinks it succeeded */ 914 /* See if device thinks it succeeded */
924 if (status & 0x01) { 915 if (status & 0x01) {
925 DEBUG(MTD_DEBUG_LEVEL0, "%s: Error status = 0x%08x\n", 916 pr_debug("%s: error status = 0x%08x\n",
926 __func__, status); 917 __func__, status);
927 ret = -EIO; 918 ret = -EIO;
928 } 919 }
@@ -932,12 +923,11 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
932 923
933/** 924/**
934 * nand_unlock - [REPLACEABLE] unlocks specified locked blocks 925 * nand_unlock - [REPLACEABLE] unlocks specified locked blocks
935 *
936 * @mtd: mtd info 926 * @mtd: mtd info
937 * @ofs: offset to start unlock from 927 * @ofs: offset to start unlock from
938 * @len: length to unlock 928 * @len: length to unlock
939 * 929 *
940 * return - unlock status 930 * Returns unlock status.
941 */ 931 */
942int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 932int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
943{ 933{
@@ -945,7 +935,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
945 int chipnr; 935 int chipnr;
946 struct nand_chip *chip = mtd->priv; 936 struct nand_chip *chip = mtd->priv;
947 937
948 DEBUG(MTD_DEBUG_LEVEL3, "%s: start = 0x%012llx, len = %llu\n", 938 pr_debug("%s: start = 0x%012llx, len = %llu\n",
949 __func__, (unsigned long long)ofs, len); 939 __func__, (unsigned long long)ofs, len);
950 940
951 if (check_offs_len(mtd, ofs, len)) 941 if (check_offs_len(mtd, ofs, len))
@@ -964,7 +954,7 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
964 954
965 /* Check, if it is write protected */ 955 /* Check, if it is write protected */
966 if (nand_check_wp(mtd)) { 956 if (nand_check_wp(mtd)) {
967 DEBUG(MTD_DEBUG_LEVEL0, "%s: Device is write protected!!!\n", 957 pr_debug("%s: device is write protected!\n",
968 __func__); 958 __func__);
969 ret = -EIO; 959 ret = -EIO;
970 goto out; 960 goto out;
@@ -981,18 +971,16 @@ EXPORT_SYMBOL(nand_unlock);
981 971
982/** 972/**
983 * nand_lock - [REPLACEABLE] locks all blocks present in the device 973 * nand_lock - [REPLACEABLE] locks all blocks present in the device
984 *
985 * @mtd: mtd info 974 * @mtd: mtd info
986 * @ofs: offset to start unlock from 975 * @ofs: offset to start unlock from
987 * @len: length to unlock 976 * @len: length to unlock
988 * 977 *
989 * return - lock status 978 * This feature is not supported in many NAND parts. 'Micron' NAND parts do
979 * have this feature, but it allows only to lock all blocks, not for specified
980 * range for block. Implementing 'lock' feature by making use of 'unlock', for
981 * now.
990 * 982 *
991 * This feature is not supported in many NAND parts. 'Micron' NAND parts 983 * Returns lock status.
992 * do have this feature, but it allows only to lock all blocks, not for
993 * specified range for block.
994 *
995 * Implementing 'lock' feature by making use of 'unlock', for now.
996 */ 984 */
997int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 985int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
998{ 986{
@@ -1000,7 +988,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1000 int chipnr, status, page; 988 int chipnr, status, page;
1001 struct nand_chip *chip = mtd->priv; 989 struct nand_chip *chip = mtd->priv;
1002 990
1003 DEBUG(MTD_DEBUG_LEVEL3, "%s: start = 0x%012llx, len = %llu\n", 991 pr_debug("%s: start = 0x%012llx, len = %llu\n",
1004 __func__, (unsigned long long)ofs, len); 992 __func__, (unsigned long long)ofs, len);
1005 993
1006 if (check_offs_len(mtd, ofs, len)) 994 if (check_offs_len(mtd, ofs, len))
@@ -1015,7 +1003,7 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1015 1003
1016 /* Check, if it is write protected */ 1004 /* Check, if it is write protected */
1017 if (nand_check_wp(mtd)) { 1005 if (nand_check_wp(mtd)) {
1018 DEBUG(MTD_DEBUG_LEVEL0, "%s: Device is write protected!!!\n", 1006 pr_debug("%s: device is write protected!\n",
1019 __func__); 1007 __func__);
1020 status = MTD_ERASE_FAILED; 1008 status = MTD_ERASE_FAILED;
1021 ret = -EIO; 1009 ret = -EIO;
@@ -1028,10 +1016,9 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1028 1016
1029 /* Call wait ready function */ 1017 /* Call wait ready function */
1030 status = chip->waitfunc(mtd, chip); 1018 status = chip->waitfunc(mtd, chip);
1031 udelay(1000);
1032 /* See if device thinks it succeeded */ 1019 /* See if device thinks it succeeded */
1033 if (status & 0x01) { 1020 if (status & 0x01) {
1034 DEBUG(MTD_DEBUG_LEVEL0, "%s: Error status = 0x%08x\n", 1021 pr_debug("%s: error status = 0x%08x\n",
1035 __func__, status); 1022 __func__, status);
1036 ret = -EIO; 1023 ret = -EIO;
1037 goto out; 1024 goto out;
@@ -1047,13 +1034,13 @@ out:
1047EXPORT_SYMBOL(nand_lock); 1034EXPORT_SYMBOL(nand_lock);
1048 1035
1049/** 1036/**
1050 * nand_read_page_raw - [Intern] read raw page data without ecc 1037 * nand_read_page_raw - [INTERN] read raw page data without ecc
1051 * @mtd: mtd info structure 1038 * @mtd: mtd info structure
1052 * @chip: nand chip info structure 1039 * @chip: nand chip info structure
1053 * @buf: buffer to store read data 1040 * @buf: buffer to store read data
1054 * @page: page number to read 1041 * @page: page number to read
1055 * 1042 *
1056 * Not for syndrome calculating ecc controllers, which use a special oob layout 1043 * Not for syndrome calculating ECC controllers, which use a special oob layout.
1057 */ 1044 */
1058static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1045static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1059 uint8_t *buf, int page) 1046 uint8_t *buf, int page)
@@ -1064,11 +1051,11 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1064} 1051}
1065 1052
1066/** 1053/**
1067 * nand_read_page_raw_syndrome - [Intern] read raw page data without ecc 1054 * nand_read_page_raw_syndrome - [INTERN] read raw page data without ecc
1068 * @mtd: mtd info structure 1055 * @mtd: mtd info structure
1069 * @chip: nand chip info structure 1056 * @chip: nand chip info structure
1070 * @buf: buffer to store read data 1057 * @buf: buffer to store read data
1071 * @page: page number to read 1058 * @page: page number to read
1072 * 1059 *
1073 * We need a special oob layout and handling even when OOB isn't used. 1060 * We need a special oob layout and handling even when OOB isn't used.
1074 */ 1061 */
@@ -1107,11 +1094,11 @@ static int nand_read_page_raw_syndrome(struct mtd_info *mtd,
1107} 1094}
1108 1095
1109/** 1096/**
1110 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function 1097 * nand_read_page_swecc - [REPLACEABLE] software ECC based page read function
1111 * @mtd: mtd info structure 1098 * @mtd: mtd info structure
1112 * @chip: nand chip info structure 1099 * @chip: nand chip info structure
1113 * @buf: buffer to store read data 1100 * @buf: buffer to store read data
1114 * @page: page number to read 1101 * @page: page number to read
1115 */ 1102 */
1116static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, 1103static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1117 uint8_t *buf, int page) 1104 uint8_t *buf, int page)
@@ -1148,12 +1135,12 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1148} 1135}
1149 1136
1150/** 1137/**
1151 * nand_read_subpage - [REPLACABLE] software ecc based sub-page read function 1138 * nand_read_subpage - [REPLACEABLE] software ECC based sub-page read function
1152 * @mtd: mtd info structure 1139 * @mtd: mtd info structure
1153 * @chip: nand chip info structure 1140 * @chip: nand chip info structure
1154 * @data_offs: offset of requested data within the page 1141 * @data_offs: offset of requested data within the page
1155 * @readlen: data length 1142 * @readlen: data length
1156 * @bufpoi: buffer to store read data 1143 * @bufpoi: buffer to store read data
1157 */ 1144 */
1158static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, 1145static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1159 uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi) 1146 uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi)
@@ -1166,12 +1153,12 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1166 int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1; 1153 int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1;
1167 int index = 0; 1154 int index = 0;
1168 1155
1169 /* Column address wihin the page aligned to ECC size (256bytes). */ 1156 /* Column address within the page aligned to ECC size (256bytes) */
1170 start_step = data_offs / chip->ecc.size; 1157 start_step = data_offs / chip->ecc.size;
1171 end_step = (data_offs + readlen - 1) / chip->ecc.size; 1158 end_step = (data_offs + readlen - 1) / chip->ecc.size;
1172 num_steps = end_step - start_step + 1; 1159 num_steps = end_step - start_step + 1;
1173 1160
1174 /* Data size aligned to ECC ecc.size*/ 1161 /* Data size aligned to ECC ecc.size */
1175 datafrag_len = num_steps * chip->ecc.size; 1162 datafrag_len = num_steps * chip->ecc.size;
1176 eccfrag_len = num_steps * chip->ecc.bytes; 1163 eccfrag_len = num_steps * chip->ecc.bytes;
1177 1164
@@ -1183,13 +1170,14 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1183 p = bufpoi + data_col_addr; 1170 p = bufpoi + data_col_addr;
1184 chip->read_buf(mtd, p, datafrag_len); 1171 chip->read_buf(mtd, p, datafrag_len);
1185 1172
1186 /* Calculate ECC */ 1173 /* Calculate ECC */
1187 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) 1174 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size)
1188 chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); 1175 chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]);
1189 1176
1190 /* The performance is faster if to position offsets 1177 /*
1191 according to ecc.pos. Let make sure here that 1178 * The performance is faster if we position offsets according to
1192 there are no gaps in ecc positions */ 1179 * ecc.pos. Let's make sure that there are no gaps in ECC positions.
1180 */
1193 for (i = 0; i < eccfrag_len - 1; i++) { 1181 for (i = 0; i < eccfrag_len - 1; i++) {
1194 if (eccpos[i + start_step * chip->ecc.bytes] + 1 != 1182 if (eccpos[i + start_step * chip->ecc.bytes] + 1 !=
1195 eccpos[i + start_step * chip->ecc.bytes + 1]) { 1183 eccpos[i + start_step * chip->ecc.bytes + 1]) {
@@ -1201,8 +1189,10 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1201 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1); 1189 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
1202 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 1190 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
1203 } else { 1191 } else {
1204 /* send the command to read the particular ecc bytes */ 1192 /*
1205 /* take care about buswidth alignment in read_buf */ 1193 * Send the command to read the particular ECC bytes take care
1194 * about buswidth alignment in read_buf.
1195 */
1206 index = start_step * chip->ecc.bytes; 1196 index = start_step * chip->ecc.bytes;
1207 1197
1208 aligned_pos = eccpos[index] & ~(busw - 1); 1198 aligned_pos = eccpos[index] & ~(busw - 1);
@@ -1235,13 +1225,13 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1235} 1225}
1236 1226
1237/** 1227/**
1238 * nand_read_page_hwecc - [REPLACABLE] hardware ecc based page read function 1228 * nand_read_page_hwecc - [REPLACEABLE] hardware ECC based page read function
1239 * @mtd: mtd info structure 1229 * @mtd: mtd info structure
1240 * @chip: nand chip info structure 1230 * @chip: nand chip info structure
1241 * @buf: buffer to store read data 1231 * @buf: buffer to store read data
1242 * @page: page number to read 1232 * @page: page number to read
1243 * 1233 *
1244 * Not for syndrome calculating ecc controllers which need a special oob layout 1234 * Not for syndrome calculating ECC controllers which need a special oob layout.
1245 */ 1235 */
1246static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 1236static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1247 uint8_t *buf, int page) 1237 uint8_t *buf, int page)
@@ -1280,18 +1270,17 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1280} 1270}
1281 1271
1282/** 1272/**
1283 * nand_read_page_hwecc_oob_first - [REPLACABLE] hw ecc, read oob first 1273 * nand_read_page_hwecc_oob_first - [REPLACEABLE] hw ecc, read oob first
1284 * @mtd: mtd info structure 1274 * @mtd: mtd info structure
1285 * @chip: nand chip info structure 1275 * @chip: nand chip info structure
1286 * @buf: buffer to store read data 1276 * @buf: buffer to store read data
1287 * @page: page number to read 1277 * @page: page number to read
1288 * 1278 *
1289 * Hardware ECC for large page chips, require OOB to be read first. 1279 * Hardware ECC for large page chips, require OOB to be read first. For this
1290 * For this ECC mode, the write_page method is re-used from ECC_HW. 1280 * ECC mode, the write_page method is re-used from ECC_HW. These methods
1291 * These methods read/write ECC from the OOB area, unlike the 1281 * read/write ECC from the OOB area, unlike the ECC_HW_SYNDROME support with
1292 * ECC_HW_SYNDROME support with multiple ECC steps, follows the 1282 * multiple ECC steps, follows the "infix ECC" scheme and reads/writes ECC from
1293 * "infix ECC" scheme and reads/writes ECC from the data area, by 1283 * the data area, by overwriting the NAND manufacturer bad block markings.
1294 * overwriting the NAND manufacturer bad block markings.
1295 */ 1284 */
1296static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, 1285static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
1297 struct nand_chip *chip, uint8_t *buf, int page) 1286 struct nand_chip *chip, uint8_t *buf, int page)
@@ -1329,14 +1318,14 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
1329} 1318}
1330 1319
1331/** 1320/**
1332 * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read 1321 * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read
1333 * @mtd: mtd info structure 1322 * @mtd: mtd info structure
1334 * @chip: nand chip info structure 1323 * @chip: nand chip info structure
1335 * @buf: buffer to store read data 1324 * @buf: buffer to store read data
1336 * @page: page number to read 1325 * @page: page number to read
1337 * 1326 *
1338 * The hw generator calculates the error syndrome automatically. Therefor 1327 * The hw generator calculates the error syndrome automatically. Therefore we
1339 * we need a special oob layout and handling. 1328 * need a special oob layout and handling.
1340 */ 1329 */
1341static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, 1330static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1342 uint8_t *buf, int page) 1331 uint8_t *buf, int page)
@@ -1384,29 +1373,29 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1384} 1373}
1385 1374
1386/** 1375/**
1387 * nand_transfer_oob - [Internal] Transfer oob to client buffer 1376 * nand_transfer_oob - [INTERN] Transfer oob to client buffer
1388 * @chip: nand chip structure 1377 * @chip: nand chip structure
1389 * @oob: oob destination address 1378 * @oob: oob destination address
1390 * @ops: oob ops structure 1379 * @ops: oob ops structure
1391 * @len: size of oob to transfer 1380 * @len: size of oob to transfer
1392 */ 1381 */
1393static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, 1382static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
1394 struct mtd_oob_ops *ops, size_t len) 1383 struct mtd_oob_ops *ops, size_t len)
1395{ 1384{
1396 switch (ops->mode) { 1385 switch (ops->mode) {
1397 1386
1398 case MTD_OOB_PLACE: 1387 case MTD_OPS_PLACE_OOB:
1399 case MTD_OOB_RAW: 1388 case MTD_OPS_RAW:
1400 memcpy(oob, chip->oob_poi + ops->ooboffs, len); 1389 memcpy(oob, chip->oob_poi + ops->ooboffs, len);
1401 return oob + len; 1390 return oob + len;
1402 1391
1403 case MTD_OOB_AUTO: { 1392 case MTD_OPS_AUTO_OOB: {
1404 struct nand_oobfree *free = chip->ecc.layout->oobfree; 1393 struct nand_oobfree *free = chip->ecc.layout->oobfree;
1405 uint32_t boffs = 0, roffs = ops->ooboffs; 1394 uint32_t boffs = 0, roffs = ops->ooboffs;
1406 size_t bytes = 0; 1395 size_t bytes = 0;
1407 1396
1408 for (; free->length && len; free++, len -= bytes) { 1397 for (; free->length && len; free++, len -= bytes) {
1409 /* Read request not from offset 0 ? */ 1398 /* Read request not from offset 0? */
1410 if (unlikely(roffs)) { 1399 if (unlikely(roffs)) {
1411 if (roffs >= free->length) { 1400 if (roffs >= free->length) {
1412 roffs -= free->length; 1401 roffs -= free->length;
@@ -1432,11 +1421,10 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
1432} 1421}
1433 1422
1434/** 1423/**
1435 * nand_do_read_ops - [Internal] Read data with ECC 1424 * nand_do_read_ops - [INTERN] Read data with ECC
1436 * 1425 * @mtd: MTD device structure
1437 * @mtd: MTD device structure 1426 * @from: offset to read from
1438 * @from: offset to read from 1427 * @ops: oob ops structure
1439 * @ops: oob ops structure
1440 * 1428 *
1441 * Internal function. Called with chip held. 1429 * Internal function. Called with chip held.
1442 */ 1430 */
@@ -1451,7 +1439,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1451 int ret = 0; 1439 int ret = 0;
1452 uint32_t readlen = ops->len; 1440 uint32_t readlen = ops->len;
1453 uint32_t oobreadlen = ops->ooblen; 1441 uint32_t oobreadlen = ops->ooblen;
1454 uint32_t max_oobsize = ops->mode == MTD_OOB_AUTO ? 1442 uint32_t max_oobsize = ops->mode == MTD_OPS_AUTO_OOB ?
1455 mtd->oobavail : mtd->oobsize; 1443 mtd->oobavail : mtd->oobsize;
1456 1444
1457 uint8_t *bufpoi, *oob, *buf; 1445 uint8_t *bufpoi, *oob, *buf;
@@ -1473,7 +1461,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1473 bytes = min(mtd->writesize - col, readlen); 1461 bytes = min(mtd->writesize - col, readlen);
1474 aligned = (bytes == mtd->writesize); 1462 aligned = (bytes == mtd->writesize);
1475 1463
1476 /* Is the current page in the buffer ? */ 1464 /* Is the current page in the buffer? */
1477 if (realpage != chip->pagebuf || oob) { 1465 if (realpage != chip->pagebuf || oob) {
1478 bufpoi = aligned ? buf : chip->buffers->databuf; 1466 bufpoi = aligned ? buf : chip->buffers->databuf;
1479 1467
@@ -1483,7 +1471,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1483 } 1471 }
1484 1472
1485 /* Now read the page into the buffer */ 1473 /* Now read the page into the buffer */
1486 if (unlikely(ops->mode == MTD_OOB_RAW)) 1474 if (unlikely(ops->mode == MTD_OPS_RAW))
1487 ret = chip->ecc.read_page_raw(mtd, chip, 1475 ret = chip->ecc.read_page_raw(mtd, chip,
1488 bufpoi, page); 1476 bufpoi, page);
1489 else if (!aligned && NAND_SUBPAGE_READ(chip) && !oob) 1477 else if (!aligned && NAND_SUBPAGE_READ(chip) && !oob)
@@ -1492,14 +1480,22 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1492 else 1480 else
1493 ret = chip->ecc.read_page(mtd, chip, bufpoi, 1481 ret = chip->ecc.read_page(mtd, chip, bufpoi,
1494 page); 1482 page);
1495 if (ret < 0) 1483 if (ret < 0) {
1484 if (!aligned)
1485 /* Invalidate page cache */
1486 chip->pagebuf = -1;
1496 break; 1487 break;
1488 }
1497 1489
1498 /* Transfer not aligned data */ 1490 /* Transfer not aligned data */
1499 if (!aligned) { 1491 if (!aligned) {
1500 if (!NAND_SUBPAGE_READ(chip) && !oob && 1492 if (!NAND_SUBPAGE_READ(chip) && !oob &&
1501 !(mtd->ecc_stats.failed - stats.failed)) 1493 !(mtd->ecc_stats.failed - stats.failed) &&
1494 (ops->mode != MTD_OPS_RAW))
1502 chip->pagebuf = realpage; 1495 chip->pagebuf = realpage;
1496 else
1497 /* Invalidate page cache */
1498 chip->pagebuf = -1;
1503 memcpy(buf, chip->buffers->databuf + col, bytes); 1499 memcpy(buf, chip->buffers->databuf + col, bytes);
1504 } 1500 }
1505 1501
@@ -1539,7 +1535,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1539 if (!readlen) 1535 if (!readlen)
1540 break; 1536 break;
1541 1537
1542 /* For subsequent reads align to page boundary. */ 1538 /* For subsequent reads align to page boundary */
1543 col = 0; 1539 col = 0;
1544 /* Increment page address */ 1540 /* Increment page address */
1545 realpage++; 1541 realpage++;
@@ -1552,8 +1548,9 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1552 chip->select_chip(mtd, chipnr); 1548 chip->select_chip(mtd, chipnr);
1553 } 1549 }
1554 1550
1555 /* Check, if the chip supports auto page increment 1551 /*
1556 * or if we have hit a block boundary. 1552 * Check, if the chip supports auto page increment or if we
1553 * have hit a block boundary.
1557 */ 1554 */
1558 if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck)) 1555 if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck))
1559 sndcmd = 1; 1556 sndcmd = 1;
@@ -1574,18 +1571,19 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1574 1571
1575/** 1572/**
1576 * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc 1573 * nand_read - [MTD Interface] MTD compatibility function for nand_do_read_ecc
1577 * @mtd: MTD device structure 1574 * @mtd: MTD device structure
1578 * @from: offset to read from 1575 * @from: offset to read from
1579 * @len: number of bytes to read 1576 * @len: number of bytes to read
1580 * @retlen: pointer to variable to store the number of read bytes 1577 * @retlen: pointer to variable to store the number of read bytes
1581 * @buf: the databuffer to put data 1578 * @buf: the databuffer to put data
1582 * 1579 *
1583 * Get hold of the chip and call nand_do_read 1580 * Get hold of the chip and call nand_do_read.
1584 */ 1581 */
1585static int nand_read(struct mtd_info *mtd, loff_t from, size_t len, 1582static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
1586 size_t *retlen, uint8_t *buf) 1583 size_t *retlen, uint8_t *buf)
1587{ 1584{
1588 struct nand_chip *chip = mtd->priv; 1585 struct nand_chip *chip = mtd->priv;
1586 struct mtd_oob_ops ops;
1589 int ret; 1587 int ret;
1590 1588
1591 /* Do not allow reads past end of device */ 1589 /* Do not allow reads past end of device */
@@ -1596,13 +1594,14 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
1596 1594
1597 nand_get_device(chip, mtd, FL_READING); 1595 nand_get_device(chip, mtd, FL_READING);
1598 1596
1599 chip->ops.len = len; 1597 ops.len = len;
1600 chip->ops.datbuf = buf; 1598 ops.datbuf = buf;
1601 chip->ops.oobbuf = NULL; 1599 ops.oobbuf = NULL;
1600 ops.mode = 0;
1602 1601
1603 ret = nand_do_read_ops(mtd, from, &chip->ops); 1602 ret = nand_do_read_ops(mtd, from, &ops);
1604 1603
1605 *retlen = chip->ops.retlen; 1604 *retlen = ops.retlen;
1606 1605
1607 nand_release_device(mtd); 1606 nand_release_device(mtd);
1608 1607
@@ -1610,11 +1609,11 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
1610} 1609}
1611 1610
1612/** 1611/**
1613 * nand_read_oob_std - [REPLACABLE] the most common OOB data read function 1612 * nand_read_oob_std - [REPLACEABLE] the most common OOB data read function
1614 * @mtd: mtd info structure 1613 * @mtd: mtd info structure
1615 * @chip: nand chip info structure 1614 * @chip: nand chip info structure
1616 * @page: page number to read 1615 * @page: page number to read
1617 * @sndcmd: flag whether to issue read command or not 1616 * @sndcmd: flag whether to issue read command or not
1618 */ 1617 */
1619static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, 1618static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
1620 int page, int sndcmd) 1619 int page, int sndcmd)
@@ -1628,12 +1627,12 @@ static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
1628} 1627}
1629 1628
1630/** 1629/**
1631 * nand_read_oob_syndrome - [REPLACABLE] OOB data read function for HW ECC 1630 * nand_read_oob_syndrome - [REPLACEABLE] OOB data read function for HW ECC
1632 * with syndromes 1631 * with syndromes
1633 * @mtd: mtd info structure 1632 * @mtd: mtd info structure
1634 * @chip: nand chip info structure 1633 * @chip: nand chip info structure
1635 * @page: page number to read 1634 * @page: page number to read
1636 * @sndcmd: flag whether to issue read command or not 1635 * @sndcmd: flag whether to issue read command or not
1637 */ 1636 */
1638static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, 1637static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1639 int page, int sndcmd) 1638 int page, int sndcmd)
@@ -1667,10 +1666,10 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1667} 1666}
1668 1667
1669/** 1668/**
1670 * nand_write_oob_std - [REPLACABLE] the most common OOB data write function 1669 * nand_write_oob_std - [REPLACEABLE] the most common OOB data write function
1671 * @mtd: mtd info structure 1670 * @mtd: mtd info structure
1672 * @chip: nand chip info structure 1671 * @chip: nand chip info structure
1673 * @page: page number to write 1672 * @page: page number to write
1674 */ 1673 */
1675static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, 1674static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
1676 int page) 1675 int page)
@@ -1690,11 +1689,11 @@ static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
1690} 1689}
1691 1690
1692/** 1691/**
1693 * nand_write_oob_syndrome - [REPLACABLE] OOB data write function for HW ECC 1692 * nand_write_oob_syndrome - [REPLACEABLE] OOB data write function for HW ECC
1694 * with syndrome - only for large page flash ! 1693 * with syndrome - only for large page flash
1695 * @mtd: mtd info structure 1694 * @mtd: mtd info structure
1696 * @chip: nand chip info structure 1695 * @chip: nand chip info structure
1697 * @page: page number to write 1696 * @page: page number to write
1698 */ 1697 */
1699static int nand_write_oob_syndrome(struct mtd_info *mtd, 1698static int nand_write_oob_syndrome(struct mtd_info *mtd,
1700 struct nand_chip *chip, int page) 1699 struct nand_chip *chip, int page)
@@ -1749,34 +1748,37 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
1749} 1748}
1750 1749
1751/** 1750/**
1752 * nand_do_read_oob - [Intern] NAND read out-of-band 1751 * nand_do_read_oob - [INTERN] NAND read out-of-band
1753 * @mtd: MTD device structure 1752 * @mtd: MTD device structure
1754 * @from: offset to read from 1753 * @from: offset to read from
1755 * @ops: oob operations description structure 1754 * @ops: oob operations description structure
1756 * 1755 *
1757 * NAND read out-of-band data from the spare area 1756 * NAND read out-of-band data from the spare area.
1758 */ 1757 */
1759static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, 1758static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1760 struct mtd_oob_ops *ops) 1759 struct mtd_oob_ops *ops)
1761{ 1760{
1762 int page, realpage, chipnr, sndcmd = 1; 1761 int page, realpage, chipnr, sndcmd = 1;
1763 struct nand_chip *chip = mtd->priv; 1762 struct nand_chip *chip = mtd->priv;
1763 struct mtd_ecc_stats stats;
1764 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1; 1764 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1765 int readlen = ops->ooblen; 1765 int readlen = ops->ooblen;
1766 int len; 1766 int len;
1767 uint8_t *buf = ops->oobbuf; 1767 uint8_t *buf = ops->oobbuf;
1768 1768
1769 DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08Lx, len = %i\n", 1769 pr_debug("%s: from = 0x%08Lx, len = %i\n",
1770 __func__, (unsigned long long)from, readlen); 1770 __func__, (unsigned long long)from, readlen);
1771 1771
1772 if (ops->mode == MTD_OOB_AUTO) 1772 stats = mtd->ecc_stats;
1773
1774 if (ops->mode == MTD_OPS_AUTO_OOB)
1773 len = chip->ecc.layout->oobavail; 1775 len = chip->ecc.layout->oobavail;
1774 else 1776 else
1775 len = mtd->oobsize; 1777 len = mtd->oobsize;
1776 1778
1777 if (unlikely(ops->ooboffs >= len)) { 1779 if (unlikely(ops->ooboffs >= len)) {
1778 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to start read " 1780 pr_debug("%s: attempt to start read outside oob\n",
1779 "outside oob\n", __func__); 1781 __func__);
1780 return -EINVAL; 1782 return -EINVAL;
1781 } 1783 }
1782 1784
@@ -1784,8 +1786,8 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1784 if (unlikely(from >= mtd->size || 1786 if (unlikely(from >= mtd->size ||
1785 ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) - 1787 ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -
1786 (from >> chip->page_shift)) * len)) { 1788 (from >> chip->page_shift)) * len)) {
1787 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt read beyond end " 1789 pr_debug("%s: attempt to read beyond end of device\n",
1788 "of device\n", __func__); 1790 __func__);
1789 return -EINVAL; 1791 return -EINVAL;
1790 } 1792 }
1791 1793
@@ -1797,7 +1799,10 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1797 page = realpage & chip->pagemask; 1799 page = realpage & chip->pagemask;
1798 1800
1799 while (1) { 1801 while (1) {
1800 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); 1802 if (ops->mode == MTD_OPS_RAW)
1803 sndcmd = chip->ecc.read_oob_raw(mtd, chip, page, sndcmd);
1804 else
1805 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd);
1801 1806
1802 len = min(len, readlen); 1807 len = min(len, readlen);
1803 buf = nand_transfer_oob(chip, buf, ops, len); 1808 buf = nand_transfer_oob(chip, buf, ops, len);
@@ -1830,24 +1835,29 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1830 chip->select_chip(mtd, chipnr); 1835 chip->select_chip(mtd, chipnr);
1831 } 1836 }
1832 1837
1833 /* Check, if the chip supports auto page increment 1838 /*
1834 * or if we have hit a block boundary. 1839 * Check, if the chip supports auto page increment or if we
1840 * have hit a block boundary.
1835 */ 1841 */
1836 if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck)) 1842 if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck))
1837 sndcmd = 1; 1843 sndcmd = 1;
1838 } 1844 }
1839 1845
1840 ops->oobretlen = ops->ooblen; 1846 ops->oobretlen = ops->ooblen;
1841 return 0; 1847
1848 if (mtd->ecc_stats.failed - stats.failed)
1849 return -EBADMSG;
1850
1851 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;
1842} 1852}
1843 1853
1844/** 1854/**
1845 * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band 1855 * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band
1846 * @mtd: MTD device structure 1856 * @mtd: MTD device structure
1847 * @from: offset to read from 1857 * @from: offset to read from
1848 * @ops: oob operation description structure 1858 * @ops: oob operation description structure
1849 * 1859 *
1850 * NAND read data and/or out-of-band data 1860 * NAND read data and/or out-of-band data.
1851 */ 1861 */
1852static int nand_read_oob(struct mtd_info *mtd, loff_t from, 1862static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1853 struct mtd_oob_ops *ops) 1863 struct mtd_oob_ops *ops)
@@ -1859,17 +1869,17 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1859 1869
1860 /* Do not allow reads past end of device */ 1870 /* Do not allow reads past end of device */
1861 if (ops->datbuf && (from + ops->len) > mtd->size) { 1871 if (ops->datbuf && (from + ops->len) > mtd->size) {
1862 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt read " 1872 pr_debug("%s: attempt to read beyond end of device\n",
1863 "beyond end of device\n", __func__); 1873 __func__);
1864 return -EINVAL; 1874 return -EINVAL;
1865 } 1875 }
1866 1876
1867 nand_get_device(chip, mtd, FL_READING); 1877 nand_get_device(chip, mtd, FL_READING);
1868 1878
1869 switch (ops->mode) { 1879 switch (ops->mode) {
1870 case MTD_OOB_PLACE: 1880 case MTD_OPS_PLACE_OOB:
1871 case MTD_OOB_AUTO: 1881 case MTD_OPS_AUTO_OOB:
1872 case MTD_OOB_RAW: 1882 case MTD_OPS_RAW:
1873 break; 1883 break;
1874 1884
1875 default: 1885 default:
@@ -1888,12 +1898,12 @@ out:
1888 1898
1889 1899
1890/** 1900/**
1891 * nand_write_page_raw - [Intern] raw page write function 1901 * nand_write_page_raw - [INTERN] raw page write function
1892 * @mtd: mtd info structure 1902 * @mtd: mtd info structure
1893 * @chip: nand chip info structure 1903 * @chip: nand chip info structure
1894 * @buf: data buffer 1904 * @buf: data buffer
1895 * 1905 *
1896 * Not for syndrome calculating ecc controllers, which use a special oob layout 1906 * Not for syndrome calculating ECC controllers, which use a special oob layout.
1897 */ 1907 */
1898static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1908static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1899 const uint8_t *buf) 1909 const uint8_t *buf)
@@ -1903,10 +1913,10 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1903} 1913}
1904 1914
1905/** 1915/**
1906 * nand_write_page_raw_syndrome - [Intern] raw page write function 1916 * nand_write_page_raw_syndrome - [INTERN] raw page write function
1907 * @mtd: mtd info structure 1917 * @mtd: mtd info structure
1908 * @chip: nand chip info structure 1918 * @chip: nand chip info structure
1909 * @buf: data buffer 1919 * @buf: data buffer
1910 * 1920 *
1911 * We need a special oob layout and handling even when ECC isn't checked. 1921 * We need a special oob layout and handling even when ECC isn't checked.
1912 */ 1922 */
@@ -1942,10 +1952,10 @@ static void nand_write_page_raw_syndrome(struct mtd_info *mtd,
1942 chip->write_buf(mtd, oob, size); 1952 chip->write_buf(mtd, oob, size);
1943} 1953}
1944/** 1954/**
1945 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function 1955 * nand_write_page_swecc - [REPLACEABLE] software ECC based page write function
1946 * @mtd: mtd info structure 1956 * @mtd: mtd info structure
1947 * @chip: nand chip info structure 1957 * @chip: nand chip info structure
1948 * @buf: data buffer 1958 * @buf: data buffer
1949 */ 1959 */
1950static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, 1960static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1951 const uint8_t *buf) 1961 const uint8_t *buf)
@@ -1957,7 +1967,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1957 const uint8_t *p = buf; 1967 const uint8_t *p = buf;
1958 uint32_t *eccpos = chip->ecc.layout->eccpos; 1968 uint32_t *eccpos = chip->ecc.layout->eccpos;
1959 1969
1960 /* Software ecc calculation */ 1970 /* Software ECC calculation */
1961 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) 1971 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
1962 chip->ecc.calculate(mtd, p, &ecc_calc[i]); 1972 chip->ecc.calculate(mtd, p, &ecc_calc[i]);
1963 1973
@@ -1968,10 +1978,10 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1968} 1978}
1969 1979
1970/** 1980/**
1971 * nand_write_page_hwecc - [REPLACABLE] hardware ecc based page write function 1981 * nand_write_page_hwecc - [REPLACEABLE] hardware ECC based page write function
1972 * @mtd: mtd info structure 1982 * @mtd: mtd info structure
1973 * @chip: nand chip info structure 1983 * @chip: nand chip info structure
1974 * @buf: data buffer 1984 * @buf: data buffer
1975 */ 1985 */
1976static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 1986static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1977 const uint8_t *buf) 1987 const uint8_t *buf)
@@ -1996,13 +2006,13 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1996} 2006}
1997 2007
1998/** 2008/**
1999 * nand_write_page_syndrome - [REPLACABLE] hardware ecc syndrom based page write 2009 * nand_write_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page write
2000 * @mtd: mtd info structure 2010 * @mtd: mtd info structure
2001 * @chip: nand chip info structure 2011 * @chip: nand chip info structure
2002 * @buf: data buffer 2012 * @buf: data buffer
2003 * 2013 *
2004 * The hw generator calculates the error syndrome automatically. Therefor 2014 * The hw generator calculates the error syndrome automatically. Therefore we
2005 * we need a special oob layout and handling. 2015 * need a special oob layout and handling.
2006 */ 2016 */
2007static void nand_write_page_syndrome(struct mtd_info *mtd, 2017static void nand_write_page_syndrome(struct mtd_info *mtd,
2008 struct nand_chip *chip, const uint8_t *buf) 2018 struct nand_chip *chip, const uint8_t *buf)
@@ -2041,12 +2051,12 @@ static void nand_write_page_syndrome(struct mtd_info *mtd,
2041 2051
2042/** 2052/**
2043 * nand_write_page - [REPLACEABLE] write one page 2053 * nand_write_page - [REPLACEABLE] write one page
2044 * @mtd: MTD device structure 2054 * @mtd: MTD device structure
2045 * @chip: NAND chip descriptor 2055 * @chip: NAND chip descriptor
2046 * @buf: the data to write 2056 * @buf: the data to write
2047 * @page: page number to write 2057 * @page: page number to write
2048 * @cached: cached programming 2058 * @cached: cached programming
2049 * @raw: use _raw version of write_page 2059 * @raw: use _raw version of write_page
2050 */ 2060 */
2051static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, 2061static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2052 const uint8_t *buf, int page, int cached, int raw) 2062 const uint8_t *buf, int page, int cached, int raw)
@@ -2061,8 +2071,8 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2061 chip->ecc.write_page(mtd, chip, buf); 2071 chip->ecc.write_page(mtd, chip, buf);
2062 2072
2063 /* 2073 /*
2064 * Cached progamming disabled for now, Not sure if its worth the 2074 * Cached progamming disabled for now. Not sure if it's worth the
2065 * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s) 2075 * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s).
2066 */ 2076 */
2067 cached = 0; 2077 cached = 0;
2068 2078
@@ -2072,7 +2082,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2072 status = chip->waitfunc(mtd, chip); 2082 status = chip->waitfunc(mtd, chip);
2073 /* 2083 /*
2074 * See if operation failed and additional status checks are 2084 * See if operation failed and additional status checks are
2075 * available 2085 * available.
2076 */ 2086 */
2077 if ((status & NAND_STATUS_FAIL) && (chip->errstat)) 2087 if ((status & NAND_STATUS_FAIL) && (chip->errstat))
2078 status = chip->errstat(mtd, chip, FL_WRITING, status, 2088 status = chip->errstat(mtd, chip, FL_WRITING, status,
@@ -2096,29 +2106,37 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2096} 2106}
2097 2107
2098/** 2108/**
2099 * nand_fill_oob - [Internal] Transfer client buffer to oob 2109 * nand_fill_oob - [INTERN] Transfer client buffer to oob
2100 * @chip: nand chip structure 2110 * @mtd: MTD device structure
2101 * @oob: oob data buffer 2111 * @oob: oob data buffer
2102 * @len: oob data write length 2112 * @len: oob data write length
2103 * @ops: oob ops structure 2113 * @ops: oob ops structure
2104 */ 2114 */
2105static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, 2115static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len,
2106 struct mtd_oob_ops *ops) 2116 struct mtd_oob_ops *ops)
2107{ 2117{
2118 struct nand_chip *chip = mtd->priv;
2119
2120 /*
2121 * Initialise to all 0xFF, to avoid the possibility of left over OOB
2122 * data from a previous OOB read.
2123 */
2124 memset(chip->oob_poi, 0xff, mtd->oobsize);
2125
2108 switch (ops->mode) { 2126 switch (ops->mode) {
2109 2127
2110 case MTD_OOB_PLACE: 2128 case MTD_OPS_PLACE_OOB:
2111 case MTD_OOB_RAW: 2129 case MTD_OPS_RAW:
2112 memcpy(chip->oob_poi + ops->ooboffs, oob, len); 2130 memcpy(chip->oob_poi + ops->ooboffs, oob, len);
2113 return oob + len; 2131 return oob + len;
2114 2132
2115 case MTD_OOB_AUTO: { 2133 case MTD_OPS_AUTO_OOB: {
2116 struct nand_oobfree *free = chip->ecc.layout->oobfree; 2134 struct nand_oobfree *free = chip->ecc.layout->oobfree;
2117 uint32_t boffs = 0, woffs = ops->ooboffs; 2135 uint32_t boffs = 0, woffs = ops->ooboffs;
2118 size_t bytes = 0; 2136 size_t bytes = 0;
2119 2137
2120 for (; free->length && len; free++, len -= bytes) { 2138 for (; free->length && len; free++, len -= bytes) {
2121 /* Write request not from offset 0 ? */ 2139 /* Write request not from offset 0? */
2122 if (unlikely(woffs)) { 2140 if (unlikely(woffs)) {
2123 if (woffs >= free->length) { 2141 if (woffs >= free->length) {
2124 woffs -= free->length; 2142 woffs -= free->length;
@@ -2146,12 +2164,12 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len,
2146#define NOTALIGNED(x) ((x & (chip->subpagesize - 1)) != 0) 2164#define NOTALIGNED(x) ((x & (chip->subpagesize - 1)) != 0)
2147 2165
2148/** 2166/**
2149 * nand_do_write_ops - [Internal] NAND write with ECC 2167 * nand_do_write_ops - [INTERN] NAND write with ECC
2150 * @mtd: MTD device structure 2168 * @mtd: MTD device structure
2151 * @to: offset to write to 2169 * @to: offset to write to
2152 * @ops: oob operations description structure 2170 * @ops: oob operations description structure
2153 * 2171 *
2154 * NAND write with ECC 2172 * NAND write with ECC.
2155 */ 2173 */
2156static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, 2174static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2157 struct mtd_oob_ops *ops) 2175 struct mtd_oob_ops *ops)
@@ -2161,7 +2179,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2161 uint32_t writelen = ops->len; 2179 uint32_t writelen = ops->len;
2162 2180
2163 uint32_t oobwritelen = ops->ooblen; 2181 uint32_t oobwritelen = ops->ooblen;
2164 uint32_t oobmaxlen = ops->mode == MTD_OOB_AUTO ? 2182 uint32_t oobmaxlen = ops->mode == MTD_OPS_AUTO_OOB ?
2165 mtd->oobavail : mtd->oobsize; 2183 mtd->oobavail : mtd->oobsize;
2166 2184
2167 uint8_t *oob = ops->oobbuf; 2185 uint8_t *oob = ops->oobbuf;
@@ -2172,10 +2190,10 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2172 if (!writelen) 2190 if (!writelen)
2173 return 0; 2191 return 0;
2174 2192
2175 /* reject writes, which are not page aligned */ 2193 /* Reject writes, which are not page aligned */
2176 if (NOTALIGNED(to) || NOTALIGNED(ops->len)) { 2194 if (NOTALIGNED(to) || NOTALIGNED(ops->len)) {
2177 printk(KERN_NOTICE "%s: Attempt to write not " 2195 pr_notice("%s: attempt to write non page aligned data\n",
2178 "page aligned data\n", __func__); 2196 __func__);
2179 return -EINVAL; 2197 return -EINVAL;
2180 } 2198 }
2181 2199
@@ -2201,10 +2219,6 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2201 (chip->pagebuf << chip->page_shift) < (to + ops->len)) 2219 (chip->pagebuf << chip->page_shift) < (to + ops->len))
2202 chip->pagebuf = -1; 2220 chip->pagebuf = -1;
2203 2221
2204 /* If we're not given explicit OOB data, let it be 0xFF */
2205 if (likely(!oob))
2206 memset(chip->oob_poi, 0xff, mtd->oobsize);
2207
2208 /* Don't allow multipage oob writes with offset */ 2222 /* Don't allow multipage oob writes with offset */
2209 if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) 2223 if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen))
2210 return -EINVAL; 2224 return -EINVAL;
@@ -2214,7 +2228,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2214 int cached = writelen > bytes && page != blockmask; 2228 int cached = writelen > bytes && page != blockmask;
2215 uint8_t *wbuf = buf; 2229 uint8_t *wbuf = buf;
2216 2230
2217 /* Partial page write ? */ 2231 /* Partial page write? */
2218 if (unlikely(column || writelen < (mtd->writesize - 1))) { 2232 if (unlikely(column || writelen < (mtd->writesize - 1))) {
2219 cached = 0; 2233 cached = 0;
2220 bytes = min_t(int, bytes - column, (int) writelen); 2234 bytes = min_t(int, bytes - column, (int) writelen);
@@ -2226,12 +2240,15 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2226 2240
2227 if (unlikely(oob)) { 2241 if (unlikely(oob)) {
2228 size_t len = min(oobwritelen, oobmaxlen); 2242 size_t len = min(oobwritelen, oobmaxlen);
2229 oob = nand_fill_oob(chip, oob, len, ops); 2243 oob = nand_fill_oob(mtd, oob, len, ops);
2230 oobwritelen -= len; 2244 oobwritelen -= len;
2245 } else {
2246 /* We still need to erase leftover OOB data */
2247 memset(chip->oob_poi, 0xff, mtd->oobsize);
2231 } 2248 }
2232 2249
2233 ret = chip->write_page(mtd, chip, wbuf, page, cached, 2250 ret = chip->write_page(mtd, chip, wbuf, page, cached,
2234 (ops->mode == MTD_OOB_RAW)); 2251 (ops->mode == MTD_OPS_RAW));
2235 if (ret) 2252 if (ret)
2236 break; 2253 break;
2237 2254
@@ -2260,11 +2277,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2260 2277
2261/** 2278/**
2262 * panic_nand_write - [MTD Interface] NAND write with ECC 2279 * panic_nand_write - [MTD Interface] NAND write with ECC
2263 * @mtd: MTD device structure 2280 * @mtd: MTD device structure
2264 * @to: offset to write to 2281 * @to: offset to write to
2265 * @len: number of bytes to write 2282 * @len: number of bytes to write
2266 * @retlen: pointer to variable to store the number of written bytes 2283 * @retlen: pointer to variable to store the number of written bytes
2267 * @buf: the data to write 2284 * @buf: the data to write
2268 * 2285 *
2269 * NAND write with ECC. Used when performing writes in interrupt context, this 2286 * NAND write with ECC. Used when performing writes in interrupt context, this
2270 * may for example be called by mtdoops when writing an oops while in panic. 2287 * may for example be called by mtdoops when writing an oops while in panic.
@@ -2273,6 +2290,7 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
2273 size_t *retlen, const uint8_t *buf) 2290 size_t *retlen, const uint8_t *buf)
2274{ 2291{
2275 struct nand_chip *chip = mtd->priv; 2292 struct nand_chip *chip = mtd->priv;
2293 struct mtd_oob_ops ops;
2276 int ret; 2294 int ret;
2277 2295
2278 /* Do not allow reads past end of device */ 2296 /* Do not allow reads past end of device */
@@ -2281,36 +2299,38 @@ static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
2281 if (!len) 2299 if (!len)
2282 return 0; 2300 return 0;
2283 2301
2284 /* Wait for the device to get ready. */ 2302 /* Wait for the device to get ready */
2285 panic_nand_wait(mtd, chip, 400); 2303 panic_nand_wait(mtd, chip, 400);
2286 2304
2287 /* Grab the device. */ 2305 /* Grab the device */
2288 panic_nand_get_device(chip, mtd, FL_WRITING); 2306 panic_nand_get_device(chip, mtd, FL_WRITING);
2289 2307
2290 chip->ops.len = len; 2308 ops.len = len;
2291 chip->ops.datbuf = (uint8_t *)buf; 2309 ops.datbuf = (uint8_t *)buf;
2292 chip->ops.oobbuf = NULL; 2310 ops.oobbuf = NULL;
2311 ops.mode = 0;
2293 2312
2294 ret = nand_do_write_ops(mtd, to, &chip->ops); 2313 ret = nand_do_write_ops(mtd, to, &ops);
2295 2314
2296 *retlen = chip->ops.retlen; 2315 *retlen = ops.retlen;
2297 return ret; 2316 return ret;
2298} 2317}
2299 2318
2300/** 2319/**
2301 * nand_write - [MTD Interface] NAND write with ECC 2320 * nand_write - [MTD Interface] NAND write with ECC
2302 * @mtd: MTD device structure 2321 * @mtd: MTD device structure
2303 * @to: offset to write to 2322 * @to: offset to write to
2304 * @len: number of bytes to write 2323 * @len: number of bytes to write
2305 * @retlen: pointer to variable to store the number of written bytes 2324 * @retlen: pointer to variable to store the number of written bytes
2306 * @buf: the data to write 2325 * @buf: the data to write
2307 * 2326 *
2308 * NAND write with ECC 2327 * NAND write with ECC.
2309 */ 2328 */
2310static int nand_write(struct mtd_info *mtd, loff_t to, size_t len, 2329static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
2311 size_t *retlen, const uint8_t *buf) 2330 size_t *retlen, const uint8_t *buf)
2312{ 2331{
2313 struct nand_chip *chip = mtd->priv; 2332 struct nand_chip *chip = mtd->priv;
2333 struct mtd_oob_ops ops;
2314 int ret; 2334 int ret;
2315 2335
2316 /* Do not allow reads past end of device */ 2336 /* Do not allow reads past end of device */
@@ -2321,13 +2341,14 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
2321 2341
2322 nand_get_device(chip, mtd, FL_WRITING); 2342 nand_get_device(chip, mtd, FL_WRITING);
2323 2343
2324 chip->ops.len = len; 2344 ops.len = len;
2325 chip->ops.datbuf = (uint8_t *)buf; 2345 ops.datbuf = (uint8_t *)buf;
2326 chip->ops.oobbuf = NULL; 2346 ops.oobbuf = NULL;
2347 ops.mode = 0;
2327 2348
2328 ret = nand_do_write_ops(mtd, to, &chip->ops); 2349 ret = nand_do_write_ops(mtd, to, &ops);
2329 2350
2330 *retlen = chip->ops.retlen; 2351 *retlen = ops.retlen;
2331 2352
2332 nand_release_device(mtd); 2353 nand_release_device(mtd);
2333 2354
@@ -2336,11 +2357,11 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
2336 2357
2337/** 2358/**
2338 * nand_do_write_oob - [MTD Interface] NAND write out-of-band 2359 * nand_do_write_oob - [MTD Interface] NAND write out-of-band
2339 * @mtd: MTD device structure 2360 * @mtd: MTD device structure
2340 * @to: offset to write to 2361 * @to: offset to write to
2341 * @ops: oob operation description structure 2362 * @ops: oob operation description structure
2342 * 2363 *
2343 * NAND write out-of-band 2364 * NAND write out-of-band.
2344 */ 2365 */
2345static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, 2366static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2346 struct mtd_oob_ops *ops) 2367 struct mtd_oob_ops *ops)
@@ -2348,24 +2369,24 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2348 int chipnr, page, status, len; 2369 int chipnr, page, status, len;
2349 struct nand_chip *chip = mtd->priv; 2370 struct nand_chip *chip = mtd->priv;
2350 2371
2351 DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", 2372 pr_debug("%s: to = 0x%08x, len = %i\n",
2352 __func__, (unsigned int)to, (int)ops->ooblen); 2373 __func__, (unsigned int)to, (int)ops->ooblen);
2353 2374
2354 if (ops->mode == MTD_OOB_AUTO) 2375 if (ops->mode == MTD_OPS_AUTO_OOB)
2355 len = chip->ecc.layout->oobavail; 2376 len = chip->ecc.layout->oobavail;
2356 else 2377 else
2357 len = mtd->oobsize; 2378 len = mtd->oobsize;
2358 2379
2359 /* Do not allow write past end of page */ 2380 /* Do not allow write past end of page */
2360 if ((ops->ooboffs + ops->ooblen) > len) { 2381 if ((ops->ooboffs + ops->ooblen) > len) {
2361 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to write " 2382 pr_debug("%s: attempt to write past end of page\n",
2362 "past end of page\n", __func__); 2383 __func__);
2363 return -EINVAL; 2384 return -EINVAL;
2364 } 2385 }
2365 2386
2366 if (unlikely(ops->ooboffs >= len)) { 2387 if (unlikely(ops->ooboffs >= len)) {
2367 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to start " 2388 pr_debug("%s: attempt to start write outside oob\n",
2368 "write outside oob\n", __func__); 2389 __func__);
2369 return -EINVAL; 2390 return -EINVAL;
2370 } 2391 }
2371 2392
@@ -2374,8 +2395,8 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2374 ops->ooboffs + ops->ooblen > 2395 ops->ooboffs + ops->ooblen >
2375 ((mtd->size >> chip->page_shift) - 2396 ((mtd->size >> chip->page_shift) -
2376 (to >> chip->page_shift)) * len)) { 2397 (to >> chip->page_shift)) * len)) {
2377 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt write beyond " 2398 pr_debug("%s: attempt to write beyond end of device\n",
2378 "end of device\n", __func__); 2399 __func__);
2379 return -EINVAL; 2400 return -EINVAL;
2380 } 2401 }
2381 2402
@@ -2401,10 +2422,12 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2401 if (page == chip->pagebuf) 2422 if (page == chip->pagebuf)
2402 chip->pagebuf = -1; 2423 chip->pagebuf = -1;
2403 2424
2404 memset(chip->oob_poi, 0xff, mtd->oobsize); 2425 nand_fill_oob(mtd, ops->oobbuf, ops->ooblen, ops);
2405 nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); 2426
2406 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); 2427 if (ops->mode == MTD_OPS_RAW)
2407 memset(chip->oob_poi, 0xff, mtd->oobsize); 2428 status = chip->ecc.write_oob_raw(mtd, chip, page & chip->pagemask);
2429 else
2430 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask);
2408 2431
2409 if (status) 2432 if (status)
2410 return status; 2433 return status;
@@ -2416,9 +2439,9 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2416 2439
2417/** 2440/**
2418 * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band 2441 * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band
2419 * @mtd: MTD device structure 2442 * @mtd: MTD device structure
2420 * @to: offset to write to 2443 * @to: offset to write to
2421 * @ops: oob operation description structure 2444 * @ops: oob operation description structure
2422 */ 2445 */
2423static int nand_write_oob(struct mtd_info *mtd, loff_t to, 2446static int nand_write_oob(struct mtd_info *mtd, loff_t to,
2424 struct mtd_oob_ops *ops) 2447 struct mtd_oob_ops *ops)
@@ -2430,17 +2453,17 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
2430 2453
2431 /* Do not allow writes past end of device */ 2454 /* Do not allow writes past end of device */
2432 if (ops->datbuf && (to + ops->len) > mtd->size) { 2455 if (ops->datbuf && (to + ops->len) > mtd->size) {
2433 DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt write beyond " 2456 pr_debug("%s: attempt to write beyond end of device\n",
2434 "end of device\n", __func__); 2457 __func__);
2435 return -EINVAL; 2458 return -EINVAL;
2436 } 2459 }
2437 2460
2438 nand_get_device(chip, mtd, FL_WRITING); 2461 nand_get_device(chip, mtd, FL_WRITING);
2439 2462
2440 switch (ops->mode) { 2463 switch (ops->mode) {
2441 case MTD_OOB_PLACE: 2464 case MTD_OPS_PLACE_OOB:
2442 case MTD_OOB_AUTO: 2465 case MTD_OPS_AUTO_OOB:
2443 case MTD_OOB_RAW: 2466 case MTD_OPS_RAW:
2444 break; 2467 break;
2445 2468
2446 default: 2469 default:
@@ -2458,11 +2481,11 @@ out:
2458} 2481}
2459 2482
2460/** 2483/**
2461 * single_erease_cmd - [GENERIC] NAND standard block erase command function 2484 * single_erase_cmd - [GENERIC] NAND standard block erase command function
2462 * @mtd: MTD device structure 2485 * @mtd: MTD device structure
2463 * @page: the page address of the block which will be erased 2486 * @page: the page address of the block which will be erased
2464 * 2487 *
2465 * Standard erase command for NAND chips 2488 * Standard erase command for NAND chips.
2466 */ 2489 */
2467static void single_erase_cmd(struct mtd_info *mtd, int page) 2490static void single_erase_cmd(struct mtd_info *mtd, int page)
2468{ 2491{
@@ -2473,12 +2496,11 @@ static void single_erase_cmd(struct mtd_info *mtd, int page)
2473} 2496}
2474 2497
2475/** 2498/**
2476 * multi_erease_cmd - [GENERIC] AND specific block erase command function 2499 * multi_erase_cmd - [GENERIC] AND specific block erase command function
2477 * @mtd: MTD device structure 2500 * @mtd: MTD device structure
2478 * @page: the page address of the block which will be erased 2501 * @page: the page address of the block which will be erased
2479 * 2502 *
2480 * AND multi block erase command function 2503 * AND multi block erase command function. Erase 4 consecutive blocks.
2481 * Erase 4 consecutive blocks
2482 */ 2504 */
2483static void multi_erase_cmd(struct mtd_info *mtd, int page) 2505static void multi_erase_cmd(struct mtd_info *mtd, int page)
2484{ 2506{
@@ -2493,10 +2515,10 @@ static void multi_erase_cmd(struct mtd_info *mtd, int page)
2493 2515
2494/** 2516/**
2495 * nand_erase - [MTD Interface] erase block(s) 2517 * nand_erase - [MTD Interface] erase block(s)
2496 * @mtd: MTD device structure 2518 * @mtd: MTD device structure
2497 * @instr: erase instruction 2519 * @instr: erase instruction
2498 * 2520 *
2499 * Erase one ore more blocks 2521 * Erase one ore more blocks.
2500 */ 2522 */
2501static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) 2523static int nand_erase(struct mtd_info *mtd, struct erase_info *instr)
2502{ 2524{
@@ -2505,12 +2527,12 @@ static int nand_erase(struct mtd_info *mtd, struct erase_info *instr)
2505 2527
2506#define BBT_PAGE_MASK 0xffffff3f 2528#define BBT_PAGE_MASK 0xffffff3f
2507/** 2529/**
2508 * nand_erase_nand - [Internal] erase block(s) 2530 * nand_erase_nand - [INTERN] erase block(s)
2509 * @mtd: MTD device structure 2531 * @mtd: MTD device structure
2510 * @instr: erase instruction 2532 * @instr: erase instruction
2511 * @allowbbt: allow erasing the bbt area 2533 * @allowbbt: allow erasing the bbt area
2512 * 2534 *
2513 * Erase one ore more blocks 2535 * Erase one ore more blocks.
2514 */ 2536 */
2515int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, 2537int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2516 int allowbbt) 2538 int allowbbt)
@@ -2521,9 +2543,9 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2521 unsigned int bbt_masked_page = 0xffffffff; 2543 unsigned int bbt_masked_page = 0xffffffff;
2522 loff_t len; 2544 loff_t len;
2523 2545
2524 DEBUG(MTD_DEBUG_LEVEL3, "%s: start = 0x%012llx, len = %llu\n", 2546 pr_debug("%s: start = 0x%012llx, len = %llu\n",
2525 __func__, (unsigned long long)instr->addr, 2547 __func__, (unsigned long long)instr->addr,
2526 (unsigned long long)instr->len); 2548 (unsigned long long)instr->len);
2527 2549
2528 if (check_offs_len(mtd, instr->addr, instr->len)) 2550 if (check_offs_len(mtd, instr->addr, instr->len))
2529 return -EINVAL; 2551 return -EINVAL;
@@ -2545,8 +2567,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2545 2567
2546 /* Check, if it is write protected */ 2568 /* Check, if it is write protected */
2547 if (nand_check_wp(mtd)) { 2569 if (nand_check_wp(mtd)) {
2548 DEBUG(MTD_DEBUG_LEVEL0, "%s: Device is write protected!!!\n", 2570 pr_debug("%s: device is write protected!\n",
2549 __func__); 2571 __func__);
2550 instr->state = MTD_ERASE_FAILED; 2572 instr->state = MTD_ERASE_FAILED;
2551 goto erase_exit; 2573 goto erase_exit;
2552 } 2574 }
@@ -2555,7 +2577,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2555 * If BBT requires refresh, set the BBT page mask to see if the BBT 2577 * If BBT requires refresh, set the BBT page mask to see if the BBT
2556 * should be rewritten. Otherwise the mask is set to 0xffffffff which 2578 * should be rewritten. Otherwise the mask is set to 0xffffffff which
2557 * can not be matched. This is also done when the bbt is actually 2579 * can not be matched. This is also done when the bbt is actually
2558 * erased to avoid recusrsive updates 2580 * erased to avoid recursive updates.
2559 */ 2581 */
2560 if (chip->options & BBT_AUTO_REFRESH && !allowbbt) 2582 if (chip->options & BBT_AUTO_REFRESH && !allowbbt)
2561 bbt_masked_page = chip->bbt_td->pages[chipnr] & BBT_PAGE_MASK; 2583 bbt_masked_page = chip->bbt_td->pages[chipnr] & BBT_PAGE_MASK;
@@ -2566,20 +2588,18 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2566 instr->state = MTD_ERASING; 2588 instr->state = MTD_ERASING;
2567 2589
2568 while (len) { 2590 while (len) {
2569 /* 2591 /* Heck if we have a bad block, we do not erase bad blocks! */
2570 * heck if we have a bad block, we do not erase bad blocks !
2571 */
2572 if (nand_block_checkbad(mtd, ((loff_t) page) << 2592 if (nand_block_checkbad(mtd, ((loff_t) page) <<
2573 chip->page_shift, 0, allowbbt)) { 2593 chip->page_shift, 0, allowbbt)) {
2574 printk(KERN_WARNING "%s: attempt to erase a bad block " 2594 pr_warn("%s: attempt to erase a bad block at page 0x%08x\n",
2575 "at page 0x%08x\n", __func__, page); 2595 __func__, page);
2576 instr->state = MTD_ERASE_FAILED; 2596 instr->state = MTD_ERASE_FAILED;
2577 goto erase_exit; 2597 goto erase_exit;
2578 } 2598 }
2579 2599
2580 /* 2600 /*
2581 * Invalidate the page cache, if we erase the block which 2601 * Invalidate the page cache, if we erase the block which
2582 * contains the current cached page 2602 * contains the current cached page.
2583 */ 2603 */
2584 if (page <= chip->pagebuf && chip->pagebuf < 2604 if (page <= chip->pagebuf && chip->pagebuf <
2585 (page + pages_per_block)) 2605 (page + pages_per_block))
@@ -2599,8 +2619,8 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2599 2619
2600 /* See if block erase succeeded */ 2620 /* See if block erase succeeded */
2601 if (status & NAND_STATUS_FAIL) { 2621 if (status & NAND_STATUS_FAIL) {
2602 DEBUG(MTD_DEBUG_LEVEL0, "%s: Failed erase, " 2622 pr_debug("%s: failed erase, page 0x%08x\n",
2603 "page 0x%08x\n", __func__, page); 2623 __func__, page);
2604 instr->state = MTD_ERASE_FAILED; 2624 instr->state = MTD_ERASE_FAILED;
2605 instr->fail_addr = 2625 instr->fail_addr =
2606 ((loff_t)page << chip->page_shift); 2626 ((loff_t)page << chip->page_shift);
@@ -2609,7 +2629,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2609 2629
2610 /* 2630 /*
2611 * If BBT requires refresh, set the BBT rewrite flag to the 2631 * If BBT requires refresh, set the BBT rewrite flag to the
2612 * page being erased 2632 * page being erased.
2613 */ 2633 */
2614 if (bbt_masked_page != 0xffffffff && 2634 if (bbt_masked_page != 0xffffffff &&
2615 (page & BBT_PAGE_MASK) == bbt_masked_page) 2635 (page & BBT_PAGE_MASK) == bbt_masked_page)
@@ -2628,7 +2648,7 @@ int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
2628 2648
2629 /* 2649 /*
2630 * If BBT requires refresh and BBT-PERCHIP, set the BBT 2650 * If BBT requires refresh and BBT-PERCHIP, set the BBT
2631 * page mask to see if this BBT should be rewritten 2651 * page mask to see if this BBT should be rewritten.
2632 */ 2652 */
2633 if (bbt_masked_page != 0xffffffff && 2653 if (bbt_masked_page != 0xffffffff &&
2634 (chip->bbt_td->options & NAND_BBT_PERCHIP)) 2654 (chip->bbt_td->options & NAND_BBT_PERCHIP))
@@ -2651,7 +2671,7 @@ erase_exit:
2651 2671
2652 /* 2672 /*
2653 * If BBT requires refresh and erase was successful, rewrite any 2673 * If BBT requires refresh and erase was successful, rewrite any
2654 * selected bad block tables 2674 * selected bad block tables.
2655 */ 2675 */
2656 if (bbt_masked_page == 0xffffffff || ret) 2676 if (bbt_masked_page == 0xffffffff || ret)
2657 return ret; 2677 return ret;
@@ -2659,10 +2679,10 @@ erase_exit:
2659 for (chipnr = 0; chipnr < chip->numchips; chipnr++) { 2679 for (chipnr = 0; chipnr < chip->numchips; chipnr++) {
2660 if (!rewrite_bbt[chipnr]) 2680 if (!rewrite_bbt[chipnr])
2661 continue; 2681 continue;
2662 /* update the BBT for chip */ 2682 /* Update the BBT for chip */
2663 DEBUG(MTD_DEBUG_LEVEL0, "%s: nand_update_bbt " 2683 pr_debug("%s: nand_update_bbt (%d:0x%0llx 0x%0x)\n",
2664 "(%d:0x%0llx 0x%0x)\n", __func__, chipnr, 2684 __func__, chipnr, rewrite_bbt[chipnr],
2665 rewrite_bbt[chipnr], chip->bbt_td->pages[chipnr]); 2685 chip->bbt_td->pages[chipnr]);
2666 nand_update_bbt(mtd, rewrite_bbt[chipnr]); 2686 nand_update_bbt(mtd, rewrite_bbt[chipnr]);
2667 } 2687 }
2668 2688
@@ -2672,15 +2692,15 @@ erase_exit:
2672 2692
2673/** 2693/**
2674 * nand_sync - [MTD Interface] sync 2694 * nand_sync - [MTD Interface] sync
2675 * @mtd: MTD device structure 2695 * @mtd: MTD device structure
2676 * 2696 *
2677 * Sync is actually a wait for chip ready function 2697 * Sync is actually a wait for chip ready function.
2678 */ 2698 */
2679static void nand_sync(struct mtd_info *mtd) 2699static void nand_sync(struct mtd_info *mtd)
2680{ 2700{
2681 struct nand_chip *chip = mtd->priv; 2701 struct nand_chip *chip = mtd->priv;
2682 2702
2683 DEBUG(MTD_DEBUG_LEVEL3, "%s: called\n", __func__); 2703 pr_debug("%s: called\n", __func__);
2684 2704
2685 /* Grab the lock and see if the device is available */ 2705 /* Grab the lock and see if the device is available */
2686 nand_get_device(chip, mtd, FL_SYNCING); 2706 nand_get_device(chip, mtd, FL_SYNCING);
@@ -2690,8 +2710,8 @@ static void nand_sync(struct mtd_info *mtd)
2690 2710
2691/** 2711/**
2692 * nand_block_isbad - [MTD Interface] Check if block at offset is bad 2712 * nand_block_isbad - [MTD Interface] Check if block at offset is bad
2693 * @mtd: MTD device structure 2713 * @mtd: MTD device structure
2694 * @offs: offset relative to mtd start 2714 * @offs: offset relative to mtd start
2695 */ 2715 */
2696static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) 2716static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
2697{ 2717{
@@ -2704,8 +2724,8 @@ static int nand_block_isbad(struct mtd_info *mtd, loff_t offs)
2704 2724
2705/** 2725/**
2706 * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad 2726 * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad
2707 * @mtd: MTD device structure 2727 * @mtd: MTD device structure
2708 * @ofs: offset relative to mtd start 2728 * @ofs: offset relative to mtd start
2709 */ 2729 */
2710static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) 2730static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
2711{ 2731{
@@ -2714,7 +2734,7 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
2714 2734
2715 ret = nand_block_isbad(mtd, ofs); 2735 ret = nand_block_isbad(mtd, ofs);
2716 if (ret) { 2736 if (ret) {
2717 /* If it was bad already, return success and do nothing. */ 2737 /* If it was bad already, return success and do nothing */
2718 if (ret > 0) 2738 if (ret > 0)
2719 return 0; 2739 return 0;
2720 return ret; 2740 return ret;
@@ -2725,7 +2745,7 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
2725 2745
2726/** 2746/**
2727 * nand_suspend - [MTD Interface] Suspend the NAND flash 2747 * nand_suspend - [MTD Interface] Suspend the NAND flash
2728 * @mtd: MTD device structure 2748 * @mtd: MTD device structure
2729 */ 2749 */
2730static int nand_suspend(struct mtd_info *mtd) 2750static int nand_suspend(struct mtd_info *mtd)
2731{ 2751{
@@ -2736,7 +2756,7 @@ static int nand_suspend(struct mtd_info *mtd)
2736 2756
2737/** 2757/**
2738 * nand_resume - [MTD Interface] Resume the NAND flash 2758 * nand_resume - [MTD Interface] Resume the NAND flash
2739 * @mtd: MTD device structure 2759 * @mtd: MTD device structure
2740 */ 2760 */
2741static void nand_resume(struct mtd_info *mtd) 2761static void nand_resume(struct mtd_info *mtd)
2742{ 2762{
@@ -2745,13 +2765,11 @@ static void nand_resume(struct mtd_info *mtd)
2745 if (chip->state == FL_PM_SUSPENDED) 2765 if (chip->state == FL_PM_SUSPENDED)
2746 nand_release_device(mtd); 2766 nand_release_device(mtd);
2747 else 2767 else
2748 printk(KERN_ERR "%s called for a chip which is not " 2768 pr_err("%s called for a chip which is not in suspended state\n",
2749 "in suspended state\n", __func__); 2769 __func__);
2750} 2770}
2751 2771
2752/* 2772/* Set default functions */
2753 * Set default functions
2754 */
2755static void nand_set_defaults(struct nand_chip *chip, int busw) 2773static void nand_set_defaults(struct nand_chip *chip, int busw)
2756{ 2774{
2757 /* check for proper chip_delay setup, set 20us if not */ 2775 /* check for proper chip_delay setup, set 20us if not */
@@ -2793,23 +2811,21 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
2793 2811
2794} 2812}
2795 2813
2796/* 2814/* Sanitize ONFI strings so we can safely print them */
2797 * sanitize ONFI strings so we can safely print them
2798 */
2799static void sanitize_string(uint8_t *s, size_t len) 2815static void sanitize_string(uint8_t *s, size_t len)
2800{ 2816{
2801 ssize_t i; 2817 ssize_t i;
2802 2818
2803 /* null terminate */ 2819 /* Null terminate */
2804 s[len - 1] = 0; 2820 s[len - 1] = 0;
2805 2821
2806 /* remove non printable chars */ 2822 /* Remove non printable chars */
2807 for (i = 0; i < len - 1; i++) { 2823 for (i = 0; i < len - 1; i++) {
2808 if (s[i] < ' ' || s[i] > 127) 2824 if (s[i] < ' ' || s[i] > 127)
2809 s[i] = '?'; 2825 s[i] = '?';
2810 } 2826 }
2811 2827
2812 /* remove trailing spaces */ 2828 /* Remove trailing spaces */
2813 strim(s); 2829 strim(s);
2814} 2830}
2815 2831
@@ -2826,28 +2842,28 @@ static u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
2826} 2842}
2827 2843
2828/* 2844/*
2829 * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise 2845 * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
2830 */ 2846 */
2831static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, 2847static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
2832 int busw) 2848 int *busw)
2833{ 2849{
2834 struct nand_onfi_params *p = &chip->onfi_params; 2850 struct nand_onfi_params *p = &chip->onfi_params;
2835 int i; 2851 int i;
2836 int val; 2852 int val;
2837 2853
2838 /* try ONFI for unknow chip or LP */ 2854 /* Try ONFI for unknown chip or LP */
2839 chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); 2855 chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1);
2840 if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || 2856 if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' ||
2841 chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I') 2857 chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I')
2842 return 0; 2858 return 0;
2843 2859
2844 printk(KERN_INFO "ONFI flash detected\n"); 2860 pr_info("ONFI flash detected\n");
2845 chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1); 2861 chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
2846 for (i = 0; i < 3; i++) { 2862 for (i = 0; i < 3; i++) {
2847 chip->read_buf(mtd, (uint8_t *)p, sizeof(*p)); 2863 chip->read_buf(mtd, (uint8_t *)p, sizeof(*p));
2848 if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) == 2864 if (onfi_crc16(ONFI_CRC_BASE, (uint8_t *)p, 254) ==
2849 le16_to_cpu(p->crc)) { 2865 le16_to_cpu(p->crc)) {
2850 printk(KERN_INFO "ONFI param page %d valid\n", i); 2866 pr_info("ONFI param page %d valid\n", i);
2851 break; 2867 break;
2852 } 2868 }
2853 } 2869 }
@@ -2855,7 +2871,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
2855 if (i == 3) 2871 if (i == 3)
2856 return 0; 2872 return 0;
2857 2873
2858 /* check version */ 2874 /* Check version */
2859 val = le16_to_cpu(p->revision); 2875 val = le16_to_cpu(p->revision);
2860 if (val & (1 << 5)) 2876 if (val & (1 << 5))
2861 chip->onfi_version = 23; 2877 chip->onfi_version = 23;
@@ -2871,8 +2887,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
2871 chip->onfi_version = 0; 2887 chip->onfi_version = 0;
2872 2888
2873 if (!chip->onfi_version) { 2889 if (!chip->onfi_version) {
2874 printk(KERN_INFO "%s: unsupported ONFI version: %d\n", 2890 pr_info("%s: unsupported ONFI version: %d\n", __func__, val);
2875 __func__, val);
2876 return 0; 2891 return 0;
2877 } 2892 }
2878 2893
@@ -2884,9 +2899,9 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
2884 mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize; 2899 mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize;
2885 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); 2900 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page);
2886 chip->chipsize = (uint64_t)le32_to_cpu(p->blocks_per_lun) * mtd->erasesize; 2901 chip->chipsize = (uint64_t)le32_to_cpu(p->blocks_per_lun) * mtd->erasesize;
2887 busw = 0; 2902 *busw = 0;
2888 if (le16_to_cpu(p->features) & 1) 2903 if (le16_to_cpu(p->features) & 1)
2889 busw = NAND_BUSWIDTH_16; 2904 *busw = NAND_BUSWIDTH_16;
2890 2905
2891 chip->options &= ~NAND_CHIPOPTIONS_MSK; 2906 chip->options &= ~NAND_CHIPOPTIONS_MSK;
2892 chip->options |= (NAND_NO_READRDY | 2907 chip->options |= (NAND_NO_READRDY |
@@ -2896,7 +2911,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
2896} 2911}
2897 2912
2898/* 2913/*
2899 * Get the flash and manufacturer id and lookup if the type is supported 2914 * Get the flash and manufacturer id and lookup if the type is supported.
2900 */ 2915 */
2901static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, 2916static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2902 struct nand_chip *chip, 2917 struct nand_chip *chip,
@@ -2913,7 +2928,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2913 2928
2914 /* 2929 /*
2915 * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) 2930 * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx)
2916 * after power-up 2931 * after power-up.
2917 */ 2932 */
2918 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 2933 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
2919 2934
@@ -2924,7 +2939,8 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2924 *maf_id = chip->read_byte(mtd); 2939 *maf_id = chip->read_byte(mtd);
2925 *dev_id = chip->read_byte(mtd); 2940 *dev_id = chip->read_byte(mtd);
2926 2941
2927 /* Try again to make sure, as some systems the bus-hold or other 2942 /*
2943 * Try again to make sure, as some systems the bus-hold or other
2928 * interface concerns can cause random data which looks like a 2944 * interface concerns can cause random data which looks like a
2929 * possibly credible NAND flash to appear. If the two results do 2945 * possibly credible NAND flash to appear. If the two results do
2930 * not match, ignore the device completely. 2946 * not match, ignore the device completely.
@@ -2936,9 +2952,9 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2936 id_data[i] = chip->read_byte(mtd); 2952 id_data[i] = chip->read_byte(mtd);
2937 2953
2938 if (id_data[0] != *maf_id || id_data[1] != *dev_id) { 2954 if (id_data[0] != *maf_id || id_data[1] != *dev_id) {
2939 printk(KERN_INFO "%s: second ID read did not match " 2955 pr_info("%s: second ID read did not match "
2940 "%02x,%02x against %02x,%02x\n", __func__, 2956 "%02x,%02x against %02x,%02x\n", __func__,
2941 *maf_id, *dev_id, id_data[0], id_data[1]); 2957 *maf_id, *dev_id, id_data[0], id_data[1]);
2942 return ERR_PTR(-ENODEV); 2958 return ERR_PTR(-ENODEV);
2943 } 2959 }
2944 2960
@@ -2952,7 +2968,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2952 chip->onfi_version = 0; 2968 chip->onfi_version = 0;
2953 if (!type->name || !type->pagesize) { 2969 if (!type->name || !type->pagesize) {
2954 /* Check is chip is ONFI compliant */ 2970 /* Check is chip is ONFI compliant */
2955 ret = nand_flash_detect_onfi(mtd, chip, busw); 2971 ret = nand_flash_detect_onfi(mtd, chip, &busw);
2956 if (ret) 2972 if (ret)
2957 goto ident_done; 2973 goto ident_done;
2958 } 2974 }
@@ -2973,7 +2989,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2973 chip->chipsize = (uint64_t)type->chipsize << 20; 2989 chip->chipsize = (uint64_t)type->chipsize << 20;
2974 2990
2975 if (!type->pagesize && chip->init_size) { 2991 if (!type->pagesize && chip->init_size) {
2976 /* set the pagesize, oobsize, erasesize by the driver*/ 2992 /* Set the pagesize, oobsize, erasesize by the driver */
2977 busw = chip->init_size(mtd, chip, id_data); 2993 busw = chip->init_size(mtd, chip, id_data);
2978 } else if (!type->pagesize) { 2994 } else if (!type->pagesize) {
2979 int extid; 2995 int extid;
@@ -3033,7 +3049,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
3033 } 3049 }
3034 } else { 3050 } else {
3035 /* 3051 /*
3036 * Old devices have chip data hardcoded in the device id table 3052 * Old devices have chip data hardcoded in the device id table.
3037 */ 3053 */
3038 mtd->erasesize = type->erasesize; 3054 mtd->erasesize = type->erasesize;
3039 mtd->writesize = type->pagesize; 3055 mtd->writesize = type->pagesize;
@@ -3043,7 +3059,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
3043 /* 3059 /*
3044 * Check for Spansion/AMD ID + repeating 5th, 6th byte since 3060 * Check for Spansion/AMD ID + repeating 5th, 6th byte since
3045 * some Spansion chips have erasesize that conflicts with size 3061 * some Spansion chips have erasesize that conflicts with size
3046 * listed in nand_ids table 3062 * listed in nand_ids table.
3047 * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) 3063 * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
3048 */ 3064 */
3049 if (*maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && 3065 if (*maf_id == NAND_MFR_AMD && id_data[4] != 0x00 &&
@@ -3057,15 +3073,16 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
3057 chip->options &= ~NAND_CHIPOPTIONS_MSK; 3073 chip->options &= ~NAND_CHIPOPTIONS_MSK;
3058 chip->options |= type->options & NAND_CHIPOPTIONS_MSK; 3074 chip->options |= type->options & NAND_CHIPOPTIONS_MSK;
3059 3075
3060 /* Check if chip is a not a samsung device. Do not clear the 3076 /*
3061 * options for chips which are not having an extended id. 3077 * Check if chip is not a Samsung device. Do not clear the
3078 * options for chips which do not have an extended id.
3062 */ 3079 */
3063 if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize) 3080 if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize)
3064 chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; 3081 chip->options &= ~NAND_SAMSUNG_LP_OPTIONS;
3065ident_done: 3082ident_done:
3066 3083
3067 /* 3084 /*
3068 * Set chip as a default. Board drivers can override it, if necessary 3085 * Set chip as a default. Board drivers can override it, if necessary.
3069 */ 3086 */
3070 chip->options |= NAND_NO_AUTOINCR; 3087 chip->options |= NAND_NO_AUTOINCR;
3071 3088
@@ -3077,21 +3094,21 @@ ident_done:
3077 3094
3078 /* 3095 /*
3079 * Check, if buswidth is correct. Hardware drivers should set 3096 * Check, if buswidth is correct. Hardware drivers should set
3080 * chip correct ! 3097 * chip correct!
3081 */ 3098 */
3082 if (busw != (chip->options & NAND_BUSWIDTH_16)) { 3099 if (busw != (chip->options & NAND_BUSWIDTH_16)) {
3083 printk(KERN_INFO "NAND device: Manufacturer ID:" 3100 pr_info("NAND device: Manufacturer ID:"
3084 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, 3101 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id,
3085 *dev_id, nand_manuf_ids[maf_idx].name, mtd->name); 3102 *dev_id, nand_manuf_ids[maf_idx].name, mtd->name);
3086 printk(KERN_WARNING "NAND bus width %d instead %d bit\n", 3103 pr_warn("NAND bus width %d instead %d bit\n",
3087 (chip->options & NAND_BUSWIDTH_16) ? 16 : 8, 3104 (chip->options & NAND_BUSWIDTH_16) ? 16 : 8,
3088 busw ? 16 : 8); 3105 busw ? 16 : 8);
3089 return ERR_PTR(-EINVAL); 3106 return ERR_PTR(-EINVAL);
3090 } 3107 }
3091 3108
3092 /* Calculate the address shift from the page size */ 3109 /* Calculate the address shift from the page size */
3093 chip->page_shift = ffs(mtd->writesize) - 1; 3110 chip->page_shift = ffs(mtd->writesize) - 1;
3094 /* Convert chipsize to number of pages per chip -1. */ 3111 /* Convert chipsize to number of pages per chip -1 */
3095 chip->pagemask = (chip->chipsize >> chip->page_shift) - 1; 3112 chip->pagemask = (chip->chipsize >> chip->page_shift) - 1;
3096 3113
3097 chip->bbt_erase_shift = chip->phys_erase_shift = 3114 chip->bbt_erase_shift = chip->phys_erase_shift =
@@ -3121,7 +3138,7 @@ ident_done:
3121 if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) && 3138 if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
3122 (*maf_id == NAND_MFR_SAMSUNG || 3139 (*maf_id == NAND_MFR_SAMSUNG ||
3123 *maf_id == NAND_MFR_HYNIX)) 3140 *maf_id == NAND_MFR_HYNIX))
3124 chip->options |= NAND_BBT_SCANLASTPAGE; 3141 chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
3125 else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) && 3142 else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
3126 (*maf_id == NAND_MFR_SAMSUNG || 3143 (*maf_id == NAND_MFR_SAMSUNG ||
3127 *maf_id == NAND_MFR_HYNIX || 3144 *maf_id == NAND_MFR_HYNIX ||
@@ -3129,17 +3146,7 @@ ident_done:
3129 *maf_id == NAND_MFR_AMD)) || 3146 *maf_id == NAND_MFR_AMD)) ||
3130 (mtd->writesize == 2048 && 3147 (mtd->writesize == 2048 &&
3131 *maf_id == NAND_MFR_MICRON)) 3148 *maf_id == NAND_MFR_MICRON))
3132 chip->options |= NAND_BBT_SCAN2NDPAGE; 3149 chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
3133
3134 /*
3135 * Numonyx/ST 2K pages, x8 bus use BOTH byte 1 and 6
3136 */
3137 if (!(busw & NAND_BUSWIDTH_16) &&
3138 *maf_id == NAND_MFR_STMICRO &&
3139 mtd->writesize == 2048) {
3140 chip->options |= NAND_BBT_SCANBYTE1AND6;
3141 chip->badblockpos = 0;
3142 }
3143 3150
3144 /* Check for AND chips with 4 page planes */ 3151 /* Check for AND chips with 4 page planes */
3145 if (chip->options & NAND_4PAGE_ARRAY) 3152 if (chip->options & NAND_4PAGE_ARRAY)
@@ -3147,12 +3154,11 @@ ident_done:
3147 else 3154 else
3148 chip->erase_cmd = single_erase_cmd; 3155 chip->erase_cmd = single_erase_cmd;
3149 3156
3150 /* Do not replace user supplied command function ! */ 3157 /* Do not replace user supplied command function! */
3151 if (mtd->writesize > 512 && chip->cmdfunc == nand_command) 3158 if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
3152 chip->cmdfunc = nand_command_lp; 3159 chip->cmdfunc = nand_command_lp;
3153 3160
3154 /* TODO onfi flash name */ 3161 pr_info("NAND device: Manufacturer ID:"
3155 printk(KERN_INFO "NAND device: Manufacturer ID:"
3156 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, *dev_id, 3162 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, *dev_id,
3157 nand_manuf_ids[maf_idx].name, 3163 nand_manuf_ids[maf_idx].name,
3158 chip->onfi_version ? chip->onfi_params.model : type->name); 3164 chip->onfi_version ? chip->onfi_params.model : type->name);
@@ -3162,12 +3168,12 @@ ident_done:
3162 3168
3163/** 3169/**
3164 * nand_scan_ident - [NAND Interface] Scan for the NAND device 3170 * nand_scan_ident - [NAND Interface] Scan for the NAND device
3165 * @mtd: MTD device structure 3171 * @mtd: MTD device structure
3166 * @maxchips: Number of chips to scan for 3172 * @maxchips: number of chips to scan for
3167 * @table: Alternative NAND ID table 3173 * @table: alternative NAND ID table
3168 * 3174 *
3169 * This is the first phase of the normal nand_scan() function. It 3175 * This is the first phase of the normal nand_scan() function. It reads the
3170 * reads the flash ID and sets up MTD fields accordingly. 3176 * flash ID and sets up MTD fields accordingly.
3171 * 3177 *
3172 * The mtd->owner field must be set to the module of the caller. 3178 * The mtd->owner field must be set to the module of the caller.
3173 */ 3179 */
@@ -3189,7 +3195,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
3189 3195
3190 if (IS_ERR(type)) { 3196 if (IS_ERR(type)) {
3191 if (!(chip->options & NAND_SCAN_SILENT_NODEV)) 3197 if (!(chip->options & NAND_SCAN_SILENT_NODEV))
3192 printk(KERN_WARNING "No NAND device found.\n"); 3198 pr_warn("No NAND device found\n");
3193 chip->select_chip(mtd, -1); 3199 chip->select_chip(mtd, -1);
3194 return PTR_ERR(type); 3200 return PTR_ERR(type);
3195 } 3201 }
@@ -3207,7 +3213,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
3207 break; 3213 break;
3208 } 3214 }
3209 if (i > 1) 3215 if (i > 1)
3210 printk(KERN_INFO "%d NAND chips detected\n", i); 3216 pr_info("%d NAND chips detected\n", i);
3211 3217
3212 /* Store the number of chips and calc total size for mtd */ 3218 /* Store the number of chips and calc total size for mtd */
3213 chip->numchips = i; 3219 chip->numchips = i;
@@ -3220,11 +3226,11 @@ EXPORT_SYMBOL(nand_scan_ident);
3220 3226
3221/** 3227/**
3222 * nand_scan_tail - [NAND Interface] Scan for the NAND device 3228 * nand_scan_tail - [NAND Interface] Scan for the NAND device
3223 * @mtd: MTD device structure 3229 * @mtd: MTD device structure
3224 * 3230 *
3225 * This is the second phase of the normal nand_scan() function. It 3231 * This is the second phase of the normal nand_scan() function. It fills out
3226 * fills out all the uninitialized function pointers with the defaults 3232 * all the uninitialized function pointers with the defaults and scans for a
3227 * and scans for a bad block table if appropriate. 3233 * bad block table if appropriate.
3228 */ 3234 */
3229int nand_scan_tail(struct mtd_info *mtd) 3235int nand_scan_tail(struct mtd_info *mtd)
3230{ 3236{
@@ -3240,7 +3246,7 @@ int nand_scan_tail(struct mtd_info *mtd)
3240 chip->oob_poi = chip->buffers->databuf + mtd->writesize; 3246 chip->oob_poi = chip->buffers->databuf + mtd->writesize;
3241 3247
3242 /* 3248 /*
3243 * If no default placement scheme is given, select an appropriate one 3249 * If no default placement scheme is given, select an appropriate one.
3244 */ 3250 */
3245 if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) { 3251 if (!chip->ecc.layout && (chip->ecc.mode != NAND_ECC_SOFT_BCH)) {
3246 switch (mtd->oobsize) { 3252 switch (mtd->oobsize) {
@@ -3257,8 +3263,8 @@ int nand_scan_tail(struct mtd_info *mtd)
3257 chip->ecc.layout = &nand_oob_128; 3263 chip->ecc.layout = &nand_oob_128;
3258 break; 3264 break;
3259 default: 3265 default:
3260 printk(KERN_WARNING "No oob scheme defined for " 3266 pr_warn("No oob scheme defined for oobsize %d\n",
3261 "oobsize %d\n", mtd->oobsize); 3267 mtd->oobsize);
3262 BUG(); 3268 BUG();
3263 } 3269 }
3264 } 3270 }
@@ -3267,7 +3273,7 @@ int nand_scan_tail(struct mtd_info *mtd)
3267 chip->write_page = nand_write_page; 3273 chip->write_page = nand_write_page;
3268 3274
3269 /* 3275 /*
3270 * check ECC mode, default to software if 3byte/512byte hardware ECC is 3276 * Check ECC mode, default to software if 3byte/512byte hardware ECC is
3271 * selected and we have 256 byte pagesize fallback to software ECC 3277 * selected and we have 256 byte pagesize fallback to software ECC
3272 */ 3278 */
3273 3279
@@ -3276,15 +3282,15 @@ int nand_scan_tail(struct mtd_info *mtd)
3276 /* Similar to NAND_ECC_HW, but a separate read_page handle */ 3282 /* Similar to NAND_ECC_HW, but a separate read_page handle */
3277 if (!chip->ecc.calculate || !chip->ecc.correct || 3283 if (!chip->ecc.calculate || !chip->ecc.correct ||
3278 !chip->ecc.hwctl) { 3284 !chip->ecc.hwctl) {
3279 printk(KERN_WARNING "No ECC functions supplied; " 3285 pr_warn("No ECC functions supplied; "
3280 "Hardware ECC not possible\n"); 3286 "hardware ECC not possible\n");
3281 BUG(); 3287 BUG();
3282 } 3288 }
3283 if (!chip->ecc.read_page) 3289 if (!chip->ecc.read_page)
3284 chip->ecc.read_page = nand_read_page_hwecc_oob_first; 3290 chip->ecc.read_page = nand_read_page_hwecc_oob_first;
3285 3291
3286 case NAND_ECC_HW: 3292 case NAND_ECC_HW:
3287 /* Use standard hwecc read page function ? */ 3293 /* Use standard hwecc read page function? */
3288 if (!chip->ecc.read_page) 3294 if (!chip->ecc.read_page)
3289 chip->ecc.read_page = nand_read_page_hwecc; 3295 chip->ecc.read_page = nand_read_page_hwecc;
3290 if (!chip->ecc.write_page) 3296 if (!chip->ecc.write_page)
@@ -3305,11 +3311,11 @@ int nand_scan_tail(struct mtd_info *mtd)
3305 chip->ecc.read_page == nand_read_page_hwecc || 3311 chip->ecc.read_page == nand_read_page_hwecc ||
3306 !chip->ecc.write_page || 3312 !chip->ecc.write_page ||
3307 chip->ecc.write_page == nand_write_page_hwecc)) { 3313 chip->ecc.write_page == nand_write_page_hwecc)) {
3308 printk(KERN_WARNING "No ECC functions supplied; " 3314 pr_warn("No ECC functions supplied; "
3309 "Hardware ECC not possible\n"); 3315 "hardware ECC not possible\n");
3310 BUG(); 3316 BUG();
3311 } 3317 }
3312 /* Use standard syndrome read/write page function ? */ 3318 /* Use standard syndrome read/write page function? */
3313 if (!chip->ecc.read_page) 3319 if (!chip->ecc.read_page)
3314 chip->ecc.read_page = nand_read_page_syndrome; 3320 chip->ecc.read_page = nand_read_page_syndrome;
3315 if (!chip->ecc.write_page) 3321 if (!chip->ecc.write_page)
@@ -3325,9 +3331,9 @@ int nand_scan_tail(struct mtd_info *mtd)
3325 3331
3326 if (mtd->writesize >= chip->ecc.size) 3332 if (mtd->writesize >= chip->ecc.size)
3327 break; 3333 break;
3328 printk(KERN_WARNING "%d byte HW ECC not possible on " 3334 pr_warn("%d byte HW ECC not possible on "
3329 "%d byte page size, fallback to SW ECC\n", 3335 "%d byte page size, fallback to SW ECC\n",
3330 chip->ecc.size, mtd->writesize); 3336 chip->ecc.size, mtd->writesize);
3331 chip->ecc.mode = NAND_ECC_SOFT; 3337 chip->ecc.mode = NAND_ECC_SOFT;
3332 3338
3333 case NAND_ECC_SOFT: 3339 case NAND_ECC_SOFT:
@@ -3347,7 +3353,7 @@ int nand_scan_tail(struct mtd_info *mtd)
3347 3353
3348 case NAND_ECC_SOFT_BCH: 3354 case NAND_ECC_SOFT_BCH:
3349 if (!mtd_nand_has_bch()) { 3355 if (!mtd_nand_has_bch()) {
3350 printk(KERN_WARNING "CONFIG_MTD_ECC_BCH not enabled\n"); 3356 pr_warn("CONFIG_MTD_ECC_BCH not enabled\n");
3351 BUG(); 3357 BUG();
3352 } 3358 }
3353 chip->ecc.calculate = nand_bch_calculate_ecc; 3359 chip->ecc.calculate = nand_bch_calculate_ecc;
@@ -3362,8 +3368,8 @@ int nand_scan_tail(struct mtd_info *mtd)
3362 /* 3368 /*
3363 * Board driver should supply ecc.size and ecc.bytes values to 3369 * Board driver should supply ecc.size and ecc.bytes values to
3364 * select how many bits are correctable; see nand_bch_init() 3370 * select how many bits are correctable; see nand_bch_init()
3365 * for details. 3371 * for details. Otherwise, default to 4 bits for large page
3366 * Otherwise, default to 4 bits for large page devices 3372 * devices.
3367 */ 3373 */
3368 if (!chip->ecc.size && (mtd->oobsize >= 64)) { 3374 if (!chip->ecc.size && (mtd->oobsize >= 64)) {
3369 chip->ecc.size = 512; 3375 chip->ecc.size = 512;
@@ -3374,14 +3380,14 @@ int nand_scan_tail(struct mtd_info *mtd)
3374 chip->ecc.bytes, 3380 chip->ecc.bytes,
3375 &chip->ecc.layout); 3381 &chip->ecc.layout);
3376 if (!chip->ecc.priv) { 3382 if (!chip->ecc.priv) {
3377 printk(KERN_WARNING "BCH ECC initialization failed!\n"); 3383 pr_warn("BCH ECC initialization failed!\n");
3378 BUG(); 3384 BUG();
3379 } 3385 }
3380 break; 3386 break;
3381 3387
3382 case NAND_ECC_NONE: 3388 case NAND_ECC_NONE:
3383 printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. " 3389 pr_warn("NAND_ECC_NONE selected by board driver. "
3384 "This is not recommended !!\n"); 3390 "This is not recommended!\n");
3385 chip->ecc.read_page = nand_read_page_raw; 3391 chip->ecc.read_page = nand_read_page_raw;
3386 chip->ecc.write_page = nand_write_page_raw; 3392 chip->ecc.write_page = nand_write_page_raw;
3387 chip->ecc.read_oob = nand_read_oob_std; 3393 chip->ecc.read_oob = nand_read_oob_std;
@@ -3393,14 +3399,19 @@ int nand_scan_tail(struct mtd_info *mtd)
3393 break; 3399 break;
3394 3400
3395 default: 3401 default:
3396 printk(KERN_WARNING "Invalid NAND_ECC_MODE %d\n", 3402 pr_warn("Invalid NAND_ECC_MODE %d\n", chip->ecc.mode);
3397 chip->ecc.mode);
3398 BUG(); 3403 BUG();
3399 } 3404 }
3400 3405
3406 /* For many systems, the standard OOB write also works for raw */
3407 if (!chip->ecc.read_oob_raw)
3408 chip->ecc.read_oob_raw = chip->ecc.read_oob;
3409 if (!chip->ecc.write_oob_raw)
3410 chip->ecc.write_oob_raw = chip->ecc.write_oob;
3411
3401 /* 3412 /*
3402 * The number of bytes available for a client to place data into 3413 * The number of bytes available for a client to place data into
3403 * the out of band area 3414 * the out of band area.
3404 */ 3415 */
3405 chip->ecc.layout->oobavail = 0; 3416 chip->ecc.layout->oobavail = 0;
3406 for (i = 0; chip->ecc.layout->oobfree[i].length 3417 for (i = 0; chip->ecc.layout->oobfree[i].length
@@ -3411,19 +3422,16 @@ int nand_scan_tail(struct mtd_info *mtd)
3411 3422
3412 /* 3423 /*
3413 * Set the number of read / write steps for one page depending on ECC 3424 * Set the number of read / write steps for one page depending on ECC
3414 * mode 3425 * mode.
3415 */ 3426 */
3416 chip->ecc.steps = mtd->writesize / chip->ecc.size; 3427 chip->ecc.steps = mtd->writesize / chip->ecc.size;
3417 if (chip->ecc.steps * chip->ecc.size != mtd->writesize) { 3428 if (chip->ecc.steps * chip->ecc.size != mtd->writesize) {
3418 printk(KERN_WARNING "Invalid ecc parameters\n"); 3429 pr_warn("Invalid ECC parameters\n");
3419 BUG(); 3430 BUG();
3420 } 3431 }
3421 chip->ecc.total = chip->ecc.steps * chip->ecc.bytes; 3432 chip->ecc.total = chip->ecc.steps * chip->ecc.bytes;
3422 3433
3423 /* 3434 /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
3424 * Allow subpage writes up to ecc.steps. Not possible for MLC
3425 * FLASH.
3426 */
3427 if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && 3435 if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
3428 !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) { 3436 !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
3429 switch (chip->ecc.steps) { 3437 switch (chip->ecc.steps) {
@@ -3481,9 +3489,11 @@ int nand_scan_tail(struct mtd_info *mtd)
3481} 3489}
3482EXPORT_SYMBOL(nand_scan_tail); 3490EXPORT_SYMBOL(nand_scan_tail);
3483 3491
3484/* is_module_text_address() isn't exported, and it's mostly a pointless 3492/*
3493 * is_module_text_address() isn't exported, and it's mostly a pointless
3485 * test if this is a module _anyway_ -- they'd have to try _really_ hard 3494 * test if this is a module _anyway_ -- they'd have to try _really_ hard
3486 * to call us from in-kernel code if the core NAND support is modular. */ 3495 * to call us from in-kernel code if the core NAND support is modular.
3496 */
3487#ifdef MODULE 3497#ifdef MODULE
3488#define caller_is_module() (1) 3498#define caller_is_module() (1)
3489#else 3499#else
@@ -3493,15 +3503,13 @@ EXPORT_SYMBOL(nand_scan_tail);
3493 3503
3494/** 3504/**
3495 * nand_scan - [NAND Interface] Scan for the NAND device 3505 * nand_scan - [NAND Interface] Scan for the NAND device
3496 * @mtd: MTD device structure 3506 * @mtd: MTD device structure
3497 * @maxchips: Number of chips to scan for 3507 * @maxchips: number of chips to scan for
3498 *
3499 * This fills out all the uninitialized function pointers
3500 * with the defaults.
3501 * The flash ID is read and the mtd/chip structures are
3502 * filled with the appropriate values.
3503 * The mtd->owner field must be set to the module of the caller
3504 * 3508 *
3509 * This fills out all the uninitialized function pointers with the defaults.
3510 * The flash ID is read and the mtd/chip structures are filled with the
3511 * appropriate values. The mtd->owner field must be set to the module of the
3512 * caller.
3505 */ 3513 */
3506int nand_scan(struct mtd_info *mtd, int maxchips) 3514int nand_scan(struct mtd_info *mtd, int maxchips)
3507{ 3515{
@@ -3509,8 +3517,7 @@ int nand_scan(struct mtd_info *mtd, int maxchips)
3509 3517
3510 /* Many callers got this wrong, so check for it for a while... */ 3518 /* Many callers got this wrong, so check for it for a while... */
3511 if (!mtd->owner && caller_is_module()) { 3519 if (!mtd->owner && caller_is_module()) {
3512 printk(KERN_CRIT "%s called with NULL mtd->owner!\n", 3520 pr_crit("%s called with NULL mtd->owner!\n", __func__);
3513 __func__);
3514 BUG(); 3521 BUG();
3515 } 3522 }
3516 3523
@@ -3523,8 +3530,8 @@ EXPORT_SYMBOL(nand_scan);
3523 3530
3524/** 3531/**
3525 * nand_release - [NAND Interface] Free resources held by the NAND device 3532 * nand_release - [NAND Interface] Free resources held by the NAND device
3526 * @mtd: MTD device structure 3533 * @mtd: MTD device structure
3527*/ 3534 */
3528void nand_release(struct mtd_info *mtd) 3535void nand_release(struct mtd_info *mtd)
3529{ 3536{
3530 struct nand_chip *chip = mtd->priv; 3537 struct nand_chip *chip = mtd->priv;
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index ccbeaa1e4a8..69148ae3bf5 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -14,7 +14,7 @@
14 * 14 *
15 * When nand_scan_bbt is called, then it tries to find the bad block table 15 * When nand_scan_bbt is called, then it tries to find the bad block table
16 * depending on the options in the BBT descriptor(s). If no flash based BBT 16 * depending on the options in the BBT descriptor(s). If no flash based BBT
17 * (NAND_USE_FLASH_BBT) is specified then the device is scanned for factory 17 * (NAND_BBT_USE_FLASH) is specified then the device is scanned for factory
18 * marked good / bad blocks. This information is used to create a memory BBT. 18 * marked good / bad blocks. This information is used to create a memory BBT.
19 * Once a new bad block is discovered then the "factory" information is updated 19 * Once a new bad block is discovered then the "factory" information is updated
20 * on the device. 20 * on the device.
@@ -36,9 +36,9 @@
36 * The table is marked in the OOB area with an ident pattern and a version 36 * The table is marked in the OOB area with an ident pattern and a version
37 * number which indicates which of both tables is more up to date. If the NAND 37 * number which indicates which of both tables is more up to date. If the NAND
38 * controller needs the complete OOB area for the ECC information then the 38 * controller needs the complete OOB area for the ECC information then the
39 * option NAND_USE_FLASH_BBT_NO_OOB should be used: it moves the ident pattern 39 * option NAND_BBT_NO_OOB should be used (along with NAND_BBT_USE_FLASH, of
40 * and the version byte into the data area and the OOB area will remain 40 * course): it moves the ident pattern and the version byte into the data area
41 * untouched. 41 * and the OOB area will remain untouched.
42 * 42 *
43 * The table uses 2 bits per block 43 * The table uses 2 bits per block
44 * 11b: block is good 44 * 11b: block is good
@@ -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{
@@ -80,17 +81,15 @@ static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td)
80 81
81/** 82/**
82 * check_pattern - [GENERIC] check if a pattern is in the buffer 83 * check_pattern - [GENERIC] check if a pattern is in the buffer
83 * @buf: the buffer to search 84 * @buf: the buffer to search
84 * @len: the length of buffer to search 85 * @len: the length of buffer to search
85 * @paglen: the pagelength 86 * @paglen: the pagelength
86 * @td: search pattern descriptor 87 * @td: search pattern descriptor
87 * 88 *
88 * Check for a pattern at the given place. Used to search bad block 89 * Check for a pattern at the given place. Used to search bad block tables and
89 * tables and good / bad block identifiers. 90 * good / bad block identifiers. If the SCAN_EMPTY option is set then check, if
90 * If the SCAN_EMPTY option is set then check, if all bytes except the 91 * all bytes except the pattern area contain 0xff.
91 * pattern area contain 0xff 92 */
92 *
93*/
94static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) 93static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
95{ 94{
96 int i, end = 0; 95 int i, end = 0;
@@ -109,32 +108,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
109 p += end; 108 p += end;
110 109
111 /* Compare the pattern */ 110 /* Compare the pattern */
112 for (i = 0; i < td->len; i++) { 111 if (memcmp(p, td->pattern, td->len))
113 if (p[i] != td->pattern[i]) 112 return -1;
114 return -1;
115 }
116
117 /* Check both positions 1 and 6 for pattern? */
118 if (td->options & NAND_BBT_SCANBYTE1AND6) {
119 if (td->options & NAND_BBT_SCANEMPTY) {
120 p += td->len;
121 end += NAND_SMALL_BADBLOCK_POS - td->offs;
122 /* Check region between positions 1 and 6 */
123 for (i = 0; i < NAND_SMALL_BADBLOCK_POS - td->offs - td->len;
124 i++) {
125 if (*p++ != 0xff)
126 return -1;
127 }
128 }
129 else {
130 p += NAND_SMALL_BADBLOCK_POS - td->offs;
131 }
132 /* Compare the pattern */
133 for (i = 0; i < td->len; i++) {
134 if (p[i] != td->pattern[i])
135 return -1;
136 }
137 }
138 113
139 if (td->options & NAND_BBT_SCANEMPTY) { 114 if (td->options & NAND_BBT_SCANEMPTY) {
140 p += td->len; 115 p += td->len;
@@ -149,14 +124,13 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
149 124
150/** 125/**
151 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 126 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
152 * @buf: the buffer to search 127 * @buf: the buffer to search
153 * @td: search pattern descriptor 128 * @td: search pattern descriptor
154 *
155 * Check for a pattern at the given place. Used to search bad block
156 * tables and good / bad block identifiers. Same as check_pattern, but
157 * no optional empty check
158 * 129 *
159*/ 130 * Check for a pattern at the given place. Used to search bad block tables and
131 * good / bad block identifiers. Same as check_pattern, but no optional empty
132 * check.
133 */
160static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td) 134static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
161{ 135{
162 int i; 136 int i;
@@ -167,21 +141,14 @@ static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
167 if (p[td->offs + i] != td->pattern[i]) 141 if (p[td->offs + i] != td->pattern[i])
168 return -1; 142 return -1;
169 } 143 }
170 /* Need to check location 1 AND 6? */
171 if (td->options & NAND_BBT_SCANBYTE1AND6) {
172 for (i = 0; i < td->len; i++) {
173 if (p[NAND_SMALL_BADBLOCK_POS + i] != td->pattern[i])
174 return -1;
175 }
176 }
177 return 0; 144 return 0;
178} 145}
179 146
180/** 147/**
181 * add_marker_len - compute the length of the marker in data area 148 * add_marker_len - compute the length of the marker in data area
182 * @td: BBT descriptor used for computation 149 * @td: BBT descriptor used for computation
183 * 150 *
184 * The length will be 0 if the markeris located in OOB area. 151 * The length will be 0 if the marker is located in OOB area.
185 */ 152 */
186static u32 add_marker_len(struct nand_bbt_descr *td) 153static u32 add_marker_len(struct nand_bbt_descr *td)
187{ 154{
@@ -198,34 +165,33 @@ static u32 add_marker_len(struct nand_bbt_descr *td)
198 165
199/** 166/**
200 * read_bbt - [GENERIC] Read the bad block table starting from page 167 * read_bbt - [GENERIC] Read the bad block table starting from page
201 * @mtd: MTD device structure 168 * @mtd: MTD device structure
202 * @buf: temporary buffer 169 * @buf: temporary buffer
203 * @page: the starting page 170 * @page: the starting page
204 * @num: the number of bbt descriptors to read 171 * @num: the number of bbt descriptors to read
205 * @td: the bbt describtion table 172 * @td: the bbt describtion table
206 * @offs: offset in the memory table 173 * @offs: offset in the memory table
207 * 174 *
208 * Read the bad block table starting from page. 175 * Read the bad block table starting from page.
209 *
210 */ 176 */
211static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, 177static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
212 struct nand_bbt_descr *td, int offs) 178 struct nand_bbt_descr *td, int offs)
213{ 179{
214 int res, i, j, act = 0; 180 int res, ret = 0, i, j, act = 0;
215 struct nand_chip *this = mtd->priv; 181 struct nand_chip *this = mtd->priv;
216 size_t retlen, len, totlen; 182 size_t retlen, len, totlen;
217 loff_t from; 183 loff_t from;
218 int bits = td->options & NAND_BBT_NRBITS_MSK; 184 int bits = td->options & NAND_BBT_NRBITS_MSK;
219 uint8_t msk = (uint8_t) ((1 << bits) - 1); 185 uint8_t msk = (uint8_t)((1 << bits) - 1);
220 u32 marker_len; 186 u32 marker_len;
221 int reserved_block_code = td->reserved_block_code; 187 int reserved_block_code = td->reserved_block_code;
222 188
223 totlen = (num * bits) >> 3; 189 totlen = (num * bits) >> 3;
224 marker_len = add_marker_len(td); 190 marker_len = add_marker_len(td);
225 from = ((loff_t) page) << this->page_shift; 191 from = ((loff_t)page) << this->page_shift;
226 192
227 while (totlen) { 193 while (totlen) {
228 len = min(totlen, (size_t) (1 << this->bbt_erase_shift)); 194 len = min(totlen, (size_t)(1 << this->bbt_erase_shift));
229 if (marker_len) { 195 if (marker_len) {
230 /* 196 /*
231 * In case the BBT marker is not in the OOB area it 197 * In case the BBT marker is not in the OOB area it
@@ -237,11 +203,18 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
237 } 203 }
238 res = mtd->read(mtd, from, len, &retlen, buf); 204 res = mtd->read(mtd, from, len, &retlen, buf);
239 if (res < 0) { 205 if (res < 0) {
240 if (retlen != len) { 206 if (mtd_is_eccerr(res)) {
241 printk(KERN_INFO "nand_bbt: Error reading bad block table\n"); 207 pr_info("nand_bbt: ECC error in BBT at "
208 "0x%012llx\n", from & ~mtd->writesize);
209 return res;
210 } else if (mtd_is_bitflip(res)) {
211 pr_info("nand_bbt: corrected error in BBT at "
212 "0x%012llx\n", from & ~mtd->writesize);
213 ret = res;
214 } else {
215 pr_info("nand_bbt: error reading BBT\n");
242 return res; 216 return res;
243 } 217 }
244 printk(KERN_WARNING "nand_bbt: ECC error while reading bad block table\n");
245 } 218 }
246 219
247 /* Analyse data */ 220 /* Analyse data */
@@ -252,17 +225,19 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
252 if (tmp == msk) 225 if (tmp == msk)
253 continue; 226 continue;
254 if (reserved_block_code && (tmp == reserved_block_code)) { 227 if (reserved_block_code && (tmp == reserved_block_code)) {
255 printk(KERN_DEBUG "nand_read_bbt: Reserved block at 0x%012llx\n", 228 pr_info("nand_read_bbt: reserved block at 0x%012llx\n",
256 (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift); 229 (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
257 this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06); 230 this->bbt[offs + (act >> 3)] |= 0x2 << (act & 0x06);
258 mtd->ecc_stats.bbtblocks++; 231 mtd->ecc_stats.bbtblocks++;
259 continue; 232 continue;
260 } 233 }
261 /* Leave it for now, if its matured we can move this 234 /*
262 * message to MTD_DEBUG_LEVEL0 */ 235 * Leave it for now, if it's matured we can
263 printk(KERN_DEBUG "nand_read_bbt: Bad block at 0x%012llx\n", 236 * move this message to pr_debug.
264 (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift); 237 */
265 /* Factory marked bad or worn out ? */ 238 pr_info("nand_read_bbt: bad block at 0x%012llx\n",
239 (loff_t)((offs << 2) + (act >> 1)) << this->bbt_erase_shift);
240 /* Factory marked bad or worn out? */
266 if (tmp == 0) 241 if (tmp == 0)
267 this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06); 242 this->bbt[offs + (act >> 3)] |= 0x3 << (act & 0x06);
268 else 243 else
@@ -273,20 +248,20 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
273 totlen -= len; 248 totlen -= len;
274 from += len; 249 from += len;
275 } 250 }
276 return 0; 251 return ret;
277} 252}
278 253
279/** 254/**
280 * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page 255 * read_abs_bbt - [GENERIC] Read the bad block table starting at a given page
281 * @mtd: MTD device structure 256 * @mtd: MTD device structure
282 * @buf: temporary buffer 257 * @buf: temporary buffer
283 * @td: descriptor for the bad block table 258 * @td: descriptor for the bad block table
284 * @chip: read the table for a specific chip, -1 read all chips. 259 * @chip: read the table for a specific chip, -1 read all chips; applies only if
285 * Applies only if NAND_BBT_PERCHIP option is set 260 * NAND_BBT_PERCHIP option is set
286 * 261 *
287 * Read the bad block table for all chips starting at a given page 262 * Read the bad block table for all chips starting at a given page. We assume
288 * We assume that the bbt bits are in consecutive order. 263 * that the bbt bits are in consecutive order.
289*/ 264 */
290static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip) 265static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
291{ 266{
292 struct nand_chip *this = mtd->priv; 267 struct nand_chip *this = mtd->priv;
@@ -312,9 +287,7 @@ static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
312 return 0; 287 return 0;
313} 288}
314 289
315/* 290/* BBT marker is in the first page, no OOB */
316 * BBT marker is in the first page, no OOB.
317 */
318static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs, 291static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
319 struct nand_bbt_descr *td) 292 struct nand_bbt_descr *td)
320{ 293{
@@ -328,35 +301,26 @@ static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
328 return mtd->read(mtd, offs, len, &retlen, buf); 301 return mtd->read(mtd, offs, len, &retlen, buf);
329} 302}
330 303
331/* 304/* Scan read raw data from flash */
332 * Scan read raw data from flash
333 */
334static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs, 305static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
335 size_t len) 306 size_t len)
336{ 307{
337 struct mtd_oob_ops ops; 308 struct mtd_oob_ops ops;
338 int res; 309 int res;
339 310
340 ops.mode = MTD_OOB_RAW; 311 ops.mode = MTD_OPS_RAW;
341 ops.ooboffs = 0; 312 ops.ooboffs = 0;
342 ops.ooblen = mtd->oobsize; 313 ops.ooblen = mtd->oobsize;
343 314
344
345 while (len > 0) { 315 while (len > 0) {
346 if (len <= mtd->writesize) { 316 ops.datbuf = buf;
347 ops.oobbuf = buf + len; 317 ops.len = min(len, (size_t)mtd->writesize);
348 ops.datbuf = buf; 318 ops.oobbuf = buf + ops.len;
349 ops.len = len;
350 return mtd->read_oob(mtd, offs, &ops);
351 } else {
352 ops.oobbuf = buf + mtd->writesize;
353 ops.datbuf = buf;
354 ops.len = mtd->writesize;
355 res = mtd->read_oob(mtd, offs, &ops);
356 319
357 if (res) 320 res = mtd->read_oob(mtd, offs, &ops);
358 return res; 321
359 } 322 if (res)
323 return res;
360 324
361 buf += mtd->oobsize + mtd->writesize; 325 buf += mtd->oobsize + mtd->writesize;
362 len -= mtd->writesize; 326 len -= mtd->writesize;
@@ -373,15 +337,13 @@ static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
373 return scan_read_raw_oob(mtd, buf, offs, len); 337 return scan_read_raw_oob(mtd, buf, offs, len);
374} 338}
375 339
376/* 340/* Scan write data with oob to flash */
377 * Scan write data with oob to flash
378 */
379static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len, 341static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len,
380 uint8_t *buf, uint8_t *oob) 342 uint8_t *buf, uint8_t *oob)
381{ 343{
382 struct mtd_oob_ops ops; 344 struct mtd_oob_ops ops;
383 345
384 ops.mode = MTD_OOB_PLACE; 346 ops.mode = MTD_OPS_PLACE_OOB;
385 ops.ooboffs = 0; 347 ops.ooboffs = 0;
386 ops.ooblen = mtd->oobsize; 348 ops.ooblen = mtd->oobsize;
387 ops.datbuf = buf; 349 ops.datbuf = buf;
@@ -402,15 +364,14 @@ static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td)
402 364
403/** 365/**
404 * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page 366 * read_abs_bbts - [GENERIC] Read the bad block table(s) for all chips starting at a given page
405 * @mtd: MTD device structure 367 * @mtd: MTD device structure
406 * @buf: temporary buffer 368 * @buf: temporary buffer
407 * @td: descriptor for the bad block table 369 * @td: descriptor for the bad block table
408 * @md: descriptor for the bad block table mirror 370 * @md: descriptor for the bad block table mirror
409 * 371 *
410 * Read the bad block table(s) for all chips starting at a given page 372 * Read the bad block table(s) for all chips starting at a given page. We
411 * We assume that the bbt bits are in consecutive order. 373 * assume that the bbt bits are in consecutive order.
412 * 374 */
413*/
414static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf, 375static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
415 struct nand_bbt_descr *td, struct nand_bbt_descr *md) 376 struct nand_bbt_descr *td, struct nand_bbt_descr *md)
416{ 377{
@@ -421,8 +382,8 @@ static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
421 scan_read_raw(mtd, buf, (loff_t)td->pages[0] << this->page_shift, 382 scan_read_raw(mtd, buf, (loff_t)td->pages[0] << this->page_shift,
422 mtd->writesize, td); 383 mtd->writesize, td);
423 td->version[0] = buf[bbt_get_ver_offs(mtd, td)]; 384 td->version[0] = buf[bbt_get_ver_offs(mtd, td)];
424 printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", 385 pr_info("Bad block table at page %d, version 0x%02X\n",
425 td->pages[0], td->version[0]); 386 td->pages[0], td->version[0]);
426 } 387 }
427 388
428 /* Read the mirror version, if available */ 389 /* Read the mirror version, if available */
@@ -430,15 +391,13 @@ static int read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
430 scan_read_raw(mtd, buf, (loff_t)md->pages[0] << this->page_shift, 391 scan_read_raw(mtd, buf, (loff_t)md->pages[0] << this->page_shift,
431 mtd->writesize, td); 392 mtd->writesize, td);
432 md->version[0] = buf[bbt_get_ver_offs(mtd, md)]; 393 md->version[0] = buf[bbt_get_ver_offs(mtd, md)];
433 printk(KERN_DEBUG "Bad block table at page %d, version 0x%02X\n", 394 pr_info("Bad block table at page %d, version 0x%02X\n",
434 md->pages[0], md->version[0]); 395 md->pages[0], md->version[0]);
435 } 396 }
436 return 1; 397 return 1;
437} 398}
438 399
439/* 400/* Scan a given block full */
440 * Scan a given block full
441 */
442static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd, 401static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd,
443 loff_t offs, uint8_t *buf, size_t readlen, 402 loff_t offs, uint8_t *buf, size_t readlen,
444 int scanlen, int len) 403 int scanlen, int len)
@@ -446,7 +405,8 @@ static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd,
446 int ret, j; 405 int ret, j;
447 406
448 ret = scan_read_raw_oob(mtd, buf, offs, readlen); 407 ret = scan_read_raw_oob(mtd, buf, offs, readlen);
449 if (ret) 408 /* Ignore ECC errors when checking for BBM */
409 if (ret && !mtd_is_bitflip_or_eccerr(ret))
450 return ret; 410 return ret;
451 411
452 for (j = 0; j < len; j++, buf += scanlen) { 412 for (j = 0; j < len; j++, buf += scanlen) {
@@ -456,9 +416,7 @@ static int scan_block_full(struct mtd_info *mtd, struct nand_bbt_descr *bd,
456 return 0; 416 return 0;
457} 417}
458 418
459/* 419/* Scan a given block partially */
460 * Scan a given block partially
461 */
462static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, 420static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
463 loff_t offs, uint8_t *buf, int len) 421 loff_t offs, uint8_t *buf, int len)
464{ 422{
@@ -469,16 +427,16 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
469 ops.oobbuf = buf; 427 ops.oobbuf = buf;
470 ops.ooboffs = 0; 428 ops.ooboffs = 0;
471 ops.datbuf = NULL; 429 ops.datbuf = NULL;
472 ops.mode = MTD_OOB_PLACE; 430 ops.mode = MTD_OPS_PLACE_OOB;
473 431
474 for (j = 0; j < len; j++) { 432 for (j = 0; j < len; j++) {
475 /* 433 /*
476 * Read the full oob until read_oob is fixed to 434 * Read the full oob until read_oob is fixed to handle single
477 * handle single byte reads for 16 bit 435 * byte reads for 16 bit buswidth.
478 * buswidth
479 */ 436 */
480 ret = mtd->read_oob(mtd, offs, &ops); 437 ret = mtd->read_oob(mtd, offs, &ops);
481 if (ret) 438 /* Ignore ECC errors when checking for BBM */
439 if (ret && !mtd_is_bitflip_or_eccerr(ret))
482 return ret; 440 return ret;
483 441
484 if (check_short_pattern(buf, bd)) 442 if (check_short_pattern(buf, bd))
@@ -491,14 +449,14 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
491 449
492/** 450/**
493 * create_bbt - [GENERIC] Create a bad block table by scanning the device 451 * create_bbt - [GENERIC] Create a bad block table by scanning the device
494 * @mtd: MTD device structure 452 * @mtd: MTD device structure
495 * @buf: temporary buffer 453 * @buf: temporary buffer
496 * @bd: descriptor for the good/bad block search pattern 454 * @bd: descriptor for the good/bad block search pattern
497 * @chip: create the table for a specific chip, -1 read all chips. 455 * @chip: create the table for a specific chip, -1 read all chips; applies only
498 * Applies only if NAND_BBT_PERCHIP option is set 456 * if NAND_BBT_PERCHIP option is set
499 * 457 *
500 * Create a bad block table by scanning the device 458 * Create a bad block table by scanning the device for the given good/bad block
501 * for the given good/bad block identify pattern 459 * identify pattern.
502 */ 460 */
503static int create_bbt(struct mtd_info *mtd, uint8_t *buf, 461static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
504 struct nand_bbt_descr *bd, int chip) 462 struct nand_bbt_descr *bd, int chip)
@@ -509,7 +467,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
509 loff_t from; 467 loff_t from;
510 size_t readlen; 468 size_t readlen;
511 469
512 printk(KERN_INFO "Scanning device for bad blocks\n"); 470 pr_info("Scanning device for bad blocks\n");
513 471
514 if (bd->options & NAND_BBT_SCANALLPAGES) 472 if (bd->options & NAND_BBT_SCANALLPAGES)
515 len = 1 << (this->bbt_erase_shift - this->page_shift); 473 len = 1 << (this->bbt_erase_shift - this->page_shift);
@@ -529,14 +487,16 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
529 } 487 }
530 488
531 if (chip == -1) { 489 if (chip == -1) {
532 /* Note that numblocks is 2 * (real numblocks) here, see i+=2 490 /*
533 * below as it makes shifting and masking less painful */ 491 * Note that numblocks is 2 * (real numblocks) here, see i+=2
492 * below as it makes shifting and masking less painful
493 */
534 numblocks = mtd->size >> (this->bbt_erase_shift - 1); 494 numblocks = mtd->size >> (this->bbt_erase_shift - 1);
535 startblock = 0; 495 startblock = 0;
536 from = 0; 496 from = 0;
537 } else { 497 } else {
538 if (chip >= this->numchips) { 498 if (chip >= this->numchips) {
539 printk(KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n", 499 pr_warn("create_bbt(): chipnr (%d) > available chips (%d)\n",
540 chip + 1, this->numchips); 500 chip + 1, this->numchips);
541 return -EINVAL; 501 return -EINVAL;
542 } 502 }
@@ -546,7 +506,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
546 from = (loff_t)startblock << (this->bbt_erase_shift - 1); 506 from = (loff_t)startblock << (this->bbt_erase_shift - 1);
547 } 507 }
548 508
549 if (this->options & NAND_BBT_SCANLASTPAGE) 509 if (this->bbt_options & NAND_BBT_SCANLASTPAGE)
550 from += mtd->erasesize - (mtd->writesize * len); 510 from += mtd->erasesize - (mtd->writesize * len);
551 511
552 for (i = startblock; i < numblocks;) { 512 for (i = startblock; i < numblocks;) {
@@ -565,8 +525,8 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
565 525
566 if (ret) { 526 if (ret) {
567 this->bbt[i >> 3] |= 0x03 << (i & 0x6); 527 this->bbt[i >> 3] |= 0x03 << (i & 0x6);
568 printk(KERN_WARNING "Bad eraseblock %d at 0x%012llx\n", 528 pr_warn("Bad eraseblock %d at 0x%012llx\n",
569 i >> 1, (unsigned long long)from); 529 i >> 1, (unsigned long long)from);
570 mtd->ecc_stats.badblocks++; 530 mtd->ecc_stats.badblocks++;
571 } 531 }
572 532
@@ -578,20 +538,18 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
578 538
579/** 539/**
580 * search_bbt - [GENERIC] scan the device for a specific bad block table 540 * search_bbt - [GENERIC] scan the device for a specific bad block table
581 * @mtd: MTD device structure 541 * @mtd: MTD device structure
582 * @buf: temporary buffer 542 * @buf: temporary buffer
583 * @td: descriptor for the bad block table 543 * @td: descriptor for the bad block table
584 * 544 *
585 * Read the bad block table by searching for a given ident pattern. 545 * Read the bad block table by searching for a given ident pattern. Search is
586 * Search is preformed either from the beginning up or from the end of 546 * preformed either from the beginning up or from the end of the device
587 * the device downwards. The search starts always at the start of a 547 * downwards. The search starts always at the start of a block. If the option
588 * block. 548 * NAND_BBT_PERCHIP is given, each chip is searched for a bbt, which contains
589 * If the option NAND_BBT_PERCHIP is given, each chip is searched 549 * the bad block information of this chip. This is necessary to provide support
590 * for a bbt, which contains the bad block information of this chip. 550 * for certain DOC devices.
591 * This is necessary to provide support for certain DOC devices.
592 * 551 *
593 * The bbt ident pattern resides in the oob area of the first page 552 * The bbt ident pattern resides in the oob area of the first page in a block.
594 * in a block.
595 */ 553 */
596static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td) 554static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
597{ 555{
@@ -602,7 +560,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
602 int bbtblocks; 560 int bbtblocks;
603 int blocktopage = this->bbt_erase_shift - this->page_shift; 561 int blocktopage = this->bbt_erase_shift - this->page_shift;
604 562
605 /* Search direction top -> down ? */ 563 /* Search direction top -> down? */
606 if (td->options & NAND_BBT_LASTBLOCK) { 564 if (td->options & NAND_BBT_LASTBLOCK) {
607 startblock = (mtd->size >> this->bbt_erase_shift) - 1; 565 startblock = (mtd->size >> this->bbt_erase_shift) - 1;
608 dir = -1; 566 dir = -1;
@@ -611,7 +569,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
611 dir = 1; 569 dir = 1;
612 } 570 }
613 571
614 /* Do we have a bbt per chip ? */ 572 /* Do we have a bbt per chip? */
615 if (td->options & NAND_BBT_PERCHIP) { 573 if (td->options & NAND_BBT_PERCHIP) {
616 chips = this->numchips; 574 chips = this->numchips;
617 bbtblocks = this->chipsize >> this->bbt_erase_shift; 575 bbtblocks = this->chipsize >> this->bbt_erase_shift;
@@ -650,23 +608,23 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
650 /* Check, if we found a bbt for each requested chip */ 608 /* Check, if we found a bbt for each requested chip */
651 for (i = 0; i < chips; i++) { 609 for (i = 0; i < chips; i++) {
652 if (td->pages[i] == -1) 610 if (td->pages[i] == -1)
653 printk(KERN_WARNING "Bad block table not found for chip %d\n", i); 611 pr_warn("Bad block table not found for chip %d\n", i);
654 else 612 else
655 printk(KERN_DEBUG "Bad block table found at page %d, version 0x%02X\n", td->pages[i], 613 pr_info("Bad block table found at page %d, version "
656 td->version[i]); 614 "0x%02X\n", td->pages[i], td->version[i]);
657 } 615 }
658 return 0; 616 return 0;
659} 617}
660 618
661/** 619/**
662 * search_read_bbts - [GENERIC] scan the device for bad block table(s) 620 * search_read_bbts - [GENERIC] scan the device for bad block table(s)
663 * @mtd: MTD device structure 621 * @mtd: MTD device structure
664 * @buf: temporary buffer 622 * @buf: temporary buffer
665 * @td: descriptor for the bad block table 623 * @td: descriptor for the bad block table
666 * @md: descriptor for the bad block table mirror 624 * @md: descriptor for the bad block table mirror
667 * 625 *
668 * Search and read the bad block table(s) 626 * Search and read the bad block table(s).
669*/ 627 */
670static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md) 628static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt_descr *td, struct nand_bbt_descr *md)
671{ 629{
672 /* Search the primary table */ 630 /* Search the primary table */
@@ -682,16 +640,14 @@ static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt
682 640
683/** 641/**
684 * write_bbt - [GENERIC] (Re)write the bad block table 642 * write_bbt - [GENERIC] (Re)write the bad block table
643 * @mtd: MTD device structure
644 * @buf: temporary buffer
645 * @td: descriptor for the bad block table
646 * @md: descriptor for the bad block table mirror
647 * @chipsel: selector for a specific chip, -1 for all
685 * 648 *
686 * @mtd: MTD device structure 649 * (Re)write the bad block table.
687 * @buf: temporary buffer 650 */
688 * @td: descriptor for the bad block table
689 * @md: descriptor for the bad block table mirror
690 * @chipsel: selector for a specific chip, -1 for all
691 *
692 * (Re)write the bad block table
693 *
694*/
695static int write_bbt(struct mtd_info *mtd, uint8_t *buf, 651static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
696 struct nand_bbt_descr *td, struct nand_bbt_descr *md, 652 struct nand_bbt_descr *td, struct nand_bbt_descr *md,
697 int chipsel) 653 int chipsel)
@@ -710,14 +666,14 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
710 ops.ooblen = mtd->oobsize; 666 ops.ooblen = mtd->oobsize;
711 ops.ooboffs = 0; 667 ops.ooboffs = 0;
712 ops.datbuf = NULL; 668 ops.datbuf = NULL;
713 ops.mode = MTD_OOB_PLACE; 669 ops.mode = MTD_OPS_PLACE_OOB;
714 670
715 if (!rcode) 671 if (!rcode)
716 rcode = 0xff; 672 rcode = 0xff;
717 /* Write bad block table per chip rather than per device ? */ 673 /* Write bad block table per chip rather than per device? */
718 if (td->options & NAND_BBT_PERCHIP) { 674 if (td->options & NAND_BBT_PERCHIP) {
719 numblocks = (int)(this->chipsize >> this->bbt_erase_shift); 675 numblocks = (int)(this->chipsize >> this->bbt_erase_shift);
720 /* Full device write or specific chip ? */ 676 /* Full device write or specific chip? */
721 if (chipsel == -1) { 677 if (chipsel == -1) {
722 nrchips = this->numchips; 678 nrchips = this->numchips;
723 } else { 679 } else {
@@ -731,8 +687,8 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
731 687
732 /* Loop through the chips */ 688 /* Loop through the chips */
733 for (; chip < nrchips; chip++) { 689 for (; chip < nrchips; chip++) {
734 690 /*
735 /* There was already a version of the table, reuse the page 691 * There was already a version of the table, reuse the page
736 * This applies for absolute placement too, as we have the 692 * This applies for absolute placement too, as we have the
737 * page nr. in td->pages. 693 * page nr. in td->pages.
738 */ 694 */
@@ -741,8 +697,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
741 goto write; 697 goto write;
742 } 698 }
743 699
744 /* Automatic placement of the bad block table */ 700 /*
745 /* Search direction top -> down ? */ 701 * Automatic placement of the bad block table. Search direction
702 * top -> down?
703 */
746 if (td->options & NAND_BBT_LASTBLOCK) { 704 if (td->options & NAND_BBT_LASTBLOCK) {
747 startblock = numblocks * (chip + 1) - 1; 705 startblock = numblocks * (chip + 1) - 1;
748 dir = -1; 706 dir = -1;
@@ -766,7 +724,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
766 if (!md || md->pages[chip] != page) 724 if (!md || md->pages[chip] != page)
767 goto write; 725 goto write;
768 } 726 }
769 printk(KERN_ERR "No space left to write bad block table\n"); 727 pr_err("No space left to write bad block table\n");
770 return -ENOSPC; 728 return -ENOSPC;
771 write: 729 write:
772 730
@@ -791,24 +749,22 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
791 749
792 bbtoffs = chip * (numblocks >> 2); 750 bbtoffs = chip * (numblocks >> 2);
793 751
794 to = ((loff_t) page) << this->page_shift; 752 to = ((loff_t)page) << this->page_shift;
795 753
796 /* Must we save the block contents ? */ 754 /* Must we save the block contents? */
797 if (td->options & NAND_BBT_SAVECONTENT) { 755 if (td->options & NAND_BBT_SAVECONTENT) {
798 /* Make it block aligned */ 756 /* Make it block aligned */
799 to &= ~((loff_t) ((1 << this->bbt_erase_shift) - 1)); 757 to &= ~((loff_t)((1 << this->bbt_erase_shift) - 1));
800 len = 1 << this->bbt_erase_shift; 758 len = 1 << this->bbt_erase_shift;
801 res = mtd->read(mtd, to, len, &retlen, buf); 759 res = mtd->read(mtd, to, len, &retlen, buf);
802 if (res < 0) { 760 if (res < 0) {
803 if (retlen != len) { 761 if (retlen != len) {
804 printk(KERN_INFO "nand_bbt: Error " 762 pr_info("nand_bbt: error reading block "
805 "reading block for writing " 763 "for writing the bad block table\n");
806 "the bad block table\n");
807 return res; 764 return res;
808 } 765 }
809 printk(KERN_WARNING "nand_bbt: ECC error " 766 pr_warn("nand_bbt: ECC error while reading "
810 "while reading block for writing " 767 "block for writing bad block table\n");
811 "bad block table\n");
812 } 768 }
813 /* Read oob data */ 769 /* Read oob data */
814 ops.ooblen = (len >> this->page_shift) * mtd->oobsize; 770 ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
@@ -821,19 +777,19 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
821 pageoffs = page - (int)(to >> this->page_shift); 777 pageoffs = page - (int)(to >> this->page_shift);
822 offs = pageoffs << this->page_shift; 778 offs = pageoffs << this->page_shift;
823 /* Preset the bbt area with 0xff */ 779 /* Preset the bbt area with 0xff */
824 memset(&buf[offs], 0xff, (size_t) (numblocks >> sft)); 780 memset(&buf[offs], 0xff, (size_t)(numblocks >> sft));
825 ooboffs = len + (pageoffs * mtd->oobsize); 781 ooboffs = len + (pageoffs * mtd->oobsize);
826 782
827 } else if (td->options & NAND_BBT_NO_OOB) { 783 } else if (td->options & NAND_BBT_NO_OOB) {
828 ooboffs = 0; 784 ooboffs = 0;
829 offs = td->len; 785 offs = td->len;
830 /* the version byte */ 786 /* The version byte */
831 if (td->options & NAND_BBT_VERSION) 787 if (td->options & NAND_BBT_VERSION)
832 offs++; 788 offs++;
833 /* Calc length */ 789 /* Calc length */
834 len = (size_t) (numblocks >> sft); 790 len = (size_t)(numblocks >> sft);
835 len += offs; 791 len += offs;
836 /* Make it page aligned ! */ 792 /* Make it page aligned! */
837 len = ALIGN(len, mtd->writesize); 793 len = ALIGN(len, mtd->writesize);
838 /* Preset the buffer with 0xff */ 794 /* Preset the buffer with 0xff */
839 memset(buf, 0xff, len); 795 memset(buf, 0xff, len);
@@ -841,8 +797,8 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
841 memcpy(buf, td->pattern, td->len); 797 memcpy(buf, td->pattern, td->len);
842 } else { 798 } else {
843 /* Calc length */ 799 /* Calc length */
844 len = (size_t) (numblocks >> sft); 800 len = (size_t)(numblocks >> sft);
845 /* Make it page aligned ! */ 801 /* Make it page aligned! */
846 len = ALIGN(len, mtd->writesize); 802 len = ALIGN(len, mtd->writesize);
847 /* Preset the buffer with 0xff */ 803 /* Preset the buffer with 0xff */
848 memset(buf, 0xff, len + 804 memset(buf, 0xff, len +
@@ -856,13 +812,13 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
856 if (td->options & NAND_BBT_VERSION) 812 if (td->options & NAND_BBT_VERSION)
857 buf[ooboffs + td->veroffs] = td->version[chip]; 813 buf[ooboffs + td->veroffs] = td->version[chip];
858 814
859 /* walk through the memory table */ 815 /* Walk through the memory table */
860 for (i = 0; i < numblocks;) { 816 for (i = 0; i < numblocks;) {
861 uint8_t dat; 817 uint8_t dat;
862 dat = this->bbt[bbtoffs + (i >> 2)]; 818 dat = this->bbt[bbtoffs + (i >> 2)];
863 for (j = 0; j < 4; j++, i++) { 819 for (j = 0; j < 4; j++, i++) {
864 int sftcnt = (i << (3 - sft)) & sftmsk; 820 int sftcnt = (i << (3 - sft)) & sftmsk;
865 /* Do not store the reserved bbt blocks ! */ 821 /* Do not store the reserved bbt blocks! */
866 buf[offs + (i >> sft)] &= 822 buf[offs + (i >> sft)] &=
867 ~(msk[dat & 0x03] << sftcnt); 823 ~(msk[dat & 0x03] << sftcnt);
868 dat >>= 2; 824 dat >>= 2;
@@ -883,8 +839,8 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
883 if (res < 0) 839 if (res < 0)
884 goto outerr; 840 goto outerr;
885 841
886 printk(KERN_DEBUG "Bad block table written to 0x%012llx, version " 842 pr_info("Bad block table written to 0x%012llx, version 0x%02X\n",
887 "0x%02X\n", (unsigned long long)to, td->version[chip]); 843 (unsigned long long)to, td->version[chip]);
888 844
889 /* Mark it as used */ 845 /* Mark it as used */
890 td->pages[chip] = page; 846 td->pages[chip] = page;
@@ -892,19 +848,18 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
892 return 0; 848 return 0;
893 849
894 outerr: 850 outerr:
895 printk(KERN_WARNING 851 pr_warn("nand_bbt: error while writing bad block table %d\n", res);
896 "nand_bbt: Error while writing bad block table %d\n", res);
897 return res; 852 return res;
898} 853}
899 854
900/** 855/**
901 * nand_memory_bbt - [GENERIC] create a memory based bad block table 856 * nand_memory_bbt - [GENERIC] create a memory based bad block table
902 * @mtd: MTD device structure 857 * @mtd: MTD device structure
903 * @bd: descriptor for the good/bad block search pattern 858 * @bd: descriptor for the good/bad block search pattern
904 * 859 *
905 * The function creates a memory based bbt by scanning the device 860 * The function creates a memory based bbt by scanning the device for
906 * for manufacturer / software marked good / bad blocks 861 * manufacturer / software marked good / bad blocks.
907*/ 862 */
908static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 863static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
909{ 864{
910 struct nand_chip *this = mtd->priv; 865 struct nand_chip *this = mtd->priv;
@@ -915,25 +870,24 @@ static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *b
915 870
916/** 871/**
917 * check_create - [GENERIC] create and write bbt(s) if necessary 872 * check_create - [GENERIC] create and write bbt(s) if necessary
918 * @mtd: MTD device structure 873 * @mtd: MTD device structure
919 * @buf: temporary buffer 874 * @buf: temporary buffer
920 * @bd: descriptor for the good/bad block search pattern 875 * @bd: descriptor for the good/bad block search pattern
921 * 876 *
922 * The function checks the results of the previous call to read_bbt 877 * The function checks the results of the previous call to read_bbt and creates
923 * and creates / updates the bbt(s) if necessary 878 * / updates the bbt(s) if necessary. Creation is necessary if no bbt was found
924 * Creation is necessary if no bbt was found for the chip/device 879 * for the chip/device. Update is necessary if one of the tables is missing or
925 * Update is necessary if one of the tables is missing or the 880 * the version nr. of one table is less than the other.
926 * version nr. of one table is less than the other 881 */
927*/
928static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd) 882static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
929{ 883{
930 int i, chips, writeops, chipsel, res; 884 int i, chips, writeops, create, chipsel, res, res2;
931 struct nand_chip *this = mtd->priv; 885 struct nand_chip *this = mtd->priv;
932 struct nand_bbt_descr *td = this->bbt_td; 886 struct nand_bbt_descr *td = this->bbt_td;
933 struct nand_bbt_descr *md = this->bbt_md; 887 struct nand_bbt_descr *md = this->bbt_md;
934 struct nand_bbt_descr *rd, *rd2; 888 struct nand_bbt_descr *rd, *rd2;
935 889
936 /* Do we have a bbt per chip ? */ 890 /* Do we have a bbt per chip? */
937 if (td->options & NAND_BBT_PERCHIP) 891 if (td->options & NAND_BBT_PERCHIP)
938 chips = this->numchips; 892 chips = this->numchips;
939 else 893 else
@@ -941,86 +895,98 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
941 895
942 for (i = 0; i < chips; i++) { 896 for (i = 0; i < chips; i++) {
943 writeops = 0; 897 writeops = 0;
898 create = 0;
944 rd = NULL; 899 rd = NULL;
945 rd2 = NULL; 900 rd2 = NULL;
946 /* Per chip or per device ? */ 901 res = res2 = 0;
902 /* Per chip or per device? */
947 chipsel = (td->options & NAND_BBT_PERCHIP) ? i : -1; 903 chipsel = (td->options & NAND_BBT_PERCHIP) ? i : -1;
948 /* Mirrored table available ? */ 904 /* Mirrored table available? */
949 if (md) { 905 if (md) {
950 if (td->pages[i] == -1 && md->pages[i] == -1) { 906 if (td->pages[i] == -1 && md->pages[i] == -1) {
907 create = 1;
951 writeops = 0x03; 908 writeops = 0x03;
952 goto create; 909 } else if (td->pages[i] == -1) {
953 }
954
955 if (td->pages[i] == -1) {
956 rd = md; 910 rd = md;
957 td->version[i] = md->version[i]; 911 writeops = 0x01;
958 writeops = 1; 912 } else if (md->pages[i] == -1) {
959 goto writecheck;
960 }
961
962 if (md->pages[i] == -1) {
963 rd = td; 913 rd = td;
964 md->version[i] = td->version[i]; 914 writeops = 0x02;
965 writeops = 2; 915 } else if (td->version[i] == md->version[i]) {
966 goto writecheck;
967 }
968
969 if (td->version[i] == md->version[i]) {
970 rd = td; 916 rd = td;
971 if (!(td->options & NAND_BBT_VERSION)) 917 if (!(td->options & NAND_BBT_VERSION))
972 rd2 = md; 918 rd2 = md;
973 goto writecheck; 919 } else if (((int8_t)(td->version[i] - md->version[i])) > 0) {
974 }
975
976 if (((int8_t) (td->version[i] - md->version[i])) > 0) {
977 rd = td; 920 rd = td;
978 md->version[i] = td->version[i]; 921 writeops = 0x02;
979 writeops = 2;
980 } else { 922 } else {
981 rd = md; 923 rd = md;
982 td->version[i] = md->version[i]; 924 writeops = 0x01;
983 writeops = 1;
984 } 925 }
985
986 goto writecheck;
987
988 } else { 926 } else {
989 if (td->pages[i] == -1) { 927 if (td->pages[i] == -1) {
928 create = 1;
990 writeops = 0x01; 929 writeops = 0x01;
991 goto create; 930 } else {
931 rd = td;
992 } 932 }
993 rd = td;
994 goto writecheck;
995 } 933 }
996 create:
997 /* Create the bad block table by scanning the device ? */
998 if (!(td->options & NAND_BBT_CREATE))
999 continue;
1000 934
1001 /* Create the table in memory by scanning the chip(s) */ 935 if (create) {
1002 if (!(this->options & NAND_CREATE_EMPTY_BBT)) 936 /* Create the bad block table by scanning the device? */
1003 create_bbt(mtd, buf, bd, chipsel); 937 if (!(td->options & NAND_BBT_CREATE))
1004 938 continue;
1005 td->version[i] = 1; 939
1006 if (md) 940 /* Create the table in memory by scanning the chip(s) */
1007 md->version[i] = 1; 941 if (!(this->bbt_options & NAND_BBT_CREATE_EMPTY))
1008 writecheck: 942 create_bbt(mtd, buf, bd, chipsel);
1009 /* read back first ? */ 943
1010 if (rd) 944 td->version[i] = 1;
1011 read_abs_bbt(mtd, buf, rd, chipsel); 945 if (md)
1012 /* If they weren't versioned, read both. */ 946 md->version[i] = 1;
1013 if (rd2) 947 }
1014 read_abs_bbt(mtd, buf, rd2, chipsel); 948
1015 949 /* Read back first? */
1016 /* Write the bad block table to the device ? */ 950 if (rd) {
951 res = read_abs_bbt(mtd, buf, rd, chipsel);
952 if (mtd_is_eccerr(res)) {
953 /* Mark table as invalid */
954 rd->pages[i] = -1;
955 rd->version[i] = 0;
956 i--;
957 continue;
958 }
959 }
960 /* If they weren't versioned, read both */
961 if (rd2) {
962 res2 = read_abs_bbt(mtd, buf, rd2, chipsel);
963 if (mtd_is_eccerr(res2)) {
964 /* Mark table as invalid */
965 rd2->pages[i] = -1;
966 rd2->version[i] = 0;
967 i--;
968 continue;
969 }
970 }
971
972 /* Scrub the flash table(s)? */
973 if (mtd_is_bitflip(res) || mtd_is_bitflip(res2))
974 writeops = 0x03;
975
976 /* Update version numbers before writing */
977 if (md) {
978 td->version[i] = max(td->version[i], md->version[i]);
979 md->version[i] = td->version[i];
980 }
981
982 /* Write the bad block table to the device? */
1017 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { 983 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
1018 res = write_bbt(mtd, buf, td, md, chipsel); 984 res = write_bbt(mtd, buf, td, md, chipsel);
1019 if (res < 0) 985 if (res < 0)
1020 return res; 986 return res;
1021 } 987 }
1022 988
1023 /* Write the mirror bad block table to the device ? */ 989 /* Write the mirror bad block table to the device? */
1024 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { 990 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) {
1025 res = write_bbt(mtd, buf, md, td, chipsel); 991 res = write_bbt(mtd, buf, md, td, chipsel);
1026 if (res < 0) 992 if (res < 0)
@@ -1032,20 +998,19 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
1032 998
1033/** 999/**
1034 * mark_bbt_regions - [GENERIC] mark the bad block table regions 1000 * mark_bbt_regions - [GENERIC] mark the bad block table regions
1035 * @mtd: MTD device structure 1001 * @mtd: MTD device structure
1036 * @td: bad block table descriptor 1002 * @td: bad block table descriptor
1037 * 1003 *
1038 * The bad block table regions are marked as "bad" to prevent 1004 * The bad block table regions are marked as "bad" to prevent accidental
1039 * accidental erasures / writes. The regions are identified by 1005 * erasures / writes. The regions are identified by the mark 0x02.
1040 * the mark 0x02. 1006 */
1041*/
1042static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td) 1007static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
1043{ 1008{
1044 struct nand_chip *this = mtd->priv; 1009 struct nand_chip *this = mtd->priv;
1045 int i, j, chips, block, nrblocks, update; 1010 int i, j, chips, block, nrblocks, update;
1046 uint8_t oldval, newval; 1011 uint8_t oldval, newval;
1047 1012
1048 /* Do we have a bbt per chip ? */ 1013 /* Do we have a bbt per chip? */
1049 if (td->options & NAND_BBT_PERCHIP) { 1014 if (td->options & NAND_BBT_PERCHIP) {
1050 chips = this->numchips; 1015 chips = this->numchips;
1051 nrblocks = (int)(this->chipsize >> this->bbt_erase_shift); 1016 nrblocks = (int)(this->chipsize >> this->bbt_erase_shift);
@@ -1082,9 +1047,11 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
1082 update = 1; 1047 update = 1;
1083 block += 2; 1048 block += 2;
1084 } 1049 }
1085 /* If we want reserved blocks to be recorded to flash, and some 1050 /*
1086 new ones have been marked, then we need to update the stored 1051 * If we want reserved blocks to be recorded to flash, and some
1087 bbts. This should only happen once. */ 1052 * new ones have been marked, then we need to update the stored
1053 * bbts. This should only happen once.
1054 */
1088 if (update && td->reserved_block_code) 1055 if (update && td->reserved_block_code)
1089 nand_update_bbt(mtd, (loff_t)(block - 2) << (this->bbt_erase_shift - 1)); 1056 nand_update_bbt(mtd, (loff_t)(block - 2) << (this->bbt_erase_shift - 1));
1090 } 1057 }
@@ -1092,8 +1059,8 @@ static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
1092 1059
1093/** 1060/**
1094 * verify_bbt_descr - verify the bad block description 1061 * verify_bbt_descr - verify the bad block description
1095 * @mtd: MTD device structure 1062 * @mtd: MTD device structure
1096 * @bd: the table to verify 1063 * @bd: the table to verify
1097 * 1064 *
1098 * This functions performs a few sanity checks on the bad block description 1065 * This functions performs a few sanity checks on the bad block description
1099 * table. 1066 * table.
@@ -1111,16 +1078,16 @@ static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1111 pattern_len = bd->len; 1078 pattern_len = bd->len;
1112 bits = bd->options & NAND_BBT_NRBITS_MSK; 1079 bits = bd->options & NAND_BBT_NRBITS_MSK;
1113 1080
1114 BUG_ON((this->options & NAND_USE_FLASH_BBT_NO_OOB) && 1081 BUG_ON((this->bbt_options & NAND_BBT_NO_OOB) &&
1115 !(this->options & NAND_USE_FLASH_BBT)); 1082 !(this->bbt_options & NAND_BBT_USE_FLASH));
1116 BUG_ON(!bits); 1083 BUG_ON(!bits);
1117 1084
1118 if (bd->options & NAND_BBT_VERSION) 1085 if (bd->options & NAND_BBT_VERSION)
1119 pattern_len++; 1086 pattern_len++;
1120 1087
1121 if (bd->options & NAND_BBT_NO_OOB) { 1088 if (bd->options & NAND_BBT_NO_OOB) {
1122 BUG_ON(!(this->options & NAND_USE_FLASH_BBT)); 1089 BUG_ON(!(this->bbt_options & NAND_BBT_USE_FLASH));
1123 BUG_ON(!(this->options & NAND_USE_FLASH_BBT_NO_OOB)); 1090 BUG_ON(!(this->bbt_options & NAND_BBT_NO_OOB));
1124 BUG_ON(bd->offs); 1091 BUG_ON(bd->offs);
1125 if (bd->options & NAND_BBT_VERSION) 1092 if (bd->options & NAND_BBT_VERSION)
1126 BUG_ON(bd->veroffs != bd->len); 1093 BUG_ON(bd->veroffs != bd->len);
@@ -1140,18 +1107,16 @@ static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1140 1107
1141/** 1108/**
1142 * nand_scan_bbt - [NAND Interface] scan, find, read and maybe create bad block table(s) 1109 * nand_scan_bbt - [NAND Interface] scan, find, read and maybe create bad block table(s)
1143 * @mtd: MTD device structure 1110 * @mtd: MTD device structure
1144 * @bd: descriptor for the good/bad block search pattern 1111 * @bd: descriptor for the good/bad block search pattern
1145 *
1146 * The function checks, if a bad block table(s) is/are already
1147 * available. If not it scans the device for manufacturer
1148 * marked good / bad blocks and writes the bad block table(s) to
1149 * the selected place.
1150 * 1112 *
1151 * The bad block table memory is allocated here. It must be freed 1113 * The function checks, if a bad block table(s) is/are already available. If
1152 * by calling the nand_free_bbt function. 1114 * not it scans the device for manufacturer marked good / bad blocks and writes
1115 * the bad block table(s) to the selected place.
1153 * 1116 *
1154*/ 1117 * The bad block table memory is allocated here. It must be freed by calling
1118 * the nand_free_bbt function.
1119 */
1155int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 1120int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1156{ 1121{
1157 struct nand_chip *this = mtd->priv; 1122 struct nand_chip *this = mtd->priv;
@@ -1161,19 +1126,21 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1161 struct nand_bbt_descr *md = this->bbt_md; 1126 struct nand_bbt_descr *md = this->bbt_md;
1162 1127
1163 len = mtd->size >> (this->bbt_erase_shift + 2); 1128 len = mtd->size >> (this->bbt_erase_shift + 2);
1164 /* Allocate memory (2bit per block) and clear the memory bad block table */ 1129 /*
1130 * Allocate memory (2bit per block) and clear the memory bad block
1131 * table.
1132 */
1165 this->bbt = kzalloc(len, GFP_KERNEL); 1133 this->bbt = kzalloc(len, GFP_KERNEL);
1166 if (!this->bbt) { 1134 if (!this->bbt)
1167 printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
1168 return -ENOMEM; 1135 return -ENOMEM;
1169 }
1170 1136
1171 /* If no primary table decriptor is given, scan the device 1137 /*
1172 * to build a memory based bad block table 1138 * If no primary table decriptor is given, scan the device to build a
1139 * memory based bad block table.
1173 */ 1140 */
1174 if (!td) { 1141 if (!td) {
1175 if ((res = nand_memory_bbt(mtd, bd))) { 1142 if ((res = nand_memory_bbt(mtd, bd))) {
1176 printk(KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n"); 1143 pr_err("nand_bbt: can't scan flash and build the RAM-based BBT\n");
1177 kfree(this->bbt); 1144 kfree(this->bbt);
1178 this->bbt = NULL; 1145 this->bbt = NULL;
1179 } 1146 }
@@ -1187,13 +1154,12 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1187 len += (len >> this->page_shift) * mtd->oobsize; 1154 len += (len >> this->page_shift) * mtd->oobsize;
1188 buf = vmalloc(len); 1155 buf = vmalloc(len);
1189 if (!buf) { 1156 if (!buf) {
1190 printk(KERN_ERR "nand_bbt: Out of memory\n");
1191 kfree(this->bbt); 1157 kfree(this->bbt);
1192 this->bbt = NULL; 1158 this->bbt = NULL;
1193 return -ENOMEM; 1159 return -ENOMEM;
1194 } 1160 }
1195 1161
1196 /* Is the bbt at a given page ? */ 1162 /* Is the bbt at a given page? */
1197 if (td->options & NAND_BBT_ABSPAGE) { 1163 if (td->options & NAND_BBT_ABSPAGE) {
1198 res = read_abs_bbts(mtd, buf, td, md); 1164 res = read_abs_bbts(mtd, buf, td, md);
1199 } else { 1165 } else {
@@ -1215,15 +1181,15 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
1215 1181
1216/** 1182/**
1217 * nand_update_bbt - [NAND Interface] update bad block table(s) 1183 * nand_update_bbt - [NAND Interface] update bad block table(s)
1218 * @mtd: MTD device structure 1184 * @mtd: MTD device structure
1219 * @offs: the offset of the newly marked block 1185 * @offs: the offset of the newly marked block
1220 * 1186 *
1221 * The function updates the bad block table(s) 1187 * The function updates the bad block table(s).
1222*/ 1188 */
1223int nand_update_bbt(struct mtd_info *mtd, loff_t offs) 1189int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1224{ 1190{
1225 struct nand_chip *this = mtd->priv; 1191 struct nand_chip *this = mtd->priv;
1226 int len, res = 0, writeops = 0; 1192 int len, res = 0;
1227 int chip, chipsel; 1193 int chip, chipsel;
1228 uint8_t *buf; 1194 uint8_t *buf;
1229 struct nand_bbt_descr *td = this->bbt_td; 1195 struct nand_bbt_descr *td = this->bbt_td;
@@ -1236,14 +1202,10 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1236 len = (1 << this->bbt_erase_shift); 1202 len = (1 << this->bbt_erase_shift);
1237 len += (len >> this->page_shift) * mtd->oobsize; 1203 len += (len >> this->page_shift) * mtd->oobsize;
1238 buf = kmalloc(len, GFP_KERNEL); 1204 buf = kmalloc(len, GFP_KERNEL);
1239 if (!buf) { 1205 if (!buf)
1240 printk(KERN_ERR "nand_update_bbt: Out of memory\n");
1241 return -ENOMEM; 1206 return -ENOMEM;
1242 }
1243
1244 writeops = md != NULL ? 0x03 : 0x01;
1245 1207
1246 /* Do we have a bbt per chip ? */ 1208 /* Do we have a bbt per chip? */
1247 if (td->options & NAND_BBT_PERCHIP) { 1209 if (td->options & NAND_BBT_PERCHIP) {
1248 chip = (int)(offs >> this->chip_shift); 1210 chip = (int)(offs >> this->chip_shift);
1249 chipsel = chip; 1211 chipsel = chip;
@@ -1256,14 +1218,14 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1256 if (md) 1218 if (md)
1257 md->version[chip]++; 1219 md->version[chip]++;
1258 1220
1259 /* Write the bad block table to the device ? */ 1221 /* Write the bad block table to the device? */
1260 if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) { 1222 if (td->options & NAND_BBT_WRITE) {
1261 res = write_bbt(mtd, buf, td, md, chipsel); 1223 res = write_bbt(mtd, buf, td, md, chipsel);
1262 if (res < 0) 1224 if (res < 0)
1263 goto out; 1225 goto out;
1264 } 1226 }
1265 /* Write the mirror bad block table to the device ? */ 1227 /* Write the mirror bad block table to the device? */
1266 if ((writeops & 0x02) && md && (md->options & NAND_BBT_WRITE)) { 1228 if (md && (md->options & NAND_BBT_WRITE)) {
1267 res = write_bbt(mtd, buf, md, td, chipsel); 1229 res = write_bbt(mtd, buf, md, td, chipsel);
1268 } 1230 }
1269 1231
@@ -1272,8 +1234,10 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1272 return res; 1234 return res;
1273} 1235}
1274 1236
1275/* Define some generic bad / good block scan pattern which are used 1237/*
1276 * while scanning a device for factory marked good / bad blocks. */ 1238 * Define some generic bad / good block scan pattern which are used
1239 * while scanning a device for factory marked good / bad blocks.
1240 */
1277static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 1241static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
1278 1242
1279static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 }; 1243static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 };
@@ -1285,8 +1249,7 @@ static struct nand_bbt_descr agand_flashbased = {
1285 .pattern = scan_agand_pattern 1249 .pattern = scan_agand_pattern
1286}; 1250};
1287 1251
1288/* Generic flash bbt decriptors 1252/* Generic flash bbt descriptors */
1289*/
1290static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; 1253static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
1291static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; 1254static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' };
1292 1255
@@ -1330,31 +1293,27 @@ static struct nand_bbt_descr bbt_mirror_no_bbt_descr = {
1330 .pattern = mirror_pattern 1293 .pattern = mirror_pattern
1331}; 1294};
1332 1295
1333#define BBT_SCAN_OPTIONS (NAND_BBT_SCANLASTPAGE | NAND_BBT_SCAN2NDPAGE | \ 1296#define BADBLOCK_SCAN_MASK (~NAND_BBT_NO_OOB)
1334 NAND_BBT_SCANBYTE1AND6)
1335/** 1297/**
1336 * nand_create_default_bbt_descr - [Internal] Creates a BBT descriptor structure 1298 * nand_create_badblock_pattern - [INTERN] Creates a BBT descriptor structure
1337 * @this: NAND chip to create descriptor for 1299 * @this: NAND chip to create descriptor for
1338 * 1300 *
1339 * This function allocates and initializes a nand_bbt_descr for BBM detection 1301 * This function allocates and initializes a nand_bbt_descr for BBM detection
1340 * based on the properties of "this". The new descriptor is stored in 1302 * based on the properties of @this. The new descriptor is stored in
1341 * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when 1303 * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when
1342 * passed to this function. 1304 * passed to this function.
1343 *
1344 */ 1305 */
1345static int nand_create_default_bbt_descr(struct nand_chip *this) 1306static int nand_create_badblock_pattern(struct nand_chip *this)
1346{ 1307{
1347 struct nand_bbt_descr *bd; 1308 struct nand_bbt_descr *bd;
1348 if (this->badblock_pattern) { 1309 if (this->badblock_pattern) {
1349 printk(KERN_WARNING "BBT descr already allocated; not replacing.\n"); 1310 pr_warn("Bad block pattern already allocated; not replacing\n");
1350 return -EINVAL; 1311 return -EINVAL;
1351 } 1312 }
1352 bd = kzalloc(sizeof(*bd), GFP_KERNEL); 1313 bd = kzalloc(sizeof(*bd), GFP_KERNEL);
1353 if (!bd) { 1314 if (!bd)
1354 printk(KERN_ERR "nand_create_default_bbt_descr: Out of memory\n");
1355 return -ENOMEM; 1315 return -ENOMEM;
1356 } 1316 bd->options = this->bbt_options & BADBLOCK_SCAN_MASK;
1357 bd->options = this->options & BBT_SCAN_OPTIONS;
1358 bd->offs = this->badblockpos; 1317 bd->offs = this->badblockpos;
1359 bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1; 1318 bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1;
1360 bd->pattern = scan_ff_pattern; 1319 bd->pattern = scan_ff_pattern;
@@ -1365,22 +1324,20 @@ static int nand_create_default_bbt_descr(struct nand_chip *this)
1365 1324
1366/** 1325/**
1367 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device 1326 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device
1368 * @mtd: MTD device structure 1327 * @mtd: MTD device structure
1369 *
1370 * This function selects the default bad block table
1371 * support for the device and calls the nand_scan_bbt function
1372 * 1328 *
1373*/ 1329 * This function selects the default bad block table support for the device and
1330 * calls the nand_scan_bbt function.
1331 */
1374int nand_default_bbt(struct mtd_info *mtd) 1332int nand_default_bbt(struct mtd_info *mtd)
1375{ 1333{
1376 struct nand_chip *this = mtd->priv; 1334 struct nand_chip *this = mtd->priv;
1377 1335
1378 /* Default for AG-AND. We must use a flash based 1336 /*
1379 * bad block table as the devices have factory marked 1337 * Default for AG-AND. We must use a flash based bad block table as the
1380 * _good_ blocks. Erasing those blocks leads to loss 1338 * devices have factory marked _good_ blocks. Erasing those blocks
1381 * of the good / bad information, so we _must_ store 1339 * leads to loss of the good / bad information, so we _must_ store this
1382 * this information in a good / bad table during 1340 * information in a good / bad table during startup.
1383 * startup
1384 */ 1341 */
1385 if (this->options & NAND_IS_AND) { 1342 if (this->options & NAND_IS_AND) {
1386 /* Use the default pattern descriptors */ 1343 /* Use the default pattern descriptors */
@@ -1388,15 +1345,15 @@ int nand_default_bbt(struct mtd_info *mtd)
1388 this->bbt_td = &bbt_main_descr; 1345 this->bbt_td = &bbt_main_descr;
1389 this->bbt_md = &bbt_mirror_descr; 1346 this->bbt_md = &bbt_mirror_descr;
1390 } 1347 }
1391 this->options |= NAND_USE_FLASH_BBT; 1348 this->bbt_options |= NAND_BBT_USE_FLASH;
1392 return nand_scan_bbt(mtd, &agand_flashbased); 1349 return nand_scan_bbt(mtd, &agand_flashbased);
1393 } 1350 }
1394 1351
1395 /* Is a flash based bad block table requested ? */ 1352 /* Is a flash based bad block table requested? */
1396 if (this->options & NAND_USE_FLASH_BBT) { 1353 if (this->bbt_options & NAND_BBT_USE_FLASH) {
1397 /* Use the default pattern descriptors */ 1354 /* Use the default pattern descriptors */
1398 if (!this->bbt_td) { 1355 if (!this->bbt_td) {
1399 if (this->options & NAND_USE_FLASH_BBT_NO_OOB) { 1356 if (this->bbt_options & NAND_BBT_NO_OOB) {
1400 this->bbt_td = &bbt_main_no_bbt_descr; 1357 this->bbt_td = &bbt_main_no_bbt_descr;
1401 this->bbt_md = &bbt_mirror_no_bbt_descr; 1358 this->bbt_md = &bbt_mirror_no_bbt_descr;
1402 } else { 1359 } else {
@@ -1410,18 +1367,17 @@ int nand_default_bbt(struct mtd_info *mtd)
1410 } 1367 }
1411 1368
1412 if (!this->badblock_pattern) 1369 if (!this->badblock_pattern)
1413 nand_create_default_bbt_descr(this); 1370 nand_create_badblock_pattern(this);
1414 1371
1415 return nand_scan_bbt(mtd, this->badblock_pattern); 1372 return nand_scan_bbt(mtd, this->badblock_pattern);
1416} 1373}
1417 1374
1418/** 1375/**
1419 * nand_isbad_bbt - [NAND Interface] Check if a block is bad 1376 * nand_isbad_bbt - [NAND Interface] Check if a block is bad
1420 * @mtd: MTD device structure 1377 * @mtd: MTD device structure
1421 * @offs: offset in the device 1378 * @offs: offset in the device
1422 * @allowbbt: allow access to bad block table region 1379 * @allowbbt: allow access to bad block table region
1423 * 1380 */
1424*/
1425int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) 1381int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
1426{ 1382{
1427 struct nand_chip *this = mtd->priv; 1383 struct nand_chip *this = mtd->priv;
@@ -1432,8 +1388,9 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
1432 block = (int)(offs >> (this->bbt_erase_shift - 1)); 1388 block = (int)(offs >> (this->bbt_erase_shift - 1));
1433 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; 1389 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03;
1434 1390
1435 DEBUG(MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 1391 pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: "
1436 (unsigned int)offs, block >> 1, res); 1392 "(block %d) 0x%02x\n",
1393 (unsigned int)offs, block >> 1, res);
1437 1394
1438 switch ((int)res) { 1395 switch ((int)res) {
1439 case 0x00: 1396 case 0x00:
diff --git a/drivers/mtd/nand/nand_bch.c b/drivers/mtd/nand/nand_bch.c
index 0f931e75711..3803e0bba23 100644
--- a/drivers/mtd/nand/nand_bch.c
+++ b/drivers/mtd/nand/nand_bch.c
@@ -93,8 +93,8 @@ int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
93 buf[errloc[i] >> 3] ^= (1 << (errloc[i] & 7)); 93 buf[errloc[i] >> 3] ^= (1 << (errloc[i] & 7));
94 /* else error in ecc, no action needed */ 94 /* else error in ecc, no action needed */
95 95
96 DEBUG(MTD_DEBUG_LEVEL0, "%s: corrected bitflip %u\n", 96 pr_debug("%s: corrected bitflip %u\n", __func__,
97 __func__, errloc[i]); 97 errloc[i]);
98 } 98 }
99 } else if (count < 0) { 99 } else if (count < 0) {
100 printk(KERN_ERR "ecc unrecoverable error\n"); 100 printk(KERN_ERR "ecc unrecoverable error\n");
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
index 271b8e735e8..b7cfe0d3712 100644
--- a/drivers/mtd/nand/nand_ecc.c
+++ b/drivers/mtd/nand/nand_ecc.c
@@ -110,7 +110,7 @@ static const char bitsperbyte[256] = {
110 110
111/* 111/*
112 * addressbits is a lookup table to filter out the bits from the xor-ed 112 * addressbits is a lookup table to filter out the bits from the xor-ed
113 * ecc data that identify the faulty location. 113 * ECC data that identify the faulty location.
114 * this is only used for repairing parity 114 * this is only used for repairing parity
115 * see the comments in nand_correct_data for more details 115 * see the comments in nand_correct_data for more details
116 */ 116 */
@@ -153,7 +153,7 @@ static const char addressbits[256] = {
153 * __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte 153 * __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte
154 * block 154 * block
155 * @buf: input buffer with raw data 155 * @buf: input buffer with raw data
156 * @eccsize: data bytes per ecc step (256 or 512) 156 * @eccsize: data bytes per ECC step (256 or 512)
157 * @code: output buffer with ECC 157 * @code: output buffer with ECC
158 */ 158 */
159void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize, 159void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
@@ -348,7 +348,7 @@ void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
348 rp17 = (par ^ rp16) & 0xff; 348 rp17 = (par ^ rp16) & 0xff;
349 349
350 /* 350 /*
351 * Finally calculate the ecc bits. 351 * Finally calculate the ECC bits.
352 * Again here it might seem that there are performance optimisations 352 * Again here it might seem that there are performance optimisations
353 * possible, but benchmarks showed that on the system this is developed 353 * possible, but benchmarks showed that on the system this is developed
354 * the code below is the fastest 354 * the code below is the fastest
@@ -436,7 +436,7 @@ EXPORT_SYMBOL(nand_calculate_ecc);
436 * @buf: raw data read from the chip 436 * @buf: raw data read from the chip
437 * @read_ecc: ECC from the chip 437 * @read_ecc: ECC from the chip
438 * @calc_ecc: the ECC calculated from raw data 438 * @calc_ecc: the ECC calculated from raw data
439 * @eccsize: data bytes per ecc step (256 or 512) 439 * @eccsize: data bytes per ECC step (256 or 512)
440 * 440 *
441 * Detect and correct a 1 bit error for eccsize byte block 441 * Detect and correct a 1 bit error for eccsize byte block
442 */ 442 */
@@ -505,7 +505,7 @@ int __nand_correct_data(unsigned char *buf,
505 } 505 }
506 /* count nr of bits; use table lookup, faster than calculating it */ 506 /* count nr of bits; use table lookup, faster than calculating it */
507 if ((bitsperbyte[b0] + bitsperbyte[b1] + bitsperbyte[b2]) == 1) 507 if ((bitsperbyte[b0] + bitsperbyte[b1] + bitsperbyte[b2]) == 1)
508 return 1; /* error in ecc data; no action needed */ 508 return 1; /* error in ECC data; no action needed */
509 509
510 printk(KERN_ERR "uncorrectable error : "); 510 printk(KERN_ERR "uncorrectable error : ");
511 return -1; 511 return -1;
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 357e8c5252a..34c03be7730 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2273,9 +2273,9 @@ static int __init ns_init_module(void)
2273 2273
2274 switch (bbt) { 2274 switch (bbt) {
2275 case 2: 2275 case 2:
2276 chip->options |= NAND_USE_FLASH_BBT_NO_OOB; 2276 chip->bbt_options |= NAND_BBT_NO_OOB;
2277 case 1: 2277 case 1:
2278 chip->options |= NAND_USE_FLASH_BBT; 2278 chip->bbt_options |= NAND_BBT_USE_FLASH;
2279 case 0: 2279 case 0:
2280 break; 2280 break;
2281 default: 2281 default:
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index ea2dea8a9c8..ee1713907b9 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -42,7 +42,6 @@ struct ndfc_controller {
42 struct nand_chip chip; 42 struct nand_chip chip;
43 int chip_select; 43 int chip_select;
44 struct nand_hw_control ndfc_control; 44 struct nand_hw_control ndfc_control;
45 struct mtd_partition *parts;
46}; 45};
47 46
48static struct ndfc_controller ndfc_ctrl[NDFC_MAX_CS]; 47static struct ndfc_controller ndfc_ctrl[NDFC_MAX_CS];
@@ -159,13 +158,9 @@ static int ndfc_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
159static int ndfc_chip_init(struct ndfc_controller *ndfc, 158static int ndfc_chip_init(struct ndfc_controller *ndfc,
160 struct device_node *node) 159 struct device_node *node)
161{ 160{
162#ifdef CONFIG_MTD_CMDLINE_PARTS
163 static const char *part_types[] = { "cmdlinepart", NULL };
164#else
165 static const char *part_types[] = { NULL };
166#endif
167 struct device_node *flash_np; 161 struct device_node *flash_np;
168 struct nand_chip *chip = &ndfc->chip; 162 struct nand_chip *chip = &ndfc->chip;
163 struct mtd_part_parser_data ppdata;
169 int ret; 164 int ret;
170 165
171 chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA; 166 chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
@@ -193,6 +188,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
193 if (!flash_np) 188 if (!flash_np)
194 return -ENODEV; 189 return -ENODEV;
195 190
191 ppdata->of_node = flash_np;
196 ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s", 192 ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s",
197 dev_name(&ndfc->ofdev->dev), flash_np->name); 193 dev_name(&ndfc->ofdev->dev), flash_np->name);
198 if (!ndfc->mtd.name) { 194 if (!ndfc->mtd.name) {
@@ -204,18 +200,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
204 if (ret) 200 if (ret)
205 goto err; 201 goto err;
206 202
207 ret = parse_mtd_partitions(&ndfc->mtd, part_types, &ndfc->parts, 0); 203 ret = mtd_device_parse_register(&ndfc->mtd, NULL, &ppdata, NULL, 0);
208 if (ret < 0)
209 goto err;
210
211 if (ret == 0) {
212 ret = of_mtd_parse_partitions(&ndfc->ofdev->dev, flash_np,
213 &ndfc->parts);
214 if (ret < 0)
215 goto err;
216 }
217
218 ret = mtd_device_register(&ndfc->mtd, ndfc->parts, ret);
219 204
220err: 205err:
221 of_node_put(flash_np); 206 of_node_put(flash_np);
@@ -288,6 +273,7 @@ static int __devexit ndfc_remove(struct platform_device *ofdev)
288 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev); 273 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev);
289 274
290 nand_release(&ndfc->mtd); 275 nand_release(&ndfc->mtd);
276 kfree(ndfc->mtd.name);
291 277
292 return 0; 278 return 0;
293} 279}
diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c
index b6a5c86ab31..b463ecfb4c1 100644
--- a/drivers/mtd/nand/nomadik_nand.c
+++ b/drivers/mtd/nand/nomadik_nand.c
@@ -187,6 +187,7 @@ static int nomadik_nand_remove(struct platform_device *pdev)
187 pdata->exit(); 187 pdata->exit();
188 188
189 if (host) { 189 if (host) {
190 nand_release(&host->mtd);
190 iounmap(host->cmd_va); 191 iounmap(host->cmd_va);
191 iounmap(host->data_va); 192 iounmap(host->data_va);
192 iounmap(host->addr_va); 193 iounmap(host->addr_va);
diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c
index 9c30a0b0317..fa8faedfad6 100644
--- a/drivers/mtd/nand/nuc900_nand.c
+++ b/drivers/mtd/nand/nuc900_nand.c
@@ -339,6 +339,7 @@ static int __devexit nuc900_nand_remove(struct platform_device *pdev)
339 struct nuc900_nand *nuc900_nand = platform_get_drvdata(pdev); 339 struct nuc900_nand *nuc900_nand = platform_get_drvdata(pdev);
340 struct resource *res; 340 struct resource *res;
341 341
342 nand_release(&nuc900_nand->mtd);
342 iounmap(nuc900_nand->reg); 343 iounmap(nuc900_nand->reg);
343 344
344 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 345 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 0db2c0e7656..f745f00f316 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>
@@ -94,8 +95,6 @@
94#define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0) 95#define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0)
95#define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1) 96#define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1)
96 97
97static const char *part_probes[] = { "cmdlinepart", NULL };
98
99/* oob info generated runtime depending on ecc algorithm and layout selected */ 98/* oob info generated runtime depending on ecc algorithm and layout selected */
100static struct nand_ecclayout omap_oobinfo; 99static struct nand_ecclayout omap_oobinfo;
101/* Define some generic bad / good block scan pattern which are used 100/* Define some generic bad / good block scan pattern which are used
@@ -114,7 +113,6 @@ struct omap_nand_info {
114 struct nand_hw_control controller; 113 struct nand_hw_control controller;
115 struct omap_nand_platform_data *pdata; 114 struct omap_nand_platform_data *pdata;
116 struct mtd_info mtd; 115 struct mtd_info mtd;
117 struct mtd_partition *parts;
118 struct nand_chip nand; 116 struct nand_chip nand;
119 struct platform_device *pdev; 117 struct platform_device *pdev;
120 118
@@ -744,12 +742,12 @@ static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
744 742
745 case 1: 743 case 1:
746 /* Uncorrectable error */ 744 /* Uncorrectable error */
747 DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n"); 745 pr_debug("ECC UNCORRECTED_ERROR 1\n");
748 return -1; 746 return -1;
749 747
750 case 11: 748 case 11:
751 /* UN-Correctable error */ 749 /* UN-Correctable error */
752 DEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR B\n"); 750 pr_debug("ECC UNCORRECTED_ERROR B\n");
753 return -1; 751 return -1;
754 752
755 case 12: 753 case 12:
@@ -766,8 +764,8 @@ static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
766 764
767 find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1]; 765 find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
768 766
769 DEBUG(MTD_DEBUG_LEVEL0, "Correcting single bit ECC error at " 767 pr_debug("Correcting single bit ECC error at offset: "
770 "offset: %d, bit: %d\n", find_byte, find_bit); 768 "%d, bit: %d\n", find_byte, find_bit);
771 769
772 page_data[find_byte] ^= (1 << find_bit); 770 page_data[find_byte] ^= (1 << find_bit);
773 771
@@ -779,7 +777,7 @@ static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
779 ecc_data2[2] == 0) 777 ecc_data2[2] == 0)
780 return 0; 778 return 0;
781 } 779 }
782 DEBUG(MTD_DEBUG_LEVEL0, "UNCORRECTED_ERROR default\n"); 780 pr_debug("UNCORRECTED_ERROR default\n");
783 return -1; 781 return -1;
784 } 782 }
785} 783}
@@ -1103,13 +1101,8 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1103 goto out_release_mem_region; 1101 goto out_release_mem_region;
1104 } 1102 }
1105 1103
1106 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); 1104 mtd_device_parse_register(&info->mtd, NULL, 0,
1107 if (err > 0) 1105 pdata->parts, pdata->nr_parts);
1108 mtd_device_register(&info->mtd, info->parts, err);
1109 else if (pdata->parts)
1110 mtd_device_register(&info->mtd, pdata->parts, pdata->nr_parts);
1111 else
1112 mtd_device_register(&info->mtd, NULL, 0);
1113 1106
1114 platform_set_drvdata(pdev, &info->mtd); 1107 platform_set_drvdata(pdev, &info->mtd);
1115 1108
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 7794d0680f9..29f505adaf8 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -21,8 +21,6 @@
21#include <mach/hardware.h> 21#include <mach/hardware.h>
22#include <plat/orion_nand.h> 22#include <plat/orion_nand.h>
23 23
24static const char *part_probes[] = { "cmdlinepart", NULL };
25
26static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 24static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
27{ 25{
28 struct nand_chip *nc = mtd->priv; 26 struct nand_chip *nc = mtd->priv;
@@ -81,8 +79,6 @@ static int __init orion_nand_probe(struct platform_device *pdev)
81 struct resource *res; 79 struct resource *res;
82 void __iomem *io_base; 80 void __iomem *io_base;
83 int ret = 0; 81 int ret = 0;
84 struct mtd_partition *partitions = NULL;
85 int num_part = 0;
86 82
87 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL); 83 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL);
88 if (!nc) { 84 if (!nc) {
@@ -132,17 +128,9 @@ static int __init orion_nand_probe(struct platform_device *pdev)
132 goto no_dev; 128 goto no_dev;
133 } 129 }
134 130
135#ifdef CONFIG_MTD_CMDLINE_PARTS
136 mtd->name = "orion_nand"; 131 mtd->name = "orion_nand";
137 num_part = parse_mtd_partitions(mtd, part_probes, &partitions, 0); 132 ret = mtd_device_parse_register(mtd, NULL, 0,
138#endif 133 board->parts, board->nr_parts);
139 /* If cmdline partitions have been passed, let them be used */
140 if (num_part <= 0) {
141 num_part = board->nr_parts;
142 partitions = board->parts;
143 }
144
145 ret = mtd_device_register(mtd, partitions, num_part);
146 if (ret) { 134 if (ret) {
147 nand_release(mtd); 135 nand_release(mtd);
148 goto no_dev; 136 goto no_dev;
diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index b1aa41b8a4e..a97264ececd 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -155,7 +155,8 @@ static int __devinit pasemi_nand_probe(struct platform_device *ofdev)
155 chip->ecc.mode = NAND_ECC_SOFT; 155 chip->ecc.mode = NAND_ECC_SOFT;
156 156
157 /* Enable the following for a flash based bad block table */ 157 /* Enable the following for a flash based bad block table */
158 chip->options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR; 158 chip->options = NAND_NO_AUTOINCR;
159 chip->bbt_options = NAND_BBT_USE_FLASH;
159 160
160 /* Scan to find existence of the device */ 161 /* Scan to find existence of the device */
161 if (nand_scan(pasemi_nand_mtd, 1)) { 162 if (nand_scan(pasemi_nand_mtd, 1)) {
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 633c04bf76f..ea8e1234e0e 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -21,8 +21,6 @@ struct plat_nand_data {
21 struct nand_chip chip; 21 struct nand_chip chip;
22 struct mtd_info mtd; 22 struct mtd_info mtd;
23 void __iomem *io_base; 23 void __iomem *io_base;
24 int nr_parts;
25 struct mtd_partition *parts;
26}; 24};
27 25
28/* 26/*
@@ -79,6 +77,7 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
79 data->chip.read_buf = pdata->ctrl.read_buf; 77 data->chip.read_buf = pdata->ctrl.read_buf;
80 data->chip.chip_delay = pdata->chip.chip_delay; 78 data->chip.chip_delay = pdata->chip.chip_delay;
81 data->chip.options |= pdata->chip.options; 79 data->chip.options |= pdata->chip.options;
80 data->chip.bbt_options |= pdata->chip.bbt_options;
82 81
83 data->chip.ecc.hwctl = pdata->ctrl.hwcontrol; 82 data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
84 data->chip.ecc.layout = pdata->chip.ecclayout; 83 data->chip.ecc.layout = pdata->chip.ecclayout;
@@ -99,23 +98,9 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
99 goto out; 98 goto out;
100 } 99 }
101 100
102 if (pdata->chip.part_probe_types) { 101 err = mtd_device_parse_register(&data->mtd,
103 err = parse_mtd_partitions(&data->mtd, 102 pdata->chip.part_probe_types, 0,
104 pdata->chip.part_probe_types, 103 pdata->chip.partitions, pdata->chip.nr_partitions);
105 &data->parts, 0);
106 if (err > 0) {
107 mtd_device_register(&data->mtd, data->parts, err);
108 return 0;
109 }
110 }
111 if (pdata->chip.set_parts)
112 pdata->chip.set_parts(data->mtd.size, &pdata->chip);
113 if (pdata->chip.partitions) {
114 data->parts = pdata->chip.partitions;
115 err = mtd_device_register(&data->mtd, data->parts,
116 pdata->chip.nr_partitions);
117 } else
118 err = mtd_device_register(&data->mtd, NULL, 0);
119 104
120 if (!err) 105 if (!err)
121 return err; 106 return err;
@@ -145,8 +130,6 @@ static int __devexit plat_nand_remove(struct platform_device *pdev)
145 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 130 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146 131
147 nand_release(&data->mtd); 132 nand_release(&data->mtd);
148 if (data->parts && data->parts != pdata->chip.partitions)
149 kfree(data->parts);
150 if (pdata->ctrl.remove) 133 if (pdata->ctrl.remove)
151 pdata->ctrl.remove(pdev); 134 pdata->ctrl.remove(pdev);
152 iounmap(data->io_base); 135 iounmap(data->io_base);
diff --git a/drivers/mtd/nand/ppchameleonevb.c b/drivers/mtd/nand/ppchameleonevb.c
index 3bbb796b451..7e52af51a19 100644
--- a/drivers/mtd/nand/ppchameleonevb.c
+++ b/drivers/mtd/nand/ppchameleonevb.c
@@ -99,8 +99,6 @@ static struct mtd_partition partition_info_evb[] = {
99 99
100#define NUM_PARTITIONS 1 100#define NUM_PARTITIONS 1
101 101
102extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id);
103
104/* 102/*
105 * hardware specific access to control-lines 103 * hardware specific access to control-lines
106 */ 104 */
@@ -187,18 +185,12 @@ static int ppchameleonevb_device_ready(struct mtd_info *minfo)
187} 185}
188#endif 186#endif
189 187
190const char *part_probes[] = { "cmdlinepart", NULL };
191const char *part_probes_evb[] = { "cmdlinepart", NULL };
192
193/* 188/*
194 * Main initialization routine 189 * Main initialization routine
195 */ 190 */
196static int __init ppchameleonevb_init(void) 191static int __init ppchameleonevb_init(void)
197{ 192{
198 struct nand_chip *this; 193 struct nand_chip *this;
199 const char *part_type = 0;
200 int mtd_parts_nb = 0;
201 struct mtd_partition *mtd_parts = 0;
202 void __iomem *ppchameleon_fio_base; 194 void __iomem *ppchameleon_fio_base;
203 void __iomem *ppchameleonevb_fio_base; 195 void __iomem *ppchameleonevb_fio_base;
204 196
@@ -281,24 +273,13 @@ static int __init ppchameleonevb_init(void)
281#endif 273#endif
282 274
283 ppchameleon_mtd->name = "ppchameleon-nand"; 275 ppchameleon_mtd->name = "ppchameleon-nand";
284 mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0);
285 if (mtd_parts_nb > 0)
286 part_type = "command line";
287 else
288 mtd_parts_nb = 0;
289
290 if (mtd_parts_nb == 0) {
291 if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
292 mtd_parts = partition_info_me;
293 else
294 mtd_parts = partition_info_hi;
295 mtd_parts_nb = NUM_PARTITIONS;
296 part_type = "static";
297 }
298 276
299 /* Register the partitions */ 277 /* Register the partitions */
300 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 278 mtd_device_parse_register(ppchameleon_mtd, NULL, 0,
301 mtd_device_register(ppchameleon_mtd, mtd_parts, mtd_parts_nb); 279 ppchameleon_mtd->size == NAND_SMALL_SIZE ?
280 partition_info_me :
281 partition_info_hi,
282 NUM_PARTITIONS);
302 283
303 nand_evb_init: 284 nand_evb_init:
304 /**************************** 285 /****************************
@@ -382,21 +363,13 @@ static int __init ppchameleonevb_init(void)
382 } 363 }
383 364
384 ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME; 365 ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
385 mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
386 if (mtd_parts_nb > 0)
387 part_type = "command line";
388 else
389 mtd_parts_nb = 0;
390
391 if (mtd_parts_nb == 0) {
392 mtd_parts = partition_info_evb;
393 mtd_parts_nb = NUM_PARTITIONS;
394 part_type = "static";
395 }
396 366
397 /* Register the partitions */ 367 /* Register the partitions */
398 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 368 mtd_device_parse_register(ppchameleonevb_mtd, NULL, 0,
399 mtd_device_register(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb); 369 ppchameleon_mtd->size == NAND_SMALL_SIZE ?
370 partition_info_me :
371 partition_info_hi,
372 NUM_PARTITIONS);
400 373
401 /* Return happy */ 374 /* Return happy */
402 return 0; 375 return 0;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 1fb3b3a8058..9eb7f879969 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -110,6 +110,7 @@ enum {
110 110
111enum { 111enum {
112 STATE_IDLE = 0, 112 STATE_IDLE = 0,
113 STATE_PREPARED,
113 STATE_CMD_HANDLE, 114 STATE_CMD_HANDLE,
114 STATE_DMA_READING, 115 STATE_DMA_READING,
115 STATE_DMA_WRITING, 116 STATE_DMA_WRITING,
@@ -120,21 +121,40 @@ enum {
120 STATE_READY, 121 STATE_READY,
121}; 122};
122 123
123struct pxa3xx_nand_info { 124struct pxa3xx_nand_host {
124 struct nand_chip nand_chip; 125 struct nand_chip chip;
126 struct pxa3xx_nand_cmdset *cmdset;
127 struct mtd_info *mtd;
128 void *info_data;
129
130 /* page size of attached chip */
131 unsigned int page_size;
132 int use_ecc;
133 int cs;
125 134
135 /* calculated from pxa3xx_nand_flash data */
136 unsigned int col_addr_cycles;
137 unsigned int row_addr_cycles;
138 size_t read_id_bytes;
139
140 /* cached register value */
141 uint32_t reg_ndcr;
142 uint32_t ndtr0cs0;
143 uint32_t ndtr1cs0;
144};
145
146struct pxa3xx_nand_info {
126 struct nand_hw_control controller; 147 struct nand_hw_control controller;
127 struct platform_device *pdev; 148 struct platform_device *pdev;
128 struct pxa3xx_nand_cmdset *cmdset;
129 149
130 struct clk *clk; 150 struct clk *clk;
131 void __iomem *mmio_base; 151 void __iomem *mmio_base;
132 unsigned long mmio_phys; 152 unsigned long mmio_phys;
153 struct completion cmd_complete;
133 154
134 unsigned int buf_start; 155 unsigned int buf_start;
135 unsigned int buf_count; 156 unsigned int buf_count;
136 157
137 struct mtd_info *mtd;
138 /* DMA information */ 158 /* DMA information */
139 int drcmr_dat; 159 int drcmr_dat;
140 int drcmr_cmd; 160 int drcmr_cmd;
@@ -142,44 +162,27 @@ struct pxa3xx_nand_info {
142 unsigned char *data_buff; 162 unsigned char *data_buff;
143 unsigned char *oob_buff; 163 unsigned char *oob_buff;
144 dma_addr_t data_buff_phys; 164 dma_addr_t data_buff_phys;
145 size_t data_buff_size;
146 int data_dma_ch; 165 int data_dma_ch;
147 struct pxa_dma_desc *data_desc; 166 struct pxa_dma_desc *data_desc;
148 dma_addr_t data_desc_addr; 167 dma_addr_t data_desc_addr;
149 168
150 uint32_t reg_ndcr; 169 struct pxa3xx_nand_host *host[NUM_CHIP_SELECT];
151
152 /* saved column/page_addr during CMD_SEQIN */
153 int seqin_column;
154 int seqin_page_addr;
155
156 /* relate to the command */
157 unsigned int state; 170 unsigned int state;
158 171
172 int cs;
159 int use_ecc; /* use HW ECC ? */ 173 int use_ecc; /* use HW ECC ? */
160 int use_dma; /* use DMA ? */ 174 int use_dma; /* use DMA ? */
161 int is_ready; 175 int is_ready;
162 176
163 unsigned int page_size; /* page size of attached chip */ 177 unsigned int page_size; /* page size of attached chip */
164 unsigned int data_size; /* data size in FIFO */ 178 unsigned int data_size; /* data size in FIFO */
179 unsigned int oob_size;
165 int retcode; 180 int retcode;
166 struct completion cmd_complete;
167 181
168 /* generated NDCBx register values */ 182 /* generated NDCBx register values */
169 uint32_t ndcb0; 183 uint32_t ndcb0;
170 uint32_t ndcb1; 184 uint32_t ndcb1;
171 uint32_t ndcb2; 185 uint32_t ndcb2;
172
173 /* timing calcuted from setting */
174 uint32_t ndtr0cs0;
175 uint32_t ndtr1cs0;
176
177 /* calculated from pxa3xx_nand_flash data */
178 size_t oob_size;
179 size_t read_id_bytes;
180
181 unsigned int col_addr_cycles;
182 unsigned int row_addr_cycles;
183}; 186};
184 187
185static int use_dma = 1; 188static int use_dma = 1;
@@ -225,7 +228,7 @@ static struct pxa3xx_nand_flash builtin_flash_types[] = {
225/* Define a default flash type setting serve as flash detecting only */ 228/* Define a default flash type setting serve as flash detecting only */
226#define DEFAULT_FLASH_TYPE (&builtin_flash_types[0]) 229#define DEFAULT_FLASH_TYPE (&builtin_flash_types[0])
227 230
228const char *mtd_names[] = {"pxa3xx_nand-0", NULL}; 231const char *mtd_names[] = {"pxa3xx_nand-0", "pxa3xx_nand-1", NULL};
229 232
230#define NDTR0_tCH(c) (min((c), 7) << 19) 233#define NDTR0_tCH(c) (min((c), 7) << 19)
231#define NDTR0_tCS(c) (min((c), 7) << 16) 234#define NDTR0_tCS(c) (min((c), 7) << 16)
@@ -241,9 +244,10 @@ const char *mtd_names[] = {"pxa3xx_nand-0", NULL};
241/* convert nano-seconds to nand flash controller clock cycles */ 244/* convert nano-seconds to nand flash controller clock cycles */
242#define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000) 245#define ns2cycle(ns, clk) (int)((ns) * (clk / 1000000) / 1000)
243 246
244static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, 247static void pxa3xx_nand_set_timing(struct pxa3xx_nand_host *host,
245 const struct pxa3xx_nand_timing *t) 248 const struct pxa3xx_nand_timing *t)
246{ 249{
250 struct pxa3xx_nand_info *info = host->info_data;
247 unsigned long nand_clk = clk_get_rate(info->clk); 251 unsigned long nand_clk = clk_get_rate(info->clk);
248 uint32_t ndtr0, ndtr1; 252 uint32_t ndtr0, ndtr1;
249 253
@@ -258,23 +262,24 @@ static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
258 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) | 262 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) |
259 NDTR1_tAR(ns2cycle(t->tAR, nand_clk)); 263 NDTR1_tAR(ns2cycle(t->tAR, nand_clk));
260 264
261 info->ndtr0cs0 = ndtr0; 265 host->ndtr0cs0 = ndtr0;
262 info->ndtr1cs0 = ndtr1; 266 host->ndtr1cs0 = ndtr1;
263 nand_writel(info, NDTR0CS0, ndtr0); 267 nand_writel(info, NDTR0CS0, ndtr0);
264 nand_writel(info, NDTR1CS0, ndtr1); 268 nand_writel(info, NDTR1CS0, ndtr1);
265} 269}
266 270
267static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info) 271static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info)
268{ 272{
269 int oob_enable = info->reg_ndcr & NDCR_SPARE_EN; 273 struct pxa3xx_nand_host *host = info->host[info->cs];
274 int oob_enable = host->reg_ndcr & NDCR_SPARE_EN;
270 275
271 info->data_size = info->page_size; 276 info->data_size = host->page_size;
272 if (!oob_enable) { 277 if (!oob_enable) {
273 info->oob_size = 0; 278 info->oob_size = 0;
274 return; 279 return;
275 } 280 }
276 281
277 switch (info->page_size) { 282 switch (host->page_size) {
278 case 2048: 283 case 2048:
279 info->oob_size = (info->use_ecc) ? 40 : 64; 284 info->oob_size = (info->use_ecc) ? 40 : 64;
280 break; 285 break;
@@ -292,9 +297,10 @@ static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info)
292 */ 297 */
293static void pxa3xx_nand_start(struct pxa3xx_nand_info *info) 298static void pxa3xx_nand_start(struct pxa3xx_nand_info *info)
294{ 299{
300 struct pxa3xx_nand_host *host = info->host[info->cs];
295 uint32_t ndcr; 301 uint32_t ndcr;
296 302
297 ndcr = info->reg_ndcr; 303 ndcr = host->reg_ndcr;
298 ndcr |= info->use_ecc ? NDCR_ECC_EN : 0; 304 ndcr |= info->use_ecc ? NDCR_ECC_EN : 0;
299 ndcr |= info->use_dma ? NDCR_DMA_EN : 0; 305 ndcr |= info->use_dma ? NDCR_DMA_EN : 0;
300 ndcr |= NDCR_ND_RUN; 306 ndcr |= NDCR_ND_RUN;
@@ -359,7 +365,7 @@ static void handle_data_pio(struct pxa3xx_nand_info *info)
359 DIV_ROUND_UP(info->oob_size, 4)); 365 DIV_ROUND_UP(info->oob_size, 4));
360 break; 366 break;
361 default: 367 default:
362 printk(KERN_ERR "%s: invalid state %d\n", __func__, 368 dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__,
363 info->state); 369 info->state);
364 BUG(); 370 BUG();
365 } 371 }
@@ -385,7 +391,7 @@ static void start_data_dma(struct pxa3xx_nand_info *info)
385 desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC; 391 desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC;
386 break; 392 break;
387 default: 393 default:
388 printk(KERN_ERR "%s: invalid state %d\n", __func__, 394 dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__,
389 info->state); 395 info->state);
390 BUG(); 396 BUG();
391 } 397 }
@@ -416,6 +422,15 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
416{ 422{
417 struct pxa3xx_nand_info *info = devid; 423 struct pxa3xx_nand_info *info = devid;
418 unsigned int status, is_completed = 0; 424 unsigned int status, is_completed = 0;
425 unsigned int ready, cmd_done;
426
427 if (info->cs == 0) {
428 ready = NDSR_FLASH_RDY;
429 cmd_done = NDSR_CS0_CMDD;
430 } else {
431 ready = NDSR_RDY;
432 cmd_done = NDSR_CS1_CMDD;
433 }
419 434
420 status = nand_readl(info, NDSR); 435 status = nand_readl(info, NDSR);
421 436
@@ -437,11 +452,11 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
437 handle_data_pio(info); 452 handle_data_pio(info);
438 } 453 }
439 } 454 }
440 if (status & NDSR_CS0_CMDD) { 455 if (status & cmd_done) {
441 info->state = STATE_CMD_DONE; 456 info->state = STATE_CMD_DONE;
442 is_completed = 1; 457 is_completed = 1;
443 } 458 }
444 if (status & NDSR_FLASH_RDY) { 459 if (status & ready) {
445 info->is_ready = 1; 460 info->is_ready = 1;
446 info->state = STATE_READY; 461 info->state = STATE_READY;
447 } 462 }
@@ -463,12 +478,6 @@ NORMAL_IRQ_EXIT:
463 return IRQ_HANDLED; 478 return IRQ_HANDLED;
464} 479}
465 480
466static int pxa3xx_nand_dev_ready(struct mtd_info *mtd)
467{
468 struct pxa3xx_nand_info *info = mtd->priv;
469 return (nand_readl(info, NDSR) & NDSR_RDY) ? 1 : 0;
470}
471
472static inline int is_buf_blank(uint8_t *buf, size_t len) 481static inline int is_buf_blank(uint8_t *buf, size_t len)
473{ 482{
474 for (; len > 0; len--) 483 for (; len > 0; len--)
@@ -481,10 +490,12 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
481 uint16_t column, int page_addr) 490 uint16_t column, int page_addr)
482{ 491{
483 uint16_t cmd; 492 uint16_t cmd;
484 int addr_cycle, exec_cmd, ndcb0; 493 int addr_cycle, exec_cmd;
485 struct mtd_info *mtd = info->mtd; 494 struct pxa3xx_nand_host *host;
495 struct mtd_info *mtd;
486 496
487 ndcb0 = 0; 497 host = info->host[info->cs];
498 mtd = host->mtd;
488 addr_cycle = 0; 499 addr_cycle = 0;
489 exec_cmd = 1; 500 exec_cmd = 1;
490 501
@@ -495,6 +506,10 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
495 info->use_ecc = 0; 506 info->use_ecc = 0;
496 info->is_ready = 0; 507 info->is_ready = 0;
497 info->retcode = ERR_NONE; 508 info->retcode = ERR_NONE;
509 if (info->cs != 0)
510 info->ndcb0 = NDCB0_CSEL;
511 else
512 info->ndcb0 = 0;
498 513
499 switch (command) { 514 switch (command) {
500 case NAND_CMD_READ0: 515 case NAND_CMD_READ0:
@@ -512,20 +527,19 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
512 break; 527 break;
513 } 528 }
514 529
515 info->ndcb0 = ndcb0; 530 addr_cycle = NDCB0_ADDR_CYC(host->row_addr_cycles
516 addr_cycle = NDCB0_ADDR_CYC(info->row_addr_cycles 531 + host->col_addr_cycles);
517 + info->col_addr_cycles);
518 532
519 switch (command) { 533 switch (command) {
520 case NAND_CMD_READOOB: 534 case NAND_CMD_READOOB:
521 case NAND_CMD_READ0: 535 case NAND_CMD_READ0:
522 cmd = info->cmdset->read1; 536 cmd = host->cmdset->read1;
523 if (command == NAND_CMD_READOOB) 537 if (command == NAND_CMD_READOOB)
524 info->buf_start = mtd->writesize + column; 538 info->buf_start = mtd->writesize + column;
525 else 539 else
526 info->buf_start = column; 540 info->buf_start = column;
527 541
528 if (unlikely(info->page_size < PAGE_CHUNK_SIZE)) 542 if (unlikely(host->page_size < PAGE_CHUNK_SIZE))
529 info->ndcb0 |= NDCB0_CMD_TYPE(0) 543 info->ndcb0 |= NDCB0_CMD_TYPE(0)
530 | addr_cycle 544 | addr_cycle
531 | (cmd & NDCB0_CMD1_MASK); 545 | (cmd & NDCB0_CMD1_MASK);
@@ -537,7 +551,7 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
537 551
538 case NAND_CMD_SEQIN: 552 case NAND_CMD_SEQIN:
539 /* small page addr setting */ 553 /* small page addr setting */
540 if (unlikely(info->page_size < PAGE_CHUNK_SIZE)) { 554 if (unlikely(host->page_size < PAGE_CHUNK_SIZE)) {
541 info->ndcb1 = ((page_addr & 0xFFFFFF) << 8) 555 info->ndcb1 = ((page_addr & 0xFFFFFF) << 8)
542 | (column & 0xFF); 556 | (column & 0xFF);
543 557
@@ -564,7 +578,7 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
564 break; 578 break;
565 } 579 }
566 580
567 cmd = info->cmdset->program; 581 cmd = host->cmdset->program;
568 info->ndcb0 |= NDCB0_CMD_TYPE(0x1) 582 info->ndcb0 |= NDCB0_CMD_TYPE(0x1)
569 | NDCB0_AUTO_RS 583 | NDCB0_AUTO_RS
570 | NDCB0_ST_ROW_EN 584 | NDCB0_ST_ROW_EN
@@ -574,8 +588,8 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
574 break; 588 break;
575 589
576 case NAND_CMD_READID: 590 case NAND_CMD_READID:
577 cmd = info->cmdset->read_id; 591 cmd = host->cmdset->read_id;
578 info->buf_count = info->read_id_bytes; 592 info->buf_count = host->read_id_bytes;
579 info->ndcb0 |= NDCB0_CMD_TYPE(3) 593 info->ndcb0 |= NDCB0_CMD_TYPE(3)
580 | NDCB0_ADDR_CYC(1) 594 | NDCB0_ADDR_CYC(1)
581 | cmd; 595 | cmd;
@@ -583,7 +597,7 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
583 info->data_size = 8; 597 info->data_size = 8;
584 break; 598 break;
585 case NAND_CMD_STATUS: 599 case NAND_CMD_STATUS:
586 cmd = info->cmdset->read_status; 600 cmd = host->cmdset->read_status;
587 info->buf_count = 1; 601 info->buf_count = 1;
588 info->ndcb0 |= NDCB0_CMD_TYPE(4) 602 info->ndcb0 |= NDCB0_CMD_TYPE(4)
589 | NDCB0_ADDR_CYC(1) 603 | NDCB0_ADDR_CYC(1)
@@ -593,7 +607,7 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
593 break; 607 break;
594 608
595 case NAND_CMD_ERASE1: 609 case NAND_CMD_ERASE1:
596 cmd = info->cmdset->erase; 610 cmd = host->cmdset->erase;
597 info->ndcb0 |= NDCB0_CMD_TYPE(2) 611 info->ndcb0 |= NDCB0_CMD_TYPE(2)
598 | NDCB0_AUTO_RS 612 | NDCB0_AUTO_RS
599 | NDCB0_ADDR_CYC(3) 613 | NDCB0_ADDR_CYC(3)
@@ -604,7 +618,7 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
604 618
605 break; 619 break;
606 case NAND_CMD_RESET: 620 case NAND_CMD_RESET:
607 cmd = info->cmdset->reset; 621 cmd = host->cmdset->reset;
608 info->ndcb0 |= NDCB0_CMD_TYPE(5) 622 info->ndcb0 |= NDCB0_CMD_TYPE(5)
609 | cmd; 623 | cmd;
610 624
@@ -616,8 +630,8 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
616 630
617 default: 631 default:
618 exec_cmd = 0; 632 exec_cmd = 0;
619 printk(KERN_ERR "pxa3xx-nand: non-supported" 633 dev_err(&info->pdev->dev, "non-supported command %x\n",
620 " command %x\n", command); 634 command);
621 break; 635 break;
622 } 636 }
623 637
@@ -627,7 +641,8 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,
627static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, 641static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
628 int column, int page_addr) 642 int column, int page_addr)
629{ 643{
630 struct pxa3xx_nand_info *info = mtd->priv; 644 struct pxa3xx_nand_host *host = mtd->priv;
645 struct pxa3xx_nand_info *info = host->info_data;
631 int ret, exec_cmd; 646 int ret, exec_cmd;
632 647
633 /* 648 /*
@@ -635,9 +650,21 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
635 * "byte" address into a "word" address appropriate 650 * "byte" address into a "word" address appropriate
636 * for indexing a word-oriented device 651 * for indexing a word-oriented device
637 */ 652 */
638 if (info->reg_ndcr & NDCR_DWIDTH_M) 653 if (host->reg_ndcr & NDCR_DWIDTH_M)
639 column /= 2; 654 column /= 2;
640 655
656 /*
657 * There may be different NAND chip hooked to
658 * different chip select, so check whether
659 * chip select has been changed, if yes, reset the timing
660 */
661 if (info->cs != host->cs) {
662 info->cs = host->cs;
663 nand_writel(info, NDTR0CS0, host->ndtr0cs0);
664 nand_writel(info, NDTR1CS0, host->ndtr1cs0);
665 }
666
667 info->state = STATE_PREPARED;
641 exec_cmd = prepare_command_pool(info, command, column, page_addr); 668 exec_cmd = prepare_command_pool(info, command, column, page_addr);
642 if (exec_cmd) { 669 if (exec_cmd) {
643 init_completion(&info->cmd_complete); 670 init_completion(&info->cmd_complete);
@@ -646,12 +673,12 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
646 ret = wait_for_completion_timeout(&info->cmd_complete, 673 ret = wait_for_completion_timeout(&info->cmd_complete,
647 CHIP_DELAY_TIMEOUT); 674 CHIP_DELAY_TIMEOUT);
648 if (!ret) { 675 if (!ret) {
649 printk(KERN_ERR "Wait time out!!!\n"); 676 dev_err(&info->pdev->dev, "Wait time out!!!\n");
650 /* Stop State Machine for next command cycle */ 677 /* Stop State Machine for next command cycle */
651 pxa3xx_nand_stop(info); 678 pxa3xx_nand_stop(info);
652 } 679 }
653 info->state = STATE_IDLE;
654 } 680 }
681 info->state = STATE_IDLE;
655} 682}
656 683
657static void pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd, 684static void pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd,
@@ -664,7 +691,8 @@ static void pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd,
664static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, 691static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
665 struct nand_chip *chip, uint8_t *buf, int page) 692 struct nand_chip *chip, uint8_t *buf, int page)
666{ 693{
667 struct pxa3xx_nand_info *info = mtd->priv; 694 struct pxa3xx_nand_host *host = mtd->priv;
695 struct pxa3xx_nand_info *info = host->info_data;
668 696
669 chip->read_buf(mtd, buf, mtd->writesize); 697 chip->read_buf(mtd, buf, mtd->writesize);
670 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 698 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -685,6 +713,8 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
685 * OOB, ignore such double bit errors 713 * OOB, ignore such double bit errors
686 */ 714 */
687 if (is_buf_blank(buf, mtd->writesize)) 715 if (is_buf_blank(buf, mtd->writesize))
716 info->retcode = ERR_NONE;
717 else
688 mtd->ecc_stats.failed++; 718 mtd->ecc_stats.failed++;
689 } 719 }
690 720
@@ -693,7 +723,8 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
693 723
694static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd) 724static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
695{ 725{
696 struct pxa3xx_nand_info *info = mtd->priv; 726 struct pxa3xx_nand_host *host = mtd->priv;
727 struct pxa3xx_nand_info *info = host->info_data;
697 char retval = 0xFF; 728 char retval = 0xFF;
698 729
699 if (info->buf_start < info->buf_count) 730 if (info->buf_start < info->buf_count)
@@ -705,7 +736,8 @@ static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
705 736
706static u16 pxa3xx_nand_read_word(struct mtd_info *mtd) 737static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
707{ 738{
708 struct pxa3xx_nand_info *info = mtd->priv; 739 struct pxa3xx_nand_host *host = mtd->priv;
740 struct pxa3xx_nand_info *info = host->info_data;
709 u16 retval = 0xFFFF; 741 u16 retval = 0xFFFF;
710 742
711 if (!(info->buf_start & 0x01) && info->buf_start < info->buf_count) { 743 if (!(info->buf_start & 0x01) && info->buf_start < info->buf_count) {
@@ -717,7 +749,8 @@ static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
717 749
718static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 750static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
719{ 751{
720 struct pxa3xx_nand_info *info = mtd->priv; 752 struct pxa3xx_nand_host *host = mtd->priv;
753 struct pxa3xx_nand_info *info = host->info_data;
721 int real_len = min_t(size_t, len, info->buf_count - info->buf_start); 754 int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
722 755
723 memcpy(buf, info->data_buff + info->buf_start, real_len); 756 memcpy(buf, info->data_buff + info->buf_start, real_len);
@@ -727,7 +760,8 @@ static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
727static void pxa3xx_nand_write_buf(struct mtd_info *mtd, 760static void pxa3xx_nand_write_buf(struct mtd_info *mtd,
728 const uint8_t *buf, int len) 761 const uint8_t *buf, int len)
729{ 762{
730 struct pxa3xx_nand_info *info = mtd->priv; 763 struct pxa3xx_nand_host *host = mtd->priv;
764 struct pxa3xx_nand_info *info = host->info_data;
731 int real_len = min_t(size_t, len, info->buf_count - info->buf_start); 765 int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
732 766
733 memcpy(info->data_buff + info->buf_start, buf, real_len); 767 memcpy(info->data_buff + info->buf_start, buf, real_len);
@@ -747,7 +781,8 @@ static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip)
747 781
748static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) 782static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
749{ 783{
750 struct pxa3xx_nand_info *info = mtd->priv; 784 struct pxa3xx_nand_host *host = mtd->priv;
785 struct pxa3xx_nand_info *info = host->info_data;
751 786
752 /* pxa3xx_nand_send_command has waited for command complete */ 787 /* pxa3xx_nand_send_command has waited for command complete */
753 if (this->state == FL_WRITING || this->state == FL_ERASING) { 788 if (this->state == FL_WRITING || this->state == FL_ERASING) {
@@ -770,54 +805,70 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
770{ 805{
771 struct platform_device *pdev = info->pdev; 806 struct platform_device *pdev = info->pdev;
772 struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; 807 struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
808 struct pxa3xx_nand_host *host = info->host[info->cs];
773 uint32_t ndcr = 0x0; /* enable all interrupts */ 809 uint32_t ndcr = 0x0; /* enable all interrupts */
774 810
775 if (f->page_size != 2048 && f->page_size != 512) 811 if (f->page_size != 2048 && f->page_size != 512) {
812 dev_err(&pdev->dev, "Current only support 2048 and 512 size\n");
776 return -EINVAL; 813 return -EINVAL;
814 }
777 815
778 if (f->flash_width != 16 && f->flash_width != 8) 816 if (f->flash_width != 16 && f->flash_width != 8) {
817 dev_err(&pdev->dev, "Only support 8bit and 16 bit!\n");
779 return -EINVAL; 818 return -EINVAL;
819 }
780 820
781 /* calculate flash information */ 821 /* calculate flash information */
782 info->cmdset = &default_cmdset; 822 host->cmdset = &default_cmdset;
783 info->page_size = f->page_size; 823 host->page_size = f->page_size;
784 info->read_id_bytes = (f->page_size == 2048) ? 4 : 2; 824 host->read_id_bytes = (f->page_size == 2048) ? 4 : 2;
785 825
786 /* calculate addressing information */ 826 /* calculate addressing information */
787 info->col_addr_cycles = (f->page_size == 2048) ? 2 : 1; 827 host->col_addr_cycles = (f->page_size == 2048) ? 2 : 1;
788 828
789 if (f->num_blocks * f->page_per_block > 65536) 829 if (f->num_blocks * f->page_per_block > 65536)
790 info->row_addr_cycles = 3; 830 host->row_addr_cycles = 3;
791 else 831 else
792 info->row_addr_cycles = 2; 832 host->row_addr_cycles = 2;
793 833
794 ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0; 834 ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
795 ndcr |= (info->col_addr_cycles == 2) ? NDCR_RA_START : 0; 835 ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0;
796 ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0; 836 ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0;
797 ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0; 837 ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0;
798 ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0; 838 ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0;
799 ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0; 839 ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0;
800 840
801 ndcr |= NDCR_RD_ID_CNT(info->read_id_bytes); 841 ndcr |= NDCR_RD_ID_CNT(host->read_id_bytes);
802 ndcr |= NDCR_SPARE_EN; /* enable spare by default */ 842 ndcr |= NDCR_SPARE_EN; /* enable spare by default */
803 843
804 info->reg_ndcr = ndcr; 844 host->reg_ndcr = ndcr;
805 845
806 pxa3xx_nand_set_timing(info, f->timing); 846 pxa3xx_nand_set_timing(host, f->timing);
807 return 0; 847 return 0;
808} 848}
809 849
810static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info) 850static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
811{ 851{
852 /*
853 * We set 0 by hard coding here, for we don't support keep_config
854 * when there is more than one chip attached to the controller
855 */
856 struct pxa3xx_nand_host *host = info->host[0];
812 uint32_t ndcr = nand_readl(info, NDCR); 857 uint32_t ndcr = nand_readl(info, NDCR);
813 info->page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
814 /* set info fields needed to read id */
815 info->read_id_bytes = (info->page_size == 2048) ? 4 : 2;
816 info->reg_ndcr = ndcr;
817 info->cmdset = &default_cmdset;
818 858
819 info->ndtr0cs0 = nand_readl(info, NDTR0CS0); 859 if (ndcr & NDCR_PAGE_SZ) {
820 info->ndtr1cs0 = nand_readl(info, NDTR1CS0); 860 host->page_size = 2048;
861 host->read_id_bytes = 4;
862 } else {
863 host->page_size = 512;
864 host->read_id_bytes = 2;
865 }
866
867 host->reg_ndcr = ndcr & ~NDCR_INT_MASK;
868 host->cmdset = &default_cmdset;
869
870 host->ndtr0cs0 = nand_readl(info, NDTR0CS0);
871 host->ndtr1cs0 = nand_readl(info, NDTR1CS0);
821 872
822 return 0; 873 return 0;
823} 874}
@@ -847,7 +898,6 @@ static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
847 return -ENOMEM; 898 return -ENOMEM;
848 } 899 }
849 900
850 info->data_buff_size = MAX_BUFF_SIZE;
851 info->data_desc = (void *)info->data_buff + data_desc_offset; 901 info->data_desc = (void *)info->data_buff + data_desc_offset;
852 info->data_desc_addr = info->data_buff_phys + data_desc_offset; 902 info->data_desc_addr = info->data_buff_phys + data_desc_offset;
853 903
@@ -855,7 +905,7 @@ static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
855 pxa3xx_nand_data_dma_irq, info); 905 pxa3xx_nand_data_dma_irq, info);
856 if (info->data_dma_ch < 0) { 906 if (info->data_dma_ch < 0) {
857 dev_err(&pdev->dev, "failed to request data dma\n"); 907 dev_err(&pdev->dev, "failed to request data dma\n");
858 dma_free_coherent(&pdev->dev, info->data_buff_size, 908 dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE,
859 info->data_buff, info->data_buff_phys); 909 info->data_buff, info->data_buff_phys);
860 return info->data_dma_ch; 910 return info->data_dma_ch;
861 } 911 }
@@ -865,24 +915,28 @@ static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
865 915
866static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info) 916static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)
867{ 917{
868 struct mtd_info *mtd = info->mtd; 918 struct mtd_info *mtd;
869 struct nand_chip *chip = mtd->priv; 919 int ret;
870 920 mtd = info->host[info->cs]->mtd;
871 /* use the common timing to make a try */ 921 /* use the common timing to make a try */
872 pxa3xx_nand_config_flash(info, &builtin_flash_types[0]); 922 ret = pxa3xx_nand_config_flash(info, &builtin_flash_types[0]);
873 chip->cmdfunc(mtd, NAND_CMD_RESET, 0, 0); 923 if (ret)
924 return ret;
925
926 pxa3xx_nand_cmdfunc(mtd, NAND_CMD_RESET, 0, 0);
874 if (info->is_ready) 927 if (info->is_ready)
875 return 1;
876 else
877 return 0; 928 return 0;
929
930 return -ENODEV;
878} 931}
879 932
880static int pxa3xx_nand_scan(struct mtd_info *mtd) 933static int pxa3xx_nand_scan(struct mtd_info *mtd)
881{ 934{
882 struct pxa3xx_nand_info *info = mtd->priv; 935 struct pxa3xx_nand_host *host = mtd->priv;
936 struct pxa3xx_nand_info *info = host->info_data;
883 struct platform_device *pdev = info->pdev; 937 struct platform_device *pdev = info->pdev;
884 struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; 938 struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
885 struct nand_flash_dev pxa3xx_flash_ids[2] = { {NULL,}, {NULL,} }; 939 struct nand_flash_dev pxa3xx_flash_ids[2], *def = NULL;
886 const struct pxa3xx_nand_flash *f = NULL; 940 const struct pxa3xx_nand_flash *f = NULL;
887 struct nand_chip *chip = mtd->priv; 941 struct nand_chip *chip = mtd->priv;
888 uint32_t id = -1; 942 uint32_t id = -1;
@@ -893,22 +947,20 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
893 goto KEEP_CONFIG; 947 goto KEEP_CONFIG;
894 948
895 ret = pxa3xx_nand_sensing(info); 949 ret = pxa3xx_nand_sensing(info);
896 if (!ret) { 950 if (ret) {
897 kfree(mtd); 951 dev_info(&info->pdev->dev, "There is no chip on cs %d!\n",
898 info->mtd = NULL; 952 info->cs);
899 printk(KERN_INFO "There is no nand chip on cs 0!\n");
900 953
901 return -EINVAL; 954 return ret;
902 } 955 }
903 956
904 chip->cmdfunc(mtd, NAND_CMD_READID, 0, 0); 957 chip->cmdfunc(mtd, NAND_CMD_READID, 0, 0);
905 id = *((uint16_t *)(info->data_buff)); 958 id = *((uint16_t *)(info->data_buff));
906 if (id != 0) 959 if (id != 0)
907 printk(KERN_INFO "Detect a flash id %x\n", id); 960 dev_info(&info->pdev->dev, "Detect a flash id %x\n", id);
908 else { 961 else {
909 kfree(mtd); 962 dev_warn(&info->pdev->dev,
910 info->mtd = NULL; 963 "Read out ID 0, potential timing set wrong!!\n");
911 printk(KERN_WARNING "Read out ID 0, potential timing set wrong!!\n");
912 964
913 return -EINVAL; 965 return -EINVAL;
914 } 966 }
@@ -926,14 +978,17 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
926 } 978 }
927 979
928 if (i >= (ARRAY_SIZE(builtin_flash_types) + pdata->num_flash - 1)) { 980 if (i >= (ARRAY_SIZE(builtin_flash_types) + pdata->num_flash - 1)) {
929 kfree(mtd); 981 dev_err(&info->pdev->dev, "ERROR!! flash not defined!!!\n");
930 info->mtd = NULL;
931 printk(KERN_ERR "ERROR!! flash not defined!!!\n");
932 982
933 return -EINVAL; 983 return -EINVAL;
934 } 984 }
935 985
936 pxa3xx_nand_config_flash(info, f); 986 ret = pxa3xx_nand_config_flash(info, f);
987 if (ret) {
988 dev_err(&info->pdev->dev, "ERROR! Configure failed\n");
989 return ret;
990 }
991
937 pxa3xx_flash_ids[0].name = f->name; 992 pxa3xx_flash_ids[0].name = f->name;
938 pxa3xx_flash_ids[0].id = (f->chip_id >> 8) & 0xffff; 993 pxa3xx_flash_ids[0].id = (f->chip_id >> 8) & 0xffff;
939 pxa3xx_flash_ids[0].pagesize = f->page_size; 994 pxa3xx_flash_ids[0].pagesize = f->page_size;
@@ -942,62 +997,78 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
942 pxa3xx_flash_ids[0].erasesize = f->page_size * f->page_per_block; 997 pxa3xx_flash_ids[0].erasesize = f->page_size * f->page_per_block;
943 if (f->flash_width == 16) 998 if (f->flash_width == 16)
944 pxa3xx_flash_ids[0].options = NAND_BUSWIDTH_16; 999 pxa3xx_flash_ids[0].options = NAND_BUSWIDTH_16;
1000 pxa3xx_flash_ids[1].name = NULL;
1001 def = pxa3xx_flash_ids;
945KEEP_CONFIG: 1002KEEP_CONFIG:
946 if (nand_scan_ident(mtd, 1, pxa3xx_flash_ids)) 1003 chip->ecc.mode = NAND_ECC_HW;
1004 chip->ecc.size = host->page_size;
1005
1006 chip->options = NAND_NO_AUTOINCR;
1007 chip->options |= NAND_NO_READRDY;
1008 if (host->reg_ndcr & NDCR_DWIDTH_M)
1009 chip->options |= NAND_BUSWIDTH_16;
1010
1011 if (nand_scan_ident(mtd, 1, def))
947 return -ENODEV; 1012 return -ENODEV;
948 /* calculate addressing information */ 1013 /* calculate addressing information */
949 info->col_addr_cycles = (mtd->writesize >= 2048) ? 2 : 1; 1014 if (mtd->writesize >= 2048)
1015 host->col_addr_cycles = 2;
1016 else
1017 host->col_addr_cycles = 1;
1018
950 info->oob_buff = info->data_buff + mtd->writesize; 1019 info->oob_buff = info->data_buff + mtd->writesize;
951 if ((mtd->size >> chip->page_shift) > 65536) 1020 if ((mtd->size >> chip->page_shift) > 65536)
952 info->row_addr_cycles = 3; 1021 host->row_addr_cycles = 3;
953 else 1022 else
954 info->row_addr_cycles = 2; 1023 host->row_addr_cycles = 2;
955 mtd->name = mtd_names[0];
956 chip->ecc.mode = NAND_ECC_HW;
957 chip->ecc.size = f->page_size;
958
959 chip->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16 : 0;
960 chip->options |= NAND_NO_AUTOINCR;
961 chip->options |= NAND_NO_READRDY;
962 1024
1025 mtd->name = mtd_names[0];
963 return nand_scan_tail(mtd); 1026 return nand_scan_tail(mtd);
964} 1027}
965 1028
966static 1029static int alloc_nand_resource(struct platform_device *pdev)
967struct pxa3xx_nand_info *alloc_nand_resource(struct platform_device *pdev)
968{ 1030{
1031 struct pxa3xx_nand_platform_data *pdata;
969 struct pxa3xx_nand_info *info; 1032 struct pxa3xx_nand_info *info;
1033 struct pxa3xx_nand_host *host;
970 struct nand_chip *chip; 1034 struct nand_chip *chip;
971 struct mtd_info *mtd; 1035 struct mtd_info *mtd;
972 struct resource *r; 1036 struct resource *r;
973 int ret, irq; 1037 int ret, irq, cs;
974 1038
975 mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct pxa3xx_nand_info), 1039 pdata = pdev->dev.platform_data;
976 GFP_KERNEL); 1040 info = kzalloc(sizeof(*info) + (sizeof(*mtd) +
977 if (!mtd) { 1041 sizeof(*host)) * pdata->num_cs, GFP_KERNEL);
1042 if (!info) {
978 dev_err(&pdev->dev, "failed to allocate memory\n"); 1043 dev_err(&pdev->dev, "failed to allocate memory\n");
979 return NULL; 1044 return -ENOMEM;
980 } 1045 }
981 1046
982 info = (struct pxa3xx_nand_info *)(&mtd[1]);
983 chip = (struct nand_chip *)(&mtd[1]);
984 info->pdev = pdev; 1047 info->pdev = pdev;
985 info->mtd = mtd; 1048 for (cs = 0; cs < pdata->num_cs; cs++) {
986 mtd->priv = info; 1049 mtd = (struct mtd_info *)((unsigned int)&info[1] +
987 mtd->owner = THIS_MODULE; 1050 (sizeof(*mtd) + sizeof(*host)) * cs);
988 1051 chip = (struct nand_chip *)(&mtd[1]);
989 chip->ecc.read_page = pxa3xx_nand_read_page_hwecc; 1052 host = (struct pxa3xx_nand_host *)chip;
990 chip->ecc.write_page = pxa3xx_nand_write_page_hwecc; 1053 info->host[cs] = host;
991 chip->controller = &info->controller; 1054 host->mtd = mtd;
992 chip->waitfunc = pxa3xx_nand_waitfunc; 1055 host->cs = cs;
993 chip->select_chip = pxa3xx_nand_select_chip; 1056 host->info_data = info;
994 chip->dev_ready = pxa3xx_nand_dev_ready; 1057 mtd->priv = host;
995 chip->cmdfunc = pxa3xx_nand_cmdfunc; 1058 mtd->owner = THIS_MODULE;
996 chip->read_word = pxa3xx_nand_read_word; 1059
997 chip->read_byte = pxa3xx_nand_read_byte; 1060 chip->ecc.read_page = pxa3xx_nand_read_page_hwecc;
998 chip->read_buf = pxa3xx_nand_read_buf; 1061 chip->ecc.write_page = pxa3xx_nand_write_page_hwecc;
999 chip->write_buf = pxa3xx_nand_write_buf; 1062 chip->controller = &info->controller;
1000 chip->verify_buf = pxa3xx_nand_verify_buf; 1063 chip->waitfunc = pxa3xx_nand_waitfunc;
1064 chip->select_chip = pxa3xx_nand_select_chip;
1065 chip->cmdfunc = pxa3xx_nand_cmdfunc;
1066 chip->read_word = pxa3xx_nand_read_word;
1067 chip->read_byte = pxa3xx_nand_read_byte;
1068 chip->read_buf = pxa3xx_nand_read_buf;
1069 chip->write_buf = pxa3xx_nand_write_buf;
1070 chip->verify_buf = pxa3xx_nand_verify_buf;
1071 }
1001 1072
1002 spin_lock_init(&chip->controller->lock); 1073 spin_lock_init(&chip->controller->lock);
1003 init_waitqueue_head(&chip->controller->wq); 1074 init_waitqueue_head(&chip->controller->wq);
@@ -1070,13 +1141,13 @@ struct pxa3xx_nand_info *alloc_nand_resource(struct platform_device *pdev)
1070 1141
1071 platform_set_drvdata(pdev, info); 1142 platform_set_drvdata(pdev, info);
1072 1143
1073 return info; 1144 return 0;
1074 1145
1075fail_free_buf: 1146fail_free_buf:
1076 free_irq(irq, info); 1147 free_irq(irq, info);
1077 if (use_dma) { 1148 if (use_dma) {
1078 pxa_free_dma(info->data_dma_ch); 1149 pxa_free_dma(info->data_dma_ch);
1079 dma_free_coherent(&pdev->dev, info->data_buff_size, 1150 dma_free_coherent(&pdev->dev, MAX_BUFF_SIZE,
1080 info->data_buff, info->data_buff_phys); 1151 info->data_buff, info->data_buff_phys);
1081 } else 1152 } else
1082 kfree(info->data_buff); 1153 kfree(info->data_buff);
@@ -1088,17 +1159,21 @@ fail_put_clk:
1088 clk_disable(info->clk); 1159 clk_disable(info->clk);
1089 clk_put(info->clk); 1160 clk_put(info->clk);
1090fail_free_mtd: 1161fail_free_mtd:
1091 kfree(mtd); 1162 kfree(info);
1092 return NULL; 1163 return ret;
1093} 1164}
1094 1165
1095static int pxa3xx_nand_remove(struct platform_device *pdev) 1166static int pxa3xx_nand_remove(struct platform_device *pdev)
1096{ 1167{
1097 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); 1168 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev);
1098 struct mtd_info *mtd = info->mtd; 1169 struct pxa3xx_nand_platform_data *pdata;
1099 struct resource *r; 1170 struct resource *r;
1100 int irq; 1171 int irq, cs;
1101 1172
1173 if (!info)
1174 return 0;
1175
1176 pdata = pdev->dev.platform_data;
1102 platform_set_drvdata(pdev, NULL); 1177 platform_set_drvdata(pdev, NULL);
1103 1178
1104 irq = platform_get_irq(pdev, 0); 1179 irq = platform_get_irq(pdev, 0);
@@ -1106,7 +1181,7 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1106 free_irq(irq, info); 1181 free_irq(irq, info);
1107 if (use_dma) { 1182 if (use_dma) {
1108 pxa_free_dma(info->data_dma_ch); 1183 pxa_free_dma(info->data_dma_ch);
1109 dma_free_writecombine(&pdev->dev, info->data_buff_size, 1184 dma_free_writecombine(&pdev->dev, MAX_BUFF_SIZE,
1110 info->data_buff, info->data_buff_phys); 1185 info->data_buff, info->data_buff_phys);
1111 } else 1186 } else
1112 kfree(info->data_buff); 1187 kfree(info->data_buff);
@@ -1118,10 +1193,9 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1118 clk_disable(info->clk); 1193 clk_disable(info->clk);
1119 clk_put(info->clk); 1194 clk_put(info->clk);
1120 1195
1121 if (mtd) { 1196 for (cs = 0; cs < pdata->num_cs; cs++)
1122 mtd_device_unregister(mtd); 1197 nand_release(info->host[cs]->mtd);
1123 kfree(mtd); 1198 kfree(info);
1124 }
1125 return 0; 1199 return 0;
1126} 1200}
1127 1201
@@ -1129,6 +1203,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1129{ 1203{
1130 struct pxa3xx_nand_platform_data *pdata; 1204 struct pxa3xx_nand_platform_data *pdata;
1131 struct pxa3xx_nand_info *info; 1205 struct pxa3xx_nand_info *info;
1206 int ret, cs, probe_success;
1132 1207
1133 pdata = pdev->dev.platform_data; 1208 pdata = pdev->dev.platform_data;
1134 if (!pdata) { 1209 if (!pdata) {
@@ -1136,52 +1211,88 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1136 return -ENODEV; 1211 return -ENODEV;
1137 } 1212 }
1138 1213
1139 info = alloc_nand_resource(pdev); 1214 ret = alloc_nand_resource(pdev);
1140 if (info == NULL) 1215 if (ret) {
1141 return -ENOMEM; 1216 dev_err(&pdev->dev, "alloc nand resource failed\n");
1142 1217 return ret;
1143 if (pxa3xx_nand_scan(info->mtd)) {
1144 dev_err(&pdev->dev, "failed to scan nand\n");
1145 pxa3xx_nand_remove(pdev);
1146 return -ENODEV;
1147 } 1218 }
1148 1219
1149 if (mtd_has_cmdlinepart()) { 1220 info = platform_get_drvdata(pdev);
1150 const char *probes[] = { "cmdlinepart", NULL }; 1221 probe_success = 0;
1151 struct mtd_partition *parts; 1222 for (cs = 0; cs < pdata->num_cs; cs++) {
1152 int nr_parts; 1223 info->cs = cs;
1224 ret = pxa3xx_nand_scan(info->host[cs]->mtd);
1225 if (ret) {
1226 dev_warn(&pdev->dev, "failed to scan nand at cs %d\n",
1227 cs);
1228 continue;
1229 }
1153 1230
1154 nr_parts = parse_mtd_partitions(info->mtd, probes, &parts, 0); 1231 ret = mtd_device_parse_register(info->host[cs]->mtd, NULL, 0,
1232 pdata->parts[cs], pdata->nr_parts[cs]);
1233 if (!ret)
1234 probe_success = 1;
1235 }
1155 1236
1156 if (nr_parts) 1237 if (!probe_success) {
1157 return mtd_device_register(info->mtd, parts, nr_parts); 1238 pxa3xx_nand_remove(pdev);
1239 return -ENODEV;
1158 } 1240 }
1159 1241
1160 return mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts); 1242 return 0;
1161} 1243}
1162 1244
1163#ifdef CONFIG_PM 1245#ifdef CONFIG_PM
1164static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state) 1246static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state)
1165{ 1247{
1166 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); 1248 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev);
1167 struct mtd_info *mtd = info->mtd; 1249 struct pxa3xx_nand_platform_data *pdata;
1250 struct mtd_info *mtd;
1251 int cs;
1168 1252
1253 pdata = pdev->dev.platform_data;
1169 if (info->state) { 1254 if (info->state) {
1170 dev_err(&pdev->dev, "driver busy, state = %d\n", info->state); 1255 dev_err(&pdev->dev, "driver busy, state = %d\n", info->state);
1171 return -EAGAIN; 1256 return -EAGAIN;
1172 } 1257 }
1173 1258
1259 for (cs = 0; cs < pdata->num_cs; cs++) {
1260 mtd = info->host[cs]->mtd;
1261 mtd->suspend(mtd);
1262 }
1263
1174 return 0; 1264 return 0;
1175} 1265}
1176 1266
1177static int pxa3xx_nand_resume(struct platform_device *pdev) 1267static int pxa3xx_nand_resume(struct platform_device *pdev)
1178{ 1268{
1179 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); 1269 struct pxa3xx_nand_info *info = platform_get_drvdata(pdev);
1180 struct mtd_info *mtd = info->mtd; 1270 struct pxa3xx_nand_platform_data *pdata;
1271 struct mtd_info *mtd;
1272 int cs;
1181 1273
1182 nand_writel(info, NDTR0CS0, info->ndtr0cs0); 1274 pdata = pdev->dev.platform_data;
1183 nand_writel(info, NDTR1CS0, info->ndtr1cs0); 1275 /* We don't want to handle interrupt without calling mtd routine */
1184 clk_enable(info->clk); 1276 disable_int(info, NDCR_INT_MASK);
1277
1278 /*
1279 * Directly set the chip select to a invalid value,
1280 * then the driver would reset the timing according
1281 * to current chip select at the beginning of cmdfunc
1282 */
1283 info->cs = 0xff;
1284
1285 /*
1286 * As the spec says, the NDSR would be updated to 0x1800 when
1287 * doing the nand_clk disable/enable.
1288 * To prevent it damaging state machine of the driver, clear
1289 * all status before resume
1290 */
1291 nand_writel(info, NDSR, NDSR_MASK);
1292 for (cs = 0; cs < pdata->num_cs; cs++) {
1293 mtd = info->host[cs]->mtd;
1294 mtd->resume(mtd);
1295 }
1185 1296
1186 return 0; 1297 return 0;
1187} 1298}
diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c
index cae2e013c98..f20f393bfda 100644
--- a/drivers/mtd/nand/r852.c
+++ b/drivers/mtd/nand/r852.c
@@ -1027,7 +1027,7 @@ void r852_shutdown(struct pci_dev *pci_dev)
1027} 1027}
1028 1028
1029#ifdef CONFIG_PM 1029#ifdef CONFIG_PM
1030int r852_suspend(struct device *device) 1030static int r852_suspend(struct device *device)
1031{ 1031{
1032 struct r852_device *dev = pci_get_drvdata(to_pci_dev(device)); 1032 struct r852_device *dev = pci_get_drvdata(to_pci_dev(device));
1033 1033
@@ -1048,7 +1048,7 @@ int r852_suspend(struct device *device)
1048 return 0; 1048 return 0;
1049} 1049}
1050 1050
1051int r852_resume(struct device *device) 1051static int r852_resume(struct device *device)
1052{ 1052{
1053 struct r852_device *dev = pci_get_drvdata(to_pci_dev(device)); 1053 struct r852_device *dev = pci_get_drvdata(to_pci_dev(device));
1054 1054
@@ -1092,7 +1092,7 @@ static const struct pci_device_id r852_pci_id_tbl[] = {
1092 1092
1093MODULE_DEVICE_TABLE(pci, r852_pci_id_tbl); 1093MODULE_DEVICE_TABLE(pci, r852_pci_id_tbl);
1094 1094
1095SIMPLE_DEV_PM_OPS(r852_pm_ops, r852_suspend, r852_resume); 1095static SIMPLE_DEV_PM_OPS(r852_pm_ops, r852_suspend, r852_resume);
1096 1096
1097static struct pci_driver r852_pci_driver = { 1097static struct pci_driver r852_pci_driver = {
1098 .name = DRV_NAME, 1098 .name = DRV_NAME,
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index c9f9127ff77..f309addc2fa 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -351,7 +351,7 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
351 return 0; 351 return 0;
352 } 352 }
353 353
354 /* Read the syndrom pattern from the FPGA and correct the bitorder */ 354 /* Read the syndrome pattern from the FPGA and correct the bitorder */
355 rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC); 355 rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC);
356 for (i = 0; i < 8; i++) { 356 for (i = 0; i < 8; i++) {
357 ecc[i] = bitrev8(*rs_ecc); 357 ecc[i] = bitrev8(*rs_ecc);
@@ -380,7 +380,7 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
380 /* Let the library code do its magic. */ 380 /* Let the library code do its magic. */
381 res = decode_rs8(rs_decoder, (uint8_t *) buf, par, 512, syn, 0, NULL, 0xff, NULL); 381 res = decode_rs8(rs_decoder, (uint8_t *) buf, par, 512, syn, 0, NULL, 0xff, NULL);
382 if (res > 0) { 382 if (res > 0) {
383 DEBUG(MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " "ECC corrected %d errors on read\n", res); 383 pr_debug("rtc_from4_correct_data: " "ECC corrected %d errors on read\n", res);
384 } 384 }
385 return res; 385 return res;
386} 386}
@@ -444,7 +444,6 @@ static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this,
444 len = mtd->writesize; 444 len = mtd->writesize;
445 buf = kmalloc(len, GFP_KERNEL); 445 buf = kmalloc(len, GFP_KERNEL);
446 if (!buf) { 446 if (!buf) {
447 printk(KERN_ERR "rtc_from4_errstat: Out of memory!\n");
448 er_stat = 1; 447 er_stat = 1;
449 goto out; 448 goto out;
450 } 449 }
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 4405468f196..868685db671 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -723,7 +723,7 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
723 723
724 /* free the common resources */ 724 /* free the common resources */
725 725
726 if (info->clk != NULL && !IS_ERR(info->clk)) { 726 if (!IS_ERR(info->clk)) {
727 s3c2410_nand_clk_set_state(info, CLOCK_DISABLE); 727 s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
728 clk_put(info->clk); 728 clk_put(info->clk);
729 } 729 }
@@ -744,26 +744,15 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
744 return 0; 744 return 0;
745} 745}
746 746
747const char *part_probes[] = { "cmdlinepart", NULL };
748static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info, 747static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
749 struct s3c2410_nand_mtd *mtd, 748 struct s3c2410_nand_mtd *mtd,
750 struct s3c2410_nand_set *set) 749 struct s3c2410_nand_set *set)
751{ 750{
752 struct mtd_partition *part_info; 751 if (set)
753 int nr_part = 0; 752 mtd->mtd.name = set->name;
754 753
755 if (set == NULL) 754 return mtd_device_parse_register(&mtd->mtd, NULL, 0,
756 return mtd_device_register(&mtd->mtd, NULL, 0); 755 set->partitions, set->nr_partitions);
757
758 mtd->mtd.name = set->name;
759 nr_part = parse_mtd_partitions(&mtd->mtd, part_probes, &part_info, 0);
760
761 if (nr_part <= 0 && set->nr_partitions > 0) {
762 nr_part = set->nr_partitions;
763 part_info = set->partitions;
764 }
765
766 return mtd_device_register(&mtd->mtd, part_info, nr_part);
767} 756}
768 757
769/** 758/**
@@ -880,8 +869,10 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
880 /* If you use u-boot BBT creation code, specifying this flag will 869 /* If you use u-boot BBT creation code, specifying this flag will
881 * let the kernel fish out the BBT from the NAND, and also skip the 870 * let the kernel fish out the BBT from the NAND, and also skip the
882 * full NAND scan that can take 1/2s or so. Little things... */ 871 * full NAND scan that can take 1/2s or so. Little things... */
883 if (set->flash_bbt) 872 if (set->flash_bbt) {
884 chip->options |= NAND_USE_FLASH_BBT | NAND_SKIP_BBTSCAN; 873 chip->bbt_options |= NAND_BBT_USE_FLASH;
874 chip->options |= NAND_SKIP_BBTSCAN;
875 }
885} 876}
886 877
887/** 878/**
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 19e24ed089e..619d2a50478 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -103,16 +103,12 @@ static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat,
103 return readb(sharpsl->io + ECCCNTR) != 0; 103 return readb(sharpsl->io + ECCCNTR) != 0;
104} 104}
105 105
106static const char *part_probes[] = { "cmdlinepart", NULL };
107
108/* 106/*
109 * Main initialization routine 107 * Main initialization routine
110 */ 108 */
111static int __devinit sharpsl_nand_probe(struct platform_device *pdev) 109static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
112{ 110{
113 struct nand_chip *this; 111 struct nand_chip *this;
114 struct mtd_partition *sharpsl_partition_info;
115 int nr_partitions;
116 struct resource *r; 112 struct resource *r;
117 int err = 0; 113 int err = 0;
118 struct sharpsl_nand *sharpsl; 114 struct sharpsl_nand *sharpsl;
@@ -184,14 +180,9 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
184 180
185 /* Register the partitions */ 181 /* Register the partitions */
186 sharpsl->mtd.name = "sharpsl-nand"; 182 sharpsl->mtd.name = "sharpsl-nand";
187 nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0);
188 if (nr_partitions <= 0) {
189 nr_partitions = data->nr_partitions;
190 sharpsl_partition_info = data->partitions;
191 }
192 183
193 err = mtd_device_register(&sharpsl->mtd, sharpsl_partition_info, 184 err = mtd_device_parse_register(&sharpsl->mtd, NULL, 0,
194 nr_partitions); 185 data->partitions, data->nr_partitions);
195 if (err) 186 if (err)
196 goto err_add; 187 goto err_add;
197 188
diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c
index b6332e83b28..32ae5af7444 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 = {
@@ -47,7 +48,7 @@ static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs)
47 48
48 /* As long as this function is called on erase block boundaries 49 /* As long as this function is called on erase block boundaries
49 it will work correctly for 256 byte nand */ 50 it will work correctly for 256 byte nand */
50 ops.mode = MTD_OOB_PLACE; 51 ops.mode = MTD_OPS_PLACE_OOB;
51 ops.ooboffs = 0; 52 ops.ooboffs = 0;
52 ops.ooblen = mtd->oobsize; 53 ops.ooblen = mtd->oobsize;
53 ops.oobbuf = (void *)&oob; 54 ops.oobbuf = (void *)&oob;
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index ca2d0555729..0fb24f9c232 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -155,8 +155,6 @@ static int socrates_nand_device_ready(struct mtd_info *mtd)
155 return 1; 155 return 1;
156} 156}
157 157
158static const char *part_probes[] = { "cmdlinepart", NULL };
159
160/* 158/*
161 * Probe for the NAND device. 159 * Probe for the NAND device.
162 */ 160 */
@@ -166,8 +164,7 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
166 struct mtd_info *mtd; 164 struct mtd_info *mtd;
167 struct nand_chip *nand_chip; 165 struct nand_chip *nand_chip;
168 int res; 166 int res;
169 struct mtd_partition *partitions = NULL; 167 struct mtd_part_parser_data ppdata;
170 int num_partitions = 0;
171 168
172 /* Allocate memory for the device structure (and zero it) */ 169 /* Allocate memory for the device structure (and zero it) */
173 host = kzalloc(sizeof(struct socrates_nand_host), GFP_KERNEL); 170 host = kzalloc(sizeof(struct socrates_nand_host), GFP_KERNEL);
@@ -193,6 +190,7 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
193 mtd->name = "socrates_nand"; 190 mtd->name = "socrates_nand";
194 mtd->owner = THIS_MODULE; 191 mtd->owner = THIS_MODULE;
195 mtd->dev.parent = &ofdev->dev; 192 mtd->dev.parent = &ofdev->dev;
193 ppdata.of_node = ofdev->dev.of_node;
196 194
197 /*should never be accessed directly */ 195 /*should never be accessed directly */
198 nand_chip->IO_ADDR_R = (void *)0xdeadbeef; 196 nand_chip->IO_ADDR_R = (void *)0xdeadbeef;
@@ -225,30 +223,10 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
225 goto out; 223 goto out;
226 } 224 }
227 225
228#ifdef CONFIG_MTD_CMDLINE_PARTS 226 res = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
229 num_partitions = parse_mtd_partitions(mtd, part_probes,
230 &partitions, 0);
231 if (num_partitions < 0) {
232 res = num_partitions;
233 goto release;
234 }
235#endif
236
237 if (num_partitions == 0) {
238 num_partitions = of_mtd_parse_partitions(&ofdev->dev,
239 ofdev->dev.of_node,
240 &partitions);
241 if (num_partitions < 0) {
242 res = num_partitions;
243 goto release;
244 }
245 }
246
247 res = mtd_device_register(mtd, partitions, num_partitions);
248 if (!res) 227 if (!res)
249 return res; 228 return res;
250 229
251release:
252 nand_release(mtd); 230 nand_release(mtd);
253 231
254out: 232out:
diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index 11e8371b568..beebd95f769 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -121,9 +121,6 @@ struct tmio_nand {
121 121
122#define mtd_to_tmio(m) container_of(m, struct tmio_nand, mtd) 122#define mtd_to_tmio(m) container_of(m, struct tmio_nand, mtd)
123 123
124#ifdef CONFIG_MTD_CMDLINE_PARTS
125static const char *part_probes[] = { "cmdlinepart", NULL };
126#endif
127 124
128/*--------------------------------------------------------------------------*/ 125/*--------------------------------------------------------------------------*/
129 126
@@ -381,8 +378,6 @@ static int tmio_probe(struct platform_device *dev)
381 struct tmio_nand *tmio; 378 struct tmio_nand *tmio;
382 struct mtd_info *mtd; 379 struct mtd_info *mtd;
383 struct nand_chip *nand_chip; 380 struct nand_chip *nand_chip;
384 struct mtd_partition *parts;
385 int nbparts = 0;
386 int retval; 381 int retval;
387 382
388 if (data == NULL) 383 if (data == NULL)
@@ -461,15 +456,9 @@ static int tmio_probe(struct platform_device *dev)
461 goto err_scan; 456 goto err_scan;
462 } 457 }
463 /* Register the partitions */ 458 /* Register the partitions */
464#ifdef CONFIG_MTD_CMDLINE_PARTS 459 retval = mtd_device_parse_register(mtd, NULL, 0,
465 nbparts = parse_mtd_partitions(mtd, part_probes, &parts, 0); 460 data ? data->partition : NULL,
466#endif 461 data ? data->num_partitions : 0);
467 if (nbparts <= 0 && data) {
468 parts = data->partition;
469 nbparts = data->num_partitions;
470 }
471
472 retval = mtd_device_register(mtd, parts, nbparts);
473 if (!retval) 462 if (!retval)
474 return retval; 463 return retval;
475 464
diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c
index bfba4e39a6c..ace46fdaef5 100644
--- a/drivers/mtd/nand/txx9ndfmc.c
+++ b/drivers/mtd/nand/txx9ndfmc.c
@@ -74,7 +74,6 @@ struct txx9ndfmc_drvdata {
74 unsigned char hold; /* in gbusclock */ 74 unsigned char hold; /* in gbusclock */
75 unsigned char spw; /* in gbusclock */ 75 unsigned char spw; /* in gbusclock */
76 struct nand_hw_control hw_control; 76 struct nand_hw_control hw_control;
77 struct mtd_partition *parts[MAX_TXX9NDFMC_DEV];
78}; 77};
79 78
80static struct platform_device *mtd_to_platdev(struct mtd_info *mtd) 79static struct platform_device *mtd_to_platdev(struct mtd_info *mtd)
@@ -287,7 +286,6 @@ static int txx9ndfmc_nand_scan(struct mtd_info *mtd)
287static int __init txx9ndfmc_probe(struct platform_device *dev) 286static int __init txx9ndfmc_probe(struct platform_device *dev)
288{ 287{
289 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data; 288 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data;
290 static const char *probes[] = { "cmdlinepart", NULL };
291 int hold, spw; 289 int hold, spw;
292 int i; 290 int i;
293 struct txx9ndfmc_drvdata *drvdata; 291 struct txx9ndfmc_drvdata *drvdata;
@@ -333,7 +331,6 @@ static int __init txx9ndfmc_probe(struct platform_device *dev)
333 struct txx9ndfmc_priv *txx9_priv; 331 struct txx9ndfmc_priv *txx9_priv;
334 struct nand_chip *chip; 332 struct nand_chip *chip;
335 struct mtd_info *mtd; 333 struct mtd_info *mtd;
336 int nr_parts;
337 334
338 if (!(plat->ch_mask & (1 << i))) 335 if (!(plat->ch_mask & (1 << i)))
339 continue; 336 continue;
@@ -393,9 +390,7 @@ static int __init txx9ndfmc_probe(struct platform_device *dev)
393 } 390 }
394 mtd->name = txx9_priv->mtdname; 391 mtd->name = txx9_priv->mtdname;
395 392
396 nr_parts = parse_mtd_partitions(mtd, probes, 393 mtd_device_parse_register(mtd, NULL, 0, NULL, 0);
397 &drvdata->parts[i], 0);
398 mtd_device_register(mtd, drvdata->parts[i], nr_parts);
399 drvdata->mtds[i] = mtd; 394 drvdata->mtds[i] = mtd;
400 } 395 }
401 396
@@ -421,7 +416,6 @@ static int __exit txx9ndfmc_remove(struct platform_device *dev)
421 txx9_priv = chip->priv; 416 txx9_priv = chip->priv;
422 417
423 nand_release(mtd); 418 nand_release(mtd);
424 kfree(drvdata->parts[i]);
425 kfree(txx9_priv->mtdname); 419 kfree(txx9_priv->mtdname);
426 kfree(txx9_priv); 420 kfree(txx9_priv);
427 } 421 }
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index b155666acfb..cda77b562ad 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -63,14 +63,12 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
63 return; 63 return;
64 } 64 }
65 65
66 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name); 66 pr_debug("NFTL: add_mtd for %s\n", mtd->name);
67 67
68 nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL); 68 nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
69 69
70 if (!nftl) { 70 if (!nftl)
71 printk(KERN_WARNING "NFTL: out of memory for data structures\n");
72 return; 71 return;
73 }
74 72
75 nftl->mbd.mtd = mtd; 73 nftl->mbd.mtd = mtd;
76 nftl->mbd.devnum = -1; 74 nftl->mbd.devnum = -1;
@@ -132,7 +130,7 @@ static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
132{ 130{
133 struct NFTLrecord *nftl = (void *)dev; 131 struct NFTLrecord *nftl = (void *)dev;
134 132
135 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: remove_dev (i=%d)\n", dev->devnum); 133 pr_debug("NFTL: remove_dev (i=%d)\n", dev->devnum);
136 134
137 del_mtd_blktrans_dev(dev); 135 del_mtd_blktrans_dev(dev);
138 kfree(nftl->ReplUnitTable); 136 kfree(nftl->ReplUnitTable);
@@ -149,7 +147,7 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
149 struct mtd_oob_ops ops; 147 struct mtd_oob_ops ops;
150 int res; 148 int res;
151 149
152 ops.mode = MTD_OOB_PLACE; 150 ops.mode = MTD_OPS_PLACE_OOB;
153 ops.ooboffs = offs & mask; 151 ops.ooboffs = offs & mask;
154 ops.ooblen = len; 152 ops.ooblen = len;
155 ops.oobbuf = buf; 153 ops.oobbuf = buf;
@@ -170,7 +168,7 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
170 struct mtd_oob_ops ops; 168 struct mtd_oob_ops ops;
171 int res; 169 int res;
172 170
173 ops.mode = MTD_OOB_PLACE; 171 ops.mode = MTD_OPS_PLACE_OOB;
174 ops.ooboffs = offs & mask; 172 ops.ooboffs = offs & mask;
175 ops.ooblen = len; 173 ops.ooblen = len;
176 ops.oobbuf = buf; 174 ops.oobbuf = buf;
@@ -193,7 +191,7 @@ static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len,
193 struct mtd_oob_ops ops; 191 struct mtd_oob_ops ops;
194 int res; 192 int res;
195 193
196 ops.mode = MTD_OOB_PLACE; 194 ops.mode = MTD_OPS_PLACE_OOB;
197 ops.ooboffs = offs & mask; 195 ops.ooboffs = offs & mask;
198 ops.ooblen = mtd->oobsize; 196 ops.ooblen = mtd->oobsize;
199 ops.oobbuf = oob; 197 ops.oobbuf = oob;
@@ -220,7 +218,7 @@ static u16 NFTL_findfreeblock(struct NFTLrecord *nftl, int desperate )
220 218
221 /* Normally, we force a fold to happen before we run out of free blocks completely */ 219 /* Normally, we force a fold to happen before we run out of free blocks completely */
222 if (!desperate && nftl->numfreeEUNs < 2) { 220 if (!desperate && nftl->numfreeEUNs < 2) {
223 DEBUG(MTD_DEBUG_LEVEL1, "NFTL_findfreeblock: there are too few free EUNs\n"); 221 pr_debug("NFTL_findfreeblock: there are too few free EUNs\n");
224 return BLOCK_NIL; 222 return BLOCK_NIL;
225 } 223 }
226 224
@@ -291,8 +289,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
291 if (block == 2) { 289 if (block == 2) {
292 foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1; 290 foldmark = oob.u.c.FoldMark | oob.u.c.FoldMark1;
293 if (foldmark == FOLD_MARK_IN_PROGRESS) { 291 if (foldmark == FOLD_MARK_IN_PROGRESS) {
294 DEBUG(MTD_DEBUG_LEVEL1, 292 pr_debug("Write Inhibited on EUN %d\n", thisEUN);
295 "Write Inhibited on EUN %d\n", thisEUN);
296 inplace = 0; 293 inplace = 0;
297 } else { 294 } else {
298 /* There's no other reason not to do inplace, 295 /* There's no other reason not to do inplace,
@@ -357,7 +354,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
357 if (BlockLastState[block] != SECTOR_FREE && 354 if (BlockLastState[block] != SECTOR_FREE &&
358 BlockMap[block] != BLOCK_NIL && 355 BlockMap[block] != BLOCK_NIL &&
359 BlockMap[block] != targetEUN) { 356 BlockMap[block] != targetEUN) {
360 DEBUG(MTD_DEBUG_LEVEL1, "Setting inplace to 0. VUC %d, " 357 pr_debug("Setting inplace to 0. VUC %d, "
361 "block %d was %x lastEUN, " 358 "block %d was %x lastEUN, "
362 "and is in EUN %d (%s) %d\n", 359 "and is in EUN %d (%s) %d\n",
363 thisVUC, block, BlockLastState[block], 360 thisVUC, block, BlockLastState[block],
@@ -373,14 +370,14 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
373 pendingblock < ((thisVUC + 1)* (nftl->EraseSize / 512)) && 370 pendingblock < ((thisVUC + 1)* (nftl->EraseSize / 512)) &&
374 BlockLastState[pendingblock - (thisVUC * (nftl->EraseSize / 512))] != 371 BlockLastState[pendingblock - (thisVUC * (nftl->EraseSize / 512))] !=
375 SECTOR_FREE) { 372 SECTOR_FREE) {
376 DEBUG(MTD_DEBUG_LEVEL1, "Pending write not free in EUN %d. " 373 pr_debug("Pending write not free in EUN %d. "
377 "Folding out of place.\n", targetEUN); 374 "Folding out of place.\n", targetEUN);
378 inplace = 0; 375 inplace = 0;
379 } 376 }
380 } 377 }
381 378
382 if (!inplace) { 379 if (!inplace) {
383 DEBUG(MTD_DEBUG_LEVEL1, "Cannot fold Virtual Unit Chain %d in place. " 380 pr_debug("Cannot fold Virtual Unit Chain %d in place. "
384 "Trying out-of-place\n", thisVUC); 381 "Trying out-of-place\n", thisVUC);
385 /* We need to find a targetEUN to fold into. */ 382 /* We need to find a targetEUN to fold into. */
386 targetEUN = NFTL_findfreeblock(nftl, 1); 383 targetEUN = NFTL_findfreeblock(nftl, 1);
@@ -410,7 +407,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
410 and the Erase Unit into which we are supposed to be copying. 407 and the Erase Unit into which we are supposed to be copying.
411 Go for it. 408 Go for it.
412 */ 409 */
413 DEBUG(MTD_DEBUG_LEVEL1,"Folding chain %d into unit %d\n", thisVUC, targetEUN); 410 pr_debug("Folding chain %d into unit %d\n", thisVUC, targetEUN);
414 for (block = 0; block < nftl->EraseSize / 512 ; block++) { 411 for (block = 0; block < nftl->EraseSize / 512 ; block++) {
415 unsigned char movebuf[512]; 412 unsigned char movebuf[512];
416 int ret; 413 int ret;
@@ -428,7 +425,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
428 425
429 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), 426 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512),
430 512, &retlen, movebuf); 427 512, &retlen, movebuf);
431 if (ret < 0 && ret != -EUCLEAN) { 428 if (ret < 0 && !mtd_is_bitflip(ret)) {
432 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) 429 ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block])
433 + (block * 512), 512, &retlen, 430 + (block * 512), 512, &retlen,
434 movebuf); 431 movebuf);
@@ -457,7 +454,7 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
457 has duplicate chains, we need to free one of the chains because it's not necessary any more. 454 has duplicate chains, we need to free one of the chains because it's not necessary any more.
458 */ 455 */
459 thisEUN = nftl->EUNtable[thisVUC]; 456 thisEUN = nftl->EUNtable[thisVUC];
460 DEBUG(MTD_DEBUG_LEVEL1,"Want to erase\n"); 457 pr_debug("Want to erase\n");
461 458
462 /* For each block in the old chain (except the targetEUN of course), 459 /* For each block in the old chain (except the targetEUN of course),
463 free it and make it available for future use */ 460 free it and make it available for future use */
@@ -570,7 +567,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
570 (writeEUN * nftl->EraseSize) + blockofs, 567 (writeEUN * nftl->EraseSize) + blockofs,
571 8, &retlen, (char *)&bci); 568 8, &retlen, (char *)&bci);
572 569
573 DEBUG(MTD_DEBUG_LEVEL2, "Status of block %d in EUN %d is %x\n", 570 pr_debug("Status of block %d in EUN %d is %x\n",
574 block , writeEUN, le16_to_cpu(bci.Status)); 571 block , writeEUN, le16_to_cpu(bci.Status));
575 572
576 status = bci.Status | bci.Status1; 573 status = bci.Status | bci.Status1;
@@ -623,7 +620,7 @@ static inline u16 NFTL_findwriteunit(struct NFTLrecord *nftl, unsigned block)
623 but they are reserved for when we're 620 but they are reserved for when we're
624 desperate. Well, now we're desperate. 621 desperate. Well, now we're desperate.
625 */ 622 */
626 DEBUG(MTD_DEBUG_LEVEL1, "Using desperate==1 to find free EUN to accommodate write to VUC %d\n", thisVUC); 623 pr_debug("Using desperate==1 to find free EUN to accommodate write to VUC %d\n", thisVUC);
627 writeEUN = NFTL_findfreeblock(nftl, 1); 624 writeEUN = NFTL_findfreeblock(nftl, 1);
628 } 625 }
629 if (writeEUN == BLOCK_NIL) { 626 if (writeEUN == BLOCK_NIL) {
@@ -776,7 +773,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block,
776 size_t retlen; 773 size_t retlen;
777 int res = mtd->read(mtd, ptr, 512, &retlen, buffer); 774 int res = mtd->read(mtd, ptr, 512, &retlen, buffer);
778 775
779 if (res < 0 && res != -EUCLEAN) 776 if (res < 0 && !mtd_is_bitflip(res))
780 return -EIO; 777 return -EIO;
781 } 778 }
782 return 0; 779 return 0;
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index e3cd1ffad2f..ac4092591ae 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -32,7 +32,7 @@
32 32
33/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the 33/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the
34 * various device information of the NFTL partition and Bad Unit Table. Update 34 * various device information of the NFTL partition and Bad Unit Table. Update
35 * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[] 35 * the ReplUnitTable[] table according to the Bad Unit Table. ReplUnitTable[]
36 * is used for management of Erase Unit in other routines in nftl.c and nftlmount.c 36 * is used for management of Erase Unit in other routines in nftl.c and nftlmount.c
37 */ 37 */
38static int find_boot_record(struct NFTLrecord *nftl) 38static int find_boot_record(struct NFTLrecord *nftl)
@@ -297,7 +297,7 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int
297 * 297 *
298 * Return: 0 when succeed, -1 on error. 298 * Return: 0 when succeed, -1 on error.
299 * 299 *
300 * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? 300 * ToDo: 1. Is it necessary to check_free_sector after erasing ??
301 */ 301 */
302int NFTL_formatblock(struct NFTLrecord *nftl, int block) 302int NFTL_formatblock(struct NFTLrecord *nftl, int block)
303{ 303{
@@ -337,7 +337,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
337 nb_erases = le32_to_cpu(uci.WearInfo); 337 nb_erases = le32_to_cpu(uci.WearInfo);
338 nb_erases++; 338 nb_erases++;
339 339
340 /* wrap (almost impossible with current flashs) or free block */ 340 /* wrap (almost impossible with current flash) or free block */
341 if (nb_erases == 0) 341 if (nb_erases == 0)
342 nb_erases = 1; 342 nb_erases = 1;
343 343
@@ -363,10 +363,10 @@ fail:
363 * Mark as 'IGNORE' each incorrect sector. This check is only done if the chain 363 * Mark as 'IGNORE' each incorrect sector. This check is only done if the chain
364 * was being folded when NFTL was interrupted. 364 * was being folded when NFTL was interrupted.
365 * 365 *
366 * The check_free_sectors in this function is neceressary. There is a possible 366 * The check_free_sectors in this function is necessary. There is a possible
367 * situation that after writing the Data area, the Block Control Information is 367 * situation that after writing the Data area, the Block Control Information is
368 * not updated according (due to power failure or something) which leaves the block 368 * not updated according (due to power failure or something) which leaves the block
369 * in an umconsistent state. So we have to check if a block is really FREE in this 369 * in an inconsistent state. So we have to check if a block is really FREE in this
370 * case. */ 370 * case. */
371static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_block) 371static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_block)
372{ 372{
@@ -428,7 +428,7 @@ static int calc_chain_length(struct NFTLrecord *nftl, unsigned int first_block)
428 428
429 for (;;) { 429 for (;;) {
430 length++; 430 length++;
431 /* avoid infinite loops, although this is guaranted not to 431 /* avoid infinite loops, although this is guaranteed not to
432 happen because of the previous checks */ 432 happen because of the previous checks */
433 if (length >= nftl->nb_blocks) { 433 if (length >= nftl->nb_blocks) {
434 printk("nftl: length too long %d !\n", length); 434 printk("nftl: length too long %d !\n", length);
@@ -447,11 +447,11 @@ static int calc_chain_length(struct NFTLrecord *nftl, unsigned int first_block)
447/* format_chain: Format an invalid Virtual Unit chain. It frees all the Erase Units in a 447/* format_chain: Format an invalid Virtual Unit chain. It frees all the Erase Units in a
448 * Virtual Unit Chain, i.e. all the units are disconnected. 448 * Virtual Unit Chain, i.e. all the units are disconnected.
449 * 449 *
450 * It is not stricly correct to begin from the first block of the chain because 450 * It is not strictly correct to begin from the first block of the chain because
451 * if we stop the code, we may see again a valid chain if there was a first_block 451 * if we stop the code, we may see again a valid chain if there was a first_block
452 * flag in a block inside it. But is it really a problem ? 452 * flag in a block inside it. But is it really a problem ?
453 * 453 *
454 * FixMe: Figure out what the last statesment means. What if power failure when we are 454 * FixMe: Figure out what the last statement means. What if power failure when we are
455 * in the for (;;) loop formatting blocks ?? 455 * in the for (;;) loop formatting blocks ??
456 */ 456 */
457static void format_chain(struct NFTLrecord *nftl, unsigned int first_block) 457static void format_chain(struct NFTLrecord *nftl, unsigned int first_block)
@@ -485,7 +485,7 @@ static void format_chain(struct NFTLrecord *nftl, unsigned int first_block)
485 * totally free (only 0xff). 485 * totally free (only 0xff).
486 * 486 *
487 * Definition: Free Erase Unit -- A properly erased/formatted Free Erase Unit should have meet the 487 * Definition: Free Erase Unit -- A properly erased/formatted Free Erase Unit should have meet the
488 * following critia: 488 * following criteria:
489 * 1. */ 489 * 1. */
490static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) 490static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
491{ 491{
@@ -502,7 +502,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
502 erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1)); 502 erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1));
503 if (erase_mark != ERASE_MARK) { 503 if (erase_mark != ERASE_MARK) {
504 /* if no erase mark, the block must be totally free. This is 504 /* if no erase mark, the block must be totally free. This is
505 possible in two cases : empty filsystem or interrupted erase (very unlikely) */ 505 possible in two cases : empty filesystem or interrupted erase (very unlikely) */
506 if (check_free_sectors (nftl, block * nftl->EraseSize, nftl->EraseSize, 1) != 0) 506 if (check_free_sectors (nftl, block * nftl->EraseSize, nftl->EraseSize, 1) != 0)
507 return -1; 507 return -1;
508 508
@@ -544,7 +544,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
544/* get_fold_mark: Read fold mark from Unit Control Information #2, we use FOLD_MARK_IN_PROGRESS 544/* get_fold_mark: Read fold mark from Unit Control Information #2, we use FOLD_MARK_IN_PROGRESS
545 * to indicate that we are in the progression of a Virtual Unit Chain folding. If the UCI #2 545 * to indicate that we are in the progression of a Virtual Unit Chain folding. If the UCI #2
546 * is FOLD_MARK_IN_PROGRESS when mounting the NFTL, the (previous) folding process is interrupted 546 * is FOLD_MARK_IN_PROGRESS when mounting the NFTL, the (previous) folding process is interrupted
547 * for some reason. A clean up/check of the VUC is neceressary in this case. 547 * for some reason. A clean up/check of the VUC is necessary in this case.
548 * 548 *
549 * WARNING: return 0 if read error 549 * WARNING: return 0 if read error
550 */ 550 */
@@ -657,7 +657,7 @@ int NFTL_mount(struct NFTLrecord *s)
657 printk("Block %d: incorrect logical block: %d expected: %d\n", 657 printk("Block %d: incorrect logical block: %d expected: %d\n",
658 block, logical_block, first_logical_block); 658 block, logical_block, first_logical_block);
659 /* the chain is incorrect : we must format it, 659 /* the chain is incorrect : we must format it,
660 but we need to read it completly */ 660 but we need to read it completely */
661 do_format_chain = 1; 661 do_format_chain = 1;
662 } 662 }
663 if (is_first_block) { 663 if (is_first_block) {
@@ -669,7 +669,7 @@ int NFTL_mount(struct NFTLrecord *s)
669 printk("Block %d: incorrectly marked as first block in chain\n", 669 printk("Block %d: incorrectly marked as first block in chain\n",
670 block); 670 block);
671 /* the chain is incorrect : we must format it, 671 /* the chain is incorrect : we must format it,
672 but we need to read it completly */ 672 but we need to read it completely */
673 do_format_chain = 1; 673 do_format_chain = 1;
674 } else { 674 } else {
675 printk("Block %d: folding in progress - ignoring first block flag\n", 675 printk("Block %d: folding in progress - ignoring first block flag\n",
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index a996718fa6b..64be8f0848b 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -20,14 +20,23 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/mtd/partitions.h> 21#include <linux/mtd/partitions.h>
22 22
23int __devinit of_mtd_parse_partitions(struct device *dev, 23static int parse_ofpart_partitions(struct mtd_info *master,
24 struct device_node *node, 24 struct mtd_partition **pparts,
25 struct mtd_partition **pparts) 25 struct mtd_part_parser_data *data)
26{ 26{
27 struct device_node *node;
27 const char *partname; 28 const char *partname;
28 struct device_node *pp; 29 struct device_node *pp;
29 int nr_parts, i; 30 int nr_parts, i;
30 31
32
33 if (!data)
34 return 0;
35
36 node = data->of_node;
37 if (!node)
38 return 0;
39
31 /* First count the subnodes */ 40 /* First count the subnodes */
32 pp = NULL; 41 pp = NULL;
33 nr_parts = 0; 42 nr_parts = 0;
@@ -69,7 +78,7 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
69 78
70 if (!i) { 79 if (!i) {
71 of_node_put(pp); 80 of_node_put(pp);
72 dev_err(dev, "No valid partition found on %s\n", node->full_name); 81 pr_err("No valid partition found on %s\n", node->full_name);
73 kfree(*pparts); 82 kfree(*pparts);
74 *pparts = NULL; 83 *pparts = NULL;
75 return -EINVAL; 84 return -EINVAL;
@@ -77,6 +86,99 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
77 86
78 return nr_parts; 87 return nr_parts;
79} 88}
80EXPORT_SYMBOL(of_mtd_parse_partitions); 89
90static struct mtd_part_parser ofpart_parser = {
91 .owner = THIS_MODULE,
92 .parse_fn = parse_ofpart_partitions,
93 .name = "ofpart",
94};
95
96static int parse_ofoldpart_partitions(struct mtd_info *master,
97 struct mtd_partition **pparts,
98 struct mtd_part_parser_data *data)
99{
100 struct device_node *dp;
101 int i, plen, nr_parts;
102 const struct {
103 __be32 offset, len;
104 } *part;
105 const char *names;
106
107 if (!data)
108 return 0;
109
110 dp = data->of_node;
111 if (!dp)
112 return 0;
113
114 part = of_get_property(dp, "partitions", &plen);
115 if (!part)
116 return 0; /* No partitions found */
117
118 pr_warning("Device tree uses obsolete partition map binding: %s\n",
119 dp->full_name);
120
121 nr_parts = plen / sizeof(part[0]);
122
123 *pparts = kzalloc(nr_parts * sizeof(*(*pparts)), GFP_KERNEL);
124 if (!pparts)
125 return -ENOMEM;
126
127 names = of_get_property(dp, "partition-names", &plen);
128
129 for (i = 0; i < nr_parts; i++) {
130 (*pparts)[i].offset = be32_to_cpu(part->offset);
131 (*pparts)[i].size = be32_to_cpu(part->len) & ~1;
132 /* bit 0 set signifies read only partition */
133 if (be32_to_cpu(part->len) & 1)
134 (*pparts)[i].mask_flags = MTD_WRITEABLE;
135
136 if (names && (plen > 0)) {
137 int len = strlen(names) + 1;
138
139 (*pparts)[i].name = (char *)names;
140 plen -= len;
141 names += len;
142 } else {
143 (*pparts)[i].name = "unnamed";
144 }
145
146 part++;
147 }
148
149 return nr_parts;
150}
151
152static struct mtd_part_parser ofoldpart_parser = {
153 .owner = THIS_MODULE,
154 .parse_fn = parse_ofoldpart_partitions,
155 .name = "ofoldpart",
156};
157
158static int __init ofpart_parser_init(void)
159{
160 int rc;
161 rc = register_mtd_parser(&ofpart_parser);
162 if (rc)
163 goto out;
164
165 rc = register_mtd_parser(&ofoldpart_parser);
166 if (!rc)
167 return 0;
168
169 deregister_mtd_parser(&ofoldpart_parser);
170out:
171 return rc;
172}
173
174module_init(ofpart_parser_init);
81 175
82MODULE_LICENSE("GPL"); 176MODULE_LICENSE("GPL");
177MODULE_DESCRIPTION("Parser for MTD partitioning information in device tree");
178MODULE_AUTHOR("Vitaly Wool, David Gibson");
179/*
180 * When MTD core cannot find the requested parser, it tries to load the module
181 * with the same name. Since we provide the ofoldpart parser, we should have
182 * the corresponding alias.
183 */
184MODULE_ALIAS("ofoldpart");
diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c
index 2d70d354d84..7813095264a 100644
--- a/drivers/mtd/onenand/generic.c
+++ b/drivers/mtd/onenand/generic.c
@@ -30,11 +30,8 @@
30 */ 30 */
31#define DRIVER_NAME "onenand-flash" 31#define DRIVER_NAME "onenand-flash"
32 32
33static const char *part_probes[] = { "cmdlinepart", NULL, };
34
35struct onenand_info { 33struct onenand_info {
36 struct mtd_info mtd; 34 struct mtd_info mtd;
37 struct mtd_partition *parts;
38 struct onenand_chip onenand; 35 struct onenand_chip onenand;
39}; 36};
40 37
@@ -73,13 +70,9 @@ static int __devinit generic_onenand_probe(struct platform_device *pdev)
73 goto out_iounmap; 70 goto out_iounmap;
74 } 71 }
75 72
76 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); 73 err = mtd_device_parse_register(&info->mtd, NULL, 0,
77 if (err > 0) 74 pdata ? pdata->parts : NULL,
78 mtd_device_register(&info->mtd, info->parts, err); 75 pdata ? pdata->nr_parts : 0);
79 else if (err <= 0 && pdata && pdata->parts)
80 mtd_device_register(&info->mtd, pdata->parts, pdata->nr_parts);
81 else
82 err = mtd_device_register(&info->mtd, NULL, 0);
83 76
84 platform_set_drvdata(pdev, info); 77 platform_set_drvdata(pdev, info);
85 78
@@ -104,7 +97,6 @@ static int __devexit generic_onenand_remove(struct platform_device *pdev)
104 platform_set_drvdata(pdev, NULL); 97 platform_set_drvdata(pdev, NULL);
105 98
106 if (info) { 99 if (info) {
107 mtd_device_unregister(&info->mtd);
108 onenand_release(&info->mtd); 100 onenand_release(&info->mtd);
109 release_mem_region(res->start, size); 101 release_mem_region(res->start, size);
110 iounmap(info->onenand.base); 102 iounmap(info->onenand.base);
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c
index 6a1d6d9a2df..7e9ea6852b6 100644
--- a/drivers/mtd/onenand/omap2.c
+++ b/drivers/mtd/onenand/omap2.c
@@ -57,7 +57,6 @@ struct omap2_onenand {
57 unsigned long phys_base; 57 unsigned long phys_base;
58 int gpio_irq; 58 int gpio_irq;
59 struct mtd_info mtd; 59 struct mtd_info mtd;
60 struct mtd_partition *parts;
61 struct onenand_chip onenand; 60 struct onenand_chip onenand;
62 struct completion irq_done; 61 struct completion irq_done;
63 struct completion dma_done; 62 struct completion dma_done;
@@ -67,8 +66,6 @@ struct omap2_onenand {
67 struct regulator *regulator; 66 struct regulator *regulator;
68}; 67};
69 68
70static const char *part_probes[] = { "cmdlinepart", NULL, };
71
72static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data) 69static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data)
73{ 70{
74 struct omap2_onenand *c = data; 71 struct omap2_onenand *c = data;
@@ -741,6 +738,7 @@ static int __devinit omap2_onenand_probe(struct platform_device *pdev)
741 c->regulator = regulator_get(&pdev->dev, "vonenand"); 738 c->regulator = regulator_get(&pdev->dev, "vonenand");
742 if (IS_ERR(c->regulator)) { 739 if (IS_ERR(c->regulator)) {
743 dev_err(&pdev->dev, "Failed to get regulator\n"); 740 dev_err(&pdev->dev, "Failed to get regulator\n");
741 r = PTR_ERR(c->regulator);
744 goto err_release_dma; 742 goto err_release_dma;
745 } 743 }
746 c->onenand.enable = omap2_onenand_enable; 744 c->onenand.enable = omap2_onenand_enable;
@@ -753,13 +751,9 @@ static int __devinit omap2_onenand_probe(struct platform_device *pdev)
753 if ((r = onenand_scan(&c->mtd, 1)) < 0) 751 if ((r = onenand_scan(&c->mtd, 1)) < 0)
754 goto err_release_regulator; 752 goto err_release_regulator;
755 753
756 r = parse_mtd_partitions(&c->mtd, part_probes, &c->parts, 0); 754 r = mtd_device_parse_register(&c->mtd, NULL, 0,
757 if (r > 0) 755 pdata ? pdata->parts : NULL,
758 r = mtd_device_register(&c->mtd, c->parts, r); 756 pdata ? pdata->nr_parts : 0);
759 else if (pdata->parts != NULL)
760 r = mtd_device_register(&c->mtd, pdata->parts, pdata->nr_parts);
761 else
762 r = mtd_device_register(&c->mtd, NULL, 0);
763 if (r) 757 if (r)
764 goto err_release_onenand; 758 goto err_release_onenand;
765 759
@@ -786,7 +780,6 @@ err_release_mem_region:
786err_free_cs: 780err_free_cs:
787 gpmc_cs_free(c->gpmc_cs); 781 gpmc_cs_free(c->gpmc_cs);
788err_kfree: 782err_kfree:
789 kfree(c->parts);
790 kfree(c); 783 kfree(c);
791 784
792 return r; 785 return r;
@@ -809,7 +802,6 @@ static int __devexit omap2_onenand_remove(struct platform_device *pdev)
809 iounmap(c->onenand.base); 802 iounmap(c->onenand.base);
810 release_mem_region(c->phys_base, ONENAND_IO_SIZE); 803 release_mem_region(c->phys_base, ONENAND_IO_SIZE);
811 gpmc_cs_free(c->gpmc_cs); 804 gpmc_cs_free(c->gpmc_cs);
812 kfree(c->parts);
813 kfree(c); 805 kfree(c);
814 806
815 return 0; 807 return 0;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index ac9e959802a..a8394730b4b 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1015,7 +1015,7 @@ static void onenand_release_device(struct mtd_info *mtd)
1015} 1015}
1016 1016
1017/** 1017/**
1018 * onenand_transfer_auto_oob - [Internal] oob auto-placement transfer 1018 * onenand_transfer_auto_oob - [INTERN] oob auto-placement transfer
1019 * @param mtd MTD device structure 1019 * @param mtd MTD device structure
1020 * @param buf destination address 1020 * @param buf destination address
1021 * @param column oob offset to read from 1021 * @param column oob offset to read from
@@ -1079,7 +1079,7 @@ static int onenand_recover_lsb(struct mtd_info *mtd, loff_t addr, int status)
1079 return status; 1079 return status;
1080 1080
1081 /* check if we failed due to uncorrectable error */ 1081 /* check if we failed due to uncorrectable error */
1082 if (status != -EBADMSG && status != ONENAND_BBT_READ_ECC_ERROR) 1082 if (!mtd_is_eccerr(status) && status != ONENAND_BBT_READ_ECC_ERROR)
1083 return status; 1083 return status;
1084 1084
1085 /* check if address lies in MLC region */ 1085 /* check if address lies in MLC region */
@@ -1122,10 +1122,10 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1122 int ret = 0; 1122 int ret = 0;
1123 int writesize = this->writesize; 1123 int writesize = this->writesize;
1124 1124
1125 DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %i\n", 1125 pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
1126 __func__, (unsigned int) from, (int) len); 1126 (int)len);
1127 1127
1128 if (ops->mode == MTD_OOB_AUTO) 1128 if (ops->mode == MTD_OPS_AUTO_OOB)
1129 oobsize = this->ecclayout->oobavail; 1129 oobsize = this->ecclayout->oobavail;
1130 else 1130 else
1131 oobsize = mtd->oobsize; 1131 oobsize = mtd->oobsize;
@@ -1159,7 +1159,7 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1159 if (unlikely(ret)) 1159 if (unlikely(ret))
1160 ret = onenand_recover_lsb(mtd, from, ret); 1160 ret = onenand_recover_lsb(mtd, from, ret);
1161 onenand_update_bufferram(mtd, from, !ret); 1161 onenand_update_bufferram(mtd, from, !ret);
1162 if (ret == -EBADMSG) 1162 if (mtd_is_eccerr(ret))
1163 ret = 0; 1163 ret = 0;
1164 if (ret) 1164 if (ret)
1165 break; 1165 break;
@@ -1170,7 +1170,7 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1170 thisooblen = oobsize - oobcolumn; 1170 thisooblen = oobsize - oobcolumn;
1171 thisooblen = min_t(int, thisooblen, ooblen - oobread); 1171 thisooblen = min_t(int, thisooblen, ooblen - oobread);
1172 1172
1173 if (ops->mode == MTD_OOB_AUTO) 1173 if (ops->mode == MTD_OPS_AUTO_OOB)
1174 onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen); 1174 onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen);
1175 else 1175 else
1176 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); 1176 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen);
@@ -1226,10 +1226,10 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1226 int ret = 0, boundary = 0; 1226 int ret = 0, boundary = 0;
1227 int writesize = this->writesize; 1227 int writesize = this->writesize;
1228 1228
1229 DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %i\n", 1229 pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
1230 __func__, (unsigned int) from, (int) len); 1230 (int)len);
1231 1231
1232 if (ops->mode == MTD_OOB_AUTO) 1232 if (ops->mode == MTD_OPS_AUTO_OOB)
1233 oobsize = this->ecclayout->oobavail; 1233 oobsize = this->ecclayout->oobavail;
1234 else 1234 else
1235 oobsize = mtd->oobsize; 1235 oobsize = mtd->oobsize;
@@ -1255,7 +1255,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1255 this->command(mtd, ONENAND_CMD_READ, from, writesize); 1255 this->command(mtd, ONENAND_CMD_READ, from, writesize);
1256 ret = this->wait(mtd, FL_READING); 1256 ret = this->wait(mtd, FL_READING);
1257 onenand_update_bufferram(mtd, from, !ret); 1257 onenand_update_bufferram(mtd, from, !ret);
1258 if (ret == -EBADMSG) 1258 if (mtd_is_eccerr(ret))
1259 ret = 0; 1259 ret = 0;
1260 } 1260 }
1261 } 1261 }
@@ -1291,7 +1291,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1291 thisooblen = oobsize - oobcolumn; 1291 thisooblen = oobsize - oobcolumn;
1292 thisooblen = min_t(int, thisooblen, ooblen - oobread); 1292 thisooblen = min_t(int, thisooblen, ooblen - oobread);
1293 1293
1294 if (ops->mode == MTD_OOB_AUTO) 1294 if (ops->mode == MTD_OPS_AUTO_OOB)
1295 onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen); 1295 onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen);
1296 else 1296 else
1297 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); 1297 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen);
@@ -1315,7 +1315,7 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1315 /* Now wait for load */ 1315 /* Now wait for load */
1316 ret = this->wait(mtd, FL_READING); 1316 ret = this->wait(mtd, FL_READING);
1317 onenand_update_bufferram(mtd, from, !ret); 1317 onenand_update_bufferram(mtd, from, !ret);
1318 if (ret == -EBADMSG) 1318 if (mtd_is_eccerr(ret))
1319 ret = 0; 1319 ret = 0;
1320 } 1320 }
1321 1321
@@ -1351,19 +1351,19 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from,
1351 struct mtd_ecc_stats stats; 1351 struct mtd_ecc_stats stats;
1352 int read = 0, thislen, column, oobsize; 1352 int read = 0, thislen, column, oobsize;
1353 size_t len = ops->ooblen; 1353 size_t len = ops->ooblen;
1354 mtd_oob_mode_t mode = ops->mode; 1354 unsigned int mode = ops->mode;
1355 u_char *buf = ops->oobbuf; 1355 u_char *buf = ops->oobbuf;
1356 int ret = 0, readcmd; 1356 int ret = 0, readcmd;
1357 1357
1358 from += ops->ooboffs; 1358 from += ops->ooboffs;
1359 1359
1360 DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %i\n", 1360 pr_debug("%s: from = 0x%08x, len = %i\n", __func__, (unsigned int)from,
1361 __func__, (unsigned int) from, (int) len); 1361 (int)len);
1362 1362
1363 /* Initialize return length value */ 1363 /* Initialize return length value */
1364 ops->oobretlen = 0; 1364 ops->oobretlen = 0;
1365 1365
1366 if (mode == MTD_OOB_AUTO) 1366 if (mode == MTD_OPS_AUTO_OOB)
1367 oobsize = this->ecclayout->oobavail; 1367 oobsize = this->ecclayout->oobavail;
1368 else 1368 else
1369 oobsize = mtd->oobsize; 1369 oobsize = mtd->oobsize;
@@ -1403,13 +1403,13 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from,
1403 if (unlikely(ret)) 1403 if (unlikely(ret))
1404 ret = onenand_recover_lsb(mtd, from, ret); 1404 ret = onenand_recover_lsb(mtd, from, ret);
1405 1405
1406 if (ret && ret != -EBADMSG) { 1406 if (ret && !mtd_is_eccerr(ret)) {
1407 printk(KERN_ERR "%s: read failed = 0x%x\n", 1407 printk(KERN_ERR "%s: read failed = 0x%x\n",
1408 __func__, ret); 1408 __func__, ret);
1409 break; 1409 break;
1410 } 1410 }
1411 1411
1412 if (mode == MTD_OOB_AUTO) 1412 if (mode == MTD_OPS_AUTO_OOB)
1413 onenand_transfer_auto_oob(mtd, buf, column, thislen); 1413 onenand_transfer_auto_oob(mtd, buf, column, thislen);
1414 else 1414 else
1415 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); 1415 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
@@ -1487,10 +1487,10 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
1487 int ret; 1487 int ret;
1488 1488
1489 switch (ops->mode) { 1489 switch (ops->mode) {
1490 case MTD_OOB_PLACE: 1490 case MTD_OPS_PLACE_OOB:
1491 case MTD_OOB_AUTO: 1491 case MTD_OPS_AUTO_OOB:
1492 break; 1492 break;
1493 case MTD_OOB_RAW: 1493 case MTD_OPS_RAW:
1494 /* Not implemented yet */ 1494 /* Not implemented yet */
1495 default: 1495 default:
1496 return -EINVAL; 1496 return -EINVAL;
@@ -1576,8 +1576,8 @@ int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
1576 size_t len = ops->ooblen; 1576 size_t len = ops->ooblen;
1577 u_char *buf = ops->oobbuf; 1577 u_char *buf = ops->oobbuf;
1578 1578
1579 DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %zi\n", 1579 pr_debug("%s: from = 0x%08x, len = %zi\n", __func__, (unsigned int)from,
1580 __func__, (unsigned int) from, len); 1580 len);
1581 1581
1582 /* Initialize return value */ 1582 /* Initialize return value */
1583 ops->oobretlen = 0; 1583 ops->oobretlen = 0;
@@ -1750,8 +1750,8 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
1750 /* Wait for any existing operation to clear */ 1750 /* Wait for any existing operation to clear */
1751 onenand_panic_wait(mtd); 1751 onenand_panic_wait(mtd);
1752 1752
1753 DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", 1753 pr_debug("%s: to = 0x%08x, len = %i\n", __func__, (unsigned int)to,
1754 __func__, (unsigned int) to, (int) len); 1754 (int)len);
1755 1755
1756 /* Initialize retlen, in case of early exit */ 1756 /* Initialize retlen, in case of early exit */
1757 *retlen = 0; 1757 *retlen = 0;
@@ -1821,7 +1821,7 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
1821} 1821}
1822 1822
1823/** 1823/**
1824 * onenand_fill_auto_oob - [Internal] oob auto-placement transfer 1824 * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer
1825 * @param mtd MTD device structure 1825 * @param mtd MTD device structure
1826 * @param oob_buf oob buffer 1826 * @param oob_buf oob buffer
1827 * @param buf source address 1827 * @param buf source address
@@ -1883,8 +1883,8 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1883 u_char *oobbuf; 1883 u_char *oobbuf;
1884 int ret = 0, cmd; 1884 int ret = 0, cmd;
1885 1885
1886 DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", 1886 pr_debug("%s: to = 0x%08x, len = %i\n", __func__, (unsigned int)to,
1887 __func__, (unsigned int) to, (int) len); 1887 (int)len);
1888 1888
1889 /* Initialize retlen, in case of early exit */ 1889 /* Initialize retlen, in case of early exit */
1890 ops->retlen = 0; 1890 ops->retlen = 0;
@@ -1908,7 +1908,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1908 if (!len) 1908 if (!len)
1909 return 0; 1909 return 0;
1910 1910
1911 if (ops->mode == MTD_OOB_AUTO) 1911 if (ops->mode == MTD_OPS_AUTO_OOB)
1912 oobsize = this->ecclayout->oobavail; 1912 oobsize = this->ecclayout->oobavail;
1913 else 1913 else
1914 oobsize = mtd->oobsize; 1914 oobsize = mtd->oobsize;
@@ -1945,7 +1945,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1945 /* We send data to spare ram with oobsize 1945 /* We send data to spare ram with oobsize
1946 * to prevent byte access */ 1946 * to prevent byte access */
1947 memset(oobbuf, 0xff, mtd->oobsize); 1947 memset(oobbuf, 0xff, mtd->oobsize);
1948 if (ops->mode == MTD_OOB_AUTO) 1948 if (ops->mode == MTD_OPS_AUTO_OOB)
1949 onenand_fill_auto_oob(mtd, oobbuf, oob, oobcolumn, thisooblen); 1949 onenand_fill_auto_oob(mtd, oobbuf, oob, oobcolumn, thisooblen);
1950 else 1950 else
1951 memcpy(oobbuf + oobcolumn, oob, thisooblen); 1951 memcpy(oobbuf + oobcolumn, oob, thisooblen);
@@ -2055,7 +2055,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
2055 2055
2056 2056
2057/** 2057/**
2058 * onenand_write_oob_nolock - [Internal] OneNAND write out-of-band 2058 * onenand_write_oob_nolock - [INTERN] OneNAND write out-of-band
2059 * @param mtd MTD device structure 2059 * @param mtd MTD device structure
2060 * @param to offset to write to 2060 * @param to offset to write to
2061 * @param len number of bytes to write 2061 * @param len number of bytes to write
@@ -2074,17 +2074,17 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to,
2074 u_char *oobbuf; 2074 u_char *oobbuf;
2075 size_t len = ops->ooblen; 2075 size_t len = ops->ooblen;
2076 const u_char *buf = ops->oobbuf; 2076 const u_char *buf = ops->oobbuf;
2077 mtd_oob_mode_t mode = ops->mode; 2077 unsigned int mode = ops->mode;
2078 2078
2079 to += ops->ooboffs; 2079 to += ops->ooboffs;
2080 2080
2081 DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", 2081 pr_debug("%s: to = 0x%08x, len = %i\n", __func__, (unsigned int)to,
2082 __func__, (unsigned int) to, (int) len); 2082 (int)len);
2083 2083
2084 /* Initialize retlen, in case of early exit */ 2084 /* Initialize retlen, in case of early exit */
2085 ops->oobretlen = 0; 2085 ops->oobretlen = 0;
2086 2086
2087 if (mode == MTD_OOB_AUTO) 2087 if (mode == MTD_OPS_AUTO_OOB)
2088 oobsize = this->ecclayout->oobavail; 2088 oobsize = this->ecclayout->oobavail;
2089 else 2089 else
2090 oobsize = mtd->oobsize; 2090 oobsize = mtd->oobsize;
@@ -2128,7 +2128,7 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to,
2128 /* We send data to spare ram with oobsize 2128 /* We send data to spare ram with oobsize
2129 * to prevent byte access */ 2129 * to prevent byte access */
2130 memset(oobbuf, 0xff, mtd->oobsize); 2130 memset(oobbuf, 0xff, mtd->oobsize);
2131 if (mode == MTD_OOB_AUTO) 2131 if (mode == MTD_OPS_AUTO_OOB)
2132 onenand_fill_auto_oob(mtd, oobbuf, buf, column, thislen); 2132 onenand_fill_auto_oob(mtd, oobbuf, buf, column, thislen);
2133 else 2133 else
2134 memcpy(oobbuf + column, buf, thislen); 2134 memcpy(oobbuf + column, buf, thislen);
@@ -2217,10 +2217,10 @@ static int onenand_write_oob(struct mtd_info *mtd, loff_t to,
2217 int ret; 2217 int ret;
2218 2218
2219 switch (ops->mode) { 2219 switch (ops->mode) {
2220 case MTD_OOB_PLACE: 2220 case MTD_OPS_PLACE_OOB:
2221 case MTD_OOB_AUTO: 2221 case MTD_OPS_AUTO_OOB:
2222 break; 2222 break;
2223 case MTD_OOB_RAW: 2223 case MTD_OPS_RAW:
2224 /* Not implemented yet */ 2224 /* Not implemented yet */
2225 default: 2225 default:
2226 return -EINVAL; 2226 return -EINVAL;
@@ -2281,7 +2281,7 @@ static int onenand_multiblock_erase_verify(struct mtd_info *mtd,
2281} 2281}
2282 2282
2283/** 2283/**
2284 * onenand_multiblock_erase - [Internal] erase block(s) using multiblock erase 2284 * onenand_multiblock_erase - [INTERN] erase block(s) using multiblock erase
2285 * @param mtd MTD device structure 2285 * @param mtd MTD device structure
2286 * @param instr erase instruction 2286 * @param instr erase instruction
2287 * @param region erase region 2287 * @param region erase region
@@ -2397,7 +2397,7 @@ static int onenand_multiblock_erase(struct mtd_info *mtd,
2397 2397
2398 2398
2399/** 2399/**
2400 * onenand_block_by_block_erase - [Internal] erase block(s) using regular erase 2400 * onenand_block_by_block_erase - [INTERN] erase block(s) using regular erase
2401 * @param mtd MTD device structure 2401 * @param mtd MTD device structure
2402 * @param instr erase instruction 2402 * @param instr erase instruction
2403 * @param region erase region 2403 * @param region erase region
@@ -2489,8 +2489,9 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
2489 struct mtd_erase_region_info *region = NULL; 2489 struct mtd_erase_region_info *region = NULL;
2490 loff_t region_offset = 0; 2490 loff_t region_offset = 0;
2491 2491
2492 DEBUG(MTD_DEBUG_LEVEL3, "%s: start=0x%012llx, len=%llu\n", __func__, 2492 pr_debug("%s: start=0x%012llx, len=%llu\n", __func__,
2493 (unsigned long long) instr->addr, (unsigned long long) instr->len); 2493 (unsigned long long)instr->addr,
2494 (unsigned long long)instr->len);
2494 2495
2495 /* Do not allow erase past end of device */ 2496 /* Do not allow erase past end of device */
2496 if (unlikely((len + addr) > mtd->size)) { 2497 if (unlikely((len + addr) > mtd->size)) {
@@ -2558,7 +2559,7 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
2558 */ 2559 */
2559static void onenand_sync(struct mtd_info *mtd) 2560static void onenand_sync(struct mtd_info *mtd)
2560{ 2561{
2561 DEBUG(MTD_DEBUG_LEVEL3, "%s: called\n", __func__); 2562 pr_debug("%s: called\n", __func__);
2562 2563
2563 /* Grab the lock and see if the device is available */ 2564 /* Grab the lock and see if the device is available */
2564 onenand_get_device(mtd, FL_SYNCING); 2565 onenand_get_device(mtd, FL_SYNCING);
@@ -2602,7 +2603,7 @@ static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
2602 struct bbm_info *bbm = this->bbm; 2603 struct bbm_info *bbm = this->bbm;
2603 u_char buf[2] = {0, 0}; 2604 u_char buf[2] = {0, 0};
2604 struct mtd_oob_ops ops = { 2605 struct mtd_oob_ops ops = {
2605 .mode = MTD_OOB_PLACE, 2606 .mode = MTD_OPS_PLACE_OOB,
2606 .ooblen = 2, 2607 .ooblen = 2,
2607 .oobbuf = buf, 2608 .oobbuf = buf,
2608 .ooboffs = 0, 2609 .ooboffs = 0,
@@ -2922,7 +2923,7 @@ static int onenand_otp_command(struct mtd_info *mtd, int cmd, loff_t addr,
2922} 2923}
2923 2924
2924/** 2925/**
2925 * onenand_otp_write_oob_nolock - [Internal] OneNAND write out-of-band, specific to OTP 2926 * onenand_otp_write_oob_nolock - [INTERN] OneNAND write out-of-band, specific to OTP
2926 * @param mtd MTD device structure 2927 * @param mtd MTD device structure
2927 * @param to offset to write to 2928 * @param to offset to write to
2928 * @param len number of bytes to write 2929 * @param len number of bytes to write
@@ -3170,7 +3171,7 @@ static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len,
3170 this->command(mtd, ONENAND_CMD_RESET, 0, 0); 3171 this->command(mtd, ONENAND_CMD_RESET, 0, 0);
3171 this->wait(mtd, FL_RESETING); 3172 this->wait(mtd, FL_RESETING);
3172 } else { 3173 } else {
3173 ops.mode = MTD_OOB_PLACE; 3174 ops.mode = MTD_OPS_PLACE_OOB;
3174 ops.ooblen = len; 3175 ops.ooblen = len;
3175 ops.oobbuf = buf; 3176 ops.oobbuf = buf;
3176 ops.ooboffs = 0; 3177 ops.ooboffs = 0;
@@ -3429,6 +3430,19 @@ static void onenand_check_features(struct mtd_info *mtd)
3429 else if (numbufs == 1) { 3430 else if (numbufs == 1) {
3430 this->options |= ONENAND_HAS_4KB_PAGE; 3431 this->options |= ONENAND_HAS_4KB_PAGE;
3431 this->options |= ONENAND_HAS_CACHE_PROGRAM; 3432 this->options |= ONENAND_HAS_CACHE_PROGRAM;
3433 /*
3434 * There are two different 4KiB pagesize chips
3435 * and no way to detect it by H/W config values.
3436 *
3437 * To detect the correct NOP for each chips,
3438 * It should check the version ID as workaround.
3439 *
3440 * Now it has as following
3441 * KFM4G16Q4M has NOP 4 with version ID 0x0131
3442 * KFM4G16Q5M has NOP 1 with versoin ID 0x013e
3443 */
3444 if ((this->version_id & 0xf) == 0xe)
3445 this->options |= ONENAND_HAS_NOP_1;
3432 } 3446 }
3433 3447
3434 case ONENAND_DEVICE_DENSITY_2Gb: 3448 case ONENAND_DEVICE_DENSITY_2Gb:
@@ -3663,7 +3677,7 @@ static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int
3663 int i, ret; 3677 int i, ret;
3664 int block; 3678 int block;
3665 struct mtd_oob_ops ops = { 3679 struct mtd_oob_ops ops = {
3666 .mode = MTD_OOB_PLACE, 3680 .mode = MTD_OPS_PLACE_OOB,
3667 .ooboffs = 0, 3681 .ooboffs = 0,
3668 .ooblen = mtd->oobsize, 3682 .ooblen = mtd->oobsize,
3669 .datbuf = NULL, 3683 .datbuf = NULL,
@@ -4054,6 +4068,8 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
4054 this->ecclayout = &onenand_oob_128; 4068 this->ecclayout = &onenand_oob_128;
4055 mtd->subpage_sft = 2; 4069 mtd->subpage_sft = 2;
4056 } 4070 }
4071 if (ONENAND_IS_NOP_1(this))
4072 mtd->subpage_sft = 0;
4057 break; 4073 break;
4058 case 64: 4074 case 64:
4059 this->ecclayout = &onenand_oob_64; 4075 this->ecclayout = &onenand_oob_64;
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index fc2c16a0fd1..66fe3b7e785 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
@@ -80,7 +81,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
80 startblock = 0; 81 startblock = 0;
81 from = 0; 82 from = 0;
82 83
83 ops.mode = MTD_OOB_PLACE; 84 ops.mode = MTD_OPS_PLACE_OOB;
84 ops.ooblen = readlen; 85 ops.ooblen = readlen;
85 ops.oobbuf = buf; 86 ops.oobbuf = buf;
86 ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; 87 ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
@@ -153,7 +154,7 @@ static int onenand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
153 block = (int) (onenand_block(this, offs) << 1); 154 block = (int) (onenand_block(this, offs) << 1);
154 res = (bbm->bbt[block >> 3] >> (block & 0x06)) & 0x03; 155 res = (bbm->bbt[block >> 3] >> (block & 0x06)) & 0x03;
155 156
156 DEBUG(MTD_DEBUG_LEVEL2, "onenand_isbad_bbt: bbt info for offs 0x%08x: (block %d) 0x%02x\n", 157 pr_debug("onenand_isbad_bbt: bbt info for offs 0x%08x: (block %d) 0x%02x\n",
157 (unsigned int) offs, block >> 1, res); 158 (unsigned int) offs, block >> 1, res);
158 159
159 switch ((int) res) { 160 switch ((int) res) {
@@ -188,10 +189,8 @@ int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
188 len = this->chipsize >> (this->erase_shift + 2); 189 len = this->chipsize >> (this->erase_shift + 2);
189 /* Allocate memory (2bit per block) and clear the memory bad block table */ 190 /* Allocate memory (2bit per block) and clear the memory bad block table */
190 bbm->bbt = kzalloc(len, GFP_KERNEL); 191 bbm->bbt = kzalloc(len, GFP_KERNEL);
191 if (!bbm->bbt) { 192 if (!bbm->bbt)
192 printk(KERN_ERR "onenand_scan_bbt: Out of memory\n");
193 return -ENOMEM; 193 return -ENOMEM;
194 }
195 194
196 /* Set the bad block position */ 195 /* Set the bad block position */
197 bbm->badblockpos = ONENAND_BADBLOCK_POS; 196 bbm->badblockpos = ONENAND_BADBLOCK_POS;
diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c
index 3306b5b3c73..5474547eafc 100644
--- a/drivers/mtd/onenand/samsung.c
+++ b/drivers/mtd/onenand/samsung.c
@@ -147,7 +147,6 @@ struct s3c_onenand {
147 struct resource *dma_res; 147 struct resource *dma_res;
148 unsigned long phys_base; 148 unsigned long phys_base;
149 struct completion complete; 149 struct completion complete;
150 struct mtd_partition *parts;
151}; 150};
152 151
153#define CMD_MAP_00(dev, addr) (dev->cmd_map(MAP_00, ((addr) << 1))) 152#define CMD_MAP_00(dev, addr) (dev->cmd_map(MAP_00, ((addr) << 1)))
@@ -157,8 +156,6 @@ struct s3c_onenand {
157 156
158static struct s3c_onenand *onenand; 157static struct s3c_onenand *onenand;
159 158
160static const char *part_probes[] = { "cmdlinepart", NULL, };
161
162static inline int s3c_read_reg(int offset) 159static inline int s3c_read_reg(int offset)
163{ 160{
164 return readl(onenand->base + offset); 161 return readl(onenand->base + offset);
@@ -1017,13 +1014,9 @@ static int s3c_onenand_probe(struct platform_device *pdev)
1017 if (s3c_read_reg(MEM_CFG_OFFSET) & ONENAND_SYS_CFG1_SYNC_READ) 1014 if (s3c_read_reg(MEM_CFG_OFFSET) & ONENAND_SYS_CFG1_SYNC_READ)
1018 dev_info(&onenand->pdev->dev, "OneNAND Sync. Burst Read enabled\n"); 1015 dev_info(&onenand->pdev->dev, "OneNAND Sync. Burst Read enabled\n");
1019 1016
1020 err = parse_mtd_partitions(mtd, part_probes, &onenand->parts, 0); 1017 err = mtd_device_parse_register(mtd, NULL, 0,
1021 if (err > 0) 1018 pdata ? pdata->parts : NULL,
1022 mtd_device_register(mtd, onenand->parts, err); 1019 pdata ? pdata->nr_parts : 0);
1023 else if (err <= 0 && pdata && pdata->parts)
1024 mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
1025 else
1026 err = mtd_device_register(mtd, NULL, 0);
1027 1020
1028 platform_set_drvdata(pdev, mtd); 1021 platform_set_drvdata(pdev, mtd);
1029 1022
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 7a87d07cd79..e366b1d84ea 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
@@ -56,8 +57,8 @@ static inline int redboot_checksum(struct fis_image_desc *img)
56} 57}
57 58
58static int parse_redboot_partitions(struct mtd_info *master, 59static int parse_redboot_partitions(struct mtd_info *master,
59 struct mtd_partition **pparts, 60 struct mtd_partition **pparts,
60 unsigned long fis_origin) 61 struct mtd_part_parser_data *data)
61{ 62{
62 int nrparts = 0; 63 int nrparts = 0;
63 struct fis_image_desc *buf; 64 struct fis_image_desc *buf;
@@ -197,11 +198,10 @@ static int parse_redboot_partitions(struct mtd_info *master,
197 goto out; 198 goto out;
198 } 199 }
199 new_fl->img = &buf[i]; 200 new_fl->img = &buf[i];
200 if (fis_origin) { 201 if (data && data->origin)
201 buf[i].flash_base -= fis_origin; 202 buf[i].flash_base -= data->origin;
202 } else { 203 else
203 buf[i].flash_base &= master->size-1; 204 buf[i].flash_base &= master->size-1;
204 }
205 205
206 /* I'm sure the JFFS2 code has done me permanent damage. 206 /* I'm sure the JFFS2 code has done me permanent damage.
207 * I now think the following is _normal_ 207 * I now think the following is _normal_
@@ -297,6 +297,9 @@ static struct mtd_part_parser redboot_parser = {
297 .name = "RedBoot", 297 .name = "RedBoot",
298}; 298};
299 299
300/* mtd parsers will request the module by parser name */
301MODULE_ALIAS("RedBoot");
302
300static int __init redboot_parser_init(void) 303static int __init redboot_parser_init(void)
301{ 304{
302 return register_mtd_parser(&redboot_parser); 305 return register_mtd_parser(&redboot_parser);
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index cc4d1805b86..73ae217a425 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/sm_ftl.c b/drivers/mtd/sm_ftl.c
index ed3d6cd2c6d..fddb714e323 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -34,7 +34,7 @@ module_param(debug, int, S_IRUGO | S_IWUSR);
34MODULE_PARM_DESC(debug, "Debug level (0-2)"); 34MODULE_PARM_DESC(debug, "Debug level (0-2)");
35 35
36 36
37/* ------------------- sysfs attributtes ---------------------------------- */ 37/* ------------------- sysfs attributes ---------------------------------- */
38struct sm_sysfs_attribute { 38struct sm_sysfs_attribute {
39 struct device_attribute dev_attr; 39 struct device_attribute dev_attr;
40 char *data; 40 char *data;
@@ -138,7 +138,7 @@ static int sm_get_lba(uint8_t *lba)
138 if ((lba[0] & 0xF8) != 0x10) 138 if ((lba[0] & 0xF8) != 0x10)
139 return -2; 139 return -2;
140 140
141 /* check parity - endianess doesn't matter */ 141 /* check parity - endianness doesn't matter */
142 if (hweight16(*(uint16_t *)lba) & 1) 142 if (hweight16(*(uint16_t *)lba) & 1)
143 return -2; 143 return -2;
144 144
@@ -147,7 +147,7 @@ static int sm_get_lba(uint8_t *lba)
147 147
148 148
149/* 149/*
150 * Read LBA asscociated with block 150 * Read LBA associated with block
151 * returns -1, if block is erased 151 * returns -1, if block is erased
152 * returns -2 if error happens 152 * returns -2 if error happens
153 */ 153 */
@@ -252,11 +252,11 @@ static int sm_read_sector(struct sm_ftl *ftl,
252 return 0; 252 return 0;
253 } 253 }
254 254
255 /* User might not need the oob, but we do for data vertification */ 255 /* User might not need the oob, but we do for data verification */
256 if (!oob) 256 if (!oob)
257 oob = &tmp_oob; 257 oob = &tmp_oob;
258 258
259 ops.mode = ftl->smallpagenand ? MTD_OOB_RAW : MTD_OOB_PLACE; 259 ops.mode = ftl->smallpagenand ? MTD_OPS_RAW : MTD_OPS_PLACE_OOB;
260 ops.ooboffs = 0; 260 ops.ooboffs = 0;
261 ops.ooblen = SM_OOB_SIZE; 261 ops.ooblen = SM_OOB_SIZE;
262 ops.oobbuf = (void *)oob; 262 ops.oobbuf = (void *)oob;
@@ -276,12 +276,12 @@ again:
276 return ret; 276 return ret;
277 } 277 }
278 278
279 /* Unfortunelly, oob read will _always_ succeed, 279 /* Unfortunately, oob read will _always_ succeed,
280 despite card removal..... */ 280 despite card removal..... */
281 ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); 281 ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops);
282 282
283 /* Test for unknown errors */ 283 /* Test for unknown errors */
284 if (ret != 0 && ret != -EUCLEAN && ret != -EBADMSG) { 284 if (ret != 0 && !mtd_is_bitflip_or_eccerr(ret)) {
285 dbg("read of block %d at zone %d, failed due to error (%d)", 285 dbg("read of block %d at zone %d, failed due to error (%d)",
286 block, zone, ret); 286 block, zone, ret);
287 goto again; 287 goto again;
@@ -306,7 +306,7 @@ again:
306 } 306 }
307 307
308 /* Test ECC*/ 308 /* Test ECC*/
309 if (ret == -EBADMSG || 309 if (mtd_is_eccerr(ret) ||
310 (ftl->smallpagenand && sm_correct_sector(buffer, oob))) { 310 (ftl->smallpagenand && sm_correct_sector(buffer, oob))) {
311 311
312 dbg("read of block %d at zone %d, failed due to ECC error", 312 dbg("read of block %d at zone %d, failed due to ECC error",
@@ -336,7 +336,7 @@ static int sm_write_sector(struct sm_ftl *ftl,
336 if (ftl->unstable) 336 if (ftl->unstable)
337 return -EIO; 337 return -EIO;
338 338
339 ops.mode = ftl->smallpagenand ? MTD_OOB_RAW : MTD_OOB_PLACE; 339 ops.mode = ftl->smallpagenand ? MTD_OPS_RAW : MTD_OPS_PLACE_OOB;
340 ops.len = SM_SECTOR_SIZE; 340 ops.len = SM_SECTOR_SIZE;
341 ops.datbuf = buffer; 341 ops.datbuf = buffer;
342 ops.ooboffs = 0; 342 ops.ooboffs = 0;
@@ -447,14 +447,14 @@ static void sm_mark_block_bad(struct sm_ftl *ftl, int zone, int block)
447 447
448 /* We aren't checking the return value, because we don't care */ 448 /* We aren't checking the return value, because we don't care */
449 /* This also fails on fake xD cards, but I guess these won't expose 449 /* This also fails on fake xD cards, but I guess these won't expose
450 any bad blocks till fail completly */ 450 any bad blocks till fail completely */
451 for (boffset = 0; boffset < ftl->block_size; boffset += SM_SECTOR_SIZE) 451 for (boffset = 0; boffset < ftl->block_size; boffset += SM_SECTOR_SIZE)
452 sm_write_sector(ftl, zone, block, boffset, NULL, &oob); 452 sm_write_sector(ftl, zone, block, boffset, NULL, &oob);
453} 453}
454 454
455/* 455/*
456 * Erase a block within a zone 456 * Erase a block within a zone
457 * If erase succedes, it updates free block fifo, otherwise marks block as bad 457 * If erase succeeds, it updates free block fifo, otherwise marks block as bad
458 */ 458 */
459static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block, 459static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block,
460 int put_free) 460 int put_free)
@@ -510,7 +510,7 @@ static void sm_erase_callback(struct erase_info *self)
510 complete(&ftl->erase_completion); 510 complete(&ftl->erase_completion);
511} 511}
512 512
513/* Throughtly test that block is valid. */ 513/* Thoroughly test that block is valid. */
514static int sm_check_block(struct sm_ftl *ftl, int zone, int block) 514static int sm_check_block(struct sm_ftl *ftl, int zone, int block)
515{ 515{
516 int boffset; 516 int boffset;
@@ -526,7 +526,7 @@ static int sm_check_block(struct sm_ftl *ftl, int zone, int block)
526 for (boffset = 0; boffset < ftl->block_size; 526 for (boffset = 0; boffset < ftl->block_size;
527 boffset += SM_SECTOR_SIZE) { 527 boffset += SM_SECTOR_SIZE) {
528 528
529 /* This shoudn't happen anyway */ 529 /* This shouldn't happen anyway */
530 if (sm_read_sector(ftl, zone, block, boffset, NULL, &oob)) 530 if (sm_read_sector(ftl, zone, block, boffset, NULL, &oob))
531 return -2; 531 return -2;
532 532
diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c
index 5cd18979333..976e3d28b96 100644
--- a/drivers/mtd/ssfdc.c
+++ b/drivers/mtd/ssfdc.c
@@ -135,8 +135,7 @@ static int get_valid_cis_sector(struct mtd_info *mtd)
135 /* Found */ 135 /* Found */
136 cis_sector = (int)(offset >> SECTOR_SHIFT); 136 cis_sector = (int)(offset >> SECTOR_SHIFT);
137 } else { 137 } else {
138 DEBUG(MTD_DEBUG_LEVEL1, 138 pr_debug("SSFDC_RO: CIS/IDI sector not found"
139 "SSFDC_RO: CIS/IDI sector not found"
140 " on %s (mtd%d)\n", mtd->name, 139 " on %s (mtd%d)\n", mtd->name,
141 mtd->index); 140 mtd->index);
142 } 141 }
@@ -170,7 +169,7 @@ static int read_raw_oob(struct mtd_info *mtd, loff_t offs, uint8_t *buf)
170 struct mtd_oob_ops ops; 169 struct mtd_oob_ops ops;
171 int ret; 170 int ret;
172 171
173 ops.mode = MTD_OOB_RAW; 172 ops.mode = MTD_OPS_RAW;
174 ops.ooboffs = 0; 173 ops.ooboffs = 0;
175 ops.ooblen = OOB_SIZE; 174 ops.ooblen = OOB_SIZE;
176 ops.oobbuf = buf; 175 ops.oobbuf = buf;
@@ -221,8 +220,7 @@ static int get_logical_address(uint8_t *oob_buf)
221 block_address >>= 1; 220 block_address >>= 1;
222 221
223 if (get_parity(block_address, 10) != parity) { 222 if (get_parity(block_address, 10) != parity) {
224 DEBUG(MTD_DEBUG_LEVEL0, 223 pr_debug("SSFDC_RO: logical address field%d"
225 "SSFDC_RO: logical address field%d"
226 "parity error(0x%04X)\n", j+1, 224 "parity error(0x%04X)\n", j+1,
227 block_address); 225 block_address);
228 } else { 226 } else {
@@ -235,7 +233,7 @@ static int get_logical_address(uint8_t *oob_buf)
235 if (!ok) 233 if (!ok)
236 block_address = -2; 234 block_address = -2;
237 235
238 DEBUG(MTD_DEBUG_LEVEL3, "SSFDC_RO: get_logical_address() %d\n", 236 pr_debug("SSFDC_RO: get_logical_address() %d\n",
239 block_address); 237 block_address);
240 238
241 return block_address; 239 return block_address;
@@ -249,7 +247,7 @@ static int build_logical_block_map(struct ssfdcr_record *ssfdc)
249 int ret, block_address, phys_block; 247 int ret, block_address, phys_block;
250 struct mtd_info *mtd = ssfdc->mbd.mtd; 248 struct mtd_info *mtd = ssfdc->mbd.mtd;
251 249
252 DEBUG(MTD_DEBUG_LEVEL1, "SSFDC_RO: build_block_map() nblks=%d (%luK)\n", 250 pr_debug("SSFDC_RO: build_block_map() nblks=%d (%luK)\n",
253 ssfdc->map_len, 251 ssfdc->map_len,
254 (unsigned long)ssfdc->map_len * ssfdc->erase_size / 1024); 252 (unsigned long)ssfdc->map_len * ssfdc->erase_size / 1024);
255 253
@@ -262,8 +260,7 @@ static int build_logical_block_map(struct ssfdcr_record *ssfdc)
262 260
263 ret = read_raw_oob(mtd, offset, oob_buf); 261 ret = read_raw_oob(mtd, offset, oob_buf);
264 if (ret < 0) { 262 if (ret < 0) {
265 DEBUG(MTD_DEBUG_LEVEL0, 263 pr_debug("SSFDC_RO: mtd read_oob() failed at %lu\n",
266 "SSFDC_RO: mtd read_oob() failed at %lu\n",
267 offset); 264 offset);
268 return -1; 265 return -1;
269 } 266 }
@@ -279,8 +276,7 @@ static int build_logical_block_map(struct ssfdcr_record *ssfdc)
279 ssfdc->logic_block_map[block_address] = 276 ssfdc->logic_block_map[block_address] =
280 (unsigned short)phys_block; 277 (unsigned short)phys_block;
281 278
282 DEBUG(MTD_DEBUG_LEVEL2, 279 pr_debug("SSFDC_RO: build_block_map() phys_block=%d,"
283 "SSFDC_RO: build_block_map() phys_block=%d,"
284 "logic_block_addr=%d, zone=%d\n", 280 "logic_block_addr=%d, zone=%d\n",
285 phys_block, block_address, zone_index); 281 phys_block, block_address, zone_index);
286 } 282 }
@@ -304,11 +300,8 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
304 return; 300 return;
305 301
306 ssfdc = kzalloc(sizeof(struct ssfdcr_record), GFP_KERNEL); 302 ssfdc = kzalloc(sizeof(struct ssfdcr_record), GFP_KERNEL);
307 if (!ssfdc) { 303 if (!ssfdc)
308 printk(KERN_WARNING
309 "SSFDC_RO: out of memory for data structures\n");
310 return; 304 return;
311 }
312 305
313 ssfdc->mbd.mtd = mtd; 306 ssfdc->mbd.mtd = mtd;
314 ssfdc->mbd.devnum = -1; 307 ssfdc->mbd.devnum = -1;
@@ -319,8 +312,7 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
319 ssfdc->erase_size = mtd->erasesize; 312 ssfdc->erase_size = mtd->erasesize;
320 ssfdc->map_len = (u32)mtd->size / mtd->erasesize; 313 ssfdc->map_len = (u32)mtd->size / mtd->erasesize;
321 314
322 DEBUG(MTD_DEBUG_LEVEL1, 315 pr_debug("SSFDC_RO: cis_block=%d,erase_size=%d,map_len=%d,n_zones=%d\n",
323 "SSFDC_RO: cis_block=%d,erase_size=%d,map_len=%d,n_zones=%d\n",
324 ssfdc->cis_block, ssfdc->erase_size, ssfdc->map_len, 316 ssfdc->cis_block, ssfdc->erase_size, ssfdc->map_len,
325 DIV_ROUND_UP(ssfdc->map_len, MAX_PHYS_BLK_PER_ZONE)); 317 DIV_ROUND_UP(ssfdc->map_len, MAX_PHYS_BLK_PER_ZONE));
326 318
@@ -331,7 +323,7 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
331 ssfdc->cylinders = (unsigned short)(((u32)mtd->size >> SECTOR_SHIFT) / 323 ssfdc->cylinders = (unsigned short)(((u32)mtd->size >> SECTOR_SHIFT) /
332 ((long)ssfdc->sectors * (long)ssfdc->heads)); 324 ((long)ssfdc->sectors * (long)ssfdc->heads));
333 325
334 DEBUG(MTD_DEBUG_LEVEL1, "SSFDC_RO: using C:%d H:%d S:%d == %ld sects\n", 326 pr_debug("SSFDC_RO: using C:%d H:%d S:%d == %ld sects\n",
335 ssfdc->cylinders, ssfdc->heads , ssfdc->sectors, 327 ssfdc->cylinders, ssfdc->heads , ssfdc->sectors,
336 (long)ssfdc->cylinders * (long)ssfdc->heads * 328 (long)ssfdc->cylinders * (long)ssfdc->heads *
337 (long)ssfdc->sectors); 329 (long)ssfdc->sectors);
@@ -342,11 +334,8 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
342 /* Allocate logical block map */ 334 /* Allocate logical block map */
343 ssfdc->logic_block_map = kmalloc(sizeof(ssfdc->logic_block_map[0]) * 335 ssfdc->logic_block_map = kmalloc(sizeof(ssfdc->logic_block_map[0]) *
344 ssfdc->map_len, GFP_KERNEL); 336 ssfdc->map_len, GFP_KERNEL);
345 if (!ssfdc->logic_block_map) { 337 if (!ssfdc->logic_block_map)
346 printk(KERN_WARNING
347 "SSFDC_RO: out of memory for data structures\n");
348 goto out_err; 338 goto out_err;
349 }
350 memset(ssfdc->logic_block_map, 0xff, sizeof(ssfdc->logic_block_map[0]) * 339 memset(ssfdc->logic_block_map, 0xff, sizeof(ssfdc->logic_block_map[0]) *
351 ssfdc->map_len); 340 ssfdc->map_len);
352 341
@@ -371,7 +360,7 @@ static void ssfdcr_remove_dev(struct mtd_blktrans_dev *dev)
371{ 360{
372 struct ssfdcr_record *ssfdc = (struct ssfdcr_record *)dev; 361 struct ssfdcr_record *ssfdc = (struct ssfdcr_record *)dev;
373 362
374 DEBUG(MTD_DEBUG_LEVEL1, "SSFDC_RO: remove_dev (i=%d)\n", dev->devnum); 363 pr_debug("SSFDC_RO: remove_dev (i=%d)\n", dev->devnum);
375 364
376 del_mtd_blktrans_dev(dev); 365 del_mtd_blktrans_dev(dev);
377 kfree(ssfdc->logic_block_map); 366 kfree(ssfdc->logic_block_map);
@@ -387,8 +376,7 @@ static int ssfdcr_readsect(struct mtd_blktrans_dev *dev,
387 offset = (int)(logic_sect_no % sectors_per_block); 376 offset = (int)(logic_sect_no % sectors_per_block);
388 block_address = (int)(logic_sect_no / sectors_per_block); 377 block_address = (int)(logic_sect_no / sectors_per_block);
389 378
390 DEBUG(MTD_DEBUG_LEVEL3, 379 pr_debug("SSFDC_RO: ssfdcr_readsect(%lu) sec_per_blk=%d, ofst=%d,"
391 "SSFDC_RO: ssfdcr_readsect(%lu) sec_per_blk=%d, ofst=%d,"
392 " block_addr=%d\n", logic_sect_no, sectors_per_block, offset, 380 " block_addr=%d\n", logic_sect_no, sectors_per_block, offset,
393 block_address); 381 block_address);
394 382
@@ -397,8 +385,7 @@ static int ssfdcr_readsect(struct mtd_blktrans_dev *dev,
397 385
398 block_address = ssfdc->logic_block_map[block_address]; 386 block_address = ssfdc->logic_block_map[block_address];
399 387
400 DEBUG(MTD_DEBUG_LEVEL3, 388 pr_debug("SSFDC_RO: ssfdcr_readsect() phys_block_addr=%d\n",
401 "SSFDC_RO: ssfdcr_readsect() phys_block_addr=%d\n",
402 block_address); 389 block_address);
403 390
404 if (block_address < 0xffff) { 391 if (block_address < 0xffff) {
@@ -407,8 +394,7 @@ static int ssfdcr_readsect(struct mtd_blktrans_dev *dev,
407 sect_no = (unsigned long)block_address * sectors_per_block + 394 sect_no = (unsigned long)block_address * sectors_per_block +
408 offset; 395 offset;
409 396
410 DEBUG(MTD_DEBUG_LEVEL3, 397 pr_debug("SSFDC_RO: ssfdcr_readsect() phys_sect_no=%lu\n",
411 "SSFDC_RO: ssfdcr_readsect() phys_sect_no=%lu\n",
412 sect_no); 398 sect_no);
413 399
414 if (read_physical_sector(ssfdc->mbd.mtd, buf, sect_no) < 0) 400 if (read_physical_sector(ssfdc->mbd.mtd, buf, sect_no) < 0)
@@ -424,7 +410,7 @@ static int ssfdcr_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
424{ 410{
425 struct ssfdcr_record *ssfdc = (struct ssfdcr_record *)dev; 411 struct ssfdcr_record *ssfdc = (struct ssfdcr_record *)dev;
426 412
427 DEBUG(MTD_DEBUG_LEVEL1, "SSFDC_RO: ssfdcr_getgeo() C=%d, H=%d, S=%d\n", 413 pr_debug("SSFDC_RO: ssfdcr_getgeo() C=%d, H=%d, S=%d\n",
428 ssfdc->cylinders, ssfdc->heads, ssfdc->sectors); 414 ssfdc->cylinders, ssfdc->heads, ssfdc->sectors);
429 415
430 geo->heads = ssfdc->heads; 416 geo->heads = ssfdc->heads;
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c
index dec92ae6111..933f7e5f32d 100644
--- a/drivers/mtd/tests/mtd_oobtest.c
+++ b/drivers/mtd/tests/mtd_oobtest.c
@@ -30,7 +30,7 @@
30 30
31#define PRINT_PREF KERN_INFO "mtd_oobtest: " 31#define PRINT_PREF KERN_INFO "mtd_oobtest: "
32 32
33static int dev; 33static int dev = -EINVAL;
34module_param(dev, int, S_IRUGO); 34module_param(dev, int, S_IRUGO);
35MODULE_PARM_DESC(dev, "MTD device number to use"); 35MODULE_PARM_DESC(dev, "MTD device number to use");
36 36
@@ -131,7 +131,7 @@ static int write_eraseblock(int ebnum)
131 131
132 for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { 132 for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
133 set_random_data(writebuf, use_len); 133 set_random_data(writebuf, use_len);
134 ops.mode = MTD_OOB_AUTO; 134 ops.mode = MTD_OPS_AUTO_OOB;
135 ops.len = 0; 135 ops.len = 0;
136 ops.retlen = 0; 136 ops.retlen = 0;
137 ops.ooblen = use_len; 137 ops.ooblen = use_len;
@@ -184,7 +184,7 @@ static int verify_eraseblock(int ebnum)
184 184
185 for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) { 185 for (i = 0; i < pgcnt; ++i, addr += mtd->writesize) {
186 set_random_data(writebuf, use_len); 186 set_random_data(writebuf, use_len);
187 ops.mode = MTD_OOB_AUTO; 187 ops.mode = MTD_OPS_AUTO_OOB;
188 ops.len = 0; 188 ops.len = 0;
189 ops.retlen = 0; 189 ops.retlen = 0;
190 ops.ooblen = use_len; 190 ops.ooblen = use_len;
@@ -211,7 +211,7 @@ static int verify_eraseblock(int ebnum)
211 if (use_offset != 0 || use_len < mtd->ecclayout->oobavail) { 211 if (use_offset != 0 || use_len < mtd->ecclayout->oobavail) {
212 int k; 212 int k;
213 213
214 ops.mode = MTD_OOB_AUTO; 214 ops.mode = MTD_OPS_AUTO_OOB;
215 ops.len = 0; 215 ops.len = 0;
216 ops.retlen = 0; 216 ops.retlen = 0;
217 ops.ooblen = mtd->ecclayout->oobavail; 217 ops.ooblen = mtd->ecclayout->oobavail;
@@ -276,7 +276,7 @@ static int verify_eraseblock_in_one_go(int ebnum)
276 size_t len = mtd->ecclayout->oobavail * pgcnt; 276 size_t len = mtd->ecclayout->oobavail * pgcnt;
277 277
278 set_random_data(writebuf, len); 278 set_random_data(writebuf, len);
279 ops.mode = MTD_OOB_AUTO; 279 ops.mode = MTD_OPS_AUTO_OOB;
280 ops.len = 0; 280 ops.len = 0;
281 ops.retlen = 0; 281 ops.retlen = 0;
282 ops.ooblen = len; 282 ops.ooblen = len;
@@ -366,6 +366,13 @@ static int __init mtd_oobtest_init(void)
366 366
367 printk(KERN_INFO "\n"); 367 printk(KERN_INFO "\n");
368 printk(KERN_INFO "=================================================\n"); 368 printk(KERN_INFO "=================================================\n");
369
370 if (dev < 0) {
371 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
372 printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
373 return -EINVAL;
374 }
375
369 printk(PRINT_PREF "MTD device: %d\n", dev); 376 printk(PRINT_PREF "MTD device: %d\n", dev);
370 377
371 mtd = get_mtd_device(NULL, dev); 378 mtd = get_mtd_device(NULL, dev);
@@ -507,7 +514,7 @@ static int __init mtd_oobtest_init(void)
507 addr0 += mtd->erasesize; 514 addr0 += mtd->erasesize;
508 515
509 /* Attempt to write off end of OOB */ 516 /* Attempt to write off end of OOB */
510 ops.mode = MTD_OOB_AUTO; 517 ops.mode = MTD_OPS_AUTO_OOB;
511 ops.len = 0; 518 ops.len = 0;
512 ops.retlen = 0; 519 ops.retlen = 0;
513 ops.ooblen = 1; 520 ops.ooblen = 1;
@@ -527,7 +534,7 @@ static int __init mtd_oobtest_init(void)
527 } 534 }
528 535
529 /* Attempt to read off end of OOB */ 536 /* Attempt to read off end of OOB */
530 ops.mode = MTD_OOB_AUTO; 537 ops.mode = MTD_OPS_AUTO_OOB;
531 ops.len = 0; 538 ops.len = 0;
532 ops.retlen = 0; 539 ops.retlen = 0;
533 ops.ooblen = 1; 540 ops.ooblen = 1;
@@ -551,7 +558,7 @@ static int __init mtd_oobtest_init(void)
551 "block is bad\n"); 558 "block is bad\n");
552 else { 559 else {
553 /* Attempt to write off end of device */ 560 /* Attempt to write off end of device */
554 ops.mode = MTD_OOB_AUTO; 561 ops.mode = MTD_OPS_AUTO_OOB;
555 ops.len = 0; 562 ops.len = 0;
556 ops.retlen = 0; 563 ops.retlen = 0;
557 ops.ooblen = mtd->ecclayout->oobavail + 1; 564 ops.ooblen = mtd->ecclayout->oobavail + 1;
@@ -571,7 +578,7 @@ static int __init mtd_oobtest_init(void)
571 } 578 }
572 579
573 /* Attempt to read off end of device */ 580 /* Attempt to read off end of device */
574 ops.mode = MTD_OOB_AUTO; 581 ops.mode = MTD_OPS_AUTO_OOB;
575 ops.len = 0; 582 ops.len = 0;
576 ops.retlen = 0; 583 ops.retlen = 0;
577 ops.ooblen = mtd->ecclayout->oobavail + 1; 584 ops.ooblen = mtd->ecclayout->oobavail + 1;
@@ -595,7 +602,7 @@ static int __init mtd_oobtest_init(void)
595 goto out; 602 goto out;
596 603
597 /* Attempt to write off end of device */ 604 /* Attempt to write off end of device */
598 ops.mode = MTD_OOB_AUTO; 605 ops.mode = MTD_OPS_AUTO_OOB;
599 ops.len = 0; 606 ops.len = 0;
600 ops.retlen = 0; 607 ops.retlen = 0;
601 ops.ooblen = mtd->ecclayout->oobavail; 608 ops.ooblen = mtd->ecclayout->oobavail;
@@ -615,7 +622,7 @@ static int __init mtd_oobtest_init(void)
615 } 622 }
616 623
617 /* Attempt to read off end of device */ 624 /* Attempt to read off end of device */
618 ops.mode = MTD_OOB_AUTO; 625 ops.mode = MTD_OPS_AUTO_OOB;
619 ops.len = 0; 626 ops.len = 0;
620 ops.retlen = 0; 627 ops.retlen = 0;
621 ops.ooblen = mtd->ecclayout->oobavail; 628 ops.ooblen = mtd->ecclayout->oobavail;
@@ -655,7 +662,7 @@ static int __init mtd_oobtest_init(void)
655 addr = (i + 1) * mtd->erasesize - mtd->writesize; 662 addr = (i + 1) * mtd->erasesize - mtd->writesize;
656 for (pg = 0; pg < cnt; ++pg) { 663 for (pg = 0; pg < cnt; ++pg) {
657 set_random_data(writebuf, sz); 664 set_random_data(writebuf, sz);
658 ops.mode = MTD_OOB_AUTO; 665 ops.mode = MTD_OPS_AUTO_OOB;
659 ops.len = 0; 666 ops.len = 0;
660 ops.retlen = 0; 667 ops.retlen = 0;
661 ops.ooblen = sz; 668 ops.ooblen = sz;
@@ -683,7 +690,7 @@ static int __init mtd_oobtest_init(void)
683 continue; 690 continue;
684 set_random_data(writebuf, mtd->ecclayout->oobavail * 2); 691 set_random_data(writebuf, mtd->ecclayout->oobavail * 2);
685 addr = (i + 1) * mtd->erasesize - mtd->writesize; 692 addr = (i + 1) * mtd->erasesize - mtd->writesize;
686 ops.mode = MTD_OOB_AUTO; 693 ops.mode = MTD_OPS_AUTO_OOB;
687 ops.len = 0; 694 ops.len = 0;
688 ops.retlen = 0; 695 ops.retlen = 0;
689 ops.ooblen = mtd->ecclayout->oobavail * 2; 696 ops.ooblen = mtd->ecclayout->oobavail * 2;
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 00b937e38c1..afafb6935fd 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -30,7 +30,7 @@
30 30
31#define PRINT_PREF KERN_INFO "mtd_pagetest: " 31#define PRINT_PREF KERN_INFO "mtd_pagetest: "
32 32
33static int dev; 33static int dev = -EINVAL;
34module_param(dev, int, S_IRUGO); 34module_param(dev, int, S_IRUGO);
35MODULE_PARM_DESC(dev, "MTD device number to use"); 35MODULE_PARM_DESC(dev, "MTD device number to use");
36 36
@@ -128,7 +128,7 @@ static int verify_eraseblock(int ebnum)
128 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { 128 for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) {
129 /* Do a read to set the internal dataRAMs to different data */ 129 /* Do a read to set the internal dataRAMs to different data */
130 err = mtd->read(mtd, addr0, bufsize, &read, twopages); 130 err = mtd->read(mtd, addr0, bufsize, &read, twopages);
131 if (err == -EUCLEAN) 131 if (mtd_is_bitflip(err))
132 err = 0; 132 err = 0;
133 if (err || read != bufsize) { 133 if (err || read != bufsize) {
134 printk(PRINT_PREF "error: read failed at %#llx\n", 134 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -136,7 +136,7 @@ static int verify_eraseblock(int ebnum)
136 return err; 136 return err;
137 } 137 }
138 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages); 138 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages);
139 if (err == -EUCLEAN) 139 if (mtd_is_bitflip(err))
140 err = 0; 140 err = 0;
141 if (err || read != bufsize) { 141 if (err || read != bufsize) {
142 printk(PRINT_PREF "error: read failed at %#llx\n", 142 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -146,7 +146,7 @@ static int verify_eraseblock(int ebnum)
146 memset(twopages, 0, bufsize); 146 memset(twopages, 0, bufsize);
147 read = 0; 147 read = 0;
148 err = mtd->read(mtd, addr, bufsize, &read, twopages); 148 err = mtd->read(mtd, addr, bufsize, &read, twopages);
149 if (err == -EUCLEAN) 149 if (mtd_is_bitflip(err))
150 err = 0; 150 err = 0;
151 if (err || read != bufsize) { 151 if (err || read != bufsize) {
152 printk(PRINT_PREF "error: read failed at %#llx\n", 152 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -164,7 +164,7 @@ static int verify_eraseblock(int ebnum)
164 unsigned long oldnext = next; 164 unsigned long oldnext = next;
165 /* Do a read to set the internal dataRAMs to different data */ 165 /* Do a read to set the internal dataRAMs to different data */
166 err = mtd->read(mtd, addr0, bufsize, &read, twopages); 166 err = mtd->read(mtd, addr0, bufsize, &read, twopages);
167 if (err == -EUCLEAN) 167 if (mtd_is_bitflip(err))
168 err = 0; 168 err = 0;
169 if (err || read != bufsize) { 169 if (err || read != bufsize) {
170 printk(PRINT_PREF "error: read failed at %#llx\n", 170 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -172,7 +172,7 @@ static int verify_eraseblock(int ebnum)
172 return err; 172 return err;
173 } 173 }
174 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages); 174 err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages);
175 if (err == -EUCLEAN) 175 if (mtd_is_bitflip(err))
176 err = 0; 176 err = 0;
177 if (err || read != bufsize) { 177 if (err || read != bufsize) {
178 printk(PRINT_PREF "error: read failed at %#llx\n", 178 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -182,7 +182,7 @@ static int verify_eraseblock(int ebnum)
182 memset(twopages, 0, bufsize); 182 memset(twopages, 0, bufsize);
183 read = 0; 183 read = 0;
184 err = mtd->read(mtd, addr, bufsize, &read, twopages); 184 err = mtd->read(mtd, addr, bufsize, &read, twopages);
185 if (err == -EUCLEAN) 185 if (mtd_is_bitflip(err))
186 err = 0; 186 err = 0;
187 if (err || read != bufsize) { 187 if (err || read != bufsize) {
188 printk(PRINT_PREF "error: read failed at %#llx\n", 188 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -231,7 +231,7 @@ static int crosstest(void)
231 read = 0; 231 read = 0;
232 addr = addrn - pgsize - pgsize; 232 addr = addrn - pgsize - pgsize;
233 err = mtd->read(mtd, addr, pgsize, &read, pp1); 233 err = mtd->read(mtd, addr, pgsize, &read, pp1);
234 if (err == -EUCLEAN) 234 if (mtd_is_bitflip(err))
235 err = 0; 235 err = 0;
236 if (err || read != pgsize) { 236 if (err || read != pgsize) {
237 printk(PRINT_PREF "error: read failed at %#llx\n", 237 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -244,7 +244,7 @@ static int crosstest(void)
244 read = 0; 244 read = 0;
245 addr = addrn - pgsize - pgsize - pgsize; 245 addr = addrn - pgsize - pgsize - pgsize;
246 err = mtd->read(mtd, addr, pgsize, &read, pp1); 246 err = mtd->read(mtd, addr, pgsize, &read, pp1);
247 if (err == -EUCLEAN) 247 if (mtd_is_bitflip(err))
248 err = 0; 248 err = 0;
249 if (err || read != pgsize) { 249 if (err || read != pgsize) {
250 printk(PRINT_PREF "error: read failed at %#llx\n", 250 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -258,7 +258,7 @@ static int crosstest(void)
258 addr = addr0; 258 addr = addr0;
259 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); 259 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
260 err = mtd->read(mtd, addr, pgsize, &read, pp2); 260 err = mtd->read(mtd, addr, pgsize, &read, pp2);
261 if (err == -EUCLEAN) 261 if (mtd_is_bitflip(err))
262 err = 0; 262 err = 0;
263 if (err || read != pgsize) { 263 if (err || read != pgsize) {
264 printk(PRINT_PREF "error: read failed at %#llx\n", 264 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -272,7 +272,7 @@ static int crosstest(void)
272 addr = addrn - pgsize; 272 addr = addrn - pgsize;
273 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); 273 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
274 err = mtd->read(mtd, addr, pgsize, &read, pp3); 274 err = mtd->read(mtd, addr, pgsize, &read, pp3);
275 if (err == -EUCLEAN) 275 if (mtd_is_bitflip(err))
276 err = 0; 276 err = 0;
277 if (err || read != pgsize) { 277 if (err || read != pgsize) {
278 printk(PRINT_PREF "error: read failed at %#llx\n", 278 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -286,7 +286,7 @@ static int crosstest(void)
286 addr = addr0; 286 addr = addr0;
287 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); 287 printk(PRINT_PREF "reading page at %#llx\n", (long long)addr);
288 err = mtd->read(mtd, addr, pgsize, &read, pp4); 288 err = mtd->read(mtd, addr, pgsize, &read, pp4);
289 if (err == -EUCLEAN) 289 if (mtd_is_bitflip(err))
290 err = 0; 290 err = 0;
291 if (err || read != pgsize) { 291 if (err || read != pgsize) {
292 printk(PRINT_PREF "error: read failed at %#llx\n", 292 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -345,7 +345,7 @@ static int erasecrosstest(void)
345 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); 345 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
346 memset(readbuf, 0, pgsize); 346 memset(readbuf, 0, pgsize);
347 err = mtd->read(mtd, addr0, pgsize, &read, readbuf); 347 err = mtd->read(mtd, addr0, pgsize, &read, readbuf);
348 if (err == -EUCLEAN) 348 if (mtd_is_bitflip(err))
349 err = 0; 349 err = 0;
350 if (err || read != pgsize) { 350 if (err || read != pgsize) {
351 printk(PRINT_PREF "error: read failed at %#llx\n", 351 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -383,7 +383,7 @@ static int erasecrosstest(void)
383 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); 383 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
384 memset(readbuf, 0, pgsize); 384 memset(readbuf, 0, pgsize);
385 err = mtd->read(mtd, addr0, pgsize, &read, readbuf); 385 err = mtd->read(mtd, addr0, pgsize, &read, readbuf);
386 if (err == -EUCLEAN) 386 if (mtd_is_bitflip(err))
387 err = 0; 387 err = 0;
388 if (err || read != pgsize) { 388 if (err || read != pgsize) {
389 printk(PRINT_PREF "error: read failed at %#llx\n", 389 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -439,7 +439,7 @@ static int erasetest(void)
439 439
440 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); 440 printk(PRINT_PREF "reading 1st page of block %d\n", ebnum);
441 err = mtd->read(mtd, addr0, pgsize, &read, twopages); 441 err = mtd->read(mtd, addr0, pgsize, &read, twopages);
442 if (err == -EUCLEAN) 442 if (mtd_is_bitflip(err))
443 err = 0; 443 err = 0;
444 if (err || read != pgsize) { 444 if (err || read != pgsize) {
445 printk(PRINT_PREF "error: read failed at %#llx\n", 445 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -504,6 +504,13 @@ static int __init mtd_pagetest_init(void)
504 504
505 printk(KERN_INFO "\n"); 505 printk(KERN_INFO "\n");
506 printk(KERN_INFO "=================================================\n"); 506 printk(KERN_INFO "=================================================\n");
507
508 if (dev < 0) {
509 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
510 printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
511 return -EINVAL;
512 }
513
507 printk(PRINT_PREF "MTD device: %d\n", dev); 514 printk(PRINT_PREF "MTD device: %d\n", dev);
508 515
509 mtd = get_mtd_device(NULL, dev); 516 mtd = get_mtd_device(NULL, dev);
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c
index afe71aa15c4..550fe51225a 100644
--- a/drivers/mtd/tests/mtd_readtest.c
+++ b/drivers/mtd/tests/mtd_readtest.c
@@ -29,7 +29,7 @@
29 29
30#define PRINT_PREF KERN_INFO "mtd_readtest: " 30#define PRINT_PREF KERN_INFO "mtd_readtest: "
31 31
32static int dev; 32static int dev = -EINVAL;
33module_param(dev, int, S_IRUGO); 33module_param(dev, int, S_IRUGO);
34MODULE_PARM_DESC(dev, "MTD device number to use"); 34MODULE_PARM_DESC(dev, "MTD device number to use");
35 35
@@ -66,7 +66,7 @@ static int read_eraseblock_by_page(int ebnum)
66 if (mtd->oobsize) { 66 if (mtd->oobsize) {
67 struct mtd_oob_ops ops; 67 struct mtd_oob_ops ops;
68 68
69 ops.mode = MTD_OOB_PLACE; 69 ops.mode = MTD_OPS_PLACE_OOB;
70 ops.len = 0; 70 ops.len = 0;
71 ops.retlen = 0; 71 ops.retlen = 0;
72 ops.ooblen = mtd->oobsize; 72 ops.ooblen = mtd->oobsize;
@@ -75,7 +75,8 @@ static int read_eraseblock_by_page(int ebnum)
75 ops.datbuf = NULL; 75 ops.datbuf = NULL;
76 ops.oobbuf = oobbuf; 76 ops.oobbuf = oobbuf;
77 ret = mtd->read_oob(mtd, addr, &ops); 77 ret = mtd->read_oob(mtd, addr, &ops);
78 if (ret || ops.oobretlen != mtd->oobsize) { 78 if ((ret && !mtd_is_bitflip(ret)) ||
79 ops.oobretlen != mtd->oobsize) {
79 printk(PRINT_PREF "error: read oob failed at " 80 printk(PRINT_PREF "error: read oob failed at "
80 "%#llx\n", (long long)addr); 81 "%#llx\n", (long long)addr);
81 if (!err) 82 if (!err)
@@ -169,6 +170,12 @@ static int __init mtd_readtest_init(void)
169 170
170 printk(KERN_INFO "\n"); 171 printk(KERN_INFO "\n");
171 printk(KERN_INFO "=================================================\n"); 172 printk(KERN_INFO "=================================================\n");
173
174 if (dev < 0) {
175 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
176 return -EINVAL;
177 }
178
172 printk(PRINT_PREF "MTD device: %d\n", dev); 179 printk(PRINT_PREF "MTD device: %d\n", dev);
173 180
174 mtd = get_mtd_device(NULL, dev); 181 mtd = get_mtd_device(NULL, dev);
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 627d4e2466a..493b367bdd3 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -29,7 +29,7 @@
29 29
30#define PRINT_PREF KERN_INFO "mtd_speedtest: " 30#define PRINT_PREF KERN_INFO "mtd_speedtest: "
31 31
32static int dev; 32static int dev = -EINVAL;
33module_param(dev, int, S_IRUGO); 33module_param(dev, int, S_IRUGO);
34MODULE_PARM_DESC(dev, "MTD device number to use"); 34MODULE_PARM_DESC(dev, "MTD device number to use");
35 35
@@ -216,7 +216,7 @@ static int read_eraseblock(int ebnum)
216 216
217 err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf); 217 err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf);
218 /* Ignore corrected ECC errors */ 218 /* Ignore corrected ECC errors */
219 if (err == -EUCLEAN) 219 if (mtd_is_bitflip(err))
220 err = 0; 220 err = 0;
221 if (err || read != mtd->erasesize) { 221 if (err || read != mtd->erasesize) {
222 printk(PRINT_PREF "error: read failed at %#llx\n", addr); 222 printk(PRINT_PREF "error: read failed at %#llx\n", addr);
@@ -237,7 +237,7 @@ static int read_eraseblock_by_page(int ebnum)
237 for (i = 0; i < pgcnt; i++) { 237 for (i = 0; i < pgcnt; i++) {
238 err = mtd->read(mtd, addr, pgsize, &read, buf); 238 err = mtd->read(mtd, addr, pgsize, &read, buf);
239 /* Ignore corrected ECC errors */ 239 /* Ignore corrected ECC errors */
240 if (err == -EUCLEAN) 240 if (mtd_is_bitflip(err))
241 err = 0; 241 err = 0;
242 if (err || read != pgsize) { 242 if (err || read != pgsize) {
243 printk(PRINT_PREF "error: read failed at %#llx\n", 243 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -263,7 +263,7 @@ static int read_eraseblock_by_2pages(int ebnum)
263 for (i = 0; i < n; i++) { 263 for (i = 0; i < n; i++) {
264 err = mtd->read(mtd, addr, sz, &read, buf); 264 err = mtd->read(mtd, addr, sz, &read, buf);
265 /* Ignore corrected ECC errors */ 265 /* Ignore corrected ECC errors */
266 if (err == -EUCLEAN) 266 if (mtd_is_bitflip(err))
267 err = 0; 267 err = 0;
268 if (err || read != sz) { 268 if (err || read != sz) {
269 printk(PRINT_PREF "error: read failed at %#llx\n", 269 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -278,7 +278,7 @@ static int read_eraseblock_by_2pages(int ebnum)
278 if (pgcnt % 2) { 278 if (pgcnt % 2) {
279 err = mtd->read(mtd, addr, pgsize, &read, buf); 279 err = mtd->read(mtd, addr, pgsize, &read, buf);
280 /* Ignore corrected ECC errors */ 280 /* Ignore corrected ECC errors */
281 if (err == -EUCLEAN) 281 if (mtd_is_bitflip(err))
282 err = 0; 282 err = 0;
283 if (err || read != pgsize) { 283 if (err || read != pgsize) {
284 printk(PRINT_PREF "error: read failed at %#llx\n", 284 printk(PRINT_PREF "error: read failed at %#llx\n",
@@ -361,6 +361,13 @@ static int __init mtd_speedtest_init(void)
361 361
362 printk(KERN_INFO "\n"); 362 printk(KERN_INFO "\n");
363 printk(KERN_INFO "=================================================\n"); 363 printk(KERN_INFO "=================================================\n");
364
365 if (dev < 0) {
366 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
367 printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
368 return -EINVAL;
369 }
370
364 if (count) 371 if (count)
365 printk(PRINT_PREF "MTD device: %d count: %d\n", dev, count); 372 printk(PRINT_PREF "MTD device: %d count: %d\n", dev, count);
366 else 373 else
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 531625fc925..52ffd9120e0 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -30,7 +30,7 @@
30 30
31#define PRINT_PREF KERN_INFO "mtd_stresstest: " 31#define PRINT_PREF KERN_INFO "mtd_stresstest: "
32 32
33static int dev; 33static int dev = -EINVAL;
34module_param(dev, int, S_IRUGO); 34module_param(dev, int, S_IRUGO);
35MODULE_PARM_DESC(dev, "MTD device number to use"); 35MODULE_PARM_DESC(dev, "MTD device number to use");
36 36
@@ -154,7 +154,7 @@ static int do_read(void)
154 } 154 }
155 addr = eb * mtd->erasesize + offs; 155 addr = eb * mtd->erasesize + offs;
156 err = mtd->read(mtd, addr, len, &read, readbuf); 156 err = mtd->read(mtd, addr, len, &read, readbuf);
157 if (err == -EUCLEAN) 157 if (mtd_is_bitflip(err))
158 err = 0; 158 err = 0;
159 if (unlikely(err || read != len)) { 159 if (unlikely(err || read != len)) {
160 printk(PRINT_PREF "error: read failed at 0x%llx\n", 160 printk(PRINT_PREF "error: read failed at 0x%llx\n",
@@ -250,6 +250,13 @@ static int __init mtd_stresstest_init(void)
250 250
251 printk(KERN_INFO "\n"); 251 printk(KERN_INFO "\n");
252 printk(KERN_INFO "=================================================\n"); 252 printk(KERN_INFO "=================================================\n");
253
254 if (dev < 0) {
255 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
256 printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
257 return -EINVAL;
258 }
259
253 printk(PRINT_PREF "MTD device: %d\n", dev); 260 printk(PRINT_PREF "MTD device: %d\n", dev);
254 261
255 mtd = get_mtd_device(NULL, dev); 262 mtd = get_mtd_device(NULL, dev);
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index 334eae53a3d..1a05bfac4ee 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -29,7 +29,7 @@
29 29
30#define PRINT_PREF KERN_INFO "mtd_subpagetest: " 30#define PRINT_PREF KERN_INFO "mtd_subpagetest: "
31 31
32static int dev; 32static int dev = -EINVAL;
33module_param(dev, int, S_IRUGO); 33module_param(dev, int, S_IRUGO);
34MODULE_PARM_DESC(dev, "MTD device number to use"); 34MODULE_PARM_DESC(dev, "MTD device number to use");
35 35
@@ -198,7 +198,7 @@ static int verify_eraseblock(int ebnum)
198 read = 0; 198 read = 0;
199 err = mtd->read(mtd, addr, subpgsize, &read, readbuf); 199 err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
200 if (unlikely(err || read != subpgsize)) { 200 if (unlikely(err || read != subpgsize)) {
201 if (err == -EUCLEAN && read == subpgsize) { 201 if (mtd_is_bitflip(err) && read == subpgsize) {
202 printk(PRINT_PREF "ECC correction at %#llx\n", 202 printk(PRINT_PREF "ECC correction at %#llx\n",
203 (long long)addr); 203 (long long)addr);
204 err = 0; 204 err = 0;
@@ -226,7 +226,7 @@ static int verify_eraseblock(int ebnum)
226 read = 0; 226 read = 0;
227 err = mtd->read(mtd, addr, subpgsize, &read, readbuf); 227 err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
228 if (unlikely(err || read != subpgsize)) { 228 if (unlikely(err || read != subpgsize)) {
229 if (err == -EUCLEAN && read == subpgsize) { 229 if (mtd_is_bitflip(err) && read == subpgsize) {
230 printk(PRINT_PREF "ECC correction at %#llx\n", 230 printk(PRINT_PREF "ECC correction at %#llx\n",
231 (long long)addr); 231 (long long)addr);
232 err = 0; 232 err = 0;
@@ -264,7 +264,7 @@ static int verify_eraseblock2(int ebnum)
264 read = 0; 264 read = 0;
265 err = mtd->read(mtd, addr, subpgsize * k, &read, readbuf); 265 err = mtd->read(mtd, addr, subpgsize * k, &read, readbuf);
266 if (unlikely(err || read != subpgsize * k)) { 266 if (unlikely(err || read != subpgsize * k)) {
267 if (err == -EUCLEAN && read == subpgsize * k) { 267 if (mtd_is_bitflip(err) && read == subpgsize * k) {
268 printk(PRINT_PREF "ECC correction at %#llx\n", 268 printk(PRINT_PREF "ECC correction at %#llx\n",
269 (long long)addr); 269 (long long)addr);
270 err = 0; 270 err = 0;
@@ -298,7 +298,7 @@ static int verify_eraseblock_ff(int ebnum)
298 read = 0; 298 read = 0;
299 err = mtd->read(mtd, addr, subpgsize, &read, readbuf); 299 err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
300 if (unlikely(err || read != subpgsize)) { 300 if (unlikely(err || read != subpgsize)) {
301 if (err == -EUCLEAN && read == subpgsize) { 301 if (mtd_is_bitflip(err) && read == subpgsize) {
302 printk(PRINT_PREF "ECC correction at %#llx\n", 302 printk(PRINT_PREF "ECC correction at %#llx\n",
303 (long long)addr); 303 (long long)addr);
304 err = 0; 304 err = 0;
@@ -379,6 +379,13 @@ static int __init mtd_subpagetest_init(void)
379 379
380 printk(KERN_INFO "\n"); 380 printk(KERN_INFO "\n");
381 printk(KERN_INFO "=================================================\n"); 381 printk(KERN_INFO "=================================================\n");
382
383 if (dev < 0) {
384 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
385 printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
386 return -EINVAL;
387 }
388
382 printk(PRINT_PREF "MTD device: %d\n", dev); 389 printk(PRINT_PREF "MTD device: %d\n", dev);
383 390
384 mtd = get_mtd_device(NULL, dev); 391 mtd = get_mtd_device(NULL, dev);
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 5c6c3d24890..03ab649a696 100644
--- a/drivers/mtd/tests/mtd_torturetest.c
+++ b/drivers/mtd/tests/mtd_torturetest.c
@@ -46,7 +46,7 @@ static int pgcnt;
46module_param(pgcnt, int, S_IRUGO); 46module_param(pgcnt, int, S_IRUGO);
47MODULE_PARM_DESC(pgcnt, "number of pages per eraseblock to torture (0 => all)"); 47MODULE_PARM_DESC(pgcnt, "number of pages per eraseblock to torture (0 => all)");
48 48
49static int dev; 49static int dev = -EINVAL;
50module_param(dev, int, S_IRUGO); 50module_param(dev, int, S_IRUGO);
51MODULE_PARM_DESC(dev, "MTD device number to use"); 51MODULE_PARM_DESC(dev, "MTD device number to use");
52 52
@@ -138,7 +138,7 @@ static inline int check_eraseblock(int ebnum, unsigned char *buf)
138 138
139retry: 139retry:
140 err = mtd->read(mtd, addr, len, &read, check_buf); 140 err = mtd->read(mtd, addr, len, &read, check_buf);
141 if (err == -EUCLEAN) 141 if (mtd_is_bitflip(err))
142 printk(PRINT_PREF "single bit flip occurred at EB %d " 142 printk(PRINT_PREF "single bit flip occurred at EB %d "
143 "MTD reported that it was fixed.\n", ebnum); 143 "MTD reported that it was fixed.\n", ebnum);
144 else if (err) { 144 else if (err) {
@@ -213,6 +213,13 @@ static int __init tort_init(void)
213 printk(KERN_INFO "=================================================\n"); 213 printk(KERN_INFO "=================================================\n");
214 printk(PRINT_PREF "Warning: this program is trying to wear out your " 214 printk(PRINT_PREF "Warning: this program is trying to wear out your "
215 "flash, stop it if this is not wanted.\n"); 215 "flash, stop it if this is not wanted.\n");
216
217 if (dev < 0) {
218 printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
219 printk(KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n");
220 return -EINVAL;
221 }
222
216 printk(PRINT_PREF "MTD device: %d\n", dev); 223 printk(PRINT_PREF "MTD device: %d\n", dev);
217 printk(PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n", 224 printk(PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n",
218 ebcnt, eb, eb + ebcnt - 1, dev); 225 ebcnt, eb, eb + ebcnt - 1, dev);
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 4be67181501..fb7f19b62d9 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -443,7 +443,7 @@ retry:
443 if (err == UBI_IO_BITFLIPS) { 443 if (err == UBI_IO_BITFLIPS) {
444 scrub = 1; 444 scrub = 1;
445 err = 0; 445 err = 0;
446 } else if (err == -EBADMSG) { 446 } else if (mtd_is_eccerr(err)) {
447 if (vol->vol_type == UBI_DYNAMIC_VOLUME) 447 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
448 goto out_unlock; 448 goto out_unlock;
449 scrub = 1; 449 scrub = 1;
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 6ba55c23587..f20b6f22f24 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -172,9 +172,9 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
172retry: 172retry:
173 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); 173 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
174 if (err) { 174 if (err) {
175 const char *errstr = (err == -EBADMSG) ? " (ECC error)" : ""; 175 const char *errstr = mtd_is_eccerr(err) ? " (ECC error)" : "";
176 176
177 if (err == -EUCLEAN) { 177 if (mtd_is_bitflip(err)) {
178 /* 178 /*
179 * -EUCLEAN is reported if there was a bit-flip which 179 * -EUCLEAN is reported if there was a bit-flip which
180 * was corrected, so this is harmless. 180 * was corrected, so this is harmless.
@@ -205,7 +205,7 @@ retry:
205 * all the requested data. But some buggy drivers might do 205 * all the requested data. But some buggy drivers might do
206 * this, so we change it to -EIO. 206 * this, so we change it to -EIO.
207 */ 207 */
208 if (read != len && err == -EBADMSG) { 208 if (read != len && mtd_is_eccerr(err)) {
209 ubi_assert(0); 209 ubi_assert(0);
210 err = -EIO; 210 err = -EIO;
211 } 211 }
@@ -469,7 +469,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
469 469
470out: 470out:
471 mutex_unlock(&ubi->buf_mutex); 471 mutex_unlock(&ubi->buf_mutex);
472 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) { 472 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
473 /* 473 /*
474 * If a bit-flip or data integrity error was detected, the test 474 * If a bit-flip or data integrity error was detected, the test
475 * has not passed because it happened on a freshly erased 475 * has not passed because it happened on a freshly erased
@@ -760,7 +760,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
760 760
761 read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 761 read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
762 if (read_err) { 762 if (read_err) {
763 if (read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG) 763 if (read_err != UBI_IO_BITFLIPS && !mtd_is_eccerr(read_err))
764 return read_err; 764 return read_err;
765 765
766 /* 766 /*
@@ -776,7 +776,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
776 776
777 magic = be32_to_cpu(ec_hdr->magic); 777 magic = be32_to_cpu(ec_hdr->magic);
778 if (magic != UBI_EC_HDR_MAGIC) { 778 if (magic != UBI_EC_HDR_MAGIC) {
779 if (read_err == -EBADMSG) 779 if (mtd_is_eccerr(read_err))
780 return UBI_IO_BAD_HDR_EBADMSG; 780 return UBI_IO_BAD_HDR_EBADMSG;
781 781
782 /* 782 /*
@@ -1032,12 +1032,12 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1032 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1032 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1033 read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 1033 read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
1034 ubi->vid_hdr_alsize); 1034 ubi->vid_hdr_alsize);
1035 if (read_err && read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG) 1035 if (read_err && read_err != UBI_IO_BITFLIPS && !mtd_is_eccerr(read_err))
1036 return read_err; 1036 return read_err;
1037 1037
1038 magic = be32_to_cpu(vid_hdr->magic); 1038 magic = be32_to_cpu(vid_hdr->magic);
1039 if (magic != UBI_VID_HDR_MAGIC) { 1039 if (magic != UBI_VID_HDR_MAGIC) {
1040 if (read_err == -EBADMSG) 1040 if (mtd_is_eccerr(read_err))
1041 return UBI_IO_BAD_HDR_EBADMSG; 1041 return UBI_IO_BAD_HDR_EBADMSG;
1042 1042
1043 if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { 1043 if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
@@ -1219,7 +1219,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1219 return -ENOMEM; 1219 return -ENOMEM;
1220 1220
1221 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 1221 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
1222 if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG) 1222 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
1223 goto exit; 1223 goto exit;
1224 1224
1225 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 1225 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
@@ -1306,7 +1306,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1306 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1306 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1307 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 1307 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
1308 ubi->vid_hdr_alsize); 1308 ubi->vid_hdr_alsize);
1309 if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG) 1309 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
1310 goto exit; 1310 goto exit;
1311 1311
1312 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); 1312 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC);
@@ -1358,7 +1358,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1358 } 1358 }
1359 1359
1360 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1); 1360 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1);
1361 if (err && err != -EUCLEAN) 1361 if (err && !mtd_is_bitflip(err))
1362 goto out_free; 1362 goto out_free;
1363 1363
1364 for (i = 0; i < len; i++) { 1364 for (i = 0; i < len; i++) {
@@ -1422,7 +1422,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1422 } 1422 }
1423 1423
1424 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); 1424 err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
1425 if (err && err != -EUCLEAN) { 1425 if (err && !mtd_is_bitflip(err)) {
1426 ubi_err("error %d while reading %d bytes from PEB %d:%d, " 1426 ubi_err("error %d while reading %d bytes from PEB %d:%d, "
1427 "read %zd bytes", err, len, pnum, offset, read); 1427 "read %zd bytes", err, len, pnum, offset, read);
1428 goto error; 1428 goto error;
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index d39716e5b20..1a35fc5e3b4 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -410,7 +410,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
410 return 0; 410 return 0;
411 411
412 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check); 412 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check);
413 if (err && err == -EBADMSG && vol->vol_type == UBI_STATIC_VOLUME) { 413 if (err && mtd_is_eccerr(err) && vol->vol_type == UBI_STATIC_VOLUME) {
414 ubi_warn("mark volume %d as corrupted", vol_id); 414 ubi_warn("mark volume %d as corrupted", vol_id);
415 vol->corrupted = 1; 415 vol->corrupted = 1;
416 } 416 }
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index ff2a65c37f6..f6a7d7ac4b9 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -81,7 +81,7 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id)
81 81
82 err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1); 82 err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1);
83 if (err) { 83 if (err) {
84 if (err == -EBADMSG) 84 if (mtd_is_eccerr(err))
85 err = 1; 85 err = 1;
86 break; 86 break;
87 } 87 }
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index a3a198f9b98..0cb17d936b5 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -395,7 +395,7 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
395 } 395 }
396 396
397 err = ubi_io_read_data(ubi, buf, pnum, 0, len); 397 err = ubi_io_read_data(ubi, buf, pnum, 0, len);
398 if (err && err != UBI_IO_BITFLIPS && err != -EBADMSG) 398 if (err && err != UBI_IO_BITFLIPS && !mtd_is_eccerr(err))
399 goto out_free_buf; 399 goto out_free_buf;
400 400
401 data_crc = be32_to_cpu(vid_hdr->data_crc); 401 data_crc = be32_to_cpu(vid_hdr->data_crc);
@@ -793,7 +793,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
793 793
794 err = ubi_io_read(ubi, ubi->peb_buf1, pnum, ubi->leb_start, 794 err = ubi_io_read(ubi, ubi->peb_buf1, pnum, ubi->leb_start,
795 ubi->leb_size); 795 ubi->leb_size);
796 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) { 796 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err)) {
797 /* 797 /*
798 * Bit-flips or integrity errors while reading the data area. 798 * Bit-flips or integrity errors while reading the data area.
799 * It is difficult to say for sure what type of corruption is 799 * It is difficult to say for sure what type of corruption is
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 97e093d1967..863835f4aef 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/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 4b50a3029b8..9ad18da1891 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -423,7 +423,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
423 423
424 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0, 424 err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
425 ubi->vtbl_size); 425 ubi->vtbl_size);
426 if (err == UBI_IO_BITFLIPS || err == -EBADMSG) 426 if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err))
427 /* 427 /*
428 * Scrub the PEB later. Note, -EBADMSG indicates an 428 * Scrub the PEB later. Note, -EBADMSG indicates an
429 * uncorrectable ECC error, but we have our own CRC and 429 * uncorrectable ECC error, but we have our own CRC and
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 583f66cd5bb..654a5e94e0e 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -245,6 +245,8 @@ source "drivers/net/ethernet/Kconfig"
245 245
246source "drivers/net/fddi/Kconfig" 246source "drivers/net/fddi/Kconfig"
247 247
248source "drivers/net/hippi/Kconfig"
249
248config NET_SB1000 250config NET_SB1000
249 tristate "General Instruments Surfboard 1000" 251 tristate "General Instruments Surfboard 1000"
250 depends on PNP 252 depends on PNP
diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index a73d9dc80ff..84fb6349a59 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -4,7 +4,7 @@
4 4
5menuconfig ARCNET 5menuconfig ARCNET
6 depends on NETDEVICES && (ISA || PCI || PCMCIA) 6 depends on NETDEVICES && (ISA || PCI || PCMCIA)
7 bool "ARCnet support" 7 tristate "ARCnet support"
8 ---help--- 8 ---help---
9 If you have a network card of this type, say Y and check out the 9 If you have a network card of this type, say Y and check out the
10 (arguably) beautiful poetry in 10 (arguably) beautiful poetry in
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c34cc1e7c6f..7f8756825b8 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 = SPEED_UNKNOWN;
564 slave->speed = SPEED_100; 564 slave->duplex = DUPLEX_UNKNOWN;
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 */
@@ -2563,30 +2553,6 @@ re_arm:
2563 } 2553 }
2564} 2554}
2565 2555
2566static __be32 bond_glean_dev_ip(struct net_device *dev)
2567{
2568 struct in_device *idev;
2569 struct in_ifaddr *ifa;
2570 __be32 addr = 0;
2571
2572 if (!dev)
2573 return 0;
2574
2575 rcu_read_lock();
2576 idev = __in_dev_get_rcu(dev);
2577 if (!idev)
2578 goto out;
2579
2580 ifa = idev->ifa_list;
2581 if (!ifa)
2582 goto out;
2583
2584 addr = ifa->ifa_local;
2585out:
2586 rcu_read_unlock();
2587 return addr;
2588}
2589
2590static int bond_has_this_ip(struct bonding *bond, __be32 ip) 2556static int bond_has_this_ip(struct bonding *bond, __be32 ip)
2591{ 2557{
2592 struct vlan_entry *vlan; 2558 struct vlan_entry *vlan;
@@ -3220,6 +3186,7 @@ static int bond_slave_netdev_event(unsigned long event,
3220{ 3186{
3221 struct net_device *bond_dev = slave_dev->master; 3187 struct net_device *bond_dev = slave_dev->master;
3222 struct bonding *bond = netdev_priv(bond_dev); 3188 struct bonding *bond = netdev_priv(bond_dev);
3189 struct slave *slave = NULL;
3223 3190
3224 switch (event) { 3191 switch (event) {
3225 case NETDEV_UNREGISTER: 3192 case NETDEV_UNREGISTER:
@@ -3230,20 +3197,16 @@ static int bond_slave_netdev_event(unsigned long event,
3230 bond_release(bond_dev, slave_dev); 3197 bond_release(bond_dev, slave_dev);
3231 } 3198 }
3232 break; 3199 break;
3200 case NETDEV_UP:
3233 case NETDEV_CHANGE: 3201 case NETDEV_CHANGE:
3234 if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) { 3202 slave = bond_get_slave_by_dev(bond, slave_dev);
3235 struct slave *slave; 3203 if (slave) {
3204 u32 old_speed = slave->speed;
3205 u8 old_duplex = slave->duplex;
3236 3206
3237 slave = bond_get_slave_by_dev(bond, slave_dev); 3207 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 3208
3209 if (bond->params.mode == BOND_MODE_8023AD) {
3247 if (old_speed != slave->speed) 3210 if (old_speed != slave->speed)
3248 bond_3ad_adapter_speed_changed(slave); 3211 bond_3ad_adapter_speed_changed(slave);
3249 if (old_duplex != slave->duplex) 3212 if (old_duplex != slave->duplex)
@@ -3335,6 +3298,10 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
3335 struct bonding *bond; 3298 struct bonding *bond;
3336 struct vlan_entry *vlan; 3299 struct vlan_entry *vlan;
3337 3300
3301 /* we only care about primary address */
3302 if(ifa->ifa_flags & IFA_F_SECONDARY)
3303 return NOTIFY_DONE;
3304
3338 list_for_each_entry(bond, &bn->dev_list, bond_list) { 3305 list_for_each_entry(bond, &bn->dev_list, bond_list) {
3339 if (bond->dev == event_dev) { 3306 if (bond->dev == event_dev) {
3340 switch (event) { 3307 switch (event) {
@@ -3342,7 +3309,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
3342 bond->master_ip = ifa->ifa_local; 3309 bond->master_ip = ifa->ifa_local;
3343 return NOTIFY_OK; 3310 return NOTIFY_OK;
3344 case NETDEV_DOWN: 3311 case NETDEV_DOWN:
3345 bond->master_ip = bond_glean_dev_ip(bond->dev); 3312 bond->master_ip = 0;
3346 return NOTIFY_OK; 3313 return NOTIFY_OK;
3347 default: 3314 default:
3348 return NOTIFY_DONE; 3315 return NOTIFY_DONE;
@@ -3358,8 +3325,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
3358 vlan->vlan_ip = ifa->ifa_local; 3325 vlan->vlan_ip = ifa->ifa_local;
3359 return NOTIFY_OK; 3326 return NOTIFY_OK;
3360 case NETDEV_DOWN: 3327 case NETDEV_DOWN:
3361 vlan->vlan_ip = 3328 vlan->vlan_ip = 0;
3362 bond_glean_dev_ip(vlan_dev);
3363 return NOTIFY_OK; 3329 return NOTIFY_OK;
3364 default: 3330 default:
3365 return NOTIFY_DONE; 3331 return NOTIFY_DONE;
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index 95de93b9038..ad284baafe8 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 == SPEED_UNKNOWN)
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 == DUPLEX_UNKNOWN)
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/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 5a20804fdec..4ef7e2fd9fe 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -319,6 +319,13 @@ static ssize_t bonding_store_mode(struct device *d,
319 goto out; 319 goto out;
320 } 320 }
321 321
322 if (bond->slave_cnt > 0) {
323 pr_err("unable to update mode of %s because it has slaves.\n",
324 bond->dev->name);
325 ret = -EPERM;
326 goto out;
327 }
328
322 new_value = bond_parse_parm(buf, bond_mode_tbl); 329 new_value = bond_parse_parm(buf, bond_mode_tbl);
323 if (new_value < 0) { 330 if (new_value < 0) {
324 pr_err("%s: Ignoring invalid mode value %.*s.\n", 331 pr_err("%s: Ignoring invalid mode value %.*s.\n",
diff --git a/drivers/net/can/sja1000/peak_pci.c b/drivers/net/can/sja1000/peak_pci.c
index 905bce0b3a4..2c7f5036f57 100644
--- a/drivers/net/can/sja1000/peak_pci.c
+++ b/drivers/net/can/sja1000/peak_pci.c
@@ -20,7 +20,6 @@
20 */ 20 */
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/version.h>
24#include <linux/module.h> 23#include <linux/module.h>
25#include <linux/interrupt.h> 24#include <linux/interrupt.h>
26#include <linux/netdevice.h> 25#include <linux/netdevice.h>
diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig
index 6dff5a0e733..597f4d45c63 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 c53ad3afc99..be5dde04026 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 82386677bb8..4865ff14beb 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 6229c774552..4b7f7ad62bb 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 a759d5483ab..1375e2dc946 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 0d3a5919c95..86eaa17af0f 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/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
index 4cf835dbc12..3fb66d09ece 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -608,7 +608,7 @@ static void b44_tx(struct b44 *bp)
608 skb->len, 608 skb->len,
609 DMA_TO_DEVICE); 609 DMA_TO_DEVICE);
610 rp->skb = NULL; 610 rp->skb = NULL;
611 dev_kfree_skb(skb); 611 dev_kfree_skb_irq(skb);
612 } 612 }
613 613
614 bp->tx_cons = cons; 614 bp->tx_cons = cons;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
index bce203fa4b9..882f48f0a03 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_link.c
@@ -10327,6 +10327,43 @@ static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
10327 return 0; 10327 return 0;
10328} 10328}
10329 10329
10330
10331static void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
10332 struct link_params *params, u8 mode)
10333{
10334 struct bnx2x *bp = params->bp;
10335 u16 temp;
10336
10337 bnx2x_cl22_write(bp, phy,
10338 MDIO_REG_GPHY_SHADOW,
10339 MDIO_REG_GPHY_SHADOW_LED_SEL1);
10340 bnx2x_cl22_read(bp, phy,
10341 MDIO_REG_GPHY_SHADOW,
10342 &temp);
10343 temp &= 0xff00;
10344
10345 DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
10346 switch (mode) {
10347 case LED_MODE_FRONT_PANEL_OFF:
10348 case LED_MODE_OFF:
10349 temp |= 0x00ee;
10350 break;
10351 case LED_MODE_OPER:
10352 temp |= 0x0001;
10353 break;
10354 case LED_MODE_ON:
10355 temp |= 0x00ff;
10356 break;
10357 default:
10358 break;
10359 }
10360 bnx2x_cl22_write(bp, phy,
10361 MDIO_REG_GPHY_SHADOW,
10362 MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
10363 return;
10364}
10365
10366
10330static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy, 10367static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
10331 struct link_params *params) 10368 struct link_params *params)
10332{ 10369{
@@ -11103,7 +11140,7 @@ static struct bnx2x_phy phy_54618se = {
11103 .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback, 11140 .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
11104 .format_fw_ver = (format_fw_ver_t)NULL, 11141 .format_fw_ver = (format_fw_ver_t)NULL,
11105 .hw_reset = (hw_reset_t)NULL, 11142 .hw_reset = (hw_reset_t)NULL,
11106 .set_link_led = (set_link_led_t)NULL, 11143 .set_link_led = (set_link_led_t)bnx2x_5461x_set_link_led,
11107 .phy_specific_func = (phy_specific_func_t)NULL 11144 .phy_specific_func = (phy_specific_func_t)NULL
11108}; 11145};
11109/*****************************************************************/ 11146/*****************************************************************/
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 6486ab8c8fc..2f6361e949f 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -10548,33 +10548,38 @@ do { \
10548 10548
10549int bnx2x_init_firmware(struct bnx2x *bp) 10549int bnx2x_init_firmware(struct bnx2x *bp)
10550{ 10550{
10551 const char *fw_file_name;
10552 struct bnx2x_fw_file_hdr *fw_hdr; 10551 struct bnx2x_fw_file_hdr *fw_hdr;
10553 int rc; 10552 int rc;
10554 10553
10555 if (CHIP_IS_E1(bp))
10556 fw_file_name = FW_FILE_NAME_E1;
10557 else if (CHIP_IS_E1H(bp))
10558 fw_file_name = FW_FILE_NAME_E1H;
10559 else if (!CHIP_IS_E1x(bp))
10560 fw_file_name = FW_FILE_NAME_E2;
10561 else {
10562 BNX2X_ERR("Unsupported chip revision\n");
10563 return -EINVAL;
10564 }
10565 10554
10566 BNX2X_DEV_INFO("Loading %s\n", fw_file_name); 10555 if (!bp->firmware) {
10556 const char *fw_file_name;
10567 10557
10568 rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev); 10558 if (CHIP_IS_E1(bp))
10569 if (rc) { 10559 fw_file_name = FW_FILE_NAME_E1;
10570 BNX2X_ERR("Can't load firmware file %s\n", fw_file_name); 10560 else if (CHIP_IS_E1H(bp))
10571 goto request_firmware_exit; 10561 fw_file_name = FW_FILE_NAME_E1H;
10572 } 10562 else if (!CHIP_IS_E1x(bp))
10563 fw_file_name = FW_FILE_NAME_E2;
10564 else {
10565 BNX2X_ERR("Unsupported chip revision\n");
10566 return -EINVAL;
10567 }
10568 BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
10573 10569
10574 rc = bnx2x_check_firmware(bp); 10570 rc = request_firmware(&bp->firmware, fw_file_name,
10575 if (rc) { 10571 &bp->pdev->dev);
10576 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name); 10572 if (rc) {
10577 goto request_firmware_exit; 10573 BNX2X_ERR("Can't load firmware file %s\n",
10574 fw_file_name);
10575 goto request_firmware_exit;
10576 }
10577
10578 rc = bnx2x_check_firmware(bp);
10579 if (rc) {
10580 BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
10581 goto request_firmware_exit;
10582 }
10578 } 10583 }
10579 10584
10580 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data; 10585 fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
@@ -10630,6 +10635,7 @@ static void bnx2x_release_firmware(struct bnx2x *bp)
10630 kfree(bp->init_ops); 10635 kfree(bp->init_ops);
10631 kfree(bp->init_data); 10636 kfree(bp->init_data);
10632 release_firmware(bp->firmware); 10637 release_firmware(bp->firmware);
10638 bp->firmware = NULL;
10633} 10639}
10634 10640
10635 10641
@@ -10925,6 +10931,8 @@ static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
10925 if (bp->doorbells) 10931 if (bp->doorbells)
10926 iounmap(bp->doorbells); 10932 iounmap(bp->doorbells);
10927 10933
10934 bnx2x_release_firmware(bp);
10935
10928 bnx2x_free_mem_bp(bp); 10936 bnx2x_free_mem_bp(bp);
10929 10937
10930 free_netdev(dev); 10938 free_netdev(dev);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
index fc7bd0f23c0..e58073ef33b 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
@@ -6990,6 +6990,7 @@ Theotherbitsarereservedandshouldbezero*/
6990#define MDIO_REG_INTR_MASK 0x1b 6990#define MDIO_REG_INTR_MASK 0x1b
6991#define MDIO_REG_INTR_MASK_LINK_STATUS (0x1 << 1) 6991#define MDIO_REG_INTR_MASK_LINK_STATUS (0x1 << 1)
6992#define MDIO_REG_GPHY_SHADOW 0x1c 6992#define MDIO_REG_GPHY_SHADOW 0x1c
6993#define MDIO_REG_GPHY_SHADOW_LED_SEL1 (0x0d << 10)
6993#define MDIO_REG_GPHY_SHADOW_LED_SEL2 (0x0e << 10) 6994#define MDIO_REG_GPHY_SHADOW_LED_SEL2 (0x0e << 10)
6994#define MDIO_REG_GPHY_SHADOW_WR_ENA (0x1 << 15) 6995#define MDIO_REG_GPHY_SHADOW_WR_ENA (0x1 << 15)
6995#define MDIO_REG_GPHY_SHADOW_AUTO_DET_MED (0x1e << 10) 6996#define MDIO_REG_GPHY_SHADOW_AUTO_DET_MED (0x1e << 10)
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
index 0440425c83d..14517691f8d 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
@@ -5380,7 +5380,7 @@ static int bnx2x_func_hw_init(struct bnx2x *bp,
5380 rc = drv->init_fw(bp); 5380 rc = drv->init_fw(bp);
5381 if (rc) { 5381 if (rc) {
5382 BNX2X_ERR("Error loading firmware\n"); 5382 BNX2X_ERR("Error loading firmware\n");
5383 goto fw_init_err; 5383 goto init_err;
5384 } 5384 }
5385 5385
5386 /* Handle the beginning of COMMON_XXX pases separatelly... */ 5386 /* Handle the beginning of COMMON_XXX pases separatelly... */
@@ -5388,25 +5388,25 @@ static int bnx2x_func_hw_init(struct bnx2x *bp,
5388 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: 5388 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5389 rc = bnx2x_func_init_cmn_chip(bp, drv); 5389 rc = bnx2x_func_init_cmn_chip(bp, drv);
5390 if (rc) 5390 if (rc)
5391 goto init_hw_err; 5391 goto init_err;
5392 5392
5393 break; 5393 break;
5394 case FW_MSG_CODE_DRV_LOAD_COMMON: 5394 case FW_MSG_CODE_DRV_LOAD_COMMON:
5395 rc = bnx2x_func_init_cmn(bp, drv); 5395 rc = bnx2x_func_init_cmn(bp, drv);
5396 if (rc) 5396 if (rc)
5397 goto init_hw_err; 5397 goto init_err;
5398 5398
5399 break; 5399 break;
5400 case FW_MSG_CODE_DRV_LOAD_PORT: 5400 case FW_MSG_CODE_DRV_LOAD_PORT:
5401 rc = bnx2x_func_init_port(bp, drv); 5401 rc = bnx2x_func_init_port(bp, drv);
5402 if (rc) 5402 if (rc)
5403 goto init_hw_err; 5403 goto init_err;
5404 5404
5405 break; 5405 break;
5406 case FW_MSG_CODE_DRV_LOAD_FUNCTION: 5406 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5407 rc = bnx2x_func_init_func(bp, drv); 5407 rc = bnx2x_func_init_func(bp, drv);
5408 if (rc) 5408 if (rc)
5409 goto init_hw_err; 5409 goto init_err;
5410 5410
5411 break; 5411 break;
5412 default: 5412 default:
@@ -5414,10 +5414,7 @@ static int bnx2x_func_hw_init(struct bnx2x *bp,
5414 rc = -EINVAL; 5414 rc = -EINVAL;
5415 } 5415 }
5416 5416
5417init_hw_err: 5417init_err:
5418 drv->release_fw(bp);
5419
5420fw_init_err:
5421 drv->gunzip_end(bp); 5418 drv->gunzip_end(bp);
5422 5419
5423 /* In case of success, complete the comand immediatelly: no ramrods 5420 /* In case of success, complete the comand immediatelly: no ramrods
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 161cbbb4814..bf4074167d6 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -89,10 +89,10 @@ static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits)
89 89
90#define DRV_MODULE_NAME "tg3" 90#define DRV_MODULE_NAME "tg3"
91#define TG3_MAJ_NUM 3 91#define TG3_MAJ_NUM 3
92#define TG3_MIN_NUM 120 92#define TG3_MIN_NUM 121
93#define DRV_MODULE_VERSION \ 93#define DRV_MODULE_VERSION \
94 __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) 94 __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM)
95#define DRV_MODULE_RELDATE "August 18, 2011" 95#define DRV_MODULE_RELDATE "November 2, 2011"
96 96
97#define RESET_KIND_SHUTDOWN 0 97#define RESET_KIND_SHUTDOWN 0
98#define RESET_KIND_INIT 1 98#define RESET_KIND_INIT 1
@@ -628,19 +628,23 @@ static void tg3_ape_lock_init(struct tg3 *tp)
628 regbase = TG3_APE_PER_LOCK_GRANT; 628 regbase = TG3_APE_PER_LOCK_GRANT;
629 629
630 /* Make sure the driver hasn't any stale locks. */ 630 /* Make sure the driver hasn't any stale locks. */
631 for (i = 0; i < 8; i++) { 631 for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) {
632 if (i == TG3_APE_LOCK_GPIO) 632 switch (i) {
633 continue; 633 case TG3_APE_LOCK_PHY0:
634 tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); 634 case TG3_APE_LOCK_PHY1:
635 case TG3_APE_LOCK_PHY2:
636 case TG3_APE_LOCK_PHY3:
637 bit = APE_LOCK_GRANT_DRIVER;
638 break;
639 default:
640 if (!tp->pci_fn)
641 bit = APE_LOCK_GRANT_DRIVER;
642 else
643 bit = 1 << tp->pci_fn;
644 }
645 tg3_ape_write32(tp, regbase + 4 * i, bit);
635 } 646 }
636 647
637 /* Clear the correct bit of the GPIO lock too. */
638 if (!tp->pci_fn)
639 bit = APE_LOCK_GRANT_DRIVER;
640 else
641 bit = 1 << tp->pci_fn;
642
643 tg3_ape_write32(tp, regbase + 4 * TG3_APE_LOCK_GPIO, bit);
644} 648}
645 649
646static int tg3_ape_lock(struct tg3 *tp, int locknum) 650static int tg3_ape_lock(struct tg3 *tp, int locknum)
@@ -658,6 +662,10 @@ static int tg3_ape_lock(struct tg3 *tp, int locknum)
658 return 0; 662 return 0;
659 case TG3_APE_LOCK_GRC: 663 case TG3_APE_LOCK_GRC:
660 case TG3_APE_LOCK_MEM: 664 case TG3_APE_LOCK_MEM:
665 if (!tp->pci_fn)
666 bit = APE_LOCK_REQ_DRIVER;
667 else
668 bit = 1 << tp->pci_fn;
661 break; 669 break;
662 default: 670 default:
663 return -EINVAL; 671 return -EINVAL;
@@ -673,11 +681,6 @@ static int tg3_ape_lock(struct tg3 *tp, int locknum)
673 681
674 off = 4 * locknum; 682 off = 4 * locknum;
675 683
676 if (locknum != TG3_APE_LOCK_GPIO || !tp->pci_fn)
677 bit = APE_LOCK_REQ_DRIVER;
678 else
679 bit = 1 << tp->pci_fn;
680
681 tg3_ape_write32(tp, req + off, bit); 684 tg3_ape_write32(tp, req + off, bit);
682 685
683 /* Wait for up to 1 millisecond to acquire lock. */ 686 /* Wait for up to 1 millisecond to acquire lock. */
@@ -710,6 +713,10 @@ static void tg3_ape_unlock(struct tg3 *tp, int locknum)
710 return; 713 return;
711 case TG3_APE_LOCK_GRC: 714 case TG3_APE_LOCK_GRC:
712 case TG3_APE_LOCK_MEM: 715 case TG3_APE_LOCK_MEM:
716 if (!tp->pci_fn)
717 bit = APE_LOCK_GRANT_DRIVER;
718 else
719 bit = 1 << tp->pci_fn;
713 break; 720 break;
714 default: 721 default:
715 return; 722 return;
@@ -720,11 +727,6 @@ static void tg3_ape_unlock(struct tg3 *tp, int locknum)
720 else 727 else
721 gnt = TG3_APE_PER_LOCK_GRANT; 728 gnt = TG3_APE_PER_LOCK_GRANT;
722 729
723 if (locknum != TG3_APE_LOCK_GPIO || !tp->pci_fn)
724 bit = APE_LOCK_GRANT_DRIVER;
725 else
726 bit = 1 << tp->pci_fn;
727
728 tg3_ape_write32(tp, gnt + 4 * locknum, bit); 730 tg3_ape_write32(tp, gnt + 4 * locknum, bit);
729} 731}
730 732
@@ -5927,6 +5929,18 @@ static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget)
5927 return work_done; 5929 return work_done;
5928} 5930}
5929 5931
5932static inline void tg3_reset_task_schedule(struct tg3 *tp)
5933{
5934 if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags))
5935 schedule_work(&tp->reset_task);
5936}
5937
5938static inline void tg3_reset_task_cancel(struct tg3 *tp)
5939{
5940 cancel_work_sync(&tp->reset_task);
5941 tg3_flag_clear(tp, RESET_TASK_PENDING);
5942}
5943
5930static int tg3_poll_msix(struct napi_struct *napi, int budget) 5944static int tg3_poll_msix(struct napi_struct *napi, int budget)
5931{ 5945{
5932 struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); 5946 struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi);
@@ -5967,7 +5981,7 @@ static int tg3_poll_msix(struct napi_struct *napi, int budget)
5967tx_recovery: 5981tx_recovery:
5968 /* work_done is guaranteed to be less than budget. */ 5982 /* work_done is guaranteed to be less than budget. */
5969 napi_complete(napi); 5983 napi_complete(napi);
5970 schedule_work(&tp->reset_task); 5984 tg3_reset_task_schedule(tp);
5971 return work_done; 5985 return work_done;
5972} 5986}
5973 5987
@@ -6002,7 +6016,7 @@ static void tg3_process_error(struct tg3 *tp)
6002 tg3_dump_state(tp); 6016 tg3_dump_state(tp);
6003 6017
6004 tg3_flag_set(tp, ERROR_PROCESSED); 6018 tg3_flag_set(tp, ERROR_PROCESSED);
6005 schedule_work(&tp->reset_task); 6019 tg3_reset_task_schedule(tp);
6006} 6020}
6007 6021
6008static int tg3_poll(struct napi_struct *napi, int budget) 6022static int tg3_poll(struct napi_struct *napi, int budget)
@@ -6049,7 +6063,7 @@ static int tg3_poll(struct napi_struct *napi, int budget)
6049tx_recovery: 6063tx_recovery:
6050 /* work_done is guaranteed to be less than budget. */ 6064 /* work_done is guaranteed to be less than budget. */
6051 napi_complete(napi); 6065 napi_complete(napi);
6052 schedule_work(&tp->reset_task); 6066 tg3_reset_task_schedule(tp);
6053 return work_done; 6067 return work_done;
6054} 6068}
6055 6069
@@ -6338,11 +6352,11 @@ static void tg3_reset_task(struct work_struct *work)
6338{ 6352{
6339 struct tg3 *tp = container_of(work, struct tg3, reset_task); 6353 struct tg3 *tp = container_of(work, struct tg3, reset_task);
6340 int err; 6354 int err;
6341 unsigned int restart_timer;
6342 6355
6343 tg3_full_lock(tp, 0); 6356 tg3_full_lock(tp, 0);
6344 6357
6345 if (!netif_running(tp->dev)) { 6358 if (!netif_running(tp->dev)) {
6359 tg3_flag_clear(tp, RESET_TASK_PENDING);
6346 tg3_full_unlock(tp); 6360 tg3_full_unlock(tp);
6347 return; 6361 return;
6348 } 6362 }
@@ -6355,9 +6369,6 @@ static void tg3_reset_task(struct work_struct *work)
6355 6369
6356 tg3_full_lock(tp, 1); 6370 tg3_full_lock(tp, 1);
6357 6371
6358 restart_timer = tg3_flag(tp, RESTART_TIMER);
6359 tg3_flag_clear(tp, RESTART_TIMER);
6360
6361 if (tg3_flag(tp, TX_RECOVERY_PENDING)) { 6372 if (tg3_flag(tp, TX_RECOVERY_PENDING)) {
6362 tp->write32_tx_mbox = tg3_write32_tx_mbox; 6373 tp->write32_tx_mbox = tg3_write32_tx_mbox;
6363 tp->write32_rx_mbox = tg3_write_flush_reg32; 6374 tp->write32_rx_mbox = tg3_write_flush_reg32;
@@ -6372,14 +6383,13 @@ static void tg3_reset_task(struct work_struct *work)
6372 6383
6373 tg3_netif_start(tp); 6384 tg3_netif_start(tp);
6374 6385
6375 if (restart_timer)
6376 mod_timer(&tp->timer, jiffies + 1);
6377
6378out: 6386out:
6379 tg3_full_unlock(tp); 6387 tg3_full_unlock(tp);
6380 6388
6381 if (!err) 6389 if (!err)
6382 tg3_phy_start(tp); 6390 tg3_phy_start(tp);
6391
6392 tg3_flag_clear(tp, RESET_TASK_PENDING);
6383} 6393}
6384 6394
6385static void tg3_tx_timeout(struct net_device *dev) 6395static void tg3_tx_timeout(struct net_device *dev)
@@ -6391,7 +6401,7 @@ static void tg3_tx_timeout(struct net_device *dev)
6391 tg3_dump_state(tp); 6401 tg3_dump_state(tp);
6392 } 6402 }
6393 6403
6394 schedule_work(&tp->reset_task); 6404 tg3_reset_task_schedule(tp);
6395} 6405}
6396 6406
6397/* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ 6407/* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */
@@ -6442,31 +6452,26 @@ static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget,
6442 hwbug = 1; 6452 hwbug = 1;
6443 6453
6444 if (tg3_flag(tp, 4K_FIFO_LIMIT)) { 6454 if (tg3_flag(tp, 4K_FIFO_LIMIT)) {
6455 u32 prvidx = *entry;
6445 u32 tmp_flag = flags & ~TXD_FLAG_END; 6456 u32 tmp_flag = flags & ~TXD_FLAG_END;
6446 while (len > TG3_TX_BD_DMA_MAX) { 6457 while (len > TG3_TX_BD_DMA_MAX && *budget) {
6447 u32 frag_len = TG3_TX_BD_DMA_MAX; 6458 u32 frag_len = TG3_TX_BD_DMA_MAX;
6448 len -= TG3_TX_BD_DMA_MAX; 6459 len -= TG3_TX_BD_DMA_MAX;
6449 6460
6450 if (len) { 6461 /* Avoid the 8byte DMA problem */
6451 tnapi->tx_buffers[*entry].fragmented = true; 6462 if (len <= 8) {
6452 /* Avoid the 8byte DMA problem */ 6463 len += TG3_TX_BD_DMA_MAX / 2;
6453 if (len <= 8) { 6464 frag_len = TG3_TX_BD_DMA_MAX / 2;
6454 len += TG3_TX_BD_DMA_MAX / 2;
6455 frag_len = TG3_TX_BD_DMA_MAX / 2;
6456 }
6457 } else
6458 tmp_flag = flags;
6459
6460 if (*budget) {
6461 tg3_tx_set_bd(&tnapi->tx_ring[*entry], map,
6462 frag_len, tmp_flag, mss, vlan);
6463 (*budget)--;
6464 *entry = NEXT_TX(*entry);
6465 } else {
6466 hwbug = 1;
6467 break;
6468 } 6465 }
6469 6466
6467 tnapi->tx_buffers[*entry].fragmented = true;
6468
6469 tg3_tx_set_bd(&tnapi->tx_ring[*entry], map,
6470 frag_len, tmp_flag, mss, vlan);
6471 *budget -= 1;
6472 prvidx = *entry;
6473 *entry = NEXT_TX(*entry);
6474
6470 map += frag_len; 6475 map += frag_len;
6471 } 6476 }
6472 6477
@@ -6474,10 +6479,11 @@ static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget,
6474 if (*budget) { 6479 if (*budget) {
6475 tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, 6480 tg3_tx_set_bd(&tnapi->tx_ring[*entry], map,
6476 len, flags, mss, vlan); 6481 len, flags, mss, vlan);
6477 (*budget)--; 6482 *budget -= 1;
6478 *entry = NEXT_TX(*entry); 6483 *entry = NEXT_TX(*entry);
6479 } else { 6484 } else {
6480 hwbug = 1; 6485 hwbug = 1;
6486 tnapi->tx_buffers[prvidx].fragmented = false;
6481 } 6487 }
6482 } 6488 }
6483 } else { 6489 } else {
@@ -6509,7 +6515,7 @@ static void tg3_tx_skb_unmap(struct tg3_napi *tnapi, u32 entry, int last)
6509 txb = &tnapi->tx_buffers[entry]; 6515 txb = &tnapi->tx_buffers[entry];
6510 } 6516 }
6511 6517
6512 for (i = 0; i < last; i++) { 6518 for (i = 0; i <= last; i++) {
6513 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 6519 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
6514 6520
6515 entry = NEXT_TX(entry); 6521 entry = NEXT_TX(entry);
@@ -6559,6 +6565,8 @@ static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi,
6559 dev_kfree_skb(new_skb); 6565 dev_kfree_skb(new_skb);
6560 ret = -1; 6566 ret = -1;
6561 } else { 6567 } else {
6568 u32 save_entry = *entry;
6569
6562 base_flags |= TXD_FLAG_END; 6570 base_flags |= TXD_FLAG_END;
6563 6571
6564 tnapi->tx_buffers[*entry].skb = new_skb; 6572 tnapi->tx_buffers[*entry].skb = new_skb;
@@ -6568,7 +6576,7 @@ static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi,
6568 if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, 6576 if (tg3_tx_frag_set(tnapi, entry, budget, new_addr,
6569 new_skb->len, base_flags, 6577 new_skb->len, base_flags,
6570 mss, vlan)) { 6578 mss, vlan)) {
6571 tg3_tx_skb_unmap(tnapi, *entry, 0); 6579 tg3_tx_skb_unmap(tnapi, save_entry, -1);
6572 dev_kfree_skb(new_skb); 6580 dev_kfree_skb(new_skb);
6573 ret = -1; 6581 ret = -1;
6574 } 6582 }
@@ -6758,11 +6766,10 @@ static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
6758 6766
6759 if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | 6767 if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags |
6760 ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), 6768 ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0),
6761 mss, vlan)) 6769 mss, vlan)) {
6762 would_hit_hwbug = 1; 6770 would_hit_hwbug = 1;
6763
6764 /* Now loop through additional data fragments, and queue them. */ 6771 /* Now loop through additional data fragments, and queue them. */
6765 if (skb_shinfo(skb)->nr_frags > 0) { 6772 } else if (skb_shinfo(skb)->nr_frags > 0) {
6766 u32 tmp_mss = mss; 6773 u32 tmp_mss = mss;
6767 6774
6768 if (!tg3_flag(tp, HW_TSO_1) && 6775 if (!tg3_flag(tp, HW_TSO_1) &&
@@ -6784,11 +6791,14 @@ static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
6784 if (dma_mapping_error(&tp->pdev->dev, mapping)) 6791 if (dma_mapping_error(&tp->pdev->dev, mapping))
6785 goto dma_error; 6792 goto dma_error;
6786 6793
6787 if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, 6794 if (!budget ||
6795 tg3_tx_frag_set(tnapi, &entry, &budget, mapping,
6788 len, base_flags | 6796 len, base_flags |
6789 ((i == last) ? TXD_FLAG_END : 0), 6797 ((i == last) ? TXD_FLAG_END : 0),
6790 tmp_mss, vlan)) 6798 tmp_mss, vlan)) {
6791 would_hit_hwbug = 1; 6799 would_hit_hwbug = 1;
6800 break;
6801 }
6792 } 6802 }
6793 } 6803 }
6794 6804
@@ -6828,7 +6838,7 @@ static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
6828 return NETDEV_TX_OK; 6838 return NETDEV_TX_OK;
6829 6839
6830dma_error: 6840dma_error:
6831 tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); 6841 tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i);
6832 tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; 6842 tnapi->tx_buffers[tnapi->tx_prod].skb = NULL;
6833drop: 6843drop:
6834 dev_kfree_skb(skb); 6844 dev_kfree_skb(skb);
@@ -7281,7 +7291,8 @@ static void tg3_free_rings(struct tg3 *tp)
7281 if (!skb) 7291 if (!skb)
7282 continue; 7292 continue;
7283 7293
7284 tg3_tx_skb_unmap(tnapi, i, skb_shinfo(skb)->nr_frags); 7294 tg3_tx_skb_unmap(tnapi, i,
7295 skb_shinfo(skb)->nr_frags - 1);
7285 7296
7286 dev_kfree_skb_any(skb); 7297 dev_kfree_skb_any(skb);
7287 } 7298 }
@@ -9200,7 +9211,7 @@ static void tg3_timer(unsigned long __opaque)
9200{ 9211{
9201 struct tg3 *tp = (struct tg3 *) __opaque; 9212 struct tg3 *tp = (struct tg3 *) __opaque;
9202 9213
9203 if (tp->irq_sync) 9214 if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING))
9204 goto restart_timer; 9215 goto restart_timer;
9205 9216
9206 spin_lock(&tp->lock); 9217 spin_lock(&tp->lock);
@@ -9223,10 +9234,9 @@ static void tg3_timer(unsigned long __opaque)
9223 } 9234 }
9224 9235
9225 if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { 9236 if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
9226 tg3_flag_set(tp, RESTART_TIMER);
9227 spin_unlock(&tp->lock); 9237 spin_unlock(&tp->lock);
9228 schedule_work(&tp->reset_task); 9238 tg3_reset_task_schedule(tp);
9229 return; 9239 goto restart_timer;
9230 } 9240 }
9231 } 9241 }
9232 9242
@@ -9674,15 +9684,14 @@ static int tg3_open(struct net_device *dev)
9674 struct tg3_napi *tnapi = &tp->napi[i]; 9684 struct tg3_napi *tnapi = &tp->napi[i];
9675 err = tg3_request_irq(tp, i); 9685 err = tg3_request_irq(tp, i);
9676 if (err) { 9686 if (err) {
9677 for (i--; i >= 0; i--) 9687 for (i--; i >= 0; i--) {
9688 tnapi = &tp->napi[i];
9678 free_irq(tnapi->irq_vec, tnapi); 9689 free_irq(tnapi->irq_vec, tnapi);
9679 break; 9690 }
9691 goto err_out2;
9680 } 9692 }
9681 } 9693 }
9682 9694
9683 if (err)
9684 goto err_out2;
9685
9686 tg3_full_lock(tp, 0); 9695 tg3_full_lock(tp, 0);
9687 9696
9688 err = tg3_init_hw(tp, 1); 9697 err = tg3_init_hw(tp, 1);
@@ -9783,7 +9792,7 @@ static int tg3_close(struct net_device *dev)
9783 struct tg3 *tp = netdev_priv(dev); 9792 struct tg3 *tp = netdev_priv(dev);
9784 9793
9785 tg3_napi_disable(tp); 9794 tg3_napi_disable(tp);
9786 cancel_work_sync(&tp->reset_task); 9795 tg3_reset_task_cancel(tp);
9787 9796
9788 netif_tx_stop_all_queues(dev); 9797 netif_tx_stop_all_queues(dev);
9789 9798
@@ -11520,7 +11529,7 @@ static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, bool tso_loopback)
11520 break; 11529 break;
11521 } 11530 }
11522 11531
11523 tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, 0); 11532 tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1);
11524 dev_kfree_skb(skb); 11533 dev_kfree_skb(skb);
11525 11534
11526 if (tx_idx != tnapi->tx_prod) 11535 if (tx_idx != tnapi->tx_prod)
@@ -14228,12 +14237,30 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
14228 val = tr32(MEMARB_MODE); 14237 val = tr32(MEMARB_MODE);
14229 tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); 14238 tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE);
14230 14239
14231 if (tg3_flag(tp, PCIX_MODE)) { 14240 tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3;
14232 pci_read_config_dword(tp->pdev, 14241 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 ||
14233 tp->pcix_cap + PCI_X_STATUS, &val); 14242 tg3_flag(tp, 5780_CLASS)) {
14234 tp->pci_fn = val & 0x7; 14243 if (tg3_flag(tp, PCIX_MODE)) {
14235 } else { 14244 pci_read_config_dword(tp->pdev,
14236 tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; 14245 tp->pcix_cap + PCI_X_STATUS,
14246 &val);
14247 tp->pci_fn = val & 0x7;
14248 }
14249 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) {
14250 tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val);
14251 if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) ==
14252 NIC_SRAM_CPMUSTAT_SIG) {
14253 tp->pci_fn = val & TG3_CPMU_STATUS_FMSK_5717;
14254 tp->pci_fn = tp->pci_fn ? 1 : 0;
14255 }
14256 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 ||
14257 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) {
14258 tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val);
14259 if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) ==
14260 NIC_SRAM_CPMUSTAT_SIG) {
14261 tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >>
14262 TG3_CPMU_STATUS_FSHFT_5719;
14263 }
14237 } 14264 }
14238 14265
14239 /* Get eeprom hw config before calling tg3_set_power_state(). 14266 /* Get eeprom hw config before calling tg3_set_power_state().
@@ -15665,7 +15692,7 @@ static void __devexit tg3_remove_one(struct pci_dev *pdev)
15665 if (tp->fw) 15692 if (tp->fw)
15666 release_firmware(tp->fw); 15693 release_firmware(tp->fw);
15667 15694
15668 cancel_work_sync(&tp->reset_task); 15695 tg3_reset_task_cancel(tp);
15669 15696
15670 if (tg3_flag(tp, USE_PHYLIB)) { 15697 if (tg3_flag(tp, USE_PHYLIB)) {
15671 tg3_phy_fini(tp); 15698 tg3_phy_fini(tp);
@@ -15699,7 +15726,7 @@ static int tg3_suspend(struct device *device)
15699 if (!netif_running(dev)) 15726 if (!netif_running(dev))
15700 return 0; 15727 return 0;
15701 15728
15702 flush_work_sync(&tp->reset_task); 15729 tg3_reset_task_cancel(tp);
15703 tg3_phy_stop(tp); 15730 tg3_phy_stop(tp);
15704 tg3_netif_stop(tp); 15731 tg3_netif_stop(tp);
15705 15732
@@ -15812,12 +15839,10 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
15812 tg3_netif_stop(tp); 15839 tg3_netif_stop(tp);
15813 15840
15814 del_timer_sync(&tp->timer); 15841 del_timer_sync(&tp->timer);
15815 tg3_flag_clear(tp, RESTART_TIMER);
15816 15842
15817 /* Want to make sure that the reset task doesn't run */ 15843 /* Want to make sure that the reset task doesn't run */
15818 cancel_work_sync(&tp->reset_task); 15844 tg3_reset_task_cancel(tp);
15819 tg3_flag_clear(tp, TX_RECOVERY_PENDING); 15845 tg3_flag_clear(tp, TX_RECOVERY_PENDING);
15820 tg3_flag_clear(tp, RESTART_TIMER);
15821 15846
15822 netif_device_detach(netdev); 15847 netif_device_detach(netdev);
15823 15848
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index f32f288134c..94b4bd049a3 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -1095,6 +1095,11 @@
1095#define TG3_CPMU_CLCK_ORIDE 0x00003624 1095#define TG3_CPMU_CLCK_ORIDE 0x00003624
1096#define CPMU_CLCK_ORIDE_MAC_ORIDE_EN 0x80000000 1096#define CPMU_CLCK_ORIDE_MAC_ORIDE_EN 0x80000000
1097 1097
1098#define TG3_CPMU_STATUS 0x0000362c
1099#define TG3_CPMU_STATUS_FMSK_5717 0x20000000
1100#define TG3_CPMU_STATUS_FMSK_5719 0xc0000000
1101#define TG3_CPMU_STATUS_FSHFT_5719 30
1102
1098#define TG3_CPMU_CLCK_STAT 0x00003630 1103#define TG3_CPMU_CLCK_STAT 0x00003630
1099#define CPMU_CLCK_STAT_MAC_CLCK_MASK 0x001f0000 1104#define CPMU_CLCK_STAT_MAC_CLCK_MASK 0x001f0000
1100#define CPMU_CLCK_STAT_MAC_CLCK_62_5 0x00000000 1105#define CPMU_CLCK_STAT_MAC_CLCK_62_5 0x00000000
@@ -2128,6 +2133,10 @@
2128#define NIC_SRAM_RGMII_EXT_IBND_RX_EN 0x00000008 2133#define NIC_SRAM_RGMII_EXT_IBND_RX_EN 0x00000008
2129#define NIC_SRAM_RGMII_EXT_IBND_TX_EN 0x00000010 2134#define NIC_SRAM_RGMII_EXT_IBND_TX_EN 0x00000010
2130 2135
2136#define NIC_SRAM_CPMU_STATUS 0x00000e00
2137#define NIC_SRAM_CPMUSTAT_SIG 0x0000362c
2138#define NIC_SRAM_CPMUSTAT_SIG_MSK 0x0000ffff
2139
2131#define NIC_SRAM_RX_MINI_BUFFER_DESC 0x00001000 2140#define NIC_SRAM_RX_MINI_BUFFER_DESC 0x00001000
2132 2141
2133#define NIC_SRAM_DMA_DESC_POOL_BASE 0x00002000 2142#define NIC_SRAM_DMA_DESC_POOL_BASE 0x00002000
@@ -2344,9 +2353,13 @@
2344#define APE_PER_LOCK_GRANT_DRIVER 0x00001000 2353#define APE_PER_LOCK_GRANT_DRIVER 0x00001000
2345 2354
2346/* APE convenience enumerations. */ 2355/* APE convenience enumerations. */
2347#define TG3_APE_LOCK_GRC 1 2356#define TG3_APE_LOCK_PHY0 0
2348#define TG3_APE_LOCK_MEM 4 2357#define TG3_APE_LOCK_GRC 1
2349#define TG3_APE_LOCK_GPIO 7 2358#define TG3_APE_LOCK_PHY1 2
2359#define TG3_APE_LOCK_PHY2 3
2360#define TG3_APE_LOCK_MEM 4
2361#define TG3_APE_LOCK_PHY3 5
2362#define TG3_APE_LOCK_GPIO 7
2350 2363
2351#define TG3_EEPROM_SB_F1R2_MBA_OFF 0x10 2364#define TG3_EEPROM_SB_F1R2_MBA_OFF 0x10
2352 2365
@@ -2866,7 +2879,6 @@ enum TG3_FLAGS {
2866 TG3_FLAG_JUMBO_CAPABLE, 2879 TG3_FLAG_JUMBO_CAPABLE,
2867 TG3_FLAG_CHIP_RESETTING, 2880 TG3_FLAG_CHIP_RESETTING,
2868 TG3_FLAG_INIT_COMPLETE, 2881 TG3_FLAG_INIT_COMPLETE,
2869 TG3_FLAG_RESTART_TIMER,
2870 TG3_FLAG_TSO_BUG, 2882 TG3_FLAG_TSO_BUG,
2871 TG3_FLAG_IS_5788, 2883 TG3_FLAG_IS_5788,
2872 TG3_FLAG_MAX_RXPEND_64, 2884 TG3_FLAG_MAX_RXPEND_64,
@@ -2909,6 +2921,7 @@ enum TG3_FLAGS {
2909 TG3_FLAG_APE_HAS_NCSI, 2921 TG3_FLAG_APE_HAS_NCSI,
2910 TG3_FLAG_5717_PLUS, 2922 TG3_FLAG_5717_PLUS,
2911 TG3_FLAG_4K_FIFO_LIMIT, 2923 TG3_FLAG_4K_FIFO_LIMIT,
2924 TG3_FLAG_RESET_TASK_PENDING,
2912 2925
2913 /* Add new flags before this comment and TG3_FLAG_NUMBER_OF_FLAGS */ 2926 /* Add new flags before this comment and TG3_FLAG_NUMBER_OF_FLAGS */
2914 TG3_FLAG_NUMBER_OF_FLAGS, /* Last entry in enum TG3_FLAGS */ 2927 TG3_FLAG_NUMBER_OF_FLAGS, /* Last entry in enum TG3_FLAGS */
diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
index 5d7872ecff5..7f3091e7eb4 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/cadence/Kconfig b/drivers/net/ethernet/cadence/Kconfig
index 98849a1fc74..b48378a41e4 100644
--- a/drivers/net/ethernet/cadence/Kconfig
+++ b/drivers/net/ethernet/cadence/Kconfig
@@ -7,6 +7,7 @@ config HAVE_NET_MACB
7 7
8config NET_ATMEL 8config NET_ATMEL
9 bool "Atmel devices" 9 bool "Atmel devices"
10 default y
10 depends on HAVE_NET_MACB || (ARM && ARCH_AT91RM9200) 11 depends on HAVE_NET_MACB || (ARM && ARCH_AT91RM9200)
11 ---help--- 12 ---help---
12 If you have a network (Ethernet) card belonging to this class, say Y. 13 If you have a network (Ethernet) card belonging to this class, say Y.
diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c
index da5a5d9b8af..90ff1318cc0 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 41540978a17..70fec8b1140 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 a2d323c473f..6ac77a62f36 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 ddc16985d0f..140254c7cba 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 6cbb81ccc02..1f8648f099c 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 14bd77e0cb5..ca245e2b5d9 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 83781f316d1..83781f316d1 100644
--- a/drivers/net/ethernet/apple/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index 438f4580bf6..2a22f525635 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -613,7 +613,7 @@ static int dm9000_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
613 613
614 if (!dm->wake_state) 614 if (!dm->wake_state)
615 irq_set_irq_wake(dm->irq_wake, 1); 615 irq_set_irq_wake(dm->irq_wake, 1);
616 else if (dm->wake_state & !opts) 616 else if (dm->wake_state && !opts)
617 irq_set_irq_wake(dm->irq_wake, 0); 617 irq_set_irq_wake(dm->irq_wake, 0);
618 } 618 }
619 619
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index 824b8e6021f..2c7b36673df 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 fbc8a915519..f2c89e3ccab 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 21804972fa2..bf266a00c77 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 bdb348a5ccf..251b635fe75 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/Kconfig b/drivers/net/ethernet/freescale/Kconfig
index 1cf671643d1..5272f9d4dda 100644
--- a/drivers/net/ethernet/freescale/Kconfig
+++ b/drivers/net/ethernet/freescale/Kconfig
@@ -7,8 +7,7 @@ config NET_VENDOR_FREESCALE
7 default y 7 default y
8 depends on FSL_SOC || QUICC_ENGINE || CPM1 || CPM2 || PPC_MPC512x || \ 8 depends on FSL_SOC || QUICC_ENGINE || CPM1 || CPM2 || PPC_MPC512x || \
9 M523x || M527x || M5272 || M528x || M520x || M532x || \ 9 M523x || M527x || M5272 || M528x || M520x || M532x || \
10 ARCH_MXC || ARCH_MXS || \ 10 ARCH_MXC || ARCH_MXS || (PPC_MPC52xx && PPC_BESTCOMM)
11 (PPC_MPC52xx && PPC_BESTCOMM)
12 ---help--- 11 ---help---
13 If you have a network (Ethernet) card belonging to this class, say Y 12 If you have a network (Ethernet) card belonging to this class, say Y
14 and read the Ethernet-HOWTO, available from 13 and read the Ethernet-HOWTO, available from
@@ -25,6 +24,7 @@ config FEC
25 bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)" 24 bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
26 depends on (M523x || M527x || M5272 || M528x || M520x || M532x || \ 25 depends on (M523x || M527x || M5272 || M528x || M520x || M532x || \
27 ARCH_MXC || ARCH_MXS) 26 ARCH_MXC || ARCH_MXS)
27 default ARCH_MXC || ARCH_MXS if ARM
28 select PHYLIB 28 select PHYLIB
29 ---help--- 29 ---help---
30 Say Y here if you want to use the built-in 10/100 Fast ethernet 30 Say Y here if you want to use the built-in 10/100 Fast ethernet
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index 46d690a92c0..b5dc0273a1d 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 40e1a175fce..ba82a266051 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/ibm/ehea/ehea.h b/drivers/net/ethernet/ibm/ehea/ehea.h
index 410d6a1984e..6650068c996 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea.h
+++ b/drivers/net/ethernet/ibm/ehea/ehea.h
@@ -61,9 +61,9 @@
61#ifdef EHEA_SMALL_QUEUES 61#ifdef EHEA_SMALL_QUEUES
62#define EHEA_MAX_CQE_COUNT 1023 62#define EHEA_MAX_CQE_COUNT 1023
63#define EHEA_DEF_ENTRIES_SQ 1023 63#define EHEA_DEF_ENTRIES_SQ 1023
64#define EHEA_DEF_ENTRIES_RQ1 4095 64#define EHEA_DEF_ENTRIES_RQ1 1023
65#define EHEA_DEF_ENTRIES_RQ2 1023 65#define EHEA_DEF_ENTRIES_RQ2 1023
66#define EHEA_DEF_ENTRIES_RQ3 1023 66#define EHEA_DEF_ENTRIES_RQ3 511
67#else 67#else
68#define EHEA_MAX_CQE_COUNT 4080 68#define EHEA_MAX_CQE_COUNT 4080
69#define EHEA_DEF_ENTRIES_SQ 4080 69#define EHEA_DEF_ENTRIES_SQ 4080
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_main.c b/drivers/net/ethernet/ibm/ehea/ehea_main.c
index 37b70f7052b..bfeccbfde23 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_main.c
+++ b/drivers/net/ethernet/ibm/ehea/ehea_main.c
@@ -371,7 +371,8 @@ static void ehea_update_stats(struct work_struct *work)
371out_herr: 371out_herr:
372 free_page((unsigned long)cb2); 372 free_page((unsigned long)cb2);
373resched: 373resched:
374 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000)); 374 schedule_delayed_work(&port->stats_work,
375 round_jiffies_relative(msecs_to_jiffies(1000)));
375} 376}
376 377
377static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes) 378static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
@@ -2434,7 +2435,8 @@ static int ehea_open(struct net_device *dev)
2434 } 2435 }
2435 2436
2436 mutex_unlock(&port->port_lock); 2437 mutex_unlock(&port->port_lock);
2437 schedule_delayed_work(&port->stats_work, msecs_to_jiffies(1000)); 2438 schedule_delayed_work(&port->stats_work,
2439 round_jiffies_relative(msecs_to_jiffies(1000)));
2438 2440
2439 return ret; 2441 return ret;
2440} 2442}
diff --git a/drivers/net/ethernet/ibm/iseries_veth.c b/drivers/net/ethernet/ibm/iseries_veth.c
index 4326681df38..acc31af6594 100644
--- a/drivers/net/ethernet/ibm/iseries_veth.c
+++ b/drivers/net/ethernet/ibm/iseries_veth.c
@@ -1421,7 +1421,7 @@ static void veth_receive(struct veth_lpar_connection *cnx,
1421 1421
1422 /* FIXME: do we need this? */ 1422 /* FIXME: do we need this? */
1423 memset(local_list, 0, sizeof(local_list)); 1423 memset(local_list, 0, sizeof(local_list));
1424 memset(remote_list, 0, sizeof(VETH_MAX_FRAMES_PER_MSG)); 1424 memset(remote_list, 0, sizeof(remote_list));
1425 1425
1426 /* a 0 address marks the end of the valid entries */ 1426 /* a 0 address marks the end of the valid entries */
1427 if (senddata->addr[startchunk] == 0) 1427 if (senddata->addr[startchunk] == 0)
diff --git a/drivers/net/ethernet/intel/Kconfig b/drivers/net/ethernet/intel/Kconfig
index 61029dc7fa6..76213162fbe 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -5,7 +5,11 @@
5config NET_VENDOR_INTEL 5config NET_VENDOR_INTEL
6 bool "Intel devices" 6 bool "Intel devices"
7 default y 7 default y
8 depends on PCI || PCI_MSI 8 depends on PCI || PCI_MSI || ISA || ISA_DMA_API || ARM || \
9 ARCH_ACORN || MCA || MCA_LEGACY || SNI_RM || SUN3 || \
10 GSC || BVME6000 || MVME16x || ARCH_ENP2611 || \
11 (ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR) || \
12 EXPERIMENTAL
9 ---help--- 13 ---help---
10 If you have a network (Ethernet) card belonging to this class, say Y 14 If you have a network (Ethernet) card belonging to this class, say Y
11 and read the Ethernet-HOWTO, available from 15 and read the Ethernet-HOWTO, available from
diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index ae17cd1a907..5a2fdf7a00c 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 6a17c62cb86..e2a80a283fd 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 4dd9b63273f..20e93b08e7f 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 7edf31efe75..b17d7c20f81 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 834f044be4c..f1365fef4ed 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 3631d639d86..33b93ffb87c 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 09b8e88b299..8ef92d1a6aa 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.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
index db95731863d..00fcd39ad66 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
@@ -442,12 +442,14 @@ static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter,
442 442
443int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter) 443int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter)
444{ 444{
445#ifdef CONFIG_PCI_IOV
445 int i; 446 int i;
446 for (i = 0; i < adapter->num_vfs; i++) { 447 for (i = 0; i < adapter->num_vfs; i++) {
447 if (adapter->vfinfo[i].vfdev->dev_flags & 448 if (adapter->vfinfo[i].vfdev->dev_flags &
448 PCI_DEV_FLAGS_ASSIGNED) 449 PCI_DEV_FLAGS_ASSIGNED)
449 return true; 450 return true;
450 } 451 }
452#endif
451 return false; 453 return false;
452} 454}
453 455
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
index 5a7e1eb3359..df04f1a3857 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
@@ -43,9 +43,11 @@ int 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);
45void ixgbe_disable_sriov(struct ixgbe_adapter *adapter); 45void ixgbe_disable_sriov(struct ixgbe_adapter *adapter);
46int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter);
47#ifdef CONFIG_PCI_IOV
46void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, 48void ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
47 const struct ixgbe_info *ii); 49 const struct ixgbe_info *ii);
48int 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 5e92cc2079b..4c8e19951d5 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/jme.c b/drivers/net/ethernet/jme.c
index 7becff1f387..76b84573566 100644
--- a/drivers/net/ethernet/jme.c
+++ b/drivers/net/ethernet/jme.c
@@ -1745,6 +1745,112 @@ jme_phy_off(struct jme_adapter *jme)
1745} 1745}
1746 1746
1747static int 1747static int
1748jme_phy_specreg_read(struct jme_adapter *jme, u32 specreg)
1749{
1750 u32 phy_addr;
1751
1752 phy_addr = JM_PHY_SPEC_REG_READ | specreg;
1753 jme_mdio_write(jme->dev, jme->mii_if.phy_id, JM_PHY_SPEC_ADDR_REG,
1754 phy_addr);
1755 return jme_mdio_read(jme->dev, jme->mii_if.phy_id,
1756 JM_PHY_SPEC_DATA_REG);
1757}
1758
1759static void
1760jme_phy_specreg_write(struct jme_adapter *jme, u32 ext_reg, u32 phy_data)
1761{
1762 u32 phy_addr;
1763
1764 phy_addr = JM_PHY_SPEC_REG_WRITE | ext_reg;
1765 jme_mdio_write(jme->dev, jme->mii_if.phy_id, JM_PHY_SPEC_DATA_REG,
1766 phy_data);
1767 jme_mdio_write(jme->dev, jme->mii_if.phy_id, JM_PHY_SPEC_ADDR_REG,
1768 phy_addr);
1769}
1770
1771static int
1772jme_phy_calibration(struct jme_adapter *jme)
1773{
1774 u32 ctrl1000, phy_data;
1775
1776 jme_phy_off(jme);
1777 jme_phy_on(jme);
1778 /* Enabel PHY test mode 1 */
1779 ctrl1000 = jme_mdio_read(jme->dev, jme->mii_if.phy_id, MII_CTRL1000);
1780 ctrl1000 &= ~PHY_GAD_TEST_MODE_MSK;
1781 ctrl1000 |= PHY_GAD_TEST_MODE_1;
1782 jme_mdio_write(jme->dev, jme->mii_if.phy_id, MII_CTRL1000, ctrl1000);
1783
1784 phy_data = jme_phy_specreg_read(jme, JM_PHY_EXT_COMM_2_REG);
1785 phy_data &= ~JM_PHY_EXT_COMM_2_CALI_MODE_0;
1786 phy_data |= JM_PHY_EXT_COMM_2_CALI_LATCH |
1787 JM_PHY_EXT_COMM_2_CALI_ENABLE;
1788 jme_phy_specreg_write(jme, JM_PHY_EXT_COMM_2_REG, phy_data);
1789 msleep(20);
1790 phy_data = jme_phy_specreg_read(jme, JM_PHY_EXT_COMM_2_REG);
1791 phy_data &= ~(JM_PHY_EXT_COMM_2_CALI_ENABLE |
1792 JM_PHY_EXT_COMM_2_CALI_MODE_0 |
1793 JM_PHY_EXT_COMM_2_CALI_LATCH);
1794 jme_phy_specreg_write(jme, JM_PHY_EXT_COMM_2_REG, phy_data);
1795
1796 /* Disable PHY test mode */
1797 ctrl1000 = jme_mdio_read(jme->dev, jme->mii_if.phy_id, MII_CTRL1000);
1798 ctrl1000 &= ~PHY_GAD_TEST_MODE_MSK;
1799 jme_mdio_write(jme->dev, jme->mii_if.phy_id, MII_CTRL1000, ctrl1000);
1800 return 0;
1801}
1802
1803static int
1804jme_phy_setEA(struct jme_adapter *jme)
1805{
1806 u32 phy_comm0 = 0, phy_comm1 = 0;
1807 u8 nic_ctrl;
1808
1809 pci_read_config_byte(jme->pdev, PCI_PRIV_SHARE_NICCTRL, &nic_ctrl);
1810 if ((nic_ctrl & 0x3) == JME_FLAG_PHYEA_ENABLE)
1811 return 0;
1812
1813 switch (jme->pdev->device) {
1814 case PCI_DEVICE_ID_JMICRON_JMC250:
1815 if (((jme->chip_main_rev == 5) &&
1816 ((jme->chip_sub_rev == 0) || (jme->chip_sub_rev == 1) ||
1817 (jme->chip_sub_rev == 3))) ||
1818 (jme->chip_main_rev >= 6)) {
1819 phy_comm0 = 0x008A;
1820 phy_comm1 = 0x4109;
1821 }
1822 if ((jme->chip_main_rev == 3) &&
1823 ((jme->chip_sub_rev == 1) || (jme->chip_sub_rev == 2)))
1824 phy_comm0 = 0xE088;
1825 break;
1826 case PCI_DEVICE_ID_JMICRON_JMC260:
1827 if (((jme->chip_main_rev == 5) &&
1828 ((jme->chip_sub_rev == 0) || (jme->chip_sub_rev == 1) ||
1829 (jme->chip_sub_rev == 3))) ||
1830 (jme->chip_main_rev >= 6)) {
1831 phy_comm0 = 0x008A;
1832 phy_comm1 = 0x4109;
1833 }
1834 if ((jme->chip_main_rev == 3) &&
1835 ((jme->chip_sub_rev == 1) || (jme->chip_sub_rev == 2)))
1836 phy_comm0 = 0xE088;
1837 if ((jme->chip_main_rev == 2) && (jme->chip_sub_rev == 0))
1838 phy_comm0 = 0x608A;
1839 if ((jme->chip_main_rev == 2) && (jme->chip_sub_rev == 2))
1840 phy_comm0 = 0x408A;
1841 break;
1842 default:
1843 return -ENODEV;
1844 }
1845 if (phy_comm0)
1846 jme_phy_specreg_write(jme, JM_PHY_EXT_COMM_0_REG, phy_comm0);
1847 if (phy_comm1)
1848 jme_phy_specreg_write(jme, JM_PHY_EXT_COMM_1_REG, phy_comm1);
1849
1850 return 0;
1851}
1852
1853static int
1748jme_open(struct net_device *netdev) 1854jme_open(struct net_device *netdev)
1749{ 1855{
1750 struct jme_adapter *jme = netdev_priv(netdev); 1856 struct jme_adapter *jme = netdev_priv(netdev);
@@ -1769,7 +1875,8 @@ jme_open(struct net_device *netdev)
1769 jme_set_settings(netdev, &jme->old_ecmd); 1875 jme_set_settings(netdev, &jme->old_ecmd);
1770 else 1876 else
1771 jme_reset_phy_processor(jme); 1877 jme_reset_phy_processor(jme);
1772 1878 jme_phy_calibration(jme);
1879 jme_phy_setEA(jme);
1773 jme_reset_link(jme); 1880 jme_reset_link(jme);
1774 1881
1775 return 0; 1882 return 0;
@@ -3184,7 +3291,8 @@ jme_resume(struct device *dev)
3184 jme_set_settings(netdev, &jme->old_ecmd); 3291 jme_set_settings(netdev, &jme->old_ecmd);
3185 else 3292 else
3186 jme_reset_phy_processor(jme); 3293 jme_reset_phy_processor(jme);
3187 3294 jme_phy_calibration(jme);
3295 jme_phy_setEA(jme);
3188 jme_start_irq(jme); 3296 jme_start_irq(jme);
3189 netif_device_attach(netdev); 3297 netif_device_attach(netdev);
3190 3298
@@ -3239,4 +3347,3 @@ MODULE_DESCRIPTION("JMicron JMC2x0 PCI Express Ethernet driver");
3239MODULE_LICENSE("GPL"); 3347MODULE_LICENSE("GPL");
3240MODULE_VERSION(DRV_VERSION); 3348MODULE_VERSION(DRV_VERSION);
3241MODULE_DEVICE_TABLE(pci, jme_pci_tbl); 3349MODULE_DEVICE_TABLE(pci, jme_pci_tbl);
3242
diff --git a/drivers/net/ethernet/jme.h b/drivers/net/ethernet/jme.h
index 02ea27c1dcb..4304072bd3c 100644
--- a/drivers/net/ethernet/jme.h
+++ b/drivers/net/ethernet/jme.h
@@ -760,6 +760,25 @@ enum jme_rxmcs_bits {
760 RXMCS_CHECKSUM, 760 RXMCS_CHECKSUM,
761}; 761};
762 762
763/* Extern PHY common register 2 */
764
765#define PHY_GAD_TEST_MODE_1 0x00002000
766#define PHY_GAD_TEST_MODE_MSK 0x0000E000
767#define JM_PHY_SPEC_REG_READ 0x00004000
768#define JM_PHY_SPEC_REG_WRITE 0x00008000
769#define PHY_CALIBRATION_DELAY 20
770#define JM_PHY_SPEC_ADDR_REG 0x1E
771#define JM_PHY_SPEC_DATA_REG 0x1F
772
773#define JM_PHY_EXT_COMM_0_REG 0x30
774#define JM_PHY_EXT_COMM_1_REG 0x31
775#define JM_PHY_EXT_COMM_2_REG 0x32
776#define JM_PHY_EXT_COMM_2_CALI_ENABLE 0x01
777#define JM_PHY_EXT_COMM_2_CALI_MODE_0 0x02
778#define JM_PHY_EXT_COMM_2_CALI_LATCH 0x10
779#define PCI_PRIV_SHARE_NICCTRL 0xF5
780#define JME_FLAG_PHYEA_ENABLE 0x2
781
763/* 782/*
764 * Wakeup Frame setup interface registers 783 * Wakeup Frame setup interface registers
765 */ 784 */
diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 6bb2b9506ca..0b3567ab812 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -34,6 +34,8 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/dma-mapping.h>
38#include <linux/module.h>
37 39
38#include <asm/checksum.h> 40#include <asm/checksum.h>
39 41
diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index cbd026f3bc5..7803efa46eb 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -50,7 +50,7 @@
50#include "sky2.h" 50#include "sky2.h"
51 51
52#define DRV_NAME "sky2" 52#define DRV_NAME "sky2"
53#define DRV_VERSION "1.29" 53#define DRV_VERSION "1.30"
54 54
55/* 55/*
56 * The Yukon II chipset takes 64 bit command blocks (called list elements) 56 * The Yukon II chipset takes 64 bit command blocks (called list elements)
@@ -68,7 +68,7 @@
68#define MAX_SKB_TX_LE (2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1)) 68#define MAX_SKB_TX_LE (2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1))
69#define TX_MIN_PENDING (MAX_SKB_TX_LE+1) 69#define TX_MIN_PENDING (MAX_SKB_TX_LE+1)
70#define TX_MAX_PENDING 1024 70#define TX_MAX_PENDING 1024
71#define TX_DEF_PENDING 127 71#define TX_DEF_PENDING 63
72 72
73#define TX_WATCHDOG (5 * HZ) 73#define TX_WATCHDOG (5 * HZ)
74#define NAPI_WEIGHT 64 74#define NAPI_WEIGHT 64
@@ -366,17 +366,6 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
366 gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec); 366 gm_phy_write(hw, port, PHY_MARV_FE_SPEC_2, spec);
367 } 367 }
368 } else { 368 } else {
369 if (hw->chip_id >= CHIP_ID_YUKON_OPT) {
370 u16 ctrl2 = gm_phy_read(hw, port, PHY_MARV_EXT_CTRL_2);
371
372 /* enable PHY Reverse Auto-Negotiation */
373 ctrl2 |= 1u << 13;
374
375 /* Write PHY changes (SW-reset must follow) */
376 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL_2, ctrl2);
377 }
378
379
380 /* disable energy detect */ 369 /* disable energy detect */
381 ctrl &= ~PHY_M_PC_EN_DET_MSK; 370 ctrl &= ~PHY_M_PC_EN_DET_MSK;
382 371
@@ -880,6 +869,7 @@ static void sky2_wol_init(struct sky2_port *sky2)
880 869
881 /* block receiver */ 870 /* block receiver */
882 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 871 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
872 sky2_read32(hw, B0_CTST);
883} 873}
884 874
885static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port) 875static void sky2_set_tx_stfwd(struct sky2_hw *hw, unsigned port)
@@ -1285,6 +1275,14 @@ static void rx_set_checksum(struct sky2_port *sky2)
1285 ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM); 1275 ? BMU_ENA_RX_CHKSUM : BMU_DIS_RX_CHKSUM);
1286} 1276}
1287 1277
1278/*
1279 * Fixed initial key as seed to RSS.
1280 */
1281static const uint32_t rss_init_key[10] = {
1282 0x7c3351da, 0x51c5cf4e, 0x44adbdd1, 0xe8d38d18, 0x48897c43,
1283 0xb1d60e7e, 0x6a3dd760, 0x01a2e453, 0x16f46f13, 0x1a0e7b30
1284};
1285
1288/* Enable/disable receive hash calculation (RSS) */ 1286/* Enable/disable receive hash calculation (RSS) */
1289static void rx_set_rss(struct net_device *dev, u32 features) 1287static void rx_set_rss(struct net_device *dev, u32 features)
1290{ 1288{
@@ -1300,12 +1298,9 @@ static void rx_set_rss(struct net_device *dev, u32 features)
1300 1298
1301 /* Program RSS initial values */ 1299 /* Program RSS initial values */
1302 if (features & NETIF_F_RXHASH) { 1300 if (features & NETIF_F_RXHASH) {
1303 u32 key[nkeys];
1304
1305 get_random_bytes(key, nkeys * sizeof(u32));
1306 for (i = 0; i < nkeys; i++) 1301 for (i = 0; i < nkeys; i++)
1307 sky2_write32(hw, SK_REG(sky2->port, RSS_KEY + i * 4), 1302 sky2_write32(hw, SK_REG(sky2->port, RSS_KEY + i * 4),
1308 key[i]); 1303 rss_init_key[i]);
1309 1304
1310 /* Need to turn on (undocumented) flag to make hashing work */ 1305 /* Need to turn on (undocumented) flag to make hashing work */
1311 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T), 1306 sky2_write32(hw, SK_REG(sky2->port, RX_GMF_CTRL_T),
@@ -1728,6 +1723,8 @@ static int sky2_setup_irq(struct sky2_hw *hw, const char *name)
1728 if (err) 1723 if (err)
1729 dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq); 1724 dev_err(&pdev->dev, "cannot assign irq %d\n", pdev->irq);
1730 else { 1725 else {
1726 hw->flags |= SKY2_HW_IRQ_SETUP;
1727
1731 napi_enable(&hw->napi); 1728 napi_enable(&hw->napi);
1732 sky2_write32(hw, B0_IMSK, Y2_IS_BASE); 1729 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
1733 sky2_read32(hw, B0_IMSK); 1730 sky2_read32(hw, B0_IMSK);
@@ -1738,7 +1735,7 @@ static int sky2_setup_irq(struct sky2_hw *hw, const char *name)
1738 1735
1739 1736
1740/* Bring up network interface. */ 1737/* Bring up network interface. */
1741static int sky2_up(struct net_device *dev) 1738static int sky2_open(struct net_device *dev)
1742{ 1739{
1743 struct sky2_port *sky2 = netdev_priv(dev); 1740 struct sky2_port *sky2 = netdev_priv(dev);
1744 struct sky2_hw *hw = sky2->hw; 1741 struct sky2_hw *hw = sky2->hw;
@@ -1758,6 +1755,11 @@ static int sky2_up(struct net_device *dev)
1758 1755
1759 sky2_hw_up(sky2); 1756 sky2_hw_up(sky2);
1760 1757
1758 if (hw->chip_id == CHIP_ID_YUKON_OPT ||
1759 hw->chip_id == CHIP_ID_YUKON_PRM ||
1760 hw->chip_id == CHIP_ID_YUKON_OP_2)
1761 imask |= Y2_IS_PHY_QLNK; /* enable PHY Quick Link */
1762
1761 /* Enable interrupts from phy/mac for port */ 1763 /* Enable interrupts from phy/mac for port */
1762 imask = sky2_read32(hw, B0_IMSK); 1764 imask = sky2_read32(hw, B0_IMSK);
1763 imask |= portirq_msk[port]; 1765 imask |= portirq_msk[port];
@@ -2051,6 +2053,8 @@ static void sky2_tx_reset(struct sky2_hw *hw, unsigned port)
2051 2053
2052 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET); 2054 sky2_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), RB_RST_SET);
2053 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 2055 sky2_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
2056
2057 sky2_read32(hw, B0_CTST);
2054} 2058}
2055 2059
2056static void sky2_hw_down(struct sky2_port *sky2) 2060static void sky2_hw_down(struct sky2_port *sky2)
@@ -2101,7 +2105,7 @@ static void sky2_hw_down(struct sky2_port *sky2)
2101} 2105}
2102 2106
2103/* Network shutdown */ 2107/* Network shutdown */
2104static int sky2_down(struct net_device *dev) 2108static int sky2_close(struct net_device *dev)
2105{ 2109{
2106 struct sky2_port *sky2 = netdev_priv(dev); 2110 struct sky2_port *sky2 = netdev_priv(dev);
2107 struct sky2_hw *hw = sky2->hw; 2111 struct sky2_hw *hw = sky2->hw;
@@ -2112,15 +2116,22 @@ static int sky2_down(struct net_device *dev)
2112 2116
2113 netif_info(sky2, ifdown, dev, "disabling interface\n"); 2117 netif_info(sky2, ifdown, dev, "disabling interface\n");
2114 2118
2115 /* Disable port IRQ */
2116 sky2_write32(hw, B0_IMSK,
2117 sky2_read32(hw, B0_IMSK) & ~portirq_msk[sky2->port]);
2118 sky2_read32(hw, B0_IMSK);
2119
2120 if (hw->ports == 1) { 2119 if (hw->ports == 1) {
2120 sky2_write32(hw, B0_IMSK, 0);
2121 sky2_read32(hw, B0_IMSK);
2122
2121 napi_disable(&hw->napi); 2123 napi_disable(&hw->napi);
2122 free_irq(hw->pdev->irq, hw); 2124 free_irq(hw->pdev->irq, hw);
2125 hw->flags &= ~SKY2_HW_IRQ_SETUP;
2123 } else { 2126 } else {
2127 u32 imask;
2128
2129 /* Disable port IRQ */
2130 imask = sky2_read32(hw, B0_IMSK);
2131 imask &= ~portirq_msk[sky2->port];
2132 sky2_write32(hw, B0_IMSK, imask);
2133 sky2_read32(hw, B0_IMSK);
2134
2124 synchronize_irq(hw->pdev->irq); 2135 synchronize_irq(hw->pdev->irq);
2125 napi_synchronize(&hw->napi); 2136 napi_synchronize(&hw->napi);
2126 } 2137 }
@@ -2598,7 +2609,7 @@ static inline void sky2_tx_done(struct net_device *dev, u16 last)
2598 if (netif_running(dev)) { 2609 if (netif_running(dev)) {
2599 sky2_tx_complete(sky2, last); 2610 sky2_tx_complete(sky2, last);
2600 2611
2601 /* Wake unless it's detached, and called e.g. from sky2_down() */ 2612 /* Wake unless it's detached, and called e.g. from sky2_close() */
2602 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4) 2613 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4)
2603 netif_wake_queue(dev); 2614 netif_wake_queue(dev);
2604 } 2615 }
@@ -3269,7 +3280,6 @@ static void sky2_reset(struct sky2_hw *hw)
3269 hw->chip_id == CHIP_ID_YUKON_PRM || 3280 hw->chip_id == CHIP_ID_YUKON_PRM ||
3270 hw->chip_id == CHIP_ID_YUKON_OP_2) { 3281 hw->chip_id == CHIP_ID_YUKON_OP_2) {
3271 u16 reg; 3282 u16 reg;
3272 u32 msk;
3273 3283
3274 if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) { 3284 if (hw->chip_id == CHIP_ID_YUKON_OPT && hw->chip_rev == 0) {
3275 /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */ 3285 /* disable PCI-E PHY power down (set PHY reg 0x80, bit 7 */
@@ -3292,11 +3302,6 @@ static void sky2_reset(struct sky2_hw *hw)
3292 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 3302 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
3293 sky2_pci_write16(hw, PSM_CONFIG_REG4, reg); 3303 sky2_pci_write16(hw, PSM_CONFIG_REG4, reg);
3294 3304
3295 /* enable PHY Quick Link */
3296 msk = sky2_read32(hw, B0_IMSK);
3297 msk |= Y2_IS_PHY_QLNK;
3298 sky2_write32(hw, B0_IMSK, msk);
3299
3300 /* check if PSMv2 was running before */ 3305 /* check if PSMv2 was running before */
3301 reg = sky2_pci_read16(hw, PSM_CONFIG_REG3); 3306 reg = sky2_pci_read16(hw, PSM_CONFIG_REG3);
3302 if (reg & PCI_EXP_LNKCTL_ASPMC) 3307 if (reg & PCI_EXP_LNKCTL_ASPMC)
@@ -3394,7 +3399,7 @@ static void sky2_detach(struct net_device *dev)
3394 netif_tx_lock(dev); 3399 netif_tx_lock(dev);
3395 netif_device_detach(dev); /* stop txq */ 3400 netif_device_detach(dev); /* stop txq */
3396 netif_tx_unlock(dev); 3401 netif_tx_unlock(dev);
3397 sky2_down(dev); 3402 sky2_close(dev);
3398 } 3403 }
3399} 3404}
3400 3405
@@ -3404,7 +3409,7 @@ static int sky2_reattach(struct net_device *dev)
3404 int err = 0; 3409 int err = 0;
3405 3410
3406 if (netif_running(dev)) { 3411 if (netif_running(dev)) {
3407 err = sky2_up(dev); 3412 err = sky2_open(dev);
3408 if (err) { 3413 if (err) {
3409 netdev_info(dev, "could not restart %d\n", err); 3414 netdev_info(dev, "could not restart %d\n", err);
3410 dev_close(dev); 3415 dev_close(dev);
@@ -3421,10 +3426,13 @@ static void sky2_all_down(struct sky2_hw *hw)
3421{ 3426{
3422 int i; 3427 int i;
3423 3428
3424 sky2_read32(hw, B0_IMSK); 3429 if (hw->flags & SKY2_HW_IRQ_SETUP) {
3425 sky2_write32(hw, B0_IMSK, 0); 3430 sky2_read32(hw, B0_IMSK);
3426 synchronize_irq(hw->pdev->irq); 3431 sky2_write32(hw, B0_IMSK, 0);
3427 napi_disable(&hw->napi); 3432
3433 synchronize_irq(hw->pdev->irq);
3434 napi_disable(&hw->napi);
3435 }
3428 3436
3429 for (i = 0; i < hw->ports; i++) { 3437 for (i = 0; i < hw->ports; i++) {
3430 struct net_device *dev = hw->dev[i]; 3438 struct net_device *dev = hw->dev[i];
@@ -3457,11 +3465,12 @@ static void sky2_all_up(struct sky2_hw *hw)
3457 netif_wake_queue(dev); 3465 netif_wake_queue(dev);
3458 } 3466 }
3459 3467
3460 sky2_write32(hw, B0_IMSK, imask); 3468 if (hw->flags & SKY2_HW_IRQ_SETUP) {
3461 sky2_read32(hw, B0_IMSK); 3469 sky2_write32(hw, B0_IMSK, imask);
3462 3470 sky2_read32(hw, B0_IMSK);
3463 sky2_read32(hw, B0_Y2_SP_LISR); 3471 sky2_read32(hw, B0_Y2_SP_LISR);
3464 napi_enable(&hw->napi); 3472 napi_enable(&hw->napi);
3473 }
3465} 3474}
3466 3475
3467static void sky2_restart(struct work_struct *work) 3476static void sky2_restart(struct work_struct *work)
@@ -4082,6 +4091,16 @@ static int sky2_set_coalesce(struct net_device *dev,
4082 return 0; 4091 return 0;
4083} 4092}
4084 4093
4094/*
4095 * Hardware is limited to min of 128 and max of 2048 for ring size
4096 * and rounded up to next power of two
4097 * to avoid division in modulus calclation
4098 */
4099static unsigned long roundup_ring_size(unsigned long pending)
4100{
4101 return max(128ul, roundup_pow_of_two(pending+1));
4102}
4103
4085static void sky2_get_ringparam(struct net_device *dev, 4104static void sky2_get_ringparam(struct net_device *dev,
4086 struct ethtool_ringparam *ering) 4105 struct ethtool_ringparam *ering)
4087{ 4106{
@@ -4109,7 +4128,7 @@ static int sky2_set_ringparam(struct net_device *dev,
4109 4128
4110 sky2->rx_pending = ering->rx_pending; 4129 sky2->rx_pending = ering->rx_pending;
4111 sky2->tx_pending = ering->tx_pending; 4130 sky2->tx_pending = ering->tx_pending;
4112 sky2->tx_ring_size = roundup_pow_of_two(sky2->tx_pending+1); 4131 sky2->tx_ring_size = roundup_ring_size(sky2->tx_pending);
4113 4132
4114 return sky2_reattach(dev); 4133 return sky2_reattach(dev);
4115} 4134}
@@ -4567,7 +4586,7 @@ static int sky2_device_event(struct notifier_block *unused,
4567 struct net_device *dev = ptr; 4586 struct net_device *dev = ptr;
4568 struct sky2_port *sky2 = netdev_priv(dev); 4587 struct sky2_port *sky2 = netdev_priv(dev);
4569 4588
4570 if (dev->netdev_ops->ndo_open != sky2_up || !sky2_debug) 4589 if (dev->netdev_ops->ndo_open != sky2_open || !sky2_debug)
4571 return NOTIFY_DONE; 4590 return NOTIFY_DONE;
4572 4591
4573 switch (event) { 4592 switch (event) {
@@ -4632,8 +4651,8 @@ static __exit void sky2_debug_cleanup(void)
4632 not allowing netpoll on second port */ 4651 not allowing netpoll on second port */
4633static const struct net_device_ops sky2_netdev_ops[2] = { 4652static const struct net_device_ops sky2_netdev_ops[2] = {
4634 { 4653 {
4635 .ndo_open = sky2_up, 4654 .ndo_open = sky2_open,
4636 .ndo_stop = sky2_down, 4655 .ndo_stop = sky2_close,
4637 .ndo_start_xmit = sky2_xmit_frame, 4656 .ndo_start_xmit = sky2_xmit_frame,
4638 .ndo_do_ioctl = sky2_ioctl, 4657 .ndo_do_ioctl = sky2_ioctl,
4639 .ndo_validate_addr = eth_validate_addr, 4658 .ndo_validate_addr = eth_validate_addr,
@@ -4649,8 +4668,8 @@ static const struct net_device_ops sky2_netdev_ops[2] = {
4649#endif 4668#endif
4650 }, 4669 },
4651 { 4670 {
4652 .ndo_open = sky2_up, 4671 .ndo_open = sky2_open,
4653 .ndo_stop = sky2_down, 4672 .ndo_stop = sky2_close,
4654 .ndo_start_xmit = sky2_xmit_frame, 4673 .ndo_start_xmit = sky2_xmit_frame,
4655 .ndo_do_ioctl = sky2_ioctl, 4674 .ndo_do_ioctl = sky2_ioctl,
4656 .ndo_validate_addr = eth_validate_addr, 4675 .ndo_validate_addr = eth_validate_addr,
@@ -4703,7 +4722,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
4703 spin_lock_init(&sky2->phy_lock); 4722 spin_lock_init(&sky2->phy_lock);
4704 4723
4705 sky2->tx_pending = TX_DEF_PENDING; 4724 sky2->tx_pending = TX_DEF_PENDING;
4706 sky2->tx_ring_size = roundup_pow_of_two(TX_DEF_PENDING+1); 4725 sky2->tx_ring_size = roundup_ring_size(TX_DEF_PENDING);
4707 sky2->rx_pending = RX_DEF_PENDING; 4726 sky2->rx_pending = RX_DEF_PENDING;
4708 4727
4709 hw->dev[port] = dev; 4728 hw->dev[port] = dev;
diff --git a/drivers/net/ethernet/marvell/sky2.h b/drivers/net/ethernet/marvell/sky2.h
index 0af31b8b5f1..ff6f58bf822 100644
--- a/drivers/net/ethernet/marvell/sky2.h
+++ b/drivers/net/ethernet/marvell/sky2.h
@@ -2287,6 +2287,7 @@ struct sky2_hw {
2287#define SKY2_HW_RSS_BROKEN 0x00000100 2287#define SKY2_HW_RSS_BROKEN 0x00000100
2288#define SKY2_HW_VLAN_BROKEN 0x00000200 2288#define SKY2_HW_VLAN_BROKEN 0x00000200
2289#define SKY2_HW_RSS_CHKSUM 0x00000400 /* RSS requires chksum */ 2289#define SKY2_HW_RSS_CHKSUM 0x00000400 /* RSS requires chksum */
2290#define SKY2_HW_IRQ_SETUP 0x00000800
2290 2291
2291 u8 chip_id; 2292 u8 chip_id;
2292 u8 chip_rev; 2293 u8 chip_rev;
diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 116cae334da..8be20e7ea3d 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 32f947154c3..45aea9c3ae2 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 23cee7b6af9..78f5a1a0b8c 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 bd8ef9f2fa7..499a5168892 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_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index b89c36dbf5b..c2df6c35860 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -581,6 +581,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
581 * Packet is OK - process it. 581 * Packet is OK - process it.
582 */ 582 */
583 length = be32_to_cpu(cqe->byte_cnt); 583 length = be32_to_cpu(cqe->byte_cnt);
584 length -= ring->fcs_del;
584 ring->bytes += length; 585 ring->bytes += length;
585 ring->packets++; 586 ring->packets++;
586 587
@@ -813,8 +814,11 @@ static int mlx4_en_config_rss_qp(struct mlx4_en_priv *priv, int qpn,
813 context->db_rec_addr = cpu_to_be64(ring->wqres.db.dma); 814 context->db_rec_addr = cpu_to_be64(ring->wqres.db.dma);
814 815
815 /* Cancel FCS removal if FW allows */ 816 /* Cancel FCS removal if FW allows */
816 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP) 817 if (mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP) {
817 context->param3 |= cpu_to_be32(1 << 29); 818 context->param3 |= cpu_to_be32(1 << 29);
819 ring->fcs_del = ETH_FCS_LEN;
820 } else
821 ring->fcs_del = 0;
818 822
819 err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, context, qp, state); 823 err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, context, qp, state);
820 if (err) { 824 if (err) {
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 90f2cd24faa..d901b426753 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 869a2c220a7..24ee9677599 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 abdfbacab4a..435ca6e4973 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 73c94fcdfdd..ca6feb55bd9 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 cd1784593a3..978688c3104 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/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 8fda331c65d..207b5add3ca 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -272,6 +272,7 @@ struct mlx4_en_rx_ring {
272 u32 prod; 272 u32 prod;
273 u32 cons; 273 u32 cons;
274 u32 buf_size; 274 u32 buf_size;
275 u8 fcs_del;
275 void *buf; 276 void *buf;
276 void *rx_info; 277 void *rx_info;
277 unsigned long bytes; 278 unsigned long bytes;
diff --git a/drivers/net/ethernet/mellanox/mlx4/mr.c b/drivers/net/ethernet/mellanox/mlx4/mr.c
index ab639cfef78..efa3e77355e 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 3736163e30e..260ed259ce9 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 a44f080fdfe..d942aea4927 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 51c53898c35..15f870cb259 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 a20b141dbb5..9cbf3fce014 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/natsemi/Kconfig b/drivers/net/ethernet/natsemi/Kconfig
index 4a6b9fd073b..eb836f770f5 100644
--- a/drivers/net/ethernet/natsemi/Kconfig
+++ b/drivers/net/ethernet/natsemi/Kconfig
@@ -5,7 +5,10 @@
5config NET_VENDOR_NATSEMI 5config NET_VENDOR_NATSEMI
6 bool "National Semi-conductor devices" 6 bool "National Semi-conductor devices"
7 default y 7 default y
8 depends on MCA || MAC || MACH_JAZZ || PCI || XTENSA_PLATFORM_XT2000 8 depends on AMIGA_PCMCIA || ARM || EISA || EXPERIMENTAL || H8300 || \
9 ISA || M32R || MAC || MACH_JAZZ || MACH_TX49XX || MCA || \
10 MCA_LEGACY || MIPS || PCI || PCMCIA || SUPERH || \
11 XTENSA_PLATFORM_XT2000 || ZORRO
9 ---help--- 12 ---help---
10 If you have a network (Ethernet) card belonging to this class, say Y 13 If you have a network (Ethernet) card belonging to this class, say Y
11 and read the Ethernet-HOWTO, available from 14 and read the Ethernet-HOWTO, available from
diff --git a/drivers/net/ethernet/neterion/vxge/vxge-main.c b/drivers/net/ethernet/neterion/vxge/vxge-main.c
index 671e166b5af..a83197d757c 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/nvidia/forcedeth.c b/drivers/net/ethernet/nvidia/forcedeth.c
index 1e37eb98c4e..1c61d36e657 100644
--- a/drivers/net/ethernet/nvidia/forcedeth.c
+++ b/drivers/net/ethernet/nvidia/forcedeth.c
@@ -609,7 +609,7 @@ struct nv_ethtool_str {
609}; 609};
610 610
611static const struct nv_ethtool_str nv_estats_str[] = { 611static const struct nv_ethtool_str nv_estats_str[] = {
612 { "tx_bytes" }, 612 { "tx_bytes" }, /* includes Ethernet FCS CRC */
613 { "tx_zero_rexmt" }, 613 { "tx_zero_rexmt" },
614 { "tx_one_rexmt" }, 614 { "tx_one_rexmt" },
615 { "tx_many_rexmt" }, 615 { "tx_many_rexmt" },
@@ -637,7 +637,7 @@ static const struct nv_ethtool_str nv_estats_str[] = {
637 /* version 2 stats */ 637 /* version 2 stats */
638 { "tx_deferral" }, 638 { "tx_deferral" },
639 { "tx_packets" }, 639 { "tx_packets" },
640 { "rx_bytes" }, 640 { "rx_bytes" }, /* includes Ethernet FCS CRC */
641 { "tx_pause" }, 641 { "tx_pause" },
642 { "rx_pause" }, 642 { "rx_pause" },
643 { "rx_drop_frame" }, 643 { "rx_drop_frame" },
@@ -649,7 +649,7 @@ static const struct nv_ethtool_str nv_estats_str[] = {
649}; 649};
650 650
651struct nv_ethtool_stats { 651struct nv_ethtool_stats {
652 u64 tx_bytes; 652 u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */
653 u64 tx_zero_rexmt; 653 u64 tx_zero_rexmt;
654 u64 tx_one_rexmt; 654 u64 tx_one_rexmt;
655 u64 tx_many_rexmt; 655 u64 tx_many_rexmt;
@@ -670,14 +670,14 @@ struct nv_ethtool_stats {
670 u64 rx_unicast; 670 u64 rx_unicast;
671 u64 rx_multicast; 671 u64 rx_multicast;
672 u64 rx_broadcast; 672 u64 rx_broadcast;
673 u64 rx_packets; 673 u64 rx_packets; /* should be ifconfig->rx_packets */
674 u64 rx_errors_total; 674 u64 rx_errors_total;
675 u64 tx_errors_total; 675 u64 tx_errors_total;
676 676
677 /* version 2 stats */ 677 /* version 2 stats */
678 u64 tx_deferral; 678 u64 tx_deferral;
679 u64 tx_packets; 679 u64 tx_packets; /* should be ifconfig->tx_packets */
680 u64 rx_bytes; 680 u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */
681 u64 tx_pause; 681 u64 tx_pause;
682 u64 rx_pause; 682 u64 rx_pause;
683 u64 rx_drop_frame; 683 u64 rx_drop_frame;
@@ -1682,6 +1682,7 @@ static void nv_get_hw_stats(struct net_device *dev)
1682 np->estats.tx_pause += readl(base + NvRegTxPause); 1682 np->estats.tx_pause += readl(base + NvRegTxPause);
1683 np->estats.rx_pause += readl(base + NvRegRxPause); 1683 np->estats.rx_pause += readl(base + NvRegRxPause);
1684 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame); 1684 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
1685 np->estats.rx_errors_total += np->estats.rx_drop_frame;
1685 } 1686 }
1686 1687
1687 if (np->driver_data & DEV_HAS_STATISTICS_V3) { 1688 if (np->driver_data & DEV_HAS_STATISTICS_V3) {
@@ -1705,12 +1706,22 @@ static struct net_device_stats *nv_get_stats(struct net_device *dev)
1705 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) { 1706 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) {
1706 nv_get_hw_stats(dev); 1707 nv_get_hw_stats(dev);
1707 1708
1709 /*
1710 * Note: because HW stats are not always available and
1711 * for consistency reasons, the following ifconfig
1712 * stats are managed by software: rx_bytes, tx_bytes,
1713 * rx_packets and tx_packets. The related hardware
1714 * stats reported by ethtool should be equivalent to
1715 * these ifconfig stats, with 4 additional bytes per
1716 * packet (Ethernet FCS CRC).
1717 */
1718
1708 /* copy to net_device stats */ 1719 /* copy to net_device stats */
1709 dev->stats.tx_bytes = np->estats.tx_bytes;
1710 dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors; 1720 dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
1711 dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors; 1721 dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
1712 dev->stats.rx_crc_errors = np->estats.rx_crc_errors; 1722 dev->stats.rx_crc_errors = np->estats.rx_crc_errors;
1713 dev->stats.rx_over_errors = np->estats.rx_over_errors; 1723 dev->stats.rx_over_errors = np->estats.rx_over_errors;
1724 dev->stats.rx_fifo_errors = np->estats.rx_drop_frame;
1714 dev->stats.rx_errors = np->estats.rx_errors_total; 1725 dev->stats.rx_errors = np->estats.rx_errors_total;
1715 dev->stats.tx_errors = np->estats.tx_errors_total; 1726 dev->stats.tx_errors = np->estats.tx_errors_total;
1716 } 1727 }
@@ -2099,10 +2110,10 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
2099 2110
2100 /* add fragments to entries count */ 2111 /* add fragments to entries count */
2101 for (i = 0; i < fragments; i++) { 2112 for (i = 0; i < fragments; i++) {
2102 u32 size = skb_frag_size(&skb_shinfo(skb)->frags[i]); 2113 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
2103 2114
2104 entries += (size >> NV_TX2_TSO_MAX_SHIFT) + 2115 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2105 ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); 2116 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2106 } 2117 }
2107 2118
2108 spin_lock_irqsave(&np->lock, flags); 2119 spin_lock_irqsave(&np->lock, flags);
@@ -2141,13 +2152,13 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
2141 /* setup the fragments */ 2152 /* setup the fragments */
2142 for (i = 0; i < fragments; i++) { 2153 for (i = 0; i < fragments; i++) {
2143 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 2154 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2144 u32 size = skb_frag_size(frag); 2155 u32 frag_size = skb_frag_size(frag);
2145 offset = 0; 2156 offset = 0;
2146 2157
2147 do { 2158 do {
2148 prev_tx = put_tx; 2159 prev_tx = put_tx;
2149 prev_tx_ctx = np->put_tx_ctx; 2160 prev_tx_ctx = np->put_tx_ctx;
2150 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; 2161 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
2151 np->put_tx_ctx->dma = skb_frag_dma_map( 2162 np->put_tx_ctx->dma = skb_frag_dma_map(
2152 &np->pci_dev->dev, 2163 &np->pci_dev->dev,
2153 frag, offset, 2164 frag, offset,
@@ -2159,12 +2170,12 @@ static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
2159 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); 2170 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
2160 2171
2161 offset += bcnt; 2172 offset += bcnt;
2162 size -= bcnt; 2173 frag_size -= bcnt;
2163 if (unlikely(put_tx++ == np->last_tx.orig)) 2174 if (unlikely(put_tx++ == np->last_tx.orig))
2164 put_tx = np->first_tx.orig; 2175 put_tx = np->first_tx.orig;
2165 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) 2176 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
2166 np->put_tx_ctx = np->first_tx_ctx; 2177 np->put_tx_ctx = np->first_tx_ctx;
2167 } while (size); 2178 } while (frag_size);
2168 } 2179 }
2169 2180
2170 /* set last fragment flag */ 2181 /* set last fragment flag */
@@ -2213,10 +2224,10 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2213 2224
2214 /* add fragments to entries count */ 2225 /* add fragments to entries count */
2215 for (i = 0; i < fragments; i++) { 2226 for (i = 0; i < fragments; i++) {
2216 u32 size = skb_frag_size(&skb_shinfo(skb)->frags[i]); 2227 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
2217 2228
2218 entries += (size >> NV_TX2_TSO_MAX_SHIFT) + 2229 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2219 ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); 2230 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2220 } 2231 }
2221 2232
2222 spin_lock_irqsave(&np->lock, flags); 2233 spin_lock_irqsave(&np->lock, flags);
@@ -2257,13 +2268,13 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2257 /* setup the fragments */ 2268 /* setup the fragments */
2258 for (i = 0; i < fragments; i++) { 2269 for (i = 0; i < fragments; i++) {
2259 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 2270 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2260 u32 size = skb_frag_size(frag); 2271 u32 frag_size = skb_frag_size(frag);
2261 offset = 0; 2272 offset = 0;
2262 2273
2263 do { 2274 do {
2264 prev_tx = put_tx; 2275 prev_tx = put_tx;
2265 prev_tx_ctx = np->put_tx_ctx; 2276 prev_tx_ctx = np->put_tx_ctx;
2266 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; 2277 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
2267 np->put_tx_ctx->dma = skb_frag_dma_map( 2278 np->put_tx_ctx->dma = skb_frag_dma_map(
2268 &np->pci_dev->dev, 2279 &np->pci_dev->dev,
2269 frag, offset, 2280 frag, offset,
@@ -2276,12 +2287,12 @@ static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2276 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); 2287 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
2277 2288
2278 offset += bcnt; 2289 offset += bcnt;
2279 size -= bcnt; 2290 frag_size -= bcnt;
2280 if (unlikely(put_tx++ == np->last_tx.ex)) 2291 if (unlikely(put_tx++ == np->last_tx.ex))
2281 put_tx = np->first_tx.ex; 2292 put_tx = np->first_tx.ex;
2282 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) 2293 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
2283 np->put_tx_ctx = np->first_tx_ctx; 2294 np->put_tx_ctx = np->first_tx_ctx;
2284 } while (size); 2295 } while (frag_size);
2285 } 2296 }
2286 2297
2287 /* set last fragment flag */ 2298 /* set last fragment flag */
@@ -2374,13 +2385,8 @@ static int nv_tx_done(struct net_device *dev, int limit)
2374 if (np->desc_ver == DESC_VER_1) { 2385 if (np->desc_ver == DESC_VER_1) {
2375 if (flags & NV_TX_LASTPACKET) { 2386 if (flags & NV_TX_LASTPACKET) {
2376 if (flags & NV_TX_ERROR) { 2387 if (flags & NV_TX_ERROR) {
2377 if (flags & NV_TX_UNDERFLOW)
2378 dev->stats.tx_fifo_errors++;
2379 if (flags & NV_TX_CARRIERLOST)
2380 dev->stats.tx_carrier_errors++;
2381 if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK)) 2388 if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK))
2382 nv_legacybackoff_reseed(dev); 2389 nv_legacybackoff_reseed(dev);
2383 dev->stats.tx_errors++;
2384 } else { 2390 } else {
2385 dev->stats.tx_packets++; 2391 dev->stats.tx_packets++;
2386 dev->stats.tx_bytes += np->get_tx_ctx->skb->len; 2392 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
@@ -2392,13 +2398,8 @@ static int nv_tx_done(struct net_device *dev, int limit)
2392 } else { 2398 } else {
2393 if (flags & NV_TX2_LASTPACKET) { 2399 if (flags & NV_TX2_LASTPACKET) {
2394 if (flags & NV_TX2_ERROR) { 2400 if (flags & NV_TX2_ERROR) {
2395 if (flags & NV_TX2_UNDERFLOW)
2396 dev->stats.tx_fifo_errors++;
2397 if (flags & NV_TX2_CARRIERLOST)
2398 dev->stats.tx_carrier_errors++;
2399 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) 2401 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK))
2400 nv_legacybackoff_reseed(dev); 2402 nv_legacybackoff_reseed(dev);
2401 dev->stats.tx_errors++;
2402 } else { 2403 } else {
2403 dev->stats.tx_packets++; 2404 dev->stats.tx_packets++;
2404 dev->stats.tx_bytes += np->get_tx_ctx->skb->len; 2405 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
@@ -2434,15 +2435,16 @@ static int nv_tx_done_optimized(struct net_device *dev, int limit)
2434 nv_unmap_txskb(np, np->get_tx_ctx); 2435 nv_unmap_txskb(np, np->get_tx_ctx);
2435 2436
2436 if (flags & NV_TX2_LASTPACKET) { 2437 if (flags & NV_TX2_LASTPACKET) {
2437 if (!(flags & NV_TX2_ERROR)) 2438 if (flags & NV_TX2_ERROR) {
2438 dev->stats.tx_packets++;
2439 else {
2440 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) { 2439 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
2441 if (np->driver_data & DEV_HAS_GEAR_MODE) 2440 if (np->driver_data & DEV_HAS_GEAR_MODE)
2442 nv_gear_backoff_reseed(dev); 2441 nv_gear_backoff_reseed(dev);
2443 else 2442 else
2444 nv_legacybackoff_reseed(dev); 2443 nv_legacybackoff_reseed(dev);
2445 } 2444 }
2445 } else {
2446 dev->stats.tx_packets++;
2447 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
2446 } 2448 }
2447 2449
2448 dev_kfree_skb_any(np->get_tx_ctx->skb); 2450 dev_kfree_skb_any(np->get_tx_ctx->skb);
@@ -2636,7 +2638,6 @@ static int nv_rx_process(struct net_device *dev, int limit)
2636 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) { 2638 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
2637 len = nv_getlen(dev, skb->data, len); 2639 len = nv_getlen(dev, skb->data, len);
2638 if (len < 0) { 2640 if (len < 0) {
2639 dev->stats.rx_errors++;
2640 dev_kfree_skb(skb); 2641 dev_kfree_skb(skb);
2641 goto next_pkt; 2642 goto next_pkt;
2642 } 2643 }
@@ -2650,11 +2651,6 @@ static int nv_rx_process(struct net_device *dev, int limit)
2650 else { 2651 else {
2651 if (flags & NV_RX_MISSEDFRAME) 2652 if (flags & NV_RX_MISSEDFRAME)
2652 dev->stats.rx_missed_errors++; 2653 dev->stats.rx_missed_errors++;
2653 if (flags & NV_RX_CRCERR)
2654 dev->stats.rx_crc_errors++;
2655 if (flags & NV_RX_OVERFLOW)
2656 dev->stats.rx_over_errors++;
2657 dev->stats.rx_errors++;
2658 dev_kfree_skb(skb); 2654 dev_kfree_skb(skb);
2659 goto next_pkt; 2655 goto next_pkt;
2660 } 2656 }
@@ -2670,7 +2666,6 @@ static int nv_rx_process(struct net_device *dev, int limit)
2670 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) { 2666 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
2671 len = nv_getlen(dev, skb->data, len); 2667 len = nv_getlen(dev, skb->data, len);
2672 if (len < 0) { 2668 if (len < 0) {
2673 dev->stats.rx_errors++;
2674 dev_kfree_skb(skb); 2669 dev_kfree_skb(skb);
2675 goto next_pkt; 2670 goto next_pkt;
2676 } 2671 }
@@ -2682,11 +2677,6 @@ static int nv_rx_process(struct net_device *dev, int limit)
2682 } 2677 }
2683 /* the rest are hard errors */ 2678 /* the rest are hard errors */
2684 else { 2679 else {
2685 if (flags & NV_RX2_CRCERR)
2686 dev->stats.rx_crc_errors++;
2687 if (flags & NV_RX2_OVERFLOW)
2688 dev->stats.rx_over_errors++;
2689 dev->stats.rx_errors++;
2690 dev_kfree_skb(skb); 2680 dev_kfree_skb(skb);
2691 goto next_pkt; 2681 goto next_pkt;
2692 } 2682 }
@@ -2787,7 +2777,6 @@ static int nv_rx_process_optimized(struct net_device *dev, int limit)
2787 __vlan_hwaccel_put_tag(skb, vid); 2777 __vlan_hwaccel_put_tag(skb, vid);
2788 } 2778 }
2789 napi_gro_receive(&np->napi, skb); 2779 napi_gro_receive(&np->napi, skb);
2790
2791 dev->stats.rx_packets++; 2780 dev->stats.rx_packets++;
2792 dev->stats.rx_bytes += len; 2781 dev->stats.rx_bytes += len;
2793 } else { 2782 } else {
@@ -2962,11 +2951,11 @@ static void nv_set_multicast(struct net_device *dev)
2962 struct netdev_hw_addr *ha; 2951 struct netdev_hw_addr *ha;
2963 2952
2964 netdev_for_each_mc_addr(ha, dev) { 2953 netdev_for_each_mc_addr(ha, dev) {
2965 unsigned char *addr = ha->addr; 2954 unsigned char *hw_addr = ha->addr;
2966 u32 a, b; 2955 u32 a, b;
2967 2956
2968 a = le32_to_cpu(*(__le32 *) addr); 2957 a = le32_to_cpu(*(__le32 *) hw_addr);
2969 b = le16_to_cpu(*(__le16 *) (&addr[4])); 2958 b = le16_to_cpu(*(__le16 *) (&hw_addr[4]));
2970 alwaysOn[0] &= a; 2959 alwaysOn[0] &= a;
2971 alwaysOff[0] &= ~a; 2960 alwaysOff[0] &= ~a;
2972 alwaysOn[1] &= b; 2961 alwaysOn[1] &= b;
@@ -3398,7 +3387,8 @@ static irqreturn_t nv_nic_irq_tx(int foo, void *data)
3398 3387
3399 for (i = 0;; i++) { 3388 for (i = 0;; i++) {
3400 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL; 3389 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
3401 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus); 3390 writel(events, base + NvRegMSIXIrqStatus);
3391 netdev_dbg(dev, "tx irq events: %08x\n", events);
3402 if (!(events & np->irqmask)) 3392 if (!(events & np->irqmask))
3403 break; 3393 break;
3404 3394
@@ -3509,7 +3499,8 @@ static irqreturn_t nv_nic_irq_rx(int foo, void *data)
3509 3499
3510 for (i = 0;; i++) { 3500 for (i = 0;; i++) {
3511 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL; 3501 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3512 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus); 3502 writel(events, base + NvRegMSIXIrqStatus);
3503 netdev_dbg(dev, "rx irq events: %08x\n", events);
3513 if (!(events & np->irqmask)) 3504 if (!(events & np->irqmask))
3514 break; 3505 break;
3515 3506
@@ -3553,7 +3544,8 @@ static irqreturn_t nv_nic_irq_other(int foo, void *data)
3553 3544
3554 for (i = 0;; i++) { 3545 for (i = 0;; i++) {
3555 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER; 3546 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
3556 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus); 3547 writel(events, base + NvRegMSIXIrqStatus);
3548 netdev_dbg(dev, "irq events: %08x\n", events);
3557 if (!(events & np->irqmask)) 3549 if (!(events & np->irqmask))
3558 break; 3550 break;
3559 3551
@@ -3617,10 +3609,10 @@ static irqreturn_t nv_nic_irq_test(int foo, void *data)
3617 3609
3618 if (!(np->msi_flags & NV_MSI_X_ENABLED)) { 3610 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3619 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; 3611 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3620 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus); 3612 writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus);
3621 } else { 3613 } else {
3622 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; 3614 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3623 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus); 3615 writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
3624 } 3616 }
3625 pci_push(base); 3617 pci_push(base);
3626 if (!(events & NVREG_IRQ_TIMER)) 3618 if (!(events & NVREG_IRQ_TIMER))
@@ -4566,7 +4558,7 @@ static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *e
4566 struct fe_priv *np = netdev_priv(dev); 4558 struct fe_priv *np = netdev_priv(dev);
4567 4559
4568 /* update stats */ 4560 /* update stats */
4569 nv_do_stats_poll((unsigned long)dev); 4561 nv_get_hw_stats(dev);
4570 4562
4571 memcpy(buffer, &np->estats, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64)); 4563 memcpy(buffer, &np->estats, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
4572} 4564}
diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c b/drivers/net/ethernet/octeon/octeon_mgmt.c
index bc1d946b797..212f43b308a 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 b89f3a684ae..48406ca382f 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 5b5d90a47e2..9cb5f912e48 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
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "pch_gbe.h" 21#include "pch_gbe.h"
22#include <linux/module.h> /* for __MODULE_STRING */
22 23
23#define OPTION_UNSET -1 24#define OPTION_UNSET -1
24#define OPTION_DISABLED 0 25#define OPTION_DISABLED 0
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge.h b/drivers/net/ethernet/qlogic/qlge/qlge.h
index 8731f79c9ef..b8478aab050 100644
--- a/drivers/net/ethernet/qlogic/qlge/qlge.h
+++ b/drivers/net/ethernet/qlogic/qlge/qlge.h
@@ -58,10 +58,8 @@
58 58
59 59
60#define TX_DESC_PER_IOCB 8 60#define TX_DESC_PER_IOCB 8
61/* The maximum number of frags we handle is based 61
62 * on PAGE_SIZE... 62#if ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2) > 0
63 */
64#if (PAGE_SHIFT == 12) || (PAGE_SHIFT == 13) /* 4k & 8k pages */
65#define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2) 63#define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2)
66#else /* all other page sizes */ 64#else /* all other page sizes */
67#define TX_DESC_PER_OAL 0 65#define TX_DESC_PER_OAL 0
@@ -1353,7 +1351,7 @@ struct tx_ring_desc {
1353 struct ob_mac_iocb_req *queue_entry; 1351 struct ob_mac_iocb_req *queue_entry;
1354 u32 index; 1352 u32 index;
1355 struct oal oal; 1353 struct oal oal;
1356 struct map_list map[MAX_SKB_FRAGS + 1]; 1354 struct map_list map[MAX_SKB_FRAGS + 2];
1357 int map_cnt; 1355 int map_cnt;
1358 struct tx_ring_desc *next; 1356 struct tx_ring_desc *next;
1359}; 1357};
diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index 1fc01ca72b4..4bf68cfef39 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -940,7 +940,7 @@ static void r6040_multicast_list(struct net_device *dev)
940 iowrite16(lp->mcr0, ioaddr + MCR0); 940 iowrite16(lp->mcr0, ioaddr + MCR0);
941 941
942 /* Fill the MAC hash tables with their values */ 942 /* Fill the MAC hash tables with their values */
943 if (lp->mcr0 && MCR0_HASH_EN) { 943 if (lp->mcr0 & MCR0_HASH_EN) {
944 iowrite16(hash_table[0], ioaddr + MAR0); 944 iowrite16(hash_table[0], ioaddr + MAR0);
945 iowrite16(hash_table[1], ioaddr + MAR1); 945 iowrite16(hash_table[1], ioaddr + MAR1);
946 iowrite16(hash_table[2], ioaddr + MAR2); 946 iowrite16(hash_table[2], ioaddr + MAR2);
diff --git a/drivers/net/ethernet/realtek/Kconfig b/drivers/net/ethernet/realtek/Kconfig
index 84083ec6e61..0578859a3c7 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 e48cfb6ac42..71b1da30ecb 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/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 92b45f08858..6f06aa10f0d 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -1292,7 +1292,7 @@ static void __rtl8169_check_link_status(struct net_device *dev,
1292 netif_carrier_off(dev); 1292 netif_carrier_off(dev);
1293 netif_info(tp, ifdown, dev, "link down\n"); 1293 netif_info(tp, ifdown, dev, "link down\n");
1294 if (pm) 1294 if (pm)
1295 pm_schedule_suspend(&tp->pci_dev->dev, 100); 1295 pm_schedule_suspend(&tp->pci_dev->dev, 5000);
1296 } 1296 }
1297 spin_unlock_irqrestore(&tp->lock, flags); 1297 spin_unlock_irqrestore(&tp->lock, flags);
1298} 1298}
diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c
index adbda182f15..752d521c09b 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 00000000000..ae1ce170864
--- /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 00000000000..4ad3523dcb9
--- /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 a284d644053..a284d644053 100644
--- a/drivers/net/ethernet/realtek/sc92031.c
+++ b/drivers/net/ethernet/silan/sc92031.c
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index d2be42aafbe..8843071fe98 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -1937,6 +1937,7 @@ static int __devinit smsc911x_init(struct net_device *dev)
1937{ 1937{
1938 struct smsc911x_data *pdata = netdev_priv(dev); 1938 struct smsc911x_data *pdata = netdev_priv(dev);
1939 unsigned int byte_test; 1939 unsigned int byte_test;
1940 unsigned int to = 100;
1940 1941
1941 SMSC_TRACE(pdata, probe, "Driver Parameters:"); 1942 SMSC_TRACE(pdata, probe, "Driver Parameters:");
1942 SMSC_TRACE(pdata, probe, "LAN base: 0x%08lX", 1943 SMSC_TRACE(pdata, probe, "LAN base: 0x%08lX",
@@ -1952,6 +1953,17 @@ static int __devinit smsc911x_init(struct net_device *dev)
1952 return -ENODEV; 1953 return -ENODEV;
1953 } 1954 }
1954 1955
1956 /*
1957 * poll the READY bit in PMT_CTRL. Any other access to the device is
1958 * forbidden while this bit isn't set. Try for 100ms
1959 */
1960 while (!(smsc911x_reg_read(pdata, PMT_CTRL) & PMT_CTRL_READY_) && --to)
1961 udelay(1000);
1962 if (to == 0) {
1963 pr_err("Device not READY in 100ms aborting\n");
1964 return -ENODEV;
1965 }
1966
1955 /* Check byte ordering */ 1967 /* Check byte ordering */
1956 byte_test = smsc911x_reg_read(pdata, BYTE_TEST); 1968 byte_test = smsc911x_reg_read(pdata, BYTE_TEST);
1957 SMSC_TRACE(pdata, probe, "BYTE_TEST: 0x%08X", byte_test); 1969 SMSC_TRACE(pdata, probe, "BYTE_TEST: 0x%08X", byte_test);
diff --git a/drivers/net/ethernet/smsc/smsc9420.c b/drivers/net/ethernet/smsc/smsc9420.c
index 4f15680849f..edb24b0e337 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 ac6f190743d..22745d7bf53 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/stmicro/stmmac/dwmac1000_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
index da66ac511c4..4d5402a1d26 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
@@ -39,10 +39,11 @@ static int dwmac1000_dma_init(void __iomem *ioaddr, int pbl, u32 dma_tx,
39 /* DMA SW reset */ 39 /* DMA SW reset */
40 value |= DMA_BUS_MODE_SFT_RESET; 40 value |= DMA_BUS_MODE_SFT_RESET;
41 writel(value, ioaddr + DMA_BUS_MODE); 41 writel(value, ioaddr + DMA_BUS_MODE);
42 limit = 15000; 42 limit = 10;
43 while (limit--) { 43 while (limit--) {
44 if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET)) 44 if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
45 break; 45 break;
46 mdelay(10);
46 } 47 }
47 if (limit < 0) 48 if (limit < 0)
48 return -EBUSY; 49 return -EBUSY;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c
index 627f656b0f3..bc17fd08b55 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c
@@ -41,10 +41,11 @@ static int dwmac100_dma_init(void __iomem *ioaddr, int pbl, u32 dma_tx,
41 /* DMA SW reset */ 41 /* DMA SW reset */
42 value |= DMA_BUS_MODE_SFT_RESET; 42 value |= DMA_BUS_MODE_SFT_RESET;
43 writel(value, ioaddr + DMA_BUS_MODE); 43 writel(value, ioaddr + DMA_BUS_MODE);
44 limit = 15000; 44 limit = 10;
45 while (limit--) { 45 while (limit--) {
46 if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET)) 46 if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
47 break; 47 break;
48 mdelay(10);
48 } 49 }
49 if (limit < 0) 50 if (limit < 0)
50 return -EBUSY; 51 return -EBUSY;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 9bafa6cf9e8..a140a8fbf05 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -72,7 +72,6 @@ struct stmmac_priv {
72 spinlock_t lock; 72 spinlock_t lock;
73 spinlock_t tx_lock; 73 spinlock_t tx_lock;
74 int wolopts; 74 int wolopts;
75 int wolenabled;
76 int wol_irq; 75 int wol_irq;
77#ifdef CONFIG_STMMAC_TIMER 76#ifdef CONFIG_STMMAC_TIMER
78 struct stmmac_timer *tm; 77 struct stmmac_timer *tm;
@@ -80,6 +79,7 @@ struct stmmac_priv {
80 struct plat_stmmacenet_data *plat; 79 struct plat_stmmacenet_data *plat;
81 struct stmmac_counters mmc; 80 struct stmmac_counters mmc;
82 struct dma_features dma_cap; 81 struct dma_features dma_cap;
82 int hw_cap_support;
83}; 83};
84 84
85extern int stmmac_mdio_unregister(struct net_device *ndev); 85extern int stmmac_mdio_unregister(struct net_device *ndev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index e8eff09bbbd..0395f9eba80 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -430,6 +430,12 @@ static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
430 struct stmmac_priv *priv = netdev_priv(dev); 430 struct stmmac_priv *priv = netdev_priv(dev);
431 u32 support = WAKE_MAGIC | WAKE_UCAST; 431 u32 support = WAKE_MAGIC | WAKE_UCAST;
432 432
433 /* By default almost all GMAC devices support the WoL via
434 * magic frame but we can disable it if the HW capability
435 * register shows no support for pmt_magic_frame. */
436 if ((priv->hw_cap_support) && (!priv->dma_cap.pmt_magic_frame))
437 wol->wolopts &= ~WAKE_MAGIC;
438
433 if (!device_can_wakeup(priv->device)) 439 if (!device_can_wakeup(priv->device))
434 return -EINVAL; 440 return -EINVAL;
435 441
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 20546bbbb8d..72cd190b9c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -321,12 +321,10 @@ static int stmmac_init_phy(struct net_device *dev)
321 } 321 }
322 322
323 /* Stop Advertising 1000BASE Capability if interface is not GMII */ 323 /* Stop Advertising 1000BASE Capability if interface is not GMII */
324 if ((interface) && ((interface == PHY_INTERFACE_MODE_MII) || 324 if ((interface == PHY_INTERFACE_MODE_MII) ||
325 (interface == PHY_INTERFACE_MODE_RMII))) { 325 (interface == PHY_INTERFACE_MODE_RMII))
326 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause | 326 phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
327 SUPPORTED_Asym_Pause); 327 SUPPORTED_1000baseT_Full);
328 phydev->advertising = phydev->supported;
329 }
330 328
331 /* 329 /*
332 * Broken HW is sometimes missing the pull-up resistor on the 330 * Broken HW is sometimes missing the pull-up resistor on the
@@ -783,10 +781,15 @@ static void stmmac_mmc_setup(struct stmmac_priv *priv)
783 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET | 781 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
784 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET; 782 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
785 783
786 /* Do not manage MMC IRQ (FIXME) */ 784 /* Mask MMC irq, counters are managed in SW and registers
785 * are cleared on each READ eventually. */
787 dwmac_mmc_intr_all_mask(priv->ioaddr); 786 dwmac_mmc_intr_all_mask(priv->ioaddr);
788 dwmac_mmc_ctrl(priv->ioaddr, mode); 787
789 memset(&priv->mmc, 0, sizeof(struct stmmac_counters)); 788 if (priv->dma_cap.rmon) {
789 dwmac_mmc_ctrl(priv->ioaddr, mode);
790 memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
791 } else
792 pr_info(" No MAC Management Counters available");
790} 793}
791 794
792static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv) 795static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
@@ -807,8 +810,29 @@ static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
807 return 0; 810 return 0;
808} 811}
809 812
810/* New GMAC chips support a new register to indicate the 813/**
811 * presence of the optional feature/functions. 814 * stmmac_selec_desc_mode
815 * @dev : device pointer
816 * Description: select the Enhanced/Alternate or Normal descriptors */
817static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
818{
819 if (priv->plat->enh_desc) {
820 pr_info(" Enhanced/Alternate descriptors\n");
821 priv->hw->desc = &enh_desc_ops;
822 } else {
823 pr_info(" Normal descriptors\n");
824 priv->hw->desc = &ndesc_ops;
825 }
826}
827
828/**
829 * stmmac_get_hw_features
830 * @priv : private device pointer
831 * Description:
832 * new GMAC chip generations have a new register to indicate the
833 * presence of the optional feature/functions.
834 * This can be also used to override the value passed through the
835 * platform and necessary for old MAC10/100 and GMAC chips.
812 */ 836 */
813static int stmmac_get_hw_features(struct stmmac_priv *priv) 837static int stmmac_get_hw_features(struct stmmac_priv *priv)
814{ 838{
@@ -829,7 +853,7 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv)
829 (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9; 853 (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
830 priv->dma_cap.pmt_magic_frame = 854 priv->dma_cap.pmt_magic_frame =
831 (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10; 855 (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
832 /*MMC*/ 856 /* MMC */
833 priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11; 857 priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
834 /* IEEE 1588-2002*/ 858 /* IEEE 1588-2002*/
835 priv->dma_cap.time_stamp = 859 priv->dma_cap.time_stamp =
@@ -857,8 +881,7 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv)
857 priv->dma_cap.enh_desc = 881 priv->dma_cap.enh_desc =
858 (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24; 882 (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
859 883
860 } else 884 }
861 pr_debug("\tNo HW DMA feature register supported");
862 885
863 return hw_cap; 886 return hw_cap;
864} 887}
@@ -913,6 +936,44 @@ static int stmmac_open(struct net_device *dev)
913 goto open_error; 936 goto open_error;
914 } 937 }
915 938
939 stmmac_get_synopsys_id(priv);
940
941 priv->hw_cap_support = stmmac_get_hw_features(priv);
942
943 if (priv->hw_cap_support) {
944 pr_info(" Support DMA HW capability register");
945
946 /* We can override some gmac/dma configuration fields: e.g.
947 * enh_desc, tx_coe (e.g. that are passed through the
948 * platform) with the values from the HW capability
949 * register (if supported).
950 */
951 priv->plat->enh_desc = priv->dma_cap.enh_desc;
952 priv->plat->tx_coe = priv->dma_cap.tx_coe;
953 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
954
955 /* By default disable wol on magic frame if not supported */
956 if (!priv->dma_cap.pmt_magic_frame)
957 priv->wolopts &= ~WAKE_MAGIC;
958
959 } else
960 pr_info(" No HW DMA feature register supported");
961
962 /* Select the enhnaced/normal descriptor structures */
963 stmmac_selec_desc_mode(priv);
964
965 /* PMT module is not integrated in all the MAC devices. */
966 if (priv->plat->pmt) {
967 pr_info(" Remote wake-up capable\n");
968 device_set_wakeup_capable(priv->device, 1);
969 }
970
971 priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
972 if (priv->rx_coe)
973 pr_info(" Checksum Offload Engine supported\n");
974 if (priv->plat->tx_coe)
975 pr_info(" Checksum insertion supported\n");
976
916 /* Create and initialize the TX/RX descriptors chains. */ 977 /* Create and initialize the TX/RX descriptors chains. */
917 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize); 978 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
918 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize); 979 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
@@ -935,15 +996,6 @@ static int stmmac_open(struct net_device *dev)
935 /* Initialize the MAC Core */ 996 /* Initialize the MAC Core */
936 priv->hw->mac->core_init(priv->ioaddr); 997 priv->hw->mac->core_init(priv->ioaddr);
937 998
938 stmmac_get_synopsys_id(priv);
939
940 stmmac_get_hw_features(priv);
941
942 priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
943 if (priv->rx_coe)
944 pr_info("stmmac: Rx Checksum Offload Engine supported\n");
945 if (priv->plat->tx_coe)
946 pr_info("\tTX Checksum insertion supported\n");
947 netdev_update_features(dev); 999 netdev_update_features(dev);
948 1000
949 /* Request the IRQ lines */ 1001 /* Request the IRQ lines */
@@ -965,8 +1017,7 @@ static int stmmac_open(struct net_device *dev)
965 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats)); 1017 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
966 priv->xstats.threshold = tc; 1018 priv->xstats.threshold = tc;
967 1019
968 if (priv->dma_cap.rmon) 1020 stmmac_mmc_setup(priv);
969 stmmac_mmc_setup(priv);
970 1021
971 /* Start the ball rolling... */ 1022 /* Start the ball rolling... */
972 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name); 1023 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
@@ -1489,9 +1540,7 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1489 if (!priv->phydev) 1540 if (!priv->phydev)
1490 return -EINVAL; 1541 return -EINVAL;
1491 1542
1492 spin_lock(&priv->lock);
1493 ret = phy_mii_ioctl(priv->phydev, rq, cmd); 1543 ret = phy_mii_ioctl(priv->phydev, rq, cmd);
1494 spin_unlock(&priv->lock);
1495 1544
1496 return ret; 1545 return ret;
1497} 1546}
@@ -1558,7 +1607,7 @@ static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
1558 struct net_device *dev = seq->private; 1607 struct net_device *dev = seq->private;
1559 struct stmmac_priv *priv = netdev_priv(dev); 1608 struct stmmac_priv *priv = netdev_priv(dev);
1560 1609
1561 if (!stmmac_get_hw_features(priv)) { 1610 if (!priv->hw_cap_support) {
1562 seq_printf(seq, "DMA HW features not supported\n"); 1611 seq_printf(seq, "DMA HW features not supported\n");
1563 return 0; 1612 return 0;
1564 } 1613 }
@@ -1766,12 +1815,6 @@ static int stmmac_mac_device_setup(struct net_device *dev)
1766 if (!device) 1815 if (!device)
1767 return -ENOMEM; 1816 return -ENOMEM;
1768 1817
1769 if (priv->plat->enh_desc) {
1770 device->desc = &enh_desc_ops;
1771 pr_info("\tEnhanced descriptor structure\n");
1772 } else
1773 device->desc = &ndesc_ops;
1774
1775 priv->hw = device; 1818 priv->hw = device;
1776 priv->hw->ring = &ring_mode_ops; 1819 priv->hw->ring = &ring_mode_ops;
1777 1820
@@ -1845,11 +1888,6 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
1845 1888
1846 priv->ioaddr = addr; 1889 priv->ioaddr = addr;
1847 1890
1848 /* PMT module is not integrated in all the MAC devices. */
1849 if (plat_dat->pmt) {
1850 pr_info("\tPMT module supported\n");
1851 device_set_wakeup_capable(&pdev->dev, 1);
1852 }
1853 /* 1891 /*
1854 * On some platforms e.g. SPEAr the wake up irq differs from the mac irq 1892 * On some platforms e.g. SPEAr the wake up irq differs from the mac irq
1855 * The external wake up irq can be passed through the platform code 1893 * The external wake up irq can be passed through the platform code
@@ -1862,7 +1900,6 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
1862 if (priv->wol_irq == -ENXIO) 1900 if (priv->wol_irq == -ENXIO)
1863 priv->wol_irq = ndev->irq; 1901 priv->wol_irq = ndev->irq;
1864 1902
1865
1866 platform_set_drvdata(pdev, ndev); 1903 platform_set_drvdata(pdev, ndev);
1867 1904
1868 /* Set the I/O base addr */ 1905 /* Set the I/O base addr */
@@ -1875,7 +1912,7 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
1875 goto out_free_ndev; 1912 goto out_free_ndev;
1876 } 1913 }
1877 1914
1878 /* MAC HW revice detection */ 1915 /* MAC HW device detection */
1879 ret = stmmac_mac_device_setup(ndev); 1916 ret = stmmac_mac_device_setup(ndev);
1880 if (ret < 0) 1917 if (ret < 0)
1881 goto out_plat_exit; 1918 goto out_plat_exit;
@@ -1978,12 +2015,13 @@ static int stmmac_suspend(struct device *dev)
1978 if (!ndev || !netif_running(ndev)) 2015 if (!ndev || !netif_running(ndev))
1979 return 0; 2016 return 0;
1980 2017
2018 if (priv->phydev)
2019 phy_stop(priv->phydev);
2020
1981 spin_lock(&priv->lock); 2021 spin_lock(&priv->lock);
1982 2022
1983 netif_device_detach(ndev); 2023 netif_device_detach(ndev);
1984 netif_stop_queue(ndev); 2024 netif_stop_queue(ndev);
1985 if (priv->phydev)
1986 phy_stop(priv->phydev);
1987 2025
1988#ifdef CONFIG_STMMAC_TIMER 2026#ifdef CONFIG_STMMAC_TIMER
1989 priv->tm->timer_stop(); 2027 priv->tm->timer_stop();
@@ -2041,12 +2079,13 @@ static int stmmac_resume(struct device *dev)
2041#endif 2079#endif
2042 napi_enable(&priv->napi); 2080 napi_enable(&priv->napi);
2043 2081
2044 if (priv->phydev)
2045 phy_start(priv->phydev);
2046
2047 netif_start_queue(ndev); 2082 netif_start_queue(ndev);
2048 2083
2049 spin_unlock(&priv->lock); 2084 spin_unlock(&priv->lock);
2085
2086 if (priv->phydev)
2087 phy_start(priv->phydev);
2088
2050 return 0; 2089 return 0;
2051} 2090}
2052 2091
diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
index c517dac02ae..cf14ab9db57 100644
--- a/drivers/net/ethernet/sun/sunhme.c
+++ b/drivers/net/ethernet/sun/sunhme.c
@@ -2637,7 +2637,7 @@ static int __devinit happy_meal_sbus_probe_one(struct platform_device *op, int i
2637 sbus_dp = op->dev.parent->of_node; 2637 sbus_dp = op->dev.parent->of_node;
2638 2638
2639 /* We can match PCI devices too, do not accept those here. */ 2639 /* We can match PCI devices too, do not accept those here. */
2640 if (strcmp(sbus_dp->name, "sbus")) 2640 if (strcmp(sbus_dp->name, "sbus") && strcmp(sbus_dp->name, "sbi"))
2641 return err; 2641 return err;
2642 2642
2643 if (is_qfe) { 2643 if (is_qfe) {
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index ddb33cfd354..7bf1e201578 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 d3fadfbc3bc..a93df6ac190 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 4d1658e78de..2681b53820e 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -114,6 +114,7 @@ void temac_indirect_out32(struct temac_local *lp, int reg, u32 value)
114 return; 114 return;
115 temac_iow(lp, XTE_LSW0_OFFSET, value); 115 temac_iow(lp, XTE_LSW0_OFFSET, value);
116 temac_iow(lp, XTE_CTL0_OFFSET, CNTLREG_WRITE_ENABLE_MASK | reg); 116 temac_iow(lp, XTE_CTL0_OFFSET, CNTLREG_WRITE_ENABLE_MASK | reg);
117 temac_indirect_busywait(lp);
117} 118}
118 119
119/** 120/**
@@ -203,6 +204,9 @@ static void temac_dma_bd_release(struct net_device *ndev)
203 struct temac_local *lp = netdev_priv(ndev); 204 struct temac_local *lp = netdev_priv(ndev);
204 int i; 205 int i;
205 206
207 /* Reset Local Link (DMA) */
208 lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST);
209
206 for (i = 0; i < RX_BD_NUM; i++) { 210 for (i = 0; i < RX_BD_NUM; i++) {
207 if (!lp->rx_skb[i]) 211 if (!lp->rx_skb[i])
208 break; 212 break;
@@ -716,8 +720,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]; 720 cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
717 cur_p->phys = dma_map_single(ndev->dev.parent, 721 cur_p->phys = dma_map_single(ndev->dev.parent,
718 skb_frag_address(frag), 722 skb_frag_address(frag),
719 frag_size(frag), DMA_TO_DEVICE); 723 skb_frag_size(frag), DMA_TO_DEVICE);
720 cur_p->len = frag_size(frag); 724 cur_p->len = skb_frag_size(frag);
721 cur_p->app0 = 0; 725 cur_p->app0 = 0;
722 frag++; 726 frag++;
723 } 727 }
@@ -860,6 +864,8 @@ static int temac_open(struct net_device *ndev)
860 phy_start(lp->phy_dev); 864 phy_start(lp->phy_dev);
861 } 865 }
862 866
867 temac_device_reset(ndev);
868
863 rc = request_irq(lp->tx_irq, ll_temac_tx_irq, 0, ndev->name, ndev); 869 rc = request_irq(lp->tx_irq, ll_temac_tx_irq, 0, ndev->name, ndev);
864 if (rc) 870 if (rc)
865 goto err_tx_irq; 871 goto err_tx_irq;
@@ -867,7 +873,6 @@ static int temac_open(struct net_device *ndev)
867 if (rc) 873 if (rc)
868 goto err_rx_irq; 874 goto err_rx_irq;
869 875
870 temac_device_reset(ndev);
871 return 0; 876 return 0;
872 877
873 err_rx_irq: 878 err_rx_irq:
diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index ec96d910e9a..f45c85a8426 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/hippi/Kconfig b/drivers/net/hippi/Kconfig
index 7393eb732ee..95eb34fdbba 100644
--- a/drivers/net/hippi/Kconfig
+++ b/drivers/net/hippi/Kconfig
@@ -36,4 +36,4 @@ config ROADRUNNER_LARGE_RINGS
36 kernel code or by user space programs. Say Y here only if you have 36 kernel code or by user space programs. Say Y here only if you have
37 the memory. 37 the memory.
38 38
39endif /* HIPPI */ 39endif # HIPPI
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index a40fab44b9a..d423d18b4ad 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/macvlan.c b/drivers/net/macvlan.c
index a3ce3d4561e..74134970b70 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -192,6 +192,13 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
192 */ 192 */
193 macvlan_broadcast(skb, port, src->dev, 193 macvlan_broadcast(skb, port, src->dev,
194 MACVLAN_MODE_VEPA); 194 MACVLAN_MODE_VEPA);
195 else {
196 /* forward to original port. */
197 vlan = src;
198 ret = macvlan_broadcast_one(skb, vlan, eth, 0);
199 goto out;
200 }
201
195 return RX_HANDLER_PASS; 202 return RX_HANDLER_PASS;
196 } 203 }
197 204
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index bb88e12101c..a70244306c9 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menuconfig PHYLIB 5menuconfig PHYLIB
6 bool "PHY Device support and infrastructure" 6 tristate "PHY Device support and infrastructure"
7 depends on !S390 7 depends on !S390
8 depends on NETDEVICES 8 depends on NETDEVICES
9 help 9 help
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index a4eae750a41..f414ffb5b72 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/usb/asix.c b/drivers/net/usb/asix.c
index e81e22e3d1d..e6fed4d4cb7 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -36,7 +36,7 @@
36#include <linux/usb/usbnet.h> 36#include <linux/usb/usbnet.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38 38
39#define DRIVER_VERSION "26-Sep-2011" 39#define DRIVER_VERSION "08-Nov-2011"
40#define DRIVER_NAME "asix" 40#define DRIVER_NAME "asix"
41 41
42/* ASIX AX8817X based USB 2.0 Ethernet Devices */ 42/* ASIX AX8817X based USB 2.0 Ethernet Devices */
@@ -163,7 +163,7 @@
163#define MARVELL_CTRL_TXDELAY 0x0002 163#define MARVELL_CTRL_TXDELAY 0x0002
164#define MARVELL_CTRL_RXDELAY 0x0080 164#define MARVELL_CTRL_RXDELAY 0x0080
165 165
166#define PHY_MODE_RTL8211CL 0x0004 166#define PHY_MODE_RTL8211CL 0x000C
167 167
168/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ 168/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
169struct asix_data { 169struct asix_data {
@@ -652,9 +652,17 @@ static u32 asix_get_phyid(struct usbnet *dev)
652{ 652{
653 int phy_reg; 653 int phy_reg;
654 u32 phy_id; 654 u32 phy_id;
655 int i;
655 656
656 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1); 657 /* Poll for the rare case the FW or phy isn't ready yet. */
657 if (phy_reg < 0) 658 for (i = 0; i < 100; i++) {
659 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
660 if (phy_reg != 0 && phy_reg != 0xFFFF)
661 break;
662 mdelay(1);
663 }
664
665 if (phy_reg <= 0 || phy_reg == 0xFFFF)
658 return 0; 666 return 0;
659 667
660 phy_id = (phy_reg & 0xffff) << 16; 668 phy_id = (phy_reg & 0xffff) << 16;
@@ -1075,7 +1083,7 @@ static const struct net_device_ops ax88772_netdev_ops = {
1075 1083
1076static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 1084static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
1077{ 1085{
1078 int ret; 1086 int ret, embd_phy;
1079 struct asix_data *data = (struct asix_data *)&dev->data; 1087 struct asix_data *data = (struct asix_data *)&dev->data;
1080 u8 buf[ETH_ALEN]; 1088 u8 buf[ETH_ALEN];
1081 u32 phyid; 1089 u32 phyid;
@@ -1100,16 +1108,36 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
1100 dev->mii.reg_num_mask = 0x1f; 1108 dev->mii.reg_num_mask = 0x1f;
1101 dev->mii.phy_id = asix_get_phy_addr(dev); 1109 dev->mii.phy_id = asix_get_phy_addr(dev);
1102 1110
1103 phyid = asix_get_phyid(dev);
1104 dbg("PHYID=0x%08x", phyid);
1105
1106 dev->net->netdev_ops = &ax88772_netdev_ops; 1111 dev->net->netdev_ops = &ax88772_netdev_ops;
1107 dev->net->ethtool_ops = &ax88772_ethtool_ops; 1112 dev->net->ethtool_ops = &ax88772_ethtool_ops;
1108 1113
1109 ret = ax88772_reset(dev); 1114 embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
1115
1116 /* Reset the PHY to normal operation mode */
1117 ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
1118 if (ret < 0) {
1119 dbg("Select PHY #1 failed: %d", ret);
1120 return ret;
1121 }
1122
1123 ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
1124 if (ret < 0)
1125 return ret;
1126
1127 msleep(150);
1128
1129 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
1110 if (ret < 0) 1130 if (ret < 0)
1111 return ret; 1131 return ret;
1112 1132
1133 msleep(150);
1134
1135 ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_PRTE);
1136
1137 /* Read PHYID register *AFTER* the PHY was reset properly */
1138 phyid = asix_get_phyid(dev);
1139 dbg("PHYID=0x%08x", phyid);
1140
1113 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ 1141 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1114 if (dev->driver_info->flags & FLAG_FRAMING_AX) { 1142 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1115 /* hard_mtu is still the default - the device does not support 1143 /* hard_mtu is still the default - the device does not support
@@ -1220,6 +1248,7 @@ static int ax88178_reset(struct usbnet *dev)
1220 __le16 eeprom; 1248 __le16 eeprom;
1221 u8 status; 1249 u8 status;
1222 int gpio0 = 0; 1250 int gpio0 = 0;
1251 u32 phyid;
1223 1252
1224 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status); 1253 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
1225 dbg("GPIO Status: 0x%04x", status); 1254 dbg("GPIO Status: 0x%04x", status);
@@ -1235,12 +1264,13 @@ static int ax88178_reset(struct usbnet *dev)
1235 data->ledmode = 0; 1264 data->ledmode = 0;
1236 gpio0 = 1; 1265 gpio0 = 1;
1237 } else { 1266 } else {
1238 data->phymode = le16_to_cpu(eeprom) & 7; 1267 data->phymode = le16_to_cpu(eeprom) & 0x7F;
1239 data->ledmode = le16_to_cpu(eeprom) >> 8; 1268 data->ledmode = le16_to_cpu(eeprom) >> 8;
1240 gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1; 1269 gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
1241 } 1270 }
1242 dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode); 1271 dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode);
1243 1272
1273 /* Power up external GigaPHY through AX88178 GPIO pin */
1244 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40); 1274 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
1245 if ((le16_to_cpu(eeprom) >> 8) != 1) { 1275 if ((le16_to_cpu(eeprom) >> 8) != 1) {
1246 asix_write_gpio(dev, 0x003c, 30); 1276 asix_write_gpio(dev, 0x003c, 30);
@@ -1252,6 +1282,13 @@ static int ax88178_reset(struct usbnet *dev)
1252 asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30); 1282 asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
1253 } 1283 }
1254 1284
1285 /* Read PHYID register *AFTER* powering up PHY */
1286 phyid = asix_get_phyid(dev);
1287 dbg("PHYID=0x%08x", phyid);
1288
1289 /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
1290 asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL);
1291
1255 asix_sw_reset(dev, 0); 1292 asix_sw_reset(dev, 0);
1256 msleep(150); 1293 msleep(150);
1257 1294
@@ -1396,7 +1433,6 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1396{ 1433{
1397 int ret; 1434 int ret;
1398 u8 buf[ETH_ALEN]; 1435 u8 buf[ETH_ALEN];
1399 u32 phyid;
1400 struct asix_data *data = (struct asix_data *)&dev->data; 1436 struct asix_data *data = (struct asix_data *)&dev->data;
1401 1437
1402 data->eeprom_len = AX88772_EEPROM_LEN; 1438 data->eeprom_len = AX88772_EEPROM_LEN;
@@ -1423,12 +1459,12 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1423 dev->net->netdev_ops = &ax88178_netdev_ops; 1459 dev->net->netdev_ops = &ax88178_netdev_ops;
1424 dev->net->ethtool_ops = &ax88178_ethtool_ops; 1460 dev->net->ethtool_ops = &ax88178_ethtool_ops;
1425 1461
1426 phyid = asix_get_phyid(dev); 1462 /* Blink LEDS so users know driver saw dongle */
1427 dbg("PHYID=0x%08x", phyid); 1463 asix_sw_reset(dev, 0);
1464 msleep(150);
1428 1465
1429 ret = ax88178_reset(dev); 1466 asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1430 if (ret < 0) 1467 msleep(150);
1431 return ret;
1432 1468
1433 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ 1469 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1434 if (dev->driver_info->flags & FLAG_FRAMING_AX) { 1470 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index c924ea2bce0..99ed6eb4dfa 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -567,7 +567,7 @@ static const struct usb_device_id products [] = {
567{ 567{
568 USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM, 568 USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM,
569 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE), 569 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
570 .driver_info = (unsigned long)&wwan_info, 570 .driver_info = 0,
571}, 571},
572 572
573/* 573/*
diff --git a/drivers/net/usb/lg-vl600.c b/drivers/net/usb/lg-vl600.c
index 1e722195105..9c26c6390d6 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
@@ -143,10 +144,11 @@ static int vl600_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
143 } 144 }
144 145
145 frame = (struct vl600_frame_hdr *) buf->data; 146 frame = (struct vl600_frame_hdr *) buf->data;
146 /* NOTE: Should check that frame->magic == 0x53544448? 147 /* Yes, check that frame->magic == 0x53544448 (or 0x44544d48),
147 * Otherwise if we receive garbage at the beginning of the frame 148 * otherwise we may run out of memory w/a bad packet */
148 * we may end up allocating a huge buffer and saving all the 149 if (ntohl(frame->magic) != 0x53544448 &&
149 * future incoming data into it. */ 150 ntohl(frame->magic) != 0x44544d48)
151 goto error;
150 152
151 if (buf->len < sizeof(*frame) || 153 if (buf->len < sizeof(*frame) ||
152 buf->len != le32_to_cpup(&frame->len)) { 154 buf->len != le32_to_cpup(&frame->len)) {
@@ -295,6 +297,11 @@ encapsulate:
295 * overwrite the remaining fields. 297 * overwrite the remaining fields.
296 */ 298 */
297 packet = (struct vl600_pkt_hdr *) skb->data; 299 packet = (struct vl600_pkt_hdr *) skb->data;
300 /* The VL600 wants IPv6 packets to have an IPv4 ethertype
301 * Since this modem only supports IPv4 and IPv6, just set all
302 * frames to 0x0800 (ETH_P_IP)
303 */
304 packet->h_proto = htons(ETH_P_IP);
298 memset(&packet->dummy, 0, sizeof(packet->dummy)); 305 memset(&packet->dummy, 0, sizeof(packet->dummy));
299 packet->len = cpu_to_le32(orig_len); 306 packet->len = cpu_to_le32(orig_len);
300 307
@@ -307,21 +314,12 @@ encapsulate:
307 if (skb->len < full_len) /* Pad */ 314 if (skb->len < full_len) /* Pad */
308 skb_put(skb, full_len - skb->len); 315 skb_put(skb, full_len - skb->len);
309 316
310 /* The VL600 wants IPv6 packets to have an IPv4 ethertype
311 * Check if this is an IPv6 packet, and set the ethertype
312 * to 0x800
313 */
314 if ((skb->data[sizeof(struct vl600_pkt_hdr *) + 0x22] & 0xf0) == 0x60) {
315 skb->data[sizeof(struct vl600_pkt_hdr *) + 0x20] = 0x08;
316 skb->data[sizeof(struct vl600_pkt_hdr *) + 0x21] = 0;
317 }
318
319 return skb; 317 return skb;
320} 318}
321 319
322static const struct driver_info vl600_info = { 320static const struct driver_info vl600_info = {
323 .description = "LG VL600 modem", 321 .description = "LG VL600 modem",
324 .flags = FLAG_ETHER | FLAG_RX_ASSEMBLE, 322 .flags = FLAG_RX_ASSEMBLE | FLAG_WWAN,
325 .bind = vl600_bind, 323 .bind = vl600_bind,
326 .unbind = vl600_unbind, 324 .unbind = vl600_unbind,
327 .status = usbnet_cdc_status, 325 .status = usbnet_cdc_status,
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 22a7cf951e7..a5b9b12ef26 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -51,6 +51,7 @@
51#define USB_VENDOR_ID_SMSC (0x0424) 51#define USB_VENDOR_ID_SMSC (0x0424)
52#define USB_PRODUCT_ID_LAN7500 (0x7500) 52#define USB_PRODUCT_ID_LAN7500 (0x7500)
53#define USB_PRODUCT_ID_LAN7505 (0x7505) 53#define USB_PRODUCT_ID_LAN7505 (0x7505)
54#define RXW_PADDING 2
54 55
55#define check_warn(ret, fmt, args...) \ 56#define check_warn(ret, fmt, args...) \
56 ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); }) 57 ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); })
@@ -1088,13 +1089,13 @@ static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1088 1089
1089 memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b)); 1090 memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
1090 le32_to_cpus(&rx_cmd_b); 1091 le32_to_cpus(&rx_cmd_b);
1091 skb_pull(skb, 4 + NET_IP_ALIGN); 1092 skb_pull(skb, 4 + RXW_PADDING);
1092 1093
1093 packet = skb->data; 1094 packet = skb->data;
1094 1095
1095 /* get the packet length */ 1096 /* get the packet length */
1096 size = (rx_cmd_a & RX_CMD_A_LEN) - NET_IP_ALIGN; 1097 size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
1097 align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 1098 align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
1098 1099
1099 if (unlikely(rx_cmd_a & RX_CMD_A_RED)) { 1100 if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
1100 netif_dbg(dev, rx_err, dev->net, 1101 netif_dbg(dev, rx_err, dev->net,
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 7d6082160bc..fae0fbd8bc8 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1057,7 +1057,8 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1057 unsigned long flags; 1057 unsigned long flags;
1058 int retval; 1058 int retval;
1059 1059
1060 skb_tx_timestamp(skb); 1060 if (skb)
1061 skb_tx_timestamp(skb);
1061 1062
1062 // some devices want funky USB-level framing, for 1063 // some devices want funky USB-level framing, for
1063 // win32 driver (usually) and/or hardware quirks 1064 // win32 driver (usually) and/or hardware quirks
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 5b23767ea81..ef883e97cee 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/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index b771ebac0f0..d96bfb1ac20 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 727d728649b..2fea02b35b2 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 9c70b5fa3f5..129ba36bd04 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 85dadd5bf4b..7cbd7d231e1 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 2edd8fe1c1f..64a110604ad 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 2f94a872101..37becfcc98f 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 be428cae28d..21a9edd6e75 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 4b30ed11d78..4b9ecb20dee 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 9a644d052f1..2c1b8b68764 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 3b752d9fb3c..f5ce5623da9 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/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
index fce8c904eea..8c5ce8b0c73 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 c1dff2ced04..dfa48eb7d95 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 3aff36bad5d..f517eb8f7b4 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 ba3f23d7115..7879b531428 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 f1dc311ee0c..066d4f88807 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 85a54cd2b08..5e47ca6d16a 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 2776c3c1f50..a639b94f764 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_calib.c b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
index e0ab0657cc3..88279e325dc 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
@@ -868,10 +868,6 @@ static bool ar9002_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
868 /* Do PA Calibration */ 868 /* Do PA Calibration */
869 ar9002_hw_pa_cal(ah, true); 869 ar9002_hw_pa_cal(ah, true);
870 870
871 /* Do NF Calibration after DC offset and other calibrations */
872 ath9k_hw_loadnf(ah, chan);
873 ath9k_hw_start_nfcal(ah, true);
874
875 if (ah->caldata) 871 if (ah->caldata)
876 ah->caldata->nfcal_pending = true; 872 ah->caldata->nfcal_pending = true;
877 873
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_hw.c b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
index 626d547d2f0..11f192a1ceb 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 f7d8e516a2a..b5920168606 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_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index 16851cb109a..12a730dcb50 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -908,12 +908,15 @@ static bool ar9003_hw_rtt_restore(struct ath_hw *ah, struct ath9k_channel *chan)
908 int i; 908 int i;
909 bool restore; 909 bool restore;
910 910
911 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_RTT) || !ah->caldata) 911 if (!ah->caldata)
912 return false; 912 return false;
913 913
914 hist = &ah->caldata->rtt_hist; 914 hist = &ah->caldata->rtt_hist;
915 if (!hist->num_readings)
916 return false;
917
915 ar9003_hw_rtt_enable(ah); 918 ar9003_hw_rtt_enable(ah);
916 ar9003_hw_rtt_set_mask(ah, 0x10); 919 ar9003_hw_rtt_set_mask(ah, 0x00);
917 for (i = 0; i < AR9300_MAX_CHAINS; i++) { 920 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
918 if (!(ah->rxchainmask & (1 << i))) 921 if (!(ah->rxchainmask & (1 << i)))
919 continue; 922 continue;
@@ -1070,6 +1073,7 @@ skip_tx_iqcal:
1070 if (is_reusable && (hist->num_readings < RTT_HIST_MAX)) { 1073 if (is_reusable && (hist->num_readings < RTT_HIST_MAX)) {
1071 u32 *table; 1074 u32 *table;
1072 1075
1076 hist->num_readings++;
1073 for (i = 0; i < AR9300_MAX_CHAINS; i++) { 1077 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
1074 if (!(ah->rxchainmask & (1 << i))) 1078 if (!(ah->rxchainmask & (1 << i)))
1075 continue; 1079 continue;
@@ -1081,9 +1085,6 @@ skip_tx_iqcal:
1081 ar9003_hw_rtt_disable(ah); 1085 ar9003_hw_rtt_disable(ah);
1082 } 1086 }
1083 1087
1084 ath9k_hw_loadnf(ah, chan);
1085 ath9k_hw_start_nfcal(ah, true);
1086
1087 /* Initialize list pointers */ 1088 /* Initialize list pointers */
1088 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; 1089 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
1089 ah->supp_cals = IQ_MISMATCH_CAL; 1090 ah->supp_cals = IQ_MISMATCH_CAL;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
index b363cc06cfd..ccde784a842 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 0c462c904cb..a4450cba065 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 fe96997921d..2330e7ede19 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/ar9003_phy.h b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
index 2f4023e6608..4114fe752c6 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
@@ -572,14 +572,14 @@
572 572
573#define AR_PHY_TXGAIN_TABLE (AR_SM_BASE + 0x300) 573#define AR_PHY_TXGAIN_TABLE (AR_SM_BASE + 0x300)
574 574
575#define AR_PHY_TX_IQCAL_CONTROL_0 (AR_SM_BASE + AR_SREV_9485(ah) ? \ 575#define AR_PHY_TX_IQCAL_CONTROL_0 (AR_SM_BASE + (AR_SREV_9485(ah) ? \
576 0x3c4 : 0x444) 576 0x3c4 : 0x444))
577#define AR_PHY_TX_IQCAL_CONTROL_1 (AR_SM_BASE + AR_SREV_9485(ah) ? \ 577#define AR_PHY_TX_IQCAL_CONTROL_1 (AR_SM_BASE + (AR_SREV_9485(ah) ? \
578 0x3c8 : 0x448) 578 0x3c8 : 0x448))
579#define AR_PHY_TX_IQCAL_START (AR_SM_BASE + AR_SREV_9485(ah) ? \ 579#define AR_PHY_TX_IQCAL_START (AR_SM_BASE + (AR_SREV_9485(ah) ? \
580 0x3c4 : 0x440) 580 0x3c4 : 0x440))
581#define AR_PHY_TX_IQCAL_STATUS_B0 (AR_SM_BASE + AR_SREV_9485(ah) ? \ 581#define AR_PHY_TX_IQCAL_STATUS_B0 (AR_SM_BASE + (AR_SREV_9485(ah) ? \
582 0x3f0 : 0x48c) 582 0x3f0 : 0x48c))
583#define AR_PHY_TX_IQCAL_CORR_COEFF_B0(_i) (AR_SM_BASE + \ 583#define AR_PHY_TX_IQCAL_CORR_COEFF_B0(_i) (AR_SM_BASE + \
584 (AR_SREV_9485(ah) ? \ 584 (AR_SREV_9485(ah) ? \
585 0x3d0 : 0x450) + ((_i) << 2)) 585 0x3d0 : 0x450) + ((_i) << 2))
@@ -651,7 +651,7 @@
651#define AR_SWITCH_TABLE_ALL_S (0) 651#define AR_SWITCH_TABLE_ALL_S (0)
652 652
653#define AR_PHY_65NM_CH0_THERM (AR_SREV_9300(ah) ? 0x16290 :\ 653#define AR_PHY_65NM_CH0_THERM (AR_SREV_9300(ah) ? 0x16290 :\
654 (AR_SREV_9485(ah) ? 0x1628c : 0x16294)) 654 (AR_SREV_9462(ah) ? 0x16294 : 0x1628c))
655 655
656#define AR_PHY_65NM_CH0_THERM_LOCAL 0x80000000 656#define AR_PHY_65NM_CH0_THERM_LOCAL 0x80000000
657#define AR_PHY_65NM_CH0_THERM_LOCAL_S 31 657#define AR_PHY_65NM_CH0_THERM_LOCAL_S 31
@@ -668,12 +668,12 @@
668#define AR_PHY_65NM_CH2_RXTX2 0x16904 668#define AR_PHY_65NM_CH2_RXTX2 0x16904
669 669
670#define AR_CH0_TOP2 (AR_SREV_9300(ah) ? 0x1628c : \ 670#define AR_CH0_TOP2 (AR_SREV_9300(ah) ? 0x1628c : \
671 (AR_SREV_9485(ah) ? 0x16284 : 0x16290)) 671 (AR_SREV_9462(ah) ? 0x16290 : 0x16284))
672#define AR_CH0_TOP2_XPABIASLVL 0xf000 672#define AR_CH0_TOP2_XPABIASLVL 0xf000
673#define AR_CH0_TOP2_XPABIASLVL_S 12 673#define AR_CH0_TOP2_XPABIASLVL_S 12
674 674
675#define AR_CH0_XTAL (AR_SREV_9300(ah) ? 0x16294 : \ 675#define AR_CH0_XTAL (AR_SREV_9300(ah) ? 0x16294 : \
676 (AR_SREV_9485(ah) ? 0x16290 : 0x16298)) 676 (AR_SREV_9462(ah) ? 0x16298 : 0x16290))
677#define AR_CH0_XTAL_CAPINDAC 0x7f000000 677#define AR_CH0_XTAL_CAPINDAC 0x7f000000
678#define AR_CH0_XTAL_CAPINDAC_S 24 678#define AR_CH0_XTAL_CAPINDAC_S 24
679#define AR_CH0_XTAL_CAPOUTDAC 0x00fe0000 679#define AR_CH0_XTAL_CAPOUTDAC 0x00fe0000
@@ -908,8 +908,8 @@
908#define AR_PHY_TPC_5_B1 (AR_SM1_BASE + 0x208) 908#define AR_PHY_TPC_5_B1 (AR_SM1_BASE + 0x208)
909#define AR_PHY_TPC_6_B1 (AR_SM1_BASE + 0x20c) 909#define AR_PHY_TPC_6_B1 (AR_SM1_BASE + 0x20c)
910#define AR_PHY_TPC_11_B1 (AR_SM1_BASE + 0x220) 910#define AR_PHY_TPC_11_B1 (AR_SM1_BASE + 0x220)
911#define AR_PHY_PDADC_TAB_1 (AR_SM1_BASE + (AR_SREV_AR9300(ah) ? \ 911#define AR_PHY_PDADC_TAB_1 (AR_SM1_BASE + (AR_SREV_AR9462(ah) ? \
912 0x240 : 0x280)) 912 0x280 : 0x240))
913#define AR_PHY_TPC_19_B1 (AR_SM1_BASE + 0x240) 913#define AR_PHY_TPC_19_B1 (AR_SM1_BASE + 0x240)
914#define AR_PHY_TPC_19_B1_ALPHA_THERM 0xff 914#define AR_PHY_TPC_19_B1_ALPHA_THERM 0xff
915#define AR_PHY_TPC_19_B1_ALPHA_THERM_S 0 915#define AR_PHY_TPC_19_B1_ALPHA_THERM_S 0
@@ -931,10 +931,10 @@
931#define AR_PHY_AIC_SRAM_ADDR_B1 (AR_SM1_BASE + 0x5f0) 931#define AR_PHY_AIC_SRAM_ADDR_B1 (AR_SM1_BASE + 0x5f0)
932#define AR_PHY_AIC_SRAM_DATA_B1 (AR_SM1_BASE + 0x5f4) 932#define AR_PHY_AIC_SRAM_DATA_B1 (AR_SM1_BASE + 0x5f4)
933 933
934#define AR_PHY_RTT_TABLE_SW_INTF_B(i) (0x384 + (i) ? \ 934#define AR_PHY_RTT_TABLE_SW_INTF_B(i) (0x384 + ((i) ? \
935 AR_SM1_BASE : AR_SM_BASE) 935 AR_SM1_BASE : AR_SM_BASE))
936#define AR_PHY_RTT_TABLE_SW_INTF_1_B(i) (0x388 + (i) ? \ 936#define AR_PHY_RTT_TABLE_SW_INTF_1_B(i) (0x388 + ((i) ? \
937 AR_SM1_BASE : AR_SM_BASE) 937 AR_SM1_BASE : AR_SM_BASE))
938/* 938/*
939 * Channel 2 Register Map 939 * Channel 2 Register Map
940 */ 940 */
diff --git a/drivers/net/wireless/ath/ath9k/ar9485_initvals.h b/drivers/net/wireless/ath/ath9k/ar9485_initvals.h
index 611ea6ce850..d16d029f81a 100644
--- a/drivers/net/wireless/ath/ath9k/ar9485_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9485_initvals.h
@@ -521,7 +521,7 @@ static const u32 ar9485_1_1_radio_postamble[][2] = {
521 {0x000160ac, 0x24611800}, 521 {0x000160ac, 0x24611800},
522 {0x000160b0, 0x03284f3e}, 522 {0x000160b0, 0x03284f3e},
523 {0x0001610c, 0x00170000}, 523 {0x0001610c, 0x00170000},
524 {0x00016140, 0x10804008}, 524 {0x00016140, 0x50804008},
525}; 525};
526 526
527static const u32 ar9485_1_1_mac_postamble[][5] = { 527static const u32 ar9485_1_1_mac_postamble[][5] = {
@@ -603,7 +603,7 @@ static const u32 ar9485_1_1_radio_core[][2] = {
603 603
604static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_enable_L1[][2] = { 604static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_enable_L1[][2] = {
605 /* Addr allmodes */ 605 /* Addr allmodes */
606 {0x00018c00, 0x10052e5e}, 606 {0x00018c00, 0x18052e5e},
607 {0x00018c04, 0x000801d8}, 607 {0x00018c04, 0x000801d8},
608 {0x00018c08, 0x0000080c}, 608 {0x00018c08, 0x0000080c},
609}; 609};
@@ -776,7 +776,7 @@ static const u32 ar9485_modes_green_ob_db_tx_gain_1_1[][5] = {
776 776
777static const u32 ar9485_1_1_pcie_phy_clkreq_disable_L1[][2] = { 777static const u32 ar9485_1_1_pcie_phy_clkreq_disable_L1[][2] = {
778 /* Addr allmodes */ 778 /* Addr allmodes */
779 {0x00018c00, 0x10013e5e}, 779 {0x00018c00, 0x18013e5e},
780 {0x00018c04, 0x000801d8}, 780 {0x00018c04, 0x000801d8},
781 {0x00018c08, 0x0000080c}, 781 {0x00018c08, 0x0000080c},
782}; 782};
@@ -882,7 +882,7 @@ static const u32 ar9485_fast_clock_1_1_baseband_postamble[][3] = {
882 882
883static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = { 883static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = {
884 /* Addr allmodes */ 884 /* Addr allmodes */
885 {0x00018c00, 0x10012e5e}, 885 {0x00018c00, 0x18012e5e},
886 {0x00018c04, 0x000801d8}, 886 {0x00018c04, 0x000801d8},
887 {0x00018c08, 0x0000080c}, 887 {0x00018c08, 0x0000080c},
888}; 888};
@@ -1021,7 +1021,7 @@ static const u32 ar9485_common_rx_gain_1_1[][2] = {
1021 1021
1022static const u32 ar9485_1_1_pcie_phy_clkreq_enable_L1[][2] = { 1022static const u32 ar9485_1_1_pcie_phy_clkreq_enable_L1[][2] = {
1023 /* Addr allmodes */ 1023 /* Addr allmodes */
1024 {0x00018c00, 0x10053e5e}, 1024 {0x00018c00, 0x18053e5e},
1025 {0x00018c04, 0x000801d8}, 1025 {0x00018c04, 0x000801d8},
1026 {0x00018c08, 0x0000080c}, 1026 {0x00018c08, 0x0000080c},
1027}; 1027};
diff --git a/drivers/net/wireless/ath/ath9k/btcoex.c b/drivers/net/wireless/ath/ath9k/btcoex.c
index 6635c377dc0..012263968d6 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 ebaf304f464..99538810a31 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 327aa28f603..2741203e803 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 f16d2033081..8873c6e6fb9 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"
@@ -1724,6 +1725,9 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1724 if (!ath9k_hw_init_cal(ah, chan)) 1725 if (!ath9k_hw_init_cal(ah, chan))
1725 return -EIO; 1726 return -EIO;
1726 1727
1728 ath9k_hw_loadnf(ah, chan);
1729 ath9k_hw_start_nfcal(ah, true);
1730
1727 ENABLE_REGWRITE_BUFFER(ah); 1731 ENABLE_REGWRITE_BUFFER(ah);
1728 1732
1729 ath9k_hw_restore_chainmask(ah); 1733 ath9k_hw_restore_chainmask(ah);
@@ -1823,7 +1827,8 @@ static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
1823 } 1827 }
1824 1828
1825 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */ 1829 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
1826 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE); 1830 if (AR_SREV_9300_20_OR_LATER(ah))
1831 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
1827} 1832}
1828 1833
1829/* 1834/*
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index af1b3254953..d4c909f8e47 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 6a8fdf33a52..ecdb6fd2907 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 edb0b4b3da3..2dcdf63cb39 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 8448281dd06..888abc2be3a 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 f4cae1cccbf..cba9d0435dc 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/carl9170/tx.c b/drivers/net/wireless/ath/carl9170/tx.c
index d20946939cd..59472e1605c 100644
--- a/drivers/net/wireless/ath/carl9170/tx.c
+++ b/drivers/net/wireless/ath/carl9170/tx.c
@@ -296,7 +296,8 @@ static void carl9170_tx_release(struct kref *ref)
296 super = (void *)skb->data; 296 super = (void *)skb->data;
297 txinfo->status.ampdu_len = super->s.rix; 297 txinfo->status.ampdu_len = super->s.rix;
298 txinfo->status.ampdu_ack_len = super->s.cnt; 298 txinfo->status.ampdu_ack_len = super->s.cnt;
299 } else if (txinfo->flags & IEEE80211_TX_STAT_ACK) { 299 } else if ((txinfo->flags & IEEE80211_TX_STAT_ACK) &&
300 !(txinfo->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)) {
300 /* 301 /*
301 * drop redundant tx_status reports: 302 * drop redundant tx_status reports:
302 * 303 *
@@ -308,15 +309,17 @@ static void carl9170_tx_release(struct kref *ref)
308 * 309 *
309 * 3. minstrel_ht is picky, it only accepts 310 * 3. minstrel_ht is picky, it only accepts
310 * reports of frames with the TX_STATUS_AMPDU flag. 311 * reports of frames with the TX_STATUS_AMPDU flag.
312 *
313 * 4. mac80211 is not particularly interested in
314 * feedback either [CTL_REQ_TX_STATUS not set]
311 */ 315 */
312 316
313 dev_kfree_skb_any(skb); 317 dev_kfree_skb_any(skb);
314 return; 318 return;
315 } else { 319 } else {
316 /* 320 /*
317 * Frame has failed, but we want to keep it in 321 * Either the frame transmission has failed or
318 * case it was lost due to a power-state 322 * mac80211 requested tx status.
319 * transition.
320 */ 323 */
321 } 324 }
322 } 325 }
diff --git a/drivers/net/wireless/ath/debug.c b/drivers/net/wireless/ath/debug.c
index 5367b1086e0..508eccf5d98 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 3f508e59f14..19befb33107 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 17b0efd86f9..4cf7c5eb481 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 028310f263c..65ecb5bab25 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"
@@ -253,6 +254,8 @@ ath_reg_apply_active_scan_flags(struct wiphy *wiphy,
253 int r; 254 int r;
254 255
255 sband = wiphy->bands[IEEE80211_BAND_2GHZ]; 256 sband = wiphy->bands[IEEE80211_BAND_2GHZ];
257 if (!sband)
258 return;
256 259
257 /* 260 /*
258 * If no country IE has been received always enable active scan 261 * If no country IE has been received always enable active scan
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 7cf4125a162..5634d9a9965 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 12b6b4067a3..714cad649c4 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/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
index c73e8600d21..5f77cbe0b6a 100644
--- a/drivers/net/wireless/b43/xmit.c
+++ b/drivers/net/wireless/b43/xmit.c
@@ -175,6 +175,7 @@ void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
175 } 175 }
176} 176}
177 177
178/* TODO: verify if needed for SSLPN or LCN */
178static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate) 179static u16 b43_generate_tx_phy_ctl1(struct b43_wldev *dev, u8 bitrate)
179{ 180{
180 const struct b43_phy *phy = &dev->phy; 181 const struct b43_phy *phy = &dev->phy;
@@ -256,6 +257,9 @@ int b43_generate_txhdr(struct b43_wldev *dev,
256 unsigned int plcp_fragment_len; 257 unsigned int plcp_fragment_len;
257 u32 mac_ctl = 0; 258 u32 mac_ctl = 0;
258 u16 phy_ctl = 0; 259 u16 phy_ctl = 0;
260 bool fill_phy_ctl1 = (phy->type == B43_PHYTYPE_LP ||
261 phy->type == B43_PHYTYPE_N ||
262 phy->type == B43_PHYTYPE_HT);
259 u8 extra_ft = 0; 263 u8 extra_ft = 0;
260 struct ieee80211_rate *txrate; 264 struct ieee80211_rate *txrate;
261 struct ieee80211_tx_rate *rates; 265 struct ieee80211_tx_rate *rates;
@@ -531,7 +535,7 @@ int b43_generate_txhdr(struct b43_wldev *dev,
531 extra_ft |= B43_TXH_EFT_RTSFB_CCK; 535 extra_ft |= B43_TXH_EFT_RTSFB_CCK;
532 536
533 if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS && 537 if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS &&
534 phy->type == B43_PHYTYPE_N) { 538 fill_phy_ctl1) {
535 txhdr->phy_ctl1_rts = cpu_to_le16( 539 txhdr->phy_ctl1_rts = cpu_to_le16(
536 b43_generate_tx_phy_ctl1(dev, rts_rate)); 540 b43_generate_tx_phy_ctl1(dev, rts_rate));
537 txhdr->phy_ctl1_rts_fb = cpu_to_le16( 541 txhdr->phy_ctl1_rts_fb = cpu_to_le16(
@@ -552,7 +556,7 @@ int b43_generate_txhdr(struct b43_wldev *dev,
552 break; 556 break;
553 } 557 }
554 558
555 if (phy->type == B43_PHYTYPE_N) { 559 if (fill_phy_ctl1) {
556 txhdr->phy_ctl1 = 560 txhdr->phy_ctl1 =
557 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate)); 561 cpu_to_le16(b43_generate_tx_phy_ctl1(dev, rate));
558 txhdr->phy_ctl1_fb = 562 txhdr->phy_ctl1_fb =
@@ -736,7 +740,14 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
736 740
737 /* Link quality statistics */ 741 /* Link quality statistics */
738 switch (chanstat & B43_RX_CHAN_PHYTYPE) { 742 switch (chanstat & B43_RX_CHAN_PHYTYPE) {
743 case B43_PHYTYPE_HT:
744 /* TODO: is max the right choice? */
745 status.signal = max_t(__s8,
746 max(rxhdr->phy_ht_power0, rxhdr->phy_ht_power1),
747 rxhdr->phy_ht_power2);
748 break;
739 case B43_PHYTYPE_N: 749 case B43_PHYTYPE_N:
750 /* Broadcom has code for min and avg, but always uses max */
740 if (rxhdr->power0 == 16 || rxhdr->power0 == 32) 751 if (rxhdr->power0 == 16 || rxhdr->power0 == 32)
741 status.signal = max(rxhdr->power1, rxhdr->power2); 752 status.signal = max(rxhdr->power1, rxhdr->power2);
742 else 753 else
@@ -827,7 +838,6 @@ void b43_rx(struct b43_wldev *dev, struct sk_buff *skb, const void *_rxhdr)
827#endif 838#endif
828 return; 839 return;
829drop: 840drop:
830 b43dbg(dev->wl, "RX: Packet dropped\n");
831 dev_kfree_skb_any(skb); 841 dev_kfree_skb_any(skb);
832} 842}
833 843
diff --git a/drivers/net/wireless/b43/xmit.h b/drivers/net/wireless/b43/xmit.h
index 16c514d54af..98d90747836 100644
--- a/drivers/net/wireless/b43/xmit.h
+++ b/drivers/net/wireless/b43/xmit.h
@@ -249,6 +249,12 @@ struct b43_rxhdr_fw4 {
249 } __packed; 249 } __packed;
250 } __packed; 250 } __packed;
251 union { 251 union {
252 /* HT-PHY */
253 struct {
254 PAD_BYTES(1);
255 __s8 phy_ht_power0;
256 } __packed;
257
252 /* RSSI for N-PHYs */ 258 /* RSSI for N-PHYs */
253 struct { 259 struct {
254 __s8 power2; 260 __s8 power2;
@@ -257,7 +263,15 @@ struct b43_rxhdr_fw4 {
257 263
258 __le16 phy_status2; /* PHY RX Status 2 */ 264 __le16 phy_status2; /* PHY RX Status 2 */
259 } __packed; 265 } __packed;
260 __le16 phy_status3; /* PHY RX Status 3 */ 266 union {
267 /* HT-PHY */
268 struct {
269 __s8 phy_ht_power1;
270 __s8 phy_ht_power2;
271 } __packed;
272
273 __le16 phy_status3; /* PHY RX Status 3 */
274 } __packed;
261 union { 275 union {
262 /* Tested with 598.314, 644.1001 and 666.2 */ 276 /* Tested with 598.314, 644.1001 and 666.2 */
263 struct { 277 struct {
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index a3b72cd72c6..20f02437af8 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 bff9dcd6fad..89ff94da556 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/dma.c b/drivers/net/wireless/brcm80211/brcmsmac/dma.c
index b56a30297c2..6ebec8f4284 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/dma.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/dma.c
@@ -358,13 +358,14 @@ static uint nrxdactive(struct dma_info *di, uint h, uint t)
358 358
359static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags) 359static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags)
360{ 360{
361 uint dmactrlflags = di->dma.dmactrlflags; 361 uint dmactrlflags;
362 362
363 if (di == NULL) { 363 if (di == NULL) {
364 DMA_ERROR(("%s: _dma_ctrlflags: NULL dma handle\n", di->name)); 364 DMA_ERROR(("_dma_ctrlflags: NULL dma handle\n"));
365 return 0; 365 return 0;
366 } 366 }
367 367
368 dmactrlflags = di->dma.dmactrlflags;
368 dmactrlflags &= ~mask; 369 dmactrlflags &= ~mask;
369 dmactrlflags |= flags; 370 dmactrlflags |= flags;
370 371
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
index ac8d02bd34f..0d8a9cdf897 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 e0b3e8d406b..df7050abe71 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 c34a3b7f129..344a981a052 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 3d05dc15c6b..e1f41027724 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 d737091cf6a..47932b28aac 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 12de46407c7..045a93645a3 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 005ff25a405..75ef8f04aab 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 996996a7165..1407dca70de 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 9b5d0abe8be..f4d21ec2249 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 a6b5222fc59..521b73b527d 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 66f0fb2bbe0..f10df3e2813 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 ef9e268bf8a..c0dfb1a4e96 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-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index b247a56d513..001fdf140ab 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -1755,16 +1755,6 @@ static inline int iwl_check_stuck_queue(struct iwl_priv *priv, int txq)
1755{ 1755{
1756 if (iwl_trans_check_stuck_queue(trans(priv), txq)) { 1756 if (iwl_trans_check_stuck_queue(trans(priv), txq)) {
1757 int ret; 1757 int ret;
1758 if (txq == priv->shrd->cmd_queue) {
1759 /*
1760 * validate command queue still working
1761 * by sending "ECHO" command
1762 */
1763 if (!iwl_cmd_echo_test(priv))
1764 return 0;
1765 else
1766 IWL_DEBUG_HC(priv, "echo testing fail\n");
1767 }
1768 ret = iwl_force_reset(priv, IWL_FW_RESET, false); 1758 ret = iwl_force_reset(priv, IWL_FW_RESET, false);
1769 return (ret == -EAGAIN) ? 0 : 1; 1759 return (ret == -EAGAIN) ? 0 : 1;
1770 } 1760 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-pci.c b/drivers/net/wireless/iwlwifi/iwl-pci.c
index 3b6cc66365e..1800029911a 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
@@ -445,10 +446,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
445 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); 446 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
446 447
447 err = pci_enable_msi(pdev); 448 err = pci_enable_msi(pdev);
448 if (err) { 449 if (err)
449 dev_printk(KERN_ERR, &pdev->dev, "pci_enable_msi failed"); 450 dev_printk(KERN_ERR, &pdev->dev,
450 goto out_iounmap; 451 "pci_enable_msi failed(0X%x)", err);
451 }
452 452
453 /* TODO: Move this away, not needed if not MSI */ 453 /* TODO: Move this away, not needed if not MSI */
454 /* enable rfkill interrupt: hw bug w/a */ 454 /* enable rfkill interrupt: hw bug w/a */
@@ -469,7 +469,6 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
469 469
470out_disable_msi: 470out_disable_msi:
471 pci_disable_msi(pdev); 471 pci_disable_msi(pdev);
472out_iounmap:
473 pci_iounmap(pdev, pci_bus->hw_base); 472 pci_iounmap(pdev, pci_bus->hw_base);
474out_pci_release_regions: 473out_pci_release_regions:
475 pci_set_drvdata(pdev, NULL); 474 pci_set_drvdata(pdev, NULL);
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
index 8e8c75c997e..ce918980e97 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
+++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
@@ -407,6 +407,7 @@ static void iwl_tx_queue_unmap(struct iwl_trans *trans, int txq_id)
407 struct iwl_queue *q = &txq->q; 407 struct iwl_queue *q = &txq->q;
408 enum dma_data_direction dma_dir; 408 enum dma_data_direction dma_dir;
409 unsigned long flags; 409 unsigned long flags;
410 spinlock_t *lock;
410 411
411 if (!q->n_bd) 412 if (!q->n_bd)
412 return; 413 return;
@@ -414,19 +415,22 @@ static void iwl_tx_queue_unmap(struct iwl_trans *trans, int txq_id)
414 /* In the command queue, all the TBs are mapped as BIDI 415 /* In the command queue, all the TBs are mapped as BIDI
415 * so unmap them as such. 416 * so unmap them as such.
416 */ 417 */
417 if (txq_id == trans->shrd->cmd_queue) 418 if (txq_id == trans->shrd->cmd_queue) {
418 dma_dir = DMA_BIDIRECTIONAL; 419 dma_dir = DMA_BIDIRECTIONAL;
419 else 420 lock = &trans->hcmd_lock;
421 } else {
420 dma_dir = DMA_TO_DEVICE; 422 dma_dir = DMA_TO_DEVICE;
423 lock = &trans->shrd->sta_lock;
424 }
421 425
422 spin_lock_irqsave(&trans->shrd->sta_lock, flags); 426 spin_lock_irqsave(lock, flags);
423 while (q->write_ptr != q->read_ptr) { 427 while (q->write_ptr != q->read_ptr) {
424 /* The read_ptr needs to bound by q->n_window */ 428 /* The read_ptr needs to bound by q->n_window */
425 iwlagn_txq_free_tfd(trans, txq, get_cmd_index(q, q->read_ptr), 429 iwlagn_txq_free_tfd(trans, txq, get_cmd_index(q, q->read_ptr),
426 dma_dir); 430 dma_dir);
427 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd); 431 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd);
428 } 432 }
429 spin_unlock_irqrestore(&trans->shrd->sta_lock, flags); 433 spin_unlock_irqrestore(lock, flags);
430} 434}
431 435
432/** 436/**
@@ -986,29 +990,16 @@ static int iwl_trans_tx_stop(struct iwl_trans *trans)
986 return 0; 990 return 0;
987} 991}
988 992
989static void iwl_trans_pcie_disable_sync_irq(struct iwl_trans *trans) 993static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
990{ 994{
991 unsigned long flags; 995 unsigned long flags;
992 struct iwl_trans_pcie *trans_pcie = 996 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
993 IWL_TRANS_GET_PCIE_TRANS(trans);
994 997
998 /* tell the device to stop sending interrupts */
995 spin_lock_irqsave(&trans->shrd->lock, flags); 999 spin_lock_irqsave(&trans->shrd->lock, flags);
996 iwl_disable_interrupts(trans); 1000 iwl_disable_interrupts(trans);
997 spin_unlock_irqrestore(&trans->shrd->lock, flags); 1001 spin_unlock_irqrestore(&trans->shrd->lock, flags);
998 1002
999 /* wait to make sure we flush pending tasklet*/
1000 synchronize_irq(bus(trans)->irq);
1001 tasklet_kill(&trans_pcie->irq_tasklet);
1002}
1003
1004static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
1005{
1006 /* stop and reset the on-board processor */
1007 iwl_write32(bus(trans), CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
1008
1009 /* tell the device to stop sending interrupts */
1010 iwl_trans_pcie_disable_sync_irq(trans);
1011
1012 /* device going down, Stop using ICT table */ 1003 /* device going down, Stop using ICT table */
1013 iwl_disable_ict(trans); 1004 iwl_disable_ict(trans);
1014 1005
@@ -1035,6 +1026,20 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
1035 1026
1036 /* Stop the device, and put it in low power state */ 1027 /* Stop the device, and put it in low power state */
1037 iwl_apm_stop(priv(trans)); 1028 iwl_apm_stop(priv(trans));
1029
1030 /* Upon stop, the APM issues an interrupt if HW RF kill is set.
1031 * Clean again the interrupt here
1032 */
1033 spin_lock_irqsave(&trans->shrd->lock, flags);
1034 iwl_disable_interrupts(trans);
1035 spin_unlock_irqrestore(&trans->shrd->lock, flags);
1036
1037 /* wait to make sure we flush pending tasklet*/
1038 synchronize_irq(bus(trans)->irq);
1039 tasklet_kill(&trans_pcie->irq_tasklet);
1040
1041 /* stop and reset the on-board processor */
1042 iwl_write32(bus(trans), CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
1038} 1043}
1039 1044
1040static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb, 1045static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
diff --git a/drivers/net/wireless/iwmc3200wifi/commands.c b/drivers/net/wireless/iwmc3200wifi/commands.c
index 50dee6a0a5c..bd75078c454 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 0a0cc9667cd..87eef5773a0 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 362002735b1..98a179f98ea 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 56383e7be83..764b40dd24a 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/cfg.c b/drivers/net/wireless/libertas/cfg.c
index ff6378276ff..a7f1ab28940 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -634,7 +634,7 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
634 if (channel && 634 if (channel &&
635 !(channel->flags & IEEE80211_CHAN_DISABLED)) 635 !(channel->flags & IEEE80211_CHAN_DISABLED))
636 cfg80211_inform_bss(wiphy, channel, 636 cfg80211_inform_bss(wiphy, channel,
637 bssid, le64_to_cpu(*(__le64 *)tsfdesc), 637 bssid, get_unaligned_le64(tsfdesc),
638 capa, intvl, ie, ielen, 638 capa, intvl, ie, ielen,
639 LBS_SCAN_RSSI_TO_MBM(rssi), 639 LBS_SCAN_RSSI_TO_MBM(rssi),
640 GFP_KERNEL); 640 GFP_KERNEL);
@@ -728,15 +728,9 @@ static void lbs_scan_worker(struct work_struct *work)
728 le16_to_cpu(scan_cmd->hdr.size), 728 le16_to_cpu(scan_cmd->hdr.size),
729 lbs_ret_scan, 0); 729 lbs_ret_scan, 0);
730 730
731 if (priv->scan_channel >= priv->scan_req->n_channels) { 731 if (priv->scan_channel >= priv->scan_req->n_channels)
732 /* Mark scan done */ 732 /* Mark scan done */
733 if (priv->internal_scan) 733 lbs_scan_done(priv);
734 kfree(priv->scan_req);
735 else
736 cfg80211_scan_done(priv->scan_req, false);
737
738 priv->scan_req = NULL;
739 }
740 734
741 /* Restart network */ 735 /* Restart network */
742 if (carrier) 736 if (carrier)
@@ -774,6 +768,21 @@ static void _internal_start_scan(struct lbs_private *priv, bool internal,
774 lbs_deb_leave(LBS_DEB_CFG80211); 768 lbs_deb_leave(LBS_DEB_CFG80211);
775} 769}
776 770
771/*
772 * Clean up priv->scan_req. Should be used to handle the allocation details.
773 */
774void lbs_scan_done(struct lbs_private *priv)
775{
776 WARN_ON(!priv->scan_req);
777
778 if (priv->internal_scan)
779 kfree(priv->scan_req);
780 else
781 cfg80211_scan_done(priv->scan_req, false);
782
783 priv->scan_req = NULL;
784}
785
777static int lbs_cfg_scan(struct wiphy *wiphy, 786static int lbs_cfg_scan(struct wiphy *wiphy,
778 struct net_device *dev, 787 struct net_device *dev,
779 struct cfg80211_scan_request *request) 788 struct cfg80211_scan_request *request)
diff --git a/drivers/net/wireless/libertas/cfg.h b/drivers/net/wireless/libertas/cfg.h
index a02ee151710..558168ce634 100644
--- a/drivers/net/wireless/libertas/cfg.h
+++ b/drivers/net/wireless/libertas/cfg.h
@@ -16,6 +16,7 @@ int lbs_reg_notifier(struct wiphy *wiphy,
16void lbs_send_disconnect_notification(struct lbs_private *priv); 16void lbs_send_disconnect_notification(struct lbs_private *priv);
17void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event); 17void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event);
18 18
19void lbs_scan_done(struct lbs_private *priv);
19void lbs_scan_deinit(struct lbs_private *priv); 20void lbs_scan_deinit(struct lbs_private *priv);
20int lbs_disconnect(struct lbs_private *priv, u16 reason); 21int lbs_disconnect(struct lbs_private *priv, u16 reason);
21 22
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index e08ab1de3d9..d798bcc0d83 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 1af18277884..d8d8f0d0899 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 c962e21762d..9804ebc892d 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 622ae6de0d8..728baa44525 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>
@@ -995,6 +995,7 @@ static int if_spi_host_to_card(struct lbs_private *priv,
995 spin_unlock_irqrestore(&card->buffer_lock, flags); 995 spin_unlock_irqrestore(&card->buffer_lock, flags);
996 break; 996 break;
997 default: 997 default:
998 kfree(packet);
998 netdev_err(priv->dev, "can't transfer buffer of type %d\n", 999 netdev_err(priv->dev, "can't transfer buffer of type %d\n",
999 type); 1000 type);
1000 err = -EINVAL; 1001 err = -EINVAL;
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 8147f1e2a0b..db879c364eb 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 b03779bcd54..957681dede1 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>
@@ -255,10 +255,8 @@ static int lbs_eth_stop(struct net_device *dev)
255 255
256 lbs_update_mcast(priv); 256 lbs_update_mcast(priv);
257 cancel_delayed_work_sync(&priv->scan_work); 257 cancel_delayed_work_sync(&priv->scan_work);
258 if (priv->scan_req) { 258 if (priv->scan_req)
259 cfg80211_scan_done(priv->scan_req, false); 259 lbs_scan_done(priv);
260 priv->scan_req = NULL;
261 }
262 260
263 netif_carrier_off(priv->dev); 261 netif_carrier_off(priv->dev);
264 262
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index 62e10eeadd7..c7366b07b56 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 8f127520d78..c025f9c1828 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 13557fe0bf9..909ac368501 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 ba7d96584cb..68202e63873 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 acc461aa385..ceb51b6e670 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 68455a2307c..523ad55a288 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/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index dae8dbb24a0..8d3ab378662 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -819,8 +819,10 @@ mwifiex_scan_setup_scan_config(struct mwifiex_private *priv,
819 wildcard_ssid_tlv->header.len = cpu_to_le16( 819 wildcard_ssid_tlv->header.len = cpu_to_le16(
820 (u16) (ssid_len + sizeof(wildcard_ssid_tlv-> 820 (u16) (ssid_len + sizeof(wildcard_ssid_tlv->
821 max_ssid_length))); 821 max_ssid_length)));
822 wildcard_ssid_tlv->max_ssid_length = 822
823 user_scan_in->ssid_list[ssid_idx].max_len; 823 /* max_ssid_length = 0 tells firmware to perform
824 specific scan for the SSID filled */
825 wildcard_ssid_tlv->max_ssid_length = 0;
824 826
825 memcpy(wildcard_ssid_tlv->ssid, 827 memcpy(wildcard_ssid_tlv->ssid,
826 user_scan_in->ssid_list[ssid_idx].ssid, 828 user_scan_in->ssid_list[ssid_idx].ssid,
@@ -1469,7 +1471,7 @@ mwifiex_update_curr_bss_params(struct mwifiex_private *priv, u8 *bssid,
1469 s32 rssi, const u8 *ie_buf, size_t ie_len, 1471 s32 rssi, const u8 *ie_buf, size_t ie_len,
1470 u16 beacon_period, u16 cap_info_bitmap, u8 band) 1472 u16 beacon_period, u16 cap_info_bitmap, u8 band)
1471{ 1473{
1472 struct mwifiex_bssdescriptor *bss_desc = NULL; 1474 struct mwifiex_bssdescriptor *bss_desc;
1473 int ret; 1475 int ret;
1474 unsigned long flags; 1476 unsigned long flags;
1475 u8 *beacon_ie; 1477 u8 *beacon_ie;
@@ -1484,6 +1486,7 @@ mwifiex_update_curr_bss_params(struct mwifiex_private *priv, u8 *bssid,
1484 1486
1485 beacon_ie = kmemdup(ie_buf, ie_len, GFP_KERNEL); 1487 beacon_ie = kmemdup(ie_buf, ie_len, GFP_KERNEL);
1486 if (!beacon_ie) { 1488 if (!beacon_ie) {
1489 kfree(bss_desc);
1487 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n"); 1490 dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
1488 return -ENOMEM; 1491 return -ENOMEM;
1489 } 1492 }
diff --git a/drivers/net/wireless/orinoco/fw.c b/drivers/net/wireless/orinoco/fw.c
index 527cf5333db..4df8cf64b56 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 8b6f363b3f7..fa8ce510478 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 53a3408931b..18e82b31afa 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 ad9ae04d07a..db4d9a02f26 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 1b753173680..b1f51a21579 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/p54spi.c b/drivers/net/wireless/p54/p54spi.c
index f18df82eeb9..78d0d698855 100644
--- a/drivers/net/wireless/p54/p54spi.c
+++ b/drivers/net/wireless/p54/p54spi.c
@@ -588,8 +588,6 @@ static void p54spi_op_stop(struct ieee80211_hw *dev)
588 588
589 WARN_ON(priv->fw_state != FW_STATE_READY); 589 WARN_ON(priv->fw_state != FW_STATE_READY);
590 590
591 cancel_work_sync(&priv->work);
592
593 p54spi_power_off(priv); 591 p54spi_power_off(priv);
594 spin_lock_irqsave(&priv->tx_lock, flags); 592 spin_lock_irqsave(&priv->tx_lock, flags);
595 INIT_LIST_HEAD(&priv->tx_pending); 593 INIT_LIST_HEAD(&priv->tx_pending);
@@ -597,6 +595,8 @@ static void p54spi_op_stop(struct ieee80211_hw *dev)
597 595
598 priv->fw_state = FW_STATE_OFF; 596 priv->fw_state = FW_STATE_OFF;
599 mutex_unlock(&priv->mutex); 597 mutex_unlock(&priv->mutex);
598
599 cancel_work_sync(&priv->work);
600} 600}
601 601
602static int __devinit p54spi_probe(struct spi_device *spi) 602static int __devinit p54spi_probe(struct spi_device *spi)
@@ -656,6 +656,7 @@ static int __devinit p54spi_probe(struct spi_device *spi)
656 init_completion(&priv->fw_comp); 656 init_completion(&priv->fw_comp);
657 INIT_LIST_HEAD(&priv->tx_pending); 657 INIT_LIST_HEAD(&priv->tx_pending);
658 mutex_init(&priv->mutex); 658 mutex_init(&priv->mutex);
659 spin_lock_init(&priv->tx_lock);
659 SET_IEEE80211_DEV(hw, &spi->dev); 660 SET_IEEE80211_DEV(hw, &spi->dev);
660 priv->common.open = p54spi_op_start; 661 priv->common.open = p54spi_op_start;
661 priv->common.stop = p54spi_op_stop; 662 priv->common.stop = p54spi_op_stop;
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index a8f3bc740df..9b609686642 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 f485784a60a..6ed9c323e3c 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/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index d97a2caf582..bc2ba80c47b 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -778,7 +778,7 @@ prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
778 dwrq->flags = 0; 778 dwrq->flags = 0;
779 dwrq->length = 0; 779 dwrq->length = 0;
780 } 780 }
781 essid->octets[essid->length] = '\0'; 781 essid->octets[dwrq->length] = '\0';
782 memcpy(extra, essid->octets, dwrq->length); 782 memcpy(extra, essid->octets, dwrq->length);
783 kfree(essid); 783 kfree(essid);
784 784
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index 3f183a15186..1ba079dffb1 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -3771,7 +3771,7 @@ static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
3771 /* Apparently the data is read from end to start */ 3771 /* Apparently the data is read from end to start */
3772 rt2800_register_read_lock(rt2x00dev, EFUSE_DATA3, &reg); 3772 rt2800_register_read_lock(rt2x00dev, EFUSE_DATA3, &reg);
3773 /* The returned value is in CPU order, but eeprom is le */ 3773 /* The returned value is in CPU order, but eeprom is le */
3774 rt2x00dev->eeprom[i] = cpu_to_le32(reg); 3774 *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
3775 rt2800_register_read_lock(rt2x00dev, EFUSE_DATA2, &reg); 3775 rt2800_register_read_lock(rt2x00dev, EFUSE_DATA2, &reg);
3776 *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg); 3776 *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
3777 rt2800_register_read_lock(rt2x00dev, EFUSE_DATA1, &reg); 3777 rt2800_register_read_lock(rt2x00dev, EFUSE_DATA1, &reg);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index f1565792f27..377876315b8 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -919,6 +919,7 @@ static struct usb_device_id rt2800usb_device_table[] = {
919 { USB_DEVICE(0x050d, 0x935b) }, 919 { USB_DEVICE(0x050d, 0x935b) },
920 /* Buffalo */ 920 /* Buffalo */
921 { USB_DEVICE(0x0411, 0x00e8) }, 921 { USB_DEVICE(0x0411, 0x00e8) },
922 { USB_DEVICE(0x0411, 0x0158) },
922 { USB_DEVICE(0x0411, 0x016f) }, 923 { USB_DEVICE(0x0411, 0x016f) },
923 { USB_DEVICE(0x0411, 0x01a2) }, 924 { USB_DEVICE(0x0411, 0x01a2) },
924 /* Corega */ 925 /* Corega */
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 2ec5c00235e..99ff12d0c29 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -943,6 +943,7 @@ struct rt2x00_dev {
943 * Powersaving work 943 * Powersaving work
944 */ 944 */
945 struct delayed_work autowakeup_work; 945 struct delayed_work autowakeup_work;
946 struct work_struct sleep_work;
946 947
947 /* 948 /*
948 * Data queue arrays for RX, TX, Beacon and ATIM. 949 * Data queue arrays for RX, TX, Beacon and ATIM.
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index e1fb2a8569b..edd317fa7c0 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -465,6 +465,23 @@ static u8 *rt2x00lib_find_ie(u8 *data, unsigned int len, u8 ie)
465 return NULL; 465 return NULL;
466} 466}
467 467
468static void rt2x00lib_sleep(struct work_struct *work)
469{
470 struct rt2x00_dev *rt2x00dev =
471 container_of(work, struct rt2x00_dev, sleep_work);
472
473 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
474 return;
475
476 /*
477 * Check again is powersaving is enabled, to prevent races from delayed
478 * work execution.
479 */
480 if (!test_bit(CONFIG_POWERSAVING, &rt2x00dev->flags))
481 rt2x00lib_config(rt2x00dev, &rt2x00dev->hw->conf,
482 IEEE80211_CONF_CHANGE_PS);
483}
484
468static void rt2x00lib_rxdone_check_ps(struct rt2x00_dev *rt2x00dev, 485static void rt2x00lib_rxdone_check_ps(struct rt2x00_dev *rt2x00dev,
469 struct sk_buff *skb, 486 struct sk_buff *skb,
470 struct rxdone_entry_desc *rxdesc) 487 struct rxdone_entry_desc *rxdesc)
@@ -512,8 +529,7 @@ static void rt2x00lib_rxdone_check_ps(struct rt2x00_dev *rt2x00dev,
512 cam |= (tim_ie->bitmap_ctrl & 0x01); 529 cam |= (tim_ie->bitmap_ctrl & 0x01);
513 530
514 if (!cam && !test_bit(CONFIG_POWERSAVING, &rt2x00dev->flags)) 531 if (!cam && !test_bit(CONFIG_POWERSAVING, &rt2x00dev->flags))
515 rt2x00lib_config(rt2x00dev, &rt2x00dev->hw->conf, 532 queue_work(rt2x00dev->workqueue, &rt2x00dev->sleep_work);
516 IEEE80211_CONF_CHANGE_PS);
517} 533}
518 534
519static int rt2x00lib_rxdone_read_signal(struct rt2x00_dev *rt2x00dev, 535static int rt2x00lib_rxdone_read_signal(struct rt2x00_dev *rt2x00dev,
@@ -1141,6 +1157,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1141 1157
1142 INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled); 1158 INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled);
1143 INIT_DELAYED_WORK(&rt2x00dev->autowakeup_work, rt2x00lib_autowakeup); 1159 INIT_DELAYED_WORK(&rt2x00dev->autowakeup_work, rt2x00lib_autowakeup);
1160 INIT_WORK(&rt2x00dev->sleep_work, rt2x00lib_sleep);
1144 1161
1145 /* 1162 /*
1146 * Let the driver probe the device to detect the capabilities. 1163 * Let the driver probe the device to detect the capabilities.
@@ -1197,6 +1214,7 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev)
1197 */ 1214 */
1198 cancel_work_sync(&rt2x00dev->intf_work); 1215 cancel_work_sync(&rt2x00dev->intf_work);
1199 cancel_delayed_work_sync(&rt2x00dev->autowakeup_work); 1216 cancel_delayed_work_sync(&rt2x00dev->autowakeup_work);
1217 cancel_work_sync(&rt2x00dev->sleep_work);
1200 if (rt2x00_is_usb(rt2x00dev)) { 1218 if (rt2x00_is_usb(rt2x00dev)) {
1201 del_timer_sync(&rt2x00dev->txstatus_timer); 1219 del_timer_sync(&rt2x00dev->txstatus_timer);
1202 cancel_work_sync(&rt2x00dev->rxdone_work); 1220 cancel_work_sync(&rt2x00dev->rxdone_work);
diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index 0082015ff66..2f14a5fb0cb 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 24873b55b55..4a78f9e39df 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/base.c b/drivers/net/wireless/rtlwifi/base.c
index d4fdd2a5a73..b4ce93436d2 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 7babb6acd95..dc36d7461ca 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 3fc21f60bb0..ed1058b7158 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 177a8e66924..eb61061821e 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 a693feffbe7..55c8e50f45f 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"
@@ -394,7 +395,7 @@ void rtl_lps_enter(struct ieee80211_hw *hw)
394 if (mac->link_state != MAC80211_LINKED) 395 if (mac->link_state != MAC80211_LINKED)
395 return; 396 return;
396 397
397 spin_lock(&rtlpriv->locks.lps_lock); 398 spin_lock_irq(&rtlpriv->locks.lps_lock);
398 399
399 /* Idle for a while if we connect to AP a while ago. */ 400 /* Idle for a while if we connect to AP a while ago. */
400 if (mac->cnt_after_linked >= 2) { 401 if (mac->cnt_after_linked >= 2) {
@@ -406,7 +407,7 @@ void rtl_lps_enter(struct ieee80211_hw *hw)
406 } 407 }
407 } 408 }
408 409
409 spin_unlock(&rtlpriv->locks.lps_lock); 410 spin_unlock_irq(&rtlpriv->locks.lps_lock);
410} 411}
411 412
412/*Leave the leisure power save mode.*/ 413/*Leave the leisure power save mode.*/
@@ -415,8 +416,9 @@ void rtl_lps_leave(struct ieee80211_hw *hw)
415 struct rtl_priv *rtlpriv = rtl_priv(hw); 416 struct rtl_priv *rtlpriv = rtl_priv(hw);
416 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 417 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
417 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 418 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
419 unsigned long flags;
418 420
419 spin_lock(&rtlpriv->locks.lps_lock); 421 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flags);
420 422
421 if (ppsc->fwctrl_lps) { 423 if (ppsc->fwctrl_lps) {
422 if (ppsc->dot11_psmode != EACTIVE) { 424 if (ppsc->dot11_psmode != EACTIVE) {
@@ -437,7 +439,7 @@ void rtl_lps_leave(struct ieee80211_hw *hw)
437 rtl_lps_set_psmode(hw, EACTIVE); 439 rtl_lps_set_psmode(hw, EACTIVE);
438 } 440 }
439 } 441 }
440 spin_unlock(&rtlpriv->locks.lps_lock); 442 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flags);
441} 443}
442 444
443/* For sw LPS*/ 445/* For sw LPS*/
@@ -538,9 +540,9 @@ void rtl_swlps_rf_awake(struct ieee80211_hw *hw)
538 RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM); 540 RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM);
539 } 541 }
540 542
541 spin_lock(&rtlpriv->locks.lps_lock); 543 spin_lock_irq(&rtlpriv->locks.lps_lock);
542 rtl_ps_set_rf_state(hw, ERFON, RF_CHANGE_BY_PS); 544 rtl_ps_set_rf_state(hw, ERFON, RF_CHANGE_BY_PS);
543 spin_unlock(&rtlpriv->locks.lps_lock); 545 spin_unlock_irq(&rtlpriv->locks.lps_lock);
544} 546}
545 547
546void rtl_swlps_rfon_wq_callback(void *data) 548void rtl_swlps_rfon_wq_callback(void *data)
@@ -573,9 +575,9 @@ void rtl_swlps_rf_sleep(struct ieee80211_hw *hw)
573 if (rtlpriv->link_info.busytraffic) 575 if (rtlpriv->link_info.busytraffic)
574 return; 576 return;
575 577
576 spin_lock(&rtlpriv->locks.lps_lock); 578 spin_lock_irq(&rtlpriv->locks.lps_lock);
577 rtl_ps_set_rf_state(hw, ERFSLEEP, RF_CHANGE_BY_PS); 579 rtl_ps_set_rf_state(hw, ERFSLEEP, RF_CHANGE_BY_PS);
578 spin_unlock(&rtlpriv->locks.lps_lock); 580 spin_unlock_irq(&rtlpriv->locks.lps_lock);
579 581
580 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM && 582 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM &&
581 !RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) { 583 !RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
index a00774e7090..72a98cab6f6 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 49a064bdbce..950c65a15b8 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 2f624fc2749..605ff191aeb 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 3b11642d3f7..1f07558debf 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 a48404cc2b9..f2aa33dc4d7 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 feed1ed8d9b..c244f2f1b83 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 691f8009218..149493f4c25 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 3ec9a0d41ba..92f49d522c5 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 b42c2e2b205..54cb8a60514 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 d4e628db76b..68133791497 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/wl12xx/scan.c b/drivers/net/wireless/wl12xx/scan.c
index 128ccb79318..fc29c671cf3 100644
--- a/drivers/net/wireless/wl12xx/scan.c
+++ b/drivers/net/wireless/wl12xx/scan.c
@@ -559,7 +559,7 @@ wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
559 break; 559 break;
560 } 560 }
561 /* Fail if SSID isn't present in the filters */ 561 /* Fail if SSID isn't present in the filters */
562 if (j == req->n_ssids) { 562 if (j == cmd->n_ssids) {
563 ret = -EINVAL; 563 ret = -EINVAL;
564 goto out_free; 564 goto out_free;
565 } 565 }
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index cf0d69dd7be..785bdbe38f2 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 161f207786a..94b79c3338c 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 d5508957200..1ae270eed51 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1021,7 +1021,7 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,
1021 pending_idx = *((u16 *)skb->data); 1021 pending_idx = *((u16 *)skb->data);
1022 xen_netbk_idx_release(netbk, pending_idx); 1022 xen_netbk_idx_release(netbk, pending_idx);
1023 for (j = start; j < i; j++) { 1023 for (j = start; j < i; j++) {
1024 pending_idx = frag_get_pending_idx(&shinfo->frags[i]); 1024 pending_idx = frag_get_pending_idx(&shinfo->frags[j]);
1025 xen_netbk_idx_release(netbk, pending_idx); 1025 xen_netbk_idx_release(netbk, pending_idx);
1026 } 1026 }
1027 1027
@@ -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 5b0f1ff8036..06c3642e5bd 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 aeec35bc378..fd85fa298e0 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/irq.c b/drivers/of/irq.c
index 6d3dd3988d0..19c0115092d 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -60,27 +60,27 @@ EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
60 */ 60 */
61struct device_node *of_irq_find_parent(struct device_node *child) 61struct device_node *of_irq_find_parent(struct device_node *child)
62{ 62{
63 struct device_node *p, *c = child; 63 struct device_node *p;
64 const __be32 *parp; 64 const __be32 *parp;
65 65
66 if (!of_node_get(c)) 66 if (!of_node_get(child))
67 return NULL; 67 return NULL;
68 68
69 do { 69 do {
70 parp = of_get_property(c, "interrupt-parent", NULL); 70 parp = of_get_property(child, "interrupt-parent", NULL);
71 if (parp == NULL) 71 if (parp == NULL)
72 p = of_get_parent(c); 72 p = of_get_parent(child);
73 else { 73 else {
74 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE) 74 if (of_irq_workarounds & OF_IMAP_NO_PHANDLE)
75 p = of_node_get(of_irq_dflt_pic); 75 p = of_node_get(of_irq_dflt_pic);
76 else 76 else
77 p = of_find_node_by_phandle(be32_to_cpup(parp)); 77 p = of_find_node_by_phandle(be32_to_cpup(parp));
78 } 78 }
79 of_node_put(c); 79 of_node_put(child);
80 c = p; 80 child = p;
81 } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL); 81 } while (p && of_get_property(p, "#interrupt-cells", NULL) == NULL);
82 82
83 return (p == child) ? NULL : p; 83 return p;
84} 84}
85 85
86/** 86/**
@@ -424,6 +424,8 @@ void __init of_irq_init(const struct of_device_id *matches)
424 424
425 desc->dev = np; 425 desc->dev = np;
426 desc->interrupt_parent = of_irq_find_parent(np); 426 desc->interrupt_parent = of_irq_find_parent(np);
427 if (desc->interrupt_parent == np)
428 desc->interrupt_parent = NULL;
427 list_add_tail(&desc->list, &intc_desc_list); 429 list_add_tail(&desc->list, &intc_desc_list);
428 } 430 }
429 431
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index bb184717588..ffab033d207 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 3701b62c1d5..13e37e2d8ec 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 ac1ec54e4fd..93125163dea 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 1dbce58a58b..6dbc074e487 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 ed5a6d3c26a..cbd5d701c7e 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 75a80e46b39..8b490d77054 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 a6f762188bc..8644d5372e7 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 cec66064ee4..f02b5235056 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
@@ -87,6 +76,7 @@ config PCI_IOV
87 76
88config PCI_PRI 77config PCI_PRI
89 bool "PCI PRI support" 78 bool "PCI PRI support"
79 depends on PCI
90 select PCI_ATS 80 select PCI_ATS
91 help 81 help
92 PRI is the PCI Page Request Interface. It allows PCI devices that are 82 PRI is the PCI Page Request Interface. It allows PCI devices that are
diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
index f727a09eb72..7ec56fb0bd7 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 4d4a6447840..d3509cdeb55 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/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 596172b4ae9..fce1c54a0c8 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -459,8 +459,17 @@ static int add_bridge(acpi_handle handle)
459{ 459{
460 acpi_status status; 460 acpi_status status;
461 unsigned long long tmp; 461 unsigned long long tmp;
462 struct acpi_pci_root *root;
462 acpi_handle dummy_handle; 463 acpi_handle dummy_handle;
463 464
465 /*
466 * We shouldn't use this bridge if PCIe native hotplug control has been
467 * granted by the BIOS for it.
468 */
469 root = acpi_pci_find_root(handle);
470 if (root && (root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
471 return -ENODEV;
472
464 /* if the bridge doesn't have _STA, we assume it is always there */ 473 /* if the bridge doesn't have _STA, we assume it is always there */
465 status = acpi_get_handle(handle, "_STA", &dummy_handle); 474 status = acpi_get_handle(handle, "_STA", &dummy_handle);
466 if (ACPI_SUCCESS(status)) { 475 if (ACPI_SUCCESS(status)) {
@@ -1376,13 +1385,23 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type,
1376static acpi_status 1385static acpi_status
1377find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv) 1386find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1378{ 1387{
1388 struct acpi_pci_root *root;
1379 int *count = (int *)context; 1389 int *count = (int *)context;
1380 1390
1381 if (acpi_is_root_bridge(handle)) { 1391 if (!acpi_is_root_bridge(handle))
1382 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, 1392 return AE_OK;
1383 handle_hotplug_event_bridge, NULL); 1393
1384 (*count)++; 1394 root = acpi_pci_find_root(handle);
1385 } 1395 if (!root)
1396 return AE_OK;
1397
1398 if (root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)
1399 return AE_OK;
1400
1401 (*count)++;
1402 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1403 handle_hotplug_event_bridge, NULL);
1404
1386 return AE_OK ; 1405 return AE_OK ;
1387} 1406}
1388 1407
diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c
index 5f7226223a6..376d70d1717 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/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index 1e9c9aacc3a..085dbb5fc16 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -213,9 +213,6 @@ static int board_added(struct slot *p_slot)
213 goto err_exit; 213 goto err_exit;
214 } 214 }
215 215
216 /* Wait for 1 second after checking link training status */
217 msleep(1000);
218
219 /* Check for a power fault */ 216 /* Check for a power fault */
220 if (ctrl->power_fault_detected || pciehp_query_power_fault(p_slot)) { 217 if (ctrl->power_fault_detected || pciehp_query_power_fault(p_slot)) {
221 ctrl_err(ctrl, "Power fault on slot %s\n", slot_name(p_slot)); 218 ctrl_err(ctrl, "Power fault on slot %s\n", slot_name(p_slot));
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 96dc4734e4a..7b1414810ae 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -280,6 +280,14 @@ int pciehp_check_link_status(struct controller *ctrl)
280 else 280 else
281 msleep(1000); 281 msleep(1000);
282 282
283 /*
284 * Need to wait for 1000 ms after Data Link Layer Link Active
285 * (DLLLA) bit reads 1b before sending configuration request.
286 * We need it before checking Link Training (LT) bit becuase
287 * LT is still set even after DLLLA bit is set on some platform.
288 */
289 msleep(1000);
290
283 retval = pciehp_readw(ctrl, PCI_EXP_LNKSTA, &lnk_status); 291 retval = pciehp_readw(ctrl, PCI_EXP_LNKSTA, &lnk_status);
284 if (retval) { 292 if (retval) {
285 ctrl_err(ctrl, "Cannot read LNKSTATUS register\n"); 293 ctrl_err(ctrl, "Cannot read LNKSTATUS register\n");
@@ -294,6 +302,16 @@ int pciehp_check_link_status(struct controller *ctrl)
294 return retval; 302 return retval;
295 } 303 }
296 304
305 /*
306 * If the port supports Link speeds greater than 5.0 GT/s, we
307 * must wait for 100 ms after Link training completes before
308 * sending configuration request.
309 */
310 if (ctrl->pcie->port->subordinate->max_bus_speed > PCIE_SPEED_5_0GT)
311 msleep(100);
312
313 pcie_update_link_speed(ctrl->pcie->port->subordinate, lnk_status);
314
297 return retval; 315 return retval;
298} 316}
299 317
@@ -484,7 +502,6 @@ int pciehp_power_on_slot(struct slot * slot)
484 u16 slot_cmd; 502 u16 slot_cmd;
485 u16 cmd_mask; 503 u16 cmd_mask;
486 u16 slot_status; 504 u16 slot_status;
487 u16 lnk_status;
488 int retval = 0; 505 int retval = 0;
489 506
490 /* Clear sticky power-fault bit from previous power failures */ 507 /* Clear sticky power-fault bit from previous power failures */
@@ -516,14 +533,6 @@ int pciehp_power_on_slot(struct slot * slot)
516 ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, 533 ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__,
517 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); 534 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd);
518 535
519 retval = pciehp_readw(ctrl, PCI_EXP_LNKSTA, &lnk_status);
520 if (retval) {
521 ctrl_err(ctrl, "%s: Cannot read LNKSTA register\n",
522 __func__);
523 return retval;
524 }
525 pcie_update_link_speed(ctrl->pcie->port->subordinate, lnk_status);
526
527 return retval; 536 return retval;
528} 537}
529 538
diff --git a/drivers/pci/hotplug/pcihp_slot.c b/drivers/pci/hotplug/pcihp_slot.c
index 3ffd9c1acc0..8c05a18c977 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 1d002b1c2bf..c56a9413e1a 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/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index aca972bbfb4..dd7e0c51a33 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -278,8 +278,8 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
278 278
279static int is_shpc_capable(struct pci_dev *dev) 279static int is_shpc_capable(struct pci_dev *dev)
280{ 280{
281 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == 281 if (dev->vendor == PCI_VENDOR_ID_AMD &&
282 PCI_DEVICE_ID_AMD_GOLAM_7450)) 282 dev->device == PCI_DEVICE_ID_AMD_GOLAM_7450)
283 return 1; 283 return 1;
284 if (!pci_find_capability(dev, PCI_CAP_ID_SHPC)) 284 if (!pci_find_capability(dev, PCI_CAP_ID_SHPC))
285 return 0; 285 return 0;
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 36547f0ce30..75ba2311b54 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -944,8 +944,8 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
944 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ 944 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
945 ctrl_dbg(ctrl, "Hotplug Controller:\n"); 945 ctrl_dbg(ctrl, "Hotplug Controller:\n");
946 946
947 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == 947 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
948 PCI_DEVICE_ID_AMD_GOLAM_7450)) { 948 pdev->device == PCI_DEVICE_ID_AMD_GOLAM_7450) {
949 /* amd shpc driver doesn't use Base Offset; assume 0 */ 949 /* amd shpc driver doesn't use Base Offset; assume 0 */
950 ctrl->mmio_base = pci_resource_start(pdev, 0); 950 ctrl->mmio_base = pci_resource_start(pdev, 0);
951 ctrl->mmio_size = pci_resource_len(pdev, 0); 951 ctrl->mmio_size = pci_resource_len(pdev, 0);
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c
index db057b6fe0c..6e373ea57b3 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 203508b227b..5775638ac01 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 9b4e88c636f..b82c155d7b3 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 de01174aff0..e5f69a43b1b 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 2f10328bf66..0e6d04d7ba4 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 7bcf12adced..106be0d08f8 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 7285145ac1c..64765474676 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 36864a935d6..48ebdb237f3 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 51a9095c7da..5717509becb 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 968cfea04f7..ac6412fb8d6 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 a5a5ca17cfe..39b79070335 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 01757f18a20..3e49df6d5e3 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 2c540542b5a..a87e2728b2c 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 63f4d5211ed..0b4f946cf13 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 6ee42b4c3e6..923f315926e 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 4f09506ad8d..6e7dcfd22ed 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/Kconfig b/drivers/pinctrl/Kconfig
index ef566443f94..e17e2f8001d 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -2,23 +2,17 @@
2# PINCTRL infrastructure and drivers 2# PINCTRL infrastructure and drivers
3# 3#
4 4
5menuconfig PINCTRL 5config PINCTRL
6 bool "PINCTRL Support" 6 bool
7 depends on EXPERIMENTAL 7 depends on EXPERIMENTAL
8 help
9 This enables the PINCTRL subsystem for controlling pins
10 on chip packages, for example multiplexing pins on primarily
11 PGA and BGA packages for systems on chip.
12
13 If unsure, say N.
14 8
15if PINCTRL 9if PINCTRL
16 10
11menu "Pin controllers"
12 depends on PINCTRL
13
17config PINMUX 14config PINMUX
18 bool "Support pinmux controllers" 15 bool "Support pinmux controllers"
19 help
20 Say Y here if you want the pincontrol subsystem to handle pin
21 multiplexing drivers.
22 16
23config DEBUG_PINCTRL 17config DEBUG_PINCTRL
24 bool "Debug PINCTRL calls" 18 bool "Debug PINCTRL calls"
@@ -30,14 +24,12 @@ config PINMUX_SIRF
30 bool "CSR SiRFprimaII pinmux driver" 24 bool "CSR SiRFprimaII pinmux driver"
31 depends on ARCH_PRIMA2 25 depends on ARCH_PRIMA2
32 select PINMUX 26 select PINMUX
33 help
34 Say Y here to enable the SiRFprimaII pinmux driver
35 27
36config PINMUX_U300 28config PINMUX_U300
37 bool "U300 pinmux driver" 29 bool "U300 pinmux driver"
38 depends on ARCH_U300 30 depends on ARCH_U300
39 select PINMUX 31 select PINMUX
40 help 32
41 Say Y here to enable the U300 pinmux driver 33endmenu
42 34
43endif 35endif
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 423522d8731..eadef9e191e 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/Kconfig b/drivers/platform/x86/Kconfig
index f4e3d82379d..7f43cf86d77 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -83,8 +83,10 @@ config DELL_LAPTOP
83 depends on EXPERIMENTAL 83 depends on EXPERIMENTAL
84 depends on BACKLIGHT_CLASS_DEVICE 84 depends on BACKLIGHT_CLASS_DEVICE
85 depends on RFKILL || RFKILL = n 85 depends on RFKILL || RFKILL = n
86 depends on POWER_SUPPLY
87 depends on SERIO_I8042 86 depends on SERIO_I8042
87 select POWER_SUPPLY
88 select LEDS_CLASS
89 select NEW_LEDS
88 default n 90 default n
89 ---help--- 91 ---help---
90 This driver adds support for rfkill and backlight control to Dell 92 This driver adds support for rfkill and backlight control to Dell
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index a43cfd906c6..d93e962f261 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -589,14 +589,14 @@ static const struct backlight_ops dell_ops = {
589 .update_status = dell_send_intensity, 589 .update_status = dell_send_intensity,
590}; 590};
591 591
592static void touchpad_led_on() 592static void touchpad_led_on(void)
593{ 593{
594 int command = 0x97; 594 int command = 0x97;
595 char data = 1; 595 char data = 1;
596 i8042_command(&data, command | 1 << 12); 596 i8042_command(&data, command | 1 << 12);
597} 597}
598 598
599static void touchpad_led_off() 599static void touchpad_led_off(void)
600{ 600{
601 int command = 0x97; 601 int command = 0x97;
602 char data = 2; 602 char data = 2;
diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
index c86665369a2..48870e50423 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 6f40bf202dc..2264331bd48 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 9b88be42b6c..a134c26870b 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 ca84d5099ce..b00c17612a8 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/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index bbf3edd85be..5be4a392a3a 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -509,15 +509,12 @@ static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
509 struct acpi_resource_dma *p) 509 struct acpi_resource_dma *p)
510{ 510{
511 int i; 511 int i;
512 unsigned char map = 0, flags = 0; 512 unsigned char map = 0, flags;
513
514 if (p->channel_count == 0)
515 flags |= IORESOURCE_DISABLED;
516 513
517 for (i = 0; i < p->channel_count; i++) 514 for (i = 0; i < p->channel_count; i++)
518 map |= 1 << p->channels[i]; 515 map |= 1 << p->channels[i];
519 516
520 flags |= dma_flags(dev, p->type, p->bus_master, p->transfer); 517 flags = dma_flags(dev, p->type, p->bus_master, p->transfer);
521 pnp_register_dma_resource(dev, option_flags, map, flags); 518 pnp_register_dma_resource(dev, option_flags, map, flags);
522} 519}
523 520
@@ -527,17 +524,14 @@ static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
527{ 524{
528 int i; 525 int i;
529 pnp_irq_mask_t map; 526 pnp_irq_mask_t map;
530 unsigned char flags = 0; 527 unsigned char flags;
531
532 if (p->interrupt_count == 0)
533 flags |= IORESOURCE_DISABLED;
534 528
535 bitmap_zero(map.bits, PNP_IRQ_NR); 529 bitmap_zero(map.bits, PNP_IRQ_NR);
536 for (i = 0; i < p->interrupt_count; i++) 530 for (i = 0; i < p->interrupt_count; i++)
537 if (p->interrupts[i]) 531 if (p->interrupts[i])
538 __set_bit(p->interrupts[i], map.bits); 532 __set_bit(p->interrupts[i], map.bits);
539 533
540 flags |= irq_flags(p->triggering, p->polarity, p->sharable); 534 flags = irq_flags(p->triggering, p->polarity, p->sharable);
541 pnp_register_irq_resource(dev, option_flags, &map, flags); 535 pnp_register_irq_resource(dev, option_flags, &map, flags);
542} 536}
543 537
@@ -547,10 +541,7 @@ static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
547{ 541{
548 int i; 542 int i;
549 pnp_irq_mask_t map; 543 pnp_irq_mask_t map;
550 unsigned char flags = 0; 544 unsigned char flags;
551
552 if (p->interrupt_count == 0)
553 flags |= IORESOURCE_DISABLED;
554 545
555 bitmap_zero(map.bits, PNP_IRQ_NR); 546 bitmap_zero(map.bits, PNP_IRQ_NR);
556 for (i = 0; i < p->interrupt_count; i++) { 547 for (i = 0; i < p->interrupt_count; i++) {
@@ -564,7 +555,7 @@ static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
564 } 555 }
565 } 556 }
566 557
567 flags |= irq_flags(p->triggering, p->polarity, p->sharable); 558 flags = irq_flags(p->triggering, p->polarity, p->sharable);
568 pnp_register_irq_resource(dev, option_flags, &map, flags); 559 pnp_register_irq_resource(dev, option_flags, &map, flags);
569} 560}
570 561
@@ -574,11 +565,8 @@ static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
574{ 565{
575 unsigned char flags = 0; 566 unsigned char flags = 0;
576 567
577 if (io->address_length == 0)
578 flags |= IORESOURCE_DISABLED;
579
580 if (io->io_decode == ACPI_DECODE_16) 568 if (io->io_decode == ACPI_DECODE_16)
581 flags |= IORESOURCE_IO_16BIT_ADDR; 569 flags = IORESOURCE_IO_16BIT_ADDR;
582 pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum, 570 pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum,
583 io->alignment, io->address_length, flags); 571 io->alignment, io->address_length, flags);
584} 572}
@@ -587,13 +575,8 @@ static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
587 unsigned int option_flags, 575 unsigned int option_flags,
588 struct acpi_resource_fixed_io *io) 576 struct acpi_resource_fixed_io *io)
589{ 577{
590 unsigned char flags = 0;
591
592 if (io->address_length == 0)
593 flags |= IORESOURCE_DISABLED;
594
595 pnp_register_port_resource(dev, option_flags, io->address, io->address, 578 pnp_register_port_resource(dev, option_flags, io->address, io->address,
596 0, io->address_length, flags | IORESOURCE_IO_FIXED); 579 0, io->address_length, IORESOURCE_IO_FIXED);
597} 580}
598 581
599static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev, 582static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
@@ -602,11 +585,8 @@ static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
602{ 585{
603 unsigned char flags = 0; 586 unsigned char flags = 0;
604 587
605 if (p->address_length == 0)
606 flags |= IORESOURCE_DISABLED;
607
608 if (p->write_protect == ACPI_READ_WRITE_MEMORY) 588 if (p->write_protect == ACPI_READ_WRITE_MEMORY)
609 flags |= IORESOURCE_MEM_WRITEABLE; 589 flags = IORESOURCE_MEM_WRITEABLE;
610 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, 590 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum,
611 p->alignment, p->address_length, flags); 591 p->alignment, p->address_length, flags);
612} 592}
@@ -617,11 +597,8 @@ static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
617{ 597{
618 unsigned char flags = 0; 598 unsigned char flags = 0;
619 599
620 if (p->address_length == 0)
621 flags |= IORESOURCE_DISABLED;
622
623 if (p->write_protect == ACPI_READ_WRITE_MEMORY) 600 if (p->write_protect == ACPI_READ_WRITE_MEMORY)
624 flags |= IORESOURCE_MEM_WRITEABLE; 601 flags = IORESOURCE_MEM_WRITEABLE;
625 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, 602 pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum,
626 p->alignment, p->address_length, flags); 603 p->alignment, p->address_length, flags);
627} 604}
@@ -632,11 +609,8 @@ static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
632{ 609{
633 unsigned char flags = 0; 610 unsigned char flags = 0;
634 611
635 if (p->address_length == 0)
636 flags |= IORESOURCE_DISABLED;
637
638 if (p->write_protect == ACPI_READ_WRITE_MEMORY) 612 if (p->write_protect == ACPI_READ_WRITE_MEMORY)
639 flags |= IORESOURCE_MEM_WRITEABLE; 613 flags = IORESOURCE_MEM_WRITEABLE;
640 pnp_register_mem_resource(dev, option_flags, p->address, p->address, 614 pnp_register_mem_resource(dev, option_flags, p->address, p->address,
641 0, p->address_length, flags); 615 0, p->address_length, flags);
642} 616}
@@ -656,19 +630,16 @@ static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
656 return; 630 return;
657 } 631 }
658 632
659 if (p->address_length == 0)
660 flags |= IORESOURCE_DISABLED;
661
662 if (p->resource_type == ACPI_MEMORY_RANGE) { 633 if (p->resource_type == ACPI_MEMORY_RANGE) {
663 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) 634 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)
664 flags |= IORESOURCE_MEM_WRITEABLE; 635 flags = IORESOURCE_MEM_WRITEABLE;
665 pnp_register_mem_resource(dev, option_flags, p->minimum, 636 pnp_register_mem_resource(dev, option_flags, p->minimum,
666 p->minimum, 0, p->address_length, 637 p->minimum, 0, p->address_length,
667 flags); 638 flags);
668 } else if (p->resource_type == ACPI_IO_RANGE) 639 } else if (p->resource_type == ACPI_IO_RANGE)
669 pnp_register_port_resource(dev, option_flags, p->minimum, 640 pnp_register_port_resource(dev, option_flags, p->minimum,
670 p->minimum, 0, p->address_length, 641 p->minimum, 0, p->address_length,
671 flags | IORESOURCE_IO_FIXED); 642 IORESOURCE_IO_FIXED);
672} 643}
673 644
674static __init void pnpacpi_parse_ext_address_option(struct pnp_dev *dev, 645static __init void pnpacpi_parse_ext_address_option(struct pnp_dev *dev,
@@ -678,19 +649,16 @@ static __init void pnpacpi_parse_ext_address_option(struct pnp_dev *dev,
678 struct acpi_resource_extended_address64 *p = &r->data.ext_address64; 649 struct acpi_resource_extended_address64 *p = &r->data.ext_address64;
679 unsigned char flags = 0; 650 unsigned char flags = 0;
680 651
681 if (p->address_length == 0)
682 flags |= IORESOURCE_DISABLED;
683
684 if (p->resource_type == ACPI_MEMORY_RANGE) { 652 if (p->resource_type == ACPI_MEMORY_RANGE) {
685 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) 653 if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)
686 flags |= IORESOURCE_MEM_WRITEABLE; 654 flags = IORESOURCE_MEM_WRITEABLE;
687 pnp_register_mem_resource(dev, option_flags, p->minimum, 655 pnp_register_mem_resource(dev, option_flags, p->minimum,
688 p->minimum, 0, p->address_length, 656 p->minimum, 0, p->address_length,
689 flags); 657 flags);
690 } else if (p->resource_type == ACPI_IO_RANGE) 658 } else if (p->resource_type == ACPI_IO_RANGE)
691 pnp_register_port_resource(dev, option_flags, p->minimum, 659 pnp_register_port_resource(dev, option_flags, p->minimum,
692 p->minimum, 0, p->address_length, 660 p->minimum, 0, p->address_length,
693 flags | IORESOURCE_IO_FIXED); 661 IORESOURCE_IO_FIXED);
694} 662}
695 663
696struct acpipnp_parse_option_s { 664struct acpipnp_parse_option_s {
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 98bfab35b8e..9f0183c7307 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 a9b0209a2f5..2595145f3bf 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 ffc5033ea9c..a23317d75c5 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 ef8efadb58c..93e3bb47a3a 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 605514afc29..e15d4c9d398 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/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
index d9fb729535a..fb7300837fe 100644
--- a/drivers/ps3/ps3-vuart.c
+++ b/drivers/ps3/ps3-vuart.c
@@ -952,7 +952,7 @@ static int ps3_vuart_bus_interrupt_get(void)
952 } 952 }
953 953
954 result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler, 954 result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
955 IRQF_DISABLED, "vuart", &vuart_bus_priv); 955 0, "vuart", &vuart_bus_priv);
956 956
957 if (result) { 957 if (result) {
958 pr_debug("%s:%d: request_irq failed (%d)\n", 958 pr_debug("%s:%d: request_irq failed (%d)\n",
diff --git a/drivers/ps3/ps3stor_lib.c b/drivers/ps3/ps3stor_lib.c
index af0afa1db4a..8c3f5adf1bc 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>
@@ -166,7 +167,7 @@ int ps3stor_setup(struct ps3_storage_device *dev, irq_handler_t handler)
166 goto fail_close_device; 167 goto fail_close_device;
167 } 168 }
168 169
169 error = request_irq(dev->irq, handler, IRQF_DISABLED, 170 error = request_irq(dev->irq, handler, 0,
170 dev->sbd.core.driver->name, dev); 171 dev->sbd.core.driver->name, dev);
171 if (error) { 172 if (error) {
172 dev_err(&dev->sbd.core, "%s:%u: request_irq failed %d\n", 173 dev_err(&dev->sbd.core, "%s:%u: request_irq failed %d\n",
diff --git a/drivers/ps3/sys-manager-core.c b/drivers/ps3/sys-manager-core.c
index 474225852b6..0e41737ea83 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/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
index 043ee3136e4..809b7a3336b 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 e821b2159b4..ca0d608f824 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/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 5abeb3ac3e8..298c6c6a279 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -160,7 +160,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
160 break; 160 break;
161 } 161 }
162 162
163 if (!ri) 163 if (i == ARRAY_SIZE(aat2870_regulators))
164 return NULL; 164 return NULL;
165 165
166 ri->enable_addr = AAT2870_LDO_EN; 166 ri->enable_addr = AAT2870_LDO_EN;
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index 02f3c2333c8..6e1ae69646b 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 068d488a4f7..e24d1b7d97a 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 67fa2a3297a..938398f3e86 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>
@@ -2798,8 +2799,8 @@ void regulator_unregister(struct regulator_dev *rdev)
2798 list_del(&rdev->list); 2799 list_del(&rdev->list);
2799 if (rdev->supply) 2800 if (rdev->supply)
2800 regulator_put(rdev->supply); 2801 regulator_put(rdev->supply);
2801 device_unregister(&rdev->dev);
2802 kfree(rdev->constraints); 2802 kfree(rdev->constraints);
2803 device_unregister(&rdev->dev);
2803 mutex_unlock(&regulator_list_mutex); 2804 mutex_unlock(&regulator_list_mutex);
2804} 2805}
2805EXPORT_SYMBOL_GPL(regulator_unregister); 2806EXPORT_SYMBOL_GPL(regulator_unregister);
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 362e0822108..e23ddfa8b2c 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 2bb8f451cc0..78329751af5 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 f6ef6694ab9..b8f520513ce 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 2fe9d99c9f2..21ecf212a52 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 0f22ef12601..72b16b5f3db 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 6aa1b506fb5..fbc5e3741be 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 e4dbd667c04..cc9ec0e0327 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 ad6628ca94f..6176129a27e 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 730f43ad415..8479082e1ae 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 3285d41842f..023d17d022c 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 bc27ab13637..6532853a6ef 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 dbcf09d5080..14b9389dd52 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/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 66d2d60b436..b552aae55b4 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -664,10 +664,10 @@ static int tps65910_set_voltage_dcdc(struct regulator_dev *dev,
664 664
665 switch (id) { 665 switch (id) {
666 case TPS65910_REG_VDD1: 666 case TPS65910_REG_VDD1:
667 dcdc_mult = (selector / VDD1_2_NUM_VOLTS) + 1; 667 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
668 if (dcdc_mult == 1) 668 if (dcdc_mult == 1)
669 dcdc_mult--; 669 dcdc_mult--;
670 vsel = (selector % VDD1_2_NUM_VOLTS) + 3; 670 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
671 671
672 tps65910_modify_bits(pmic, TPS65910_VDD1, 672 tps65910_modify_bits(pmic, TPS65910_VDD1,
673 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT), 673 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
@@ -675,10 +675,10 @@ static int tps65910_set_voltage_dcdc(struct regulator_dev *dev,
675 tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel); 675 tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
676 break; 676 break;
677 case TPS65910_REG_VDD2: 677 case TPS65910_REG_VDD2:
678 dcdc_mult = (selector / VDD1_2_NUM_VOLTS) + 1; 678 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
679 if (dcdc_mult == 1) 679 if (dcdc_mult == 1)
680 dcdc_mult--; 680 dcdc_mult--;
681 vsel = (selector % VDD1_2_NUM_VOLTS) + 3; 681 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
682 682
683 tps65910_modify_bits(pmic, TPS65910_VDD2, 683 tps65910_modify_bits(pmic, TPS65910_VDD2,
684 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT), 684 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
@@ -756,9 +756,9 @@ static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
756 switch (id) { 756 switch (id) {
757 case TPS65910_REG_VDD1: 757 case TPS65910_REG_VDD1:
758 case TPS65910_REG_VDD2: 758 case TPS65910_REG_VDD2:
759 mult = (selector / VDD1_2_NUM_VOLTS) + 1; 759 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
760 volt = VDD1_2_MIN_VOLT + 760 volt = VDD1_2_MIN_VOLT +
761 (selector % VDD1_2_NUM_VOLTS) * VDD1_2_OFFSET; 761 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
762 break; 762 break;
763 case TPS65911_REG_VDDCTRL: 763 case TPS65911_REG_VDDCTRL:
764 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET); 764 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
@@ -947,6 +947,8 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
947 947
948 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { 948 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
949 pmic->desc[i].ops = &tps65910_ops_dcdc; 949 pmic->desc[i].ops = &tps65910_ops_dcdc;
950 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
951 VDD1_2_NUM_VOLT_COARSE;
950 } else if (i == TPS65910_REG_VDD3) { 952 } else if (i == TPS65910_REG_VDD3) {
951 if (tps65910_chip_id(tps65910) == TPS65910) 953 if (tps65910_chip_id(tps65910) == TPS65910)
952 pmic->desc[i].ops = &tps65910_ops_vdd3; 954 pmic->desc[i].ops = &tps65910_ops_vdd3;
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index ee8747f4fa0..11cc308d66e 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -71,6 +71,7 @@ struct twlreg_info {
71#define VREG_TYPE 1 71#define VREG_TYPE 1
72#define VREG_REMAP 2 72#define VREG_REMAP 2
73#define VREG_DEDICATED 3 /* LDO control */ 73#define VREG_DEDICATED 3 /* LDO control */
74#define VREG_VOLTAGE_SMPS_4030 9
74/* TWL6030 register offsets */ 75/* TWL6030 register offsets */
75#define VREG_TRANS 1 76#define VREG_TRANS 1
76#define VREG_STATE 2 77#define VREG_STATE 2
@@ -514,6 +515,32 @@ static struct regulator_ops twl4030ldo_ops = {
514 .get_status = twl4030reg_get_status, 515 .get_status = twl4030reg_get_status,
515}; 516};
516 517
518static int
519twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
520 unsigned *selector)
521{
522 struct twlreg_info *info = rdev_get_drvdata(rdev);
523 int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
524
525 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030,
526 vsel);
527 return 0;
528}
529
530static int twl4030smps_get_voltage(struct regulator_dev *rdev)
531{
532 struct twlreg_info *info = rdev_get_drvdata(rdev);
533 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
534 VREG_VOLTAGE_SMPS_4030);
535
536 return vsel * 12500 + 600000;
537}
538
539static struct regulator_ops twl4030smps_ops = {
540 .set_voltage = twl4030smps_set_voltage,
541 .get_voltage = twl4030smps_get_voltage,
542};
543
517static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) 544static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
518{ 545{
519 struct twlreg_info *info = rdev_get_drvdata(rdev); 546 struct twlreg_info *info = rdev_get_drvdata(rdev);
@@ -856,6 +883,21 @@ static struct regulator_ops twlsmps_ops = {
856 }, \ 883 }, \
857 } 884 }
858 885
886#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
887 { \
888 .base = offset, \
889 .id = num, \
890 .delay = turnon_delay, \
891 .remap = remap_conf, \
892 .desc = { \
893 .name = #label, \
894 .id = TWL4030_REG_##label, \
895 .ops = &twl4030smps_ops, \
896 .type = REGULATOR_VOLTAGE, \
897 .owner = THIS_MODULE, \
898 }, \
899 }
900
859#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \ 901#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
860 .base = offset, \ 902 .base = offset, \
861 .min_mV = min_mVolts, \ 903 .min_mV = min_mVolts, \
@@ -947,8 +989,8 @@ static struct twlreg_info twl_regs[] = {
947 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08), 989 TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
948 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08), 990 TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
949 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08), 991 TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
950 TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08), 992 TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08),
951 TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08), 993 TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08),
952 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08), 994 TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
953 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08), 995 TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
954 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08), 996 TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 9d5ba935759..fc665514699 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 69e550f5763..858c1f861ba 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 0f12c70bebc..71632ddc378 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/interface.c b/drivers/rtc/interface.c
index 44e91e598f8..8e286259a00 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 58d4e18530d..2322c43af20 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 57fbcc149ba..3a33b1fdbe0 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-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 568ad30617e..586c244a05d 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 fee41b97c9e..1350029044e 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 06dfb54f99b..a319402a544 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 d84a448dd75..e3e0f92b60f 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 d8e1c257855..8414dea5fb1 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 ddbc797ea6c..6186833973e 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-mrst.c b/drivers/rtc/rtc-mrst.c
index d33544802a2..bb21f443fb7 100644
--- a/drivers/rtc/rtc-mrst.c
+++ b/drivers/rtc/rtc-mrst.c
@@ -76,12 +76,15 @@ static inline unsigned char vrtc_is_updating(void)
76/* 76/*
77 * rtc_time's year contains the increment over 1900, but vRTC's YEAR 77 * rtc_time's year contains the increment over 1900, but vRTC's YEAR
78 * register can't be programmed to value larger than 0x64, so vRTC 78 * register can't be programmed to value larger than 0x64, so vRTC
79 * driver chose to use 1960 (1970 is UNIX time start point) as the base, 79 * driver chose to use 1972 (1970 is UNIX time start point) as the base,
80 * and does the translation at read/write time. 80 * and does the translation at read/write time.
81 * 81 *
82 * Why not just use 1970 as the offset? it's because using 1960 will 82 * Why not just use 1970 as the offset? it's because using 1972 will
83 * make it consistent in leap year setting for both vrtc and low-level 83 * make it consistent in leap year setting for both vrtc and low-level
84 * physical rtc devices. 84 * physical rtc devices. Then why not use 1960 as the offset? If we use
85 * 1960, for a device's first use, its YEAR register is 0 and the system
86 * year will be parsed as 1960 which is not a valid UNIX time and will
87 * cause many applications to fail mysteriously.
85 */ 88 */
86static int mrst_read_time(struct device *dev, struct rtc_time *time) 89static int mrst_read_time(struct device *dev, struct rtc_time *time)
87{ 90{
@@ -99,10 +102,10 @@ static int mrst_read_time(struct device *dev, struct rtc_time *time)
99 time->tm_year = vrtc_cmos_read(RTC_YEAR); 102 time->tm_year = vrtc_cmos_read(RTC_YEAR);
100 spin_unlock_irqrestore(&rtc_lock, flags); 103 spin_unlock_irqrestore(&rtc_lock, flags);
101 104
102 /* Adjust for the 1960/1900 */ 105 /* Adjust for the 1972/1900 */
103 time->tm_year += 60; 106 time->tm_year += 72;
104 time->tm_mon--; 107 time->tm_mon--;
105 return RTC_24H; 108 return rtc_valid_tm(time);
106} 109}
107 110
108static int mrst_set_time(struct device *dev, struct rtc_time *time) 111static int mrst_set_time(struct device *dev, struct rtc_time *time)
@@ -119,9 +122,9 @@ static int mrst_set_time(struct device *dev, struct rtc_time *time)
119 min = time->tm_min; 122 min = time->tm_min;
120 sec = time->tm_sec; 123 sec = time->tm_sec;
121 124
122 if (yrs < 70 || yrs > 138) 125 if (yrs < 72 || yrs > 138)
123 return -EINVAL; 126 return -EINVAL;
124 yrs -= 60; 127 yrs -= 72;
125 128
126 spin_lock_irqsave(&rtc_lock, flags); 129 spin_lock_irqsave(&rtc_lock, flags);
127 130
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index 60627a76451..768e2edb967 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 71bab0ef544..2ee3bbf7e5e 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 b42c0c67926..606fdfab34e 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-puv3.c b/drivers/rtc/rtc-puv3.c
index b3eba3cddd4..e4b6880aabd 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -220,7 +220,7 @@ static void puv3_rtc_enable(struct platform_device *pdev, int en)
220 } 220 }
221} 221}
222 222
223static int puv3_rtc_remove(struct platform_device *dev) 223static int __devexit puv3_rtc_remove(struct platform_device *dev)
224{ 224{
225 struct rtc_device *rtc = platform_get_drvdata(dev); 225 struct rtc_device *rtc = platform_get_drvdata(dev);
226 226
@@ -236,7 +236,7 @@ static int puv3_rtc_remove(struct platform_device *dev)
236 return 0; 236 return 0;
237} 237}
238 238
239static int puv3_rtc_probe(struct platform_device *pdev) 239static int __devinit puv3_rtc_probe(struct platform_device *pdev)
240{ 240{
241 struct rtc_device *rtc; 241 struct rtc_device *rtc;
242 struct resource *res; 242 struct resource *res;
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 368d0e63cf8..971bc8e08da 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 85c1b848dd7..d29f5432c6e 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 3b943673cd3..ed3e9b59903 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 ec6313d1535..aac0ffed434 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 b00aad2620d..8c051d3179d 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 9b43ae94beb..a5a55da2a1a 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 1f6a4d894e7..98f3e4ade92 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 f6489eb7e97..e71298158f9 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 4a51e3f0968..bd1b9c91905 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 31a3ccbb649..75bde6a8b7d 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 d291a54acfa..85f4a9a5d12 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/char/zcore.c b/drivers/s390/char/zcore.c
index 43068fbd0ba..1b6d9247fdc 100644
--- a/drivers/s390/char/zcore.c
+++ b/drivers/s390/char/zcore.c
@@ -641,6 +641,8 @@ static int __init zcore_init(void)
641 641
642 if (ipl_info.type != IPL_TYPE_FCP_DUMP) 642 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
643 return -ENODATA; 643 return -ENODATA;
644 if (OLDMEM_BASE)
645 return -ENODATA;
644 646
645 zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long)); 647 zcore_dbf = debug_register("zcore", 4, 1, 4 * sizeof(long));
646 debug_register_view(zcore_dbf, &debug_sprintf_view); 648 debug_register_view(zcore_dbf, &debug_sprintf_view);
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index 2d32233943a..e792436c927 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 ed68245f974..29021f4e96b 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 d9a46a429bc..2acc01f90a6 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/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index b77ae519d79..ec94f049e99 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -1271,18 +1271,16 @@ ap_config_timeout(unsigned long ptr)
1271} 1271}
1272 1272
1273/** 1273/**
1274 * ap_schedule_poll_timer(): Schedule poll timer. 1274 * __ap_schedule_poll_timer(): Schedule poll timer.
1275 * 1275 *
1276 * Set up the timer to run the poll tasklet 1276 * Set up the timer to run the poll tasklet
1277 */ 1277 */
1278static inline void ap_schedule_poll_timer(void) 1278static inline void __ap_schedule_poll_timer(void)
1279{ 1279{
1280 ktime_t hr_time; 1280 ktime_t hr_time;
1281 1281
1282 spin_lock_bh(&ap_poll_timer_lock); 1282 spin_lock_bh(&ap_poll_timer_lock);
1283 if (ap_using_interrupts() || ap_suspend_flag) 1283 if (hrtimer_is_queued(&ap_poll_timer) || ap_suspend_flag)
1284 goto out;
1285 if (hrtimer_is_queued(&ap_poll_timer))
1286 goto out; 1284 goto out;
1287 if (ktime_to_ns(hrtimer_expires_remaining(&ap_poll_timer)) <= 0) { 1285 if (ktime_to_ns(hrtimer_expires_remaining(&ap_poll_timer)) <= 0) {
1288 hr_time = ktime_set(0, poll_timeout); 1286 hr_time = ktime_set(0, poll_timeout);
@@ -1294,6 +1292,18 @@ out:
1294} 1292}
1295 1293
1296/** 1294/**
1295 * ap_schedule_poll_timer(): Schedule poll timer.
1296 *
1297 * Set up the timer to run the poll tasklet
1298 */
1299static inline void ap_schedule_poll_timer(void)
1300{
1301 if (ap_using_interrupts())
1302 return;
1303 __ap_schedule_poll_timer();
1304}
1305
1306/**
1297 * ap_poll_read(): Receive pending reply messages from an AP device. 1307 * ap_poll_read(): Receive pending reply messages from an AP device.
1298 * @ap_dev: pointer to the AP device 1308 * @ap_dev: pointer to the AP device
1299 * @flags: pointer to control flags, bit 2^0 is set if another poll is 1309 * @flags: pointer to control flags, bit 2^0 is set if another poll is
@@ -1374,8 +1384,9 @@ static int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags)
1374 *flags |= 1; 1384 *flags |= 1;
1375 *flags |= 2; 1385 *flags |= 2;
1376 break; 1386 break;
1377 case AP_RESPONSE_Q_FULL:
1378 case AP_RESPONSE_RESET_IN_PROGRESS: 1387 case AP_RESPONSE_RESET_IN_PROGRESS:
1388 __ap_schedule_poll_timer();
1389 case AP_RESPONSE_Q_FULL:
1379 *flags |= 2; 1390 *flags |= 2;
1380 break; 1391 break;
1381 case AP_RESPONSE_MESSAGE_TOO_BIG: 1392 case AP_RESPONSE_MESSAGE_TOO_BIG:
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 3c2c923d5c0..94f49ffa70b 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/net/Kconfig b/drivers/s390/net/Kconfig
index fa80ba1f034..9b66d2d1809 100644
--- a/drivers/s390/net/Kconfig
+++ b/drivers/s390/net/Kconfig
@@ -4,7 +4,7 @@ menu "S/390 network device drivers"
4config LCS 4config LCS
5 def_tristate m 5 def_tristate m
6 prompt "Lan Channel Station Interface" 6 prompt "Lan Channel Station Interface"
7 depends on CCW && NETDEVICES && (NET_ETHERNET || TR || FDDI) 7 depends on CCW && NETDEVICES && (ETHERNET || TR || FDDI)
8 help 8 help
9 Select this option if you want to use LCS networking on IBM System z. 9 Select this option if you want to use LCS networking on IBM System z.
10 This device driver supports Token Ring (IEEE 802.5), 10 This device driver supports Token Ring (IEEE 802.5),
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index c28713da1ec..863fc219715 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -50,7 +50,7 @@
50#include "lcs.h" 50#include "lcs.h"
51 51
52 52
53#if !defined(CONFIG_NET_ETHERNET) && \ 53#if !defined(CONFIG_ETHERNET) && \
54 !defined(CONFIG_TR) && !defined(CONFIG_FDDI) 54 !defined(CONFIG_TR) && !defined(CONFIG_FDDI)
55#error Cannot compile lcs.c without some net devices switched on. 55#error Cannot compile lcs.c without some net devices switched on.
56#endif 56#endif
@@ -1634,7 +1634,7 @@ lcs_startlan_auto(struct lcs_card *card)
1634 int rc; 1634 int rc;
1635 1635
1636 LCS_DBF_TEXT(2, trace, "strtauto"); 1636 LCS_DBF_TEXT(2, trace, "strtauto");
1637#ifdef CONFIG_NET_ETHERNET 1637#ifdef CONFIG_ETHERNET
1638 card->lan_type = LCS_FRAME_TYPE_ENET; 1638 card->lan_type = LCS_FRAME_TYPE_ENET;
1639 rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP); 1639 rc = lcs_send_startlan(card, LCS_INITIATOR_TCPIP);
1640 if (rc == 0) 1640 if (rc == 0)
@@ -2166,7 +2166,7 @@ lcs_new_device(struct ccwgroup_device *ccwgdev)
2166 goto netdev_out; 2166 goto netdev_out;
2167 } 2167 }
2168 switch (card->lan_type) { 2168 switch (card->lan_type) {
2169#ifdef CONFIG_NET_ETHERNET 2169#ifdef CONFIG_ETHERNET
2170 case LCS_FRAME_TYPE_ENET: 2170 case LCS_FRAME_TYPE_ENET:
2171 card->lan_type_trans = eth_type_trans; 2171 card->lan_type_trans = eth_type_trans;
2172 dev = alloc_etherdev(0); 2172 dev = alloc_etherdev(0);
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 3251333a23d..b6a6356d09b 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -1994,6 +1994,8 @@ static struct net_device *netiucv_init_netdevice(char *username)
1994 netiucv_setup_netdevice); 1994 netiucv_setup_netdevice);
1995 if (!dev) 1995 if (!dev)
1996 return NULL; 1996 return NULL;
1997 if (dev_alloc_name(dev, dev->name) < 0)
1998 goto out_netdev;
1997 1999
1998 privptr = netdev_priv(dev); 2000 privptr = netdev_priv(dev);
1999 privptr->fsm = init_fsm("netiucvdev", dev_state_names, 2001 privptr->fsm = init_fsm("netiucvdev", dev_state_names,
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index b77c65ed138..4abc79d3963 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -236,8 +236,7 @@ static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa,
236#define QETH_IN_BUF_COUNT_MAX 128 236#define QETH_IN_BUF_COUNT_MAX 128
237#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12) 237#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
238#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \ 238#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
239 ((card)->ssqd.qdioac1 & AC1_SIGA_INPUT_NEEDED ? 1 : \ 239 ((card)->qdio.in_buf_pool.buf_count / 2)
240 ((card)->qdio.in_buf_pool.buf_count / 2))
241 240
242/* buffers we have to be behind before we get a PCI */ 241/* buffers we have to be behind before we get a PCI */
243#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1) 242#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 81534437373..fff57de7894 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -881,7 +881,6 @@ EXPORT_SYMBOL_GPL(qeth_do_run_thread);
881void qeth_schedule_recovery(struct qeth_card *card) 881void qeth_schedule_recovery(struct qeth_card *card)
882{ 882{
883 QETH_CARD_TEXT(card, 2, "startrec"); 883 QETH_CARD_TEXT(card, 2, "startrec");
884 WARN_ON(1);
885 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0) 884 if (qeth_set_thread_start_bit(card, QETH_RECOVER_THREAD) == 0)
886 schedule_work(&card->kernel_thread_starter); 885 schedule_work(&card->kernel_thread_starter);
887} 886}
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index e4c1176ee25..4d5307ddbe5 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -2756,11 +2756,13 @@ int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2756 struct neighbour *n = NULL; 2756 struct neighbour *n = NULL;
2757 struct dst_entry *dst; 2757 struct dst_entry *dst;
2758 2758
2759 rcu_read_lock();
2759 dst = skb_dst(skb); 2760 dst = skb_dst(skb);
2760 if (dst) 2761 if (dst)
2761 n = dst_get_neighbour(dst); 2762 n = dst_get_neighbour(dst);
2762 if (n) { 2763 if (n) {
2763 cast_type = n->type; 2764 cast_type = n->type;
2765 rcu_read_unlock();
2764 if ((cast_type == RTN_BROADCAST) || 2766 if ((cast_type == RTN_BROADCAST) ||
2765 (cast_type == RTN_MULTICAST) || 2767 (cast_type == RTN_MULTICAST) ||
2766 (cast_type == RTN_ANYCAST)) 2768 (cast_type == RTN_ANYCAST))
@@ -2768,6 +2770,8 @@ int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
2768 else 2770 else
2769 return RTN_UNSPEC; 2771 return RTN_UNSPEC;
2770 } 2772 }
2773 rcu_read_unlock();
2774
2771 /* try something else */ 2775 /* try something else */
2772 if (skb->protocol == ETH_P_IPV6) 2776 if (skb->protocol == ETH_P_IPV6)
2773 return (skb_network_header(skb)[24] == 0xff) ? 2777 return (skb_network_header(skb)[24] == 0xff) ?
@@ -2847,6 +2851,8 @@ static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2847 } 2851 }
2848 2852
2849 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr); 2853 hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
2854
2855 rcu_read_lock();
2850 dst = skb_dst(skb); 2856 dst = skb_dst(skb);
2851 if (dst) 2857 if (dst)
2852 n = dst_get_neighbour(dst); 2858 n = dst_get_neighbour(dst);
@@ -2893,6 +2899,7 @@ static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2893 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU; 2899 QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
2894 } 2900 }
2895 } 2901 }
2902 rcu_read_unlock();
2896} 2903}
2897 2904
2898static inline void qeth_l3_hdr_csum(struct qeth_card *card, 2905static inline void qeth_l3_hdr_csum(struct qeth_card *card,
diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
index 0ea2fbfe0e9..d979bb26522 100644
--- a/drivers/s390/net/qeth_l3_sys.c
+++ b/drivers/s390/net/qeth_l3_sys.c
@@ -335,10 +335,10 @@ static ssize_t qeth_l3_dev_sniffer_store(struct device *dev,
335 QETH_IN_BUF_COUNT_MAX) 335 QETH_IN_BUF_COUNT_MAX)
336 qeth_realloc_buffer_pool(card, 336 qeth_realloc_buffer_pool(card,
337 QETH_IN_BUF_COUNT_MAX); 337 QETH_IN_BUF_COUNT_MAX);
338 break;
339 } else 338 } else
340 rc = -EPERM; 339 rc = -EPERM;
341 default: /* fall through */ 340 break;
341 default:
342 rc = -EINVAL; 342 rc = -EINVAL;
343 } 343 }
344out: 344out:
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 645b0fcbb37..08601810966 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 e8b7cee6204..96f13ad8812 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 967e7b70e97..a9a816e4aa5 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 df9e69f5474..e14da5751d3 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 09126a9d62f..11f07f88822 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 aa573c39f59..06ea3bcfdd2 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 1bb5d3f0e26..79a30633d4a 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 d9468027fb6..e29fe0e708f 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 06199574144..409f5805bdd 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/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 4aa76d6f11d..705e13e470a 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/moduleparam.h> 39#include <linux/moduleparam.h>
40#include <linux/pci.h> 40#include <linux/pci.h>
41#include <linux/pci-aspm.h>
41#include <linux/slab.h> 42#include <linux/slab.h>
42#include <linux/mutex.h> 43#include <linux/mutex.h>
43#include <linux/spinlock.h> 44#include <linux/spinlock.h>
@@ -1109,6 +1110,9 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
1109 unique_id++; 1110 unique_id++;
1110 } 1111 }
1111 1112
1113 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
1114 PCIE_LINK_STATE_CLKPM);
1115
1112 error = pci_enable_device(pdev); 1116 error = pci_enable_device(pdev);
1113 if (error) 1117 if (error)
1114 goto out; 1118 goto out;
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 7b0a8ab7104..379c696dac1 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 b412e0300dd..dee1a094c2c 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 01312381639..e5db649e8eb 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 63de1c7cd0c..049ea907e04 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 fd382fe33f6..ce0ce3e32f3 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 85bcc4b5596..8c6156a10d9 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 0c64d184d73..84a78af83f9 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 c363a4b260f..c10f74a566f 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 7c05fd9dccf..23149b9e297 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 627f4b5e517..4ef021291a4 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 48441f6908a..591186cf189 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 b479f1eef96..0f86a18b157 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 82d612f0c49..1d312792006 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 61384ee4049..cefbe44bb84 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 50bb54150a7..488fbc64865 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 4f7a5829ea4..351dc0b86fa 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 9825ecf3495..865d452542b 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/pci-aspm.h>
26#include <linux/kernel.h> 27#include <linux/kernel.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
@@ -48,6 +49,7 @@
48#include <linux/bitmap.h> 49#include <linux/bitmap.h>
49#include <linux/atomic.h> 50#include <linux/atomic.h>
50#include <linux/kthread.h> 51#include <linux/kthread.h>
52#include <linux/jiffies.h>
51#include "hpsa_cmd.h" 53#include "hpsa_cmd.h"
52#include "hpsa.h" 54#include "hpsa.h"
53 55
@@ -127,6 +129,10 @@ static struct board_type products[] = {
127 129
128static int number_of_controllers; 130static int number_of_controllers;
129 131
132static struct list_head hpsa_ctlr_list = LIST_HEAD_INIT(hpsa_ctlr_list);
133static spinlock_t lockup_detector_lock;
134static struct task_struct *hpsa_lockup_detector;
135
130static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); 136static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id);
131static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); 137static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id);
132static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg); 138static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg);
@@ -484,6 +490,7 @@ static struct scsi_host_template hpsa_driver_template = {
484#endif 490#endif
485 .sdev_attrs = hpsa_sdev_attrs, 491 .sdev_attrs = hpsa_sdev_attrs,
486 .shost_attrs = hpsa_shost_attrs, 492 .shost_attrs = hpsa_shost_attrs,
493 .max_sectors = 8192,
487}; 494};
488 495
489 496
@@ -566,16 +573,16 @@ static int hpsa_find_target_lun(struct ctlr_info *h,
566 * assumes h->devlock is held 573 * assumes h->devlock is held
567 */ 574 */
568 int i, found = 0; 575 int i, found = 0;
569 DECLARE_BITMAP(lun_taken, HPSA_MAX_SCSI_DEVS_PER_HBA); 576 DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES);
570 577
571 memset(&lun_taken[0], 0, HPSA_MAX_SCSI_DEVS_PER_HBA >> 3); 578 memset(&lun_taken[0], 0, HPSA_MAX_DEVICES >> 3);
572 579
573 for (i = 0; i < h->ndevices; i++) { 580 for (i = 0; i < h->ndevices; i++) {
574 if (h->dev[i]->bus == bus && h->dev[i]->target != -1) 581 if (h->dev[i]->bus == bus && h->dev[i]->target != -1)
575 set_bit(h->dev[i]->target, lun_taken); 582 set_bit(h->dev[i]->target, lun_taken);
576 } 583 }
577 584
578 for (i = 0; i < HPSA_MAX_SCSI_DEVS_PER_HBA; i++) { 585 for (i = 0; i < HPSA_MAX_DEVICES; i++) {
579 if (!test_bit(i, lun_taken)) { 586 if (!test_bit(i, lun_taken)) {
580 /* *bus = 1; */ 587 /* *bus = 1; */
581 *target = i; 588 *target = i;
@@ -598,7 +605,7 @@ static int hpsa_scsi_add_entry(struct ctlr_info *h, int hostno,
598 unsigned char addr1[8], addr2[8]; 605 unsigned char addr1[8], addr2[8];
599 struct hpsa_scsi_dev_t *sd; 606 struct hpsa_scsi_dev_t *sd;
600 607
601 if (n >= HPSA_MAX_SCSI_DEVS_PER_HBA) { 608 if (n >= HPSA_MAX_DEVICES) {
602 dev_err(&h->pdev->dev, "too many devices, some will be " 609 dev_err(&h->pdev->dev, "too many devices, some will be "
603 "inaccessible.\n"); 610 "inaccessible.\n");
604 return -1; 611 return -1;
@@ -673,7 +680,7 @@ static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno,
673 struct hpsa_scsi_dev_t *removed[], int *nremoved) 680 struct hpsa_scsi_dev_t *removed[], int *nremoved)
674{ 681{
675 /* assumes h->devlock is held */ 682 /* assumes h->devlock is held */
676 BUG_ON(entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA); 683 BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES);
677 removed[*nremoved] = h->dev[entry]; 684 removed[*nremoved] = h->dev[entry];
678 (*nremoved)++; 685 (*nremoved)++;
679 686
@@ -702,7 +709,7 @@ static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry,
702 int i; 709 int i;
703 struct hpsa_scsi_dev_t *sd; 710 struct hpsa_scsi_dev_t *sd;
704 711
705 BUG_ON(entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA); 712 BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES);
706 713
707 sd = h->dev[entry]; 714 sd = h->dev[entry];
708 removed[*nremoved] = h->dev[entry]; 715 removed[*nremoved] = h->dev[entry];
@@ -814,10 +821,8 @@ static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
814 int nadded, nremoved; 821 int nadded, nremoved;
815 struct Scsi_Host *sh = NULL; 822 struct Scsi_Host *sh = NULL;
816 823
817 added = kzalloc(sizeof(*added) * HPSA_MAX_SCSI_DEVS_PER_HBA, 824 added = kzalloc(sizeof(*added) * HPSA_MAX_DEVICES, GFP_KERNEL);
818 GFP_KERNEL); 825 removed = kzalloc(sizeof(*removed) * HPSA_MAX_DEVICES, GFP_KERNEL);
819 removed = kzalloc(sizeof(*removed) * HPSA_MAX_SCSI_DEVS_PER_HBA,
820 GFP_KERNEL);
821 826
822 if (!added || !removed) { 827 if (!added || !removed) {
823 dev_warn(&h->pdev->dev, "out of memory in " 828 dev_warn(&h->pdev->dev, "out of memory in "
@@ -1338,6 +1343,22 @@ static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h,
1338 wait_for_completion(&wait); 1343 wait_for_completion(&wait);
1339} 1344}
1340 1345
1346static void hpsa_scsi_do_simple_cmd_core_if_no_lockup(struct ctlr_info *h,
1347 struct CommandList *c)
1348{
1349 unsigned long flags;
1350
1351 /* If controller lockup detected, fake a hardware error. */
1352 spin_lock_irqsave(&h->lock, flags);
1353 if (unlikely(h->lockup_detected)) {
1354 spin_unlock_irqrestore(&h->lock, flags);
1355 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
1356 } else {
1357 spin_unlock_irqrestore(&h->lock, flags);
1358 hpsa_scsi_do_simple_cmd_core(h, c);
1359 }
1360}
1361
1341static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, 1362static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h,
1342 struct CommandList *c, int data_direction) 1363 struct CommandList *c, int data_direction)
1343{ 1364{
@@ -1735,7 +1756,6 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1735 if (is_scsi_rev_5(h)) 1756 if (is_scsi_rev_5(h))
1736 return 0; /* p1210m doesn't need to do this. */ 1757 return 0; /* p1210m doesn't need to do this. */
1737 1758
1738#define MAX_MSA2XXX_ENCLOSURES 32
1739 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) { 1759 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) {
1740 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX " 1760 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX "
1741 "enclosures exceeded. Check your hardware " 1761 "enclosures exceeded. Check your hardware "
@@ -1846,8 +1866,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1846 int raid_ctlr_position; 1866 int raid_ctlr_position;
1847 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR); 1867 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR);
1848 1868
1849 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_SCSI_DEVS_PER_HBA, 1869 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL);
1850 GFP_KERNEL);
1851 physdev_list = kzalloc(reportlunsize, GFP_KERNEL); 1870 physdev_list = kzalloc(reportlunsize, GFP_KERNEL);
1852 logdev_list = kzalloc(reportlunsize, GFP_KERNEL); 1871 logdev_list = kzalloc(reportlunsize, GFP_KERNEL);
1853 tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); 1872 tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL);
@@ -1870,6 +1889,13 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1870 1889
1871 /* Allocate the per device structures */ 1890 /* Allocate the per device structures */
1872 for (i = 0; i < ndevs_to_allocate; i++) { 1891 for (i = 0; i < ndevs_to_allocate; i++) {
1892 if (i >= HPSA_MAX_DEVICES) {
1893 dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded."
1894 " %d devices ignored.\n", HPSA_MAX_DEVICES,
1895 ndevs_to_allocate - HPSA_MAX_DEVICES);
1896 break;
1897 }
1898
1873 currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL); 1899 currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL);
1874 if (!currentsd[i]) { 1900 if (!currentsd[i]) {
1875 dev_warn(&h->pdev->dev, "out of memory at %s:%d\n", 1901 dev_warn(&h->pdev->dev, "out of memory at %s:%d\n",
@@ -1956,7 +1982,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1956 default: 1982 default:
1957 break; 1983 break;
1958 } 1984 }
1959 if (ncurrent >= HPSA_MAX_SCSI_DEVS_PER_HBA) 1985 if (ncurrent >= HPSA_MAX_DEVICES)
1960 break; 1986 break;
1961 } 1987 }
1962 adjust_hpsa_scsi_table(h, hostno, currentsd, ncurrent); 1988 adjust_hpsa_scsi_table(h, hostno, currentsd, ncurrent);
@@ -2048,8 +2074,14 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
2048 } 2074 }
2049 memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); 2075 memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr));
2050 2076
2051 /* Need a lock as this is being allocated from the pool */
2052 spin_lock_irqsave(&h->lock, flags); 2077 spin_lock_irqsave(&h->lock, flags);
2078 if (unlikely(h->lockup_detected)) {
2079 spin_unlock_irqrestore(&h->lock, flags);
2080 cmd->result = DID_ERROR << 16;
2081 done(cmd);
2082 return 0;
2083 }
2084 /* Need a lock as this is being allocated from the pool */
2053 c = cmd_alloc(h); 2085 c = cmd_alloc(h);
2054 spin_unlock_irqrestore(&h->lock, flags); 2086 spin_unlock_irqrestore(&h->lock, flags);
2055 if (c == NULL) { /* trouble... */ 2087 if (c == NULL) { /* trouble... */
@@ -2601,7 +2633,7 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2601 c->SG[0].Len = iocommand.buf_size; 2633 c->SG[0].Len = iocommand.buf_size;
2602 c->SG[0].Ext = 0; /* we are not chaining*/ 2634 c->SG[0].Ext = 0; /* we are not chaining*/
2603 } 2635 }
2604 hpsa_scsi_do_simple_cmd_core(h, c); 2636 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c);
2605 if (iocommand.buf_size > 0) 2637 if (iocommand.buf_size > 0)
2606 hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL); 2638 hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL);
2607 check_ioctl_unit_attention(h, c); 2639 check_ioctl_unit_attention(h, c);
@@ -2724,7 +2756,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2724 c->SG[i].Ext = 0; 2756 c->SG[i].Ext = 0;
2725 } 2757 }
2726 } 2758 }
2727 hpsa_scsi_do_simple_cmd_core(h, c); 2759 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c);
2728 if (sg_used) 2760 if (sg_used)
2729 hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); 2761 hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL);
2730 check_ioctl_unit_attention(h, c); 2762 check_ioctl_unit_attention(h, c);
@@ -2872,6 +2904,8 @@ static void fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
2872 c->Request.Timeout = 0; 2904 c->Request.Timeout = 0;
2873 c->Request.CDB[0] = BMIC_WRITE; 2905 c->Request.CDB[0] = BMIC_WRITE;
2874 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 2906 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
2907 c->Request.CDB[7] = (size >> 8) & 0xFF;
2908 c->Request.CDB[8] = size & 0xFF;
2875 break; 2909 break;
2876 case TEST_UNIT_READY: 2910 case TEST_UNIT_READY:
2877 c->Request.CDBLen = 6; 2911 c->Request.CDBLen = 6;
@@ -3091,6 +3125,7 @@ static irqreturn_t hpsa_intx_discard_completions(int irq, void *dev_id)
3091 if (interrupt_not_for_us(h)) 3125 if (interrupt_not_for_us(h))
3092 return IRQ_NONE; 3126 return IRQ_NONE;
3093 spin_lock_irqsave(&h->lock, flags); 3127 spin_lock_irqsave(&h->lock, flags);
3128 h->last_intr_timestamp = get_jiffies_64();
3094 while (interrupt_pending(h)) { 3129 while (interrupt_pending(h)) {
3095 raw_tag = get_next_completion(h); 3130 raw_tag = get_next_completion(h);
3096 while (raw_tag != FIFO_EMPTY) 3131 while (raw_tag != FIFO_EMPTY)
@@ -3110,6 +3145,7 @@ static irqreturn_t hpsa_msix_discard_completions(int irq, void *dev_id)
3110 return IRQ_NONE; 3145 return IRQ_NONE;
3111 3146
3112 spin_lock_irqsave(&h->lock, flags); 3147 spin_lock_irqsave(&h->lock, flags);
3148 h->last_intr_timestamp = get_jiffies_64();
3113 raw_tag = get_next_completion(h); 3149 raw_tag = get_next_completion(h);
3114 while (raw_tag != FIFO_EMPTY) 3150 while (raw_tag != FIFO_EMPTY)
3115 raw_tag = next_command(h); 3151 raw_tag = next_command(h);
@@ -3126,6 +3162,7 @@ static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id)
3126 if (interrupt_not_for_us(h)) 3162 if (interrupt_not_for_us(h))
3127 return IRQ_NONE; 3163 return IRQ_NONE;
3128 spin_lock_irqsave(&h->lock, flags); 3164 spin_lock_irqsave(&h->lock, flags);
3165 h->last_intr_timestamp = get_jiffies_64();
3129 while (interrupt_pending(h)) { 3166 while (interrupt_pending(h)) {
3130 raw_tag = get_next_completion(h); 3167 raw_tag = get_next_completion(h);
3131 while (raw_tag != FIFO_EMPTY) { 3168 while (raw_tag != FIFO_EMPTY) {
@@ -3146,6 +3183,7 @@ static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id)
3146 u32 raw_tag; 3183 u32 raw_tag;
3147 3184
3148 spin_lock_irqsave(&h->lock, flags); 3185 spin_lock_irqsave(&h->lock, flags);
3186 h->last_intr_timestamp = get_jiffies_64();
3149 raw_tag = get_next_completion(h); 3187 raw_tag = get_next_completion(h);
3150 while (raw_tag != FIFO_EMPTY) { 3188 while (raw_tag != FIFO_EMPTY) {
3151 if (hpsa_tag_contains_index(raw_tag)) 3189 if (hpsa_tag_contains_index(raw_tag))
@@ -3300,6 +3338,13 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,
3300 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 3338 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
3301 pmcsr |= PCI_D0; 3339 pmcsr |= PCI_D0;
3302 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); 3340 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
3341
3342 /*
3343 * The P600 requires a small delay when changing states.
3344 * Otherwise we may think the board did not reset and we bail.
3345 * This for kdump only and is particular to the P600.
3346 */
3347 msleep(500);
3303 } 3348 }
3304 return 0; 3349 return 0;
3305} 3350}
@@ -3878,6 +3923,10 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
3878 dev_warn(&h->pdev->dev, "controller appears to be disabled\n"); 3923 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
3879 return -ENODEV; 3924 return -ENODEV;
3880 } 3925 }
3926
3927 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
3928 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
3929
3881 err = pci_enable_device(h->pdev); 3930 err = pci_enable_device(h->pdev);
3882 if (err) { 3931 if (err) {
3883 dev_warn(&h->pdev->dev, "unable to enable PCI device\n"); 3932 dev_warn(&h->pdev->dev, "unable to enable PCI device\n");
@@ -4083,6 +4132,149 @@ static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h)
4083 kfree(h); 4132 kfree(h);
4084} 4133}
4085 4134
4135static void remove_ctlr_from_lockup_detector_list(struct ctlr_info *h)
4136{
4137 assert_spin_locked(&lockup_detector_lock);
4138 if (!hpsa_lockup_detector)
4139 return;
4140 if (h->lockup_detected)
4141 return; /* already stopped the lockup detector */
4142 list_del(&h->lockup_list);
4143}
4144
4145/* Called when controller lockup detected. */
4146static void fail_all_cmds_on_list(struct ctlr_info *h, struct list_head *list)
4147{
4148 struct CommandList *c = NULL;
4149
4150 assert_spin_locked(&h->lock);
4151 /* Mark all outstanding commands as failed and complete them. */
4152 while (!list_empty(list)) {
4153 c = list_entry(list->next, struct CommandList, list);
4154 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
4155 finish_cmd(c, c->Header.Tag.lower);
4156 }
4157}
4158
4159static void controller_lockup_detected(struct ctlr_info *h)
4160{
4161 unsigned long flags;
4162
4163 assert_spin_locked(&lockup_detector_lock);
4164 remove_ctlr_from_lockup_detector_list(h);
4165 h->access.set_intr_mask(h, HPSA_INTR_OFF);
4166 spin_lock_irqsave(&h->lock, flags);
4167 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
4168 spin_unlock_irqrestore(&h->lock, flags);
4169 dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n",
4170 h->lockup_detected);
4171 pci_disable_device(h->pdev);
4172 spin_lock_irqsave(&h->lock, flags);
4173 fail_all_cmds_on_list(h, &h->cmpQ);
4174 fail_all_cmds_on_list(h, &h->reqQ);
4175 spin_unlock_irqrestore(&h->lock, flags);
4176}
4177
4178#define HEARTBEAT_SAMPLE_INTERVAL (10 * HZ)
4179#define HEARTBEAT_CHECK_MINIMUM_INTERVAL (HEARTBEAT_SAMPLE_INTERVAL / 2)
4180
4181static void detect_controller_lockup(struct ctlr_info *h)
4182{
4183 u64 now;
4184 u32 heartbeat;
4185 unsigned long flags;
4186
4187 assert_spin_locked(&lockup_detector_lock);
4188 now = get_jiffies_64();
4189 /* If we've received an interrupt recently, we're ok. */
4190 if (time_after64(h->last_intr_timestamp +
4191 (HEARTBEAT_CHECK_MINIMUM_INTERVAL), now))
4192 return;
4193
4194 /*
4195 * If we've already checked the heartbeat recently, we're ok.
4196 * This could happen if someone sends us a signal. We
4197 * otherwise don't care about signals in this thread.
4198 */
4199 if (time_after64(h->last_heartbeat_timestamp +
4200 (HEARTBEAT_CHECK_MINIMUM_INTERVAL), now))
4201 return;
4202
4203 /* If heartbeat has not changed since we last looked, we're not ok. */
4204 spin_lock_irqsave(&h->lock, flags);
4205 heartbeat = readl(&h->cfgtable->HeartBeat);
4206 spin_unlock_irqrestore(&h->lock, flags);
4207 if (h->last_heartbeat == heartbeat) {
4208 controller_lockup_detected(h);
4209 return;
4210 }
4211
4212 /* We're ok. */
4213 h->last_heartbeat = heartbeat;
4214 h->last_heartbeat_timestamp = now;
4215}
4216
4217static int detect_controller_lockup_thread(void *notused)
4218{
4219 struct ctlr_info *h;
4220 unsigned long flags;
4221
4222 while (1) {
4223 struct list_head *this, *tmp;
4224
4225 schedule_timeout_interruptible(HEARTBEAT_SAMPLE_INTERVAL);
4226 if (kthread_should_stop())
4227 break;
4228 spin_lock_irqsave(&lockup_detector_lock, flags);
4229 list_for_each_safe(this, tmp, &hpsa_ctlr_list) {
4230 h = list_entry(this, struct ctlr_info, lockup_list);
4231 detect_controller_lockup(h);
4232 }
4233 spin_unlock_irqrestore(&lockup_detector_lock, flags);
4234 }
4235 return 0;
4236}
4237
4238static void add_ctlr_to_lockup_detector_list(struct ctlr_info *h)
4239{
4240 unsigned long flags;
4241
4242 spin_lock_irqsave(&lockup_detector_lock, flags);
4243 list_add_tail(&h->lockup_list, &hpsa_ctlr_list);
4244 spin_unlock_irqrestore(&lockup_detector_lock, flags);
4245}
4246
4247static void start_controller_lockup_detector(struct ctlr_info *h)
4248{
4249 /* Start the lockup detector thread if not already started */
4250 if (!hpsa_lockup_detector) {
4251 spin_lock_init(&lockup_detector_lock);
4252 hpsa_lockup_detector =
4253 kthread_run(detect_controller_lockup_thread,
4254 NULL, "hpsa");
4255 }
4256 if (!hpsa_lockup_detector) {
4257 dev_warn(&h->pdev->dev,
4258 "Could not start lockup detector thread\n");
4259 return;
4260 }
4261 add_ctlr_to_lockup_detector_list(h);
4262}
4263
4264static void stop_controller_lockup_detector(struct ctlr_info *h)
4265{
4266 unsigned long flags;
4267
4268 spin_lock_irqsave(&lockup_detector_lock, flags);
4269 remove_ctlr_from_lockup_detector_list(h);
4270 /* If the list of ctlr's to monitor is empty, stop the thread */
4271 if (list_empty(&hpsa_ctlr_list)) {
4272 kthread_stop(hpsa_lockup_detector);
4273 hpsa_lockup_detector = NULL;
4274 }
4275 spin_unlock_irqrestore(&lockup_detector_lock, flags);
4276}
4277
4086static int __devinit hpsa_init_one(struct pci_dev *pdev, 4278static int __devinit hpsa_init_one(struct pci_dev *pdev,
4087 const struct pci_device_id *ent) 4279 const struct pci_device_id *ent)
4088{ 4280{
@@ -4120,7 +4312,6 @@ reinit_after_soft_reset:
4120 return -ENOMEM; 4312 return -ENOMEM;
4121 4313
4122 h->pdev = pdev; 4314 h->pdev = pdev;
4123 h->busy_initializing = 1;
4124 h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT; 4315 h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
4125 INIT_LIST_HEAD(&h->cmpQ); 4316 INIT_LIST_HEAD(&h->cmpQ);
4126 INIT_LIST_HEAD(&h->reqQ); 4317 INIT_LIST_HEAD(&h->reqQ);
@@ -4229,7 +4420,7 @@ reinit_after_soft_reset:
4229 4420
4230 hpsa_hba_inquiry(h); 4421 hpsa_hba_inquiry(h);
4231 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */ 4422 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
4232 h->busy_initializing = 0; 4423 start_controller_lockup_detector(h);
4233 return 1; 4424 return 1;
4234 4425
4235clean4: 4426clean4:
@@ -4238,7 +4429,6 @@ clean4:
4238 free_irq(h->intr[h->intr_mode], h); 4429 free_irq(h->intr[h->intr_mode], h);
4239clean2: 4430clean2:
4240clean1: 4431clean1:
4241 h->busy_initializing = 0;
4242 kfree(h); 4432 kfree(h);
4243 return rc; 4433 return rc;
4244} 4434}
@@ -4293,10 +4483,11 @@ static void __devexit hpsa_remove_one(struct pci_dev *pdev)
4293 struct ctlr_info *h; 4483 struct ctlr_info *h;
4294 4484
4295 if (pci_get_drvdata(pdev) == NULL) { 4485 if (pci_get_drvdata(pdev) == NULL) {
4296 dev_err(&pdev->dev, "unable to remove device \n"); 4486 dev_err(&pdev->dev, "unable to remove device\n");
4297 return; 4487 return;
4298 } 4488 }
4299 h = pci_get_drvdata(pdev); 4489 h = pci_get_drvdata(pdev);
4490 stop_controller_lockup_detector(h);
4300 hpsa_unregister_scsi(h); /* unhook from SCSI subsystem */ 4491 hpsa_unregister_scsi(h); /* unhook from SCSI subsystem */
4301 hpsa_shutdown(pdev); 4492 hpsa_shutdown(pdev);
4302 iounmap(h->vaddr); 4493 iounmap(h->vaddr);
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 7f53ceaa723..91edafb8c7e 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 55d741b019d..3fd4715935c 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 73e24b48dce..fd860d952b2 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 6d257e0dd6a..ac84736c1b9 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 f07f30fada1..e7fe9c4c85b 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 43fe840fbe9..a97edabcb85 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 8e59c8865dc..ac7f27749f9 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 b50ecd4e8f9..cb5ffbc3860 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 dc007e692f4..2c75248ca32 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 fbf9ce28c3f..b207cd3b15a 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 e1747ea0d0e..483ee50152f 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 565a9f0a9bc..192cb48d849 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 f720b97b7bb..be38933dd6d 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 e2d9418683c..66ad3dc8949 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 15b18d15899..bc78c0a41d5 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 23e706673d0..7c34d8e7cc7 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 b9cb8140b39..7269e928824 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 9b25969e2ad..fb9161dc4ca 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 7c055fdca45..9de9db27e87 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 b7735129f1f..1bf9841ef15 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 628f347404f..e77094a587e 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 f33b897e478..9fbf78ed821 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 760db761944..b9e434844a6 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 d7c76f2eb63..143bbe448be 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 09b232fd9a1..5715a3d0a3d 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 e1aa17840c5..bb8f49269a6 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 b2c4a773165..b6e233d9a0a 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 b13a3346894..a78e5bd3e51 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 ff6a28ce9b6..0707ecdbaa3 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 4b0333ee2d9..d0ebaeb7ef6 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 2cd844f7058..28382596fb9 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 907c94b9245..55bc4fc7376 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 5b8790b3cf4..2e1e54e5c3a 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 6c42dff0f4d..e6173376605 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 8883ca36f93..35bd13879fe 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 3105d5e8d90..8dc1b32918d 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 61475a6480e..cfd95b4e300 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 1f0c190d336..93d9b6956d0 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 81209ca8727..beda04a8404 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 59354dba68c..3c3babc7d26 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 2b1101076cf..36ea0b2d802 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 9adb0133d6f..aabcb911706 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 1da1aa1a11e..4e041f6d808 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,43 @@ _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)
2804 return;
2805
2806 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2807 if (!fw_event)
2728 return; 2808 return;
2809
2810 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2811 fw_event->ioc = ioc;
2812 _scsih_fw_event_add(ioc, fw_event);
2813}
2814
2815/**
2816 * mpt2sas_port_enable_complete - port enable completed (fake event)
2817 * @ioc: per adapter object
2818 *
2819 * Return nothing.
2820 */
2821void
2822mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2823{
2824 struct fw_event_work *fw_event;
2825
2729 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); 2826 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2730 if (!fw_event) 2827 if (!fw_event)
2731 return; 2828 return;
2732 fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET; 2829 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2733 fw_event->ioc = ioc; 2830 fw_event->ioc = ioc;
2734 _scsih_fw_event_add(ioc, fw_event); 2831 _scsih_fw_event_add(ioc, fw_event);
2735} 2832}
@@ -2977,14 +3074,27 @@ _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2977 Mpi2SCSITaskManagementRequest_t *mpi_request; 3074 Mpi2SCSITaskManagementRequest_t *mpi_request;
2978 u16 smid; 3075 u16 smid;
2979 struct _sas_device *sas_device; 3076 struct _sas_device *sas_device;
2980 struct MPT2SAS_TARGET *sas_target_priv_data; 3077 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3078 u64 sas_address = 0;
2981 unsigned long flags; 3079 unsigned long flags;
2982 struct _tr_list *delayed_tr; 3080 struct _tr_list *delayed_tr;
3081 u32 ioc_state;
2983 3082
2984 if (ioc->shost_recovery || ioc->remove_host || 3083 if (ioc->remove_host) {
2985 ioc->pci_error_recovery) { 3084 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
2986 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " 3085 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
2987 "progress!\n", __func__, ioc->name)); 3086 return;
3087 } else if (ioc->pci_error_recovery) {
3088 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3089 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3090 handle));
3091 return;
3092 }
3093 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3094 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3095 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3096 "operational: handle(0x%04x)\n", __func__, ioc->name,
3097 handle));
2988 return; 3098 return;
2989 } 3099 }
2990 3100
@@ -2998,13 +3108,18 @@ _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2998 sas_device->starget->hostdata) { 3108 sas_device->starget->hostdata) {
2999 sas_target_priv_data = sas_device->starget->hostdata; 3109 sas_target_priv_data = sas_device->starget->hostdata;
3000 sas_target_priv_data->deleted = 1; 3110 sas_target_priv_data->deleted = 1;
3001 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT 3111 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 } 3112 }
3006 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 3113 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3007 3114
3115 if (sas_target_priv_data) {
3116 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3117 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3118 (unsigned long long)sas_address));
3119 _scsih_ublock_io_device(ioc, handle);
3120 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3121 }
3122
3008 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); 3123 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3009 if (!smid) { 3124 if (!smid) {
3010 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); 3125 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
@@ -3185,11 +3300,21 @@ _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3185 mpt2sas_base_get_reply_virt_addr(ioc, reply); 3300 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3186 Mpi2SasIoUnitControlRequest_t *mpi_request; 3301 Mpi2SasIoUnitControlRequest_t *mpi_request;
3187 u16 smid_sas_ctrl; 3302 u16 smid_sas_ctrl;
3303 u32 ioc_state;
3188 3304
3189 if (ioc->shost_recovery || ioc->remove_host || 3305 if (ioc->remove_host) {
3190 ioc->pci_error_recovery) { 3306 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3191 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " 3307 "removed\n", __func__, ioc->name));
3192 "progress!\n", __func__, ioc->name)); 3308 return 1;
3309 } else if (ioc->pci_error_recovery) {
3310 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3311 "error recovery\n", __func__, ioc->name));
3312 return 1;
3313 }
3314 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3315 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3316 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3317 "operational\n", __func__, ioc->name));
3193 return 1; 3318 return 1;
3194 } 3319 }
3195 3320
@@ -5099,7 +5224,7 @@ _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5099 /* get device name */ 5224 /* get device name */
5100 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); 5225 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5101 5226
5102 if (ioc->wait_for_port_enable_to_complete) 5227 if (ioc->wait_for_discovery_to_complete)
5103 _scsih_sas_device_init_add(ioc, sas_device); 5228 _scsih_sas_device_init_add(ioc, sas_device);
5104 else 5229 else
5105 _scsih_sas_device_add(ioc, sas_device); 5230 _scsih_sas_device_add(ioc, sas_device);
@@ -5135,6 +5260,9 @@ _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5135 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) { 5260 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5136 sas_target_priv_data = sas_device_backup.starget->hostdata; 5261 sas_target_priv_data = sas_device_backup.starget->hostdata;
5137 sas_target_priv_data->deleted = 1; 5262 sas_target_priv_data->deleted = 1;
5263 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5264 sas_target_priv_data->handle =
5265 MPT2SAS_INVALID_DEVICE_HANDLE;
5138 } 5266 }
5139 5267
5140 _scsih_ublock_io_device(ioc, sas_device_backup.handle); 5268 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
@@ -5288,7 +5416,7 @@ _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5288 _scsih_sas_topology_change_event_debug(ioc, event_data); 5416 _scsih_sas_topology_change_event_debug(ioc, event_data);
5289#endif 5417#endif
5290 5418
5291 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) 5419 if (ioc->remove_host || ioc->pci_error_recovery)
5292 return; 5420 return;
5293 5421
5294 if (!ioc->sas_hba.num_phys) 5422 if (!ioc->sas_hba.num_phys)
@@ -5349,6 +5477,9 @@ _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5349 switch (reason_code) { 5477 switch (reason_code) {
5350 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: 5478 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5351 5479
5480 if (ioc->shost_recovery)
5481 break;
5482
5352 if (link_rate == prev_link_rate) 5483 if (link_rate == prev_link_rate)
5353 break; 5484 break;
5354 5485
@@ -5362,6 +5493,9 @@ _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5362 break; 5493 break;
5363 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: 5494 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5364 5495
5496 if (ioc->shost_recovery)
5497 break;
5498
5365 mpt2sas_transport_update_links(ioc, sas_address, 5499 mpt2sas_transport_update_links(ioc, sas_address,
5366 handle, phy_number, link_rate); 5500 handle, phy_number, link_rate);
5367 5501
@@ -5622,7 +5756,7 @@ broadcast_aen_retry:
5622 termination_count = 0; 5756 termination_count = 0;
5623 query_count = 0; 5757 query_count = 0;
5624 for (smid = 1; smid <= ioc->scsiio_depth; smid++) { 5758 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5625 if (ioc->ioc_reset_in_progress_status) 5759 if (ioc->shost_recovery)
5626 goto out; 5760 goto out;
5627 scmd = _scsih_scsi_lookup_get(ioc, smid); 5761 scmd = _scsih_scsi_lookup_get(ioc, smid);
5628 if (!scmd) 5762 if (!scmd)
@@ -5644,7 +5778,7 @@ broadcast_aen_retry:
5644 lun = sas_device_priv_data->lun; 5778 lun = sas_device_priv_data->lun;
5645 query_count++; 5779 query_count++;
5646 5780
5647 if (ioc->ioc_reset_in_progress_status) 5781 if (ioc->shost_recovery)
5648 goto out; 5782 goto out;
5649 5783
5650 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 5784 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
@@ -5686,7 +5820,7 @@ broadcast_aen_retry:
5686 goto broadcast_aen_retry; 5820 goto broadcast_aen_retry;
5687 } 5821 }
5688 5822
5689 if (ioc->ioc_reset_in_progress_status) 5823 if (ioc->shost_recovery)
5690 goto out_no_lock; 5824 goto out_no_lock;
5691 5825
5692 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, 5826 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
@@ -5725,7 +5859,7 @@ broadcast_aen_retry:
5725 ioc->name, __func__, query_count, termination_count)); 5859 ioc->name, __func__, query_count, termination_count));
5726 5860
5727 ioc->broadcast_aen_busy = 0; 5861 ioc->broadcast_aen_busy = 0;
5728 if (!ioc->ioc_reset_in_progress_status) 5862 if (!ioc->shost_recovery)
5729 _scsih_ublock_io_all_device(ioc); 5863 _scsih_ublock_io_all_device(ioc);
5730 mutex_unlock(&ioc->tm_cmds.mutex); 5864 mutex_unlock(&ioc->tm_cmds.mutex);
5731} 5865}
@@ -5789,8 +5923,11 @@ _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5789static void 5923static void
5790_scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach) 5924_scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5791{ 5925{
5792 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata; 5926 struct MPT2SAS_TARGET *sas_target_priv_data;
5793 5927
5928 if (starget == NULL)
5929 return;
5930 sas_target_priv_data = starget->hostdata;
5794 if (no_uld_attach) 5931 if (no_uld_attach)
5795 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 5932 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5796 else 5933 else
@@ -5845,7 +5982,7 @@ _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5845 raid_device->handle = handle; 5982 raid_device->handle = handle;
5846 raid_device->wwid = wwid; 5983 raid_device->wwid = wwid;
5847 _scsih_raid_device_add(ioc, raid_device); 5984 _scsih_raid_device_add(ioc, raid_device);
5848 if (!ioc->wait_for_port_enable_to_complete) { 5985 if (!ioc->wait_for_discovery_to_complete) {
5849 rc = scsi_add_device(ioc->shost, RAID_CHANNEL, 5986 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5850 raid_device->id, 0); 5987 raid_device->id, 0);
5851 if (rc) 5988 if (rc)
@@ -6127,6 +6264,10 @@ _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6127 _scsih_sas_ir_config_change_event_debug(ioc, event_data); 6264 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6128 6265
6129#endif 6266#endif
6267
6268 if (ioc->shost_recovery)
6269 return;
6270
6130 foreign_config = (le32_to_cpu(event_data->Flags) & 6271 foreign_config = (le32_to_cpu(event_data->Flags) &
6131 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; 6272 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6132 6273
@@ -6185,6 +6326,9 @@ _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6185 int rc; 6326 int rc;
6186 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; 6327 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6187 6328
6329 if (ioc->shost_recovery)
6330 return;
6331
6188 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) 6332 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6189 return; 6333 return;
6190 6334
@@ -6267,6 +6411,9 @@ _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6267 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; 6411 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6268 u64 sas_address; 6412 u64 sas_address;
6269 6413
6414 if (ioc->shost_recovery)
6415 return;
6416
6270 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) 6417 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6271 return; 6418 return;
6272 6419
@@ -6510,10 +6657,10 @@ _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6510 u32 device_info; 6657 u32 device_info;
6511 u16 slot; 6658 u16 slot;
6512 6659
6513 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); 6660 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6514 6661
6515 if (list_empty(&ioc->sas_device_list)) 6662 if (list_empty(&ioc->sas_device_list))
6516 return; 6663 goto out;
6517 6664
6518 handle = 0xFFFF; 6665 handle = 0xFFFF;
6519 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, 6666 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
@@ -6532,6 +6679,9 @@ _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6532 _scsih_mark_responding_sas_device(ioc, sas_address, slot, 6679 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6533 handle); 6680 handle);
6534 } 6681 }
6682out:
6683 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6684 ioc->name);
6535} 6685}
6536 6686
6537/** 6687/**
@@ -6607,10 +6757,14 @@ _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6607 u16 handle; 6757 u16 handle;
6608 u8 phys_disk_num; 6758 u8 phys_disk_num;
6609 6759
6610 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); 6760 if (!ioc->ir_firmware)
6761 return;
6762
6763 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6764 ioc->name);
6611 6765
6612 if (list_empty(&ioc->raid_device_list)) 6766 if (list_empty(&ioc->raid_device_list))
6613 return; 6767 goto out;
6614 6768
6615 handle = 0xFFFF; 6769 handle = 0xFFFF;
6616 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, 6770 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
@@ -6649,6 +6803,9 @@ _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6649 set_bit(handle, ioc->pd_handles); 6803 set_bit(handle, ioc->pd_handles);
6650 } 6804 }
6651 } 6805 }
6806out:
6807 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6808 "complete\n", ioc->name);
6652} 6809}
6653 6810
6654/** 6811/**
@@ -6708,10 +6865,10 @@ _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6708 u64 sas_address; 6865 u64 sas_address;
6709 u16 handle; 6866 u16 handle;
6710 6867
6711 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); 6868 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6712 6869
6713 if (list_empty(&ioc->sas_expander_list)) 6870 if (list_empty(&ioc->sas_expander_list))
6714 return; 6871 goto out;
6715 6872
6716 handle = 0xFFFF; 6873 handle = 0xFFFF;
6717 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, 6874 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
@@ -6730,6 +6887,8 @@ _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6730 _scsih_mark_responding_expander(ioc, sas_address, handle); 6887 _scsih_mark_responding_expander(ioc, sas_address, handle);
6731 } 6888 }
6732 6889
6890 out:
6891 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6733} 6892}
6734 6893
6735/** 6894/**
@@ -6745,6 +6904,8 @@ _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6745 struct _sas_node *sas_expander; 6904 struct _sas_node *sas_expander;
6746 struct _raid_device *raid_device, *raid_device_next; 6905 struct _raid_device *raid_device, *raid_device_next;
6747 6906
6907 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6908 ioc->name);
6748 6909
6749 list_for_each_entry_safe(sas_device, sas_device_next, 6910 list_for_each_entry_safe(sas_device, sas_device_next,
6750 &ioc->sas_device_list, list) { 6911 &ioc->sas_device_list, list) {
@@ -6764,6 +6925,9 @@ _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6764 _scsih_remove_device(ioc, sas_device); 6925 _scsih_remove_device(ioc, sas_device);
6765 } 6926 }
6766 6927
6928 if (!ioc->ir_firmware)
6929 goto retry_expander_search;
6930
6767 list_for_each_entry_safe(raid_device, raid_device_next, 6931 list_for_each_entry_safe(raid_device, raid_device_next,
6768 &ioc->raid_device_list, list) { 6932 &ioc->raid_device_list, list) {
6769 if (raid_device->responding) { 6933 if (raid_device->responding) {
@@ -6790,52 +6954,170 @@ _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6790 mpt2sas_expander_remove(ioc, sas_expander->sas_address); 6954 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6791 goto retry_expander_search; 6955 goto retry_expander_search;
6792 } 6956 }
6957 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6958 ioc->name);
6959 /* unblock devices */
6960 _scsih_ublock_io_all_device(ioc);
6961}
6962
6963static void
6964_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6965 struct _sas_node *sas_expander, u16 handle)
6966{
6967 Mpi2ExpanderPage1_t expander_pg1;
6968 Mpi2ConfigReply_t mpi_reply;
6969 int i;
6970
6971 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6972 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6973 &expander_pg1, i, handle))) {
6974 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6975 ioc->name, __FILE__, __LINE__, __func__);
6976 return;
6977 }
6978
6979 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6980 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6981 expander_pg1.NegotiatedLinkRate >> 4);
6982 }
6793} 6983}
6794 6984
6795/** 6985/**
6796 * _scsih_hide_unhide_sas_devices - add/remove device to/from OS 6986 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6797 * @ioc: per adapter object 6987 * @ioc: per adapter object
6798 * 6988 *
6799 * Return nothing. 6989 * Return nothing.
6800 */ 6990 */
6801static void 6991static void
6802_scsih_hide_unhide_sas_devices(struct MPT2SAS_ADAPTER *ioc) 6992_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
6803{ 6993{
6804 struct _sas_device *sas_device, *sas_device_next; 6994 Mpi2ExpanderPage0_t expander_pg0;
6995 Mpi2SasDevicePage0_t sas_device_pg0;
6996 Mpi2RaidVolPage1_t volume_pg1;
6997 Mpi2RaidVolPage0_t volume_pg0;
6998 Mpi2RaidPhysDiskPage0_t pd_pg0;
6999 Mpi2EventIrConfigElement_t element;
7000 Mpi2ConfigReply_t mpi_reply;
7001 u8 phys_disk_num;
7002 u16 ioc_status;
7003 u16 handle, parent_handle;
7004 u64 sas_address;
7005 struct _sas_device *sas_device;
7006 struct _sas_node *expander_device;
7007 static struct _raid_device *raid_device;
6805 7008
6806 if (!ioc->is_warpdrive || ioc->mfg_pg10_hide_flag != 7009 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
6807 MFG_PAGE10_HIDE_IF_VOL_PRESENT)
6808 return;
6809 7010
6810 if (ioc->hide_drives) { 7011 _scsih_sas_host_refresh(ioc);
6811 if (_scsih_get_num_volumes(ioc)) 7012
6812 return; 7013 /* expanders */
6813 ioc->hide_drives = 0; 7014 handle = 0xFFFF;
6814 list_for_each_entry_safe(sas_device, sas_device_next, 7015 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6815 &ioc->sas_device_list, list) { 7016 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6816 if (!mpt2sas_transport_port_add(ioc, sas_device->handle, 7017 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6817 sas_device->sas_address_parent)) { 7018 MPI2_IOCSTATUS_MASK;
6818 _scsih_sas_device_remove(ioc, sas_device); 7019 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6819 } else if (!sas_device->starget) { 7020 break;
6820 mpt2sas_transport_port_remove(ioc, 7021 handle = le16_to_cpu(expander_pg0.DevHandle);
6821 sas_device->sas_address, 7022 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
6822 sas_device->sas_address_parent); 7023 ioc, le64_to_cpu(expander_pg0.SASAddress));
6823 _scsih_sas_device_remove(ioc, sas_device); 7024 if (expander_device)
6824 } 7025 _scsih_refresh_expander_links(ioc, expander_device,
7026 handle);
7027 else
7028 _scsih_expander_add(ioc, handle);
7029 }
7030
7031 if (!ioc->ir_firmware)
7032 goto skip_to_sas;
7033
7034 /* phys disk */
7035 phys_disk_num = 0xFF;
7036 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7037 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7038 phys_disk_num))) {
7039 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7040 MPI2_IOCSTATUS_MASK;
7041 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7042 break;
7043 phys_disk_num = pd_pg0.PhysDiskNum;
7044 handle = le16_to_cpu(pd_pg0.DevHandle);
7045 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7046 if (sas_device)
7047 continue;
7048 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7049 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7050 handle) != 0)
7051 continue;
7052 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7053 if (!_scsih_get_sas_address(ioc, parent_handle,
7054 &sas_address)) {
7055 mpt2sas_transport_update_links(ioc, sas_address,
7056 handle, sas_device_pg0.PhyNum,
7057 MPI2_SAS_NEG_LINK_RATE_1_5);
7058 set_bit(handle, ioc->pd_handles);
7059 _scsih_add_device(ioc, handle, 0, 1);
6825 } 7060 }
6826 } else { 7061 }
6827 if (!_scsih_get_num_volumes(ioc)) 7062
6828 return; 7063 /* volumes */
6829 ioc->hide_drives = 1; 7064 handle = 0xFFFF;
6830 list_for_each_entry_safe(sas_device, sas_device_next, 7065 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6831 &ioc->sas_device_list, list) { 7066 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6832 mpt2sas_transport_port_remove(ioc, 7067 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6833 sas_device->sas_address, 7068 MPI2_IOCSTATUS_MASK;
6834 sas_device->sas_address_parent); 7069 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7070 break;
7071 handle = le16_to_cpu(volume_pg1.DevHandle);
7072 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7073 le64_to_cpu(volume_pg1.WWID));
7074 if (raid_device)
7075 continue;
7076 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7077 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7078 sizeof(Mpi2RaidVolPage0_t)))
7079 continue;
7080 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7081 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7082 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7083 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7084 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7085 element.VolDevHandle = volume_pg1.DevHandle;
7086 _scsih_sas_volume_add(ioc, &element);
6835 } 7087 }
6836 } 7088 }
7089
7090 skip_to_sas:
7091
7092 /* sas devices */
7093 handle = 0xFFFF;
7094 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7095 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7096 handle))) {
7097 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7098 MPI2_IOCSTATUS_MASK;
7099 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7100 break;
7101 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7102 if (!(_scsih_is_end_device(
7103 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7104 continue;
7105 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7106 le64_to_cpu(sas_device_pg0.SASAddress));
7107 if (sas_device)
7108 continue;
7109 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7110 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7111 mpt2sas_transport_update_links(ioc, sas_address, handle,
7112 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7113 _scsih_add_device(ioc, handle, 0, 0);
7114 }
7115 }
7116
7117 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
6837} 7118}
6838 7119
7120
6839/** 7121/**
6840 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) 7122 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6841 * @ioc: per adapter object 7123 * @ioc: per adapter object
@@ -6871,7 +7153,6 @@ mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
6871 } 7153 }
6872 _scsih_fw_event_cleanup_queue(ioc); 7154 _scsih_fw_event_cleanup_queue(ioc);
6873 _scsih_flush_running_cmds(ioc); 7155 _scsih_flush_running_cmds(ioc);
6874 _scsih_queue_rescan(ioc);
6875 break; 7156 break;
6876 case MPT2_IOC_DONE_RESET: 7157 case MPT2_IOC_DONE_RESET:
6877 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " 7158 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
@@ -6881,6 +7162,13 @@ mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
6881 _scsih_search_responding_sas_devices(ioc); 7162 _scsih_search_responding_sas_devices(ioc);
6882 _scsih_search_responding_raid_devices(ioc); 7163 _scsih_search_responding_raid_devices(ioc);
6883 _scsih_search_responding_expanders(ioc); 7164 _scsih_search_responding_expanders(ioc);
7165 if (!ioc->is_driver_loading) {
7166 _scsih_prep_device_scan(ioc);
7167 _scsih_search_responding_sas_devices(ioc);
7168 _scsih_search_responding_raid_devices(ioc);
7169 _scsih_search_responding_expanders(ioc);
7170 _scsih_error_recovery_delete_devices(ioc);
7171 }
6884 break; 7172 break;
6885 } 7173 }
6886} 7174}
@@ -6898,7 +7186,6 @@ _firmware_event_work(struct work_struct *work)
6898{ 7186{
6899 struct fw_event_work *fw_event = container_of(work, 7187 struct fw_event_work *fw_event = container_of(work,
6900 struct fw_event_work, delayed_work.work); 7188 struct fw_event_work, delayed_work.work);
6901 unsigned long flags;
6902 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; 7189 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
6903 7190
6904 /* the queue is being flushed so ignore this event */ 7191 /* the queue is being flushed so ignore this event */
@@ -6908,23 +7195,21 @@ _firmware_event_work(struct work_struct *work)
6908 return; 7195 return;
6909 } 7196 }
6910 7197
6911 if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) { 7198 switch (fw_event->event) {
6912 _scsih_fw_event_free(ioc, fw_event); 7199 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
6913 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); 7200 while (scsi_host_in_recovery(ioc->shost))
6914 if (ioc->shost_recovery) { 7201 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); 7202 _scsih_remove_unresponding_sas_devices(ioc);
6923 _scsih_hide_unhide_sas_devices(ioc); 7203 _scsih_scan_for_devices_after_reset(ioc);
6924 return; 7204 break;
6925 } 7205 case MPT2SAS_PORT_ENABLE_COMPLETE:
7206 ioc->start_scan = 0;
6926 7207
6927 switch (fw_event->event) { 7208
7209
7210 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7211 "from worker thread\n", ioc->name));
7212 break;
6928 case MPT2SAS_TURN_ON_FAULT_LED: 7213 case MPT2SAS_TURN_ON_FAULT_LED:
6929 _scsih_turn_on_fault_led(ioc, fw_event->device_handle); 7214 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
6930 break; 7215 break;
@@ -7121,6 +7406,8 @@ static struct scsi_host_template scsih_driver_template = {
7121 .slave_configure = _scsih_slave_configure, 7406 .slave_configure = _scsih_slave_configure,
7122 .target_destroy = _scsih_target_destroy, 7407 .target_destroy = _scsih_target_destroy,
7123 .slave_destroy = _scsih_slave_destroy, 7408 .slave_destroy = _scsih_slave_destroy,
7409 .scan_finished = _scsih_scan_finished,
7410 .scan_start = _scsih_scan_start,
7124 .change_queue_depth = _scsih_change_queue_depth, 7411 .change_queue_depth = _scsih_change_queue_depth,
7125 .change_queue_type = _scsih_change_queue_type, 7412 .change_queue_type = _scsih_change_queue_type,
7126 .eh_abort_handler = _scsih_abort, 7413 .eh_abort_handler = _scsih_abort,
@@ -7381,7 +7668,12 @@ _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7381 unsigned long flags; 7668 unsigned long flags;
7382 int rc; 7669 int rc;
7383 7670
7671 /* no Bios, return immediately */
7672 if (!ioc->bios_pg3.BiosVersion)
7673 return;
7674
7384 device = NULL; 7675 device = NULL;
7676 is_raid = 0;
7385 if (ioc->req_boot_device.device) { 7677 if (ioc->req_boot_device.device) {
7386 device = ioc->req_boot_device.device; 7678 device = ioc->req_boot_device.device;
7387 is_raid = ioc->req_boot_device.is_raid; 7679 is_raid = ioc->req_boot_device.is_raid;
@@ -7417,8 +7709,9 @@ _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7417 sas_device->sas_address_parent)) { 7709 sas_device->sas_address_parent)) {
7418 _scsih_sas_device_remove(ioc, sas_device); 7710 _scsih_sas_device_remove(ioc, sas_device);
7419 } else if (!sas_device->starget) { 7711 } else if (!sas_device->starget) {
7420 mpt2sas_transport_port_remove(ioc, sas_address, 7712 if (!ioc->is_driver_loading)
7421 sas_address_parent); 7713 mpt2sas_transport_port_remove(ioc, sas_address,
7714 sas_address_parent);
7422 _scsih_sas_device_remove(ioc, sas_device); 7715 _scsih_sas_device_remove(ioc, sas_device);
7423 } 7716 }
7424 } 7717 }
@@ -7462,22 +7755,28 @@ _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7462 /* SAS Device List */ 7755 /* SAS Device List */
7463 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, 7756 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7464 list) { 7757 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 7758
7469 if (ioc->hide_drives) 7759 if (ioc->hide_drives)
7470 continue; 7760 continue;
7471 7761
7472 if (!mpt2sas_transport_port_add(ioc, sas_device->handle, 7762 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7473 sas_device->sas_address_parent)) { 7763 sas_device->sas_address_parent)) {
7474 _scsih_sas_device_remove(ioc, sas_device); 7764 list_del(&sas_device->list);
7765 kfree(sas_device);
7766 continue;
7475 } else if (!sas_device->starget) { 7767 } else if (!sas_device->starget) {
7476 mpt2sas_transport_port_remove(ioc, 7768 if (!ioc->is_driver_loading)
7477 sas_device->sas_address, 7769 mpt2sas_transport_port_remove(ioc,
7478 sas_device->sas_address_parent); 7770 sas_device->sas_address,
7479 _scsih_sas_device_remove(ioc, sas_device); 7771 sas_device->sas_address_parent);
7772 list_del(&sas_device->list);
7773 kfree(sas_device);
7774 continue;
7775
7480 } 7776 }
7777 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7778 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7779 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7481 } 7780 }
7482} 7781}
7483 7782
@@ -7490,9 +7789,7 @@ _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7490static void 7789static void
7491_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) 7790_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7492{ 7791{
7493 u16 volume_mapping_flags = 7792 u16 volume_mapping_flags;
7494 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7495 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7496 7793
7497 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) 7794 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7498 return; /* return when IOC doesn't support initiator mode */ 7795 return; /* return when IOC doesn't support initiator mode */
@@ -7500,18 +7797,93 @@ _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7500 _scsih_probe_boot_devices(ioc); 7797 _scsih_probe_boot_devices(ioc);
7501 7798
7502 if (ioc->ir_firmware) { 7799 if (ioc->ir_firmware) {
7503 if ((volume_mapping_flags & 7800 volume_mapping_flags =
7504 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) { 7801 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7505 _scsih_probe_sas(ioc); 7802 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7803 if (volume_mapping_flags ==
7804 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7506 _scsih_probe_raid(ioc); 7805 _scsih_probe_raid(ioc);
7806 _scsih_probe_sas(ioc);
7507 } else { 7807 } else {
7508 _scsih_probe_raid(ioc);
7509 _scsih_probe_sas(ioc); 7808 _scsih_probe_sas(ioc);
7809 _scsih_probe_raid(ioc);
7510 } 7810 }
7511 } else 7811 } else
7512 _scsih_probe_sas(ioc); 7812 _scsih_probe_sas(ioc);
7513} 7813}
7514 7814
7815
7816/**
7817 * _scsih_scan_start - scsi lld callback for .scan_start
7818 * @shost: SCSI host pointer
7819 *
7820 * The shost has the ability to discover targets on its own instead
7821 * of scanning the entire bus. In our implemention, we will kick off
7822 * firmware discovery.
7823 */
7824static void
7825_scsih_scan_start(struct Scsi_Host *shost)
7826{
7827 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7828 int rc;
7829
7830 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7831 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7832
7833 ioc->start_scan = 1;
7834 rc = mpt2sas_port_enable(ioc);
7835
7836 if (rc != 0)
7837 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7838}
7839
7840/**
7841 * _scsih_scan_finished - scsi lld callback for .scan_finished
7842 * @shost: SCSI host pointer
7843 * @time: elapsed time of the scan in jiffies
7844 *
7845 * This function will be called periodically until it returns 1 with the
7846 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7847 * we wait for firmware discovery to complete, then return 1.
7848 */
7849static int
7850_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7851{
7852 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7853
7854 if (time >= (300 * HZ)) {
7855 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7856 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7857 "(timeout=300s)\n", ioc->name);
7858 ioc->is_driver_loading = 0;
7859 return 1;
7860 }
7861
7862 if (ioc->start_scan)
7863 return 0;
7864
7865 if (ioc->start_scan_failed) {
7866 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7867 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7868 ioc->is_driver_loading = 0;
7869 ioc->wait_for_discovery_to_complete = 0;
7870 ioc->remove_host = 1;
7871 return 1;
7872 }
7873
7874 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7875 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7876
7877 if (ioc->wait_for_discovery_to_complete) {
7878 ioc->wait_for_discovery_to_complete = 0;
7879 _scsih_probe_devices(ioc);
7880 }
7881 mpt2sas_base_start_watchdog(ioc);
7882 ioc->is_driver_loading = 0;
7883 return 1;
7884}
7885
7886
7515/** 7887/**
7516 * _scsih_probe - attach and add scsi host 7888 * _scsih_probe - attach and add scsi host
7517 * @pdev: PCI device struct 7889 * @pdev: PCI device struct
@@ -7548,6 +7920,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7548 ioc->tm_cb_idx = tm_cb_idx; 7920 ioc->tm_cb_idx = tm_cb_idx;
7549 ioc->ctl_cb_idx = ctl_cb_idx; 7921 ioc->ctl_cb_idx = ctl_cb_idx;
7550 ioc->base_cb_idx = base_cb_idx; 7922 ioc->base_cb_idx = base_cb_idx;
7923 ioc->port_enable_cb_idx = port_enable_cb_idx;
7551 ioc->transport_cb_idx = transport_cb_idx; 7924 ioc->transport_cb_idx = transport_cb_idx;
7552 ioc->scsih_cb_idx = scsih_cb_idx; 7925 ioc->scsih_cb_idx = scsih_cb_idx;
7553 ioc->config_cb_idx = config_cb_idx; 7926 ioc->config_cb_idx = config_cb_idx;
@@ -7620,14 +7993,14 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7620 goto out_thread_fail; 7993 goto out_thread_fail;
7621 } 7994 }
7622 7995
7623 ioc->wait_for_port_enable_to_complete = 1; 7996 ioc->is_driver_loading = 1;
7624 if ((mpt2sas_base_attach(ioc))) { 7997 if ((mpt2sas_base_attach(ioc))) {
7625 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 7998 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7626 ioc->name, __FILE__, __LINE__, __func__); 7999 ioc->name, __FILE__, __LINE__, __func__);
7627 goto out_attach_fail; 8000 goto out_attach_fail;
7628 } 8001 }
7629 8002
7630 ioc->wait_for_port_enable_to_complete = 0; 8003 scsi_scan_host(shost);
7631 if (ioc->is_warpdrive) { 8004 if (ioc->is_warpdrive) {
7632 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) 8005 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7633 ioc->hide_drives = 0; 8006 ioc->hide_drives = 0;
@@ -7650,6 +8023,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7650 out_thread_fail: 8023 out_thread_fail:
7651 list_del(&ioc->list); 8024 list_del(&ioc->list);
7652 scsi_remove_host(shost); 8025 scsi_remove_host(shost);
8026 scsi_host_put(shost);
7653 out_add_shost_fail: 8027 out_add_shost_fail:
7654 return -ENODEV; 8028 return -ENODEV;
7655} 8029}
@@ -7896,6 +8270,8 @@ _scsih_init(void)
7896 8270
7897 /* base internal commands callback handler */ 8271 /* base internal commands callback handler */
7898 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); 8272 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8273 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8274 mpt2sas_port_enable_done);
7899 8275
7900 /* transport internal commands callback handler */ 8276 /* transport internal commands callback handler */
7901 transport_cb_idx = mpt2sas_base_register_callback_handler( 8277 transport_cb_idx = mpt2sas_base_register_callback_handler(
@@ -7950,6 +8326,7 @@ _scsih_exit(void)
7950 mpt2sas_base_release_callback_handler(scsi_io_cb_idx); 8326 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
7951 mpt2sas_base_release_callback_handler(tm_cb_idx); 8327 mpt2sas_base_release_callback_handler(tm_cb_idx);
7952 mpt2sas_base_release_callback_handler(base_cb_idx); 8328 mpt2sas_base_release_callback_handler(base_cb_idx);
8329 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
7953 mpt2sas_base_release_callback_handler(transport_cb_idx); 8330 mpt2sas_base_release_callback_handler(transport_cb_idx);
7954 mpt2sas_base_release_callback_handler(scsih_cb_idx); 8331 mpt2sas_base_release_callback_handler(scsih_cb_idx);
7955 mpt2sas_base_release_callback_handler(config_cb_idx); 8332 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 621b5e07275..6f589195746 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 86afb13f1e7..c06b8e5aa2c 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 b86db84d6f3..5163edb925c 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 cd178b9e40c..959f10055be 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 3474e86e98a..2516adf1aee 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 fc3f168decb..f85cfa6c47b 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>
@@ -1408,6 +1409,8 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
1408 1409
1409 blk_start_request(req); 1410 blk_start_request(req);
1410 1411
1412 scmd_printk(KERN_INFO, cmd, "killing request\n");
1413
1411 sdev = cmd->device; 1414 sdev = cmd->device;
1412 starget = scsi_target(sdev); 1415 starget = scsi_target(sdev);
1413 shost = sdev->host; 1416 shost = sdev->host;
@@ -1489,7 +1492,6 @@ static void scsi_request_fn(struct request_queue *q)
1489 struct request *req; 1492 struct request *req;
1490 1493
1491 if (!sdev) { 1494 if (!sdev) {
1492 printk("scsi: killing requests for dead queue\n");
1493 while ((req = blk_peek_request(q)) != NULL) 1495 while ((req = blk_peek_request(q)) != NULL)
1494 scsi_kill_request(req, q); 1496 scsi_kill_request(req, q);
1495 return; 1497 return;
@@ -1698,6 +1700,15 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
1698 1700
1699void scsi_free_queue(struct request_queue *q) 1701void scsi_free_queue(struct request_queue *q)
1700{ 1702{
1703 unsigned long flags;
1704
1705 WARN_ON(q->queuedata);
1706
1707 /* cause scsi_request_fn() to kill all non-finished requests */
1708 spin_lock_irqsave(q->queue_lock, flags);
1709 q->request_fn(q);
1710 spin_unlock_irqrestore(q->queue_lock, flags);
1711
1701 blk_cleanup_queue(q); 1712 blk_cleanup_queue(q);
1702} 1713}
1703 1714
diff --git a/drivers/scsi/scsi_lib_dma.c b/drivers/scsi/scsi_lib_dma.c
index dcd128583b8..2ac3f3975f7 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 26a8a45584e..44f76e8b58a 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 d82a023a901..d329f8b12e2 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 44e8ca398ef..b3c6d957fbd 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -319,10 +319,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
319 return sdev; 319 return sdev;
320 320
321out_device_destroy: 321out_device_destroy:
322 scsi_device_set_state(sdev, SDEV_DEL); 322 __scsi_remove_device(sdev);
323 transport_destroy_device(&sdev->sdev_gendev);
324 put_device(&sdev->sdev_dev);
325 put_device(&sdev->sdev_gendev);
326out: 323out:
327 if (display_failure_msg) 324 if (display_failure_msg)
328 printk(ALLOC_FAILURE_MSG, __func__); 325 printk(ALLOC_FAILURE_MSG, __func__);
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index 0172de19700..6209110f295 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 1bcd65a509e..96029e6d027 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 a7942e5c8be..fa3a5918009 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 6ad798bfd52..4163f2910e3 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 8be30554119..a3911c39ea5 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 1871b8ae83a..9b28f39bac2 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 b7cf220d44e..1d5cfe854cf 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/Makefile b/drivers/sh/Makefile
index 24e6cec0ae8..67e272ab162 100644
--- a/drivers/sh/Makefile
+++ b/drivers/sh/Makefile
@@ -7,3 +7,11 @@ obj-$(CONFIG_HAVE_CLK) += clk/
7obj-$(CONFIG_MAPLE) += maple/ 7obj-$(CONFIG_MAPLE) += maple/
8obj-$(CONFIG_SUPERHYWAY) += superhyway/ 8obj-$(CONFIG_SUPERHYWAY) += superhyway/
9obj-$(CONFIG_GENERIC_GPIO) += pfc.o 9obj-$(CONFIG_GENERIC_GPIO) += pfc.o
10
11#
12# For the moment we only use this framework for ARM-based SH/R-Mobile
13# platforms and generic SH. SH-based SH-Mobile platforms are still using
14# an older framework that is pending up-porting, at which point this
15# special casing can go away.
16#
17obj-$(CONFIG_SUPERH)$(CONFIG_ARCH_SHMOBILE) += pm_runtime.o
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index dc8d022c07a..db257a35e71 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -25,7 +25,6 @@
25#include <linux/seq_file.h> 25#include <linux/seq_file.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/debugfs.h>
29#include <linux/cpufreq.h> 28#include <linux/cpufreq.h>
30#include <linux/clk.h> 29#include <linux/clk.h>
31#include <linux/sh_clk.h> 30#include <linux/sh_clk.h>
@@ -173,6 +172,26 @@ long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
173 return clk_rate_round_helper(&div_range_round); 172 return clk_rate_round_helper(&div_range_round);
174} 173}
175 174
175static long clk_rate_mult_range_iter(unsigned int pos,
176 struct clk_rate_round_data *rounder)
177{
178 return clk_get_rate(rounder->arg) * pos;
179}
180
181long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
182 unsigned int mult_max, unsigned long rate)
183{
184 struct clk_rate_round_data mult_range_round = {
185 .min = mult_min,
186 .max = mult_max,
187 .func = clk_rate_mult_range_iter,
188 .arg = clk_get_parent(clk),
189 .rate = rate,
190 };
191
192 return clk_rate_round_helper(&mult_range_round);
193}
194
176int clk_rate_table_find(struct clk *clk, 195int clk_rate_table_find(struct clk *clk,
177 struct cpufreq_frequency_table *freq_table, 196 struct cpufreq_frequency_table *freq_table,
178 unsigned long rate) 197 unsigned long rate)
@@ -205,9 +224,6 @@ int clk_reparent(struct clk *child, struct clk *parent)
205 list_add(&child->sibling, &parent->children); 224 list_add(&child->sibling, &parent->children);
206 child->parent = parent; 225 child->parent = parent;
207 226
208 /* now do the debugfs renaming to reattach the child
209 to the proper parent */
210
211 return 0; 227 return 0;
212} 228}
213 229
@@ -665,89 +681,6 @@ static int __init clk_syscore_init(void)
665subsys_initcall(clk_syscore_init); 681subsys_initcall(clk_syscore_init);
666#endif 682#endif
667 683
668/*
669 * debugfs support to trace clock tree hierarchy and attributes
670 */
671static struct dentry *clk_debugfs_root;
672
673static int clk_debugfs_register_one(struct clk *c)
674{
675 int err;
676 struct dentry *d;
677 struct clk *pa = c->parent;
678 char s[255];
679 char *p = s;
680
681 p += sprintf(p, "%p", c);
682 d = debugfs_create_dir(s, pa ? pa->dentry : clk_debugfs_root);
683 if (!d)
684 return -ENOMEM;
685 c->dentry = d;
686
687 d = debugfs_create_u8("usecount", S_IRUGO, c->dentry, (u8 *)&c->usecount);
688 if (!d) {
689 err = -ENOMEM;
690 goto err_out;
691 }
692 d = debugfs_create_u32("rate", S_IRUGO, c->dentry, (u32 *)&c->rate);
693 if (!d) {
694 err = -ENOMEM;
695 goto err_out;
696 }
697 d = debugfs_create_x32("flags", S_IRUGO, c->dentry, (u32 *)&c->flags);
698 if (!d) {
699 err = -ENOMEM;
700 goto err_out;
701 }
702 return 0;
703
704err_out:
705 debugfs_remove_recursive(c->dentry);
706 return err;
707}
708
709static int clk_debugfs_register(struct clk *c)
710{
711 int err;
712 struct clk *pa = c->parent;
713
714 if (pa && !pa->dentry) {
715 err = clk_debugfs_register(pa);
716 if (err)
717 return err;
718 }
719
720 if (!c->dentry) {
721 err = clk_debugfs_register_one(c);
722 if (err)
723 return err;
724 }
725 return 0;
726}
727
728static int __init clk_debugfs_init(void)
729{
730 struct clk *c;
731 struct dentry *d;
732 int err;
733
734 d = debugfs_create_dir("clock", NULL);
735 if (!d)
736 return -ENOMEM;
737 clk_debugfs_root = d;
738
739 list_for_each_entry(c, &clock_list, node) {
740 err = clk_debugfs_register(c);
741 if (err)
742 goto err_out;
743 }
744 return 0;
745err_out:
746 debugfs_remove_recursive(clk_debugfs_root);
747 return err;
748}
749late_initcall(clk_debugfs_init);
750
751static int __init clk_late_init(void) 684static int __init clk_late_init(void)
752{ 685{
753 unsigned long flags; 686 unsigned long flags;
diff --git a/drivers/sh/intc/chip.c b/drivers/sh/intc/chip.c
index 33b2ed451e0..7b246efa94e 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 c6ca115c71d..8b7a141ff35 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 a3677c9dfe3..5fea1ee8799 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 e32304b66cf..56bf9336b92 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 1e6e2d0353e..c7ec49ffd9f 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 1e20604257a..bec81c2404f 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 75934e3ea34..e67fe170d8d 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/sh/pm_runtime.c b/drivers/sh/pm_runtime.c
new file mode 100644
index 00000000000..afe9282629b
--- /dev/null
+++ b/drivers/sh/pm_runtime.c
@@ -0,0 +1,65 @@
1/*
2 * Runtime PM support code
3 *
4 * Copyright (C) 2009-2010 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/io.h>
14#include <linux/pm_runtime.h>
15#include <linux/pm_domain.h>
16#include <linux/pm_clock.h>
17#include <linux/platform_device.h>
18#include <linux/clk.h>
19#include <linux/sh_clk.h>
20#include <linux/bitmap.h>
21#include <linux/slab.h>
22
23#ifdef CONFIG_PM_RUNTIME
24
25static int default_platform_runtime_idle(struct device *dev)
26{
27 /* suspend synchronously to disable clocks immediately */
28 return pm_runtime_suspend(dev);
29}
30
31static struct dev_pm_domain default_pm_domain = {
32 .ops = {
33 .runtime_suspend = pm_clk_suspend,
34 .runtime_resume = pm_clk_resume,
35 .runtime_idle = default_platform_runtime_idle,
36 USE_PLATFORM_PM_SLEEP_OPS
37 },
38};
39
40#define DEFAULT_PM_DOMAIN_PTR (&default_pm_domain)
41
42#else
43
44#define DEFAULT_PM_DOMAIN_PTR NULL
45
46#endif /* CONFIG_PM_RUNTIME */
47
48static struct pm_clk_notifier_block platform_bus_notifier = {
49 .pm_domain = DEFAULT_PM_DOMAIN_PTR,
50 .con_ids = { NULL, },
51};
52
53static int __init sh_pm_runtime_init(void)
54{
55 pm_clk_add_notifier(&platform_bus_type, &platform_bus_notifier);
56 return 0;
57}
58core_initcall(sh_pm_runtime_init);
59
60static int __init sh_pm_runtime_late_init(void)
61{
62 pm_genpd_poweroff_unused();
63 return 0;
64}
65late_initcall(sh_pm_runtime_late_init);
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 52e2900d9d8..a1fd73df541 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 881c1967741..c00d00e96ee 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-atmel.c b/drivers/spi/spi-atmel.c
index 79665e2e6ec..16d6a839c7f 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -907,7 +907,7 @@ static void atmel_spi_cleanup(struct spi_device *spi)
907 907
908/*-------------------------------------------------------------------------*/ 908/*-------------------------------------------------------------------------*/
909 909
910static int __init atmel_spi_probe(struct platform_device *pdev) 910static int __devinit atmel_spi_probe(struct platform_device *pdev)
911{ 911{
912 struct resource *regs; 912 struct resource *regs;
913 int irq; 913 int irq;
@@ -1003,7 +1003,7 @@ out_free:
1003 return ret; 1003 return ret;
1004} 1004}
1005 1005
1006static int __exit atmel_spi_remove(struct platform_device *pdev) 1006static int __devexit atmel_spi_remove(struct platform_device *pdev)
1007{ 1007{
1008 struct spi_master *master = platform_get_drvdata(pdev); 1008 struct spi_master *master = platform_get_drvdata(pdev);
1009 struct atmel_spi *as = spi_master_get_devdata(master); 1009 struct atmel_spi *as = spi_master_get_devdata(master);
@@ -1072,6 +1072,7 @@ static struct platform_driver atmel_spi_driver = {
1072 }, 1072 },
1073 .suspend = atmel_spi_suspend, 1073 .suspend = atmel_spi_suspend,
1074 .resume = atmel_spi_resume, 1074 .resume = atmel_spi_resume,
1075 .probe = atmel_spi_probe,
1075 .remove = __exit_p(atmel_spi_remove), 1076 .remove = __exit_p(atmel_spi_remove),
1076}; 1077};
1077module_platform_driver(atmel_spi_driver); 1078module_platform_driver(atmel_spi_driver);
diff --git a/drivers/spi/spi-au1550.c b/drivers/spi/spi-au1550.c
index bddee5f516b..5784c879961 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 02d57fbba29..aef59b1a15f 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 9f907ec52de..5ed08e53743 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 fac399c3022..db2f1ba06ea 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 c5f37f03ac8..f64250ea161 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 296d94f4cf7..082458d73ce 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 635ff08b377..e093d3ec41b 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-nuc900.c b/drivers/spi/spi-nuc900.c
index e763254741c..21c70b2b831 100644
--- a/drivers/spi/spi-nuc900.c
+++ b/drivers/spi/spi-nuc900.c
@@ -426,7 +426,7 @@ static int __devinit nuc900_spi_probe(struct platform_device *pdev)
426 goto err_clk; 426 goto err_clk;
427 } 427 }
428 428
429 mfp_set_groupg(&pdev->dev); 429 mfp_set_groupg(&pdev->dev, NULL);
430 nuc900_init_spi(hw); 430 nuc900_init_spi(hw);
431 431
432 err = spi_bitbang_start(&hw->bitbang); 432 err = spi_bitbang_start(&hw->bitbang);
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c
index 897274e8715..698018fd992 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 00a8e9d7dbe..610f7391456 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 9421a390a5e..13448c832c4 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-pl022.c b/drivers/spi/spi-pl022.c
index f103e470cb6..5559b229919 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -2184,6 +2184,12 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2184 goto err_clk_prep; 2184 goto err_clk_prep;
2185 } 2185 }
2186 2186
2187 status = clk_enable(pl022->clk);
2188 if (status) {
2189 dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n");
2190 goto err_no_clk_en;
2191 }
2192
2187 /* Disable SSP */ 2193 /* Disable SSP */
2188 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)), 2194 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)),
2189 SSP_CR1(pl022->virtbase)); 2195 SSP_CR1(pl022->virtbase));
@@ -2237,6 +2243,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2237 2243
2238 free_irq(adev->irq[0], pl022); 2244 free_irq(adev->irq[0], pl022);
2239 err_no_irq: 2245 err_no_irq:
2246 clk_disable(pl022->clk);
2247 err_no_clk_en:
2240 clk_unprepare(pl022->clk); 2248 clk_unprepare(pl022->clk);
2241 err_clk_prep: 2249 err_clk_prep:
2242 clk_put(pl022->clk); 2250 clk_put(pl022->clk);
diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c
index 378e504f89e..8caa07d58e6 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 b857a3e7af9..fc064535f4f 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 595dacc7645..019a7163572 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 0f4834ae28c..1f466bc66d9 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 8844bc34278..097e506042b 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 7963c60063d..3f6f6e81c65 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 940e73d1cf0..0ce5c12aab5 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 f0a2ab0428a..d5a3cbb646c 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 4d1b9f517ce..77eae99af11 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 bf53e44c82a..bad7ba517a1 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 5d9c97c2479..e9d2ca11283 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 52901c14c68..e5a2e0e9bc1 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 3adb98dad70..f30ea689933 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 e6ac3177fbb..84c934c0a54 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 eec3e267be4..9ef124f9ee2 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 d0cbdb0cf9d..bb6317fb925 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 116a8116984..af5448f5e2d 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 d132c27dfb3..25cdff36a78 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 936b7c22e18..a25f3f26c7f 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/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 21d8c1c16cd..5e78c77d5a0 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -671,7 +671,7 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
671 } 671 }
672 672
673 insns = 673 insns =
674 kmalloc(sizeof(struct comedi_insn) * insnlist.n_insns, GFP_KERNEL); 674 kcalloc(insnlist.n_insns, sizeof(struct comedi_insn), GFP_KERNEL);
675 if (!insns) { 675 if (!insns) {
676 DPRINTK("kmalloc failed\n"); 676 DPRINTK("kmalloc failed\n");
677 ret = -ENOMEM; 677 ret = -ENOMEM;
@@ -1432,7 +1432,21 @@ static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
1432 return ret; 1432 return ret;
1433} 1433}
1434 1434
1435static void comedi_unmap(struct vm_area_struct *area) 1435
1436static void comedi_vm_open(struct vm_area_struct *area)
1437{
1438 struct comedi_async *async;
1439 struct comedi_device *dev;
1440
1441 async = area->vm_private_data;
1442 dev = async->subdevice->device;
1443
1444 mutex_lock(&dev->mutex);
1445 async->mmap_count++;
1446 mutex_unlock(&dev->mutex);
1447}
1448
1449static void comedi_vm_close(struct vm_area_struct *area)
1436{ 1450{
1437 struct comedi_async *async; 1451 struct comedi_async *async;
1438 struct comedi_device *dev; 1452 struct comedi_device *dev;
@@ -1446,15 +1460,13 @@ static void comedi_unmap(struct vm_area_struct *area)
1446} 1460}
1447 1461
1448static struct vm_operations_struct comedi_vm_ops = { 1462static struct vm_operations_struct comedi_vm_ops = {
1449 .close = comedi_unmap, 1463 .open = comedi_vm_open,
1464 .close = comedi_vm_close,
1450}; 1465};
1451 1466
1452static int comedi_mmap(struct file *file, struct vm_area_struct *vma) 1467static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
1453{ 1468{
1454 const unsigned minor = iminor(file->f_dentry->d_inode); 1469 const unsigned minor = iminor(file->f_dentry->d_inode);
1455 struct comedi_device_file_info *dev_file_info =
1456 comedi_get_device_file_info(minor);
1457 struct comedi_device *dev = dev_file_info->device;
1458 struct comedi_async *async = NULL; 1470 struct comedi_async *async = NULL;
1459 unsigned long start = vma->vm_start; 1471 unsigned long start = vma->vm_start;
1460 unsigned long size; 1472 unsigned long size;
@@ -1462,6 +1474,15 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
1462 int i; 1474 int i;
1463 int retval; 1475 int retval;
1464 struct comedi_subdevice *s; 1476 struct comedi_subdevice *s;
1477 struct comedi_device_file_info *dev_file_info;
1478 struct comedi_device *dev;
1479
1480 dev_file_info = comedi_get_device_file_info(minor);
1481 if (dev_file_info == NULL)
1482 return -ENODEV;
1483 dev = dev_file_info->device;
1484 if (dev == NULL)
1485 return -ENODEV;
1465 1486
1466 mutex_lock(&dev->mutex); 1487 mutex_lock(&dev->mutex);
1467 if (!dev->attached) { 1488 if (!dev->attached) {
@@ -1528,11 +1549,17 @@ static unsigned int comedi_poll(struct file *file, poll_table * wait)
1528{ 1549{
1529 unsigned int mask = 0; 1550 unsigned int mask = 0;
1530 const unsigned minor = iminor(file->f_dentry->d_inode); 1551 const unsigned minor = iminor(file->f_dentry->d_inode);
1531 struct comedi_device_file_info *dev_file_info =
1532 comedi_get_device_file_info(minor);
1533 struct comedi_device *dev = dev_file_info->device;
1534 struct comedi_subdevice *read_subdev; 1552 struct comedi_subdevice *read_subdev;
1535 struct comedi_subdevice *write_subdev; 1553 struct comedi_subdevice *write_subdev;
1554 struct comedi_device_file_info *dev_file_info;
1555 struct comedi_device *dev;
1556 dev_file_info = comedi_get_device_file_info(minor);
1557
1558 if (dev_file_info == NULL)
1559 return -ENODEV;
1560 dev = dev_file_info->device;
1561 if (dev == NULL)
1562 return -ENODEV;
1536 1563
1537 mutex_lock(&dev->mutex); 1564 mutex_lock(&dev->mutex);
1538 if (!dev->attached) { 1565 if (!dev->attached) {
@@ -1578,9 +1605,15 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
1578 int n, m, count = 0, retval = 0; 1605 int n, m, count = 0, retval = 0;
1579 DECLARE_WAITQUEUE(wait, current); 1606 DECLARE_WAITQUEUE(wait, current);
1580 const unsigned minor = iminor(file->f_dentry->d_inode); 1607 const unsigned minor = iminor(file->f_dentry->d_inode);
1581 struct comedi_device_file_info *dev_file_info = 1608 struct comedi_device_file_info *dev_file_info;
1582 comedi_get_device_file_info(minor); 1609 struct comedi_device *dev;
1583 struct comedi_device *dev = dev_file_info->device; 1610 dev_file_info = comedi_get_device_file_info(minor);
1611
1612 if (dev_file_info == NULL)
1613 return -ENODEV;
1614 dev = dev_file_info->device;
1615 if (dev == NULL)
1616 return -ENODEV;
1584 1617
1585 if (!dev->attached) { 1618 if (!dev->attached) {
1586 DPRINTK("no driver configured on comedi%i\n", dev->minor); 1619 DPRINTK("no driver configured on comedi%i\n", dev->minor);
@@ -1640,11 +1673,11 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
1640 retval = -EAGAIN; 1673 retval = -EAGAIN;
1641 break; 1674 break;
1642 } 1675 }
1676 schedule();
1643 if (signal_pending(current)) { 1677 if (signal_pending(current)) {
1644 retval = -ERESTARTSYS; 1678 retval = -ERESTARTSYS;
1645 break; 1679 break;
1646 } 1680 }
1647 schedule();
1648 if (!s->busy) 1681 if (!s->busy)
1649 break; 1682 break;
1650 if (s->busy != file) { 1683 if (s->busy != file) {
@@ -1683,9 +1716,15 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
1683 int n, m, count = 0, retval = 0; 1716 int n, m, count = 0, retval = 0;
1684 DECLARE_WAITQUEUE(wait, current); 1717 DECLARE_WAITQUEUE(wait, current);
1685 const unsigned minor = iminor(file->f_dentry->d_inode); 1718 const unsigned minor = iminor(file->f_dentry->d_inode);
1686 struct comedi_device_file_info *dev_file_info = 1719 struct comedi_device_file_info *dev_file_info;
1687 comedi_get_device_file_info(minor); 1720 struct comedi_device *dev;
1688 struct comedi_device *dev = dev_file_info->device; 1721 dev_file_info = comedi_get_device_file_info(minor);
1722
1723 if (dev_file_info == NULL)
1724 return -ENODEV;
1725 dev = dev_file_info->device;
1726 if (dev == NULL)
1727 return -ENODEV;
1689 1728
1690 if (!dev->attached) { 1729 if (!dev->attached) {
1691 DPRINTK("no driver configured on comedi%i\n", dev->minor); 1730 DPRINTK("no driver configured on comedi%i\n", dev->minor);
@@ -1741,11 +1780,11 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
1741 retval = -EAGAIN; 1780 retval = -EAGAIN;
1742 break; 1781 break;
1743 } 1782 }
1783 schedule();
1744 if (signal_pending(current)) { 1784 if (signal_pending(current)) {
1745 retval = -ERESTARTSYS; 1785 retval = -ERESTARTSYS;
1746 break; 1786 break;
1747 } 1787 }
1748 schedule();
1749 if (!s->busy) { 1788 if (!s->busy) {
1750 retval = 0; 1789 retval = 0;
1751 break; 1790 break;
@@ -1885,11 +1924,17 @@ ok:
1885static int comedi_close(struct inode *inode, struct file *file) 1924static int comedi_close(struct inode *inode, struct file *file)
1886{ 1925{
1887 const unsigned minor = iminor(inode); 1926 const unsigned minor = iminor(inode);
1888 struct comedi_device_file_info *dev_file_info =
1889 comedi_get_device_file_info(minor);
1890 struct comedi_device *dev = dev_file_info->device;
1891 struct comedi_subdevice *s = NULL; 1927 struct comedi_subdevice *s = NULL;
1892 int i; 1928 int i;
1929 struct comedi_device_file_info *dev_file_info;
1930 struct comedi_device *dev;
1931 dev_file_info = comedi_get_device_file_info(minor);
1932
1933 if (dev_file_info == NULL)
1934 return -ENODEV;
1935 dev = dev_file_info->device;
1936 if (dev == NULL)
1937 return -ENODEV;
1893 1938
1894 mutex_lock(&dev->mutex); 1939 mutex_lock(&dev->mutex);
1895 1940
@@ -1923,10 +1968,15 @@ static int comedi_close(struct inode *inode, struct file *file)
1923static int comedi_fasync(int fd, struct file *file, int on) 1968static int comedi_fasync(int fd, struct file *file, int on)
1924{ 1969{
1925 const unsigned minor = iminor(file->f_dentry->d_inode); 1970 const unsigned minor = iminor(file->f_dentry->d_inode);
1926 struct comedi_device_file_info *dev_file_info = 1971 struct comedi_device_file_info *dev_file_info;
1927 comedi_get_device_file_info(minor); 1972 struct comedi_device *dev;
1973 dev_file_info = comedi_get_device_file_info(minor);
1928 1974
1929 struct comedi_device *dev = dev_file_info->device; 1975 if (dev_file_info == NULL)
1976 return -ENODEV;
1977 dev = dev_file_info->device;
1978 if (dev == NULL)
1979 return -ENODEV;
1930 1980
1931 return fasync_helper(fd, file, on, &dev->async_queue); 1981 return fasync_helper(fd, file, on, &dev->async_queue);
1932} 1982}
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index a8fea9a9173..6144afb8cba 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1,4 +1,4 @@
1#define DRIVER_VERSION "v0.5" 1#define DRIVER_VERSION "v0.6"
2#define DRIVER_AUTHOR "Bernd Porr, BerndPorr@f2s.com" 2#define DRIVER_AUTHOR "Bernd Porr, BerndPorr@f2s.com"
3#define DRIVER_DESC "Stirling/ITL USB-DUX SIGMA -- Bernd.Porr@f2s.com" 3#define DRIVER_DESC "Stirling/ITL USB-DUX SIGMA -- Bernd.Porr@f2s.com"
4/* 4/*
@@ -25,7 +25,7 @@ Driver: usbduxsigma
25Description: University of Stirling USB DAQ & INCITE Technology Limited 25Description: University of Stirling USB DAQ & INCITE Technology Limited
26Devices: [ITL] USB-DUX (usbduxsigma.o) 26Devices: [ITL] USB-DUX (usbduxsigma.o)
27Author: Bernd Porr <BerndPorr@f2s.com> 27Author: Bernd Porr <BerndPorr@f2s.com>
28Updated: 21 Jul 2011 28Updated: 8 Nov 2011
29Status: testing 29Status: testing
30*/ 30*/
31/* 31/*
@@ -44,6 +44,7 @@ Status: testing
44 * 0.3: proper vendor ID and driver name 44 * 0.3: proper vendor ID and driver name
45 * 0.4: fixed D/A voltage range 45 * 0.4: fixed D/A voltage range
46 * 0.5: various bug fixes, health check at startup 46 * 0.5: various bug fixes, health check at startup
47 * 0.6: corrected wrong input range
47 */ 48 */
48 49
49/* generates loads of debug info */ 50/* generates loads of debug info */
@@ -175,7 +176,7 @@ Status: testing
175/* comedi constants */ 176/* comedi constants */
176static const struct comedi_lrange range_usbdux_ai_range = { 1, { 177static const struct comedi_lrange range_usbdux_ai_range = { 1, {
177 BIP_RANGE 178 BIP_RANGE
178 (2.65) 179 (2.65/2.0)
179 } 180 }
180}; 181};
181 182
diff --git a/drivers/staging/cx25821/README b/drivers/staging/cx25821/README
deleted file mode 100644
index a9ba50b9888..00000000000
--- 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 24e009c0149..911c0e4375f 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/et131x/Kconfig b/drivers/staging/et131x/Kconfig
index 9e1864c6dfd..8190f2aaf53 100644
--- a/drivers/staging/et131x/Kconfig
+++ b/drivers/staging/et131x/Kconfig
@@ -1,6 +1,7 @@
1config ET131X 1config ET131X
2 tristate "Agere ET-1310 Gigabit Ethernet support" 2 tristate "Agere ET-1310 Gigabit Ethernet support"
3 depends on PCI 3 depends on PCI && NET && NETDEVICES
4 select PHYLIB
4 default n 5 default n
5 ---help--- 6 ---help---
6 This driver supports Agere ET-1310 ethernet adapters. 7 This driver supports Agere ET-1310 ethernet adapters.
diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index f5f44a02456..0c1c6ca8c37 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -4469,6 +4469,12 @@ static int et131x_resume(struct device *dev)
4469 return 0; 4469 return 0;
4470} 4470}
4471 4471
4472static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
4473#define ET131X_PM_OPS (&et131x_pm_ops)
4474#else
4475#define ET131X_PM_OPS NULL
4476#endif
4477
4472/* ISR functions */ 4478/* ISR functions */
4473 4479
4474/** 4480/**
@@ -5470,12 +5476,6 @@ err_out:
5470 return result; 5476 return result;
5471} 5477}
5472 5478
5473static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
5474#define ET131X_PM_OPS (&et131x_pm_ops)
5475#else
5476#define ET131X_PM_OPS NULL
5477#endif
5478
5479static DEFINE_PCI_DEVICE_TABLE(et131x_pci_table) = { 5479static DEFINE_PCI_DEVICE_TABLE(et131x_pci_table) = {
5480 { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL}, 5480 { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL},
5481 { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL}, 5481 { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL},
diff --git a/drivers/staging/gma500/intel_i2c.c b/drivers/staging/gma500/intel_i2c.c
index e33432df510..51cbf65268e 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 9050c0f78b1..3f979db2c3a 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 ee55f87ba1f..eabf53d58f9 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 8cfe301f8fb..ee3c0368e32 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 351b9d897b9..36e7edc4d14 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 dc676c2ce81..986a04d16ba 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/hv/Kconfig b/drivers/staging/hv/Kconfig
index 072185ebe95..6c0dc300647 100644
--- a/drivers/staging/hv/Kconfig
+++ b/drivers/staging/hv/Kconfig
@@ -9,9 +9,3 @@ config HYPERV_NET
9 depends on HYPERV && NET 9 depends on HYPERV && NET
10 help 10 help
11 Select this option to enable the Hyper-V virtual network driver. 11 Select this option to enable the Hyper-V virtual network driver.
12
13config HYPERV_MOUSE
14 tristate "Microsoft Hyper-V mouse driver"
15 depends on HYPERV && HID
16 help
17 Select this option to enable the Hyper-V mouse driver.
diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile
index 0f55ceee919..fbe9a427a2a 100644
--- a/drivers/staging/hv/Makefile
+++ b/drivers/staging/hv/Makefile
@@ -1,6 +1,5 @@
1obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o 1obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o
2obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o 2obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o
3obj-$(CONFIG_HYPERV_MOUSE) += hv_mouse.o
4 3
5hv_storvsc-y := storvsc_drv.o 4hv_storvsc-y := storvsc_drv.o
6hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o 5hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o
diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index dbd883294d6..0016ed378e3 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 f448258884c..bce505e716d 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 838d3012c87..1fdfe6f6ac6 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 50165f9ddc5..24bcb8e15c5 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 08551bb48f1..6fd3d8f51f2 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 55b661c98d2..6e542af02c0 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 bb66364bef0..d17e39d9545 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 8df8a9791d5..c5d82c1a55d 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 34f1e7e6a56..b907ca3f4fd 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 13f1d142eea..8e0ce568e64 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 5c542dd0461..89527af8f4c 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 a831b92cd08..999f8f746cf 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 48389e1c19f..974c6f5b60c 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 38cf3f4bf72..ff1b5a82b3d 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 679c1515571..52a9e784e7c 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 2f2b2160f44..8299cd18d70 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 f0b36d25414..edad0e7b4f4 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 c3682458d78..fd886bf51a6 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 bf991531e0d..5bf00075752 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 6dd5d7d629a..9df0ce81dad 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/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 326e967d54e..aec9311b108 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -242,19 +242,26 @@ static const struct file_operations iio_event_chrdev_fileops = {
242 242
243static int iio_event_getfd(struct iio_dev *indio_dev) 243static int iio_event_getfd(struct iio_dev *indio_dev)
244{ 244{
245 if (indio_dev->event_interface == NULL) 245 struct iio_event_interface *ev_int = indio_dev->event_interface;
246 int fd;
247
248 if (ev_int == NULL)
246 return -ENODEV; 249 return -ENODEV;
247 250
248 mutex_lock(&indio_dev->event_interface->event_list_lock); 251 mutex_lock(&ev_int->event_list_lock);
249 if (test_and_set_bit(IIO_BUSY_BIT_POS, 252 if (test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
250 &indio_dev->event_interface->flags)) { 253 mutex_unlock(&ev_int->event_list_lock);
251 mutex_unlock(&indio_dev->event_interface->event_list_lock);
252 return -EBUSY; 254 return -EBUSY;
253 } 255 }
254 mutex_unlock(&indio_dev->event_interface->event_list_lock); 256 mutex_unlock(&ev_int->event_list_lock);
255 return anon_inode_getfd("iio:event", 257 fd = anon_inode_getfd("iio:event",
256 &iio_event_chrdev_fileops, 258 &iio_event_chrdev_fileops, ev_int, O_RDONLY);
257 indio_dev->event_interface, O_RDONLY); 259 if (fd < 0) {
260 mutex_lock(&ev_int->event_list_lock);
261 clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
262 mutex_unlock(&ev_int->event_list_lock);
263 }
264 return fd;
258} 265}
259 266
260static int __init iio_init(void) 267static int __init iio_init(void)
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index 99ade658a2d..00fa2ac5c45 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 392dfe30244..b6569c70665 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 c303d85011b..ff9aaec0557 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 69daa1404b6..22bd29c0c43 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 61db1f99b0c..8e7398393a5 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 00000000000..7e5caa39ed3
--- /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 00000000000..c69124cdb0d
--- /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 00000000000..5865029db0f
--- /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 00000000000..e7dbb6f814d
--- /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 00000000000..828526d4c28
--- /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 as102_debug;
36module_param_named(debug, as102_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 00000000000..fd33f5a12dc
--- /dev/null
+++ b/drivers/staging/media/as102/as102_drv.h
@@ -0,0 +1,142 @@
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 as102_debug;
41#define debug as102_debug
42
43#define dprintk(debug, args...) \
44 do { if (debug) { \
45 printk(KERN_DEBUG "%s: ",__FUNCTION__); \
46 printk(args); \
47 } } while (0)
48
49#ifdef TRACE
50#define ENTER() printk(">> enter %s\n", __FUNCTION__)
51#define LEAVE() printk("<< leave %s\n", __FUNCTION__)
52#else
53#define ENTER()
54#define LEAVE()
55#endif
56
57#define AS102_DEVICE_MAJOR 192
58
59#define AS102_USB_BUF_SIZE 512
60#define MAX_STREAM_URB 32
61
62#include "as10x_cmd.h"
63
64#if defined(CONFIG_AS102_USB)
65#include "as102_usb_drv.h"
66#endif
67
68#if defined(CONFIG_AS102_SPI)
69#include "as10x_spi_drv.h"
70#endif
71
72
73struct as102_bus_adapter_t {
74#if defined(CONFIG_AS102_USB)
75 struct usb_device *usb_dev;
76#elif defined(CONFIG_AS102_SPI)
77 struct spi_device *spi_dev;
78 struct cdev cdev; /* spidev raw device */
79
80 struct timer_list timer;
81 struct completion xfer_done;
82#endif
83 /* bus token lock */
84 struct mutex lock;
85 /* low level interface for bus adapter */
86 union as10x_bus_token_t {
87#if defined(CONFIG_AS102_USB)
88 /* usb token */
89 struct as10x_usb_token_cmd_t usb;
90#endif
91#if defined(CONFIG_AS102_SPI)
92 /* spi token */
93 struct as10x_spi_token_cmd_t spi;
94#endif
95 } token;
96
97 /* token cmd xfer id */
98 uint16_t cmd_xid;
99
100 /* as10x command and response for dvb interface*/
101 struct as10x_cmd_t *cmd, *rsp;
102
103 /* bus adapter private ops callback */
104 struct as102_priv_ops_t *ops;
105};
106
107struct as102_dev_t {
108 const char *name;
109 struct as102_bus_adapter_t bus_adap;
110 struct list_head device_entry;
111 struct kref kref;
112 unsigned long minor;
113
114 struct dvb_adapter dvb_adap;
115 struct dvb_frontend dvb_fe;
116 struct dvb_demux dvb_dmx;
117 struct dmxdev dvb_dmxdev;
118
119 /* demodulator stats */
120 struct as10x_demod_stats demod_stats;
121 /* signal strength */
122 uint16_t signal_strength;
123 /* bit error rate */
124 uint32_t ber;
125
126 /* timer handle to trig ts stream download */
127 struct timer_list timer_handle;
128
129 struct mutex sem;
130 dma_addr_t dma_addr;
131 void *stream;
132 int streaming;
133 struct urb *stream_urb[MAX_STREAM_URB];
134};
135
136int as102_dvb_register(struct as102_dev_t *dev);
137void as102_dvb_unregister(struct as102_dev_t *dev);
138
139int as102_dvb_register_fe(struct as102_dev_t *dev, struct dvb_frontend *fe);
140int as102_dvb_unregister_fe(struct dvb_frontend *dev);
141
142/* 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 00000000000..3550f905367
--- /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 00000000000..c019df933cc
--- /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 00000000000..27e5347e2e1
--- /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 00000000000..264be2dbd2a
--- /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 00000000000..fb1fc41dcd7
--- /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 00000000000..0dcba806578
--- /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 00000000000..01a716380e0
--- /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 00000000000..ec6f69fcf39
--- /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 00000000000..045c7068319
--- /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 00000000000..4f01a76e982
--- /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 00000000000..3dedb3c1420
--- /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 b48aefddc84..b48aefddc84 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 64cfc77be35..64cfc77be35 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 375bb6f8ee2..375bb6f8ee2 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 1c04185bcfd..1c04185bcfd 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 19c588a5958..19c588a5958 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 226a1ca90b3..226a1ca90b3 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 ce7a3ec2faf..ce7a3ec2faf 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 04e93c49f03..04e93c49f03 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 2e4f89d402e..2e4f89d402e 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 a425a6f9cdc..a425a6f9cdc 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 a34e75f59c1..a34e75f59c1 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 796b032384b..796b032384b 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 7b256a948c2..7b256a948c2 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 c99addfb624..c99addfb624 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 0385735ac6d..0385735ac6d 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 a45c0b50706..a45c0b50706 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 70f59b13c34..70f59b13c34 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 b22bb39b5f6..b22bb39b5f6 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 0f71470ace3..0f71470ace3 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 7dfb2815b9e..7dfb2815b9e 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 6ee837c5670..6ee837c5670 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 48f44763781..48f44763781 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 6c9279a6d60..6c9279a6d60 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 c9a6409edfe..c9a6409edfe 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 b8cfa1a6eae..b8cfa1a6eae 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 b58c394c655..b58c394c655 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 3db3b0a91cc..3db3b0a91cc 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 2b27d8da70a..2b27d8da70a 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 7399c915a93..7399c915a93 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 9db1f3952fd..9db1f3952fd 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 e7736a91553..e7736a91553 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 4e132519e25..4e132519e25 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 b7c301af16c..b7c301af16c 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 cf7c34a9945..cf7c34a9945 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 deac938d850..deac938d850 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 3c2b9be455d..3c2b9be455d 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 6bc9470fecb..6bc9470fecb 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 05e0e108386..05e0e108386 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 46cff59e28b..46cff59e28b 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 8f1b7d4f6a2..8f1b7d4f6a2 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 9134f03e3cf..9134f03e3cf 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 9230f4a8052..9230f4a8052 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 0127be2f3be..0127be2f3be 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 526ec0fc2f0..526ec0fc2f0 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 d76b0fa2af5..d76b0fa2af5 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 b6cb593f55c..b6cb593f55c 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 a97800a8e12..a97800a8e12 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 c5a0d27a02d..c5a0d27a02d 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 06bebd6acc4..06bebd6acc4 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 0dc2c2b22c2..0dc2c2b22c2 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 f5308d5929c..f5308d5929c 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 792aac0a8e7..792aac0a8e7 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 4bed6afe063..4bed6afe063 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 a2d18b0aa04..a2d18b0aa04 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 8a060a8a722..8a060a8a722 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 6903d3992ec..6903d3992ec 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 e4b329b8caf..e4b329b8caf 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 0302d82a12f..0302d82a12f 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 03dcac4ea4d..03dcac4ea4d 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 72816cf1670..72816cf1670 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 7e6c4fa130d..7e6c4fa130d 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 f974f6412ad..f974f6412ad 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 884c0eb757c..884c0eb757c 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 de502599bb1..de502599bb1 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 59274bfca95..2cd0de28a63 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 0925e6f33a9..0925e6f33a9 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 ef95a500b4d..ef95a500b4d 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 50defec318c..50defec318c 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 3d7e569f1cf..3d7e569f1cf 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 591e0e82e0e..591e0e82e0e 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 56210f0fc5e..56210f0fc5e 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 aca544472c9..aca544472c9 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 abee7213202..abee7213202 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 db56b42c56c..db56b42c56c 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 a44a03afbd3..a44a03afbd3 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 bee7280bbed..bee7280bbed 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 571c3a348d3..571c3a348d3 100644
--- a/drivers/staging/solo6x10/v4l2.c
+++ b/drivers/staging/media/solo6x10/v4l2.c
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index b445cd63f90..2542c374390 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -275,7 +275,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
275 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64; 275 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64;
276 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 276 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
277 struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i; 277 struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i;
278 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)(page_address(fs->page) + fs->page_offset)); 278 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)(page_address(fs->page.p) + fs->page_offset));
279 hw_buffer.s.size = fs->size; 279 hw_buffer.s.size = fs->size;
280 CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64; 280 CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64;
281 } 281 }
diff --git a/drivers/staging/rts5139/rts51x_scsi.c b/drivers/staging/rts5139/rts51x_scsi.c
index 3b32f9e6e4f..87c9cdc8bd2 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/rts_pstor/rtsx.c b/drivers/staging/rts_pstor/rtsx.c
index 480b0ed2e4d..115635f9502 100644
--- a/drivers/staging/rts_pstor/rtsx.c
+++ b/drivers/staging/rts_pstor/rtsx.c
@@ -1021,6 +1021,7 @@ static int __devinit rtsx_probe(struct pci_dev *pci,
1021 th = kthread_create(rtsx_scan_thread, dev, "rtsx-scan"); 1021 th = kthread_create(rtsx_scan_thread, dev, "rtsx-scan");
1022 if (IS_ERR(th)) { 1022 if (IS_ERR(th)) {
1023 printk(KERN_ERR "Unable to start the device-scanning thread\n"); 1023 printk(KERN_ERR "Unable to start the device-scanning thread\n");
1024 complete(&dev->scanning_done);
1024 quiesce_and_remove_host(dev); 1025 quiesce_and_remove_host(dev);
1025 err = PTR_ERR(th); 1026 err = PTR_ERR(th);
1026 goto errout; 1027 goto errout;
diff --git a/drivers/staging/slicoss/Kconfig b/drivers/staging/slicoss/Kconfig
index 5cde96b2e6e..5c2a15b42df 100644
--- a/drivers/staging/slicoss/Kconfig
+++ b/drivers/staging/slicoss/Kconfig
@@ -1,6 +1,6 @@
1config SLICOSS 1config SLICOSS
2 tristate "Alacritech Gigabit IS-NIC support" 2 tristate "Alacritech Gigabit IS-NIC support"
3 depends on PCI && X86 3 depends on PCI && X86 && NET
4 default n 4 default n
5 help 5 help
6 This driver supports Alacritech's IS-NIC gigabit ethernet cards. 6 This driver supports Alacritech's IS-NIC gigabit ethernet cards.
diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c
index 2bd34662beb..a9c309a167c 100644
--- a/drivers/staging/spectra/lld_mtd.c
+++ b/drivers/staging/spectra/lld_mtd.c
@@ -340,7 +340,7 @@ u16 mtd_Read_Page_Main_Spare(u8 *read_data, u32 Block,
340 struct mtd_oob_ops ops; 340 struct mtd_oob_ops ops;
341 int ret; 341 int ret;
342 342
343 ops.mode = MTD_OOB_AUTO; 343 ops.mode = MTD_OPS_AUTO_OOB;
344 ops.datbuf = read_data; 344 ops.datbuf = read_data;
345 ops.len = DeviceInfo.wPageDataSize; 345 ops.len = DeviceInfo.wPageDataSize;
346 ops.oobbuf = read_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET; 346 ops.oobbuf = read_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET;
@@ -400,7 +400,7 @@ u16 mtd_Write_Page_Main_Spare(u8 *write_data, u32 Block,
400 struct mtd_oob_ops ops; 400 struct mtd_oob_ops ops;
401 int ret; 401 int ret;
402 402
403 ops.mode = MTD_OOB_AUTO; 403 ops.mode = MTD_OPS_AUTO_OOB;
404 ops.datbuf = write_data; 404 ops.datbuf = write_data;
405 ops.len = DeviceInfo.wPageDataSize; 405 ops.len = DeviceInfo.wPageDataSize;
406 ops.oobbuf = write_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET; 406 ops.oobbuf = write_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET;
@@ -473,7 +473,7 @@ u16 mtd_Read_Page_Spare(u8 *read_data, u32 Block,
473 struct mtd_oob_ops ops; 473 struct mtd_oob_ops ops;
474 int ret; 474 int ret;
475 475
476 ops.mode = MTD_OOB_AUTO; 476 ops.mode = MTD_OPS_AUTO_OOB;
477 ops.datbuf = NULL; 477 ops.datbuf = NULL;
478 ops.len = 0; 478 ops.len = 0;
479 ops.oobbuf = read_data; 479 ops.oobbuf = read_data;
diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c
index f4b53d103c5..3b7a847f465 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 ecd1862539c..d332a34ddb6 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/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
index 09c44abb89e..3872b8cccdc 100644
--- a/drivers/staging/usbip/vhci_rx.c
+++ b/drivers/staging/usbip/vhci_rx.c
@@ -68,6 +68,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
68{ 68{
69 struct usbip_device *ud = &vdev->ud; 69 struct usbip_device *ud = &vdev->ud;
70 struct urb *urb; 70 struct urb *urb;
71 unsigned long flags;
71 72
72 spin_lock(&vdev->priv_lock); 73 spin_lock(&vdev->priv_lock);
73 urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum); 74 urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum);
@@ -101,9 +102,9 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
101 102
102 usbip_dbg_vhci_rx("now giveback urb %p\n", urb); 103 usbip_dbg_vhci_rx("now giveback urb %p\n", urb);
103 104
104 spin_lock(&the_controller->lock); 105 spin_lock_irqsave(&the_controller->lock, flags);
105 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 106 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
106 spin_unlock(&the_controller->lock); 107 spin_unlock_irqrestore(&the_controller->lock, flags);
107 108
108 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); 109 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status);
109 110
@@ -141,6 +142,7 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
141{ 142{
142 struct vhci_unlink *unlink; 143 struct vhci_unlink *unlink;
143 struct urb *urb; 144 struct urb *urb;
145 unsigned long flags;
144 146
145 usbip_dump_header(pdu); 147 usbip_dump_header(pdu);
146 148
@@ -170,9 +172,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
170 urb->status = pdu->u.ret_unlink.status; 172 urb->status = pdu->u.ret_unlink.status;
171 pr_info("urb->status %d\n", urb->status); 173 pr_info("urb->status %d\n", urb->status);
172 174
173 spin_lock(&the_controller->lock); 175 spin_lock_irqsave(&the_controller->lock, flags);
174 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 176 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
175 spin_unlock(&the_controller->lock); 177 spin_unlock_irqrestore(&the_controller->lock, flags);
176 178
177 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, 179 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
178 urb->status); 180 urb->status);
diff --git a/drivers/staging/winbond/wbusb.c b/drivers/staging/winbond/wbusb.c
index a2e8bd452ed..f958eb4f0d8 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 321580267fe..2faee2dd4bb 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 b9926ee0052..09de99fbb7e 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 4d01768fcd9..0fd96c10271 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 f1643dbf6a9..db327845e46 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 bbdbe9301b2..f1db83077e0 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 b15d8cbf630..3df1c9b8ae6 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 8f4447749c7..88f2ad43ec8 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 c86f97a081e..c5b4ecd3e74 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 38535eb1392..683ba02b824 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 00000000000..ad6b1e39300
--- /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 f870c3bcfd8..ba5edec2c5f 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 39f021b855e..ec4249be617 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 19a0be9c657..67cd6fe05bf 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 0639b975d6f..c68019d6c40 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 41ad02b5fb8..7698efe2926 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 0c4f783f924..5a4ebfc3a54 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 c8f47d06458..b97f6940dd0 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 dad671dee9e..ed32e1efe42 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 570b144a1ed..217e29df629 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 49fd0a9b0a5..8ddd133025b 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 d7525580448..3400ae6e93f 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 3749d8b4b42..e05c55100ec 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 6195026cc7b..4fac37c4c61 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/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 708f8e92771..dd9a5743fa9 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -678,10 +678,10 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
678 return; 678 return;
679 679
680 if (delay > 1000) 680 if (delay > 1000)
681 schedule_delayed_work(&(tz->poll_queue), 681 queue_delayed_work(system_freezable_wq, &(tz->poll_queue),
682 round_jiffies(msecs_to_jiffies(delay))); 682 round_jiffies(msecs_to_jiffies(delay)));
683 else 683 else
684 schedule_delayed_work(&(tz->poll_queue), 684 queue_delayed_work(system_freezable_wq, &(tz->poll_queue),
685 msecs_to_jiffies(delay)); 685 msecs_to_jiffies(delay));
686} 686}
687 687
diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index e371753ba92..4222035acfb 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 e2920531637..89abf40bc73 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_console.c b/drivers/tty/hvc/hvc_console.c
index 7430bc3c8d5..b6b2d18fa38 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -852,7 +852,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
852 * find index to use: 852 * find index to use:
853 * see if this vterm id matches one registered for console. 853 * see if this vterm id matches one registered for console.
854 */ 854 */
855 for (i = 0; i < MAX_NR_HVC_CONSOLES; i++) 855 for (i=0; i < MAX_NR_HVC_CONSOLES; i++)
856 if (vtermnos[i] == hp->vtermno && 856 if (vtermnos[i] == hp->vtermno &&
857 cons_ops[i] == hp->ops) 857 cons_ops[i] == hp->ops)
858 break; 858 break;
@@ -862,13 +862,9 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
862 i = ++last_hvc; 862 i = ++last_hvc;
863 863
864 hp->index = i; 864 hp->index = i;
865 hvc_console.index = i;
866 vtermnos[i] = vtermno;
867 cons_ops[i] = ops;
868 865
869 list_add_tail(&(hp->next), &hvc_structs); 866 list_add_tail(&(hp->next), &hvc_structs);
870 spin_unlock(&hvc_structs_lock); 867 spin_unlock(&hvc_structs_lock);
871 register_console(&hvc_console);
872 868
873 return hp; 869 return hp;
874} 870}
@@ -879,7 +875,6 @@ int hvc_remove(struct hvc_struct *hp)
879 unsigned long flags; 875 unsigned long flags;
880 struct tty_struct *tty; 876 struct tty_struct *tty;
881 877
882 unregister_console(&hvc_console);
883 spin_lock_irqsave(&hp->lock, flags); 878 spin_lock_irqsave(&hp->lock, flags);
884 tty = tty_kref_get(hp->tty); 879 tty = tty_kref_get(hp->tty);
885 880
diff --git a/drivers/tty/hvc/hvc_dcc.c b/drivers/tty/hvc/hvc_dcc.c
index 435f6facbc2..44fbebab507 100644
--- a/drivers/tty/hvc/hvc_dcc.c
+++ b/drivers/tty/hvc/hvc_dcc.c
@@ -46,6 +46,7 @@ static inline char __dcc_getchar(void)
46 46
47 asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg" 47 asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
48 : "=r" (__c)); 48 : "=r" (__c));
49 isb();
49 50
50 return __c; 51 return __c;
51} 52}
@@ -55,6 +56,7 @@ static inline void __dcc_putchar(char c)
55 asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char" 56 asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
56 : /* no output register */ 57 : /* no output register */
57 : "r" (c)); 58 : "r" (c));
59 isb();
58} 60}
59 61
60static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count) 62static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
diff --git a/drivers/tty/hvc/hvc_iseries.c b/drivers/tty/hvc/hvc_iseries.c
index 21c54955084..3f4a897bf4d 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 00000000000..ced26c8ccd5
--- /dev/null
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -0,0 +1,425 @@
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#include <linux/export.h>
32
33#include <asm/hvconsole.h>
34#include <asm/prom.h>
35#include <asm/firmware.h>
36#include <asm/hvsi.h>
37#include <asm/udbg.h>
38#include <asm/opal.h>
39
40#include "hvc_console.h"
41
42static const char hvc_opal_name[] = "hvc_opal";
43
44static struct of_device_id hvc_opal_match[] __devinitdata = {
45 { .name = "serial", .compatible = "ibm,opal-console-raw" },
46 { .name = "serial", .compatible = "ibm,opal-console-hvsi" },
47 { },
48};
49
50typedef enum hv_protocol {
51 HV_PROTOCOL_RAW,
52 HV_PROTOCOL_HVSI
53} hv_protocol_t;
54
55struct hvc_opal_priv {
56 hv_protocol_t proto; /* Raw data or HVSI packets */
57 struct hvsi_priv hvsi; /* HVSI specific data */
58};
59static struct hvc_opal_priv *hvc_opal_privs[MAX_NR_HVC_CONSOLES];
60
61/* For early boot console */
62static struct hvc_opal_priv hvc_opal_boot_priv;
63static u32 hvc_opal_boot_termno;
64
65static const struct hv_ops hvc_opal_raw_ops = {
66 .get_chars = opal_get_chars,
67 .put_chars = opal_put_chars,
68 .notifier_add = notifier_add_irq,
69 .notifier_del = notifier_del_irq,
70 .notifier_hangup = notifier_hangup_irq,
71};
72
73static int hvc_opal_hvsi_get_chars(uint32_t vtermno, char *buf, int count)
74{
75 struct hvc_opal_priv *pv = hvc_opal_privs[vtermno];
76
77 if (WARN_ON(!pv))
78 return -ENODEV;
79
80 return hvsilib_get_chars(&pv->hvsi, buf, count);
81}
82
83static int hvc_opal_hvsi_put_chars(uint32_t vtermno, const char *buf, int count)
84{
85 struct hvc_opal_priv *pv = hvc_opal_privs[vtermno];
86
87 if (WARN_ON(!pv))
88 return -ENODEV;
89
90 return hvsilib_put_chars(&pv->hvsi, buf, count);
91}
92
93static int hvc_opal_hvsi_open(struct hvc_struct *hp, int data)
94{
95 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
96 int rc;
97
98 pr_devel("HVSI@%x: do open !\n", hp->vtermno);
99
100 rc = notifier_add_irq(hp, data);
101 if (rc)
102 return rc;
103
104 return hvsilib_open(&pv->hvsi, hp);
105}
106
107static void hvc_opal_hvsi_close(struct hvc_struct *hp, int data)
108{
109 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
110
111 pr_devel("HVSI@%x: do close !\n", hp->vtermno);
112
113 hvsilib_close(&pv->hvsi, hp);
114
115 notifier_del_irq(hp, data);
116}
117
118void hvc_opal_hvsi_hangup(struct hvc_struct *hp, int data)
119{
120 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
121
122 pr_devel("HVSI@%x: do hangup !\n", hp->vtermno);
123
124 hvsilib_close(&pv->hvsi, hp);
125
126 notifier_hangup_irq(hp, data);
127}
128
129static int hvc_opal_hvsi_tiocmget(struct hvc_struct *hp)
130{
131 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
132
133 if (!pv)
134 return -EINVAL;
135 return pv->hvsi.mctrl;
136}
137
138static int hvc_opal_hvsi_tiocmset(struct hvc_struct *hp, unsigned int set,
139 unsigned int clear)
140{
141 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
142
143 pr_devel("HVSI@%x: Set modem control, set=%x,clr=%x\n",
144 hp->vtermno, set, clear);
145
146 if (set & TIOCM_DTR)
147 hvsilib_write_mctrl(&pv->hvsi, 1);
148 else if (clear & TIOCM_DTR)
149 hvsilib_write_mctrl(&pv->hvsi, 0);
150
151 return 0;
152}
153
154static const struct hv_ops hvc_opal_hvsi_ops = {
155 .get_chars = hvc_opal_hvsi_get_chars,
156 .put_chars = hvc_opal_hvsi_put_chars,
157 .notifier_add = hvc_opal_hvsi_open,
158 .notifier_del = hvc_opal_hvsi_close,
159 .notifier_hangup = hvc_opal_hvsi_hangup,
160 .tiocmget = hvc_opal_hvsi_tiocmget,
161 .tiocmset = hvc_opal_hvsi_tiocmset,
162};
163
164static int __devinit hvc_opal_probe(struct platform_device *dev)
165{
166 const struct hv_ops *ops;
167 struct hvc_struct *hp;
168 struct hvc_opal_priv *pv;
169 hv_protocol_t proto;
170 unsigned int termno, boot = 0;
171 const __be32 *reg;
172
173 if (of_device_is_compatible(dev->dev.of_node, "ibm,opal-console-raw")) {
174 proto = HV_PROTOCOL_RAW;
175 ops = &hvc_opal_raw_ops;
176 } else if (of_device_is_compatible(dev->dev.of_node,
177 "ibm,opal-console-hvsi")) {
178 proto = HV_PROTOCOL_HVSI;
179 ops = &hvc_opal_hvsi_ops;
180 } else {
181 pr_err("hvc_opal: Unkown protocol for %s\n",
182 dev->dev.of_node->full_name);
183 return -ENXIO;
184 }
185
186 reg = of_get_property(dev->dev.of_node, "reg", NULL);
187 termno = reg ? be32_to_cpup(reg) : 0;
188
189 /* Is it our boot one ? */
190 if (hvc_opal_privs[termno] == &hvc_opal_boot_priv) {
191 pv = hvc_opal_privs[termno];
192 boot = 1;
193 } else if (hvc_opal_privs[termno] == NULL) {
194 pv = kzalloc(sizeof(struct hvc_opal_priv), GFP_KERNEL);
195 if (!pv)
196 return -ENOMEM;
197 pv->proto = proto;
198 hvc_opal_privs[termno] = pv;
199 if (proto == HV_PROTOCOL_HVSI)
200 hvsilib_init(&pv->hvsi, opal_get_chars, opal_put_chars,
201 termno, 0);
202
203 /* Instanciate now to establish a mapping index==vtermno */
204 hvc_instantiate(termno, termno, ops);
205 } else {
206 pr_err("hvc_opal: Device %s has duplicate terminal number #%d\n",
207 dev->dev.of_node->full_name, termno);
208 return -ENXIO;
209 }
210
211 pr_info("hvc%d: %s protocol on %s%s\n", termno,
212 proto == HV_PROTOCOL_RAW ? "raw" : "hvsi",
213 dev->dev.of_node->full_name,
214 boot ? " (boot console)" : "");
215
216 /* We don't do IRQ yet */
217 hp = hvc_alloc(termno, 0, ops, MAX_VIO_PUT_CHARS);
218 if (IS_ERR(hp))
219 return PTR_ERR(hp);
220 dev_set_drvdata(&dev->dev, hp);
221
222 return 0;
223}
224
225static int __devexit hvc_opal_remove(struct platform_device *dev)
226{
227 struct hvc_struct *hp = dev_get_drvdata(&dev->dev);
228 int rc, termno;
229
230 termno = hp->vtermno;
231 rc = hvc_remove(hp);
232 if (rc == 0) {
233 if (hvc_opal_privs[termno] != &hvc_opal_boot_priv)
234 kfree(hvc_opal_privs[termno]);
235 hvc_opal_privs[termno] = NULL;
236 }
237 return rc;
238}
239
240static struct platform_driver hvc_opal_driver = {
241 .probe = hvc_opal_probe,
242 .remove = __devexit_p(hvc_opal_remove),
243 .driver = {
244 .name = hvc_opal_name,
245 .owner = THIS_MODULE,
246 .of_match_table = hvc_opal_match,
247 }
248};
249
250static int __init hvc_opal_init(void)
251{
252 if (!firmware_has_feature(FW_FEATURE_OPAL))
253 return -ENODEV;
254
255 /* Register as a vio device to receive callbacks */
256 return platform_driver_register(&hvc_opal_driver);
257}
258module_init(hvc_opal_init);
259
260static void __exit hvc_opal_exit(void)
261{
262 platform_driver_unregister(&hvc_opal_driver);
263}
264module_exit(hvc_opal_exit);
265
266static void udbg_opal_putc(char c)
267{
268 unsigned int termno = hvc_opal_boot_termno;
269 int count = -1;
270
271 if (c == '\n')
272 udbg_opal_putc('\r');
273
274 do {
275 switch(hvc_opal_boot_priv.proto) {
276 case HV_PROTOCOL_RAW:
277 count = opal_put_chars(termno, &c, 1);
278 break;
279 case HV_PROTOCOL_HVSI:
280 count = hvc_opal_hvsi_put_chars(termno, &c, 1);
281 break;
282 }
283 } while(count == 0 || count == -EAGAIN);
284}
285
286static int udbg_opal_getc_poll(void)
287{
288 unsigned int termno = hvc_opal_boot_termno;
289 int rc = 0;
290 char c;
291
292 switch(hvc_opal_boot_priv.proto) {
293 case HV_PROTOCOL_RAW:
294 rc = opal_get_chars(termno, &c, 1);
295 break;
296 case HV_PROTOCOL_HVSI:
297 rc = hvc_opal_hvsi_get_chars(termno, &c, 1);
298 break;
299 }
300 if (!rc)
301 return -1;
302 return c;
303}
304
305static int udbg_opal_getc(void)
306{
307 int ch;
308 for (;;) {
309 ch = udbg_opal_getc_poll();
310 if (ch == -1) {
311 /* This shouldn't be needed...but... */
312 volatile unsigned long delay;
313 for (delay=0; delay < 2000000; delay++)
314 ;
315 } else {
316 return ch;
317 }
318 }
319}
320
321static void udbg_init_opal_common(void)
322{
323 udbg_putc = udbg_opal_putc;
324 udbg_getc = udbg_opal_getc;
325 udbg_getc_poll = udbg_opal_getc_poll;
326 tb_ticks_per_usec = 0x200; /* Make udelay not suck */
327}
328
329void __init hvc_opal_init_early(void)
330{
331 struct device_node *stdout_node = NULL;
332 const u32 *termno;
333 const char *name = NULL;
334 const struct hv_ops *ops;
335 u32 index;
336
337 /* find the boot console from /chosen/stdout */
338 if (of_chosen)
339 name = of_get_property(of_chosen, "linux,stdout-path", NULL);
340 if (name) {
341 stdout_node = of_find_node_by_path(name);
342 if (!stdout_node) {
343 pr_err("hvc_opal: Failed to locate default console!\n");
344 return;
345 }
346 } else {
347 struct device_node *opal, *np;
348
349 /* Current OPAL takeover doesn't provide the stdout
350 * path, so we hard wire it
351 */
352 opal = of_find_node_by_path("/ibm,opal/consoles");
353 if (opal)
354 pr_devel("hvc_opal: Found consoles in new location\n");
355 if (!opal) {
356 opal = of_find_node_by_path("/ibm,opal");
357 if (opal)
358 pr_devel("hvc_opal: "
359 "Found consoles in old location\n");
360 }
361 if (!opal)
362 return;
363 for_each_child_of_node(opal, np) {
364 if (!strcmp(np->name, "serial")) {
365 stdout_node = np;
366 break;
367 }
368 }
369 of_node_put(opal);
370 }
371 if (!stdout_node)
372 return;
373 termno = of_get_property(stdout_node, "reg", NULL);
374 index = termno ? *termno : 0;
375 if (index >= MAX_NR_HVC_CONSOLES)
376 return;
377 hvc_opal_privs[index] = &hvc_opal_boot_priv;
378
379 /* Check the protocol */
380 if (of_device_is_compatible(stdout_node, "ibm,opal-console-raw")) {
381 hvc_opal_boot_priv.proto = HV_PROTOCOL_RAW;
382 ops = &hvc_opal_raw_ops;
383 pr_devel("hvc_opal: Found RAW console\n");
384 }
385 else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) {
386 hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI;
387 ops = &hvc_opal_hvsi_ops;
388 hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars,
389 opal_put_chars, index, 1);
390 /* HVSI, perform the handshake now */
391 hvsilib_establish(&hvc_opal_boot_priv.hvsi);
392 pr_devel("hvc_opal: Found HVSI console\n");
393 } else
394 goto out;
395 hvc_opal_boot_termno = index;
396 udbg_init_opal_common();
397 add_preferred_console("hvc", index, NULL);
398 hvc_instantiate(index, index, ops);
399out:
400 of_node_put(stdout_node);
401}
402
403#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_RAW
404void __init udbg_init_debug_opal(void)
405{
406 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
407 hvc_opal_privs[index] = &hvc_opal_boot_priv;
408 hvc_opal_boot_priv.proto = HV_PROTOCOL_RAW;
409 hvc_opal_boot_termno = index;
410 udbg_init_opal_common();
411}
412#endif /* CONFIG_PPC_EARLY_DEBUG_OPAL_RAW */
413
414#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI
415void __init udbg_init_debug_opal_hvsi(void)
416{
417 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
418 hvc_opal_privs[index] = &hvc_opal_boot_priv;
419 hvc_opal_boot_termno = index;
420 udbg_init_opal_common();
421 hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, opal_put_chars,
422 index, 1);
423 hvsilib_establish(&hvc_opal_boot_priv.hvsi);
424}
425#endif /* CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI */
diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c
index 130aace67f3..fc3c3ad6c07 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 55882b5930a..b9040bec36b 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 bd9b09827b2..6f4dd83d869 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/n_gsm.c b/drivers/tty/n_gsm.c
index 4cb0d0a3e57..fc7bbba585c 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -66,14 +66,16 @@
66static int debug; 66static int debug;
67module_param(debug, int, 0600); 67module_param(debug, int, 0600);
68 68
69#define T1 (HZ/10) 69/* Defaults: these are from the specification */
70#define T2 (HZ/3) 70
71#define N2 3 71#define T1 10 /* 100mS */
72#define T2 34 /* 333mS */
73#define N2 3 /* Retry 3 times */
72 74
73/* Use long timers for testing at low speed with debug on */ 75/* Use long timers for testing at low speed with debug on */
74#ifdef DEBUG_TIMING 76#ifdef DEBUG_TIMING
75#define T1 HZ 77#define T1 100
76#define T2 (2 * HZ) 78#define T2 200
77#endif 79#endif
78 80
79/* 81/*
diff --git a/drivers/tty/serial/8250.c b/drivers/tty/serial/8250.c
index a87a56cb541..eeadf1b8e09 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/Kconfig b/drivers/tty/serial/Kconfig
index 5f479dada6f..925a1e547a8 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1560,7 +1560,7 @@ config SERIAL_IFX6X60
1560 Support for the IFX6x60 modem devices on Intel MID platforms. 1560 Support for the IFX6x60 modem devices on Intel MID platforms.
1561 1561
1562config SERIAL_PCH_UART 1562config SERIAL_PCH_UART
1563 tristate "Intel EG20T PCH / OKI SEMICONDUCTOR IOH(ML7213/ML7223) UART" 1563 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) UART"
1564 depends on PCI 1564 depends on PCI
1565 select SERIAL_CORE 1565 select SERIAL_CORE
1566 help 1566 help
@@ -1568,12 +1568,12 @@ config SERIAL_PCH_UART
1568 which is an IOH(Input/Output Hub) for x86 embedded processor. 1568 which is an IOH(Input/Output Hub) for x86 embedded processor.
1569 Enabling PCH_DMA, this PCH UART works as DMA mode. 1569 Enabling PCH_DMA, this PCH UART works as DMA mode.
1570 1570
1571 This driver also can be used for OKI SEMICONDUCTOR IOH(Input/ 1571 This driver also can be used for LAPIS Semiconductor IOH(Input/
1572 Output Hub), ML7213 and ML7223. 1572 Output Hub), ML7213, ML7223 and ML7831.
1573 ML7213 IOH is for IVI(In-Vehicle Infotainment) use and ML7223 IOH is 1573 ML7213 IOH is for IVI(In-Vehicle Infotainment) use, ML7223 IOH is
1574 for MP(Media Phone) use. 1574 for MP(Media Phone) use and ML7831 IOH is for general purpose use.
1575 ML7213/ML7223 is companion chip for Intel Atom E6xx series. 1575 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series.
1576 ML7213/ML7223 is completely compatible for Intel EG20T PCH. 1576 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH.
1577 1577
1578config SERIAL_MSM_SMD 1578config SERIAL_MSM_SMD
1579 bool "Enable tty device interface for some SMD ports" 1579 bool "Enable tty device interface for some SMD ports"
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 4a0f86fa1e9..4c823f341d9 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -228,7 +228,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
228 if (rs485conf->flags & SER_RS485_ENABLED) { 228 if (rs485conf->flags & SER_RS485_ENABLED) {
229 dev_dbg(port->dev, "Setting UART to RS485\n"); 229 dev_dbg(port->dev, "Setting UART to RS485\n");
230 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; 230 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
231 if (rs485conf->flags & SER_RS485_RTS_AFTER_SEND) 231 if ((rs485conf->delay_rts_after_send) > 0)
232 UART_PUT_TTGR(port, rs485conf->delay_rts_after_send); 232 UART_PUT_TTGR(port, rs485conf->delay_rts_after_send);
233 mode |= ATMEL_US_USMODE_RS485; 233 mode |= ATMEL_US_USMODE_RS485;
234 } else { 234 } else {
@@ -304,7 +304,7 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
304 304
305 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 305 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
306 dev_dbg(port->dev, "Setting UART to RS485\n"); 306 dev_dbg(port->dev, "Setting UART to RS485\n");
307 if (atmel_port->rs485.flags & SER_RS485_RTS_AFTER_SEND) 307 if ((atmel_port->rs485.delay_rts_after_send) > 0)
308 UART_PUT_TTGR(port, 308 UART_PUT_TTGR(port,
309 atmel_port->rs485.delay_rts_after_send); 309 atmel_port->rs485.delay_rts_after_send);
310 mode |= ATMEL_US_USMODE_RS485; 310 mode |= ATMEL_US_USMODE_RS485;
@@ -1228,7 +1228,7 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
1228 1228
1229 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 1229 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
1230 dev_dbg(port->dev, "Setting UART to RS485\n"); 1230 dev_dbg(port->dev, "Setting UART to RS485\n");
1231 if (atmel_port->rs485.flags & SER_RS485_RTS_AFTER_SEND) 1231 if ((atmel_port->rs485.delay_rts_after_send) > 0)
1232 UART_PUT_TTGR(port, 1232 UART_PUT_TTGR(port,
1233 atmel_port->rs485.delay_rts_after_send); 1233 atmel_port->rs485.delay_rts_after_send);
1234 mode |= ATMEL_US_USMODE_RS485; 1234 mode |= ATMEL_US_USMODE_RS485;
@@ -1447,16 +1447,6 @@ static void __devinit atmel_of_init_port(struct atmel_uart_port *atmel_port,
1447 rs485conf->delay_rts_after_send = rs485_delay[1]; 1447 rs485conf->delay_rts_after_send = rs485_delay[1];
1448 rs485conf->flags = 0; 1448 rs485conf->flags = 0;
1449 1449
1450 if (rs485conf->delay_rts_before_send == 0 &&
1451 rs485conf->delay_rts_after_send == 0) {
1452 rs485conf->flags |= SER_RS485_RTS_ON_SEND;
1453 } else {
1454 if (rs485conf->delay_rts_before_send)
1455 rs485conf->flags |= SER_RS485_RTS_BEFORE_SEND;
1456 if (rs485conf->delay_rts_after_send)
1457 rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
1458 }
1459
1460 if (of_get_property(np, "rs485-rx-during-tx", NULL)) 1450 if (of_get_property(np, "rs485-rx-during-tx", NULL))
1461 rs485conf->flags |= SER_RS485_RX_DURING_TX; 1451 rs485conf->flags |= SER_RS485_RX_DURING_TX;
1462 1452
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index b7435043f2f..1dfba7b779c 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -3234,9 +3234,8 @@ rs_write(struct tty_struct *tty,
3234 e100_disable_rx(info); 3234 e100_disable_rx(info);
3235 e100_enable_rx_irq(info); 3235 e100_enable_rx_irq(info);
3236#endif 3236#endif
3237 if ((info->rs485.flags & SER_RS485_RTS_BEFORE_SEND) && 3237 if (info->rs485.delay_rts_before_send > 0)
3238 (info->rs485.delay_rts_before_send > 0)) 3238 msleep(info->rs485.delay_rts_before_send);
3239 msleep(info->rs485.delay_rts_before_send);
3240 } 3239 }
3241#endif /* CONFIG_ETRAX_RS485 */ 3240#endif /* CONFIG_ETRAX_RS485 */
3242 3241
@@ -3693,10 +3692,6 @@ rs_ioctl(struct tty_struct *tty,
3693 3692
3694 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send; 3693 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send;
3695 rs485data.flags = 0; 3694 rs485data.flags = 0;
3696 if (rs485data.delay_rts_before_send != 0)
3697 rs485data.flags |= SER_RS485_RTS_BEFORE_SEND;
3698 else
3699 rs485data.flags &= ~(SER_RS485_RTS_BEFORE_SEND);
3700 3695
3701 if (rs485ctrl.enabled) 3696 if (rs485ctrl.enabled)
3702 rs485data.flags |= SER_RS485_ENABLED; 3697 rs485data.flags |= SER_RS485_ENABLED;
@@ -4531,7 +4526,6 @@ static int __init rs_init(void)
4531 /* Set sane defaults */ 4526 /* Set sane defaults */
4532 info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND); 4527 info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND);
4533 info->rs485.flags |= SER_RS485_RTS_AFTER_SEND; 4528 info->rs485.flags |= SER_RS485_RTS_AFTER_SEND;
4534 info->rs485.flags &= ~(SER_RS485_RTS_BEFORE_SEND);
4535 info->rs485.delay_rts_before_send = 0; 4529 info->rs485.delay_rts_before_send = 0;
4536 info->rs485.flags &= ~(SER_RS485_ENABLED); 4530 info->rs485.flags &= ~(SER_RS485_ENABLED);
4537#endif 4531#endif
diff --git a/drivers/tty/serial/jsm/jsm_driver.c b/drivers/tty/serial/jsm/jsm_driver.c
index 648b6a3efa3..7c867a046c9 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 87e7e6c876d..2b42a01a81c 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 2af5aa5f3a8..8a6cc8c30b5 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 d73aadd7a9a..90c40f22ec7 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 db00b595cab..7827000db4f 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/mfd.c b/drivers/tty/serial/mfd.c
index 286c386d9c4..e272d3919c6 100644
--- a/drivers/tty/serial/mfd.c
+++ b/drivers/tty/serial/mfd.c
@@ -884,7 +884,6 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
884{ 884{
885 struct uart_hsu_port *up = 885 struct uart_hsu_port *up =
886 container_of(port, struct uart_hsu_port, port); 886 container_of(port, struct uart_hsu_port, port);
887 struct tty_struct *tty = port->state->port.tty;
888 unsigned char cval, fcr = 0; 887 unsigned char cval, fcr = 0;
889 unsigned long flags; 888 unsigned long flags;
890 unsigned int baud, quot; 889 unsigned int baud, quot;
@@ -907,8 +906,7 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
907 } 906 }
908 907
909 /* CMSPAR isn't supported by this driver */ 908 /* CMSPAR isn't supported by this driver */
910 if (tty) 909 termios->c_cflag &= ~CMSPAR;
911 tty->termios->c_cflag &= ~CMSPAR;
912 910
913 if (termios->c_cflag & CSTOPB) 911 if (termios->c_cflag & CSTOPB)
914 cval |= UART_LCR_STOP; 912 cval |= UART_LCR_STOP;
diff --git a/drivers/tty/serial/nwpserial.c b/drivers/tty/serial/nwpserial.c
index 9beaff1cec2..dd4c31d1aee 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/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 21febef926a..d6aba8c087e 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -1,5 +1,5 @@
1/* 1/*
2 *Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. 2 *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
3 * 3 *
4 *This program is free software; you can redistribute it and/or modify 4 *This program is free software; you can redistribute it and/or modify
5 *it under the terms of the GNU General Public License as published by 5 *it under the terms of the GNU General Public License as published by
@@ -46,8 +46,8 @@ enum {
46 46
47/* Set the max number of UART port 47/* Set the max number of UART port
48 * Intel EG20T PCH: 4 port 48 * Intel EG20T PCH: 4 port
49 * OKI SEMICONDUCTOR ML7213 IOH: 3 port 49 * LAPIS Semiconductor ML7213 IOH: 3 port
50 * OKI SEMICONDUCTOR ML7223 IOH: 2 port 50 * LAPIS Semiconductor ML7223 IOH: 2 port
51*/ 51*/
52#define PCH_UART_NR 4 52#define PCH_UART_NR 4
53 53
@@ -258,6 +258,8 @@ enum pch_uart_num_t {
258 pch_ml7213_uart2, 258 pch_ml7213_uart2,
259 pch_ml7223_uart0, 259 pch_ml7223_uart0,
260 pch_ml7223_uart1, 260 pch_ml7223_uart1,
261 pch_ml7831_uart0,
262 pch_ml7831_uart1,
261}; 263};
262 264
263static struct pch_uart_driver_data drv_dat[] = { 265static struct pch_uart_driver_data drv_dat[] = {
@@ -270,6 +272,8 @@ static struct pch_uart_driver_data drv_dat[] = {
270 [pch_ml7213_uart2] = {PCH_UART_2LINE, 2}, 272 [pch_ml7213_uart2] = {PCH_UART_2LINE, 2},
271 [pch_ml7223_uart0] = {PCH_UART_8LINE, 0}, 273 [pch_ml7223_uart0] = {PCH_UART_8LINE, 0},
272 [pch_ml7223_uart1] = {PCH_UART_2LINE, 1}, 274 [pch_ml7223_uart1] = {PCH_UART_2LINE, 1},
275 [pch_ml7831_uart0] = {PCH_UART_8LINE, 0},
276 [pch_ml7831_uart1] = {PCH_UART_2LINE, 1},
273}; 277};
274 278
275static unsigned int default_baud = 9600; 279static unsigned int default_baud = 9600;
@@ -628,6 +632,7 @@ static void pch_request_dma(struct uart_port *port)
628 dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n", 632 dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n",
629 __func__); 633 __func__);
630 dma_release_channel(priv->chan_tx); 634 dma_release_channel(priv->chan_tx);
635 priv->chan_tx = NULL;
631 return; 636 return;
632 } 637 }
633 638
@@ -1215,8 +1220,7 @@ static void pch_uart_shutdown(struct uart_port *port)
1215 dev_err(priv->port.dev, 1220 dev_err(priv->port.dev,
1216 "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret); 1221 "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret);
1217 1222
1218 if (priv->use_dma_flag) 1223 pch_free_dma(port);
1219 pch_free_dma(port);
1220 1224
1221 free_irq(priv->port.irq, priv); 1225 free_irq(priv->port.irq, priv);
1222} 1226}
@@ -1280,6 +1284,7 @@ static void pch_uart_set_termios(struct uart_port *port,
1280 if (rtn) 1284 if (rtn)
1281 goto out; 1285 goto out;
1282 1286
1287 pch_uart_set_mctrl(&priv->port, priv->port.mctrl);
1283 /* Don't rewrite B0 */ 1288 /* Don't rewrite B0 */
1284 if (tty_termios_baud_rate(termios)) 1289 if (tty_termios_baud_rate(termios))
1285 tty_termios_encode_baud_rate(termios, baud, baud); 1290 tty_termios_encode_baud_rate(termios, baud, baud);
@@ -1552,6 +1557,10 @@ static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id) = {
1552 .driver_data = pch_ml7223_uart0}, 1557 .driver_data = pch_ml7223_uart0},
1553 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D), 1558 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D),
1554 .driver_data = pch_ml7223_uart1}, 1559 .driver_data = pch_ml7223_uart1},
1560 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8811),
1561 .driver_data = pch_ml7831_uart0},
1562 {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8812),
1563 .driver_data = pch_ml7831_uart1},
1555 {0,}, 1564 {0,},
1556}; 1565};
1557 1566
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 9871c57b348..aff9d612dff 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -207,6 +207,25 @@ static struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
207 }, 207 },
208 208
209 /* 209 /*
210 * Common SH-2(A) SCIF definitions for ports with FIFO data
211 * count registers.
212 */
213 [SCIx_SH2_SCIF_FIFODATA_REGTYPE] = {
214 [SCSMR] = { 0x00, 16 },
215 [SCBRR] = { 0x04, 8 },
216 [SCSCR] = { 0x08, 16 },
217 [SCxTDR] = { 0x0c, 8 },
218 [SCxSR] = { 0x10, 16 },
219 [SCxRDR] = { 0x14, 8 },
220 [SCFCR] = { 0x18, 16 },
221 [SCFDR] = { 0x1c, 16 },
222 [SCTFDR] = sci_reg_invalid,
223 [SCRFDR] = sci_reg_invalid,
224 [SCSPTR] = { 0x20, 16 },
225 [SCLSR] = { 0x24, 16 },
226 },
227
228 /*
210 * Common SH-3 SCIF definitions. 229 * Common SH-3 SCIF definitions.
211 */ 230 */
212 [SCIx_SH3_SCIF_REGTYPE] = { 231 [SCIx_SH3_SCIF_REGTYPE] = {
@@ -1446,12 +1465,8 @@ static bool filter(struct dma_chan *chan, void *slave)
1446 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__, 1465 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__,
1447 param->slave_id); 1466 param->slave_id);
1448 1467
1449 if (param->dma_dev == chan->device->dev) { 1468 chan->private = param;
1450 chan->private = param; 1469 return true;
1451 return true;
1452 } else {
1453 return false;
1454 }
1455} 1470}
1456 1471
1457static void rx_timer_fn(unsigned long arg) 1472static void rx_timer_fn(unsigned long arg)
@@ -1477,10 +1492,10 @@ static void sci_request_dma(struct uart_port *port)
1477 dma_cap_mask_t mask; 1492 dma_cap_mask_t mask;
1478 int nent; 1493 int nent;
1479 1494
1480 dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__, 1495 dev_dbg(port->dev, "%s: port %d\n", __func__,
1481 port->line, s->cfg->dma_dev); 1496 port->line);
1482 1497
1483 if (!s->cfg->dma_dev) 1498 if (s->cfg->dma_slave_tx <= 0 || s->cfg->dma_slave_rx <= 0)
1484 return; 1499 return;
1485 1500
1486 dma_cap_zero(mask); 1501 dma_cap_zero(mask);
@@ -1490,7 +1505,6 @@ static void sci_request_dma(struct uart_port *port)
1490 1505
1491 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */ 1506 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */
1492 param->slave_id = s->cfg->dma_slave_tx; 1507 param->slave_id = s->cfg->dma_slave_tx;
1493 param->dma_dev = s->cfg->dma_dev;
1494 1508
1495 s->cookie_tx = -EINVAL; 1509 s->cookie_tx = -EINVAL;
1496 chan = dma_request_channel(mask, filter, param); 1510 chan = dma_request_channel(mask, filter, param);
@@ -1519,7 +1533,6 @@ static void sci_request_dma(struct uart_port *port)
1519 1533
1520 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */ 1534 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */
1521 param->slave_id = s->cfg->dma_slave_rx; 1535 param->slave_id = s->cfg->dma_slave_rx;
1522 param->dma_dev = s->cfg->dma_dev;
1523 1536
1524 chan = dma_request_channel(mask, filter, param); 1537 chan = dma_request_channel(mask, filter, param);
1525 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan); 1538 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan);
@@ -1564,9 +1577,6 @@ static void sci_free_dma(struct uart_port *port)
1564{ 1577{
1565 struct sci_port *s = to_sci_port(port); 1578 struct sci_port *s = to_sci_port(port);
1566 1579
1567 if (!s->cfg->dma_dev)
1568 return;
1569
1570 if (s->chan_tx) 1580 if (s->chan_tx)
1571 sci_tx_dma_release(s, false); 1581 sci_tx_dma_release(s, false);
1572 if (s->chan_rx) 1582 if (s->chan_rx)
@@ -1981,9 +1991,9 @@ static int __devinit sci_init_single(struct platform_device *dev,
1981 port->serial_in = sci_serial_in; 1991 port->serial_in = sci_serial_in;
1982 port->serial_out = sci_serial_out; 1992 port->serial_out = sci_serial_out;
1983 1993
1984 if (p->dma_dev) 1994 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0)
1985 dev_dbg(port->dev, "DMA device %p, tx %d, rx %d\n", 1995 dev_dbg(port->dev, "DMA tx %d, rx %d\n",
1986 p->dma_dev, p->dma_slave_tx, p->dma_slave_rx); 1996 p->dma_slave_tx, p->dma_slave_rx);
1987 1997
1988 return 0; 1998 return 0;
1989} 1999}
diff --git a/drivers/tty/serial/timbuart.c b/drivers/tty/serial/timbuart.c
index a4b63bfeaa2..e76c8b747fb 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 8c03b127fd0..b627363352e 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/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 512c49f98e8..8e0924f5544 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -36,6 +36,7 @@
36 36
37#include <linux/kmod.h> 37#include <linux/kmod.h>
38#include <linux/nsproxy.h> 38#include <linux/nsproxy.h>
39#include <linux/ratelimit.h>
39 40
40/* 41/*
41 * This guards the refcounted line discipline lists. The lock 42 * This guards the refcounted line discipline lists. The lock
@@ -547,15 +548,16 @@ static void tty_ldisc_flush_works(struct tty_struct *tty)
547/** 548/**
548 * tty_ldisc_wait_idle - wait for the ldisc to become idle 549 * tty_ldisc_wait_idle - wait for the ldisc to become idle
549 * @tty: tty to wait for 550 * @tty: tty to wait for
551 * @timeout: for how long to wait at most
550 * 552 *
551 * Wait for the line discipline to become idle. The discipline must 553 * Wait for the line discipline to become idle. The discipline must
552 * have been halted for this to guarantee it remains idle. 554 * have been halted for this to guarantee it remains idle.
553 */ 555 */
554static int tty_ldisc_wait_idle(struct tty_struct *tty) 556static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout)
555{ 557{
556 int ret; 558 long ret;
557 ret = wait_event_timeout(tty_ldisc_idle, 559 ret = wait_event_timeout(tty_ldisc_idle,
558 atomic_read(&tty->ldisc->users) == 1, 5 * HZ); 560 atomic_read(&tty->ldisc->users) == 1, timeout);
559 if (ret < 0) 561 if (ret < 0)
560 return ret; 562 return ret;
561 return ret > 0 ? 0 : -EBUSY; 563 return ret > 0 ? 0 : -EBUSY;
@@ -665,7 +667,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
665 667
666 tty_ldisc_flush_works(tty); 668 tty_ldisc_flush_works(tty);
667 669
668 retval = tty_ldisc_wait_idle(tty); 670 retval = tty_ldisc_wait_idle(tty, 5 * HZ);
669 671
670 tty_lock(); 672 tty_lock();
671 mutex_lock(&tty->ldisc_mutex); 673 mutex_lock(&tty->ldisc_mutex);
@@ -762,8 +764,6 @@ static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
762 if (IS_ERR(ld)) 764 if (IS_ERR(ld))
763 return -1; 765 return -1;
764 766
765 WARN_ON_ONCE(tty_ldisc_wait_idle(tty));
766
767 tty_ldisc_close(tty, tty->ldisc); 767 tty_ldisc_close(tty, tty->ldisc);
768 tty_ldisc_put(tty->ldisc); 768 tty_ldisc_put(tty->ldisc);
769 tty->ldisc = NULL; 769 tty->ldisc = NULL;
@@ -838,7 +838,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
838 tty_unlock(); 838 tty_unlock();
839 cancel_work_sync(&tty->buf.work); 839 cancel_work_sync(&tty->buf.work);
840 mutex_unlock(&tty->ldisc_mutex); 840 mutex_unlock(&tty->ldisc_mutex);
841 841retry:
842 tty_lock(); 842 tty_lock();
843 mutex_lock(&tty->ldisc_mutex); 843 mutex_lock(&tty->ldisc_mutex);
844 844
@@ -847,6 +847,22 @@ void tty_ldisc_hangup(struct tty_struct *tty)
847 it means auditing a lot of other paths so this is 847 it means auditing a lot of other paths so this is
848 a FIXME */ 848 a FIXME */
849 if (tty->ldisc) { /* Not yet closed */ 849 if (tty->ldisc) { /* Not yet closed */
850 if (atomic_read(&tty->ldisc->users) != 1) {
851 char cur_n[TASK_COMM_LEN], tty_n[64];
852 long timeout = 3 * HZ;
853 tty_unlock();
854
855 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
856 timeout = MAX_SCHEDULE_TIMEOUT;
857 printk_ratelimited(KERN_WARNING
858 "%s: waiting (%s) for %s took too long, but we keep waiting...\n",
859 __func__, get_task_comm(cur_n, current),
860 tty_name(tty, tty_n));
861 }
862 mutex_unlock(&tty->ldisc_mutex);
863 goto retry;
864 }
865
850 if (reset == 0) { 866 if (reset == 0) {
851 867
852 if (!tty_ldisc_reinit(tty, tty->termios->c_line)) 868 if (!tty_ldisc_reinit(tty, tty->termios->c_line))
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index 66825c9f516..7a367ff5122 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 bdc3db94612..ff505951735 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 0b2ed71e3bf..25de302009a 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 4ac2750491d..791f11bed60 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 62050f7a4f9..57ae44cd0b8 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/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 6960715c506..e8c564a5334 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -539,7 +539,6 @@ static void acm_port_down(struct acm *acm)
539{ 539{
540 int i; 540 int i;
541 541
542 mutex_lock(&open_mutex);
543 if (acm->dev) { 542 if (acm->dev) {
544 usb_autopm_get_interface(acm->control); 543 usb_autopm_get_interface(acm->control);
545 acm_set_control(acm, acm->ctrlout = 0); 544 acm_set_control(acm, acm->ctrlout = 0);
@@ -551,14 +550,15 @@ static void acm_port_down(struct acm *acm)
551 acm->control->needs_remote_wakeup = 0; 550 acm->control->needs_remote_wakeup = 0;
552 usb_autopm_put_interface(acm->control); 551 usb_autopm_put_interface(acm->control);
553 } 552 }
554 mutex_unlock(&open_mutex);
555} 553}
556 554
557static void acm_tty_hangup(struct tty_struct *tty) 555static void acm_tty_hangup(struct tty_struct *tty)
558{ 556{
559 struct acm *acm = tty->driver_data; 557 struct acm *acm = tty->driver_data;
560 tty_port_hangup(&acm->port); 558 tty_port_hangup(&acm->port);
559 mutex_lock(&open_mutex);
561 acm_port_down(acm); 560 acm_port_down(acm);
561 mutex_unlock(&open_mutex);
562} 562}
563 563
564static void acm_tty_close(struct tty_struct *tty, struct file *filp) 564static void acm_tty_close(struct tty_struct *tty, struct file *filp)
@@ -569,8 +569,9 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
569 shutdown */ 569 shutdown */
570 if (!acm) 570 if (!acm)
571 return; 571 return;
572
573 mutex_lock(&open_mutex);
572 if (tty_port_close_start(&acm->port, tty, filp) == 0) { 574 if (tty_port_close_start(&acm->port, tty, filp) == 0) {
573 mutex_lock(&open_mutex);
574 if (!acm->dev) { 575 if (!acm->dev) {
575 tty_port_tty_set(&acm->port, NULL); 576 tty_port_tty_set(&acm->port, NULL);
576 acm_tty_unregister(acm); 577 acm_tty_unregister(acm);
@@ -582,6 +583,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
582 acm_port_down(acm); 583 acm_port_down(acm);
583 tty_port_close_end(&acm->port, tty); 584 tty_port_close_end(&acm->port, tty);
584 tty_port_tty_set(&acm->port, NULL); 585 tty_port_tty_set(&acm->port, NULL);
586 mutex_unlock(&open_mutex);
585} 587}
586 588
587static int acm_tty_write(struct tty_struct *tty, 589static int acm_tty_write(struct tty_struct *tty,
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 3b029a0a478..45887a0ff87 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/hub.c b/drivers/usb/core/hub.c
index 96f05b29c9a..79781461eec 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -813,6 +813,12 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
813 USB_PORT_FEAT_C_PORT_LINK_STATE); 813 USB_PORT_FEAT_C_PORT_LINK_STATE);
814 } 814 }
815 815
816 if ((portchange & USB_PORT_STAT_C_BH_RESET) &&
817 hub_is_superspeed(hub->hdev)) {
818 need_debounce_delay = true;
819 clear_port_feature(hub->hdev, port1,
820 USB_PORT_FEAT_C_BH_PORT_RESET);
821 }
816 /* We can forget about a "removed" device when there's a 822 /* We can forget about a "removed" device when there's a
817 * physical disconnect or the connect status changes. 823 * physical disconnect or the connect status changes.
818 */ 824 */
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index 7542dce3f5a..7728c91dfa2 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/core/quirks.c b/drivers/usb/core/quirks.c
index d6a8d8269bf..ecf12e15a7e 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -50,15 +50,42 @@ static const struct usb_device_id usb_quirk_list[] = {
50 /* Logitech Webcam B/C500 */ 50 /* Logitech Webcam B/C500 */
51 { USB_DEVICE(0x046d, 0x0807), .driver_info = USB_QUIRK_RESET_RESUME }, 51 { USB_DEVICE(0x046d, 0x0807), .driver_info = USB_QUIRK_RESET_RESUME },
52 52
53 /* Logitech Webcam C600 */
54 { USB_DEVICE(0x046d, 0x0808), .driver_info = USB_QUIRK_RESET_RESUME },
55
53 /* Logitech Webcam Pro 9000 */ 56 /* Logitech Webcam Pro 9000 */
54 { USB_DEVICE(0x046d, 0x0809), .driver_info = USB_QUIRK_RESET_RESUME }, 57 { USB_DEVICE(0x046d, 0x0809), .driver_info = USB_QUIRK_RESET_RESUME },
55 58
59 /* Logitech Webcam C905 */
60 { USB_DEVICE(0x046d, 0x080a), .driver_info = USB_QUIRK_RESET_RESUME },
61
62 /* Logitech Webcam C210 */
63 { USB_DEVICE(0x046d, 0x0819), .driver_info = USB_QUIRK_RESET_RESUME },
64
65 /* Logitech Webcam C260 */
66 { USB_DEVICE(0x046d, 0x081a), .driver_info = USB_QUIRK_RESET_RESUME },
67
56 /* Logitech Webcam C310 */ 68 /* Logitech Webcam C310 */
57 { USB_DEVICE(0x046d, 0x081b), .driver_info = USB_QUIRK_RESET_RESUME }, 69 { USB_DEVICE(0x046d, 0x081b), .driver_info = USB_QUIRK_RESET_RESUME },
58 70
71 /* Logitech Webcam C910 */
72 { USB_DEVICE(0x046d, 0x0821), .driver_info = USB_QUIRK_RESET_RESUME },
73
74 /* Logitech Webcam C160 */
75 { USB_DEVICE(0x046d, 0x0824), .driver_info = USB_QUIRK_RESET_RESUME },
76
59 /* Logitech Webcam C270 */ 77 /* Logitech Webcam C270 */
60 { USB_DEVICE(0x046d, 0x0825), .driver_info = USB_QUIRK_RESET_RESUME }, 78 { USB_DEVICE(0x046d, 0x0825), .driver_info = USB_QUIRK_RESET_RESUME },
61 79
80 /* Logitech Quickcam Pro 9000 */
81 { USB_DEVICE(0x046d, 0x0990), .driver_info = USB_QUIRK_RESET_RESUME },
82
83 /* Logitech Quickcam E3500 */
84 { USB_DEVICE(0x046d, 0x09a4), .driver_info = USB_QUIRK_RESET_RESUME },
85
86 /* Logitech Quickcam Vision Pro */
87 { USB_DEVICE(0x046d, 0x09a6), .driver_info = USB_QUIRK_RESET_RESUME },
88
62 /* Logitech Harmony 700-series */ 89 /* Logitech Harmony 700-series */
63 { USB_DEVICE(0x046d, 0xc122), .driver_info = USB_QUIRK_DELAY_INIT }, 90 { USB_DEVICE(0x046d, 0xc122), .driver_info = USB_QUIRK_DELAY_INIT },
64 91
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index fa824cfdd2e..25dbd8614e7 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1284,6 +1284,7 @@ static int __devinit dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1284 int ret; 1284 int ret;
1285 1285
1286 dep->endpoint.maxpacket = 1024; 1286 dep->endpoint.maxpacket = 1024;
1287 dep->endpoint.max_streams = 15;
1287 dep->endpoint.ops = &dwc3_gadget_ep_ops; 1288 dep->endpoint.ops = &dwc3_gadget_ep_ops;
1288 list_add_tail(&dep->endpoint.ep_list, 1289 list_add_tail(&dep->endpoint.ep_list,
1289 &dwc->gadget.ep_list); 1290 &dwc->gadget.ep_list);
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index b21cd376c11..23a447373c5 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -469,7 +469,7 @@ config USB_LANGWELL
469 gadget drivers to also be dynamically linked. 469 gadget drivers to also be dynamically linked.
470 470
471config USB_EG20T 471config USB_EG20T
472 tristate "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH UDC" 472 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC"
473 depends on PCI 473 depends on PCI
474 select USB_GADGET_DUALSPEED 474 select USB_GADGET_DUALSPEED
475 help 475 help
@@ -485,10 +485,11 @@ config USB_EG20T
485 This driver dose not support interrupt transfer or isochronous 485 This driver dose not support interrupt transfer or isochronous
486 transfer modes. 486 transfer modes.
487 487
488 This driver also can be used for OKI SEMICONDUCTOR's ML7213 which is 488 This driver also can be used for LAPIS Semiconductor's ML7213 which is
489 for IVI(In-Vehicle Infotainment) use. 489 for IVI(In-Vehicle Infotainment) use.
490 ML7213 is companion chip for Intel Atom E6xx series. 490 ML7831 is for general purpose use.
491 ML7213 is completely compatible for Intel EG20T PCH. 491 ML7213/ML7831 is companion chip for Intel Atom E6xx series.
492 ML7213/ML7831 is completely compatible for Intel EG20T PCH.
492 493
493config USB_CI13XXX_MSM 494config USB_CI13XXX_MSM
494 tristate "MIPS USB CI13xxx for MSM" 495 tristate "MIPS USB CI13xxx for MSM"
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 4730016d7cd..45f422ac103 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1959,7 +1959,7 @@ static int amd5536_start(struct usb_gadget_driver *driver,
1959 u32 tmp; 1959 u32 tmp;
1960 1960
1961 if (!driver || !bind || !driver->setup 1961 if (!driver || !bind || !driver->setup
1962 || driver->speed != USB_SPEED_HIGH) 1962 || driver->speed < USB_SPEED_HIGH)
1963 return -EINVAL; 1963 return -EINVAL;
1964 if (!dev) 1964 if (!dev)
1965 return -ENODEV; 1965 return -ENODEV;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 672674c2fb3..725550f06fa 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/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c
index 4eedfe55715..1fc612914c5 100644
--- a/drivers/usb/gadget/ci13xxx_msm.c
+++ b/drivers/usb/gadget/ci13xxx_msm.c
@@ -122,3 +122,5 @@ static int __init ci13xxx_msm_init(void)
122 return platform_driver_register(&ci13xxx_msm_driver); 122 return platform_driver_register(&ci13xxx_msm_driver);
123} 123}
124module_init(ci13xxx_msm_init); 124module_init(ci13xxx_msm_init);
125
126MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 83428f56253..9a0c3979ff4 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -71,6 +71,9 @@
71/****************************************************************************** 71/******************************************************************************
72 * DEFINE 72 * DEFINE
73 *****************************************************************************/ 73 *****************************************************************************/
74
75#define DMA_ADDR_INVALID (~(dma_addr_t)0)
76
74/* ctrl register bank access */ 77/* ctrl register bank access */
75static DEFINE_SPINLOCK(udc_lock); 78static DEFINE_SPINLOCK(udc_lock);
76 79
@@ -1434,7 +1437,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1434 return -EALREADY; 1437 return -EALREADY;
1435 1438
1436 mReq->req.status = -EALREADY; 1439 mReq->req.status = -EALREADY;
1437 if (length && !mReq->req.dma) { 1440 if (length && mReq->req.dma == DMA_ADDR_INVALID) {
1438 mReq->req.dma = \ 1441 mReq->req.dma = \
1439 dma_map_single(mEp->device, mReq->req.buf, 1442 dma_map_single(mEp->device, mReq->req.buf,
1440 length, mEp->dir ? DMA_TO_DEVICE : 1443 length, mEp->dir ? DMA_TO_DEVICE :
@@ -1453,7 +1456,7 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1453 dma_unmap_single(mEp->device, mReq->req.dma, 1456 dma_unmap_single(mEp->device, mReq->req.dma,
1454 length, mEp->dir ? DMA_TO_DEVICE : 1457 length, mEp->dir ? DMA_TO_DEVICE :
1455 DMA_FROM_DEVICE); 1458 DMA_FROM_DEVICE);
1456 mReq->req.dma = 0; 1459 mReq->req.dma = DMA_ADDR_INVALID;
1457 mReq->map = 0; 1460 mReq->map = 0;
1458 } 1461 }
1459 return -ENOMEM; 1462 return -ENOMEM;
@@ -1549,7 +1552,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
1549 if (mReq->map) { 1552 if (mReq->map) {
1550 dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length, 1553 dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length,
1551 mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 1554 mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
1552 mReq->req.dma = 0; 1555 mReq->req.dma = DMA_ADDR_INVALID;
1553 mReq->map = 0; 1556 mReq->map = 0;
1554 } 1557 }
1555 1558
@@ -1610,7 +1613,6 @@ __acquires(mEp->lock)
1610 * @gadget: gadget 1613 * @gadget: gadget
1611 * 1614 *
1612 * This function returns an error code 1615 * This function returns an error code
1613 * Caller must hold lock
1614 */ 1616 */
1615static int _gadget_stop_activity(struct usb_gadget *gadget) 1617static int _gadget_stop_activity(struct usb_gadget *gadget)
1616{ 1618{
@@ -2189,6 +2191,7 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
2189 mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags); 2191 mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags);
2190 if (mReq != NULL) { 2192 if (mReq != NULL) {
2191 INIT_LIST_HEAD(&mReq->queue); 2193 INIT_LIST_HEAD(&mReq->queue);
2194 mReq->req.dma = DMA_ADDR_INVALID;
2192 2195
2193 mReq->ptr = dma_pool_alloc(mEp->td_pool, gfp_flags, 2196 mReq->ptr = dma_pool_alloc(mEp->td_pool, gfp_flags,
2194 &mReq->dma); 2197 &mReq->dma);
@@ -2328,7 +2331,7 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
2328 if (mReq->map) { 2331 if (mReq->map) {
2329 dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length, 2332 dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length,
2330 mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 2333 mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
2331 mReq->req.dma = 0; 2334 mReq->req.dma = DMA_ADDR_INVALID;
2332 mReq->map = 0; 2335 mReq->map = 0;
2333 } 2336 }
2334 req->status = -ECONNRESET; 2337 req->status = -ECONNRESET;
@@ -2500,12 +2503,12 @@ static int ci13xxx_wakeup(struct usb_gadget *_gadget)
2500 spin_lock_irqsave(udc->lock, flags); 2503 spin_lock_irqsave(udc->lock, flags);
2501 if (!udc->remote_wakeup) { 2504 if (!udc->remote_wakeup) {
2502 ret = -EOPNOTSUPP; 2505 ret = -EOPNOTSUPP;
2503 dbg_trace("remote wakeup feature is not enabled\n"); 2506 trace("remote wakeup feature is not enabled\n");
2504 goto out; 2507 goto out;
2505 } 2508 }
2506 if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) { 2509 if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) {
2507 ret = -EINVAL; 2510 ret = -EINVAL;
2508 dbg_trace("port is not suspended\n"); 2511 trace("port is not suspended\n");
2509 goto out; 2512 goto out;
2510 } 2513 }
2511 hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR); 2514 hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR);
@@ -2703,7 +2706,9 @@ static int ci13xxx_stop(struct usb_gadget_driver *driver)
2703 if (udc->udc_driver->notify_event) 2706 if (udc->udc_driver->notify_event)
2704 udc->udc_driver->notify_event(udc, 2707 udc->udc_driver->notify_event(udc,
2705 CI13XXX_CONTROLLER_STOPPED_EVENT); 2708 CI13XXX_CONTROLLER_STOPPED_EVENT);
2709 spin_unlock_irqrestore(udc->lock, flags);
2706 _gadget_stop_activity(&udc->gadget); 2710 _gadget_stop_activity(&udc->gadget);
2711 spin_lock_irqsave(udc->lock, flags);
2707 pm_runtime_put(&udc->gadget.dev); 2712 pm_runtime_put(&udc->gadget.dev);
2708 } 2713 }
2709 2714
@@ -2850,7 +2855,7 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
2850 struct ci13xxx *udc; 2855 struct ci13xxx *udc;
2851 int retval = 0; 2856 int retval = 0;
2852 2857
2853 trace("%p, %p, %p", dev, regs, name); 2858 trace("%p, %p, %p", dev, regs, driver->name);
2854 2859
2855 if (dev == NULL || regs == NULL || driver == NULL || 2860 if (dev == NULL || regs == NULL || driver == NULL ||
2856 driver->name == NULL) 2861 driver->name == NULL)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 8a5529d214f..f71b0787983 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 f855ecf7a63..6256420089f 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 6b1c20b6c9b..acb38004eec 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_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 52583a23533..c39d58860fa 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -624,7 +624,8 @@ static int fsg_setup(struct usb_function *f,
624 if (ctrl->bRequestType != 624 if (ctrl->bRequestType !=
625 (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 625 (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
626 break; 626 break;
627 if (w_index != fsg->interface_number || w_value != 0) 627 if (w_index != fsg->interface_number || w_value != 0 ||
628 w_length != 0)
628 return -EDOM; 629 return -EDOM;
629 630
630 /* 631 /*
@@ -639,7 +640,8 @@ static int fsg_setup(struct usb_function *f,
639 if (ctrl->bRequestType != 640 if (ctrl->bRequestType !=
640 (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 641 (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
641 break; 642 break;
642 if (w_index != fsg->interface_number || w_value != 0) 643 if (w_index != fsg->interface_number || w_value != 0 ||
644 w_length != 1)
643 return -EDOM; 645 return -EDOM;
644 VDBG(fsg, "get max LUN\n"); 646 VDBG(fsg, "get max LUN\n");
645 *(u8 *)req->buf = fsg->common->nluns - 1; 647 *(u8 *)req->buf = fsg->common->nluns - 1;
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c
index 67b222908cf..3797b3d6c62 100644
--- a/drivers/usb/gadget/f_midi.c
+++ b/drivers/usb/gadget/f_midi.c
@@ -95,7 +95,6 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req);
95 95
96DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); 96DECLARE_UAC_AC_HEADER_DESCRIPTOR(1);
97DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); 97DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
98DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(16);
99DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16); 98DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16);
100 99
101/* B.3.1 Standard AC Interface Descriptor */ 100/* B.3.1 Standard AC Interface Descriptor */
@@ -140,26 +139,6 @@ static struct usb_ms_header_descriptor ms_header_desc __initdata = {
140 /* .wTotalLength = DYNAMIC */ 139 /* .wTotalLength = DYNAMIC */
141}; 140};
142 141
143/* B.4.3 Embedded MIDI IN Jack Descriptor */
144static struct usb_midi_in_jack_descriptor jack_in_emb_desc = {
145 .bLength = USB_DT_MIDI_IN_SIZE,
146 .bDescriptorType = USB_DT_CS_INTERFACE,
147 .bDescriptorSubtype = USB_MS_MIDI_IN_JACK,
148 .bJackType = USB_MS_EMBEDDED,
149 /* .bJackID = DYNAMIC */
150};
151
152/* B.4.4 Embedded MIDI OUT Jack Descriptor */
153static struct usb_midi_out_jack_descriptor_16 jack_out_emb_desc = {
154 /* .bLength = DYNAMIC */
155 .bDescriptorType = USB_DT_CS_INTERFACE,
156 .bDescriptorSubtype = USB_MS_MIDI_OUT_JACK,
157 .bJackType = USB_MS_EMBEDDED,
158 /* .bJackID = DYNAMIC */
159 /* .bNrInputPins = DYNAMIC */
160 /* .pins = DYNAMIC */
161};
162
163/* B.5.1 Standard Bulk OUT Endpoint Descriptor */ 142/* B.5.1 Standard Bulk OUT Endpoint Descriptor */
164static struct usb_endpoint_descriptor bulk_out_desc = { 143static struct usb_endpoint_descriptor bulk_out_desc = {
165 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, 144 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE,
@@ -758,9 +737,11 @@ fail:
758static int __init 737static int __init
759f_midi_bind(struct usb_configuration *c, struct usb_function *f) 738f_midi_bind(struct usb_configuration *c, struct usb_function *f)
760{ 739{
761 struct usb_descriptor_header *midi_function[(MAX_PORTS * 2) + 12]; 740 struct usb_descriptor_header **midi_function;
762 struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS]; 741 struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS];
742 struct usb_midi_in_jack_descriptor jack_in_emb_desc[MAX_PORTS];
763 struct usb_midi_out_jack_descriptor_1 jack_out_ext_desc[MAX_PORTS]; 743 struct usb_midi_out_jack_descriptor_1 jack_out_ext_desc[MAX_PORTS];
744 struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc[MAX_PORTS];
764 struct usb_composite_dev *cdev = c->cdev; 745 struct usb_composite_dev *cdev = c->cdev;
765 struct f_midi *midi = func_to_midi(f); 746 struct f_midi *midi = func_to_midi(f);
766 int status, n, jack = 1, i = 0; 747 int status, n, jack = 1, i = 0;
@@ -798,6 +779,14 @@ f_midi_bind(struct usb_configuration *c, struct usb_function *f)
798 goto fail; 779 goto fail;
799 midi->out_ep->driver_data = cdev; /* claim */ 780 midi->out_ep->driver_data = cdev; /* claim */
800 781
782 /* allocate temporary function list */
783 midi_function = kcalloc((MAX_PORTS * 4) + 9, sizeof(midi_function),
784 GFP_KERNEL);
785 if (!midi_function) {
786 status = -ENOMEM;
787 goto fail;
788 }
789
801 /* 790 /*
802 * construct the function's descriptor set. As the number of 791 * construct the function's descriptor set. As the number of
803 * input and output MIDI ports is configurable, we have to do 792 * input and output MIDI ports is configurable, we have to do
@@ -811,73 +800,74 @@ f_midi_bind(struct usb_configuration *c, struct usb_function *f)
811 800
812 /* calculate the header's wTotalLength */ 801 /* calculate the header's wTotalLength */
813 n = USB_DT_MS_HEADER_SIZE 802 n = USB_DT_MS_HEADER_SIZE
814 + (1 + midi->in_ports) * USB_DT_MIDI_IN_SIZE 803 + (midi->in_ports + midi->out_ports) *
815 + (1 + midi->out_ports) * USB_DT_MIDI_OUT_SIZE(1); 804 (USB_DT_MIDI_IN_SIZE + USB_DT_MIDI_OUT_SIZE(1));
816 ms_header_desc.wTotalLength = cpu_to_le16(n); 805 ms_header_desc.wTotalLength = cpu_to_le16(n);
817 806
818 midi_function[i++] = (struct usb_descriptor_header *) &ms_header_desc; 807 midi_function[i++] = (struct usb_descriptor_header *) &ms_header_desc;
819 808
820 /* we have one embedded IN jack */ 809 /* configure the external IN jacks, each linked to an embedded OUT jack */
821 jack_in_emb_desc.bJackID = jack++;
822 midi_function[i++] = (struct usb_descriptor_header *) &jack_in_emb_desc;
823
824 /* and a dynamic amount of external IN jacks */
825 for (n = 0; n < midi->in_ports; n++) {
826 struct usb_midi_in_jack_descriptor *ext = &jack_in_ext_desc[n];
827
828 ext->bLength = USB_DT_MIDI_IN_SIZE;
829 ext->bDescriptorType = USB_DT_CS_INTERFACE;
830 ext->bDescriptorSubtype = USB_MS_MIDI_IN_JACK;
831 ext->bJackType = USB_MS_EXTERNAL;
832 ext->bJackID = jack++;
833 ext->iJack = 0;
834
835 midi_function[i++] = (struct usb_descriptor_header *) ext;
836 }
837
838 /* one embedded OUT jack ... */
839 jack_out_emb_desc.bLength = USB_DT_MIDI_OUT_SIZE(midi->in_ports);
840 jack_out_emb_desc.bJackID = jack++;
841 jack_out_emb_desc.bNrInputPins = midi->in_ports;
842 /* ... which referencess all external IN jacks */
843 for (n = 0; n < midi->in_ports; n++) { 810 for (n = 0; n < midi->in_ports; n++) {
844 jack_out_emb_desc.pins[n].baSourceID = jack_in_ext_desc[n].bJackID; 811 struct usb_midi_in_jack_descriptor *in_ext = &jack_in_ext_desc[n];
845 jack_out_emb_desc.pins[n].baSourcePin = 1; 812 struct usb_midi_out_jack_descriptor_1 *out_emb = &jack_out_emb_desc[n];
813
814 in_ext->bLength = USB_DT_MIDI_IN_SIZE;
815 in_ext->bDescriptorType = USB_DT_CS_INTERFACE;
816 in_ext->bDescriptorSubtype = USB_MS_MIDI_IN_JACK;
817 in_ext->bJackType = USB_MS_EXTERNAL;
818 in_ext->bJackID = jack++;
819 in_ext->iJack = 0;
820 midi_function[i++] = (struct usb_descriptor_header *) in_ext;
821
822 out_emb->bLength = USB_DT_MIDI_OUT_SIZE(1);
823 out_emb->bDescriptorType = USB_DT_CS_INTERFACE;
824 out_emb->bDescriptorSubtype = USB_MS_MIDI_OUT_JACK;
825 out_emb->bJackType = USB_MS_EMBEDDED;
826 out_emb->bJackID = jack++;
827 out_emb->bNrInputPins = 1;
828 out_emb->pins[0].baSourcePin = 1;
829 out_emb->pins[0].baSourceID = in_ext->bJackID;
830 out_emb->iJack = 0;
831 midi_function[i++] = (struct usb_descriptor_header *) out_emb;
832
833 /* link it to the endpoint */
834 ms_in_desc.baAssocJackID[n] = out_emb->bJackID;
846 } 835 }
847 836
848 midi_function[i++] = (struct usb_descriptor_header *) &jack_out_emb_desc; 837 /* configure the external OUT jacks, each linked to an embedded IN jack */
849
850 /* and multiple external OUT jacks ... */
851 for (n = 0; n < midi->out_ports; n++) { 838 for (n = 0; n < midi->out_ports; n++) {
852 struct usb_midi_out_jack_descriptor_1 *ext = &jack_out_ext_desc[n]; 839 struct usb_midi_in_jack_descriptor *in_emb = &jack_in_emb_desc[n];
853 int m; 840 struct usb_midi_out_jack_descriptor_1 *out_ext = &jack_out_ext_desc[n];
854 841
855 ext->bLength = USB_DT_MIDI_OUT_SIZE(1); 842 in_emb->bLength = USB_DT_MIDI_IN_SIZE;
856 ext->bDescriptorType = USB_DT_CS_INTERFACE; 843 in_emb->bDescriptorType = USB_DT_CS_INTERFACE;
857 ext->bDescriptorSubtype = USB_MS_MIDI_OUT_JACK; 844 in_emb->bDescriptorSubtype = USB_MS_MIDI_IN_JACK;
858 ext->bJackType = USB_MS_EXTERNAL; 845 in_emb->bJackType = USB_MS_EMBEDDED;
859 ext->bJackID = jack++; 846 in_emb->bJackID = jack++;
860 ext->bNrInputPins = 1; 847 in_emb->iJack = 0;
861 ext->iJack = 0; 848 midi_function[i++] = (struct usb_descriptor_header *) in_emb;
862 /* ... which all reference the same embedded IN jack */ 849
863 for (m = 0; m < midi->out_ports; m++) { 850 out_ext->bLength = USB_DT_MIDI_OUT_SIZE(1);
864 ext->pins[m].baSourceID = jack_in_emb_desc.bJackID; 851 out_ext->bDescriptorType = USB_DT_CS_INTERFACE;
865 ext->pins[m].baSourcePin = 1; 852 out_ext->bDescriptorSubtype = USB_MS_MIDI_OUT_JACK;
866 } 853 out_ext->bJackType = USB_MS_EXTERNAL;
867 854 out_ext->bJackID = jack++;
868 midi_function[i++] = (struct usb_descriptor_header *) ext; 855 out_ext->bNrInputPins = 1;
856 out_ext->iJack = 0;
857 out_ext->pins[0].baSourceID = in_emb->bJackID;
858 out_ext->pins[0].baSourcePin = 1;
859 midi_function[i++] = (struct usb_descriptor_header *) out_ext;
860
861 /* link it to the endpoint */
862 ms_out_desc.baAssocJackID[n] = in_emb->bJackID;
869 } 863 }
870 864
871 /* configure the endpoint descriptors ... */ 865 /* configure the endpoint descriptors ... */
872 ms_out_desc.bLength = USB_DT_MS_ENDPOINT_SIZE(midi->in_ports); 866 ms_out_desc.bLength = USB_DT_MS_ENDPOINT_SIZE(midi->in_ports);
873 ms_out_desc.bNumEmbMIDIJack = midi->in_ports; 867 ms_out_desc.bNumEmbMIDIJack = midi->in_ports;
874 for (n = 0; n < midi->in_ports; n++)
875 ms_out_desc.baAssocJackID[n] = jack_in_emb_desc.bJackID;
876 868
877 ms_in_desc.bLength = USB_DT_MS_ENDPOINT_SIZE(midi->out_ports); 869 ms_in_desc.bLength = USB_DT_MS_ENDPOINT_SIZE(midi->out_ports);
878 ms_in_desc.bNumEmbMIDIJack = midi->out_ports; 870 ms_in_desc.bNumEmbMIDIJack = midi->out_ports;
879 for (n = 0; n < midi->out_ports; n++)
880 ms_in_desc.baAssocJackID[n] = jack_out_emb_desc.bJackID;
881 871
882 /* ... and add them to the list */ 872 /* ... and add them to the list */
883 midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc; 873 midi_function[i++] = (struct usb_descriptor_header *) &bulk_out_desc;
@@ -901,6 +891,8 @@ f_midi_bind(struct usb_configuration *c, struct usb_function *f)
901 f->descriptors = usb_copy_descriptors(midi_function); 891 f->descriptors = usb_copy_descriptors(midi_function);
902 } 892 }
903 893
894 kfree(midi_function);
895
904 return 0; 896 return 0;
905 897
906fail: 898fail:
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index e3f74bf5da2..5f400f66aa9 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_phonet.c b/drivers/usb/gadget/f_phonet.c
index 34907703333..16a509ae517 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -346,7 +346,7 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
346 } 346 }
347 347
348 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 348 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
349 skb->len == 0, req->actual); 349 skb->len <= 1, req->actual);
350 page = NULL; 350 page = NULL;
351 351
352 if (req->actual < req->length) { /* Last fragment */ 352 if (req->actual < req->length) { /* Last fragment */
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index 91fdf790ed2..cf33a8d0fd5 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -131,8 +131,8 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
131 } 131 }
132 if (!gser->port.in->desc || !gser->port.out->desc) { 132 if (!gser->port.in->desc || !gser->port.out->desc) {
133 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); 133 DBG(cdev, "activate generic ttyGS%d\n", gser->port_num);
134 if (!config_ep_by_speed(cdev->gadget, f, gser->port.in) || 134 if (config_ep_by_speed(cdev->gadget, f, gser->port.in) ||
135 !config_ep_by_speed(cdev->gadget, f, gser->port.out)) { 135 config_ep_by_speed(cdev->gadget, f, gser->port.out)) {
136 gser->port.in->desc = NULL; 136 gser->port.in->desc = NULL;
137 gser->port.out->desc = NULL; 137 gser->port.out->desc = NULL;
138 return -EINVAL; 138 return -EINVAL;
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 168906d2b5d..7aa7ac82c02 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 3ac4f51cd0b..11b5196284a 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>
@@ -858,7 +859,7 @@ static int class_setup_req(struct fsg_dev *fsg,
858 if (ctrl->bRequestType != (USB_DIR_OUT | 859 if (ctrl->bRequestType != (USB_DIR_OUT |
859 USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 860 USB_TYPE_CLASS | USB_RECIP_INTERFACE))
860 break; 861 break;
861 if (w_index != 0 || w_value != 0) { 862 if (w_index != 0 || w_value != 0 || w_length != 0) {
862 value = -EDOM; 863 value = -EDOM;
863 break; 864 break;
864 } 865 }
@@ -874,7 +875,7 @@ static int class_setup_req(struct fsg_dev *fsg,
874 if (ctrl->bRequestType != (USB_DIR_IN | 875 if (ctrl->bRequestType != (USB_DIR_IN |
875 USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 876 USB_TYPE_CLASS | USB_RECIP_INTERFACE))
876 break; 877 break;
877 if (w_index != 0 || w_value != 0) { 878 if (w_index != 0 || w_value != 0 || w_length != 1) {
878 value = -EDOM; 879 value = -EDOM;
879 break; 880 break;
880 } 881 }
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index 43a49ecc1f3..dcbc0a2e48d 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -16,6 +16,7 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/fsl_devices.h> 17#include <linux/fsl_devices.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/io.h>
19 20
20#include <mach/hardware.h> 21#include <mach/hardware.h>
21 22
@@ -88,7 +89,6 @@ eenahb:
88void fsl_udc_clk_finalize(struct platform_device *pdev) 89void fsl_udc_clk_finalize(struct platform_device *pdev)
89{ 90{
90 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 91 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
91#if defined(CONFIG_SOC_IMX35)
92 if (cpu_is_mx35()) { 92 if (cpu_is_mx35()) {
93 unsigned int v; 93 unsigned int v;
94 94
@@ -101,7 +101,6 @@ void fsl_udc_clk_finalize(struct platform_device *pdev)
101 USBPHYCTRL_OTGBASE_OFFSET)); 101 USBPHYCTRL_OTGBASE_OFFSET));
102 } 102 }
103 } 103 }
104#endif
105 104
106 /* ULPI transceivers don't need usbpll */ 105 /* ULPI transceivers don't need usbpll */
107 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) { 106 if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 2a03e4de11c..e00cf92409c 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2336,8 +2336,7 @@ static int fsl_qe_start(struct usb_gadget_driver *driver,
2336 if (!udc_controller) 2336 if (!udc_controller)
2337 return -ENODEV; 2337 return -ENODEV;
2338 2338
2339 if (!driver || (driver->speed != USB_SPEED_FULL 2339 if (!driver || driver->speed < USB_SPEED_FULL
2340 && driver->speed != USB_SPEED_HIGH)
2341 || !bind || !driver->disconnect || !driver->setup) 2340 || !bind || !driver->disconnect || !driver->setup)
2342 return -EINVAL; 2341 return -EINVAL;
2343 2342
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index b2c44e1d581..dd28ef3def7 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -696,12 +696,31 @@ static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req)
696 kfree(req); 696 kfree(req);
697} 697}
698 698
699/*-------------------------------------------------------------------------*/ 699/* Actually add a dTD chain to an empty dQH and let go */
700static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
701{
702 struct ep_queue_head *qh = get_qh_by_ep(ep);
703
704 /* Write dQH next pointer and terminate bit to 0 */
705 qh->next_dtd_ptr = cpu_to_hc32(td->td_dma
706 & EP_QUEUE_HEAD_NEXT_POINTER_MASK);
707
708 /* Clear active and halt bit */
709 qh->size_ioc_int_sts &= cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
710 | EP_QUEUE_HEAD_STATUS_HALT));
711
712 /* Ensure that updates to the QH will occur before priming. */
713 wmb();
714
715 /* Prime endpoint by writing correct bit to ENDPTPRIME */
716 fsl_writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
717 : (1 << (ep_index(ep))), &dr_regs->endpointprime);
718}
719
720/* Add dTD chain to the dQH of an EP */
700static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) 721static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
701{ 722{
702 int i = ep_index(ep) * 2 + ep_is_in(ep);
703 u32 temp, bitmask, tmp_stat; 723 u32 temp, bitmask, tmp_stat;
704 struct ep_queue_head *dQH = &ep->udc->ep_qh[i];
705 724
706 /* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr); 725 /* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr);
707 VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */ 726 VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */
@@ -719,7 +738,7 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
719 cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK); 738 cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
720 /* Read prime bit, if 1 goto done */ 739 /* Read prime bit, if 1 goto done */
721 if (fsl_readl(&dr_regs->endpointprime) & bitmask) 740 if (fsl_readl(&dr_regs->endpointprime) & bitmask)
722 goto out; 741 return;
723 742
724 do { 743 do {
725 /* Set ATDTW bit in USBCMD */ 744 /* Set ATDTW bit in USBCMD */
@@ -736,28 +755,10 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
736 fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd); 755 fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
737 756
738 if (tmp_stat) 757 if (tmp_stat)
739 goto out; 758 return;
740 } 759 }
741 760
742 /* Write dQH next pointer and terminate bit to 0 */ 761 fsl_prime_ep(ep, req->head);
743 temp = req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK;
744 dQH->next_dtd_ptr = cpu_to_hc32(temp);
745
746 /* Clear active and halt bit */
747 temp = cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
748 | EP_QUEUE_HEAD_STATUS_HALT));
749 dQH->size_ioc_int_sts &= temp;
750
751 /* Ensure that updates to the QH will occur before priming. */
752 wmb();
753
754 /* Prime endpoint by writing 1 to ENDPTPRIME */
755 temp = ep_is_in(ep)
756 ? (1 << (ep_index(ep) + 16))
757 : (1 << (ep_index(ep)));
758 fsl_writel(temp, &dr_regs->endpointprime);
759out:
760 return;
761} 762}
762 763
763/* Fill in the dTD structure 764/* Fill in the dTD structure
@@ -877,7 +878,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
877 VDBG("%s, bad ep", __func__); 878 VDBG("%s, bad ep", __func__);
878 return -EINVAL; 879 return -EINVAL;
879 } 880 }
880 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 881 if (usb_endpoint_xfer_isoc(ep->desc)) {
881 if (req->req.length > ep->ep.maxpacket) 882 if (req->req.length > ep->ep.maxpacket)
882 return -EMSGSIZE; 883 return -EMSGSIZE;
883 } 884 }
@@ -973,25 +974,20 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
973 974
974 /* The request isn't the last request in this ep queue */ 975 /* The request isn't the last request in this ep queue */
975 if (req->queue.next != &ep->queue) { 976 if (req->queue.next != &ep->queue) {
976 struct ep_queue_head *qh;
977 struct fsl_req *next_req; 977 struct fsl_req *next_req;
978 978
979 qh = ep->qh;
980 next_req = list_entry(req->queue.next, struct fsl_req, 979 next_req = list_entry(req->queue.next, struct fsl_req,
981 queue); 980 queue);
982 981
983 /* Point the QH to the first TD of next request */ 982 /* prime with dTD of next request */
984 fsl_writel((u32) next_req->head, &qh->curr_dtd_ptr); 983 fsl_prime_ep(ep, next_req->head);
985 } 984 }
986 985 /* The request hasn't been processed, patch up the TD chain */
987 /* The request hasn't been processed, patch up the TD chain */
988 } else { 986 } else {
989 struct fsl_req *prev_req; 987 struct fsl_req *prev_req;
990 988
991 prev_req = list_entry(req->queue.prev, struct fsl_req, queue); 989 prev_req = list_entry(req->queue.prev, struct fsl_req, queue);
992 fsl_writel(fsl_readl(&req->tail->next_td_ptr), 990 prev_req->tail->next_td_ptr = req->tail->next_td_ptr;
993 &prev_req->tail->next_td_ptr);
994
995 } 991 }
996 992
997 done(ep, req, -ECONNRESET); 993 done(ep, req, -ECONNRESET);
@@ -1032,7 +1028,7 @@ static int fsl_ep_set_halt(struct usb_ep *_ep, int value)
1032 goto out; 1028 goto out;
1033 } 1029 }
1034 1030
1035 if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { 1031 if (usb_endpoint_xfer_isoc(ep->desc)) {
1036 status = -EOPNOTSUPP; 1032 status = -EOPNOTSUPP;
1037 goto out; 1033 goto out;
1038 } 1034 }
@@ -1068,7 +1064,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
1068 struct fsl_udc *udc; 1064 struct fsl_udc *udc;
1069 int size = 0; 1065 int size = 0;
1070 u32 bitmask; 1066 u32 bitmask;
1071 struct ep_queue_head *d_qh; 1067 struct ep_queue_head *qh;
1072 1068
1073 ep = container_of(_ep, struct fsl_ep, ep); 1069 ep = container_of(_ep, struct fsl_ep, ep);
1074 if (!_ep || (!ep->desc && ep_index(ep) != 0)) 1070 if (!_ep || (!ep->desc && ep_index(ep) != 0))
@@ -1079,13 +1075,13 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
1079 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) 1075 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN)
1080 return -ESHUTDOWN; 1076 return -ESHUTDOWN;
1081 1077
1082 d_qh = &ep->udc->ep_qh[ep_index(ep) * 2 + ep_is_in(ep)]; 1078 qh = get_qh_by_ep(ep);
1083 1079
1084 bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) : 1080 bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
1085 (1 << (ep_index(ep))); 1081 (1 << (ep_index(ep)));
1086 1082
1087 if (fsl_readl(&dr_regs->endptstatus) & bitmask) 1083 if (fsl_readl(&dr_regs->endptstatus) & bitmask)
1088 size = (d_qh->size_ioc_int_sts & DTD_PACKET_SIZE) 1084 size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
1089 >> DTD_LENGTH_BIT_POS; 1085 >> DTD_LENGTH_BIT_POS;
1090 1086
1091 pr_debug("%s %u\n", __func__, size); 1087 pr_debug("%s %u\n", __func__, size);
@@ -1717,7 +1713,7 @@ static void dtd_complete_irq(struct fsl_udc *udc)
1717 1713
1718static inline enum usb_device_speed portscx_device_speed(u32 reg) 1714static inline enum usb_device_speed portscx_device_speed(u32 reg)
1719{ 1715{
1720 switch (speed & PORTSCX_PORT_SPEED_MASK) { 1716 switch (reg & PORTSCX_PORT_SPEED_MASK) {
1721 case PORTSCX_PORT_SPEED_HIGH: 1717 case PORTSCX_PORT_SPEED_HIGH:
1722 return USB_SPEED_HIGH; 1718 return USB_SPEED_HIGH;
1723 case PORTSCX_PORT_SPEED_FULL: 1719 case PORTSCX_PORT_SPEED_FULL:
@@ -1938,8 +1934,7 @@ static int fsl_start(struct usb_gadget_driver *driver,
1938 if (!udc_controller) 1934 if (!udc_controller)
1939 return -ENODEV; 1935 return -ENODEV;
1940 1936
1941 if (!driver || (driver->speed != USB_SPEED_FULL 1937 if (!driver || driver->speed < USB_SPEED_FULL
1942 && driver->speed != USB_SPEED_HIGH)
1943 || !bind || !driver->disconnect || !driver->setup) 1938 || !bind || !driver->disconnect || !driver->setup)
1944 return -EINVAL; 1939 return -EINVAL;
1945 1940
@@ -2480,8 +2475,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2480 2475
2481#ifndef CONFIG_ARCH_MXC 2476#ifndef CONFIG_ARCH_MXC
2482 if (pdata->have_sysif_regs) 2477 if (pdata->have_sysif_regs)
2483 usb_sys_regs = (struct usb_sys_interface *) 2478 usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
2484 ((u32)dr_regs + USB_DR_SYS_OFFSET);
2485#endif 2479#endif
2486 2480
2487 /* Initialize USB clocks */ 2481 /* Initialize USB clocks */
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 1d51be83fda..f781f5dec41 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -569,6 +569,16 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
569 * 2 + ((windex & USB_DIR_IN) ? 1 : 0)) 569 * 2 + ((windex & USB_DIR_IN) ? 1 : 0))
570#define get_pipe_by_ep(EP) (ep_index(EP) * 2 + ep_is_in(EP)) 570#define get_pipe_by_ep(EP) (ep_index(EP) * 2 + ep_is_in(EP))
571 571
572static inline struct ep_queue_head *get_qh_by_ep(struct fsl_ep *ep)
573{
574 /* we only have one ep0 structure but two queue heads */
575 if (ep_index(ep) != 0)
576 return ep->qh;
577 else
578 return &ep->udc->ep_qh[(ep->udc->ep0_dir ==
579 USB_DIR_IN) ? 1 : 0];
580}
581
572struct platform_device; 582struct platform_device;
573#ifdef CONFIG_ARCH_MXC 583#ifdef CONFIG_ARCH_MXC
574int fsl_udc_clk_init(struct platform_device *pdev); 584int fsl_udc_clk_init(struct platform_device *pdev);
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index e593f2849fa..74da206c840 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 8fcde37aa6d..681bd038b1d 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/inode.c b/drivers/usb/gadget/inode.c
index a392ec0d2d5..6ccae2707e5 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1730,8 +1730,9 @@ static void
1730gadgetfs_disconnect (struct usb_gadget *gadget) 1730gadgetfs_disconnect (struct usb_gadget *gadget)
1731{ 1731{
1732 struct dev_data *dev = get_gadget_data (gadget); 1732 struct dev_data *dev = get_gadget_data (gadget);
1733 unsigned long flags;
1733 1734
1734 spin_lock (&dev->lock); 1735 spin_lock_irqsave (&dev->lock, flags);
1735 if (dev->state == STATE_DEV_UNCONNECTED) 1736 if (dev->state == STATE_DEV_UNCONNECTED)
1736 goto exit; 1737 goto exit;
1737 dev->state = STATE_DEV_UNCONNECTED; 1738 dev->state = STATE_DEV_UNCONNECTED;
@@ -1740,7 +1741,7 @@ gadgetfs_disconnect (struct usb_gadget *gadget)
1740 next_event (dev, GADGETFS_DISCONNECT); 1741 next_event (dev, GADGETFS_DISCONNECT);
1741 ep0_readable (dev); 1742 ep0_readable (dev);
1742exit: 1743exit:
1743 spin_unlock (&dev->lock); 1744 spin_unlock_irqrestore (&dev->lock, flags);
1744} 1745}
1745 1746
1746static void 1747static void
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 91d0af2a24a..9aa1cbbee45 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1472,7 +1472,7 @@ static int m66592_start(struct usb_gadget_driver *driver,
1472 int retval; 1472 int retval;
1473 1473
1474 if (!driver 1474 if (!driver
1475 || driver->speed != USB_SPEED_HIGH 1475 || driver->speed < USB_SPEED_HIGH
1476 || !bind 1476 || !bind
1477 || !driver->setup) 1477 || !driver->setup)
1478 return -EINVAL; 1478 return -EINVAL;
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 7f1bc9a73cd..da2b9d0be3c 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1881,7 +1881,7 @@ static int net2280_start(struct usb_gadget *_gadget,
1881 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE) 1881 * (dev->usb->xcvrdiag & FORCE_FULL_SPEED_MODE)
1882 * "must not be used in normal operation" 1882 * "must not be used in normal operation"
1883 */ 1883 */
1884 if (!driver || driver->speed != USB_SPEED_HIGH 1884 if (!driver || driver->speed < USB_SPEED_HIGH
1885 || !driver->setup) 1885 || !driver->setup)
1886 return -EINVAL; 1886 return -EINVAL;
1887 1887
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 550d6dcdf10..5048a0c0764 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. 2 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -354,6 +354,7 @@ struct pch_udc_dev {
354#define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808 354#define PCI_DEVICE_ID_INTEL_EG20T_UDC 0x8808
355#define PCI_VENDOR_ID_ROHM 0x10DB 355#define PCI_VENDOR_ID_ROHM 0x10DB
356#define PCI_DEVICE_ID_ML7213_IOH_UDC 0x801D 356#define PCI_DEVICE_ID_ML7213_IOH_UDC 0x801D
357#define PCI_DEVICE_ID_ML7831_IOH_UDC 0x8808
357 358
358static const char ep0_string[] = "ep0in"; 359static const char ep0_string[] = "ep0in";
359static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ 360static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */
@@ -2970,6 +2971,11 @@ static DEFINE_PCI_DEVICE_TABLE(pch_udc_pcidev_id) = {
2970 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, 2971 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe,
2971 .class_mask = 0xffffffff, 2972 .class_mask = 0xffffffff,
2972 }, 2973 },
2974 {
2975 PCI_DEVICE(PCI_VENDOR_ID_ROHM, PCI_DEVICE_ID_ML7831_IOH_UDC),
2976 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe,
2977 .class_mask = 0xffffffff,
2978 },
2973 { 0 }, 2979 { 0 },
2974}; 2980};
2975 2981
@@ -2999,5 +3005,5 @@ static void __exit pch_udc_pci_exit(void)
2999module_exit(pch_udc_pci_exit); 3005module_exit(pch_udc_pci_exit);
3000 3006
3001MODULE_DESCRIPTION("Intel EG20T USB Device Controller"); 3007MODULE_DESCRIPTION("Intel EG20T USB Device Controller");
3002MODULE_AUTHOR("OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>"); 3008MODULE_AUTHOR("LAPIS Semiconductor, <tomoya-linux@dsn.lapis-semi.com>");
3003MODULE_LICENSE("GPL"); 3009MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index 68a826a1b86..fc719a3f855 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1718,6 +1718,8 @@ static void r8a66597_fifo_flush(struct usb_ep *_ep)
1718 if (list_empty(&ep->queue) && !ep->busy) { 1718 if (list_empty(&ep->queue) && !ep->busy) {
1719 pipe_stop(ep->r8a66597, ep->pipenum); 1719 pipe_stop(ep->r8a66597, ep->pipenum);
1720 r8a66597_bclr(ep->r8a66597, BCLR, ep->fifoctr); 1720 r8a66597_bclr(ep->r8a66597, BCLR, ep->fifoctr);
1721 r8a66597_write(ep->r8a66597, ACLRM, ep->pipectr);
1722 r8a66597_write(ep->r8a66597, 0, ep->pipectr);
1721 } 1723 }
1722 spin_unlock_irqrestore(&ep->r8a66597->lock, flags); 1724 spin_unlock_irqrestore(&ep->r8a66597->lock, flags);
1723} 1725}
@@ -1742,26 +1744,16 @@ static int r8a66597_start(struct usb_gadget *gadget,
1742 struct usb_gadget_driver *driver) 1744 struct usb_gadget_driver *driver)
1743{ 1745{
1744 struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); 1746 struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget);
1745 int retval;
1746 1747
1747 if (!driver 1748 if (!driver
1748 || driver->speed != USB_SPEED_HIGH 1749 || driver->speed < USB_SPEED_HIGH
1749 || !driver->setup) 1750 || !driver->setup)
1750 return -EINVAL; 1751 return -EINVAL;
1751 if (!r8a66597) 1752 if (!r8a66597)
1752 return -ENODEV; 1753 return -ENODEV;
1753 1754
1754 /* hook up the driver */ 1755 /* hook up the driver */
1755 driver->driver.bus = NULL;
1756 r8a66597->driver = driver; 1756 r8a66597->driver = driver;
1757 r8a66597->gadget.dev.driver = &driver->driver;
1758
1759 retval = device_add(&r8a66597->gadget.dev);
1760 if (retval) {
1761 dev_err(r8a66597_to_dev(r8a66597), "device_add error (%d)\n",
1762 retval);
1763 goto error;
1764 }
1765 1757
1766 init_controller(r8a66597); 1758 init_controller(r8a66597);
1767 r8a66597_bset(r8a66597, VBSE, INTENB0); 1759 r8a66597_bset(r8a66597, VBSE, INTENB0);
@@ -1775,12 +1767,6 @@ static int r8a66597_start(struct usb_gadget *gadget,
1775 } 1767 }
1776 1768
1777 return 0; 1769 return 0;
1778
1779error:
1780 r8a66597->driver = NULL;
1781 r8a66597->gadget.dev.driver = NULL;
1782
1783 return retval;
1784} 1770}
1785 1771
1786static int r8a66597_stop(struct usb_gadget *gadget, 1772static int r8a66597_stop(struct usb_gadget *gadget,
@@ -1794,7 +1780,6 @@ static int r8a66597_stop(struct usb_gadget *gadget,
1794 disable_controller(r8a66597); 1780 disable_controller(r8a66597);
1795 spin_unlock_irqrestore(&r8a66597->lock, flags); 1781 spin_unlock_irqrestore(&r8a66597->lock, flags);
1796 1782
1797 device_del(&r8a66597->gadget.dev);
1798 r8a66597->driver = NULL; 1783 r8a66597->driver = NULL;
1799 return 0; 1784 return 0;
1800} 1785}
@@ -1845,6 +1830,7 @@ static int __exit r8a66597_remove(struct platform_device *pdev)
1845 clk_put(r8a66597->clk); 1830 clk_put(r8a66597->clk);
1846 } 1831 }
1847#endif 1832#endif
1833 device_unregister(&r8a66597->gadget.dev);
1848 kfree(r8a66597); 1834 kfree(r8a66597);
1849 return 0; 1835 return 0;
1850} 1836}
@@ -1924,13 +1910,17 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1924 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; 1910 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
1925 1911
1926 r8a66597->gadget.ops = &r8a66597_gadget_ops; 1912 r8a66597->gadget.ops = &r8a66597_gadget_ops;
1927 device_initialize(&r8a66597->gadget.dev);
1928 dev_set_name(&r8a66597->gadget.dev, "gadget"); 1913 dev_set_name(&r8a66597->gadget.dev, "gadget");
1929 r8a66597->gadget.is_dualspeed = 1; 1914 r8a66597->gadget.is_dualspeed = 1;
1930 r8a66597->gadget.dev.parent = &pdev->dev; 1915 r8a66597->gadget.dev.parent = &pdev->dev;
1931 r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask; 1916 r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask;
1932 r8a66597->gadget.dev.release = pdev->dev.release; 1917 r8a66597->gadget.dev.release = pdev->dev.release;
1933 r8a66597->gadget.name = udc_name; 1918 r8a66597->gadget.name = udc_name;
1919 ret = device_register(&r8a66597->gadget.dev);
1920 if (ret < 0) {
1921 dev_err(&pdev->dev, "device_register failed\n");
1922 goto clean_up;
1923 }
1934 1924
1935 init_timer(&r8a66597->timer); 1925 init_timer(&r8a66597->timer);
1936 r8a66597->timer.function = r8a66597_timer; 1926 r8a66597->timer.function = r8a66597_timer;
@@ -1945,7 +1935,7 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1945 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", 1935 dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
1946 clk_name); 1936 clk_name);
1947 ret = PTR_ERR(r8a66597->clk); 1937 ret = PTR_ERR(r8a66597->clk);
1948 goto clean_up; 1938 goto clean_up_dev;
1949 } 1939 }
1950 clk_enable(r8a66597->clk); 1940 clk_enable(r8a66597->clk);
1951 } 1941 }
@@ -2014,7 +2004,9 @@ clean_up2:
2014 clk_disable(r8a66597->clk); 2004 clk_disable(r8a66597->clk);
2015 clk_put(r8a66597->clk); 2005 clk_put(r8a66597->clk);
2016 } 2006 }
2007clean_up_dev:
2017#endif 2008#endif
2009 device_unregister(&r8a66597->gadget.dev);
2018clean_up: 2010clean_up:
2019 if (r8a66597) { 2011 if (r8a66597) {
2020 if (r8a66597->sudmac_reg) 2012 if (r8a66597->sudmac_reg)
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index a552453dc94..b31448229f0 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2586,10 +2586,8 @@ static int s3c_hsotg_start(struct usb_gadget_driver *driver,
2586 return -EINVAL; 2586 return -EINVAL;
2587 } 2587 }
2588 2588
2589 if (driver->speed != USB_SPEED_HIGH && 2589 if (driver->speed < USB_SPEED_FULL)
2590 driver->speed != USB_SPEED_FULL) {
2591 dev_err(hsotg->dev, "%s: bad speed\n", __func__); 2590 dev_err(hsotg->dev, "%s: bad speed\n", __func__);
2592 }
2593 2591
2594 if (!bind || !driver->setup) { 2592 if (!bind || !driver->setup) {
2595 dev_err(hsotg->dev, "%s: missing entry points\n", __func__); 2593 dev_err(hsotg->dev, "%s: missing entry points\n", __func__);
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 8d54f893cef..20a553b46ae 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -1142,8 +1142,7 @@ static int s3c_hsudc_start(struct usb_gadget_driver *driver,
1142 int ret; 1142 int ret;
1143 1143
1144 if (!driver 1144 if (!driver
1145 || (driver->speed != USB_SPEED_FULL && 1145 || driver->speed < USB_SPEED_FULL
1146 driver->speed != USB_SPEED_HIGH)
1147 || !bind 1146 || !bind
1148 || !driver->unbind || !driver->disconnect || !driver->setup) 1147 || !driver->unbind || !driver->disconnect || !driver->setup)
1149 return -EINVAL; 1148 return -EINVAL;
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 3a4a664bab4..6597a6813e4 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/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 022baeca7c9..6939e17f458 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -210,10 +210,10 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
210 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 210 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
211 211
212 if (udc_is_newstyle(udc)) { 212 if (udc_is_newstyle(udc)) {
213 usb_gadget_disconnect(udc->gadget); 213 udc->driver->disconnect(udc->gadget);
214 udc->driver->unbind(udc->gadget); 214 udc->driver->unbind(udc->gadget);
215 usb_gadget_udc_stop(udc->gadget, udc->driver); 215 usb_gadget_udc_stop(udc->gadget, udc->driver);
216 216 usb_gadget_disconnect(udc->gadget);
217 } else { 217 } else {
218 usb_gadget_stop(udc->gadget, udc->driver); 218 usb_gadget_stop(udc->gadget, udc->driver);
219 } 219 }
@@ -344,7 +344,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
344static ssize_t usb_udc_srp_store(struct device *dev, 344static ssize_t usb_udc_srp_store(struct device *dev,
345 struct device_attribute *attr, const char *buf, size_t n) 345 struct device_attribute *attr, const char *buf, size_t n)
346{ 346{
347 struct usb_udc *udc = dev_get_drvdata(dev); 347 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
348 348
349 if (sysfs_streq(buf, "1")) 349 if (sysfs_streq(buf, "1"))
350 usb_gadget_wakeup(udc->gadget); 350 usb_gadget_wakeup(udc->gadget);
@@ -378,7 +378,7 @@ static ssize_t usb_udc_speed_show(struct device *dev,
378 return snprintf(buf, PAGE_SIZE, "%s\n", 378 return snprintf(buf, PAGE_SIZE, "%s\n",
379 usb_speed_string(udc->gadget->speed)); 379 usb_speed_string(udc->gadget->speed));
380} 380}
381static DEVICE_ATTR(speed, S_IRUSR, usb_udc_speed_show, NULL); 381static DEVICE_ATTR(speed, S_IRUGO, usb_udc_speed_show, NULL);
382 382
383#define USB_UDC_ATTR(name) \ 383#define USB_UDC_ATTR(name) \
384ssize_t usb_udc_##name##_show(struct device *dev, \ 384ssize_t usb_udc_##name##_show(struct device *dev, \
@@ -389,7 +389,7 @@ ssize_t usb_udc_##name##_show(struct device *dev, \
389 \ 389 \
390 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \ 390 return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
391} \ 391} \
392static DEVICE_ATTR(name, S_IRUSR, usb_udc_##name##_show, NULL) 392static DEVICE_ATTR(name, S_IRUGO, usb_udc_##name##_show, NULL)
393 393
394static USB_UDC_ATTR(is_dualspeed); 394static USB_UDC_ATTR(is_dualspeed);
395static USB_UDC_ATTR(is_otg); 395static USB_UDC_ATTR(is_otg);
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index ed48a5d79e1..7ca290fcb07 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 00000000000..b4192c964d0
--- /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 65719e8d24e..18bafa99fe5 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 59e81615e09..3ff9f82f726 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/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 2e829fae648..a60679cbbf8 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1475,30 +1475,36 @@ iso_stream_schedule (
1475 * jump until after the queue is primed. 1475 * jump until after the queue is primed.
1476 */ 1476 */
1477 else { 1477 else {
1478 int done = 0;
1478 start = SCHEDULE_SLOP + (now & ~0x07); 1479 start = SCHEDULE_SLOP + (now & ~0x07);
1479 1480
1480 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 1481 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
1481 1482
1482 /* find a uframe slot with enough bandwidth */ 1483 /* find a uframe slot with enough bandwidth.
1483 next = start + period; 1484 * Early uframes are more precious because full-speed
1484 for (; start < next; start++) { 1485 * iso IN transfers can't use late uframes,
1485 1486 * and therefore they should be allocated last.
1487 */
1488 next = start;
1489 start += period;
1490 do {
1491 start--;
1486 /* check schedule: enough space? */ 1492 /* check schedule: enough space? */
1487 if (stream->highspeed) { 1493 if (stream->highspeed) {
1488 if (itd_slot_ok(ehci, mod, start, 1494 if (itd_slot_ok(ehci, mod, start,
1489 stream->usecs, period)) 1495 stream->usecs, period))
1490 break; 1496 done = 1;
1491 } else { 1497 } else {
1492 if ((start % 8) >= 6) 1498 if ((start % 8) >= 6)
1493 continue; 1499 continue;
1494 if (sitd_slot_ok(ehci, mod, stream, 1500 if (sitd_slot_ok(ehci, mod, stream,
1495 start, sched, period)) 1501 start, sched, period))
1496 break; 1502 done = 1;
1497 } 1503 }
1498 } 1504 } while (start > next && !done);
1499 1505
1500 /* no room in the schedule */ 1506 /* no room in the schedule */
1501 if (start == next) { 1507 if (!done) {
1502 ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n", 1508 ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n",
1503 urb, now, now + mod); 1509 urb, now, now + mod);
1504 status = -ENOSPC; 1510 status = -ENOSPC;
diff --git a/drivers/usb/host/ehci-xls.c b/drivers/usb/host/ehci-xls.c
index fe74bd67601..b4fb511d24b 100644
--- a/drivers/usb/host/ehci-xls.c
+++ b/drivers/usb/host/ehci-xls.c
@@ -19,7 +19,7 @@ static int ehci_xls_setup(struct usb_hcd *hcd)
19 19
20 ehci->caps = hcd->regs; 20 ehci->caps = hcd->regs;
21 ehci->regs = hcd->regs + 21 ehci->regs = hcd->regs +
22 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 22 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
23 dbg_hcs_params(ehci, "reset"); 23 dbg_hcs_params(ehci, "reset");
24 dbg_hcc_params(ehci, "reset"); 24 dbg_hcc_params(ehci, "reset");
25 25
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index 79a66d622f9..9037035ad1e 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 2c7fc830c9e..a7dc1e1d45f 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-at91.c b/drivers/usb/host/ohci-at91.c
index ba3a46b78b7..95a9fec38e8 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -223,6 +223,9 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int
223 if (port < 0 || port >= 2) 223 if (port < 0 || port >= 2)
224 return; 224 return;
225 225
226 if (pdata->vbus_pin[port] <= 0)
227 return;
228
226 gpio_set_value(pdata->vbus_pin[port], !pdata->vbus_pin_inverted ^ enable); 229 gpio_set_value(pdata->vbus_pin[port], !pdata->vbus_pin_inverted ^ enable);
227} 230}
228 231
@@ -231,6 +234,9 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
231 if (port < 0 || port >= 2) 234 if (port < 0 || port >= 2)
232 return -EINVAL; 235 return -EINVAL;
233 236
237 if (pdata->vbus_pin[port] <= 0)
238 return -EINVAL;
239
234 return gpio_get_value(pdata->vbus_pin[port]) ^ !pdata->vbus_pin_inverted; 240 return gpio_get_value(pdata->vbus_pin[port]) ^ !pdata->vbus_pin_inverted;
235} 241}
236 242
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 6b7bc50dfea..9b66df8278f 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/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 34efd479e06..b2639191549 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -389,17 +389,14 @@ ohci_shutdown (struct usb_hcd *hcd)
389 struct ohci_hcd *ohci; 389 struct ohci_hcd *ohci;
390 390
391 ohci = hcd_to_ohci (hcd); 391 ohci = hcd_to_ohci (hcd);
392 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 392 ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
393 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
394 393
395 /* If the SHUTDOWN quirk is set, don't put the controller in RESET */ 394 /* Software reset, after which the controller goes into SUSPEND */
396 ohci->hc_control &= (ohci->flags & OHCI_QUIRK_SHUTDOWN ? 395 ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
397 OHCI_CTRL_RWC | OHCI_CTRL_HCFS : 396 ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */
398 OHCI_CTRL_RWC); 397 udelay(10);
399 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
400 398
401 /* flush the writes */ 399 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
402 (void) ohci_readl (ohci, &ohci->regs->control);
403} 400}
404 401
405static int check_ed(struct ohci_hcd *ohci, struct ed *ed) 402static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index ad8166c681e..bc01b064585 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -175,28 +175,6 @@ static int ohci_quirk_amd700(struct usb_hcd *hcd)
175 return 0; 175 return 0;
176} 176}
177 177
178/* nVidia controllers continue to drive Reset signalling on the bus
179 * even after system shutdown, wasting power. This flag tells the
180 * shutdown routine to leave the controller OPERATIONAL instead of RESET.
181 */
182static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd)
183{
184 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
185 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
186
187 /* Evidently nVidia fixed their later hardware; this is a guess at
188 * the changeover point.
189 */
190#define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB 0x026d
191
192 if (pdev->device < PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB) {
193 ohci->flags |= OHCI_QUIRK_SHUTDOWN;
194 ohci_dbg(ohci, "enabled nVidia shutdown quirk\n");
195 }
196
197 return 0;
198}
199
200static void sb800_prefetch(struct ohci_hcd *ohci, int on) 178static void sb800_prefetch(struct ohci_hcd *ohci, int on)
201{ 179{
202 struct pci_dev *pdev; 180 struct pci_dev *pdev;
@@ -260,10 +238,6 @@ static const struct pci_device_id ohci_pci_quirks[] = {
260 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399), 238 PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399),
261 .driver_data = (unsigned long)ohci_quirk_amd700, 239 .driver_data = (unsigned long)ohci_quirk_amd700,
262 }, 240 },
263 {
264 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
265 .driver_data = (unsigned long) ohci_quirk_nvidia_shutdown,
266 },
267 241
268 /* FIXME for some of the early AMD 760 southbridges, OHCI 242 /* FIXME for some of the early AMD 760 southbridges, OHCI
269 * won't work at all. blacklist them. 243 * won't work at all. blacklist them.
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 35e5fd640ce..0795b934d00 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -403,7 +403,6 @@ struct ohci_hcd {
403#define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ 403#define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */
404#define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/ 404#define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/
405#define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ 405#define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */
406#define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */
407 // there are also chip quirks/bugs in init logic 406 // there are also chip quirks/bugs in init logic
408 407
409 struct work_struct nec_work; /* Worker for NEC quirk */ 408 struct work_struct nec_work; /* Worker for NEC quirk */
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 629a96813fd..caf87428ca4 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"
@@ -36,6 +37,7 @@
36#define OHCI_INTRENABLE 0x10 37#define OHCI_INTRENABLE 0x10
37#define OHCI_INTRDISABLE 0x14 38#define OHCI_INTRDISABLE 0x14
38#define OHCI_FMINTERVAL 0x34 39#define OHCI_FMINTERVAL 0x34
40#define OHCI_HCFS (3 << 6) /* hc functional state */
39#define OHCI_HCR (1 << 0) /* host controller reset */ 41#define OHCI_HCR (1 << 0) /* host controller reset */
40#define OHCI_OCR (1 << 3) /* ownership change request */ 42#define OHCI_OCR (1 << 3) /* ownership change request */
41#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */ 43#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
@@ -465,6 +467,8 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
465{ 467{
466 void __iomem *base; 468 void __iomem *base;
467 u32 control; 469 u32 control;
470 u32 fminterval;
471 int cnt;
468 472
469 if (!mmio_resource_enabled(pdev, 0)) 473 if (!mmio_resource_enabled(pdev, 0))
470 return; 474 return;
@@ -497,41 +501,32 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
497 } 501 }
498#endif 502#endif
499 503
500 /* reset controller, preserving RWC (and possibly IR) */ 504 /* disable interrupts */
501 writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL); 505 writel((u32) ~0, base + OHCI_INTRDISABLE);
502 readl(base + OHCI_CONTROL);
503 506
504 /* Some NVIDIA controllers stop working if kept in RESET for too long */ 507 /* Reset the USB bus, if the controller isn't already in RESET */
505 if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) { 508 if (control & OHCI_HCFS) {
506 u32 fminterval; 509 /* Go into RESET, preserving RWC (and possibly IR) */
507 int cnt; 510 writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL);
511 readl(base + OHCI_CONTROL);
508 512
509 /* drive reset for at least 50 ms (7.1.7.5) */ 513 /* drive bus reset for at least 50 ms (7.1.7.5) */
510 msleep(50); 514 msleep(50);
515 }
511 516
512 /* software reset of the controller, preserving HcFmInterval */ 517 /* software reset of the controller, preserving HcFmInterval */
513 fminterval = readl(base + OHCI_FMINTERVAL); 518 fminterval = readl(base + OHCI_FMINTERVAL);
514 writel(OHCI_HCR, base + OHCI_CMDSTATUS); 519 writel(OHCI_HCR, base + OHCI_CMDSTATUS);
515 520
516 /* reset requires max 10 us delay */ 521 /* reset requires max 10 us delay */
517 for (cnt = 30; cnt > 0; --cnt) { /* ... allow extra time */ 522 for (cnt = 30; cnt > 0; --cnt) { /* ... allow extra time */
518 if ((readl(base + OHCI_CMDSTATUS) & OHCI_HCR) == 0) 523 if ((readl(base + OHCI_CMDSTATUS) & OHCI_HCR) == 0)
519 break; 524 break;
520 udelay(1); 525 udelay(1);
521 }
522 writel(fminterval, base + OHCI_FMINTERVAL);
523
524 /* Now we're in the SUSPEND state with all devices reset
525 * and wakeups and interrupts disabled
526 */
527 } 526 }
527 writel(fminterval, base + OHCI_FMINTERVAL);
528 528
529 /* 529 /* Now the controller is safely in SUSPEND and nothing can wake it up */
530 * disable interrupts
531 */
532 writel(~(u32)0, base + OHCI_INTRDISABLE);
533 writel(~(u32)0, base + OHCI_INTRSTATUS);
534
535 iounmap(base); 530 iounmap(base);
536} 531}
537 532
@@ -626,7 +621,7 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
626 void __iomem *base, *op_reg_base; 621 void __iomem *base, *op_reg_base;
627 u32 hcc_params, cap, val; 622 u32 hcc_params, cap, val;
628 u8 offset, cap_length; 623 u8 offset, cap_length;
629 int wait_time, delta, count = 256/4; 624 int wait_time, count = 256/4;
630 625
631 if (!mmio_resource_enabled(pdev, 0)) 626 if (!mmio_resource_enabled(pdev, 0))
632 return; 627 return;
@@ -672,11 +667,10 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
672 writel(val, op_reg_base + EHCI_USBCMD); 667 writel(val, op_reg_base + EHCI_USBCMD);
673 668
674 wait_time = 2000; 669 wait_time = 2000;
675 delta = 100;
676 do { 670 do {
677 writel(0x3f, op_reg_base + EHCI_USBSTS); 671 writel(0x3f, op_reg_base + EHCI_USBSTS);
678 udelay(delta); 672 udelay(100);
679 wait_time -= delta; 673 wait_time -= 100;
680 val = readl(op_reg_base + EHCI_USBSTS); 674 val = readl(op_reg_base + EHCI_USBSTS);
681 if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) { 675 if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) {
682 break; 676 break;
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c
index 767af265e00..ba61dae9e4d 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 9546f6cd01f..1e141f755b2 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/whci/qset.c b/drivers/usb/host/whci/qset.c
index d6e17542861..a403b53e86b 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -124,7 +124,7 @@ void qset_clear(struct whc *whc, struct whc_qset *qset)
124{ 124{
125 qset->td_start = qset->td_end = qset->ntds = 0; 125 qset->td_start = qset->td_end = qset->ntds = 0;
126 126
127 qset->qh.link = cpu_to_le32(QH_LINK_NTDS(8) | QH_LINK_T); 127 qset->qh.link = cpu_to_le64(QH_LINK_NTDS(8) | QH_LINK_T);
128 qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK; 128 qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK;
129 qset->qh.err_count = 0; 129 qset->qh.err_count = 0;
130 qset->qh.scratch[0] = 0; 130 qset->qh.scratch[0] = 0;
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 431efe72b1f..430e88fd3f6 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-mem.c b/drivers/usb/host/xhci-mem.c
index 42a22b8e692..0e4b25fa3bc 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -982,7 +982,6 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
982 struct xhci_virt_device *dev; 982 struct xhci_virt_device *dev;
983 struct xhci_ep_ctx *ep0_ctx; 983 struct xhci_ep_ctx *ep0_ctx;
984 struct xhci_slot_ctx *slot_ctx; 984 struct xhci_slot_ctx *slot_ctx;
985 struct xhci_input_control_ctx *ctrl_ctx;
986 u32 port_num; 985 u32 port_num;
987 struct usb_device *top_dev; 986 struct usb_device *top_dev;
988 987
@@ -994,12 +993,8 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
994 return -EINVAL; 993 return -EINVAL;
995 } 994 }
996 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); 995 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0);
997 ctrl_ctx = xhci_get_input_control_ctx(xhci, dev->in_ctx);
998 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); 996 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx);
999 997
1000 /* 2) New slot context and endpoint 0 context are valid*/
1001 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
1002
1003 /* 3) Only the control endpoint is valid - one endpoint context */ 998 /* 3) Only the control endpoint is valid - one endpoint context */
1004 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); 999 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route);
1005 switch (udev->speed) { 1000 switch (udev->speed) {
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 9f51f88cc0f..ef98b38626f 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/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 940321b3ec6..9f1d4b15d81 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -816,23 +816,24 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
816 struct xhci_ring *ring; 816 struct xhci_ring *ring;
817 struct xhci_td *cur_td; 817 struct xhci_td *cur_td;
818 int ret, i, j; 818 int ret, i, j;
819 unsigned long flags;
819 820
820 ep = (struct xhci_virt_ep *) arg; 821 ep = (struct xhci_virt_ep *) arg;
821 xhci = ep->xhci; 822 xhci = ep->xhci;
822 823
823 spin_lock(&xhci->lock); 824 spin_lock_irqsave(&xhci->lock, flags);
824 825
825 ep->stop_cmds_pending--; 826 ep->stop_cmds_pending--;
826 if (xhci->xhc_state & XHCI_STATE_DYING) { 827 if (xhci->xhc_state & XHCI_STATE_DYING) {
827 xhci_dbg(xhci, "Stop EP timer ran, but another timer marked " 828 xhci_dbg(xhci, "Stop EP timer ran, but another timer marked "
828 "xHCI as DYING, exiting.\n"); 829 "xHCI as DYING, exiting.\n");
829 spin_unlock(&xhci->lock); 830 spin_unlock_irqrestore(&xhci->lock, flags);
830 return; 831 return;
831 } 832 }
832 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) { 833 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) {
833 xhci_dbg(xhci, "Stop EP timer ran, but no command pending, " 834 xhci_dbg(xhci, "Stop EP timer ran, but no command pending, "
834 "exiting.\n"); 835 "exiting.\n");
835 spin_unlock(&xhci->lock); 836 spin_unlock_irqrestore(&xhci->lock, flags);
836 return; 837 return;
837 } 838 }
838 839
@@ -844,11 +845,11 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
844 xhci->xhc_state |= XHCI_STATE_DYING; 845 xhci->xhc_state |= XHCI_STATE_DYING;
845 /* Disable interrupts from the host controller and start halting it */ 846 /* Disable interrupts from the host controller and start halting it */
846 xhci_quiesce(xhci); 847 xhci_quiesce(xhci);
847 spin_unlock(&xhci->lock); 848 spin_unlock_irqrestore(&xhci->lock, flags);
848 849
849 ret = xhci_halt(xhci); 850 ret = xhci_halt(xhci);
850 851
851 spin_lock(&xhci->lock); 852 spin_lock_irqsave(&xhci->lock, flags);
852 if (ret < 0) { 853 if (ret < 0) {
853 /* This is bad; the host is not responding to commands and it's 854 /* This is bad; the host is not responding to commands and it's
854 * not allowing itself to be halted. At least interrupts are 855 * not allowing itself to be halted. At least interrupts are
@@ -896,7 +897,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
896 } 897 }
897 } 898 }
898 } 899 }
899 spin_unlock(&xhci->lock); 900 spin_unlock_irqrestore(&xhci->lock, flags);
900 xhci_dbg(xhci, "Calling usb_hc_died()\n"); 901 xhci_dbg(xhci, "Calling usb_hc_died()\n");
901 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); 902 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd);
902 xhci_dbg(xhci, "xHCI host controller is dead.\n"); 903 xhci_dbg(xhci, "xHCI host controller is dead.\n");
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 1ff95a0df57..a1afb7c39f7 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -711,7 +711,10 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
711 ring = xhci->cmd_ring; 711 ring = xhci->cmd_ring;
712 seg = ring->deq_seg; 712 seg = ring->deq_seg;
713 do { 713 do {
714 memset(seg->trbs, 0, SEGMENT_SIZE); 714 memset(seg->trbs, 0,
715 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1));
716 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &=
717 cpu_to_le32(~TRB_CYCLE);
715 seg = seg->next; 718 seg = seg->next;
716 } while (seg != ring->deq_seg); 719 } while (seg != ring->deq_seg);
717 720
@@ -799,7 +802,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
799 u32 command, temp = 0; 802 u32 command, temp = 0;
800 struct usb_hcd *hcd = xhci_to_hcd(xhci); 803 struct usb_hcd *hcd = xhci_to_hcd(xhci);
801 struct usb_hcd *secondary_hcd; 804 struct usb_hcd *secondary_hcd;
802 int retval; 805 int retval = 0;
803 806
804 /* Wait a bit if either of the roothubs need to settle from the 807 /* Wait a bit if either of the roothubs need to settle from the
805 * transition into bus suspend. 808 * transition into bus suspend.
@@ -809,6 +812,9 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
809 xhci->bus_state[1].next_statechange)) 812 xhci->bus_state[1].next_statechange))
810 msleep(100); 813 msleep(100);
811 814
815 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
816 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
817
812 spin_lock_irq(&xhci->lock); 818 spin_lock_irq(&xhci->lock);
813 if (xhci->quirks & XHCI_RESET_ON_RESUME) 819 if (xhci->quirks & XHCI_RESET_ON_RESUME)
814 hibernated = true; 820 hibernated = true;
@@ -878,20 +884,13 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
878 return retval; 884 return retval;
879 xhci_dbg(xhci, "Start the primary HCD\n"); 885 xhci_dbg(xhci, "Start the primary HCD\n");
880 retval = xhci_run(hcd->primary_hcd); 886 retval = xhci_run(hcd->primary_hcd);
881 if (retval)
882 goto failed_restart;
883
884 xhci_dbg(xhci, "Start the secondary HCD\n");
885 retval = xhci_run(secondary_hcd);
886 if (!retval) { 887 if (!retval) {
887 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 888 xhci_dbg(xhci, "Start the secondary HCD\n");
888 set_bit(HCD_FLAG_HW_ACCESSIBLE, 889 retval = xhci_run(secondary_hcd);
889 &xhci->shared_hcd->flags);
890 } 890 }
891failed_restart:
892 hcd->state = HC_STATE_SUSPENDED; 891 hcd->state = HC_STATE_SUSPENDED;
893 xhci->shared_hcd->state = HC_STATE_SUSPENDED; 892 xhci->shared_hcd->state = HC_STATE_SUSPENDED;
894 return retval; 893 goto done;
895 } 894 }
896 895
897 /* step 4: set Run/Stop bit */ 896 /* step 4: set Run/Stop bit */
@@ -910,11 +909,14 @@ failed_restart:
910 * Running endpoints by ringing their doorbells 909 * Running endpoints by ringing their doorbells
911 */ 910 */
912 911
913 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
914 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags);
915
916 spin_unlock_irq(&xhci->lock); 912 spin_unlock_irq(&xhci->lock);
917 return 0; 913
914 done:
915 if (retval == 0) {
916 usb_hcd_resume_root_hub(hcd);
917 usb_hcd_resume_root_hub(xhci->shared_hcd);
918 }
919 return retval;
918} 920}
919#endif /* CONFIG_PM */ 921#endif /* CONFIG_PM */
920 922
@@ -3504,6 +3506,10 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3504 /* Otherwise, update the control endpoint ring enqueue pointer. */ 3506 /* Otherwise, update the control endpoint ring enqueue pointer. */
3505 else 3507 else
3506 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); 3508 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev);
3509 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
3510 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG);
3511 ctrl_ctx->drop_flags = 0;
3512
3507 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); 3513 xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id);
3508 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); 3514 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2);
3509 3515
@@ -3585,7 +3591,6 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3585 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK) 3591 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK)
3586 + 1; 3592 + 1;
3587 /* Zero the input context control for later use */ 3593 /* Zero the input context control for later use */
3588 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
3589 ctrl_ctx->add_flags = 0; 3594 ctrl_ctx->add_flags = 0;
3590 ctrl_ctx->drop_flags = 0; 3595 ctrl_ctx->drop_flags = 0;
3591 3596
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index a04b2ff9dd8..91cd85076a4 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 e5ce42bd316..ebd6189a501 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 1c3afcc11bd..ad408251d95 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/musb/Kconfig b/drivers/usb/musb/Kconfig
index fc34b8b1191..07a03460a59 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -11,6 +11,7 @@ config USB_MUSB_HDRC
11 select TWL4030_USB if MACH_OMAP_3430SDP 11 select TWL4030_USB if MACH_OMAP_3430SDP
12 select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA 12 select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA
13 select USB_OTG_UTILS 13 select USB_OTG_UTILS
14 select USB_GADGET_DUALSPEED
14 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 15 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
15 help 16 help
16 Say Y here if your system has a dual role high speed USB 17 Say Y here if your system has a dual role high speed USB
@@ -60,7 +61,7 @@ config USB_MUSB_BLACKFIN
60 61
61config USB_MUSB_UX500 62config USB_MUSB_UX500
62 tristate "U8500 and U5500" 63 tristate "U8500 and U5500"
63 depends on (ARCH_U8500 && AB8500_USB) || (ARCH_U5500) 64 depends on (ARCH_U8500 && AB8500_USB)
64 65
65endchoice 66endchoice
66 67
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 08f1d0b662a..e233d2b7d33 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -27,6 +27,7 @@
27 */ 27 */
28 28
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/module.h>
30#include <linux/clk.h> 31#include <linux/clk.h>
31#include <linux/io.h> 32#include <linux/io.h>
32#include <linux/platform_device.h> 33#include <linux/platform_device.h>
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 4da7492ddbd..2613bfdb09b 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -27,6 +27,7 @@
27 */ 27 */
28 28
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/module.h>
30#include <linux/clk.h> 31#include <linux/clk.h>
31#include <linux/io.h> 32#include <linux/io.h>
32#include <linux/platform_device.h> 33#include <linux/platform_device.h>
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 20a28731c33..b63ab157010 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1477,8 +1477,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1477/*-------------------------------------------------------------------------*/ 1477/*-------------------------------------------------------------------------*/
1478 1478
1479#if defined(CONFIG_SOC_OMAP2430) || defined(CONFIG_SOC_OMAP3430) || \ 1479#if defined(CONFIG_SOC_OMAP2430) || defined(CONFIG_SOC_OMAP3430) || \
1480 defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_ARCH_U8500) || \ 1480 defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_ARCH_U8500)
1481 defined(CONFIG_ARCH_U5500)
1482 1481
1483static irqreturn_t generic_interrupt(int irq, void *__hci) 1482static irqreturn_t generic_interrupt(int irq, void *__hci)
1484{ 1483{
@@ -2302,18 +2301,12 @@ static int musb_suspend(struct device *dev)
2302 */ 2301 */
2303 } 2302 }
2304 2303
2305 musb_save_context(musb);
2306
2307 spin_unlock_irqrestore(&musb->lock, flags); 2304 spin_unlock_irqrestore(&musb->lock, flags);
2308 return 0; 2305 return 0;
2309} 2306}
2310 2307
2311static int musb_resume_noirq(struct device *dev) 2308static int musb_resume_noirq(struct device *dev)
2312{ 2309{
2313 struct musb *musb = dev_to_musb(dev);
2314
2315 musb_restore_context(musb);
2316
2317 /* for static cmos like DaVinci, register values were preserved 2310 /* for static cmos like DaVinci, register values were preserved
2318 * unless for some reason the whole soc powered down or the USB 2311 * unless for some reason the whole soc powered down or the USB
2319 * module got reset through the PSC (vs just being disabled). 2312 * module got reset through the PSC (vs just being disabled).
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index ae4a20acef6..922148ff8d2 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1903,7 +1903,7 @@ static int musb_gadget_start(struct usb_gadget *g,
1903 unsigned long flags; 1903 unsigned long flags;
1904 int retval = -EINVAL; 1904 int retval = -EINVAL;
1905 1905
1906 if (driver->speed != USB_SPEED_HIGH) 1906 if (driver->speed < USB_SPEED_HIGH)
1907 goto err0; 1907 goto err0;
1908 1908
1909 pm_runtime_get_sync(musb->controller); 1909 pm_runtime_get_sync(musb->controller);
@@ -1999,10 +1999,6 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver)
1999 nuke(&hw_ep->ep_out, -ESHUTDOWN); 1999 nuke(&hw_ep->ep_out, -ESHUTDOWN);
2000 } 2000 }
2001 } 2001 }
2002
2003 spin_unlock(&musb->lock);
2004 driver->disconnect(&musb->g);
2005 spin_lock(&musb->lock);
2006 } 2002 }
2007} 2003}
2008 2004
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index 52733d9959b..fb644c107de 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 fb7adeff9ff..307c27bc51e 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 770d799d5af..0b0466728fd 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/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
index d2e2efaba65..08c679c0dde 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -405,7 +405,7 @@ int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
405/* 405/*
406 * platform functions 406 * platform functions
407 */ 407 */
408static int __devinit usbhs_probe(struct platform_device *pdev) 408static int usbhs_probe(struct platform_device *pdev)
409{ 409{
410 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data; 410 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
411 struct renesas_usbhs_driver_callback *dfunc; 411 struct renesas_usbhs_driver_callback *dfunc;
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 8da685e796d..ffdf5d15085 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -820,7 +820,7 @@ static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
820 if (len % 4) /* 32bit alignment */ 820 if (len % 4) /* 32bit alignment */
821 goto usbhsf_pio_prepare_push; 821 goto usbhsf_pio_prepare_push;
822 822
823 if ((*(u32 *) pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */ 823 if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
824 goto usbhsf_pio_prepare_push; 824 goto usbhsf_pio_prepare_push;
825 825
826 /* get enable DMA fifo */ 826 /* get enable DMA fifo */
@@ -897,7 +897,7 @@ static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
897 if (!fifo) 897 if (!fifo)
898 goto usbhsf_pio_prepare_pop; 898 goto usbhsf_pio_prepare_pop;
899 899
900 if ((*(u32 *) pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */ 900 if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
901 goto usbhsf_pio_prepare_pop; 901 goto usbhsf_pio_prepare_pop;
902 902
903 ret = usbhsf_fifo_select(pipe, fifo, 0); 903 ret = usbhsf_fifo_select(pipe, fifo, 0);
diff --git a/drivers/usb/renesas_usbhs/mod.h b/drivers/usb/renesas_usbhs/mod.h
index 8ae3733031c..6c6875533f0 100644
--- a/drivers/usb/renesas_usbhs/mod.h
+++ b/drivers/usb/renesas_usbhs/mod.h
@@ -143,8 +143,8 @@ void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
143 */ 143 */
144#if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \ 144#if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
145 defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE) 145 defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
146extern int __devinit usbhs_mod_host_probe(struct usbhs_priv *priv); 146extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
147extern int __devexit usbhs_mod_host_remove(struct usbhs_priv *priv); 147extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
148#else 148#else
149static inline int usbhs_mod_host_probe(struct usbhs_priv *priv) 149static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
150{ 150{
@@ -157,8 +157,8 @@ static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
157 157
158#if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \ 158#if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
159 defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE) 159 defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
160extern int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv); 160extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
161extern void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv); 161extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
162#else 162#else
163static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv) 163static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
164{ 164{
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 4cc7ee0babc..7f4e8033857 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -751,53 +751,32 @@ static int usbhsg_gadget_start(struct usb_gadget *gadget,
751 struct usb_gadget_driver *driver) 751 struct usb_gadget_driver *driver)
752{ 752{
753 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); 753 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
754 struct usbhs_priv *priv; 754 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
755 struct device *dev;
756 int ret;
757 755
758 if (!driver || 756 if (!driver ||
759 !driver->setup || 757 !driver->setup ||
760 driver->speed != USB_SPEED_HIGH) 758 driver->speed < USB_SPEED_FULL)
761 return -EINVAL; 759 return -EINVAL;
762 760
763 dev = usbhsg_gpriv_to_dev(gpriv);
764 priv = usbhsg_gpriv_to_priv(gpriv);
765
766 /* first hook up the driver ... */ 761 /* first hook up the driver ... */
767 gpriv->driver = driver; 762 gpriv->driver = driver;
768 gpriv->gadget.dev.driver = &driver->driver; 763 gpriv->gadget.dev.driver = &driver->driver;
769 764
770 ret = device_add(&gpriv->gadget.dev);
771 if (ret) {
772 dev_err(dev, "device_add error %d\n", ret);
773 goto add_fail;
774 }
775
776 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); 765 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD);
777
778add_fail:
779 gpriv->driver = NULL;
780 gpriv->gadget.dev.driver = NULL;
781
782 return ret;
783} 766}
784 767
785static int usbhsg_gadget_stop(struct usb_gadget *gadget, 768static int usbhsg_gadget_stop(struct usb_gadget *gadget,
786 struct usb_gadget_driver *driver) 769 struct usb_gadget_driver *driver)
787{ 770{
788 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget); 771 struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
789 struct usbhs_priv *priv; 772 struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
790 struct device *dev;
791 773
792 if (!driver || 774 if (!driver ||
793 !driver->unbind) 775 !driver->unbind)
794 return -EINVAL; 776 return -EINVAL;
795 777
796 dev = usbhsg_gpriv_to_dev(gpriv);
797 priv = usbhsg_gpriv_to_priv(gpriv);
798
799 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); 778 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD);
800 device_del(&gpriv->gadget.dev); 779 gpriv->gadget.dev.driver = NULL;
801 gpriv->driver = NULL; 780 gpriv->driver = NULL;
802 781
803 return 0; 782 return 0;
@@ -827,10 +806,17 @@ static int usbhsg_start(struct usbhs_priv *priv)
827 806
828static int usbhsg_stop(struct usbhs_priv *priv) 807static int usbhsg_stop(struct usbhs_priv *priv)
829{ 808{
809 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
810
811 /* cable disconnect */
812 if (gpriv->driver &&
813 gpriv->driver->disconnect)
814 gpriv->driver->disconnect(&gpriv->gadget);
815
830 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); 816 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED);
831} 817}
832 818
833int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv) 819int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
834{ 820{
835 struct usbhsg_gpriv *gpriv; 821 struct usbhsg_gpriv *gpriv;
836 struct usbhsg_uep *uep; 822 struct usbhsg_uep *uep;
@@ -876,12 +862,14 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
876 /* 862 /*
877 * init gadget 863 * init gadget
878 */ 864 */
879 device_initialize(&gpriv->gadget.dev);
880 dev_set_name(&gpriv->gadget.dev, "gadget"); 865 dev_set_name(&gpriv->gadget.dev, "gadget");
881 gpriv->gadget.dev.parent = dev; 866 gpriv->gadget.dev.parent = dev;
882 gpriv->gadget.name = "renesas_usbhs_udc"; 867 gpriv->gadget.name = "renesas_usbhs_udc";
883 gpriv->gadget.ops = &usbhsg_gadget_ops; 868 gpriv->gadget.ops = &usbhsg_gadget_ops;
884 gpriv->gadget.is_dualspeed = 1; 869 gpriv->gadget.is_dualspeed = 1;
870 ret = device_register(&gpriv->gadget.dev);
871 if (ret < 0)
872 goto err_add_udc;
885 873
886 INIT_LIST_HEAD(&gpriv->gadget.ep_list); 874 INIT_LIST_HEAD(&gpriv->gadget.ep_list);
887 875
@@ -912,12 +900,15 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv)
912 900
913 ret = usb_add_gadget_udc(dev, &gpriv->gadget); 901 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
914 if (ret) 902 if (ret)
915 goto err_add_udc; 903 goto err_register;
916 904
917 905
918 dev_info(dev, "gadget probed\n"); 906 dev_info(dev, "gadget probed\n");
919 907
920 return 0; 908 return 0;
909
910err_register:
911 device_unregister(&gpriv->gadget.dev);
921err_add_udc: 912err_add_udc:
922 kfree(gpriv->uep); 913 kfree(gpriv->uep);
923 914
@@ -927,12 +918,14 @@ usbhs_mod_gadget_probe_err_gpriv:
927 return ret; 918 return ret;
928} 919}
929 920
930void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv) 921void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
931{ 922{
932 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); 923 struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
933 924
934 usb_del_gadget_udc(&gpriv->gadget); 925 usb_del_gadget_udc(&gpriv->gadget);
935 926
927 device_unregister(&gpriv->gadget.dev);
928
936 usbhsg_controller_unregister(gpriv); 929 usbhsg_controller_unregister(gpriv);
937 930
938 kfree(gpriv->uep); 931 kfree(gpriv->uep);
diff --git a/drivers/usb/renesas_usbhs/mod_host.c b/drivers/usb/renesas_usbhs/mod_host.c
index 1a7208a50af..bade761a1e5 100644
--- a/drivers/usb/renesas_usbhs/mod_host.c
+++ b/drivers/usb/renesas_usbhs/mod_host.c
@@ -103,7 +103,7 @@ struct usbhsh_hpriv {
103 103
104 u32 port_stat; /* USB_PORT_STAT_xxx */ 104 u32 port_stat; /* USB_PORT_STAT_xxx */
105 105
106 struct completion *done; 106 struct completion setup_ack_done;
107 107
108 /* see usbhsh_req_alloc/free */ 108 /* see usbhsh_req_alloc/free */
109 struct list_head ureq_link_active; 109 struct list_head ureq_link_active;
@@ -355,6 +355,7 @@ static void usbhsh_device_free(struct usbhsh_hpriv *hpriv,
355struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv, 355struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
356 struct usbhsh_device *udev, 356 struct usbhsh_device *udev,
357 struct usb_host_endpoint *ep, 357 struct usb_host_endpoint *ep,
358 int dir_in_req,
358 gfp_t mem_flags) 359 gfp_t mem_flags)
359{ 360{
360 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv); 361 struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
@@ -364,27 +365,38 @@ struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
364 struct usbhs_pipe *pipe, *best_pipe; 365 struct usbhs_pipe *pipe, *best_pipe;
365 struct device *dev = usbhsh_hcd_to_dev(hcd); 366 struct device *dev = usbhsh_hcd_to_dev(hcd);
366 struct usb_endpoint_descriptor *desc = &ep->desc; 367 struct usb_endpoint_descriptor *desc = &ep->desc;
367 int type, i; 368 int type, i, dir_in;
368 unsigned int min_usr; 369 unsigned int min_usr;
369 370
371 dir_in_req = !!dir_in_req;
372
370 uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags); 373 uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags);
371 if (!uep) { 374 if (!uep) {
372 dev_err(dev, "usbhsh_ep alloc fail\n"); 375 dev_err(dev, "usbhsh_ep alloc fail\n");
373 return NULL; 376 return NULL;
374 } 377 }
375 type = usb_endpoint_type(desc); 378
379 if (usb_endpoint_xfer_control(desc)) {
380 best_pipe = usbhsh_hpriv_to_dcp(hpriv);
381 goto usbhsh_endpoint_alloc_find_pipe;
382 }
376 383
377 /* 384 /*
378 * find best pipe for endpoint 385 * find best pipe for endpoint
379 * see 386 * see
380 * HARDWARE LIMITATION 387 * HARDWARE LIMITATION
381 */ 388 */
389 type = usb_endpoint_type(desc);
382 min_usr = ~0; 390 min_usr = ~0;
383 best_pipe = NULL; 391 best_pipe = NULL;
384 usbhs_for_each_pipe_with_dcp(pipe, priv, i) { 392 usbhs_for_each_pipe(pipe, priv, i) {
385 if (!usbhs_pipe_type_is(pipe, type)) 393 if (!usbhs_pipe_type_is(pipe, type))
386 continue; 394 continue;
387 395
396 dir_in = !!usbhs_pipe_is_dir_in(pipe);
397 if (0 != (dir_in - dir_in_req))
398 continue;
399
388 info = usbhsh_pipe_info(pipe); 400 info = usbhsh_pipe_info(pipe);
389 401
390 if (min_usr > info->usr_cnt) { 402 if (min_usr > info->usr_cnt) {
@@ -398,7 +410,7 @@ struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
398 kfree(uep); 410 kfree(uep);
399 return NULL; 411 return NULL;
400 } 412 }
401 413usbhsh_endpoint_alloc_find_pipe:
402 /* 414 /*
403 * init uep 415 * init uep
404 */ 416 */
@@ -423,6 +435,7 @@ struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
423 * see 435 * see
424 * DCPMAXP/PIPEMAXP 436 * DCPMAXP/PIPEMAXP
425 */ 437 */
438 usbhs_pipe_sequence_data0(uep->pipe);
426 usbhs_pipe_config_update(uep->pipe, 439 usbhs_pipe_config_update(uep->pipe,
427 usbhsh_device_number(hpriv, udev), 440 usbhsh_device_number(hpriv, udev),
428 usb_endpoint_num(desc), 441 usb_endpoint_num(desc),
@@ -430,7 +443,7 @@ struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
430 443
431 dev_dbg(dev, "%s [%d-%s](%p)\n", __func__, 444 dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
432 usbhsh_device_number(hpriv, udev), 445 usbhsh_device_number(hpriv, udev),
433 usbhs_pipe_name(pipe), uep); 446 usbhs_pipe_name(uep->pipe), uep);
434 447
435 return uep; 448 return uep;
436} 449}
@@ -549,8 +562,7 @@ static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv *hpriv,
549 * usbhsh_irq_setup_ack() 562 * usbhsh_irq_setup_ack()
550 * usbhsh_irq_setup_err() 563 * usbhsh_irq_setup_err()
551 */ 564 */
552 DECLARE_COMPLETION(done); 565 init_completion(&hpriv->setup_ack_done);
553 hpriv->done = &done;
554 566
555 /* copy original request */ 567 /* copy original request */
556 memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest)); 568 memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest));
@@ -572,8 +584,7 @@ static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv *hpriv,
572 /* 584 /*
573 * wait setup packet ACK 585 * wait setup packet ACK
574 */ 586 */
575 wait_for_completion(&done); 587 wait_for_completion(&hpriv->setup_ack_done);
576 hpriv->done = NULL;
577 588
578 dev_dbg(dev, "%s done\n", __func__); 589 dev_dbg(dev, "%s done\n", __func__);
579} 590}
@@ -724,11 +735,11 @@ static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
724 struct usbhsh_device *udev, *new_udev = NULL; 735 struct usbhsh_device *udev, *new_udev = NULL;
725 struct usbhs_pipe *pipe; 736 struct usbhs_pipe *pipe;
726 struct usbhsh_ep *uep; 737 struct usbhsh_ep *uep;
738 int is_dir_in = usb_pipein(urb->pipe);
727 739
728 int ret; 740 int ret;
729 741
730 dev_dbg(dev, "%s (%s)\n", 742 dev_dbg(dev, "%s (%s)\n", __func__, is_dir_in ? "in" : "out");
731 __func__, usb_pipein(urb->pipe) ? "in" : "out");
732 743
733 ret = usb_hcd_link_urb_to_ep(hcd, urb); 744 ret = usb_hcd_link_urb_to_ep(hcd, urb);
734 if (ret) 745 if (ret)
@@ -751,7 +762,8 @@ static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
751 */ 762 */
752 uep = usbhsh_ep_to_uep(ep); 763 uep = usbhsh_ep_to_uep(ep);
753 if (!uep) { 764 if (!uep) {
754 uep = usbhsh_endpoint_alloc(hpriv, udev, ep, mem_flags); 765 uep = usbhsh_endpoint_alloc(hpriv, udev, ep,
766 is_dir_in, mem_flags);
755 if (!uep) 767 if (!uep)
756 goto usbhsh_urb_enqueue_error_free_device; 768 goto usbhsh_urb_enqueue_error_free_device;
757 } 769 }
@@ -1095,10 +1107,7 @@ static int usbhsh_irq_setup_ack(struct usbhs_priv *priv,
1095 1107
1096 dev_dbg(dev, "setup packet OK\n"); 1108 dev_dbg(dev, "setup packet OK\n");
1097 1109
1098 if (unlikely(!hpriv->done)) 1110 complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
1099 dev_err(dev, "setup ack happen without necessary data\n");
1100 else
1101 complete(hpriv->done); /* see usbhsh_urb_enqueue() */
1102 1111
1103 return 0; 1112 return 0;
1104} 1113}
@@ -1111,10 +1120,7 @@ static int usbhsh_irq_setup_err(struct usbhs_priv *priv,
1111 1120
1112 dev_dbg(dev, "setup packet Err\n"); 1121 dev_dbg(dev, "setup packet Err\n");
1113 1122
1114 if (unlikely(!hpriv->done)) 1123 complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
1115 dev_err(dev, "setup err happen without necessary data\n");
1116 else
1117 complete(hpriv->done); /* see usbhsh_urb_enqueue() */
1118 1124
1119 return 0; 1125 return 0;
1120} 1126}
@@ -1221,8 +1227,18 @@ static int usbhsh_stop(struct usbhs_priv *priv)
1221{ 1227{
1222 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); 1228 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1223 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); 1229 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
1230 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1224 struct device *dev = usbhs_priv_to_dev(priv); 1231 struct device *dev = usbhs_priv_to_dev(priv);
1225 1232
1233 /*
1234 * disable irq callback
1235 */
1236 mod->irq_attch = NULL;
1237 mod->irq_dtch = NULL;
1238 mod->irq_sack = NULL;
1239 mod->irq_sign = NULL;
1240 usbhs_irq_callback_update(priv, mod);
1241
1226 usb_remove_hcd(hcd); 1242 usb_remove_hcd(hcd);
1227 1243
1228 /* disable sys */ 1244 /* disable sys */
@@ -1235,7 +1251,7 @@ static int usbhsh_stop(struct usbhs_priv *priv)
1235 return 0; 1251 return 0;
1236} 1252}
1237 1253
1238int __devinit usbhs_mod_host_probe(struct usbhs_priv *priv) 1254int usbhs_mod_host_probe(struct usbhs_priv *priv)
1239{ 1255{
1240 struct usbhsh_hpriv *hpriv; 1256 struct usbhsh_hpriv *hpriv;
1241 struct usb_hcd *hcd; 1257 struct usb_hcd *hcd;
@@ -1279,7 +1295,6 @@ int __devinit usbhs_mod_host_probe(struct usbhs_priv *priv)
1279 hpriv->mod.stop = usbhsh_stop; 1295 hpriv->mod.stop = usbhsh_stop;
1280 hpriv->pipe_info = pipe_info; 1296 hpriv->pipe_info = pipe_info;
1281 hpriv->pipe_size = pipe_size; 1297 hpriv->pipe_size = pipe_size;
1282 hpriv->done = NULL;
1283 usbhsh_req_list_init(hpriv); 1298 usbhsh_req_list_init(hpriv);
1284 usbhsh_port_stat_init(hpriv); 1299 usbhsh_port_stat_init(hpriv);
1285 1300
@@ -1299,7 +1314,7 @@ usbhs_mod_host_probe_err:
1299 return -ENOMEM; 1314 return -ENOMEM;
1300} 1315}
1301 1316
1302int __devexit usbhs_mod_host_remove(struct usbhs_priv *priv) 1317int usbhs_mod_host_remove(struct usbhs_priv *priv)
1303{ 1318{
1304 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); 1319 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
1305 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); 1320 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index aba201cb872..b43d07df4c4 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/ark3116.c b/drivers/usb/serial/ark3116.c
index 5cdb9d91227..18e875b92e0 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -42,7 +42,7 @@ static int debug;
42 * Version information 42 * Version information
43 */ 43 */
44 44
45#define DRIVER_VERSION "v0.6" 45#define DRIVER_VERSION "v0.7"
46#define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>" 46#define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>"
47#define DRIVER_DESC "USB ARK3116 serial/IrDA driver" 47#define DRIVER_DESC "USB ARK3116 serial/IrDA driver"
48#define DRIVER_DEV_DESC "ARK3116 RS232/IrDA" 48#define DRIVER_DEV_DESC "ARK3116 RS232/IrDA"
@@ -380,10 +380,6 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
380 goto err_out; 380 goto err_out;
381 } 381 }
382 382
383 /* setup termios */
384 if (tty)
385 ark3116_set_termios(tty, port, NULL);
386
387 /* remove any data still left: also clears error state */ 383 /* remove any data still left: also clears error state */
388 ark3116_read_reg(serial, UART_RX, buf); 384 ark3116_read_reg(serial, UART_RX, buf);
389 385
@@ -406,6 +402,10 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
406 /* enable DMA */ 402 /* enable DMA */
407 ark3116_write_reg(port->serial, UART_FCR, UART_FCR_DMA_SELECT); 403 ark3116_write_reg(port->serial, UART_FCR, UART_FCR_DMA_SELECT);
408 404
405 /* setup termios */
406 if (tty)
407 ark3116_set_termios(tty, port, NULL);
408
409err_out: 409err_out:
410 kfree(buf); 410 kfree(buf);
411 return result; 411 return result;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 8fe034d2d3e..ff3db5d056a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -736,6 +736,7 @@ static struct usb_device_id id_table_combined [] = {
736 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) }, 736 { USB_DEVICE(TML_VID, TML_USB_SERIAL_PID) },
737 { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) }, 737 { USB_DEVICE(FTDI_VID, FTDI_ELSTER_UNICOM_PID) },
738 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) }, 738 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) },
739 { USB_DEVICE(FTDI_VID, FTDI_PROPOX_ISPCABLEIII_PID) },
739 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), 740 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID),
740 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 741 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
741 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID), 742 { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID),
@@ -2104,13 +2105,19 @@ static void ftdi_set_termios(struct tty_struct *tty,
2104 2105
2105 cflag = termios->c_cflag; 2106 cflag = termios->c_cflag;
2106 2107
2107 /* FIXME -For this cut I don't care if the line is really changing or 2108 if (old_termios->c_cflag == termios->c_cflag
2108 not - so just do the change regardless - should be able to 2109 && old_termios->c_ispeed == termios->c_ispeed
2109 compare old_termios and tty->termios */ 2110 && old_termios->c_ospeed == termios->c_ospeed)
2111 goto no_c_cflag_changes;
2112
2110 /* NOTE These routines can get interrupted by 2113 /* NOTE These routines can get interrupted by
2111 ftdi_sio_read_bulk_callback - need to examine what this means - 2114 ftdi_sio_read_bulk_callback - need to examine what this means -
2112 don't see any problems yet */ 2115 don't see any problems yet */
2113 2116
2117 if ((old_termios->c_cflag & (CSIZE|PARODD|PARENB|CMSPAR|CSTOPB)) ==
2118 (termios->c_cflag & (CSIZE|PARODD|PARENB|CMSPAR|CSTOPB)))
2119 goto no_data_parity_stop_changes;
2120
2114 /* Set number of data bits, parity, stop bits */ 2121 /* Set number of data bits, parity, stop bits */
2115 2122
2116 urb_value = 0; 2123 urb_value = 0;
@@ -2151,6 +2158,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2151 } 2158 }
2152 2159
2153 /* Now do the baudrate */ 2160 /* Now do the baudrate */
2161no_data_parity_stop_changes:
2154 if ((cflag & CBAUD) == B0) { 2162 if ((cflag & CBAUD) == B0) {
2155 /* Disable flow control */ 2163 /* Disable flow control */
2156 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 2164 if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -2178,6 +2186,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2178 2186
2179 /* Set flow control */ 2187 /* Set flow control */
2180 /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */ 2188 /* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */
2189no_c_cflag_changes:
2181 if (cflag & CRTSCTS) { 2190 if (cflag & CRTSCTS) {
2182 dbg("%s Setting to CRTSCTS flow control", __func__); 2191 dbg("%s Setting to CRTSCTS flow control", __func__);
2183 if (usb_control_msg(dev, 2192 if (usb_control_msg(dev,
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 571fa96b49c..055b64ef0bb 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -112,6 +112,7 @@
112 112
113/* Propox devices */ 113/* Propox devices */
114#define FTDI_PROPOX_JTAGCABLEII_PID 0xD738 114#define FTDI_PROPOX_JTAGCABLEII_PID 0xD738
115#define FTDI_PROPOX_ISPCABLEIII_PID 0xD739
115 116
116/* Lenz LI-USB Computer Interface. */ 117/* Lenz LI-USB Computer Interface. */
117#define FTDI_LENZ_LIUSB_PID 0xD780 118#define FTDI_LENZ_LIUSB_PID 0xD780
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 89ae1f65e1b..e3426602dc8 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -156,6 +156,7 @@ static void option_instat_callback(struct urb *urb);
156#define HUAWEI_PRODUCT_K4511 0x14CC 156#define HUAWEI_PRODUCT_K4511 0x14CC
157#define HUAWEI_PRODUCT_ETS1220 0x1803 157#define HUAWEI_PRODUCT_ETS1220 0x1803
158#define HUAWEI_PRODUCT_E353 0x1506 158#define HUAWEI_PRODUCT_E353 0x1506
159#define HUAWEI_PRODUCT_E173S 0x1C05
159 160
160#define QUANTA_VENDOR_ID 0x0408 161#define QUANTA_VENDOR_ID 0x0408
161#define QUANTA_PRODUCT_Q101 0xEA02 162#define QUANTA_PRODUCT_Q101 0xEA02
@@ -316,6 +317,9 @@ static void option_instat_callback(struct urb *urb);
316#define ZTE_PRODUCT_AC8710 0xfff1 317#define ZTE_PRODUCT_AC8710 0xfff1
317#define ZTE_PRODUCT_AC2726 0xfff5 318#define ZTE_PRODUCT_AC2726 0xfff5
318#define ZTE_PRODUCT_AC8710T 0xffff 319#define ZTE_PRODUCT_AC8710T 0xffff
320#define ZTE_PRODUCT_MC2718 0xffe8
321#define ZTE_PRODUCT_AD3812 0xffeb
322#define ZTE_PRODUCT_MC2716 0xffed
319 323
320#define BENQ_VENDOR_ID 0x04a5 324#define BENQ_VENDOR_ID 0x04a5
321#define BENQ_PRODUCT_H10 0x4068 325#define BENQ_PRODUCT_H10 0x4068
@@ -468,6 +472,10 @@ static void option_instat_callback(struct urb *urb);
468#define YUGA_PRODUCT_CLU528 0x260D 472#define YUGA_PRODUCT_CLU528 0x260D
469#define YUGA_PRODUCT_CLU526 0x260F 473#define YUGA_PRODUCT_CLU526 0x260F
470 474
475/* Viettel products */
476#define VIETTEL_VENDOR_ID 0x2262
477#define VIETTEL_PRODUCT_VT1000 0x0002
478
471/* some devices interfaces need special handling due to a number of reasons */ 479/* some devices interfaces need special handling due to a number of reasons */
472enum option_blacklist_reason { 480enum option_blacklist_reason {
473 OPTION_BLACKLIST_NONE = 0, 481 OPTION_BLACKLIST_NONE = 0,
@@ -500,6 +508,18 @@ static const struct option_blacklist_info zte_k3765_z_blacklist = {
500 .reserved = BIT(4), 508 .reserved = BIT(4),
501}; 509};
502 510
511static const struct option_blacklist_info zte_ad3812_z_blacklist = {
512 .sendsetup = BIT(0) | BIT(1) | BIT(2),
513};
514
515static const struct option_blacklist_info zte_mc2718_z_blacklist = {
516 .sendsetup = BIT(1) | BIT(2) | BIT(3) | BIT(4),
517};
518
519static const struct option_blacklist_info zte_mc2716_z_blacklist = {
520 .sendsetup = BIT(1) | BIT(2) | BIT(3),
521};
522
503static const struct option_blacklist_info huawei_cdc12_blacklist = { 523static const struct option_blacklist_info huawei_cdc12_blacklist = {
504 .reserved = BIT(1) | BIT(2), 524 .reserved = BIT(1) | BIT(2),
505}; 525};
@@ -622,6 +642,7 @@ static const struct usb_device_id option_ids[] = {
622 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) }, 642 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) },
623 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) }, 643 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) },
624 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) }, 644 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) },
645 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E173S, 0xff, 0xff, 0xff) },
625 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff), 646 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff),
626 .driver_info = (kernel_ulong_t) &huawei_cdc12_blacklist }, 647 .driver_info = (kernel_ulong_t) &huawei_cdc12_blacklist },
627 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff), 648 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff),
@@ -640,6 +661,9 @@ static const struct usb_device_id option_ids[] = {
640 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x31) }, 661 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x31) },
641 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x32) }, 662 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4511, 0xff, 0x01, 0x32) },
642 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x01) }, 663 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x01) },
664 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x02) },
665 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x03) },
666 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E353, 0xff, 0x01, 0x08) },
643 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, 667 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) },
644 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, 668 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) },
645 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, 669 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) },
@@ -726,6 +750,7 @@ static const struct usb_device_id option_ids[] = {
726 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) }, 750 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) },
727 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */ 751 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */
728 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ 752 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
753 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x9000)}, /* SIMCom SIM5218 */
729 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6280) }, /* BP3-USB & BP3-EXT HSDPA */ 754 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6280) }, /* BP3-USB & BP3-EXT HSDPA */
730 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6008) }, 755 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6008) },
731 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, 756 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
@@ -1043,6 +1068,12 @@ static const struct usb_device_id option_ids[] = {
1043 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, 1068 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
1044 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) }, 1069 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) },
1045 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) }, 1070 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) },
1071 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2718, 0xff, 0xff, 0xff),
1072 .driver_info = (kernel_ulong_t)&zte_mc2718_z_blacklist },
1073 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AD3812, 0xff, 0xff, 0xff),
1074 .driver_info = (kernel_ulong_t)&zte_ad3812_z_blacklist },
1075 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MC2716, 0xff, 0xff, 0xff),
1076 .driver_info = (kernel_ulong_t)&zte_mc2716_z_blacklist },
1046 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, 1077 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
1047 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, 1078 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
1048 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */ 1079 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */
@@ -1141,6 +1172,7 @@ static const struct usb_device_id option_ids[] = {
1141 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU516) }, 1172 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU516) },
1142 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU528) }, 1173 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU528) },
1143 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU526) }, 1174 { USB_DEVICE(YUGA_VENDOR_ID, YUGA_PRODUCT_CLU526) },
1175 { USB_DEVICE_AND_INTERFACE_INFO(VIETTEL_VENDOR_ID, VIETTEL_PRODUCT_VT1000, 0xff, 0xff, 0xff) },
1144 { } /* Terminating entry */ 1176 { } /* Terminating entry */
1145}; 1177};
1146MODULE_DEVICE_TABLE(usb, option_ids); 1178MODULE_DEVICE_TABLE(usb, option_ids);
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 9083d1e616b..fc2d66f7f4e 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -91,7 +91,6 @@ static const struct usb_device_id id_table[] = {
91 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, 91 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
92 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) }, 92 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
93 { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) }, 93 { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) },
94 { USB_DEVICE(WINCHIPHEAD_VENDOR_ID, WINCHIPHEAD_USBSER_PRODUCT_ID) },
95 { USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) }, 94 { USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) },
96 { } /* Terminating entry */ 95 { } /* Terminating entry */
97}; 96};
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 3d10d7f0207..c38b8c00c06 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -145,10 +145,6 @@
145#define ADLINK_VENDOR_ID 0x0b63 145#define ADLINK_VENDOR_ID 0x0b63
146#define ADLINK_ND6530_PRODUCT_ID 0x6530 146#define ADLINK_ND6530_PRODUCT_ID 0x6530
147 147
148/* WinChipHead USB->RS 232 adapter */
149#define WINCHIPHEAD_VENDOR_ID 0x4348
150#define WINCHIPHEAD_USBSER_PRODUCT_ID 0x5523
151
152/* SMART USB Serial Adapter */ 148/* SMART USB Serial Adapter */
153#define SMART_VENDOR_ID 0x0b8c 149#define SMART_VENDOR_ID 0x0b8c
154#define SMART_PRODUCT_ID 0x2303 150#define SMART_PRODUCT_ID 0x2303
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index b9bb24729c9..aa9367f5b42 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/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c
index 4dca3ef0668..9fbe742343c 100644
--- a/drivers/usb/storage/ene_ub6250.c
+++ b/drivers/usb/storage/ene_ub6250.c
@@ -1762,10 +1762,9 @@ static int ms_scsi_write(struct us_data *us, struct scsi_cmnd *srb)
1762 result = ene_send_scsi_cmd(us, FDIR_WRITE, scsi_sglist(srb), 1); 1762 result = ene_send_scsi_cmd(us, FDIR_WRITE, scsi_sglist(srb), 1);
1763 } else { 1763 } else {
1764 void *buf; 1764 void *buf;
1765 int offset; 1765 int offset = 0;
1766 u16 PhyBlockAddr; 1766 u16 PhyBlockAddr;
1767 u8 PageNum; 1767 u8 PageNum;
1768 u32 result;
1769 u16 len, oldphy, newphy; 1768 u16 len, oldphy, newphy;
1770 1769
1771 buf = kmalloc(blenByte, GFP_KERNEL); 1770 buf = kmalloc(blenByte, GFP_KERNEL);
diff --git a/drivers/usb/storage/option_ms.c b/drivers/usb/storage/option_ms.c
index 89460181d12..e0f76bb0591 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 fc310f75ead..82dd834709c 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
@@ -58,7 +59,9 @@
58 59
59void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us) 60void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us)
60{ 61{
61 /* Pad the SCSI command with zeros out to 12 bytes 62 /*
63 * Pad the SCSI command with zeros out to 12 bytes. If the
64 * command already is 12 bytes or longer, leave it alone.
62 * 65 *
63 * NOTE: This only works because a scsi_cmnd struct field contains 66 * NOTE: This only works because a scsi_cmnd struct field contains
64 * a unsigned char cmnd[16], so we know we have storage available 67 * a unsigned char cmnd[16], so we know we have storage available
@@ -66,9 +69,6 @@ void usb_stor_pad12_command(struct scsi_cmnd *srb, struct us_data *us)
66 for (; srb->cmd_len<12; srb->cmd_len++) 69 for (; srb->cmd_len<12; srb->cmd_len++)
67 srb->cmnd[srb->cmd_len] = 0; 70 srb->cmnd[srb->cmd_len] = 0;
68 71
69 /* set command length to 12 bytes */
70 srb->cmd_len = 12;
71
72 /* send the command to the transport layer */ 72 /* send the command to the transport layer */
73 usb_stor_invoke_transport(srb, us); 73 usb_stor_invoke_transport(srb, us);
74} 74}
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index 1deca07c826..37539c89e3b 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 ff32390d61e..0e5c91c6187 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 23f0dd9c36d..1d10d5b8204 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/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 3041a974faf..24caba79d72 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1854,6 +1854,13 @@ UNUSUAL_DEV( 0x1370, 0x6828, 0x0110, 0x0110,
1854 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 1854 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1855 US_FL_IGNORE_RESIDUE ), 1855 US_FL_IGNORE_RESIDUE ),
1856 1856
1857/* Reported by Qinglin Ye <yestyle@gmail.com> */
1858UNUSUAL_DEV( 0x13fe, 0x3600, 0x0100, 0x0100,
1859 "Kingston",
1860 "DT 101 G2",
1861 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
1862 US_FL_BULK_IGNORE_TAG ),
1863
1857/* Reported by Francesco Foresti <frafore@tiscali.it> */ 1864/* Reported by Francesco Foresti <frafore@tiscali.it> */
1858UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201, 1865UNUSUAL_DEV( 0x14cd, 0x6600, 0x0201, 0x0201,
1859 "Super Top", 1866 "Super Top",
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index 7ec24e46b34..231009af65a 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 0a57ff0a0b0..b8c72583c04 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 39de3900ad2..59ff254dfb6 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 b60799b811c..371f61733f0 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 0d1863c9edd..9e4a9246168 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 2acc7f504c5..f0d546c5a08 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 419334568be..57c01ab09ad 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 a2eaa3c33b0..de81ebf5178 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 da7b1d08003..b08d1c2ee3f 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 30acec74042..902b0f2f961 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 90113bafefc..5241f1d0ef7 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 b4395f41a00..4d688c75080 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 697e56a5bcd..a269937be1b 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 99a19c19909..8ee7d90a8c6 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 f0d55495f5e..d58dfecf9a7 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 3de630b0f69..703228559e8 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 78c892233cf..0b0d8bce842 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 367aa12786b..cbb6a5e703d 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 5fad4e791b3..82a84d53120 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 b2948ec5787..4613c13cd85 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 367b5eb85d6..26d0ae1816b 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 b221142446a..f48093e649e 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 8165c5577d7..d83e967e4e1 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 4ac48d9ee66..63409c122ae 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 c04b94da81f..1105fa1ed7f 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 d1aee730d7d..dfb763e9147 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 9f0a491e2a0..7838a23fbdd 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 62043f12a5a..d68f14bbb68 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 b0582917f0c..c74a6f4baa1 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 3543f1b7d5f..4f5d1c4cb6a 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 5934655eb1f..da9a5ce0ccb 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 5d3cf33953a..4ec78cfe26e 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 07e8e273ced..7bbc802560e 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 694e5aab0d6..e132157d854 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 d4c6eb248ff..fbe9e9316f3 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 cb09aa1fa13..2c76fdf23f2 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 e02764319ff..f56699d8122 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/da8xx-fb.c b/drivers/video/da8xx-fb.c
index 55f91d9ab00..29577bf1f55 100644
--- a/drivers/video/da8xx-fb.c
+++ b/drivers/video/da8xx-fb.c
@@ -116,6 +116,7 @@
116/* Clock registers available only on Version 2 */ 116/* Clock registers available only on Version 2 */
117#define LCD_CLK_ENABLE_REG 0x6c 117#define LCD_CLK_ENABLE_REG 0x6c
118#define LCD_CLK_RESET_REG 0x70 118#define LCD_CLK_RESET_REG 0x70
119#define LCD_CLK_MAIN_RESET BIT(3)
119 120
120#define LCD_NUM_BUFFERS 2 121#define LCD_NUM_BUFFERS 2
121 122
@@ -244,6 +245,10 @@ static inline void lcd_enable_raster(void)
244{ 245{
245 u32 reg; 246 u32 reg;
246 247
248 /* Bring LCDC out of reset */
249 if (lcd_revision == LCD_VERSION_2)
250 lcdc_write(0, LCD_CLK_RESET_REG);
251
247 reg = lcdc_read(LCD_RASTER_CTRL_REG); 252 reg = lcdc_read(LCD_RASTER_CTRL_REG);
248 if (!(reg & LCD_RASTER_ENABLE)) 253 if (!(reg & LCD_RASTER_ENABLE))
249 lcdc_write(reg | LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG); 254 lcdc_write(reg | LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG);
@@ -257,6 +262,10 @@ static inline void lcd_disable_raster(void)
257 reg = lcdc_read(LCD_RASTER_CTRL_REG); 262 reg = lcdc_read(LCD_RASTER_CTRL_REG);
258 if (reg & LCD_RASTER_ENABLE) 263 if (reg & LCD_RASTER_ENABLE)
259 lcdc_write(reg & ~LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG); 264 lcdc_write(reg & ~LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG);
265
266 if (lcd_revision == LCD_VERSION_2)
267 /* Write 1 to reset LCDC */
268 lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG);
260} 269}
261 270
262static void lcd_blit(int load_mode, struct da8xx_fb_par *par) 271static void lcd_blit(int load_mode, struct da8xx_fb_par *par)
@@ -584,8 +593,12 @@ static void lcd_reset(struct da8xx_fb_par *par)
584 lcdc_write(0, LCD_DMA_CTRL_REG); 593 lcdc_write(0, LCD_DMA_CTRL_REG);
585 lcdc_write(0, LCD_RASTER_CTRL_REG); 594 lcdc_write(0, LCD_RASTER_CTRL_REG);
586 595
587 if (lcd_revision == LCD_VERSION_2) 596 if (lcd_revision == LCD_VERSION_2) {
588 lcdc_write(0, LCD_INT_ENABLE_SET_REG); 597 lcdc_write(0, LCD_INT_ENABLE_SET_REG);
598 /* Write 1 to reset */
599 lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG);
600 lcdc_write(0, LCD_CLK_RESET_REG);
601 }
589} 602}
590 603
591static void lcd_calc_clk_divider(struct da8xx_fb_par *par) 604static void lcd_calc_clk_divider(struct da8xx_fb_par *par)
diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c
index 40e5f17d1e4..2e830ec52a5 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 4a874c8d039..2b106f046fd 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 8c020389e4f..74c2da52888 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 934081d2b7a..273769bb8de 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 c16ff1d62e9..11a7a333701 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 b9344772bac..cb2ddf164c9 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/dispc.c b/drivers/video/omap/dispc.c
index 0ccd7adf47b..6f61e781f15 100644
--- a/drivers/video/omap/dispc.c
+++ b/drivers/video/omap/dispc.c
@@ -19,6 +19,7 @@
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */ 20 */
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h>
22#include <linux/dma-mapping.h> 23#include <linux/dma-mapping.h>
23#include <linux/mm.h> 24#include <linux/mm.h>
24#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
diff --git a/drivers/video/omap/lcd_mipid.c b/drivers/video/omap/lcd_mipid.c
index 90e3bdd1b7a..eb381db7fe5 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 b3ddd743d8a..25d8e510319 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 6892cfd2e3b..5c81533eaca 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>
@@ -1719,12 +1720,11 @@ static int dispc_ovl_calc_scaling(enum omap_plane plane,
1719 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE); 1720 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
1720 unsigned long fclk = 0; 1721 unsigned long fclk = 0;
1721 1722
1722 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) { 1723 if (width == out_width && height == out_height)
1723 if (width != out_width || height != out_height) 1724 return 0;
1724 return -EINVAL; 1725
1725 else 1726 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
1726 return 0; 1727 return -EINVAL;
1727 }
1728 1728
1729 if (out_width < width / maxdownscale || 1729 if (out_width < width / maxdownscale ||
1730 out_width > width * 8) 1730 out_width > width * 8)
diff --git a/drivers/video/omap2/dss/dpi.c b/drivers/video/omap2/dss/dpi.c
index 483888a85cf..976ac23dcd0 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 43c04a9889c..5abf8e7e745 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 3e09726d32c..17033457ee8 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/hdmi.c b/drivers/video/omap2/dss/hdmi.c
index 3262f0f1fa3..c56378c555b 100644
--- a/drivers/video/omap2/dss/hdmi.c
+++ b/drivers/video/omap2/dss/hdmi.c
@@ -269,7 +269,7 @@ static void update_hdmi_timings(struct hdmi_config *cfg,
269unsigned long hdmi_get_pixel_clock(void) 269unsigned long hdmi_get_pixel_clock(void)
270{ 270{
271 /* HDMI Pixel Clock in Mhz */ 271 /* HDMI Pixel Clock in Mhz */
272 return hdmi.ip_data.cfg.timings.timings.pixel_clock * 10000; 272 return hdmi.ip_data.cfg.timings.timings.pixel_clock * 1000;
273} 273}
274 274
275static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy, 275static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
diff --git a/drivers/video/omap2/dss/rfbi.c b/drivers/video/omap2/dss/rfbi.c
index 1bd3703e42f..1130c608a56 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 695dc04cabb..40305ad7841 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 6b1ac23dbbd..df7bcce5b10 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 bbcc055d3bb..bfefa6234cf 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 24640c8458a..72ee96bc6b3 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 3a41c013d03..facffc25497 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/share.h b/drivers/video/via/share.h
index 69d882cbe70..c01c1c16272 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -559,8 +559,8 @@
559#define M1200X720_R60_VSP POSITIVE 559#define M1200X720_R60_VSP POSITIVE
560 560
561/* 1200x900@60 Sync Polarity (DCON) */ 561/* 1200x900@60 Sync Polarity (DCON) */
562#define M1200X900_R60_HSP NEGATIVE 562#define M1200X900_R60_HSP POSITIVE
563#define M1200X900_R60_VSP NEGATIVE 563#define M1200X900_R60_VSP POSITIVE
564 564
565/* 1280x600@60 Sync Polarity (GTF Mode) */ 565/* 1280x600@60 Sync Polarity (GTF Mode) */
566#define M1280x600_R60_HSP NEGATIVE 566#define M1280x600_R60_HSP NEGATIVE
diff --git a/drivers/video/via/via-gpio.c b/drivers/video/via/via-gpio.c
index ab5341814c7..d69cfef7c33 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 c8be8af0cc6..2375e5bbf57 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 3d9162151fd..4939e0ccc4e 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 816ed08e7cf..1a61939b85f 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -37,7 +37,7 @@ config VIRTIO_BALLOON
37 37
38 config VIRTIO_MMIO 38 config VIRTIO_MMIO
39 tristate "Platform bus driver for memory mapped virtio devices (EXPERIMENTAL)" 39 tristate "Platform bus driver for memory mapped virtio devices (EXPERIMENTAL)"
40 depends on EXPERIMENTAL 40 depends on HAS_IOMEM && EXPERIMENTAL
41 select VIRTIO 41 select VIRTIO
42 select VIRTIO_RING 42 select VIRTIO_RING
43 ---help--- 43 ---help---
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index efb35aa8309..984c501c258 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 e058ace2a4a..94fd738a774 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
index acc5e43c373..7317dc2ec42 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -118,7 +118,7 @@ static void vm_finalize_features(struct virtio_device *vdev)
118 vring_transport_features(vdev); 118 vring_transport_features(vdev);
119 119
120 for (i = 0; i < ARRAY_SIZE(vdev->features); i++) { 120 for (i = 0; i < ARRAY_SIZE(vdev->features); i++) {
121 writel(i, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SET); 121 writel(i, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
122 writel(vdev->features[i], 122 writel(vdev->features[i],
123 vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES); 123 vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
124 } 124 }
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 79a31e5b4b6..03d1984bd36 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -169,11 +169,29 @@ static void vp_set_status(struct virtio_device *vdev, u8 status)
169 iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS); 169 iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
170} 170}
171 171
172/* wait for pending irq handlers */
173static void vp_synchronize_vectors(struct virtio_device *vdev)
174{
175 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
176 int i;
177
178 if (vp_dev->intx_enabled)
179 synchronize_irq(vp_dev->pci_dev->irq);
180
181 for (i = 0; i < vp_dev->msix_vectors; ++i)
182 synchronize_irq(vp_dev->msix_entries[i].vector);
183}
184
172static void vp_reset(struct virtio_device *vdev) 185static void vp_reset(struct virtio_device *vdev)
173{ 186{
174 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 187 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
175 /* 0 status means a reset. */ 188 /* 0 status means a reset. */
176 iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS); 189 iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
190 /* Flush out the status write, and flush in device writes,
191 * including MSi-X interrupts, if any. */
192 ioread8(vp_dev->ioaddr + VIRTIO_PCI_STATUS);
193 /* Flush pending VQ/configuration callbacks. */
194 vp_synchronize_vectors(vdev);
177} 195}
178 196
179/* the notify function used when creating a virt queue */ 197/* the notify function used when creating a virt queue */
@@ -594,11 +612,11 @@ static struct virtio_config_ops virtio_pci_config_ops = {
594 612
595static void virtio_pci_release_dev(struct device *_d) 613static void virtio_pci_release_dev(struct device *_d)
596{ 614{
597 struct virtio_device *dev = container_of(_d, struct virtio_device, 615 /*
598 dev); 616 * No need for a release method as we allocate/free
599 struct virtio_pci_device *vp_dev = to_vp_device(dev); 617 * all devices together with the pci devices.
600 618 * Provide an empty one to avoid getting a warning from core.
601 kfree(vp_dev); 619 */
602} 620}
603 621
604/* the PCI probing function */ 622/* the PCI probing function */
@@ -686,6 +704,7 @@ static void __devexit virtio_pci_remove(struct pci_dev *pci_dev)
686 pci_iounmap(pci_dev, vp_dev->ioaddr); 704 pci_iounmap(pci_dev, vp_dev->ioaddr);
687 pci_release_regions(pci_dev); 705 pci_release_regions(pci_dev);
688 pci_disable_device(pci_dev); 706 pci_disable_device(pci_dev);
707 kfree(vp_dev);
689} 708}
690 709
691#ifdef CONFIG_PM 710#ifdef CONFIG_PM
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 4acf88884f9..c7a2c208f6e 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/w1_family.c b/drivers/w1/w1_family.c
index 63359797c8b..e9309778ee7 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 f79e62e54e8..68288355727 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"
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 64c6752ea2c..79fd606b7cd 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.
@@ -312,13 +314,6 @@ config NUC900_WATCHDOG
312 To compile this driver as a module, choose M here: the 314 To compile this driver as a module, choose M here: the
313 module will be called nuc900_wdt. 315 module will be called nuc900_wdt.
314 316
315config ADX_WATCHDOG
316 tristate "Avionic Design Xanthos watchdog"
317 depends on ARCH_PXA_ADX
318 help
319 Say Y here if you want support for the watchdog timer on Avionic
320 Design Xanthos boards.
321
322config TS72XX_WATCHDOG 317config TS72XX_WATCHDOG
323 tristate "TS-72XX SBC Watchdog" 318 tristate "TS-72XX SBC Watchdog"
324 depends on MACH_TS72XX 319 depends on MACH_TS72XX
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 55bd5740e91..fe893e91935 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -51,7 +51,6 @@ obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
51obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o 51obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
52obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o 52obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o
53obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o 53obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
54obj-$(CONFIG_ADX_WATCHDOG) += adx_wdt.o
55obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o 54obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o
56obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o 55obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
57 56
diff --git a/drivers/watchdog/adx_wdt.c b/drivers/watchdog/adx_wdt.c
deleted file mode 100644
index af6e6b16475..00000000000
--- a/drivers/watchdog/adx_wdt.c
+++ /dev/null
@@ -1,355 +0,0 @@
1/*
2 * Copyright (C) 2008-2009 Avionic Design GmbH
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/fs.h>
10#include <linux/gfp.h>
11#include <linux/io.h>
12#include <linux/miscdevice.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/types.h>
16#include <linux/uaccess.h>
17#include <linux/watchdog.h>
18
19#define WATCHDOG_NAME "adx-wdt"
20
21/* register offsets */
22#define ADX_WDT_CONTROL 0x00
23#define ADX_WDT_CONTROL_ENABLE (1 << 0)
24#define ADX_WDT_CONTROL_nRESET (1 << 1)
25#define ADX_WDT_TIMEOUT 0x08
26
27static struct platform_device *adx_wdt_dev;
28static unsigned long driver_open;
29
30#define WDT_STATE_STOP 0
31#define WDT_STATE_START 1
32
33struct adx_wdt {
34 void __iomem *base;
35 unsigned long timeout;
36 unsigned int state;
37 unsigned int wake;
38 spinlock_t lock;
39};
40
41static const struct watchdog_info adx_wdt_info = {
42 .identity = "Avionic Design Xanthos Watchdog",
43 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
44};
45
46static void adx_wdt_start_locked(struct adx_wdt *wdt)
47{
48 u32 ctrl;
49
50 ctrl = readl(wdt->base + ADX_WDT_CONTROL);
51 ctrl |= ADX_WDT_CONTROL_ENABLE;
52 writel(ctrl, wdt->base + ADX_WDT_CONTROL);
53 wdt->state = WDT_STATE_START;
54}
55
56static void adx_wdt_start(struct adx_wdt *wdt)
57{
58 unsigned long flags;
59
60 spin_lock_irqsave(&wdt->lock, flags);
61 adx_wdt_start_locked(wdt);
62 spin_unlock_irqrestore(&wdt->lock, flags);
63}
64
65static void adx_wdt_stop_locked(struct adx_wdt *wdt)
66{
67 u32 ctrl;
68
69 ctrl = readl(wdt->base + ADX_WDT_CONTROL);
70 ctrl &= ~ADX_WDT_CONTROL_ENABLE;
71 writel(ctrl, wdt->base + ADX_WDT_CONTROL);
72 wdt->state = WDT_STATE_STOP;
73}
74
75static void adx_wdt_stop(struct adx_wdt *wdt)
76{
77 unsigned long flags;
78
79 spin_lock_irqsave(&wdt->lock, flags);
80 adx_wdt_stop_locked(wdt);
81 spin_unlock_irqrestore(&wdt->lock, flags);
82}
83
84static void adx_wdt_set_timeout(struct adx_wdt *wdt, unsigned long seconds)
85{
86 unsigned long timeout = seconds * 1000;
87 unsigned long flags;
88 unsigned int state;
89
90 spin_lock_irqsave(&wdt->lock, flags);
91 state = wdt->state;
92 adx_wdt_stop_locked(wdt);
93 writel(timeout, wdt->base + ADX_WDT_TIMEOUT);
94
95 if (state == WDT_STATE_START)
96 adx_wdt_start_locked(wdt);
97
98 wdt->timeout = timeout;
99 spin_unlock_irqrestore(&wdt->lock, flags);
100}
101
102static void adx_wdt_get_timeout(struct adx_wdt *wdt, unsigned long *seconds)
103{
104 *seconds = wdt->timeout / 1000;
105}
106
107static void adx_wdt_keepalive(struct adx_wdt *wdt)
108{
109 unsigned long flags;
110
111 spin_lock_irqsave(&wdt->lock, flags);
112 writel(wdt->timeout, wdt->base + ADX_WDT_TIMEOUT);
113 spin_unlock_irqrestore(&wdt->lock, flags);
114}
115
116static int adx_wdt_open(struct inode *inode, struct file *file)
117{
118 struct adx_wdt *wdt = platform_get_drvdata(adx_wdt_dev);
119
120 if (test_and_set_bit(0, &driver_open))
121 return -EBUSY;
122
123 file->private_data = wdt;
124 adx_wdt_set_timeout(wdt, 30);
125 adx_wdt_start(wdt);
126
127 return nonseekable_open(inode, file);
128}
129
130static int adx_wdt_release(struct inode *inode, struct file *file)
131{
132 struct adx_wdt *wdt = file->private_data;
133
134 adx_wdt_stop(wdt);
135 clear_bit(0, &driver_open);
136
137 return 0;
138}
139
140static long adx_wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
141{
142 struct adx_wdt *wdt = file->private_data;
143 void __user *argp = (void __user *)arg;
144 unsigned long __user *p = argp;
145 unsigned long seconds = 0;
146 unsigned int options;
147 long ret = -EINVAL;
148
149 switch (cmd) {
150 case WDIOC_GETSUPPORT:
151 if (copy_to_user(argp, &adx_wdt_info, sizeof(adx_wdt_info)))
152 return -EFAULT;
153 else
154 return 0;
155
156 case WDIOC_GETSTATUS:
157 case WDIOC_GETBOOTSTATUS:
158 return put_user(0, p);
159
160 case WDIOC_KEEPALIVE:
161 adx_wdt_keepalive(wdt);
162 return 0;
163
164 case WDIOC_SETTIMEOUT:
165 if (get_user(seconds, p))
166 return -EFAULT;
167
168 adx_wdt_set_timeout(wdt, seconds);
169
170 /* fallthrough */
171 case WDIOC_GETTIMEOUT:
172 adx_wdt_get_timeout(wdt, &seconds);
173 return put_user(seconds, p);
174
175 case WDIOC_SETOPTIONS:
176 if (copy_from_user(&options, argp, sizeof(options)))
177 return -EFAULT;
178
179 if (options & WDIOS_DISABLECARD) {
180 adx_wdt_stop(wdt);
181 ret = 0;
182 }
183
184 if (options & WDIOS_ENABLECARD) {
185 adx_wdt_start(wdt);
186 ret = 0;
187 }
188
189 return ret;
190
191 default:
192 break;
193 }
194
195 return -ENOTTY;
196}
197
198static ssize_t adx_wdt_write(struct file *file, const char __user *data,
199 size_t len, loff_t *ppos)
200{
201 struct adx_wdt *wdt = file->private_data;
202
203 if (len)
204 adx_wdt_keepalive(wdt);
205
206 return len;
207}
208
209static const struct file_operations adx_wdt_fops = {
210 .owner = THIS_MODULE,
211 .llseek = no_llseek,
212 .open = adx_wdt_open,
213 .release = adx_wdt_release,
214 .unlocked_ioctl = adx_wdt_ioctl,
215 .write = adx_wdt_write,
216};
217
218static struct miscdevice adx_wdt_miscdev = {
219 .minor = WATCHDOG_MINOR,
220 .name = "watchdog",
221 .fops = &adx_wdt_fops,
222};
223
224static int __devinit adx_wdt_probe(struct platform_device *pdev)
225{
226 struct resource *res;
227 struct adx_wdt *wdt;
228 int ret = 0;
229 u32 ctrl;
230
231 wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
232 if (!wdt) {
233 dev_err(&pdev->dev, "cannot allocate WDT structure\n");
234 return -ENOMEM;
235 }
236
237 spin_lock_init(&wdt->lock);
238
239 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
240 if (!res) {
241 dev_err(&pdev->dev, "cannot obtain I/O memory region\n");
242 return -ENXIO;
243 }
244
245 res = devm_request_mem_region(&pdev->dev, res->start,
246 resource_size(res), res->name);
247 if (!res) {
248 dev_err(&pdev->dev, "cannot request I/O memory region\n");
249 return -ENXIO;
250 }
251
252 wdt->base = devm_ioremap_nocache(&pdev->dev, res->start,
253 resource_size(res));
254 if (!wdt->base) {
255 dev_err(&pdev->dev, "cannot remap I/O memory region\n");
256 return -ENXIO;
257 }
258
259 /* disable watchdog and reboot on timeout */
260 ctrl = readl(wdt->base + ADX_WDT_CONTROL);
261 ctrl &= ~ADX_WDT_CONTROL_ENABLE;
262 ctrl &= ~ADX_WDT_CONTROL_nRESET;
263 writel(ctrl, wdt->base + ADX_WDT_CONTROL);
264
265 platform_set_drvdata(pdev, wdt);
266 adx_wdt_dev = pdev;
267
268 ret = misc_register(&adx_wdt_miscdev);
269 if (ret) {
270 dev_err(&pdev->dev, "cannot register miscdev on minor %d "
271 "(err=%d)\n", WATCHDOG_MINOR, ret);
272 return ret;
273 }
274
275 return 0;
276}
277
278static int __devexit adx_wdt_remove(struct platform_device *pdev)
279{
280 struct adx_wdt *wdt = platform_get_drvdata(pdev);
281
282 misc_deregister(&adx_wdt_miscdev);
283 adx_wdt_stop(wdt);
284 platform_set_drvdata(pdev, NULL);
285
286 return 0;
287}
288
289static void adx_wdt_shutdown(struct platform_device *pdev)
290{
291 struct adx_wdt *wdt = platform_get_drvdata(pdev);
292 adx_wdt_stop(wdt);
293}
294
295#ifdef CONFIG_PM
296static int adx_wdt_suspend(struct device *dev)
297{
298 struct platform_device *pdev = to_platform_device(dev);
299 struct adx_wdt *wdt = platform_get_drvdata(pdev);
300
301 wdt->wake = (wdt->state == WDT_STATE_START) ? 1 : 0;
302 adx_wdt_stop(wdt);
303
304 return 0;
305}
306
307static int adx_wdt_resume(struct device *dev)
308{
309 struct platform_device *pdev = to_platform_device(dev);
310 struct adx_wdt *wdt = platform_get_drvdata(pdev);
311
312 if (wdt->wake)
313 adx_wdt_start(wdt);
314
315 return 0;
316}
317
318static const struct dev_pm_ops adx_wdt_pm_ops = {
319 .suspend = adx_wdt_suspend,
320 .resume = adx_wdt_resume,
321};
322
323# define ADX_WDT_PM_OPS (&adx_wdt_pm_ops)
324#else
325# define ADX_WDT_PM_OPS NULL
326#endif
327
328static struct platform_driver adx_wdt_driver = {
329 .probe = adx_wdt_probe,
330 .remove = __devexit_p(adx_wdt_remove),
331 .shutdown = adx_wdt_shutdown,
332 .driver = {
333 .name = WATCHDOG_NAME,
334 .owner = THIS_MODULE,
335 .pm = ADX_WDT_PM_OPS,
336 },
337};
338
339static int __init adx_wdt_init(void)
340{
341 return platform_driver_register(&adx_wdt_driver);
342}
343
344static void __exit adx_wdt_exit(void)
345{
346 platform_driver_unregister(&adx_wdt_driver);
347}
348
349module_init(adx_wdt_init);
350module_exit(adx_wdt_exit);
351
352MODULE_DESCRIPTION("Avionic Design Xanthos Watchdog Driver");
353MODULE_LICENSE("GPL v2");
354MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
355MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/coh901327_wdt.c b/drivers/watchdog/coh901327_wdt.c
index 9291506b8b2..03f449a430d 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 f1d1da662fb..41018d429ab 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 751a591684d..ba6ad662635 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 4dc31024d26..82ccd36e2c9 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 945ee830030..7c0d8630e64 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 30da88f47cd..a79e3840782 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 */
@@ -503,8 +401,8 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
503 401
504 dev_info(dev, "watchdog %sactive, reset %sabled, irq %sabled\n", 402 dev_info(dev, "watchdog %sactive, reset %sabled, irq %sabled\n",
505 (wtcon & S3C2410_WTCON_ENABLE) ? "" : "in", 403 (wtcon & S3C2410_WTCON_ENABLE) ? "" : "in",
506 (wtcon & S3C2410_WTCON_RSTEN) ? "" : "dis", 404 (wtcon & S3C2410_WTCON_RSTEN) ? "en" : "dis",
507 (wtcon & S3C2410_WTCON_INTEN) ? "" : "en"); 405 (wtcon & S3C2410_WTCON_INTEN) ? "en" : "dis");
508 406
509 return 0; 407 return 0;
510 408
@@ -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 f31493e65b3..b01a30e5a66 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 52b63f2f0da..b2840409ebc 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 b3421fd2cda..ac2346a452e 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 e5c91d4404e..dd5d6754875 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 bb03e151a1d..d2ef002be96 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 172dad6c769..e0fc3baa919 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 871caea4e1c..e789a47db41 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 return -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 5876e1ae6c2..31ab82fda38 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>
@@ -93,8 +94,8 @@ static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
93#define inc_totalhigh_pages() (totalhigh_pages++) 94#define inc_totalhigh_pages() (totalhigh_pages++)
94#define dec_totalhigh_pages() (totalhigh_pages--) 95#define dec_totalhigh_pages() (totalhigh_pages--)
95#else 96#else
96#define inc_totalhigh_pages() do {} while(0) 97#define inc_totalhigh_pages() do {} while (0)
97#define dec_totalhigh_pages() do {} while(0) 98#define dec_totalhigh_pages() do {} while (0)
98#endif 99#endif
99 100
100/* List of ballooned pages, threaded through the mem_map array. */ 101/* List of ballooned pages, threaded through the mem_map array. */
@@ -154,8 +155,7 @@ static struct page *balloon_retrieve(bool prefer_highmem)
154 if (PageHighMem(page)) { 155 if (PageHighMem(page)) {
155 balloon_stats.balloon_high--; 156 balloon_stats.balloon_high--;
156 inc_totalhigh_pages(); 157 inc_totalhigh_pages();
157 } 158 } else
158 else
159 balloon_stats.balloon_low--; 159 balloon_stats.balloon_low--;
160 160
161 totalram_pages++; 161 totalram_pages++;
@@ -422,7 +422,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
422 (unsigned long)__va(pfn << PAGE_SHIFT), 422 (unsigned long)__va(pfn << PAGE_SHIFT),
423 __pte_ma(0), 0); 423 __pte_ma(0), 0);
424 BUG_ON(ret); 424 BUG_ON(ret);
425 } 425 }
426 426
427 } 427 }
428 428
@@ -501,17 +501,17 @@ EXPORT_SYMBOL_GPL(balloon_set_new_target);
501 * alloc_xenballooned_pages - get pages that have been ballooned out 501 * alloc_xenballooned_pages - get pages that have been ballooned out
502 * @nr_pages: Number of pages to get 502 * @nr_pages: Number of pages to get
503 * @pages: pages returned 503 * @pages: pages returned
504 * @highmem: highmem or lowmem pages 504 * @highmem: allow highmem pages
505 * @return 0 on success, error otherwise 505 * @return 0 on success, error otherwise
506 */ 506 */
507int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem) 507int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem)
508{ 508{
509 int pgno = 0; 509 int pgno = 0;
510 struct page* page; 510 struct page *page;
511 mutex_lock(&balloon_mutex); 511 mutex_lock(&balloon_mutex);
512 while (pgno < nr_pages) { 512 while (pgno < nr_pages) {
513 page = balloon_retrieve(highmem); 513 page = balloon_retrieve(highmem);
514 if (page && PageHighMem(page) == highmem) { 514 if (page && (highmem || !PageHighMem(page))) {
515 pages[pgno++] = page; 515 pages[pgno++] = page;
516 } else { 516 } else {
517 enum bp_state st; 517 enum bp_state st;
@@ -540,7 +540,7 @@ EXPORT_SYMBOL(alloc_xenballooned_pages);
540 * @nr_pages: Number of pages 540 * @nr_pages: Number of pages
541 * @pages: pages to return 541 * @pages: pages to return
542 */ 542 */
543void free_xenballooned_pages(int nr_pages, struct page** pages) 543void free_xenballooned_pages(int nr_pages, struct page **pages)
544{ 544{
545 int i; 545 int i;
546 546
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 0eb8a57cc80..6e075cdd0c6 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -85,8 +85,7 @@ enum xen_irq_type {
85 * IPI - IPI vector 85 * IPI - IPI vector
86 * EVTCHN - 86 * EVTCHN -
87 */ 87 */
88struct irq_info 88struct irq_info {
89{
90 struct list_head list; 89 struct list_head list;
91 enum xen_irq_type type; /* type */ 90 enum xen_irq_type type; /* type */
92 unsigned irq; 91 unsigned irq;
@@ -282,9 +281,9 @@ static inline unsigned long active_evtchns(unsigned int cpu,
282 struct shared_info *sh, 281 struct shared_info *sh,
283 unsigned int idx) 282 unsigned int idx)
284{ 283{
285 return (sh->evtchn_pending[idx] & 284 return sh->evtchn_pending[idx] &
286 per_cpu(cpu_evtchn_mask, cpu)[idx] & 285 per_cpu(cpu_evtchn_mask, cpu)[idx] &
287 ~sh->evtchn_mask[idx]); 286 ~sh->evtchn_mask[idx];
288} 287}
289 288
290static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu) 289static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
@@ -1180,7 +1179,7 @@ static void __xen_evtchn_do_upcall(void)
1180 int cpu = get_cpu(); 1179 int cpu = get_cpu();
1181 struct shared_info *s = HYPERVISOR_shared_info; 1180 struct shared_info *s = HYPERVISOR_shared_info;
1182 struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu); 1181 struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
1183 unsigned count; 1182 unsigned count;
1184 1183
1185 do { 1184 do {
1186 unsigned long pending_words; 1185 unsigned long pending_words;
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c
index f6832f46aea..e1c4c6e5b46 100644
--- a/drivers/xen/gntalloc.c
+++ b/drivers/xen/gntalloc.c
@@ -135,7 +135,7 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
135 /* Grant foreign access to the page. */ 135 /* Grant foreign access to the page. */
136 gref->gref_id = gnttab_grant_foreign_access(op->domid, 136 gref->gref_id = gnttab_grant_foreign_access(op->domid,
137 pfn_to_mfn(page_to_pfn(gref->page)), readonly); 137 pfn_to_mfn(page_to_pfn(gref->page)), readonly);
138 if (gref->gref_id < 0) { 138 if ((int)gref->gref_id < 0) {
139 rc = gref->gref_id; 139 rc = gref->gref_id;
140 goto undo; 140 goto undo;
141 } 141 }
@@ -280,7 +280,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
280 goto out; 280 goto out;
281 } 281 }
282 282
283 gref_ids = kzalloc(sizeof(gref_ids[0]) * op.count, GFP_TEMPORARY); 283 gref_ids = kcalloc(op.count, sizeof(gref_ids[0]), GFP_TEMPORARY);
284 if (!gref_ids) { 284 if (!gref_ids) {
285 rc = -ENOMEM; 285 rc = -ENOMEM;
286 goto out; 286 goto out;
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 880798aae2f..afca14d9042 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -114,11 +114,11 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
114 if (NULL == add) 114 if (NULL == add)
115 return NULL; 115 return NULL;
116 116
117 add->grants = kzalloc(sizeof(add->grants[0]) * count, GFP_KERNEL); 117 add->grants = kcalloc(count, sizeof(add->grants[0]), GFP_KERNEL);
118 add->map_ops = kzalloc(sizeof(add->map_ops[0]) * count, GFP_KERNEL); 118 add->map_ops = kcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL);
119 add->unmap_ops = kzalloc(sizeof(add->unmap_ops[0]) * count, GFP_KERNEL); 119 add->unmap_ops = kcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL);
120 add->kmap_ops = kzalloc(sizeof(add->kmap_ops[0]) * count, GFP_KERNEL); 120 add->kmap_ops = kcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL);
121 add->pages = kzalloc(sizeof(add->pages[0]) * count, GFP_KERNEL); 121 add->pages = kcalloc(count, sizeof(add->pages[0]), GFP_KERNEL);
122 if (NULL == add->grants || 122 if (NULL == add->grants ||
123 NULL == add->map_ops || 123 NULL == add->map_ops ||
124 NULL == add->unmap_ops || 124 NULL == add->unmap_ops ||
@@ -193,9 +193,8 @@ static void gntdev_put_map(struct grant_map *map)
193 193
194 atomic_sub(map->count, &pages_mapped); 194 atomic_sub(map->count, &pages_mapped);
195 195
196 if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) { 196 if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT)
197 notify_remote_via_evtchn(map->notify.event); 197 notify_remote_via_evtchn(map->notify.event);
198 }
199 198
200 if (map->pages) { 199 if (map->pages) {
201 if (!use_ptemod) 200 if (!use_ptemod)
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index 8c71ab80175..bf1c094f4eb 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -193,7 +193,7 @@ int gnttab_query_foreign_access(grant_ref_t ref)
193 193
194 nflags = shared[ref].flags; 194 nflags = shared[ref].flags;
195 195
196 return (nflags & (GTF_reading|GTF_writing)); 196 return nflags & (GTF_reading|GTF_writing);
197} 197}
198EXPORT_SYMBOL_GPL(gnttab_query_foreign_access); 198EXPORT_SYMBOL_GPL(gnttab_query_foreign_access);
199 199
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index 0b5366b5be2..ce4fa083186 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/pci.c b/drivers/xen/pci.c
index 66057075d6e..b84bf0b6cc3 100644
--- a/drivers/xen/pci.c
+++ b/drivers/xen/pci.c
@@ -116,7 +116,7 @@ static int xen_add_device(struct device *dev)
116 &manage_pci_ext); 116 &manage_pci_ext);
117 } else { 117 } else {
118 struct physdev_manage_pci manage_pci = { 118 struct physdev_manage_pci manage_pci = {
119 .bus = pci_dev->bus->number, 119 .bus = pci_dev->bus->number,
120 .devfn = pci_dev->devfn, 120 .devfn = pci_dev->devfn,
121 }; 121 };
122 122
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c984768d98c..8e964b91c44 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-balloon.c b/drivers/xen/xen-balloon.c
index 5c9dc43c1e9..9cc2259c999 100644
--- a/drivers/xen/xen-balloon.c
+++ b/drivers/xen/xen-balloon.c
@@ -50,11 +50,6 @@ static struct sys_device balloon_sysdev;
50 50
51static int register_balloon(struct sys_device *sysdev); 51static int register_balloon(struct sys_device *sysdev);
52 52
53static struct xenbus_watch target_watch =
54{
55 .node = "memory/target"
56};
57
58/* React to a change in the target key */ 53/* React to a change in the target key */
59static void watch_target(struct xenbus_watch *watch, 54static void watch_target(struct xenbus_watch *watch,
60 const char **vec, unsigned int len) 55 const char **vec, unsigned int len)
@@ -73,6 +68,11 @@ static void watch_target(struct xenbus_watch *watch,
73 */ 68 */
74 balloon_set_new_target(new_target >> (PAGE_SHIFT - 10)); 69 balloon_set_new_target(new_target >> (PAGE_SHIFT - 10));
75} 70}
71static struct xenbus_watch target_watch = {
72 .node = "memory/target",
73 .callback = watch_target,
74};
75
76 76
77static int balloon_init_watcher(struct notifier_block *notifier, 77static int balloon_init_watcher(struct notifier_block *notifier,
78 unsigned long event, 78 unsigned long event,
@@ -87,7 +87,9 @@ static int balloon_init_watcher(struct notifier_block *notifier,
87 return NOTIFY_DONE; 87 return NOTIFY_DONE;
88} 88}
89 89
90static struct notifier_block xenstore_notifier; 90static struct notifier_block xenstore_notifier = {
91 .notifier_call = balloon_init_watcher,
92};
91 93
92static int __init balloon_init(void) 94static int __init balloon_init(void)
93{ 95{
@@ -100,9 +102,6 @@ static int __init balloon_init(void)
100 102
101 register_xen_selfballooning(&balloon_sysdev); 103 register_xen_selfballooning(&balloon_sysdev);
102 104
103 target_watch.callback = watch_target;
104 xenstore_notifier.notifier_call = balloon_init_watcher;
105
106 register_xenstore_notifier(&xenstore_notifier); 105 register_xenstore_notifier(&xenstore_notifier);
107 106
108 return 0; 107 return 0;
diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c
index 444345afbd5..52fed16d870 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 cdacf923e07..1906125eab4 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -33,7 +33,9 @@
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>
38#include <asm/xen/page.h>
37#include <xen/interface/xen.h> 39#include <xen/interface/xen.h>
38#include <xen/interface/event_channel.h> 40#include <xen/interface/event_channel.h>
39#include <xen/events.h> 41#include <xen/events.h>
@@ -435,25 +437,26 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
435int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr) 437int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
436{ 438{
437 struct gnttab_map_grant_ref op = { 439 struct gnttab_map_grant_ref op = {
438 .flags = GNTMAP_host_map, 440 .flags = GNTMAP_host_map | GNTMAP_contains_pte,
439 .ref = gnt_ref, 441 .ref = gnt_ref,
440 .dom = dev->otherend_id, 442 .dom = dev->otherend_id,
441 }; 443 };
442 struct vm_struct *area; 444 struct vm_struct *area;
445 pte_t *pte;
443 446
444 *vaddr = NULL; 447 *vaddr = NULL;
445 448
446 area = xen_alloc_vm_area(PAGE_SIZE); 449 area = alloc_vm_area(PAGE_SIZE, &pte);
447 if (!area) 450 if (!area)
448 return -ENOMEM; 451 return -ENOMEM;
449 452
450 op.host_addr = (unsigned long)area->addr; 453 op.host_addr = arbitrary_virt_to_machine(pte).maddr;
451 454
452 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)) 455 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
453 BUG(); 456 BUG();
454 457
455 if (op.status != GNTST_okay) { 458 if (op.status != GNTST_okay) {
456 xen_free_vm_area(area); 459 free_vm_area(area);
457 xenbus_dev_fatal(dev, op.status, 460 xenbus_dev_fatal(dev, op.status,
458 "mapping in shared page %d from domain %d", 461 "mapping in shared page %d from domain %d",
459 gnt_ref, dev->otherend_id); 462 gnt_ref, dev->otherend_id);
@@ -526,6 +529,7 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
526 struct gnttab_unmap_grant_ref op = { 529 struct gnttab_unmap_grant_ref op = {
527 .host_addr = (unsigned long)vaddr, 530 .host_addr = (unsigned long)vaddr,
528 }; 531 };
532 unsigned int level;
529 533
530 /* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr) 534 /* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr)
531 * method so that we don't have to muck with vmalloc internals here. 535 * method so that we don't have to muck with vmalloc internals here.
@@ -547,12 +551,14 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
547 } 551 }
548 552
549 op.handle = (grant_handle_t)area->phys_addr; 553 op.handle = (grant_handle_t)area->phys_addr;
554 op.host_addr = arbitrary_virt_to_machine(
555 lookup_address((unsigned long)vaddr, &level)).maddr;
550 556
551 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)) 557 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
552 BUG(); 558 BUG();
553 559
554 if (op.status == GNTST_okay) 560 if (op.status == GNTST_okay)
555 xen_free_vm_area(area); 561 free_vm_area(area);
556 else 562 else
557 xenbus_dev_error(dev, op.status, 563 xenbus_dev_error(dev, op.status,
558 "unmapping page at handle %d error %d", 564 "unmapping page at handle %d error %d",
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index cef9b0bf63d..1b178c6e893 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>
@@ -309,8 +310,7 @@ void xenbus_unregister_driver(struct xenbus_driver *drv)
309} 310}
310EXPORT_SYMBOL_GPL(xenbus_unregister_driver); 311EXPORT_SYMBOL_GPL(xenbus_unregister_driver);
311 312
312struct xb_find_info 313struct xb_find_info {
313{
314 struct xenbus_device *dev; 314 struct xenbus_device *dev;
315 const char *nodename; 315 const char *nodename;
316}; 316};
@@ -639,7 +639,7 @@ int xenbus_dev_cancel(struct device *dev)
639EXPORT_SYMBOL_GPL(xenbus_dev_cancel); 639EXPORT_SYMBOL_GPL(xenbus_dev_cancel);
640 640
641/* A flag to determine if xenstored is 'ready' (i.e. has started) */ 641/* A flag to determine if xenstored is 'ready' (i.e. has started) */
642int xenstored_ready = 0; 642int xenstored_ready;
643 643
644 644
645int register_xenstore_notifier(struct notifier_block *nb) 645int register_xenstore_notifier(struct notifier_block *nb)
@@ -770,7 +770,7 @@ static int __init xenbus_init(void)
770 proc_mkdir("xen", NULL); 770 proc_mkdir("xen", NULL);
771#endif 771#endif
772 772
773 out_error: 773out_error:
774 return err; 774 return err;
775} 775}
776 776
diff --git a/drivers/xen/xenbus/xenbus_probe.h b/drivers/xen/xenbus/xenbus_probe.h
index b814935378c..9b1de4e34c6 100644
--- a/drivers/xen/xenbus/xenbus_probe.h
+++ b/drivers/xen/xenbus/xenbus_probe.h
@@ -36,8 +36,7 @@
36 36
37#define XEN_BUS_ID_SIZE 20 37#define XEN_BUS_ID_SIZE 20
38 38
39struct xen_bus_type 39struct xen_bus_type {
40{
41 char *root; 40 char *root;
42 unsigned int levels; 41 unsigned int levels;
43 int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename); 42 int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename);
diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c
index 32417b5064f..c3c7cd195c1 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 540587e18a9..2f73195512b 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 e0c84725d3e..988880dcee7 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>