Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 20 Nov 2013 22:25:39 +0000 (14:25 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 20 Nov 2013 22:25:39 +0000 (14:25 -0800)
Pull vfs bits and pieces from Al Viro:
 "Assorted bits that got missed in the first pull request + fixes for a
  couple of coredump regressions"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  fold try_to_ascend() into the sole remaining caller
  dcache.c: get rid of pointless macros
  take read_seqbegin_or_lock() and friends to seqlock.h
  consolidate simple ->d_delete() instances
  gfs2: endianness misannotations
  dump_emit(): use __kernel_write(), not vfs_write()
  dump_align(): fix the dumb braino

1398 files changed:
Documentation/ABI/stable/sysfs-driver-ib_srp
Documentation/ABI/stable/sysfs-transport-srp
Documentation/ABI/testing/sysfs-driver-hid-roccat-ryos [new file with mode: 0644]
Documentation/ABI/testing/sysfs-driver-hid-wiimote
Documentation/DMA-attributes.txt
Documentation/devicetree/bindings/arc/pmu.txt [new file with mode: 0644]
Documentation/devicetree/bindings/arm/calxeda/mem-ctrlr.txt
Documentation/devicetree/bindings/crypto/omap-des.txt [new file with mode: 0644]
Documentation/devicetree/bindings/crypto/omap-sham.txt
Documentation/devicetree/bindings/dma/atmel-dma.txt
Documentation/devicetree/bindings/gpio/men-a021-wdt.txt [deleted file]
Documentation/devicetree/bindings/hwmon/lm90.txt [new file with mode: 0644]
Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt [new file with mode: 0644]
Documentation/devicetree/bindings/i2c/i2c-exynos5.txt [new file with mode: 0644]
Documentation/devicetree/bindings/i2c/i2c-rcar.txt [new file with mode: 0644]
Documentation/devicetree/bindings/i2c/i2c-st.txt [new file with mode: 0644]
Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt
Documentation/devicetree/bindings/media/st-rc.txt [new file with mode: 0644]
Documentation/devicetree/bindings/mfd/as3722.txt [new file with mode: 0644]
Documentation/devicetree/bindings/mfd/s2mps11.txt
Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
Documentation/devicetree/bindings/mmc/synopsys-dw-mshc.txt
Documentation/devicetree/bindings/power/twl-charger.txt [new file with mode: 0644]
Documentation/devicetree/bindings/power_supply/ti,bq24735.txt [new file with mode: 0644]
Documentation/devicetree/bindings/powerpc/fsl/dma.txt
Documentation/devicetree/bindings/pwm/pwm-samsung.txt
Documentation/devicetree/bindings/spi/omap-spi.txt
Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
Documentation/devicetree/bindings/watchdog/dw_wdt.txt [new file with mode: 0644]
Documentation/devicetree/bindings/watchdog/men-a021-wdt.txt [new file with mode: 0644]
Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt [new file with mode: 0644]
Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt [new file with mode: 0644]
Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt [new file with mode: 0644]
Documentation/dmatest.txt
Documentation/hwmon/lm90
Documentation/i2c/busses/i2c-i801
Documentation/input/gamepad.txt
Documentation/kbuild/kconfig.txt
Documentation/networking/ip-sysctl.txt
Documentation/power/power_supply_class.txt
Documentation/power/runtime_pm.txt
Documentation/pwm.txt
Documentation/timers/00-INDEX
Documentation/usb/gadget_configfs.txt
Documentation/vm/00-INDEX
MAINTAINERS
Makefile
arch/alpha/Kconfig
arch/alpha/include/asm/thread_info.h
arch/arc/boot/dts/abilis_tb100.dtsi
arch/arc/boot/dts/abilis_tb100_dvk.dts
arch/arc/boot/dts/abilis_tb101.dtsi
arch/arc/boot/dts/abilis_tb101_dvk.dts
arch/arc/boot/dts/abilis_tb10x.dtsi
arch/arc/boot/dts/angel4.dts
arch/arc/configs/fpga_noramfs_defconfig [new file with mode: 0644]
arch/arc/include/asm/perf_event.h
arch/arc/include/asm/thread_info.h
arch/arc/kernel/Makefile
arch/arc/kernel/kprobes.c
arch/arc/kernel/perf_event.c [new file with mode: 0644]
arch/arc/plat-tb10x/Kconfig
arch/arm/Kconfig
arch/arm/boot/dts/am335x-evm.dts
arch/arm/boot/dts/am335x-evmsk.dts
arch/arm/boot/dts/ecx-2000.dts
arch/arm/boot/dts/ecx-common.dtsi
arch/arm/boot/dts/highbank.dts
arch/arm/boot/dts/imx51.dtsi
arch/arm/boot/dts/twl4030.dtsi
arch/arm/common/edma.c
arch/arm/configs/prima2_defconfig
arch/arm/configs/vt8500_v6_v7_defconfig [new file with mode: 0644]
arch/arm/include/asm/hardware/iop3xx-adma.h
arch/arm/include/asm/hardware/iop_adma.h
arch/arm/include/asm/thread_info.h
arch/arm/mach-at91/Makefile
arch/arm/mach-at91/at91sam9260.c
arch/arm/mach-at91/at91sam9261.c
arch/arm/mach-at91/at91sam9263.c
arch/arm/mach-at91/at91sam9g45.c
arch/arm/mach-at91/at91sam9n12.c
arch/arm/mach-at91/at91sam9rl.c
arch/arm/mach-at91/at91sam9x5.c
arch/arm/mach-at91/board-sam9260ek.c
arch/arm/mach-at91/board-sam9263ek.c
arch/arm/mach-at91/generic.h
arch/arm/mach-at91/include/mach/at91sam9n12.h
arch/arm/mach-at91/include/mach/at91sam9x5.h
arch/arm/mach-at91/include/mach/sama5d3.h
arch/arm/mach-at91/sama5d3.c
arch/arm/mach-at91/sysirq_mask.c [new file with mode: 0644]
arch/arm/mach-davinci/board-da830-evm.c
arch/arm/mach-davinci/board-da850-evm.c
arch/arm/mach-davinci/board-dm365-evm.c
arch/arm/mach-davinci/board-dm644x-evm.c
arch/arm/mach-davinci/board-dm646x-evm.c
arch/arm/mach-davinci/board-mityomapl138.c
arch/arm/mach-davinci/board-sffsdr.c
arch/arm/mach-highbank/Kconfig
arch/arm/mach-imx/Makefile
arch/arm/mach-imx/clk-imx6q.c
arch/arm/mach-imx/clk-pllv3.c
arch/arm/mach-imx/common.h
arch/arm/mach-imx/mach-pca100.c
arch/arm/mach-imx/mach-pcm037.c
arch/arm/mach-imx/mach-pcm038.c
arch/arm/mach-imx/mach-pcm043.c
arch/arm/mach-imx/mach-vpr200.c
arch/arm/mach-imx/src.c
arch/arm/mach-imx/system.c
arch/arm/mach-integrator/integrator_cp.c
arch/arm/mach-iop13xx/include/mach/adma.h
arch/arm/mach-kirkwood/lacie_v2-common.c
arch/arm/mach-omap1/board-osk.c
arch/arm/mach-omap2/Makefile
arch/arm/mach-omap2/board-cm-t35.c
arch/arm/mach-omap2/board-h4.c
arch/arm/mach-omap2/board-omap3beagle.c
arch/arm/mach-omap2/board-omap3stalker.c
arch/arm/mach-omap2/cclock3xxx_data.c
arch/arm/mach-omap2/cclock44xx_data.c
arch/arm/mach-omap2/gpmc-smsc911x.c
arch/arm/mach-omap2/omap_device.c
arch/arm/mach-omap2/prm44xx_54xx.h
arch/arm/mach-pxa/cm-x300.c
arch/arm/mach-pxa/colibri-pxa270-income.c
arch/arm/mach-pxa/ezx.c
arch/arm/mach-pxa/hx4700.c
arch/arm/mach-pxa/lpd270.c
arch/arm/mach-pxa/magician.c
arch/arm/mach-pxa/mainstone.c
arch/arm/mach-pxa/mioa701.c
arch/arm/mach-pxa/palm27x.c
arch/arm/mach-pxa/palmtc.c
arch/arm/mach-pxa/palmte2.c
arch/arm/mach-pxa/pcm990-baseboard.c
arch/arm/mach-pxa/raumfeld.c
arch/arm/mach-pxa/stargate2.c
arch/arm/mach-pxa/tavorevb.c
arch/arm/mach-pxa/viper.c
arch/arm/mach-pxa/z2.c
arch/arm/mach-pxa/zylonite.c
arch/arm/mach-s3c24xx/mach-h1940.c
arch/arm/mach-s3c24xx/mach-mini2440.c
arch/arm/mach-s3c24xx/mach-rx1950.c
arch/arm/mach-s3c64xx/mach-crag6410.c
arch/arm/mach-s3c64xx/mach-hmt.c
arch/arm/mach-s3c64xx/mach-smartq.c
arch/arm/mach-s3c64xx/mach-smdk6410.c
arch/arm/mach-s5p64x0/mach-smdk6440.c
arch/arm/mach-s5p64x0/mach-smdk6450.c
arch/arm/mach-s5pc100/mach-smdkc100.c
arch/arm/mach-s5pv210/mach-smdkv210.c
arch/arm/mach-shmobile/board-armadillo800eva.c
arch/arm/mach-sti/Kconfig
arch/arm/mach-tegra/tegra.c
arch/arm/plat-samsung/dev-backlight.c
arch/arm64/include/asm/thread_info.h
arch/avr32/include/asm/thread_info.h
arch/blackfin/configs/BF609-EZKIT_defconfig
arch/blackfin/include/asm/hardirq.h
arch/blackfin/include/asm/irq.h
arch/blackfin/include/asm/irq_handler.h
arch/blackfin/include/asm/thread_info.h
arch/blackfin/kernel/bfin_gpio.c
arch/blackfin/mach-bf548/Kconfig
arch/blackfin/mach-bf548/boards/ezkit.c
arch/blackfin/mach-bf548/include/mach/gpio.h
arch/blackfin/mach-bf548/include/mach/irq.h
arch/blackfin/mach-bf609/Kconfig
arch/blackfin/mach-bf609/boards/ezkit.c
arch/blackfin/mach-bf609/include/mach/gpio.h
arch/blackfin/mach-bf609/include/mach/irq.h
arch/blackfin/mach-bf609/include/mach/portmux.h
arch/blackfin/mach-common/ints-priority.c
arch/blackfin/mach-common/pm.c
arch/blackfin/mach-common/smp.c
arch/c6x/Kconfig
arch/c6x/include/asm/thread_info.h
arch/cris/include/asm/hardirq.h
arch/cris/include/asm/thread_info.h
arch/frv/include/asm/thread_info.h
arch/hexagon/include/asm/thread_info.h
arch/ia64/Kconfig
arch/ia64/hp/common/sba_iommu.c
arch/ia64/include/asm/pci.h
arch/ia64/include/asm/thread_info.h
arch/ia64/kernel/entry.S
arch/ia64/kernel/kprobes.c
arch/ia64/pci/pci.c
arch/ia64/sn/kernel/io_acpi_init.c
arch/m32r/include/asm/hardirq.h
arch/m32r/include/asm/mmu_context.h
arch/m32r/include/asm/thread_info.h
arch/m32r/kernel/entry.S
arch/m68k/Kconfig
arch/m68k/include/asm/hardirq.h
arch/m68k/include/asm/thread_info.h
arch/m68k/kernel/entry.S
arch/m68k/kernel/ints.c
arch/m68k/platform/68000/entry.S
arch/m68k/platform/68360/entry.S
arch/metag/include/asm/thread_info.h
arch/microblaze/Kconfig
arch/microblaze/include/asm/thread_info.h
arch/mips/Kconfig
arch/mips/configs/db1235_defconfig
arch/mips/include/asm/octeon/cvmx-pip.h
arch/mips/include/asm/thread_info.h
arch/mn10300/include/asm/mmu_context.h
arch/mn10300/include/asm/thread_info.h
arch/openrisc/Makefile
arch/openrisc/configs/or1ksim_defconfig
arch/openrisc/include/asm/Kbuild
arch/openrisc/kernel/module.c
arch/openrisc/kernel/setup.c
arch/openrisc/kernel/vmlinux.h
arch/parisc/Kconfig
arch/parisc/include/asm/thread_info.h
arch/powerpc/Kconfig
arch/powerpc/boot/dts/fsl/b4si-post.dtsi
arch/powerpc/boot/dts/fsl/elo3-dma-0.dtsi [new file with mode: 0644]
arch/powerpc/boot/dts/fsl/elo3-dma-1.dtsi [new file with mode: 0644]
arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
arch/powerpc/include/asm/thread_info.h
arch/powerpc/kernel/kprobes.c
arch/powerpc/platforms/pseries/nvram.c
arch/s390/boot/Makefile
arch/s390/include/asm/ctl_reg.h
arch/s390/include/asm/eadm.h
arch/s390/include/asm/hardirq.h
arch/s390/include/asm/pci.h
arch/s390/include/asm/sclp.h
arch/s390/include/asm/setup.h
arch/s390/include/asm/thread_info.h
arch/s390/kernel/crash_dump.c
arch/s390/kernel/early.c
arch/s390/kernel/kprobes.c
arch/s390/kernel/setup.c
arch/s390/pci/pci.c
arch/s390/pci/pci_clp.c
arch/s390/pci/pci_event.c
arch/score/include/asm/thread_info.h
arch/sh/Kconfig
arch/sh/boards/mach-ecovec24/setup.c
arch/sh/include/asm/mmu_context.h
arch/sh/include/asm/thread_info.h
arch/sh/kernel/entry-common.S
arch/sparc/Kconfig
arch/sparc/include/asm/hardirq_32.h
arch/sparc/include/asm/hardirq_64.h
arch/sparc/include/asm/thread_info_32.h
arch/sparc/include/asm/thread_info_64.h
arch/sparc/include/asm/tlbflush_64.h
arch/sparc/kernel/kprobes.c
arch/sparc/kernel/rtrap_64.S
arch/sparc/mm/init_64.c
arch/tile/include/asm/hardirq.h
arch/tile/include/asm/thread_info.h
arch/um/Kconfig.char
arch/um/Kconfig.common
arch/um/Makefile
arch/um/configs/i386_defconfig [new file with mode: 0644]
arch/um/configs/x86_64_defconfig [new file with mode: 0644]
arch/um/defconfig [deleted file]
arch/um/drivers/mconsole_kern.c
arch/um/include/asm/processor-generic.h
arch/um/include/asm/thread_info.h
arch/um/include/shared/as-layout.h
arch/um/include/shared/os.h
arch/um/kernel/process.c
arch/um/kernel/sysrq.c
arch/um/kernel/trap.c
arch/um/kernel/um_arch.c
arch/um/os-Linux/signal.c
arch/unicore32/Kconfig
arch/unicore32/include/asm/thread_info.h
arch/unicore32/kernel/puv3-nb0916.c
arch/x86/Kconfig
arch/x86/include/asm/pci.h
arch/x86/include/asm/thread_info.h
arch/x86/include/uapi/asm/msr-index.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/cpu/amd.c
arch/x86/kernel/cpu/intel_cacheinfo.c
arch/x86/kernel/cpu/scattered.c
arch/x86/kernel/ftrace.c
arch/x86/mm/pgtable.c
arch/x86/pci/acpi.c
arch/x86/um/Kconfig
arch/x86/um/asm/processor_32.h
arch/x86/um/asm/processor_64.h
arch/x86/um/sysrq_32.c
arch/x86/um/sysrq_64.c
arch/x86/um/vdso/.gitignore [new file with mode: 0644]
arch/xtensa/include/asm/thread_info.h
block/blk-ioc.c
block/blk-mq-cpu.c
block/blk-mq.c
crypto/async_tx/async_memcpy.c
crypto/async_tx/async_pq.c
crypto/async_tx/async_raid6_recov.c
crypto/async_tx/async_tx.c
crypto/async_tx/async_xor.c
crypto/async_tx/raid6test.c
drivers/acpi/Kconfig
drivers/acpi/ac.c
drivers/acpi/acpi_lpss.c
drivers/acpi/acpi_platform.c
drivers/acpi/acpica/utobject.c
drivers/acpi/blacklist.c
drivers/acpi/device_pm.c
drivers/acpi/ec.c
drivers/acpi/event.c
drivers/acpi/glue.c
drivers/acpi/pci_root.c
drivers/acpi/scan.c
drivers/acpi/video.c
drivers/ata/libata-acpi.c
drivers/ata/pata_arasan_cf.c
drivers/atm/idt77252.c
drivers/base/dma-contiguous.c
drivers/base/platform.c
drivers/base/power/main.c
drivers/block/virtio_blk.c
drivers/char/random.c
drivers/clk/clk-fixed-factor.c
drivers/connector/cn_proc.c
drivers/cpufreq/Kconfig.x86
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_governor.c
drivers/cpufreq/exynos-cpufreq.c
drivers/cpufreq/omap-cpufreq.c
drivers/dma/Kconfig
drivers/dma/amba-pl08x.c
drivers/dma/at_hdmac.c
drivers/dma/coh901318.c
drivers/dma/cppi41.c
drivers/dma/dma-jz4740.c
drivers/dma/dmaengine.c
drivers/dma/dmatest.c
drivers/dma/dw/core.c
drivers/dma/edma.c
drivers/dma/ep93xx_dma.c
drivers/dma/fsldma.c
drivers/dma/fsldma.h
drivers/dma/imx-dma.c
drivers/dma/imx-sdma.c
drivers/dma/intel_mid_dma.c
drivers/dma/ioat/dma.c
drivers/dma/ioat/dma.h
drivers/dma/ioat/dma_v2.c
drivers/dma/ioat/dma_v2.h
drivers/dma/ioat/dma_v3.c
drivers/dma/ioat/pci.c
drivers/dma/iop-adma.c
drivers/dma/ipu/ipu_idmac.c
drivers/dma/k3dma.c
drivers/dma/mmp_pdma.c
drivers/dma/mmp_tdma.c
drivers/dma/mv_xor.c
drivers/dma/mv_xor.h
drivers/dma/mxs-dma.c
drivers/dma/omap-dma.c
drivers/dma/pl330.c
drivers/dma/ppc4xx/adma.c
drivers/dma/sa11x0-dma.c
drivers/dma/sh/shdma-base.c
drivers/dma/sh/shdmac.c
drivers/dma/ste_dma40.c
drivers/dma/tegra20-apb-dma.c
drivers/dma/timb_dma.c
drivers/dma/txx9dmac.c
drivers/edac/cell_edac.c
drivers/edac/edac_device.c
drivers/edac/edac_mc.c
drivers/edac/edac_pci.c
drivers/edac/highbank_l2_edac.c
drivers/edac/highbank_mc_edac.c
drivers/edac/mpc85xx_edac.c
drivers/edac/sb_edac.c
drivers/fmc/Kconfig
drivers/gpio/gpiolib.c
drivers/gpu/drm/drm_encoder_slave.c
drivers/gpu/drm/drm_irq.c
drivers/gpu/drm/drm_stub.c
drivers/gpu/drm/i915/intel_acpi.c
drivers/gpu/drm/i915/intel_opregion.c
drivers/gpu/drm/nouveau/core/subdev/mxm/base.c
drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
drivers/gpu/drm/nouveau/nouveau_acpi.c
drivers/gpu/drm/radeon/radeon_acpi.c
drivers/gpu/drm/radeon/radeon_atpx_handler.c
drivers/gpu/drm/radeon/radeon_bios.c
drivers/hid/Kconfig
drivers/hid/Makefile
drivers/hid/hid-apple.c
drivers/hid/hid-axff.c
drivers/hid/hid-core.c
drivers/hid/hid-elo.c
drivers/hid/hid-holtek-mouse.c
drivers/hid/hid-ids.h
drivers/hid/hid-lenovo-tpkbd.c
drivers/hid/hid-lg.c
drivers/hid/hid-lg2ff.c
drivers/hid/hid-lg4ff.c
drivers/hid/hid-logitech-dj.c
drivers/hid/hid-multitouch.c
drivers/hid/hid-roccat-common.c
drivers/hid/hid-roccat-common.h
drivers/hid/hid-roccat-konepure.c
drivers/hid/hid-roccat-konepure.h [deleted file]
drivers/hid/hid-roccat-kovaplus.c
drivers/hid/hid-roccat-ryos.c [new file with mode: 0644]
drivers/hid/hid-roccat-savu.c
drivers/hid/hid-roccat-savu.h
drivers/hid/hid-sensor-hub.c
drivers/hid/hid-sony.c
drivers/hid/hid-wiimote-modules.c
drivers/hid/hid-wiimote.h
drivers/hid/i2c-hid/i2c-hid.c
drivers/hid/usbhid/hid-quirks.c
drivers/hwmon/lm90.c
drivers/i2c/busses/Kconfig
drivers/i2c/busses/Makefile
drivers/i2c/busses/i2c-bcm-kona.c [new file with mode: 0644]
drivers/i2c/busses/i2c-bfin-twi.c
drivers/i2c/busses/i2c-cbus-gpio.c
drivers/i2c/busses/i2c-davinci.c
drivers/i2c/busses/i2c-designware-platdrv.c
drivers/i2c/busses/i2c-eg20t.c
drivers/i2c/busses/i2c-exynos5.c [new file with mode: 0644]
drivers/i2c/busses/i2c-gpio.c
drivers/i2c/busses/i2c-i801.c
drivers/i2c/busses/i2c-mv64xxx.c
drivers/i2c/busses/i2c-mxs.c
drivers/i2c/busses/i2c-pnx.c
drivers/i2c/busses/i2c-rcar.c
drivers/i2c/busses/i2c-s3c2410.c
drivers/i2c/busses/i2c-scmi.c
drivers/i2c/busses/i2c-sh_mobile.c
drivers/i2c/busses/i2c-st.c [new file with mode: 0644]
drivers/i2c/busses/i2c-wmt.c
drivers/i2c/busses/i2c-xiic.c
drivers/i2c/i2c-core.c
drivers/i2c/i2c-dev.c
drivers/i2c/i2c-smbus.c
drivers/i2c/muxes/i2c-arb-gpio-challenge.c
drivers/i2c/muxes/i2c-mux-gpio.c
drivers/i2c/muxes/i2c-mux-pinctrl.c
drivers/ide/ide-acpi.c
drivers/idle/intel_idle.c
drivers/infiniband/Kconfig
drivers/infiniband/core/cm.c
drivers/infiniband/core/cma.c
drivers/infiniband/core/netlink.c
drivers/infiniband/core/sysfs.c
drivers/infiniband/core/ucma.c
drivers/infiniband/core/uverbs.h
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/core/uverbs_main.c
drivers/infiniband/core/verbs.c
drivers/infiniband/hw/cxgb4/device.c
drivers/infiniband/hw/ipath/ipath_user_sdma.c
drivers/infiniband/hw/mlx4/cq.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/cq.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/mlx5_ib.h
drivers/infiniband/hw/mlx5/mr.c
drivers/infiniband/hw/mlx5/qp.c
drivers/infiniband/hw/mlx5/srq.c
drivers/infiniband/hw/nes/nes_verbs.c
drivers/infiniband/hw/ocrdma/ocrdma.h
drivers/infiniband/hw/ocrdma/ocrdma_hw.c
drivers/infiniband/hw/ocrdma/ocrdma_main.c
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
drivers/infiniband/hw/qib/qib_iba7322.c
drivers/infiniband/hw/qib/qib_mad.h
drivers/infiniband/hw/qib/qib_user_sdma.c
drivers/infiniband/hw/qib/qib_verbs.h
drivers/infiniband/ulp/ipoib/ipoib.h
drivers/infiniband/ulp/ipoib/ipoib_cm.c
drivers/infiniband/ulp/ipoib/ipoib_ib.c
drivers/infiniband/ulp/ipoib/ipoib_main.c
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
drivers/infiniband/ulp/ipoib/ipoib_netlink.c
drivers/infiniband/ulp/ipoib/ipoib_vlan.c
drivers/infiniband/ulp/isert/Kconfig
drivers/infiniband/ulp/srp/ib_srp.c
drivers/infiniband/ulp/srp/ib_srp.h
drivers/input/Kconfig
drivers/input/evdev.c
drivers/input/input.c
drivers/input/keyboard/Kconfig
drivers/input/keyboard/gpio_keys.c
drivers/input/keyboard/gpio_keys_polled.c
drivers/input/keyboard/lpc32xx-keys.c
drivers/input/keyboard/nspire-keypad.c
drivers/input/keyboard/pxa27x_keypad.c
drivers/input/keyboard/tegra-kbc.c
drivers/input/keyboard/tnetv107x-keypad.c
drivers/input/misc/Kconfig
drivers/input/misc/ad714x-spi.c
drivers/input/misc/cobalt_btns.c
drivers/input/misc/mma8450.c
drivers/input/misc/mpu3050.c
drivers/input/misc/pwm-beeper.c
drivers/input/misc/rb532_button.c
drivers/input/misc/rotary_encoder.c
drivers/input/misc/sirfsoc-onkey.c
drivers/input/misc/uinput.c
drivers/input/mouse/alps.c
drivers/input/mouse/cypress_ps2.c
drivers/input/serio/Kconfig
drivers/input/serio/Makefile
drivers/input/serio/hyperv-keyboard.c [new file with mode: 0644]
drivers/input/serio/i8042-x86ia64io.h
drivers/input/serio/i8042.c
drivers/input/tablet/wacom_sys.c
drivers/input/tablet/wacom_wac.c
drivers/input/tablet/wacom_wac.h
drivers/input/touchscreen/Kconfig
drivers/input/touchscreen/Makefile
drivers/input/touchscreen/ad7877.c
drivers/input/touchscreen/ad7879-spi.c
drivers/input/touchscreen/cyttsp4_core.c
drivers/input/touchscreen/cyttsp4_spi.c
drivers/input/touchscreen/egalax_ts.c
drivers/input/touchscreen/htcpen.c
drivers/input/touchscreen/st1232.c
drivers/input/touchscreen/ti_am335x_tsc.c
drivers/input/touchscreen/tsc2005.c
drivers/input/touchscreen/usbtouchscreen.c
drivers/input/touchscreen/zforce_ts.c [new file with mode: 0644]
drivers/iommu/Kconfig
drivers/isdn/isdnloop/isdnloop.c
drivers/md/bcache/Kconfig
drivers/md/bcache/alloc.c
drivers/md/bcache/bcache.h
drivers/md/bcache/bset.c
drivers/md/bcache/bset.h
drivers/md/bcache/btree.c
drivers/md/bcache/btree.h
drivers/md/bcache/closure.c
drivers/md/bcache/closure.h
drivers/md/bcache/debug.c
drivers/md/bcache/debug.h
drivers/md/bcache/journal.c
drivers/md/bcache/journal.h
drivers/md/bcache/movinggc.c
drivers/md/bcache/request.c
drivers/md/bcache/request.h
drivers/md/bcache/stats.c
drivers/md/bcache/stats.h
drivers/md/bcache/super.c
drivers/md/bcache/sysfs.c
drivers/md/bcache/trace.c
drivers/md/bcache/util.c
drivers/md/bcache/util.h
drivers/md/bcache/writeback.c
drivers/md/bcache/writeback.h
drivers/md/md.c
drivers/md/raid1.c
drivers/md/raid1.h
drivers/md/raid10.c
drivers/md/raid5.c
drivers/md/raid5.h
drivers/media/common/b2c2/flexcop-sram.c
drivers/media/common/saa7146/saa7146_core.c
drivers/media/common/siano/smscoreapi.c
drivers/media/common/siano/smsdvb-main.c
drivers/media/dvb-core/dvb_demux.c
drivers/media/dvb-frontends/Kconfig
drivers/media/dvb-frontends/Makefile
drivers/media/dvb-frontends/af9013.c
drivers/media/dvb-frontends/af9033.c
drivers/media/dvb-frontends/bcm3510.c
drivers/media/dvb-frontends/cx24110.c
drivers/media/dvb-frontends/cx24117.c [new file with mode: 0644]
drivers/media/dvb-frontends/cx24117.h [new file with mode: 0644]
drivers/media/dvb-frontends/cx24123.c
drivers/media/dvb-frontends/cxd2820r_core.c
drivers/media/dvb-frontends/dib9000.c
drivers/media/dvb-frontends/drxd_hard.c
drivers/media/dvb-frontends/drxk_hard.c
drivers/media/dvb-frontends/itd1000.c
drivers/media/dvb-frontends/mt312.c
drivers/media/dvb-frontends/nxt200x.c
drivers/media/dvb-frontends/rtl2830.c
drivers/media/dvb-frontends/rtl2832.c
drivers/media/dvb-frontends/rtl2832.h
drivers/media/dvb-frontends/s5h1420.c
drivers/media/dvb-frontends/stb0899_drv.c
drivers/media/dvb-frontends/stb6100.c
drivers/media/dvb-frontends/stv0367.c
drivers/media/dvb-frontends/stv090x.c
drivers/media/dvb-frontends/stv6110.c
drivers/media/dvb-frontends/stv6110x.c
drivers/media/dvb-frontends/tda10071.c
drivers/media/dvb-frontends/tda18271c2dd.c
drivers/media/dvb-frontends/tda8083.c
drivers/media/dvb-frontends/ts2020.c
drivers/media/dvb-frontends/ts2020.h
drivers/media/dvb-frontends/zl10039.c
drivers/media/i2c/Kconfig
drivers/media/i2c/Makefile
drivers/media/i2c/adv7183.c
drivers/media/i2c/adv7343.c
drivers/media/i2c/lm3560.c [new file with mode: 0644]
drivers/media/i2c/s5c73m3/s5c73m3-core.c
drivers/media/i2c/soc_camera/imx074.c
drivers/media/i2c/soc_camera/ov9640.c
drivers/media/i2c/ths8200.c
drivers/media/i2c/tvp514x.c
drivers/media/i2c/tvp7002.c
drivers/media/pci/b2c2/flexcop-pci.c
drivers/media/pci/bt8xx/bt878.c
drivers/media/pci/bt8xx/bttv-driver.c
drivers/media/pci/cx18/cx18-driver.c
drivers/media/pci/cx23885/Kconfig
drivers/media/pci/cx23885/cimax2.c
drivers/media/pci/cx23885/cx23885-cards.c
drivers/media/pci/cx23885/cx23885-core.c
drivers/media/pci/cx23885/cx23885-dvb.c
drivers/media/pci/cx23885/cx23885-input.c
drivers/media/pci/cx23885/cx23885-video.c
drivers/media/pci/cx23885/cx23885.h
drivers/media/pci/cx25821/cx25821-cards.c
drivers/media/pci/cx25821/cx25821-medusa-video.c
drivers/media/pci/cx25821/cx25821-medusa-video.h
drivers/media/pci/cx25821/cx25821-video-upstream.c
drivers/media/pci/cx88/cx88-alsa.c
drivers/media/pci/cx88/cx88-mpeg.c
drivers/media/pci/cx88/cx88-video.c
drivers/media/pci/ddbridge/ddbridge-core.c
drivers/media/pci/dm1105/dm1105.c
drivers/media/pci/ivtv/ivtv-driver.c
drivers/media/pci/mantis/mantis_pci.c
drivers/media/pci/meye/meye.c
drivers/media/pci/ngene/ngene-core.c
drivers/media/pci/pluto2/pluto2.c
drivers/media/pci/pt1/pt1.c
drivers/media/pci/saa7134/saa7134-alsa.c
drivers/media/pci/saa7134/saa7134-core.c
drivers/media/pci/saa7164/saa7164-core.c
drivers/media/pci/ttpci/av7110_hw.c
drivers/media/pci/zoran/Kconfig
drivers/media/pci/zoran/zoran_card.c
drivers/media/platform/Kconfig
drivers/media/platform/Makefile
drivers/media/platform/coda.c
drivers/media/platform/davinci/vpbe_display.c
drivers/media/platform/davinci/vpfe_capture.c
drivers/media/platform/davinci/vpif_capture.c
drivers/media/platform/exynos-gsc/gsc-core.h
drivers/media/platform/exynos-gsc/gsc-m2m.c
drivers/media/platform/exynos4-is/fimc-isp.c
drivers/media/platform/exynos4-is/media-dev.c
drivers/media/platform/m2m-deinterlace.c
drivers/media/platform/marvell-ccic/mcam-core.c
drivers/media/platform/marvell-ccic/mmp-driver.c
drivers/media/platform/mem2mem_testdev.c
drivers/media/platform/s5p-g2d/g2d.c
drivers/media/platform/s5p-mfc/s5p_mfc.c
drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v5.c
drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
drivers/media/platform/s5p-tv/mixer_grp_layer.c
drivers/media/platform/s5p-tv/mixer_vp_layer.c
drivers/media/platform/soc_camera/rcar_vin.c
drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
drivers/media/platform/soc_camera/soc_camera.c
drivers/media/platform/ti-vpe/Makefile [new file with mode: 0644]
drivers/media/platform/ti-vpe/vpdma.c [new file with mode: 0644]
drivers/media/platform/ti-vpe/vpdma.h [new file with mode: 0644]
drivers/media/platform/ti-vpe/vpdma_priv.h [new file with mode: 0644]
drivers/media/platform/ti-vpe/vpe.c [new file with mode: 0644]
drivers/media/platform/ti-vpe/vpe_regs.h [new file with mode: 0644]
drivers/media/platform/timblogiw.c
drivers/media/radio/radio-keene.c
drivers/media/radio/radio-sf16fmr2.c
drivers/media/radio/radio-shark.c
drivers/media/radio/radio-shark2.c
drivers/media/radio/si470x/radio-si470x-common.c
drivers/media/radio/si470x/radio-si470x-i2c.c
drivers/media/radio/si4713-i2c.c
drivers/media/radio/tef6862.c
drivers/media/radio/wl128x/fmdrv_common.c
drivers/media/rc/Kconfig
drivers/media/rc/Makefile
drivers/media/rc/fintek-cir.h
drivers/media/rc/gpio-ir-recv.c
drivers/media/rc/iguanair.c
drivers/media/rc/ir-rx51.c
drivers/media/rc/keymaps/rc-dib0700-nec.c
drivers/media/rc/keymaps/rc-dib0700-rc5.c
drivers/media/rc/nuvoton-cir.h
drivers/media/rc/st_rc.c [new file with mode: 0644]
drivers/media/rc/winbond-cir.c
drivers/media/tuners/e4000.c
drivers/media/tuners/fc0012.c
drivers/media/tuners/fc0013.c
drivers/media/tuners/fc2580.c
drivers/media/tuners/r820t.c
drivers/media/tuners/tda18212.c
drivers/media/tuners/tda18218.c
drivers/media/tuners/tda9887.c
drivers/media/tuners/tuner-xc2028.c
drivers/media/usb/b2c2/flexcop-usb.c
drivers/media/usb/cpia2/cpia2_usb.c
drivers/media/usb/cx231xx/cx231xx-cards.c
drivers/media/usb/cx231xx/cx231xx-pcb-cfg.c
drivers/media/usb/dvb-usb-v2/af9015.c
drivers/media/usb/dvb-usb-v2/af9035.c
drivers/media/usb/dvb-usb-v2/mxl111sf.c
drivers/media/usb/dvb-usb-v2/rtl28xxu.c
drivers/media/usb/dvb-usb-v2/rtl28xxu.h
drivers/media/usb/dvb-usb/az6027.c
drivers/media/usb/dvb-usb/cxusb.c
drivers/media/usb/dvb-usb/dibusb-common.c
drivers/media/usb/dvb-usb/dw2102.c
drivers/media/usb/em28xx/em28xx-camera.c
drivers/media/usb/em28xx/em28xx-cards.c
drivers/media/usb/em28xx/em28xx-dvb.c
drivers/media/usb/em28xx/em28xx-video.c
drivers/media/usb/em28xx/em28xx.h
drivers/media/usb/gspca/conex.c
drivers/media/usb/gspca/cpia1.c
drivers/media/usb/gspca/gspca.c
drivers/media/usb/gspca/gspca.h
drivers/media/usb/gspca/jeilinj.c
drivers/media/usb/gspca/jl2005bcd.c
drivers/media/usb/gspca/m5602/m5602_mt9m111.c
drivers/media/usb/gspca/mars.c
drivers/media/usb/gspca/mr97310a.c
drivers/media/usb/gspca/nw80x.c
drivers/media/usb/gspca/ov519.c
drivers/media/usb/gspca/ov534.c
drivers/media/usb/gspca/ov534_9.c
drivers/media/usb/gspca/pac207.c
drivers/media/usb/gspca/pac7311.c
drivers/media/usb/gspca/se401.c
drivers/media/usb/gspca/sn9c20x.c
drivers/media/usb/gspca/sonixb.c
drivers/media/usb/gspca/sonixj.c
drivers/media/usb/gspca/spca1528.c
drivers/media/usb/gspca/spca500.c
drivers/media/usb/gspca/sq905c.c
drivers/media/usb/gspca/sq930x.c
drivers/media/usb/gspca/stk014.c
drivers/media/usb/gspca/stk1135.c
drivers/media/usb/gspca/stv06xx/stv06xx.c
drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c
drivers/media/usb/gspca/sunplus.c
drivers/media/usb/gspca/topro.c
drivers/media/usb/gspca/tv8532.c
drivers/media/usb/gspca/vicam.c
drivers/media/usb/gspca/w996Xcf.c
drivers/media/usb/gspca/xirlink_cit.c
drivers/media/usb/gspca/zc3xx.c
drivers/media/usb/hdpvr/hdpvr-core.c
drivers/media/usb/pvrusb2/pvrusb2-hdw.c
drivers/media/usb/siano/smsusb.c
drivers/media/usb/tlg2300/pd-main.c
drivers/media/usb/ttusb-dec/ttusb_dec.c
drivers/media/usb/uvc/uvc_ctrl.c
drivers/media/usb/uvc/uvc_video.c
drivers/media/v4l2-core/tuner-core.c
drivers/media/v4l2-core/v4l2-async.c
drivers/media/v4l2-core/v4l2-clk.c
drivers/media/v4l2-core/v4l2-common.c
drivers/media/v4l2-core/v4l2-ctrls.c
drivers/media/v4l2-core/v4l2-mem2mem.c
drivers/media/v4l2-core/videobuf2-core.c
drivers/media/v4l2-core/videobuf2-dma-sg.c
drivers/mfd/88pm860x-core.c
drivers/mfd/Kconfig
drivers/mfd/Makefile
drivers/mfd/aat2870-core.c
drivers/mfd/arizona-core.c
drivers/mfd/arizona-i2c.c
drivers/mfd/arizona-spi.c
drivers/mfd/as3711.c
drivers/mfd/as3722.c [new file with mode: 0644]
drivers/mfd/da9052-i2c.c
drivers/mfd/ezx-pcap.c
drivers/mfd/lpc_ich.c
drivers/mfd/lpc_sch.c
drivers/mfd/max77686.c
drivers/mfd/max77693-irq.c
drivers/mfd/max77693.c
drivers/mfd/max8907.c
drivers/mfd/max8925-i2c.c
drivers/mfd/max8997.c
drivers/mfd/mc13xxx-i2c.c
drivers/mfd/mfd-core.c
drivers/mfd/omap-usb-host.c
drivers/mfd/omap-usb-tll.c
drivers/mfd/palmas.c
drivers/mfd/pm8921-core.c
drivers/mfd/rts5249.c
drivers/mfd/rtsx_pcr.c
drivers/mfd/sec-core.c
drivers/mfd/sm501.c
drivers/mfd/stw481x.c [new file with mode: 0644]
drivers/mfd/tc3589x.c
drivers/mfd/ti-ssp.c
drivers/mfd/ti_am335x_tscadc.c
drivers/mfd/timberdale.c
drivers/mfd/tps6507x.c
drivers/mfd/tps65217.c
drivers/mfd/tps6586x.c
drivers/mfd/tps65910.c
drivers/mfd/twl6040.c
drivers/mfd/ucb1x00-core.c
drivers/mfd/wm5102-tables.c
drivers/mfd/wm5110-tables.c
drivers/mfd/wm8994-core.c
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/carma/carma-fpga.c
drivers/misc/eeprom/at24.c
drivers/misc/ep93xx_pwm.c [deleted file]
drivers/mmc/card/block.c
drivers/mmc/core/bus.c
drivers/mmc/core/core.c
drivers/mmc/core/core.h
drivers/mmc/core/mmc.c
drivers/mmc/core/mmc_ops.c
drivers/mmc/core/sd.c
drivers/mmc/core/sdio.c
drivers/mmc/core/sdio_bus.c
drivers/mmc/host/atmel-mci.c
drivers/mmc/host/au1xmmc.c
drivers/mmc/host/bfin_sdh.c
drivers/mmc/host/cb710-mmc.c
drivers/mmc/host/davinci_mmc.c
drivers/mmc/host/dw_mmc-exynos.c
drivers/mmc/host/dw_mmc-pltfm.c
drivers/mmc/host/dw_mmc-socfpga.c
drivers/mmc/host/dw_mmc.c
drivers/mmc/host/dw_mmc.h
drivers/mmc/host/jz4740_mmc.c
drivers/mmc/host/mmci.c
drivers/mmc/host/msm_sdcc.c
drivers/mmc/host/mvsdio.c
drivers/mmc/host/mxcmmc.c
drivers/mmc/host/mxs-mmc.c
drivers/mmc/host/omap.c
drivers/mmc/host/omap_hsmmc.c
drivers/mmc/host/pxamci.c
drivers/mmc/host/rtsx_pci_sdmmc.c
drivers/mmc/host/s3cmci.c
drivers/mmc/host/sdhci-bcm-kona.c
drivers/mmc/host/sdhci-bcm2835.c
drivers/mmc/host/sdhci-esdhc-imx.c
drivers/mmc/host/sdhci-esdhc.h
drivers/mmc/host/sdhci-of-esdhc.c
drivers/mmc/host/sdhci-pci.c
drivers/mmc/host/sdhci.c
drivers/mmc/host/sdhci.h
drivers/mmc/host/sdricoh_cs.c
drivers/mmc/host/sh_mmcif.c
drivers/mmc/host/tifm_sd.c
drivers/mmc/host/tmio_mmc_pio.c
drivers/mmc/host/via-sdmmc.c
drivers/mmc/host/vub300.c
drivers/mmc/host/wbsd.c
drivers/mmc/host/wmt-sdmmc.c
drivers/mtd/nand/atmel_nand.c
drivers/mtd/nand/docg4.c
drivers/mtd/nand/fsmc_nand.c
drivers/net/bonding/bond_sysfs.c
drivers/net/bonding/bonding.h
drivers/net/ethernet/atheros/alx/main.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_reg.h
drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
drivers/net/ethernet/broadcom/tg3.c
drivers/net/ethernet/emulex/benet/be_cmds.c
drivers/net/ethernet/emulex/benet/be_cmds.h
drivers/net/ethernet/emulex/benet/be_main.c
drivers/net/ethernet/freescale/fec_main.c
drivers/net/ethernet/intel/e1000e/netdev.c
drivers/net/ethernet/marvell/mv643xx_eth.c
drivers/net/ethernet/mellanox/mlx4/fw.c
drivers/net/ethernet/mellanox/mlx5/core/cmd.c
drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
drivers/net/ethernet/mellanox/mlx5/core/eq.c
drivers/net/ethernet/mellanox/mlx5/core/main.c
drivers/net/ethernet/mellanox/mlx5/core/mr.c
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
drivers/net/ethernet/micrel/ks8842.c
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
drivers/net/ethernet/ti/cpsw.c
drivers/net/ethernet/xscale/ixp4xx_eth.c
drivers/net/irda/ali-ircc.c
drivers/net/irda/nsc-ircc.c
drivers/net/macvtap.c
drivers/net/team/team.c
drivers/net/tun.c
drivers/net/usb/cdc_ncm.c
drivers/net/usb/usbnet.c
drivers/net/virtio_net.c
drivers/net/wireless/ath/ath10k/pci.c
drivers/net/wireless/ath/ath5k/dma.c
drivers/net/wireless/ath/ath9k/ar9003_hw.c
drivers/net/wireless/ath/ath9k/ar9485_initvals.h
drivers/net/wireless/ath/ath9k/ath9k.h
drivers/net/wireless/ath/ath9k/dfs_debug.c
drivers/net/wireless/ath/ath9k/hw.h
drivers/net/wireless/ath/ath9k/init.c
drivers/net/wireless/ath/ath9k/pci.c
drivers/net/wireless/ath/wcn36xx/debug.c
drivers/net/wireless/ath/wcn36xx/smd.c
drivers/net/wireless/libertas/debugfs.c
drivers/net/wireless/libertas/if_cs.c
drivers/net/wireless/mac80211_hwsim.c
drivers/net/wireless/mwifiex/fw.h
drivers/net/wireless/mwifiex/ie.c
drivers/net/wireless/mwifiex/sdio.c
drivers/net/wireless/mwifiex/sta_cmd.c
drivers/net/wireless/mwifiex/sta_cmdresp.c
drivers/net/wireless/mwifiex/sta_ioctl.c
drivers/net/wireless/mwifiex/uap_txrx.c
drivers/net/wireless/mwifiex/wmm.c
drivers/net/wireless/prism54/islpci_dev.c
drivers/net/wireless/rt2x00/rt2800lib.c
drivers/net/wireless/rt2x00/rt2x00lib.h
drivers/net/wireless/rt2x00/rt2x00mac.c
drivers/net/wireless/rt2x00/rt2x00queue.c
drivers/net/wireless/rtlwifi/base.c
drivers/net/wireless/rtlwifi/efuse.c
drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
drivers/net/wireless/rtlwifi/rtl8192de/trx.c
drivers/net/wireless/rtlwifi/rtl8192se/rf.c
drivers/net/wireless/rtlwifi/rtl8192se/trx.c
drivers/net/wireless/rtlwifi/wifi.h
drivers/net/xen-netfront.c
drivers/ntb/ntb_transport.c
drivers/parport/Kconfig
drivers/pci/hotplug/acpi_pcihp.c
drivers/pci/hotplug/acpiphp.h
drivers/pci/hotplug/pciehp_acpi.c
drivers/pci/hotplug/sgi_hotplug.c
drivers/pci/ioapic.c
drivers/pci/pci-acpi.c
drivers/pci/pci-label.c
drivers/pinctrl/pinctrl-single.c
drivers/platform/x86/apple-gmux.c
drivers/pnp/pnpacpi/core.c
drivers/power/Kconfig
drivers/power/Makefile
drivers/power/ab8500_charger.c
drivers/power/bq2415x_charger.c
drivers/power/bq24735-charger.c [new file with mode: 0644]
drivers/power/charger-manager.c
drivers/power/isp1704_charger.c
drivers/power/max17042_battery.c
drivers/power/pm2301_charger.c
drivers/power/tps65090-charger.c
drivers/power/twl4030_charger.c
drivers/pwm/Kconfig
drivers/pwm/Makefile
drivers/pwm/pwm-atmel-tcb.c
drivers/pwm/pwm-ep93xx.c [new file with mode: 0644]
drivers/pwm/pwm-imx.c
drivers/pwm/pwm-lpc32xx.c
drivers/pwm/pwm-mxs.c
drivers/pwm/pwm-samsung.c
drivers/pwm/pwm-tiecap.c
drivers/pwm/pwm-tiehrpwm.c
drivers/pwm/pwm-twl-led.c
drivers/pwm/pwm-twl.c
drivers/regulator/tps65910-regulator.c
drivers/s390/block/scm_blk.c
drivers/s390/block/scm_blk_cluster.c
drivers/s390/char/Makefile
drivers/s390/char/fs3270.c
drivers/s390/char/sclp.h
drivers/s390/char/sclp_cmd.c
drivers/s390/char/sclp_early.c [new file with mode: 0644]
drivers/s390/char/sclp_sdias.c
drivers/s390/char/sclp_sdias.h [new file with mode: 0644]
drivers/s390/char/zcore.c
drivers/s390/cio/eadm_sch.c
drivers/s390/cio/scm.c
drivers/s390/scsi/zfcp_dbf.c
drivers/scsi/aacraid/commctrl.c
drivers/scsi/arcmsr/arcmsr_hba.c
drivers/scsi/atp870u.c
drivers/scsi/bfa/bfad.c
drivers/scsi/bnx2i/bnx2i_hwi.c
drivers/scsi/bnx2i/bnx2i_iscsi.c
drivers/scsi/csiostor/csio_init.c
drivers/scsi/dc395x.c
drivers/scsi/fnic/fnic_main.c
drivers/scsi/gdth.c
drivers/scsi/hpsa.c
drivers/scsi/lpfc/lpfc_init.c
drivers/scsi/megaraid/megaraid_mbox.c
drivers/scsi/megaraid/megaraid_sas_base.c
drivers/scsi/mvsas/mv_init.c
drivers/scsi/mvsas/mv_sas.c
drivers/scsi/mvumi.c
drivers/scsi/ncr53c8xx.c
drivers/scsi/pm8001/pm8001_init.c
drivers/scsi/pmcraid.c
drivers/scsi/qla2xxx/qla_os.c
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/scsi_transport_srp.c
drivers/scsi/stex.c
drivers/scsi/sym53c8xx_2/sym_glue.h
drivers/scsi/tmscsim.c
drivers/scsi/ufs/ufshcd-pci.c
drivers/scsi/vmw_pvscsi.c
drivers/spi/spi-dw-mid.c
drivers/spi/spi.c
drivers/staging/iio/adc/ad7606.h
drivers/staging/media/lirc/TODO
drivers/staging/media/lirc/lirc_bt829.c
drivers/staging/media/lirc/lirc_serial.c
drivers/staging/media/lirc/lirc_zilog.c
drivers/staging/media/msi3101/Kconfig
drivers/staging/media/solo6x10/solo6x10-disp.c
drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
drivers/staging/media/solo6x10/solo6x10.h
drivers/thermal/thermal_core.c
drivers/tty/serial/sh-sci.c
drivers/usb/core/Kconfig
drivers/usb/core/hub.c
drivers/usb/core/usb-acpi.c
drivers/video/backlight/pwm_bl.c
drivers/video/exynos/exynos_mipi_dsi.c
drivers/watchdog/Kconfig
drivers/watchdog/Makefile
drivers/watchdog/acquirewdt.c
drivers/watchdog/advantechwdt.c
drivers/watchdog/alim1535_wdt.c
drivers/watchdog/alim7101_wdt.c
drivers/watchdog/ar7_wdt.c
drivers/watchdog/at32ap700x_wdt.c
drivers/watchdog/at91rm9200_wdt.c
drivers/watchdog/ath79_wdt.c
drivers/watchdog/bcm2835_wdt.c
drivers/watchdog/bcm63xx_wdt.c
drivers/watchdog/bfin_wdt.c
drivers/watchdog/cpu5wdt.c
drivers/watchdog/davinci_wdt.c
drivers/watchdog/dw_wdt.c
drivers/watchdog/ep93xx_wdt.c
drivers/watchdog/eurotechwdt.c
drivers/watchdog/gef_wdt.c
drivers/watchdog/geodewdt.c
drivers/watchdog/hpwdt.c
drivers/watchdog/i6300esb.c
drivers/watchdog/iTCO_wdt.c
drivers/watchdog/ib700wdt.c
drivers/watchdog/ibmasr.c
drivers/watchdog/ie6xx_wdt.c
drivers/watchdog/imx2_wdt.c
drivers/watchdog/indydog.c
drivers/watchdog/intel_scu_watchdog.c
drivers/watchdog/iop_wdt.c
drivers/watchdog/it8712f_wdt.c
drivers/watchdog/it87_wdt.c
drivers/watchdog/ixp4xx_wdt.c
drivers/watchdog/jz4740_wdt.c
drivers/watchdog/kempld_wdt.c
drivers/watchdog/ks8695_wdt.c
drivers/watchdog/lantiq_wdt.c
drivers/watchdog/m54xx_wdt.c
drivers/watchdog/machzwd.c
drivers/watchdog/max63xx_wdt.c
drivers/watchdog/mixcomwd.c
drivers/watchdog/moxart_wdt.c [new file with mode: 0644]
drivers/watchdog/mpc8xxx_wdt.c
drivers/watchdog/mtx-1_wdt.c
drivers/watchdog/mv64x60_wdt.c
drivers/watchdog/nuc900_wdt.c
drivers/watchdog/nv_tco.c
drivers/watchdog/of_xilinx_wdt.c
drivers/watchdog/omap_wdt.c
drivers/watchdog/orion_wdt.c
drivers/watchdog/pc87413_wdt.c
drivers/watchdog/pcwd.c
drivers/watchdog/pcwd_pci.c
drivers/watchdog/pcwd_usb.c
drivers/watchdog/pika_wdt.c
drivers/watchdog/pnx4008_wdt.c
drivers/watchdog/pnx833x_wdt.c
drivers/watchdog/rc32434_wdt.c
drivers/watchdog/rdc321x_wdt.c
drivers/watchdog/rt2880_wdt.c [new file with mode: 0644]
drivers/watchdog/s3c2410_wdt.c
drivers/watchdog/sa1100_wdt.c
drivers/watchdog/sb_wdog.c
drivers/watchdog/sbc60xxwdt.c
drivers/watchdog/sbc7240_wdt.c
drivers/watchdog/sbc8360.c
drivers/watchdog/sbc_epx_c3.c
drivers/watchdog/sbc_fitpc2_wdt.c
drivers/watchdog/sc1200wdt.c
drivers/watchdog/sc520_wdt.c
drivers/watchdog/sch311x_wdt.c
drivers/watchdog/scx200_wdt.c
drivers/watchdog/shwdt.c
drivers/watchdog/sirfsoc_wdt.c [new file with mode: 0644]
drivers/watchdog/smsc37b787_wdt.c
drivers/watchdog/softdog.c
drivers/watchdog/sp5100_tco.c
drivers/watchdog/sp805_wdt.c
drivers/watchdog/stmp3xxx_rtc_wdt.c
drivers/watchdog/sunxi_wdt.c
drivers/watchdog/ts72xx_wdt.c
drivers/watchdog/txx9wdt.c
drivers/watchdog/ux500_wdt.c
drivers/watchdog/w83627hf_wdt.c
drivers/watchdog/w83697hf_wdt.c
drivers/watchdog/w83697ug_wdt.c
drivers/watchdog/w83877f_wdt.c
drivers/watchdog/w83977f_wdt.c
drivers/watchdog/wafer5823wdt.c
drivers/watchdog/watchdog_core.c
drivers/watchdog/wdrtas.c
drivers/watchdog/wdt.c
drivers/watchdog/wdt285.c
drivers/watchdog/wdt977.c
drivers/watchdog/wdt_pci.c
drivers/watchdog/wm831x_wdt.c
drivers/watchdog/xen_wdt.c
drivers/xen/pci.c
fs/bio.c
fs/btrfs/Kconfig
fs/btrfs/ctree.h
fs/btrfs/ioctl.c
fs/cifs/cifsencrypt.c
fs/cifs/cifsglob.h
fs/cifs/cifspdu.h
fs/cifs/cifssmb.c
fs/cifs/dir.c
fs/cifs/file.c
fs/cifs/inode.c
fs/cifs/ioctl.c
fs/cifs/netmisc.c
fs/cifs/readdir.c
fs/cifs/smb1ops.c
fs/cifs/smb2inode.c
fs/cifs/smb2maperror.c
fs/cifs/smb2ops.c
fs/cifs/smb2pdu.c
fs/cifs/smb2pdu.h
fs/cifs/smb2proto.h
fs/dlm/netlink.c
fs/nfs/Kconfig
fs/nfs/nfs4state.c
fs/nfs/super.c
fs/nfsd/Kconfig
fs/nfsd/export.c
fs/nfsd/nfs4state.c
fs/nfsd/nfs4xdr.c
fs/nfsd/nfsfh.c
fs/quota/netlink.c
fs/seq_file.c
include/acpi/acpi_bus.h
include/asm-generic/memory_model.h
include/dt-bindings/mfd/as3722.h [new file with mode: 0644]
include/linux/acpi.h
include/linux/amba/serial.h
include/linux/blkdev.h
include/linux/devfreq.h
include/linux/device.h
include/linux/dmaengine.h
include/linux/ftrace.h
include/linux/ftrace_event.h
include/linux/genl_magic_func.h
include/linux/i2c.h
include/linux/i2c/at24.h [deleted file]
include/linux/if_macvlan.h
include/linux/irq.h
include/linux/kernel.h
include/linux/mfd/arizona/registers.h
include/linux/mfd/as3722.h [new file with mode: 0644]
include/linux/mfd/core.h
include/linux/mfd/da9052/da9052.h
include/linux/mfd/max77693-private.h
include/linux/mfd/max77693.h
include/linux/mfd/rtsx_pci.h
include/linux/mfd/si476x-core.h
include/linux/mfd/stw481x.h [new file with mode: 0644]
include/linux/mfd/syscon.h
include/linux/mfd/ti_am335x_tscadc.h
include/linux/mfd/wm8994/core.h
include/linux/mlx5/device.h
include/linux/mlx5/driver.h
include/linux/mmc/card.h
include/linux/mmc/core.h
include/linux/mmc/dw_mmc.h
include/linux/mmc/host.h
include/linux/netdevice.h
include/linux/nfs4.h
include/linux/pci-acpi.h
include/linux/platform_data/at24.h [new file with mode: 0644]
include/linux/platform_data/edma.h
include/linux/platform_data/mmc-esdhc-imx.h
include/linux/platform_data/zforce_ts.h [new file with mode: 0644]
include/linux/power/bq24735-charger.h [new file with mode: 0644]
include/linux/preempt_mask.h
include/linux/pwm_backlight.h
include/linux/sched.h
include/linux/skbuff.h
include/linux/syscalls.h
include/linux/wait.h
include/media/lm3560.h [new file with mode: 0644]
include/media/soc_camera.h
include/media/v4l2-clk.h
include/media/v4l2-common.h
include/media/v4l2-ctrls.h
include/media/v4l2-fh.h
include/media/v4l2-subdev.h
include/media/videobuf2-core.h
include/media/videobuf2-dma-sg.h
include/net/bluetooth/l2cap.h
include/net/genetlink.h
include/rdma/ib_verbs.h
include/scsi/scsi_transport_srp.h
include/trace/events/bcache.h
include/trace/events/random.h
include/trace/ftrace.h
include/uapi/linux/bcache.h [new file with mode: 0644]
include/uapi/linux/genetlink.h
include/uapi/linux/pkt_sched.h
include/uapi/linux/raid/md_p.h
include/uapi/linux/v4l2-controls.h
include/uapi/rdma/ib_user_verbs.h
init/Kconfig
kernel/bounds.c
kernel/irq/chip.c
kernel/irq/manage.c
kernel/irq/settings.h
kernel/irq/spurious.c
kernel/kexec.c
kernel/power/snapshot.c
kernel/power/user.c
kernel/rcu/tiny.c
kernel/rcu/tree.c
kernel/taskstats.c
kernel/trace/ftrace.c
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_branch.c
kernel/trace/trace_events.c
kernel/trace/trace_events_filter.c
kernel/trace/trace_export.c
kernel/trace/trace_functions_graph.c
kernel/trace/trace_kprobe.c
kernel/trace/trace_mmiotrace.c
kernel/trace/trace_sched_switch.c
kernel/trace/trace_stat.c
kernel/trace/trace_syscalls.c
kernel/trace/trace_uprobe.c
lib/random32.c
mm/Kconfig
mm/slub.c
net/bridge/br_if.c
net/bridge/br_vlan.c
net/can/af_can.c
net/core/dev.c
net/core/drop_monitor.c
net/hsr/hsr_netlink.c
net/ieee802154/6lowpan.c
net/ieee802154/dgram.c
net/ieee802154/ieee802154.h
net/ieee802154/netlink.c
net/ieee802154/nl-mac.c
net/ieee802154/nl-phy.c
net/ipv4/datagram.c
net/ipv4/ip_tunnel.c
net/ipv4/ip_vti.c
net/ipv4/ping.c
net/ipv4/raw.c
net/ipv4/tcp.c
net/ipv4/tcp_metrics.c
net/ipv4/tcp_output.c
net/ipv4/udp.c
net/ipv6/addrconf.c
net/ipv6/af_inet6.c
net/ipv6/ip6_tunnel.c
net/ipv6/ndisc.c
net/ipv6/raw.c
net/ipv6/sit.c
net/ipv6/udp.c
net/irda/irnetlink.c
net/l2tp/l2tp_ip.c
net/l2tp/l2tp_netlink.c
net/netfilter/ipvs/ip_vs_ctl.c
net/netfilter/xt_set.c
net/netlabel/netlabel_cipso_v4.c
net/netlabel/netlabel_mgmt.c
net/netlabel/netlabel_unlabeled.c
net/netlink/af_netlink.c
net/netlink/genetlink.c
net/nfc/netlink.c
net/openvswitch/datapath.c
net/openvswitch/datapath.h
net/openvswitch/dp_notify.c
net/phonet/datagram.c
net/sched/sch_fq.c
net/sctp/associola.c
net/sunrpc/auth_gss/gss_krb5_unseal.c
net/sunrpc/auth_gss/gss_krb5_wrap.c
net/sunrpc/auth_gss/gss_rpc_upcall.c
net/sunrpc/auth_gss/gss_rpc_xdr.c
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/clnt.c
net/sunrpc/svc.c
net/sunrpc/xprtsock.c
net/tipc/link.c
net/tipc/netlink.c
net/vmw_vsock/Kconfig
net/wimax/op-msg.c
net/wimax/op-reset.c
net/wimax/op-rfkill.c
net/wimax/op-state-get.c
net/wimax/stack.c
net/wimax/wimax-internal.h
net/wireless/nl80211.c
scripts/bloat-o-meter
scripts/coccinelle/api/devm_request_and_ioremap.cocci [deleted file]
scripts/kallsyms.c
scripts/kconfig/expr.h
scripts/kconfig/mconf.c
scripts/kconfig/menu.c
scripts/kconfig/qconf.cc
scripts/kconfig/qconf.h
scripts/kconfig/symbol.c
scripts/kconfig/zconf.l
scripts/kernel-doc
scripts/mod/sumversion.c
scripts/recordmcount.pl
scripts/show_delta
scripts/tags.sh
sound/aoa/fabrics/layout.c
sound/core/compress_offload.c
sound/core/jack.c
sound/drivers/pcsp/pcsp.c
sound/isa/msnd/msnd_pinnacle.c
sound/isa/wavefront/wavefront_synth.c
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_eld.c
sound/pci/hda/hda_generic.c
sound/pci/hda/patch_analog.c
sound/pci/hda/patch_cirrus.c
sound/pci/hda/patch_hdmi.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_sigmatel.c
sound/ppc/keywest.c
sound/soc/blackfin/bf5xx-i2s.c
sound/soc/codecs/alc5632.c
sound/soc/codecs/cs42l52.h
sound/soc/codecs/wm5102.c
sound/soc/codecs/wm5110.c
sound/soc/codecs/wm8962.c
sound/soc/codecs/wm8997.c
sound/soc/davinci/davinci-pcm.c
sound/soc/fsl/imx-pcm-fiq.c
sound/soc/fsl/imx-wm8962.c
sound/sparc/cs4231.c
sound/usb/mixer_quirks.c
sound/usb/stream.c
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-probe.c
tools/perf/builtin-record.c
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/config/Makefile
tools/perf/config/feature-checks/Makefile
tools/perf/config/feature-checks/test-all.c
tools/perf/tests/parse-events.c
tools/perf/ui/browser.c
tools/perf/ui/browsers/hists.c
tools/perf/util/event.c
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/machine.c
tools/perf/util/target.h
tools/perf/util/unwind.c
tools/perf/util/unwind.h
tools/power/x86/turbostat/turbostat.c

index 5c53d28f775cde36f4e77f46e41dc9ead66aa9c1..b9688de8455bb1577ef923af907bcbf86da0f0e4 100644 (file)
@@ -61,6 +61,12 @@ Description: Interface for making ib_srp connect to a new target.
                  interrupt is handled by a different CPU then the comp_vector
                  parameter can be used to spread the SRP completion workload
                  over multiple CPU's.
+               * tl_retry_count, a number in the range 2..7 specifying the
+                 IB RC retry count.
+               * queue_size, the maximum number of commands that the
+                 initiator is allowed to queue per SCSI host. The default
+                 value for this parameter is 62. The lowest supported value
+                 is 2.
 
 What:          /sys/class/infiniband_srp/srp-<hca>-<port_number>/ibdev
 Date:          January 2, 2006
@@ -153,6 +159,13 @@ Contact:   linux-rdma@vger.kernel.org
 Description:   InfiniBand service ID used for establishing communication with
                the SRP target.
 
+What:          /sys/class/scsi_host/host<n>/sgid
+Date:          February 1, 2014
+KernelVersion: 3.13
+Contact:       linux-rdma@vger.kernel.org
+Description:   InfiniBand GID of the source port used for communication with
+               the SRP target.
+
 What:          /sys/class/scsi_host/host<n>/zero_req_lim
 Date:          September 20, 2006
 KernelVersion: 2.6.18
index b36fb0dc13c8ee14a8ca8c58bd2792ee1376f657..ec7af69fea0afd9fe57f6600adc6b9be8fceb90d 100644 (file)
@@ -5,6 +5,24 @@ Contact:       linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
 Description:   Instructs an SRP initiator to disconnect from a target and to
                remove all LUNs imported from that target.
 
+What:          /sys/class/srp_remote_ports/port-<h>:<n>/dev_loss_tmo
+Date:          February 1, 2014
+KernelVersion: 3.13
+Contact:       linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
+Description:   Number of seconds the SCSI layer will wait after a transport
+               layer error has been observed before removing a target port.
+               Zero means immediate removal. Setting this attribute to "off"
+               will disable the dev_loss timer.
+
+What:          /sys/class/srp_remote_ports/port-<h>:<n>/fast_io_fail_tmo
+Date:          February 1, 2014
+KernelVersion: 3.13
+Contact:       linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
+Description:   Number of seconds the SCSI layer will wait after a transport
+               layer error has been observed before failing I/O. Zero means
+               failing I/O immediately. Setting this attribute to "off" will
+               disable the fast_io_fail timer.
+
 What:          /sys/class/srp_remote_ports/port-<h>:<n>/port_id
 Date:          June 27, 2007
 KernelVersion: 2.6.24
@@ -12,8 +30,29 @@ Contact:     linux-scsi@vger.kernel.org
 Description:   16-byte local SRP port identifier in hexadecimal format. An
                example: 4c:49:4e:55:58:20:56:49:4f:00:00:00:00:00:00:00.
 
+What:          /sys/class/srp_remote_ports/port-<h>:<n>/reconnect_delay
+Date:          February 1, 2014
+KernelVersion: 3.13
+Contact:       linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
+Description:   Number of seconds the SCSI layer will wait after a reconnect
+               attempt failed before retrying. Setting this attribute to
+               "off" will disable time-based reconnecting.
+
 What:          /sys/class/srp_remote_ports/port-<h>:<n>/roles
 Date:          June 27, 2007
 KernelVersion: 2.6.24
 Contact:       linux-scsi@vger.kernel.org
 Description:   Role of the remote port. Either "SRP Initiator" or "SRP Target".
+
+What:          /sys/class/srp_remote_ports/port-<h>:<n>/state
+Date:          February 1, 2014
+KernelVersion: 3.13
+Contact:       linux-scsi@vger.kernel.org, linux-rdma@vger.kernel.org
+Description:   State of the transport layer used for communication with the
+               remote port. "running" if the transport layer is operational;
+               "blocked" if a transport layer error has been encountered but
+               the fast_io_fail_tmo timer has not yet fired; "fail-fast"
+               after the fast_io_fail_tmo timer has fired and before the
+               "dev_loss_tmo" timer has fired; "lost" after the
+               "dev_loss_tmo" timer has fired and before the port is finally
+               removed.
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-roccat-ryos b/Documentation/ABI/testing/sysfs-driver-hid-roccat-ryos
new file mode 100644 (file)
index 0000000..1d6a8cf
--- /dev/null
@@ -0,0 +1,178 @@
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/control
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one select which data from which
+               profile will be read next. The data has to be 3 bytes long.
+               This file is writeonly.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/profile
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   The mouse can store 5 profiles which can be switched by the
+               press of a button. profile holds index of actual profile.
+               This value is persistent, so its value determines the profile
+               that's active when the device is powered on next time.
+               When written, the device activates the set profile immediately.
+               The data has to be 3 bytes long.
+               The device will reject invalid data.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/keys_primary
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the default of all keys for
+               a specific profile. Profile index is included in written data.
+               The data has to be 125 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/keys_function
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the function of the
+               function keys for a specific profile. Profile index is included
+               in written data. The data has to be 95 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/keys_macro
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the function of the macro
+               keys for a specific profile. Profile index is included in
+               written data. The data has to be 35 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/keys_thumbster
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the function of the
+               thumbster keys for a specific profile. Profile index is included
+               in written data. The data has to be 23 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/keys_extra
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the function of the
+               capslock and function keys for a specific profile. Profile index
+               is included in written data. The data has to be 8 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/keys_easyzone
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the function of the
+               easyzone keys for a specific profile. Profile index is included
+               in written data. The data has to be 294 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/key_mask
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one deactivate certain keys like
+               windows and application keys, to prevent accidental presses.
+               Profile index for which this settings occur is included in
+               written data. The data has to be 6 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/light
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the backlight intensity for
+               a specific profile. Profile index is included in written data.
+               This attribute is only valid for the glow and pro variant.
+               The data has to be 16 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/macro
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one store macros with max 480
+               keystrokes for a specific button for a specific profile.
+               Button and profile indexes are included in written data.
+               The data has to be 2002 bytes long.
+               Before reading this file, control has to be written to select
+               which profile and key to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/info
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When read, this file returns general data like firmware version.
+               The data is 8 bytes long.
+               This file is readonly.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/reset
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one reset the device.
+               The data has to be 3 bytes long.
+               This file is writeonly.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/talk
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one trigger easyshift functionality
+               from the host.
+               The data has to be 16 bytes long.
+               This file is writeonly.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/light_control
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one switch between stored and custom
+               light settings.
+               This attribute is only valid for the pro variant.
+               The data has to be 8 bytes long.
+               This file is writeonly.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/stored_lights
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set per-key lighting for different
+               layers.
+               This attribute is only valid for the pro variant.
+               The data has to be 1382 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/custom_lights
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set the actual per-key lighting.
+               This attribute is only valid for the pro variant.
+               The data has to be 20 bytes long.
+               This file is writeonly.
+Users:         http://roccat.sourceforge.net
+
+What:          /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/ryos/roccatryos<minor>/light_macro
+Date:          October 2013
+Contact:       Stefan Achatz <erazor_de@users.sourceforge.net>
+Description:   When written, this file lets one set a light macro that is looped
+               whenever the device gets in dimness mode.
+               This attribute is only valid for the pro variant.
+               The data has to be 2002 bytes long.
+               Before reading this file, control has to be written to select
+               which profile to read.
+Users:         http://roccat.sourceforge.net
index ed5dd567d397bab239a0ffe5abbe7696e24fce61..39dfa5cb1cc56c41af0ca297de0d3c003655ce2d 100644 (file)
@@ -57,3 +57,21 @@ Description: This attribute is only provided if the device was detected as a
                Calibration data is already applied by the kernel to all input
                values but may be used by user-space to perform other
                transformations.
+
+What:          /sys/bus/hid/drivers/wiimote/<dev>/pro_calib
+Date:          October 2013
+KernelVersion: 3.13
+Contact:       David Herrmann <dh.herrmann@gmail.com>
+Description:   This attribute is only provided if the device was detected as a
+               pro-controller. It provides a single line with 4 calibration
+               values for all 4 analog sticks. Format is: "x1:y1 x2:y2". Data
+               is prefixed with a +/-. Each value is a signed 16bit number.
+               Data is encoded as decimal numbers and specifies the offsets of
+               the analog sticks of the pro-controller.
+               Calibration data is already applied by the kernel to all input
+               values but may be used by user-space to perform other
+               transformations.
+               Calibration data is detected by the kernel during device setup.
+               You can write "scan\n" into this file to re-trigger calibration.
+               You can also write data directly in the form "x1:y1 x2:y2" to
+               set the calibration values manually.
index e59480db9ee0acb6be2793a9e48ea4e55d1bf5e3..cc2450d80310a5b8b0d979a23bd469c2d22ec130 100644 (file)
@@ -13,7 +13,7 @@ all pending DMA writes to complete, and thus provides a mechanism to
 strictly order DMA from a device across all intervening busses and
 bridges.  This barrier is not specific to a particular type of
 interconnect, it applies to the system as a whole, and so its
-implementation must account for the idiosyncracies of the system all
+implementation must account for the idiosyncrasies of the system all
 the way from the DMA device to memory.
 
 As an example of a situation where DMA_ATTR_WRITE_BARRIER would be
@@ -60,7 +60,7 @@ such mapping is non-trivial task and consumes very limited resources
 Buffers allocated with this attribute can be only passed to user space
 by calling dma_mmap_attrs(). By using this API, you are guaranteeing
 that you won't dereference the pointer returned by dma_alloc_attr(). You
-can threat it as a cookie that must be passed to dma_mmap_attrs() and
+can treat it as a cookie that must be passed to dma_mmap_attrs() and
 dma_free_attrs(). Make sure that both of these also get this attribute
 set on each call.
 
@@ -82,7 +82,7 @@ to 'device' domain, what synchronizes CPU caches for the given region
 (usually it means that the cache has been flushed or invalidated
 depending on the dma direction). However, next calls to
 dma_map_{single,page,sg}() for other devices will perform exactly the
-same sychronization operation on the CPU cache. CPU cache sychronization
+same synchronization operation on the CPU cache. CPU cache synchronization
 might be a time consuming operation, especially if the buffers are
 large, so it is highly recommended to avoid it if possible.
 DMA_ATTR_SKIP_CPU_SYNC allows platform code to skip synchronization of
diff --git a/Documentation/devicetree/bindings/arc/pmu.txt b/Documentation/devicetree/bindings/arc/pmu.txt
new file mode 100644 (file)
index 0000000..49d5173
--- /dev/null
@@ -0,0 +1,24 @@
+* ARC Performance Monitor Unit
+
+The ARC 700 can be configured with a pipeline performance monitor for counting
+CPU and cache events like cache misses and hits.
+
+Note that:
+ * ARC 700 refers to a family of ARC processor cores;
+   - There is only one type of PMU available for the whole family;
+   - The PMU may support different sets of events; supported events are probed
+     at boot time, as required by the reference manual.
+
+ * The ARC 700 PMU does not support interrupts; although HW events may be
+   counted, the HW events themselves cannot serve as a trigger for a sample.
+
+Required properties:
+
+- compatible : should contain
+       "snps,arc700-pmu"
+
+Example:
+
+pmu {
+        compatible = "snps,arc700-pmu";
+};
index f770ac0893d4acbfe0e412e0508317016d60a0e7..049675944b78035b5829ed94d53f5c0d2d45fc5b 100644 (file)
@@ -1,7 +1,9 @@
 Calxeda DDR memory controller
 
 Properties:
-- compatible : Should be "calxeda,hb-ddr-ctrl"
+- compatible : Should be:
+  - "calxeda,hb-ddr-ctrl" for ECX-1000
+  - "calxeda,ecx-2000-ddr-ctrl" for ECX-2000
 - reg : Address and size for DDR controller registers.
 - interrupts : Interrupt for DDR controller.
 
diff --git a/Documentation/devicetree/bindings/crypto/omap-des.txt b/Documentation/devicetree/bindings/crypto/omap-des.txt
new file mode 100644 (file)
index 0000000..e8c63bf
--- /dev/null
@@ -0,0 +1,30 @@
+OMAP SoC DES crypto Module
+
+Required properties:
+
+- compatible : Should contain "ti,omap4-des"
+- ti,hwmods: Name of the hwmod associated with the DES module
+- reg : Offset and length of the register set for the module
+- interrupts : the interrupt-specifier for the DES module
+- clocks : A phandle to the functional clock node of the DES module
+           corresponding to each entry in clock-names
+- clock-names : Name of the functional clock, should be "fck"
+
+Optional properties:
+- dmas: DMA specifiers for tx and rx dma. See the DMA client binding,
+       Documentation/devicetree/bindings/dma/dma.txt
+       Each entry corresponds to an entry in dma-names
+- dma-names: DMA request names should include "tx" and "rx" if present
+
+Example:
+       /* DRA7xx SoC */
+       des: des@480a5000 {
+               compatible = "ti,omap4-des";
+               ti,hwmods = "des";
+               reg = <0x480a5000 0xa0>;
+               interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>;
+               dmas = <&sdma 117>, <&sdma 116>;
+               dma-names = "tx", "rx";
+               clocks = <&l3_iclk_div>;
+               clock-names = "fck";
+       };
index f839acd6f0ee3af5d6c626ae0b12029580156bda..ad911556961144cb76958411c4a95a7d5dfde279 100644 (file)
@@ -6,7 +6,7 @@ Required properties:
   SHAM versions:
   - "ti,omap2-sham" for OMAP2 & OMAP3.
   - "ti,omap4-sham" for OMAP4 and AM33XX.
-  Note that these two versions are incompatible.
+  - "ti,omap5-sham" for OMAP5, DRA7 and AM43XX.
 - ti,hwmods: Name of the hwmod associated with the SHAM module
 - reg : Offset and length of the register set for the module
 - interrupts : the interrupt-specifier for the SHAM module.
index e1f343c7a34b7b10ea462a39b5e9a320ef463ba6..f69bcf5a6343bf314b5eef199999c5a676131e74 100644 (file)
@@ -28,7 +28,7 @@ The three cells in order are:
 dependent:
   - bit 7-0: peripheral identifier for the hardware handshaking interface. The
   identifier can be different for tx and rx.
-  - bit 11-8: FIFO configuration. 0 for half FIFO, 1 for ALAP, 1 for ASAP.
+  - bit 11-8: FIFO configuration. 0 for half FIFO, 1 for ALAP, 2 for ASAP.
 
 Example:
 
diff --git a/Documentation/devicetree/bindings/gpio/men-a021-wdt.txt b/Documentation/devicetree/bindings/gpio/men-a021-wdt.txt
deleted file mode 100644 (file)
index 370dee3..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-Bindings for MEN A21 Watchdog device connected to GPIO lines
-
-Required properties:
-- compatible: "men,a021-wdt"
-- gpios: Specifies the pins that control the Watchdog, order:
-  1: Watchdog enable
-  2: Watchdog fast-mode
-  3: Watchdog trigger
-  4: Watchdog reset cause bit 0
-  5: Watchdog reset cause bit 1
-  6: Watchdog reset cause bit 2
-
-Optional properties:
-- None
-
-Example:
-       watchdog {
-               compatible ="men,a021-wdt";
-               gpios = <&gpio3 9  1    /* WD_EN */
-                        &gpio3 10 1    /* WD_FAST */
-                        &gpio3 11 1    /* WD_TRIG */
-                        &gpio3 6  1    /* RST_CAUSE[0] */
-                        &gpio3 7  1    /* RST_CAUSE[1] */
-                        &gpio3 8  1>;  /* RST_CAUSE[2] */
-       };
diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
new file mode 100644 (file)
index 0000000..e863248
--- /dev/null
@@ -0,0 +1,44 @@
+* LM90 series thermometer.
+
+Required node properties:
+- compatible: manufacturer and chip name, one of
+               "adi,adm1032"
+               "adi,adt7461"
+               "adi,adt7461a"
+               "gmt,g781"
+               "national,lm90"
+               "national,lm86"
+               "national,lm89"
+               "national,lm99"
+               "dallas,max6646"
+               "dallas,max6647"
+               "dallas,max6649"
+               "dallas,max6657"
+               "dallas,max6658"
+               "dallas,max6659"
+               "dallas,max6680"
+               "dallas,max6681"
+               "dallas,max6695"
+               "dallas,max6696"
+               "onnn,nct1008"
+               "winbond,w83l771"
+               "nxp,sa56004"
+
+- reg: I2C bus address of the device
+
+- vcc-supply: vcc regulator for the supply voltage.
+
+Optional properties:
+- interrupts: Contains a single interrupt specifier which describes the
+              LM90 "-ALERT" pin output.
+              See interrupt-controller/interrupts.txt for the format.
+
+Example LM90 node:
+
+temp-sensor {
+       compatible = "onnn,nct1008";
+       reg = <0x4c>;
+       vcc-supply = <&palmas_ldo6_reg>;
+       interrupt-parent = <&gpio>;
+       interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
+}
diff --git a/Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt b/Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt
new file mode 100644 (file)
index 0000000..1b87b74
--- /dev/null
@@ -0,0 +1,35 @@
+Broadcom Kona Family I2C
+=========================
+
+This I2C controller is used in the following Broadcom SoCs:
+
+  BCM11130
+  BCM11140
+  BCM11351
+  BCM28145
+  BCM28155
+
+Required Properties
+-------------------
+- compatible: "brcm,bcm11351-i2c", "brcm,kona-i2c"
+- reg: Physical base address and length of controller registers
+- interrupts: The interrupt number used by the controller
+- clocks: clock specifier for the kona i2c external clock
+- clock-frequency: The I2C bus frequency in Hz
+- #address-cells: Should be <1>
+- #size-cells: Should be <0>
+
+Refer to clocks/clock-bindings.txt for generic clock consumer
+properties.
+
+Example:
+
+i2c@3e016000 {
+       compatible = "brcm,bcm11351-i2c","brcm,kona-i2c";
+       reg = <0x3e016000 0x80>;
+       interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+       clocks = <&bsc1_clk>;
+       clock-frequency = <400000>;
+       #address-cells = <1>;
+       #size-cells = <0>;
+};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-exynos5.txt b/Documentation/devicetree/bindings/i2c/i2c-exynos5.txt
new file mode 100644 (file)
index 0000000..056732c
--- /dev/null
@@ -0,0 +1,44 @@
+* Samsung's High Speed I2C controller
+
+The Samsung's High Speed I2C controller is used to interface with I2C devices
+at various speeds ranging from 100khz to 3.4Mhz.
+
+Required properties:
+  - compatible: value should be.
+      -> "samsung,exynos5-hsi2c", for i2c compatible with exynos5 hsi2c.
+  - reg: physical base address of the controller and length of memory mapped
+    region.
+  - interrupts: interrupt number to the cpu.
+  - #address-cells: always 1 (for i2c addresses)
+  - #size-cells: always 0
+
+  - Pinctrl:
+    - pinctrl-0: Pin control group to be used for this controller.
+    - pinctrl-names: Should contain only one value - "default".
+
+Optional properties:
+  - clock-frequency: Desired operating frequency in Hz of the bus.
+    -> If not specified, the bus operates in fast-speed mode at
+       at 100khz.
+    -> If specified, the bus operates in high-speed mode only if the
+       clock-frequency is >= 1Mhz.
+
+Example:
+
+hsi2c@12ca0000 {
+       compatible = "samsung,exynos5-hsi2c";
+       reg = <0x12ca0000 0x100>;
+       interrupts = <56>;
+       clock-frequency = <100000>;
+
+       pinctrl-0 = <&i2c4_bus>;
+       pinctrl-names = "default";
+
+       #address-cells = <1>;
+       #size-cells = <0>;
+
+       s2mps11_pmic@66 {
+               compatible = "samsung,s2mps11-pmic";
+               reg = <0x66>;
+       };
+};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-rcar.txt b/Documentation/devicetree/bindings/i2c/i2c-rcar.txt
new file mode 100644 (file)
index 0000000..897cfcd
--- /dev/null
@@ -0,0 +1,23 @@
+I2C for R-Car platforms
+
+Required properties:
+- compatible: Must be one of
+       "renesas,i2c-rcar"
+       "renesas,i2c-r8a7778"
+       "renesas,i2c-r8a7779"
+       "renesas,i2c-r8a7790"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: interrupt specifier.
+
+Optional properties:
+- clock-frequency: desired I2C bus clock frequency in Hz. The absence of this
+  propoerty indicates the default frequency 100 kHz.
+
+Examples :
+
+i2c0: i2c@e6500000 {
+       compatible = "renesas,i2c-rcar-h2";
+       reg = <0 0xe6500000 0 0x428>;
+       interrupts = <0 174 0x4>;
+};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-st.txt b/Documentation/devicetree/bindings/i2c/i2c-st.txt
new file mode 100644 (file)
index 0000000..437e0db
--- /dev/null
@@ -0,0 +1,41 @@
+ST SSC binding, for I2C mode operation
+
+Required properties :
+- compatible : Must be "st,comms-ssc-i2c" or "st,comms-ssc4-i2c"
+- reg : Offset and length of the register set for the device
+- interrupts : the interrupt specifier
+- clock-names: Must contain "ssc".
+- clocks: Must contain an entry for each name in clock-names. See the common
+  clock bindings.
+- A pinctrl state named "default" must be defined to set pins in mode of
+  operation for I2C transfer.
+
+Optional properties :
+- clock-frequency : Desired I2C bus clock frequency in Hz. If not specified,
+  the default 100 kHz frequency will be used. As only Normal and Fast modes
+  are supported, possible values are 100000 and 400000.
+- st,i2c-min-scl-pulse-width-us : The minimum valid SCL pulse width that is
+  allowed through the deglitch circuit. In units of us.
+- st,i2c-min-sda-pulse-width-us : The minimum valid SDA pulse width that is
+  allowed through the deglitch circuit. In units of us.
+- A pinctrl state named "idle" could be defined to set pins in idle state
+  when I2C instance is not performing a transfer.
+- A pinctrl state named "sleep" could be defined to set pins in sleep state
+  when driver enters in suspend.
+
+
+
+Example :
+
+i2c0: i2c@fed40000 {
+       compatible      = "st,comms-ssc4-i2c";
+       reg             = <0xfed40000 0x110>;
+       interrupts      =  <GIC_SPI 187 IRQ_TYPE_LEVEL_HIGH>;
+       clocks          = <&CLK_S_ICN_REG_0>;
+       clock-names     = "ssc";
+       clock-frequency = <400000>;
+       pinctrl-names   = "default";
+       pinctrl-0       = <&pinctrl_i2c0_default>;
+       st,i2c-min-scl-pulse-width-us = <0>;
+       st,i2c-min-sda-pulse-width-us = <5>;
+};
index 491c97b783843c733444c60c00e0c7cf41843138..878549ba814d5d1684ff2b5a960bc1725854e3f2 100644 (file)
@@ -6,7 +6,7 @@ Required properties:
        ti,wires: Wires refer to application modes i.e. 4/5/8 wire touchscreen
                  support on the platform.
        ti,x-plate-resistance: X plate resistance
-       ti,coordiante-readouts: The sequencer supports a total of 16
+       ti,coordinate-readouts: The sequencer supports a total of 16
                                programmable steps each step is used to
                                read a single coordinate. A single
                                 readout is enough but multiple reads can
diff --git a/Documentation/devicetree/bindings/media/st-rc.txt b/Documentation/devicetree/bindings/media/st-rc.txt
new file mode 100644 (file)
index 0000000..05c432d
--- /dev/null
@@ -0,0 +1,29 @@
+Device-Tree bindings for ST IRB IP
+
+Required properties:
+       - compatible: Should contain "st,comms-irb".
+       - reg: Base physical address of the controller and length of memory
+         mapped region.
+       - interrupts: interrupt-specifier for the sole interrupt generated by
+         the device. The interrupt specifier format depends on the interrupt
+         controller parent.
+       - rx-mode: can be "infrared" or "uhf". This property specifies the L1
+         protocol used for receiving remote control signals. rx-mode should
+         be present iff the rx pins are wired up.
+       - tx-mode: should be "infrared". This property specifies the L1
+         protocol used for transmitting remote control signals. tx-mode should
+         be present iff the tx pins are wired up.
+
+Optional properties:
+       - pinctrl-names, pinctrl-0: the pincontrol settings to configure muxing
+         properly for IRB pins.
+       - clocks : phandle with clock-specifier pair for IRB.
+
+Example node:
+
+       rc: rc@fe518000 {
+               compatible      = "st,comms-irb";
+               reg             = <0xfe518000 0x234>;
+               interrupts      = <0 203 0>;
+               rx-mode         = "infrared";
+       };
diff --git a/Documentation/devicetree/bindings/mfd/as3722.txt b/Documentation/devicetree/bindings/mfd/as3722.txt
new file mode 100644 (file)
index 0000000..fc2191e
--- /dev/null
@@ -0,0 +1,194 @@
+* ams AS3722 Power management IC.
+
+Required properties:
+-------------------
+- compatible: Must be "ams,as3722".
+- reg: I2C device address.
+- interrupt-controller: AS3722 has internal interrupt controller which takes the
+  interrupt request from internal sub-blocks like RTC, regulators, GPIOs as well
+  as external input.
+- #interrupt-cells: Should be set to 2 for IRQ number and flags.
+  The first cell is the IRQ number. IRQ numbers for different interrupt source
+  of AS3722 are defined at dt-bindings/mfd/as3722.h
+  The second cell is the flags, encoded as the trigger masks from binding document
+       interrupts.txt, using dt-bindings/irq.
+
+Optional submodule and their properties:
+=======================================
+
+Pinmux and GPIO:
+===============
+Device has 8 GPIO pins which can be configured as GPIO as well as the special IO
+functions.
+
+Please refer to pinctrl-bindings.txt in this directory for details of the
+common pinctrl bindings used by client devices, including the meaning of the
+phrase "pin configuration node".
+
+Following are properties which is needed if GPIO and pinmux functionality
+is required:
+    Required properties:
+    -------------------
+       - gpio-controller: Marks the device node as a GPIO controller.
+       - #gpio-cells: Number of GPIO cells. Refer to binding document
+                       gpio/gpio.txt
+
+    Optional properties:
+    --------------------
+       Following properties are require if pin control setting is required
+       at boot.
+       - pinctrl-names: A pinctrl state named "default" be defined, using the
+               bindings in pinctrl/pinctrl-binding.txt.
+       - pinctrl[0...n]: Properties to contain the phandle that refer to
+               different nodes of pin control settings. These nodes represents
+               the pin control setting of state 0 to state n. Each of these
+               nodes contains different subnodes to represents some desired
+               configuration for a list of pins. This configuration can
+               include the mux function to select on those pin(s), and
+               various pin configuration parameters, such as pull-up,
+               open drain.
+
+               Each subnode have following properties:
+               Required properties:
+                   - pins: List of pins. Valid values of pins properties are:
+                               gpio0, gpio1, gpio2, gpio3, gpio4, gpio5,
+                               gpio6, gpio7
+
+               Optional properties:
+                       function, bias-disable, bias-pull-up, bias-pull-down,
+                       bias-high-impedance, drive-open-drain.
+
+                       Valid values for function properties are:
+                               gpio, interrupt-out, gpio-in-interrupt,
+                               vsup-vbat-low-undebounce-out,
+                               vsup-vbat-low-debounce-out,
+                               voltage-in-standby, oc-pg-sd0, oc-pg-sd6,
+                               powergood-out, pwm-in, pwm-out, clk32k-out,
+                               watchdog-in, soft-reset-in
+
+Regulators:
+===========
+Device has multiple DCDC and LDOs. The node "regulators" is require if regulator
+functionality is needed.
+
+Following are properties of regulator subnode.
+
+    Optional properties:
+    -------------------
+       The input supply of regulators are the optional properties on the
+       regulator node. The input supply of these regulators are provided
+       through following properties:
+               vsup-sd2-supply: Input supply for SD2.
+               vsup-sd3-supply: Input supply for SD3.
+               vsup-sd4-supply: Input supply for SD4.
+               vsup-sd5-supply: Input supply for SD5.
+               vin-ldo0-supply: Input supply for LDO0.
+               vin-ldo1-6-supply: Input supply for LDO1 and LDO6.
+               vin-ldo2-5-7-supply: Input supply for LDO2, LDO5 and LDO7.
+               vin-ldo3-4-supply: Input supply for LDO3 and LDO4.
+               vin-ldo9-10-supply: Input supply for LDO9 and LDO10.
+               vin-ldo11-supply: Input supply for LDO11.
+
+    Optional sub nodes for regulators:
+    ---------------------------------
+       The subnodes name is the name of regulator and it must be one of:
+       sd[0-6], ldo[0-7], ldo[9-11]
+
+       Each sub-node should contain the constraints and initialization
+       information for that regulator. See regulator.txt for a description
+       of standard properties for these sub-nodes.
+       Additional optional custom properties  are listed below.
+               ams,ext-control: External control of the rail. The option of
+                       this properties will tell which external input is
+                       controlling this rail. Valid values are 0, 1, 2 ad 3.
+                       0: There is no external control of this rail.
+                       1: Rail is controlled by ENABLE1 input pin.
+                       2: Rail is controlled by ENABLE2 input pin.
+                       3: Rail is controlled by ENABLE3 input pin.
+                       Missing this property on DT will be assume as no
+                       external control. The external control pin macros
+                       are defined @dt-bindings/mfd/as3722.h
+
+               ams,enable-tracking: Enable tracking with SD1, only supported
+                       by LDO3.
+
+Example:
+--------
+#include <dt-bindings/mfd/as3722.h>
+...
+ams3722 {
+       compatible = "ams,as3722";
+       reg = <0x48>;
+
+       interrupt-parent = <&intc>;
+       interrupt-controller;
+       #interrupt-cells = <2>;
+
+       gpio-controller;
+       #gpio-cells = <2>;
+
+       pinctrl-names = "default";
+       pinctrl-0 = <&as3722_default>;
+
+       as3722_default: pinmux {
+                       gpio0 {
+                               pins = "gpio0";
+                               function = "gpio";
+                               bias-pull-down;
+                       };
+
+                       gpio1_2_4_7 {
+                               pins = "gpio1", "gpio2", "gpio4", "gpio7";
+                               function = "gpio";
+                               bias-pull-up;
+                       };
+
+                       gpio5 {
+                               pins = "gpio5";
+                               function = "clk32k_out";
+                       };
+       }
+
+       regulators {
+                       vsup-sd2-supply = <...>;
+                       ...
+
+                       sd0 {
+                               regulator-name = "vdd_cpu";
+                               regulator-min-microvolt = <700000>;
+                               regulator-max-microvolt = <1400000>;
+                               regulator-always-on;
+                               ams,ext-control = <2>;
+                       };
+
+                       sd1 {
+                               regulator-name = "vdd_core";
+                               regulator-min-microvolt = <700000>;
+                               regulator-max-microvolt = <1400000>;
+                               regulator-always-on;
+                               ams,ext-control = <1>;
+                       };
+
+                       sd2 {
+                               regulator-name = "vddio_ddr";
+                               regulator-min-microvolt = <1350000>;
+                               regulator-max-microvolt = <1350000>;
+                               regulator-always-on;
+                       };
+
+                       sd4 {
+                               regulator-name = "avdd-hdmi-pex";
+                               regulator-min-microvolt = <1050000>;
+                               regulator-max-microvolt = <1050000>;
+                               regulator-always-on;
+                       };
+
+                       sd5 {
+                               regulator-name = "vdd-1v8";
+                               regulator-min-microvolt = <1800000>;
+                               regulator-max-microvolt = <1800000>;
+                               regulator-always-on;
+                       };
+                       ....
+       };
+};
index c9332c6260214bf8d4e065b05257dbb10f669c53..78a840d7510d27ab51eb892542318e01a6bc3774 100644 (file)
@@ -1,10 +1,10 @@
 
 * Samsung S2MPS11 Voltage and Current Regulator
 
-The Samsung S2MP211 is a multi-function device which includes voltage and
+The Samsung S2MPS11 is a multi-function device which includes voltage and
 current regulators, RTC, charger controller and other sub-blocks. It is
-interfaced to the host controller using a I2C interface. Each sub-block is
-addressed by the host system using different I2C slave address.
+interfaced to the host controller using an I2C interface. Each sub-block is
+addressed by the host system using different I2C slave addresses.
 
 Required properties:
 - compatible: Should be "samsung,s2mps11-pmic".
@@ -43,7 +43,8 @@ sub-node should be of the format as listed below.
 
  BUCK[2/3/4/6] supports disabling ramp delay on hardware, so explictly
  regulator-ramp-delay = <0> can be used for them to disable ramp delay.
- In absence of regulator-ramp-delay property, default ramp delay will be used.
+ In the absence of the regulator-ramp-delay property, the default ramp
+ delay will be used.
 
 NOTE: Some BUCKs share the ramp rate setting i.e. same ramp value will be set
 for a particular group of BUCKs. So provide same regulator-ramp-delay<value>.
@@ -58,10 +59,10 @@ supports. Note: The 'n' in LDOn and BUCKn represents the LDO or BUCK number
 as per the datasheet of s2mps11.
 
        - LDOn
-                 - valid values for n are 1 to 28
+                 - valid values for n are 1 to 38
                  - Example: LDO0, LD01, LDO28
        - BUCKn
-                 - valid values for n are 1 to 9.
+                 - valid values for n are 1 to 10.
                  - Example: BUCK1, BUCK2, BUCK9
 
 Example:
index 1dd622546d06b711bf262358b387b4bb9af3f68a..9046ba06c47ab63570f99769455dcfeeea020e10 100644 (file)
@@ -12,6 +12,11 @@ Required properties:
 Optional properties:
 - fsl,cd-controller : Indicate to use controller internal card detection
 - fsl,wp-controller : Indicate to use controller internal write protection
+- fsl,delay-line : Specify the number of delay cells for override mode.
+  This is used to set the clock delay for DLL(Delay Line) on override mode
+  to select a proper data sampling window in case the clock quality is not good
+  due to signal path is too long on the board. Please refer to eSDHC/uSDHC
+  chapter, DLL (Delay Line) section in RM for details.
 
 Examples:
 
index 066a78b034ca8589e4de4d31183075768496f81a..8f3f13315358028f20a5a79720e6a27266caf2be 100644 (file)
@@ -52,6 +52,9 @@ Optional properties:
   is specified and the ciu clock is specified then we'll try to set the ciu
   clock to this at probe time.
 
+* clock-freq-min-max: Minimum and Maximum clock frequency for card output
+  clock(cclk_out). If it's not specified, max is 200MHZ and min is 400KHz by default.
+
 * num-slots: specifies the number of slots supported by the controller.
   The number of physical slots actually used could be equal or less than the
   value specified by num-slots. If this property is not specified, the value
@@ -66,6 +69,10 @@ Optional properties:
 
 * supports-highspeed: Enables support for high speed cards (up to 50MHz)
 
+* caps2-mmc-hs200-1_8v: Supports mmc HS200 SDR 1.8V mode
+
+* caps2-mmc-hs200-1_2v: Supports mmc HS200 SDR 1.2V mode
+
 * broken-cd: as documented in mmc core bindings.
 
 * vmmc-supply: The phandle to the regulator to use for vmmc.  If this is
@@ -93,8 +100,10 @@ board specific portions as listed below.
 
        dwmmc0@12200000 {
                clock-frequency = <400000000>;
+               clock-freq-min-max = <400000 200000000>;
                num-slots = <1>;
                supports-highspeed;
+               caps2-mmc-hs200-1_8v;
                broken-cd;
                fifo-depth = <0x80>;
                card-detect-delay = <200>;
diff --git a/Documentation/devicetree/bindings/power/twl-charger.txt b/Documentation/devicetree/bindings/power/twl-charger.txt
new file mode 100644 (file)
index 0000000..d5c7062
--- /dev/null
@@ -0,0 +1,20 @@
+TWL BCI (Battery Charger Interface)
+
+Required properties:
+- compatible:
+  - "ti,twl4030-bci"
+- interrupts: two interrupt lines from the TWL SIH (secondary
+  interrupt handler) - interrupts 9 and 2.
+
+Optional properties:
+- ti,bb-uvolt: microvolts for charging the backup battery.
+- ti,bb-uamp: microamps for charging the backup battery.
+
+Examples:
+
+bci {
+   compatible = "ti,twl4030-bci";
+   interrupts = <9>, <2>;
+   ti,bb-uvolt = <3200000>;
+   ti,bb-uamp = <150>;
+};
diff --git a/Documentation/devicetree/bindings/power_supply/ti,bq24735.txt b/Documentation/devicetree/bindings/power_supply/ti,bq24735.txt
new file mode 100644 (file)
index 0000000..4f6a550
--- /dev/null
@@ -0,0 +1,32 @@
+TI BQ24735 Charge Controller
+~~~~~~~~~~
+
+Required properties :
+ - compatible : "ti,bq24735"
+
+Optional properties :
+ - interrupts : Specify the interrupt to be used to trigger when the AC
+   adapter is either plugged in or removed.
+ - ti,ac-detect-gpios : This GPIO is optionally used to read the AC adapter
+   presence. This is a Host GPIO that is configured as an input and
+   connected to the bq24735.
+ - ti,charge-current : Used to control and set the charging current. This value
+   must be between 128mA and 8.128A with a 64mA step resolution. The POR value
+   is 0x0000h. This number is in mA (e.g. 8192), see spec for more information
+   about the ChargeCurrent (0x14h) register.
+ - ti,charge-voltage : Used to control and set the charging voltage. This value
+   must be between 1.024V and 19.2V with a 16mV step resolution. The POR value
+   is 0x0000h. This number is in mV (e.g. 19200), see spec for more information
+   about the ChargeVoltage (0x15h) register.
+ - ti,input-current : Used to control and set the charger input current. This
+   value must be between 128mA and 8.064A with a 128mA step resolution. The
+   POR value is 0x1000h. This number is in mA (e.g. 8064), see the spec for
+   more information about the InputCurrent (0x3fh) register.
+
+Example:
+
+       bq24735@9 {
+               compatible = "ti,bq24735";
+               reg = <0x9>;
+               ti,ac-detect-gpios = <&gpio 72 0x1>;
+       }
index 2a4b4bce6110af59579c6f29e36fb8bcd71f7428..7fc1b010fa759a9cb69ab286b4ca032d295f0046 100644 (file)
@@ -1,33 +1,30 @@
-* Freescale 83xx DMA Controller
+* Freescale DMA Controllers
 
-Freescale PowerPC 83xx have on chip general purpose DMA controllers.
+** Freescale Elo DMA Controller
+   This is a little-endian 4-channel DMA controller, used in Freescale mpc83xx
+   series chips such as mpc8315, mpc8349, mpc8379 etc.
 
 Required properties:
 
-- compatible        : compatible list, contains 2 entries, first is
-                "fsl,CHIP-dma", where CHIP is the processor
-                (mpc8349, mpc8360, etc.) and the second is
-                "fsl,elo-dma"
-- reg               : <registers mapping for DMA general status reg>
-- ranges               : Should be defined as specified in 1) to describe the
-                 DMA controller channels.
+- compatible        : must include "fsl,elo-dma"
+- reg               : DMA General Status Register, i.e. DGSR which contains
+                      status for all the 4 DMA channels
+- ranges            : describes the mapping between the address space of the
+                      DMA channels and the address space of the DMA controller
 - cell-index        : controller index.  0 for controller @ 0x8100
-- interrupts        : <interrupt mapping for DMA IRQ>
+- interrupts        : interrupt specifier for DMA IRQ
 - interrupt-parent  : optional, if needed for interrupt mapping
 
-
 - DMA channel nodes:
-        - compatible        : compatible list, contains 2 entries, first is
-                        "fsl,CHIP-dma-channel", where CHIP is the processor
-                        (mpc8349, mpc8350, etc.) and the second is
-                        "fsl,elo-dma-channel". However, see note below.
-        - reg               : <registers mapping for channel>
-        - cell-index        : dma channel index starts at 0.
+        - compatible        : must include "fsl,elo-dma-channel"
+                              However, see note below.
+        - reg               : DMA channel specific registers
+        - cell-index        : DMA channel index starts at 0.
 
 Optional properties:
-        - interrupts        : <interrupt mapping for DMA channel IRQ>
-                         (on 83xx this is expected to be identical to
-                          the interrupts property of the parent node)
+        - interrupts        : interrupt specifier for DMA channel IRQ
+                              (on 83xx this is expected to be identical to
+                              the interrupts property of the parent node)
         - interrupt-parent  : optional, if needed for interrupt mapping
 
 Example:
@@ -70,30 +67,27 @@ Example:
                };
        };
 
-* Freescale 85xx/86xx DMA Controller
-
-Freescale PowerPC 85xx/86xx have on chip general purpose DMA controllers.
+** Freescale EloPlus DMA Controller
+   This is a 4-channel DMA controller with extended addresses and chaining,
+   mainly used in Freescale mpc85xx/86xx, Pxxx and BSC series chips, such as
+   mpc8540, mpc8641 p4080, bsc9131 etc.
 
 Required properties:
 
-- compatible        : compatible list, contains 2 entries, first is
-                "fsl,CHIP-dma", where CHIP is the processor
-                (mpc8540, mpc8540, etc.) and the second is
-                "fsl,eloplus-dma"
-- reg               : <registers mapping for DMA general status reg>
+- compatible        : must include "fsl,eloplus-dma"
+- reg               : DMA General Status Register, i.e. DGSR which contains
+                      status for all the 4 DMA channels
 - cell-index        : controller index.  0 for controller @ 0x21000,
                                          1 for controller @ 0xc000
-- ranges               : Should be defined as specified in 1) to describe the
-                 DMA controller channels.
+- ranges            : describes the mapping between the address space of the
+                      DMA channels and the address space of the DMA controller
 
 - DMA channel nodes:
-        - compatible        : compatible list, contains 2 entries, first is
-                        "fsl,CHIP-dma-channel", where CHIP is the processor
-                        (mpc8540, mpc8560, etc.) and the second is
-                        "fsl,eloplus-dma-channel". However, see note below.
-        - cell-index        : dma channel index starts at 0.
-        - reg               : <registers mapping for channel>
-        - interrupts        : <interrupt mapping for DMA channel IRQ>
+        - compatible        : must include "fsl,eloplus-dma-channel"
+                              However, see note below.
+        - cell-index        : DMA channel index starts at 0.
+        - reg               : DMA channel specific registers
+        - interrupts        : interrupt specifier for DMA channel IRQ
         - interrupt-parent  : optional, if needed for interrupt mapping
 
 Example:
@@ -134,6 +128,76 @@ Example:
                };
        };
 
+** Freescale Elo3 DMA Controller
+   DMA controller which has same function as EloPlus except that Elo3 has 8
+   channels while EloPlus has only 4, it is used in Freescale Txxx and Bxxx
+   series chips, such as t1040, t4240, b4860.
+
+Required properties:
+
+- compatible        : must include "fsl,elo3-dma"
+- reg               : contains two entries for DMA General Status Registers,
+                      i.e. DGSR0 which includes status for channel 1~4, and
+                      DGSR1 for channel 5~8
+- ranges            : describes the mapping between the address space of the
+                      DMA channels and the address space of the DMA controller
+
+- DMA channel nodes:
+        - compatible        : must include "fsl,eloplus-dma-channel"
+        - reg               : DMA channel specific registers
+        - interrupts        : interrupt specifier for DMA channel IRQ
+        - interrupt-parent  : optional, if needed for interrupt mapping
+
+Example:
+dma@100300 {
+       #address-cells = <1>;
+       #size-cells = <1>;
+       compatible = "fsl,elo3-dma";
+       reg = <0x100300 0x4>,
+             <0x100600 0x4>;
+       ranges = <0x0 0x100100 0x500>;
+       dma-channel@0 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x0 0x80>;
+               interrupts = <28 2 0 0>;
+       };
+       dma-channel@80 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x80 0x80>;
+               interrupts = <29 2 0 0>;
+       };
+       dma-channel@100 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x100 0x80>;
+               interrupts = <30 2 0 0>;
+       };
+       dma-channel@180 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x180 0x80>;
+               interrupts = <31 2 0 0>;
+       };
+       dma-channel@300 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x300 0x80>;
+               interrupts = <76 2 0 0>;
+       };
+       dma-channel@380 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x380 0x80>;
+               interrupts = <77 2 0 0>;
+       };
+       dma-channel@400 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x400 0x80>;
+               interrupts = <78 2 0 0>;
+       };
+       dma-channel@480 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x480 0x80>;
+               interrupts = <79 2 0 0>;
+       };
+};
+
 Note on DMA channel compatible properties: The compatible property must say
 "fsl,elo-dma-channel" or "fsl,eloplus-dma-channel" to be used by the Elo DMA
 driver (fsldma).  Any DMA channel used by fsldma cannot be used by another
index d61fccd40bad42a746374c29f8589891bb75621f..5538de9c20077566c4dec8243fcba0f78778f4fc 100644 (file)
@@ -15,7 +15,7 @@ Required properties:
     samsung,s5pc100-pwm - for 32-bit timers present on S5PC100, S5PV210,
                          Exynos4210 rev0 SoCs
     samsung,exynos4210-pwm - for 32-bit timers present on Exynos4210,
-                          Exynos4x12 and Exynos5250 SoCs
+                          Exynos4x12, Exynos5250 and Exynos5420 SoCs
 - reg: base address and size of register area
 - interrupts: list of timer interrupts (one interrupt per timer, starting at
   timer 0)
index 4c85c4c69584a14d39dd8597facb920b4b69cf46..2ba5f9c023acb93be4e8089fd3c817a44cd08bc7 100644 (file)
@@ -2,8 +2,8 @@ OMAP2+ McSPI device
 
 Required properties:
 - compatible :
-  - "ti,omap2-spi" for OMAP2 & OMAP3.
-  - "ti,omap4-spi" for OMAP4+.
+  - "ti,omap2-mcspi" for OMAP2 & OMAP3.
+  - "ti,omap4-mcspi" for OMAP4+.
 - ti,spi-num-cs : Number of chipselect supported  by the instance.
 - ti,hwmods: Name of the hwmod associated to the McSPI
 - ti,pindir-d0-out-d1-in: Select the D0 pin as output and D1 as
index 1e4fc727f3b180f84242a3d77b3854ad113b4a60..764db86d441ad131aceca0e15146d5c914d97919 100644 (file)
@@ -10,12 +10,16 @@ Required properties:
       last value in the array represents a 100% duty cycle (brightest).
   - default-brightness-level: the default brightness level (index into the
       array defined by the "brightness-levels" property)
+  - power-supply: regulator for supply voltage
 
 Optional properties:
   - pwm-names: a list of names for the PWM devices specified in the
                "pwms" property (see PWM binding[0])
+  - enable-gpios: contains a single GPIO specifier for the GPIO which enables
+                  and disables the backlight (see GPIO binding[1])
 
 [0]: Documentation/devicetree/bindings/pwm/pwm.txt
+[1]: Documentation/devicetree/bindings/gpio/gpio.txt
 
 Example:
 
@@ -25,4 +29,7 @@ Example:
 
                brightness-levels = <0 4 8 16 32 64 128 255>;
                default-brightness-level = <6>;
+
+               power-supply = <&vdd_bl_reg>;
+               enable-gpios = <&gpio 58 0>;
        };
diff --git a/Documentation/devicetree/bindings/watchdog/dw_wdt.txt b/Documentation/devicetree/bindings/watchdog/dw_wdt.txt
new file mode 100644 (file)
index 0000000..08e16f6
--- /dev/null
@@ -0,0 +1,21 @@
+Synopsys Designware Watchdog Timer
+
+Required Properties:
+
+- compatible   : Should contain "snps,dw-wdt"
+- reg          : Base address and size of the watchdog timer registers.
+- clocks       : phandle + clock-specifier for the clock that drives the
+               watchdog timer.
+
+Optional Properties:
+
+- interrupts   : The interrupt used for the watchdog timeout warning.
+
+Example:
+
+       watchdog0: wd@ffd02000 {
+               compatible = "snps,dw-wdt";
+               reg = <0xffd02000 0x1000>;
+               interrupts = <0 171 4>;
+               clocks = <&per_base_clk>;
+       };
diff --git a/Documentation/devicetree/bindings/watchdog/men-a021-wdt.txt b/Documentation/devicetree/bindings/watchdog/men-a021-wdt.txt
new file mode 100644 (file)
index 0000000..370dee3
--- /dev/null
@@ -0,0 +1,25 @@
+Bindings for MEN A21 Watchdog device connected to GPIO lines
+
+Required properties:
+- compatible: "men,a021-wdt"
+- gpios: Specifies the pins that control the Watchdog, order:
+  1: Watchdog enable
+  2: Watchdog fast-mode
+  3: Watchdog trigger
+  4: Watchdog reset cause bit 0
+  5: Watchdog reset cause bit 1
+  6: Watchdog reset cause bit 2
+
+Optional properties:
+- None
+
+Example:
+       watchdog {
+               compatible ="men,a021-wdt";
+               gpios = <&gpio3 9  1    /* WD_EN */
+                        &gpio3 10 1    /* WD_FAST */
+                        &gpio3 11 1    /* WD_TRIG */
+                        &gpio3 6  1    /* RST_CAUSE[0] */
+                        &gpio3 7  1    /* RST_CAUSE[1] */
+                        &gpio3 8  1>;  /* RST_CAUSE[2] */
+       };
diff --git a/Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt b/Documentation/devicetree/bindings/watchdog/moxa,moxart-watchdog.txt
new file mode 100644 (file)
index 0000000..1169857
--- /dev/null
@@ -0,0 +1,15 @@
+MOXA ART Watchdog timer
+
+Required properties:
+
+- compatible : Must be "moxa,moxart-watchdog"
+- reg : Should contain registers location and length
+- clocks : Should contain phandle for the clock that drives the counter
+
+Example:
+
+       watchdog: watchdog@98500000 {
+               compatible = "moxa,moxart-watchdog";
+               reg = <0x98500000 0x10>;
+               clocks = <&coreclk>;
+       };
diff --git a/Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt b/Documentation/devicetree/bindings/watchdog/rt2880-wdt.txt
new file mode 100644 (file)
index 0000000..d7bab3d
--- /dev/null
@@ -0,0 +1,19 @@
+Ralink Watchdog Timers
+
+Required properties:
+- compatible: must be "ralink,rt2880-wdt"
+- reg: physical base address of the controller and length of the register range
+
+Optional properties:
+- interrupt-parent: phandle to the INTC device node
+- interrupts: Specify the INTC interrupt number
+
+Example:
+
+       watchdog@120 {
+               compatible = "ralink,rt2880-wdt";
+               reg = <0x120 0x10>;
+
+               interrupt-parent = <&intc>;
+               interrupts = <1>;
+       };
diff --git a/Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt b/Documentation/devicetree/bindings/watchdog/sirfsoc_wdt.txt
new file mode 100644 (file)
index 0000000..9cbc76c
--- /dev/null
@@ -0,0 +1,14 @@
+SiRFSoC Timer and Watchdog Timer(WDT) Controller
+
+Required properties:
+- compatible: "sirf,prima2-tick"
+- reg: Address range of tick timer/WDT register set
+- interrupts: interrupt number to the cpu
+
+Example:
+
+timer@b0020000 {
+       compatible = "sirf,prima2-tick";
+       reg = <0xb0020000 0x1000>;
+       interrupts = <0>;
+};
index a2b5663eae266d2dcae8fcf9400ef9eb16b24709..dd77a81bdb80b82b5c732ceb33ba2ef30b1d9eea 100644 (file)
@@ -15,39 +15,48 @@ be built as module or inside kernel. Let's consider those cases.
 
        Part 2 - When dmatest is built as a module...
 
-After mounting debugfs and loading the module, the /sys/kernel/debug/dmatest
-folder with nodes will be created. There are two important files located. First
-is the 'run' node that controls run and stop phases of the test, and the second
-one, 'results', is used to get the test case results.
-
-Note that in this case test will not run on load automatically.
-
 Example of usage:
+       % modprobe dmatest channel=dma0chan0 timeout=2000 iterations=1 run=1
+
+...or:
+       % modprobe dmatest
        % echo dma0chan0 > /sys/module/dmatest/parameters/channel
        % echo 2000 > /sys/module/dmatest/parameters/timeout
        % echo 1 > /sys/module/dmatest/parameters/iterations
-       % echo 1 > /sys/kernel/debug/dmatest/run
+       % echo 1 > /sys/module/dmatest/parameters/run
+
+...or on the kernel command line:
+
+       dmatest.channel=dma0chan0 dmatest.timeout=2000 dmatest.iterations=1 dmatest.run=1
 
 Hint: available channel list could be extracted by running the following
 command:
        % ls -1 /sys/class/dma/
 
-After a while you will start to get messages about current status or error like
-in the original code.
+Once started a message like "dmatest: Started 1 threads using dma0chan0" is
+emitted.  After that only test failure messages are reported until the test
+stops.
 
 Note that running a new test will not stop any in progress test.
 
-The following command should return actual state of the test.
-       % cat /sys/kernel/debug/dmatest/run
-
-To wait for test done the user may perform a busy loop that checks the state.
-
-       % while [ $(cat /sys/kernel/debug/dmatest/run) = "Y" ]
-       > do
-       >       echo -n "."
-       >       sleep 1
-       > done
-       > echo
+The following command returns the state of the test.
+       % cat /sys/module/dmatest/parameters/run
+
+To wait for test completion userpace can poll 'run' until it is false, or use
+the wait parameter.  Specifying 'wait=1' when loading the module causes module
+initialization to pause until a test run has completed, while reading
+/sys/module/dmatest/parameters/wait waits for any running test to complete
+before returning.  For example, the following scripts wait for 42 tests
+to complete before exiting.  Note that if 'iterations' is set to 'infinite' then
+waiting is disabled.
+
+Example:
+       % modprobe dmatest run=1 iterations=42 wait=1
+       % modprobe -r dmatest
+...or:
+       % modprobe dmatest run=1 iterations=42
+       % cat /sys/module/dmatest/parameters/wait
+       % modprobe -r dmatest
 
        Part 3 - When built-in in the kernel...
 
@@ -62,21 +71,22 @@ case. You always could check them at run-time by running
 
        Part 4 - Gathering the test results
 
-The module provides a storage for the test results in the memory. The gathered
-data could be used after test is done.
+Test results are printed to the kernel log buffer with the format:
 
-The special file 'results' in the debugfs represents gathered data of the in
-progress test. The messages collected are printed to the kernel log as well.
+"dmatest: result <channel>: <test id>: '<error msg>' with src_off=<val> dst_off=<val> len=<val> (<err code>)"
 
 Example of output:
-       % cat /sys/kernel/debug/dmatest/results
-       dma0chan0-copy0: #1: No errors with src_off=0x7bf dst_off=0x8ad len=0x3fea (0)
+       % dmesg | tail -n 1
+       dmatest: result dma0chan0-copy0: #1: No errors with src_off=0x7bf dst_off=0x8ad len=0x3fea (0)
 
 The message format is unified across the different types of errors. A number in
 the parens represents additional information, e.g. error code, error counter,
-or status.
+or status.  A test thread also emits a summary line at completion listing the
+number of tests executed, number that failed, and a result code.
 
-Comparison between buffers is stored to the dedicated structure.
+Example:
+       % dmesg | tail -n 1
+       dmatest: dma0chan0-copy0: summary 1 test, 0 failures 1000 iops 100000 KB/s (0)
 
-Note that the verify result is now accessible only via file 'results' in the
-debugfs.
+The details of a data miscompare error are also emitted, but do not follow the
+above format.
index b466974e142fc3e288c993697455b24020ece1ce..ab81013cc3907a45ffb039a1f72a98d83f1b46b8 100644 (file)
@@ -122,6 +122,12 @@ Supported chips:
     Prefix: 'g781'
     Addresses scanned: I2C 0x4c, 0x4d
     Datasheet: Not publicly available from GMT
+  * Texas Instruments TMP451
+    Prefix: 'tmp451'
+    Addresses scanned: I2C 0x4c
+    Datasheet: Publicly available at TI website
+               http://www.ti.com/litv/pdf/sbos686
+
 
 Author: Jean Delvare <khali@linux-fr.org>
 
index d29dea0f323287a3617205de7f12880e706a0cd8..7b0dcdb57173ce2246303c2f20eec1e94a5c6b8b 100644 (file)
@@ -25,6 +25,7 @@ Supported adapters:
   * Intel Avoton (SOC)
   * Intel Wellsburg (PCH)
   * Intel Coleto Creek (PCH)
+  * Intel Wildcat Point-LP (PCH)
    Datasheets: Publicly available at the Intel website
 
 On Intel Patsburg and later chipsets, both the normal host SMBus controller
index 8002c894c6b052f3dc8443b82a69ec2ba36faae1..31bb6a4029ef84863a8f1341e023ed8961142a23 100644 (file)
@@ -122,12 +122,14 @@ D-Pad:
       BTN_DPAD_*
     Analog buttons are reported as:
       ABS_HAT0X and ABS_HAT0Y
+      (for ABS values negative is left/up, positive is right/down)
 
 Analog-Sticks:
   The left analog-stick is reported as ABS_X, ABS_Y. The right analog stick is
   reported as ABS_RX, ABS_RY. Zero, one or two sticks may be present.
   If analog-sticks provide digital buttons, they are mapped accordingly as
   BTN_THUMBL (first/left) and BTN_THUMBR (second/right).
+    (for ABS values negative is left/up, positive is right/down)
 
 Triggers:
   Trigger buttons can be available as digital or analog buttons or both. User-
@@ -138,6 +140,7 @@ Triggers:
   ABS_HAT2X (right/ZR) and BTN_TL2 or ABS_HAT2Y (left/ZL).
   If only one trigger-button combination is present (upper+lower), they are
   reported as "right" triggers (BTN_TR/ABS_HAT1X).
+    (ABS trigger values start at 0, pressure is reported as positive values)
 
 Menu-Pad:
   Menu buttons are always digital and are mapped according to their location
index 8ef6dbb6a462d707401fe08289dfa51702125789..bbc99c0c1094949d8dd36f68f2516e8fb879b0e4 100644 (file)
@@ -20,16 +20,9 @@ symbols have been introduced.
 To see a list of new config symbols when using "make oldconfig", use
 
        cp user/some/old.config .config
-       yes "" | make oldconfig >conf.new
+       make listnewconfig
 
-and the config program will list as (NEW) any new symbols that have
-unknown values.  Of course, the .config file is also updated with
-new (default) values, so you can use:
-
-       grep "(NEW)" conf.new
-
-to see the new config symbols or you can use diffconfig to see the
-differences between the previous and new .config files:
+and the config program will list any new symbols, one per line.
 
        scripts/diffconfig .config.old .config | less
 
index 8b8a0578764112c1dacc4a719f454c676c09100c..3c12d9a7ed00391d5c3f49ef80d7b1ae9abc40fe 100644 (file)
@@ -577,9 +577,6 @@ tcp_limit_output_bytes - INTEGER
        typical pfifo_fast qdiscs.
        tcp_limit_output_bytes limits the number of bytes on qdisc
        or device to reduce artificial RTT/cwnd and reduce bufferbloat.
-       Note: For GSO/TSO enabled flows, we try to have at least two
-       packets in flight. Reducing tcp_limit_output_bytes might also
-       reduce the size of individual GSO packet (64KB being the max)
        Default: 131072
 
 tcp_challenge_ack_limit - INTEGER
index 3f10b39b034639cd558e080d289ed361c7ea63f7..89a8816990ffbdc1b5be616427f8977f802db38a 100644 (file)
@@ -135,11 +135,11 @@ CAPACITY_LEVEL - capacity level. This corresponds to
 POWER_SUPPLY_CAPACITY_LEVEL_*.
 
 TEMP - temperature of the power supply.
-TEMP_ALERT_MIN - minimum battery temperature alert value in milli centigrade.
-TEMP_ALERT_MAX - maximum battery temperature alert value in milli centigrade.
+TEMP_ALERT_MIN - minimum battery temperature alert.
+TEMP_ALERT_MAX - maximum battery temperature alert.
 TEMP_AMBIENT - ambient temperature.
-TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert value in milli centigrade.
-TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert value in milli centigrade.
+TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert.
+TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert.
 
 TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
 while battery powers a load)
index 0f54333b0ff2990ce090f88087e17417a894b46c..b6ce00b2be9ae9682c6821bfb70175e42cc75e57 100644 (file)
@@ -547,13 +547,11 @@ helper functions described in Section 4.  In that case, pm_runtime_resume()
 should be used.  Of course, for this purpose the device's runtime PM has to be
 enabled earlier by calling pm_runtime_enable().
 
-If the device bus type's or driver's ->probe() callback runs
-pm_runtime_suspend() or pm_runtime_idle() or their asynchronous counterparts,
-they will fail returning -EAGAIN, because the device's usage counter is
-incremented by the driver core before executing ->probe().  Still, it may be
-desirable to suspend the device as soon as ->probe() has finished, so the driver
-core uses pm_runtime_put_sync() to invoke the subsystem-level idle callback for
-the device at that time.
+It may be desirable to suspend the device once ->probe() has finished.
+Therefore the driver core uses the asyncronous pm_request_idle() to submit a
+request to execute the subsystem-level idle callback for the device at that
+time.  A driver that makes use of the runtime autosuspend feature, may want to
+update the last busy mark before returning from ->probe().
 
 Moreover, the driver core prevents runtime PM callbacks from racing with the bus
 notifier callback in __device_release_driver(), which is necessary, because the
@@ -656,7 +654,7 @@ out the following operations:
     __pm_runtime_disable() with 'false' as the second argument for every device
     right before executing the subsystem-level .suspend_late() callback for it.
 
-  * During system resume it calls pm_runtime_enable() and pm_runtime_put_sync()
+  * During system resume it calls pm_runtime_enable() and pm_runtime_put()
     for every device right after executing the subsystem-level .resume_early()
     callback and right after executing the subsystem-level .resume() callback
     for it, respectively.
index 1039b68fe9c62aa773f4e90e68613870c0cd9db3..93cb979749860f323bb797ce2adc2923d629e1ed 100644 (file)
@@ -39,7 +39,7 @@ New users should use the pwm_get() function and pass to it the consumer
 device or a consumer name. pwm_put() is used to free the PWM device. Managed
 variants of these functions, devm_pwm_get() and devm_pwm_put(), also exist.
 
-After being requested a PWM has to be configured using:
+After being requested, a PWM has to be configured using:
 
 int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
 
@@ -94,7 +94,7 @@ for new drivers to use the generic PWM framework.
 A new PWM controller/chip can be added using pwmchip_add() and removed
 again with pwmchip_remove(). pwmchip_add() takes a filled in struct
 pwm_chip as argument which provides a description of the PWM chip, the
-number of PWM devices provider by the chip and the chip-specific
+number of PWM devices provided by the chip and the chip-specific
 implementation of the supported PWM operations to the framework.
 
 Locking
index a9248da5cdbc1a0c7b60031f6d0677d726e532ec..ef2ccbf77fa2d4e8b8152d844d3a24de8fb54045 100644 (file)
@@ -8,5 +8,9 @@ hpet_example.c
        - sample hpet timer test program
 hrtimers.txt
        - subsystem for high-resolution kernel timers
+NO_HZ.txt
+       - Summary of the different methods for the scheduler clock-interrupts management.
+timers-howto.txt
+       - how to insert delays in the kernel the right (tm) way.
 timer_stats.txt
        - timer usage statistics
index 8ec2a67c39b7c6a1114e75563fd980717155103f..4cf53e40661392438cf54d0edda07c87f0ac8e4f 100644 (file)
@@ -26,7 +26,7 @@ Linux provides a number of functions for gadgets to use.
 Creating a gadget means deciding what configurations there will be
 and which functions each configuration will provide.
 
-Configfs (please see Documentation/filesystems/configfs/*) lends itslef nicely
+Configfs (please see Documentation/filesystems/configfs/*) lends itself nicely
 for the purpose of telling the kernel about the above mentioned decision.
 This document is about how to do it.
 
@@ -99,7 +99,7 @@ directories must be created:
 $ mkdir configs/<name>.<number>
 
 where <name> can be any string which is legal in a filesystem and the
-<numebr> is the configuration's number, e.g.:
+<number> is the configuration's number, e.g.:
 
 $ mkdir configs/c.1
 
@@ -327,7 +327,7 @@ from the buffer to the cs), but it is up to the implementer of the
 two functions to decide what they actually do.
 
 typedef struct configured_structure cs;
-typedef struc specific_attribute sa;
+typedef struct specific_attribute sa;
 
                                        sa
                        +----------------------------------+
index 5481c8ba34122df7d89ccc16f732174b987c699a..a39d06680e1c1a738437dfafdb36f1fda29b2f66 100644 (file)
@@ -4,10 +4,12 @@ active_mm.txt
        - An explanation from Linus about tsk->active_mm vs tsk->mm.
 balance
        - various information on memory balancing.
-hugepage-mmap.c
-       - Example app using huge page memory with the mmap system call.
-hugepage-shm.c
-       - Example app using huge page memory with Sys V shared memory system calls.
+cleancache.txt
+       - Intro to cleancache and page-granularity victim cache.
+frontswap.txt
+       - Outline frontswap, part of the transcendent memory frontend.
+highmem.txt
+       - Outline of highmem and common issues.
 hugetlbpage.txt
        - a brief summary of hugetlbpage support in the Linux kernel.
 hwpoison.txt
@@ -16,21 +18,23 @@ ksm.txt
        - how to use the Kernel Samepage Merging feature.
 locking
        - info on how locking and synchronization is done in the Linux vm code.
-map_hugetlb.c
-       - an example program that uses the MAP_HUGETLB mmap flag.
 numa
        - information about NUMA specific code in the Linux vm.
 numa_memory_policy.txt
        - documentation of concepts and APIs of the 2.6 memory policy support.
 overcommit-accounting
        - description of the Linux kernels overcommit handling modes.
-page-types.c
-       - Tool for querying page flags
 page_migration
        - description of page migration in NUMA systems.
 pagemap.txt
        - pagemap, from the userspace perspective
 slub.txt
        - a short users guide for SLUB.
+soft-dirty.txt
+       - short explanation for soft-dirty PTEs
+transhuge.txt
+       - Transparent Hugepage Support, alternative way of using hugepages.
 unevictable-lru.txt
        - Unevictable LRU infrastructure
+zswap.txt
+       - Intro to compressed cache for swap pages
index d2270c070c0fa91f7ec0e679e59f728b633b32d3..63f30484932b1cddbe5f9c5bd05ca6473d612e0b 100644 (file)
@@ -1070,7 +1070,6 @@ S:        Maintained
 ARM/NOMADIK ARCHITECTURE
 M:     Alessandro Rubini <rubini@unipv.it>
 M:     Linus Walleij <linus.walleij@linaro.org>
-M:     STEricsson <STEricsson_nomadik_linux@list.st.com>
 L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
 S:     Maintained
 F:     arch/arm/mach-nomadik/
@@ -1426,7 +1425,7 @@ M:        Wolfram Sang <wsa@the-dreams.de>
 L:     linux-i2c@vger.kernel.org
 S:     Maintained
 F:     drivers/misc/eeprom/at24.c
-F:     include/linux/i2c/at24.h
+F:     include/linux/platform_data/at24.h
 
 ATA OVER ETHERNET (AOE) DRIVER
 M:     "Ed L. Cashin" <ecashin@coraid.com>
@@ -2469,7 +2468,7 @@ S:        Maintained
 F:     drivers/media/dvb-frontends/cxd2820r*
 
 CXGB3 ETHERNET DRIVER (CXGB3)
-M:     Divy Le Ray <divy@chelsio.com>
+M:     Santosh Raspatur <santosh@chelsio.com>
 L:     netdev@vger.kernel.org
 W:     http://www.chelsio.com
 S:     Supported
@@ -3064,6 +3063,14 @@ W:       bluesmoke.sourceforge.net
 S:     Maintained
 F:     drivers/edac/amd64_edac*
 
+EDAC-CALXEDA
+M:     Doug Thompson <dougthompson@xmission.com>
+M:     Robert Richter <rric@kernel.org>
+L:     linux-edac@vger.kernel.org
+W:     bluesmoke.sourceforge.net
+S:     Maintained
+F:     drivers/edac/highbank*
+
 EDAC-CAVIUM
 M:     Ralf Baechle <ralf@linux-mips.org>
 M:     David Daney <david.daney@cavium.com>
@@ -3145,6 +3152,13 @@ W:       bluesmoke.sourceforge.net
 S:     Maintained
 F:     drivers/edac/i82975x_edac.c
 
+EDAC-MPC85XX
+M:     Johannes Thumshirn <johannes.thumshirn@men.de>
+L:     linux-edac@vger.kernel.org
+W:     bluesmoke.sourceforge.net
+S:     Maintained
+F:     drivers/edac/mpc85xx_edac.[ch]
+
 EDAC-PASEMI
 M:     Egor Martovetsky <egor@pasemi.com>
 L:     linux-edac@vger.kernel.org
@@ -4808,9 +4822,10 @@ S:       Maintained
 F:     drivers/staging/ktap/
 
 KCONFIG
-M:     Michal Marek <mmarek@suse.cz>
+M:     "Yann E. MORIN" <yann.morin.1998@free.fr>
 L:     linux-kbuild@vger.kernel.org
-S:     Odd Fixes
+T:     git://gitorious.org/linux-kconfig/linux-kconfig
+S:     Maintained
 F:     Documentation/kbuild/kconfig-language.txt
 F:     scripts/kconfig/
 
@@ -5214,6 +5229,7 @@ M:        Jean Delvare <khali@linux-fr.org>
 L:     lm-sensors@lm-sensors.org
 S:     Maintained
 F:     Documentation/hwmon/lm90
+F:     Documentation/devicetree/bindings/hwmon/lm90.txt
 F:     drivers/hwmon/lm90.c
 
 LM95234 HARDWARE MONITOR DRIVER
@@ -6783,8 +6799,7 @@ PWM SUBSYSTEM
 M:     Thierry Reding <thierry.reding@gmail.com>
 L:     linux-pwm@vger.kernel.org
 S:     Maintained
-W:     http://gitorious.org/linux-pwm
-T:     git git://gitorious.org/linux-pwm/linux-pwm.git
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git
 F:     Documentation/pwm.txt
 F:     Documentation/devicetree/bindings/pwm/
 F:     include/linux/pwm.h
@@ -8945,8 +8960,8 @@ USB PEGASUS DRIVER
 M:     Petko Manolov <petkan@nucleusys.com>
 L:     linux-usb@vger.kernel.org
 L:     netdev@vger.kernel.org
-T:     git git://git.code.sf.net/p/pegasus2/git
-W:     http://pegasus2.sourceforge.net/
+T:     git git://github.com/petkan/pegasus.git
+W:     https://github.com/petkan/pegasus
 S:     Maintained
 F:     drivers/net/usb/pegasus.*
 
@@ -8967,8 +8982,8 @@ USB RTL8150 DRIVER
 M:     Petko Manolov <petkan@nucleusys.com>
 L:     linux-usb@vger.kernel.org
 L:     netdev@vger.kernel.org
-T:     git git://git.code.sf.net/p/pegasus2/git
-W:     http://pegasus2.sourceforge.net/
+T:     git git://github.com/petkan/rtl8150.git
+W:     https://github.com/petkan/rtl8150
 S:     Maintained
 F:     drivers/net/usb/rtl8150.c
 
index 606a66cdcdb88e6e1b7d214dc7f87921c59e025d..920ad07180c9c7157c2ca3b5b1175059eb3e8b8e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,9 @@ LC_COLLATE=C
 LC_NUMERIC=C
 export LC_COLLATE LC_NUMERIC
 
+# Avoid interference with shell env settings
+unexport GREP_OPTIONS
+
 # We are using a recursive build, so we need to do a little thinking
 # to get the ordering right.
 #
@@ -659,6 +662,12 @@ KBUILD_CFLAGS      += $(call cc-option,-fno-strict-overflow)
 # conserve stack if available
 KBUILD_CFLAGS   += $(call cc-option,-fconserve-stack)
 
+# disallow errors like 'EXPORT_GPL(foo);' with missing header
+KBUILD_CFLAGS   += $(call cc-option,-Werror=implicit-int)
+
+# require functions to have arguments in prototypes, not empty 'int foo()'
+KBUILD_CFLAGS   += $(call cc-option,-Werror=strict-prototypes)
+
 # use the deterministic mode of AR if available
 KBUILD_ARFLAGS := $(call ar-option,D)
 
index 8d2a4833acda7519b79a5d84436b6e0562dfd933..135c674eaf9ec3383b309e7869ea261841a82fe4 100644 (file)
@@ -1,6 +1,7 @@
 config ALPHA
        bool
        default y
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select HAVE_AOUT
        select HAVE_IDE
        select HAVE_OPROFILE
index 52cd2a4a3ff486c8e7acefb35c6e6d24a911f025..453597b91f3a6560320524e4ef7a4338a5ae8e10 100644 (file)
@@ -58,8 +58,6 @@ register struct thread_info *__current_thread_info __asm__("$8");
 #define THREAD_SIZE_ORDER 1
 #define THREAD_SIZE (2*PAGE_SIZE)
 
-#define PREEMPT_ACTIVE         0x40000000
-
 /*
  * Thread information flags:
  * - these are process state flags and used from assembly
index d9f8249aa66e0033fa95c5c66b04d6e5f8ef641b..3942634f805ade1545d30dd066d2ba88cdec3cac 100644 (file)
                iomux: iomux@FF10601c {
                        /* Port 1 */
                        pctl_tsin_s0: pctl-tsin-s0 {   /* Serial TS-in 0 */
-                               pingrp = "mis0_pins";
+                               abilis,function = "mis0";
                        };
                        pctl_tsin_s1: pctl-tsin-s1 {   /* Serial TS-in 1 */
-                               pingrp = "mis1_pins";
+                               abilis,function = "mis1";
                        };
                        pctl_gpio_a: pctl-gpio-a {     /* GPIO bank A */
-                               pingrp = "gpioa_pins";
+                               abilis,function = "gpioa";
                        };
                        pctl_tsin_p1: pctl-tsin-p1 {   /* Parallel TS-in 1 */
-                               pingrp = "mip1_pins";
+                               abilis,function = "mip1";
                        };
                        /* Port 2 */
                        pctl_tsin_s2: pctl-tsin-s2 {   /* Serial TS-in 2 */
-                               pingrp = "mis2_pins";
+                               abilis,function = "mis2";
                        };
                        pctl_tsin_s3: pctl-tsin-s3 {   /* Serial TS-in 3 */
-                               pingrp = "mis3_pins";
+                               abilis,function = "mis3";
                        };
                        pctl_gpio_c: pctl-gpio-c {     /* GPIO bank C */
-                               pingrp = "gpioc_pins";
+                               abilis,function = "gpioc";
                        };
                        pctl_tsin_p3: pctl-tsin-p3 {   /* Parallel TS-in 3 */
-                               pingrp = "mip3_pins";
+                               abilis,function = "mip3";
                        };
                        /* Port 3 */
                        pctl_tsin_s4: pctl-tsin-s4 {   /* Serial TS-in 4 */
-                               pingrp = "mis4_pins";
+                               abilis,function = "mis4";
                        };
                        pctl_tsin_s5: pctl-tsin-s5 {   /* Serial TS-in 5 */
-                               pingrp = "mis5_pins";
+                               abilis,function = "mis5";
                        };
                        pctl_gpio_e: pctl-gpio-e {     /* GPIO bank E */
-                               pingrp = "gpioe_pins";
+                               abilis,function = "gpioe";
                        };
                        pctl_tsin_p5: pctl-tsin-p5 {   /* Parallel TS-in 5 */
-                               pingrp = "mip5_pins";
+                               abilis,function = "mip5";
                        };
                        /* Port 4 */
                        pctl_tsin_s6: pctl-tsin-s6 {   /* Serial TS-in 6 */
-                               pingrp = "mis6_pins";
+                               abilis,function = "mis6";
                        };
                        pctl_tsin_s7: pctl-tsin-s7 {   /* Serial TS-in 7 */
-                               pingrp = "mis7_pins";
+                               abilis,function = "mis7";
                        };
                        pctl_gpio_g: pctl-gpio-g {     /* GPIO bank G */
-                               pingrp = "gpiog_pins";
+                               abilis,function = "gpiog";
                        };
                        pctl_tsin_p7: pctl-tsin-p7 {   /* Parallel TS-in 7 */
-                               pingrp = "mip7_pins";
+                               abilis,function = "mip7";
                        };
                        /* Port 5 */
                        pctl_gpio_j: pctl-gpio-j {     /* GPIO bank J */
-                               pingrp = "gpioj_pins";
+                               abilis,function = "gpioj";
                        };
                        pctl_gpio_k: pctl-gpio-k {     /* GPIO bank K */
-                               pingrp = "gpiok_pins";
+                               abilis,function = "gpiok";
                        };
                        pctl_ciplus: pctl-ciplus {     /* CI+ interface */
-                               pingrp = "ciplus_pins";
+                               abilis,function = "ciplus";
                        };
                        pctl_mcard: pctl-mcard {       /* M-Card interface */
-                               pingrp = "mcard_pins";
+                               abilis,function = "mcard";
                        };
                        /* Port 6 */
                        pctl_tsout_p: pctl-tsout-p {   /* Parallel TS-out */
-                               pingrp = "mop_pins";
+                               abilis,function = "mop";
                        };
                        pctl_tsout_s0: pctl-tsout-s0 { /* Serial TS-out 0 */
-                               pingrp = "mos0_pins";
+                               abilis,function = "mos0";
                        };
                        pctl_tsout_s1: pctl-tsout-s1 { /* Serial TS-out 1 */
-                               pingrp = "mos1_pins";
+                               abilis,function = "mos1";
                        };
                        pctl_tsout_s2: pctl-tsout-s2 { /* Serial TS-out 2 */
-                               pingrp = "mos2_pins";
+                               abilis,function = "mos2";
                        };
                        pctl_tsout_s3: pctl-tsout-s3 { /* Serial TS-out 3 */
-                               pingrp = "mos3_pins";
+                               abilis,function = "mos3";
                        };
                        /* Port 7 */
                        pctl_uart0: pctl-uart0 {       /* UART 0 */
-                               pingrp = "uart0_pins";
+                               abilis,function = "uart0";
                        };
                        pctl_uart1: pctl-uart1 {       /* UART 1 */
-                               pingrp = "uart1_pins";
+                               abilis,function = "uart1";
                        };
                        pctl_gpio_l: pctl-gpio-l {     /* GPIO bank L */
-                               pingrp = "gpiol_pins";
+                               abilis,function = "gpiol";
                        };
                        pctl_gpio_m: pctl-gpio-m {     /* GPIO bank M */
-                               pingrp = "gpiom_pins";
+                               abilis,function = "gpiom";
                        };
                        /* Port 8 */
                        pctl_spi3: pctl-spi3 {
-                               pingrp = "spi3_pins";
+                               abilis,function = "spi3";
                        };
                        /* Port 9 */
                        pctl_spi1: pctl-spi1 {
-                               pingrp = "spi1_pins";
+                               abilis,function = "spi1";
                        };
                        pctl_gpio_n: pctl-gpio-n {
-                               pingrp = "gpion_pins";
+                               abilis,function = "gpion";
                        };
                        /* Unmuxed GPIOs */
                        pctl_gpio_b: pctl-gpio-b {
-                               pingrp = "gpiob_pins";
+                               abilis,function = "gpiob";
                        };
                        pctl_gpio_d: pctl-gpio-d {
-                               pingrp = "gpiod_pins";
+                               abilis,function = "gpiod";
                        };
                        pctl_gpio_f: pctl-gpio-f {
-                               pingrp = "gpiof_pins";
+                               abilis,function = "gpiof";
                        };
                        pctl_gpio_h: pctl-gpio-h {
-                               pingrp = "gpioh_pins";
+                               abilis,function = "gpioh";
                        };
                        pctl_gpio_i: pctl-gpio-i {
-                               pingrp = "gpioi_pins";
+                               abilis,function = "gpioi";
                        };
                };
 
                        interrupts = <27 2>;
                        reg = <0xFF140000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <0>;
-                       gpio-pins = <&pctl_gpio_a>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioa";
                };
                gpiob: gpio@FF141000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF141000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <3>;
-                       gpio-pins = <&pctl_gpio_b>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiob";
                };
                gpioc: gpio@FF142000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF142000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <5>;
-                       gpio-pins = <&pctl_gpio_c>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioc";
                };
                gpiod: gpio@FF143000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF143000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <8>;
-                       gpio-pins = <&pctl_gpio_d>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiod";
                };
                gpioe: gpio@FF144000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF144000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <10>;
-                       gpio-pins = <&pctl_gpio_e>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioe";
                };
                gpiof: gpio@FF145000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF145000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <13>;
-                       gpio-pins = <&pctl_gpio_f>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiof";
                };
                gpiog: gpio@FF146000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF146000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <15>;
-                       gpio-pins = <&pctl_gpio_g>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiog";
                };
                gpioh: gpio@FF147000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF147000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <18>;
-                       gpio-pins = <&pctl_gpio_h>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioh";
                };
                gpioi: gpio@FF148000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF148000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <20>;
-                       gpio-pins = <&pctl_gpio_i>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <12>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioi";
                };
                gpioj: gpio@FF149000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF149000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <32>;
-                       gpio-pins = <&pctl_gpio_j>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <32>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioj";
                };
                gpiok: gpio@FF14a000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14A000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <64>;
-                       gpio-pins = <&pctl_gpio_k>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <22>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiok";
                };
                gpiol: gpio@FF14b000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14B000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <86>;
-                       gpio-pins = <&pctl_gpio_l>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <4>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiol";
                };
                gpiom: gpio@FF14c000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14C000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <90>;
-                       gpio-pins = <&pctl_gpio_m>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <4>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiom";
                };
                gpion: gpio@FF14d000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14D000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <94>;
-                       gpio-pins = <&pctl_gpio_n>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <5>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpion";
                };
        };
 };
index ebc313a9f5b248df51352f909697afca5cc9e88f..3dd6ed941464ac663e76330b43ee0e3d588cdf87 100644 (file)
                        compatible = "gpio-leds";
                        power {
                                label = "Power";
-                               gpios = <&gpioi 0>;
+                               gpios = <&gpioi 0 0>;
                                linux,default-trigger = "default-on";
                        };
                        heartbeat {
                                label = "Heartbeat";
-                               gpios = <&gpioi 1>;
+                               gpios = <&gpioi 1 0>;
                                linux,default-trigger = "heartbeat";
                        };
                        led2 {
                                label = "LED2";
-                               gpios = <&gpioi 2>;
+                               gpios = <&gpioi 2 0>;
                                default-state = "off";
                        };
                        led3 {
                                label = "LED3";
-                               gpios = <&gpioi 3>;
+                               gpios = <&gpioi 3 0>;
                                default-state = "off";
                        };
                        led4 {
                                label = "LED4";
-                               gpios = <&gpioi 4>;
+                               gpios = <&gpioi 4 0>;
                                default-state = "off";
                        };
                        led5 {
                                label = "LED5";
-                               gpios = <&gpioi 5>;
+                               gpios = <&gpioi 5 0>;
                                default-state = "off";
                        };
                        led6 {
                                label = "LED6";
-                               gpios = <&gpioi 6>;
+                               gpios = <&gpioi 6 0>;
                                default-state = "off";
                        };
                        led7 {
                                label = "LED7";
-                               gpios = <&gpioi 7>;
+                               gpios = <&gpioi 7 0>;
                                default-state = "off";
                        };
                        led8 {
                                label = "LED8";
-                               gpios = <&gpioi 8>;
+                               gpios = <&gpioi 8 0>;
                                default-state = "off";
                        };
                        led9 {
                                label = "LED9";
-                               gpios = <&gpioi 9>;
+                               gpios = <&gpioi 9 0>;
                                default-state = "off";
                        };
                        led10 {
                                label = "LED10";
-                               gpios = <&gpioi 10>;
+                               gpios = <&gpioi 10 0>;
                                default-state = "off";
                        };
                        led11 {
                                label = "LED11";
-                               gpios = <&gpioi 11>;
+                               gpios = <&gpioi 11 0>;
                                default-state = "off";
                        };
                };
index da8ca7941e6741493dcfa0a71d62961d754571ef..b0467229a5c45e9c10eb1cc2884b84b33ef2e603 100644 (file)
                iomux: iomux@FF10601c {
                        /* Port 1 */
                        pctl_tsin_s0: pctl-tsin-s0 {   /* Serial TS-in 0 */
-                               pingrp = "mis0_pins";
+                               abilis,function = "mis0";
                        };
                        pctl_tsin_s1: pctl-tsin-s1 {   /* Serial TS-in 1 */
-                               pingrp = "mis1_pins";
+                               abilis,function = "mis1";
                        };
                        pctl_gpio_a: pctl-gpio-a {     /* GPIO bank A */
-                               pingrp = "gpioa_pins";
+                               abilis,function = "gpioa";
                        };
                        pctl_tsin_p1: pctl-tsin-p1 {   /* Parallel TS-in 1 */
-                               pingrp = "mip1_pins";
+                               abilis,function = "mip1";
                        };
                        /* Port 2 */
                        pctl_tsin_s2: pctl-tsin-s2 {   /* Serial TS-in 2 */
-                               pingrp = "mis2_pins";
+                               abilis,function = "mis2";
                        };
                        pctl_tsin_s3: pctl-tsin-s3 {   /* Serial TS-in 3 */
-                               pingrp = "mis3_pins";
+                               abilis,function = "mis3";
                        };
                        pctl_gpio_c: pctl-gpio-c {     /* GPIO bank C */
-                               pingrp = "gpioc_pins";
+                               abilis,function = "gpioc";
                        };
                        pctl_tsin_p3: pctl-tsin-p3 {   /* Parallel TS-in 3 */
-                               pingrp = "mip3_pins";
+                               abilis,function = "mip3";
                        };
                        /* Port 3 */
                        pctl_tsin_s4: pctl-tsin-s4 {   /* Serial TS-in 4 */
-                               pingrp = "mis4_pins";
+                               abilis,function = "mis4";
                        };
                        pctl_tsin_s5: pctl-tsin-s5 {   /* Serial TS-in 5 */
-                               pingrp = "mis5_pins";
+                               abilis,function = "mis5";
                        };
                        pctl_gpio_e: pctl-gpio-e {     /* GPIO bank E */
-                               pingrp = "gpioe_pins";
+                               abilis,function = "gpioe";
                        };
                        pctl_tsin_p5: pctl-tsin-p5 {   /* Parallel TS-in 5 */
-                               pingrp = "mip5_pins";
+                               abilis,function = "mip5";
                        };
                        /* Port 4 */
                        pctl_tsin_s6: pctl-tsin-s6 {   /* Serial TS-in 6 */
-                               pingrp = "mis6_pins";
+                               abilis,function = "mis6";
                        };
                        pctl_tsin_s7: pctl-tsin-s7 {   /* Serial TS-in 7 */
-                               pingrp = "mis7_pins";
+                               abilis,function = "mis7";
                        };
                        pctl_gpio_g: pctl-gpio-g {     /* GPIO bank G */
-                               pingrp = "gpiog_pins";
+                               abilis,function = "gpiog";
                        };
                        pctl_tsin_p7: pctl-tsin-p7 {   /* Parallel TS-in 7 */
-                               pingrp = "mip7_pins";
+                               abilis,function = "mip7";
                        };
                        /* Port 5 */
                        pctl_gpio_j: pctl-gpio-j {     /* GPIO bank J */
-                               pingrp = "gpioj_pins";
+                               abilis,function = "gpioj";
                        };
                        pctl_gpio_k: pctl-gpio-k {     /* GPIO bank K */
-                               pingrp = "gpiok_pins";
+                               abilis,function = "gpiok";
                        };
                        pctl_ciplus: pctl-ciplus {     /* CI+ interface */
-                               pingrp = "ciplus_pins";
+                               abilis,function = "ciplus";
                        };
                        pctl_mcard: pctl-mcard {       /* M-Card interface */
-                               pingrp = "mcard_pins";
+                               abilis,function = "mcard";
                        };
                        pctl_stc0: pctl-stc0 {         /* Smart card I/F 0 */
-                               pingrp = "stc0_pins";
+                               abilis,function = "stc0";
                        };
                        pctl_stc1: pctl-stc1 {         /* Smart card I/F 1 */
-                               pingrp = "stc1_pins";
+                               abilis,function = "stc1";
                        };
                        /* Port 6 */
                        pctl_tsout_p: pctl-tsout-p {   /* Parallel TS-out */
-                               pingrp = "mop_pins";
+                               abilis,function = "mop";
                        };
                        pctl_tsout_s0: pctl-tsout-s0 { /* Serial TS-out 0 */
-                               pingrp = "mos0_pins";
+                               abilis,function = "mos0";
                        };
                        pctl_tsout_s1: pctl-tsout-s1 { /* Serial TS-out 1 */
-                               pingrp = "mos1_pins";
+                               abilis,function = "mos1";
                        };
                        pctl_tsout_s2: pctl-tsout-s2 { /* Serial TS-out 2 */
-                               pingrp = "mos2_pins";
+                               abilis,function = "mos2";
                        };
                        pctl_tsout_s3: pctl-tsout-s3 { /* Serial TS-out 3 */
-                               pingrp = "mos3_pins";
+                               abilis,function = "mos3";
                        };
                        /* Port 7 */
                        pctl_uart0: pctl-uart0 {       /* UART 0 */
-                               pingrp = "uart0_pins";
+                               abilis,function = "uart0";
                        };
                        pctl_uart1: pctl-uart1 {       /* UART 1 */
-                               pingrp = "uart1_pins";
+                               abilis,function = "uart1";
                        };
                        pctl_gpio_l: pctl-gpio-l {     /* GPIO bank L */
-                               pingrp = "gpiol_pins";
+                               abilis,function = "gpiol";
                        };
                        pctl_gpio_m: pctl-gpio-m {     /* GPIO bank M */
-                               pingrp = "gpiom_pins";
+                               abilis,function = "gpiom";
                        };
                        /* Port 8 */
                        pctl_spi3: pctl-spi3 {
-                               pingrp = "spi3_pins";
+                               abilis,function = "spi3";
                        };
                        pctl_jtag: pctl-jtag {
-                               pingrp = "jtag_pins";
+                               abilis,function = "jtag";
                        };
                        /* Port 9 */
                        pctl_spi1: pctl-spi1 {
-                               pingrp = "spi1_pins";
+                               abilis,function = "spi1";
                        };
                        pctl_gpio_n: pctl-gpio-n {
-                               pingrp = "gpion_pins";
+                               abilis,function = "gpion";
                        };
                        /* Unmuxed GPIOs */
                        pctl_gpio_b: pctl-gpio-b {
-                               pingrp = "gpiob_pins";
+                               abilis,function = "gpiob";
                        };
                        pctl_gpio_d: pctl-gpio-d {
-                               pingrp = "gpiod_pins";
+                               abilis,function = "gpiod";
                        };
                        pctl_gpio_f: pctl-gpio-f {
-                               pingrp = "gpiof_pins";
+                               abilis,function = "gpiof";
                        };
                        pctl_gpio_h: pctl-gpio-h {
-                               pingrp = "gpioh_pins";
+                               abilis,function = "gpioh";
                        };
                        pctl_gpio_i: pctl-gpio-i {
-                               pingrp = "gpioi_pins";
+                               abilis,function = "gpioi";
                        };
                };
 
                        interrupts = <27 2>;
                        reg = <0xFF140000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <0>;
-                       gpio-pins = <&pctl_gpio_a>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioa";
                };
                gpiob: gpio@FF141000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF141000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <3>;
-                       gpio-pins = <&pctl_gpio_b>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiob";
                };
                gpioc: gpio@FF142000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF142000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <5>;
-                       gpio-pins = <&pctl_gpio_c>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioc";
                };
                gpiod: gpio@FF143000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF143000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <8>;
-                       gpio-pins = <&pctl_gpio_d>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiod";
                };
                gpioe: gpio@FF144000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF144000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <10>;
-                       gpio-pins = <&pctl_gpio_e>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioe";
                };
                gpiof: gpio@FF145000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF145000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <13>;
-                       gpio-pins = <&pctl_gpio_f>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiof";
                };
                gpiog: gpio@FF146000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF146000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <15>;
-                       gpio-pins = <&pctl_gpio_g>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <3>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiog";
                };
                gpioh: gpio@FF147000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF147000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <18>;
-                       gpio-pins = <&pctl_gpio_h>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <2>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioh";
                };
                gpioi: gpio@FF148000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF148000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <20>;
-                       gpio-pins = <&pctl_gpio_i>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <12>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioi";
                };
                gpioj: gpio@FF149000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF149000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <32>;
-                       gpio-pins = <&pctl_gpio_j>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <32>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpioj";
                };
                gpiok: gpio@FF14a000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14A000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <64>;
-                       gpio-pins = <&pctl_gpio_k>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <22>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiok";
                };
                gpiol: gpio@FF14b000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14B000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <86>;
-                       gpio-pins = <&pctl_gpio_l>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <4>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiol";
                };
                gpiom: gpio@FF14c000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14C000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <90>;
-                       gpio-pins = <&pctl_gpio_m>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <4>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpiom";
                };
                gpion: gpio@FF14d000 {
                        compatible = "abilis,tb10x-gpio";
                        interrupts = <27 2>;
                        reg = <0xFF14D000 0x1000>;
                        gpio-controller;
-                       #gpio-cells = <1>;
-                       gpio-base  = <94>;
-                       gpio-pins = <&pctl_gpio_n>;
+                       #gpio-cells = <2>;
+                       abilis,ngpio = <5>;
+                       gpio-ranges = <&iomux 0 0 0>;
+                       gpio-ranges-group-names = "gpion";
                };
        };
 };
index b204657993aab2fca0127365b74aaced843b9a2e..1cf51c280f285ea3f38ee733ff811727ae2a63c5 100644 (file)
                        compatible = "gpio-leds";
                        power {
                                label = "Power";
-                               gpios = <&gpioi 0>;
+                               gpios = <&gpioi 0 0>;
                                linux,default-trigger = "default-on";
                        };
                        heartbeat {
                                label = "Heartbeat";
-                               gpios = <&gpioi 1>;
+                               gpios = <&gpioi 1 0>;
                                linux,default-trigger = "heartbeat";
                        };
                        led2 {
                                label = "LED2";
-                               gpios = <&gpioi 2>;
+                               gpios = <&gpioi 2 0>;
                                default-state = "off";
                        };
                        led3 {
                                label = "LED3";
-                               gpios = <&gpioi 3>;
+                               gpios = <&gpioi 3 0>;
                                default-state = "off";
                        };
                        led4 {
                                label = "LED4";
-                               gpios = <&gpioi 4>;
+                               gpios = <&gpioi 4 0>;
                                default-state = "off";
                        };
                        led5 {
                                label = "LED5";
-                               gpios = <&gpioi 5>;
+                               gpios = <&gpioi 5 0>;
                                default-state = "off";
                        };
                        led6 {
                                label = "LED6";
-                               gpios = <&gpioi 6>;
+                               gpios = <&gpioi 6 0>;
                                default-state = "off";
                        };
                        led7 {
                                label = "LED7";
-                               gpios = <&gpioi 7>;
+                               gpios = <&gpioi 7 0>;
                                default-state = "off";
                        };
                        led8 {
                                label = "LED8";
-                               gpios = <&gpioi 8>;
+                               gpios = <&gpioi 8 0>;
                                default-state = "off";
                        };
                        led9 {
                                label = "LED9";
-                               gpios = <&gpioi 9>;
+                               gpios = <&gpioi 9 0>;
                                default-state = "off";
                        };
                        led10 {
                                label = "LED10";
-                               gpios = <&gpioi 10>;
+                               gpios = <&gpioi 10 0>;
                                default-state = "off";
                        };
                        led11 {
                                label = "LED11";
-                               gpios = <&gpioi 11>;
+                               gpios = <&gpioi 11 0>;
                                default-state = "off";
                        };
                };
index edf56f4749e13420dcdad51fe25ba58a2ee18ab3..a098d7c05e967461cc200fbb52d1acb51dcee966 100644 (file)
@@ -62,9 +62,8 @@
                };
 
                iomux: iomux@FF10601c {
-                       #address-cells = <1>;
-                       #size-cells = <1>;
                        compatible = "abilis,tb10x-iomux";
+                       #gpio-range-cells = <3>;
                        reg = <0xFF10601c 0x4>;
                };
 
index 4fb2d6f655bdf4162d40b6d72ae6f329b0b32ec0..bcf662d21a57b38fbb6c34ee26033fcd33b0e148 100644 (file)
@@ -67,5 +67,9 @@
                                reg = <1>;
                        };
                };
+
+               arcpmu0: pmu {
+                       compatible = "snps,arc700-pmu";
+               };
        };
 };
diff --git a/arch/arc/configs/fpga_noramfs_defconfig b/arch/arc/configs/fpga_noramfs_defconfig
new file mode 100644 (file)
index 0000000..5276a52
--- /dev/null
@@ -0,0 +1,64 @@
+CONFIG_CROSS_COMPILE="arc-linux-uclibc-"
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_DEFAULT_HOSTNAME="ARCLinux"
+# CONFIG_SWAP is not set
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_PID_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_KALLSYMS_ALL=y
+CONFIG_EMBEDDED=y
+# CONFIG_SLUB_DEBUG is not set
+# CONFIG_COMPAT_BRK is not set
+CONFIG_KPROBES=y
+CONFIG_MODULES=y
+# CONFIG_LBDAF is not set
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+CONFIG_ARC_PLAT_FPGA_LEGACY=y
+CONFIG_ARC_BOARD_ML509=y
+# CONFIG_ARC_HAS_RTSC is not set
+CONFIG_ARC_BUILTIN_DTB_NAME="angel4"
+CONFIG_PREEMPT=y
+# CONFIG_COMPACTION is not set
+# CONFIG_CROSS_MEMORY_ATTACH is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_UNIX_DIAG=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+# CONFIG_IPV6 is not set
+# CONFIG_STANDALONE is not set
+# CONFIG_PREVENT_FIRMWARE_BUILD is not set
+# CONFIG_FIRMWARE_IN_KERNEL is not set
+# CONFIG_BLK_DEV is not set
+CONFIG_NETDEVICES=y
+CONFIG_ARC_EMAC=y
+CONFIG_LXT_PHY=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_SERIO is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_DEVKMEM is not set
+CONFIG_SERIAL_ARC=y
+CONFIG_SERIAL_ARC_CONSOLE=y
+# CONFIG_HW_RANDOM is not set
+# CONFIG_HWMON is not set
+# CONFIG_VGA_CONSOLE is not set
+# CONFIG_HID is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_IOMMU_SUPPORT is not set
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+CONFIG_TMPFS=y
+# CONFIG_MISC_FILESYSTEMS is not set
+CONFIG_NFS_FS=y
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
+# CONFIG_ENABLE_MUST_CHECK is not set
+CONFIG_XZ_DEC=y
index 115ad96480e66d7e4399292bfbd64b52a16c4729..cbf755e32a03f3c19296b552e3f767865fbacc86 100644 (file)
@@ -1,5 +1,7 @@
 /*
- * Copyright (C) 2011-2012 Synopsys, Inc. (www.synopsys.com)
+ * Linux performance counter support for ARC
+ *
+ * Copyright (C) 2011-2013 Synopsys, Inc. (www.synopsys.com)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
 #ifndef __ASM_PERF_EVENT_H
 #define __ASM_PERF_EVENT_H
 
+/* real maximum varies per CPU, this is the maximum supported by the driver */
+#define ARC_PMU_MAX_HWEVENTS   64
+
+#define ARC_REG_CC_BUILD       0xF6
+#define ARC_REG_CC_INDEX       0x240
+#define ARC_REG_CC_NAME0       0x241
+#define ARC_REG_CC_NAME1       0x242
+
+#define ARC_REG_PCT_BUILD      0xF5
+#define ARC_REG_PCT_COUNTL     0x250
+#define ARC_REG_PCT_COUNTH     0x251
+#define ARC_REG_PCT_SNAPL      0x252
+#define ARC_REG_PCT_SNAPH      0x253
+#define ARC_REG_PCT_CONFIG     0x254
+#define ARC_REG_PCT_CONTROL    0x255
+#define ARC_REG_PCT_INDEX      0x256
+
+#define ARC_REG_PCT_CONTROL_CC (1 << 16)       /* clear counts */
+#define ARC_REG_PCT_CONTROL_SN (1 << 17)       /* snapshot */
+
+struct arc_reg_pct_build {
+#ifdef CONFIG_CPU_BIG_ENDIAN
+       unsigned int m:8, c:8, r:6, s:2, v:8;
+#else
+       unsigned int v:8, s:2, r:6, c:8, m:8;
+#endif
+};
+
+struct arc_reg_cc_build {
+#ifdef CONFIG_CPU_BIG_ENDIAN
+       unsigned int c:16, r:8, v:8;
+#else
+       unsigned int v:8, r:8, c:16;
+#endif
+};
+
+#define PERF_COUNT_ARC_DCLM    (PERF_COUNT_HW_MAX + 0)
+#define PERF_COUNT_ARC_DCSM    (PERF_COUNT_HW_MAX + 1)
+#define PERF_COUNT_ARC_ICM     (PERF_COUNT_HW_MAX + 2)
+#define PERF_COUNT_ARC_BPOK    (PERF_COUNT_HW_MAX + 3)
+#define PERF_COUNT_ARC_EDTLB   (PERF_COUNT_HW_MAX + 4)
+#define PERF_COUNT_ARC_EITLB   (PERF_COUNT_HW_MAX + 5)
+#define PERF_COUNT_ARC_HW_MAX  (PERF_COUNT_HW_MAX + 6)
+
+/*
+ * The "generalized" performance events seem to really be a copy
+ * of the available events on x86 processors; the mapping to ARC
+ * events is not always possible 1-to-1. Fortunately, there doesn't
+ * seem to be an exact definition for these events, so we can cheat
+ * a bit where necessary.
+ *
+ * In particular, the following PERF events may behave a bit differently
+ * compared to other architectures:
+ *
+ * PERF_COUNT_HW_CPU_CYCLES
+ *     Cycles not in halted state
+ *
+ * PERF_COUNT_HW_REF_CPU_CYCLES
+ *     Reference cycles not in halted state, same as PERF_COUNT_HW_CPU_CYCLES
+ *     for now as we don't do Dynamic Voltage/Frequency Scaling (yet)
+ *
+ * PERF_COUNT_HW_BUS_CYCLES
+ *     Unclear what this means, Intel uses 0x013c, which according to
+ *     their datasheet means "unhalted reference cycles". It sounds similar
+ *     to PERF_COUNT_HW_REF_CPU_CYCLES, and we use the same counter for it.
+ *
+ * PERF_COUNT_HW_STALLED_CYCLES_BACKEND
+ * PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
+ *     The ARC 700 can either measure stalls per pipeline stage, or all stalls
+ *     combined; for now we assign all stalls to STALLED_CYCLES_BACKEND
+ *     and all pipeline flushes (e.g. caused by mispredicts, etc.) to
+ *     STALLED_CYCLES_FRONTEND.
+ *
+ *     We could start multiple performance counters and combine everything
+ *     afterwards, but that makes it complicated.
+ *
+ *     Note that I$ cache misses aren't counted by either of the two!
+ */
+
+static const char * const arc_pmu_ev_hw_map[] = {
+       [PERF_COUNT_HW_CPU_CYCLES] = "crun",
+       [PERF_COUNT_HW_REF_CPU_CYCLES] = "crun",
+       [PERF_COUNT_HW_BUS_CYCLES] = "crun",
+       [PERF_COUNT_HW_INSTRUCTIONS] = "iall",
+       [PERF_COUNT_HW_BRANCH_MISSES] = "bpfail",
+       [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = "ijmp",
+       [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = "bflush",
+       [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = "bstall",
+       [PERF_COUNT_ARC_DCLM] = "dclm",
+       [PERF_COUNT_ARC_DCSM] = "dcsm",
+       [PERF_COUNT_ARC_ICM] = "icm",
+       [PERF_COUNT_ARC_BPOK] = "bpok",
+       [PERF_COUNT_ARC_EDTLB] = "edtlb",
+       [PERF_COUNT_ARC_EITLB] = "eitlb",
+};
+
+#define C(_x)                  PERF_COUNT_HW_CACHE_##_x
+#define CACHE_OP_UNSUPPORTED   0xffff
+
+static const unsigned arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+       [C(L1D)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = PERF_COUNT_ARC_DCLM,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = PERF_COUNT_ARC_DCSM,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(L1I)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = PERF_COUNT_ARC_ICM,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(LL)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(DTLB)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = PERF_COUNT_ARC_EDTLB,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(ITLB)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = PERF_COUNT_ARC_EITLB,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(BPU)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)] = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
+                       [C(RESULT_MISS)]        = PERF_COUNT_HW_BRANCH_MISSES,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(NODE)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+};
+
 #endif /* __ASM_PERF_EVENT_H */
index 2d50a4cdd7f3dacb8828aaa5c40133a2fc6c7681..45be2167201183172695d0a788c0b20b87ec7ce2 100644 (file)
@@ -80,8 +80,6 @@ static inline __attribute_const__ struct thread_info *current_thread_info(void)
 
 #endif /* !__ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE      0x10000000
-
 /*
  * thread information flags
  * - these are process state flags that various assembly files may need to
index c242ef07ba704d5437edeacd7dddf7e414431876..8004b4fa64615cd3c570219e8e5575848e4c99ac 100644 (file)
@@ -19,6 +19,7 @@ obj-$(CONFIG_KPROBES)                 += kprobes.o
 obj-$(CONFIG_ARC_MISALIGN_ACCESS)      += unaligned.o
 obj-$(CONFIG_KGDB)                     += kgdb.o
 obj-$(CONFIG_ARC_METAWARE_HLINK)       += arc_hostlink.o
+obj-$(CONFIG_PERF_EVENTS)              += perf_event.o
 
 obj-$(CONFIG_ARC_FPU_SAVE_RESTORE)     += fpu.o
 CFLAGS_fpu.o   += -mdpfp
index eb1c2ee5eaf0a4e0b8811092568943ed96be5388..42b05046fad9f13b3cffecc1cb041e8febed3840 100644 (file)
@@ -327,7 +327,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned long trapnr)
                 */
 
                /* We increment the nmissed count for accounting,
-                * we can also use npre/npostfault count for accouting
+                * we can also use npre/npostfault count for accounting
                 * these specific fault cases.
                 */
                kprobes_inc_nmissed_count(cur);
diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c
new file mode 100644 (file)
index 0000000..e46d81f
--- /dev/null
@@ -0,0 +1,326 @@
+/*
+ * Linux performance counter support for ARC700 series
+ *
+ * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
+ *
+ * This code is inspired by the perf support of various other architectures.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/perf_event.h>
+#include <linux/platform_device.h>
+#include <asm/arcregs.h>
+
+struct arc_pmu {
+       struct pmu      pmu;
+       int             counter_size;   /* in bits */
+       int             n_counters;
+       unsigned long   used_mask[BITS_TO_LONGS(ARC_PMU_MAX_HWEVENTS)];
+       int             ev_hw_idx[PERF_COUNT_ARC_HW_MAX];
+};
+
+/* read counter #idx; note that counter# != event# on ARC! */
+static uint64_t arc_pmu_read_counter(int idx)
+{
+       uint32_t tmp;
+       uint64_t result;
+
+       /*
+        * ARC supports making 'snapshots' of the counters, so we don't
+        * need to care about counters wrapping to 0 underneath our feet
+        */
+       write_aux_reg(ARC_REG_PCT_INDEX, idx);
+       tmp = read_aux_reg(ARC_REG_PCT_CONTROL);
+       write_aux_reg(ARC_REG_PCT_CONTROL, tmp | ARC_REG_PCT_CONTROL_SN);
+       result = (uint64_t) (read_aux_reg(ARC_REG_PCT_SNAPH)) << 32;
+       result |= read_aux_reg(ARC_REG_PCT_SNAPL);
+
+       return result;
+}
+
+static void arc_perf_event_update(struct perf_event *event,
+                                 struct hw_perf_event *hwc, int idx)
+{
+       struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
+       uint64_t prev_raw_count, new_raw_count;
+       int64_t delta;
+
+       do {
+               prev_raw_count = local64_read(&hwc->prev_count);
+               new_raw_count = arc_pmu_read_counter(idx);
+       } while (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
+                                new_raw_count) != prev_raw_count);
+
+       delta = (new_raw_count - prev_raw_count) &
+               ((1ULL << arc_pmu->counter_size) - 1ULL);
+
+       local64_add(delta, &event->count);
+       local64_sub(delta, &hwc->period_left);
+}
+
+static void arc_pmu_read(struct perf_event *event)
+{
+       arc_perf_event_update(event, &event->hw, event->hw.idx);
+}
+
+static int arc_pmu_cache_event(u64 config)
+{
+       unsigned int cache_type, cache_op, cache_result;
+       int ret;
+
+       cache_type      = (config >>  0) & 0xff;
+       cache_op        = (config >>  8) & 0xff;
+       cache_result    = (config >> 16) & 0xff;
+       if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
+               return -EINVAL;
+       if (cache_type >= PERF_COUNT_HW_CACHE_OP_MAX)
+               return -EINVAL;
+       if (cache_type >= PERF_COUNT_HW_CACHE_RESULT_MAX)
+               return -EINVAL;
+
+       ret = arc_pmu_cache_map[cache_type][cache_op][cache_result];
+
+       if (ret == CACHE_OP_UNSUPPORTED)
+               return -ENOENT;
+
+       return ret;
+}
+
+/* initializes hw_perf_event structure if event is supported */
+static int arc_pmu_event_init(struct perf_event *event)
+{
+       struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
+       struct hw_perf_event *hwc = &event->hw;
+       int ret;
+
+       /* ARC 700 PMU does not support sampling events */
+       if (is_sampling_event(event))
+               return -ENOENT;
+
+       switch (event->attr.type) {
+       case PERF_TYPE_HARDWARE:
+               if (event->attr.config >= PERF_COUNT_HW_MAX)
+                       return -ENOENT;
+               if (arc_pmu->ev_hw_idx[event->attr.config] < 0)
+                       return -ENOENT;
+               hwc->config = arc_pmu->ev_hw_idx[event->attr.config];
+               pr_debug("initializing event %d with cfg %d\n",
+                        (int) event->attr.config, (int) hwc->config);
+               return 0;
+       case PERF_TYPE_HW_CACHE:
+               ret = arc_pmu_cache_event(event->attr.config);
+               if (ret < 0)
+                       return ret;
+               hwc->config = arc_pmu->ev_hw_idx[ret];
+               return 0;
+       default:
+               return -ENOENT;
+       }
+}
+
+/* starts all counters */
+static void arc_pmu_enable(struct pmu *pmu)
+{
+       uint32_t tmp;
+       tmp = read_aux_reg(ARC_REG_PCT_CONTROL);
+       write_aux_reg(ARC_REG_PCT_CONTROL, (tmp & 0xffff0000) | 0x1);
+}
+
+/* stops all counters */
+static void arc_pmu_disable(struct pmu *pmu)
+{
+       uint32_t tmp;
+       tmp = read_aux_reg(ARC_REG_PCT_CONTROL);
+       write_aux_reg(ARC_REG_PCT_CONTROL, (tmp & 0xffff0000) | 0x0);
+}
+
+/*
+ * Assigns hardware counter to hardware condition.
+ * Note that there is no separate start/stop mechanism;
+ * stopping is achieved by assigning the 'never' condition
+ */
+static void arc_pmu_start(struct perf_event *event, int flags)
+{
+       struct hw_perf_event *hwc = &event->hw;
+       int idx = hwc->idx;
+
+       if (WARN_ON_ONCE(idx == -1))
+               return;
+
+       if (flags & PERF_EF_RELOAD)
+               WARN_ON_ONCE(!(event->hw.state & PERF_HES_UPTODATE));
+
+       event->hw.state = 0;
+
+       /* enable ARC pmu here */
+       write_aux_reg(ARC_REG_PCT_INDEX, idx);
+       write_aux_reg(ARC_REG_PCT_CONFIG, hwc->config);
+}
+
+static void arc_pmu_stop(struct perf_event *event, int flags)
+{
+       struct hw_perf_event *hwc = &event->hw;
+       int idx = hwc->idx;
+
+       if (!(event->hw.state & PERF_HES_STOPPED)) {
+               /* stop ARC pmu here */
+               write_aux_reg(ARC_REG_PCT_INDEX, idx);
+
+               /* condition code #0 is always "never" */
+               write_aux_reg(ARC_REG_PCT_CONFIG, 0);
+
+               event->hw.state |= PERF_HES_STOPPED;
+       }
+
+       if ((flags & PERF_EF_UPDATE) &&
+           !(event->hw.state & PERF_HES_UPTODATE)) {
+               arc_perf_event_update(event, &event->hw, idx);
+               event->hw.state |= PERF_HES_UPTODATE;
+       }
+}
+
+static void arc_pmu_del(struct perf_event *event, int flags)
+{
+       struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
+
+       arc_pmu_stop(event, PERF_EF_UPDATE);
+       __clear_bit(event->hw.idx, arc_pmu->used_mask);
+
+       perf_event_update_userpage(event);
+}
+
+/* allocate hardware counter and optionally start counting */
+static int arc_pmu_add(struct perf_event *event, int flags)
+{
+       struct arc_pmu *arc_pmu = container_of(event->pmu, struct arc_pmu, pmu);
+       struct hw_perf_event *hwc = &event->hw;
+       int idx = hwc->idx;
+
+       if (__test_and_set_bit(idx, arc_pmu->used_mask)) {
+               idx = find_first_zero_bit(arc_pmu->used_mask,
+                                         arc_pmu->n_counters);
+               if (idx == arc_pmu->n_counters)
+                       return -EAGAIN;
+
+               __set_bit(idx, arc_pmu->used_mask);
+               hwc->idx = idx;
+       }
+
+       write_aux_reg(ARC_REG_PCT_INDEX, idx);
+       write_aux_reg(ARC_REG_PCT_CONFIG, 0);
+       write_aux_reg(ARC_REG_PCT_COUNTL, 0);
+       write_aux_reg(ARC_REG_PCT_COUNTH, 0);
+       local64_set(&hwc->prev_count, 0);
+
+       hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
+       if (flags & PERF_EF_START)
+               arc_pmu_start(event, PERF_EF_RELOAD);
+
+       perf_event_update_userpage(event);
+
+       return 0;
+}
+
+static int arc_pmu_device_probe(struct platform_device *pdev)
+{
+       struct arc_pmu *arc_pmu;
+       struct arc_reg_pct_build pct_bcr;
+       struct arc_reg_cc_build cc_bcr;
+       int i, j, ret;
+
+       union cc_name {
+               struct {
+                       uint32_t word0, word1;
+                       char sentinel;
+               } indiv;
+               char str[9];
+       } cc_name;
+
+
+       READ_BCR(ARC_REG_PCT_BUILD, pct_bcr);
+       if (!pct_bcr.v) {
+               pr_err("This core does not have performance counters!\n");
+               return -ENODEV;
+       }
+
+       arc_pmu = devm_kzalloc(&pdev->dev, sizeof(struct arc_pmu),
+                              GFP_KERNEL);
+       if (!arc_pmu)
+               return -ENOMEM;
+
+       arc_pmu->n_counters = pct_bcr.c;
+       BUG_ON(arc_pmu->n_counters > ARC_PMU_MAX_HWEVENTS);
+
+       arc_pmu->counter_size = 32 + (pct_bcr.s << 4);
+       pr_info("ARC PMU found with %d counters of size %d bits\n",
+               arc_pmu->n_counters, arc_pmu->counter_size);
+
+       READ_BCR(ARC_REG_CC_BUILD, cc_bcr);
+
+       if (!cc_bcr.v)
+               pr_err("Strange! Performance counters exist, but no countable conditions?\n");
+
+       pr_info("ARC PMU has %d countable conditions\n", cc_bcr.c);
+
+       cc_name.str[8] = 0;
+       for (i = 0; i < PERF_COUNT_HW_MAX; i++)
+               arc_pmu->ev_hw_idx[i] = -1;
+
+       for (j = 0; j < cc_bcr.c; j++) {
+               write_aux_reg(ARC_REG_CC_INDEX, j);
+               cc_name.indiv.word0 = read_aux_reg(ARC_REG_CC_NAME0);
+               cc_name.indiv.word1 = read_aux_reg(ARC_REG_CC_NAME1);
+               for (i = 0; i < ARRAY_SIZE(arc_pmu_ev_hw_map); i++) {
+                       if (arc_pmu_ev_hw_map[i] &&
+                           !strcmp(arc_pmu_ev_hw_map[i], cc_name.str) &&
+                           strlen(arc_pmu_ev_hw_map[i])) {
+                               pr_debug("mapping %d to idx %d with name %s\n",
+                                        i, j, cc_name.str);
+                               arc_pmu->ev_hw_idx[i] = j;
+                       }
+               }
+       }
+
+       arc_pmu->pmu = (struct pmu) {
+               .pmu_enable     = arc_pmu_enable,
+               .pmu_disable    = arc_pmu_disable,
+               .event_init     = arc_pmu_event_init,
+               .add            = arc_pmu_add,
+               .del            = arc_pmu_del,
+               .start          = arc_pmu_start,
+               .stop           = arc_pmu_stop,
+               .read           = arc_pmu_read,
+       };
+
+       ret = perf_pmu_register(&arc_pmu->pmu, pdev->name, PERF_TYPE_RAW);
+
+       return ret;
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id arc_pmu_match[] = {
+       { .compatible = "snps,arc700-pmu" },
+       {},
+};
+MODULE_DEVICE_TABLE(of, arc_pmu_match);
+#endif
+
+static struct platform_driver arc_pmu_driver = {
+       .driver = {
+               .name           = "arc700-pmu",
+               .of_match_table = of_match_ptr(arc_pmu_match),
+       },
+       .probe          = arc_pmu_device_probe,
+};
+
+module_platform_driver(arc_pmu_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mischa Jonker <mjonker@synopsys.com>");
+MODULE_DESCRIPTION("ARC PMU driver");
index 1ab386bb5da895bd4e876b1d78977e684c83f3fe..6994c188dc88c82bbc256f6835c6e54b6107545a 100644 (file)
@@ -20,8 +20,10 @@ menuconfig ARC_PLAT_TB10X
        bool "Abilis TB10x"
        select COMMON_CLK
        select PINCTRL
+       select PINCTRL_TB10X
        select PINMUX
        select ARCH_REQUIRE_GPIOLIB
+       select GPIO_TB10X
        select TB10X_IRQC
        help
          Support for platforms based on the TB10x home media gateway SOC by
index e089e622be79115697ba213a816eaeb003def98b..214b698cefea895e35b345dc9e8d070d33cf6929 100644 (file)
@@ -5,6 +5,7 @@ config ARM
        select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select ARCH_HAVE_CUSTOM_GPIO_H
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select ARCH_USE_CMPXCHG_LOCKREF
        select ARCH_WANT_IPC_PARSE_VERSION
        select BUILDTIME_EXTABLE_SORT if MMU
index 987429436171f0dd2ac8bb1bd0b64e548fc1e722..7e6c64ed966d66b4bfe365db5f85186a88b49a24 100644 (file)
        tsc {
                ti,wires = <4>;
                ti,x-plate-resistance = <200>;
-               ti,coordiante-readouts = <5>;
+               ti,coordinate-readouts = <5>;
                ti,wire-config = <0x00 0x11 0x22 0x33>;
        };
 
index 03febf85fd2f055373259c19e01c5ad9d8148e65..4718ec4a4dbfef5e2a7273726cb6a8f0750623e3 100644 (file)
                tx-num-evt = <1>;
                rx-num-evt = <1>;
 };
+
+&tscadc {
+       status = "okay";
+       tsc {
+               ti,wires = <4>;
+               ti,x-plate-resistance = <200>;
+               ti,coordinate-readouts = <5>;
+               ti,wire-config = <0x00 0x11 0x22 0x33>;
+       };
+};
index 139b40cc3a23e63087fc6154ca6e7f79ed828fae..2ccbb57fbfa87d8a86aef40d16e756aa78df6d3b 100644 (file)
                                <1 10 0xf08>;
                };
 
+               memory-controller@fff00000 {
+                       compatible = "calxeda,ecx-2000-ddr-ctrl";
+                       reg = <0xfff00000 0x1000>;
+                       interrupts = <0 91 4>;
+               };
+
                intc: interrupt-controller@fff11000 {
                        compatible = "arm,cortex-a15-gic";
                        #interrupt-cells = <3>;
index bc22557d7a6a977b3cce656c115eb31e1d060398..b90045a8f8e3749f849c3e0d790e99565a313094 100644 (file)
                        status = "disabled";
                };
 
-               memory-controller@fff00000 {
-                       compatible = "calxeda,hb-ddr-ctrl";
-                       reg = <0xfff00000 0x1000>;
-                       interrupts = <0 91 4>;
-               };
-
                ipc@fff20000 {
                        compatible = "arm,pl320", "arm,primecell";
                        reg = <0xfff20000 0x1000>;
index 6aad34ad9517f37424071dcac4859c400a93d1f5..ed14aeac056679059d823b8502a122e28ab1ddaa 100644 (file)
        soc {
                ranges = <0x00000000 0x00000000 0xffffffff>;
 
+               memory-controller@fff00000 {
+                       compatible = "calxeda,hb-ddr-ctrl";
+                       reg = <0xfff00000 0x1000>;
+                       interrupts = <0 91 4>;
+               };
+
                timer@fff10600 {
                        compatible = "arm,cortex-a9-twd-timer";
                        reg = <0xfff10600 0x20>;
index f4dcff3a9969a053d0a7c136015c94526a739cb8..4bcdd3ad15e524d95cb553b47fc6f61e5eef9a3a 100644 (file)
 
                        usbphy0: usbphy@0 {
                                compatible = "usb-nop-xceiv";
-                               clocks = <&clks 124>;
+                               clocks = <&clks 75>;
                                clock-names = "main_clk";
                                status = "okay";
                        };
index fb1b2ec8eaa99f4b366ccb29a5ed28f78a109571..4217096ee6777bd292c208a23ba02ad86a2af8c9 100644 (file)
                interrupts = <11>;
        };
 
+       charger: bci {
+               compatible = "ti,twl4030-bci";
+               interrupts = <9>, <2>;
+               bci3v1-supply = <&vusb3v1>;
+       };
+
        watchdog {
                compatible = "ti,twl4030-wdt";
        };
index 8e1a0245907f85be1a460bfa785f744daf285d6f..41bca32409fce81358c3b5c35bc081bcc28e7c76 100644 (file)
@@ -404,7 +404,7 @@ static irqreturn_t dma_irq_handler(int irq, void *data)
                                        BIT(slot));
                        if (edma_cc[ctlr]->intr_data[channel].callback)
                                edma_cc[ctlr]->intr_data[channel].callback(
-                                       channel, DMA_COMPLETE,
+                                       channel, EDMA_DMA_COMPLETE,
                                        edma_cc[ctlr]->intr_data[channel].data);
                }
        } while (sh_ipr);
@@ -459,7 +459,7 @@ static irqreturn_t dma_ccerr_handler(int irq, void *data)
                                                                callback) {
                                                edma_cc[ctlr]->intr_data[k].
                                                callback(k,
-                                               DMA_CC_ERROR,
+                                               EDMA_DMA_CC_ERROR,
                                                edma_cc[ctlr]->intr_data
                                                [k].data);
                                        }
index 002a1ceadceb635f65b1e5523ecdb7f4e74710a6..23591dba47a04ac2fe5efdd55f493551cfd63538 100644 (file)
@@ -39,6 +39,7 @@ CONFIG_SPI=y
 CONFIG_SPI_SIRF=y
 CONFIG_SPI_SPIDEV=y
 # CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_MASS_STORAGE=m
 CONFIG_MMC=y
diff --git a/arch/arm/configs/vt8500_v6_v7_defconfig b/arch/arm/configs/vt8500_v6_v7_defconfig
new file mode 100644 (file)
index 0000000..f052017
--- /dev/null
@@ -0,0 +1,90 @@
+CONFIG_IRQ_DOMAIN_DEBUG=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_ARCH_MULTI_V6=y
+CONFIG_ARCH_WM8750=y
+CONFIG_ARCH_WM8850=y
+CONFIG_ARM_ERRATA_720789=y
+CONFIG_ARM_ERRATA_754322=y
+CONFIG_ARM_ERRATA_775420=y
+CONFIG_HAVE_ARM_ARCH_TIMER=y
+CONFIG_AEABI=y
+CONFIG_HIGHMEM=y
+CONFIG_HIGHPTE=y
+CONFIG_ARM_APPENDED_DTB=y
+CONFIG_ARM_ATAG_DTB_COMPAT=y
+CONFIG_VFP=y
+CONFIG_NEON=y
+CONFIG_PM_RUNTIME=y
+CONFIG_NET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_PROC_DEVICETREE=y
+CONFIG_EEPROM_93CX6=y
+CONFIG_SCSI=y
+CONFIG_BLK_DEV_SD=y
+CONFIG_NETDEVICES=y
+# CONFIG_NET_CADENCE is not set
+# CONFIG_NET_VENDOR_BROADCOM is not set
+# CONFIG_NET_VENDOR_CIRRUS is not set
+# CONFIG_NET_VENDOR_FARADAY is not set
+# CONFIG_NET_VENDOR_INTEL is not set
+# CONFIG_NET_VENDOR_MARVELL is not set
+# CONFIG_NET_VENDOR_MICREL is not set
+# CONFIG_NET_VENDOR_NATSEMI is not set
+# CONFIG_NET_VENDOR_SEEQ is not set
+# CONFIG_NET_VENDOR_SMSC is not set
+# CONFIG_NET_VENDOR_STMICRO is not set
+CONFIG_VIA_VELOCITY=y
+# CONFIG_NET_VENDOR_WIZNET is not set
+CONFIG_PHYLIB=y
+CONFIG_INPUT_MATRIXKMAP=y
+CONFIG_SERIAL_VT8500=y
+CONFIG_SERIAL_VT8500_CONSOLE=y
+CONFIG_I2C=y
+CONFIG_I2C_WMT=y
+CONFIG_PINCTRL_SINGLE=y
+CONFIG_PINCTRL_WM8750=y
+CONFIG_GPIO_GENERIC_PLATFORM=y
+CONFIG_POWER_SUPPLY=y
+CONFIG_POWER_RESET=y
+CONFIG_MFD_SYSCON=y
+CONFIG_REGULATOR=y
+CONFIG_REGULATOR_FIXED_VOLTAGE=y
+CONFIG_REGULATOR_GPIO=y
+CONFIG_USB=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_HCD_PLATFORM=y
+CONFIG_USB_UHCI_HCD=y
+CONFIG_USB_STORAGE=y
+CONFIG_NOP_USB_XCEIV=y
+CONFIG_USB_GPIO_VBUS=y
+CONFIG_USB_ULPI=y
+CONFIG_MMC=y
+CONFIG_MMC_DEBUG=y
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_VT8500=y
+CONFIG_DMADEVICES=y
+CONFIG_COMMON_CLK_DEBUG=y
+# CONFIG_IOMMU_SUPPORT is not set
+CONFIG_PWM=y
+CONFIG_PWM_VT8500=y
+CONFIG_RESET_CONTROLLER=y
+CONFIG_GENERIC_PHY=y
+CONFIG_EXT4_FS=y
+CONFIG_TMPFS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+CONFIG_ROOT_NFS=y
+CONFIG_PRINTK_TIME=y
+CONFIG_DEBUG_KERNEL=y
+CONFIG_LOCKUP_DETECTOR=y
index 9b28f1243bdc1d96c2be3dac0ad947a72a61a264..240b29ef17db9772af6abc4855b90c7c16621e81 100644 (file)
@@ -393,36 +393,6 @@ static inline int iop_chan_zero_sum_slot_count(size_t len, int src_cnt,
        return slot_cnt;
 }
 
-static inline int iop_desc_is_pq(struct iop_adma_desc_slot *desc)
-{
-       return 0;
-}
-
-static inline u32 iop_desc_get_dest_addr(struct iop_adma_desc_slot *desc,
-                                       struct iop_adma_chan *chan)
-{
-       union iop3xx_desc hw_desc = { .ptr = desc->hw_desc, };
-
-       switch (chan->device->id) {
-       case DMA0_ID:
-       case DMA1_ID:
-               return hw_desc.dma->dest_addr;
-       case AAU_ID:
-               return hw_desc.aau->dest_addr;
-       default:
-               BUG();
-       }
-       return 0;
-}
-
-
-static inline u32 iop_desc_get_qdest_addr(struct iop_adma_desc_slot *desc,
-                                         struct iop_adma_chan *chan)
-{
-       BUG();
-       return 0;
-}
-
 static inline u32 iop_desc_get_byte_count(struct iop_adma_desc_slot *desc,
                                        struct iop_adma_chan *chan)
 {
index 122f86d8c991d73e587c786eba41bf85a6ec5a21..250760e081039542dbcdae191b1b5321921a1d3d 100644 (file)
@@ -82,8 +82,6 @@ struct iop_adma_chan {
  * @slot_cnt: total slots used in an transaction (group of operations)
  * @slots_per_op: number of slots per operation
  * @idx: pool index
- * @unmap_src_cnt: number of xor sources
- * @unmap_len: transaction bytecount
  * @tx_list: list of descriptors that are associated with one operation
  * @async_tx: support for the async_tx api
  * @group_list: list of slots that make up a multi-descriptor transaction
@@ -99,8 +97,6 @@ struct iop_adma_desc_slot {
        u16 slot_cnt;
        u16 slots_per_op;
        u16 idx;
-       u16 unmap_src_cnt;
-       size_t unmap_len;
        struct list_head tx_list;
        struct dma_async_tx_descriptor async_tx;
        union {
index df5e13d64f2c02b28963c23b319a7634cf5dacc8..71a06b293489ddffd1b4177eca38572501c0ce36 100644 (file)
@@ -140,12 +140,6 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
                                    struct user_vfp_exc __user *);
 #endif
 
-/*
- * We use bit 30 of the preempt_count to indicate that kernel
- * preemption is occurring.  See <asm/hardirq.h>.
- */
-#define PREEMPT_ACTIVE 0x40000000
-
 /*
  * thread information flags:
  *  TIF_SYSCALL_TRACE  - syscall trace active
index c1b737097c9543faf67c4ed78f2617e3add0606f..90aab2d5a07f3aed6acc2ed8788105b877756fe6 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y          := irq.o gpio.o setup.o
+obj-y          := irq.o gpio.o setup.o sysirq_mask.o
 obj-m          :=
 obj-n          :=
 obj-           :=
index f8629a3fa2452791b6215c19f77124813e1d3f5f..d6a1fa85371d3ee732f4048298532dab817478fc 100644 (file)
@@ -351,6 +351,8 @@ static void __init at91sam9260_initialize(void)
        arm_pm_idle = at91sam9_idle;
        arm_pm_restart = at91sam9_alt_restart;
 
+       at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
+
        /* Register GPIO subsystem */
        at91_gpio_init(at91sam9260_gpio, 3);
 }
index 1f3867a17a289beee4bb1a44ae64ca3bc96b044d..23ba1d8a1531ca5f123f94591290450a0a403be6 100644 (file)
@@ -293,6 +293,8 @@ static void __init at91sam9261_initialize(void)
        arm_pm_idle = at91sam9_idle;
        arm_pm_restart = at91sam9_alt_restart;
 
+       at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
+
        /* Register GPIO subsystem */
        at91_gpio_init(at91sam9261_gpio, 3);
 }
index 90d455d294a1814e7e72722b5614b4d15548c298..7eccb0fc57bc080c3eaee8c8f830a2a7fb127cad 100644 (file)
@@ -330,6 +330,9 @@ static void __init at91sam9263_initialize(void)
        arm_pm_idle = at91sam9_idle;
        arm_pm_restart = at91sam9_alt_restart;
 
+       at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
+       at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
+
        /* Register GPIO subsystem */
        at91_gpio_init(at91sam9263_gpio, 5);
 }
index e9bf0b8f40eb745d317e2d1d50c500eea1491aa4..9405aa08b10498430b097594865c95976297c6ba 100644 (file)
@@ -379,6 +379,9 @@ static void __init at91sam9g45_initialize(void)
        arm_pm_idle = at91sam9_idle;
        arm_pm_restart = at91sam9g45_restart;
 
+       at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+       at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
+
        /* Register GPIO subsystem */
        at91_gpio_init(at91sam9g45_gpio, 5);
 }
index 2d895a297739d85d4302ec8e9ec2e01cfb4f1c69..388ec3aec4b95edc8e63f8907a09fd66b2889a15 100644 (file)
@@ -224,7 +224,13 @@ static void __init at91sam9n12_map_io(void)
        at91_init_sram(0, AT91SAM9N12_SRAM_BASE, AT91SAM9N12_SRAM_SIZE);
 }
 
+static void __init at91sam9n12_initialize(void)
+{
+       at91_sysirq_mask_rtc(AT91SAM9N12_BASE_RTC);
+}
+
 AT91_SOC_START(at91sam9n12)
        .map_io = at91sam9n12_map_io,
        .register_clocks = at91sam9n12_register_clocks,
+       .init = at91sam9n12_initialize,
 AT91_SOC_END
index 88995af09c043abf6198124d1c651d60ac03b0ff..0750ffb7e6b16d7a52dd636475226b9b9035b301 100644 (file)
@@ -296,6 +296,9 @@ static void __init at91sam9rl_initialize(void)
        arm_pm_idle = at91sam9_idle;
        arm_pm_restart = at91sam9_alt_restart;
 
+       at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+       at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
+
        /* Register GPIO subsystem */
        at91_gpio_init(at91sam9rl_gpio, 4);
 }
index 916e5a1429171bd39835da54b02fa444b1941905..e8a2e075a1b888262077e46457774679d51776e9 100644 (file)
@@ -322,6 +322,11 @@ static void __init at91sam9x5_map_io(void)
        at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
 }
 
+static void __init at91sam9x5_initialize(void)
+{
+       at91_sysirq_mask_rtc(AT91SAM9X5_BASE_RTC);
+}
+
 /* --------------------------------------------------------------------
  *  Interrupt initialization
  * -------------------------------------------------------------------- */
@@ -329,4 +334,5 @@ static void __init at91sam9x5_map_io(void)
 AT91_SOC_START(at91sam9x5)
        .map_io = at91sam9x5_map_io,
        .register_clocks = at91sam9x5_register_clocks,
+       .init = at91sam9x5_initialize,
 AT91_SOC_END
index 0b153c87521d8e73feaf6b9bc53291431bc6b7a8..f4f8735315dafd8247f686e756423d8b9608a013 100644 (file)
@@ -28,7 +28,7 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/at73c213.h>
 #include <linux/clk.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
 
index 8b4942cbb6d9a62ffdb1f88e9676670817b7a107..2f931915c80c8d2f9a6c9059cf2e6eb07d2093a7 100644 (file)
@@ -27,7 +27,7 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/ads7846.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/fb.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
index dc6e2f5f804dcc26471daf42ecd4ef1e454656fa..26dee3ce9397a0cf41705d0fbafe6ee87b0a9fbc 100644 (file)
@@ -34,6 +34,8 @@ extern int  __init at91_aic_of_init(struct device_node *node,
                                    struct device_node *parent);
 extern int  __init at91_aic5_of_init(struct device_node *node,
                                    struct device_node *parent);
+extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
+extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
 
 
  /* Timer */
index d374b87c045914348349ef721feadd9e87170921..0151bcf6163cddd349c5d6f8e88198c3831bf3b9 100644 (file)
 #define AT91SAM9N12_BASE_USART2        0xf8024000
 #define AT91SAM9N12_BASE_USART3        0xf8028000
 
+/*
+ * System Peripherals
+ */
+#define AT91SAM9N12_BASE_RTC   0xfffffeb0
+
 /*
  * Internal Memory.
  */
index c75ee19b58d3de69c79e81e312c416fbd6071ef0..2fc76c49e97cf4152c9427f62a39bad4e71b51d4 100644 (file)
 #define AT91SAM9X5_BASE_USART1 0xf8020000
 #define AT91SAM9X5_BASE_USART2 0xf8024000
 
+/*
+ * System Peripherals
+ */
+#define AT91SAM9X5_BASE_RTC    0xfffffeb0
+
 /*
  * Internal Memory.
  */
index 31096a8aaf1d507287d62f6ef8250096f7ee09ea..25613d8c6dcd6687dd0b896883aedbe52f3461c6 100644 (file)
 #define SAMA5D3_BASE_USART2    0xf8020000
 #define SAMA5D3_BASE_USART3    0xf8024000
 
+/*
+ * System Peripherals
+ */
+#define SAMA5D3_BASE_RTC       0xfffffeb0
+
 /*
  * Internal Memory
  */
index 401279715ab19b8ec694463d442af33b93aff827..3ea86428ee0964f11d0955a90d0348626e68da58 100644 (file)
@@ -371,7 +371,13 @@ static void __init sama5d3_map_io(void)
        at91_init_sram(0, SAMA5D3_SRAM_BASE, SAMA5D3_SRAM_SIZE);
 }
 
+static void __init sama5d3_initialize(void)
+{
+       at91_sysirq_mask_rtc(SAMA5D3_BASE_RTC);
+}
+
 AT91_SOC_START(sama5d3)
        .map_io = sama5d3_map_io,
        .register_clocks = sama5d3_register_clocks,
+       .init = sama5d3_initialize,
 AT91_SOC_END
diff --git a/arch/arm/mach-at91/sysirq_mask.c b/arch/arm/mach-at91/sysirq_mask.c
new file mode 100644 (file)
index 0000000..2ba694f
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * sysirq_mask.c - System-interrupt masking
+ *
+ * Copyright (C) 2013 Johan Hovold <jhovold@gmail.com>
+ *
+ * Functions to disable system interrupts from backup-powered peripherals.
+ *
+ * The RTC and RTT-peripherals are generally powered by backup power (VDDBU)
+ * and are not reset on wake-up, user, watchdog or software reset. This means
+ * that their interrupts may be enabled during early boot (e.g. after a user
+ * reset).
+ *
+ * As the RTC and RTT share the system-interrupt line with the PIT, an
+ * interrupt occurring before a handler has been installed would lead to the
+ * system interrupt being disabled and prevent the system from booting.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/io.h>
+#include <mach/at91_rtt.h>
+
+#include "generic.h"
+
+#define AT91_RTC_IDR   0x24    /* Interrupt Disable Register */
+#define AT91_RTC_IMR   0x28    /* Interrupt Mask Register */
+
+void __init at91_sysirq_mask_rtc(u32 rtc_base)
+{
+       void __iomem *base;
+       u32 mask;
+
+       base = ioremap(rtc_base, 64);
+       if (!base)
+               return;
+
+       mask = readl_relaxed(base + AT91_RTC_IMR);
+       if (mask) {
+               pr_info("AT91: Disabling rtc irq\n");
+               writel_relaxed(mask, base + AT91_RTC_IDR);
+               (void)readl_relaxed(base + AT91_RTC_IMR);       /* flush */
+       }
+
+       iounmap(base);
+}
+
+void __init at91_sysirq_mask_rtt(u32 rtt_base)
+{
+       void __iomem *base;
+       void __iomem *reg;
+       u32 mode;
+
+       base = ioremap(rtt_base, 16);
+       if (!base)
+               return;
+
+       reg = base + AT91_RTT_MR;
+
+       mode = readl_relaxed(reg);
+       if (mode & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)) {
+               pr_info("AT91: Disabling rtt irq\n");
+               mode &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+               writel_relaxed(mode, reg);
+               (void)readl_relaxed(reg);                       /* flush */
+       }
+
+       iounmap(base);
+}
index 40f15f133c55c3646d5eeac3ef3eec7764cae760..d1f45af7a530e9abc33d794fcc6cf52010cfc52b 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
 #include <linux/i2c/pcf857x.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/spi/spi.h>
index df16cb88a26b643814af5385affb94a7a8220882..e0af0eccde8fbe0d9f54abaeb339ee974db4c2d2 100644 (file)
@@ -18,7 +18,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/platform_data/pca953x.h>
 #include <linux/input.h>
 #include <linux/input/tps6507x-ts.h>
index f4a6c18912ea50abaac233fedf26cef69af06724..e08a8684ead2fed54938bcfeaaac7fe3b5b0efb2 100644 (file)
@@ -18,7 +18,7 @@
 #include <linux/i2c.h>
 #include <linux/io.h>
 #include <linux/clk.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/leds.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
index 9cc32c283b8b90af050de90411a9b1d168b3b050..987605b78556f9e8fa16b1e9b1b278ad0abe4d1c 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/i2c/pcf857x.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
index 44b20191a9fed5359ed0b24344e0aeb15430d210..13d0801fd6b170e155dfe3d4cf8c069522c4baf7 100644 (file)
@@ -22,7 +22,7 @@
 #include <linux/gpio.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/i2c/pcf857x.h>
 
 #include <media/tvp514x.h>
index cd0f58730c2ba63234fb5e673156c10214300a80..7aa105b1fd0f7553170134c9a8dae654c931784d 100644 (file)
@@ -15,7 +15,7 @@
 #include <linux/mtd/partitions.h>
 #include <linux/regulator/machine.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/etherdevice.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/flash.h>
index d84360148100831265561696b1e661f16a035361..41c7c961579133d9a80070a2c46ce56c07f1d8d9 100644 (file)
@@ -26,7 +26,7 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
index 08332d84144052899382d6d2543dc4d754779e6f..0aded64a9ebcd68a4213620ace8b5b2f81b53121 100644 (file)
@@ -7,7 +7,7 @@ config ARCH_HIGHBANK
        select ARCH_SUPPORTS_BIG_ENDIAN
        select ARCH_WANT_OPTIONAL_GPIOLIB
        select ARM_AMBA
-       select ARM_ERRATA_764369
+       select ARM_ERRATA_764369 if SMP
        select ARM_ERRATA_775420
        select ARM_ERRATA_798181 if SMP
        select ARM_GIC
index bbe1f5bb799c1a0db3cd403f01767b2a7af4471b..1789e2b3190389f287a4ce79a747b17c1072a48d 100644 (file)
@@ -102,8 +102,8 @@ obj-$(CONFIG_SOC_IMX6SL) += clk-imx6sl.o mach-imx6sl.o
 
 ifeq ($(CONFIG_PM),y)
 obj-$(CONFIG_SOC_IMX6Q) += pm-imx6q.o headsmp.o
-# i.MX6SL reuses pm-imx6q.c
-obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o
+# i.MX6SL reuses i.MX6Q code
+obj-$(CONFIG_SOC_IMX6SL) += pm-imx6q.o headsmp.o
 endif
 
 # i.MX5 based machines
index d756d91fd74163852b810a0b0d578eaac5236552..04cfd0fcb0e56db864d28f4240b2341ae20927b0 100644 (file)
@@ -122,13 +122,14 @@ static struct clk_div_table clk_enet_ref_table[] = {
        { .val = 1, .div = 10, },
        { .val = 2, .div = 5, },
        { .val = 3, .div = 4, },
+       { /* sentinel */ }
 };
 
 static struct clk_div_table post_div_table[] = {
        { .val = 2, .div = 1, },
        { .val = 1, .div = 2, },
        { .val = 0, .div = 4, },
-       { }
+       { /* sentinel */ }
 };
 
 static struct clk_div_table video_div_table[] = {
@@ -136,7 +137,7 @@ static struct clk_div_table video_div_table[] = {
        { .val = 1, .div = 2, },
        { .val = 2, .div = 1, },
        { .val = 3, .div = 4, },
-       { }
+       { /* sentinel */ }
 };
 
 static void __init imx6q_clocks_init(struct device_node *ccm_node)
@@ -298,7 +299,7 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
        clk[asrc_podf]        = imx_clk_divider("asrc_podf",        "asrc_pred",         base + 0x30, 9,  3);
        clk[spdif_pred]       = imx_clk_divider("spdif_pred",       "spdif_sel",         base + 0x30, 25, 3);
        clk[spdif_podf]       = imx_clk_divider("spdif_podf",       "spdif_pred",        base + 0x30, 22, 3);
-       clk[can_root]         = imx_clk_divider("can_root",         "pll3_usb_otg",      base + 0x20, 2,  6);
+       clk[can_root]         = imx_clk_divider("can_root",         "pll3_60m",          base + 0x20, 2,  6);
        clk[ecspi_root]       = imx_clk_divider("ecspi_root",       "pll3_60m",          base + 0x38, 19, 6);
        clk[gpu2d_core_podf]  = imx_clk_divider("gpu2d_core_podf",  "gpu2d_core_sel",    base + 0x18, 23, 3);
        clk[gpu3d_core_podf]  = imx_clk_divider("gpu3d_core_podf",  "gpu3d_core_sel",    base + 0x18, 26, 3);
index f6640b6a7b3128a7ca6a6d8d31578419ea1be431..61364050fccdce42b477f2a7a4aaafddf136f41a 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
@@ -45,33 +46,49 @@ struct clk_pllv3 {
 
 #define to_clk_pllv3(_hw) container_of(_hw, struct clk_pllv3, hw)
 
+static int clk_pllv3_wait_lock(struct clk_pllv3 *pll)
+{
+       unsigned long timeout = jiffies + msecs_to_jiffies(10);
+       u32 val = readl_relaxed(pll->base) & BM_PLL_POWER;
+
+       /* No need to wait for lock when pll is not powered up */
+       if ((pll->powerup_set && !val) || (!pll->powerup_set && val))
+               return 0;
+
+       /* Wait for PLL to lock */
+       do {
+               if (readl_relaxed(pll->base) & BM_PLL_LOCK)
+                       break;
+               if (time_after(jiffies, timeout))
+                       break;
+               usleep_range(50, 500);
+       } while (1);
+
+       return readl_relaxed(pll->base) & BM_PLL_LOCK ? 0 : -ETIMEDOUT;
+}
+
 static int clk_pllv3_prepare(struct clk_hw *hw)
 {
        struct clk_pllv3 *pll = to_clk_pllv3(hw);
-       unsigned long timeout;
        u32 val;
+       int ret;
 
        val = readl_relaxed(pll->base);
-       val &= ~BM_PLL_BYPASS;
        if (pll->powerup_set)
                val |= BM_PLL_POWER;
        else
                val &= ~BM_PLL_POWER;
        writel_relaxed(val, pll->base);
 
-       timeout = jiffies + msecs_to_jiffies(10);
-       /* Wait for PLL to lock */
-       do {
-               if (readl_relaxed(pll->base) & BM_PLL_LOCK)
-                       break;
-               if (time_after(jiffies, timeout))
-                       break;
-       } while (1);
+       ret = clk_pllv3_wait_lock(pll);
+       if (ret)
+               return ret;
 
-       if (readl_relaxed(pll->base) & BM_PLL_LOCK)
-               return 0;
-       else
-               return -ETIMEDOUT;
+       val = readl_relaxed(pll->base);
+       val &= ~BM_PLL_BYPASS;
+       writel_relaxed(val, pll->base);
+
+       return 0;
 }
 
 static void clk_pllv3_unprepare(struct clk_hw *hw)
@@ -146,7 +163,7 @@ static int clk_pllv3_set_rate(struct clk_hw *hw, unsigned long rate,
        val |= div;
        writel_relaxed(val, pll->base);
 
-       return 0;
+       return clk_pllv3_wait_lock(pll);
 }
 
 static const struct clk_ops clk_pllv3_ops = {
@@ -202,7 +219,7 @@ static int clk_pllv3_sys_set_rate(struct clk_hw *hw, unsigned long rate,
        val |= div;
        writel_relaxed(val, pll->base);
 
-       return 0;
+       return clk_pllv3_wait_lock(pll);
 }
 
 static const struct clk_ops clk_pllv3_sys_ops = {
@@ -276,7 +293,7 @@ static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate,
        writel_relaxed(mfn, pll->base + PLL_NUM_OFFSET);
        writel_relaxed(mfd, pll->base + PLL_DENOM_OFFSET);
 
-       return 0;
+       return clk_pllv3_wait_lock(pll);
 }
 
 static const struct clk_ops clk_pllv3_av_ops = {
index 7cbe22d0c6e9c8ae4060e71c06d2c7eb73c0d389..24a7899e36a8abed143d2bfdadcf854e0970a14c 100644 (file)
@@ -127,11 +127,6 @@ static inline void imx_smp_prepare(void) {}
 static inline void imx_scu_standby_enable(void) {}
 #endif
 void imx_src_init(void);
-#ifdef CONFIG_HAVE_IMX_SRC
-void imx_src_prepare_restart(void);
-#else
-static inline void imx_src_prepare_restart(void) {}
-#endif
 void imx_gpc_init(void);
 void imx_gpc_pre_suspend(void);
 void imx_gpc_post_resume(void);
index 19bb6441a7d4aaddb106afa71634606acfae7466..c5f95674e9b72c8caa61052a25c7e90521b3ce42 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/dma-mapping.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/eeprom.h>
index 45303bd629022d66ef167d0830f5c6088c5c44d8..639a3dfb00923317871724f1848ace2d9c7e0125 100644 (file)
@@ -23,7 +23,7 @@
 #include <linux/smsc911x.h>
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/delay.h>
 #include <linux/spi/spi.h>
 #include <linux/irq.h>
index e805ac273e9c6cc952e400a4f542f9727881650c..592ddbe031ac714bf7d2d0f0519ba38a3957d0ee 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/io.h>
 #include <linux/mtd/plat-ram.h>
 #include <linux/mtd/physmap.h>
index b726cb1c5fdd638326148cb4ce66783f69dd7659..ac504b67326b12b51ba9c1ccea470b85e74b1dd3 100644 (file)
@@ -24,7 +24,7 @@
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/ulpi.h>
 
index 0910761e8280894918927554598c1f4d1d1f4b79..8825d1217d189e7d026dff24f7b2e41af54fde4a 100644 (file)
@@ -29,7 +29,7 @@
 #include <asm/mach/time.h>
 
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/mfd/mc13xxx.h>
 
 #include "common.h"
index 4754373e7e7d3a97b29e5af8a143bb27379bb9a5..45f7f4e0a447c517bb9b731eb402e33ea3083f43 100644 (file)
@@ -115,21 +115,6 @@ void imx_set_cpu_arg(int cpu, u32 arg)
        writel_relaxed(arg, src_base + SRC_GPR1 + cpu * 8 + 4);
 }
 
-void imx_src_prepare_restart(void)
-{
-       u32 val;
-
-       /* clear enable bits of secondary cores */
-       spin_lock(&scr_lock);
-       val = readl_relaxed(src_base + SRC_SCR);
-       val &= ~(0x7 << BP_SRC_SCR_CORE1_ENABLE);
-       writel_relaxed(val, src_base + SRC_SCR);
-       spin_unlock(&scr_lock);
-
-       /* clear persistent entry register of primary core */
-       writel_relaxed(0, src_base + SRC_GPR1);
-}
-
 void __init imx_src_init(void)
 {
        struct device_node *np;
index e6edcd38b282fdaa74027731841c187ed93cda4d..5e3027d3692f8b02c8f3cb327f935520cdce29f3 100644 (file)
@@ -42,9 +42,6 @@ void mxc_restart(enum reboot_mode mode, const char *cmd)
 {
        unsigned int wcr_enable;
 
-       if (cpu_is_imx6q() || cpu_is_imx6dl())
-               imx_src_prepare_restart();
-
        if (wdog_clk)
                clk_enable(wdog_clk);
 
@@ -55,7 +52,14 @@ void mxc_restart(enum reboot_mode mode, const char *cmd)
 
        /* Assert SRS signal */
        __raw_writew(wcr_enable, wdog_base);
-       /* write twice to ensure the request will not get ignored */
+       /*
+        * Due to imx6q errata ERR004346 (WDOG: WDOG SRS bit requires to be
+        * written twice), we add another two writes to ensure there must be at
+        * least two writes happen in the same one 32kHz clock period.  We save
+        * the target check here, since the writes shouldn't be a huge burden
+        * for other platforms.
+        */
+       __raw_writew(wcr_enable, wdog_base);
        __raw_writew(wcr_enable, wdog_base);
 
        /* wait for reset to assert... */
index 1df6e7602cadb75dac78a961352624b8f855d73f..4fc0a195de0103e865b4827af89dd101f6336241 100644 (file)
@@ -198,7 +198,8 @@ static struct mmci_platform_data mmc_data = {
 static void cp_clcd_enable(struct clcd_fb *fb)
 {
        struct fb_var_screeninfo *var = &fb->fb.var;
-       u32 val = CM_CTRL_STATIC1 | CM_CTRL_STATIC2;
+       u32 val = CM_CTRL_STATIC1 | CM_CTRL_STATIC2
+                       | CM_CTRL_LCDEN0 | CM_CTRL_LCDEN1;
 
        if (var->bits_per_pixel <= 8 ||
            (var->bits_per_pixel == 16 && var->green.length == 5))
index 6d3782d85a9ff6d2db65a71de2632cc0b1151b33..a86fd0ed775788012197270c96ea8190282aed47 100644 (file)
@@ -218,20 +218,6 @@ iop_chan_xor_slot_count(size_t len, int src_cnt, int *slots_per_op)
 #define iop_chan_pq_slot_count iop_chan_xor_slot_count
 #define iop_chan_pq_zero_sum_slot_count iop_chan_xor_slot_count
 
-static inline u32 iop_desc_get_dest_addr(struct iop_adma_desc_slot *desc,
-                                       struct iop_adma_chan *chan)
-{
-       struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
-       return hw_desc->dest_addr;
-}
-
-static inline u32 iop_desc_get_qdest_addr(struct iop_adma_desc_slot *desc,
-                                         struct iop_adma_chan *chan)
-{
-       struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
-       return hw_desc->q_dest_addr;
-}
-
 static inline u32 iop_desc_get_byte_count(struct iop_adma_desc_slot *desc,
                                        struct iop_adma_chan *chan)
 {
@@ -350,18 +336,6 @@ iop_desc_init_pq(struct iop_adma_desc_slot *desc, int src_cnt,
        hw_desc->desc_ctrl = u_desc_ctrl.value;
 }
 
-static inline int iop_desc_is_pq(struct iop_adma_desc_slot *desc)
-{
-       struct iop13xx_adma_desc_hw *hw_desc = desc->hw_desc;
-       union {
-               u32 value;
-               struct iop13xx_adma_desc_ctrl field;
-       } u_desc_ctrl;
-
-       u_desc_ctrl.value = hw_desc->desc_ctrl;
-       return u_desc_ctrl.field.pq_xfer_en;
-}
-
 static inline void
 iop_desc_init_pq_zero_sum(struct iop_adma_desc_slot *desc, int src_cnt,
                          unsigned long flags)
index 489495976fcd794e211d10c82e59e087bd40b79c..8e3e4331c380dabd5c3a818626b4eabc7922776b 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/spi/flash.h>
 #include <linux/spi/spi.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/gpio.h>
 #include <asm/mach/time.h>
 #include <mach/kirkwood.h>
index a7ce69286688434e0e195e3c8a2e24728ff6dc60..d68909b095f1c06b135bac8e07dee46408dd5d40 100644 (file)
@@ -300,7 +300,7 @@ static struct omap_lcd_config osk_lcd_config __initdata = {
 #ifdef CONFIG_OMAP_OSK_MISTRAL
 
 #include <linux/input.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/ads7846.h>
 
index e15ac005ef17d02a102ad87def740ef1211d53d0..1f25f3e99c05481418dcb7aa1472df14cee7202f 100644 (file)
@@ -40,7 +40,7 @@ omap-4-5-common                               =  omap4-common.o omap-wakeupgen.o
 obj-$(CONFIG_ARCH_OMAP4)               += $(omap-4-5-common) $(smp-y) sleep44xx.o
 obj-$(CONFIG_SOC_OMAP5)                        += $(omap-4-5-common) $(smp-y) sleep44xx.o
 obj-$(CONFIG_SOC_AM43XX)               += $(omap-4-5-common)
-obj-$(CONFIG_SOC_DRA7XX)               += $(omap-4-5-common) $(smp-y)
+obj-$(CONFIG_SOC_DRA7XX)               += $(omap-4-5-common) $(smp-y) sleep44xx.o
 
 plus_sec := $(call as-instr,.arch_extension sec,+sec)
 AFLAGS_omap-headsmp.o                  :=-Wa,-march=armv7-a$(plus_sec)
index 33d159e2386e6a86801d7decced3522125c3b8fb..8dd0ec858cf1cc71372cb1e9d97d23232f7ed0de 100644 (file)
@@ -25,7 +25,7 @@
 #include <linux/gpio.h>
 #include <linux/platform_data/gpio-omap.h>
 
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/i2c/twl.h>
 #include <linux/regulator/fixed.h>
 #include <linux/regulator/machine.h>
index 87e41a8b8d4666059c43a49c2f4ea953b3327fb2..f7808349a7346642a58994c2b5a7b43f3dddb5da 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/delay.h>
 #include <linux/workqueue.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/input.h>
 #include <linux/err.h>
 #include <linux/clk.h>
index a516c1bda1418b05612a529ff1673411afe8d8f5..d6ed819ff15ce111faaff0cfa825dc0b70ad55ee 100644 (file)
@@ -510,7 +510,7 @@ static int __init beagle_opp_init(void)
                mpu_dev = get_cpu_device(0);
                iva_dev = omap_device_get_by_hwmod_name("iva");
 
-               if (IS_ERR(mpu_dev) || IS_ERR(iva_dev)) {
+               if (!mpu_dev || IS_ERR(iva_dev)) {
                        pr_err("%s: Aiee.. no mpu/dsp devices? %p %p\n",
                                __func__, mpu_dev, iva_dev);
                        return -ENODEV;
index ba8342fef799ee10c3248bc75188bad47b5971bf..119efaf5808ab3df5291969f311e555704e84ee2 100644 (file)
@@ -32,7 +32,7 @@
 #include <linux/spi/spi.h>
 #include <linux/interrupt.h>
 #include <linux/smsc911x.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/usb/phy.h>
 
 #include <asm/mach-types.h>
index 03a2829beb8e4c69144dfd5e5eb639189b836b02..3b05aea56d1f5636d5ff2e154513cf22349b3eec 100644 (file)
@@ -381,6 +381,42 @@ static struct clk_hw_omap dpll4_ck_hw = {
 
 DEFINE_STRUCT_CLK(dpll4_ck, dpll3_ck_parent_names, dpll4_ck_ops);
 
+static const struct clk_div_table dpll4_mx_ck_div_table[] = {
+       { .div = 1, .val = 1 },
+       { .div = 2, .val = 2 },
+       { .div = 3, .val = 3 },
+       { .div = 4, .val = 4 },
+       { .div = 5, .val = 5 },
+       { .div = 6, .val = 6 },
+       { .div = 7, .val = 7 },
+       { .div = 8, .val = 8 },
+       { .div = 9, .val = 9 },
+       { .div = 10, .val = 10 },
+       { .div = 11, .val = 11 },
+       { .div = 12, .val = 12 },
+       { .div = 13, .val = 13 },
+       { .div = 14, .val = 14 },
+       { .div = 15, .val = 15 },
+       { .div = 16, .val = 16 },
+       { .div = 17, .val = 17 },
+       { .div = 18, .val = 18 },
+       { .div = 19, .val = 19 },
+       { .div = 20, .val = 20 },
+       { .div = 21, .val = 21 },
+       { .div = 22, .val = 22 },
+       { .div = 23, .val = 23 },
+       { .div = 24, .val = 24 },
+       { .div = 25, .val = 25 },
+       { .div = 26, .val = 26 },
+       { .div = 27, .val = 27 },
+       { .div = 28, .val = 28 },
+       { .div = 29, .val = 29 },
+       { .div = 30, .val = 30 },
+       { .div = 31, .val = 31 },
+       { .div = 32, .val = 32 },
+       { .div = 0 },
+};
+
 DEFINE_CLK_DIVIDER(dpll4_m5_ck, "dpll4_ck", &dpll4_ck, 0x0,
                   OMAP_CM_REGADDR(OMAP3430_CAM_MOD, CM_CLKSEL),
                   OMAP3430_CLKSEL_CAM_SHIFT, OMAP3630_CLKSEL_CAM_WIDTH,
@@ -524,10 +560,10 @@ static const struct clksel_rate clkout2_src_54m_rates[] = {
        { .div = 0 }
 };
 
-DEFINE_CLK_DIVIDER(dpll4_m3_ck, "dpll4_ck", &dpll4_ck, 0x0,
+DEFINE_CLK_DIVIDER_TABLE(dpll4_m3_ck, "dpll4_ck", &dpll4_ck, 0x0,
                   OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL),
                   OMAP3430_CLKSEL_TV_SHIFT, OMAP3630_CLKSEL_TV_WIDTH,
-                  CLK_DIVIDER_ONE_BASED, NULL);
+                  0, dpll4_mx_ck_div_table, NULL);
 
 static struct clk dpll4_m3x2_ck;
 
@@ -847,10 +883,10 @@ static struct clk dpll3_m3x2_ck_3630 = {
 
 DEFINE_CLK_FIXED_FACTOR(dpll3_x2_ck, "dpll3_ck", &dpll3_ck, 0x0, 2, 1);
 
-DEFINE_CLK_DIVIDER(dpll4_m4_ck, "dpll4_ck", &dpll4_ck, 0x0,
+DEFINE_CLK_DIVIDER_TABLE(dpll4_m4_ck, "dpll4_ck", &dpll4_ck, 0x0,
                   OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_CLKSEL),
                   OMAP3430_CLKSEL_DSS1_SHIFT, OMAP3630_CLKSEL_DSS1_WIDTH,
-                  CLK_DIVIDER_ONE_BASED, NULL);
+                  0, dpll4_mx_ck_div_table, NULL);
 
 static struct clk dpll4_m4x2_ck;
 
@@ -869,7 +905,8 @@ static struct clk_hw_omap dpll4_m4x2_ck_hw = {
        .clkdm_name     = "dpll4_clkdm",
 };
 
-DEFINE_STRUCT_CLK(dpll4_m4x2_ck, dpll4_m4x2_ck_parent_names, dpll4_m5x2_ck_ops);
+DEFINE_STRUCT_CLK_FLAGS(dpll4_m4x2_ck, dpll4_m4x2_ck_parent_names,
+               dpll4_m5x2_ck_ops, CLK_SET_RATE_PARENT);
 
 static struct clk dpll4_m4x2_ck_3630 = {
        .name           = "dpll4_m4x2_ck",
@@ -877,6 +914,7 @@ static struct clk dpll4_m4x2_ck_3630 = {
        .parent_names   = dpll4_m4x2_ck_parent_names,
        .num_parents    = ARRAY_SIZE(dpll4_m4x2_ck_parent_names),
        .ops            = &dpll4_m5x2_ck_3630_ops,
+       .flags          = CLK_SET_RATE_PARENT,
 };
 
 DEFINE_CLK_DIVIDER(dpll4_m6_ck, "dpll4_ck", &dpll4_ck, 0x0,
@@ -968,8 +1006,9 @@ static struct clk_hw_omap dss1_alwon_fck_3430es1_hw = {
        .clkdm_name     = "dss_clkdm",
 };
 
-DEFINE_STRUCT_CLK(dss1_alwon_fck_3430es1, dss1_alwon_fck_3430es1_parent_names,
-                 aes2_ick_ops);
+DEFINE_STRUCT_CLK_FLAGS(dss1_alwon_fck_3430es1,
+               dss1_alwon_fck_3430es1_parent_names, aes2_ick_ops,
+               CLK_SET_RATE_PARENT);
 
 static struct clk dss1_alwon_fck_3430es2;
 
@@ -983,8 +1022,9 @@ static struct clk_hw_omap dss1_alwon_fck_3430es2_hw = {
        .clkdm_name     = "dss_clkdm",
 };
 
-DEFINE_STRUCT_CLK(dss1_alwon_fck_3430es2, dss1_alwon_fck_3430es1_parent_names,
-                 aes2_ick_ops);
+DEFINE_STRUCT_CLK_FLAGS(dss1_alwon_fck_3430es2,
+               dss1_alwon_fck_3430es1_parent_names, aes2_ick_ops,
+               CLK_SET_RATE_PARENT);
 
 static struct clk dss2_alwon_fck;
 
index b237950eb8a319f9fb879d051245cc7c6fea6968..ec0dc0b1755ef97c32424b8a10db8a878e82c15c 100644 (file)
@@ -830,7 +830,8 @@ DEFINE_CLK_GATE(dss_tv_clk, "extalt_clkin_ck", &extalt_clkin_ck, 0x0,
                OMAP4430_CM_DSS_DSS_CLKCTRL,
                OMAP4430_OPTFCLKEN_TV_CLK_SHIFT, 0x0, NULL);
 
-DEFINE_CLK_GATE(dss_dss_clk, "dpll_per_m5x2_ck", &dpll_per_m5x2_ck, 0x0,
+DEFINE_CLK_GATE(dss_dss_clk, "dpll_per_m5x2_ck", &dpll_per_m5x2_ck,
+               CLK_SET_RATE_PARENT,
                OMAP4430_CM_DSS_DSS_CLKCTRL, OMAP4430_OPTFCLKEN_DSSCLK_SHIFT,
                0x0, NULL);
 
index ef990118d32b2f4205c25c58aec555465096aa39..2757504a13c42ae11319f9f72f4fa6ba50babd29 100644 (file)
@@ -83,7 +83,7 @@ void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg)
        pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
                 gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
                 &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
-       if (!pdev) {
+       if (IS_ERR(pdev)) {
                pr_err("Unable to register platform device\n");
                gpio_free(gpmc_cfg->gpio_reset);
                goto free2;
index b69dd9abb50aeb0003998b24d7df9063a6a41cb1..53f0735817bb7cf984f3fada24c7e8960941860c 100644 (file)
@@ -621,6 +621,7 @@ static int _od_suspend_noirq(struct device *dev)
 
        if (!ret && !pm_runtime_status_suspended(dev)) {
                if (pm_generic_runtime_suspend(dev) == 0) {
+                       pm_runtime_set_suspended(dev);
                        omap_device_idle(pdev);
                        od->flags |= OMAP_DEVICE_SUSPENDED;
                }
@@ -634,10 +635,18 @@ static int _od_resume_noirq(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct omap_device *od = to_omap_device(pdev);
 
-       if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
-           !pm_runtime_status_suspended(dev)) {
+       if (od->flags & OMAP_DEVICE_SUSPENDED) {
                od->flags &= ~OMAP_DEVICE_SUSPENDED;
                omap_device_enable(pdev);
+               /*
+                * XXX: we run before core runtime pm has resumed itself. At
+                * this point in time, we just restore the runtime pm state and
+                * considering symmetric operations in resume, we donot expect
+                * to fail. If we failed, something changed in core runtime_pm
+                * framework OR some device driver messed things up, hence, WARN
+                */
+               WARN(pm_runtime_set_active(dev),
+                    "Could not set %s runtime state active\n", dev_name(dev));
                pm_generic_runtime_resume(dev);
        }
 
index a085d9cc1f5d0c01fbe02e2f490e18037e450a33..7a976065e1389cf8396c28e5da37ca6574e8cad4 100644 (file)
@@ -42,7 +42,8 @@ extern u32 omap4_prm_vcvp_read(u8 offset);
 extern void omap4_prm_vcvp_write(u32 val, u8 offset);
 extern u32 omap4_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset);
 
-#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
+#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5) || \
+       defined(CONFIG_SOC_DRA7XX)
 void omap44xx_prm_reconfigure_io_chain(void);
 #else
 static inline void omap44xx_prm_reconfigure_io_chain(void)
index f9423493ed36407627f2bf1e7bdab115d58ad2c1..584439bfa59f4ea0631deecac94920eb4eb97280 100644 (file)
@@ -310,6 +310,7 @@ static struct platform_pwm_backlight_data cm_x300_backlight_data = {
        .max_brightness = 100,
        .dft_brightness = 100,
        .pwm_period_ns  = 10000,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device cm_x300_backlight_device = {
index 2d4a7b4d5d78b8c5d69dd985f6fbef683f8699e3..3aa264640c9dd5a0457b99e5a34897bd684ad3ba 100644 (file)
@@ -189,6 +189,7 @@ static struct platform_pwm_backlight_data income_backlight_data = {
        .max_brightness = 0x3ff,
        .dft_brightness = 0x1ff,
        .pwm_period_ns  = 1000000,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device income_backlight = {
index fe2eb8394dffe9c289a0a3a2214efc4af24bdb0b..ab93441e596ed7eb6d3e0f4552d029626e81e42c 100644 (file)
@@ -54,6 +54,7 @@ static struct platform_pwm_backlight_data ezx_backlight_data = {
        .max_brightness = 1023,
        .dft_brightness = 1023,
        .pwm_period_ns  = 78770,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device ezx_backlight_device = {
index 133109ec7332b23d1c412509f66a31f52aaaa412..a7c30eb0c8db18aaffd429ec7e637a14a892ad81 100644 (file)
@@ -561,6 +561,7 @@ static struct platform_pwm_backlight_data backlight_data = {
        .max_brightness = 200,
        .dft_brightness = 100,
        .pwm_period_ns  = 30923,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device backlight = {
index 1255ee00f3d1d7c1f80f9cd0b2a28936c47353ad..9f6ec167902a6bc1c2db823d257e006550a3c3b0 100644 (file)
@@ -269,6 +269,7 @@ static struct platform_pwm_backlight_data lpd270_backlight_data = {
        .max_brightness = 1,
        .dft_brightness = 1,
        .pwm_period_ns  = 78770,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device lpd270_backlight_device = {
index f44532fc648b1982ded0d249a18005b84647767d..fab30d666cc72534493839521324a577a40e5a54 100644 (file)
@@ -378,6 +378,7 @@ static struct platform_pwm_backlight_data backlight_data = {
        .max_brightness = 272,
        .dft_brightness = 100,
        .pwm_period_ns  = 30923,
+       .enable_gpio    = -1,
        .init           = magician_backlight_init,
        .notify         = magician_backlight_notify,
        .exit           = magician_backlight_exit,
index dd70343c87085edf4da384fedd434a339802756c..08ccc0718f319e4f7209e8592e50d0f26b92862d 100644 (file)
@@ -338,6 +338,7 @@ static struct platform_pwm_backlight_data mainstone_backlight_data = {
        .max_brightness = 1023,
        .dft_brightness = 1023,
        .pwm_period_ns  = 78770,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device mainstone_backlight_device = {
index acc9d3cc0762174f071a22a93cf8ae34f49b9cbb..f70583fee59f8b61e59a1022f07b36c26fd3210c 100644 (file)
@@ -186,6 +186,7 @@ static struct platform_pwm_backlight_data mioa701_backlight_data = {
        .max_brightness = 100,
        .dft_brightness = 50,
        .pwm_period_ns  = 4000 * 1024,  /* Fl = 250kHz */
+       .enable_gpio    = -1,
 };
 
 /*
index 17d4c53017cade633c95315782128c0e0620c776..e54a296fb81f8b045f814860c0dc729edb71d2c4 100644 (file)
@@ -322,6 +322,7 @@ static struct platform_pwm_backlight_data palm27x_backlight_data = {
        .max_brightness = 0xfe,
        .dft_brightness = 0x7e,
        .pwm_period_ns  = 3500 * 1024,
+       .enable_gpio    = -1,
        .init           = palm27x_backlight_init,
        .notify         = palm27x_backlight_notify,
        .exit           = palm27x_backlight_exit,
index 100b176f7e882aaa2ba5047fefc19eb44d514394..7691c974ca4bd0b6ade4c467e3ea6a26c611d9ce 100644 (file)
@@ -166,45 +166,12 @@ static inline void palmtc_keys_init(void) {}
  * Backlight
  ******************************************************************************/
 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
-static int palmtc_backlight_init(struct device *dev)
-{
-       int ret;
-
-       ret = gpio_request(GPIO_NR_PALMTC_BL_POWER, "BL POWER");
-       if (ret)
-               goto err;
-       ret = gpio_direction_output(GPIO_NR_PALMTC_BL_POWER, 1);
-       if (ret)
-               goto err2;
-
-       return 0;
-
-err2:
-       gpio_free(GPIO_NR_PALMTC_BL_POWER);
-err:
-       return ret;
-}
-
-static int palmtc_backlight_notify(struct device *dev, int brightness)
-{
-       /* backlight is on when GPIO16 AF0 is high */
-       gpio_set_value(GPIO_NR_PALMTC_BL_POWER, brightness);
-       return brightness;
-}
-
-static void palmtc_backlight_exit(struct device *dev)
-{
-       gpio_free(GPIO_NR_PALMTC_BL_POWER);
-}
-
 static struct platform_pwm_backlight_data palmtc_backlight_data = {
        .pwm_id         = 1,
        .max_brightness = PALMTC_MAX_INTENSITY,
        .dft_brightness = PALMTC_MAX_INTENSITY,
        .pwm_period_ns  = PALMTC_PERIOD_NS,
-       .init           = palmtc_backlight_init,
-       .notify         = palmtc_backlight_notify,
-       .exit           = palmtc_backlight_exit,
+       .enable_gpio    = GPIO_NR_PALMTC_BL_POWER,
 };
 
 static struct platform_device palmtc_backlight = {
index 0742721ced2da7eebf983026f288265e039e139f..956fd24ee6fdca69b63bed29ebe4b9ebe567fd83 100644 (file)
@@ -165,6 +165,7 @@ static struct platform_pwm_backlight_data palmte2_backlight_data = {
        .max_brightness = PALMTE2_MAX_INTENSITY,
        .dft_brightness = PALMTE2_MAX_INTENSITY,
        .pwm_period_ns  = PALMTE2_PERIOD_NS,
+       .enable_gpio    = -1,
        .init           = palmte2_backlight_init,
        .notify         = palmte2_backlight_notify,
        .exit           = palmte2_backlight_exit,
index 3133ba82c50807ec105a57f1dfe4b7d06a887c31..9a4e470f162bc0fc2403a1985e25d0cfd5bd2018 100644 (file)
@@ -153,6 +153,7 @@ static struct platform_pwm_backlight_data pcm990_backlight_data = {
        .max_brightness = 1023,
        .dft_brightness = 1023,
        .pwm_period_ns  = 78770,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device pcm990_backlight_device = {
index 969b0ba7fa703a688a7078250c2118a3e19fe4b3..8386dc30b3e40d7c8eefac202411159932553327 100644 (file)
@@ -539,6 +539,7 @@ static struct platform_pwm_backlight_data raumfeld_pwm_backlight_data = {
        .dft_brightness = 100,
        /* 10000 ns = 10 ms ^= 100 kHz */
        .pwm_period_ns  = 10000,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device raumfeld_pwm_backlight_device = {
index 62aea3e835f315266ba887367310ec249503cd21..01de542432a6107b896277da2c5c392c65e9aff6 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <linux/i2c/pxa-i2c.h>
 #include <linux/i2c/pcf857x.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/smc91x.h>
 #include <linux/gpio.h>
 #include <linux/leds.h>
index 4680efe553459bd6c98e3d4c771d7633c3a840a1..a71da84e784b75fcf9f740758ee0cb0604d3f741 100644 (file)
@@ -175,6 +175,7 @@ static struct platform_pwm_backlight_data tavorevb_backlight_data[] = {
                .max_brightness = 100,
                .dft_brightness = 100,
                .pwm_period_ns  = 100000,
+               .enable_gpio    = -1,
        },
        [1] = {
                /* secondary backlight */
@@ -182,6 +183,7 @@ static struct platform_pwm_backlight_data tavorevb_backlight_data[] = {
                .max_brightness = 100,
                .dft_brightness = 100,
                .pwm_period_ns  = 100000,
+               .enable_gpio    = -1,
        },
 };
 
index 9c363c081d3facb3be9ebe8693b32c2db9702bbc..29905b127ad988b68ec02a09b441cb48e9c59704 100644 (file)
@@ -401,6 +401,7 @@ static struct platform_pwm_backlight_data viper_backlight_data = {
        .max_brightness = 100,
        .dft_brightness = 100,
        .pwm_period_ns  = 1000000,
+       .enable_gpio    = -1,
        .init           = viper_backlight_init,
        .notify         = viper_backlight_notify,
        .exit           = viper_backlight_exit,
index 2513d8f4931f49675dfd8322edd03c2ffbd3ca0f..e1a121b36cfa6eef0e9dec7155da7f929e1075ed 100644 (file)
@@ -206,6 +206,7 @@ static struct platform_pwm_backlight_data z2_backlight_data[] = {
                .max_brightness = 1023,
                .dft_brightness = 0,
                .pwm_period_ns  = 1260320,
+               .enable_gpio    = -1,
        },
        [1] = {
                /* LCD Backlight */
@@ -213,6 +214,7 @@ static struct platform_pwm_backlight_data z2_backlight_data[] = {
                .max_brightness = 1023,
                .dft_brightness = 512,
                .pwm_period_ns  = 1260320,
+               .enable_gpio    = -1,
        },
 };
 
index 36cf7cf95ec1d5d4fe2fd764067b7d640247aa2e..77daea478e88709aa20568d30073ae3c625efa73 100644 (file)
@@ -125,6 +125,7 @@ static struct platform_pwm_backlight_data zylonite_backlight_data = {
        .max_brightness = 100,
        .dft_brightness = 100,
        .pwm_period_ns  = 10000,
+       .enable_gpio    = -1,
 };
 
 static struct platform_device zylonite_backlight_device = {
index 74dd47988b415b217dbcd931794e4fd40d5dcdd4..952b6a040d1fcaa5694d21459acec9880ba626f0 100644 (file)
@@ -504,6 +504,7 @@ static struct platform_pwm_backlight_data backlight_data = {
        .dft_brightness = 50,
        /* tcnt = 0x31 */
        .pwm_period_ns  = 36296,
+       .enable_gpio    = -1,
        .init           = h1940_backlight_init,
        .notify         = h1940_backlight_notify,
        .exit           = h1940_backlight_exit,
index a83db46320bc6d1e8345ebee8aefd3845f9b347f..4a18d49a63e0b5d7e84dc0018f9473d8f12f164a 100644 (file)
@@ -24,7 +24,7 @@
 #include <linux/io.h>
 #include <linux/serial_core.h>
 #include <linux/dm9000.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 #include <linux/platform_device.h>
 #include <linux/gpio_keys.h>
 #include <linux/i2c.h>
index 206b1f7546d16e973aaa60030ce777684cdbfe57..034b7fe45c49294908bfc5b3716d52f6d9bec3e6 100644 (file)
@@ -522,6 +522,7 @@ static struct platform_pwm_backlight_data rx1950_backlight_data = {
        .max_brightness = 24,
        .dft_brightness = 4,
        .pwm_period_ns = 48000,
+       .enable_gpio = -1,
        .init = rx1950_backlight_init,
        .notify = rx1950_backlight_notify,
        .exit = rx1950_backlight_exit,
index aca7d16e195dec0fda2989680cc58e73abb50315..758e31b265501de472aa6eba453038385e102536 100644 (file)
@@ -114,6 +114,7 @@ static struct platform_pwm_backlight_data crag6410_backlight_data = {
        .max_brightness = 1000,
        .dft_brightness = 600,
        .pwm_period_ns  = 100000,       /* about 1kHz */
+       .enable_gpio    = -1,
 };
 
 static struct platform_device crag6410_backlight_device = {
index e8064044ef796d35a12bfcc0e06c86dea065dca1..614a03a92cf70545be3fd60bb66a29dc46b1fb6e 100644 (file)
@@ -114,6 +114,7 @@ static struct platform_pwm_backlight_data hmt_backlight_data = {
        .max_brightness = 100 * 256,
        .dft_brightness = 40 * 256,
        .pwm_period_ns  = 1000000000 / (100 * 256 * 20),
+       .enable_gpio    = -1,
        .init           = hmt_bl_init,
        .notify         = hmt_bl_notify,
        .exit           = hmt_bl_exit,
index 0f47237be3b2dd2286fe0582791548d16df3a786..a6b338fd0470d6b55f0601058f4dc5446cfc480c 100644 (file)
@@ -151,6 +151,7 @@ static struct platform_pwm_backlight_data smartq_backlight_data = {
        .max_brightness = 1000,
        .dft_brightness = 600,
        .pwm_period_ns  = 1000000000 / (1000 * 20),
+       .enable_gpio    = -1,
        .init           = smartq_bl_init,
 };
 
index 2a7b32ca5c96a3037c007eeb032092cf2127bfec..d5ea938cc9a1a03f7b6f884155de620a3fc0c3b3 100644 (file)
@@ -625,6 +625,7 @@ static struct samsung_bl_gpio_info smdk6410_bl_gpio_info = {
 
 static struct platform_pwm_backlight_data smdk6410_bl_data = {
        .pwm_id = 1,
+       .enable_gpio = -1,
 };
 
 static struct s3c_hsotg_plat smdk6410_hsotg_pdata;
index 0b00304c1e91840f1760c4cae2c80b4d9441ea79..9efdcc03df3b5477bc51ccb8196f0f7fcccabd97 100644 (file)
@@ -223,6 +223,7 @@ static struct samsung_bl_gpio_info smdk6440_bl_gpio_info = {
 
 static struct platform_pwm_backlight_data smdk6440_bl_data = {
        .pwm_id = 1,
+       .enable_gpio = -1,
 };
 
 static void __init smdk6440_map_io(void)
index 5949296e88fdc07af89538478f88e0a142e5f3b7..c3cacc067efed25aff9740a2d65b795c4dd59266 100644 (file)
@@ -242,6 +242,7 @@ static struct samsung_bl_gpio_info smdk6450_bl_gpio_info = {
 
 static struct platform_pwm_backlight_data smdk6450_bl_data = {
        .pwm_id = 1,
+       .enable_gpio = -1,
 };
 
 static void __init smdk6450_map_io(void)
index 7c57a221785e65d3aeb55e9c637397b91a857daa..9e256b9fc9303a9bf3b5411e0b8d70287254e036 100644 (file)
@@ -216,6 +216,7 @@ static struct samsung_bl_gpio_info smdkc100_bl_gpio_info = {
 
 static struct platform_pwm_backlight_data smdkc100_bl_data = {
        .pwm_id = 0,
+       .enable_gpio = -1,
 };
 
 static void __init smdkc100_map_io(void)
index 6d72bb992e389b59872b3fead4742d4d3669e3bb..f52cc15c2d85a221a161f5c5d18fbf30c815dd72 100644 (file)
@@ -279,6 +279,7 @@ static struct samsung_bl_gpio_info smdkv210_bl_gpio_info = {
 static struct platform_pwm_backlight_data smdkv210_bl_data = {
        .pwm_id = 3,
        .pwm_period_ns = 1000,
+       .enable_gpio = -1,
 };
 
 static void __init smdkv210_map_io(void)
index 8bc8e4c5884767f381c09da79ffcf2b52e2ffdc9..958e3cbf0ac2f2110e7f4fc9ca41dc19e66e4ca8 100644 (file)
@@ -423,6 +423,7 @@ static struct platform_pwm_backlight_data pwm_backlight_data = {
        .max_brightness = 255,
        .dft_brightness = 255,
        .pwm_period_ns = 33333, /* 30kHz */
+       .enable_gpio = -1,
 };
 
 static struct platform_device pwm_backlight_device = {
index 835833e3c4f8fb193f6d177c88ef35199488b33f..d71654bc8d54d0be5aef108a43d5f0673bd68d40 100644 (file)
@@ -12,7 +12,7 @@ menuconfig ARCH_STI
        select HAVE_ARM_SCU if SMP
        select ARCH_REQUIRE_GPIOLIB
        select ARM_ERRATA_754322
-       select ARM_ERRATA_764369
+       select ARM_ERRATA_764369 if SMP
        select ARM_ERRATA_775420
        select PL310_ERRATA_753970 if CACHE_PL310
        select PL310_ERRATA_769419 if CACHE_PL310
@@ -30,7 +30,7 @@ config SOC_STIH415
        default y
        help
          This enables support for STMicroelectronics Digital Consumer
-         Electronics family StiH415 parts, primarily targetted at set-top-box
+         Electronics family StiH415 parts, primarily targeted at set-top-box
          and other digital audio/video applications using Flattned Device
          Trees.
 
@@ -39,7 +39,7 @@ config SOC_STIH416
        default y
        help
          This enables support for STMicroelectronics Digital Consumer
-         Electronics family StiH416 parts, primarily targetted at set-top-box
+         Electronics family StiH416 parts, primarily targeted at set-top-box
          and other digital audio/video applications using Flattened Device
          Trees.
 
index ce553d557c31caf1670e50ceadad19c067d2864c..73368176c6e8592ecc5f2f0155d5598885692fd3 100644 (file)
@@ -90,9 +90,9 @@ static void __init tegra_init_cache(void)
 
 static void __init tegra_init_early(void)
 {
-       tegra_cpu_reset_handler_init();
        tegra_apb_io_init();
        tegra_init_fuse();
+       tegra_cpu_reset_handler_init();
        tegra_init_cache();
        tegra_powergate_init();
        tegra_hotplug_init();
index d51f9565567cd1d27a197ab83a7ab35618072147..be4ad0b21c082abf990d00bec2f14d665672e78d 100644 (file)
@@ -70,6 +70,7 @@ static struct samsung_bl_drvdata samsung_dfl_bl_data __initdata = {
                .max_brightness = 255,
                .dft_brightness = 255,
                .pwm_period_ns  = 78770,
+               .enable_gpio    = -1,
                .init           = samsung_bl_init,
                .exit           = samsung_bl_exit,
        },
@@ -121,6 +122,10 @@ void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
                samsung_bl_data->lth_brightness = bl_data->lth_brightness;
        if (bl_data->pwm_period_ns)
                samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns;
+       if (bl_data->enable_gpio >= 0)
+               samsung_bl_data->enable_gpio = bl_data->enable_gpio;
+       if (bl_data->enable_gpio_flags)
+               samsung_bl_data->enable_gpio_flags = bl_data->enable_gpio_flags;
        if (bl_data->init)
                samsung_bl_data->init = bl_data->init;
        if (bl_data->notify)
index 23a3c4791d86cb71f9a2520e2176212b1e107503..720e70b66ffdcf6eff60efc964c32e9a0584325b 100644 (file)
@@ -88,12 +88,6 @@ static inline struct thread_info *current_thread_info(void)
 
 #endif
 
-/*
- * We use bit 30 of the preempt_count to indicate that kernel
- * preemption is occurring.  See <asm/hardirq.h>.
- */
-#define PREEMPT_ACTIVE 0x40000000
-
 /*
  * thread information flags:
  *  TIF_SYSCALL_TRACE  - syscall trace active
index 6dc62e1f94c7801532c9a3bc0be13abe3f8009e4..a978f3fe7c25a2fc651b19179b846f3939047bd9 100644 (file)
@@ -66,8 +66,6 @@ static inline struct thread_info *current_thread_info(void)
 
 #endif /* !__ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE         0x40000000
-
 /*
  * Thread information flags
  * - these are process state flags that various assembly files may need to access
index 13eb73231a9a417a243920c9b641db735b185559..4ca39ab6b2bf98c12b260fef822473ae75820c2f 100644 (file)
@@ -102,7 +102,7 @@ CONFIG_I2C_CHARDEV=y
 CONFIG_I2C_BLACKFIN_TWI=y
 CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=100
 CONFIG_SPI=y
-CONFIG_SPI_BFIN6XX=y
+CONFIG_SPI_BFIN_V3=y
 CONFIG_GPIOLIB=y
 CONFIG_GPIO_SYSFS=y
 # CONFIG_HWMON is not set
index c078dd78d998b54a5e39889bfa545dc58b964030..58b54a6d5a1627285ccfcfe76dae5eb0b5fec7ff 100644 (file)
@@ -12,9 +12,6 @@
 extern void ack_bad_irq(unsigned int irq);
 #define ack_bad_irq ack_bad_irq
 
-/* Define until common code gets sane defaults */
-#define HARDIRQ_BITS 9
-
 #include <asm-generic/hardirq.h>
 
 #endif
index 4ae1144a457821c9349cfa0c4026e481f86a6545..2fd04f10cc266b86d6a88c786278c18fd2a604fb 100644 (file)
@@ -23,8 +23,7 @@
 /*
  * pm save bfin pint registers
  */
-struct bfin_pm_pint_save {
-       u32 mask_set;
+struct adi_pm_pint_save {
        u32 assign;
        u32 edge_set;
        u32 invert_set;
index 4fbf83575db1ef8c363d75b374fe25cec15e162d..4b2a992794d77b187c657ad515d9db17bf4002ed 100644 (file)
 #include <mach/irq.h>
 
 /* init functions only */
-extern int __init init_arch_irq(void);
+extern int init_arch_irq(void);
 extern void init_exception_vectors(void);
-extern void __init program_IAR(void);
+extern void program_IAR(void);
 #ifdef init_mach_irq
-extern void __init init_mach_irq(void);
+extern void init_mach_irq(void);
 #else
 # define init_mach_irq()
 #endif
index 3894005337ba7d8628de4f7de2f9f7dd8f5b603d..55f473bdad361a42ca625433a8d8bfb629f378bf 100644 (file)
@@ -88,8 +88,6 @@ static inline struct thread_info *current_thread_info(void)
 #define TI_CPU         12
 #define TI_PREEMPT     16
 
-#define        PREEMPT_ACTIVE  0x4000000
-
 /*
  * thread information flag bit numbers
  */
index ed978f1c5cb9970933c102300722ae8051774d7e..a017359c182668f71583ce013ae92263b95c69e6 100644 (file)
 #include <linux/err.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-#include <asm/blackfin.h>
-#include <asm/gpio.h>
-#include <asm/portmux.h>
+#include <linux/gpio.h>
 #include <linux/irq.h>
-#include <asm/irq_handler.h>
 
 #if ANOMALY_05000311 || ANOMALY_05000323
 enum {
@@ -58,19 +55,6 @@ static struct gpio_port_t * const gpio_array[] = {
        (struct gpio_port_t *) FIO0_FLAG_D,
        (struct gpio_port_t *) FIO1_FLAG_D,
        (struct gpio_port_t *) FIO2_FLAG_D,
-#elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x) 
-       (struct gpio_port_t *)PORTA_FER,
-       (struct gpio_port_t *)PORTB_FER,
-       (struct gpio_port_t *)PORTC_FER,
-       (struct gpio_port_t *)PORTD_FER,
-       (struct gpio_port_t *)PORTE_FER,
-       (struct gpio_port_t *)PORTF_FER,
-       (struct gpio_port_t *)PORTG_FER,
-# if defined(CONFIG_BF54x)
-       (struct gpio_port_t *)PORTH_FER,
-       (struct gpio_port_t *)PORTI_FER,
-       (struct gpio_port_t *)PORTJ_FER,
-# endif
 #else
 # error no gpio arrays defined
 #endif
@@ -169,12 +153,6 @@ DECLARE_RESERVED_MAP(gpio_irq, GPIO_BANK_NUM);
 
 inline int check_gpio(unsigned gpio)
 {
-#if defined(CONFIG_BF54x)
-       if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
-           || gpio == GPIO_PH14 || gpio == GPIO_PH15
-           || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
-               return -EINVAL;
-#endif
        if (gpio >= MAX_BLACKFIN_GPIOS)
                return -EINVAL;
        return 0;
@@ -212,12 +190,6 @@ static void port_setup(unsigned gpio, unsigned short usage)
        else
                *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
        SSYNC();
-#elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-       if (usage == GPIO_USAGE)
-               gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
-       else
-               gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
-       SSYNC();
 #endif
 }
 
@@ -255,7 +227,7 @@ static int portmux_group_check(unsigned short per)
        u16 ident = P_IDENT(per);
        u16 function = P_FUNCT2MUX(per);
        s8 offset = port_mux[ident];
-       u16 m, pmux, pfunc;
+       u16 m, pmux, pfunc, mask;
 
        if (offset < 0)
                return 0;
@@ -270,10 +242,12 @@ static int portmux_group_check(unsigned short per)
                        continue;
 
                if (offset == 1)
-                       pfunc = (pmux >> offset) & 3;
+                       mask = 3;
                else
-                       pfunc = (pmux >> offset) & 1;
-               if (pfunc != function) {
+                       mask = 1;
+
+               pfunc = (pmux >> offset) & mask;
+               if (pfunc != (function & mask)) {
                        pr_err("pin group conflict! request pin %d func %d conflict with pin %d func %d\n",
                                ident, function, m, pfunc);
                        return -EINVAL;
@@ -288,43 +262,21 @@ static void portmux_setup(unsigned short per)
        u16 ident = P_IDENT(per);
        u16 function = P_FUNCT2MUX(per);
        s8 offset = port_mux[ident];
-       u16 pmux;
+       u16 pmux, mask;
 
        if (offset == -1)
                return;
 
        pmux = bfin_read_PORT_MUX();
-       if (offset != 1)
-               pmux &= ~(1 << offset);
+       if (offset == 1)
+               mask = 3;
        else
-               pmux &= ~(3 << 1);
-       pmux |= (function << offset);
-       bfin_write_PORT_MUX(pmux);
-}
-#elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-inline void portmux_setup(unsigned short per)
-{
-       u16 ident = P_IDENT(per);
-       u16 function = P_FUNCT2MUX(per);
-       u32 pmux;
+               mask = 1;
 
-       pmux = gpio_array[gpio_bank(ident)]->port_mux;
+       pmux &= ~(mask << offset);
+       pmux |= ((function & mask) << offset);
 
-       pmux &= ~(0x3 << (2 * gpio_sub_n(ident)));
-       pmux |= (function & 0x3) << (2 * gpio_sub_n(ident));
-
-       gpio_array[gpio_bank(ident)]->port_mux = pmux;
-}
-
-inline u16 get_portmux(unsigned short per)
-{
-       u16 ident = P_IDENT(per);
-       u32 pmux = gpio_array[gpio_bank(ident)]->port_mux;
-       return (pmux >> (2 * gpio_sub_n(ident)) & 0x3);
-}
-static int portmux_group_check(unsigned short per)
-{
-       return 0;
+       bfin_write_PORT_MUX(pmux);
 }
 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
 static int portmux_group_check(unsigned short per)
@@ -379,7 +331,6 @@ static int portmux_group_check(unsigned short per)
 }
 #endif
 
-#if !(defined(CONFIG_BF54x) || defined(CONFIG_BF60x))
 /***********************************************************
 *
 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
@@ -572,7 +523,7 @@ static const unsigned int sic_iwr_irqs[] = {
 *************************************************************
 * MODIFICATION HISTORY :
 **************************************************************/
-int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl)
+int bfin_gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl)
 {
        unsigned long flags;
 
@@ -591,7 +542,7 @@ int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl)
        return 0;
 }
 
-int bfin_pm_standby_ctrl(unsigned ctrl)
+int bfin_gpio_pm_standby_ctrl(unsigned ctrl)
 {
        u16 bank, mask, i;
 
@@ -682,53 +633,6 @@ void bfin_gpio_pm_hibernate_restore(void)
 
 
 #endif
-#else /* CONFIG_BF54x || CONFIG_BF60x */
-#ifdef CONFIG_PM
-
-int bfin_pm_standby_ctrl(unsigned ctrl)
-{
-       return 0;
-}
-
-void bfin_gpio_pm_hibernate_suspend(void)
-{
-       int i, bank;
-
-       for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
-               bank = gpio_bank(i);
-
-               gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer;
-               gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux;
-               gpio_bank_saved[bank].data = gpio_array[bank]->data;
-               gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
-               gpio_bank_saved[bank].dir = gpio_array[bank]->dir_set;
-       }
-}
-
-void bfin_gpio_pm_hibernate_restore(void)
-{
-       int i, bank;
-
-       for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
-               bank = gpio_bank(i);
-
-               gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux;
-               gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer;
-               gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
-               gpio_array[bank]->data_set = gpio_bank_saved[bank].data
-                                               & gpio_bank_saved[bank].dir;
-               gpio_array[bank]->dir_set = gpio_bank_saved[bank].dir;
-       }
-}
-#endif
-
-unsigned short get_gpio_dir(unsigned gpio)
-{
-       return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio)));
-}
-EXPORT_SYMBOL(get_gpio_dir);
-
-#endif /* CONFIG_BF54x || CONFIG_BF60x */
 
 /***********************************************************
 *
@@ -785,11 +689,7 @@ int peripheral_request(unsigned short per, const char *label)
                 * be requested and used by several drivers
                 */
 
-#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-               if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) {
-#else
                if (!(per & P_MAYSHARE)) {
-#endif
                        /*
                         * Allow that the identical pin function can
                         * be requested from the same driver twice
@@ -938,12 +838,9 @@ int bfin_gpio_request(unsigned gpio, const char *label)
        if (unlikely(is_reserved(gpio_irq, gpio, 1))) {
                printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!"
                       " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
-       }
-#if !(defined(CONFIG_BF54x) || defined(CONFIG_BF60x))
-       else {  /* Reset POLAR setting when acquiring a gpio for the first time */
+       } else {        /* Reset POLAR setting when acquiring a gpio for the first time */
                set_gpio_polar(gpio, 0);
        }
-#endif
 
        reserve(gpio, gpio);
        set_label(gpio, label);
@@ -1112,11 +1009,7 @@ void bfin_gpio_irq_free(unsigned gpio)
 
 static inline void __bfin_gpio_direction_input(unsigned gpio)
 {
-#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-       gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio);
-#else
        gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
-#endif
        gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
 }
 
@@ -1140,17 +1033,7 @@ EXPORT_SYMBOL(bfin_gpio_direction_input);
 
 void bfin_gpio_irq_prepare(unsigned gpio)
 {
-#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-       unsigned long flags;
-#endif
-
        port_setup(gpio, GPIO_USAGE);
-
-#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-       flags = hard_local_irq_save();
-       __bfin_gpio_direction_input(gpio);
-       hard_local_irq_restore(flags);
-#endif
 }
 
 void bfin_gpio_set_value(unsigned gpio, int arg)
@@ -1175,11 +1058,7 @@ int bfin_gpio_direction_output(unsigned gpio, int value)
 
        gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
        gpio_set_value(gpio, value);
-#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-       gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio);
-#else
        gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
-#endif
 
        AWA_DUMMY_READ(dir);
        hard_local_irq_restore(flags);
@@ -1190,9 +1069,6 @@ EXPORT_SYMBOL(bfin_gpio_direction_output);
 
 int bfin_gpio_get_value(unsigned gpio)
 {
-#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
-       return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)));
-#else
        unsigned long flags;
 
        if (unlikely(get_gpio_edge(gpio))) {
@@ -1205,7 +1081,6 @@ int bfin_gpio_get_value(unsigned gpio)
                return ret;
        } else
                return get_gpio_data(gpio);
-#endif
 }
 EXPORT_SYMBOL(bfin_gpio_get_value);
 
index 94acb586832e69a23036e6967ceb0a3142876d66..334ec7b12188d78932c57ef08e360e6e19d542dd 100644 (file)
@@ -377,40 +377,6 @@ config IRQ_PINT3
 
 endmenu
 
-comment "Pin Interrupt to Port Assignment"
-menu "Assignment"
-
-config PINTx_REASSIGN
-       bool "Reprogram PINT Assignment"
-       default y
-       help
-         The interrupt assignment registers controls the pin-to-interrupt
-         assignment in a byte-wide manner. Each option allows you to select
-         a set of pins (High/Low Byte) of an specific Port being mapped
-         to one of the four PIN Interrupts IRQ_PINTx.
-
-         You shouldn't change any of these unless you know exactly what you're doing.
-         Please consult the Blackfin BF54x Processor Hardware Reference Manual.
-
-config PINT0_ASSIGN
-       hex "PINT0_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-config PINT1_ASSIGN
-       hex "PINT1_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x01010000
-config PINT2_ASSIGN
-       hex "PINT2_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x07000101
-config PINT3_ASSIGN
-       hex "PINT3_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x02020303
-
-endmenu
-
 endmenu
 
 endif
index 372eb54944eff3cbb12269c7a69947f9b1c86ee4..d495000b81a05c1e58aa824391d0d4c8ea857d87 100644 (file)
@@ -17,6 +17,9 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/usb/musb.h>
+#include <linux/pinctrl/machine.h>
+#include <linux/pinctrl/pinconf-generic.h>
+#include <linux/platform_data/pinctrl-adi2.h>
 #include <asm/bfin5xx_spi.h>
 #include <asm/dma.h>
 #include <asm/gpio.h>
@@ -241,6 +244,13 @@ static struct resource bfin_uart0_resources[] = {
                .end = UART0_RBR+2,
                .flags = IORESOURCE_MEM,
        },
+#ifdef CONFIG_EARLY_PRINTK
+       {
+               .start = PORTE_FER,
+               .end = PORTE_FER+2,
+               .flags = IORESOURCE_REG,
+       },
+#endif
        {
                .start = IRQ_UART0_TX,
                .end = IRQ_UART0_TX,
@@ -289,6 +299,13 @@ static struct resource bfin_uart1_resources[] = {
                .end = UART1_RBR+2,
                .flags = IORESOURCE_MEM,
        },
+#ifdef CONFIG_EARLY_PRINTK
+       {
+               .start = PORTH_FER,
+               .end = PORTH_FER+2,
+               .flags = IORESOURCE_REG,
+       },
+#endif
        {
                .start = IRQ_UART1_TX,
                .end = IRQ_UART1_TX,
@@ -353,6 +370,13 @@ static struct resource bfin_uart2_resources[] = {
                .end = UART2_RBR+2,
                .flags = IORESOURCE_MEM,
        },
+#ifdef CONFIG_EARLY_PRINTK
+       {
+               .start = PORTB_FER,
+               .end = PORTB_FER+2,
+               .flags = IORESOURCE_REG,
+       },
+#endif
        {
                .start = IRQ_UART2_TX,
                .end = IRQ_UART2_TX,
@@ -401,6 +425,13 @@ static struct resource bfin_uart3_resources[] = {
                .end = UART3_RBR+2,
                .flags = IORESOURCE_MEM,
        },
+#ifdef CONFIG_EARLY_PRINTK
+       {
+               .start = PORTB_FER,
+               .end = PORTB_FER+2,
+               .flags = IORESOURCE_REG,
+       },
+#endif
        {
                .start = IRQ_UART3_TX,
                .end = IRQ_UART3_TX,
@@ -1058,6 +1089,411 @@ static const struct ad7877_platform_data bfin_ad7877_ts_info = {
 };
 #endif
 
+#ifdef CONFIG_PINCTRL_ADI2
+
+# define ADI_PINT_DEVNAME "adi-gpio-pint"
+# define ADI_GPIO_DEVNAME "adi-gpio"
+# define ADI_PINCTRL_DEVNAME "pinctrl-adi2"
+
+static struct platform_device bfin_pinctrl_device = {
+       .name = ADI_PINCTRL_DEVNAME,
+       .id = 0,
+};
+
+static struct resource bfin_pint0_resources[] = {
+       {
+               .start = PINT0_MASK_SET,
+               .end = PINT0_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT0,
+               .end = IRQ_PINT0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint0_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 0,
+       .num_resources = ARRAY_SIZE(bfin_pint0_resources),
+       .resource = bfin_pint0_resources,
+};
+
+static struct resource bfin_pint1_resources[] = {
+       {
+               .start = PINT1_MASK_SET,
+               .end = PINT1_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT1,
+               .end = IRQ_PINT1,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint1_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 1,
+       .num_resources = ARRAY_SIZE(bfin_pint1_resources),
+       .resource = bfin_pint1_resources,
+};
+
+static struct resource bfin_pint2_resources[] = {
+       {
+               .start = PINT2_MASK_SET,
+               .end = PINT2_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT2,
+               .end = IRQ_PINT2,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint2_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 2,
+       .num_resources = ARRAY_SIZE(bfin_pint2_resources),
+       .resource = bfin_pint2_resources,
+};
+
+static struct resource bfin_pint3_resources[] = {
+       {
+               .start = PINT3_MASK_SET,
+               .end = PINT3_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT3,
+               .end = IRQ_PINT3,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint3_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 3,
+       .num_resources = ARRAY_SIZE(bfin_pint3_resources),
+       .resource = bfin_pint3_resources,
+};
+
+static struct resource bfin_gpa_resources[] = {
+       {
+               .start = PORTA_FER,
+               .end = PORTA_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {       /* optional */
+               .start = IRQ_PA0,
+               .end = IRQ_PA0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpa_pdata = {
+       .port_gpio_base = GPIO_PA0,     /* Optional */
+       .port_pin_base  = GPIO_PA0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 0,            /* PINT0 */
+       .pint_assign    = true,         /* PINT upper 16 bit */
+       .pint_map       = 0,            /* mapping mask in PINT */
+};
+
+static struct platform_device bfin_gpa_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 0,
+       .num_resources = ARRAY_SIZE(bfin_gpa_resources),
+       .resource = bfin_gpa_resources,
+       .dev = {
+               .platform_data = &bfin_gpa_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpb_resources[] = {
+       {
+               .start = PORTB_FER,
+               .end = PORTB_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PB0,
+               .end = IRQ_PB0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpb_pdata = {
+       .port_gpio_base = GPIO_PB0,
+       .port_pin_base  = GPIO_PB0,
+       .port_width     = 15,
+       .pint_id        = 0,
+       .pint_assign    = true,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpb_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 1,
+       .num_resources = ARRAY_SIZE(bfin_gpb_resources),
+       .resource = bfin_gpb_resources,
+       .dev = {
+               .platform_data = &bfin_gpb_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpc_resources[] = {
+       {
+               .start = PORTC_FER,
+               .end = PORTC_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PC0,
+               .end = IRQ_PC0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpc_pdata = {
+       .port_gpio_base = GPIO_PC0,
+       .port_pin_base  = GPIO_PC0,
+       .port_width     = 14,
+       .pint_id        = 2,
+       .pint_assign    = true,
+       .pint_map       = 0,
+};
+
+static struct platform_device bfin_gpc_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 2,
+       .num_resources = ARRAY_SIZE(bfin_gpc_resources),
+       .resource = bfin_gpc_resources,
+       .dev = {
+               .platform_data = &bfin_gpc_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpd_resources[] = {
+       {
+               .start = PORTD_FER,
+               .end = PORTD_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PD0,
+               .end = IRQ_PD0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpd_pdata = {
+       .port_gpio_base = GPIO_PD0,
+       .port_pin_base  = GPIO_PD0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 2,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpd_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 3,
+       .num_resources = ARRAY_SIZE(bfin_gpd_resources),
+       .resource = bfin_gpd_resources,
+       .dev = {
+               .platform_data = &bfin_gpd_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpe_resources[] = {
+       {
+               .start = PORTE_FER,
+               .end = PORTE_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PE0,
+               .end = IRQ_PE0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpe_pdata = {
+       .port_gpio_base = GPIO_PE0,
+       .port_pin_base  = GPIO_PE0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 3,
+       .pint_assign    = true,
+       .pint_map       = 2,
+};
+
+static struct platform_device bfin_gpe_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 4,
+       .num_resources = ARRAY_SIZE(bfin_gpe_resources),
+       .resource = bfin_gpe_resources,
+       .dev = {
+               .platform_data = &bfin_gpe_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpf_resources[] = {
+       {
+               .start = PORTF_FER,
+               .end = PORTF_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PF0,
+               .end = IRQ_PF0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpf_pdata = {
+       .port_gpio_base = GPIO_PF0,
+       .port_pin_base  = GPIO_PF0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 3,
+       .pint_assign    = false,
+       .pint_map       = 3,
+};
+
+static struct platform_device bfin_gpf_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 5,
+       .num_resources = ARRAY_SIZE(bfin_gpf_resources),
+       .resource = bfin_gpf_resources,
+       .dev = {
+               .platform_data = &bfin_gpf_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpg_resources[] = {
+       {
+               .start = PORTG_FER,
+               .end = PORTG_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PG0,
+               .end = IRQ_PG0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpg_pdata = {
+       .port_gpio_base = GPIO_PG0,
+       .port_pin_base  = GPIO_PG0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = -1,
+};
+
+static struct platform_device bfin_gpg_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 6,
+       .num_resources = ARRAY_SIZE(bfin_gpg_resources),
+       .resource = bfin_gpg_resources,
+       .dev = {
+               .platform_data = &bfin_gpg_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gph_resources[] = {
+       {
+               .start = PORTH_FER,
+               .end = PORTH_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PH0,
+               .end = IRQ_PH0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gph_pdata = {
+       .port_gpio_base = GPIO_PH0,
+       .port_pin_base  = GPIO_PH0,
+       .port_width     = 14,
+       .pint_id        = -1,
+};
+
+static struct platform_device bfin_gph_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 7,
+       .num_resources = ARRAY_SIZE(bfin_gph_resources),
+       .resource = bfin_gph_resources,
+       .dev = {
+               .platform_data = &bfin_gph_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpi_resources[] = {
+       {
+               .start = PORTI_FER,
+               .end = PORTI_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PI0,
+               .end = IRQ_PI0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpi_pdata = {
+       .port_gpio_base = GPIO_PI0,
+       .port_pin_base  = GPIO_PI0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = -1,
+};
+
+static struct platform_device bfin_gpi_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 8,
+       .num_resources = ARRAY_SIZE(bfin_gpi_resources),
+       .resource = bfin_gpi_resources,
+       .dev = {
+               .platform_data = &bfin_gpi_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpj_resources[] = {
+       {
+               .start = PORTJ_FER,
+               .end = PORTJ_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PJ0,
+               .end = IRQ_PJ0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpj_pdata = {
+       .port_gpio_base = GPIO_PJ0,
+       .port_pin_base  = GPIO_PJ0,
+       .port_width     = 14,
+       .pint_id        = -1,
+};
+
+static struct platform_device bfin_gpj_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 9,
+       .num_resources = ARRAY_SIZE(bfin_gpj_resources),
+       .resource = bfin_gpj_resources,
+       .dev = {
+               .platform_data = &bfin_gpj_pdata, /* Passed to driver */
+       },
+};
+
+#endif
+
 static struct spi_board_info bfin_spi_board_info[] __initdata = {
 #if defined(CONFIG_MTD_M25P80) \
        || defined(CONFIG_MTD_M25P80_MODULE)
@@ -1066,7 +1502,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .modalias = "m25p80", /* Name of spi_driver for this device */
                .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
                .bus_num = 0, /* Framework bus number */
-               .chip_select = 1, /* SPI_SSEL1*/
+               .chip_select = MAX_CTRL_CS + GPIO_PE4, /* SPI_SSEL1*/
                .platform_data = &bfin_spi_flash_data,
                .controller_data = &spi_flash_chip_info,
                .mode = SPI_MODE_3,
@@ -1078,7 +1514,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .modalias = "ad183x",
                .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
                .bus_num = 1,
-               .chip_select = 4,
+               .chip_select = MAX_CTRL_CS + GPIO_PG6, /* SPI_SSEL2 */
        },
 #endif
 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
@@ -1088,7 +1524,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .irq                    = IRQ_PB4,      /* old boards (<=Rev 1.3) use IRQ_PJ11 */
                .max_speed_hz           = 12500000,     /* max spi clock (SCK) speed in HZ */
                .bus_num                = 0,
-               .chip_select            = 2,
+               .chip_select            = MAX_CTRL_CS + GPIO_PE5, /* SPI_SSEL2 */
        },
 #endif
 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
@@ -1096,7 +1532,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .modalias = "spidev",
                .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
                .bus_num = 0,
-               .chip_select = 1,
+               .chip_select = MAX_CTRL_CS + GPIO_PE4, /* SPI_SSEL1 */
        },
 #endif
 #if defined(CONFIG_INPUT_ADXL34X_SPI) || defined(CONFIG_INPUT_ADXL34X_SPI_MODULE)
@@ -1106,7 +1542,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .irq                    = IRQ_PC5,
                .max_speed_hz           = 5000000,     /* max spi clock (SCK) speed in HZ */
                .bus_num                = 1,
-               .chip_select            = 2,
+               .chip_select            = MAX_CTRL_CS + GPIO_PG6, /* SPI_SSEL2 */
                .mode = SPI_MODE_3,
        },
 #endif
@@ -1152,7 +1588,7 @@ static struct resource bfin_spi1_resource[] = {
 
 /* SPI controller data */
 static struct bfin5xx_spi_master bf54x_spi_master_info0 = {
-       .num_chipselect = 4,
+       .num_chipselect = MAX_CTRL_CS + MAX_BLACKFIN_GPIOS,
        .enable_dma = 1,  /* master has the ability to do dma transfer */
        .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
 };
@@ -1168,7 +1604,7 @@ static struct platform_device bf54x_spi_master0 = {
 };
 
 static struct bfin5xx_spi_master bf54x_spi_master_info1 = {
-       .num_chipselect = 4,
+       .num_chipselect = MAX_CTRL_CS + MAX_BLACKFIN_GPIOS,
        .enable_dma = 1,  /* master has the ability to do dma transfer */
        .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0},
 };
@@ -1508,6 +1944,23 @@ static struct platform_device bfin_ac97 = {
 static struct platform_device *ezkit_devices[] __initdata = {
 
        &bfin_dpmc,
+#if defined(CONFIG_PINCTRL_ADI2)
+       &bfin_pinctrl_device,
+       &bfin_pint0_device,
+       &bfin_pint1_device,
+       &bfin_pint2_device,
+       &bfin_pint3_device,
+       &bfin_gpa_device,
+       &bfin_gpb_device,
+       &bfin_gpc_device,
+       &bfin_gpd_device,
+       &bfin_gpe_device,
+       &bfin_gpf_device,
+       &bfin_gpg_device,
+       &bfin_gph_device,
+       &bfin_gpi_device,
+       &bfin_gpj_device,
+#endif
 
 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
        &rtc_device,
@@ -1644,10 +2097,66 @@ static struct platform_device *ezkit_devices[] __initdata = {
 #endif
 };
 
+/* Pin control settings */
+static struct pinctrl_map __initdata bfin_pinmux_map[] = {
+       /* per-device maps */
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.0",  "pinctrl-adi2.0", NULL, "uart0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.1",  "pinctrl-adi2.0", NULL, "uart1"),
+#ifdef CONFIG_BFIN_UART1_CTSRTS
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.1",  "pinctrl-adi2.0", NULL, "uart1_ctsrts"),
+#endif
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.2",  "pinctrl-adi2.0", NULL, "uart2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.3",  "pinctrl-adi2.0", NULL, "uart3"),
+#ifdef CONFIG_BFIN_UART3_CTSRTS
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.3",  "pinctrl-adi2.0", NULL, "uart3_ctsrts"),
+#endif
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.0",  "pinctrl-adi2.0", NULL, "uart0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.1",  "pinctrl-adi2.0", NULL, "uart1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.2",  "pinctrl-adi2.0", NULL, "uart2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.3",  "pinctrl-adi2.0", NULL, "uart3"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-sdh.0",  "pinctrl-adi2.0", NULL, "rsi0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-spi.0",  "pinctrl-adi2.0", NULL, "spi0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-spi.1",  "pinctrl-adi2.0", NULL, "spi1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("i2c-bfin-twi.0",  "pinctrl-adi2.0", NULL, "twi0"),
+#if !defined(CONFIG_BF542)     /* The BF542 only has 1 TWI */
+       PIN_MAP_MUX_GROUP_DEFAULT("i2c-bfin-twi.1",  "pinctrl-adi2.0", NULL, "twi1"),
+#endif
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-rotary",  "pinctrl-adi2.0", NULL, "rotary"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_can.0",  "pinctrl-adi2.0", NULL, "can0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_can.1",  "pinctrl-adi2.0", NULL, "can1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bf54x-lq043",  "pinctrl-adi2.0", NULL, "ppi0_24b"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.0",  "pinctrl-adi2.0", NULL, "sport0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.0",  "pinctrl-adi2.0", NULL, "sport0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-ac97.0",  "pinctrl-adi2.0", NULL, "sport0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.1",  "pinctrl-adi2.0", NULL, "sport1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.1",  "pinctrl-adi2.0", NULL, "sport1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-ac97.1",  "pinctrl-adi2.0", NULL, "sport1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.2",  "pinctrl-adi2.0", NULL, "sport2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.2",  "pinctrl-adi2.0", NULL, "sport2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-ac97.2",  "pinctrl-adi2.0", NULL, "sport2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.3",  "pinctrl-adi2.0", NULL, "sport3"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.3",  "pinctrl-adi2.0", NULL, "sport3"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-ac97.3",  "pinctrl-adi2.0", NULL, "sport3"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-sport-uart.0",  "pinctrl-adi2.0", NULL, "sport0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-sport-uart.1",  "pinctrl-adi2.0", NULL, "sport1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-sport-uart.2",  "pinctrl-adi2.0", NULL, "sport2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-sport-uart.3",  "pinctrl-adi2.0", NULL, "sport3"),
+       PIN_MAP_MUX_GROUP_DEFAULT("pata-bf54x",  "pinctrl-adi2.0", NULL, "atapi"),
+#ifdef CONFIG_BF548_ATAPI_ALTERNATIVE_PORT
+       PIN_MAP_MUX_GROUP_DEFAULT("pata-bf54x",  "pinctrl-adi2.0", NULL, "atapi_alter"),
+#endif
+       PIN_MAP_MUX_GROUP_DEFAULT("bf5xx-nand.0",  "pinctrl-adi2.0", NULL, "nfc0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bf54x-keys",  "pinctrl-adi2.0", NULL, "keys_4x4"),
+};
+
 static int __init ezkit_init(void)
 {
        printk(KERN_INFO "%s(): registering device resources\n", __func__);
 
+       /* Initialize pinmuxing */
+       pinctrl_register_mappings(bfin_pinmux_map,
+                               ARRAY_SIZE(bfin_pinmux_map));
+
        i2c_register_board_info(0, bfin_i2c_board_info0,
                                ARRAY_SIZE(bfin_i2c_board_info0));
 #if !defined(CONFIG_BF542)     /* The BF542 only has 1 TWI */
@@ -1679,21 +2188,6 @@ static struct platform_device *ezkit_early_devices[] __initdata = {
        &bfin_uart3_device,
 #endif
 #endif
-
-#if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
-#ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
-       &bfin_sport0_uart_device,
-#endif
-#ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
-       &bfin_sport1_uart_device,
-#endif
-#ifdef CONFIG_SERIAL_BFIN_SPORT2_UART
-       &bfin_sport2_uart_device,
-#endif
-#ifdef CONFIG_SERIAL_BFIN_SPORT3_UART
-       &bfin_sport3_uart_device,
-#endif
-#endif
 };
 
 void __init native_machine_early_platform_add_devices(void)
index be9edb28f96bd6bea7fb5b3604d572f6c35b1fc8..006da1edcf84bf42d95c6a7476db48f04353abca 100644 (file)
@@ -194,14 +194,6 @@ struct gpio_port_t {
        unsigned int port_mux;
 };
 
-struct gpio_port_s {
-       unsigned short fer;
-       unsigned short data;
-       unsigned short dir;
-       unsigned short inen;
-       unsigned int mux;
-};
-
 #endif
 
 #include <mach-common/ports-a.h>
index 10dc142c518d538db8c7154eb47ad36958ea63e8..cf7cb725cfa2bff44dd645333ff982ddf6e8632e 100644 (file)
 #include <linux/types.h>
 
 /*
- * bfin pint registers layout
+ * gpio pint registers layout
  */
 struct bfin_pint_regs {
        u32 mask_set;
index 2bcbf94b1edf4cbe9108b108f85bd253bb201d11..b0fca44110b032dc59dc7b5d9485ba2724bf573c 100644 (file)
@@ -9,48 +9,6 @@ source "arch/blackfin/mach-bf609/boards/Kconfig"
 
 menu "BF609 Specific Configuration"
 
-comment "Pin Interrupt to Port Assignment"
-menu "Assignment"
-
-config PINTx_REASSIGN
-       bool "Reprogram PINT Assignment"
-       default y
-       help
-         The interrupt assignment registers controls the pin-to-interrupt
-         assignment in a byte-wide manner. Each option allows you to select
-         a set of pins (High/Low Byte) of an specific Port being mapped
-         to one of the four PIN Interrupts IRQ_PINTx.
-
-         You shouldn't change any of these unless you know exactly what you're doing.
-         Please consult the Blackfin BF60x Processor Hardware Reference Manual.
-
-config PINT0_ASSIGN
-       hex "PINT0_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-config PINT1_ASSIGN
-       hex "PINT1_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-config PINT2_ASSIGN
-       hex "PINT2_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-config PINT3_ASSIGN
-       hex "PINT3_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-config PINT4_ASSIGN
-       hex "PINT3_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-config PINT5_ASSIGN
-       hex "PINT3_ASSIGN"
-       depends on PINTx_REASSIGN
-       default 0x00000101
-
-endmenu
-
 config SEC_IRQ_PRIORITY_LEVELS
        int "SEC interrupt priority levels"
        default 7
index d56a55ad83a7c2340a43744dcaeca8522909cb01..82beedd953f648849852acf15f50e789f6c04684 100644 (file)
@@ -17,6 +17,9 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/usb/musb.h>
+#include <linux/pinctrl/machine.h>
+#include <linux/pinctrl/pinconf-generic.h>
+#include <linux/platform_data/pinctrl-adi2.h>
 #include <asm/bfin_spi3.h>
 #include <asm/dma.h>
 #include <asm/gpio.h>
@@ -106,8 +109,6 @@ static struct platform_device bfin_rotary_device = {
 #include <linux/stmmac.h>
 #include <linux/phy.h>
 
-static unsigned short pins[] = P_RMII0;
-
 static struct stmmac_mdio_bus_data phy_private_data = {
        .phy_mask = 1,
 };
@@ -212,6 +213,18 @@ static struct resource bfin_uart0_resources[] = {
                .end = UART0_RXDIV+4,
                .flags = IORESOURCE_MEM,
        },
+#ifdef CONFIG_EARLY_PRINTK
+       {
+               .start = PORTD_FER,
+               .end = PORTD_FER+2,
+               .flags = IORESOURCE_REG,
+       },
+       {
+               .start = PORTD_MUX,
+               .end = PORTD_MUX+3,
+               .flags = IORESOURCE_REG,
+       },
+#endif
        {
                .start = IRQ_UART0_TX,
                .end = IRQ_UART0_TX,
@@ -276,6 +289,13 @@ static struct resource bfin_uart1_resources[] = {
                .end = UART1_RXDIV+4,
                .flags = IORESOURCE_MEM,
        },
+#ifdef CONFIG_EARLY_PRINTK
+       {
+               .start = PORTG_FER_SET,
+               .end = PORTG_FER_SET+2,
+               .flags = IORESOURCE_REG,
+       },
+#endif
        {
                .start = IRQ_UART1_TX,
                .end = IRQ_UART1_TX,
@@ -674,17 +694,12 @@ static struct mtd_partition ezkit_partitions[] = {
        },
 };
 
-int bf609_nor_flash_init(struct platform_device *dev)
+int bf609_nor_flash_init(struct platform_device *pdev)
 {
 #define CONFIG_SMC_GCTL_VAL     0x00000010
-       const unsigned short pins[] = {
-               P_A3, P_A4, P_A5, P_A6, P_A7, P_A8, P_A9, P_A10, P_A11, P_A12,
-               P_A13, P_A14, P_A15, P_A16, P_A17, P_A18, P_A19, P_A20, P_A21,
-               P_A22, P_A23, P_A24, P_A25, P_NORCK, 0,
-       };
-
-       peripheral_request_list(pins, "smc0");
 
+       if (!devm_pinctrl_get_select_default(&pdev->dev))
+               return -EBUSY;
        bfin_write32(SMC_GCTL, CONFIG_SMC_GCTL_VAL);
        bfin_write32(SMC_B0CTL, 0x01002011);
        bfin_write32(SMC_B0TIM, 0x08170977);
@@ -692,16 +707,9 @@ int bf609_nor_flash_init(struct platform_device *dev)
        return 0;
 }
 
-void bf609_nor_flash_exit(struct platform_device *dev)
+void bf609_nor_flash_exit(struct platform_device *pdev)
 {
-       const unsigned short pins[] = {
-               P_A3, P_A4, P_A5, P_A6, P_A7, P_A8, P_A9, P_A10, P_A11, P_A12,
-               P_A13, P_A14, P_A15, P_A16, P_A17, P_A18, P_A19, P_A20, P_A21,
-               P_A22, P_A23, P_A24, P_A25, P_NORCK, 0,
-       };
-
-       peripheral_free_list(pins);
-
+       devm_pinctrl_put(pdev->dev.pins->p);
        bfin_write32(SMC_GCTL, 0);
 }
 
@@ -1319,6 +1327,356 @@ static const struct ad7877_platform_data bfin_ad7877_ts_info = {
 };
 #endif
 
+#ifdef CONFIG_PINCTRL_ADI2
+
+# define ADI_PINT_DEVNAME "adi-gpio-pint"
+# define ADI_GPIO_DEVNAME "adi-gpio"
+# define ADI_PINCTRL_DEVNAME "pinctrl-adi2"
+
+static struct platform_device bfin_pinctrl_device = {
+       .name = ADI_PINCTRL_DEVNAME,
+       .id = 0,
+};
+
+static struct resource bfin_pint0_resources[] = {
+       {
+               .start = PINT0_MASK_SET,
+               .end = PINT0_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT0,
+               .end = IRQ_PINT0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint0_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 0,
+       .num_resources = ARRAY_SIZE(bfin_pint0_resources),
+       .resource = bfin_pint0_resources,
+};
+
+static struct resource bfin_pint1_resources[] = {
+       {
+               .start = PINT1_MASK_SET,
+               .end = PINT1_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT1,
+               .end = IRQ_PINT1,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint1_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 1,
+       .num_resources = ARRAY_SIZE(bfin_pint1_resources),
+       .resource = bfin_pint1_resources,
+};
+
+static struct resource bfin_pint2_resources[] = {
+       {
+               .start = PINT2_MASK_SET,
+               .end = PINT2_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT2,
+               .end = IRQ_PINT2,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint2_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 2,
+       .num_resources = ARRAY_SIZE(bfin_pint2_resources),
+       .resource = bfin_pint2_resources,
+};
+
+static struct resource bfin_pint3_resources[] = {
+       {
+               .start = PINT3_MASK_SET,
+               .end = PINT3_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT3,
+               .end = IRQ_PINT3,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint3_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 3,
+       .num_resources = ARRAY_SIZE(bfin_pint3_resources),
+       .resource = bfin_pint3_resources,
+};
+
+static struct resource bfin_pint4_resources[] = {
+       {
+               .start = PINT4_MASK_SET,
+               .end = PINT4_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT4,
+               .end = IRQ_PINT4,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint4_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 4,
+       .num_resources = ARRAY_SIZE(bfin_pint4_resources),
+       .resource = bfin_pint4_resources,
+};
+
+static struct resource bfin_pint5_resources[] = {
+       {
+               .start = PINT5_MASK_SET,
+               .end = PINT5_LATCH + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PINT5,
+               .end = IRQ_PINT5,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bfin_pint5_device = {
+       .name = ADI_PINT_DEVNAME,
+       .id = 5,
+       .num_resources = ARRAY_SIZE(bfin_pint5_resources),
+       .resource = bfin_pint5_resources,
+};
+
+static struct resource bfin_gpa_resources[] = {
+       {
+               .start = PORTA_FER,
+               .end = PORTA_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {       /* optional */
+               .start = IRQ_PA0,
+               .end = IRQ_PA0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpa_pdata = {
+       .port_pin_base  = GPIO_PA0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 0,            /* PINT0 */
+       .pint_assign    = true,         /* PINT upper 16 bit */
+       .pint_map       = 0,            /* mapping mask in PINT */
+};
+
+static struct platform_device bfin_gpa_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 0,
+       .num_resources = ARRAY_SIZE(bfin_gpa_resources),
+       .resource = bfin_gpa_resources,
+       .dev = {
+               .platform_data = &bfin_gpa_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpb_resources[] = {
+       {
+               .start = PORTB_FER,
+               .end = PORTB_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PB0,
+               .end = IRQ_PB0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpb_pdata = {
+       .port_pin_base  = GPIO_PB0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 0,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpb_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 1,
+       .num_resources = ARRAY_SIZE(bfin_gpb_resources),
+       .resource = bfin_gpb_resources,
+       .dev = {
+               .platform_data = &bfin_gpb_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpc_resources[] = {
+       {
+               .start = PORTC_FER,
+               .end = PORTC_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PC0,
+               .end = IRQ_PC0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpc_pdata = {
+       .port_pin_base  = GPIO_PC0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 1,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpc_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 2,
+       .num_resources = ARRAY_SIZE(bfin_gpc_resources),
+       .resource = bfin_gpc_resources,
+       .dev = {
+               .platform_data = &bfin_gpc_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpd_resources[] = {
+       {
+               .start = PORTD_FER,
+               .end = PORTD_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PD0,
+               .end = IRQ_PD0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpd_pdata = {
+       .port_pin_base  = GPIO_PD0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 2,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpd_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 3,
+       .num_resources = ARRAY_SIZE(bfin_gpd_resources),
+       .resource = bfin_gpd_resources,
+       .dev = {
+               .platform_data = &bfin_gpd_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpe_resources[] = {
+       {
+               .start = PORTE_FER,
+               .end = PORTE_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PE0,
+               .end = IRQ_PE0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpe_pdata = {
+       .port_pin_base  = GPIO_PE0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 3,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpe_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 4,
+       .num_resources = ARRAY_SIZE(bfin_gpe_resources),
+       .resource = bfin_gpe_resources,
+       .dev = {
+               .platform_data = &bfin_gpe_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpf_resources[] = {
+       {
+               .start = PORTF_FER,
+               .end = PORTF_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PF0,
+               .end = IRQ_PF0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpf_pdata = {
+       .port_pin_base  = GPIO_PF0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 4,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpf_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 5,
+       .num_resources = ARRAY_SIZE(bfin_gpf_resources),
+       .resource = bfin_gpf_resources,
+       .dev = {
+               .platform_data = &bfin_gpf_pdata, /* Passed to driver */
+       },
+};
+
+static struct resource bfin_gpg_resources[] = {
+       {
+               .start = PORTG_FER,
+               .end = PORTG_MUX + 3,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = IRQ_PG0,
+               .end = IRQ_PG0,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct adi_pinctrl_gpio_platform_data bfin_gpg_pdata = {
+       .port_pin_base  = GPIO_PG0,
+       .port_width     = GPIO_BANKSIZE,
+       .pint_id        = 5,
+       .pint_assign    = false,
+       .pint_map       = 1,
+};
+
+static struct platform_device bfin_gpg_device = {
+       .name = ADI_GPIO_DEVNAME,
+       .id = 6,
+       .num_resources = ARRAY_SIZE(bfin_gpg_resources),
+       .resource = bfin_gpg_resources,
+       .dev = {
+               .platform_data = &bfin_gpg_pdata, /* Passed to driver */
+       },
+};
+
+#endif
+
 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
@@ -1349,7 +1707,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .modalias = "m25p80", /* Name of spi_driver for this device */
                .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
                .bus_num = 0, /* Framework bus number */
-               .chip_select = 1, /* SPI_SSEL1*/
+               .chip_select = MAX_CTRL_CS + GPIO_PD11, /* SPI_SSEL1*/
                .platform_data = &bfin_spi_flash_data,
                .controller_data = &spi_flash_chip_info,
                .mode = SPI_MODE_3,
@@ -1362,7 +1720,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .irq                    = IRQ_PD9,
                .max_speed_hz           = 12500000,     /* max spi clock (SCK) speed in HZ */
                .bus_num                = 0,
-               .chip_select            = 4,
+               .chip_select            = MAX_CTRL_CS + GPIO_PC15, /* SPI_SSEL4 */
        },
 #endif
 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
@@ -1370,7 +1728,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
                .modalias = "spidev",
                .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
                .bus_num = 0,
-               .chip_select = 1,
+               .chip_select = MAX_CTRL_CS + GPIO_PD11, /* SPI_SSEL1*/
                .controller_data = &spidev_chip_info,
        },
 #endif
@@ -1565,6 +1923,22 @@ static struct platform_device bfin_dpmc = {
 static struct platform_device *ezkit_devices[] __initdata = {
 
        &bfin_dpmc,
+#if defined(CONFIG_PINCTRL_ADI2)
+       &bfin_pinctrl_device,
+       &bfin_pint0_device,
+       &bfin_pint1_device,
+       &bfin_pint2_device,
+       &bfin_pint3_device,
+       &bfin_pint4_device,
+       &bfin_pint5_device,
+       &bfin_gpa_device,
+       &bfin_gpb_device,
+       &bfin_gpc_device,
+       &bfin_gpd_device,
+       &bfin_gpe_device,
+       &bfin_gpf_device,
+       &bfin_gpg_device,
+#endif
 
 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
        &rtc_device,
@@ -1681,20 +2055,52 @@ static struct platform_device *ezkit_devices[] __initdata = {
 
 };
 
+/* Pin control settings */
+static struct pinctrl_map __initdata bfin_pinmux_map[] = {
+       /* per-device maps */
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.0",  "pinctrl-adi2.0", NULL, "uart0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-uart.1",  "pinctrl-adi2.0", NULL, "uart1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.0",  "pinctrl-adi2.0", NULL, "uart0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.1",  "pinctrl-adi2.0", NULL, "uart1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-sdh.0",  "pinctrl-adi2.0", NULL, "rsi0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("stmmaceth.0",  "pinctrl-adi2.0", NULL, "eth0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-spi3.0",  "pinctrl-adi2.0", NULL, "spi0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-spi3.1",  "pinctrl-adi2.0", NULL, "spi1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("i2c-bfin-twi.0",  "pinctrl-adi2.0", NULL, "twi0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("i2c-bfin-twi.1",  "pinctrl-adi2.0", NULL, "twi1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-rotary",  "pinctrl-adi2.0", NULL, "rotary"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_can.0",  "pinctrl-adi2.0", NULL, "can0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("physmap-flash.0",  "pinctrl-adi2.0", NULL, "smc0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bf609_nl8048.2",  "pinctrl-adi2.0", NULL, "ppi2_16b"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_display.0",  "pinctrl-adi2.0", NULL, "ppi0_16b"),
+#if defined(CONFIG_VIDEO_MT9M114) || defined(CONFIG_VIDEO_MT9M114_MODULE)
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_capture.0",  "pinctrl-adi2.0", NULL, "ppi0_8b"),
+#elif defined(CONFIG_VIDEO_VS6624) || defined(CONFIG_VIDEO_VS6624_MODULE)
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_capture.0",  "pinctrl-adi2.0", NULL, "ppi0_16b"),
+#else
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin_capture.0",  "pinctrl-adi2.0", NULL, "ppi0_24b"),
+#endif
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.0",  "pinctrl-adi2.0", NULL, "sport0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.0",  "pinctrl-adi2.0", NULL, "sport0"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.1",  "pinctrl-adi2.0", NULL, "sport1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.1",  "pinctrl-adi2.0", NULL, "sport1"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-i2s.2",  "pinctrl-adi2.0", NULL, "sport2"),
+       PIN_MAP_MUX_GROUP_DEFAULT("bfin-tdm.2",  "pinctrl-adi2.0", NULL, "sport2"),
+};
+
 static int __init ezkit_init(void)
 {
        printk(KERN_INFO "%s(): registering device resources\n", __func__);
 
+       /* Initialize pinmuxing */
+       pinctrl_register_mappings(bfin_pinmux_map,
+                               ARRAY_SIZE(bfin_pinmux_map));
+
        i2c_register_board_info(0, bfin_i2c_board_info0,
                                ARRAY_SIZE(bfin_i2c_board_info0));
        i2c_register_board_info(1, bfin_i2c_board_info1,
                                ARRAY_SIZE(bfin_i2c_board_info1));
 
-#if defined(CONFIG_STMMAC_ETH) || defined(CONFIG_STMMAC_ETH_MODULE)
-       if (!peripheral_request_list(pins, "emac0"))
-               printk(KERN_ERR "%s(): request emac pins failed\n", __func__);
-#endif
-
        platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
 
        spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
@@ -1713,18 +2119,6 @@ static struct platform_device *ezkit_early_devices[] __initdata = {
        &bfin_uart1_device,
 #endif
 #endif
-
-#if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
-#ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
-       &bfin_sport0_uart_device,
-#endif
-#ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
-       &bfin_sport1_uart_device,
-#endif
-#ifdef CONFIG_SERIAL_BFIN_SPORT2_UART
-       &bfin_sport2_uart_device,
-#endif
-#endif
 };
 
 void __init native_machine_early_platform_add_devices(void)
index c32c8cc8db2e79e0ae4aa2d1c892c8ec9cff4c3a..07182513e794cb2bd89bc9645c25b2bd75611c40 100644 (file)
@@ -152,14 +152,6 @@ struct gpio_port_t {
        unsigned long revid;
 };
 
-struct gpio_port_s {
-       unsigned short fer;
-       unsigned short data;
-       unsigned short dir;
-       unsigned short inen;
-       unsigned int mux;
-};
-
 #endif
 
 #include <mach-common/ports-a.h>
index fa0843d5d77ac382be120c3aa4d426adbc6fe0de..d1cb6a86f80a9fe8fc70c45214fd55e0af9cb4d3 100644 (file)
 extern u8 sec_int_priority[];
 
 /*
- * bfin pint registers layout
+ * gpio pint registers layout
  */
 struct bfin_pint_regs {
        u32 mask_set;
index fe34191eef0bb00cfac8c9c9338144eb5bdbc804..c48bb71a55ce7c56dcc412d125e4d380f9ab1dcc 100644 (file)
@@ -19,6 +19,7 @@
 #define P_MII0_CRS     (P_DEFINED | P_IDENT(GPIO_PC5) | P_FUNCT(0))
 #define P_MII0_ERxER   (P_DEFINED | P_IDENT(GPIO_PC4) | P_FUNCT(0))
 #define P_MII0_TxCLK   (P_DEFINED | P_IDENT(GPIO_PB14) | P_FUNCT(0))
+#define P_MII0_PTPPPS  (P_DEFINED | P_IDENT(GPIO_PB15) | P_FUNCT(0))
 
 #define P_RMII0 {\
        P_MII0_ETxD0, \
@@ -30,6 +31,7 @@
        P_MII0_TxCLK, \
        P_MII0_PHYINT, \
        P_MII0_CRS, \
+       P_MII0_PTPPPS, \
        P_MII0_MDC, \
        P_MII0_MDIO, 0}
 
@@ -44,6 +46,7 @@
 #define P_MII1_CRS     (P_DEFINED | P_IDENT(GPIO_PE13) | P_FUNCT(0))
 #define P_MII1_ERxER   (P_DEFINED | P_IDENT(GPIO_PE14) | P_FUNCT(0))
 #define P_MII1_TxCLK   (P_DEFINED | P_IDENT(GPIO_PG6) | P_FUNCT(0))
+#define P_MII1_PTPPPS  (P_DEFINED | P_IDENT(GPIO_PC9) | P_FUNCT(0))
 
 #define P_RMII1 {\
        P_MII1_ETxD0, \
@@ -55,6 +58,7 @@
        P_MII1_TxCLK, \
        P_MII1_PHYINT, \
        P_MII1_CRS, \
+       P_MII1_PTPPPS, \
        P_MII1_MDC, \
        P_MII1_MDIO, 0}
 
index d143fd8d2bc5075544e0bc6655306bd66bae90ca..ca75613231c84474ad276c667eb4cd415027532e 100644 (file)
@@ -704,10 +704,9 @@ static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
        __irq_set_handler_locked(irq, handle);
 }
 
-static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
-extern void bfin_gpio_irq_prepare(unsigned gpio);
+#ifdef CONFIG_GPIO_ADI
 
-#if !BFIN_GPIO_PINT
+static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
 
 static void bfin_gpio_ack_irq(struct irq_data *d)
 {
@@ -821,15 +820,6 @@ static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
-{
-       return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
-}
-#else
-# define bfin_gpio_set_wake NULL
-#endif
-
 static void bfin_demux_gpio_block(unsigned int irq)
 {
        unsigned int gpio, mask;
@@ -896,279 +886,40 @@ void bfin_demux_gpio_irq(unsigned int inta_irq,
        bfin_demux_gpio_block(irq);
 }
 
-#else
-
-#define NR_PINT_BITS           32
-#define IRQ_NOT_AVAIL          0xFF
-
-#define PINT_2_BANK(x)         ((x) >> 5)
-#define PINT_2_BIT(x)          ((x) & 0x1F)
-#define PINT_BIT(x)            (1 << (PINT_2_BIT(x)))
-
-static unsigned char irq2pint_lut[NR_PINTS];
-static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
-
-static struct bfin_pint_regs * const pint[NR_PINT_SYS_IRQS] = {
-       (struct bfin_pint_regs *)PINT0_MASK_SET,
-       (struct bfin_pint_regs *)PINT1_MASK_SET,
-       (struct bfin_pint_regs *)PINT2_MASK_SET,
-       (struct bfin_pint_regs *)PINT3_MASK_SET,
-#ifdef CONFIG_BF60x
-       (struct bfin_pint_regs *)PINT4_MASK_SET,
-       (struct bfin_pint_regs *)PINT5_MASK_SET,
-#endif
-};
-
-inline unsigned int get_irq_base(u32 bank, u8 bmap)
-{
-       unsigned int irq_base;
-
-#ifndef CONFIG_BF60x
-       if (bank < 2) {         /*PA-PB */
-               irq_base = IRQ_PA0 + bmap * 16;
-       } else {                /*PC-PJ */
-               irq_base = IRQ_PC0 + bmap * 16;
-       }
-#else
-       irq_base = IRQ_PA0 + bank * 16 + bmap * 16;
-#endif
-       return irq_base;
-}
-
-       /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
-void init_pint_lut(void)
-{
-       u16 bank, bit, irq_base, bit_pos;
-       u32 pint_assign;
-       u8 bmap;
-
-       memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
-
-       for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
-
-               pint_assign = pint[bank]->assign;
-
-               for (bit = 0; bit < NR_PINT_BITS; bit++) {
-
-                       bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
-
-                       irq_base = get_irq_base(bank, bmap);
-
-                       irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
-                       bit_pos = bit + bank * NR_PINT_BITS;
-
-                       pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
-                       irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
-               }
-       }
-}
-
-static void bfin_gpio_ack_irq(struct irq_data *d)
-{
-       u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
-       u32 pintbit = PINT_BIT(pint_val);
-       u32 bank = PINT_2_BANK(pint_val);
-
-       if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
-               if (pint[bank]->invert_set & pintbit)
-                       pint[bank]->invert_clear = pintbit;
-               else
-                       pint[bank]->invert_set = pintbit;
-       }
-       pint[bank]->request = pintbit;
-
-}
-
-static void bfin_gpio_mask_ack_irq(struct irq_data *d)
-{
-       u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
-       u32 pintbit = PINT_BIT(pint_val);
-       u32 bank = PINT_2_BANK(pint_val);
-
-       if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
-               if (pint[bank]->invert_set & pintbit)
-                       pint[bank]->invert_clear = pintbit;
-               else
-                       pint[bank]->invert_set = pintbit;
-       }
-
-       pint[bank]->request = pintbit;
-       pint[bank]->mask_clear = pintbit;
-}
-
-static void bfin_gpio_mask_irq(struct irq_data *d)
-{
-       u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
-
-       pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
-}
-
-static void bfin_gpio_unmask_irq(struct irq_data *d)
-{
-       u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
-       u32 pintbit = PINT_BIT(pint_val);
-       u32 bank = PINT_2_BANK(pint_val);
-
-       pint[bank]->mask_set = pintbit;
-}
-
-static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
-{
-       unsigned int irq = d->irq;
-       u32 gpionr = irq_to_gpio(irq);
-       u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
-
-       if (pint_val == IRQ_NOT_AVAIL) {
-               printk(KERN_ERR
-               "GPIO IRQ %d :Not in PINT Assign table "
-               "Reconfigure Interrupt to Port Assignemt\n", irq);
-               return -ENODEV;
-       }
-
-       if (__test_and_set_bit(gpionr, gpio_enabled))
-               bfin_gpio_irq_prepare(gpionr);
-
-       bfin_gpio_unmask_irq(d);
-
-       return 0;
-}
-
-static void bfin_gpio_irq_shutdown(struct irq_data *d)
-{
-       u32 gpionr = irq_to_gpio(d->irq);
-
-       bfin_gpio_mask_irq(d);
-       __clear_bit(gpionr, gpio_enabled);
-       bfin_gpio_irq_free(gpionr);
-}
-
-static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
-{
-       unsigned int irq = d->irq;
-       int ret;
-       char buf[16];
-       u32 gpionr = irq_to_gpio(irq);
-       u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
-       u32 pintbit = PINT_BIT(pint_val);
-       u32 bank = PINT_2_BANK(pint_val);
-
-       if (pint_val == IRQ_NOT_AVAIL)
-               return -ENODEV;
-
-       if (type == IRQ_TYPE_PROBE) {
-               /* only probe unenabled GPIO interrupt lines */
-               if (test_bit(gpionr, gpio_enabled))
-                       return 0;
-               type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
-       }
-
-       if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
-                   IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
-
-               snprintf(buf, 16, "gpio-irq%d", irq);
-               ret = bfin_gpio_irq_request(gpionr, buf);
-               if (ret)
-                       return ret;
-
-               if (__test_and_set_bit(gpionr, gpio_enabled))
-                       bfin_gpio_irq_prepare(gpionr);
-
-       } else {
-               __clear_bit(gpionr, gpio_enabled);
-               return 0;
-       }
-
-       if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
-               pint[bank]->invert_set = pintbit;       /* low or falling edge denoted by one */
-       else
-               pint[bank]->invert_clear = pintbit;     /* high or rising edge denoted by zero */
-
-       if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
-           == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
-               if (gpio_get_value(gpionr))
-                       pint[bank]->invert_set = pintbit;
-               else
-                       pint[bank]->invert_clear = pintbit;
-       }
-
-       if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
-               pint[bank]->edge_set = pintbit;
-               bfin_set_irq_handler(irq, handle_edge_irq);
-       } else {
-               pint[bank]->edge_clear = pintbit;
-               bfin_set_irq_handler(irq, handle_level_irq);
-       }
-
-       return 0;
-}
-
 #ifdef CONFIG_PM
-static struct bfin_pm_pint_save save_pint_reg[NR_PINT_SYS_IRQS];
-static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
 
 static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
 {
-       u32 pint_irq;
-       u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
-       u32 bank = PINT_2_BANK(pint_val);
-
-       switch (bank) {
-       case 0:
-               pint_irq = IRQ_PINT0;
-               break;
-       case 2:
-               pint_irq = IRQ_PINT2;
-               break;
-       case 3:
-               pint_irq = IRQ_PINT3;
-               break;
-       case 1:
-               pint_irq = IRQ_PINT1;
-               break;
-#ifdef CONFIG_BF60x
-       case 4:
-               pint_irq = IRQ_PINT4;
-               break;
-       case 5:
-               pint_irq = IRQ_PINT5;
-               break;
-#endif
-       default:
-               return -EINVAL;
-       }
+       return bfin_gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
+}
 
-#ifndef SEC_GCTL
-       bfin_internal_set_wake(pint_irq, state);
-#endif
+#else
 
-       return 0;
-}
+# define bfin_gpio_set_wake NULL
 
-void bfin_pint_suspend(void)
-{
-       u32 bank;
+#endif
 
-       for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
-               save_pint_reg[bank].mask_set = pint[bank]->mask_set;
-               save_pint_reg[bank].assign = pint[bank]->assign;
-               save_pint_reg[bank].edge_set = pint[bank]->edge_set;
-               save_pint_reg[bank].invert_set = pint[bank]->invert_set;
-       }
-}
+static struct irq_chip bfin_gpio_irqchip = {
+       .name = "GPIO",
+       .irq_ack = bfin_gpio_ack_irq,
+       .irq_mask = bfin_gpio_mask_irq,
+       .irq_mask_ack = bfin_gpio_mask_ack_irq,
+       .irq_unmask = bfin_gpio_unmask_irq,
+       .irq_disable = bfin_gpio_mask_irq,
+       .irq_enable = bfin_gpio_unmask_irq,
+       .irq_set_type = bfin_gpio_irq_type,
+       .irq_startup = bfin_gpio_irq_startup,
+       .irq_shutdown = bfin_gpio_irq_shutdown,
+       .irq_set_wake = bfin_gpio_set_wake,
+};
 
-void bfin_pint_resume(void)
-{
-       u32 bank;
+#endif
 
-       for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
-               pint[bank]->mask_set = save_pint_reg[bank].mask_set;
-               pint[bank]->assign = save_pint_reg[bank].assign;
-               pint[bank]->edge_set = save_pint_reg[bank].edge_set;
-               pint[bank]->invert_set = save_pint_reg[bank].invert_set;
-       }
-}
+#ifdef CONFIG_PM
 
 #ifdef SEC_GCTL
+static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
+
 static int sec_suspend(void)
 {
        u32 bank;
@@ -1195,92 +946,10 @@ static struct syscore_ops sec_pm_syscore_ops = {
        .suspend = sec_suspend,
        .resume = sec_resume,
 };
-
-#endif
-#else
-# define bfin_gpio_set_wake NULL
-#endif
-
-void bfin_demux_gpio_irq(unsigned int inta_irq,
-                       struct irq_desc *desc)
-{
-       u32 bank, pint_val;
-       u32 request, irq;
-       u32 level_mask;
-       int umask = 0;
-       struct irq_chip *chip = irq_desc_get_chip(desc);
-
-       if (chip->irq_mask_ack) {
-               chip->irq_mask_ack(&desc->irq_data);
-       } else {
-               chip->irq_mask(&desc->irq_data);
-               if (chip->irq_ack)
-                       chip->irq_ack(&desc->irq_data);
-       }
-
-       switch (inta_irq) {
-       case IRQ_PINT0:
-               bank = 0;
-               break;
-       case IRQ_PINT2:
-               bank = 2;
-               break;
-       case IRQ_PINT3:
-               bank = 3;
-               break;
-       case IRQ_PINT1:
-               bank = 1;
-               break;
-#ifdef CONFIG_BF60x
-       case IRQ_PINT4:
-               bank = 4;
-               break;
-       case IRQ_PINT5:
-               bank = 5;
-               break;
 #endif
-       default:
-               return;
-       }
-
-       pint_val = bank * NR_PINT_BITS;
-
-       request = pint[bank]->request;
-
-       level_mask = pint[bank]->edge_set & request;
-
-       while (request) {
-               if (request & 1) {
-                       irq = pint2irq_lut[pint_val] + SYS_IRQS;
-                       if (level_mask & PINT_BIT(pint_val)) {
-                               umask = 1;
-                               chip->irq_unmask(&desc->irq_data);
-                       }
-                       bfin_handle_irq(irq);
-               }
-               pint_val++;
-               request >>= 1;
-       }
 
-       if (!umask)
-               chip->irq_unmask(&desc->irq_data);
-}
 #endif
 
-static struct irq_chip bfin_gpio_irqchip = {
-       .name = "GPIO",
-       .irq_ack = bfin_gpio_ack_irq,
-       .irq_mask = bfin_gpio_mask_irq,
-       .irq_mask_ack = bfin_gpio_mask_ack_irq,
-       .irq_unmask = bfin_gpio_unmask_irq,
-       .irq_disable = bfin_gpio_mask_irq,
-       .irq_enable = bfin_gpio_unmask_irq,
-       .irq_set_type = bfin_gpio_irq_type,
-       .irq_startup = bfin_gpio_irq_startup,
-       .irq_shutdown = bfin_gpio_irq_shutdown,
-       .irq_set_wake = bfin_gpio_set_wake,
-};
-
 void init_exception_vectors(void)
 {
        /* cannot program in software:
@@ -1331,17 +1000,6 @@ int __init init_arch_irq(void)
 
        local_irq_disable();
 
-#if BFIN_GPIO_PINT
-# ifdef CONFIG_PINTx_REASSIGN
-       pint[0]->assign = CONFIG_PINT0_ASSIGN;
-       pint[1]->assign = CONFIG_PINT1_ASSIGN;
-       pint[2]->assign = CONFIG_PINT2_ASSIGN;
-       pint[3]->assign = CONFIG_PINT3_ASSIGN;
-# endif
-       /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
-       init_pint_lut();
-#endif
-
        for (irq = 0; irq <= SYS_IRQS; irq++) {
                if (irq <= IRQ_CORETMR)
                        irq_set_chip(irq, &bfin_core_irqchip);
@@ -1349,12 +1007,8 @@ int __init init_arch_irq(void)
                        irq_set_chip(irq, &bfin_internal_irqchip);
 
                switch (irq) {
-#if BFIN_GPIO_PINT
-               case IRQ_PINT0:
-               case IRQ_PINT1:
-               case IRQ_PINT2:
-               case IRQ_PINT3:
-#elif defined(BF537_FAMILY)
+#if !BFIN_GPIO_PINT
+#if defined(BF537_FAMILY)
                case IRQ_PH_INTA_MAC_RX:
                case IRQ_PF_INTA_PG_INTA:
 #elif defined(BF533_FAMILY)
@@ -1372,6 +1026,7 @@ int __init init_arch_irq(void)
 #endif
                        irq_set_chained_handler(irq, bfin_demux_gpio_irq);
                        break;
+#endif
 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
                case IRQ_MAC_ERROR:
                        irq_set_chained_handler(irq,
@@ -1419,10 +1074,12 @@ int __init init_arch_irq(void)
                                         handle_level_irq);
 #endif
        /* if configured as edge, then will be changed to do_edge_IRQ */
+#ifdef CONFIG_GPIO_ADI
        for (irq = GPIO_IRQ_BASE;
                irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
                irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
                                         handle_level_irq);
+#endif
        bfin_write_IMASK(0);
        CSYNC();
        ilat = bfin_read_ILAT();
@@ -1525,19 +1182,6 @@ int __init init_arch_irq(void)
 
        local_irq_disable();
 
-#if BFIN_GPIO_PINT
-# ifdef CONFIG_PINTx_REASSIGN
-       pint[0]->assign = CONFIG_PINT0_ASSIGN;
-       pint[1]->assign = CONFIG_PINT1_ASSIGN;
-       pint[2]->assign = CONFIG_PINT2_ASSIGN;
-       pint[3]->assign = CONFIG_PINT3_ASSIGN;
-       pint[4]->assign = CONFIG_PINT4_ASSIGN;
-       pint[5]->assign = CONFIG_PINT5_ASSIGN;
-# endif
-       /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
-       init_pint_lut();
-#endif
-
        for (irq = 0; irq <= SYS_IRQS; irq++) {
                if (irq <= IRQ_CORETMR) {
                        irq_set_chip_and_handler(irq, &bfin_core_irqchip,
@@ -1546,9 +1190,6 @@ int __init init_arch_irq(void)
                        if (irq == IRQ_CORETMR)
                                irq_set_handler(irq, handle_percpu_irq);
 #endif
-               } else if (irq >= BFIN_IRQ(21) && irq <= BFIN_IRQ(26)) {
-                       irq_set_chip(irq, &bfin_sec_irqchip);
-                       irq_set_chained_handler(irq, bfin_demux_gpio_irq);
                } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
                        irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
                                handle_percpu_irq);
@@ -1563,10 +1204,6 @@ int __init init_arch_irq(void)
                        __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
                }
        }
-       for (irq = GPIO_IRQ_BASE;
-               irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
-               irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
-                                       handle_level_irq);
 
        bfin_write_IMASK(0);
        CSYNC();
index 87bfe549ad3f5044b8ce652434b98d00470672fc..1387a94bcfd5a30e68fb00d9e293eea7db710d98 100644 (file)
@@ -27,7 +27,7 @@ struct bfin_cpu_pm_fns *bfin_cpu_pm;
 
 void bfin_pm_suspend_standby_enter(void)
 {
-#ifndef CONFIG_BF60x
+#if !BFIN_GPIO_PINT
        bfin_pm_standby_setup();
 #endif
 
@@ -41,7 +41,7 @@ void bfin_pm_suspend_standby_enter(void)
 # endif
 #endif
 
-#ifndef CONFIG_BF60x
+#if !BFIN_GPIO_PINT
        bfin_pm_standby_restore();
 #endif
 
@@ -128,6 +128,7 @@ static void flushinv_all_dcache(void)
                                        if ((status & 0x3) != 0x3)
                                                continue;
 
+
                                        /* construct the address using the tag */
                                        addr = (status & 0xFFFFC800) | (subbank << 12) | (set << 5);
 
@@ -140,11 +141,14 @@ static void flushinv_all_dcache(void)
 
 int bfin_pm_suspend_mem_enter(void)
 {
-       int wakeup, ret;
+       int ret;
+#ifndef CONFIG_BF60x
+       int wakeup;
+#endif
 
        unsigned char *memptr = kmalloc(L1_CODE_LENGTH + L1_DATA_A_LENGTH
                                         + L1_DATA_B_LENGTH + L1_SCRATCH_LENGTH,
-                                         GFP_KERNEL);
+                                         GFP_ATOMIC);
 
        if (memptr == NULL) {
                panic("bf53x_suspend_l1_mem malloc failed");
@@ -170,10 +174,8 @@ int bfin_pm_suspend_mem_enter(void)
                return ret;
        }
 
+#ifdef CONFIG_GPIO_ADI
        bfin_gpio_pm_hibernate_suspend();
-
-#if BFIN_GPIO_PINT
-       bfin_pint_suspend();
 #endif
 
 #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
@@ -194,11 +196,9 @@ int bfin_pm_suspend_mem_enter(void)
        _enable_icplb();
        _enable_dcplb();
 
-#if BFIN_GPIO_PINT
-       bfin_pint_resume();
-#endif
-
+#ifdef CONFIG_GPIO_ADI
        bfin_gpio_pm_hibernate_restore();
+#endif
        blackfin_dma_resume();
 
        kfree(memptr);
index 82f301c117a508b562cf16bd698f61e1ed9f0797..2bbae07838198912aa4beda231a0f96eaa647bd5 100644 (file)
@@ -146,6 +146,7 @@ static irqreturn_t ipi_handler_int1(int irq, void *dev_instance)
 
        platform_clear_ipi(cpu, IRQ_SUPPLE_1);
 
+       smp_rmb();
        bfin_ipi_data = &__get_cpu_var(bfin_ipi);
        while ((pending = atomic_xchg(&bfin_ipi_data->bits, 0)) != 0) {
                msg = 0;
@@ -161,18 +162,20 @@ static irqreturn_t ipi_handler_int1(int irq, void *dev_instance)
                        case BFIN_IPI_CALL_FUNC:
                                generic_smp_call_function_interrupt();
                                break;
-
                        case BFIN_IPI_CALL_FUNC_SINGLE:
                                generic_smp_call_function_single_interrupt();
                                break;
-
                        case BFIN_IPI_CPU_STOP:
                                ipi_cpu_stop(cpu);
                                break;
+                       default:
+                               goto out;
                        }
                        atomic_dec(&bfin_ipi_data->count);
                } while (msg < BITS_PER_LONG);
+
        }
+out:
        return IRQ_HANDLED;
 }
 
@@ -198,10 +201,11 @@ void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
                bfin_ipi_data = &per_cpu(bfin_ipi, cpu);
                atomic_set_mask((1 << msg), &bfin_ipi_data->bits);
                atomic_inc(&bfin_ipi_data->count);
-               platform_send_ipi_cpu(cpu, IRQ_SUPPLE_1);
        }
-
        local_irq_restore(flags);
+       smp_wmb();
+       for_each_cpu(cpu, cpumask)
+               platform_send_ipi_cpu(cpu, IRQ_SUPPLE_1);
 }
 
 void arch_send_call_function_single_ipi(int cpu)
index 957dd00ea561ce3881a0af87394d349fab04f449..77ea09b8bce1bb775c725f71211de3d3c9224229 100644 (file)
@@ -36,9 +36,6 @@ config GENERIC_HWEIGHT
 config GENERIC_BUG
        def_bool y
 
-config COMMON_CLKDEV
-       def_bool y
-
 config C6X_BIG_KERNEL
        bool "Build a big kernel"
        help
@@ -105,10 +102,6 @@ menu "Processor type and features"
 
 source "arch/c6x/platforms/Kconfig"
 
-config TMS320C6X_CACHES_ON
-       bool "L2 cache support"
-       default y
-
 config KERNEL_RAM_BASE_ADDRESS
        hex "Virtual address of memory base"
        default 0xe0000000 if SOC_TMS320C6455
index 4c8dc562bd90dce27d0236140434a34120fe33d7..d4e9ef87076dbe4e0013876c27fdd84d69840d75 100644 (file)
@@ -84,8 +84,6 @@ struct thread_info *current_thread_info(void)
 #define put_thread_info(ti)    put_task_struct((ti)->task)
 #endif /* __ASSEMBLY__ */
 
-#define        PREEMPT_ACTIVE  0x10000000
-
 /*
  * thread information flag bit numbers
  * - pending work-to-be-done flags are in LSW
index 17bb12d760b2eb2858cb39bb8e057fd51c5c96e5..04126f7bfab2a918e4e8c509d9fd989a2e7217b5 100644 (file)
@@ -2,18 +2,6 @@
 #define __ASM_HARDIRQ_H
 
 #include <asm/irq.h>
-
-#define HARDIRQ_BITS   8
-
-/*
- * The hardirq mask has to be large enough to have
- * space for potentially all IRQ sources in the system
- * nesting on a single CPU:
- */
-#if (1 << HARDIRQ_BITS) < NR_IRQS
-# error HARDIRQ_BITS is too low!
-#endif
-
 #include <asm-generic/hardirq.h>
 
 #endif /* __ASM_HARDIRQ_H */
index 07c8c40c52b312ddfee756ca8ea5b0619ddb4a65..55dede18c032e37195cdb5c17ccebfddebc505a8 100644 (file)
@@ -44,8 +44,6 @@ struct thread_info {
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * macros/functions for gaining access to the thread information structure
  */
index bebd7eadc7720c3e3ddac4fe455a8bef37308042..af29e17c01814a2d88be2ca5d535f31441ddc474 100644 (file)
@@ -52,8 +52,6 @@ struct thread_info {
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * macros/functions for gaining access to the thread information structure
  */
index f7c32406a711a5b619d53037fe76d8689107e3c6..a59dad3b3695112e6f15633de0f3b9304af17532 100644 (file)
@@ -73,10 +73,6 @@ struct thread_info {
 
 #endif  /* __ASSEMBLY__  */
 
-/*  looks like "linux/hardirq.h" uses this.  */
-
-#define PREEMPT_ACTIVE         0x10000000
-
 #ifndef __ASSEMBLY__
 
 #define INIT_THREAD_INFO(tsk)                   \
index dfe85e92ca2e37060c65b1a4f1fb70afd69a8fa5..4e4119b0e6915fc7e05c1536d9248d638cb4fe16 100644 (file)
@@ -6,6 +6,7 @@ menu "Processor type and features"
 
 config IA64
        bool
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select PCI if (!IA64_HP_SIM)
        select ACPI if (!IA64_HP_SIM)
        select PM if (!IA64_HP_SIM)
index d43daf192b21d54df034e52c809a4ac4b2178161..4c530a82fc469f976b8a38a341f077a43f9c9998 100644 (file)
@@ -1992,7 +1992,7 @@ sba_connect_bus(struct pci_bus *bus)
        if (PCI_CONTROLLER(bus)->iommu)
                return;
 
-       handle = PCI_CONTROLLER(bus)->acpi_handle;
+       handle = acpi_device_handle(PCI_CONTROLLER(bus)->companion);
        if (!handle)
                return;
 
index 80775f55f03f9293c2d05d2598e349f08ef9b56e..71fbaaa495ccc18af5f33cdaef92c0ab228dad8e 100644 (file)
@@ -95,7 +95,7 @@ struct iospace_resource {
 };
 
 struct pci_controller {
-       void *acpi_handle;
+       struct acpi_device *companion;
        void *iommu;
        int segment;
        int node;               /* nearest node with memory or -1 for global allocation */
index cade13dd0299f8754d18d87eded8661b64bf3eb8..5957cf61f8980641c54271ab4030b1d765570001 100644 (file)
@@ -11,9 +11,6 @@
 #include <asm/processor.h>
 #include <asm/ptrace.h>
 
-#define PREEMPT_ACTIVE_BIT 30
-#define PREEMPT_ACTIVE (1 << PREEMPT_ACTIVE_BIT)
-
 #ifndef __ASSEMBLY__
 
 /*
index 7a53530f22c219eb877d81d2392a85722e9503dc..ddea607f948aaa61932b022a14a390df9e816f8c 100644 (file)
@@ -1169,21 +1169,8 @@ skip_rbs_switch:
 .work_pending:
        tbit.z p6,p0=r31,TIF_NEED_RESCHED       // is resched not needed?
 (p6)   br.cond.sptk.few .notify
-#ifdef CONFIG_PREEMPT
-(pKStk) dep r21=-1,r0,PREEMPT_ACTIVE_BIT,1
-       ;;
-(pKStk) st4 [r20]=r21
-#endif
-       SSM_PSR_I(p0, p6, r2)   // enable interrupts
-       br.call.spnt.many rp=schedule
+       br.call.spnt.many rp=preempt_schedule_irq
 .ret9: cmp.eq p6,p0=r0,r0      // p6 <- 1 (re-check)
-       RSM_PSR_I(p0, r2, r20)  // disable interrupts
-       ;;
-#ifdef CONFIG_PREEMPT
-(pKStk)        adds r20=TI_PRE_COUNT+IA64_TASK_SIZE,r13
-       ;;
-(pKStk)        st4 [r20]=r0            // preempt_count() <- 0
-#endif
 (pLvSys)br.cond.sptk.few  __paravirt_pending_syscall_end
        br.cond.sptk.many .work_processed_kernel
 
index f8280a766a78672238d34ab41524f21f286b5e14..074fde49c9e6234f22e3e5b132bcdcfe176e9757 100644 (file)
@@ -947,7 +947,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
        case KPROBE_HIT_SSDONE:
                /*
                 * We increment the nmissed count for accounting,
-                * we can also use npre/npostfault count for accouting
+                * we can also use npre/npostfault count for accounting
                 * these specific fault cases.
                 */
                kprobes_inc_nmissed_count(cur);
index 2326790b7d8be4f9e6cffbea4c4a22fc1ab91f3e..9e4938d8ca4d297e331131a79d8458d97a27d256 100644 (file)
@@ -436,9 +436,9 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
        if (!controller)
                return NULL;
 
-       controller->acpi_handle = device->handle;
+       controller->companion = device;
 
-       pxm = acpi_get_pxm(controller->acpi_handle);
+       pxm = acpi_get_pxm(device->handle);
 #ifdef CONFIG_NUMA
        if (pxm >= 0)
                controller->node = pxm_to_node(pxm);
@@ -489,7 +489,7 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
 {
        struct pci_controller *controller = bridge->bus->sysdata;
 
-       ACPI_HANDLE_SET(&bridge->dev, controller->acpi_handle);
+       ACPI_COMPANION_SET(&bridge->dev, controller->companion);
        return 0;
 }
 
index b1725398b5af49683622765652104a85c3d95228..0640739cc20cf2895fca507babfe7de9096d8a41 100644 (file)
@@ -132,7 +132,7 @@ sn_get_bussoft_ptr(struct pci_bus *bus)
        struct acpi_resource_vendor_typed *vendor;
 
 
-       handle = PCI_CONTROLLER(bus)->acpi_handle;
+       handle = acpi_device_handle(PCI_CONTROLLER(bus)->companion);
        status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
                                          &sn_uuid, &buffer);
        if (ACPI_FAILURE(status)) {
@@ -360,7 +360,7 @@ sn_acpi_get_pcidev_info(struct pci_dev *dev, struct pcidev_info **pcidev_info,
        acpi_status status;
        struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
-       rootbus_handle = PCI_CONTROLLER(dev)->acpi_handle;
+       rootbus_handle = acpi_device_handle(PCI_CONTROLLER(dev)->companion);
         status = acpi_evaluate_integer(rootbus_handle, METHOD_NAME__SEG, NULL,
                                        &segment);
         if (ACPI_SUCCESS(status)) {
index 4c31c0ae215e87928098a9b60e2d978ae710f800..5f2ac4f64ddfd125e197ee045bba122cde8fa900 100644 (file)
@@ -3,22 +3,6 @@
 #define __ASM_HARDIRQ_H
 
 #include <asm/irq.h>
-
-#if NR_IRQS > 256
-#define HARDIRQ_BITS   9
-#else
-#define HARDIRQ_BITS   8
-#endif
-
-/*
- * The hardirq mask has to be large enough to have
- * space for potentially all IRQ sources in the system
- * nesting on a single CPU:
- */
-#if (1 << HARDIRQ_BITS) < NR_IRQS
-# error HARDIRQ_BITS is too low!
-#endif
-
 #include <asm-generic/hardirq.h>
 
 #endif /* __ASM_HARDIRQ_H */
index a979a41981689a7321a7e758a3c5ec744d6f9202..9fc78fc4444524681a6688d2273edae2581b4584 100644 (file)
@@ -45,7 +45,7 @@ static inline void get_new_mmu_context(struct mm_struct *mm)
                   Flush all TLB and start new cycle. */
                local_flush_tlb_all();
                /* Fix version if needed.
-                  Note that we avoid version #0 to distingush NO_CONTEXT. */
+                  Note that we avoid version #0 to distinguish NO_CONTEXT. */
                if (!mc)
                        mmu_context_cache = mc = MMU_CONTEXT_FIRST_VERSION;
        }
index c074f4c2e858e6cc76b16476a9fc24aea2566793..00171703402f19b576612f699bf733fe12252390 100644 (file)
@@ -53,8 +53,6 @@ struct thread_info {
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 #define THREAD_SIZE            (PAGE_SIZE << 1)
 #define THREAD_SIZE_ORDER      1
 /*
index 0c01543f10cd9c1ad53c9453294d185fc18730cd..7c3db9940ce1f1e1254561ff0992c3980127beeb 100644 (file)
@@ -182,13 +182,7 @@ need_resched:
        ld      r4, PSW(sp)             ; interrupts off (exception path) ?
        and3    r4, r4, #0x4000
        beqz    r4, restore_all
-       LDIMM   (r4, PREEMPT_ACTIVE)
-       st      r4, @(TI_PRE_COUNT, r8)
-       ENABLE_INTERRUPTS(r4)
-       bl      schedule
-       ldi     r4, #0
-       st      r4, @(TI_PRE_COUNT, r8)
-       DISABLE_INTERRUPTS(r4)
+       bl      preempt_schedule_irq
        bra     need_resched
 #endif
 
index 311a300d48cca82b82a5faa0bf6abbaee42cacef..75f25a8e300170ce85130da8fd2f739faa983059 100644 (file)
@@ -1,6 +1,7 @@
 config M68K
        bool
        default y
+       select ARCH_MIGHT_HAVE_PC_PARPORT if ISA
        select HAVE_IDE
        select HAVE_AOUT if MMU
        select HAVE_DEBUG_BUGVERBOSE
index db30ed276878dcbf793e667d6edb279c5234a60a..6c618529d9b96e3815568a486a146c31b4b6a005 100644 (file)
@@ -5,17 +5,6 @@
 #include <linux/cache.h>
 #include <asm/irq.h>
 
-#define HARDIRQ_BITS   8
-
-/*
- * The hardirq mask has to be large enough to have
- * space for potentially all IRQ sources in the system
- * nesting on a single CPU:
- */
-#if (1 << HARDIRQ_BITS) < NR_IRQS
-# error HARDIRQ_BITS is too low!
-#endif
-
 #ifdef CONFIG_MMU
 
 static inline void ack_bad_irq(unsigned int irq)
index 126131f94a2ca951a2db9c9a414e3c30a142baeb..21a4784ca5a186256cfbb5bc6d1d1b7cd4de3e1c 100644 (file)
@@ -35,8 +35,6 @@ struct thread_info {
 };
 #endif /* __ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE         0x4000000
-
 #define INIT_THREAD_INFO(tsk)                  \
 {                                              \
        .task           = &tsk,                 \
index a78f5649e8decf3fbd80c3d1a54567644f6fd385..b54ac7aba850eaf02ac995a857e673102039f3be 100644 (file)
@@ -45,7 +45,7 @@
 .globl system_call, buserr, trap, resume
 .globl sys_call_table
 .globl __sys_fork, __sys_clone, __sys_vfork
-.globl ret_from_interrupt, bad_interrupt
+.globl bad_interrupt
 .globl auto_irqhandler_fixup
 .globl user_irqvec_fixup
 
@@ -275,8 +275,6 @@ do_delayed_trace:
 ENTRY(auto_inthandler)
        SAVE_ALL_INT
        GET_CURRENT(%d0)
-       movel   %d0,%a1
-       addqb   #1,%a1@(TINFO_PREEMPT+1)
                                        |  put exception # in d0
        bfextu  %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
        subw    #VEC_SPUR,%d0
@@ -286,32 +284,13 @@ ENTRY(auto_inthandler)
 auto_irqhandler_fixup = . + 2
        jsr     do_IRQ                  |  process the IRQ
        addql   #8,%sp                  |  pop parameters off stack
-
-ret_from_interrupt:
-       movel   %curptr@(TASK_STACK),%a1
-       subqb   #1,%a1@(TINFO_PREEMPT+1)
-       jeq     ret_from_last_interrupt
-2:     RESTORE_ALL
-
-       ALIGN
-ret_from_last_interrupt:
-       moveq   #(~ALLOWINT>>8)&0xff,%d0
-       andb    %sp@(PT_OFF_SR),%d0
-       jne     2b
-
-       /* check if we need to do software interrupts */
-       tstl    irq_stat+CPUSTAT_SOFTIRQ_PENDING
-       jeq     .Lret_from_exception
-       pea     ret_from_exception
-       jra     do_softirq
+       jra     ret_from_exception
 
 /* Handler for user defined interrupt vectors */
 
 ENTRY(user_inthandler)
        SAVE_ALL_INT
        GET_CURRENT(%d0)
-       movel   %d0,%a1
-       addqb   #1,%a1@(TINFO_PREEMPT+1)
                                        |  put exception # in d0
        bfextu  %sp@(PT_OFF_FORMATVEC){#4,#10},%d0
 user_irqvec_fixup = . + 2
@@ -321,29 +300,18 @@ user_irqvec_fixup = . + 2
        movel   %d0,%sp@-               |  put vector # on stack
        jsr     do_IRQ                  |  process the IRQ
        addql   #8,%sp                  |  pop parameters off stack
-
-       movel   %curptr@(TASK_STACK),%a1
-       subqb   #1,%a1@(TINFO_PREEMPT+1)
-       jeq     ret_from_last_interrupt
-       RESTORE_ALL
+       jra     ret_from_exception
 
 /* Handler for uninitialized and spurious interrupts */
 
 ENTRY(bad_inthandler)
        SAVE_ALL_INT
        GET_CURRENT(%d0)
-       movel   %d0,%a1
-       addqb   #1,%a1@(TINFO_PREEMPT+1)
 
        movel   %sp,%sp@-
        jsr     handle_badint
        addql   #4,%sp
-
-       movel   %curptr@(TASK_STACK),%a1
-       subqb   #1,%a1@(TINFO_PREEMPT+1)
-       jeq     ret_from_last_interrupt
-       RESTORE_ALL
-
+       jra     ret_from_exception
 
 resume:
        /*
index 4d7da384eea03d5a1101859a5814c7dccce53a9e..077d3a70fed1995611f89e0f5795c40da07378df 100644 (file)
@@ -58,12 +58,6 @@ void __init init_IRQ(void)
 {
        int i;
 
-       /* assembly irq entry code relies on this... */
-       if (HARDIRQ_MASK != 0x00ff0000) {
-               extern void hardirq_mask_is_broken(void);
-               hardirq_mask_is_broken();
-       }
-
        for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
                irq_set_chip_and_handler(i, &auto_irq_chip, handle_simple_irq);
 
index 7f91c2fde5096b9eaaef2e33334cf0339b896352..23ac054c6e1ad929fa40e8aa033e51251c96538d 100644 (file)
@@ -27,7 +27,6 @@
 .globl ret_from_exception
 .globl ret_from_signal
 .globl sys_call_table
-.globl ret_from_interrupt
 .globl bad_interrupt
 .globl inthandler1
 .globl inthandler2
@@ -137,7 +136,7 @@ inthandler1:
        movel   #65,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler2:
        SAVE_ALL_INT
@@ -148,7 +147,7 @@ inthandler2:
        movel   #66,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler3:
        SAVE_ALL_INT
@@ -159,7 +158,7 @@ inthandler3:
        movel   #67,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler4:
        SAVE_ALL_INT
@@ -170,7 +169,7 @@ inthandler4:
        movel   #68,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler5:
        SAVE_ALL_INT
@@ -181,7 +180,7 @@ inthandler5:
        movel   #69,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler6:
        SAVE_ALL_INT
@@ -192,7 +191,7 @@ inthandler6:
        movel   #70,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler7:
        SAVE_ALL_INT
@@ -203,7 +202,7 @@ inthandler7:
        movel   #71,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
+       bra     ret_from_exception
 
 inthandler:
        SAVE_ALL_INT
@@ -214,23 +213,7 @@ inthandler:
        movel   %d0,%sp@-               /*  put vector # on stack*/
        jbsr    process_int             /*  process the IRQ*/
 3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
-
-ret_from_interrupt:
-       jeq     1f
-2:
-       RESTORE_ALL
-1:
-       moveb   %sp@(PT_OFF_SR), %d0
-       and     #7, %d0
-       jhi     2b
-
-       /* check if we need to do software interrupts */
-       jeq     ret_from_exception
-
-       pea     ret_from_exception
-       jra     do_softirq
-
+       bra     ret_from_exception
 
 /*
  * Handler for uninitialized and spurious interrupts.
index 904fd9a4af4e45d472a121fdc678a523655059cc..447c33ef37fda3456b5fad22d705f123c91b4f84 100644 (file)
@@ -29,7 +29,6 @@
 .globl ret_from_exception
 .globl ret_from_signal
 .globl sys_call_table
-.globl ret_from_interrupt
 .globl bad_interrupt
 .globl inthandler
 
@@ -132,26 +131,9 @@ inthandler:
 
        movel   %sp,%sp@-
        movel   %d0,%sp@-               /*  put vector # on stack*/
-       jbsr    do_IRQ                  /*  process the IRQ*/
-3:             addql   #8,%sp                  /*  pop parameters off stack*/
-       bra     ret_from_interrupt
-
-ret_from_interrupt:
-       jeq     1f
-2:
-       RESTORE_ALL
-1:
-       moveb   %sp@(PT_OFF_SR), %d0
-       and     #7, %d0
-       jhi     2b
-       /* check if we need to do software interrupts */
-
-       movel   irq_stat+CPUSTAT_SOFTIRQ_PENDING,%d0
-       jeq     ret_from_exception
-
-       pea     ret_from_exception
-       jra     do_softirq
-
+       jbsr    do_IRQ                  /*  process the IRQ */
+       addql   #8,%sp                  /*  pop parameters off stack*/
+       jra     ret_from_exception
 
 /*
  * Handler for uninitialized and spurious interrupts.
index 7c4a3300614230ce8d956257412e8e0ab0ade8fb..b19e9c588a16733e81f5495593c881d2d9c7c170 100644 (file)
@@ -46,8 +46,6 @@ struct thread_info {
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SHIFT           12
 #else
index 655e1cadf6924ea54ab19b1274ede3d2a7b5e46b..e23cccde9c2759b9ea798a3a0705f7f242acd474 100644 (file)
@@ -1,5 +1,6 @@
 config MICROBLAZE
        def_bool y
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select HAVE_MEMBLOCK
        select HAVE_MEMBLOCK_NODE_MAP
        select HAVE_FUNCTION_TRACER
index de26ea6373ded64af3d7793489be9343a1ee1075..8c9d36591a031d6a84e81ae7485185aea125a5e3 100644 (file)
@@ -106,8 +106,6 @@ static inline struct thread_info *current_thread_info(void)
 /* thread information allocation */
 #endif /* __ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * thread information flags
  * - these are process state flags that various assembly files may
index 867d7db11581b30517389b3b9f6045d04b683ce8..650de3976e7a5a337ab60dcc6ee5f0dd04fe22c0 100644 (file)
@@ -1,6 +1,7 @@
 config MIPS
        bool
        default y
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select HAVE_CONTEXT_TRACKING
        select HAVE_GENERIC_DMA_COHERENT
        select HAVE_IDE
index e2b4ad55462f3477f6c4b5e63d54057064b92fde..28e49f226dc0286aa73b22c1d7c76b663af1729c 100644 (file)
@@ -351,7 +351,6 @@ CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_HCD_PLATFORM=y
 CONFIG_USB_STORAGE=y
 CONFIG_MMC=y
-CONFIG_MMC_CLKGATE=y
 CONFIG_MMC_AU1X=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
index a76fe5a57a9f64e302af248194ea9288cb4590b4..df69bfd2b006bc01f300094a8ae1a571058ef101 100644 (file)
@@ -192,13 +192,13 @@ typedef struct {
        /* Number of packets processed by PIP */
        uint32_t packets;
        /*
-        * Number of indentified L2 multicast packets.  Does not
+        * Number of identified L2 multicast packets.   Does not
         * include broadcast packets.  Only includes packets whose
         * parse mode is SKIP_TO_L2
         */
        uint32_t multicast_packets;
        /*
-        * Number of indentified L2 broadcast packets.  Does not
+        * Number of identified L2 broadcast packets.   Does not
         * include multicast packets.  Only includes packets whose
         * parse mode is SKIP_TO_L2
         */
index f9b24bfbdbae96f8cc31d58d7cb0318130ceab9f..4f58ef6d0eed5c58c9e58595fac36b4b7f747a2e 100644 (file)
@@ -92,8 +92,6 @@ static inline struct thread_info *current_thread_info(void)
 
 #define STACK_WARN     (THREAD_SIZE / 8)
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * thread information flags
  * - these are process state flags that various assembly files may need to
index c67c2b5365a6dbef415d767a69db49f73ea2ad69..75dbe696f830cc93284a47f61fb5ae4a00f2a292 100644 (file)
@@ -71,7 +71,7 @@ static inline unsigned long allocate_mmu_context(struct mm_struct *mm)
                local_flush_tlb_all();
 
                /* fix the TLB version if needed (we avoid version #0 so as to
-                * distingush MMU_NO_CONTEXT) */
+                * distinguish MMU_NO_CONTEXT) */
                if (!mc)
                        *pmc = mc = MMU_CONTEXT_FIRST_VERSION;
        }
index 224b4262486dbca41453861f95461b635bb40bcc..bf280eaccd36fd7e7b963176184450fb98126340 100644 (file)
@@ -16,8 +16,6 @@
 
 #include <asm/page.h>
 
-#define PREEMPT_ACTIVE         0x10000000
-
 #ifdef CONFIG_4KSTACKS
 #define THREAD_SIZE            (4096)
 #define THREAD_SIZE_ORDER      (0)
index 4739b8302a58d38e478c7f58a10e7c22c0c20897..89076a66eee266d79782949f93a9cbba30371b1a 100644 (file)
@@ -24,7 +24,7 @@ OBJCOPYFLAGS    := -O binary -R .note -R .comment -S
 LDFLAGS_vmlinux :=
 LIBGCC                 := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
 
-KBUILD_CFLAGS  += -pipe -ffixed-r10
+KBUILD_CFLAGS  += -pipe -ffixed-r10 -D__linux__
 
 ifeq ($(CONFIG_OPENRISC_HAVE_INST_MUL),y)
        KBUILD_CFLAGS += $(call cc-option,-mhard-mul)
index ea172bdfa36ae41b139ebccd5f72a357ebd4ec28..42fe5303a37008bd33777b2c539025f259c5c9fd 100644 (file)
@@ -1,9 +1,9 @@
 CONFIG_CROSS_COMPILE="or32-linux-"
+CONFIG_NO_HZ=y
 CONFIG_LOG_BUF_SHIFT=14
 CONFIG_BLK_DEV_INITRD=y
 # CONFIG_RD_GZIP is not set
 CONFIG_EXPERT=y
-# CONFIG_SYSCTL_SYSCALL is not set
 # CONFIG_KALLSYMS is not set
 # CONFIG_EPOLL is not set
 # CONFIG_TIMERFD is not set
@@ -15,7 +15,6 @@ CONFIG_SLOB=y
 CONFIG_MODULES=y
 # CONFIG_BLOCK is not set
 CONFIG_OPENRISC_BUILTIN_DTB="or1ksim"
-CONFIG_NO_HZ=y
 CONFIG_HZ_100=y
 CONFIG_NET=y
 CONFIG_PACKET=y
@@ -39,11 +38,8 @@ CONFIG_DEVTMPFS_MOUNT=y
 # CONFIG_FW_LOADER is not set
 CONFIG_PROC_DEVICETREE=y
 CONFIG_NETDEVICES=y
-CONFIG_MICREL_PHY=y
-CONFIG_NET_ETHERNET=y
 CONFIG_ETHOC=y
-# CONFIG_NETDEV_1000 is not set
-# CONFIG_NETDEV_10000 is not set
+CONFIG_MICREL_PHY=y
 # CONFIG_WLAN is not set
 # CONFIG_INPUT is not set
 # CONFIG_SERIO is not set
@@ -55,11 +51,9 @@ CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_OF_PLATFORM=y
 # CONFIG_HW_RANDOM is not set
 # CONFIG_HWMON is not set
-# CONFIG_MFD_SUPPORT is not set
 # CONFIG_USB_SUPPORT is not set
 # CONFIG_DNOTIFY is not set
 CONFIG_TMPFS=y
 CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
 # CONFIG_ENABLE_WARN_DEPRECATED is not set
 # CONFIG_ENABLE_MUST_CHECK is not set
index 78405625e799016b46647db52711c77f5b7ef224..da1951a22907772ec776dde7761c765479b6436a 100644 (file)
@@ -65,6 +65,7 @@ generic-y += trace_clock.h
 generic-y += types.h
 generic-y += ucontext.h
 generic-y += user.h
+generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += preempt.h
index 10ff50f0202ac37181fe160fb7ac62f2d1a95dc9..ef872ae4c878970733342be87177b473bde09456 100644 (file)
@@ -47,12 +47,10 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
                        *location = value;
                        break;
                case R_OR32_CONST:
-                       location = (uint16_t *)location + 1;
-                       *((uint16_t *)location) = (uint16_t) (value);
+                       *((uint16_t *)location + 1) = value;
                        break;
                case R_OR32_CONSTH:
-                       location = (uint16_t *)location + 1;
-                       *((uint16_t *)location) = (uint16_t) (value >> 16);
+                       *((uint16_t *)location + 1) = value >> 16;
                        break;
                case R_OR32_JUMPTARG:
                        value -= (uint32_t)location;
index 09a769b695720909a52b409f9a49fe40b99f4fa0..4fc7ccc0a2cf5b43549f9de2ed09124a196b5766 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/device.h>
 #include <linux/of_platform.h>
 
+#include <asm/sections.h>
 #include <asm/segment.h>
 #include <asm/pgtable.h>
 #include <asm/types.h>
@@ -75,7 +76,7 @@ static unsigned long __init setup_memory(void)
 
        ram_start_pfn = PFN_UP(memory_start);
        /* free_ram_start_pfn is first page after kernel */
-       free_ram_start_pfn = PFN_UP(__pa(&_end));
+       free_ram_start_pfn = PFN_UP(__pa(_end));
        ram_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
 
        max_pfn = ram_end_pfn;
@@ -207,15 +208,15 @@ void __init setup_cpuinfo(void)
  * Falls back on built-in device tree in case null pointer is passed.
  */
 
-void __init or32_early_setup(unsigned int fdt)
+void __init or32_early_setup(void *fdt)
 {
-       if (fdt) {
-               early_init_devtree((void*) fdt);
-               printk(KERN_INFO "FDT at 0x%08x\n", fdt);
-       } else {
-               early_init_devtree(__dtb_start);
-               printk(KERN_INFO "Compiled-in FDT at %p\n", __dtb_start);
+       if (fdt)
+               pr_info("FDT at %p\n", fdt);
+       else {
+               fdt = __dtb_start;
+               pr_info("Compiled-in FDT at %p\n", fdt);
        }
+       early_init_devtree(fdt);
 }
 
 static int __init openrisc_device_probe(void)
@@ -288,10 +289,10 @@ void __init setup_arch(char **cmdline_p)
        setup_cpuinfo();
 
        /* process 1's initial memory region is the kernel code/data */
-       init_mm.start_code = (unsigned long)&_stext;
-       init_mm.end_code = (unsigned long)&_etext;
-       init_mm.end_data = (unsigned long)&_edata;
-       init_mm.brk = (unsigned long)&_end;
+       init_mm.start_code = (unsigned long)_stext;
+       init_mm.end_code = (unsigned long)_etext;
+       init_mm.end_data = (unsigned long)_edata;
+       init_mm.brk = (unsigned long)_end;
 
 #ifdef CONFIG_BLK_DEV_INITRD
        initrd_start = (unsigned long)&__initrd_start;
index ee842a2d3f362562e5ad753007f11d1358ed13bb..70b9ce41835cdf2a3e345a39dc9e50197f6cb330 100644 (file)
@@ -1,10 +1,8 @@
 #ifndef __OPENRISC_VMLINUX_H_
 #define __OPENRISC_VMLINUX_H_
 
-extern char _stext, _etext, _edata, _end;
 #ifdef CONFIG_BLK_DEV_INITRD
 extern char __initrd_start, __initrd_end;
-extern char __initramfs_start;
 #endif
 
 extern u32 __dtb_start[];
index c03567a9a91583a89ebd9dd24166afa7f586b64f..b5f1858baf3399b1dcb10ef3f5d19debf50876d3 100644 (file)
@@ -1,6 +1,7 @@
 config PARISC
        def_bool y
        select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select HAVE_IDE
        select HAVE_OPROFILE
        select HAVE_FUNCTION_TRACER if 64BIT
index bc7cf120106b30e477264850e373f346eeb9bf82..d5f97ea3a4e1ab13a018de4d5d549f90efe4f299 100644 (file)
@@ -46,9 +46,6 @@ struct thread_info {
 #define THREAD_SIZE             (PAGE_SIZE << THREAD_SIZE_ORDER)
 #define THREAD_SHIFT            (PAGE_SHIFT + THREAD_SIZE_ORDER)
 
-#define PREEMPT_ACTIVE_BIT     28
-#define PREEMPT_ACTIVE         (1 << PREEMPT_ACTIVE_BIT)
-
 /*
  * thread information flags
  */
index 4740b0a15fa89b220dd3e36aa7a39b3f5d25dc02..b44b52c0a8f07d2854d5a21ca6fb2ecf409409c1 100644 (file)
@@ -85,6 +85,7 @@ config GENERIC_HWEIGHT
 config PPC
        bool
        default y
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select BINFMT_ELF
        select OF
        select OF_EARLY_FLATTREE
index 4c617bf8cdb24af8f3a202d40c4cc98b776768fd..4f6e48277c46170bb806bbb17e41c2887de4054f 100644 (file)
                reg = <0xe2000 0x1000>;
        };
 
-/include/ "qoriq-dma-0.dtsi"
+/include/ "elo3-dma-0.dtsi"
        dma@100300 {
                fsl,iommu-parent = <&pamu0>;
                fsl,liodn-reg = <&guts 0x580>; /* DMA1LIODNR */
        };
 
-/include/ "qoriq-dma-1.dtsi"
+/include/ "elo3-dma-1.dtsi"
        dma@101300 {
                fsl,iommu-parent = <&pamu0>;
                fsl,liodn-reg = <&guts 0x584>; /* DMA2LIODNR */
diff --git a/arch/powerpc/boot/dts/fsl/elo3-dma-0.dtsi b/arch/powerpc/boot/dts/fsl/elo3-dma-0.dtsi
new file mode 100644 (file)
index 0000000..3c210e0
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * QorIQ Elo3 DMA device tree stub [ controller @ offset 0x100000 ]
+ *
+ * Copyright 2013 Freescale Semiconductor Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+dma0: dma@100300 {
+       #address-cells = <1>;
+       #size-cells = <1>;
+       compatible = "fsl,elo3-dma";
+       reg = <0x100300 0x4>,
+             <0x100600 0x4>;
+       ranges = <0x0 0x100100 0x500>;
+       dma-channel@0 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x0 0x80>;
+               interrupts = <28 2 0 0>;
+       };
+       dma-channel@80 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x80 0x80>;
+               interrupts = <29 2 0 0>;
+       };
+       dma-channel@100 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x100 0x80>;
+               interrupts = <30 2 0 0>;
+       };
+       dma-channel@180 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x180 0x80>;
+               interrupts = <31 2 0 0>;
+       };
+       dma-channel@300 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x300 0x80>;
+               interrupts = <76 2 0 0>;
+       };
+       dma-channel@380 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x380 0x80>;
+               interrupts = <77 2 0 0>;
+       };
+       dma-channel@400 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x400 0x80>;
+               interrupts = <78 2 0 0>;
+       };
+       dma-channel@480 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x480 0x80>;
+               interrupts = <79 2 0 0>;
+       };
+};
diff --git a/arch/powerpc/boot/dts/fsl/elo3-dma-1.dtsi b/arch/powerpc/boot/dts/fsl/elo3-dma-1.dtsi
new file mode 100644 (file)
index 0000000..cccf3bb
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * QorIQ Elo3 DMA device tree stub [ controller @ offset 0x101000 ]
+ *
+ * Copyright 2013 Freescale Semiconductor Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+dma1: dma@101300 {
+       #address-cells = <1>;
+       #size-cells = <1>;
+       compatible = "fsl,elo3-dma";
+       reg = <0x101300 0x4>,
+             <0x101600 0x4>;
+       ranges = <0x0 0x101100 0x500>;
+       dma-channel@0 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x0 0x80>;
+               interrupts = <32 2 0 0>;
+       };
+       dma-channel@80 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x80 0x80>;
+               interrupts = <33 2 0 0>;
+       };
+       dma-channel@100 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x100 0x80>;
+               interrupts = <34 2 0 0>;
+       };
+       dma-channel@180 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x180 0x80>;
+               interrupts = <35 2 0 0>;
+       };
+       dma-channel@300 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x300 0x80>;
+               interrupts = <80 2 0 0>;
+       };
+       dma-channel@380 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x380 0x80>;
+               interrupts = <81 2 0 0>;
+       };
+       dma-channel@400 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x400 0x80>;
+               interrupts = <82 2 0 0>;
+       };
+       dma-channel@480 {
+               compatible = "fsl,eloplus-dma-channel";
+               reg = <0x480 0x80>;
+               interrupts = <83 2 0 0>;
+       };
+};
index 510afa362de141465b50aada0cf0e7c9ceb83536..4143a9733cd01e0ad62d9d3d98902e7f414dd8f3 100644 (file)
                reg        = <0xea000 0x4000>;
        };
 
-/include/ "qoriq-dma-0.dtsi"
-/include/ "qoriq-dma-1.dtsi"
+/include/ "elo3-dma-0.dtsi"
+/include/ "elo3-dma-1.dtsi"
 
 /include/ "qoriq-espi-0.dtsi"
        spi@110000 {
index ba7b1973866e1933486f47ed59e3aa0efe799f34..8fd6cf6dcee854c8244010ce12d107abb0fa81d7 100644 (file)
@@ -82,8 +82,6 @@ static inline struct thread_info *current_thread_info(void)
 
 #endif /* __ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * thread information flag bit numbers
  */
index 2156ea90eb54181c84bc5d1dff48b0de80d5e405..90fab64d911dcdca1cbcf4992e1bda00160db6a4 100644 (file)
@@ -429,7 +429,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
        case KPROBE_HIT_SSDONE:
                /*
                 * We increment the nmissed count for accounting,
-                * we can also use npre/npostfault count for accouting
+                * we can also use npre/npostfault count for accounting
                 * these specific fault cases.
                 */
                kprobes_inc_nmissed_count(cur);
index 057fc894be511342da4c914d28113b73a44752c0..7bfaf58d4664460db12c94499fc151e251f47f68 100644 (file)
@@ -31,7 +31,7 @@
 #define NVRW_CNT 0x20
 
 /*
- * Set oops header version to distingush between old and new format header.
+ * Set oops header version to distinguish between old and new format header.
  * lnx,oops-log partition max size is 4000, header version > 4000 will
  * help in identifying new header.
  */
index f2737a005afcb760fa5e177d764f93d73607a985..9a42ecec564767411ff5eb506b4f2bb2e18e1107 100644 (file)
@@ -21,6 +21,6 @@ $(obj)/bzImage: $(obj)/compressed/vmlinux FORCE
 $(obj)/compressed/vmlinux: FORCE
        $(Q)$(MAKE) $(build)=$(obj)/compressed $@
 
-install: $(CONFIGURE) $(obj)/image
-       sh -x  $(srctree)/$(obj)/install.sh $(KERNELRELEASE) $(obj)/image \
+install: $(CONFIGURE) $(obj)/bzImage
+       sh -x  $(srctree)/$(obj)/install.sh $(KERNELRELEASE) $(obj)/bzImage \
              System.map "$(INSTALL_PATH)"
index 9b69c0befdcaafcb46565056e10c36e884ab8065..4e63f1a13600a4e126d470138e074d2e4e98682d 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef __ASM_CTL_REG_H
 #define __ASM_CTL_REG_H
 
+#include <linux/bug.h>
+
 #ifdef CONFIG_64BIT
 # define __CTL_LOAD    "lctlg"
 # define __CTL_STORE   "stctg"
index dc9200ca32eda4d3e5a819025b176f7af5a06d60..67026300c88e5565b1d52af8bbd3eb8fa387a62e 100644 (file)
@@ -111,18 +111,7 @@ struct scm_driver {
 int scm_driver_register(struct scm_driver *scmdrv);
 void scm_driver_unregister(struct scm_driver *scmdrv);
 
-int scm_start_aob(struct aob *aob);
+int eadm_start_aob(struct aob *aob);
 void scm_irq_handler(struct aob *aob, int error);
 
-struct eadm_ops {
-       int (*eadm_start) (struct aob *aob);
-       struct module *owner;
-};
-
-int scm_get_ref(void);
-void scm_put_ref(void);
-
-void register_eadm_ops(struct eadm_ops *ops);
-void unregister_eadm_ops(struct eadm_ops *ops);
-
 #endif /* _ASM_S390_EADM_H */
index a908d2941c5d90ab305f8e7c490585e20113579a..b7eabaaeffbd09a1310c3a8de2fe73786f00169a 100644 (file)
@@ -18,8 +18,6 @@
 #define __ARCH_HAS_DO_SOFTIRQ
 #define __ARCH_IRQ_EXIT_IRQS_DISABLED
 
-#define HARDIRQ_BITS   8
-
 static inline void ack_bad_irq(unsigned int irq)
 {
        printk(KERN_CRIT "unexpected IRQ trap at vector %02x\n", irq);
index 1cc185da9d38265aec129a0363941c630e47dfb1..c129ab2ac731c989503e0b61ee338332105a85f9 100644 (file)
@@ -63,9 +63,10 @@ enum zpci_state {
 };
 
 struct zpci_bar_struct {
+       struct resource *res;           /* bus resource */
        u32             val;            /* bar start & 3 flag bits */
-       u8              size;           /* order 2 exponent */
        u16             map_idx;        /* index into bar mapping array */
+       u8              size;           /* order 2 exponent */
 };
 
 /* Private data per function */
@@ -97,6 +98,7 @@ struct zpci_dev {
        unsigned long   iommu_pages;
        unsigned int    next_bit;
 
+       char res_name[16];
        struct zpci_bar_struct bars[PCI_BAR_COUNT];
 
        u64             start_dma;      /* Start of available DMA addresses */
@@ -122,12 +124,10 @@ static inline bool zdev_enabled(struct zpci_dev *zdev)
   Prototypes
 ----------------------------------------------------------------------------- */
 /* Base stuff */
-struct zpci_dev *zpci_alloc_device(void);
 int zpci_create_device(struct zpci_dev *);
 int zpci_enable_device(struct zpci_dev *);
 int zpci_disable_device(struct zpci_dev *);
 void zpci_stop_device(struct zpci_dev *);
-void zpci_free_device(struct zpci_dev *);
 int zpci_register_ioat(struct zpci_dev *, u8, u64, u64, u64);
 int zpci_unregister_ioat(struct zpci_dev *, u8);
 
index 7dc7f9c63b65f35f62de8566de198c97333acef6..30ef748bc161eb3a7f52084ea763d54fe6ed09fc 100644 (file)
@@ -43,7 +43,6 @@ struct sclp_cpu_info {
 int sclp_get_cpu_info(struct sclp_cpu_info *info);
 int sclp_cpu_configure(u8 cpu);
 int sclp_cpu_deconfigure(u8 cpu);
-void sclp_facilities_detect(void);
 unsigned long long sclp_get_rnmax(void);
 unsigned long long sclp_get_rzm(void);
 int sclp_sdias_blk_count(void);
@@ -57,5 +56,7 @@ bool sclp_has_vt220(void);
 int sclp_pci_configure(u32 fid);
 int sclp_pci_deconfigure(u32 fid);
 int memcpy_hsa(void *dest, unsigned long src, size_t count, int mode);
+unsigned long sclp_get_hsa_size(void);
+void sclp_early_detect(void);
 
 #endif /* _ASM_S390_SCLP_H */
index df802ee14af6f76591cebdc54030488b42c3d0cc..94cfbe442f124cc720f2436c7e3c34d485cf0139 100644 (file)
@@ -107,9 +107,6 @@ void create_mem_hole(struct mem_chunk mem_chunk[], unsigned long addr,
 #define MACHINE_HAS_RRBM       (S390_lowcore.machine_flags & MACHINE_FLAG_RRBM)
 #endif /* CONFIG_64BIT */
 
-#define ZFCPDUMP_HSA_SIZE      (32UL<<20)
-#define ZFCPDUMP_HSA_SIZE_MAX  (64UL<<20)
-
 /*
  * Console mode. Override with conmode=
  */
index eb5f64d26d06190de4695d38e9190449859588df..10e0fcd3633d178f25b299a709b9c80706f05818 100644 (file)
@@ -111,6 +111,4 @@ static inline struct thread_info *current_thread_info(void)
 #define is_32bit_task()                (1)
 #endif
 
-#define PREEMPT_ACTIVE         0x4000000
-
 #endif /* _ASM_THREAD_INFO_H */
index f45b2ab0cb81ae425ce2d72c2de9b6fa4fa241a3..d7658c4b2ed5817c75cd6a90c91b3a1b93738809 100644 (file)
@@ -95,7 +95,7 @@ static void *elfcorehdr_newmem;
 /*
  * Copy one page from zfcpdump "oldmem"
  *
- * For pages below ZFCPDUMP_HSA_SIZE memory from the HSA is copied. Otherwise
+ * For pages below HSA size memory from the HSA is copied. Otherwise
  * real memory copy is used.
  */
 static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize,
@@ -103,7 +103,7 @@ static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize,
 {
        int rc;
 
-       if (src < ZFCPDUMP_HSA_SIZE) {
+       if (src < sclp_get_hsa_size()) {
                rc = memcpy_hsa(buf, src, csize, userbuf);
        } else {
                if (userbuf)
@@ -188,18 +188,19 @@ static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma,
 /*
  * Remap "oldmem" for zfcpdump
  *
- * We only map available memory above ZFCPDUMP_HSA_SIZE. Memory below
- * ZFCPDUMP_HSA_SIZE is read on demand using the copy_oldmem_page() function.
+ * We only map available memory above HSA size. Memory below HSA size
+ * is read on demand using the copy_oldmem_page() function.
  */
 static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma,
                                           unsigned long from,
                                           unsigned long pfn,
                                           unsigned long size, pgprot_t prot)
 {
+       unsigned long hsa_end = sclp_get_hsa_size();
        unsigned long size_hsa;
 
-       if (pfn < ZFCPDUMP_HSA_SIZE >> PAGE_SHIFT) {
-               size_hsa = min(size, ZFCPDUMP_HSA_SIZE - (pfn << PAGE_SHIFT));
+       if (pfn < hsa_end >> PAGE_SHIFT) {
+               size_hsa = min(size, hsa_end - (pfn << PAGE_SHIFT));
                if (size == size_hsa)
                        return 0;
                size -= size_hsa;
@@ -238,9 +239,9 @@ int copy_from_oldmem(void *dest, void *src, size_t count)
                                return rc;
                }
        } else {
-               if ((unsigned long) src < ZFCPDUMP_HSA_SIZE) {
-                       copied = min(count,
-                                    ZFCPDUMP_HSA_SIZE - (unsigned long) src);
+               unsigned long hsa_end = sclp_get_hsa_size();
+               if ((unsigned long) src < hsa_end) {
+                       copied = min(count, hsa_end - (unsigned long) src);
                        rc = memcpy_hsa(dest, (unsigned long) src, copied, 0);
                        if (rc)
                                return rc;
@@ -580,6 +581,9 @@ int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
        /* If elfcorehdr= has been passed via cmdline, we use that one */
        if (elfcorehdr_addr != ELFCORE_ADDR_MAX)
                return 0;
+       /* If we cannot get HSA size for zfcpdump return error */
+       if (ipl_info.type == IPL_TYPE_FCP_DUMP && !sclp_get_hsa_size())
+               return -ENODEV;
        mem_chunk_cnt = get_mem_chunk_cnt();
 
        alloc_size = 0x1000 + get_cpu_cnt() * 0x300 +
index 96543ac400a7820ede40f22bf9636753920456b7..fca20b5fe79e085e4795861edf7f4bb5736c67cb 100644 (file)
@@ -483,7 +483,7 @@ void __init startup_init(void)
        detect_diag44();
        detect_machine_facilities();
        setup_topology();
-       sclp_facilities_detect();
+       sclp_early_detect();
 #ifdef CONFIG_DYNAMIC_FTRACE
        S390_lowcore.ftrace_func = (unsigned long)ftrace_caller;
 #endif
index 59a9c35c4598ae3265c60f69f8f87ca0a1538c2d..bc71a7b95af546b94d6ac6ba74c6484bbb261069 100644 (file)
@@ -680,7 +680,7 @@ static int __kprobes kprobe_trap_handler(struct pt_regs *regs, int trapnr)
        case KPROBE_HIT_SSDONE:
                /*
                 * We increment the nmissed count for accounting,
-                * we can also use npre/npostfault count for accouting
+                * we can also use npre/npostfault count for accounting
                 * these specific fault cases.
                 */
                kprobes_inc_nmissed_count(p);
index ffe1c53264a708352622d0159f437f1e176d2a75..4444875266ee028bdcc4d43604a4dea591a1a47c 100644 (file)
@@ -471,8 +471,9 @@ static void __init setup_memory_end(void)
 
 
 #ifdef CONFIG_ZFCPDUMP
-       if (ipl_info.type == IPL_TYPE_FCP_DUMP && !OLDMEM_BASE) {
-               memory_end = ZFCPDUMP_HSA_SIZE;
+       if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
+           !OLDMEM_BASE && sclp_get_hsa_size()) {
+               memory_end = sclp_get_hsa_size();
                memory_end_set = 1;
        }
 #endif
@@ -586,7 +587,7 @@ static unsigned long __init find_crash_base(unsigned long crash_size,
                crash_base = (chunk->addr + chunk->size) - crash_size;
                if (crash_base < crash_size)
                        continue;
-               if (crash_base < ZFCPDUMP_HSA_SIZE_MAX)
+               if (crash_base < sclp_get_hsa_size())
                        continue;
                if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
                        continue;
index 0c9a17780e4b9be96288a75a356444761f0085d5..bf7c73d71eef1ee46ee9bcec9516be70fcc2dc27 100644 (file)
@@ -530,20 +530,6 @@ static void zpci_unmap_resources(struct zpci_dev *zdev)
        }
 }
 
-struct zpci_dev *zpci_alloc_device(void)
-{
-       struct zpci_dev *zdev;
-
-       /* Alloc memory for our private pci device data */
-       zdev = kzalloc(sizeof(*zdev), GFP_KERNEL);
-       return zdev ? : ERR_PTR(-ENOMEM);
-}
-
-void zpci_free_device(struct zpci_dev *zdev)
-{
-       kfree(zdev);
-}
-
 int pcibios_add_platform_entries(struct pci_dev *pdev)
 {
        return zpci_sysfs_add_device(&pdev->dev);
@@ -579,37 +565,6 @@ static void zpci_irq_exit(void)
        unregister_adapter_interrupt(&zpci_airq);
 }
 
-static struct resource *zpci_alloc_bus_resource(unsigned long start, unsigned long size,
-                                               unsigned long flags, int domain)
-{
-       struct resource *r;
-       char *name;
-       int rc;
-
-       r = kzalloc(sizeof(*r), GFP_KERNEL);
-       if (!r)
-               return ERR_PTR(-ENOMEM);
-       r->start = start;
-       r->end = r->start + size - 1;
-       r->flags = flags;
-       r->parent = &iomem_resource;
-       name = kmalloc(18, GFP_KERNEL);
-       if (!name) {
-               kfree(r);
-               return ERR_PTR(-ENOMEM);
-       }
-       sprintf(name, "PCI Bus: %04x:%02x", domain, ZPCI_BUS_NR);
-       r->name = name;
-
-       rc = request_resource(&iomem_resource, r);
-       if (rc) {
-               kfree(r->name);
-               kfree(r);
-               return ERR_PTR(-ENOMEM);
-       }
-       return r;
-}
-
 static int zpci_alloc_iomap(struct zpci_dev *zdev)
 {
        int entry;
@@ -633,6 +588,82 @@ static void zpci_free_iomap(struct zpci_dev *zdev, int entry)
        spin_unlock(&zpci_iomap_lock);
 }
 
+static struct resource *__alloc_res(struct zpci_dev *zdev, unsigned long start,
+                                   unsigned long size, unsigned long flags)
+{
+       struct resource *r;
+
+       r = kzalloc(sizeof(*r), GFP_KERNEL);
+       if (!r)
+               return NULL;
+
+       r->start = start;
+       r->end = r->start + size - 1;
+       r->flags = flags;
+       r->name = zdev->res_name;
+
+       if (request_resource(&iomem_resource, r)) {
+               kfree(r);
+               return NULL;
+       }
+       return r;
+}
+
+static int zpci_setup_bus_resources(struct zpci_dev *zdev,
+                                   struct list_head *resources)
+{
+       unsigned long addr, size, flags;
+       struct resource *res;
+       int i, entry;
+
+       snprintf(zdev->res_name, sizeof(zdev->res_name),
+                "PCI Bus %04x:%02x", zdev->domain, ZPCI_BUS_NR);
+
+       for (i = 0; i < PCI_BAR_COUNT; i++) {
+               if (!zdev->bars[i].size)
+                       continue;
+               entry = zpci_alloc_iomap(zdev);
+               if (entry < 0)
+                       return entry;
+               zdev->bars[i].map_idx = entry;
+
+               /* only MMIO is supported */
+               flags = IORESOURCE_MEM;
+               if (zdev->bars[i].val & 8)
+                       flags |= IORESOURCE_PREFETCH;
+               if (zdev->bars[i].val & 4)
+                       flags |= IORESOURCE_MEM_64;
+
+               addr = ZPCI_IOMAP_ADDR_BASE + ((u64) entry << 48);
+
+               size = 1UL << zdev->bars[i].size;
+
+               res = __alloc_res(zdev, addr, size, flags);
+               if (!res) {
+                       zpci_free_iomap(zdev, entry);
+                       return -ENOMEM;
+               }
+               zdev->bars[i].res = res;
+               pci_add_resource(resources, res);
+       }
+
+       return 0;
+}
+
+static void zpci_cleanup_bus_resources(struct zpci_dev *zdev)
+{
+       int i;
+
+       for (i = 0; i < PCI_BAR_COUNT; i++) {
+               if (!zdev->bars[i].size)
+                       continue;
+
+               zpci_free_iomap(zdev, zdev->bars[i].map_idx);
+               release_resource(zdev->bars[i].res);
+               kfree(zdev->bars[i].res);
+       }
+}
+
 int pcibios_add_device(struct pci_dev *pdev)
 {
        struct zpci_dev *zdev = get_zdev(pdev);
@@ -729,52 +760,6 @@ struct dev_pm_ops pcibios_pm_ops = {
 };
 #endif /* CONFIG_HIBERNATE_CALLBACKS */
 
-static int zpci_scan_bus(struct zpci_dev *zdev)
-{
-       struct resource *res;
-       LIST_HEAD(resources);
-       int i;
-
-       /* allocate mapping entry for each used bar */
-       for (i = 0; i < PCI_BAR_COUNT; i++) {
-               unsigned long addr, size, flags;
-               int entry;
-
-               if (!zdev->bars[i].size)
-                       continue;
-               entry = zpci_alloc_iomap(zdev);
-               if (entry < 0)
-                       return entry;
-               zdev->bars[i].map_idx = entry;
-
-               /* only MMIO is supported */
-               flags = IORESOURCE_MEM;
-               if (zdev->bars[i].val & 8)
-                       flags |= IORESOURCE_PREFETCH;
-               if (zdev->bars[i].val & 4)
-                       flags |= IORESOURCE_MEM_64;
-
-               addr = ZPCI_IOMAP_ADDR_BASE + ((u64) entry << 48);
-
-               size = 1UL << zdev->bars[i].size;
-
-               res = zpci_alloc_bus_resource(addr, size, flags, zdev->domain);
-               if (IS_ERR(res)) {
-                       zpci_free_iomap(zdev, entry);
-                       return PTR_ERR(res);
-               }
-               pci_add_resource(&resources, res);
-       }
-
-       zdev->bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops,
-                                     zdev, &resources);
-       if (!zdev->bus)
-               return -EIO;
-
-       zdev->bus->max_bus_speed = zdev->max_bus_speed;
-       return 0;
-}
-
 static int zpci_alloc_domain(struct zpci_dev *zdev)
 {
        spin_lock(&zpci_domain_lock);
@@ -795,6 +780,41 @@ static void zpci_free_domain(struct zpci_dev *zdev)
        spin_unlock(&zpci_domain_lock);
 }
 
+void pcibios_remove_bus(struct pci_bus *bus)
+{
+       struct zpci_dev *zdev = get_zdev_by_bus(bus);
+
+       zpci_exit_slot(zdev);
+       zpci_cleanup_bus_resources(zdev);
+       zpci_free_domain(zdev);
+
+       spin_lock(&zpci_list_lock);
+       list_del(&zdev->entry);
+       spin_unlock(&zpci_list_lock);
+
+       kfree(zdev);
+}
+
+static int zpci_scan_bus(struct zpci_dev *zdev)
+{
+       LIST_HEAD(resources);
+       int ret;
+
+       ret = zpci_setup_bus_resources(zdev, &resources);
+       if (ret)
+               return ret;
+
+       zdev->bus = pci_scan_root_bus(NULL, ZPCI_BUS_NR, &pci_root_ops,
+                                     zdev, &resources);
+       if (!zdev->bus) {
+               zpci_cleanup_bus_resources(zdev);
+               return -EIO;
+       }
+
+       zdev->bus->max_bus_speed = zdev->max_bus_speed;
+       return 0;
+}
+
 int zpci_enable_device(struct zpci_dev *zdev)
 {
        int rc;
index 84147984224a996fca36b72d3aff574df229f1c8..c747394029eec181dbe521775296c701e9054a62 100644 (file)
@@ -155,9 +155,9 @@ int clp_add_pci_device(u32 fid, u32 fh, int configured)
        int rc;
 
        zpci_dbg(3, "add fid:%x, fh:%x, c:%d\n", fid, fh, configured);
-       zdev = zpci_alloc_device();
-       if (IS_ERR(zdev))
-               return PTR_ERR(zdev);
+       zdev = kzalloc(sizeof(*zdev), GFP_KERNEL);
+       if (!zdev)
+               return -ENOMEM;
 
        zdev->fh = fh;
        zdev->fid = fid;
@@ -178,7 +178,7 @@ int clp_add_pci_device(u32 fid, u32 fh, int configured)
        return 0;
 
 error:
-       zpci_free_device(zdev);
+       kfree(zdev);
        return rc;
 }
 
index 278e671ec9ac22b977c0598aaa31552d3e32b567..800f064b0da7c9a32c3910ecefdfb3e6979d7f9b 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <asm/pci_debug.h>
+#include <asm/sclp.h>
 
 /* Content Code Description for PCI Function Error */
 struct zpci_ccdf_err {
@@ -42,10 +43,27 @@ struct zpci_ccdf_avail {
        u16 pec;                        /* PCI event code */
 } __packed;
 
-static void zpci_event_log_avail(struct zpci_ccdf_avail *ccdf)
+void zpci_event_error(void *data)
 {
+       struct zpci_ccdf_err *ccdf = data;
+       struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
+
+       zpci_err("error CCDF:\n");
+       zpci_err_hex(ccdf, sizeof(*ccdf));
+
+       if (!zdev)
+               return;
+
+       pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
+              pci_name(zdev->pdev), ccdf->pec, ccdf->fid);
+}
+
+void zpci_event_availability(void *data)
+{
+       struct zpci_ccdf_avail *ccdf = data;
        struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
        struct pci_dev *pdev = zdev ? zdev->pdev : NULL;
+       int ret;
 
        pr_info("%s: Event 0x%x reconfigured PCI function 0x%x\n",
                pdev ? pci_name(pdev) : "n/a", ccdf->pec, ccdf->fid);
@@ -53,36 +71,47 @@ static void zpci_event_log_avail(struct zpci_ccdf_avail *ccdf)
        zpci_err_hex(ccdf, sizeof(*ccdf));
 
        switch (ccdf->pec) {
-       case 0x0301:
-               zpci_enable_device(zdev);
+       case 0x0301: /* Standby -> Configured */
+               if (!zdev || zdev->state == ZPCI_FN_STATE_CONFIGURED)
+                       break;
+               zdev->state = ZPCI_FN_STATE_CONFIGURED;
+               ret = zpci_enable_device(zdev);
+               if (ret)
+                       break;
+               pci_rescan_bus(zdev->bus);
                break;
-       case 0x0302:
+       case 0x0302: /* Reserved -> Standby */
                clp_add_pci_device(ccdf->fid, ccdf->fh, 0);
                break;
-       case 0x0306:
+       case 0x0303: /* Deconfiguration requested */
+               if (pdev)
+                       pci_stop_and_remove_bus_device(pdev);
+
+               ret = zpci_disable_device(zdev);
+               if (ret)
+                       break;
+
+               ret = sclp_pci_deconfigure(zdev->fid);
+               zpci_dbg(3, "deconf fid:%x, rc:%d\n", zdev->fid, ret);
+               if (!ret)
+                       zdev->state = ZPCI_FN_STATE_STANDBY;
+
+               break;
+       case 0x0304: /* Configured -> Standby */
+               if (pdev)
+                       pci_stop_and_remove_bus_device(pdev);
+
+               zpci_disable_device(zdev);
+               zdev->state = ZPCI_FN_STATE_STANDBY;
+               break;
+       case 0x0306: /* 0x308 or 0x302 for multiple devices */
                clp_rescan_pci_devices();
                break;
+       case 0x0308: /* Standby -> Reserved */
+               pci_stop_root_bus(zdev->bus);
+               pci_remove_root_bus(zdev->bus);
+               break;
        default:
                break;
        }
 }
-
-void zpci_event_error(void *data)
-{
-       struct zpci_ccdf_err *ccdf = data;
-       struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
-
-       zpci_err("error CCDF:\n");
-       zpci_err_hex(ccdf, sizeof(*ccdf));
-
-       if (!zdev)
-               return;
-
-       pr_err("%s: Event 0x%x reports an error for PCI function 0x%x\n",
-              pci_name(zdev->pdev), ccdf->pec, ccdf->fid);
-}
-
-void zpci_event_availability(void *data)
-{
-       zpci_event_log_avail(data);
-}
index 1425cc034872e5993320e6722f4965bdb34f1189..656b7ada9326ab63ba45b42f3404cc39979e16f5 100644 (file)
@@ -72,8 +72,6 @@ register struct thread_info *__current_thread_info __asm__("r28");
 
 #endif /* !__ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * thread information flags
  * - these are process state flags that various assembly files may need to
index e78561bc30ef2bc746d0ed9b12d5a163059c493e..9b0979f4df7a5331cdc07ea468c4e0a033510d53 100644 (file)
@@ -1,5 +1,6 @@
 config SUPERH
        def_bool y
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select EXPERT
        select CLKDEV_LOOKUP
        select HAVE_IDE if HAS_IOPORT
index 1fa8be4097715360363c41f21043d184f68517fa..122f737a901fbad4e22de06652e6eb9b04abdfc8 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/mmc/sh_mmcif.h>
 #include <linux/mmc/sh_mobile_sdhi.h>
 #include <linux/mtd/physmap.h>
+#include <linux/mfd/tmio.h>
 #include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
index 21c5088788dae27eb8c98449f22e6cdf9f464bb4..b9d9489a50125b8d732299cf707b009a37617927 100644 (file)
@@ -81,7 +81,7 @@ static inline void get_mmu_context(struct mm_struct *mm, unsigned int cpu)
 
                /*
                 * Fix version; Note that we avoid version #0
-                * to distingush NO_CONTEXT.
+                * to distinguish NO_CONTEXT.
                 */
                if (!asid)
                        asid = MMU_CONTEXT_FIRST_VERSION;
index 45a93669289da4d7ff53119d9d3ea69158fced7e..ad27ffa65e2eafd2fb89c959c812862b70ba8665 100644 (file)
@@ -41,8 +41,6 @@ struct thread_info {
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 #if defined(CONFIG_4KSTACKS)
 #define THREAD_SHIFT   12
 #else
index 9b6e4beeb296261c2fb5b315377822e236c587cf..ca46834294b7fa9fbf7f99eb0958ae1c18af6df7 100644 (file)
@@ -108,7 +108,7 @@ need_resched:
        and     #(0xf0>>1), r0          ! interrupts off (exception path)?
        cmp/eq  #(0xf0>>1), r0
        bt      noresched
-       mov.l   3f, r0
+       mov.l   1f, r0
        jsr     @r0                     ! call preempt_schedule_irq
         nop
        bra     need_resched
@@ -119,9 +119,7 @@ noresched:
         nop
 
        .align 2
-1:     .long   PREEMPT_ACTIVE
-2:     .long   schedule
-3:     .long   preempt_schedule_irq
+1:     .long   preempt_schedule_irq
 #endif
 
 ENTRY(resume_userspace)
index 05fcfc634fcb092fd10cc7b411fd51f98f90a67e..d4f7a6a163dc26869160ed74017434f106909a4d 100644 (file)
@@ -12,6 +12,7 @@ config 64BIT
 config SPARC
        bool
        default y
+       select ARCH_MIGHT_HAVE_PC_PARPORT if SPARC64 && PCI
        select OF
        select OF_PROMTREE
        select HAVE_IDE
index 162007643cdcb94faac5ceec465c095a2520be51..ee93923b7f8252d8727515c5b1e0e57132bf6484 100644 (file)
@@ -7,7 +7,6 @@
 #ifndef __SPARC_HARDIRQ_H
 #define __SPARC_HARDIRQ_H
 
-#define HARDIRQ_BITS    8
 #include <asm-generic/hardirq.h>
 
 #endif /* __SPARC_HARDIRQ_H */
index 7c29fd1a87aa4289e78bb7297a4ce41c133cce63..f478ff1ddd028733fe735bcf619e77b8f02803ee 100644 (file)
@@ -14,6 +14,4 @@
 
 void ack_bad_irq(unsigned int irq);
 
-#define HARDIRQ_BITS   8
-
 #endif /* !(__SPARC64_HARDIRQ_H) */
index dd3807599bb9ac63573191e1086e506699e5d41a..96efa7adc22330d2684e67ab3c83dafa99e89e8a 100644 (file)
@@ -105,8 +105,6 @@ register struct thread_info *current_thread_info_reg asm("g6");
 #define TI_W_SAVED     0x250
 /* #define TI_RESTART_BLOCK 0x25n */ /* Nobody cares */
 
-#define PREEMPT_ACTIVE         0x4000000
-
 /*
  * thread information flag bit numbers
  */
index 5d9292ab10777bdae90bb8e61eb4d109090f8d15..a5f01ac6d0f1a2619cdac6b639248cb5a7153dac 100644 (file)
@@ -111,8 +111,6 @@ struct thread_info {
 #define THREAD_SHIFT PAGE_SHIFT
 #endif /* PAGE_SHIFT == 13 */
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * macros/functions for gaining access to the thread information structure
  */
index f0d6a9700f4c8351e20be4743d9782c590b9e016..3c3c89f52643e9ade6ce6b508b5be41915179102 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef _SPARC64_TLBFLUSH_H
 #define _SPARC64_TLBFLUSH_H
 
-#include <linux/mm.h>
 #include <asm/mmu_context.h>
 
 /* TSB flush operations. */
index 5a09fd315e5f5d558a4af17a3e43ac0b29954135..1b0973503197508404967e8bb0ed58cc934b982e 100644 (file)
@@ -350,7 +350,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
        case KPROBE_HIT_SSDONE:
                /*
                 * We increment the nmissed count for accounting,
-                * we can also use npre/npostfault count for accouting
+                * we can also use npre/npostfault count for accounting
                 * these specific fault cases.
                 */
                kprobes_inc_nmissed_count(cur);
index a954eb81881bf37d45fd01b22dc1e42839318f40..39f0c662f4c81dcdf3050926a5a9525d352933a3 100644 (file)
@@ -312,12 +312,10 @@ to_kernel:
                 nop
                cmp                     %l4, 0
                bne,pn                  %xcc, kern_fpucheck
-                sethi                  %hi(PREEMPT_ACTIVE), %l6
-               stw                     %l6, [%g6 + TI_PRE_COUNT]
-               call                    schedule
+                nop
+               call                    preempt_schedule_irq
                 nop
                ba,pt                   %xcc, rtrap
-                stw                    %g0, [%g6 + TI_PRE_COUNT]
 #endif
 kern_fpucheck: ldub                    [%g6 + TI_FPDEPTH], %l5
                brz,pt                  %l5, rt_continue
index 6b643790e4fe016105b9525c5ae77d07c5f20512..5322e530d09cf9cbbb459198a1613997c5bf9964 100644 (file)
@@ -2565,8 +2565,6 @@ pgtable_t pte_alloc_one(struct mm_struct *mm,
 {
        struct page *page = alloc_page(GFP_KERNEL | __GFP_NOTRACK |
                                       __GFP_REPEAT | __GFP_ZERO);
-       pte_t *pte = NULL;
-
        if (!page)
                return NULL;
        if (!pgtable_page_ctor(page)) {
index 822390f9a154a620768004d76124d9b7f266add1..54110af23985ab7a395d22d659c80e1ddc93f748 100644 (file)
@@ -42,6 +42,4 @@ DECLARE_PER_CPU(irq_cpustat_t, irq_stat);
 
 #include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
 
-#define HARDIRQ_BITS   8
-
 #endif /* _ASM_TILE_HARDIRQ_H */
index b8aa6df3e102d0cf7a2dd7ba7e4f8e9309e983d6..729aa107f64e6391cb435ff1f5c038065eafe3b2 100644 (file)
@@ -113,8 +113,6 @@ extern void _cpu_idle(void);
 
 #endif /* !__ASSEMBLY__ */
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * Thread information flags that various assembly files may need to access.
  * Keep flags accessed frequently in low bits, particular since it makes
index b9d7c4276682f3b20434c596f4ef457e300b90af..f10738d68b2d67eef3448258abb1d2b5024ee532 100644 (file)
@@ -6,10 +6,6 @@ config STDERR_CONSOLE
        help
          console driver which dumps all printk messages to stderr.
 
-config STDIO_CONSOLE
-       bool
-       default y
-
 config SSL
        bool "Virtual serial line"
        help
index 8ddea1f8006a5a0732a3550ff6a5883aabd7fdec..21ca44c4f6d58b1a845dfba592cbc704649bc1e3 100644 (file)
@@ -1,8 +1,3 @@
-config DEFCONFIG_LIST
-       string
-       option defconfig_list
-       default "arch/$ARCH/defconfig"
-
 config UML
        bool
        default y
index 133f7de2a13d5ade42c217c56c74604ae6a39a58..48d92bbe62e9eae2460df5fb99bdd83974b9aecb 100644 (file)
@@ -6,6 +6,17 @@
 # Licensed under the GPL
 #
 
+# select defconfig based on actual architecture
+ifeq ($(SUBARCH),x86)
+  ifeq ($(shell uname -m),x86_64)
+        KBUILD_DEFCONFIG := x86_64_defconfig
+  else
+        KBUILD_DEFCONFIG := i386_defconfig
+  endif
+else
+        KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
+endif
+
 ARCH_DIR := arch/um
 OS := $(shell uname -s)
 # We require bash because the vmlinux link and loader script cpp use bash
diff --git a/arch/um/configs/i386_defconfig b/arch/um/configs/i386_defconfig
new file mode 100644 (file)
index 0000000..a12bf68
--- /dev/null
@@ -0,0 +1,76 @@
+CONFIG_3_LEVEL_PGTABLES=y
+# CONFIG_COMPACTION is not set
+CONFIG_BINFMT_MISC=m
+CONFIG_HOSTFS=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_KERNEL_STACK_ORDER=1
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_CGROUPS=y
+CONFIG_CGROUP_FREEZER=y
+CONFIG_CGROUP_DEVICE=y
+CONFIG_CPUSETS=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_RESOURCE_COUNTERS=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_BLK_CGROUP=y
+# CONFIG_PID_NS is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SLAB=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_IOSCHED_CFQ=m
+CONFIG_SSL=y
+CONFIG_NULL_CHAN=y
+CONFIG_PORT_CHAN=y
+CONFIG_PTY_CHAN=y
+CONFIG_TTY_CHAN=y
+CONFIG_XTERM_CHAN=y
+CONFIG_CON_CHAN="pts"
+CONFIG_SSL_CHAN="pts"
+CONFIG_UML_SOUND=m
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_BLK_DEV_UBD=y
+CONFIG_BLK_DEV_LOOP=m
+CONFIG_BLK_DEV_NBD=m
+CONFIG_DUMMY=m
+CONFIG_TUN=m
+CONFIG_PPP=m
+CONFIG_SLIP=m
+CONFIG_LEGACY_PTY_COUNT=32
+# CONFIG_HW_RANDOM is not set
+CONFIG_UML_RANDOM=y
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+# CONFIG_INET_LRO is not set
+# CONFIG_IPV6 is not set
+CONFIG_UML_NET=y
+CONFIG_UML_NET_ETHERTAP=y
+CONFIG_UML_NET_TUNTAP=y
+CONFIG_UML_NET_SLIP=y
+CONFIG_UML_NET_DAEMON=y
+CONFIG_UML_NET_MCAST=y
+CONFIG_UML_NET_SLIRP=y
+CONFIG_EXT4_FS=y
+CONFIG_REISERFS_FS=y
+CONFIG_QUOTA=y
+CONFIG_AUTOFS4_FS=m
+CONFIG_ISO9660_FS=m
+CONFIG_JOLIET=y
+CONFIG_PROC_KCORE=y
+CONFIG_TMPFS=y
+CONFIG_NLS=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_KERNEL=y
diff --git a/arch/um/configs/x86_64_defconfig b/arch/um/configs/x86_64_defconfig
new file mode 100644 (file)
index 0000000..3aab117
--- /dev/null
@@ -0,0 +1,75 @@
+# CONFIG_COMPACTION is not set
+CONFIG_BINFMT_MISC=m
+CONFIG_HOSTFS=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_CGROUPS=y
+CONFIG_CGROUP_FREEZER=y
+CONFIG_CGROUP_DEVICE=y
+CONFIG_CPUSETS=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_RESOURCE_COUNTERS=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_BLK_CGROUP=y
+# CONFIG_PID_NS is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SLAB=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_IOSCHED_CFQ=m
+CONFIG_SSL=y
+CONFIG_NULL_CHAN=y
+CONFIG_PORT_CHAN=y
+CONFIG_PTY_CHAN=y
+CONFIG_TTY_CHAN=y
+CONFIG_XTERM_CHAN=y
+CONFIG_CON_CHAN="pts"
+CONFIG_SSL_CHAN="pts"
+CONFIG_UML_SOUND=m
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_BLK_DEV_UBD=y
+CONFIG_BLK_DEV_LOOP=m
+CONFIG_BLK_DEV_NBD=m
+CONFIG_DUMMY=m
+CONFIG_TUN=m
+CONFIG_PPP=m
+CONFIG_SLIP=m
+CONFIG_LEGACY_PTY_COUNT=32
+# CONFIG_HW_RANDOM is not set
+CONFIG_UML_RANDOM=y
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
+# CONFIG_INET_LRO is not set
+# CONFIG_IPV6 is not set
+CONFIG_UML_NET=y
+CONFIG_UML_NET_ETHERTAP=y
+CONFIG_UML_NET_TUNTAP=y
+CONFIG_UML_NET_SLIP=y
+CONFIG_UML_NET_DAEMON=y
+CONFIG_UML_NET_MCAST=y
+CONFIG_UML_NET_SLIRP=y
+CONFIG_EXT4_FS=y
+CONFIG_REISERFS_FS=y
+CONFIG_QUOTA=y
+CONFIG_AUTOFS4_FS=m
+CONFIG_ISO9660_FS=m
+CONFIG_JOLIET=y
+CONFIG_PROC_KCORE=y
+CONFIG_TMPFS=y
+CONFIG_NLS=y
+CONFIG_DEBUG_INFO=y
+CONFIG_FRAME_WARN=1024
+CONFIG_DEBUG_KERNEL=y
diff --git a/arch/um/defconfig b/arch/um/defconfig
deleted file mode 100644 (file)
index 2665e6b..0000000
+++ /dev/null
@@ -1,899 +0,0 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# User Mode Linux/i386 3.3.0 Kernel Configuration
-#
-CONFIG_DEFCONFIG_LIST="arch/$ARCH/defconfig"
-CONFIG_UML=y
-CONFIG_MMU=y
-CONFIG_NO_IOMEM=y
-# CONFIG_TRACE_IRQFLAGS_SUPPORT is not set
-CONFIG_LOCKDEP_SUPPORT=y
-# CONFIG_STACKTRACE_SUPPORT is not set
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_GENERIC_BUG=y
-CONFIG_GENERIC_CLOCKEVENTS=y
-CONFIG_HZ=100
-
-#
-# UML-specific options
-#
-
-#
-# Host processor type and features
-#
-# CONFIG_M486 is not set
-# CONFIG_M586 is not set
-# CONFIG_M586TSC is not set
-# CONFIG_M586MMX is not set
-CONFIG_M686=y
-# CONFIG_MPENTIUMII is not set
-# CONFIG_MPENTIUMIII is not set
-# CONFIG_MPENTIUMM is not set
-# CONFIG_MPENTIUM4 is not set
-# CONFIG_MK6 is not set
-# CONFIG_MK7 is not set
-# CONFIG_MK8 is not set
-# CONFIG_MCRUSOE is not set
-# CONFIG_MEFFICEON is not set
-# CONFIG_MWINCHIPC6 is not set
-# CONFIG_MWINCHIP3D is not set
-# CONFIG_MELAN is not set
-# CONFIG_MGEODEGX1 is not set
-# CONFIG_MGEODE_LX is not set
-# CONFIG_MCYRIXIII is not set
-# CONFIG_MVIAC3_2 is not set
-# CONFIG_MVIAC7 is not set
-# CONFIG_MCORE2 is not set
-# CONFIG_MATOM is not set
-# CONFIG_X86_GENERIC is not set
-CONFIG_X86_INTERNODE_CACHE_SHIFT=5
-CONFIG_X86_CMPXCHG=y
-CONFIG_X86_L1_CACHE_SHIFT=5
-CONFIG_X86_XADD=y
-CONFIG_X86_PPRO_FENCE=y
-CONFIG_X86_WP_WORKS_OK=y
-CONFIG_X86_INVLPG=y
-CONFIG_X86_BSWAP=y
-CONFIG_X86_POPAD_OK=y
-CONFIG_X86_USE_PPRO_CHECKSUM=y
-CONFIG_X86_TSC=y
-CONFIG_X86_CMPXCHG64=y
-CONFIG_X86_CMOV=y
-CONFIG_X86_MINIMUM_CPU_FAMILY=5
-CONFIG_CPU_SUP_INTEL=y
-CONFIG_CPU_SUP_CYRIX_32=y
-CONFIG_CPU_SUP_AMD=y
-CONFIG_CPU_SUP_CENTAUR=y
-CONFIG_CPU_SUP_TRANSMETA_32=y
-CONFIG_CPU_SUP_UMC_32=y
-CONFIG_UML_X86=y
-# CONFIG_64BIT is not set
-CONFIG_X86_32=y
-# CONFIG_X86_64 is not set
-# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_3_LEVEL_PGTABLES is not set
-CONFIG_ARCH_HAS_SC_SIGNALS=y
-CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA=y
-CONFIG_GENERIC_HWEIGHT=y
-# CONFIG_STATIC_LINK is not set
-CONFIG_SELECT_MEMORY_MODEL=y
-CONFIG_FLATMEM_MANUAL=y
-CONFIG_FLATMEM=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-CONFIG_PAGEFLAGS_EXTENDED=y
-CONFIG_SPLIT_PTLOCK_CPUS=4
-# CONFIG_COMPACTION is not set
-# CONFIG_PHYS_ADDR_T_64BIT is not set
-CONFIG_ZONE_DMA_FLAG=0
-CONFIG_VIRT_TO_BUS=y
-# CONFIG_KSM is not set
-CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
-CONFIG_NEED_PER_CPU_KM=y
-# CONFIG_CLEANCACHE is not set
-CONFIG_TICK_ONESHOT=y
-CONFIG_NO_HZ=y
-CONFIG_HIGH_RES_TIMERS=y
-CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
-CONFIG_LD_SCRIPT_DYN=y
-CONFIG_BINFMT_ELF=y
-CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
-CONFIG_HAVE_AOUT=y
-# CONFIG_BINFMT_AOUT is not set
-CONFIG_BINFMT_MISC=m
-CONFIG_HOSTFS=y
-# CONFIG_HPPFS is not set
-CONFIG_MCONSOLE=y
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_KERNEL_STACK_ORDER=0
-# CONFIG_MMAPPER is not set
-CONFIG_NO_DMA=y
-
-#
-# General setup
-#
-CONFIG_EXPERIMENTAL=y
-CONFIG_BROKEN_ON_SMP=y
-CONFIG_INIT_ENV_ARG_LIMIT=128
-CONFIG_CROSS_COMPILE=""
-CONFIG_LOCALVERSION=""
-CONFIG_LOCALVERSION_AUTO=y
-CONFIG_DEFAULT_HOSTNAME="(none)"
-CONFIG_SWAP=y
-CONFIG_SYSVIPC=y
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_POSIX_MQUEUE=y
-CONFIG_POSIX_MQUEUE_SYSCTL=y
-CONFIG_BSD_PROCESS_ACCT=y
-# CONFIG_BSD_PROCESS_ACCT_V3 is not set
-# CONFIG_FHANDLE is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_AUDIT is not set
-
-#
-# IRQ subsystem
-#
-CONFIG_GENERIC_IRQ_SHOW=y
-
-#
-# RCU Subsystem
-#
-CONFIG_TINY_RCU=y
-# CONFIG_PREEMPT_RCU is not set
-# CONFIG_RCU_TRACE is not set
-# CONFIG_TREE_RCU_TRACE is not set
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_LOG_BUF_SHIFT=14
-CONFIG_CGROUPS=y
-# CONFIG_CGROUP_DEBUG is not set
-CONFIG_CGROUP_FREEZER=y
-CONFIG_CGROUP_DEVICE=y
-CONFIG_CPUSETS=y
-CONFIG_PROC_PID_CPUSET=y
-CONFIG_CGROUP_CPUACCT=y
-CONFIG_RESOURCE_COUNTERS=y
-CONFIG_CGROUP_MEMCG=y
-CONFIG_CGROUP_MEMCG_SWAP=y
-# CONFIG_CGROUP_MEMCG_SWAP_ENABLED is not set
-# CONFIG_CGROUP_MEMCG_KMEM is not set
-CONFIG_CGROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_CFS_BANDWIDTH is not set
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_BLK_CGROUP=y
-# CONFIG_DEBUG_BLK_CGROUP is not set
-# CONFIG_CHECKPOINT_RESTORE is not set
-CONFIG_NAMESPACES=y
-CONFIG_UTS_NS=y
-CONFIG_IPC_NS=y
-# CONFIG_USER_NS is not set
-# CONFIG_PID_NS is not set
-CONFIG_NET_NS=y
-# CONFIG_SCHED_AUTOGROUP is not set
-CONFIG_MM_OWNER=y
-CONFIG_SYSFS_DEPRECATED=y
-# CONFIG_SYSFS_DEPRECATED_V2 is not set
-# CONFIG_RELAY is not set
-# CONFIG_BLK_DEV_INITRD is not set
-CONFIG_CC_OPTIMIZE_FOR_SIZE=y
-CONFIG_SYSCTL=y
-CONFIG_ANON_INODES=y
-# CONFIG_EXPERT is not set
-CONFIG_UID16=y
-# CONFIG_SYSCTL_SYSCALL is not set
-CONFIG_KALLSYMS=y
-# CONFIG_KALLSYMS_ALL is not set
-CONFIG_HOTPLUG=y
-CONFIG_PRINTK=y
-CONFIG_BUG=y
-CONFIG_ELF_CORE=y
-CONFIG_BASE_FULL=y
-CONFIG_FUTEX=y
-CONFIG_EPOLL=y
-CONFIG_SIGNALFD=y
-CONFIG_TIMERFD=y
-CONFIG_EVENTFD=y
-CONFIG_SHMEM=y
-CONFIG_AIO=y
-# CONFIG_EMBEDDED is not set
-
-#
-# Kernel Performance Events And Counters
-#
-CONFIG_VM_EVENT_COUNTERS=y
-CONFIG_COMPAT_BRK=y
-CONFIG_SLAB=y
-# CONFIG_SLUB is not set
-# CONFIG_PROFILING is not set
-
-#
-# GCOV-based kernel profiling
-#
-# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
-CONFIG_SLABINFO=y
-CONFIG_RT_MUTEXES=y
-CONFIG_BASE_SMALL=0
-CONFIG_MODULES=y
-# CONFIG_MODULE_FORCE_LOAD is not set
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_MODULE_FORCE_UNLOAD is not set
-# CONFIG_MODVERSIONS is not set
-# CONFIG_MODULE_SRCVERSION_ALL is not set
-CONFIG_BLOCK=y
-CONFIG_LBDAF=y
-# CONFIG_BLK_DEV_BSG is not set
-# CONFIG_BLK_DEV_BSGLIB is not set
-# CONFIG_BLK_DEV_INTEGRITY is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-
-#
-# IO Schedulers
-#
-CONFIG_IOSCHED_NOOP=y
-CONFIG_IOSCHED_DEADLINE=y
-CONFIG_IOSCHED_CFQ=m
-# CONFIG_CFQ_GROUP_IOSCHED is not set
-CONFIG_DEFAULT_DEADLINE=y
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="deadline"
-# CONFIG_INLINE_SPIN_TRYLOCK is not set
-# CONFIG_INLINE_SPIN_TRYLOCK_BH is not set
-# CONFIG_INLINE_SPIN_LOCK is not set
-# CONFIG_INLINE_SPIN_LOCK_BH is not set
-# CONFIG_INLINE_SPIN_LOCK_IRQ is not set
-# CONFIG_INLINE_SPIN_LOCK_IRQSAVE is not set
-CONFIG_INLINE_SPIN_UNLOCK=y
-# CONFIG_INLINE_SPIN_UNLOCK_BH is not set
-CONFIG_INLINE_SPIN_UNLOCK_IRQ=y
-# CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE is not set
-# CONFIG_INLINE_READ_TRYLOCK is not set
-# CONFIG_INLINE_READ_LOCK is not set
-# CONFIG_INLINE_READ_LOCK_BH is not set
-# CONFIG_INLINE_READ_LOCK_IRQ is not set
-# CONFIG_INLINE_READ_LOCK_IRQSAVE is not set
-CONFIG_INLINE_READ_UNLOCK=y
-# CONFIG_INLINE_READ_UNLOCK_BH is not set
-CONFIG_INLINE_READ_UNLOCK_IRQ=y
-# CONFIG_INLINE_READ_UNLOCK_IRQRESTORE is not set
-# CONFIG_INLINE_WRITE_TRYLOCK is not set
-# CONFIG_INLINE_WRITE_LOCK is not set
-# CONFIG_INLINE_WRITE_LOCK_BH is not set
-# CONFIG_INLINE_WRITE_LOCK_IRQ is not set
-# CONFIG_INLINE_WRITE_LOCK_IRQSAVE is not set
-CONFIG_INLINE_WRITE_UNLOCK=y
-# CONFIG_INLINE_WRITE_UNLOCK_BH is not set
-CONFIG_INLINE_WRITE_UNLOCK_IRQ=y
-# CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE is not set
-# CONFIG_MUTEX_SPIN_ON_OWNER is not set
-CONFIG_FREEZER=y
-
-#
-# UML Character Devices
-#
-CONFIG_STDERR_CONSOLE=y
-CONFIG_STDIO_CONSOLE=y
-CONFIG_SSL=y
-CONFIG_NULL_CHAN=y
-CONFIG_PORT_CHAN=y
-CONFIG_PTY_CHAN=y
-CONFIG_TTY_CHAN=y
-CONFIG_XTERM_CHAN=y
-# CONFIG_NOCONFIG_CHAN is not set
-CONFIG_CON_ZERO_CHAN="fd:0,fd:1"
-CONFIG_CON_CHAN="xterm"
-CONFIG_SSL_CHAN="pts"
-CONFIG_UML_SOUND=m
-CONFIG_SOUND=m
-CONFIG_SOUND_OSS_CORE=y
-CONFIG_HOSTAUDIO=m
-
-#
-# Device Drivers
-#
-
-#
-# Generic Driver Options
-#
-CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
-CONFIG_DEVTMPFS=y
-CONFIG_DEVTMPFS_MOUNT=y
-CONFIG_STANDALONE=y
-CONFIG_PREVENT_FIRMWARE_BUILD=y
-CONFIG_FW_LOADER=y
-CONFIG_FIRMWARE_IN_KERNEL=y
-CONFIG_EXTRA_FIRMWARE=""
-# CONFIG_DEBUG_DRIVER is not set
-# CONFIG_DEBUG_DEVRES is not set
-# CONFIG_SYS_HYPERVISOR is not set
-CONFIG_GENERIC_CPU_DEVICES=y
-# CONFIG_DMA_SHARED_BUFFER is not set
-# CONFIG_CONNECTOR is not set
-# CONFIG_MTD is not set
-CONFIG_BLK_DEV=y
-CONFIG_BLK_DEV_UBD=y
-# CONFIG_BLK_DEV_UBD_SYNC is not set
-CONFIG_BLK_DEV_COW_COMMON=y
-CONFIG_BLK_DEV_LOOP=m
-CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
-# CONFIG_BLK_DEV_CRYPTOLOOP is not set
-
-#
-# DRBD disabled because PROC_FS, INET or CONNECTOR not selected
-#
-CONFIG_BLK_DEV_NBD=m
-# CONFIG_BLK_DEV_RAM is not set
-# CONFIG_ATA_OVER_ETH is not set
-# CONFIG_BLK_DEV_RBD is not set
-
-#
-# Misc devices
-#
-# CONFIG_ENCLOSURE_SERVICES is not set
-# CONFIG_C2PORT is not set
-
-#
-# EEPROM support
-#
-# CONFIG_EEPROM_93CX6 is not set
-
-#
-# Texas Instruments shared transport line discipline
-#
-
-#
-# Altera FPGA firmware download module
-#
-
-#
-# SCSI device support
-#
-CONFIG_SCSI_MOD=y
-# CONFIG_RAID_ATTRS is not set
-# CONFIG_SCSI is not set
-# CONFIG_SCSI_DMA is not set
-# CONFIG_SCSI_NETLINK is not set
-# CONFIG_MD is not set
-CONFIG_NETDEVICES=y
-CONFIG_NET_CORE=y
-# CONFIG_BONDING is not set
-CONFIG_DUMMY=m
-# CONFIG_EQUALIZER is not set
-# CONFIG_MII is not set
-# CONFIG_NET_TEAM is not set
-# CONFIG_MACVLAN is not set
-# CONFIG_NETCONSOLE is not set
-# CONFIG_NETPOLL is not set
-# CONFIG_NET_POLL_CONTROLLER is not set
-CONFIG_TUN=m
-# CONFIG_VETH is not set
-
-#
-# CAIF transport drivers
-#
-CONFIG_ETHERNET=y
-CONFIG_NET_VENDOR_CHELSIO=y
-CONFIG_NET_VENDOR_INTEL=y
-CONFIG_NET_VENDOR_I825XX=y
-CONFIG_NET_VENDOR_MARVELL=y
-CONFIG_NET_VENDOR_NATSEMI=y
-CONFIG_NET_VENDOR_8390=y
-# CONFIG_PHYLIB is not set
-CONFIG_PPP=m
-# CONFIG_PPP_BSDCOMP is not set
-# CONFIG_PPP_DEFLATE is not set
-# CONFIG_PPP_FILTER is not set
-# CONFIG_PPP_MPPE is not set
-# CONFIG_PPP_MULTILINK is not set
-# CONFIG_PPPOE is not set
-# CONFIG_PPP_ASYNC is not set
-# CONFIG_PPP_SYNC_TTY is not set
-CONFIG_SLIP=m
-CONFIG_SLHC=m
-# CONFIG_SLIP_COMPRESSED is not set
-# CONFIG_SLIP_SMART is not set
-# CONFIG_SLIP_MODE_SLIP6 is not set
-CONFIG_WLAN=y
-# CONFIG_HOSTAP is not set
-
-#
-# Enable WiMAX (Networking options) to see the WiMAX drivers
-#
-# CONFIG_WAN is not set
-
-#
-# Character devices
-#
-CONFIG_UNIX98_PTYS=y
-# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
-CONFIG_LEGACY_PTYS=y
-CONFIG_LEGACY_PTY_COUNT=32
-# CONFIG_N_GSM is not set
-# CONFIG_TRACE_SINK is not set
-CONFIG_DEVKMEM=y
-# CONFIG_HW_RANDOM is not set
-CONFIG_UML_RANDOM=y
-# CONFIG_R3964 is not set
-# CONFIG_NSC_GPIO is not set
-# CONFIG_RAW_DRIVER is not set
-
-#
-# PPS support
-#
-# CONFIG_PPS is not set
-
-#
-# PPS generators support
-#
-
-#
-# PTP clock support
-#
-
-#
-# Enable Device Drivers -> PPS to see the PTP clock options.
-#
-# CONFIG_POWER_SUPPLY is not set
-# CONFIG_THERMAL is not set
-# CONFIG_WATCHDOG is not set
-# CONFIG_REGULATOR is not set
-CONFIG_SOUND_OSS_CORE_PRECLAIM=y
-# CONFIG_MEMSTICK is not set
-# CONFIG_NEW_LEDS is not set
-# CONFIG_ACCESSIBILITY is not set
-# CONFIG_AUXDISPLAY is not set
-# CONFIG_UIO is not set
-
-#
-# Virtio drivers
-#
-# CONFIG_VIRTIO_BALLOON is not set
-
-#
-# Microsoft Hyper-V guest support
-#
-# CONFIG_STAGING is not set
-
-#
-# Hardware Spinlock drivers
-#
-CONFIG_IOMMU_SUPPORT=y
-# CONFIG_VIRT_DRIVERS is not set
-# CONFIG_PM_DEVFREQ is not set
-CONFIG_NET=y
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-CONFIG_UNIX=y
-# CONFIG_UNIX_DIAG is not set
-CONFIG_XFRM=y
-# CONFIG_XFRM_USER is not set
-# CONFIG_XFRM_SUB_POLICY is not set
-# CONFIG_XFRM_MIGRATE is not set
-# CONFIG_XFRM_STATISTICS is not set
-# CONFIG_NET_KEY is not set
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-# CONFIG_IP_PNP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE_DEMUX is not set
-# CONFIG_ARPD is not set
-# CONFIG_SYN_COOKIES is not set
-# CONFIG_INET_AH is not set
-# CONFIG_INET_ESP is not set
-# CONFIG_INET_IPCOMP is not set
-# CONFIG_INET_XFRM_TUNNEL is not set
-# CONFIG_INET_TUNNEL is not set
-CONFIG_INET_XFRM_MODE_TRANSPORT=y
-CONFIG_INET_XFRM_MODE_TUNNEL=y
-CONFIG_INET_XFRM_MODE_BEET=y
-# CONFIG_INET_LRO is not set
-CONFIG_INET_DIAG=y
-CONFIG_INET_TCP_DIAG=y
-# CONFIG_INET_UDP_DIAG is not set
-# CONFIG_TCP_CONG_ADVANCED is not set
-CONFIG_TCP_CONG_CUBIC=y
-CONFIG_DEFAULT_TCP_CONG="cubic"
-# CONFIG_TCP_MD5SIG is not set
-# CONFIG_IPV6 is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
-# CONFIG_NETFILTER is not set
-# CONFIG_IP_DCCP is not set
-# CONFIG_IP_SCTP is not set
-# CONFIG_RDS is not set
-# CONFIG_TIPC is not set
-# CONFIG_ATM is not set
-# CONFIG_L2TP is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_NET_DSA is not set
-# CONFIG_VLAN_8021Q is not set
-# CONFIG_DECNET is not set
-# CONFIG_LLC2 is not set
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-# CONFIG_PHONET is not set
-# CONFIG_IEEE802154 is not set
-# CONFIG_NET_SCHED is not set
-# CONFIG_DCB is not set
-# CONFIG_BATMAN_ADV is not set
-# CONFIG_OPENVSWITCH is not set
-# CONFIG_NETPRIO_CGROUP is not set
-CONFIG_BQL=y
-
-#
-# Network testing
-#
-# CONFIG_NET_PKTGEN is not set
-# CONFIG_HAMRADIO is not set
-# CONFIG_CAN is not set
-# CONFIG_IRDA is not set
-# CONFIG_BT is not set
-# CONFIG_AF_RXRPC is not set
-CONFIG_WIRELESS=y
-# CONFIG_CFG80211 is not set
-# CONFIG_LIB80211 is not set
-
-#
-# CFG80211 needs to be enabled for MAC80211
-#
-# CONFIG_WIMAX is not set
-# CONFIG_RFKILL is not set
-# CONFIG_NET_9P is not set
-# CONFIG_CAIF is not set
-# CONFIG_CEPH_LIB is not set
-# CONFIG_NFC is not set
-
-#
-# UML Network Devices
-#
-CONFIG_UML_NET=y
-CONFIG_UML_NET_ETHERTAP=y
-CONFIG_UML_NET_TUNTAP=y
-CONFIG_UML_NET_SLIP=y
-CONFIG_UML_NET_DAEMON=y
-# CONFIG_UML_NET_VDE is not set
-CONFIG_UML_NET_MCAST=y
-# CONFIG_UML_NET_PCAP is not set
-CONFIG_UML_NET_SLIRP=y
-
-#
-# File systems
-#
-# CONFIG_EXT2_FS is not set
-# CONFIG_EXT3_FS is not set
-CONFIG_EXT4_FS=y
-CONFIG_EXT4_USE_FOR_EXT23=y
-CONFIG_EXT4_FS_XATTR=y
-# CONFIG_EXT4_FS_POSIX_ACL is not set
-# CONFIG_EXT4_FS_SECURITY is not set
-# CONFIG_EXT4_DEBUG is not set
-CONFIG_JBD2=y
-CONFIG_FS_MBCACHE=y
-CONFIG_REISERFS_FS=y
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_REISERFS_PROC_INFO is not set
-# CONFIG_REISERFS_FS_XATTR is not set
-# CONFIG_JFS_FS is not set
-# CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
-# CONFIG_BTRFS_FS is not set
-# CONFIG_NILFS2_FS is not set
-# CONFIG_FS_POSIX_ACL is not set
-CONFIG_FILE_LOCKING=y
-CONFIG_FSNOTIFY=y
-CONFIG_DNOTIFY=y
-CONFIG_INOTIFY_USER=y
-# CONFIG_FANOTIFY is not set
-CONFIG_QUOTA=y
-# CONFIG_QUOTA_NETLINK_INTERFACE is not set
-CONFIG_PRINT_QUOTA_WARNING=y
-# CONFIG_QUOTA_DEBUG is not set
-# CONFIG_QFMT_V1 is not set
-# CONFIG_QFMT_V2 is not set
-CONFIG_QUOTACTL=y
-CONFIG_AUTOFS4_FS=m
-# CONFIG_FUSE_FS is not set
-
-#
-# Caches
-#
-# CONFIG_FSCACHE is not set
-
-#
-# CD-ROM/DVD Filesystems
-#
-CONFIG_ISO9660_FS=m
-CONFIG_JOLIET=y
-# CONFIG_ZISOFS is not set
-# CONFIG_UDF_FS is not set
-
-#
-# DOS/FAT/NT Filesystems
-#
-# CONFIG_MSDOS_FS is not set
-# CONFIG_VFAT_FS is not set
-# CONFIG_NTFS_FS is not set
-
-#
-# Pseudo filesystems
-#
-CONFIG_PROC_FS=y
-CONFIG_PROC_KCORE=y
-CONFIG_PROC_SYSCTL=y
-CONFIG_PROC_PAGE_MONITOR=y
-CONFIG_SYSFS=y
-CONFIG_TMPFS=y
-# CONFIG_TMPFS_POSIX_ACL is not set
-# CONFIG_TMPFS_XATTR is not set
-# CONFIG_HUGETLB_PAGE is not set
-# CONFIG_CONFIGFS_FS is not set
-CONFIG_MISC_FILESYSTEMS=y
-# CONFIG_ADFS_FS is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_HFSPLUS_FS is not set
-# CONFIG_BEFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_LOGFS is not set
-# CONFIG_CRAMFS is not set
-# CONFIG_SQUASHFS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_OMFS_FS is not set
-# CONFIG_HPFS_FS is not set
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_ROMFS_FS is not set
-# CONFIG_PSTORE is not set
-# CONFIG_SYSV_FS is not set
-# CONFIG_UFS_FS is not set
-CONFIG_NETWORK_FILESYSTEMS=y
-# CONFIG_NFS_FS is not set
-# CONFIG_NFSD is not set
-# CONFIG_CEPH_FS is not set
-# CONFIG_CIFS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_CODA_FS is not set
-# CONFIG_AFS_FS is not set
-CONFIG_NLS=y
-CONFIG_NLS_DEFAULT="iso8859-1"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1250 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ASCII is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Security options
-#
-# CONFIG_KEYS is not set
-# CONFIG_SECURITY_DMESG_RESTRICT is not set
-# CONFIG_SECURITY is not set
-# CONFIG_SECURITYFS is not set
-CONFIG_DEFAULT_SECURITY_DAC=y
-CONFIG_DEFAULT_SECURITY=""
-CONFIG_CRYPTO=y
-
-#
-# Crypto core or helper
-#
-# CONFIG_CRYPTO_FIPS is not set
-CONFIG_CRYPTO_ALGAPI=m
-CONFIG_CRYPTO_ALGAPI2=m
-CONFIG_CRYPTO_RNG=m
-CONFIG_CRYPTO_RNG2=m
-# CONFIG_CRYPTO_MANAGER is not set
-# CONFIG_CRYPTO_MANAGER2 is not set
-# CONFIG_CRYPTO_USER is not set
-# CONFIG_CRYPTO_GF128MUL is not set
-# CONFIG_CRYPTO_NULL is not set
-# CONFIG_CRYPTO_CRYPTD is not set
-# CONFIG_CRYPTO_AUTHENC is not set
-# CONFIG_CRYPTO_TEST is not set
-
-#
-# Authenticated Encryption with Associated Data
-#
-# CONFIG_CRYPTO_CCM is not set
-# CONFIG_CRYPTO_GCM is not set
-# CONFIG_CRYPTO_SEQIV is not set
-
-#
-# Block modes
-#
-# CONFIG_CRYPTO_CBC is not set
-# CONFIG_CRYPTO_CTR is not set
-# CONFIG_CRYPTO_CTS is not set
-# CONFIG_CRYPTO_ECB is not set
-# CONFIG_CRYPTO_LRW is not set
-# CONFIG_CRYPTO_PCBC is not set
-# CONFIG_CRYPTO_XTS is not set
-
-#
-# Hash modes
-#
-# CONFIG_CRYPTO_HMAC is not set
-# CONFIG_CRYPTO_XCBC is not set
-# CONFIG_CRYPTO_VMAC is not set
-
-#
-# Digest
-#
-# CONFIG_CRYPTO_CRC32C is not set
-# CONFIG_CRYPTO_GHASH is not set
-# CONFIG_CRYPTO_MD4 is not set
-# CONFIG_CRYPTO_MD5 is not set
-# CONFIG_CRYPTO_MICHAEL_MIC is not set
-# CONFIG_CRYPTO_RMD128 is not set
-# CONFIG_CRYPTO_RMD160 is not set
-# CONFIG_CRYPTO_RMD256 is not set
-# CONFIG_CRYPTO_RMD320 is not set
-# CONFIG_CRYPTO_SHA1 is not set
-# CONFIG_CRYPTO_SHA256 is not set
-# CONFIG_CRYPTO_SHA512 is not set
-# CONFIG_CRYPTO_TGR192 is not set
-# CONFIG_CRYPTO_WP512 is not set
-
-#
-# Ciphers
-#
-CONFIG_CRYPTO_AES=m
-# CONFIG_CRYPTO_AES_586 is not set
-# CONFIG_CRYPTO_ANUBIS is not set
-# CONFIG_CRYPTO_ARC4 is not set
-# CONFIG_CRYPTO_BLOWFISH is not set
-# CONFIG_CRYPTO_CAMELLIA is not set
-# CONFIG_CRYPTO_CAST5 is not set
-# CONFIG_CRYPTO_CAST6 is not set
-# CONFIG_CRYPTO_DES is not set
-# CONFIG_CRYPTO_FCRYPT is not set
-# CONFIG_CRYPTO_KHAZAD is not set
-# CONFIG_CRYPTO_SALSA20 is not set
-# CONFIG_CRYPTO_SALSA20_586 is not set
-# CONFIG_CRYPTO_SEED is not set
-# CONFIG_CRYPTO_SERPENT is not set
-# CONFIG_CRYPTO_TEA is not set
-# CONFIG_CRYPTO_TWOFISH is not set
-# CONFIG_CRYPTO_TWOFISH_586 is not set
-
-#
-# Compression
-#
-# CONFIG_CRYPTO_DEFLATE is not set
-# CONFIG_CRYPTO_ZLIB is not set
-# CONFIG_CRYPTO_LZO is not set
-
-#
-# Random Number Generation
-#
-CONFIG_CRYPTO_ANSI_CPRNG=m
-# CONFIG_CRYPTO_USER_API_HASH is not set
-# CONFIG_CRYPTO_USER_API_SKCIPHER is not set
-CONFIG_CRYPTO_HW=y
-# CONFIG_BINARY_PRINTF is not set
-
-#
-# Library routines
-#
-CONFIG_BITREVERSE=y
-CONFIG_GENERIC_FIND_FIRST_BIT=y
-CONFIG_GENERIC_IO=y
-# CONFIG_CRC_CCITT is not set
-CONFIG_CRC16=y
-# CONFIG_CRC_T10DIF is not set
-# CONFIG_CRC_ITU_T is not set
-CONFIG_CRC32=y
-# CONFIG_CRC7 is not set
-# CONFIG_LIBCRC32C is not set
-# CONFIG_CRC8 is not set
-# CONFIG_XZ_DEC is not set
-# CONFIG_XZ_DEC_BCJ is not set
-CONFIG_DQL=y
-CONFIG_NLATTR=y
-# CONFIG_AVERAGE is not set
-# CONFIG_CORDIC is not set
-
-#
-# Kernel hacking
-#
-# CONFIG_PRINTK_TIME is not set
-CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4
-CONFIG_ENABLE_WARN_DEPRECATED=y
-CONFIG_ENABLE_MUST_CHECK=y
-CONFIG_FRAME_WARN=1024
-# CONFIG_STRIP_ASM_SYMS is not set
-# CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_DEBUG_SECTION_MISMATCH is not set
-CONFIG_DEBUG_KERNEL=y
-# CONFIG_DEBUG_SHIRQ is not set
-# CONFIG_LOCKUP_DETECTOR is not set
-# CONFIG_HARDLOCKUP_DETECTOR is not set
-# CONFIG_DETECT_HUNG_TASK is not set
-CONFIG_SCHED_DEBUG=y
-# CONFIG_SCHEDSTATS is not set
-# CONFIG_TIMER_STATS is not set
-# CONFIG_DEBUG_OBJECTS is not set
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_RT_MUTEXES is not set
-# CONFIG_RT_MUTEX_TESTER is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_DEBUG_MUTEXES is not set
-# CONFIG_SPARSE_RCU_POINTER is not set
-# CONFIG_DEBUG_ATOMIC_SLEEP is not set
-# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-# CONFIG_DEBUG_STACK_USAGE is not set
-# CONFIG_DEBUG_KOBJECT is not set
-CONFIG_DEBUG_BUGVERBOSE=y
-CONFIG_DEBUG_INFO=y
-# CONFIG_DEBUG_INFO_REDUCED is not set
-# CONFIG_DEBUG_VM is not set
-# CONFIG_DEBUG_WRITECOUNT is not set
-CONFIG_DEBUG_MEMORY_INIT=y
-# CONFIG_DEBUG_LIST is not set
-# CONFIG_TEST_LIST_SORT is not set
-# CONFIG_DEBUG_SG is not set
-# CONFIG_DEBUG_NOTIFIERS is not set
-# CONFIG_DEBUG_CREDENTIALS is not set
-CONFIG_FRAME_POINTER=y
-# CONFIG_BOOT_PRINTK_DELAY is not set
-# CONFIG_RCU_TORTURE_TEST is not set
-# CONFIG_BACKTRACE_SELF_TEST is not set
-# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
-# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
-# CONFIG_FAULT_INJECTION is not set
-# CONFIG_SYSCTL_SYSCALL_CHECK is not set
-# CONFIG_DEBUG_PAGEALLOC is not set
-# CONFIG_ATOMIC64_SELFTEST is not set
-# CONFIG_SAMPLES is not set
-# CONFIG_TEST_KSTRTOX is not set
-# CONFIG_GPROF is not set
-# CONFIG_GCOV is not set
-CONFIG_EARLY_PRINTK=y
index 3df3bd544492012ab9b78b0c43ab2648a1760e61..29880c9b324ed33601c8af02340a4765d9d75b3b 100644 (file)
@@ -645,11 +645,9 @@ void mconsole_sysrq(struct mc_request *req)
 
 static void stack_proc(void *arg)
 {
-       struct task_struct *from = current, *to = arg;
+       struct task_struct *task = arg;
 
-       to->thread.saved_task = from;
-       rcu_user_hooks_switch(from, to);
-       switch_to(from, to, from);
+       show_stack(task, NULL);
 }
 
 /*
index c03cd5a02364493fe83c81261eb45c0689bcfed8..d89b02bb6262d2bd34f21a96f8ec8f3845b5cd8c 100644 (file)
@@ -19,8 +19,8 @@ struct task_struct;
 struct mm_struct;
 
 struct thread_struct {
-       struct task_struct *saved_task;
        struct pt_regs regs;
+       struct pt_regs *segv_regs;
        int singlestep_syscall;
        void *fault_addr;
        jmp_buf *fault_catcher;
index 2c8eeb2df8b43a6c21b4b10da99fe1042276229f..1c5b2a83046aab011e03c1e735b020a374608838 100644 (file)
@@ -60,8 +60,6 @@ static inline struct thread_info *current_thread_info(void)
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 #define TIF_SYSCALL_TRACE      0       /* syscall trace active */
 #define TIF_SIGPENDING         1       /* signal pending */
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
index 694c792bab4ec71b0829c110e59c6d774ec6223f..41c8c774ec1037ef6a64a34841729cd8c1c07f49 100644 (file)
@@ -44,7 +44,6 @@ struct cpu_task {
 
 extern struct cpu_task cpu_tasks[];
 
-extern unsigned long low_physmem;
 extern unsigned long high_physmem;
 extern unsigned long uml_physmem;
 extern unsigned long uml_reserved;
@@ -52,8 +51,6 @@ extern unsigned long end_vm;
 extern unsigned long start_vm;
 extern unsigned long long highmem;
 
-extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
-extern unsigned long _unprotected_end;
 extern unsigned long brk_start;
 
 extern unsigned long host_task_size;
index 021104d98cb351d66f9f44353a6ddfa2da71b23d..75298d3358e7f3d2c7ff4e2b2c5ed8b81a8dca6d 100644 (file)
@@ -227,6 +227,7 @@ extern void block_signals(void);
 extern void unblock_signals(void);
 extern int get_signals(void);
 extern int set_signals(int enable);
+extern int os_is_signal_stack(void);
 
 /* util.c */
 extern void stack_protections(unsigned long address);
index bbcef522bcb18ad468fcb4c0d7738010b5e667ed..eecc4142764c7328108a76f5d02126281c44f845 100644 (file)
@@ -82,19 +82,8 @@ void *__switch_to(struct task_struct *from, struct task_struct *to)
        to->thread.prev_sched = from;
        set_current(to);
 
-       do {
-               current->thread.saved_task = NULL;
-
-               switch_threads(&from->thread.switch_buf,
-                              &to->thread.switch_buf);
-
-               arch_switch_to(current);
-
-               if (current->thread.saved_task)
-                       show_regs(&(current->thread.regs));
-               to = current->thread.saved_task;
-               from = current;
-       } while (current->thread.saved_task);
+       switch_threads(&from->thread.switch_buf, &to->thread.switch_buf);
+       arch_switch_to(current);
 
        return current->thread.prev_sched;
 }
index 0dc4d1c6f98a19b5ed018c58d7aeb683d468ae1c..4d6fdf68edf31cf31b993081a6d9432dff6e3c5b 100644 (file)
@@ -1,6 +1,10 @@
 /*
  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
- * Licensed under the GPL
+ * Copyright (C) 2013 Richard Weinberger <richrd@nod.at>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
  */
 
 #include <linux/kallsyms.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <asm/sysrq.h>
+#include <os.h>
 
-/* Catch non-i386 SUBARCH's. */
-#if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT)
-void show_trace(struct task_struct *task, unsigned long * stack)
+struct stack_frame {
+       struct stack_frame *next_frame;
+       unsigned long return_address;
+};
+
+static void print_stack_trace(unsigned long *sp, unsigned long bp)
 {
+       int reliable;
        unsigned long addr;
+       struct stack_frame *frame = (struct stack_frame *)bp;
 
-       if (!stack) {
-               stack = (unsigned long*) &stack;
-               WARN_ON(1);
-       }
-
-       printk(KERN_INFO "Call Trace: \n");
-       while (((long) stack & (THREAD_SIZE-1)) != 0) {
-               addr = *stack;
+       printk(KERN_INFO "Call Trace:\n");
+       while (((long) sp & (THREAD_SIZE-1)) != 0) {
+               addr = *sp;
                if (__kernel_text_address(addr)) {
-                       printk(KERN_INFO "%08lx:  [<%08lx>]",
-                              (unsigned long) stack, addr);
-                       print_symbol(KERN_CONT " %s", addr);
+                       reliable = 0;
+                       if ((unsigned long) sp == bp + sizeof(long)) {
+                               frame = frame ? frame->next_frame : NULL;
+                               bp = (unsigned long)frame;
+                               reliable = 1;
+                       }
+
+                       printk(KERN_INFO " [<%08lx>]", addr);
+                       printk(KERN_CONT " %s", reliable ? "" : "? ");
+                       print_symbol(KERN_CONT "%s", addr);
                        printk(KERN_CONT "\n");
                }
-               stack++;
+               sp++;
        }
        printk(KERN_INFO "\n");
 }
-#endif
 
-/*Stolen from arch/i386/kernel/traps.c */
-static const int kstack_depth_to_print = 24;
+static unsigned long get_frame_pointer(struct task_struct *task,
+                                      struct pt_regs *segv_regs)
+{
+       if (!task || task == current)
+               return segv_regs ? PT_REGS_BP(segv_regs) : current_bp();
+       else
+               return KSTK_EBP(task);
+}
 
-/* This recently started being used in arch-independent code too, as in
- * kernel/sched/core.c.*/
-void show_stack(struct task_struct *task, unsigned long *esp)
+static unsigned long *get_stack_pointer(struct task_struct *task,
+                                       struct pt_regs *segv_regs)
 {
-       unsigned long *stack;
+       if (!task || task == current)
+               return segv_regs ? (unsigned long *)PT_REGS_SP(segv_regs) : current_sp();
+       else
+               return (unsigned long *)KSTK_ESP(task);
+}
+
+void show_stack(struct task_struct *task, unsigned long *stack)
+{
+       unsigned long *sp = stack, bp = 0;
+       struct pt_regs *segv_regs = current->thread.segv_regs;
        int i;
 
-       if (esp == NULL) {
-               if (task != current && task != NULL) {
-                       esp = (unsigned long *) KSTK_ESP(task);
-               } else {
-                       esp = (unsigned long *) &esp;
-               }
+       if (!segv_regs && os_is_signal_stack()) {
+               printk(KERN_ERR "Received SIGSEGV in SIGSEGV handler,"
+                               " aborting stack trace!\n");
+               return;
        }
 
-       stack = esp;
-       for (i = 0; i < kstack_depth_to_print; i++) {
+#ifdef CONFIG_FRAME_POINTER
+       bp = get_frame_pointer(task, segv_regs);
+#endif
+
+       if (!stack)
+               sp = get_stack_pointer(task, segv_regs);
+
+       printk(KERN_INFO "Stack:\n");
+       stack = sp;
+       for (i = 0; i < 3 * STACKSLOTS_PER_LINE; i++) {
                if (kstack_end(stack))
                        break;
-               if (i && ((i % 8) == 0))
-                       printk(KERN_INFO "       ");
-               printk(KERN_CONT "%08lx ", *stack++);
+               if (i && ((i % STACKSLOTS_PER_LINE) == 0))
+                       printk(KERN_CONT "\n");
+               printk(KERN_CONT " %08lx", *stack++);
        }
+       printk(KERN_CONT "\n");
 
-       show_trace(task, esp);
+       print_stack_trace(sp, bp);
 }
index 5c3aef74237ffda72a0b252d4ee4b118d14a969a..974b87474a9900f1909f845d449eba90dc9b8338 100644 (file)
@@ -206,9 +206,12 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
        int is_write = FAULT_WRITE(fi);
        unsigned long address = FAULT_ADDRESS(fi);
 
+       if (regs)
+               current->thread.segv_regs = container_of(regs, struct pt_regs, regs);
+
        if (!is_user && (address >= start_vm) && (address < end_vm)) {
                flush_tlb_kernel_vm();
-               return 0;
+               goto out;
        }
        else if (current->mm == NULL) {
                show_regs(container_of(regs, struct pt_regs, regs));
@@ -230,7 +233,7 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
 
        catcher = current->thread.fault_catcher;
        if (!err)
-               return 0;
+               goto out;
        else if (catcher != NULL) {
                current->thread.fault_addr = (void *) address;
                UML_LONGJMP(catcher, 1);
@@ -238,7 +241,7 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
        else if (current->thread.fault_addr != NULL)
                panic("fault_addr set but no fault catcher");
        else if (!is_user && arch_fixup(ip, regs))
-               return 0;
+               goto out;
 
        if (!is_user) {
                show_regs(container_of(regs, struct pt_regs, regs));
@@ -262,6 +265,11 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
                current->thread.arch.faultinfo = fi;
                force_sig_info(SIGSEGV, &si, current);
        }
+
+out:
+       if (regs)
+               current->thread.segv_regs = NULL;
+
        return 0;
 }
 
index 87df5e3acc26eaa35798da9e8d2818ae2a6a5d70..016adf0985d522ccfb5f22e6d287bb60dfdb4e61 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/sched.h>
 #include <asm/pgtable.h>
 #include <asm/processor.h>
+#include <asm/sections.h>
 #include <asm/setup.h>
 #include <as-layout.h>
 #include <arch.h>
@@ -234,7 +235,6 @@ static int panic_exit(struct notifier_block *self, unsigned long unused1,
                      void *unused2)
 {
        bust_spinlocks(1);
-       show_regs(&(current->thread.regs));
        bust_spinlocks(0);
        uml_exitcode = 1;
        os_dump_core();
index 905924b773d345b8f49de2905e62a546f6461cd9..7b605e4dfffa91305e763e7698832edcbf80d3bd 100644 (file)
@@ -304,3 +304,11 @@ int set_signals(int enable)
 
        return ret;
 }
+
+int os_is_signal_stack(void)
+{
+       stack_t ss;
+       sigaltstack(NULL, &ss);
+
+       return ss.ss_flags & SS_ONSTACK;
+}
index 82cdd8906f3d6ff70e3317a78ae00c08a0bed39e..a7ba27b2752be0923644eba19035ba3a97a6c792 100644 (file)
@@ -1,5 +1,6 @@
 config UNICORE32
        def_bool y
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select HAVE_MEMBLOCK
        select HAVE_GENERIC_DMA_COHERENT
        select HAVE_DMA_ATTRS
index 818b4a1edb5b1bd26e3d8eb7baffe212df50a6f0..af36d8eabdf1c1dd6650e10682eff053550c906a 100644 (file)
@@ -117,12 +117,6 @@ static inline struct thread_info *current_thread_info(void)
 
 #endif
 
-/*
- * We use bit 30 of the preempt_count to indicate that kernel
- * preemption is occurring.  See <asm/hardirq.h>.
- */
-#define PREEMPT_ACTIVE 0x40000000
-
 /*
  * thread information flags:
  *  TIF_SYSCALL_TRACE  - syscall trace active
index 181108b8ecce766d0102b9e12ac070e6510337b0..0c6618e7189782674af77f9130ede7b3c71d39e6 100644 (file)
@@ -54,6 +54,7 @@ static struct platform_pwm_backlight_data nb0916_backlight_data = {
        .max_brightness = 100,
        .dft_brightness = 100,
        .pwm_period_ns  = 70 * 1024,
+       .enable_gpio    = -1,
 };
 
 static struct gpio_keys_button nb0916_gpio_keys[] = {
index 83f521aa103fcfd447c2b9a90889f80fa859c9ea..e903c71f7e69822d2ce5240b957399dbab783037 100644 (file)
@@ -22,6 +22,7 @@ config X86_64
 config X86
        def_bool y
        select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
+       select ARCH_MIGHT_HAVE_PC_PARPORT
        select HAVE_AOUT if X86_32
        select HAVE_UNSTABLE_SCHED_CLOCK
        select ARCH_SUPPORTS_NUMA_BALANCING
index 7d7443283a9d5b2dc19796a7d18e9bebd66e2164..947b5c417e830ae0ead192964ef07f8a68d88851 100644 (file)
@@ -15,7 +15,7 @@ struct pci_sysdata {
        int             domain;         /* PCI domain */
        int             node;           /* NUMA node */
 #ifdef CONFIG_ACPI
-       void            *acpi;          /* ACPI-specific data */
+       struct acpi_device *companion;  /* ACPI companion device */
 #endif
 #ifdef CONFIG_X86_64
        void            *iommu;         /* IOMMU private data */
index c46a46be1ec699c0a92180c4f584da150fd7f5eb..3ba3de457d053e77eb36d7d6fe78f7769a1df470 100644 (file)
@@ -153,8 +153,6 @@ struct thread_info {
 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
 
-#define PREEMPT_ACTIVE         0x10000000
-
 #ifdef CONFIG_X86_32
 
 #define STACK_WARN     (THREAD_SIZE/8)
index b93e09a0fa21c34ee20a5cf3ddd8319efa07f40c..37813b5ddc37472dba6c64b8ff3f2508dc085de0 100644 (file)
 #define MSR_PP1_ENERGY_STATUS          0x00000641
 #define MSR_PP1_POLICY                 0x00000642
 
+#define MSR_CORE_C1_RES                        0x00000660
+
 #define MSR_AMD64_MC0_MASK             0xc0010044
 
 #define MSR_IA32_MCx_CTL(x)            (MSR_IA32_MC0_CTL + 4*(x))
index ed165d657380062387d08da7bf2f607fff192490..d278736bf774f7d5c61bd64aa735f6de829b1075 100644 (file)
@@ -62,6 +62,7 @@ unsigned disabled_cpus;
 
 /* Processor that is doing the boot up */
 unsigned int boot_cpu_physical_apicid = -1U;
+EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid);
 
 /*
  * The highest APIC ID seen during enumeration.
index 3daece79a142b5dca849468295c1d438cda592fa..bca023bdd6b2a8b4525d10145795408dee4fa01b 100644 (file)
@@ -339,7 +339,7 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
 #endif
 
 /*
- * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
+ * On a AMD dual core setup the lower bits of the APIC id distinguish the cores.
  * Assumes number of cores is a power of two.
  */
 static void amd_detect_cmp(struct cpuinfo_x86 *c)
index 1414c90feabaa25014d6b4dfb5ecde1eafceb37f..0641113e296598c058cab739d94c0ae2f5280ec0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     Routines to indentify caches on Intel CPU.
+ *     Routines to identify caches on Intel CPU.
  *
  *     Changes:
  *     Venkatesh Pallipadi     : Adding cache identification through cpuid(4)
index f2cc63e9cf08f94f50b5f618e1c07b438ac5071e..b6f794aa16937f5c3e2c09991679a75c55bf8249 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     Routines to indentify additional cpu features that are scattered in
+ *     Routines to identify additional cpu features that are scattered in
  *     cpuid space.
  */
 #include <linux/cpu.h>
index 42a392a9fd02fd3c0e306e3a4f4da323444dc3fd..d4bdd253fea71358ca080ba567a44935a9830396 100644 (file)
@@ -248,6 +248,15 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
        return ret;
 }
 
+static int is_ftrace_caller(unsigned long ip)
+{
+       if (ip == (unsigned long)(&ftrace_call) ||
+               ip == (unsigned long)(&ftrace_regs_call))
+               return 1;
+
+       return 0;
+}
+
 /*
  * A breakpoint was added to the code address we are about to
  * modify, and this is the handle that will just skip over it.
@@ -257,10 +266,13 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
  */
 int ftrace_int3_handler(struct pt_regs *regs)
 {
+       unsigned long ip;
+
        if (WARN_ON_ONCE(!regs))
                return 0;
 
-       if (!ftrace_location(regs->ip - 1))
+       ip = regs->ip - 1;
+       if (!ftrace_location(ip) && !is_ftrace_caller(ip))
                return 0;
 
        regs->ip += MCOUNT_INSN_SIZE - 1;
index a7cccb6d7fec680e184a57c197106a7d475467b1..36aa999b26318888bc9bf5b39d8966a4e084701a 100644 (file)
@@ -209,7 +209,7 @@ static int preallocate_pmds(pmd_t *pmds[])
                if (!pmd)
                        failed = true;
                if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
-                       free_page((unsigned long)pmds[i]);
+                       free_page((unsigned long)pmd);
                        pmd = NULL;
                        failed = true;
                }
index 7fb24e53d4c8b88b1fd374a327e0535269f7e328..4f25ec0775526f45133d9087bc13fd4f76dfb24e 100644 (file)
@@ -518,7 +518,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
        sd = &info->sd;
        sd->domain = domain;
        sd->node = node;
-       sd->acpi = device->handle;
+       sd->companion = device;
        /*
         * Maybe the desired pci bus has been already scanned. In such case
         * it is unnecessary to scan the pci bus with the given domain,busnum.
@@ -589,7 +589,7 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
 {
        struct pci_sysdata *sd = bridge->bus->sysdata;
 
-       ACPI_HANDLE_SET(&bridge->dev, sd->acpi);
+       ACPI_COMPANION_SET(&bridge->dev, sd->companion);
        return 0;
 }
 
index 14ef8d1dbc33bf954b062b525ed0771ef4489172..ed56a1c4ae734d8fa2b3cb2ccd4133c2ebc4c5a8 100644 (file)
@@ -31,6 +31,11 @@ config X86_64
        def_bool 64BIT
        select MODULES_USE_ELF_RELA
 
+config ARCH_DEFCONFIG
+       string
+       default "arch/um/configs/i386_defconfig" if X86_32
+       default "arch/um/configs/x86_64_defconfig" if X86_64
+
 config RWSEM_XCHGADD_ALGORITHM
        def_bool 64BIT
 
index 6c6689e574ce9057d5143b2f3196f9f11418f517..c112de81c9e19860fe59087a653697a5d2afb5e1 100644 (file)
@@ -33,6 +33,8 @@ struct arch_thread {
        .faultinfo              = { 0, 0, 0 } \
 }
 
+#define STACKSLOTS_PER_LINE 8
+
 static inline void arch_flush_thread(struct arch_thread *thread)
 {
        /* Clear any TLS still hanging */
@@ -53,4 +55,7 @@ static inline void arch_copy_thread(struct arch_thread *from,
 #define current_text_addr() \
        ({ void *pc; __asm__("movl $1f,%0\n1:":"=g" (pc)); pc; })
 
+#define current_sp() ({ void *sp; __asm__("movl %%esp, %0" : "=r" (sp) : ); sp; })
+#define current_bp() ({ unsigned long bp; __asm__("movl %%ebp, %0" : "=r" (bp) : ); bp; })
+
 #endif
index 4b02a8455bd1eb55056149630c596f9e4ea9dfd1..c3be85205a6599402d4343c8c2554bb9722a5e54 100644 (file)
@@ -19,6 +19,8 @@ struct arch_thread {
                           .fs                  = 0, \
                           .faultinfo           = { 0, 0, 0 } }
 
+#define STACKSLOTS_PER_LINE 4
+
 static inline void arch_flush_thread(struct arch_thread *thread)
 {
 }
@@ -32,4 +34,7 @@ static inline void arch_copy_thread(struct arch_thread *from,
 #define current_text_addr() \
        ({ void *pc; __asm__("movq $1f,%0\n1:":"=g" (pc)); pc; })
 
+#define current_sp() ({ void *sp; __asm__("movq %%rsp, %0" : "=r" (sp) : ); sp; })
+#define current_bp() ({ unsigned long bp; __asm__("movq %%rbp, %0" : "=r" (bp) : ); bp; })
+
 #endif
index c9bee5b8c0d3e84e7d42cef757c7c74906514e28..16ee0e450e3e39df58bcb6c7dca97b46cb01b443 100644 (file)
@@ -30,70 +30,4 @@ void show_regs(struct pt_regs *regs)
         printk(" DS: %04lx ES: %04lx\n",
               0xffff & PT_REGS_DS(regs), 
               0xffff & PT_REGS_ES(regs));
-
-        show_trace(NULL, (unsigned long *) &regs);
 }
-
-/* Copied from i386. */
-static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
-{
-       return  p > (void *)tinfo &&
-               p < (void *)tinfo + THREAD_SIZE - 3;
-}
-
-/* Adapted from i386 (we also print the address we read from). */
-static inline unsigned long print_context_stack(struct thread_info *tinfo,
-                               unsigned long *stack, unsigned long ebp)
-{
-       unsigned long addr;
-
-#ifdef CONFIG_FRAME_POINTER
-       while (valid_stack_ptr(tinfo, (void *)ebp)) {
-               addr = *(unsigned long *)(ebp + 4);
-               printk("%08lx:  [<%08lx>]", ebp + 4, addr);
-               print_symbol(" %s", addr);
-               printk("\n");
-               ebp = *(unsigned long *)ebp;
-       }
-#else
-       while (valid_stack_ptr(tinfo, stack)) {
-               addr = *stack;
-               if (__kernel_text_address(addr)) {
-                       printk("%08lx:  [<%08lx>]", (unsigned long) stack, addr);
-                       print_symbol(" %s", addr);
-                       printk("\n");
-               }
-               stack++;
-       }
-#endif
-       return ebp;
-}
-
-void show_trace(struct task_struct* task, unsigned long * stack)
-{
-       unsigned long ebp;
-       struct thread_info *context;
-
-       /* Turn this into BUG_ON if possible. */
-       if (!stack) {
-               stack = (unsigned long*) &stack;
-               printk("show_trace: got NULL stack, implicit assumption task == current");
-               WARN_ON(1);
-       }
-
-       if (!task)
-               task = current;
-
-       if (task != current) {
-               ebp = (unsigned long) KSTK_EBP(task);
-       } else {
-               asm ("movl %%ebp, %0" : "=r" (ebp) : );
-       }
-
-       context = (struct thread_info *)
-               ((unsigned long)stack & (~(THREAD_SIZE - 1)));
-       print_context_stack(context, stack, ebp);
-
-       printk("\n");
-}
-
index a0e7fb1134a074c292b248eef68f952aba755581..38b4e4abd0f836b28ee6596bf2aa2410078a6df4 100644 (file)
@@ -12,7 +12,7 @@
 #include <asm/ptrace.h>
 #include <asm/sysrq.h>
 
-void __show_regs(struct pt_regs *regs)
+void show_regs(struct pt_regs *regs)
 {
        printk("\n");
        print_modules();
@@ -33,9 +33,3 @@ void __show_regs(struct pt_regs *regs)
        printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n",
               PT_REGS_R13(regs), PT_REGS_R14(regs), PT_REGS_R15(regs));
 }
-
-void show_regs(struct pt_regs *regs)
-{
-       __show_regs(regs);
-       show_trace(current, (unsigned long *) &regs);
-}
diff --git a/arch/x86/um/vdso/.gitignore b/arch/x86/um/vdso/.gitignore
new file mode 100644 (file)
index 0000000..9cac6d0
--- /dev/null
@@ -0,0 +1,2 @@
+vdso-syms.lds
+vdso.lds
index 9481004ac119e04ef8f6a80921561de071b445a1..470153e8547c19a6819ac4cfbea3aa095b3dd33e 100644 (file)
@@ -76,8 +76,6 @@ struct thread_info {
 
 #endif
 
-#define PREEMPT_ACTIVE         0x10000000
-
 /*
  * macros/functions for gaining access to the thread information structure
  */
index 46cd7bd18b347c580bfee1f4b86fb59321070e56..242df01413f6ee902b50b028b228b31330e0c1f2 100644 (file)
@@ -6,7 +6,6 @@
 #include <linux/init.h>
 #include <linux/bio.h>
 #include <linux/blkdev.h>
-#include <linux/bootmem.h>     /* for max_pfn/max_low_pfn */
 #include <linux/slab.h>
 
 #include "blk.h"
index f8ea39d7ae5466c9a36dd7ba9274c6acb8522fa5..0045ace9bdf0301f724463c2e37ae8b62e9902cb 100644 (file)
@@ -13,8 +13,8 @@
 static LIST_HEAD(blk_mq_cpu_notify_list);
 static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock);
 
-static int __cpuinit blk_mq_main_cpu_notify(struct notifier_block *self,
-                                           unsigned long action, void *hcpu)
+static int blk_mq_main_cpu_notify(struct notifier_block *self,
+                                 unsigned long action, void *hcpu)
 {
        unsigned int cpu = (unsigned long) hcpu;
        struct blk_mq_cpu_notifier *notify;
@@ -28,8 +28,8 @@ static int __cpuinit blk_mq_main_cpu_notify(struct notifier_block *self,
        return NOTIFY_OK;
 }
 
-static void __cpuinit blk_mq_cpu_notify(void *data, unsigned long action,
-                                       unsigned int cpu)
+static void blk_mq_cpu_notify(void *data, unsigned long action,
+                             unsigned int cpu)
 {
        if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) {
                /*
index c661896e2465bd0f9248c85400be210b67efed76..cdc629cf075b74f27f7801565ec3d90f3e299ce0 100644 (file)
@@ -171,9 +171,12 @@ bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
 }
 EXPORT_SYMBOL(blk_mq_can_queue);
 
-static void blk_mq_rq_ctx_init(struct blk_mq_ctx *ctx, struct request *rq,
-                              unsigned int rw_flags)
+static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
+                              struct request *rq, unsigned int rw_flags)
 {
+       if (blk_queue_io_stat(q))
+               rw_flags |= REQ_IO_STAT;
+
        rq->mq_ctx = ctx;
        rq->cmd_flags = rw_flags;
        ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
@@ -197,7 +200,7 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
 
                rq = __blk_mq_alloc_request(hctx, gfp & ~__GFP_WAIT, reserved);
                if (rq) {
-                       blk_mq_rq_ctx_init(ctx, rq, rw);
+                       blk_mq_rq_ctx_init(q, ctx, rq, rw);
                        break;
                } else if (!(gfp & __GFP_WAIT))
                        break;
@@ -718,6 +721,8 @@ static void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx,
 {
        struct blk_mq_ctx *ctx = rq->mq_ctx;
 
+       trace_block_rq_insert(hctx->queue, rq);
+
        list_add_tail(&rq->queuelist, &ctx->rq_list);
        blk_mq_hctx_mark_pending(hctx, ctx);
 
@@ -921,7 +926,7 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
        trace_block_getrq(q, bio, rw);
        rq = __blk_mq_alloc_request(hctx, GFP_ATOMIC, false);
        if (likely(rq))
-               blk_mq_rq_ctx_init(ctx, rq, rw);
+               blk_mq_rq_ctx_init(q, ctx, rq, rw);
        else {
                blk_mq_put_ctx(ctx);
                trace_block_sleeprq(q, bio, rw);
@@ -1377,6 +1382,7 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_reg *reg,
        q->queue_hw_ctx = hctxs;
 
        q->mq_ops = reg->ops;
+       q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT;
 
        blk_queue_make_request(q, blk_mq_make_request);
        blk_queue_rq_timed_out(q, reg->ops->timeout);
@@ -1444,7 +1450,7 @@ void blk_mq_free_queue(struct request_queue *q)
 EXPORT_SYMBOL(blk_mq_free_queue);
 
 /* Basically redo blk_mq_init_queue with queue frozen */
-static void __cpuinit blk_mq_queue_reinit(struct request_queue *q)
+static void blk_mq_queue_reinit(struct request_queue *q)
 {
        blk_mq_freeze_queue(q);
 
@@ -1461,8 +1467,8 @@ static void __cpuinit blk_mq_queue_reinit(struct request_queue *q)
        blk_mq_unfreeze_queue(q);
 }
 
-static int __cpuinit blk_mq_queue_reinit_notify(struct notifier_block *nb,
-               unsigned long action, void *hcpu)
+static int blk_mq_queue_reinit_notify(struct notifier_block *nb,
+                                     unsigned long action, void *hcpu)
 {
        struct request_queue *q;
 
index 9e62feffb374536995e08357866df9787635b19e..f8c0b8dbeb7582beca1ee7fd5c7aaac58aba23cd 100644 (file)
@@ -50,33 +50,36 @@ async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
                                                      &dest, 1, &src, 1, len);
        struct dma_device *device = chan ? chan->device : NULL;
        struct dma_async_tx_descriptor *tx = NULL;
+       struct dmaengine_unmap_data *unmap = NULL;
 
-       if (device && is_dma_copy_aligned(device, src_offset, dest_offset, len)) {
-               dma_addr_t dma_dest, dma_src;
+       if (device)
+               unmap = dmaengine_get_unmap_data(device->dev, 2, GFP_NOIO);
+
+       if (unmap && is_dma_copy_aligned(device, src_offset, dest_offset, len)) {
                unsigned long dma_prep_flags = 0;
 
                if (submit->cb_fn)
                        dma_prep_flags |= DMA_PREP_INTERRUPT;
                if (submit->flags & ASYNC_TX_FENCE)
                        dma_prep_flags |= DMA_PREP_FENCE;
-               dma_dest = dma_map_page(device->dev, dest, dest_offset, len,
-                                       DMA_FROM_DEVICE);
-
-               dma_src = dma_map_page(device->dev, src, src_offset, len,
-                                      DMA_TO_DEVICE);
-
-               tx = device->device_prep_dma_memcpy(chan, dma_dest, dma_src,
-                                                   len, dma_prep_flags);
-               if (!tx) {
-                       dma_unmap_page(device->dev, dma_dest, len,
-                                      DMA_FROM_DEVICE);
-                       dma_unmap_page(device->dev, dma_src, len,
-                                      DMA_TO_DEVICE);
-               }
+
+               unmap->to_cnt = 1;
+               unmap->addr[0] = dma_map_page(device->dev, src, src_offset, len,
+                                             DMA_TO_DEVICE);
+               unmap->from_cnt = 1;
+               unmap->addr[1] = dma_map_page(device->dev, dest, dest_offset, len,
+                                             DMA_FROM_DEVICE);
+               unmap->len = len;
+
+               tx = device->device_prep_dma_memcpy(chan, unmap->addr[1],
+                                                   unmap->addr[0], len,
+                                                   dma_prep_flags);
        }
 
        if (tx) {
                pr_debug("%s: (async) len: %zu\n", __func__, len);
+
+               dma_set_unmap(tx, unmap);
                async_tx_submit(chan, tx, submit);
        } else {
                void *dest_buf, *src_buf;
@@ -96,6 +99,8 @@ async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
                async_tx_sync_epilog(submit);
        }
 
+       dmaengine_unmap_put(unmap);
+
        return tx;
 }
 EXPORT_SYMBOL_GPL(async_memcpy);
index 91d5d385899ee06c507cee1aa496330405d6276b..d05327caf69dbc18532478b122ea9834e67f1fd9 100644 (file)
@@ -46,49 +46,24 @@ static struct page *pq_scribble_page;
  * do_async_gen_syndrome - asynchronously calculate P and/or Q
  */
 static __async_inline struct dma_async_tx_descriptor *
-do_async_gen_syndrome(struct dma_chan *chan, struct page **blocks,
-                     const unsigned char *scfs, unsigned int offset, int disks,
-                     size_t len, dma_addr_t *dma_src,
+do_async_gen_syndrome(struct dma_chan *chan,
+                     const unsigned char *scfs, int disks,
+                     struct dmaengine_unmap_data *unmap,
+                     enum dma_ctrl_flags dma_flags,
                      struct async_submit_ctl *submit)
 {
        struct dma_async_tx_descriptor *tx = NULL;
        struct dma_device *dma = chan->device;
-       enum dma_ctrl_flags dma_flags = 0;
        enum async_tx_flags flags_orig = submit->flags;
        dma_async_tx_callback cb_fn_orig = submit->cb_fn;
        dma_async_tx_callback cb_param_orig = submit->cb_param;
        int src_cnt = disks - 2;
-       unsigned char coefs[src_cnt];
        unsigned short pq_src_cnt;
        dma_addr_t dma_dest[2];
        int src_off = 0;
-       int idx;
-       int i;
 
-       /* DMAs use destinations as sources, so use BIDIRECTIONAL mapping */
-       if (P(blocks, disks))
-               dma_dest[0] = dma_map_page(dma->dev, P(blocks, disks), offset,
-                                          len, DMA_BIDIRECTIONAL);
-       else
-               dma_flags |= DMA_PREP_PQ_DISABLE_P;
-       if (Q(blocks, disks))
-               dma_dest[1] = dma_map_page(dma->dev, Q(blocks, disks), offset,
-                                          len, DMA_BIDIRECTIONAL);
-       else
-               dma_flags |= DMA_PREP_PQ_DISABLE_Q;
-
-       /* convert source addresses being careful to collapse 'empty'
-        * sources and update the coefficients accordingly
-        */
-       for (i = 0, idx = 0; i < src_cnt; i++) {
-               if (blocks[i] == NULL)
-                       continue;
-               dma_src[idx] = dma_map_page(dma->dev, blocks[i], offset, len,
-                                           DMA_TO_DEVICE);
-               coefs[idx] = scfs[i];
-               idx++;
-       }
-       src_cnt = idx;
+       if (submit->flags & ASYNC_TX_FENCE)
+               dma_flags |= DMA_PREP_FENCE;
 
        while (src_cnt > 0) {
                submit->flags = flags_orig;
@@ -100,28 +75,25 @@ do_async_gen_syndrome(struct dma_chan *chan, struct page **blocks,
                if (src_cnt > pq_src_cnt) {
                        submit->flags &= ~ASYNC_TX_ACK;
                        submit->flags |= ASYNC_TX_FENCE;
-                       dma_flags |= DMA_COMPL_SKIP_DEST_UNMAP;
                        submit->cb_fn = NULL;
                        submit->cb_param = NULL;
                } else {
-                       dma_flags &= ~DMA_COMPL_SKIP_DEST_UNMAP;
                        submit->cb_fn = cb_fn_orig;
                        submit->cb_param = cb_param_orig;
                        if (cb_fn_orig)
                                dma_flags |= DMA_PREP_INTERRUPT;
                }
-               if (submit->flags & ASYNC_TX_FENCE)
-                       dma_flags |= DMA_PREP_FENCE;
 
-               /* Since we have clobbered the src_list we are committed
-                * to doing this asynchronously.  Drivers force forward
-                * progress in case they can not provide a descriptor
+               /* Drivers force forward progress in case they can not provide
+                * a descriptor
                 */
                for (;;) {
+                       dma_dest[0] = unmap->addr[disks - 2];
+                       dma_dest[1] = unmap->addr[disks - 1];
                        tx = dma->device_prep_dma_pq(chan, dma_dest,
-                                                    &dma_src[src_off],
+                                                    &unmap->addr[src_off],
                                                     pq_src_cnt,
-                                                    &coefs[src_off], len,
+                                                    &scfs[src_off], unmap->len,
                                                     dma_flags);
                        if (likely(tx))
                                break;
@@ -129,6 +101,7 @@ do_async_gen_syndrome(struct dma_chan *chan, struct page **blocks,
                        dma_async_issue_pending(chan);
                }
 
+               dma_set_unmap(tx, unmap);
                async_tx_submit(chan, tx, submit);
                submit->depend_tx = tx;
 
@@ -188,10 +161,6 @@ do_sync_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
  * set to NULL those buffers will be replaced with the raid6_zero_page
  * in the synchronous path and omitted in the hardware-asynchronous
  * path.
- *
- * 'blocks' note: if submit->scribble is NULL then the contents of
- * 'blocks' may be overwritten to perform address conversions
- * (dma_map_page() or page_address()).
  */
 struct dma_async_tx_descriptor *
 async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
@@ -202,26 +171,69 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
                                                      &P(blocks, disks), 2,
                                                      blocks, src_cnt, len);
        struct dma_device *device = chan ? chan->device : NULL;
-       dma_addr_t *dma_src = NULL;
+       struct dmaengine_unmap_data *unmap = NULL;
 
        BUG_ON(disks > 255 || !(P(blocks, disks) || Q(blocks, disks)));
 
-       if (submit->scribble)
-               dma_src = submit->scribble;
-       else if (sizeof(dma_addr_t) <= sizeof(struct page *))
-               dma_src = (dma_addr_t *) blocks;
+       if (device)
+               unmap = dmaengine_get_unmap_data(device->dev, disks, GFP_NOIO);
 
-       if (dma_src && device &&
+       if (unmap &&
            (src_cnt <= dma_maxpq(device, 0) ||
             dma_maxpq(device, DMA_PREP_CONTINUE) > 0) &&
            is_dma_pq_aligned(device, offset, 0, len)) {
+               struct dma_async_tx_descriptor *tx;
+               enum dma_ctrl_flags dma_flags = 0;
+               unsigned char coefs[src_cnt];
+               int i, j;
+
                /* run the p+q asynchronously */
                pr_debug("%s: (async) disks: %d len: %zu\n",
                         __func__, disks, len);
-               return do_async_gen_syndrome(chan, blocks, raid6_gfexp, offset,
-                                            disks, len, dma_src, submit);
+
+               /* convert source addresses being careful to collapse 'empty'
+                * sources and update the coefficients accordingly
+                */
+               unmap->len = len;
+               for (i = 0, j = 0; i < src_cnt; i++) {
+                       if (blocks[i] == NULL)
+                               continue;
+                       unmap->addr[j] = dma_map_page(device->dev, blocks[i], offset,
+                                                     len, DMA_TO_DEVICE);
+                       coefs[j] = raid6_gfexp[i];
+                       unmap->to_cnt++;
+                       j++;
+               }
+
+               /*
+                * DMAs use destinations as sources,
+                * so use BIDIRECTIONAL mapping
+                */
+               unmap->bidi_cnt++;
+               if (P(blocks, disks))
+                       unmap->addr[j++] = dma_map_page(device->dev, P(blocks, disks),
+                                                       offset, len, DMA_BIDIRECTIONAL);
+               else {
+                       unmap->addr[j++] = 0;
+                       dma_flags |= DMA_PREP_PQ_DISABLE_P;
+               }
+
+               unmap->bidi_cnt++;
+               if (Q(blocks, disks))
+                       unmap->addr[j++] = dma_map_page(device->dev, Q(blocks, disks),
+                                                      offset, len, DMA_BIDIRECTIONAL);
+               else {
+                       unmap->addr[j++] = 0;
+                       dma_flags |= DMA_PREP_PQ_DISABLE_Q;
+               }
+
+               tx = do_async_gen_syndrome(chan, coefs, j, unmap, dma_flags, submit);
+               dmaengine_unmap_put(unmap);
+               return tx;
        }
 
+       dmaengine_unmap_put(unmap);
+
        /* run the pq synchronously */
        pr_debug("%s: (sync) disks: %d len: %zu\n", __func__, disks, len);
 
@@ -277,50 +289,60 @@ async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
        struct dma_async_tx_descriptor *tx;
        unsigned char coefs[disks-2];
        enum dma_ctrl_flags dma_flags = submit->cb_fn ? DMA_PREP_INTERRUPT : 0;
-       dma_addr_t *dma_src = NULL;
-       int src_cnt = 0;
+       struct dmaengine_unmap_data *unmap = NULL;
 
        BUG_ON(disks < 4);
 
-       if (submit->scribble)
-               dma_src = submit->scribble;
-       else if (sizeof(dma_addr_t) <= sizeof(struct page *))
-               dma_src = (dma_addr_t *) blocks;
+       if (device)
+               unmap = dmaengine_get_unmap_data(device->dev, disks, GFP_NOIO);
 
-       if (dma_src && device && disks <= dma_maxpq(device, 0) &&
+       if (unmap && disks <= dma_maxpq(device, 0) &&
            is_dma_pq_aligned(device, offset, 0, len)) {
                struct device *dev = device->dev;
-               dma_addr_t *pq = &dma_src[disks-2];
-               int i;
+               dma_addr_t pq[2];
+               int i, j = 0, src_cnt = 0;
 
                pr_debug("%s: (async) disks: %d len: %zu\n",
                         __func__, disks, len);
-               if (!P(blocks, disks))
+
+               unmap->len = len;
+               for (i = 0; i < disks-2; i++)
+                       if (likely(blocks[i])) {
+                               unmap->addr[j] = dma_map_page(dev, blocks[i],
+                                                             offset, len,
+                                                             DMA_TO_DEVICE);
+                               coefs[j] = raid6_gfexp[i];
+                               unmap->to_cnt++;
+                               src_cnt++;
+                               j++;
+                       }
+
+               if (!P(blocks, disks)) {
+                       pq[0] = 0;
                        dma_flags |= DMA_PREP_PQ_DISABLE_P;
-               else
+               } else {
                        pq[0] = dma_map_page(dev, P(blocks, disks),
                                             offset, len,
                                             DMA_TO_DEVICE);
-               if (!Q(blocks, disks))
+                       unmap->addr[j++] = pq[0];
+                       unmap->to_cnt++;
+               }
+               if (!Q(blocks, disks)) {
+                       pq[1] = 0;
                        dma_flags |= DMA_PREP_PQ_DISABLE_Q;
-               else
+               } else {
                        pq[1] = dma_map_page(dev, Q(blocks, disks),
                                             offset, len,
                                             DMA_TO_DEVICE);
+                       unmap->addr[j++] = pq[1];
+                       unmap->to_cnt++;
+               }
 
                if (submit->flags & ASYNC_TX_FENCE)
                        dma_flags |= DMA_PREP_FENCE;
-               for (i = 0; i < disks-2; i++)
-                       if (likely(blocks[i])) {
-                               dma_src[src_cnt] = dma_map_page(dev, blocks[i],
-                                                               offset, len,
-                                                               DMA_TO_DEVICE);
-                               coefs[src_cnt] = raid6_gfexp[i];
-                               src_cnt++;
-                       }
-
                for (;;) {
-                       tx = device->device_prep_dma_pq_val(chan, pq, dma_src,
+                       tx = device->device_prep_dma_pq_val(chan, pq,
+                                                           unmap->addr,
                                                            src_cnt,
                                                            coefs,
                                                            len, pqres,
@@ -330,6 +352,8 @@ async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
                        async_tx_quiesce(&submit->depend_tx);
                        dma_async_issue_pending(chan);
                }
+
+               dma_set_unmap(tx, unmap);
                async_tx_submit(chan, tx, submit);
 
                return tx;
index a9f08a6a582ebccce298f718d0bbf5db8b1e1a7a..934a849814958e6ea37b9dbdb96abc820c4fe9e1 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/raid/pq.h>
 #include <linux/async_tx.h>
+#include <linux/dmaengine.h>
 
 static struct dma_async_tx_descriptor *
 async_sum_product(struct page *dest, struct page **srcs, unsigned char *coef,
@@ -34,35 +35,45 @@ async_sum_product(struct page *dest, struct page **srcs, unsigned char *coef,
        struct dma_chan *chan = async_tx_find_channel(submit, DMA_PQ,
                                                      &dest, 1, srcs, 2, len);
        struct dma_device *dma = chan ? chan->device : NULL;
+       struct dmaengine_unmap_data *unmap = NULL;
        const u8 *amul, *bmul;
        u8 ax, bx;
        u8 *a, *b, *c;
 
-       if (dma) {
-               dma_addr_t dma_dest[2];
-               dma_addr_t dma_src[2];
+       if (dma)
+               unmap = dmaengine_get_unmap_data(dma->dev, 3, GFP_NOIO);
+
+       if (unmap) {
                struct device *dev = dma->dev;
+               dma_addr_t pq[2];
                struct dma_async_tx_descriptor *tx;
                enum dma_ctrl_flags dma_flags = DMA_PREP_PQ_DISABLE_P;
 
                if (submit->flags & ASYNC_TX_FENCE)
                        dma_flags |= DMA_PREP_FENCE;
-               dma_dest[1] = dma_map_page(dev, dest, 0, len, DMA_BIDIRECTIONAL);
-               dma_src[0] = dma_map_page(dev, srcs[0], 0, len, DMA_TO_DEVICE);
-               dma_src[1] = dma_map_page(dev, srcs[1], 0, len, DMA_TO_DEVICE);
-               tx = dma->device_prep_dma_pq(chan, dma_dest, dma_src, 2, coef,
+               unmap->addr[0] = dma_map_page(dev, srcs[0], 0, len, DMA_TO_DEVICE);
+               unmap->addr[1] = dma_map_page(dev, srcs[1], 0, len, DMA_TO_DEVICE);
+               unmap->to_cnt = 2;
+
+               unmap->addr[2] = dma_map_page(dev, dest, 0, len, DMA_BIDIRECTIONAL);
+               unmap->bidi_cnt = 1;
+               /* engine only looks at Q, but expects it to follow P */
+               pq[1] = unmap->addr[2];
+
+               unmap->len = len;
+               tx = dma->device_prep_dma_pq(chan, pq, unmap->addr, 2, coef,
                                             len, dma_flags);
                if (tx) {
+                       dma_set_unmap(tx, unmap);
                        async_tx_submit(chan, tx, submit);
+                       dmaengine_unmap_put(unmap);
                        return tx;
                }
 
                /* could not get a descriptor, unmap and fall through to
                 * the synchronous path
                 */
-               dma_unmap_page(dev, dma_dest[1], len, DMA_BIDIRECTIONAL);
-               dma_unmap_page(dev, dma_src[0], len, DMA_TO_DEVICE);
-               dma_unmap_page(dev, dma_src[1], len, DMA_TO_DEVICE);
+               dmaengine_unmap_put(unmap);
        }
 
        /* run the operation synchronously */
@@ -89,23 +100,38 @@ async_mult(struct page *dest, struct page *src, u8 coef, size_t len,
        struct dma_chan *chan = async_tx_find_channel(submit, DMA_PQ,
                                                      &dest, 1, &src, 1, len);
        struct dma_device *dma = chan ? chan->device : NULL;
+       struct dmaengine_unmap_data *unmap = NULL;
        const u8 *qmul; /* Q multiplier table */
        u8 *d, *s;
 
-       if (dma) {
+       if (dma)
+               unmap = dmaengine_get_unmap_data(dma->dev, 3, GFP_NOIO);
+
+       if (unmap) {
                dma_addr_t dma_dest[2];
-               dma_addr_t dma_src[1];
                struct device *dev = dma->dev;
                struct dma_async_tx_descriptor *tx;
                enum dma_ctrl_flags dma_flags = DMA_PREP_PQ_DISABLE_P;
 
                if (submit->flags & ASYNC_TX_FENCE)
                        dma_flags |= DMA_PREP_FENCE;
-               dma_dest[1] = dma_map_page(dev, dest, 0, len, DMA_BIDIRECTIONAL);
-               dma_src[0] = dma_map_page(dev, src, 0, len, DMA_TO_DEVICE);
-               tx = dma->device_prep_dma_pq(chan, dma_dest, dma_src, 1, &coef,
-                                            len, dma_flags);
+               unmap->addr[0] = dma_map_page(dev, src, 0, len, DMA_TO_DEVICE);
+               unmap->to_cnt++;
+               unmap->addr[1] = dma_map_page(dev, dest, 0, len, DMA_BIDIRECTIONAL);
+               dma_dest[1] = unmap->addr[1];
+               unmap->bidi_cnt++;
+               unmap->len = len;
+
+               /* this looks funny, but the engine looks for Q at
+                * dma_dest[1] and ignores dma_dest[0] as a dest
+                * due to DMA_PREP_PQ_DISABLE_P
+                */
+               tx = dma->device_prep_dma_pq(chan, dma_dest, unmap->addr,
+                                            1, &coef, len, dma_flags);
+
                if (tx) {
+                       dma_set_unmap(tx, unmap);
+                       dmaengine_unmap_put(unmap);
                        async_tx_submit(chan, tx, submit);
                        return tx;
                }
@@ -113,8 +139,7 @@ async_mult(struct page *dest, struct page *src, u8 coef, size_t len,
                /* could not get a descriptor, unmap and fall through to
                 * the synchronous path
                 */
-               dma_unmap_page(dev, dma_dest[1], len, DMA_BIDIRECTIONAL);
-               dma_unmap_page(dev, dma_src[0], len, DMA_TO_DEVICE);
+               dmaengine_unmap_put(unmap);
        }
 
        /* no channel available, or failed to allocate a descriptor, so
index 7be34248b450896cfc056d1709513df4f172f79a..39ea4791a3c977ad7eda47498b9f7d7741b438e2 100644 (file)
@@ -128,7 +128,7 @@ async_tx_channel_switch(struct dma_async_tx_descriptor *depend_tx,
                }
                device->device_issue_pending(chan);
        } else {
-               if (dma_wait_for_async_tx(depend_tx) != DMA_SUCCESS)
+               if (dma_wait_for_async_tx(depend_tx) != DMA_COMPLETE)
                        panic("%s: DMA error waiting for depend_tx\n",
                              __func__);
                tx->tx_submit(tx);
@@ -280,7 +280,7 @@ void async_tx_quiesce(struct dma_async_tx_descriptor **tx)
                 * we are referring to the correct operation
                 */
                BUG_ON(async_tx_test_ack(*tx));
-               if (dma_wait_for_async_tx(*tx) != DMA_SUCCESS)
+               if (dma_wait_for_async_tx(*tx) != DMA_COMPLETE)
                        panic("%s: DMA error waiting for transaction\n",
                              __func__);
                async_tx_ack(*tx);
index 8ade0a0481c67149e72d7878deb306a0fd33e5c2..3c562f5a60bbb34f19e6b90f4d858b04d3d496e2 100644 (file)
 
 /* do_async_xor - dma map the pages and perform the xor with an engine */
 static __async_inline struct dma_async_tx_descriptor *
-do_async_xor(struct dma_chan *chan, struct page *dest, struct page **src_list,
-            unsigned int offset, int src_cnt, size_t len, dma_addr_t *dma_src,
+do_async_xor(struct dma_chan *chan, struct dmaengine_unmap_data *unmap,
             struct async_submit_ctl *submit)
 {
        struct dma_device *dma = chan->device;
        struct dma_async_tx_descriptor *tx = NULL;
-       int src_off = 0;
-       int i;
        dma_async_tx_callback cb_fn_orig = submit->cb_fn;
        void *cb_param_orig = submit->cb_param;
        enum async_tx_flags flags_orig = submit->flags;
-       enum dma_ctrl_flags dma_flags;
-       int xor_src_cnt = 0;
-       dma_addr_t dma_dest;
-
-       /* map the dest bidrectional in case it is re-used as a source */
-       dma_dest = dma_map_page(dma->dev, dest, offset, len, DMA_BIDIRECTIONAL);
-       for (i = 0; i < src_cnt; i++) {
-               /* only map the dest once */
-               if (!src_list[i])
-                       continue;
-               if (unlikely(src_list[i] == dest)) {
-                       dma_src[xor_src_cnt++] = dma_dest;
-                       continue;
-               }
-               dma_src[xor_src_cnt++] = dma_map_page(dma->dev, src_list[i], offset,
-                                                     len, DMA_TO_DEVICE);
-       }
-       src_cnt = xor_src_cnt;
+       enum dma_ctrl_flags dma_flags = 0;
+       int src_cnt = unmap->to_cnt;
+       int xor_src_cnt;
+       dma_addr_t dma_dest = unmap->addr[unmap->to_cnt];
+       dma_addr_t *src_list = unmap->addr;
 
        while (src_cnt) {
+               dma_addr_t tmp;
+
                submit->flags = flags_orig;
-               dma_flags = 0;
                xor_src_cnt = min(src_cnt, (int)dma->max_xor);
-               /* if we are submitting additional xors, leave the chain open,
-                * clear the callback parameters, and leave the destination
-                * buffer mapped
+               /* if we are submitting additional xors, leave the chain open
+                * and clear the callback parameters
                 */
                if (src_cnt > xor_src_cnt) {
                        submit->flags &= ~ASYNC_TX_ACK;
                        submit->flags |= ASYNC_TX_FENCE;
-                       dma_flags = DMA_COMPL_SKIP_DEST_UNMAP;
                        submit->cb_fn = NULL;
                        submit->cb_param = NULL;
                } else {
@@ -85,12 +68,18 @@ do_async_xor(struct dma_chan *chan, struct page *dest, struct page **src_list,
                        dma_flags |= DMA_PREP_INTERRUPT;
                if (submit->flags & ASYNC_TX_FENCE)
                        dma_flags |= DMA_PREP_FENCE;
-               /* Since we have clobbered the src_list we are committed
-                * to doing this asynchronously.  Drivers force forward progress
-                * in case they can not provide a descriptor
+
+               /* Drivers force forward progress in case they can not provide a
+                * descriptor
                 */
-               tx = dma->device_prep_dma_xor(chan, dma_dest, &dma_src[src_off],
-                                             xor_src_cnt, len, dma_flags);
+               tmp = src_list[0];
+               if (src_list > unmap->addr)
+                       src_list[0] = dma_dest;
+               tx = dma->device_prep_dma_xor(chan, dma_dest, src_list,
+                                             xor_src_cnt, unmap->len,
+                                             dma_flags);
+               src_list[0] = tmp;
+
 
                if (unlikely(!tx))
                        async_tx_quiesce(&submit->depend_tx);
@@ -99,22 +88,21 @@ do_async_xor(struct dma_chan *chan, struct page *dest, struct page **src_list,
                while (unlikely(!tx)) {
                        dma_async_issue_pending(chan);
                        tx = dma->device_prep_dma_xor(chan, dma_dest,
-                                                     &dma_src[src_off],
-                                                     xor_src_cnt, len,
+                                                     src_list,
+                                                     xor_src_cnt, unmap->len,
                                                      dma_flags);
                }
 
+               dma_set_unmap(tx, unmap);
                async_tx_submit(chan, tx, submit);
                submit->depend_tx = tx;
 
                if (src_cnt > xor_src_cnt) {
                        /* drop completed sources */
                        src_cnt -= xor_src_cnt;
-                       src_off += xor_src_cnt;
-
                        /* use the intermediate result a source */
-                       dma_src[--src_off] = dma_dest;
                        src_cnt++;
+                       src_list += xor_src_cnt - 1;
                } else
                        break;
        }
@@ -189,22 +177,40 @@ async_xor(struct page *dest, struct page **src_list, unsigned int offset,
        struct dma_chan *chan = async_tx_find_channel(submit, DMA_XOR,
                                                      &dest, 1, src_list,
                                                      src_cnt, len);
-       dma_addr_t *dma_src = NULL;
+       struct dma_device *device = chan ? chan->device : NULL;
+       struct dmaengine_unmap_data *unmap = NULL;
 
        BUG_ON(src_cnt <= 1);
 
-       if (submit->scribble)
-               dma_src = submit->scribble;
-       else if (sizeof(dma_addr_t) <= sizeof(struct page *))
-               dma_src = (dma_addr_t *) src_list;
+       if (device)
+               unmap = dmaengine_get_unmap_data(device->dev, src_cnt+1, GFP_NOIO);
+
+       if (unmap && is_dma_xor_aligned(device, offset, 0, len)) {
+               struct dma_async_tx_descriptor *tx;
+               int i, j;
 
-       if (dma_src && chan && is_dma_xor_aligned(chan->device, offset, 0, len)) {
                /* run the xor asynchronously */
                pr_debug("%s (async): len: %zu\n", __func__, len);
 
-               return do_async_xor(chan, dest, src_list, offset, src_cnt, len,
-                                   dma_src, submit);
+               unmap->len = len;
+               for (i = 0, j = 0; i < src_cnt; i++) {
+                       if (!src_list[i])
+                               continue;
+                       unmap->to_cnt++;
+                       unmap->addr[j++] = dma_map_page(device->dev, src_list[i],
+                                                       offset, len, DMA_TO_DEVICE);
+               }
+
+               /* map it bidirectional as it may be re-used as a source */
+               unmap->addr[j] = dma_map_page(device->dev, dest, offset, len,
+                                             DMA_BIDIRECTIONAL);
+               unmap->bidi_cnt = 1;
+
+               tx = do_async_xor(chan, unmap, submit);
+               dmaengine_unmap_put(unmap);
+               return tx;
        } else {
+               dmaengine_unmap_put(unmap);
                /* run the xor synchronously */
                pr_debug("%s (sync): len: %zu\n", __func__, len);
                WARN_ONCE(chan, "%s: no space for dma address conversion\n",
@@ -268,16 +274,14 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
        struct dma_chan *chan = xor_val_chan(submit, dest, src_list, src_cnt, len);
        struct dma_device *device = chan ? chan->device : NULL;
        struct dma_async_tx_descriptor *tx = NULL;
-       dma_addr_t *dma_src = NULL;
+       struct dmaengine_unmap_data *unmap = NULL;
 
        BUG_ON(src_cnt <= 1);
 
-       if (submit->scribble)
-               dma_src = submit->scribble;
-       else if (sizeof(dma_addr_t) <= sizeof(struct page *))
-               dma_src = (dma_addr_t *) src_list;
+       if (device)
+               unmap = dmaengine_get_unmap_data(device->dev, src_cnt, GFP_NOIO);
 
-       if (dma_src && device && src_cnt <= device->max_xor &&
+       if (unmap && src_cnt <= device->max_xor &&
            is_dma_xor_aligned(device, offset, 0, len)) {
                unsigned long dma_prep_flags = 0;
                int i;
@@ -288,11 +292,15 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
                        dma_prep_flags |= DMA_PREP_INTERRUPT;
                if (submit->flags & ASYNC_TX_FENCE)
                        dma_prep_flags |= DMA_PREP_FENCE;
-               for (i = 0; i < src_cnt; i++)
-                       dma_src[i] = dma_map_page(device->dev, src_list[i],
-                                                 offset, len, DMA_TO_DEVICE);
 
-               tx = device->device_prep_dma_xor_val(chan, dma_src, src_cnt,
+               for (i = 0; i < src_cnt; i++) {
+                       unmap->addr[i] = dma_map_page(device->dev, src_list[i],
+                                                     offset, len, DMA_TO_DEVICE);
+                       unmap->to_cnt++;
+               }
+               unmap->len = len;
+
+               tx = device->device_prep_dma_xor_val(chan, unmap->addr, src_cnt,
                                                     len, result,
                                                     dma_prep_flags);
                if (unlikely(!tx)) {
@@ -301,11 +309,11 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
                        while (!tx) {
                                dma_async_issue_pending(chan);
                                tx = device->device_prep_dma_xor_val(chan,
-                                       dma_src, src_cnt, len, result,
+                                       unmap->addr, src_cnt, len, result,
                                        dma_prep_flags);
                        }
                }
-
+               dma_set_unmap(tx, unmap);
                async_tx_submit(chan, tx, submit);
        } else {
                enum async_tx_flags flags_orig = submit->flags;
@@ -327,6 +335,7 @@ async_xor_val(struct page *dest, struct page **src_list, unsigned int offset,
                async_tx_sync_epilog(submit);
                submit->flags = flags_orig;
        }
+       dmaengine_unmap_put(unmap);
 
        return tx;
 }
index 4a92bac744dce500a209f5e4e6033d465eff5dc9..dad95f45b88f6566afc62df645151d3a2ae60092 100644 (file)
@@ -28,7 +28,7 @@
 #undef pr
 #define pr(fmt, args...) pr_info("raid6test: " fmt, ##args)
 
-#define NDISKS 16 /* Including P and Q */
+#define NDISKS 64 /* Including P and Q */
 
 static struct page *dataptrs[NDISKS];
 static addr_conv_t addr_conv[NDISKS];
@@ -219,6 +219,14 @@ static int raid6_test(void)
                err += test(11, &tests);
                err += test(12, &tests);
        }
+
+       /* the 24 disk case is special for ioatdma as it is the boudary point
+        * at which it needs to switch from 8-source ops to 16-source
+        * ops for continuation (assumes DMA_HAS_PQ_CONTINUE is not set)
+        */
+       if (NDISKS > 24)
+               err += test(24, &tests);
+
        err += test(NDISKS, &tests);
 
        pr("\n");
index c95df0b8c8808e505f9dbfc7c8bcc68da48af57d..5d9248526d780b06c51bee967cdd088c9c90e5e5 100644 (file)
@@ -235,17 +235,6 @@ config ACPI_INITRD_TABLE_OVERRIDE
          initrd, therefore it's safe to say Y.
          See Documentation/acpi/initrd_table_override.txt for details
 
-config ACPI_BLACKLIST_YEAR
-       int "Disable ACPI for systems before Jan 1st this year" if X86_32
-       default 0
-       help
-         Enter a 4-digit year, e.g., 2001, to disable ACPI by default
-         on platforms with DMI BIOS date before January 1st that year.
-         "acpi=force" can be used to override this mechanism.
-
-         Enter 0 to disable this mechanism and allow ACPI to
-         run by default no matter what the year.  (default)
-
 config ACPI_DEBUG
        bool "Debug Statements"
        default n
index b9f0d5f4bba51cecb6ffe8fda126762850818263..8711e3797165fa73fd0c401cedbb54c61eb68e4a 100644 (file)
@@ -56,7 +56,6 @@ static int ac_sleep_before_get_state_ms;
 
 struct acpi_ac {
        struct power_supply charger;
-       struct acpi_device *adev;
        struct platform_device *pdev;
        unsigned long long state;
 };
@@ -70,8 +69,9 @@ struct acpi_ac {
 static int acpi_ac_get_state(struct acpi_ac *ac)
 {
        acpi_status status;
+       acpi_handle handle = ACPI_HANDLE(&ac->pdev->dev);
 
-       status = acpi_evaluate_integer(ac->adev->handle, "_PSR", NULL,
+       status = acpi_evaluate_integer(handle, "_PSR", NULL,
                                       &ac->state);
        if (ACPI_FAILURE(status)) {
                ACPI_EXCEPTION((AE_INFO, status,
@@ -119,6 +119,7 @@ static enum power_supply_property ac_props[] = {
 static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data)
 {
        struct acpi_ac *ac = data;
+       struct acpi_device *adev;
 
        if (!ac)
                return;
@@ -141,10 +142,11 @@ static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data)
                        msleep(ac_sleep_before_get_state_ms);
 
                acpi_ac_get_state(ac);
-               acpi_bus_generate_netlink_event(ac->adev->pnp.device_class,
+               adev = ACPI_COMPANION(&ac->pdev->dev);
+               acpi_bus_generate_netlink_event(adev->pnp.device_class,
                                                dev_name(&ac->pdev->dev),
                                                event, (u32) ac->state);
-               acpi_notifier_call_chain(ac->adev, event, (u32) ac->state);
+               acpi_notifier_call_chain(adev, event, (u32) ac->state);
                kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
        }
 
@@ -178,8 +180,8 @@ static int acpi_ac_probe(struct platform_device *pdev)
        if (!pdev)
                return -EINVAL;
 
-       result = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
-       if (result)
+       adev = ACPI_COMPANION(&pdev->dev);
+       if (!adev)
                return -ENODEV;
 
        ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
@@ -188,7 +190,6 @@ static int acpi_ac_probe(struct platform_device *pdev)
 
        strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
        strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
-       ac->adev = adev;
        ac->pdev = pdev;
        platform_set_drvdata(pdev, ac);
 
index d3961014aad7ff9d77bcb296ec2f851f96d64b5b..6745fe137b9ea541ae729429035eaeca8fc8fc07 100644 (file)
@@ -163,6 +163,15 @@ static const struct acpi_device_id acpi_lpss_device_ids[] = {
        { "80860F41", (unsigned long)&byt_i2c_dev_desc },
        { "INT33B2", },
 
+       { "INT3430", (unsigned long)&lpt_dev_desc },
+       { "INT3431", (unsigned long)&lpt_dev_desc },
+       { "INT3432", (unsigned long)&lpt_dev_desc },
+       { "INT3433", (unsigned long)&lpt_dev_desc },
+       { "INT3434", (unsigned long)&lpt_uart_dev_desc },
+       { "INT3435", (unsigned long)&lpt_uart_dev_desc },
+       { "INT3436", (unsigned long)&lpt_sdio_dev_desc },
+       { "INT3437", },
+
        { }
 };
 
index 8a4cfc7e71f0f83cc7a8644e75eab627c8e3c52d..dbfe49e5fd63cc179559b2c5caee57d27324c012 100644 (file)
@@ -111,7 +111,7 @@ int acpi_create_platform_device(struct acpi_device *adev,
        pdevinfo.id = -1;
        pdevinfo.res = resources;
        pdevinfo.num_res = count;
-       pdevinfo.acpi_node.handle = adev->handle;
+       pdevinfo.acpi_node.companion = adev;
        pdev = platform_device_register_full(&pdevinfo);
        if (IS_ERR(pdev)) {
                dev_err(&adev->dev, "platform device creation failed: %ld\n",
index 13e045025c3366f00e4912aa1063f538d44f4687..517af700399da1e0c8f16c96baab96e7cad6299b 100644 (file)
@@ -356,7 +356,7 @@ u8 acpi_ut_valid_internal_object(void *object)
        default:
 
                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
-                                 "%p is not not an ACPI operand obj [%s]\n",
+                                 "%p is not an ACPI operand obj [%s]\n",
                                  object, acpi_ut_get_descriptor_name(object)));
                break;
        }
index fb848378d5824691af9e84b4f100a01e47df7d39..078c4f7fe2dd97c42d3e13ea11ebde804e3ae4f0 100644 (file)
@@ -75,39 +75,6 @@ static struct acpi_blacklist_item acpi_blacklist[] __initdata = {
        {""}
 };
 
-#if    CONFIG_ACPI_BLACKLIST_YEAR
-
-static int __init blacklist_by_year(void)
-{
-       int year;
-
-       /* Doesn't exist? Likely an old system */
-       if (!dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL)) {
-               printk(KERN_ERR PREFIX "no DMI BIOS year, "
-                       "acpi=force is required to enable ACPI\n" );
-               return 1;
-       }
-       /* 0? Likely a buggy new BIOS */
-       if (year == 0) {
-               printk(KERN_ERR PREFIX "DMI BIOS year==0, "
-                       "assuming ACPI-capable machine\n" );
-               return 0;
-       }
-       if (year < CONFIG_ACPI_BLACKLIST_YEAR) {
-               printk(KERN_ERR PREFIX "BIOS age (%d) fails cutoff (%d), "
-                      "acpi=force is required to enable ACPI\n",
-                      year, CONFIG_ACPI_BLACKLIST_YEAR);
-               return 1;
-       }
-       return 0;
-}
-#else
-static inline int blacklist_by_year(void)
-{
-       return 0;
-}
-#endif
-
 int __init acpi_blacklisted(void)
 {
        int i = 0;
@@ -166,8 +133,6 @@ int __init acpi_blacklisted(void)
                }
        }
 
-       blacklisted += blacklist_by_year();
-
        dmi_check_system(acpi_osi_dmi_table);
 
        return blacklisted;
index d42b2fb5a7e94131ce2633ef95f4d7631729325f..b3480cf7db1a1d1eba0e8d884cb456f92b76b660 100644 (file)
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
 
-#include <linux/device.h>
+#include <linux/acpi.h>
 #include <linux/export.h>
 #include <linux/mutex.h>
 #include <linux/pm_qos.h>
 #include <linux/pm_runtime.h>
 
-#include <acpi/acpi.h>
-#include <acpi/acpi_bus.h>
-#include <acpi/acpi_drivers.h>
-
 #include "internal.h"
 
 #define _COMPONENT     ACPI_POWER_COMPONENT
@@ -548,7 +544,7 @@ static int acpi_dev_pm_get_state(struct device *dev, struct acpi_device *adev,
  */
 int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
 {
-       acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
+       acpi_handle handle = ACPI_HANDLE(dev);
        struct acpi_device *adev;
        int ret, d_min, d_max;
 
@@ -656,7 +652,7 @@ int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
        if (!device_run_wake(phys_dev))
                return -EINVAL;
 
-       handle = DEVICE_ACPI_HANDLE(phys_dev);
+       handle = ACPI_HANDLE(phys_dev);
        if (!handle || acpi_bus_get_device(handle, &adev)) {
                dev_dbg(phys_dev, "ACPI handle without context in %s!\n",
                        __func__);
@@ -700,7 +696,7 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
        if (!device_can_wakeup(dev))
                return -EINVAL;
 
-       handle = DEVICE_ACPI_HANDLE(dev);
+       handle = ACPI_HANDLE(dev);
        if (!handle || acpi_bus_get_device(handle, &adev)) {
                dev_dbg(dev, "ACPI handle without context in %s!\n", __func__);
                return -ENODEV;
@@ -722,7 +718,7 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
  */
 struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
 {
-       acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
+       acpi_handle handle = ACPI_HANDLE(dev);
        struct acpi_device *adev;
 
        return handle && !acpi_bus_get_device(handle, &adev) ? adev : NULL;
index d5309fd494589b4d1596cb1c03576ed1e7ef252e..ba5b56db9d27c7fafa3b19c6d1f5d2549308aea6 100644 (file)
@@ -173,9 +173,10 @@ static void start_transaction(struct acpi_ec *ec)
 static void advance_transaction(struct acpi_ec *ec, u8 status)
 {
        unsigned long flags;
-       struct transaction *t = ec->curr;
+       struct transaction *t;
 
        spin_lock_irqsave(&ec->lock, flags);
+       t = ec->curr;
        if (!t)
                goto unlock;
        if (t->wlen > t->wi) {
index fdef416c0ff6f0384e107466b47b1ff8f2bac9aa..cae3b387b867a99ab7013cfc2b731b2125abc961 100644 (file)
@@ -78,15 +78,17 @@ enum {
 #define ACPI_GENL_VERSION              0x01
 #define ACPI_GENL_MCAST_GROUP_NAME     "acpi_mc_group"
 
+static const struct genl_multicast_group acpi_event_mcgrps[] = {
+       { .name = ACPI_GENL_MCAST_GROUP_NAME, },
+};
+
 static struct genl_family acpi_event_genl_family = {
        .id = GENL_ID_GENERATE,
        .name = ACPI_GENL_FAMILY_NAME,
        .version = ACPI_GENL_VERSION,
        .maxattr = ACPI_GENL_ATTR_MAX,
-};
-
-static struct genl_multicast_group acpi_event_mcgrp = {
-       .name = ACPI_GENL_MCAST_GROUP_NAME,
+       .mcgrps = acpi_event_mcgrps,
+       .n_mcgrps = ARRAY_SIZE(acpi_event_mcgrps),
 };
 
 int acpi_bus_generate_netlink_event(const char *device_class,
@@ -141,7 +143,7 @@ int acpi_bus_generate_netlink_event(const char *device_class,
                return result;
        }
 
-       genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
+       genlmsg_multicast(&acpi_event_genl_family, skb, 0, 0, GFP_ATOMIC);
        return 0;
 }
 
@@ -149,18 +151,7 @@ EXPORT_SYMBOL(acpi_bus_generate_netlink_event);
 
 static int acpi_event_genetlink_init(void)
 {
-       int result;
-
-       result = genl_register_family(&acpi_event_genl_family);
-       if (result)
-               return result;
-
-       result = genl_register_mc_group(&acpi_event_genl_family,
-                                       &acpi_event_mcgrp);
-       if (result)
-               genl_unregister_family(&acpi_event_genl_family);
-
-       return result;
+       return genl_register_family(&acpi_event_genl_family);
 }
 
 #else
index 10f0f40587bb73309eee9e959fc1049cbaf6dc05..a22a295edb692347f16066bff26d145973ab2523 100644 (file)
@@ -197,30 +197,28 @@ static void acpi_physnode_link_name(char *buf, unsigned int node_id)
 
 int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
-       struct acpi_device *acpi_dev;
-       acpi_status status;
+       struct acpi_device *acpi_dev = NULL;
        struct acpi_device_physical_node *physical_node, *pn;
        char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
        struct list_head *physnode_list;
        unsigned int node_id;
        int retval = -EINVAL;
 
-       if (ACPI_HANDLE(dev)) {
+       if (ACPI_COMPANION(dev)) {
                if (handle) {
-                       dev_warn(dev, "ACPI handle is already set\n");
+                       dev_warn(dev, "ACPI companion already set\n");
                        return -EINVAL;
                } else {
-                       handle = ACPI_HANDLE(dev);
+                       acpi_dev = ACPI_COMPANION(dev);
                }
+       } else {
+               acpi_bus_get_device(handle, &acpi_dev);
        }
-       if (!handle)
+       if (!acpi_dev)
                return -EINVAL;
 
+       get_device(&acpi_dev->dev);
        get_device(dev);
-       status = acpi_bus_get_device(handle, &acpi_dev);
-       if (ACPI_FAILURE(status))
-               goto err;
-
        physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
        if (!physical_node) {
                retval = -ENOMEM;
@@ -242,10 +240,11 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
 
                        dev_warn(dev, "Already associated with ACPI node\n");
                        kfree(physical_node);
-                       if (ACPI_HANDLE(dev) != handle)
+                       if (ACPI_COMPANION(dev) != acpi_dev)
                                goto err;
 
                        put_device(dev);
+                       put_device(&acpi_dev->dev);
                        return 0;
                }
                if (pn->node_id == node_id) {
@@ -259,8 +258,8 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        list_add(&physical_node->node, physnode_list);
        acpi_dev->physical_node_count++;
 
-       if (!ACPI_HANDLE(dev))
-               ACPI_HANDLE_SET(dev, acpi_dev->handle);
+       if (!ACPI_COMPANION(dev))
+               ACPI_COMPANION_SET(dev, acpi_dev);
 
        acpi_physnode_link_name(physical_node_name, node_id);
        retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
@@ -283,27 +282,21 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        return 0;
 
  err:
-       ACPI_HANDLE_SET(dev, NULL);
+       ACPI_COMPANION_SET(dev, NULL);
        put_device(dev);
+       put_device(&acpi_dev->dev);
        return retval;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
 
 int acpi_unbind_one(struct device *dev)
 {
+       struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
        struct acpi_device_physical_node *entry;
-       struct acpi_device *acpi_dev;
-       acpi_status status;
 
-       if (!ACPI_HANDLE(dev))
+       if (!acpi_dev)
                return 0;
 
-       status = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
-       if (ACPI_FAILURE(status)) {
-               dev_err(dev, "Oops, ACPI handle corrupt in %s()\n", __func__);
-               return -EINVAL;
-       }
-
        mutex_lock(&acpi_dev->physical_node_lock);
 
        list_for_each_entry(entry, &acpi_dev->physical_node_list, node)
@@ -316,9 +309,10 @@ int acpi_unbind_one(struct device *dev)
                        acpi_physnode_link_name(physnode_name, entry->node_id);
                        sysfs_remove_link(&acpi_dev->dev.kobj, physnode_name);
                        sysfs_remove_link(&dev->kobj, "firmware_node");
-                       ACPI_HANDLE_SET(dev, NULL);
-                       /* acpi_bind_one() increase refcnt by one. */
+                       ACPI_COMPANION_SET(dev, NULL);
+                       /* Drop references taken by acpi_bind_one(). */
                        put_device(dev);
+                       put_device(&acpi_dev->dev);
                        kfree(entry);
                        break;
                }
@@ -328,6 +322,15 @@ int acpi_unbind_one(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(acpi_unbind_one);
 
+void acpi_preset_companion(struct device *dev, acpi_handle parent, u64 addr)
+{
+       struct acpi_device *adev;
+
+       if (!acpi_bus_get_device(acpi_get_child(parent, addr), &adev))
+               ACPI_COMPANION_SET(dev, adev);
+}
+EXPORT_SYMBOL_GPL(acpi_preset_companion);
+
 static int acpi_platform_notify(struct device *dev)
 {
        struct acpi_bus_type *type = acpi_get_bus_type(dev);
index 56f05869b08df2ab89bafd661d97b282c36d0b8b..0703bff5e60ecaf2f9d207f9ffc1691d50380384 100644 (file)
@@ -575,6 +575,7 @@ static int acpi_pci_root_add(struct acpi_device *device,
                dev_err(&device->dev,
                        "Bus %04x:%02x not present in PCI namespace\n",
                        root->segment, (unsigned int)root->secondary.start);
+               device->driver_data = NULL;
                result = -ENODEV;
                goto end;
        }
index 55f9dedbbf9fedc5aae2cf21852c7474514cd0d1..15daa21fcd056cf75b50eccf34a08482e0e24e8a 100644 (file)
@@ -289,24 +289,17 @@ void acpi_bus_device_eject(void *data, u32 ost_src)
 {
        struct acpi_device *device = data;
        acpi_handle handle = device->handle;
-       struct acpi_scan_handler *handler;
        u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
        int error;
 
        lock_device_hotplug();
        mutex_lock(&acpi_scan_lock);
 
-       handler = device->handler;
-       if (!handler || !handler->hotplug.enabled) {
-               put_device(&device->dev);
-               goto err_support;
-       }
-
        if (ost_src == ACPI_NOTIFY_EJECT_REQUEST)
                acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
                                          ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
 
-       if (handler->hotplug.mode == AHM_CONTAINER)
+       if (device->handler && device->handler->hotplug.mode == AHM_CONTAINER)
                kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
 
        error = acpi_scan_hot_remove(device);
@@ -411,8 +404,7 @@ static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
                break;
        case ACPI_NOTIFY_EJECT_REQUEST:
                acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
-               status = acpi_bus_get_device(handle, &adev);
-               if (ACPI_FAILURE(status))
+               if (acpi_bus_get_device(handle, &adev))
                        goto err_out;
 
                get_device(&adev->dev);
@@ -1997,6 +1989,7 @@ static int acpi_bus_scan_fixed(void)
                if (result)
                        return result;
 
+               device->flags.match_driver = true;
                result = device_attach(&device->dev);
                if (result < 0)
                        return result;
@@ -2013,6 +2006,7 @@ static int acpi_bus_scan_fixed(void)
                if (result)
                        return result;
 
+               device->flags.match_driver = true;
                result = device_attach(&device->dev);
        }
 
index 18dbdff4656e7d6c6b8f665e9fcdb2e22067cf98..995e91bcb97b7b4d5f21d585de1f5a7e46bd9ebd 100644 (file)
@@ -81,13 +81,6 @@ module_param(brightness_switch_enabled, bool, 0644);
 static bool allow_duplicates;
 module_param(allow_duplicates, bool, 0644);
 
-/*
- * Some BIOSes claim they use minimum backlight at boot,
- * and this may bring dimming screen after boot
- */
-static bool use_bios_initial_backlight = 1;
-module_param(use_bios_initial_backlight, bool, 0644);
-
 /*
  * For Windows 8 systems: if set ture and the GPU driver has
  * registered a backlight interface, skip registering ACPI video's.
@@ -406,12 +399,6 @@ static int __init video_set_bqc_offset(const struct dmi_system_id *d)
        return 0;
 }
 
-static int video_ignore_initial_backlight(const struct dmi_system_id *d)
-{
-       use_bios_initial_backlight = 0;
-       return 0;
-}
-
 static struct dmi_system_id video_dmi_table[] __initdata = {
        /*
         * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
@@ -456,54 +443,6 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
                DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"),
                },
        },
-       {
-        .callback = video_ignore_initial_backlight,
-        .ident = "HP Folio 13-2000",
-        .matches = {
-               DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
-               DMI_MATCH(DMI_PRODUCT_NAME, "HP Folio 13 - 2000 Notebook PC"),
-               },
-       },
-       {
-        .callback = video_ignore_initial_backlight,
-        .ident = "Fujitsu E753",
-        .matches = {
-               DMI_MATCH(DMI_BOARD_VENDOR, "FUJITSU"),
-               DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK E753"),
-               },
-       },
-       {
-        .callback = video_ignore_initial_backlight,
-        .ident = "HP Pavilion dm4",
-        .matches = {
-               DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
-               DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion dm4 Notebook PC"),
-               },
-       },
-       {
-        .callback = video_ignore_initial_backlight,
-        .ident = "HP Pavilion g6 Notebook PC",
-        .matches = {
-                DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
-                DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion g6 Notebook PC"),
-               },
-       },
-       {
-        .callback = video_ignore_initial_backlight,
-        .ident = "HP 1000 Notebook PC",
-        .matches = {
-               DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
-               DMI_MATCH(DMI_PRODUCT_NAME, "HP 1000 Notebook PC"),
-               },
-       },
-       {
-        .callback = video_ignore_initial_backlight,
-        .ident = "HP Pavilion m4",
-        .matches = {
-               DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
-               DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion m4 Notebook PC"),
-               },
-       },
        {}
 };
 
@@ -839,20 +778,18 @@ acpi_video_init_brightness(struct acpi_video_device *device)
        if (!device->cap._BQC)
                goto set_level;
 
-       if (use_bios_initial_backlight) {
-               level = acpi_video_bqc_value_to_level(device, level_old);
-               /*
-                * On some buggy laptops, _BQC returns an uninitialized
-                * value when invoked for the first time, i.e.
-                * level_old is invalid (no matter whether it's a level
-                * or an index). Set the backlight to max_level in this case.
-                */
-               for (i = 2; i < br->count; i++)
-                       if (level == br->levels[i])
-                               break;
-               if (i == br->count || !level)
-                       level = max_level;
-       }
+       level = acpi_video_bqc_value_to_level(device, level_old);
+       /*
+        * On some buggy laptops, _BQC returns an uninitialized
+        * value when invoked for the first time, i.e.
+        * level_old is invalid (no matter whether it's a level
+        * or an index). Set the backlight to max_level in this case.
+        */
+       for (i = 2; i < br->count; i++)
+               if (level == br->levels[i])
+                       break;
+       if (i == br->count || !level)
+               level = max_level;
 
 set_level:
        result = acpi_video_device_lcd_set_level(device, level);
index ab714d2ad978644752ca3c9bdff74ae1c9f63934..4372cfa883c9c36cf2624f88186ef3e0e7b27d31 100644 (file)
@@ -185,7 +185,7 @@ void ata_acpi_bind_port(struct ata_port *ap)
        if (libata_noacpi || ap->flags & ATA_FLAG_ACPI_SATA || !host_handle)
                return;
 
-       ACPI_HANDLE_SET(&ap->tdev, acpi_get_child(host_handle, ap->port_no));
+       acpi_preset_companion(&ap->tdev, host_handle, ap->port_no);
 
        if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0)
                ap->pflags |= ATA_PFLAG_INIT_GTM_VALID;
@@ -222,7 +222,7 @@ void ata_acpi_bind_dev(struct ata_device *dev)
                parent_handle = port_handle;
        }
 
-       ACPI_HANDLE_SET(&dev->tdev, acpi_get_child(parent_handle, adr));
+       acpi_preset_companion(&dev->tdev, parent_handle, adr);
 
        register_hotplug_dock_device(ata_dev_acpi_handle(dev),
                                     &ata_acpi_dev_dock_ops, dev, NULL, NULL);
index 853f610af28fbc9dff0ee59d1fa1e6688cbfd732..e88690ebfd827b8a02558c4b611b474a4f8c4a1e 100644 (file)
@@ -396,8 +396,7 @@ dma_xfer(struct arasan_cf_dev *acdev, dma_addr_t src, dma_addr_t dest, u32 len)
        struct dma_async_tx_descriptor *tx;
        struct dma_chan *chan = acdev->dma_chan;
        dma_cookie_t cookie;
-       unsigned long flags = DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP |
-               DMA_COMPL_SKIP_DEST_UNMAP;
+       unsigned long flags = DMA_PREP_INTERRUPT;
        int ret = 0;
 
        tx = chan->device->device_prep_dma_memcpy(chan, dest, src, len, flags);
index 272f00927761b1e34e5676ad018e0f72ef623b8c..1bdf104e90bb7f1924acf51f78caa39817d78efb 100644 (file)
@@ -3511,7 +3511,7 @@ static int init_card(struct atm_dev *dev)
        tmp = dev_get_by_name(&init_net, tname);        /* jhs: was "tmp = dev_get(tname);" */
        if (tmp) {
                memcpy(card->atmdev->esi, tmp->dev_addr, 6);
-
+               dev_put(tmp);
                printk("%s: ESI %pM\n", card->name, card->atmdev->esi);
        }
        /*
index 99802d6f3c60f603efcff5d342ba0c9f4c937ccd..165c2c299e579805a1f234aff9d6ccf6d0c1666c 100644 (file)
@@ -49,7 +49,7 @@ struct cma *dma_contiguous_default_area;
 
 /*
  * Default global CMA area size can be defined in kernel's .config.
- * This is usefull mainly for distro maintainers to create a kernel
+ * This is useful mainly for distro maintainers to create a kernel
  * that works correctly for most supported systems.
  * The size can be set in bytes or as a percentage of the total memory
  * in the system.
index 47051cd251132ce97752bc8f8f9748be272c0f35..3a94b799f16640eb6a8e34ef2df78a31e3085e9c 100644 (file)
@@ -432,7 +432,7 @@ struct platform_device *platform_device_register_full(
                goto err_alloc;
 
        pdev->dev.parent = pdevinfo->parent;
-       ACPI_HANDLE_SET(&pdev->dev, pdevinfo->acpi_node.handle);
+       ACPI_COMPANION_SET(&pdev->dev, pdevinfo->acpi_node.companion);
 
        if (pdevinfo->dma_mask) {
                /*
@@ -463,7 +463,7 @@ struct platform_device *platform_device_register_full(
        ret = platform_device_add(pdev);
        if (ret) {
 err:
-               ACPI_HANDLE_SET(&pdev->dev, NULL);
+               ACPI_COMPANION_SET(&pdev->dev, NULL);
                kfree(pdev->dev.dma_mask);
 
 err_alloc:
index c12e9b9556be7d5d49d5d78c9de09eb39ce8a0f8..1b41fca3d65a54545c6c124e0df696998c29a1af 100644 (file)
@@ -1350,6 +1350,9 @@ static int device_prepare(struct device *dev, pm_message_t state)
 
        device_unlock(dev);
 
+       if (error)
+               pm_runtime_put(dev);
+
        return error;
 }
 
index f3be496ac8fa7d7e445aeeb91560d86810f17a5c..6a680d4de7f1c3dcfa7999e45efc98b4b14d99fc 100644 (file)
 #include <linux/string_helpers.h>
 #include <scsi/scsi_cmnd.h>
 #include <linux/idr.h>
+#include <linux/blk-mq.h>
+#include <linux/numa.h>
 
 #define PART_BITS 4
 
-static bool use_bio;
-module_param(use_bio, bool, S_IRUGO);
-
 static int major;
 static DEFINE_IDA(vd_index_ida);
 
@@ -26,13 +25,11 @@ struct virtio_blk
 {
        struct virtio_device *vdev;
        struct virtqueue *vq;
-       wait_queue_head_t queue_wait;
+       spinlock_t vq_lock;
 
        /* The disk structure for the kernel. */
        struct gendisk *disk;
 
-       mempool_t *pool;
-
        /* Process context for config space updates */
        struct work_struct config_work;
 
@@ -47,31 +44,17 @@ struct virtio_blk
 
        /* Ida index - used to track minor number allocations. */
        int index;
-
-       /* Scatterlist: can be too big for stack. */
-       struct scatterlist sg[/*sg_elems*/];
 };
 
 struct virtblk_req
 {
        struct request *req;
-       struct bio *bio;
        struct virtio_blk_outhdr out_hdr;
        struct virtio_scsi_inhdr in_hdr;
-       struct work_struct work;
-       struct virtio_blk *vblk;
-       int flags;
        u8 status;
        struct scatterlist sg[];
 };
 
-enum {
-       VBLK_IS_FLUSH           = 1,
-       VBLK_REQ_FLUSH          = 2,
-       VBLK_REQ_DATA           = 4,
-       VBLK_REQ_FUA            = 8,
-};
-
 static inline int virtblk_result(struct virtblk_req *vbr)
 {
        switch (vbr->status) {
@@ -84,22 +67,6 @@ static inline int virtblk_result(struct virtblk_req *vbr)
        }
 }
 
-static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,
-                                                   gfp_t gfp_mask)
-{
-       struct virtblk_req *vbr;
-
-       vbr = mempool_alloc(vblk->pool, gfp_mask);
-       if (!vbr)
-               return NULL;
-
-       vbr->vblk = vblk;
-       if (use_bio)
-               sg_init_table(vbr->sg, vblk->sg_elems);
-
-       return vbr;
-}
-
 static int __virtblk_add_req(struct virtqueue *vq,
                             struct virtblk_req *vbr,
                             struct scatterlist *data_sg,
@@ -143,83 +110,8 @@ static int __virtblk_add_req(struct virtqueue *vq,
        return virtqueue_add_sgs(vq, sgs, num_out, num_in, vbr, GFP_ATOMIC);
 }
 
-static void virtblk_add_req(struct virtblk_req *vbr, bool have_data)
-{
-       struct virtio_blk *vblk = vbr->vblk;
-       DEFINE_WAIT(wait);
-       int ret;
-
-       spin_lock_irq(vblk->disk->queue->queue_lock);
-       while (unlikely((ret = __virtblk_add_req(vblk->vq, vbr, vbr->sg,
-                                                have_data)) < 0)) {
-               prepare_to_wait_exclusive(&vblk->queue_wait, &wait,
-                                         TASK_UNINTERRUPTIBLE);
-
-               spin_unlock_irq(vblk->disk->queue->queue_lock);
-               io_schedule();
-               spin_lock_irq(vblk->disk->queue->queue_lock);
-
-               finish_wait(&vblk->queue_wait, &wait);
-       }
-
-       virtqueue_kick(vblk->vq);
-       spin_unlock_irq(vblk->disk->queue->queue_lock);
-}
-
-static void virtblk_bio_send_flush(struct virtblk_req *vbr)
-{
-       vbr->flags |= VBLK_IS_FLUSH;
-       vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
-       vbr->out_hdr.sector = 0;
-       vbr->out_hdr.ioprio = 0;
-
-       virtblk_add_req(vbr, false);
-}
-
-static void virtblk_bio_send_data(struct virtblk_req *vbr)
-{
-       struct virtio_blk *vblk = vbr->vblk;
-       struct bio *bio = vbr->bio;
-       bool have_data;
-
-       vbr->flags &= ~VBLK_IS_FLUSH;
-       vbr->out_hdr.type = 0;
-       vbr->out_hdr.sector = bio->bi_sector;
-       vbr->out_hdr.ioprio = bio_prio(bio);
-
-       if (blk_bio_map_sg(vblk->disk->queue, bio, vbr->sg)) {
-               have_data = true;
-               if (bio->bi_rw & REQ_WRITE)
-                       vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
-               else
-                       vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
-       } else
-               have_data = false;
-
-       virtblk_add_req(vbr, have_data);
-}
-
-static void virtblk_bio_send_data_work(struct work_struct *work)
-{
-       struct virtblk_req *vbr;
-
-       vbr = container_of(work, struct virtblk_req, work);
-
-       virtblk_bio_send_data(vbr);
-}
-
-static void virtblk_bio_send_flush_work(struct work_struct *work)
-{
-       struct virtblk_req *vbr;
-
-       vbr = container_of(work, struct virtblk_req, work);
-
-       virtblk_bio_send_flush(vbr);
-}
-
 static inline void virtblk_request_done(struct virtblk_req *vbr)
 {
-       struct virtio_blk *vblk = vbr->vblk;
        struct request *req = vbr->req;
        int error = virtblk_result(vbr);
 
@@ -231,92 +123,45 @@ static inline void virtblk_request_done(struct virtblk_req *vbr)
                req->errors = (error != 0);
        }
 
-       __blk_end_request_all(req, error);
-       mempool_free(vbr, vblk->pool);
-}
-
-static inline void virtblk_bio_flush_done(struct virtblk_req *vbr)
-{
-       struct virtio_blk *vblk = vbr->vblk;
-
-       if (vbr->flags & VBLK_REQ_DATA) {
-               /* Send out the actual write data */
-               INIT_WORK(&vbr->work, virtblk_bio_send_data_work);
-               queue_work(virtblk_wq, &vbr->work);
-       } else {
-               bio_endio(vbr->bio, virtblk_result(vbr));
-               mempool_free(vbr, vblk->pool);
-       }
-}
-
-static inline void virtblk_bio_data_done(struct virtblk_req *vbr)
-{
-       struct virtio_blk *vblk = vbr->vblk;
-
-       if (unlikely(vbr->flags & VBLK_REQ_FUA)) {
-               /* Send out a flush before end the bio */
-               vbr->flags &= ~VBLK_REQ_DATA;
-               INIT_WORK(&vbr->work, virtblk_bio_send_flush_work);
-               queue_work(virtblk_wq, &vbr->work);
-       } else {
-               bio_endio(vbr->bio, virtblk_result(vbr));
-               mempool_free(vbr, vblk->pool);
-       }
-}
-
-static inline void virtblk_bio_done(struct virtblk_req *vbr)
-{
-       if (unlikely(vbr->flags & VBLK_IS_FLUSH))
-               virtblk_bio_flush_done(vbr);
-       else
-               virtblk_bio_data_done(vbr);
+       blk_mq_end_io(req, error);
 }
 
 static void virtblk_done(struct virtqueue *vq)
 {
        struct virtio_blk *vblk = vq->vdev->priv;
-       bool bio_done = false, req_done = false;
+       bool req_done = false;
        struct virtblk_req *vbr;
        unsigned long flags;
        unsigned int len;
 
-       spin_lock_irqsave(vblk->disk->queue->queue_lock, flags);
+       spin_lock_irqsave(&vblk->vq_lock, flags);
        do {
                virtqueue_disable_cb(vq);
                while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) {
-                       if (vbr->bio) {
-                               virtblk_bio_done(vbr);
-                               bio_done = true;
-                       } else {
-                               virtblk_request_done(vbr);
-                               req_done = true;
-                       }
+                       virtblk_request_done(vbr);
+                       req_done = true;
                }
                if (unlikely(virtqueue_is_broken(vq)))
                        break;
        } while (!virtqueue_enable_cb(vq));
+       spin_unlock_irqrestore(&vblk->vq_lock, flags);
+
        /* In case queue is stopped waiting for more buffers. */
        if (req_done)
-               blk_start_queue(vblk->disk->queue);
-       spin_unlock_irqrestore(vblk->disk->queue->queue_lock, flags);
-
-       if (bio_done)
-               wake_up(&vblk->queue_wait);
+               blk_mq_start_stopped_hw_queues(vblk->disk->queue);
 }
 
-static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
-                  struct request *req)
+static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
 {
+       struct virtio_blk *vblk = hctx->queue->queuedata;
+       struct virtblk_req *vbr = req->special;
+       unsigned long flags;
        unsigned int num;
-       struct virtblk_req *vbr;
+       const bool last = (req->cmd_flags & REQ_END) != 0;
 
-       vbr = virtblk_alloc_req(vblk, GFP_ATOMIC);
-       if (!vbr)
-               /* When another request finishes we'll try again. */
-               return false;
+       BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
 
        vbr->req = req;
-       vbr->bio = NULL;
        if (req->cmd_flags & REQ_FLUSH) {
                vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
                vbr->out_hdr.sector = 0;
@@ -344,7 +189,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
                }
        }
 
-       num = blk_rq_map_sg(q, vbr->req, vblk->sg);
+       num = blk_rq_map_sg(hctx->queue, vbr->req, vbr->sg);
        if (num) {
                if (rq_data_dir(vbr->req) == WRITE)
                        vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
@@ -352,63 +197,19 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
                        vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
        }
 
-       if (__virtblk_add_req(vblk->vq, vbr, vblk->sg, num) < 0) {
-               mempool_free(vbr, vblk->pool);
-               return false;
-       }
-
-       return true;
-}
-
-static void virtblk_request(struct request_queue *q)
-{
-       struct virtio_blk *vblk = q->queuedata;
-       struct request *req;
-       unsigned int issued = 0;
-
-       while ((req = blk_peek_request(q)) != NULL) {
-               BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
-
-               /* If this request fails, stop queue and wait for something to
-                  finish to restart it. */
-               if (!do_req(q, vblk, req)) {
-                       blk_stop_queue(q);
-                       break;
-               }
-               blk_start_request(req);
-               issued++;
+       spin_lock_irqsave(&vblk->vq_lock, flags);
+       if (__virtblk_add_req(vblk->vq, vbr, vbr->sg, num) < 0) {
+               virtqueue_kick(vblk->vq);
+               spin_unlock_irqrestore(&vblk->vq_lock, flags);
+               blk_mq_stop_hw_queue(hctx);
+               return BLK_MQ_RQ_QUEUE_BUSY;
        }
 
-       if (issued)
+       if (last)
                virtqueue_kick(vblk->vq);
-}
-
-static void virtblk_make_request(struct request_queue *q, struct bio *bio)
-{
-       struct virtio_blk *vblk = q->queuedata;
-       struct virtblk_req *vbr;
-
-       BUG_ON(bio->bi_phys_segments + 2 > vblk->sg_elems);
-
-       vbr = virtblk_alloc_req(vblk, GFP_NOIO);
-       if (!vbr) {
-               bio_endio(bio, -ENOMEM);
-               return;
-       }
 
-       vbr->bio = bio;
-       vbr->flags = 0;
-       if (bio->bi_rw & REQ_FLUSH)
-               vbr->flags |= VBLK_REQ_FLUSH;
-       if (bio->bi_rw & REQ_FUA)
-               vbr->flags |= VBLK_REQ_FUA;
-       if (bio->bi_size)
-               vbr->flags |= VBLK_REQ_DATA;
-
-       if (unlikely(vbr->flags & VBLK_REQ_FLUSH))
-               virtblk_bio_send_flush(vbr);
-       else
-               virtblk_bio_send_data(vbr);
+       spin_unlock_irqrestore(&vblk->vq_lock, flags);
+       return BLK_MQ_RQ_QUEUE_OK;
 }
 
 /* return id (s/n) string for *disk to *id_str
@@ -673,12 +474,35 @@ static const struct device_attribute dev_attr_cache_type_rw =
        __ATTR(cache_type, S_IRUGO|S_IWUSR,
               virtblk_cache_type_show, virtblk_cache_type_store);
 
+static struct blk_mq_ops virtio_mq_ops = {
+       .queue_rq       = virtio_queue_rq,
+       .map_queue      = blk_mq_map_queue,
+       .alloc_hctx     = blk_mq_alloc_single_hw_queue,
+       .free_hctx      = blk_mq_free_single_hw_queue,
+};
+
+static struct blk_mq_reg virtio_mq_reg = {
+       .ops            = &virtio_mq_ops,
+       .nr_hw_queues   = 1,
+       .queue_depth    = 64,
+       .numa_node      = NUMA_NO_NODE,
+       .flags          = BLK_MQ_F_SHOULD_MERGE,
+};
+
+static void virtblk_init_vbr(void *data, struct blk_mq_hw_ctx *hctx,
+                            struct request *rq, unsigned int nr)
+{
+       struct virtio_blk *vblk = data;
+       struct virtblk_req *vbr = rq->special;
+
+       sg_init_table(vbr->sg, vblk->sg_elems);
+}
+
 static int virtblk_probe(struct virtio_device *vdev)
 {
        struct virtio_blk *vblk;
        struct request_queue *q;
        int err, index;
-       int pool_size;
 
        u64 cap;
        u32 v, blk_size, sg_elems, opt_io_size;
@@ -702,17 +526,14 @@ static int virtblk_probe(struct virtio_device *vdev)
 
        /* We need an extra sg elements at head and tail. */
        sg_elems += 2;
-       vdev->priv = vblk = kmalloc(sizeof(*vblk) +
-                                   sizeof(vblk->sg[0]) * sg_elems, GFP_KERNEL);
+       vdev->priv = vblk = kmalloc(sizeof(*vblk), GFP_KERNEL);
        if (!vblk) {
                err = -ENOMEM;
                goto out_free_index;
        }
 
-       init_waitqueue_head(&vblk->queue_wait);
        vblk->vdev = vdev;
        vblk->sg_elems = sg_elems;
-       sg_init_table(vblk->sg, vblk->sg_elems);
        mutex_init(&vblk->config_lock);
 
        INIT_WORK(&vblk->config_work, virtblk_config_changed_work);
@@ -721,31 +542,27 @@ static int virtblk_probe(struct virtio_device *vdev)
        err = init_vq(vblk);
        if (err)
                goto out_free_vblk;
-
-       pool_size = sizeof(struct virtblk_req);
-       if (use_bio)
-               pool_size += sizeof(struct scatterlist) * sg_elems;
-       vblk->pool = mempool_create_kmalloc_pool(1, pool_size);
-       if (!vblk->pool) {
-               err = -ENOMEM;
-               goto out_free_vq;
-       }
+       spin_lock_init(&vblk->vq_lock);
 
        /* FIXME: How many partitions?  How long is a piece of string? */
        vblk->disk = alloc_disk(1 << PART_BITS);
        if (!vblk->disk) {
                err = -ENOMEM;
-               goto out_mempool;
+               goto out_free_vq;
        }
 
-       q = vblk->disk->queue = blk_init_queue(virtblk_request, NULL);
+       virtio_mq_reg.cmd_size =
+               sizeof(struct virtblk_req) +
+               sizeof(struct scatterlist) * sg_elems;
+
+       q = vblk->disk->queue = blk_mq_init_queue(&virtio_mq_reg, vblk);
        if (!q) {
                err = -ENOMEM;
                goto out_put_disk;
        }
 
-       if (use_bio)
-               blk_queue_make_request(q, virtblk_make_request);
+       blk_mq_init_commands(q, virtblk_init_vbr, vblk);
+
        q->queuedata = vblk;
 
        virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);
@@ -848,8 +665,6 @@ out_del_disk:
        blk_cleanup_queue(vblk->disk->queue);
 out_put_disk:
        put_disk(vblk->disk);
-out_mempool:
-       mempool_destroy(vblk->pool);
 out_free_vq:
        vdev->config->del_vqs(vdev);
 out_free_vblk:
@@ -881,7 +696,6 @@ static void virtblk_remove(struct virtio_device *vdev)
 
        refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
        put_disk(vblk->disk);
-       mempool_destroy(vblk->pool);
        vdev->config->del_vqs(vdev);
        kfree(vblk);
 
@@ -905,10 +719,7 @@ static int virtblk_freeze(struct virtio_device *vdev)
 
        flush_work(&vblk->config_work);
 
-       spin_lock_irq(vblk->disk->queue->queue_lock);
-       blk_stop_queue(vblk->disk->queue);
-       spin_unlock_irq(vblk->disk->queue->queue_lock);
-       blk_sync_queue(vblk->disk->queue);
+       blk_mq_stop_hw_queues(vblk->disk->queue);
 
        vdev->config->del_vqs(vdev);
        return 0;
@@ -921,11 +732,9 @@ static int virtblk_restore(struct virtio_device *vdev)
 
        vblk->config_enable = true;
        ret = init_vq(vdev->priv);
-       if (!ret) {
-               spin_lock_irq(vblk->disk->queue->queue_lock);
-               blk_start_queue(vblk->disk->queue);
-               spin_unlock_irq(vblk->disk->queue->queue_lock);
-       }
+       if (!ret)
+               blk_mq_start_stopped_hw_queues(vblk->disk->queue);
+
        return ret;
 }
 #endif
index 4fe5609eeb72beb69e31ed1e7832585eafe0c591..429b75bb60e810946db46b189c4f7f2e173a204f 100644 (file)
 #include <linux/fips.h>
 #include <linux/ptrace.h>
 #include <linux/kmemcheck.h>
+#include <linux/workqueue.h>
 #include <linux/irq.h>
 
 #include <asm/processor.h>
 /*
  * Configuration information
  */
-#define INPUT_POOL_WORDS 128
-#define OUTPUT_POOL_WORDS 32
-#define SEC_XFER_SIZE 512
-#define EXTRACT_SIZE 10
+#define INPUT_POOL_SHIFT       12
+#define INPUT_POOL_WORDS       (1 << (INPUT_POOL_SHIFT-5))
+#define OUTPUT_POOL_SHIFT      10
+#define OUTPUT_POOL_WORDS      (1 << (OUTPUT_POOL_SHIFT-5))
+#define SEC_XFER_SIZE          512
+#define EXTRACT_SIZE           10
+
+#define DEBUG_RANDOM_BOOT 0
 
 #define LONGS(x) (((x) + sizeof(unsigned long) - 1)/sizeof(unsigned long))
 
+/*
+ * To allow fractional bits to be tracked, the entropy_count field is
+ * denominated in units of 1/8th bits.
+ *
+ * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
+ * credit_entropy_bits() needs to be 64 bits wide.
+ */
+#define ENTROPY_SHIFT 3
+#define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
+
 /*
  * The minimum number of bits of entropy before we wake up a read on
  * /dev/random.  Should be enough to do a significant reseed.
@@ -287,108 +302,100 @@ static int random_read_wakeup_thresh = 64;
  * should wake up processes which are selecting or polling on write
  * access to /dev/random.
  */
-static int random_write_wakeup_thresh = 128;
+static int random_write_wakeup_thresh = 28 * OUTPUT_POOL_WORDS;
 
 /*
- * When the input pool goes over trickle_thresh, start dropping most
- * samples to avoid wasting CPU time and reduce lock contention.
+ * The minimum number of seconds between urandom pool resending.  We
+ * do this to limit the amount of entropy that can be drained from the
+ * input pool even if there are heavy demands on /dev/urandom.
  */
-
-static int trickle_thresh __read_mostly = INPUT_POOL_WORDS * 28;
-
-static DEFINE_PER_CPU(int, trickle_count);
+static int random_min_urandom_seed = 60;
 
 /*
- * A pool of size .poolwords is stirred with a primitive polynomial
- * of degree .poolwords over GF(2).  The taps for various sizes are
- * defined below.  They are chosen to be evenly spaced (minimum RMS
- * distance from evenly spaced; the numbers in the comments are a
- * scaled squared error sum) except for the last tap, which is 1 to
- * get the twisting happening as fast as possible.
+ * Originally, we used a primitive polynomial of degree .poolwords
+ * over GF(2).  The taps for various sizes are defined below.  They
+ * were chosen to be evenly spaced except for the last tap, which is 1
+ * to get the twisting happening as fast as possible.
+ *
+ * For the purposes of better mixing, we use the CRC-32 polynomial as
+ * well to make a (modified) twisted Generalized Feedback Shift
+ * Register.  (See M. Matsumoto & Y. Kurita, 1992.  Twisted GFSR
+ * generators.  ACM Transactions on Modeling and Computer Simulation
+ * 2(3):179-194.  Also see M. Matsumoto & Y. Kurita, 1994.  Twisted
+ * GFSR generators II.  ACM Transactions on Mdeling and Computer
+ * Simulation 4:254-266)
+ *
+ * Thanks to Colin Plumb for suggesting this.
+ *
+ * The mixing operation is much less sensitive than the output hash,
+ * where we use SHA-1.  All that we want of mixing operation is that
+ * it be a good non-cryptographic hash; i.e. it not produce collisions
+ * when fed "random" data of the sort we expect to see.  As long as
+ * the pool state differs for different inputs, we have preserved the
+ * input entropy and done a good job.  The fact that an intelligent
+ * attacker can construct inputs that will produce controlled
+ * alterations to the pool's state is not important because we don't
+ * consider such inputs to contribute any randomness.  The only
+ * property we need with respect to them is that the attacker can't
+ * increase his/her knowledge of the pool's state.  Since all
+ * additions are reversible (knowing the final state and the input,
+ * you can reconstruct the initial state), if an attacker has any
+ * uncertainty about the initial state, he/she can only shuffle that
+ * uncertainty about, but never cause any collisions (which would
+ * decrease the uncertainty).
+ *
+ * Our mixing functions were analyzed by Lacharme, Roeck, Strubel, and
+ * Videau in their paper, "The Linux Pseudorandom Number Generator
+ * Revisited" (see: http://eprint.iacr.org/2012/251.pdf).  In their
+ * paper, they point out that we are not using a true Twisted GFSR,
+ * since Matsumoto & Kurita used a trinomial feedback polynomial (that
+ * is, with only three taps, instead of the six that we are using).
+ * As a result, the resulting polynomial is neither primitive nor
+ * irreducible, and hence does not have a maximal period over
+ * GF(2**32).  They suggest a slight change to the generator
+ * polynomial which improves the resulting TGFSR polynomial to be
+ * irreducible, which we have made here.
  */
 static struct poolinfo {
-       int poolwords;
+       int poolbitshift, poolwords, poolbytes, poolbits, poolfracbits;
+#define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
        int tap1, tap2, tap3, tap4, tap5;
 } poolinfo_table[] = {
-       /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
-       { 128,  103,    76,     51,     25,     1 },
-       /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
-       { 32,   26,     20,     14,     7,      1 },
+       /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
+       /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
+       { S(128),       104,    76,     51,     25,     1 },
+       /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
+       /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
+       { S(32),        26,     19,     14,     7,      1 },
 #if 0
        /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1  -- 115 */
-       { 2048, 1638,   1231,   819,    411,    1 },
+       { S(2048),      1638,   1231,   819,    411,    1 },
 
        /* x^1024 + x^817 + x^615 + x^412 + x^204 + x + 1 -- 290 */
-       { 1024, 817,    615,    412,    204,    1 },
+       { S(1024),      817,    615,    412,    204,    1 },
 
        /* x^1024 + x^819 + x^616 + x^410 + x^207 + x^2 + 1 -- 115 */
-       { 1024, 819,    616,    410,    207,    2 },
+       { S(1024),      819,    616,    410,    207,    2 },
 
        /* x^512 + x^411 + x^308 + x^208 + x^104 + x + 1 -- 225 */
-       { 512,  411,    308,    208,    104,    1 },
+       { S(512),       411,    308,    208,    104,    1 },
 
        /* x^512 + x^409 + x^307 + x^206 + x^102 + x^2 + 1 -- 95 */
-       { 512,  409,    307,    206,    102,    2 },
+       { S(512),       409,    307,    206,    102,    2 },
        /* x^512 + x^409 + x^309 + x^205 + x^103 + x^2 + 1 -- 95 */
-       { 512,  409,    309,    205,    103,    2 },
+       { S(512),       409,    309,    205,    103,    2 },
 
        /* x^256 + x^205 + x^155 + x^101 + x^52 + x + 1 -- 125 */
-       { 256,  205,    155,    101,    52,     1 },
+       { S(256),       205,    155,    101,    52,     1 },
 
        /* x^128 + x^103 + x^78 + x^51 + x^27 + x^2 + 1 -- 70 */
-       { 128,  103,    78,     51,     27,     2 },
+       { S(128),       103,    78,     51,     27,     2 },
 
        /* x^64 + x^52 + x^39 + x^26 + x^14 + x + 1 -- 15 */
-       { 64,   52,     39,     26,     14,     1 },
+       { S(64),        52,     39,     26,     14,     1 },
 #endif
 };
 
-#define POOLBITS       poolwords*32
-#define POOLBYTES      poolwords*4
-
-/*
- * For the purposes of better mixing, we use the CRC-32 polynomial as
- * well to make a twisted Generalized Feedback Shift Reigster
- *
- * (See M. Matsumoto & Y. Kurita, 1992.  Twisted GFSR generators.  ACM
- * Transactions on Modeling and Computer Simulation 2(3):179-194.
- * Also see M. Matsumoto & Y. Kurita, 1994.  Twisted GFSR generators
- * II.  ACM Transactions on Mdeling and Computer Simulation 4:254-266)
- *
- * Thanks to Colin Plumb for suggesting this.
- *
- * We have not analyzed the resultant polynomial to prove it primitive;
- * in fact it almost certainly isn't.  Nonetheless, the irreducible factors
- * of a random large-degree polynomial over GF(2) are more than large enough
- * that periodicity is not a concern.
- *
- * The input hash is much less sensitive than the output hash.  All
- * that we want of it is that it be a good non-cryptographic hash;
- * i.e. it not produce collisions when fed "random" data of the sort
- * we expect to see.  As long as the pool state differs for different
- * inputs, we have preserved the input entropy and done a good job.
- * The fact that an intelligent attacker can construct inputs that
- * will produce controlled alterations to the pool's state is not
- * important because we don't consider such inputs to contribute any
- * randomness.  The only property we need with respect to them is that
- * the attacker can't increase his/her knowledge of the pool's state.
- * Since all additions are reversible (knowing the final state and the
- * input, you can reconstruct the initial state), if an attacker has
- * any uncertainty about the initial state, he/she can only shuffle
- * that uncertainty about, but never cause any collisions (which would
- * decrease the uncertainty).
- *
- * The chosen system lets the state of the pool be (essentially) the input
- * modulo the generator polymnomial.  Now, for random primitive polynomials,
- * this is a universal class of hash functions, meaning that the chance
- * of a collision is limited by the attacker's knowledge of the generator
- * polynomail, so if it is chosen at random, an attacker can never force
- * a collision.  Here, we use a fixed polynomial, but we *can* assume that
- * ###--> it is unknown to the processes generating the input entropy. <-###
- * Because of this important property, this is a good, collision-resistant
- * hash; hash collisions will occur no more often than chance.
- */
-
 /*
  * Static global variables
  */
@@ -396,17 +403,6 @@ static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
 static DECLARE_WAIT_QUEUE_HEAD(random_write_wait);
 static struct fasync_struct *fasync;
 
-static bool debug;
-module_param(debug, bool, 0644);
-#define DEBUG_ENT(fmt, arg...) do { \
-       if (debug) \
-               printk(KERN_DEBUG "random %04d %04d %04d: " \
-               fmt,\
-               input_pool.entropy_count,\
-               blocking_pool.entropy_count,\
-               nonblocking_pool.entropy_count,\
-               ## arg); } while (0)
-
 /**********************************************************************
  *
  * OS independent entropy store.   Here are the functions which handle
@@ -417,23 +413,26 @@ module_param(debug, bool, 0644);
 struct entropy_store;
 struct entropy_store {
        /* read-only data: */
-       struct poolinfo *poolinfo;
+       const struct poolinfo *poolinfo;
        __u32 *pool;
        const char *name;
        struct entropy_store *pull;
-       int limit;
+       struct work_struct push_work;
 
        /* read-write data: */
+       unsigned long last_pulled;
        spinlock_t lock;
-       unsigned add_ptr;
-       unsigned input_rotate;
+       unsigned short add_ptr;
+       unsigned short input_rotate;
        int entropy_count;
        int entropy_total;
        unsigned int initialized:1;
-       bool last_data_init;
+       unsigned int limit:1;
+       unsigned int last_data_init:1;
        __u8 last_data[EXTRACT_SIZE];
 };
 
+static void push_to_pool(struct work_struct *work);
 static __u32 input_pool_data[INPUT_POOL_WORDS];
 static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
 static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
@@ -452,7 +451,9 @@ static struct entropy_store blocking_pool = {
        .limit = 1,
        .pull = &input_pool,
        .lock = __SPIN_LOCK_UNLOCKED(blocking_pool.lock),
-       .pool = blocking_pool_data
+       .pool = blocking_pool_data,
+       .push_work = __WORK_INITIALIZER(blocking_pool.push_work,
+                                       push_to_pool),
 };
 
 static struct entropy_store nonblocking_pool = {
@@ -460,7 +461,9 @@ static struct entropy_store nonblocking_pool = {
        .name = "nonblocking",
        .pull = &input_pool,
        .lock = __SPIN_LOCK_UNLOCKED(nonblocking_pool.lock),
-       .pool = nonblocking_pool_data
+       .pool = nonblocking_pool_data,
+       .push_work = __WORK_INITIALIZER(nonblocking_pool.push_work,
+                                       push_to_pool),
 };
 
 static __u32 const twist_table[8] = {
@@ -498,7 +501,7 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
 
        /* mix one byte at a time to simplify size handling and churn faster */
        while (nbytes--) {
-               w = rol32(*bytes++, input_rotate & 31);
+               w = rol32(*bytes++, input_rotate);
                i = (i - 1) & wordmask;
 
                /* XOR in the various taps */
@@ -518,7 +521,7 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
                 * rotation, so that successive passes spread the
                 * input bits across the pool evenly.
                 */
-               input_rotate += i ? 7 : 14;
+               input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
        }
 
        ACCESS_ONCE(r->input_rotate) = input_rotate;
@@ -561,65 +564,151 @@ struct fast_pool {
  * collector.  It's hardcoded for an 128 bit pool and assumes that any
  * locks that might be needed are taken by the caller.
  */
-static void fast_mix(struct fast_pool *f, const void *in, int nbytes)
+static void fast_mix(struct fast_pool *f, __u32 input[4])
 {
-       const char      *bytes = in;
        __u32           w;
-       unsigned        i = f->count;
        unsigned        input_rotate = f->rotate;
 
-       while (nbytes--) {
-               w = rol32(*bytes++, input_rotate & 31) ^ f->pool[i & 3] ^
-                       f->pool[(i + 1) & 3];
-               f->pool[i & 3] = (w >> 3) ^ twist_table[w & 7];
-               input_rotate += (i++ & 3) ? 7 : 14;
-       }
-       f->count = i;
+       w = rol32(input[0], input_rotate) ^ f->pool[0] ^ f->pool[3];
+       f->pool[0] = (w >> 3) ^ twist_table[w & 7];
+       input_rotate = (input_rotate + 14) & 31;
+       w = rol32(input[1], input_rotate) ^ f->pool[1] ^ f->pool[0];
+       f->pool[1] = (w >> 3) ^ twist_table[w & 7];
+       input_rotate = (input_rotate + 7) & 31;
+       w = rol32(input[2], input_rotate) ^ f->pool[2] ^ f->pool[1];
+       f->pool[2] = (w >> 3) ^ twist_table[w & 7];
+       input_rotate = (input_rotate + 7) & 31;
+       w = rol32(input[3], input_rotate) ^ f->pool[3] ^ f->pool[2];
+       f->pool[3] = (w >> 3) ^ twist_table[w & 7];
+       input_rotate = (input_rotate + 7) & 31;
+
        f->rotate = input_rotate;
+       f->count++;
 }
 
 /*
- * Credit (or debit) the entropy store with n bits of entropy
+ * Credit (or debit) the entropy store with n bits of entropy.
+ * Use credit_entropy_bits_safe() if the value comes from userspace
+ * or otherwise should be checked for extreme values.
  */
 static void credit_entropy_bits(struct entropy_store *r, int nbits)
 {
        int entropy_count, orig;
+       const int pool_size = r->poolinfo->poolfracbits;
+       int nfrac = nbits << ENTROPY_SHIFT;
 
        if (!nbits)
                return;
 
-       DEBUG_ENT("added %d entropy credits to %s\n", nbits, r->name);
 retry:
        entropy_count = orig = ACCESS_ONCE(r->entropy_count);
-       entropy_count += nbits;
+       if (nfrac < 0) {
+               /* Debit */
+               entropy_count += nfrac;
+       } else {
+               /*
+                * Credit: we have to account for the possibility of
+                * overwriting already present entropy.  Even in the
+                * ideal case of pure Shannon entropy, new contributions
+                * approach the full value asymptotically:
+                *
+                * entropy <- entropy + (pool_size - entropy) *
+                *      (1 - exp(-add_entropy/pool_size))
+                *
+                * For add_entropy <= pool_size/2 then
+                * (1 - exp(-add_entropy/pool_size)) >=
+                *    (add_entropy/pool_size)*0.7869...
+                * so we can approximate the exponential with
+                * 3/4*add_entropy/pool_size and still be on the
+                * safe side by adding at most pool_size/2 at a time.
+                *
+                * The use of pool_size-2 in the while statement is to
+                * prevent rounding artifacts from making the loop
+                * arbitrarily long; this limits the loop to log2(pool_size)*2
+                * turns no matter how large nbits is.
+                */
+               int pnfrac = nfrac;
+               const int s = r->poolinfo->poolbitshift + ENTROPY_SHIFT + 2;
+               /* The +2 corresponds to the /4 in the denominator */
+
+               do {
+                       unsigned int anfrac = min(pnfrac, pool_size/2);
+                       unsigned int add =
+                               ((pool_size - entropy_count)*anfrac*3) >> s;
+
+                       entropy_count += add;
+                       pnfrac -= anfrac;
+               } while (unlikely(entropy_count < pool_size-2 && pnfrac));
+       }
 
        if (entropy_count < 0) {
-               DEBUG_ENT("negative entropy/overflow\n");
+               pr_warn("random: negative entropy/overflow: pool %s count %d\n",
+                       r->name, entropy_count);
+               WARN_ON(1);
                entropy_count = 0;
-       } else if (entropy_count > r->poolinfo->POOLBITS)
-               entropy_count = r->poolinfo->POOLBITS;
+       } else if (entropy_count > pool_size)
+               entropy_count = pool_size;
        if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
                goto retry;
 
-       if (!r->initialized && nbits > 0) {
-               r->entropy_total += nbits;
-               if (r->entropy_total > 128) {
-                       r->initialized = 1;
-                       if (r == &nonblocking_pool)
-                               prandom_reseed_late();
+       r->entropy_total += nbits;
+       if (!r->initialized && r->entropy_total > 128) {
+               r->initialized = 1;
+               r->entropy_total = 0;
+               if (r == &nonblocking_pool) {
+                       prandom_reseed_late();
+                       pr_notice("random: %s pool is initialized\n", r->name);
                }
        }
 
-       trace_credit_entropy_bits(r->name, nbits, entropy_count,
+       trace_credit_entropy_bits(r->name, nbits,
+                                 entropy_count >> ENTROPY_SHIFT,
                                  r->entropy_total, _RET_IP_);
 
-       /* should we wake readers? */
-       if (r == &input_pool && entropy_count >= random_read_wakeup_thresh) {
-               wake_up_interruptible(&random_read_wait);
-               kill_fasync(&fasync, SIGIO, POLL_IN);
+       if (r == &input_pool) {
+               int entropy_bytes = entropy_count >> ENTROPY_SHIFT;
+
+               /* should we wake readers? */
+               if (entropy_bytes >= random_read_wakeup_thresh) {
+                       wake_up_interruptible(&random_read_wait);
+                       kill_fasync(&fasync, SIGIO, POLL_IN);
+               }
+               /* If the input pool is getting full, send some
+                * entropy to the two output pools, flipping back and
+                * forth between them, until the output pools are 75%
+                * full.
+                */
+               if (entropy_bytes > random_write_wakeup_thresh &&
+                   r->initialized &&
+                   r->entropy_total >= 2*random_read_wakeup_thresh) {
+                       static struct entropy_store *last = &blocking_pool;
+                       struct entropy_store *other = &blocking_pool;
+
+                       if (last == &blocking_pool)
+                               other = &nonblocking_pool;
+                       if (other->entropy_count <=
+                           3 * other->poolinfo->poolfracbits / 4)
+                               last = other;
+                       if (last->entropy_count <=
+                           3 * last->poolinfo->poolfracbits / 4) {
+                               schedule_work(&last->push_work);
+                               r->entropy_total = 0;
+                       }
+               }
        }
 }
 
+static void credit_entropy_bits_safe(struct entropy_store *r, int nbits)
+{
+       const int nbits_max = (int)(~0U >> (ENTROPY_SHIFT + 1));
+
+       /* Cap the value to avoid overflows */
+       nbits = min(nbits,  nbits_max);
+       nbits = max(nbits, -nbits_max);
+
+       credit_entropy_bits(r, nbits);
+}
+
 /*********************************************************************
  *
  * Entropy input management
@@ -633,6 +722,8 @@ struct timer_rand_state {
        unsigned dont_count_entropy:1;
 };
 
+#define INIT_TIMER_RAND_STATE { INITIAL_JIFFIES, };
+
 /*
  * Add device- or boot-specific data to the input and nonblocking
  * pools to help initialize them to unique values.
@@ -644,15 +735,22 @@ struct timer_rand_state {
 void add_device_randomness(const void *buf, unsigned int size)
 {
        unsigned long time = random_get_entropy() ^ jiffies;
+       unsigned long flags;
 
-       mix_pool_bytes(&input_pool, buf, size, NULL);
-       mix_pool_bytes(&input_pool, &time, sizeof(time), NULL);
-       mix_pool_bytes(&nonblocking_pool, buf, size, NULL);
-       mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL);
+       trace_add_device_randomness(size, _RET_IP_);
+       spin_lock_irqsave(&input_pool.lock, flags);
+       _mix_pool_bytes(&input_pool, buf, size, NULL);
+       _mix_pool_bytes(&input_pool, &time, sizeof(time), NULL);
+       spin_unlock_irqrestore(&input_pool.lock, flags);
+
+       spin_lock_irqsave(&nonblocking_pool.lock, flags);
+       _mix_pool_bytes(&nonblocking_pool, buf, size, NULL);
+       _mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL);
+       spin_unlock_irqrestore(&nonblocking_pool.lock, flags);
 }
 EXPORT_SYMBOL(add_device_randomness);
 
-static struct timer_rand_state input_timer_state;
+static struct timer_rand_state input_timer_state = INIT_TIMER_RAND_STATE;
 
 /*
  * This function adds entropy to the entropy "pool" by using timing
@@ -666,6 +764,7 @@ static struct timer_rand_state input_timer_state;
  */
 static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
 {
+       struct entropy_store    *r;
        struct {
                long jiffies;
                unsigned cycles;
@@ -674,15 +773,12 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
        long delta, delta2, delta3;
 
        preempt_disable();
-       /* if over the trickle threshold, use only 1 in 4096 samples */
-       if (input_pool.entropy_count > trickle_thresh &&
-           ((__this_cpu_inc_return(trickle_count) - 1) & 0xfff))
-               goto out;
 
        sample.jiffies = jiffies;
        sample.cycles = random_get_entropy();
        sample.num = num;
-       mix_pool_bytes(&input_pool, &sample, sizeof(sample), NULL);
+       r = nonblocking_pool.initialized ? &input_pool : &nonblocking_pool;
+       mix_pool_bytes(r, &sample, sizeof(sample), NULL);
 
        /*
         * Calculate number of bits of randomness we probably added.
@@ -716,10 +812,8 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
                 * Round down by 1 bit on general principles,
                 * and limit entropy entimate to 12 bits.
                 */
-               credit_entropy_bits(&input_pool,
-                                   min_t(int, fls(delta>>1), 11));
+               credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
        }
-out:
        preempt_enable();
 }
 
@@ -732,10 +826,10 @@ void add_input_randomness(unsigned int type, unsigned int code,
        if (value == last_value)
                return;
 
-       DEBUG_ENT("input event\n");
        last_value = value;
        add_timer_randomness(&input_timer_state,
                             (type << 4) ^ code ^ (code >> 4) ^ value);
+       trace_add_input_randomness(ENTROPY_BITS(&input_pool));
 }
 EXPORT_SYMBOL_GPL(add_input_randomness);
 
@@ -747,20 +841,21 @@ void add_interrupt_randomness(int irq, int irq_flags)
        struct fast_pool        *fast_pool = &__get_cpu_var(irq_randomness);
        struct pt_regs          *regs = get_irq_regs();
        unsigned long           now = jiffies;
-       __u32                   input[4], cycles = random_get_entropy();
-
-       input[0] = cycles ^ jiffies;
-       input[1] = irq;
-       if (regs) {
-               __u64 ip = instruction_pointer(regs);
-               input[2] = ip;
-               input[3] = ip >> 32;
-       }
+       cycles_t                cycles = random_get_entropy();
+       __u32                   input[4], c_high, j_high;
+       __u64                   ip;
 
-       fast_mix(fast_pool, input, sizeof(input));
+       c_high = (sizeof(cycles) > 4) ? cycles >> 32 : 0;
+       j_high = (sizeof(now) > 4) ? now >> 32 : 0;
+       input[0] = cycles ^ j_high ^ irq;
+       input[1] = now ^ c_high;
+       ip = regs ? instruction_pointer(regs) : _RET_IP_;
+       input[2] = ip;
+       input[3] = ip >> 32;
 
-       if ((fast_pool->count & 1023) &&
-           !time_after(now, fast_pool->last + HZ))
+       fast_mix(fast_pool, input);
+
+       if ((fast_pool->count & 63) && !time_after(now, fast_pool->last + HZ))
                return;
 
        fast_pool->last = now;
@@ -789,10 +884,8 @@ void add_disk_randomness(struct gendisk *disk)
        if (!disk || !disk->random)
                return;
        /* first major is 1, so we get >= 0x200 here */
-       DEBUG_ENT("disk event %d:%d\n",
-                 MAJOR(disk_devt(disk)), MINOR(disk_devt(disk)));
-
        add_timer_randomness(disk->random, 0x100 + disk_devt(disk));
+       trace_add_disk_randomness(disk_devt(disk), ENTROPY_BITS(&input_pool));
 }
 #endif
 
@@ -810,30 +903,58 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
  * from the primary pool to the secondary extraction pool. We make
  * sure we pull enough for a 'catastrophic reseed'.
  */
+static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes);
 static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
 {
-       __u32   tmp[OUTPUT_POOL_WORDS];
+       if (r->limit == 0 && random_min_urandom_seed) {
+               unsigned long now = jiffies;
 
-       if (r->pull && r->entropy_count < nbytes * 8 &&
-           r->entropy_count < r->poolinfo->POOLBITS) {
-               /* If we're limited, always leave two wakeup worth's BITS */
-               int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4;
-               int bytes = nbytes;
-
-               /* pull at least as many as BYTES as wakeup BITS */
-               bytes = max_t(int, bytes, random_read_wakeup_thresh / 8);
-               /* but never more than the buffer size */
-               bytes = min_t(int, bytes, sizeof(tmp));
-
-               DEBUG_ENT("going to reseed %s with %d bits "
-                         "(%zu of %d requested)\n",
-                         r->name, bytes * 8, nbytes * 8, r->entropy_count);
-
-               bytes = extract_entropy(r->pull, tmp, bytes,
-                                       random_read_wakeup_thresh / 8, rsvd);
-               mix_pool_bytes(r, tmp, bytes, NULL);
-               credit_entropy_bits(r, bytes*8);
+               if (time_before(now,
+                               r->last_pulled + random_min_urandom_seed * HZ))
+                       return;
+               r->last_pulled = now;
        }
+       if (r->pull &&
+           r->entropy_count < (nbytes << (ENTROPY_SHIFT + 3)) &&
+           r->entropy_count < r->poolinfo->poolfracbits)
+               _xfer_secondary_pool(r, nbytes);
+}
+
+static void _xfer_secondary_pool(struct entropy_store *r, size_t nbytes)
+{
+       __u32   tmp[OUTPUT_POOL_WORDS];
+
+       /* For /dev/random's pool, always leave two wakeup worth's BITS */
+       int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4;
+       int bytes = nbytes;
+
+       /* pull at least as many as BYTES as wakeup BITS */
+       bytes = max_t(int, bytes, random_read_wakeup_thresh / 8);
+       /* but never more than the buffer size */
+       bytes = min_t(int, bytes, sizeof(tmp));
+
+       trace_xfer_secondary_pool(r->name, bytes * 8, nbytes * 8,
+                                 ENTROPY_BITS(r), ENTROPY_BITS(r->pull));
+       bytes = extract_entropy(r->pull, tmp, bytes,
+                               random_read_wakeup_thresh / 8, rsvd);
+       mix_pool_bytes(r, tmp, bytes, NULL);
+       credit_entropy_bits(r, bytes*8);
+}
+
+/*
+ * Used as a workqueue function so that when the input pool is getting
+ * full, we can "spill over" some entropy to the output pools.  That
+ * way the output pools can store some of the excess entropy instead
+ * of letting it go to waste.
+ */
+static void push_to_pool(struct work_struct *work)
+{
+       struct entropy_store *r = container_of(work, struct entropy_store,
+                                             push_work);
+       BUG_ON(!r);
+       _xfer_secondary_pool(r, random_read_wakeup_thresh/8);
+       trace_push_to_pool(r->name, r->entropy_count >> ENTROPY_SHIFT,
+                          r->pull->entropy_count >> ENTROPY_SHIFT);
 }
 
 /*
@@ -853,50 +974,48 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
 {
        unsigned long flags;
        int wakeup_write = 0;
+       int have_bytes;
+       int entropy_count, orig;
+       size_t ibytes;
 
        /* Hold lock while accounting */
        spin_lock_irqsave(&r->lock, flags);
 
-       BUG_ON(r->entropy_count > r->poolinfo->POOLBITS);
-       DEBUG_ENT("trying to extract %zu bits from %s\n",
-                 nbytes * 8, r->name);
+       BUG_ON(r->entropy_count > r->poolinfo->poolfracbits);
 
        /* Can we pull enough? */
-       if (r->entropy_count / 8 < min + reserved) {
-               nbytes = 0;
-       } else {
-               int entropy_count, orig;
 retry:
-               entropy_count = orig = ACCESS_ONCE(r->entropy_count);
+       entropy_count = orig = ACCESS_ONCE(r->entropy_count);
+       have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
+       ibytes = nbytes;
+       if (have_bytes < min + reserved) {
+               ibytes = 0;
+       } else {
                /* If limited, never pull more than available */
-               if (r->limit && nbytes + reserved >= entropy_count / 8)
-                       nbytes = entropy_count/8 - reserved;
-
-               if (entropy_count / 8 >= nbytes + reserved) {
-                       entropy_count -= nbytes*8;
-                       if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
-                               goto retry;
-               } else {
-                       entropy_count = reserved;
-                       if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
-                               goto retry;
-               }
+               if (r->limit && ibytes + reserved >= have_bytes)
+                       ibytes = have_bytes - reserved;
 
-               if (entropy_count < random_write_wakeup_thresh)
-                       wakeup_write = 1;
-       }
+               if (have_bytes >= ibytes + reserved)
+                       entropy_count -= ibytes << (ENTROPY_SHIFT + 3);
+               else
+                       entropy_count = reserved << (ENTROPY_SHIFT + 3);
 
-       DEBUG_ENT("debiting %zu entropy credits from %s%s\n",
-                 nbytes * 8, r->name, r->limit ? "" : " (unlimited)");
+               if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
+                       goto retry;
 
+               if ((r->entropy_count >> ENTROPY_SHIFT)
+                   < random_write_wakeup_thresh)
+                       wakeup_write = 1;
+       }
        spin_unlock_irqrestore(&r->lock, flags);
 
+       trace_debit_entropy(r->name, 8 * ibytes);
        if (wakeup_write) {
                wake_up_interruptible(&random_write_wait);
                kill_fasync(&fasync, SIGIO, POLL_OUT);
        }
 
-       return nbytes;
+       return ibytes;
 }
 
 static void extract_buf(struct entropy_store *r, __u8 *out)
@@ -904,7 +1023,7 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
        int i;
        union {
                __u32 w[5];
-               unsigned long l[LONGS(EXTRACT_SIZE)];
+               unsigned long l[LONGS(20)];
        } hash;
        __u32 workspace[SHA_WORKSPACE_WORDS];
        __u8 extract[64];
@@ -916,6 +1035,17 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
        for (i = 0; i < r->poolinfo->poolwords; i += 16)
                sha_transform(hash.w, (__u8 *)(r->pool + i), workspace);
 
+       /*
+        * If we have a architectural hardware random number
+        * generator, mix that in, too.
+        */
+       for (i = 0; i < LONGS(20); i++) {
+               unsigned long v;
+               if (!arch_get_random_long(&v))
+                       break;
+               hash.l[i] ^= v;
+       }
+
        /*
         * We mix the hash back into the pool to prevent backtracking
         * attacks (where the attacker knows the state of the pool
@@ -945,17 +1075,6 @@ static void extract_buf(struct entropy_store *r, __u8 *out)
        hash.w[1] ^= hash.w[4];
        hash.w[2] ^= rol32(hash.w[2], 16);
 
-       /*
-        * If we have a architectural hardware random number
-        * generator, mix that in, too.
-        */
-       for (i = 0; i < LONGS(EXTRACT_SIZE); i++) {
-               unsigned long v;
-               if (!arch_get_random_long(&v))
-                       break;
-               hash.l[i] ^= v;
-       }
-
        memcpy(out, &hash, EXTRACT_SIZE);
        memset(&hash, 0, sizeof(hash));
 }
@@ -971,10 +1090,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
        if (fips_enabled) {
                spin_lock_irqsave(&r->lock, flags);
                if (!r->last_data_init) {
-                       r->last_data_init = true;
+                       r->last_data_init = 1;
                        spin_unlock_irqrestore(&r->lock, flags);
                        trace_extract_entropy(r->name, EXTRACT_SIZE,
-                                             r->entropy_count, _RET_IP_);
+                                             ENTROPY_BITS(r), _RET_IP_);
                        xfer_secondary_pool(r, EXTRACT_SIZE);
                        extract_buf(r, tmp);
                        spin_lock_irqsave(&r->lock, flags);
@@ -983,7 +1102,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
                spin_unlock_irqrestore(&r->lock, flags);
        }
 
-       trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
+       trace_extract_entropy(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
        xfer_secondary_pool(r, nbytes);
        nbytes = account(r, nbytes, min, reserved);
 
@@ -1016,7 +1135,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
        ssize_t ret = 0, i;
        __u8 tmp[EXTRACT_SIZE];
 
-       trace_extract_entropy_user(r->name, nbytes, r->entropy_count, _RET_IP_);
+       trace_extract_entropy_user(r->name, nbytes, ENTROPY_BITS(r), _RET_IP_);
        xfer_secondary_pool(r, nbytes);
        nbytes = account(r, nbytes, 0, 0);
 
@@ -1056,6 +1175,14 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
  */
 void get_random_bytes(void *buf, int nbytes)
 {
+#if DEBUG_RANDOM_BOOT > 0
+       if (unlikely(nonblocking_pool.initialized == 0))
+               printk(KERN_NOTICE "random: %pF get_random_bytes called "
+                      "with %d bits of entropy available\n",
+                      (void *) _RET_IP_,
+                      nonblocking_pool.entropy_total);
+#endif
+       trace_get_random_bytes(nbytes, _RET_IP_);
        extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
 }
 EXPORT_SYMBOL(get_random_bytes);
@@ -1074,7 +1201,7 @@ void get_random_bytes_arch(void *buf, int nbytes)
 {
        char *p = buf;
 
-       trace_get_random_bytes(nbytes, _RET_IP_);
+       trace_get_random_bytes_arch(nbytes, _RET_IP_);
        while (nbytes) {
                unsigned long v;
                int chunk = min(nbytes, (int)sizeof(unsigned long));
@@ -1108,13 +1235,11 @@ static void init_std_data(struct entropy_store *r)
        ktime_t now = ktime_get_real();
        unsigned long rv;
 
-       r->entropy_count = 0;
-       r->entropy_total = 0;
-       r->last_data_init = false;
+       r->last_pulled = jiffies;
        mix_pool_bytes(r, &now, sizeof(now), NULL);
-       for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
+       for (i = r->poolinfo->poolbytes; i > 0; i -= sizeof(rv)) {
                if (!arch_get_random_long(&rv))
-                       break;
+                       rv = random_get_entropy();
                mix_pool_bytes(r, &rv, sizeof(rv), NULL);
        }
        mix_pool_bytes(r, utsname(), sizeof(*(utsname())), NULL);
@@ -1137,7 +1262,7 @@ static int rand_initialize(void)
        init_std_data(&nonblocking_pool);
        return 0;
 }
-module_init(rand_initialize);
+early_initcall(rand_initialize);
 
 #ifdef CONFIG_BLOCK
 void rand_initialize_disk(struct gendisk *disk)
@@ -1149,8 +1274,10 @@ void rand_initialize_disk(struct gendisk *disk)
         * source.
         */
        state = kzalloc(sizeof(struct timer_rand_state), GFP_KERNEL);
-       if (state)
+       if (state) {
+               state->last_time = INITIAL_JIFFIES;
                disk->random = state;
+       }
 }
 #endif
 
@@ -1167,8 +1294,6 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
                if (n > SEC_XFER_SIZE)
                        n = SEC_XFER_SIZE;
 
-               DEBUG_ENT("reading %zu bits\n", n*8);
-
                n = extract_entropy_user(&blocking_pool, buf, n);
 
                if (n < 0) {
@@ -1176,8 +1301,9 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
                        break;
                }
 
-               DEBUG_ENT("read got %zd bits (%zd still needed)\n",
-                         n*8, (nbytes-n)*8);
+               trace_random_read(n*8, (nbytes-n)*8,
+                                 ENTROPY_BITS(&blocking_pool),
+                                 ENTROPY_BITS(&input_pool));
 
                if (n == 0) {
                        if (file->f_flags & O_NONBLOCK) {
@@ -1185,13 +1311,9 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
                                break;
                        }
 
-                       DEBUG_ENT("sleeping?\n");
-
                        wait_event_interruptible(random_read_wait,
-                               input_pool.entropy_count >=
-                                                random_read_wakeup_thresh);
-
-                       DEBUG_ENT("awake\n");
+                               ENTROPY_BITS(&input_pool) >=
+                               random_read_wakeup_thresh);
 
                        if (signal_pending(current)) {
                                retval = -ERESTARTSYS;
@@ -1214,7 +1336,18 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 static ssize_t
 urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 {
-       return extract_entropy_user(&nonblocking_pool, buf, nbytes);
+       int ret;
+
+       if (unlikely(nonblocking_pool.initialized == 0))
+               printk_once(KERN_NOTICE "random: %s urandom read "
+                           "with %d bits of entropy available\n",
+                           current->comm, nonblocking_pool.entropy_total);
+
+       ret = extract_entropy_user(&nonblocking_pool, buf, nbytes);
+
+       trace_urandom_read(8 * nbytes, ENTROPY_BITS(&nonblocking_pool),
+                          ENTROPY_BITS(&input_pool));
+       return ret;
 }
 
 static unsigned int
@@ -1225,9 +1358,9 @@ random_poll(struct file *file, poll_table * wait)
        poll_wait(file, &random_read_wait, wait);
        poll_wait(file, &random_write_wait, wait);
        mask = 0;
-       if (input_pool.entropy_count >= random_read_wakeup_thresh)
+       if (ENTROPY_BITS(&input_pool) >= random_read_wakeup_thresh)
                mask |= POLLIN | POLLRDNORM;
-       if (input_pool.entropy_count < random_write_wakeup_thresh)
+       if (ENTROPY_BITS(&input_pool) < random_write_wakeup_thresh)
                mask |= POLLOUT | POLLWRNORM;
        return mask;
 }
@@ -1278,7 +1411,8 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
        switch (cmd) {
        case RNDGETENTCNT:
                /* inherently racy, no point locking */
-               if (put_user(input_pool.entropy_count, p))
+               ent_count = ENTROPY_BITS(&input_pool);
+               if (put_user(ent_count, p))
                        return -EFAULT;
                return 0;
        case RNDADDTOENTCNT:
@@ -1286,7 +1420,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
                        return -EPERM;
                if (get_user(ent_count, p))
                        return -EFAULT;
-               credit_entropy_bits(&input_pool, ent_count);
+               credit_entropy_bits_safe(&input_pool, ent_count);
                return 0;
        case RNDADDENTROPY:
                if (!capable(CAP_SYS_ADMIN))
@@ -1301,14 +1435,19 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
                                    size);
                if (retval < 0)
                        return retval;
-               credit_entropy_bits(&input_pool, ent_count);
+               credit_entropy_bits_safe(&input_pool, ent_count);
                return 0;
        case RNDZAPENTCNT:
        case RNDCLEARPOOL:
-               /* Clear the entropy pool counters. */
+               /*
+                * Clear the entropy pool counters. We no longer clear
+                * the entropy pool, as that's silly.
+                */
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
-               rand_initialize();
+               input_pool.entropy_count = 0;
+               nonblocking_pool.entropy_count = 0;
+               blocking_pool.entropy_count = 0;
                return 0;
        default:
                return -EINVAL;
@@ -1408,6 +1547,23 @@ static int proc_do_uuid(struct ctl_table *table, int write,
        return proc_dostring(&fake_table, write, buffer, lenp, ppos);
 }
 
+/*
+ * Return entropy available scaled to integral bits
+ */
+static int proc_do_entropy(ctl_table *table, int write,
+                          void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+       ctl_table fake_table;
+       int entropy_count;
+
+       entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
+
+       fake_table.data = &entropy_count;
+       fake_table.maxlen = sizeof(entropy_count);
+
+       return proc_dointvec(&fake_table, write, buffer, lenp, ppos);
+}
+
 static int sysctl_poolsize = INPUT_POOL_WORDS * 32;
 extern struct ctl_table random_table[];
 struct ctl_table random_table[] = {
@@ -1422,7 +1578,7 @@ struct ctl_table random_table[] = {
                .procname       = "entropy_avail",
                .maxlen         = sizeof(int),
                .mode           = 0444,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_do_entropy,
                .data           = &input_pool.entropy_count,
        },
        {
@@ -1443,6 +1599,13 @@ struct ctl_table random_table[] = {
                .extra1         = &min_write_thresh,
                .extra2         = &max_write_thresh,
        },
+       {
+               .procname       = "urandom_min_reseed_secs",
+               .data           = &random_min_urandom_seed,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec,
+       },
        {
                .procname       = "boot_id",
                .data           = &sysctl_bootid,
index 0e1d89b4321b7de9b4bcb49e96f1363c9498e44c..d9e3f671c2ea634012982c2228493cba8eb71903 100644 (file)
@@ -117,7 +117,7 @@ void __init of_fixed_factor_clk_setup(struct device_node *node)
        }
 
        if (of_property_read_u32(node, "clock-mult", &mult)) {
-               pr_err("%s Fixed factor clock <%s> must have a clokc-mult property\n",
+               pr_err("%s Fixed factor clock <%s> must have a clock-mult property\n",
                        __func__, node->name);
                return;
        }
index c73fc2b74de2a1dd0665bde5693b1fce03f6d6c5..18c5b9b16645dfa49a218d4b12253240f97310b7 100644 (file)
 #include <linux/atomic.h>
 #include <linux/pid_namespace.h>
 
-#include <asm/unaligned.h>
-
 #include <linux/cn_proc.h>
 
-#define CN_PROC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event))
+/*
+ * Size of a cn_msg followed by a proc_event structure.  Since the
+ * sizeof struct cn_msg is a multiple of 4 bytes, but not 8 bytes, we
+ * add one 4-byte word to the size here, and then start the actual
+ * cn_msg structure 4 bytes into the stack buffer.  The result is that
+ * the immediately following proc_event structure is aligned to 8 bytes.
+ */
+#define CN_PROC_MSG_SIZE (sizeof(struct cn_msg) + sizeof(struct proc_event) + 4)
+
+/* See comment above; we test our assumption about sizeof struct cn_msg here. */
+static inline struct cn_msg *buffer_to_cn_msg(__u8 *buffer)
+{
+       BUILD_BUG_ON(sizeof(struct cn_msg) != 20);
+       return (struct cn_msg *)(buffer + 4);
+}
 
 static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
 static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
@@ -56,19 +68,19 @@ void proc_fork_connector(struct task_struct *task)
 {
        struct cn_msg *msg;
        struct proc_event *ev;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
        struct timespec ts;
        struct task_struct *parent;
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_FORK;
        rcu_read_lock();
        parent = rcu_dereference(task->real_parent);
@@ -91,17 +103,17 @@ void proc_exec_connector(struct task_struct *task)
        struct cn_msg *msg;
        struct proc_event *ev;
        struct timespec ts;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_EXEC;
        ev->event_data.exec.process_pid = task->pid;
        ev->event_data.exec.process_tgid = task->tgid;
@@ -117,14 +129,14 @@ void proc_id_connector(struct task_struct *task, int which_id)
 {
        struct cn_msg *msg;
        struct proc_event *ev;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
        struct timespec ts;
        const struct cred *cred;
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        ev->what = which_id;
@@ -145,7 +157,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
        rcu_read_unlock();
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
 
        memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
        msg->ack = 0; /* not used */
@@ -159,17 +171,17 @@ void proc_sid_connector(struct task_struct *task)
        struct cn_msg *msg;
        struct proc_event *ev;
        struct timespec ts;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_SID;
        ev->event_data.sid.process_pid = task->pid;
        ev->event_data.sid.process_tgid = task->tgid;
@@ -186,17 +198,17 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
        struct cn_msg *msg;
        struct proc_event *ev;
        struct timespec ts;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_PTRACE;
        ev->event_data.ptrace.process_pid  = task->pid;
        ev->event_data.ptrace.process_tgid = task->tgid;
@@ -221,17 +233,17 @@ void proc_comm_connector(struct task_struct *task)
        struct cn_msg *msg;
        struct proc_event *ev;
        struct timespec ts;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_COMM;
        ev->event_data.comm.process_pid  = task->pid;
        ev->event_data.comm.process_tgid = task->tgid;
@@ -248,18 +260,18 @@ void proc_coredump_connector(struct task_struct *task)
 {
        struct cn_msg *msg;
        struct proc_event *ev;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
        struct timespec ts;
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_COREDUMP;
        ev->event_data.coredump.process_pid = task->pid;
        ev->event_data.coredump.process_tgid = task->tgid;
@@ -275,18 +287,18 @@ void proc_exit_connector(struct task_struct *task)
 {
        struct cn_msg *msg;
        struct proc_event *ev;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
        struct timespec ts;
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        get_seq(&msg->seq, &ev->cpu);
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->what = PROC_EVENT_EXIT;
        ev->event_data.exit.process_pid = task->pid;
        ev->event_data.exit.process_tgid = task->tgid;
@@ -312,18 +324,18 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
 {
        struct cn_msg *msg;
        struct proc_event *ev;
-       __u8 buffer[CN_PROC_MSG_SIZE];
+       __u8 buffer[CN_PROC_MSG_SIZE] __aligned(8);
        struct timespec ts;
 
        if (atomic_read(&proc_event_num_listeners) < 1)
                return;
 
-       msg = (struct cn_msg *)buffer;
+       msg = buffer_to_cn_msg(buffer);
        ev = (struct proc_event *)msg->data;
        memset(&ev->event_data, 0, sizeof(ev->event_data));
        msg->seq = rcvd_seq;
        ktime_get_ts(&ts); /* get high res monotonic timestamp */
-       put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
+       ev->timestamp_ns = timespec_to_ns(&ts);
        ev->cpu = -1;
        ev->what = PROC_EVENT_NONE;
        ev->event_data.ack.err = err;
index 6897ad85b0467a8200c3a529e5dee14344c2afbf..d369349eeaab2df6fe768469470ad6de39583889 100644 (file)
@@ -129,7 +129,7 @@ config X86_AMD_FREQ_SENSITIVITY
        help
          This adds AMD-specific powersave bias function to the ondemand
          governor, which allows it to make more power-conscious frequency
-         change decisions based on feedback from hardware (availble on AMD
+         change decisions based on feedback from hardware (available on AMD
          Family 16h and above).
 
          Hardware feedback tells software how "sensitive" to frequency changes
index 218460fcd2e4f9294d24b84680f173f838c11332..25a70d06c5bf243efe85ff3ed2dfbd2a7cc590df 100644 (file)
@@ -68,6 +68,9 @@ static void cs_check_cpu(int cpu, unsigned int load)
 
                dbs_info->requested_freq += get_freq_target(cs_tuners, policy);
 
+               if (dbs_info->requested_freq > policy->max)
+                       dbs_info->requested_freq = policy->max;
+
                __cpufreq_driver_target(policy, dbs_info->requested_freq,
                        CPUFREQ_RELATION_H);
                return;
index 0806c31e57645a287490c4d851d2760cd9484ca0..e6be63561fa699a28053c7528056dcd08ffb2285 100644 (file)
@@ -328,10 +328,6 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                                             dbs_data->cdata->gov_dbs_timer);
                }
 
-               /*
-                * conservative does not implement micro like ondemand
-                * governor, thus we are bound to jiffes/HZ
-                */
                if (dbs_data->cdata->governor == GOV_CONSERVATIVE) {
                        cs_dbs_info->down_skip = 0;
                        cs_dbs_info->enable = 1;
index 7b6dc06b1bd4958bea2be16b6a13e5c209953346..f3c22874da753c07dd5f12d58f4b85a6438a2de3 100644 (file)
@@ -67,7 +67,7 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
        /*
         * The policy max have been changed so that we cannot get proper
         * old_index with cpufreq_frequency_table_target(). Thus, ignore
-        * policy and get the index from the raw freqeuncy table.
+        * policy and get the index from the raw frequency table.
         */
        old_index = exynos_cpufreq_get_index(old_freq);
        if (old_index < 0) {
index be6d14307aa81a7fa3e3626953b5a43b514933e2..a0acd0bfba40a361f3ea9eaafc42db928968dea7 100644 (file)
@@ -53,6 +53,7 @@ static unsigned int omap_getspeed(unsigned int cpu)
 
 static int omap_target(struct cpufreq_policy *policy, unsigned int index)
 {
+       int r, ret;
        struct dev_pm_opp *opp;
        unsigned long freq, volt = 0, volt_old = 0, tol = 0;
        unsigned int old_freq, new_freq;
index c61a6eccf16958ff2145d1b7971d17da92aa9032..446687cc2334ed2f60a0b6f0170382fe733aae01 100644 (file)
@@ -89,14 +89,15 @@ config AT_HDMAC
          Support the Atmel AHB DMA controller.
 
 config FSL_DMA
-       tristate "Freescale Elo and Elo Plus DMA support"
+       tristate "Freescale Elo series DMA support"
        depends on FSL_SOC
        select DMA_ENGINE
        select ASYNC_TX_ENABLE_CHANNEL_SWITCH
        ---help---
-         Enable support for the Freescale Elo and Elo Plus DMA controllers.
-         The Elo is the DMA controller on some 82xx and 83xx parts, and the
-         Elo Plus is the DMA controller on 85xx and 86xx parts.
+         Enable support for the Freescale Elo series DMA controllers.
+         The Elo is the DMA controller on some mpc82xx and mpc83xx parts, the
+         EloPlus is on mpc85xx and mpc86xx and Pxxx parts, and the Elo3 is on
+         some Txxx and Bxxx parts.
 
 config MPC512X_DMA
        tristate "Freescale MPC512x built-in DMA engine support"
@@ -313,7 +314,7 @@ config MMP_PDMA
        depends on (ARCH_MMP || ARCH_PXA)
        select DMA_ENGINE
        help
-         Support the MMP PDMA engine for PXA and MMP platfrom.
+         Support the MMP PDMA engine for PXA and MMP platform.
 
 config DMA_JZ4740
        tristate "JZ4740 DMA support"
index e51a9832ef0d06801fd151b376824a7ac3d697b7..16a2aa28f85672689f66c37039a8e72230e71b02 100644 (file)
@@ -1164,42 +1164,12 @@ static void pl08x_free_txd(struct pl08x_driver_data *pl08x,
        kfree(txd);
 }
 
-static void pl08x_unmap_buffers(struct pl08x_txd *txd)
-{
-       struct device *dev = txd->vd.tx.chan->device->dev;
-       struct pl08x_sg *dsg;
-
-       if (!(txd->vd.tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-               if (txd->vd.tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE)
-                       list_for_each_entry(dsg, &txd->dsg_list, node)
-                               dma_unmap_single(dev, dsg->src_addr, dsg->len,
-                                               DMA_TO_DEVICE);
-               else {
-                       list_for_each_entry(dsg, &txd->dsg_list, node)
-                               dma_unmap_page(dev, dsg->src_addr, dsg->len,
-                                               DMA_TO_DEVICE);
-               }
-       }
-       if (!(txd->vd.tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-               if (txd->vd.tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE)
-                       list_for_each_entry(dsg, &txd->dsg_list, node)
-                               dma_unmap_single(dev, dsg->dst_addr, dsg->len,
-                                               DMA_FROM_DEVICE);
-               else
-                       list_for_each_entry(dsg, &txd->dsg_list, node)
-                               dma_unmap_page(dev, dsg->dst_addr, dsg->len,
-                                               DMA_FROM_DEVICE);
-       }
-}
-
 static void pl08x_desc_free(struct virt_dma_desc *vd)
 {
        struct pl08x_txd *txd = to_pl08x_txd(&vd->tx);
        struct pl08x_dma_chan *plchan = to_pl08x_chan(vd->tx.chan);
 
-       if (!plchan->slave)
-               pl08x_unmap_buffers(txd);
-
+       dma_descriptor_unmap(txd);
        if (!txd->done)
                pl08x_release_mux(plchan);
 
@@ -1252,7 +1222,7 @@ static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan,
        size_t bytes = 0;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        /*
@@ -1267,7 +1237,7 @@ static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan,
 
        spin_lock_irqsave(&plchan->vc.lock, flags);
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret != DMA_SUCCESS) {
+       if (ret != DMA_COMPLETE) {
                vd = vchan_find_desc(&plchan->vc, cookie);
                if (vd) {
                        /* On the issued list, so hasn't been processed yet */
@@ -2138,8 +2108,7 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
        writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR);
        writel(0x000000FF, pl08x->base + PL080_TC_CLEAR);
 
-       ret = request_irq(adev->irq[0], pl08x_irq, IRQF_DISABLED,
-                         DRIVER_NAME, pl08x);
+       ret = request_irq(adev->irq[0], pl08x_irq, 0, DRIVER_NAME, pl08x);
        if (ret) {
                dev_err(&adev->dev, "%s failed to request interrupt %d\n",
                        __func__, adev->irq[0]);
index c787f38a186a008a6cf8fa4af1dc9d19cab8f836..e2c04dc81e2a903ea13956e872150c40ed8b00e8 100644 (file)
@@ -344,31 +344,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc)
        /* move myself to free_list */
        list_move(&desc->desc_node, &atchan->free_list);
 
-       /* unmap dma addresses (not on slave channels) */
-       if (!atchan->chan_common.private) {
-               struct device *parent = chan2parent(&atchan->chan_common);
-               if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-                       if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE)
-                               dma_unmap_single(parent,
-                                               desc->lli.daddr,
-                                               desc->len, DMA_FROM_DEVICE);
-                       else
-                               dma_unmap_page(parent,
-                                               desc->lli.daddr,
-                                               desc->len, DMA_FROM_DEVICE);
-               }
-               if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                       if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE)
-                               dma_unmap_single(parent,
-                                               desc->lli.saddr,
-                                               desc->len, DMA_TO_DEVICE);
-                       else
-                               dma_unmap_page(parent,
-                                               desc->lli.saddr,
-                                               desc->len, DMA_TO_DEVICE);
-               }
-       }
-
+       dma_descriptor_unmap(txd);
        /* for cyclic transfers,
         * no need to replay callback function while stopping */
        if (!atc_chan_is_cyclic(atchan)) {
@@ -1102,7 +1078,7 @@ atc_tx_status(struct dma_chan *chan,
        int bytes = 0;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
        /*
         * There's no point calculating the residue if there's
index 31011d2a26fcfa0510b64c1114c1f87c05762ec3..3c6716e0b78eee2592a8c977550ce036ab4318c5 100644 (file)
@@ -2369,7 +2369,7 @@ coh901318_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
        enum dma_status ret;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        dma_set_residue(txstate, coh901318_get_bytes_left(chan));
@@ -2694,7 +2694,7 @@ static int __init coh901318_probe(struct platform_device *pdev)
        if (irq < 0)
                return irq;
 
-       err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED,
+       err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, 0,
                               "coh901318", base);
        if (err)
                return err;
index 7c82b92f9b16f18bf1ce4e6bedb988f5d5b70e22..c29dacff66fa951f136657536a628b6743ccda30 100644 (file)
@@ -141,6 +141,9 @@ struct cppi41_dd {
        const struct chan_queues *queues_rx;
        const struct chan_queues *queues_tx;
        struct chan_queues td_queue;
+
+       /* context for suspend/resume */
+       unsigned int dma_tdfdq;
 };
 
 #define FIST_COMPLETION_QUEUE  93
@@ -263,6 +266,15 @@ static u32 pd_trans_len(u32 val)
        return val & ((1 << (DESC_LENGTH_BITS_NUM + 1)) - 1);
 }
 
+static u32 cppi41_pop_desc(struct cppi41_dd *cdd, unsigned queue_num)
+{
+       u32 desc;
+
+       desc = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(queue_num));
+       desc &= ~0x1f;
+       return desc;
+}
+
 static irqreturn_t cppi41_irq(int irq, void *data)
 {
        struct cppi41_dd *cdd = data;
@@ -300,8 +312,7 @@ static irqreturn_t cppi41_irq(int irq, void *data)
                        q_num = __fls(val);
                        val &= ~(1 << q_num);
                        q_num += 32 * i;
-                       desc = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(q_num));
-                       desc &= ~0x1f;
+                       desc = cppi41_pop_desc(cdd, q_num);
                        c = desc_to_chan(cdd, desc);
                        if (WARN_ON(!c)) {
                                pr_err("%s() q %d desc %08x\n", __func__,
@@ -353,7 +364,7 @@ static enum dma_status cppi41_dma_tx_status(struct dma_chan *chan,
 
        /* lock */
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (txstate && ret == DMA_SUCCESS)
+       if (txstate && ret == DMA_COMPLETE)
                txstate->residue = c->residue;
        /* unlock */
 
@@ -517,15 +528,6 @@ static void cppi41_compute_td_desc(struct cppi41_desc *d)
        d->pd0 = DESC_TYPE_TEARD << DESC_TYPE;
 }
 
-static u32 cppi41_pop_desc(struct cppi41_dd *cdd, unsigned queue_num)
-{
-       u32 desc;
-
-       desc = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(queue_num));
-       desc &= ~0x1f;
-       return desc;
-}
-
 static int cppi41_tear_down_chan(struct cppi41_channel *c)
 {
        struct cppi41_dd *cdd = c->cdd;
@@ -561,36 +563,26 @@ static int cppi41_tear_down_chan(struct cppi41_channel *c)
                c->td_retry = 100;
        }
 
-       if (!c->td_seen) {
-               unsigned td_comp_queue;
+       if (!c->td_seen || !c->td_desc_seen) {
 
-               if (c->is_tx)
-                       td_comp_queue =  cdd->td_queue.complete;
-               else
-                       td_comp_queue =  c->q_comp_num;
+               desc_phys = cppi41_pop_desc(cdd, cdd->td_queue.complete);
+               if (!desc_phys)
+                       desc_phys = cppi41_pop_desc(cdd, c->q_comp_num);
 
-               desc_phys = cppi41_pop_desc(cdd, td_comp_queue);
-               if (desc_phys) {
-                       __iormb();
+               if (desc_phys == c->desc_phys) {
+                       c->td_desc_seen = 1;
+
+               } else if (desc_phys == td_desc_phys) {
+                       u32 pd0;
 
-                       if (desc_phys == td_desc_phys) {
-                               u32 pd0;
-                               pd0 = td->pd0;
-                               WARN_ON((pd0 >> DESC_TYPE) != DESC_TYPE_TEARD);
-                               WARN_ON(!c->is_tx && !(pd0 & TD_DESC_IS_RX));
-                               WARN_ON((pd0 & 0x1f) != c->port_num);
-                       } else {
-                               WARN_ON_ONCE(1);
-                       }
-                       c->td_seen = 1;
-               }
-       }
-       if (!c->td_desc_seen) {
-               desc_phys = cppi41_pop_desc(cdd, c->q_comp_num);
-               if (desc_phys) {
                        __iormb();
-                       WARN_ON(c->desc_phys != desc_phys);
-                       c->td_desc_seen = 1;
+                       pd0 = td->pd0;
+                       WARN_ON((pd0 >> DESC_TYPE) != DESC_TYPE_TEARD);
+                       WARN_ON(!c->is_tx && !(pd0 & TD_DESC_IS_RX));
+                       WARN_ON((pd0 & 0x1f) != c->port_num);
+                       c->td_seen = 1;
+               } else if (desc_phys) {
+                       WARN_ON_ONCE(1);
                }
        }
        c->td_retry--;
@@ -609,7 +601,7 @@ static int cppi41_tear_down_chan(struct cppi41_channel *c)
 
        WARN_ON(!c->td_retry);
        if (!c->td_desc_seen) {
-               desc_phys = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(c->q_num));
+               desc_phys = cppi41_pop_desc(cdd, c->q_num);
                WARN_ON(!desc_phys);
        }
 
@@ -674,14 +666,14 @@ static void cleanup_chans(struct cppi41_dd *cdd)
        }
 }
 
-static int cppi41_add_chans(struct platform_device *pdev, struct cppi41_dd *cdd)
+static int cppi41_add_chans(struct device *dev, struct cppi41_dd *cdd)
 {
        struct cppi41_channel *cchan;
        int i;
        int ret;
        u32 n_chans;
 
-       ret = of_property_read_u32(pdev->dev.of_node, "#dma-channels",
+       ret = of_property_read_u32(dev->of_node, "#dma-channels",
                        &n_chans);
        if (ret)
                return ret;
@@ -719,7 +711,7 @@ err:
        return -ENOMEM;
 }
 
-static void purge_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
+static void purge_descs(struct device *dev, struct cppi41_dd *cdd)
 {
        unsigned int mem_decs;
        int i;
@@ -731,7 +723,7 @@ static void purge_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
                cppi_writel(0, cdd->qmgr_mem + QMGR_MEMBASE(i));
                cppi_writel(0, cdd->qmgr_mem + QMGR_MEMCTRL(i));
 
-               dma_free_coherent(&pdev->dev, mem_decs, cdd->cd,
+               dma_free_coherent(dev, mem_decs, cdd->cd,
                                cdd->descs_phys);
        }
 }
@@ -741,19 +733,19 @@ static void disable_sched(struct cppi41_dd *cdd)
        cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
 }
 
-static void deinit_cpii41(struct platform_device *pdev, struct cppi41_dd *cdd)
+static void deinit_cppi41(struct device *dev, struct cppi41_dd *cdd)
 {
        disable_sched(cdd);
 
-       purge_descs(pdev, cdd);
+       purge_descs(dev, cdd);
 
        cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
        cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
-       dma_free_coherent(&pdev->dev, QMGR_SCRATCH_SIZE, cdd->qmgr_scratch,
+       dma_free_coherent(dev, QMGR_SCRATCH_SIZE, cdd->qmgr_scratch,
                        cdd->scratch_phys);
 }
 
-static int init_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
+static int init_descs(struct device *dev, struct cppi41_dd *cdd)
 {
        unsigned int desc_size;
        unsigned int mem_decs;
@@ -777,7 +769,7 @@ static int init_descs(struct platform_device *pdev, struct cppi41_dd *cdd)
                reg |= ilog2(ALLOC_DECS_NUM) - 5;
 
                BUILD_BUG_ON(DESCS_AREAS != 1);
-               cdd->cd = dma_alloc_coherent(&pdev->dev, mem_decs,
+               cdd->cd = dma_alloc_coherent(dev, mem_decs,
                                &cdd->descs_phys, GFP_KERNEL);
                if (!cdd->cd)
                        return -ENOMEM;
@@ -813,12 +805,12 @@ static void init_sched(struct cppi41_dd *cdd)
        cppi_writel(reg, cdd->sched_mem + DMA_SCHED_CTRL);
 }
 
-static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
+static int init_cppi41(struct device *dev, struct cppi41_dd *cdd)
 {
        int ret;
 
        BUILD_BUG_ON(QMGR_SCRATCH_SIZE > ((1 << 14) - 1));
-       cdd->qmgr_scratch = dma_alloc_coherent(&pdev->dev, QMGR_SCRATCH_SIZE,
+       cdd->qmgr_scratch = dma_alloc_coherent(dev, QMGR_SCRATCH_SIZE,
                        &cdd->scratch_phys, GFP_KERNEL);
        if (!cdd->qmgr_scratch)
                return -ENOMEM;
@@ -827,7 +819,7 @@ static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
        cppi_writel(QMGR_SCRATCH_SIZE, cdd->qmgr_mem + QMGR_LRAM_SIZE);
        cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM1_BASE);
 
-       ret = init_descs(pdev, cdd);
+       ret = init_descs(dev, cdd);
        if (ret)
                goto err_td;
 
@@ -835,7 +827,7 @@ static int init_cppi41(struct platform_device *pdev, struct cppi41_dd *cdd)
        init_sched(cdd);
        return 0;
 err_td:
-       deinit_cpii41(pdev, cdd);
+       deinit_cppi41(dev, cdd);
        return ret;
 }
 
@@ -914,11 +906,11 @@ static const struct of_device_id cppi41_dma_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, cppi41_dma_ids);
 
-static const struct cppi_glue_infos *get_glue_info(struct platform_device *pdev)
+static const struct cppi_glue_infos *get_glue_info(struct device *dev)
 {
        const struct of_device_id *of_id;
 
-       of_id = of_match_node(cppi41_dma_ids, pdev->dev.of_node);
+       of_id = of_match_node(cppi41_dma_ids, dev->of_node);
        if (!of_id)
                return NULL;
        return of_id->data;
@@ -927,11 +919,12 @@ static const struct cppi_glue_infos *get_glue_info(struct platform_device *pdev)
 static int cppi41_dma_probe(struct platform_device *pdev)
 {
        struct cppi41_dd *cdd;
+       struct device *dev = &pdev->dev;
        const struct cppi_glue_infos *glue_info;
        int irq;
        int ret;
 
-       glue_info = get_glue_info(pdev);
+       glue_info = get_glue_info(dev);
        if (!glue_info)
                return -EINVAL;
 
@@ -946,14 +939,14 @@ static int cppi41_dma_probe(struct platform_device *pdev)
        cdd->ddev.device_issue_pending = cppi41_dma_issue_pending;
        cdd->ddev.device_prep_slave_sg = cppi41_dma_prep_slave_sg;
        cdd->ddev.device_control = cppi41_dma_control;
-       cdd->ddev.dev = &pdev->dev;
+       cdd->ddev.dev = dev;
        INIT_LIST_HEAD(&cdd->ddev.channels);
        cpp41_dma_info.dma_cap = cdd->ddev.cap_mask;
 
-       cdd->usbss_mem = of_iomap(pdev->dev.of_node, 0);
-       cdd->ctrl_mem = of_iomap(pdev->dev.of_node, 1);
-       cdd->sched_mem = of_iomap(pdev->dev.of_node, 2);
-       cdd->qmgr_mem = of_iomap(pdev->dev.of_node, 3);
+       cdd->usbss_mem = of_iomap(dev->of_node, 0);
+       cdd->ctrl_mem = of_iomap(dev->of_node, 1);
+       cdd->sched_mem = of_iomap(dev->of_node, 2);
+       cdd->qmgr_mem = of_iomap(dev->of_node, 3);
 
        if (!cdd->usbss_mem || !cdd->ctrl_mem || !cdd->sched_mem ||
                        !cdd->qmgr_mem) {
@@ -961,31 +954,31 @@ static int cppi41_dma_probe(struct platform_device *pdev)
                goto err_remap;
        }
 
-       pm_runtime_enable(&pdev->dev);
-       ret = pm_runtime_get_sync(&pdev->dev);
-       if (ret)
+       pm_runtime_enable(dev);
+       ret = pm_runtime_get_sync(dev);
+       if (ret < 0)
                goto err_get_sync;
 
        cdd->queues_rx = glue_info->queues_rx;
        cdd->queues_tx = glue_info->queues_tx;
        cdd->td_queue = glue_info->td_queue;
 
-       ret = init_cppi41(pdev, cdd);
+       ret = init_cppi41(dev, cdd);
        if (ret)
                goto err_init_cppi;
 
-       ret = cppi41_add_chans(pdev, cdd);
+       ret = cppi41_add_chans(dev, cdd);
        if (ret)
                goto err_chans;
 
-       irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+       irq = irq_of_parse_and_map(dev->of_node, 0);
        if (!irq)
                goto err_irq;
 
        cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
 
        ret = request_irq(irq, glue_info->isr, IRQF_SHARED,
-                       dev_name(&pdev->dev), cdd);
+                       dev_name(dev), cdd);
        if (ret)
                goto err_irq;
        cdd->irq = irq;
@@ -994,7 +987,7 @@ static int cppi41_dma_probe(struct platform_device *pdev)
        if (ret)
                goto err_dma_reg;
 
-       ret = of_dma_controller_register(pdev->dev.of_node,
+       ret = of_dma_controller_register(dev->of_node,
                        cppi41_dma_xlate, &cpp41_dma_info);
        if (ret)
                goto err_of;
@@ -1009,11 +1002,11 @@ err_irq:
        cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
        cleanup_chans(cdd);
 err_chans:
-       deinit_cpii41(pdev, cdd);
+       deinit_cppi41(dev, cdd);
 err_init_cppi:
-       pm_runtime_put(&pdev->dev);
+       pm_runtime_put(dev);
 err_get_sync:
-       pm_runtime_disable(&pdev->dev);
+       pm_runtime_disable(dev);
        iounmap(cdd->usbss_mem);
        iounmap(cdd->ctrl_mem);
        iounmap(cdd->sched_mem);
@@ -1033,7 +1026,7 @@ static int cppi41_dma_remove(struct platform_device *pdev)
        cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
        free_irq(cdd->irq, cdd);
        cleanup_chans(cdd);
-       deinit_cpii41(pdev, cdd);
+       deinit_cppi41(&pdev->dev, cdd);
        iounmap(cdd->usbss_mem);
        iounmap(cdd->ctrl_mem);
        iounmap(cdd->sched_mem);
@@ -1044,12 +1037,53 @@ static int cppi41_dma_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int cppi41_suspend(struct device *dev)
+{
+       struct cppi41_dd *cdd = dev_get_drvdata(dev);
+
+       cdd->dma_tdfdq = cppi_readl(cdd->ctrl_mem + DMA_TDFDQ);
+       cppi_writel(0, cdd->usbss_mem + USBSS_IRQ_CLEARR);
+       disable_sched(cdd);
+
+       return 0;
+}
+
+static int cppi41_resume(struct device *dev)
+{
+       struct cppi41_dd *cdd = dev_get_drvdata(dev);
+       struct cppi41_channel *c;
+       int i;
+
+       for (i = 0; i < DESCS_AREAS; i++)
+               cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
+
+       list_for_each_entry(c, &cdd->ddev.channels, chan.device_node)
+               if (!c->is_tx)
+                       cppi_writel(c->q_num, c->gcr_reg + RXHPCRA0);
+
+       init_sched(cdd);
+
+       cppi_writel(cdd->dma_tdfdq, cdd->ctrl_mem + DMA_TDFDQ);
+       cppi_writel(cdd->scratch_phys, cdd->qmgr_mem + QMGR_LRAM0_BASE);
+       cppi_writel(QMGR_SCRATCH_SIZE, cdd->qmgr_mem + QMGR_LRAM_SIZE);
+       cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM1_BASE);
+
+       cppi_writel(USBSS_IRQ_PD_COMP, cdd->usbss_mem + USBSS_IRQ_ENABLER);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(cppi41_pm_ops, cppi41_suspend, cppi41_resume);
+
 static struct platform_driver cpp41_dma_driver = {
        .probe  = cppi41_dma_probe,
        .remove = cppi41_dma_remove,
        .driver = {
                .name = "cppi41-dma-engine",
                .owner = THIS_MODULE,
+               .pm = &cppi41_pm_ops,
                .of_match_table = of_match_ptr(cppi41_dma_ids),
        },
 };
index b0c0c8268d42bb023ac94ca8f420e22a5a197c37..94c380f0753860c4c4002c19f4217332fa2460f0 100644 (file)
@@ -491,7 +491,7 @@ static enum dma_status jz4740_dma_tx_status(struct dma_chan *c,
        unsigned long flags;
 
        status = dma_cookie_status(c, cookie, state);
-       if (status == DMA_SUCCESS || !state)
+       if (status == DMA_COMPLETE || !state)
                return status;
 
        spin_lock_irqsave(&chan->vchan.lock, flags);
index 9162ac80c18f303ac9a509eb97298eba33d4753b..ea806bdc12ef92418c528be0b950758de59c3ee7 100644 (file)
@@ -65,6 +65,7 @@
 #include <linux/acpi.h>
 #include <linux/acpi_dma.h>
 #include <linux/of_dma.h>
+#include <linux/mempool.h>
 
 static DEFINE_MUTEX(dma_list_mutex);
 static DEFINE_IDR(dma_idr);
@@ -901,98 +902,132 @@ void dma_async_device_unregister(struct dma_device *device)
 }
 EXPORT_SYMBOL(dma_async_device_unregister);
 
-/**
- * dma_async_memcpy_buf_to_buf - offloaded copy between virtual addresses
- * @chan: DMA channel to offload copy to
- * @dest: destination address (virtual)
- * @src: source address (virtual)
- * @len: length
- *
- * Both @dest and @src must be mappable to a bus address according to the
- * DMA mapping API rules for streaming mappings.
- * Both @dest and @src must stay memory resident (kernel memory or locked
- * user space pages).
- */
-dma_cookie_t
-dma_async_memcpy_buf_to_buf(struct dma_chan *chan, void *dest,
-                       void *src, size_t len)
-{
-       struct dma_device *dev = chan->device;
-       struct dma_async_tx_descriptor *tx;
-       dma_addr_t dma_dest, dma_src;
-       dma_cookie_t cookie;
-       unsigned long flags;
+struct dmaengine_unmap_pool {
+       struct kmem_cache *cache;
+       const char *name;
+       mempool_t *pool;
+       size_t size;
+};
 
-       dma_src = dma_map_single(dev->dev, src, len, DMA_TO_DEVICE);
-       dma_dest = dma_map_single(dev->dev, dest, len, DMA_FROM_DEVICE);
-       flags = DMA_CTRL_ACK |
-               DMA_COMPL_SRC_UNMAP_SINGLE |
-               DMA_COMPL_DEST_UNMAP_SINGLE;
-       tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, flags);
+#define __UNMAP_POOL(x) { .size = x, .name = "dmaengine-unmap-" __stringify(x) }
+static struct dmaengine_unmap_pool unmap_pool[] = {
+       __UNMAP_POOL(2),
+       #if IS_ENABLED(CONFIG_ASYNC_TX_DMA)
+       __UNMAP_POOL(16),
+       __UNMAP_POOL(128),
+       __UNMAP_POOL(256),
+       #endif
+};
 
-       if (!tx) {
-               dma_unmap_single(dev->dev, dma_src, len, DMA_TO_DEVICE);
-               dma_unmap_single(dev->dev, dma_dest, len, DMA_FROM_DEVICE);
-               return -ENOMEM;
+static struct dmaengine_unmap_pool *__get_unmap_pool(int nr)
+{
+       int order = get_count_order(nr);
+
+       switch (order) {
+       case 0 ... 1:
+               return &unmap_pool[0];
+       case 2 ... 4:
+               return &unmap_pool[1];
+       case 5 ... 7:
+               return &unmap_pool[2];
+       case 8:
+               return &unmap_pool[3];
+       default:
+               BUG();
+               return NULL;
        }
+}
 
-       tx->callback = NULL;
-       cookie = tx->tx_submit(tx);
+static void dmaengine_unmap(struct kref *kref)
+{
+       struct dmaengine_unmap_data *unmap = container_of(kref, typeof(*unmap), kref);
+       struct device *dev = unmap->dev;
+       int cnt, i;
+
+       cnt = unmap->to_cnt;
+       for (i = 0; i < cnt; i++)
+               dma_unmap_page(dev, unmap->addr[i], unmap->len,
+                              DMA_TO_DEVICE);
+       cnt += unmap->from_cnt;
+       for (; i < cnt; i++)
+               dma_unmap_page(dev, unmap->addr[i], unmap->len,
+                              DMA_FROM_DEVICE);
+       cnt += unmap->bidi_cnt;
+       for (; i < cnt; i++) {
+               if (unmap->addr[i] == 0)
+                       continue;
+               dma_unmap_page(dev, unmap->addr[i], unmap->len,
+                              DMA_BIDIRECTIONAL);
+       }
+       mempool_free(unmap, __get_unmap_pool(cnt)->pool);
+}
 
-       preempt_disable();
-       __this_cpu_add(chan->local->bytes_transferred, len);
-       __this_cpu_inc(chan->local->memcpy_count);
-       preempt_enable();
+void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap)
+{
+       if (unmap)
+               kref_put(&unmap->kref, dmaengine_unmap);
+}
+EXPORT_SYMBOL_GPL(dmaengine_unmap_put);
 
-       return cookie;
+static void dmaengine_destroy_unmap_pool(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(unmap_pool); i++) {
+               struct dmaengine_unmap_pool *p = &unmap_pool[i];
+
+               if (p->pool)
+                       mempool_destroy(p->pool);
+               p->pool = NULL;
+               if (p->cache)
+                       kmem_cache_destroy(p->cache);
+               p->cache = NULL;
+       }
 }
-EXPORT_SYMBOL(dma_async_memcpy_buf_to_buf);
 
-/**
- * dma_async_memcpy_buf_to_pg - offloaded copy from address to page
- * @chan: DMA channel to offload copy to
- * @page: destination page
- * @offset: offset in page to copy to
- * @kdata: source address (virtual)
- * @len: length
- *
- * Both @page/@offset and @kdata must be mappable to a bus address according
- * to the DMA mapping API rules for streaming mappings.
- * Both @page/@offset and @kdata must stay memory resident (kernel memory or
- * locked user space pages)
- */
-dma_cookie_t
-dma_async_memcpy_buf_to_pg(struct dma_chan *chan, struct page *page,
-                       unsigned int offset, void *kdata, size_t len)
+static int __init dmaengine_init_unmap_pool(void)
 {
-       struct dma_device *dev = chan->device;
-       struct dma_async_tx_descriptor *tx;
-       dma_addr_t dma_dest, dma_src;
-       dma_cookie_t cookie;
-       unsigned long flags;
+       int i;
 
-       dma_src = dma_map_single(dev->dev, kdata, len, DMA_TO_DEVICE);
-       dma_dest = dma_map_page(dev->dev, page, offset, len, DMA_FROM_DEVICE);
-       flags = DMA_CTRL_ACK | DMA_COMPL_SRC_UNMAP_SINGLE;
-       tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, flags);
+       for (i = 0; i < ARRAY_SIZE(unmap_pool); i++) {
+               struct dmaengine_unmap_pool *p = &unmap_pool[i];
+               size_t size;
 
-       if (!tx) {
-               dma_unmap_single(dev->dev, dma_src, len, DMA_TO_DEVICE);
-               dma_unmap_page(dev->dev, dma_dest, len, DMA_FROM_DEVICE);
-               return -ENOMEM;
+               size = sizeof(struct dmaengine_unmap_data) +
+                      sizeof(dma_addr_t) * p->size;
+
+               p->cache = kmem_cache_create(p->name, size, 0,
+                                            SLAB_HWCACHE_ALIGN, NULL);
+               if (!p->cache)
+                       break;
+               p->pool = mempool_create_slab_pool(1, p->cache);
+               if (!p->pool)
+                       break;
        }
 
-       tx->callback = NULL;
-       cookie = tx->tx_submit(tx);
+       if (i == ARRAY_SIZE(unmap_pool))
+               return 0;
 
-       preempt_disable();
-       __this_cpu_add(chan->local->bytes_transferred, len);
-       __this_cpu_inc(chan->local->memcpy_count);
-       preempt_enable();
+       dmaengine_destroy_unmap_pool();
+       return -ENOMEM;
+}
 
-       return cookie;
+struct dmaengine_unmap_data *
+dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags)
+{
+       struct dmaengine_unmap_data *unmap;
+
+       unmap = mempool_alloc(__get_unmap_pool(nr)->pool, flags);
+       if (!unmap)
+               return NULL;
+
+       memset(unmap, 0, sizeof(*unmap));
+       kref_init(&unmap->kref);
+       unmap->dev = dev;
+
+       return unmap;
 }
-EXPORT_SYMBOL(dma_async_memcpy_buf_to_pg);
+EXPORT_SYMBOL(dmaengine_get_unmap_data);
 
 /**
  * dma_async_memcpy_pg_to_pg - offloaded copy from page to page
@@ -1015,24 +1050,33 @@ dma_async_memcpy_pg_to_pg(struct dma_chan *chan, struct page *dest_pg,
 {
        struct dma_device *dev = chan->device;
        struct dma_async_tx_descriptor *tx;
-       dma_addr_t dma_dest, dma_src;
+       struct dmaengine_unmap_data *unmap;
        dma_cookie_t cookie;
        unsigned long flags;
 
-       dma_src = dma_map_page(dev->dev, src_pg, src_off, len, DMA_TO_DEVICE);
-       dma_dest = dma_map_page(dev->dev, dest_pg, dest_off, len,
-                               DMA_FROM_DEVICE);
+       unmap = dmaengine_get_unmap_data(dev->dev, 2, GFP_NOIO);
+       if (!unmap)
+               return -ENOMEM;
+
+       unmap->to_cnt = 1;
+       unmap->from_cnt = 1;
+       unmap->addr[0] = dma_map_page(dev->dev, src_pg, src_off, len,
+                                     DMA_TO_DEVICE);
+       unmap->addr[1] = dma_map_page(dev->dev, dest_pg, dest_off, len,
+                                     DMA_FROM_DEVICE);
+       unmap->len = len;
        flags = DMA_CTRL_ACK;
-       tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, flags);
+       tx = dev->device_prep_dma_memcpy(chan, unmap->addr[1], unmap->addr[0],
+                                        len, flags);
 
        if (!tx) {
-               dma_unmap_page(dev->dev, dma_src, len, DMA_TO_DEVICE);
-               dma_unmap_page(dev->dev, dma_dest, len, DMA_FROM_DEVICE);
+               dmaengine_unmap_put(unmap);
                return -ENOMEM;
        }
 
-       tx->callback = NULL;
+       dma_set_unmap(tx, unmap);
        cookie = tx->tx_submit(tx);
+       dmaengine_unmap_put(unmap);
 
        preempt_disable();
        __this_cpu_add(chan->local->bytes_transferred, len);
@@ -1043,6 +1087,52 @@ dma_async_memcpy_pg_to_pg(struct dma_chan *chan, struct page *dest_pg,
 }
 EXPORT_SYMBOL(dma_async_memcpy_pg_to_pg);
 
+/**
+ * dma_async_memcpy_buf_to_buf - offloaded copy between virtual addresses
+ * @chan: DMA channel to offload copy to
+ * @dest: destination address (virtual)
+ * @src: source address (virtual)
+ * @len: length
+ *
+ * Both @dest and @src must be mappable to a bus address according to the
+ * DMA mapping API rules for streaming mappings.
+ * Both @dest and @src must stay memory resident (kernel memory or locked
+ * user space pages).
+ */
+dma_cookie_t
+dma_async_memcpy_buf_to_buf(struct dma_chan *chan, void *dest,
+                           void *src, size_t len)
+{
+       return dma_async_memcpy_pg_to_pg(chan, virt_to_page(dest),
+                                        (unsigned long) dest & ~PAGE_MASK,
+                                        virt_to_page(src),
+                                        (unsigned long) src & ~PAGE_MASK, len);
+}
+EXPORT_SYMBOL(dma_async_memcpy_buf_to_buf);
+
+/**
+ * dma_async_memcpy_buf_to_pg - offloaded copy from address to page
+ * @chan: DMA channel to offload copy to
+ * @page: destination page
+ * @offset: offset in page to copy to
+ * @kdata: source address (virtual)
+ * @len: length
+ *
+ * Both @page/@offset and @kdata must be mappable to a bus address according
+ * to the DMA mapping API rules for streaming mappings.
+ * Both @page/@offset and @kdata must stay memory resident (kernel memory or
+ * locked user space pages)
+ */
+dma_cookie_t
+dma_async_memcpy_buf_to_pg(struct dma_chan *chan, struct page *page,
+                          unsigned int offset, void *kdata, size_t len)
+{
+       return dma_async_memcpy_pg_to_pg(chan, page, offset,
+                                        virt_to_page(kdata),
+                                        (unsigned long) kdata & ~PAGE_MASK, len);
+}
+EXPORT_SYMBOL(dma_async_memcpy_buf_to_pg);
+
 void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx,
        struct dma_chan *chan)
 {
@@ -1062,7 +1152,7 @@ dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
        unsigned long dma_sync_wait_timeout = jiffies + msecs_to_jiffies(5000);
 
        if (!tx)
-               return DMA_SUCCESS;
+               return DMA_COMPLETE;
 
        while (tx->cookie == -EBUSY) {
                if (time_after_eq(jiffies, dma_sync_wait_timeout)) {
@@ -1116,6 +1206,10 @@ EXPORT_SYMBOL_GPL(dma_run_dependencies);
 
 static int __init dma_bus_init(void)
 {
+       int err = dmaengine_init_unmap_pool();
+
+       if (err)
+               return err;
        return class_register(&dma_devclass);
 }
 arch_initcall(dma_bus_init);
index 92f796cdc6ab1dc12c6b895fb2d6e16e5dd92264..20f9a3aaf9266ea6daa71a18f08d258afa8a1a1e 100644 (file)
@@ -8,6 +8,8 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/wait.h>
-#include <linux/ctype.h>
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
-#include <linux/seq_file.h>
 
 static unsigned int test_buf_size = 16384;
 module_param(test_buf_size, uint, S_IRUGO | S_IWUSR);
@@ -68,92 +66,13 @@ module_param(timeout, uint, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(timeout, "Transfer Timeout in msec (default: 3000), "
                 "Pass -1 for infinite timeout");
 
-/* Maximum amount of mismatched bytes in buffer to print */
-#define MAX_ERROR_COUNT                32
-
-/*
- * Initialization patterns. All bytes in the source buffer has bit 7
- * set, all bytes in the destination buffer has bit 7 cleared.
- *
- * Bit 6 is set for all bytes which are to be copied by the DMA
- * engine. Bit 5 is set for all bytes which are to be overwritten by
- * the DMA engine.
- *
- * The remaining bits are the inverse of a counter which increments by
- * one for each byte address.
- */
-#define PATTERN_SRC            0x80
-#define PATTERN_DST            0x00
-#define PATTERN_COPY           0x40
-#define PATTERN_OVERWRITE      0x20
-#define PATTERN_COUNT_MASK     0x1f
-
-enum dmatest_error_type {
-       DMATEST_ET_OK,
-       DMATEST_ET_MAP_SRC,
-       DMATEST_ET_MAP_DST,
-       DMATEST_ET_PREP,
-       DMATEST_ET_SUBMIT,
-       DMATEST_ET_TIMEOUT,
-       DMATEST_ET_DMA_ERROR,
-       DMATEST_ET_DMA_IN_PROGRESS,
-       DMATEST_ET_VERIFY,
-       DMATEST_ET_VERIFY_BUF,
-};
-
-struct dmatest_verify_buffer {
-       unsigned int    index;
-       u8              expected;
-       u8              actual;
-};
-
-struct dmatest_verify_result {
-       unsigned int                    error_count;
-       struct dmatest_verify_buffer    data[MAX_ERROR_COUNT];
-       u8                              pattern;
-       bool                            is_srcbuf;
-};
-
-struct dmatest_thread_result {
-       struct list_head        node;
-       unsigned int            n;
-       unsigned int            src_off;
-       unsigned int            dst_off;
-       unsigned int            len;
-       enum dmatest_error_type type;
-       union {
-               unsigned long                   data;
-               dma_cookie_t                    cookie;
-               enum dma_status                 status;
-               int                             error;
-               struct dmatest_verify_result    *vr;
-       };
-};
-
-struct dmatest_result {
-       struct list_head        node;
-       char                    *name;
-       struct list_head        results;
-};
-
-struct dmatest_info;
-
-struct dmatest_thread {
-       struct list_head        node;
-       struct dmatest_info     *info;
-       struct task_struct      *task;
-       struct dma_chan         *chan;
-       u8                      **srcs;
-       u8                      **dsts;
-       enum dma_transaction_type type;
-       bool                    done;
-};
+static bool noverify;
+module_param(noverify, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(noverify, "Disable random data setup and verification");
 
-struct dmatest_chan {
-       struct list_head        node;
-       struct dma_chan         *chan;
-       struct list_head        threads;
-};
+static bool verbose;
+module_param(verbose, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(verbose, "Enable \"success\" result messages (default: off)");
 
 /**
  * struct dmatest_params - test parameters.
@@ -177,6 +96,7 @@ struct dmatest_params {
        unsigned int    xor_sources;
        unsigned int    pq_sources;
        int             timeout;
+       bool            noverify;
 };
 
 /**
@@ -184,7 +104,7 @@ struct dmatest_params {
  * @params:            test parameters
  * @lock:              access protection to the fields of this structure
  */
-struct dmatest_info {
+static struct dmatest_info {
        /* Test parameters */
        struct dmatest_params   params;
 
@@ -192,16 +112,95 @@ struct dmatest_info {
        struct list_head        channels;
        unsigned int            nr_channels;
        struct mutex            lock;
+       bool                    did_init;
+} test_info = {
+       .channels = LIST_HEAD_INIT(test_info.channels),
+       .lock = __MUTEX_INITIALIZER(test_info.lock),
+};
+
+static int dmatest_run_set(const char *val, const struct kernel_param *kp);
+static int dmatest_run_get(char *val, const struct kernel_param *kp);
+static struct kernel_param_ops run_ops = {
+       .set = dmatest_run_set,
+       .get = dmatest_run_get,
+};
+static bool dmatest_run;
+module_param_cb(run, &run_ops, &dmatest_run, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(run, "Run the test (default: false)");
+
+/* Maximum amount of mismatched bytes in buffer to print */
+#define MAX_ERROR_COUNT                32
+
+/*
+ * Initialization patterns. All bytes in the source buffer has bit 7
+ * set, all bytes in the destination buffer has bit 7 cleared.
+ *
+ * Bit 6 is set for all bytes which are to be copied by the DMA
+ * engine. Bit 5 is set for all bytes which are to be overwritten by
+ * the DMA engine.
+ *
+ * The remaining bits are the inverse of a counter which increments by
+ * one for each byte address.
+ */
+#define PATTERN_SRC            0x80
+#define PATTERN_DST            0x00
+#define PATTERN_COPY           0x40
+#define PATTERN_OVERWRITE      0x20
+#define PATTERN_COUNT_MASK     0x1f
 
-       /* debugfs related stuff */
-       struct dentry           *root;
+struct dmatest_thread {
+       struct list_head        node;
+       struct dmatest_info     *info;
+       struct task_struct      *task;
+       struct dma_chan         *chan;
+       u8                      **srcs;
+       u8                      **dsts;
+       enum dma_transaction_type type;
+       bool                    done;
+};
 
-       /* Test results */
-       struct list_head        results;
-       struct mutex            results_lock;
+struct dmatest_chan {
+       struct list_head        node;
+       struct dma_chan         *chan;
+       struct list_head        threads;
 };
 
-static struct dmatest_info test_info;
+static DECLARE_WAIT_QUEUE_HEAD(thread_wait);
+static bool wait;
+
+static bool is_threaded_test_run(struct dmatest_info *info)
+{
+       struct dmatest_chan *dtc;
+
+       list_for_each_entry(dtc, &info->channels, node) {
+               struct dmatest_thread *thread;
+
+               list_for_each_entry(thread, &dtc->threads, node) {
+                       if (!thread->done)
+                               return true;
+               }
+       }
+
+       return false;
+}
+
+static int dmatest_wait_get(char *val, const struct kernel_param *kp)
+{
+       struct dmatest_info *info = &test_info;
+       struct dmatest_params *params = &info->params;
+
+       if (params->iterations)
+               wait_event(thread_wait, !is_threaded_test_run(info));
+       wait = true;
+       return param_get_bool(val, kp);
+}
+
+static struct kernel_param_ops wait_ops = {
+       .get = dmatest_wait_get,
+       .set = param_set_bool,
+};
+module_param_cb(wait, &wait_ops, &wait, S_IRUGO);
+MODULE_PARM_DESC(wait, "Wait for tests to complete (default: false)");
 
 static bool dmatest_match_channel(struct dmatest_params *params,
                struct dma_chan *chan)
@@ -223,7 +222,7 @@ static unsigned long dmatest_random(void)
 {
        unsigned long buf;
 
-       get_random_bytes(&buf, sizeof(buf));
+       prandom_bytes(&buf, sizeof(buf));
        return buf;
 }
 
@@ -262,9 +261,31 @@ static void dmatest_init_dsts(u8 **bufs, unsigned int start, unsigned int len,
        }
 }
 
-static unsigned int dmatest_verify(struct dmatest_verify_result *vr, u8 **bufs,
-               unsigned int start, unsigned int end, unsigned int counter,
-               u8 pattern, bool is_srcbuf)
+static void dmatest_mismatch(u8 actual, u8 pattern, unsigned int index,
+               unsigned int counter, bool is_srcbuf)
+{
+       u8              diff = actual ^ pattern;
+       u8              expected = pattern | (~counter & PATTERN_COUNT_MASK);
+       const char      *thread_name = current->comm;
+
+       if (is_srcbuf)
+               pr_warn("%s: srcbuf[0x%x] overwritten! Expected %02x, got %02x\n",
+                       thread_name, index, expected, actual);
+       else if ((pattern & PATTERN_COPY)
+                       && (diff & (PATTERN_COPY | PATTERN_OVERWRITE)))
+               pr_warn("%s: dstbuf[0x%x] not copied! Expected %02x, got %02x\n",
+                       thread_name, index, expected, actual);
+       else if (diff & PATTERN_SRC)
+               pr_warn("%s: dstbuf[0x%x] was copied! Expected %02x, got %02x\n",
+                       thread_name, index, expected, actual);
+       else
+               pr_warn("%s: dstbuf[0x%x] mismatch! Expected %02x, got %02x\n",
+                       thread_name, index, expected, actual);
+}
+
+static unsigned int dmatest_verify(u8 **bufs, unsigned int start,
+               unsigned int end, unsigned int counter, u8 pattern,
+               bool is_srcbuf)
 {
        unsigned int i;
        unsigned int error_count = 0;
@@ -272,7 +293,6 @@ static unsigned int dmatest_verify(struct dmatest_verify_result *vr, u8 **bufs,
        u8 expected;
        u8 *buf;
        unsigned int counter_orig = counter;
-       struct dmatest_verify_buffer *vb;
 
        for (; (buf = *bufs); bufs++) {
                counter = counter_orig;
@@ -280,12 +300,9 @@ static unsigned int dmatest_verify(struct dmatest_verify_result *vr, u8 **bufs,
                        actual = buf[i];
                        expected = pattern | (~counter & PATTERN_COUNT_MASK);
                        if (actual != expected) {
-                               if (error_count < MAX_ERROR_COUNT && vr) {
-                                       vb = &vr->data[error_count];
-                                       vb->index = i;
-                                       vb->expected = expected;
-                                       vb->actual = actual;
-                               }
+                               if (error_count < MAX_ERROR_COUNT)
+                                       dmatest_mismatch(actual, pattern, i,
+                                                        counter, is_srcbuf);
                                error_count++;
                        }
                        counter++;
@@ -293,7 +310,7 @@ static unsigned int dmatest_verify(struct dmatest_verify_result *vr, u8 **bufs,
        }
 
        if (error_count > MAX_ERROR_COUNT)
-               pr_warning("%s: %u errors suppressed\n",
+               pr_warn("%s: %u errors suppressed\n",
                        current->comm, error_count - MAX_ERROR_COUNT);
 
        return error_count;
@@ -313,20 +330,6 @@ static void dmatest_callback(void *arg)
        wake_up_all(done->wait);
 }
 
-static inline void unmap_src(struct device *dev, dma_addr_t *addr, size_t len,
-                            unsigned int count)
-{
-       while (count--)
-               dma_unmap_single(dev, addr[count], len, DMA_TO_DEVICE);
-}
-
-static inline void unmap_dst(struct device *dev, dma_addr_t *addr, size_t len,
-                            unsigned int count)
-{
-       while (count--)
-               dma_unmap_single(dev, addr[count], len, DMA_BIDIRECTIONAL);
-}
-
 static unsigned int min_odd(unsigned int x, unsigned int y)
 {
        unsigned int val = min(x, y);
@@ -334,172 +337,49 @@ static unsigned int min_odd(unsigned int x, unsigned int y)
        return val % 2 ? val : val - 1;
 }
 
-static char *verify_result_get_one(struct dmatest_verify_result *vr,
-               unsigned int i)
+static void result(const char *err, unsigned int n, unsigned int src_off,
+                  unsigned int dst_off, unsigned int len, unsigned long data)
 {
-       struct dmatest_verify_buffer *vb = &vr->data[i];
-       u8 diff = vb->actual ^ vr->pattern;
-       static char buf[512];
-       char *msg;
-
-       if (vr->is_srcbuf)
-               msg = "srcbuf overwritten!";
-       else if ((vr->pattern & PATTERN_COPY)
-                       && (diff & (PATTERN_COPY | PATTERN_OVERWRITE)))
-               msg = "dstbuf not copied!";
-       else if (diff & PATTERN_SRC)
-               msg = "dstbuf was copied!";
-       else
-               msg = "dstbuf mismatch!";
-
-       snprintf(buf, sizeof(buf) - 1, "%s [0x%x] Expected %02x, got %02x", msg,
-                vb->index, vb->expected, vb->actual);
-
-       return buf;
+       pr_info("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)",
+               current->comm, n, err, src_off, dst_off, len, data);
 }
 
-static char *thread_result_get(const char *name,
-               struct dmatest_thread_result *tr)
+static void dbg_result(const char *err, unsigned int n, unsigned int src_off,
+                      unsigned int dst_off, unsigned int len,
+                      unsigned long data)
 {
-       static const char * const messages[] = {
-               [DMATEST_ET_OK]                 = "No errors",
-               [DMATEST_ET_MAP_SRC]            = "src mapping error",
-               [DMATEST_ET_MAP_DST]            = "dst mapping error",
-               [DMATEST_ET_PREP]               = "prep error",
-               [DMATEST_ET_SUBMIT]             = "submit error",
-               [DMATEST_ET_TIMEOUT]            = "test timed out",
-               [DMATEST_ET_DMA_ERROR]          =
-                       "got completion callback (DMA_ERROR)",
-               [DMATEST_ET_DMA_IN_PROGRESS]    =
-                       "got completion callback (DMA_IN_PROGRESS)",
-               [DMATEST_ET_VERIFY]             = "errors",
-               [DMATEST_ET_VERIFY_BUF]         = "verify errors",
-       };
-       static char buf[512];
-
-       snprintf(buf, sizeof(buf) - 1,
-                "%s: #%u: %s with src_off=0x%x ""dst_off=0x%x len=0x%x (%lu)",
-                name, tr->n, messages[tr->type], tr->src_off, tr->dst_off,
-                tr->len, tr->data);
-
-       return buf;
+       pr_debug("%s: result #%u: '%s' with src_off=0x%x dst_off=0x%x len=0x%x (%lu)",
+                  current->comm, n, err, src_off, dst_off, len, data);
 }
 
-static int thread_result_add(struct dmatest_info *info,
-               struct dmatest_result *r, enum dmatest_error_type type,
-               unsigned int n, unsigned int src_off, unsigned int dst_off,
-               unsigned int len, unsigned long data)
-{
-       struct dmatest_thread_result *tr;
-
-       tr = kzalloc(sizeof(*tr), GFP_KERNEL);
-       if (!tr)
-               return -ENOMEM;
-
-       tr->type = type;
-       tr->n = n;
-       tr->src_off = src_off;
-       tr->dst_off = dst_off;
-       tr->len = len;
-       tr->data = data;
+#define verbose_result(err, n, src_off, dst_off, len, data) ({ \
+       if (verbose) \
+               result(err, n, src_off, dst_off, len, data); \
+       else \
+               dbg_result(err, n, src_off, dst_off, len, data); \
+})
 
-       mutex_lock(&info->results_lock);
-       list_add_tail(&tr->node, &r->results);
-       mutex_unlock(&info->results_lock);
-
-       if (tr->type == DMATEST_ET_OK)
-               pr_debug("%s\n", thread_result_get(r->name, tr));
-       else
-               pr_warn("%s\n", thread_result_get(r->name, tr));
-
-       return 0;
-}
-
-static unsigned int verify_result_add(struct dmatest_info *info,
-               struct dmatest_result *r, unsigned int n,
-               unsigned int src_off, unsigned int dst_off, unsigned int len,
-               u8 **bufs, int whence, unsigned int counter, u8 pattern,
-               bool is_srcbuf)
+static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
 {
-       struct dmatest_verify_result *vr;
-       unsigned int error_count;
-       unsigned int buf_off = is_srcbuf ? src_off : dst_off;
-       unsigned int start, end;
-
-       if (whence < 0) {
-               start = 0;
-               end = buf_off;
-       } else if (whence > 0) {
-               start = buf_off + len;
-               end = info->params.buf_size;
-       } else {
-               start = buf_off;
-               end = buf_off + len;
-       }
+       unsigned long long per_sec = 1000000;
 
-       vr = kmalloc(sizeof(*vr), GFP_KERNEL);
-       if (!vr) {
-               pr_warn("dmatest: No memory to store verify result\n");
-               return dmatest_verify(NULL, bufs, start, end, counter, pattern,
-                                     is_srcbuf);
-       }
-
-       vr->pattern = pattern;
-       vr->is_srcbuf = is_srcbuf;
-
-       error_count = dmatest_verify(vr, bufs, start, end, counter, pattern,
-                                    is_srcbuf);
-       if (error_count) {
-               vr->error_count = error_count;
-               thread_result_add(info, r, DMATEST_ET_VERIFY_BUF, n, src_off,
-                                 dst_off, len, (unsigned long)vr);
-               return error_count;
-       }
-
-       kfree(vr);
-       return 0;
-}
-
-static void result_free(struct dmatest_info *info, const char *name)
-{
-       struct dmatest_result *r, *_r;
-
-       mutex_lock(&info->results_lock);
-       list_for_each_entry_safe(r, _r, &info->results, node) {
-               struct dmatest_thread_result *tr, *_tr;
-
-               if (name && strcmp(r->name, name))
-                       continue;
-
-               list_for_each_entry_safe(tr, _tr, &r->results, node) {
-                       if (tr->type == DMATEST_ET_VERIFY_BUF)
-                               kfree(tr->vr);
-                       list_del(&tr->node);
-                       kfree(tr);
-               }
+       if (runtime <= 0)
+               return 0;
 
-               kfree(r->name);
-               list_del(&r->node);
-               kfree(r);
+       /* drop precision until runtime is 32-bits */
+       while (runtime > UINT_MAX) {
+               runtime >>= 1;
+               per_sec <<= 1;
        }
 
-       mutex_unlock(&info->results_lock);
+       per_sec *= val;
+       do_div(per_sec, runtime);
+       return per_sec;
 }
 
-static struct dmatest_result *result_init(struct dmatest_info *info,
-               const char *name)
+static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len)
 {
-       struct dmatest_result *r;
-
-       r = kzalloc(sizeof(*r), GFP_KERNEL);
-       if (r) {
-               r->name = kstrdup(name, GFP_KERNEL);
-               INIT_LIST_HEAD(&r->results);
-               mutex_lock(&info->results_lock);
-               list_add_tail(&r->node, &info->results);
-               mutex_unlock(&info->results_lock);
-       }
-       return r;
+       return dmatest_persec(runtime, len >> 10);
 }
 
 /*
@@ -525,7 +405,6 @@ static int dmatest_func(void *data)
        struct dmatest_params   *params;
        struct dma_chan         *chan;
        struct dma_device       *dev;
-       const char              *thread_name;
        unsigned int            src_off, dst_off, len;
        unsigned int            error_count;
        unsigned int            failed_tests = 0;
@@ -538,9 +417,10 @@ static int dmatest_func(void *data)
        int                     src_cnt;
        int                     dst_cnt;
        int                     i;
-       struct dmatest_result   *result;
+       ktime_t                 ktime;
+       s64                     runtime = 0;
+       unsigned long long      total_len = 0;
 
-       thread_name = current->comm;
        set_freezable();
 
        ret = -ENOMEM;
@@ -570,10 +450,6 @@ static int dmatest_func(void *data)
        } else
                goto err_thread_type;
 
-       result = result_init(info, thread_name);
-       if (!result)
-               goto err_srcs;
-
        thread->srcs = kcalloc(src_cnt+1, sizeof(u8 *), GFP_KERNEL);
        if (!thread->srcs)
                goto err_srcs;
@@ -597,17 +473,17 @@ static int dmatest_func(void *data)
        set_user_nice(current, 10);
 
        /*
-        * src buffers are freed by the DMAEngine code with dma_unmap_single()
-        * dst buffers are freed by ourselves below
+        * src and dst buffers are freed by ourselves below
         */
-       flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT
-             | DMA_COMPL_SKIP_DEST_UNMAP | DMA_COMPL_SRC_UNMAP_SINGLE;
+       flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
 
+       ktime = ktime_get();
        while (!kthread_should_stop()
               && !(params->iterations && total_tests >= params->iterations)) {
                struct dma_async_tx_descriptor *tx = NULL;
-               dma_addr_t dma_srcs[src_cnt];
-               dma_addr_t dma_dsts[dst_cnt];
+               struct dmaengine_unmap_data *um;
+               dma_addr_t srcs[src_cnt];
+               dma_addr_t *dsts;
                u8 align = 0;
 
                total_tests++;
@@ -626,81 +502,103 @@ static int dmatest_func(void *data)
                        break;
                }
 
-               len = dmatest_random() % params->buf_size + 1;
+               if (params->noverify) {
+                       len = params->buf_size;
+                       src_off = 0;
+                       dst_off = 0;
+               } else {
+                       len = dmatest_random() % params->buf_size + 1;
+                       len = (len >> align) << align;
+                       if (!len)
+                               len = 1 << align;
+                       src_off = dmatest_random() % (params->buf_size - len + 1);
+                       dst_off = dmatest_random() % (params->buf_size - len + 1);
+
+                       src_off = (src_off >> align) << align;
+                       dst_off = (dst_off >> align) << align;
+
+                       dmatest_init_srcs(thread->srcs, src_off, len,
+                                         params->buf_size);
+                       dmatest_init_dsts(thread->dsts, dst_off, len,
+                                         params->buf_size);
+               }
+
                len = (len >> align) << align;
                if (!len)
                        len = 1 << align;
-               src_off = dmatest_random() % (params->buf_size - len + 1);
-               dst_off = dmatest_random() % (params->buf_size - len + 1);
+               total_len += len;
 
-               src_off = (src_off >> align) << align;
-               dst_off = (dst_off >> align) << align;
-
-               dmatest_init_srcs(thread->srcs, src_off, len, params->buf_size);
-               dmatest_init_dsts(thread->dsts, dst_off, len, params->buf_size);
+               um = dmaengine_get_unmap_data(dev->dev, src_cnt+dst_cnt,
+                                             GFP_KERNEL);
+               if (!um) {
+                       failed_tests++;
+                       result("unmap data NULL", total_tests,
+                              src_off, dst_off, len, ret);
+                       continue;
+               }
 
+               um->len = params->buf_size;
                for (i = 0; i < src_cnt; i++) {
-                       u8 *buf = thread->srcs[i] + src_off;
-
-                       dma_srcs[i] = dma_map_single(dev->dev, buf, len,
-                                                    DMA_TO_DEVICE);
-                       ret = dma_mapping_error(dev->dev, dma_srcs[i]);
+                       unsigned long buf = (unsigned long) thread->srcs[i];
+                       struct page *pg = virt_to_page(buf);
+                       unsigned pg_off = buf & ~PAGE_MASK;
+
+                       um->addr[i] = dma_map_page(dev->dev, pg, pg_off,
+                                                  um->len, DMA_TO_DEVICE);
+                       srcs[i] = um->addr[i] + src_off;
+                       ret = dma_mapping_error(dev->dev, um->addr[i]);
                        if (ret) {
-                               unmap_src(dev->dev, dma_srcs, len, i);
-                               thread_result_add(info, result,
-                                                 DMATEST_ET_MAP_SRC,
-                                                 total_tests, src_off, dst_off,
-                                                 len, ret);
+                               dmaengine_unmap_put(um);
+                               result("src mapping error", total_tests,
+                                      src_off, dst_off, len, ret);
                                failed_tests++;
                                continue;
                        }
+                       um->to_cnt++;
                }
                /* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
+               dsts = &um->addr[src_cnt];
                for (i = 0; i < dst_cnt; i++) {
-                       dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i],
-                                                    params->buf_size,
-                                                    DMA_BIDIRECTIONAL);
-                       ret = dma_mapping_error(dev->dev, dma_dsts[i]);
+                       unsigned long buf = (unsigned long) thread->dsts[i];
+                       struct page *pg = virt_to_page(buf);
+                       unsigned pg_off = buf & ~PAGE_MASK;
+
+                       dsts[i] = dma_map_page(dev->dev, pg, pg_off, um->len,
+                                              DMA_BIDIRECTIONAL);
+                       ret = dma_mapping_error(dev->dev, dsts[i]);
                        if (ret) {
-                               unmap_src(dev->dev, dma_srcs, len, src_cnt);
-                               unmap_dst(dev->dev, dma_dsts, params->buf_size,
-                                         i);
-                               thread_result_add(info, result,
-                                                 DMATEST_ET_MAP_DST,
-                                                 total_tests, src_off, dst_off,
-                                                 len, ret);
+                               dmaengine_unmap_put(um);
+                               result("dst mapping error", total_tests,
+                                      src_off, dst_off, len, ret);
                                failed_tests++;
                                continue;
                        }
+                       um->bidi_cnt++;
                }
 
                if (thread->type == DMA_MEMCPY)
                        tx = dev->device_prep_dma_memcpy(chan,
-                                                        dma_dsts[0] + dst_off,
-                                                        dma_srcs[0], len,
-                                                        flags);
+                                                        dsts[0] + dst_off,
+                                                        srcs[0], len, flags);
                else if (thread->type == DMA_XOR)
                        tx = dev->device_prep_dma_xor(chan,
-                                                     dma_dsts[0] + dst_off,
-                                                     dma_srcs, src_cnt,
+                                                     dsts[0] + dst_off,
+                                                     srcs, src_cnt,
                                                      len, flags);
                else if (thread->type == DMA_PQ) {
                        dma_addr_t dma_pq[dst_cnt];
 
                        for (i = 0; i < dst_cnt; i++)
-                               dma_pq[i] = dma_dsts[i] + dst_off;
-                       tx = dev->device_prep_dma_pq(chan, dma_pq, dma_srcs,
+                               dma_pq[i] = dsts[i] + dst_off;
+                       tx = dev->device_prep_dma_pq(chan, dma_pq, srcs,
                                                     src_cnt, pq_coefs,
                                                     len, flags);
                }
 
                if (!tx) {
-                       unmap_src(dev->dev, dma_srcs, len, src_cnt);
-                       unmap_dst(dev->dev, dma_dsts, params->buf_size,
-                                 dst_cnt);
-                       thread_result_add(info, result, DMATEST_ET_PREP,
-                                         total_tests, src_off, dst_off,
-                                         len, 0);
+                       dmaengine_unmap_put(um);
+                       result("prep error", total_tests, src_off,
+                              dst_off, len, ret);
                        msleep(100);
                        failed_tests++;
                        continue;
@@ -712,9 +610,9 @@ static int dmatest_func(void *data)
                cookie = tx->tx_submit(tx);
 
                if (dma_submit_error(cookie)) {
-                       thread_result_add(info, result, DMATEST_ET_SUBMIT,
-                                         total_tests, src_off, dst_off,
-                                         len, cookie);
+                       dmaengine_unmap_put(um);
+                       result("submit error", total_tests, src_off,
+                              dst_off, len, ret);
                        msleep(100);
                        failed_tests++;
                        continue;
@@ -735,59 +633,59 @@ static int dmatest_func(void *data)
                         * free it this time?" dancing.  For now, just
                         * leave it dangling.
                         */
-                       thread_result_add(info, result, DMATEST_ET_TIMEOUT,
-                                         total_tests, src_off, dst_off,
-                                         len, 0);
+                       dmaengine_unmap_put(um);
+                       result("test timed out", total_tests, src_off, dst_off,
+                              len, 0);
                        failed_tests++;
                        continue;
-               } else if (status != DMA_SUCCESS) {
-                       enum dmatest_error_type type = (status == DMA_ERROR) ?
-                               DMATEST_ET_DMA_ERROR : DMATEST_ET_DMA_IN_PROGRESS;
-                       thread_result_add(info, result, type,
-                                         total_tests, src_off, dst_off,
-                                         len, status);
+               } else if (status != DMA_COMPLETE) {
+                       dmaengine_unmap_put(um);
+                       result(status == DMA_ERROR ?
+                              "completion error status" :
+                              "completion busy status", total_tests, src_off,
+                              dst_off, len, ret);
                        failed_tests++;
                        continue;
                }
 
-               /* Unmap by myself (see DMA_COMPL_SKIP_DEST_UNMAP above) */
-               unmap_dst(dev->dev, dma_dsts, params->buf_size, dst_cnt);
+               dmaengine_unmap_put(um);
 
-               error_count = 0;
+               if (params->noverify) {
+                       verbose_result("test passed", total_tests, src_off,
+                                      dst_off, len, 0);
+                       continue;
+               }
 
-               pr_debug("%s: verifying source buffer...\n", thread_name);
-               error_count += verify_result_add(info, result, total_tests,
-                               src_off, dst_off, len, thread->srcs, -1,
+               pr_debug("%s: verifying source buffer...\n", current->comm);
+               error_count = dmatest_verify(thread->srcs, 0, src_off,
                                0, PATTERN_SRC, true);
-               error_count += verify_result_add(info, result, total_tests,
-                               src_off, dst_off, len, thread->srcs, 0,
-                               src_off, PATTERN_SRC | PATTERN_COPY, true);
-               error_count += verify_result_add(info, result, total_tests,
-                               src_off, dst_off, len, thread->srcs, 1,
-                               src_off + len, PATTERN_SRC, true);
-
-               pr_debug("%s: verifying dest buffer...\n", thread_name);
-               error_count += verify_result_add(info, result, total_tests,
-                               src_off, dst_off, len, thread->dsts, -1,
+               error_count += dmatest_verify(thread->srcs, src_off,
+                               src_off + len, src_off,
+                               PATTERN_SRC | PATTERN_COPY, true);
+               error_count += dmatest_verify(thread->srcs, src_off + len,
+                               params->buf_size, src_off + len,
+                               PATTERN_SRC, true);
+
+               pr_debug("%s: verifying dest buffer...\n", current->comm);
+               error_count += dmatest_verify(thread->dsts, 0, dst_off,
                                0, PATTERN_DST, false);
-               error_count += verify_result_add(info, result, total_tests,
-                               src_off, dst_off, len, thread->dsts, 0,
-                               src_off, PATTERN_SRC | PATTERN_COPY, false);
-               error_count += verify_result_add(info, result, total_tests,
-                               src_off, dst_off, len, thread->dsts, 1,
-                               dst_off + len, PATTERN_DST, false);
+               error_count += dmatest_verify(thread->dsts, dst_off,
+                               dst_off + len, src_off,
+                               PATTERN_SRC | PATTERN_COPY, false);
+               error_count += dmatest_verify(thread->dsts, dst_off + len,
+                               params->buf_size, dst_off + len,
+                               PATTERN_DST, false);
 
                if (error_count) {
-                       thread_result_add(info, result, DMATEST_ET_VERIFY,
-                                         total_tests, src_off, dst_off,
-                                         len, error_count);
+                       result("data error", total_tests, src_off, dst_off,
+                              len, error_count);
                        failed_tests++;
                } else {
-                       thread_result_add(info, result, DMATEST_ET_OK,
-                                         total_tests, src_off, dst_off,
-                                         len, 0);
+                       verbose_result("test passed", total_tests, src_off,
+                                      dst_off, len, 0);
                }
        }
+       runtime = ktime_us_delta(ktime_get(), ktime);
 
        ret = 0;
        for (i = 0; thread->dsts[i]; i++)
@@ -802,20 +700,17 @@ err_srcbuf:
 err_srcs:
        kfree(pq_coefs);
 err_thread_type:
-       pr_notice("%s: terminating after %u tests, %u failures (status %d)\n",
-                       thread_name, total_tests, failed_tests, ret);
+       pr_info("%s: summary %u tests, %u failures %llu iops %llu KB/s (%d)\n",
+               current->comm, total_tests, failed_tests,
+               dmatest_persec(runtime, total_tests),
+               dmatest_KBs(runtime, total_len), ret);
 
        /* terminate all transfers on specified channels */
        if (ret)
                dmaengine_terminate_all(chan);
 
        thread->done = true;
-
-       if (params->iterations > 0)
-               while (!kthread_should_stop()) {
-                       DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
-                       interruptible_sleep_on(&wait_dmatest_exit);
-               }
+       wake_up(&thread_wait);
 
        return ret;
 }
@@ -828,9 +723,10 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
 
        list_for_each_entry_safe(thread, _thread, &dtc->threads, node) {
                ret = kthread_stop(thread->task);
-               pr_debug("dmatest: thread %s exited with status %d\n",
-                               thread->task->comm, ret);
+               pr_debug("thread %s exited with status %d\n",
+                        thread->task->comm, ret);
                list_del(&thread->node);
+               put_task_struct(thread->task);
                kfree(thread);
        }
 
@@ -861,27 +757,27 @@ static int dmatest_add_threads(struct dmatest_info *info,
        for (i = 0; i < params->threads_per_chan; i++) {
                thread = kzalloc(sizeof(struct dmatest_thread), GFP_KERNEL);
                if (!thread) {
-                       pr_warning("dmatest: No memory for %s-%s%u\n",
-                                  dma_chan_name(chan), op, i);
-
+                       pr_warn("No memory for %s-%s%u\n",
+                               dma_chan_name(chan), op, i);
                        break;
                }
                thread->info = info;
                thread->chan = dtc->chan;
                thread->type = type;
                smp_wmb();
-               thread->task = kthread_run(dmatest_func, thread, "%s-%s%u",
+               thread->task = kthread_create(dmatest_func, thread, "%s-%s%u",
                                dma_chan_name(chan), op, i);
                if (IS_ERR(thread->task)) {
-                       pr_warning("dmatest: Failed to run thread %s-%s%u\n",
-                                       dma_chan_name(chan), op, i);
+                       pr_warn("Failed to create thread %s-%s%u\n",
+                               dma_chan_name(chan), op, i);
                        kfree(thread);
                        break;
                }
 
                /* srcbuf and dstbuf are allocated by the thread itself */
-
+               get_task_struct(thread->task);
                list_add_tail(&thread->node, &dtc->threads);
+               wake_up_process(thread->task);
        }
 
        return i;
@@ -897,7 +793,7 @@ static int dmatest_add_channel(struct dmatest_info *info,
 
        dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
        if (!dtc) {
-               pr_warning("dmatest: No memory for %s\n", dma_chan_name(chan));
+               pr_warn("No memory for %s\n", dma_chan_name(chan));
                return -ENOMEM;
        }
 
@@ -917,7 +813,7 @@ static int dmatest_add_channel(struct dmatest_info *info,
                thread_count += cnt > 0 ? cnt : 0;
        }
 
-       pr_info("dmatest: Started %u threads using %s\n",
+       pr_info("Started %u threads using %s\n",
                thread_count, dma_chan_name(chan));
 
        list_add_tail(&dtc->node, &info->channels);
@@ -937,20 +833,20 @@ static bool filter(struct dma_chan *chan, void *param)
                return true;
 }
 
-static int __run_threaded_test(struct dmatest_info *info)
+static void request_channels(struct dmatest_info *info,
+                            enum dma_transaction_type type)
 {
        dma_cap_mask_t mask;
-       struct dma_chan *chan;
-       struct dmatest_params *params = &info->params;
-       int err = 0;
 
        dma_cap_zero(mask);
-       dma_cap_set(DMA_MEMCPY, mask);
+       dma_cap_set(type, mask);
        for (;;) {
+               struct dmatest_params *params = &info->params;
+               struct dma_chan *chan;
+
                chan = dma_request_channel(mask, filter, params);
                if (chan) {
-                       err = dmatest_add_channel(info, chan);
-                       if (err) {
+                       if (dmatest_add_channel(info, chan)) {
                                dma_release_channel(chan);
                                break; /* add_channel failed, punt */
                        }
@@ -960,22 +856,30 @@ static int __run_threaded_test(struct dmatest_info *info)
                    info->nr_channels >= params->max_channels)
                        break; /* we have all we need */
        }
-       return err;
 }
 
-#ifndef MODULE
-static int run_threaded_test(struct dmatest_info *info)
+static void run_threaded_test(struct dmatest_info *info)
 {
-       int ret;
+       struct dmatest_params *params = &info->params;
 
-       mutex_lock(&info->lock);
-       ret = __run_threaded_test(info);
-       mutex_unlock(&info->lock);
-       return ret;
+       /* Copy test parameters */
+       params->buf_size = test_buf_size;
+       strlcpy(params->channel, strim(test_channel), sizeof(params->channel));
+       strlcpy(params->device, strim(test_device), sizeof(params->device));
+       params->threads_per_chan = threads_per_chan;
+       params->max_channels = max_channels;
+       params->iterations = iterations;
+       params->xor_sources = xor_sources;
+       params->pq_sources = pq_sources;
+       params->timeout = timeout;
+       params->noverify = noverify;
+
+       request_channels(info, DMA_MEMCPY);
+       request_channels(info, DMA_XOR);
+       request_channels(info, DMA_PQ);
 }
-#endif
 
-static void __stop_threaded_test(struct dmatest_info *info)
+static void stop_threaded_test(struct dmatest_info *info)
 {
        struct dmatest_chan *dtc, *_dtc;
        struct dma_chan *chan;
@@ -984,203 +888,86 @@ static void __stop_threaded_test(struct dmatest_info *info)
                list_del(&dtc->node);
                chan = dtc->chan;
                dmatest_cleanup_channel(dtc);
-               pr_debug("dmatest: dropped channel %s\n", dma_chan_name(chan));
+               pr_debug("dropped channel %s\n", dma_chan_name(chan));
                dma_release_channel(chan);
        }
 
        info->nr_channels = 0;
 }
 
-static void stop_threaded_test(struct dmatest_info *info)
+static void restart_threaded_test(struct dmatest_info *info, bool run)
 {
-       mutex_lock(&info->lock);
-       __stop_threaded_test(info);
-       mutex_unlock(&info->lock);
-}
-
-static int __restart_threaded_test(struct dmatest_info *info, bool run)
-{
-       struct dmatest_params *params = &info->params;
+       /* we might be called early to set run=, defer running until all
+        * parameters have been evaluated
+        */
+       if (!info->did_init)
+               return;
 
        /* Stop any running test first */
-       __stop_threaded_test(info);
-
-       if (run == false)
-               return 0;
-
-       /* Clear results from previous run */
-       result_free(info, NULL);
-
-       /* Copy test parameters */
-       params->buf_size = test_buf_size;
-       strlcpy(params->channel, strim(test_channel), sizeof(params->channel));
-       strlcpy(params->device, strim(test_device), sizeof(params->device));
-       params->threads_per_chan = threads_per_chan;
-       params->max_channels = max_channels;
-       params->iterations = iterations;
-       params->xor_sources = xor_sources;
-       params->pq_sources = pq_sources;
-       params->timeout = timeout;
+       stop_threaded_test(info);
 
        /* Run test with new parameters */
-       return __run_threaded_test(info);
-}
-
-static bool __is_threaded_test_run(struct dmatest_info *info)
-{
-       struct dmatest_chan *dtc;
-
-       list_for_each_entry(dtc, &info->channels, node) {
-               struct dmatest_thread *thread;
-
-               list_for_each_entry(thread, &dtc->threads, node) {
-                       if (!thread->done)
-                               return true;
-               }
-       }
-
-       return false;
+       run_threaded_test(info);
 }
 
-static ssize_t dtf_read_run(struct file *file, char __user *user_buf,
-               size_t count, loff_t *ppos)
+static int dmatest_run_get(char *val, const struct kernel_param *kp)
 {
-       struct dmatest_info *info = file->private_data;
-       char buf[3];
+       struct dmatest_info *info = &test_info;
 
        mutex_lock(&info->lock);
-
-       if (__is_threaded_test_run(info)) {
-               buf[0] = 'Y';
+       if (is_threaded_test_run(info)) {
+               dmatest_run = true;
        } else {
-               __stop_threaded_test(info);
-               buf[0] = 'N';
+               stop_threaded_test(info);
+               dmatest_run = false;
        }
-
        mutex_unlock(&info->lock);
-       buf[1] = '\n';
-       buf[2] = 0x00;
-       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
-}
-
-static ssize_t dtf_write_run(struct file *file, const char __user *user_buf,
-               size_t count, loff_t *ppos)
-{
-       struct dmatest_info *info = file->private_data;
-       char buf[16];
-       bool bv;
-       int ret = 0;
 
-       if (copy_from_user(buf, user_buf, min(count, (sizeof(buf) - 1))))
-               return -EFAULT;
-
-       if (strtobool(buf, &bv) == 0) {
-               mutex_lock(&info->lock);
-
-               if (__is_threaded_test_run(info))
-                       ret = -EBUSY;
-               else
-                       ret = __restart_threaded_test(info, bv);
-
-               mutex_unlock(&info->lock);
-       }
-
-       return ret ? ret : count;
+       return param_get_bool(val, kp);
 }
 
-static const struct file_operations dtf_run_fops = {
-       .read   = dtf_read_run,
-       .write  = dtf_write_run,
-       .open   = simple_open,
-       .llseek = default_llseek,
-};
-
-static int dtf_results_show(struct seq_file *sf, void *data)
+static int dmatest_run_set(const char *val, const struct kernel_param *kp)
 {
-       struct dmatest_info *info = sf->private;
-       struct dmatest_result *result;
-       struct dmatest_thread_result *tr;
-       unsigned int i;
+       struct dmatest_info *info = &test_info;
+       int ret;
 
-       mutex_lock(&info->results_lock);
-       list_for_each_entry(result, &info->results, node) {
-               list_for_each_entry(tr, &result->results, node) {
-                       seq_printf(sf, "%s\n",
-                               thread_result_get(result->name, tr));
-                       if (tr->type == DMATEST_ET_VERIFY_BUF) {
-                               for (i = 0; i < tr->vr->error_count; i++) {
-                                       seq_printf(sf, "\t%s\n",
-                                               verify_result_get_one(tr->vr, i));
-                               }
-                       }
-               }
+       mutex_lock(&info->lock);
+       ret = param_set_bool(val, kp);
+       if (ret) {
+               mutex_unlock(&info->lock);
+               return ret;
        }
 
-       mutex_unlock(&info->results_lock);
-       return 0;
-}
-
-static int dtf_results_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, dtf_results_show, inode->i_private);
-}
-
-static const struct file_operations dtf_results_fops = {
-       .open           = dtf_results_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-};
-
-static int dmatest_register_dbgfs(struct dmatest_info *info)
-{
-       struct dentry *d;
-
-       d = debugfs_create_dir("dmatest", NULL);
-       if (IS_ERR(d))
-               return PTR_ERR(d);
-       if (!d)
-               goto err_root;
+       if (is_threaded_test_run(info))
+               ret = -EBUSY;
+       else if (dmatest_run)
+               restart_threaded_test(info, dmatest_run);
 
-       info->root = d;
-
-       /* Run or stop threaded test */
-       debugfs_create_file("run", S_IWUSR | S_IRUGO, info->root, info,
-                           &dtf_run_fops);
-
-       /* Results of test in progress */
-       debugfs_create_file("results", S_IRUGO, info->root, info,
-                           &dtf_results_fops);
-
-       return 0;
+       mutex_unlock(&info->lock);
 
-err_root:
-       pr_err("dmatest: Failed to initialize debugfs\n");
-       return -ENOMEM;
+       return ret;
 }
 
 static int __init dmatest_init(void)
 {
        struct dmatest_info *info = &test_info;
-       int ret;
-
-       memset(info, 0, sizeof(*info));
+       struct dmatest_params *params = &info->params;
 
-       mutex_init(&info->lock);
-       INIT_LIST_HEAD(&info->channels);
+       if (dmatest_run) {
+               mutex_lock(&info->lock);
+               run_threaded_test(info);
+               mutex_unlock(&info->lock);
+       }
 
-       mutex_init(&info->results_lock);
-       INIT_LIST_HEAD(&info->results);
+       if (params->iterations && wait)
+               wait_event(thread_wait, !is_threaded_test_run(info));
 
-       ret = dmatest_register_dbgfs(info);
-       if (ret)
-               return ret;
+       /* module parameters are stable, inittime tests are started,
+        * let userspace take over 'run' control
+        */
+       info->did_init = true;
 
-#ifdef MODULE
        return 0;
-#else
-       return run_threaded_test(info);
-#endif
 }
 /* when compiled-in wait for drivers to load first */
 late_initcall(dmatest_init);
@@ -1189,9 +976,9 @@ static void __exit dmatest_exit(void)
 {
        struct dmatest_info *info = &test_info;
 
-       debugfs_remove_recursive(info->root);
+       mutex_lock(&info->lock);
        stop_threaded_test(info);
-       result_free(info, NULL);
+       mutex_unlock(&info->lock);
 }
 module_exit(dmatest_exit);
 
index 89eb89f222846e0ff5d20cfc5e14619fc05d6600..7516be4677cf7e778ba3bef2482cae9179ff41a3 100644 (file)
@@ -85,10 +85,6 @@ static struct device *chan2dev(struct dma_chan *chan)
 {
        return &chan->dev->device;
 }
-static struct device *chan2parent(struct dma_chan *chan)
-{
-       return chan->dev->device.parent;
-}
 
 static struct dw_desc *dwc_first_active(struct dw_dma_chan *dwc)
 {
@@ -311,26 +307,7 @@ dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc,
        list_splice_init(&desc->tx_list, &dwc->free_list);
        list_move(&desc->desc_node, &dwc->free_list);
 
-       if (!is_slave_direction(dwc->direction)) {
-               struct device *parent = chan2parent(&dwc->chan);
-               if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-                       if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE)
-                               dma_unmap_single(parent, desc->lli.dar,
-                                       desc->total_len, DMA_FROM_DEVICE);
-                       else
-                               dma_unmap_page(parent, desc->lli.dar,
-                                       desc->total_len, DMA_FROM_DEVICE);
-               }
-               if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                       if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE)
-                               dma_unmap_single(parent, desc->lli.sar,
-                                       desc->total_len, DMA_TO_DEVICE);
-                       else
-                               dma_unmap_page(parent, desc->lli.sar,
-                                       desc->total_len, DMA_TO_DEVICE);
-               }
-       }
-
+       dma_descriptor_unmap(txd);
        spin_unlock_irqrestore(&dwc->lock, flags);
 
        if (callback)
@@ -1098,13 +1075,13 @@ dwc_tx_status(struct dma_chan *chan,
        enum dma_status         ret;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret != DMA_SUCCESS)
+       if (ret != DMA_COMPLETE)
                dma_set_residue(txstate, dwc_get_residue(dwc));
 
        if (dwc->paused && ret == DMA_IN_PROGRESS)
index bef8a368c8ddcac29f4bd7b4832bd3d0fa4cbdb6..2539ea0cbc6394f918fb849ffd3c6f6ca73f33a0 100644 (file)
 #define EDMA_CHANS     64
 #endif /* CONFIG_ARCH_DAVINCI_DA8XX */
 
-/* Max of 16 segments per channel to conserve PaRAM slots */
-#define MAX_NR_SG              16
+/*
+ * Max of 20 segments per channel to conserve PaRAM slots
+ * Also note that MAX_NR_SG should be atleast the no.of periods
+ * that are required for ASoC, otherwise DMA prep calls will
+ * fail. Today davinci-pcm is the only user of this driver and
+ * requires atleast 17 slots, so we setup the default to 20.
+ */
+#define MAX_NR_SG              20
 #define EDMA_MAX_SLOTS         MAX_NR_SG
 #define EDMA_DESCRIPTORS       16
 
 struct edma_desc {
        struct virt_dma_desc            vdesc;
        struct list_head                node;
+       int                             cyclic;
        int                             absync;
        int                             pset_nr;
        int                             processed;
@@ -167,8 +174,13 @@ static void edma_execute(struct edma_chan *echan)
         * then setup a link to the dummy slot, this results in all future
         * events being absorbed and that's OK because we're done
         */
-       if (edesc->processed == edesc->pset_nr)
-               edma_link(echan->slot[nslots-1], echan->ecc->dummy_slot);
+       if (edesc->processed == edesc->pset_nr) {
+               if (edesc->cyclic)
+                       edma_link(echan->slot[nslots-1], echan->slot[1]);
+               else
+                       edma_link(echan->slot[nslots-1],
+                                 echan->ecc->dummy_slot);
+       }
 
        edma_resume(echan->ch_num);
 
@@ -250,6 +262,117 @@ static int edma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
        return ret;
 }
 
+/*
+ * A PaRAM set configuration abstraction used by other modes
+ * @chan: Channel who's PaRAM set we're configuring
+ * @pset: PaRAM set to initialize and setup.
+ * @src_addr: Source address of the DMA
+ * @dst_addr: Destination address of the DMA
+ * @burst: In units of dev_width, how much to send
+ * @dev_width: How much is the dev_width
+ * @dma_length: Total length of the DMA transfer
+ * @direction: Direction of the transfer
+ */
+static int edma_config_pset(struct dma_chan *chan, struct edmacc_param *pset,
+       dma_addr_t src_addr, dma_addr_t dst_addr, u32 burst,
+       enum dma_slave_buswidth dev_width, unsigned int dma_length,
+       enum dma_transfer_direction direction)
+{
+       struct edma_chan *echan = to_edma_chan(chan);
+       struct device *dev = chan->device->dev;
+       int acnt, bcnt, ccnt, cidx;
+       int src_bidx, dst_bidx, src_cidx, dst_cidx;
+       int absync;
+
+       acnt = dev_width;
+       /*
+        * If the maxburst is equal to the fifo width, use
+        * A-synced transfers. This allows for large contiguous
+        * buffer transfers using only one PaRAM set.
+        */
+       if (burst == 1) {
+               /*
+                * For the A-sync case, bcnt and ccnt are the remainder
+                * and quotient respectively of the division of:
+                * (dma_length / acnt) by (SZ_64K -1). This is so
+                * that in case bcnt over flows, we have ccnt to use.
+                * Note: In A-sync tranfer only, bcntrld is used, but it
+                * only applies for sg_dma_len(sg) >= SZ_64K.
+                * In this case, the best way adopted is- bccnt for the
+                * first frame will be the remainder below. Then for
+                * every successive frame, bcnt will be SZ_64K-1. This
+                * is assured as bcntrld = 0xffff in end of function.
+                */
+               absync = false;
+               ccnt = dma_length / acnt / (SZ_64K - 1);
+               bcnt = dma_length / acnt - ccnt * (SZ_64K - 1);
+               /*
+                * If bcnt is non-zero, we have a remainder and hence an
+                * extra frame to transfer, so increment ccnt.
+                */
+               if (bcnt)
+                       ccnt++;
+               else
+                       bcnt = SZ_64K - 1;
+               cidx = acnt;
+       } else {
+               /*
+                * If maxburst is greater than the fifo address_width,
+                * use AB-synced transfers where A count is the fifo
+                * address_width and B count is the maxburst. In this
+                * case, we are limited to transfers of C count frames
+                * of (address_width * maxburst) where C count is limited
+                * to SZ_64K-1. This places an upper bound on the length
+                * of an SG segment that can be handled.
+                */
+               absync = true;
+               bcnt = burst;
+               ccnt = dma_length / (acnt * bcnt);
+               if (ccnt > (SZ_64K - 1)) {
+                       dev_err(dev, "Exceeded max SG segment size\n");
+                       return -EINVAL;
+               }
+               cidx = acnt * bcnt;
+       }
+
+       if (direction == DMA_MEM_TO_DEV) {
+               src_bidx = acnt;
+               src_cidx = cidx;
+               dst_bidx = 0;
+               dst_cidx = 0;
+       } else if (direction == DMA_DEV_TO_MEM)  {
+               src_bidx = 0;
+               src_cidx = 0;
+               dst_bidx = acnt;
+               dst_cidx = cidx;
+       } else {
+               dev_err(dev, "%s: direction not implemented yet\n", __func__);
+               return -EINVAL;
+       }
+
+       pset->opt = EDMA_TCC(EDMA_CHAN_SLOT(echan->ch_num));
+       /* Configure A or AB synchronized transfers */
+       if (absync)
+               pset->opt |= SYNCDIM;
+
+       pset->src = src_addr;
+       pset->dst = dst_addr;
+
+       pset->src_dst_bidx = (dst_bidx << 16) | src_bidx;
+       pset->src_dst_cidx = (dst_cidx << 16) | src_cidx;
+
+       pset->a_b_cnt = bcnt << 16 | acnt;
+       pset->ccnt = ccnt;
+       /*
+        * Only time when (bcntrld) auto reload is required is for
+        * A-sync case, and in this case, a requirement of reload value
+        * of SZ_64K-1 only is assured. 'link' is initially set to NULL
+        * and then later will be populated by edma_execute.
+        */
+       pset->link_bcntrld = 0xffffffff;
+       return absync;
+}
+
 static struct dma_async_tx_descriptor *edma_prep_slave_sg(
        struct dma_chan *chan, struct scatterlist *sgl,
        unsigned int sg_len, enum dma_transfer_direction direction,
@@ -258,23 +381,21 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
        struct edma_chan *echan = to_edma_chan(chan);
        struct device *dev = chan->device->dev;
        struct edma_desc *edesc;
-       dma_addr_t dev_addr;
+       dma_addr_t src_addr = 0, dst_addr = 0;
        enum dma_slave_buswidth dev_width;
        u32 burst;
        struct scatterlist *sg;
-       int acnt, bcnt, ccnt, src, dst, cidx;
-       int src_bidx, dst_bidx, src_cidx, dst_cidx;
-       int i, nslots;
+       int i, nslots, ret;
 
        if (unlikely(!echan || !sgl || !sg_len))
                return NULL;
 
        if (direction == DMA_DEV_TO_MEM) {
-               dev_addr = echan->cfg.src_addr;
+               src_addr = echan->cfg.src_addr;
                dev_width = echan->cfg.src_addr_width;
                burst = echan->cfg.src_maxburst;
        } else if (direction == DMA_MEM_TO_DEV) {
-               dev_addr = echan->cfg.dst_addr;
+               dst_addr = echan->cfg.dst_addr;
                dev_width = echan->cfg.dst_addr_width;
                burst = echan->cfg.dst_maxburst;
        } else {
@@ -307,7 +428,6 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
                        if (echan->slot[i] < 0) {
                                kfree(edesc);
                                dev_err(dev, "Failed to allocate slot\n");
-                               kfree(edesc);
                                return NULL;
                        }
                }
@@ -315,64 +435,21 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
 
        /* Configure PaRAM sets for each SG */
        for_each_sg(sgl, sg, sg_len, i) {
-
-               acnt = dev_width;
-
-               /*
-                * If the maxburst is equal to the fifo width, use
-                * A-synced transfers. This allows for large contiguous
-                * buffer transfers using only one PaRAM set.
-                */
-               if (burst == 1) {
-                       edesc->absync = false;
-                       ccnt = sg_dma_len(sg) / acnt / (SZ_64K - 1);
-                       bcnt = sg_dma_len(sg) / acnt - ccnt * (SZ_64K - 1);
-                       if (bcnt)
-                               ccnt++;
-                       else
-                               bcnt = SZ_64K - 1;
-                       cidx = acnt;
-               /*
-                * If maxburst is greater than the fifo address_width,
-                * use AB-synced transfers where A count is the fifo
-                * address_width and B count is the maxburst. In this
-                * case, we are limited to transfers of C count frames
-                * of (address_width * maxburst) where C count is limited
-                * to SZ_64K-1. This places an upper bound on the length
-                * of an SG segment that can be handled.
-                */
-               } else {
-                       edesc->absync = true;
-                       bcnt = burst;
-                       ccnt = sg_dma_len(sg) / (acnt * bcnt);
-                       if (ccnt > (SZ_64K - 1)) {
-                               dev_err(dev, "Exceeded max SG segment size\n");
-                               kfree(edesc);
-                               return NULL;
-                       }
-                       cidx = acnt * bcnt;
+               /* Get address for each SG */
+               if (direction == DMA_DEV_TO_MEM)
+                       dst_addr = sg_dma_address(sg);
+               else
+                       src_addr = sg_dma_address(sg);
+
+               ret = edma_config_pset(chan, &edesc->pset[i], src_addr,
+                                      dst_addr, burst, dev_width,
+                                      sg_dma_len(sg), direction);
+               if (ret < 0) {
+                       kfree(edesc);
+                       return NULL;
                }
 
-               if (direction == DMA_MEM_TO_DEV) {
-                       src = sg_dma_address(sg);
-                       dst = dev_addr;
-                       src_bidx = acnt;
-                       src_cidx = cidx;
-                       dst_bidx = 0;
-                       dst_cidx = 0;
-               } else {
-                       src = dev_addr;
-                       dst = sg_dma_address(sg);
-                       src_bidx = 0;
-                       src_cidx = 0;
-                       dst_bidx = acnt;
-                       dst_cidx = cidx;
-               }
-
-               edesc->pset[i].opt = EDMA_TCC(EDMA_CHAN_SLOT(echan->ch_num));
-               /* Configure A or AB synchronized transfers */
-               if (edesc->absync)
-                       edesc->pset[i].opt |= SYNCDIM;
+               edesc->absync = ret;
 
                /* If this is the last in a current SG set of transactions,
                   enable interrupts so that next set is processed */
@@ -382,17 +459,138 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
                /* If this is the last set, enable completion interrupt flag */
                if (i == sg_len - 1)
                        edesc->pset[i].opt |= TCINTEN;
+       }
 
-               edesc->pset[i].src = src;
-               edesc->pset[i].dst = dst;
+       return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
+}
 
-               edesc->pset[i].src_dst_bidx = (dst_bidx << 16) | src_bidx;
-               edesc->pset[i].src_dst_cidx = (dst_cidx << 16) | src_cidx;
+static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
+       struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
+       size_t period_len, enum dma_transfer_direction direction,
+       unsigned long tx_flags, void *context)
+{
+       struct edma_chan *echan = to_edma_chan(chan);
+       struct device *dev = chan->device->dev;
+       struct edma_desc *edesc;
+       dma_addr_t src_addr, dst_addr;
+       enum dma_slave_buswidth dev_width;
+       u32 burst;
+       int i, ret, nslots;
+
+       if (unlikely(!echan || !buf_len || !period_len))
+               return NULL;
+
+       if (direction == DMA_DEV_TO_MEM) {
+               src_addr = echan->cfg.src_addr;
+               dst_addr = buf_addr;
+               dev_width = echan->cfg.src_addr_width;
+               burst = echan->cfg.src_maxburst;
+       } else if (direction == DMA_MEM_TO_DEV) {
+               src_addr = buf_addr;
+               dst_addr = echan->cfg.dst_addr;
+               dev_width = echan->cfg.dst_addr_width;
+               burst = echan->cfg.dst_maxburst;
+       } else {
+               dev_err(dev, "%s: bad direction?\n", __func__);
+               return NULL;
+       }
+
+       if (dev_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) {
+               dev_err(dev, "Undefined slave buswidth\n");
+               return NULL;
+       }
+
+       if (unlikely(buf_len % period_len)) {
+               dev_err(dev, "Period should be multiple of Buffer length\n");
+               return NULL;
+       }
+
+       nslots = (buf_len / period_len) + 1;
+
+       /*
+        * Cyclic DMA users such as audio cannot tolerate delays introduced
+        * by cases where the number of periods is more than the maximum
+        * number of SGs the EDMA driver can handle at a time. For DMA types
+        * such as Slave SGs, such delays are tolerable and synchronized,
+        * but the synchronization is difficult to achieve with Cyclic and
+        * cannot be guaranteed, so we error out early.
+        */
+       if (nslots > MAX_NR_SG)
+               return NULL;
+
+       edesc = kzalloc(sizeof(*edesc) + nslots *
+               sizeof(edesc->pset[0]), GFP_ATOMIC);
+       if (!edesc) {
+               dev_dbg(dev, "Failed to allocate a descriptor\n");
+               return NULL;
+       }
+
+       edesc->cyclic = 1;
+       edesc->pset_nr = nslots;
+
+       dev_dbg(dev, "%s: nslots=%d\n", __func__, nslots);
+       dev_dbg(dev, "%s: period_len=%d\n", __func__, period_len);
+       dev_dbg(dev, "%s: buf_len=%d\n", __func__, buf_len);
+
+       for (i = 0; i < nslots; i++) {
+               /* Allocate a PaRAM slot, if needed */
+               if (echan->slot[i] < 0) {
+                       echan->slot[i] =
+                               edma_alloc_slot(EDMA_CTLR(echan->ch_num),
+                                               EDMA_SLOT_ANY);
+                       if (echan->slot[i] < 0) {
+                               dev_err(dev, "Failed to allocate slot\n");
+                               return NULL;
+                       }
+               }
+
+               if (i == nslots - 1) {
+                       memcpy(&edesc->pset[i], &edesc->pset[0],
+                              sizeof(edesc->pset[0]));
+                       break;
+               }
+
+               ret = edma_config_pset(chan, &edesc->pset[i], src_addr,
+                                      dst_addr, burst, dev_width, period_len,
+                                      direction);
+               if (ret < 0)
+                       return NULL;
 
-               edesc->pset[i].a_b_cnt = bcnt << 16 | acnt;
-               edesc->pset[i].ccnt = ccnt;
-               edesc->pset[i].link_bcntrld = 0xffffffff;
+               if (direction == DMA_DEV_TO_MEM)
+                       dst_addr += period_len;
+               else
+                       src_addr += period_len;
 
+               dev_dbg(dev, "%s: Configure period %d of buf:\n", __func__, i);
+               dev_dbg(dev,
+                       "\n pset[%d]:\n"
+                       "  chnum\t%d\n"
+                       "  slot\t%d\n"
+                       "  opt\t%08x\n"
+                       "  src\t%08x\n"
+                       "  dst\t%08x\n"
+                       "  abcnt\t%08x\n"
+                       "  ccnt\t%08x\n"
+                       "  bidx\t%08x\n"
+                       "  cidx\t%08x\n"
+                       "  lkrld\t%08x\n",
+                       i, echan->ch_num, echan->slot[i],
+                       edesc->pset[i].opt,
+                       edesc->pset[i].src,
+                       edesc->pset[i].dst,
+                       edesc->pset[i].a_b_cnt,
+                       edesc->pset[i].ccnt,
+                       edesc->pset[i].src_dst_bidx,
+                       edesc->pset[i].src_dst_cidx,
+                       edesc->pset[i].link_bcntrld);
+
+               edesc->absync = ret;
+
+               /*
+                * Enable interrupts for every period because callback
+                * has to be called for every period.
+                */
+               edesc->pset[i].opt |= TCINTEN;
        }
 
        return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
@@ -406,30 +604,34 @@ static void edma_callback(unsigned ch_num, u16 ch_status, void *data)
        unsigned long flags;
        struct edmacc_param p;
 
-       /* Pause the channel */
-       edma_pause(echan->ch_num);
+       edesc = echan->edesc;
+
+       /* Pause the channel for non-cyclic */
+       if (!edesc || (edesc && !edesc->cyclic))
+               edma_pause(echan->ch_num);
 
        switch (ch_status) {
-       case DMA_COMPLETE:
+       case EDMA_DMA_COMPLETE:
                spin_lock_irqsave(&echan->vchan.lock, flags);
 
-               edesc = echan->edesc;
                if (edesc) {
-                       if (edesc->processed == edesc->pset_nr) {
+                       if (edesc->cyclic) {
+                               vchan_cyclic_callback(&edesc->vdesc);
+                       } else if (edesc->processed == edesc->pset_nr) {
                                dev_dbg(dev, "Transfer complete, stopping channel %d\n", ch_num);
                                edma_stop(echan->ch_num);
                                vchan_cookie_complete(&edesc->vdesc);
+                               edma_execute(echan);
                        } else {
                                dev_dbg(dev, "Intermediate transfer complete on channel %d\n", ch_num);
+                               edma_execute(echan);
                        }
-
-                       edma_execute(echan);
                }
 
                spin_unlock_irqrestore(&echan->vchan.lock, flags);
 
                break;
-       case DMA_CC_ERROR:
+       case EDMA_DMA_CC_ERROR:
                spin_lock_irqsave(&echan->vchan.lock, flags);
 
                edma_read_slot(EDMA_CHAN_SLOT(echan->slot[0]), &p);
@@ -579,7 +781,7 @@ static enum dma_status edma_tx_status(struct dma_chan *chan,
        unsigned long flags;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS || !txstate)
+       if (ret == DMA_COMPLETE || !txstate)
                return ret;
 
        spin_lock_irqsave(&echan->vchan.lock, flags);
@@ -619,6 +821,7 @@ static void edma_dma_init(struct edma_cc *ecc, struct dma_device *dma,
                          struct device *dev)
 {
        dma->device_prep_slave_sg = edma_prep_slave_sg;
+       dma->device_prep_dma_cyclic = edma_prep_dma_cyclic;
        dma->device_alloc_chan_resources = edma_alloc_chan_resources;
        dma->device_free_chan_resources = edma_free_chan_resources;
        dma->device_issue_pending = edma_issue_pending;
index 591cd8c63abbcb081a4cd2ca264ed118f7f3d782..cb4bf682a70863e6253396eb717cc7e9ae86e453 100644 (file)
@@ -733,28 +733,6 @@ static void ep93xx_dma_advance_work(struct ep93xx_dma_chan *edmac)
        spin_unlock_irqrestore(&edmac->lock, flags);
 }
 
-static void ep93xx_dma_unmap_buffers(struct ep93xx_dma_desc *desc)
-{
-       struct device *dev = desc->txd.chan->device->dev;
-
-       if (!(desc->txd.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-               if (desc->txd.flags & DMA_COMPL_SRC_UNMAP_SINGLE)
-                       dma_unmap_single(dev, desc->src_addr, desc->size,
-                                        DMA_TO_DEVICE);
-               else
-                       dma_unmap_page(dev, desc->src_addr, desc->size,
-                                      DMA_TO_DEVICE);
-       }
-       if (!(desc->txd.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-               if (desc->txd.flags & DMA_COMPL_DEST_UNMAP_SINGLE)
-                       dma_unmap_single(dev, desc->dst_addr, desc->size,
-                                        DMA_FROM_DEVICE);
-               else
-                       dma_unmap_page(dev, desc->dst_addr, desc->size,
-                                      DMA_FROM_DEVICE);
-       }
-}
-
 static void ep93xx_dma_tasklet(unsigned long data)
 {
        struct ep93xx_dma_chan *edmac = (struct ep93xx_dma_chan *)data;
@@ -787,13 +765,7 @@ static void ep93xx_dma_tasklet(unsigned long data)
 
        /* Now we can release all the chained descriptors */
        list_for_each_entry_safe(desc, d, &list, node) {
-               /*
-                * For the memcpy channels the API requires us to unmap the
-                * buffers unless requested otherwise.
-                */
-               if (!edmac->chan.private)
-                       ep93xx_dma_unmap_buffers(desc);
-
+               dma_descriptor_unmap(&desc->txd);
                ep93xx_dma_desc_put(edmac, desc);
        }
 
index 61517dd0d0b73b7077be4acc5cf075792a00d86e..7086a16a55f2ed488573e475e615600c80be767e 100644 (file)
@@ -870,22 +870,7 @@ static void fsldma_cleanup_descriptor(struct fsldma_chan *chan,
        /* Run any dependencies */
        dma_run_dependencies(txd);
 
-       /* Unmap the dst buffer, if requested */
-       if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-               if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE)
-                       dma_unmap_single(dev, dst, len, DMA_FROM_DEVICE);
-               else
-                       dma_unmap_page(dev, dst, len, DMA_FROM_DEVICE);
-       }
-
-       /* Unmap the src buffer, if requested */
-       if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-               if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE)
-                       dma_unmap_single(dev, src, len, DMA_TO_DEVICE);
-               else
-                       dma_unmap_page(dev, src, len, DMA_TO_DEVICE);
-       }
-
+       dma_descriptor_unmap(txd);
 #ifdef FSL_DMA_LD_DEBUG
        chan_dbg(chan, "LD %p free\n", desc);
 #endif
@@ -1255,7 +1240,9 @@ static int fsl_dma_chan_probe(struct fsldma_device *fdev,
        WARN_ON(fdev->feature != chan->feature);
 
        chan->dev = fdev->dev;
-       chan->id = ((res.start - 0x100) & 0xfff) >> 7;
+       chan->id = (res.start & 0xfff) < 0x300 ?
+                  ((res.start - 0x100) & 0xfff) >> 7 :
+                  ((res.start - 0x200) & 0xfff) >> 7;
        if (chan->id >= FSL_DMA_MAX_CHANS_PER_DEVICE) {
                dev_err(fdev->dev, "too many channels for device\n");
                err = -EINVAL;
@@ -1428,6 +1415,7 @@ static int fsldma_of_remove(struct platform_device *op)
 }
 
 static const struct of_device_id fsldma_of_ids[] = {
+       { .compatible = "fsl,elo3-dma", },
        { .compatible = "fsl,eloplus-dma", },
        { .compatible = "fsl,elo-dma", },
        {}
@@ -1449,7 +1437,7 @@ static struct platform_driver fsldma_of_driver = {
 
 static __init int fsldma_init(void)
 {
-       pr_info("Freescale Elo / Elo Plus DMA driver\n");
+       pr_info("Freescale Elo series DMA driver\n");
        return platform_driver_register(&fsldma_of_driver);
 }
 
@@ -1461,5 +1449,5 @@ static void __exit fsldma_exit(void)
 subsys_initcall(fsldma_init);
 module_exit(fsldma_exit);
 
-MODULE_DESCRIPTION("Freescale Elo / Elo Plus DMA driver");
+MODULE_DESCRIPTION("Freescale Elo series DMA driver");
 MODULE_LICENSE("GPL");
index f5c38791fc7466f5d683b2ee49e718d8c29d5ca6..1ffc24484d23cdb0edd1e6011605aff5c9a6eb07 100644 (file)
@@ -112,7 +112,7 @@ struct fsldma_chan_regs {
 };
 
 struct fsldma_chan;
-#define FSL_DMA_MAX_CHANS_PER_DEVICE 4
+#define FSL_DMA_MAX_CHANS_PER_DEVICE 8
 
 struct fsldma_device {
        void __iomem *regs;     /* DGSR register base */
index 55852c02679143f453286f189e68fd777ea1afaa..6f9ac2022abd8b3d23c739bc7face1cf662a39f3 100644 (file)
@@ -572,9 +572,11 @@ static int imxdma_xfer_desc(struct imxdma_desc *d)
 
                imx_dmav1_writel(imxdma, d->len, DMA_CNTR(imxdmac->channel));
 
-               dev_dbg(imxdma->dev, "%s channel: %d dest=0x%08x src=0x%08x "
-                       "dma_length=%d\n", __func__, imxdmac->channel,
-                       d->dest, d->src, d->len);
+               dev_dbg(imxdma->dev,
+                       "%s channel: %d dest=0x%08llx src=0x%08llx dma_length=%zu\n",
+                       __func__, imxdmac->channel,
+                       (unsigned long long)d->dest,
+                       (unsigned long long)d->src, d->len);
 
                break;
        /* Cyclic transfer is the same as slave_sg with special sg configuration. */
@@ -586,20 +588,22 @@ static int imxdma_xfer_desc(struct imxdma_desc *d)
                        imx_dmav1_writel(imxdma, imxdmac->ccr_from_device,
                                         DMA_CCR(imxdmac->channel));
 
-                       dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
-                               "total length=%d dev_addr=0x%08x (dev2mem)\n",
-                               __func__, imxdmac->channel, d->sg, d->sgcount,
-                               d->len, imxdmac->per_address);
+                       dev_dbg(imxdma->dev,
+                               "%s channel: %d sg=%p sgcount=%d total length=%zu dev_addr=0x%08llx (dev2mem)\n",
+                               __func__, imxdmac->channel,
+                               d->sg, d->sgcount, d->len,
+                               (unsigned long long)imxdmac->per_address);
                } else if (d->direction == DMA_MEM_TO_DEV) {
                        imx_dmav1_writel(imxdma, imxdmac->per_address,
                                         DMA_DAR(imxdmac->channel));
                        imx_dmav1_writel(imxdma, imxdmac->ccr_to_device,
                                         DMA_CCR(imxdmac->channel));
 
-                       dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
-                               "total length=%d dev_addr=0x%08x (mem2dev)\n",
-                               __func__, imxdmac->channel, d->sg, d->sgcount,
-                               d->len, imxdmac->per_address);
+                       dev_dbg(imxdma->dev,
+                               "%s channel: %d sg=%p sgcount=%d total length=%zu dev_addr=0x%08llx (mem2dev)\n",
+                               __func__, imxdmac->channel,
+                               d->sg, d->sgcount, d->len,
+                               (unsigned long long)imxdmac->per_address);
                } else {
                        dev_err(imxdma->dev, "%s channel: %d bad dma mode\n",
                                __func__, imxdmac->channel);
@@ -771,7 +775,7 @@ static int imxdma_alloc_chan_resources(struct dma_chan *chan)
                desc->desc.tx_submit = imxdma_tx_submit;
                /* txd.flags will be overwritten in prep funcs */
                desc->desc.flags = DMA_CTRL_ACK;
-               desc->status = DMA_SUCCESS;
+               desc->status = DMA_COMPLETE;
 
                list_add_tail(&desc->node, &imxdmac->ld_free);
                imxdmac->descs_allocated++;
@@ -870,7 +874,7 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
        int i;
        unsigned int periods = buf_len / period_len;
 
-       dev_dbg(imxdma->dev, "%s channel: %d buf_len=%d period_len=%d\n",
+       dev_dbg(imxdma->dev, "%s channel: %d buf_len=%zu period_len=%zu\n",
                        __func__, imxdmac->channel, buf_len, period_len);
 
        if (list_empty(&imxdmac->ld_free) ||
@@ -926,8 +930,9 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_memcpy(
        struct imxdma_engine *imxdma = imxdmac->imxdma;
        struct imxdma_desc *desc;
 
-       dev_dbg(imxdma->dev, "%s channel: %d src=0x%x dst=0x%x len=%d\n",
-                       __func__, imxdmac->channel, src, dest, len);
+       dev_dbg(imxdma->dev, "%s channel: %d src=0x%llx dst=0x%llx len=%zu\n",
+               __func__, imxdmac->channel, (unsigned long long)src,
+               (unsigned long long)dest, len);
 
        if (list_empty(&imxdmac->ld_free) ||
            imxdma_chan_is_doing_cyclic(imxdmac))
@@ -956,9 +961,10 @@ static struct dma_async_tx_descriptor *imxdma_prep_dma_interleaved(
        struct imxdma_engine *imxdma = imxdmac->imxdma;
        struct imxdma_desc *desc;
 
-       dev_dbg(imxdma->dev, "%s channel: %d src_start=0x%x dst_start=0x%x\n"
-               "   src_sgl=%s dst_sgl=%s numf=%d frame_size=%d\n", __func__,
-               imxdmac->channel, xt->src_start, xt->dst_start,
+       dev_dbg(imxdma->dev, "%s channel: %d src_start=0x%llx dst_start=0x%llx\n"
+               "   src_sgl=%s dst_sgl=%s numf=%zu frame_size=%zu\n", __func__,
+               imxdmac->channel, (unsigned long long)xt->src_start,
+               (unsigned long long) xt->dst_start,
                xt->src_sgl ? "true" : "false", xt->dst_sgl ? "true" : "false",
                xt->numf, xt->frame_size);
 
index c1fd504cae282491969886b0d0336784229e422d..c75679d420286c522679cdb9c344549c97e7a0c4 100644 (file)
@@ -638,7 +638,7 @@ static void mxc_sdma_handle_channel_normal(struct sdma_channel *sdmac)
        if (error)
                sdmac->status = DMA_ERROR;
        else
-               sdmac->status = DMA_SUCCESS;
+               sdmac->status = DMA_COMPLETE;
 
        dma_cookie_complete(&sdmac->desc);
        if (sdmac->desc.callback)
@@ -1089,8 +1089,8 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
                        param &= ~BD_CONT;
                }
 
-               dev_dbg(sdma->dev, "entry %d: count: %d dma: 0x%08x %s%s\n",
-                               i, count, sg->dma_address,
+               dev_dbg(sdma->dev, "entry %d: count: %d dma: %#llx %s%s\n",
+                               i, count, (u64)sg->dma_address,
                                param & BD_WRAP ? "wrap" : "",
                                param & BD_INTR ? " intr" : "");
 
@@ -1163,8 +1163,8 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
                if (i + 1 == num_periods)
                        param |= BD_WRAP;
 
-               dev_dbg(sdma->dev, "entry %d: count: %d dma: 0x%08x %s%s\n",
-                               i, period_len, dma_addr,
+               dev_dbg(sdma->dev, "entry %d: count: %d dma: %#llx %s%s\n",
+                               i, period_len, (u64)dma_addr,
                                param & BD_WRAP ? "wrap" : "",
                                param & BD_INTR ? " intr" : "");
 
index a975ebebea8aaf9b8950497eefdcaf3793d930d2..1aab8130efa1c75ae51906938447c91d12a66ddc 100644 (file)
@@ -309,7 +309,7 @@ static void midc_descriptor_complete(struct intel_mid_dma_chan *midc,
                callback_txd(param_txd);
        }
        if (midc->raw_tfr) {
-               desc->status = DMA_SUCCESS;
+               desc->status = DMA_COMPLETE;
                if (desc->lli != NULL) {
                        pci_pool_free(desc->lli_pool, desc->lli,
                                                desc->lli_phys);
@@ -481,7 +481,7 @@ static enum dma_status intel_mid_dma_tx_status(struct dma_chan *chan,
        enum dma_status ret;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret != DMA_SUCCESS) {
+       if (ret != DMA_COMPLETE) {
                spin_lock_bh(&midc->lock);
                midc_scan_descriptors(to_middma_device(chan->device), midc);
                spin_unlock_bh(&midc->lock);
index 5ff6fc1819dc6a2e90c035956b23e23c56f9bb5d..1a49c777607c50d313482f3ead21c19572a1cf8d 100644 (file)
@@ -531,21 +531,6 @@ static void ioat1_cleanup_event(unsigned long data)
        writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
 }
 
-void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
-                   size_t len, struct ioat_dma_descriptor *hw)
-{
-       struct pci_dev *pdev = chan->device->pdev;
-       size_t offset = len - hw->size;
-
-       if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
-               ioat_unmap(pdev, hw->dst_addr - offset, len,
-                          PCI_DMA_FROMDEVICE, flags, 1);
-
-       if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP))
-               ioat_unmap(pdev, hw->src_addr - offset, len,
-                          PCI_DMA_TODEVICE, flags, 0);
-}
-
 dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan)
 {
        dma_addr_t phys_complete;
@@ -602,7 +587,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, dma_addr_t phys_complete)
                dump_desc_dbg(ioat, desc);
                if (tx->cookie) {
                        dma_cookie_complete(tx);
-                       ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
+                       dma_descriptor_unmap(tx);
                        ioat->active -= desc->hw->tx_cnt;
                        if (tx->callback) {
                                tx->callback(tx->callback_param);
@@ -733,7 +718,7 @@ ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
        enum dma_status ret;
 
        ret = dma_cookie_status(c, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        device->cleanup_fn((unsigned long) c);
@@ -833,8 +818,7 @@ int ioat_dma_self_test(struct ioatdma_device *device)
 
        dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
        dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
-       flags = DMA_COMPL_SKIP_SRC_UNMAP | DMA_COMPL_SKIP_DEST_UNMAP |
-               DMA_PREP_INTERRUPT;
+       flags = DMA_PREP_INTERRUPT;
        tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
                                                   IOAT_TEST_SIZE, flags);
        if (!tx) {
@@ -859,7 +843,7 @@ int ioat_dma_self_test(struct ioatdma_device *device)
 
        if (tmo == 0 ||
            dma->device_tx_status(dma_chan, cookie, NULL)
-                                       != DMA_SUCCESS) {
+                                       != DMA_COMPLETE) {
                dev_err(dev, "Self-test copy timed out, disabling\n");
                err = -ENODEV;
                goto unmap_dma;
@@ -885,8 +869,7 @@ static char ioat_interrupt_style[32] = "msix";
 module_param_string(ioat_interrupt_style, ioat_interrupt_style,
                    sizeof(ioat_interrupt_style), 0644);
 MODULE_PARM_DESC(ioat_interrupt_style,
-                "set ioat interrupt style: msix (default), "
-                "msix-single-vector, msi, intx)");
+                "set ioat interrupt style: msix (default), msi, intx");
 
 /**
  * ioat_dma_setup_interrupts - setup interrupt handler
@@ -904,8 +887,6 @@ int ioat_dma_setup_interrupts(struct ioatdma_device *device)
 
        if (!strcmp(ioat_interrupt_style, "msix"))
                goto msix;
-       if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
-               goto msix_single_vector;
        if (!strcmp(ioat_interrupt_style, "msi"))
                goto msi;
        if (!strcmp(ioat_interrupt_style, "intx"))
@@ -920,10 +901,8 @@ msix:
                device->msix_entries[i].entry = i;
 
        err = pci_enable_msix(pdev, device->msix_entries, msixcnt);
-       if (err < 0)
+       if (err)
                goto msi;
-       if (err > 0)
-               goto msix_single_vector;
 
        for (i = 0; i < msixcnt; i++) {
                msix = &device->msix_entries[i];
@@ -937,29 +916,13 @@ msix:
                                chan = ioat_chan_by_index(device, j);
                                devm_free_irq(dev, msix->vector, chan);
                        }
-                       goto msix_single_vector;
+                       goto msi;
                }
        }
        intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
        device->irq_mode = IOAT_MSIX;
        goto done;
 
-msix_single_vector:
-       msix = &device->msix_entries[0];
-       msix->entry = 0;
-       err = pci_enable_msix(pdev, device->msix_entries, 1);
-       if (err)
-               goto msi;
-
-       err = devm_request_irq(dev, msix->vector, ioat_dma_do_interrupt, 0,
-                              "ioat-msix", device);
-       if (err) {
-               pci_disable_msix(pdev);
-               goto msi;
-       }
-       device->irq_mode = IOAT_MSIX_SINGLE;
-       goto done;
-
 msi:
        err = pci_enable_msi(pdev);
        if (err)
@@ -971,7 +934,7 @@ msi:
                pci_disable_msi(pdev);
                goto intx;
        }
-       device->irq_mode = IOAT_MSIX;
+       device->irq_mode = IOAT_MSI;
        goto done;
 
 intx:
index 54fb7b9ff9aaa4afb88c823b3a129a22440a9320..11fb877ddca9a9b0888d23952dea8fb48245b617 100644 (file)
@@ -52,7 +52,6 @@
 enum ioat_irq_mode {
        IOAT_NOIRQ = 0,
        IOAT_MSIX,
-       IOAT_MSIX_SINGLE,
        IOAT_MSI,
        IOAT_INTX
 };
@@ -83,7 +82,6 @@ struct ioatdma_device {
        struct pci_pool *completion_pool;
 #define MAX_SED_POOLS  5
        struct dma_pool *sed_hw_pool[MAX_SED_POOLS];
-       struct kmem_cache *sed_pool;
        struct dma_device common;
        u8 version;
        struct msix_entry msix_entries[4];
@@ -342,16 +340,6 @@ static inline bool is_ioat_bug(unsigned long err)
        return !!err;
 }
 
-static inline void ioat_unmap(struct pci_dev *pdev, dma_addr_t addr, size_t len,
-                             int direction, enum dma_ctrl_flags flags, bool dst)
-{
-       if ((dst && (flags & DMA_COMPL_DEST_UNMAP_SINGLE)) ||
-           (!dst && (flags & DMA_COMPL_SRC_UNMAP_SINGLE)))
-               pci_unmap_single(pdev, addr, len, direction);
-       else
-               pci_unmap_page(pdev, addr, len, direction);
-}
-
 int ioat_probe(struct ioatdma_device *device);
 int ioat_register(struct ioatdma_device *device);
 int ioat1_dma_probe(struct ioatdma_device *dev, int dca);
@@ -363,8 +351,6 @@ void ioat_init_channel(struct ioatdma_device *device,
                       struct ioat_chan_common *chan, int idx);
 enum dma_status ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
                                   struct dma_tx_state *txstate);
-void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
-                   size_t len, struct ioat_dma_descriptor *hw);
 bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
                           dma_addr_t *phys_complete);
 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
index b925e1b1d139bddbc6edf86f34d4b943ebfb086c..5d3affe7e976165ec5576ac8c6551dd438af7786 100644 (file)
@@ -148,7 +148,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
                tx = &desc->txd;
                dump_desc_dbg(ioat, desc);
                if (tx->cookie) {
-                       ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
+                       dma_descriptor_unmap(tx);
                        dma_cookie_complete(tx);
                        if (tx->callback) {
                                tx->callback(tx->callback_param);
index 212d584fe4272a37d947cc72b95e836d801b77b1..470292767e68e81e390e1b9065954fd2546e04e6 100644 (file)
@@ -157,7 +157,6 @@ static inline void ioat2_set_chainaddr(struct ioat2_dma_chan *ioat, u64 addr)
 
 int ioat2_dma_probe(struct ioatdma_device *dev, int dca);
 int ioat3_dma_probe(struct ioatdma_device *dev, int dca);
-void ioat3_dma_remove(struct ioatdma_device *dev);
 struct dca_provider *ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase);
 struct dca_provider *ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase);
 int ioat2_check_space_lock(struct ioat2_dma_chan *ioat, int num_descs);
index d8ececaf1b57082cc5709aca68714542657b5566..820817e97e626a498561a9e5f0f3a61f22ffc9fa 100644 (file)
@@ -67,6 +67,8 @@
 #include "dma.h"
 #include "dma_v2.h"
 
+extern struct kmem_cache *ioat3_sed_cache;
+
 /* ioat hardware assumes at least two sources for raid operations */
 #define src_cnt_to_sw(x) ((x) + 2)
 #define src_cnt_to_hw(x) ((x) - 2)
@@ -87,22 +89,8 @@ static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
 static const u8 pq16_idx_to_field[] = { 1, 4, 1, 2, 3, 4, 5, 6, 7,
                                        0, 1, 2, 3, 4, 5, 6 };
 
-/*
- * technically sources 1 and 2 do not require SED, but the op will have
- * at least 9 descriptors so that's irrelevant.
- */
-static const u8 pq16_idx_to_sed[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                                     1, 1, 1, 1, 1, 1, 1 };
-
 static void ioat3_eh(struct ioat2_dma_chan *ioat);
 
-static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
-{
-       struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
-
-       return raw->field[xor_idx_to_field[idx]];
-}
-
 static void xor_set_src(struct ioat_raw_descriptor *descs[2],
                        dma_addr_t addr, u32 offset, int idx)
 {
@@ -135,12 +123,6 @@ static void pq_set_src(struct ioat_raw_descriptor *descs[2],
        pq->coef[idx] = coef;
 }
 
-static int sed_get_pq16_pool_idx(int src_cnt)
-{
-
-       return pq16_idx_to_sed[src_cnt];
-}
-
 static bool is_jf_ioat(struct pci_dev *pdev)
 {
        switch (pdev->device) {
@@ -272,7 +254,7 @@ ioat3_alloc_sed(struct ioatdma_device *device, unsigned int hw_pool)
        struct ioat_sed_ent *sed;
        gfp_t flags = __GFP_ZERO | GFP_ATOMIC;
 
-       sed = kmem_cache_alloc(device->sed_pool, flags);
+       sed = kmem_cache_alloc(ioat3_sed_cache, flags);
        if (!sed)
                return NULL;
 
@@ -280,7 +262,7 @@ ioat3_alloc_sed(struct ioatdma_device *device, unsigned int hw_pool)
        sed->hw = dma_pool_alloc(device->sed_hw_pool[hw_pool],
                                 flags, &sed->dma);
        if (!sed->hw) {
-               kmem_cache_free(device->sed_pool, sed);
+               kmem_cache_free(ioat3_sed_cache, sed);
                return NULL;
        }
 
@@ -293,165 +275,7 @@ static void ioat3_free_sed(struct ioatdma_device *device, struct ioat_sed_ent *s
                return;
 
        dma_pool_free(device->sed_hw_pool[sed->hw_pool], sed->hw, sed->dma);
-       kmem_cache_free(device->sed_pool, sed);
-}
-
-static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat,
-                           struct ioat_ring_ent *desc, int idx)
-{
-       struct ioat_chan_common *chan = &ioat->base;
-       struct pci_dev *pdev = chan->device->pdev;
-       size_t len = desc->len;
-       size_t offset = len - desc->hw->size;
-       struct dma_async_tx_descriptor *tx = &desc->txd;
-       enum dma_ctrl_flags flags = tx->flags;
-
-       switch (desc->hw->ctl_f.op) {
-       case IOAT_OP_COPY:
-               if (!desc->hw->ctl_f.null) /* skip 'interrupt' ops */
-                       ioat_dma_unmap(chan, flags, len, desc->hw);
-               break;
-       case IOAT_OP_XOR_VAL:
-       case IOAT_OP_XOR: {
-               struct ioat_xor_descriptor *xor = desc->xor;
-               struct ioat_ring_ent *ext;
-               struct ioat_xor_ext_descriptor *xor_ex = NULL;
-               int src_cnt = src_cnt_to_sw(xor->ctl_f.src_cnt);
-               struct ioat_raw_descriptor *descs[2];
-               int i;
-
-               if (src_cnt > 5) {
-                       ext = ioat2_get_ring_ent(ioat, idx + 1);
-                       xor_ex = ext->xor_ex;
-               }
-
-               if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                       descs[0] = (struct ioat_raw_descriptor *) xor;
-                       descs[1] = (struct ioat_raw_descriptor *) xor_ex;
-                       for (i = 0; i < src_cnt; i++) {
-                               dma_addr_t src = xor_get_src(descs, i);
-
-                               ioat_unmap(pdev, src - offset, len,
-                                          PCI_DMA_TODEVICE, flags, 0);
-                       }
-
-                       /* dest is a source in xor validate operations */
-                       if (xor->ctl_f.op == IOAT_OP_XOR_VAL) {
-                               ioat_unmap(pdev, xor->dst_addr - offset, len,
-                                          PCI_DMA_TODEVICE, flags, 1);
-                               break;
-                       }
-               }
-
-               if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
-                       ioat_unmap(pdev, xor->dst_addr - offset, len,
-                                  PCI_DMA_FROMDEVICE, flags, 1);
-               break;
-       }
-       case IOAT_OP_PQ_VAL:
-       case IOAT_OP_PQ: {
-               struct ioat_pq_descriptor *pq = desc->pq;
-               struct ioat_ring_ent *ext;
-               struct ioat_pq_ext_descriptor *pq_ex = NULL;
-               int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
-               struct ioat_raw_descriptor *descs[2];
-               int i;
-
-               if (src_cnt > 3) {
-                       ext = ioat2_get_ring_ent(ioat, idx + 1);
-                       pq_ex = ext->pq_ex;
-               }
-
-               /* in the 'continue' case don't unmap the dests as sources */
-               if (dmaf_p_disabled_continue(flags))
-                       src_cnt--;
-               else if (dmaf_continue(flags))
-                       src_cnt -= 3;
-
-               if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                       descs[0] = (struct ioat_raw_descriptor *) pq;
-                       descs[1] = (struct ioat_raw_descriptor *) pq_ex;
-                       for (i = 0; i < src_cnt; i++) {
-                               dma_addr_t src = pq_get_src(descs, i);
-
-                               ioat_unmap(pdev, src - offset, len,
-                                          PCI_DMA_TODEVICE, flags, 0);
-                       }
-
-                       /* the dests are sources in pq validate operations */
-                       if (pq->ctl_f.op == IOAT_OP_XOR_VAL) {
-                               if (!(flags & DMA_PREP_PQ_DISABLE_P))
-                                       ioat_unmap(pdev, pq->p_addr - offset,
-                                                  len, PCI_DMA_TODEVICE, flags, 0);
-                               if (!(flags & DMA_PREP_PQ_DISABLE_Q))
-                                       ioat_unmap(pdev, pq->q_addr - offset,
-                                                  len, PCI_DMA_TODEVICE, flags, 0);
-                               break;
-                       }
-               }
-
-               if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-                       if (!(flags & DMA_PREP_PQ_DISABLE_P))
-                               ioat_unmap(pdev, pq->p_addr - offset, len,
-                                          PCI_DMA_BIDIRECTIONAL, flags, 1);
-                       if (!(flags & DMA_PREP_PQ_DISABLE_Q))
-                               ioat_unmap(pdev, pq->q_addr - offset, len,
-                                          PCI_DMA_BIDIRECTIONAL, flags, 1);
-               }
-               break;
-       }
-       case IOAT_OP_PQ_16S:
-       case IOAT_OP_PQ_VAL_16S: {
-               struct ioat_pq_descriptor *pq = desc->pq;
-               int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt);
-               struct ioat_raw_descriptor *descs[4];
-               int i;
-
-               /* in the 'continue' case don't unmap the dests as sources */
-               if (dmaf_p_disabled_continue(flags))
-                       src_cnt--;
-               else if (dmaf_continue(flags))
-                       src_cnt -= 3;
-
-               if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                       descs[0] = (struct ioat_raw_descriptor *)pq;
-                       descs[1] = (struct ioat_raw_descriptor *)(desc->sed->hw);
-                       descs[2] = (struct ioat_raw_descriptor *)(&desc->sed->hw->b[0]);
-                       for (i = 0; i < src_cnt; i++) {
-                               dma_addr_t src = pq16_get_src(descs, i);
-
-                               ioat_unmap(pdev, src - offset, len,
-                                          PCI_DMA_TODEVICE, flags, 0);
-                       }
-
-                       /* the dests are sources in pq validate operations */
-                       if (pq->ctl_f.op == IOAT_OP_XOR_VAL) {
-                               if (!(flags & DMA_PREP_PQ_DISABLE_P))
-                                       ioat_unmap(pdev, pq->p_addr - offset,
-                                                  len, PCI_DMA_TODEVICE,
-                                                  flags, 0);
-                               if (!(flags & DMA_PREP_PQ_DISABLE_Q))
-                                       ioat_unmap(pdev, pq->q_addr - offset,
-                                                  len, PCI_DMA_TODEVICE,
-                                                  flags, 0);
-                               break;
-                       }
-               }
-
-               if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-                       if (!(flags & DMA_PREP_PQ_DISABLE_P))
-                               ioat_unmap(pdev, pq->p_addr - offset, len,
-                                          PCI_DMA_BIDIRECTIONAL, flags, 1);
-                       if (!(flags & DMA_PREP_PQ_DISABLE_Q))
-                               ioat_unmap(pdev, pq->q_addr - offset, len,
-                                          PCI_DMA_BIDIRECTIONAL, flags, 1);
-               }
-               break;
-       }
-       default:
-               dev_err(&pdev->dev, "%s: unknown op type: %#x\n",
-                       __func__, desc->hw->ctl_f.op);
-       }
+       kmem_cache_free(ioat3_sed_cache, sed);
 }
 
 static bool desc_has_ext(struct ioat_ring_ent *desc)
@@ -577,7 +401,7 @@ static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
                tx = &desc->txd;
                if (tx->cookie) {
                        dma_cookie_complete(tx);
-                       ioat3_dma_unmap(ioat, desc, idx + i);
+                       dma_descriptor_unmap(tx);
                        if (tx->callback) {
                                tx->callback(tx->callback_param);
                                tx->callback = NULL;
@@ -807,7 +631,7 @@ ioat3_tx_status(struct dma_chan *c, dma_cookie_t cookie,
        enum dma_status ret;
 
        ret = dma_cookie_status(c, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        ioat3_cleanup(ioat);
@@ -1129,9 +953,6 @@ __ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
        u8 op;
        int i, s, idx, num_descs;
 
-       /* this function only handles src_cnt 9 - 16 */
-       BUG_ON(src_cnt < 9);
-
        /* this function is only called with 9-16 sources */
        op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S;
 
@@ -1159,8 +980,7 @@ __ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
 
                descs[0] = (struct ioat_raw_descriptor *) pq;
 
-               desc->sed = ioat3_alloc_sed(device,
-                                           sed_get_pq16_pool_idx(src_cnt));
+               desc->sed = ioat3_alloc_sed(device, (src_cnt-2) >> 3);
                if (!desc->sed) {
                        dev_err(to_dev(chan),
                                "%s: no free sed entries\n", __func__);
@@ -1218,13 +1038,21 @@ __ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
        return &desc->txd;
 }
 
+static int src_cnt_flags(unsigned int src_cnt, unsigned long flags)
+{
+       if (dmaf_p_disabled_continue(flags))
+               return src_cnt + 1;
+       else if (dmaf_continue(flags))
+               return src_cnt + 3;
+       else
+               return src_cnt;
+}
+
 static struct dma_async_tx_descriptor *
 ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
              unsigned int src_cnt, const unsigned char *scf, size_t len,
              unsigned long flags)
 {
-       struct dma_device *dma = chan->device;
-
        /* specify valid address for disabled result */
        if (flags & DMA_PREP_PQ_DISABLE_P)
                dst[0] = dst[1];
@@ -1244,7 +1072,7 @@ ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
                single_source_coef[0] = scf[0];
                single_source_coef[1] = 0;
 
-               return (src_cnt > 8) && (dma->max_pq > 8) ?
+               return src_cnt_flags(src_cnt, flags) > 8 ?
                        __ioat3_prep_pq16_lock(chan, NULL, dst, single_source,
                                               2, single_source_coef, len,
                                               flags) :
@@ -1252,7 +1080,7 @@ ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
                                             single_source_coef, len, flags);
 
        } else {
-               return (src_cnt > 8) && (dma->max_pq > 8) ?
+               return src_cnt_flags(src_cnt, flags) > 8 ?
                        __ioat3_prep_pq16_lock(chan, NULL, dst, src, src_cnt,
                                               scf, len, flags) :
                        __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt,
@@ -1265,8 +1093,6 @@ ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
                  unsigned int src_cnt, const unsigned char *scf, size_t len,
                  enum sum_check_flags *pqres, unsigned long flags)
 {
-       struct dma_device *dma = chan->device;
-
        /* specify valid address for disabled result */
        if (flags & DMA_PREP_PQ_DISABLE_P)
                pq[0] = pq[1];
@@ -1278,7 +1104,7 @@ ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
         */
        *pqres = 0;
 
-       return (src_cnt > 8) && (dma->max_pq > 8) ?
+       return src_cnt_flags(src_cnt, flags) > 8 ?
                __ioat3_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len,
                                       flags) :
                __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
@@ -1289,7 +1115,6 @@ static struct dma_async_tx_descriptor *
 ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
                 unsigned int src_cnt, size_t len, unsigned long flags)
 {
-       struct dma_device *dma = chan->device;
        unsigned char scf[src_cnt];
        dma_addr_t pq[2];
 
@@ -1298,7 +1123,7 @@ ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
        flags |= DMA_PREP_PQ_DISABLE_Q;
        pq[1] = dst; /* specify valid address for disabled result */
 
-       return (src_cnt > 8) && (dma->max_pq > 8) ?
+       return src_cnt_flags(src_cnt, flags) > 8 ?
                __ioat3_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len,
                                       flags) :
                __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
@@ -1310,7 +1135,6 @@ ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
                     unsigned int src_cnt, size_t len,
                     enum sum_check_flags *result, unsigned long flags)
 {
-       struct dma_device *dma = chan->device;
        unsigned char scf[src_cnt];
        dma_addr_t pq[2];
 
@@ -1324,8 +1148,7 @@ ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
        flags |= DMA_PREP_PQ_DISABLE_Q;
        pq[1] = pq[0]; /* specify valid address for disabled result */
 
-
-       return (src_cnt > 8) && (dma->max_pq > 8) ?
+       return src_cnt_flags(src_cnt, flags) > 8 ?
                __ioat3_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
                                       scf, len, flags) :
                __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,
@@ -1444,9 +1267,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
                                           DMA_TO_DEVICE);
        tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
                                      IOAT_NUM_SRC_TEST, PAGE_SIZE,
-                                     DMA_PREP_INTERRUPT |
-                                     DMA_COMPL_SKIP_SRC_UNMAP |
-                                     DMA_COMPL_SKIP_DEST_UNMAP);
+                                     DMA_PREP_INTERRUPT);
 
        if (!tx) {
                dev_err(dev, "Self-test xor prep failed\n");
@@ -1468,7 +1289,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
 
        tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
 
-       if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
+       if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
                dev_err(dev, "Self-test xor timed out\n");
                err = -ENODEV;
                goto dma_unmap;
@@ -1507,9 +1328,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
                                           DMA_TO_DEVICE);
        tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
                                          IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
-                                         &xor_val_result, DMA_PREP_INTERRUPT |
-                                         DMA_COMPL_SKIP_SRC_UNMAP |
-                                         DMA_COMPL_SKIP_DEST_UNMAP);
+                                         &xor_val_result, DMA_PREP_INTERRUPT);
        if (!tx) {
                dev_err(dev, "Self-test zero prep failed\n");
                err = -ENODEV;
@@ -1530,7 +1349,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
 
        tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
 
-       if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
+       if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
                dev_err(dev, "Self-test validate timed out\n");
                err = -ENODEV;
                goto dma_unmap;
@@ -1545,6 +1364,8 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
                goto free_resources;
        }
 
+       memset(page_address(dest), 0, PAGE_SIZE);
+
        /* test for non-zero parity sum */
        op = IOAT_OP_XOR_VAL;
 
@@ -1554,9 +1375,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
                                           DMA_TO_DEVICE);
        tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
                                          IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
-                                         &xor_val_result, DMA_PREP_INTERRUPT |
-                                         DMA_COMPL_SKIP_SRC_UNMAP |
-                                         DMA_COMPL_SKIP_DEST_UNMAP);
+                                         &xor_val_result, DMA_PREP_INTERRUPT);
        if (!tx) {
                dev_err(dev, "Self-test 2nd zero prep failed\n");
                err = -ENODEV;
@@ -1577,7 +1396,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
 
        tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
 
-       if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
+       if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
                dev_err(dev, "Self-test 2nd validate timed out\n");
                err = -ENODEV;
                goto dma_unmap;
@@ -1630,52 +1449,36 @@ static int ioat3_dma_self_test(struct ioatdma_device *device)
 
 static int ioat3_irq_reinit(struct ioatdma_device *device)
 {
-       int msixcnt = device->common.chancnt;
        struct pci_dev *pdev = device->pdev;
-       int i;
-       struct msix_entry *msix;
-       struct ioat_chan_common *chan;
-       int err = 0;
+       int irq = pdev->irq, i;
+
+       if (!is_bwd_ioat(pdev))
+               return 0;
 
        switch (device->irq_mode) {
        case IOAT_MSIX:
+               for (i = 0; i < device->common.chancnt; i++) {
+                       struct msix_entry *msix = &device->msix_entries[i];
+                       struct ioat_chan_common *chan;
 
-               for (i = 0; i < msixcnt; i++) {
-                       msix = &device->msix_entries[i];
                        chan = ioat_chan_by_index(device, i);
                        devm_free_irq(&pdev->dev, msix->vector, chan);
                }
 
                pci_disable_msix(pdev);
                break;
-
-       case IOAT_MSIX_SINGLE:
-               msix = &device->msix_entries[0];
-               chan = ioat_chan_by_index(device, 0);
-               devm_free_irq(&pdev->dev, msix->vector, chan);
-               pci_disable_msix(pdev);
-               break;
-
        case IOAT_MSI:
-               chan = ioat_chan_by_index(device, 0);
-               devm_free_irq(&pdev->dev, pdev->irq, chan);
                pci_disable_msi(pdev);
-               break;
-
+               /* fall through */
        case IOAT_INTX:
-               chan = ioat_chan_by_index(device, 0);
-               devm_free_irq(&pdev->dev, pdev->irq, chan);
+               devm_free_irq(&pdev->dev, irq, device);
                break;
-
        default:
                return 0;
        }
-
        device->irq_mode = IOAT_NOIRQ;
 
-       err = ioat_dma_setup_interrupts(device);
-
-       return err;
+       return ioat_dma_setup_interrupts(device);
 }
 
 static int ioat3_reset_hw(struct ioat_chan_common *chan)
@@ -1718,14 +1521,12 @@ static int ioat3_reset_hw(struct ioat_chan_common *chan)
        }
 
        err = ioat2_reset_sync(chan, msecs_to_jiffies(200));
-       if (err) {
-               dev_err(&pdev->dev, "Failed to reset!\n");
-               return err;
-       }
-
-       if (device->irq_mode != IOAT_NOIRQ && is_bwd_ioat(pdev))
+       if (!err)
                err = ioat3_irq_reinit(device);
 
+       if (err)
+               dev_err(&pdev->dev, "Failed to reset: %d\n", err);
+
        return err;
 }
 
@@ -1835,21 +1636,15 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
                char pool_name[14];
                int i;
 
-               /* allocate sw descriptor pool for SED */
-               device->sed_pool = kmem_cache_create("ioat_sed",
-                               sizeof(struct ioat_sed_ent), 0, 0, NULL);
-               if (!device->sed_pool)
-                       return -ENOMEM;
-
                for (i = 0; i < MAX_SED_POOLS; i++) {
                        snprintf(pool_name, 14, "ioat_hw%d_sed", i);
 
                        /* allocate SED DMA pool */
-                       device->sed_hw_pool[i] = dma_pool_create(pool_name,
+                       device->sed_hw_pool[i] = dmam_pool_create(pool_name,
                                        &pdev->dev,
                                        SED_SIZE * (i + 1), 64, 0);
                        if (!device->sed_hw_pool[i])
-                               goto sed_pool_cleanup;
+                               return -ENOMEM;
 
                }
        }
@@ -1875,28 +1670,4 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
                device->dca = ioat3_dca_init(pdev, device->reg_base);
 
        return 0;
-
-sed_pool_cleanup:
-       if (device->sed_pool) {
-               int i;
-               kmem_cache_destroy(device->sed_pool);
-
-               for (i = 0; i < MAX_SED_POOLS; i++)
-                       if (device->sed_hw_pool[i])
-                               dma_pool_destroy(device->sed_hw_pool[i]);
-       }
-
-       return -ENOMEM;
-}
-
-void ioat3_dma_remove(struct ioatdma_device *device)
-{
-       if (device->sed_pool) {
-               int i;
-               kmem_cache_destroy(device->sed_pool);
-
-               for (i = 0; i < MAX_SED_POOLS; i++)
-                       if (device->sed_hw_pool[i])
-                               dma_pool_destroy(device->sed_hw_pool[i]);
-       }
 }
index 2c8d560e6334123097627ab59ac166a47cb1f0d6..1d051cd045dbc43b5d4b53d42008660f62765ddd 100644 (file)
@@ -123,6 +123,7 @@ module_param(ioat_dca_enabled, int, 0644);
 MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
 
 struct kmem_cache *ioat2_cache;
+struct kmem_cache *ioat3_sed_cache;
 
 #define DRV_NAME "ioatdma"
 
@@ -207,9 +208,6 @@ static void ioat_remove(struct pci_dev *pdev)
        if (!device)
                return;
 
-       if (device->version >= IOAT_VER_3_0)
-               ioat3_dma_remove(device);
-
        dev_err(&pdev->dev, "Removing dma and dca services\n");
        if (device->dca) {
                unregister_dca_provider(device->dca, &pdev->dev);
@@ -221,7 +219,7 @@ static void ioat_remove(struct pci_dev *pdev)
 
 static int __init ioat_init_module(void)
 {
-       int err;
+       int err = -ENOMEM;
 
        pr_info("%s: Intel(R) QuickData Technology Driver %s\n",
                DRV_NAME, IOAT_DMA_VERSION);
@@ -231,9 +229,21 @@ static int __init ioat_init_module(void)
        if (!ioat2_cache)
                return -ENOMEM;
 
+       ioat3_sed_cache = KMEM_CACHE(ioat_sed_ent, 0);
+       if (!ioat3_sed_cache)
+               goto err_ioat2_cache;
+
        err = pci_register_driver(&ioat_pci_driver);
        if (err)
-               kmem_cache_destroy(ioat2_cache);
+               goto err_ioat3_cache;
+
+       return 0;
+
+ err_ioat3_cache:
+       kmem_cache_destroy(ioat3_sed_cache);
+
+ err_ioat2_cache:
+       kmem_cache_destroy(ioat2_cache);
 
        return err;
 }
index dd8b44a56e5d0f7090b8dd65bce87a73a60c90ef..c56137bc3868da7cdc43bf38fab53a30ca410430 100644 (file)
@@ -61,80 +61,6 @@ static void iop_adma_free_slots(struct iop_adma_desc_slot *slot)
        }
 }
 
-static void
-iop_desc_unmap(struct iop_adma_chan *iop_chan, struct iop_adma_desc_slot *desc)
-{
-       struct dma_async_tx_descriptor *tx = &desc->async_tx;
-       struct iop_adma_desc_slot *unmap = desc->group_head;
-       struct device *dev = &iop_chan->device->pdev->dev;
-       u32 len = unmap->unmap_len;
-       enum dma_ctrl_flags flags = tx->flags;
-       u32 src_cnt;
-       dma_addr_t addr;
-       dma_addr_t dest;
-
-       src_cnt = unmap->unmap_src_cnt;
-       dest = iop_desc_get_dest_addr(unmap, iop_chan);
-       if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-               enum dma_data_direction dir;
-
-               if (src_cnt > 1) /* is xor? */
-                       dir = DMA_BIDIRECTIONAL;
-               else
-                       dir = DMA_FROM_DEVICE;
-
-               dma_unmap_page(dev, dest, len, dir);
-       }
-
-       if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-               while (src_cnt--) {
-                       addr = iop_desc_get_src_addr(unmap, iop_chan, src_cnt);
-                       if (addr == dest)
-                               continue;
-                       dma_unmap_page(dev, addr, len, DMA_TO_DEVICE);
-               }
-       }
-       desc->group_head = NULL;
-}
-
-static void
-iop_desc_unmap_pq(struct iop_adma_chan *iop_chan, struct iop_adma_desc_slot *desc)
-{
-       struct dma_async_tx_descriptor *tx = &desc->async_tx;
-       struct iop_adma_desc_slot *unmap = desc->group_head;
-       struct device *dev = &iop_chan->device->pdev->dev;
-       u32 len = unmap->unmap_len;
-       enum dma_ctrl_flags flags = tx->flags;
-       u32 src_cnt = unmap->unmap_src_cnt;
-       dma_addr_t pdest = iop_desc_get_dest_addr(unmap, iop_chan);
-       dma_addr_t qdest = iop_desc_get_qdest_addr(unmap, iop_chan);
-       int i;
-
-       if (tx->flags & DMA_PREP_CONTINUE)
-               src_cnt -= 3;
-
-       if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP) && !desc->pq_check_result) {
-               dma_unmap_page(dev, pdest, len, DMA_BIDIRECTIONAL);
-               dma_unmap_page(dev, qdest, len, DMA_BIDIRECTIONAL);
-       }
-
-       if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-               dma_addr_t addr;
-
-               for (i = 0; i < src_cnt; i++) {
-                       addr = iop_desc_get_src_addr(unmap, iop_chan, i);
-                       dma_unmap_page(dev, addr, len, DMA_TO_DEVICE);
-               }
-               if (desc->pq_check_result) {
-                       dma_unmap_page(dev, pdest, len, DMA_TO_DEVICE);
-                       dma_unmap_page(dev, qdest, len, DMA_TO_DEVICE);
-               }
-       }
-
-       desc->group_head = NULL;
-}
-
-
 static dma_cookie_t
 iop_adma_run_tx_complete_actions(struct iop_adma_desc_slot *desc,
        struct iop_adma_chan *iop_chan, dma_cookie_t cookie)
@@ -152,15 +78,9 @@ iop_adma_run_tx_complete_actions(struct iop_adma_desc_slot *desc,
                if (tx->callback)
                        tx->callback(tx->callback_param);
 
-               /* unmap dma addresses
-                * (unmap_single vs unmap_page?)
-                */
-               if (desc->group_head && desc->unmap_len) {
-                       if (iop_desc_is_pq(desc))
-                               iop_desc_unmap_pq(iop_chan, desc);
-                       else
-                               iop_desc_unmap(iop_chan, desc);
-               }
+               dma_descriptor_unmap(tx);
+               if (desc->group_head)
+                       desc->group_head = NULL;
        }
 
        /* run dependent operations */
@@ -591,7 +511,6 @@ iop_adma_prep_dma_interrupt(struct dma_chan *chan, unsigned long flags)
        if (sw_desc) {
                grp_start = sw_desc->group_head;
                iop_desc_init_interrupt(grp_start, iop_chan);
-               grp_start->unmap_len = 0;
                sw_desc->async_tx.flags = flags;
        }
        spin_unlock_bh(&iop_chan->lock);
@@ -623,8 +542,6 @@ iop_adma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest,
                iop_desc_set_byte_count(grp_start, iop_chan, len);
                iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
                iop_desc_set_memcpy_src_addr(grp_start, dma_src);
-               sw_desc->unmap_src_cnt = 1;
-               sw_desc->unmap_len = len;
                sw_desc->async_tx.flags = flags;
        }
        spin_unlock_bh(&iop_chan->lock);
@@ -657,8 +574,6 @@ iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest,
                iop_desc_init_xor(grp_start, src_cnt, flags);
                iop_desc_set_byte_count(grp_start, iop_chan, len);
                iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
-               sw_desc->unmap_src_cnt = src_cnt;
-               sw_desc->unmap_len = len;
                sw_desc->async_tx.flags = flags;
                while (src_cnt--)
                        iop_desc_set_xor_src_addr(grp_start, src_cnt,
@@ -694,8 +609,6 @@ iop_adma_prep_dma_xor_val(struct dma_chan *chan, dma_addr_t *dma_src,
                grp_start->xor_check_result = result;
                pr_debug("\t%s: grp_start->xor_check_result: %p\n",
                        __func__, grp_start->xor_check_result);
-               sw_desc->unmap_src_cnt = src_cnt;
-               sw_desc->unmap_len = len;
                sw_desc->async_tx.flags = flags;
                while (src_cnt--)
                        iop_desc_set_zero_sum_src_addr(grp_start, src_cnt,
@@ -748,8 +661,6 @@ iop_adma_prep_dma_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
                        dst[0] = dst[1] & 0x7;
 
                iop_desc_set_pq_addr(g, dst);
-               sw_desc->unmap_src_cnt = src_cnt;
-               sw_desc->unmap_len = len;
                sw_desc->async_tx.flags = flags;
                for (i = 0; i < src_cnt; i++)
                        iop_desc_set_pq_src_addr(g, i, src[i], scf[i]);
@@ -804,8 +715,6 @@ iop_adma_prep_dma_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
                g->pq_check_result = pqres;
                pr_debug("\t%s: g->pq_check_result: %p\n",
                        __func__, g->pq_check_result);
-               sw_desc->unmap_src_cnt = src_cnt+2;
-               sw_desc->unmap_len = len;
                sw_desc->async_tx.flags = flags;
                while (src_cnt--)
                        iop_desc_set_pq_zero_sum_src_addr(g, src_cnt,
@@ -864,7 +773,7 @@ static enum dma_status iop_adma_status(struct dma_chan *chan,
        int ret;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        iop_adma_slot_cleanup(iop_chan);
@@ -983,7 +892,7 @@ static int iop_adma_memcpy_self_test(struct iop_adma_device *device)
        msleep(1);
 
        if (iop_adma_status(dma_chan, cookie, NULL) !=
-                       DMA_SUCCESS) {
+                       DMA_COMPLETE) {
                dev_err(dma_chan->device->dev,
                        "Self-test copy timed out, disabling\n");
                err = -ENODEV;
@@ -1083,7 +992,7 @@ iop_adma_xor_val_self_test(struct iop_adma_device *device)
        msleep(8);
 
        if (iop_adma_status(dma_chan, cookie, NULL) !=
-               DMA_SUCCESS) {
+               DMA_COMPLETE) {
                dev_err(dma_chan->device->dev,
                        "Self-test xor timed out, disabling\n");
                err = -ENODEV;
@@ -1129,7 +1038,7 @@ iop_adma_xor_val_self_test(struct iop_adma_device *device)
        iop_adma_issue_pending(dma_chan);
        msleep(8);
 
-       if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
+       if (iop_adma_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
                dev_err(dma_chan->device->dev,
                        "Self-test zero sum timed out, disabling\n");
                err = -ENODEV;
@@ -1158,7 +1067,7 @@ iop_adma_xor_val_self_test(struct iop_adma_device *device)
        iop_adma_issue_pending(dma_chan);
        msleep(8);
 
-       if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
+       if (iop_adma_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
                dev_err(dma_chan->device->dev,
                        "Self-test non-zero sum timed out, disabling\n");
                err = -ENODEV;
@@ -1254,7 +1163,7 @@ iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
        msleep(8);
 
        if (iop_adma_status(dma_chan, cookie, NULL) !=
-               DMA_SUCCESS) {
+               DMA_COMPLETE) {
                dev_err(dev, "Self-test pq timed out, disabling\n");
                err = -ENODEV;
                goto free_resources;
@@ -1291,7 +1200,7 @@ iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
        msleep(8);
 
        if (iop_adma_status(dma_chan, cookie, NULL) !=
-               DMA_SUCCESS) {
+               DMA_COMPLETE) {
                dev_err(dev, "Self-test pq-zero-sum timed out, disabling\n");
                err = -ENODEV;
                goto free_resources;
@@ -1323,7 +1232,7 @@ iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
        msleep(8);
 
        if (iop_adma_status(dma_chan, cookie, NULL) !=
-               DMA_SUCCESS) {
+               DMA_COMPLETE) {
                dev_err(dev, "Self-test !pq-zero-sum timed out, disabling\n");
                err = -ENODEV;
                goto free_resources;
index cb9c0bc317e89ed6acebba276ed1be2788cc901e..128ca143486d1b59c0106cb8a177b5a2e1b803fd 100644 (file)
@@ -1232,8 +1232,10 @@ static irqreturn_t idmac_interrupt(int irq, void *dev_id)
        desc = list_entry(ichan->queue.next, struct idmac_tx_desc, list);
        descnew = desc;
 
-       dev_dbg(dev, "IDMAC irq %d, dma 0x%08x, next dma 0x%08x, current %d, curbuf 0x%08x\n",
-               irq, sg_dma_address(*sg), sgnext ? sg_dma_address(sgnext) : 0, ichan->active_buffer, curbuf);
+       dev_dbg(dev, "IDMAC irq %d, dma %#llx, next dma %#llx, current %d, curbuf %#x\n",
+               irq, (u64)sg_dma_address(*sg),
+               sgnext ? (u64)sg_dma_address(sgnext) : 0,
+               ichan->active_buffer, curbuf);
 
        /* Find the descriptor of sgnext */
        sgnew = idmac_sg_next(ichan, &descnew, *sg);
index a2c330f5f9521302ed04998dfb38eecb60b2f894..e26075408e9b95a365dfd188cad786593604412f 100644 (file)
@@ -344,7 +344,7 @@ static enum dma_status k3_dma_tx_status(struct dma_chan *chan,
        size_t bytes = 0;
 
        ret = dma_cookie_status(&c->vc.chan, cookie, state);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        spin_lock_irqsave(&c->vc.lock, flags);
@@ -693,7 +693,7 @@ static int k3_dma_probe(struct platform_device *op)
 
        irq = platform_get_irq(op, 0);
        ret = devm_request_irq(&op->dev, irq,
-                       k3_dma_int_handler, IRQF_DISABLED, DRIVER_NAME, d);
+                       k3_dma_int_handler, 0, DRIVER_NAME, d);
        if (ret)
                return ret;
 
index ff8d7827f8cbe80e2c66d78db1f50ad6fdd91b5a..dcb1e05149a7664c6e65a214d783080d540aaafd 100644 (file)
@@ -798,8 +798,7 @@ static void dma_do_tasklet(unsigned long data)
                 * move the descriptors to a temporary list so we can drop
                 * the lock during the entire cleanup operation
                 */
-               list_del(&desc->node);
-               list_add(&desc->node, &chain_cleanup);
+               list_move(&desc->node, &chain_cleanup);
 
                /*
                 * Look for the first list entry which has the ENDIRQEN flag
@@ -863,7 +862,7 @@ static int mmp_pdma_chan_init(struct mmp_pdma_device *pdev,
 
        if (irq) {
                ret = devm_request_irq(pdev->dev, irq,
-                       mmp_pdma_chan_handler, IRQF_DISABLED, "pdma", phy);
+                       mmp_pdma_chan_handler, 0, "pdma", phy);
                if (ret) {
                        dev_err(pdev->dev, "channel request irq fail!\n");
                        return ret;
@@ -970,7 +969,7 @@ static int mmp_pdma_probe(struct platform_device *op)
                /* all chan share one irq, demux inside */
                irq = platform_get_irq(op, 0);
                ret = devm_request_irq(pdev->dev, irq,
-                       mmp_pdma_int_handler, IRQF_DISABLED, "pdma", pdev);
+                       mmp_pdma_int_handler, 0, "pdma", pdev);
                if (ret)
                        return ret;
        }
index d3b6358e5a27037281f6da2efb6dad3e926b9fb1..3ddacc14a7366611ffb089d21c70fb4ba3c896c5 100644 (file)
 #define TDCR_BURSTSZ_16B       (0x3 << 6)
 #define TDCR_BURSTSZ_32B       (0x6 << 6)
 #define TDCR_BURSTSZ_64B       (0x7 << 6)
+#define TDCR_BURSTSZ_SQU_1B            (0x5 << 6)
+#define TDCR_BURSTSZ_SQU_2B            (0x6 << 6)
+#define TDCR_BURSTSZ_SQU_4B            (0x0 << 6)
+#define TDCR_BURSTSZ_SQU_8B            (0x1 << 6)
+#define TDCR_BURSTSZ_SQU_16B   (0x3 << 6)
 #define TDCR_BURSTSZ_SQU_32B   (0x7 << 6)
 #define TDCR_BURSTSZ_128B      (0x5 << 6)
 #define TDCR_DSTDIR_MSK                (0x3 << 4)      /* Dst Direction */
@@ -158,7 +163,7 @@ static void mmp_tdma_disable_chan(struct mmp_tdma_chan *tdmac)
        /* disable irq */
        writel(0, tdmac->reg_base + TDIMR);
 
-       tdmac->status = DMA_SUCCESS;
+       tdmac->status = DMA_COMPLETE;
 }
 
 static void mmp_tdma_resume_chan(struct mmp_tdma_chan *tdmac)
@@ -228,8 +233,31 @@ static int mmp_tdma_config_chan(struct mmp_tdma_chan *tdmac)
                        return -EINVAL;
                }
        } else if (tdmac->type == PXA910_SQU) {
-               tdcr |= TDCR_BURSTSZ_SQU_32B;
                tdcr |= TDCR_SSPMOD;
+
+               switch (tdmac->burst_sz) {
+               case 1:
+                       tdcr |= TDCR_BURSTSZ_SQU_1B;
+                       break;
+               case 2:
+                       tdcr |= TDCR_BURSTSZ_SQU_2B;
+                       break;
+               case 4:
+                       tdcr |= TDCR_BURSTSZ_SQU_4B;
+                       break;
+               case 8:
+                       tdcr |= TDCR_BURSTSZ_SQU_8B;
+                       break;
+               case 16:
+                       tdcr |= TDCR_BURSTSZ_SQU_16B;
+                       break;
+               case 32:
+                       tdcr |= TDCR_BURSTSZ_SQU_32B;
+                       break;
+               default:
+                       dev_err(tdmac->dev, "mmp_tdma: unknown burst size.\n");
+                       return -EINVAL;
+               }
        }
 
        writel(tdcr, tdmac->reg_base + TDCR);
@@ -324,7 +352,7 @@ static int mmp_tdma_alloc_chan_resources(struct dma_chan *chan)
 
        if (tdmac->irq) {
                ret = devm_request_irq(tdmac->dev, tdmac->irq,
-                       mmp_tdma_chan_handler, IRQF_DISABLED, "tdma", tdmac);
+                       mmp_tdma_chan_handler, 0, "tdma", tdmac);
                if (ret)
                        return ret;
        }
@@ -365,7 +393,7 @@ static struct dma_async_tx_descriptor *mmp_tdma_prep_dma_cyclic(
        int num_periods = buf_len / period_len;
        int i = 0, buf = 0;
 
-       if (tdmac->status != DMA_SUCCESS)
+       if (tdmac->status != DMA_COMPLETE)
                return NULL;
 
        if (period_len > TDMA_MAX_XFER_BYTES) {
@@ -499,7 +527,7 @@ static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev,
        tdmac->idx         = idx;
        tdmac->type        = type;
        tdmac->reg_base    = (unsigned long)tdev->base + idx * 4;
-       tdmac->status = DMA_SUCCESS;
+       tdmac->status = DMA_COMPLETE;
        tdev->tdmac[tdmac->idx] = tdmac;
        tasklet_init(&tdmac->tasklet, dma_do_tasklet, (unsigned long)tdmac);
 
@@ -554,7 +582,7 @@ static int mmp_tdma_probe(struct platform_device *pdev)
        if (irq_num != chan_num) {
                irq = platform_get_irq(pdev, 0);
                ret = devm_request_irq(&pdev->dev, irq,
-                       mmp_tdma_int_handler, IRQF_DISABLED, "tdma", tdev);
+                       mmp_tdma_int_handler, 0, "tdma", tdev);
                if (ret)
                        return ret;
        }
index 536dcb8ba5fdfe69ed5f726fc6b5897f00266698..7807f0ef4e209c25ad90db9d32f7bc13955391cf 100644 (file)
@@ -60,14 +60,6 @@ static u32 mv_desc_get_dest_addr(struct mv_xor_desc_slot *desc)
        return hw_desc->phy_dest_addr;
 }
 
-static u32 mv_desc_get_src_addr(struct mv_xor_desc_slot *desc,
-                               int src_idx)
-{
-       struct mv_xor_desc *hw_desc = desc->hw_desc;
-       return hw_desc->phy_src_addr[mv_phy_src_idx(src_idx)];
-}
-
-
 static void mv_desc_set_byte_count(struct mv_xor_desc_slot *desc,
                                   u32 byte_count)
 {
@@ -278,42 +270,9 @@ mv_xor_run_tx_complete_actions(struct mv_xor_desc_slot *desc,
                        desc->async_tx.callback(
                                desc->async_tx.callback_param);
 
-               /* unmap dma addresses
-                * (unmap_single vs unmap_page?)
-                */
-               if (desc->group_head && desc->unmap_len) {
-                       struct mv_xor_desc_slot *unmap = desc->group_head;
-                       struct device *dev = mv_chan_to_devp(mv_chan);
-                       u32 len = unmap->unmap_len;
-                       enum dma_ctrl_flags flags = desc->async_tx.flags;
-                       u32 src_cnt;
-                       dma_addr_t addr;
-                       dma_addr_t dest;
-
-                       src_cnt = unmap->unmap_src_cnt;
-                       dest = mv_desc_get_dest_addr(unmap);
-                       if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-                               enum dma_data_direction dir;
-
-                               if (src_cnt > 1) /* is xor ? */
-                                       dir = DMA_BIDIRECTIONAL;
-                               else
-                                       dir = DMA_FROM_DEVICE;
-                               dma_unmap_page(dev, dest, len, dir);
-                       }
-
-                       if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                               while (src_cnt--) {
-                                       addr = mv_desc_get_src_addr(unmap,
-                                                                   src_cnt);
-                                       if (addr == dest)
-                                               continue;
-                                       dma_unmap_page(dev, addr, len,
-                                                      DMA_TO_DEVICE);
-                               }
-                       }
+               dma_descriptor_unmap(&desc->async_tx);
+               if (desc->group_head)
                        desc->group_head = NULL;
-               }
        }
 
        /* run dependent operations */
@@ -749,7 +708,7 @@ static enum dma_status mv_xor_status(struct dma_chan *chan,
        enum dma_status ret;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS) {
+       if (ret == DMA_COMPLETE) {
                mv_xor_clean_completed_slots(mv_chan);
                return ret;
        }
@@ -874,7 +833,7 @@ static int mv_xor_memcpy_self_test(struct mv_xor_chan *mv_chan)
        msleep(1);
 
        if (mv_xor_status(dma_chan, cookie, NULL) !=
-           DMA_SUCCESS) {
+           DMA_COMPLETE) {
                dev_err(dma_chan->device->dev,
                        "Self-test copy timed out, disabling\n");
                err = -ENODEV;
@@ -968,7 +927,7 @@ mv_xor_xor_self_test(struct mv_xor_chan *mv_chan)
        msleep(8);
 
        if (mv_xor_status(dma_chan, cookie, NULL) !=
-           DMA_SUCCESS) {
+           DMA_COMPLETE) {
                dev_err(dma_chan->device->dev,
                        "Self-test xor timed out, disabling\n");
                err = -ENODEV;
@@ -1076,10 +1035,7 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
        }
 
        mv_chan->mmr_base = xordev->xor_base;
-       if (!mv_chan->mmr_base) {
-               ret = -ENOMEM;
-               goto err_free_dma;
-       }
+       mv_chan->mmr_high_base = xordev->xor_high_base;
        tasklet_init(&mv_chan->irq_tasklet, mv_xor_tasklet, (unsigned long)
                     mv_chan);
 
@@ -1138,7 +1094,7 @@ static void
 mv_xor_conf_mbus_windows(struct mv_xor_device *xordev,
                         const struct mbus_dram_target_info *dram)
 {
-       void __iomem *base = xordev->xor_base;
+       void __iomem *base = xordev->xor_high_base;
        u32 win_enable = 0;
        int i;
 
index 06b067f24c9b33f7592d65a4ece98bf99c3cb776..d0749229c875187a454c498964155c37e765d314 100644 (file)
 #define XOR_OPERATION_MODE_MEMCPY      2
 #define XOR_DESCRIPTOR_SWAP            BIT(14)
 
-#define XOR_CURR_DESC(chan)    (chan->mmr_base + 0x210 + (chan->idx * 4))
-#define XOR_NEXT_DESC(chan)    (chan->mmr_base + 0x200 + (chan->idx * 4))
-#define XOR_BYTE_COUNT(chan)   (chan->mmr_base + 0x220 + (chan->idx * 4))
-#define XOR_DEST_POINTER(chan) (chan->mmr_base + 0x2B0 + (chan->idx * 4))
-#define XOR_BLOCK_SIZE(chan)   (chan->mmr_base + 0x2C0 + (chan->idx * 4))
-#define XOR_INIT_VALUE_LOW(chan)       (chan->mmr_base + 0x2E0)
-#define XOR_INIT_VALUE_HIGH(chan)      (chan->mmr_base + 0x2E4)
+#define XOR_CURR_DESC(chan)    (chan->mmr_high_base + 0x10 + (chan->idx * 4))
+#define XOR_NEXT_DESC(chan)    (chan->mmr_high_base + 0x00 + (chan->idx * 4))
+#define XOR_BYTE_COUNT(chan)   (chan->mmr_high_base + 0x20 + (chan->idx * 4))
+#define XOR_DEST_POINTER(chan) (chan->mmr_high_base + 0xB0 + (chan->idx * 4))
+#define XOR_BLOCK_SIZE(chan)   (chan->mmr_high_base + 0xC0 + (chan->idx * 4))
+#define XOR_INIT_VALUE_LOW(chan)       (chan->mmr_high_base + 0xE0)
+#define XOR_INIT_VALUE_HIGH(chan)      (chan->mmr_high_base + 0xE4)
 
 #define XOR_CONFIG(chan)       (chan->mmr_base + 0x10 + (chan->idx * 4))
 #define XOR_ACTIVATION(chan)   (chan->mmr_base + 0x20 + (chan->idx * 4))
 #define XOR_ERROR_ADDR(chan)   (chan->mmr_base + 0x60)
 #define XOR_INTR_MASK_VALUE    0x3F5
 
-#define WINDOW_BASE(w)         (0x250 + ((w) << 2))
-#define WINDOW_SIZE(w)         (0x270 + ((w) << 2))
-#define WINDOW_REMAP_HIGH(w)   (0x290 + ((w) << 2))
-#define WINDOW_BAR_ENABLE(chan)        (0x240 + ((chan) << 2))
-#define WINDOW_OVERRIDE_CTRL(chan)     (0x2A0 + ((chan) << 2))
+#define WINDOW_BASE(w)         (0x50 + ((w) << 2))
+#define WINDOW_SIZE(w)         (0x70 + ((w) << 2))
+#define WINDOW_REMAP_HIGH(w)   (0x90 + ((w) << 2))
+#define WINDOW_BAR_ENABLE(chan)        (0x40 + ((chan) << 2))
+#define WINDOW_OVERRIDE_CTRL(chan)     (0xA0 + ((chan) << 2))
 
 struct mv_xor_device {
        void __iomem         *xor_base;
@@ -82,6 +82,7 @@ struct mv_xor_chan {
        int                     pending;
        spinlock_t              lock; /* protects the descriptor slot pool */
        void __iomem            *mmr_base;
+       void __iomem            *mmr_high_base;
        unsigned int            idx;
        int                     irq;
        enum dma_transaction_type       current_type;
index ccd13df841db790ff9eabc9cbc9df79f5f8bb9af..ead491346da70183a3a235687de975f85f89e677 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_dma.h>
+#include <linux/list.h>
 
 #include <asm/irq.h>
 
@@ -57,6 +58,9 @@
        (((dma_is_apbh(d) && apbh_is_old(d)) ? 0x050 : 0x110) + (n) * 0x70)
 #define HW_APBHX_CHn_SEMA(d, n) \
        (((dma_is_apbh(d) && apbh_is_old(d)) ? 0x080 : 0x140) + (n) * 0x70)
+#define HW_APBHX_CHn_BAR(d, n) \
+       (((dma_is_apbh(d) && apbh_is_old(d)) ? 0x070 : 0x130) + (n) * 0x70)
+#define HW_APBX_CHn_DEBUG1(d, n) (0x150 + (n) * 0x70)
 
 /*
  * ccw bits definitions
@@ -115,7 +119,9 @@ struct mxs_dma_chan {
        int                             desc_count;
        enum dma_status                 status;
        unsigned int                    flags;
+       bool                            reset;
 #define MXS_DMA_SG_LOOP                        (1 << 0)
+#define MXS_DMA_USE_SEMAPHORE          (1 << 1)
 };
 
 #define MXS_DMA_CHANNELS               16
@@ -201,12 +207,47 @@ static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)
        struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
        int chan_id = mxs_chan->chan.chan_id;
 
-       if (dma_is_apbh(mxs_dma) && apbh_is_old(mxs_dma))
+       /*
+        * mxs dma channel resets can cause a channel stall. To recover from a
+        * channel stall, we have to reset the whole DMA engine. To avoid this,
+        * we use cyclic DMA with semaphores, that are enhanced in
+        * mxs_dma_int_handler. To reset the channel, we can simply stop writing
+        * into the semaphore counter.
+        */
+       if (mxs_chan->flags & MXS_DMA_USE_SEMAPHORE &&
+                       mxs_chan->flags & MXS_DMA_SG_LOOP) {
+               mxs_chan->reset = true;
+       } else if (dma_is_apbh(mxs_dma) && apbh_is_old(mxs_dma)) {
                writel(1 << (chan_id + BP_APBH_CTRL0_RESET_CHANNEL),
                        mxs_dma->base + HW_APBHX_CTRL0 + STMP_OFFSET_REG_SET);
-       else
+       } else {
+               unsigned long elapsed = 0;
+               const unsigned long max_wait = 50000; /* 50ms */
+               void __iomem *reg_dbg1 = mxs_dma->base +
+                               HW_APBX_CHn_DEBUG1(mxs_dma, chan_id);
+
+               /*
+                * On i.MX28 APBX, the DMA channel can stop working if we reset
+                * the channel while it is in READ_FLUSH (0x08) state.
+                * We wait here until we leave the state. Then we trigger the
+                * reset. Waiting a maximum of 50ms, the kernel shouldn't crash
+                * because of this.
+                */
+               while ((readl(reg_dbg1) & 0xf) == 0x8 && elapsed < max_wait) {
+                       udelay(100);
+                       elapsed += 100;
+               }
+
+               if (elapsed >= max_wait)
+                       dev_err(&mxs_chan->mxs_dma->pdev->dev,
+                                       "Failed waiting for the DMA channel %d to leave state READ_FLUSH, trying to reset channel in READ_FLUSH state now\n",
+                                       chan_id);
+
                writel(1 << (chan_id + BP_APBHX_CHANNEL_CTRL_RESET_CHANNEL),
                        mxs_dma->base + HW_APBHX_CHANNEL_CTRL + STMP_OFFSET_REG_SET);
+       }
+
+       mxs_chan->status = DMA_COMPLETE;
 }
 
 static void mxs_dma_enable_chan(struct mxs_dma_chan *mxs_chan)
@@ -219,12 +260,21 @@ static void mxs_dma_enable_chan(struct mxs_dma_chan *mxs_chan)
                mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(mxs_dma, chan_id));
 
        /* write 1 to SEMA to kick off the channel */
-       writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(mxs_dma, chan_id));
+       if (mxs_chan->flags & MXS_DMA_USE_SEMAPHORE &&
+                       mxs_chan->flags & MXS_DMA_SG_LOOP) {
+               /* A cyclic DMA consists of at least 2 segments, so initialize
+                * the semaphore with 2 so we have enough time to add 1 to the
+                * semaphore if we need to */
+               writel(2, mxs_dma->base + HW_APBHX_CHn_SEMA(mxs_dma, chan_id));
+       } else {
+               writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(mxs_dma, chan_id));
+       }
+       mxs_chan->reset = false;
 }
 
 static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan)
 {
-       mxs_chan->status = DMA_SUCCESS;
+       mxs_chan->status = DMA_COMPLETE;
 }
 
 static void mxs_dma_pause_chan(struct mxs_dma_chan *mxs_chan)
@@ -272,58 +322,88 @@ static void mxs_dma_tasklet(unsigned long data)
                mxs_chan->desc.callback(mxs_chan->desc.callback_param);
 }
 
+static int mxs_dma_irq_to_chan(struct mxs_dma_engine *mxs_dma, int irq)
+{
+       int i;
+
+       for (i = 0; i != mxs_dma->nr_channels; ++i)
+               if (mxs_dma->mxs_chans[i].chan_irq == irq)
+                       return i;
+
+       return -EINVAL;
+}
+
 static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
 {
        struct mxs_dma_engine *mxs_dma = dev_id;
-       u32 stat1, stat2;
+       struct mxs_dma_chan *mxs_chan;
+       u32 completed;
+       u32 err;
+       int chan = mxs_dma_irq_to_chan(mxs_dma, irq);
+
+       if (chan < 0)
+               return IRQ_NONE;
 
        /* completion status */
-       stat1 = readl(mxs_dma->base + HW_APBHX_CTRL1);
-       stat1 &= MXS_DMA_CHANNELS_MASK;
-       writel(stat1, mxs_dma->base + HW_APBHX_CTRL1 + STMP_OFFSET_REG_CLR);
+       completed = readl(mxs_dma->base + HW_APBHX_CTRL1);
+       completed = (completed >> chan) & 0x1;
+
+       /* Clear interrupt */
+       writel((1 << chan),
+                       mxs_dma->base + HW_APBHX_CTRL1 + STMP_OFFSET_REG_CLR);
 
        /* error status */
-       stat2 = readl(mxs_dma->base + HW_APBHX_CTRL2);
-       writel(stat2, mxs_dma->base + HW_APBHX_CTRL2 + STMP_OFFSET_REG_CLR);
+       err = readl(mxs_dma->base + HW_APBHX_CTRL2);
+       err &= (1 << (MXS_DMA_CHANNELS + chan)) | (1 << chan);
+
+       /*
+        * error status bit is in the upper 16 bits, error irq bit in the lower
+        * 16 bits. We transform it into a simpler error code:
+        * err: 0x00 = no error, 0x01 = TERMINATION, 0x02 = BUS_ERROR
+        */
+       err = (err >> (MXS_DMA_CHANNELS + chan)) + (err >> chan);
+
+       /* Clear error irq */
+       writel((1 << chan),
+                       mxs_dma->base + HW_APBHX_CTRL2 + STMP_OFFSET_REG_CLR);
 
        /*
         * When both completion and error of termination bits set at the
         * same time, we do not take it as an error.  IOW, it only becomes
-        * an error we need to handle here in case of either it's (1) a bus
-        * error or (2) a termination error with no completion.
+        * an error we need to handle here in case of either it's a bus
+        * error or a termination error with no completion. 0x01 is termination
+        * error, so we can subtract err & completed to get the real error case.
         */
-       stat2 = ((stat2 >> MXS_DMA_CHANNELS) & stat2) | /* (1) */
-               (~(stat2 >> MXS_DMA_CHANNELS) & stat2 & ~stat1); /* (2) */
-
-       /* combine error and completion status for checking */
-       stat1 = (stat2 << MXS_DMA_CHANNELS) | stat1;
-       while (stat1) {
-               int channel = fls(stat1) - 1;
-               struct mxs_dma_chan *mxs_chan =
-                       &mxs_dma->mxs_chans[channel % MXS_DMA_CHANNELS];
-
-               if (channel >= MXS_DMA_CHANNELS) {
-                       dev_dbg(mxs_dma->dma_device.dev,
-                               "%s: error in channel %d\n", __func__,
-                               channel - MXS_DMA_CHANNELS);
-                       mxs_chan->status = DMA_ERROR;
-                       mxs_dma_reset_chan(mxs_chan);
-               } else {
-                       if (mxs_chan->flags & MXS_DMA_SG_LOOP)
-                               mxs_chan->status = DMA_IN_PROGRESS;
-                       else
-                               mxs_chan->status = DMA_SUCCESS;
-               }
+       err -= err & completed;
 
-               stat1 &= ~(1 << channel);
+       mxs_chan = &mxs_dma->mxs_chans[chan];
 
-               if (mxs_chan->status == DMA_SUCCESS)
-                       dma_cookie_complete(&mxs_chan->desc);
+       if (err) {
+               dev_dbg(mxs_dma->dma_device.dev,
+                       "%s: error in channel %d\n", __func__,
+                       chan);
+               mxs_chan->status = DMA_ERROR;
+               mxs_dma_reset_chan(mxs_chan);
+       } else if (mxs_chan->status != DMA_COMPLETE) {
+               if (mxs_chan->flags & MXS_DMA_SG_LOOP) {
+                       mxs_chan->status = DMA_IN_PROGRESS;
+                       if (mxs_chan->flags & MXS_DMA_USE_SEMAPHORE)
+                               writel(1, mxs_dma->base +
+                                       HW_APBHX_CHn_SEMA(mxs_dma, chan));
+               } else {
+                       mxs_chan->status = DMA_COMPLETE;
+               }
+       }
 
-               /* schedule tasklet on this channel */
-               tasklet_schedule(&mxs_chan->tasklet);
+       if (mxs_chan->status == DMA_COMPLETE) {
+               if (mxs_chan->reset)
+                       return IRQ_HANDLED;
+               dma_cookie_complete(&mxs_chan->desc);
        }
 
+       /* schedule tasklet on this channel */
+       tasklet_schedule(&mxs_chan->tasklet);
+
        return IRQ_HANDLED;
 }
 
@@ -523,6 +603,7 @@ static struct dma_async_tx_descriptor *mxs_dma_prep_dma_cyclic(
 
        mxs_chan->status = DMA_IN_PROGRESS;
        mxs_chan->flags |= MXS_DMA_SG_LOOP;
+       mxs_chan->flags |= MXS_DMA_USE_SEMAPHORE;
 
        if (num_periods > NUM_CCW) {
                dev_err(mxs_dma->dma_device.dev,
@@ -554,6 +635,7 @@ static struct dma_async_tx_descriptor *mxs_dma_prep_dma_cyclic(
                ccw->bits |= CCW_IRQ;
                ccw->bits |= CCW_HALT_ON_TERM;
                ccw->bits |= CCW_TERM_FLUSH;
+               ccw->bits |= CCW_DEC_SEM;
                ccw->bits |= BF_CCW(direction == DMA_DEV_TO_MEM ?
                                MXS_DMA_CMD_WRITE : MXS_DMA_CMD_READ, COMMAND);
 
@@ -599,8 +681,24 @@ static enum dma_status mxs_dma_tx_status(struct dma_chan *chan,
                        dma_cookie_t cookie, struct dma_tx_state *txstate)
 {
        struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
+       struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
+       u32 residue = 0;
+
+       if (mxs_chan->status == DMA_IN_PROGRESS &&
+                       mxs_chan->flags & MXS_DMA_SG_LOOP) {
+               struct mxs_dma_ccw *last_ccw;
+               u32 bar;
+
+               last_ccw = &mxs_chan->ccw[mxs_chan->desc_count - 1];
+               residue = last_ccw->xfer_bytes + last_ccw->bufaddr;
+
+               bar = readl(mxs_dma->base +
+                               HW_APBHX_CHn_BAR(mxs_dma, chan->chan_id));
+               residue -= bar;
+       }
 
-       dma_set_tx_state(txstate, chan->completed_cookie, chan->cookie, 0);
+       dma_set_tx_state(txstate, chan->completed_cookie, chan->cookie,
+                       residue);
 
        return mxs_chan->status;
 }
index ec3fc4fd9160e8aeddf16054cd405f35b43bfef7..2f66cf4e54fe367754378c3c8be213fe20bb8f64 100644 (file)
@@ -248,7 +248,7 @@ static enum dma_status omap_dma_tx_status(struct dma_chan *chan,
        unsigned long flags;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS || !txstate)
+       if (ret == DMA_COMPLETE || !txstate)
                return ret;
 
        spin_lock_irqsave(&c->vc.lock, flags);
index df8b10fd1726ed466d2b05e814a8feb6c711dfe3..cdf0483b8f2dfb8f746b786fd6bf84b0d5f6657b 100644 (file)
@@ -2268,6 +2268,8 @@ static void pl330_tasklet(unsigned long data)
                        list_move_tail(&desc->node, &pch->dmac->desc_pool);
                }
 
+               dma_descriptor_unmap(&desc->txd);
+
                if (callback) {
                        spin_unlock_irqrestore(&pch->lock, flags);
                        callback(callback_param);
@@ -2314,7 +2316,7 @@ bool pl330_filter(struct dma_chan *chan, void *param)
                return false;
 
        peri_id = chan->private;
-       return *peri_id == (unsigned)param;
+       return *peri_id == (unsigned long)param;
 }
 EXPORT_SYMBOL(pl330_filter);
 
@@ -2926,16 +2928,23 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 
        amba_set_drvdata(adev, pdmac);
 
-       irq = adev->irq[0];
-       ret = request_irq(irq, pl330_irq_handler, 0,
-                       dev_name(&adev->dev), pi);
-       if (ret)
-               return ret;
+       for (i = 0; i < AMBA_NR_IRQS; i++) {
+               irq = adev->irq[i];
+               if (irq) {
+                       ret = devm_request_irq(&adev->dev, irq,
+                                              pl330_irq_handler, 0,
+                                              dev_name(&adev->dev), pi);
+                       if (ret)
+                               return ret;
+               } else {
+                       break;
+               }
+       }
 
        pi->pcfg.periph_id = adev->periphid;
        ret = pl330_add(pi);
        if (ret)
-               goto probe_err1;
+               return ret;
 
        INIT_LIST_HEAD(&pdmac->desc_pool);
        spin_lock_init(&pdmac->pool_lock);
@@ -3033,8 +3042,6 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 
        return 0;
 probe_err3:
-       amba_set_drvdata(adev, NULL);
-
        /* Idle the DMAC */
        list_for_each_entry_safe(pch, _p, &pdmac->ddma.channels,
                        chan.device_node) {
@@ -3048,8 +3055,6 @@ probe_err3:
        }
 probe_err2:
        pl330_del(pi);
-probe_err1:
-       free_irq(irq, pi);
 
        return ret;
 }
@@ -3059,7 +3064,6 @@ static int pl330_remove(struct amba_device *adev)
        struct dma_pl330_dmac *pdmac = amba_get_drvdata(adev);
        struct dma_pl330_chan *pch, *_p;
        struct pl330_info *pi;
-       int irq;
 
        if (!pdmac)
                return 0;
@@ -3068,7 +3072,6 @@ static int pl330_remove(struct amba_device *adev)
                of_dma_controller_free(adev->dev.of_node);
 
        dma_async_device_unregister(&pdmac->ddma);
-       amba_set_drvdata(adev, NULL);
 
        /* Idle the DMAC */
        list_for_each_entry_safe(pch, _p, &pdmac->ddma.channels,
@@ -3086,9 +3089,6 @@ static int pl330_remove(struct amba_device *adev)
 
        pl330_del(pi);
 
-       irq = adev->irq[0];
-       free_irq(irq, pi);
-
        return 0;
 }
 
index e24b5ef486b50819957d02c03f475561bccac4df..8da48c6b2a38ccd76f3e127d53e4be5ab7be425c 100644 (file)
@@ -803,218 +803,6 @@ static void ppc440spe_desc_set_link(struct ppc440spe_adma_chan *chan,
        local_irq_restore(flags);
 }
 
-/**
- * ppc440spe_desc_get_src_addr - extract the source address from the descriptor
- */
-static u32 ppc440spe_desc_get_src_addr(struct ppc440spe_adma_desc_slot *desc,
-                               struct ppc440spe_adma_chan *chan, int src_idx)
-{
-       struct dma_cdb *dma_hw_desc;
-       struct xor_cb *xor_hw_desc;
-
-       switch (chan->device->id) {
-       case PPC440SPE_DMA0_ID:
-       case PPC440SPE_DMA1_ID:
-               dma_hw_desc = desc->hw_desc;
-               /* May have 0, 1, 2, or 3 sources */
-               switch (dma_hw_desc->opc) {
-               case DMA_CDB_OPC_NO_OP:
-               case DMA_CDB_OPC_DFILL128:
-                       return 0;
-               case DMA_CDB_OPC_DCHECK128:
-                       if (unlikely(src_idx)) {
-                               printk(KERN_ERR "%s: try to get %d source for"
-                                   " DCHECK128\n", __func__, src_idx);
-                               BUG();
-                       }
-                       return le32_to_cpu(dma_hw_desc->sg1l);
-               case DMA_CDB_OPC_MULTICAST:
-               case DMA_CDB_OPC_MV_SG1_SG2:
-                       if (unlikely(src_idx > 2)) {
-                               printk(KERN_ERR "%s: try to get %d source from"
-                                   " DMA descr\n", __func__, src_idx);
-                               BUG();
-                       }
-                       if (src_idx) {
-                               if (le32_to_cpu(dma_hw_desc->sg1u) &
-                                   DMA_CUED_XOR_WIN_MSK) {
-                                       u8 region;
-
-                                       if (src_idx == 1)
-                                               return le32_to_cpu(
-                                                   dma_hw_desc->sg1l) +
-                                                       desc->unmap_len;
-
-                                       region = (le32_to_cpu(
-                                           dma_hw_desc->sg1u)) >>
-                                               DMA_CUED_REGION_OFF;
-
-                                       region &= DMA_CUED_REGION_MSK;
-                                       switch (region) {
-                                       case DMA_RXOR123:
-                                               return le32_to_cpu(
-                                                   dma_hw_desc->sg1l) +
-                                                       (desc->unmap_len << 1);
-                                       case DMA_RXOR124:
-                                               return le32_to_cpu(
-                                                   dma_hw_desc->sg1l) +
-                                                       (desc->unmap_len * 3);
-                                       case DMA_RXOR125:
-                                               return le32_to_cpu(
-                                                   dma_hw_desc->sg1l) +
-                                                       (desc->unmap_len << 2);
-                                       default:
-                                               printk(KERN_ERR
-                                                   "%s: try to"
-                                                   " get src3 for region %02x"
-                                                   "PPC440SPE_DESC_RXOR12?\n",
-                                                   __func__, region);
-                                               BUG();
-                                       }
-                               } else {
-                                       printk(KERN_ERR
-                                               "%s: try to get %d"
-                                               " source for non-cued descr\n",
-                                               __func__, src_idx);
-                                       BUG();
-                               }
-                       }
-                       return le32_to_cpu(dma_hw_desc->sg1l);
-               default:
-                       printk(KERN_ERR "%s: unknown OPC 0x%02x\n",
-                               __func__, dma_hw_desc->opc);
-                       BUG();
-               }
-               return le32_to_cpu(dma_hw_desc->sg1l);
-       case PPC440SPE_XOR_ID:
-               /* May have up to 16 sources */
-               xor_hw_desc = desc->hw_desc;
-               return xor_hw_desc->ops[src_idx].l;
-       }
-       return 0;
-}
-
-/**
- * ppc440spe_desc_get_dest_addr - extract the destination address from the
- * descriptor
- */
-static u32 ppc440spe_desc_get_dest_addr(struct ppc440spe_adma_desc_slot *desc,
-                               struct ppc440spe_adma_chan *chan, int idx)
-{
-       struct dma_cdb *dma_hw_desc;
-       struct xor_cb *xor_hw_desc;
-
-       switch (chan->device->id) {
-       case PPC440SPE_DMA0_ID:
-       case PPC440SPE_DMA1_ID:
-               dma_hw_desc = desc->hw_desc;
-
-               if (likely(!idx))
-                       return le32_to_cpu(dma_hw_desc->sg2l);
-               return le32_to_cpu(dma_hw_desc->sg3l);
-       case PPC440SPE_XOR_ID:
-               xor_hw_desc = desc->hw_desc;
-               return xor_hw_desc->cbtal;
-       }
-       return 0;
-}
-
-/**
- * ppc440spe_desc_get_src_num - extract the number of source addresses from
- * the descriptor
- */
-static u32 ppc440spe_desc_get_src_num(struct ppc440spe_adma_desc_slot *desc,
-                               struct ppc440spe_adma_chan *chan)
-{
-       struct dma_cdb *dma_hw_desc;
-       struct xor_cb *xor_hw_desc;
-
-       switch (chan->device->id) {
-       case PPC440SPE_DMA0_ID:
-       case PPC440SPE_DMA1_ID:
-               dma_hw_desc = desc->hw_desc;
-
-               switch (dma_hw_desc->opc) {
-               case DMA_CDB_OPC_NO_OP:
-               case DMA_CDB_OPC_DFILL128:
-                       return 0;
-               case DMA_CDB_OPC_DCHECK128:
-                       return 1;
-               case DMA_CDB_OPC_MV_SG1_SG2:
-               case DMA_CDB_OPC_MULTICAST:
-                       /*
-                        * Only for RXOR operations we have more than
-                        * one source
-                        */
-                       if (le32_to_cpu(dma_hw_desc->sg1u) &
-                           DMA_CUED_XOR_WIN_MSK) {
-                               /* RXOR op, there are 2 or 3 sources */
-                               if (((le32_to_cpu(dma_hw_desc->sg1u) >>
-                                   DMA_CUED_REGION_OFF) &
-                                     DMA_CUED_REGION_MSK) == DMA_RXOR12) {
-                                       /* RXOR 1-2 */
-                                       return 2;
-                               } else {
-                                       /* RXOR 1-2-3/1-2-4/1-2-5 */
-                                       return 3;
-                               }
-                       }
-                       return 1;
-               default:
-                       printk(KERN_ERR "%s: unknown OPC 0x%02x\n",
-                               __func__, dma_hw_desc->opc);
-                       BUG();
-               }
-       case PPC440SPE_XOR_ID:
-               /* up to 16 sources */
-               xor_hw_desc = desc->hw_desc;
-               return xor_hw_desc->cbc & XOR_CDCR_OAC_MSK;
-       default:
-               BUG();
-       }
-       return 0;
-}
-
-/**
- * ppc440spe_desc_get_dst_num - get the number of destination addresses in
- * this descriptor
- */
-static u32 ppc440spe_desc_get_dst_num(struct ppc440spe_adma_desc_slot *desc,
-                               struct ppc440spe_adma_chan *chan)
-{
-       struct dma_cdb *dma_hw_desc;
-
-       switch (chan->device->id) {
-       case PPC440SPE_DMA0_ID:
-       case PPC440SPE_DMA1_ID:
-               /* May be 1 or 2 destinations */
-               dma_hw_desc = desc->hw_desc;
-               switch (dma_hw_desc->opc) {
-               case DMA_CDB_OPC_NO_OP:
-               case DMA_CDB_OPC_DCHECK128:
-                       return 0;
-               case DMA_CDB_OPC_MV_SG1_SG2:
-               case DMA_CDB_OPC_DFILL128:
-                       return 1;
-               case DMA_CDB_OPC_MULTICAST:
-                       if (desc->dst_cnt == 2)
-                               return 2;
-                       else
-                               return 1;
-               default:
-                       printk(KERN_ERR "%s: unknown OPC 0x%02x\n",
-                               __func__, dma_hw_desc->opc);
-                       BUG();
-               }
-       case PPC440SPE_XOR_ID:
-               /* Always only 1 destination */
-               return 1;
-       default:
-               BUG();
-       }
-       return 0;
-}
-
 /**
  * ppc440spe_desc_get_link - get the address of the descriptor that
  * follows this one
@@ -1707,43 +1495,6 @@ static void ppc440spe_adma_free_slots(struct ppc440spe_adma_desc_slot *slot,
        }
 }
 
-static void ppc440spe_adma_unmap(struct ppc440spe_adma_chan *chan,
-                                struct ppc440spe_adma_desc_slot *desc)
-{
-       u32 src_cnt, dst_cnt;
-       dma_addr_t addr;
-
-       /*
-        * get the number of sources & destination
-        * included in this descriptor and unmap
-        * them all
-        */
-       src_cnt = ppc440spe_desc_get_src_num(desc, chan);
-       dst_cnt = ppc440spe_desc_get_dst_num(desc, chan);
-
-       /* unmap destinations */
-       if (!(desc->async_tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-               while (dst_cnt--) {
-                       addr = ppc440spe_desc_get_dest_addr(
-                               desc, chan, dst_cnt);
-                       dma_unmap_page(chan->device->dev,
-                                       addr, desc->unmap_len,
-                                       DMA_FROM_DEVICE);
-               }
-       }
-
-       /* unmap sources */
-       if (!(desc->async_tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-               while (src_cnt--) {
-                       addr = ppc440spe_desc_get_src_addr(
-                               desc, chan, src_cnt);
-                       dma_unmap_page(chan->device->dev,
-                                       addr, desc->unmap_len,
-                                       DMA_TO_DEVICE);
-               }
-       }
-}
-
 /**
  * ppc440spe_adma_run_tx_complete_actions - call functions to be called
  * upon completion
@@ -1767,26 +1518,7 @@ static dma_cookie_t ppc440spe_adma_run_tx_complete_actions(
                        desc->async_tx.callback(
                                desc->async_tx.callback_param);
 
-               /* unmap dma addresses
-                * (unmap_single vs unmap_page?)
-                *
-                * actually, ppc's dma_unmap_page() functions are empty, so
-                * the following code is just for the sake of completeness
-                */
-               if (chan && chan->needs_unmap && desc->group_head &&
-                    desc->unmap_len) {
-                       struct ppc440spe_adma_desc_slot *unmap =
-                                                       desc->group_head;
-                       /* assume 1 slot per op always */
-                       u32 slot_count = unmap->slot_cnt;
-
-                       /* Run through the group list and unmap addresses */
-                       for (i = 0; i < slot_count; i++) {
-                               BUG_ON(!unmap);
-                               ppc440spe_adma_unmap(chan, unmap);
-                               unmap = unmap->hw_next;
-                       }
-               }
+               dma_descriptor_unmap(&desc->async_tx);
        }
 
        /* run dependent operations */
@@ -3893,7 +3625,7 @@ static enum dma_status ppc440spe_adma_tx_status(struct dma_chan *chan,
 
        ppc440spe_chan = to_ppc440spe_adma_chan(chan);
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        ppc440spe_adma_slot_cleanup(ppc440spe_chan);
index 461a91ab70bb4feca82cd27c1582f81c2905bcde..ab26d46bbe1598434625979abeb488d5199992d9 100644 (file)
@@ -436,7 +436,7 @@ static enum dma_status sa11x0_dma_tx_status(struct dma_chan *chan,
        enum dma_status ret;
 
        ret = dma_cookie_status(&c->vc.chan, cookie, state);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        if (!state)
index d94ab592cc1bb21b92c851debe381609b599fa48..2e7b394def8058e4d1216ad8a07c785db4d87048 100644 (file)
@@ -724,7 +724,7 @@ static enum dma_status shdma_tx_status(struct dma_chan *chan,
         * If we don't find cookie on the queue, it has been aborted and we have
         * to report error
         */
-       if (status != DMA_SUCCESS) {
+       if (status != DMA_COMPLETE) {
                struct shdma_desc *sdesc;
                status = DMA_ERROR;
                list_for_each_entry(sdesc, &schan->ld_queue, node)
index 1069e8869f20762928ecbbe509b2ed294f82ae35..0d765c0e21ec9de8cb4e25ff66d5fd53ee78d95d 100644 (file)
@@ -685,7 +685,7 @@ MODULE_DEVICE_TABLE(of, sh_dmae_of_match);
 static int sh_dmae_probe(struct platform_device *pdev)
 {
        const struct sh_dmae_pdata *pdata;
-       unsigned long irqflags = IRQF_DISABLED,
+       unsigned long irqflags = 0,
                chan_flag[SH_DMAE_MAX_CHANNELS] = {};
        int errirq, chan_irq[SH_DMAE_MAX_CHANNELS];
        int err, i, irq_cnt = 0, irqres = 0, irq_cap = 0;
@@ -838,7 +838,7 @@ static int sh_dmae_probe(struct platform_device *pdev)
                                    IORESOURCE_IRQ_SHAREABLE)
                                        chan_flag[irq_cnt] = IRQF_SHARED;
                                else
-                                       chan_flag[irq_cnt] = IRQF_DISABLED;
+                                       chan_flag[irq_cnt] = 0;
                                dev_dbg(&pdev->dev,
                                        "Found IRQ %d for channel %d\n",
                                        i, irq_cnt);
index 82d2b97ad942f96f2064c0ac58b11141fb85b54c..b8c031b7de4e045d22cfa0e7d495380bc94ed75f 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/log2.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/err.h>
@@ -2626,7 +2627,7 @@ static enum dma_status d40_tx_status(struct dma_chan *chan,
        }
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret != DMA_SUCCESS)
+       if (ret != DMA_COMPLETE)
                dma_set_residue(txstate, stedma40_residue(chan));
 
        if (d40_is_paused(d40c))
@@ -2796,8 +2797,8 @@ static int d40_set_runtime_config(struct dma_chan *chan,
            src_addr_width >  DMA_SLAVE_BUSWIDTH_8_BYTES   ||
            dst_addr_width <= DMA_SLAVE_BUSWIDTH_UNDEFINED ||
            dst_addr_width >  DMA_SLAVE_BUSWIDTH_8_BYTES   ||
-           ((src_addr_width > 1) && (src_addr_width & 1)) ||
-           ((dst_addr_width > 1) && (dst_addr_width & 1)))
+           !is_power_of_2(src_addr_width) ||
+           !is_power_of_2(dst_addr_width))
                return -EINVAL;
 
        cfg->src_info.data_width = src_addr_width;
index 5d4986e5f5fa6b21423084b688bd0a8afbba0c2e..73654e33f13b98c66ebce532646056ecdce79c61 100644 (file)
@@ -570,7 +570,7 @@ static void handle_once_dma_done(struct tegra_dma_channel *tdc,
 
        list_del(&sgreq->node);
        if (sgreq->last_sg) {
-               dma_desc->dma_status = DMA_SUCCESS;
+               dma_desc->dma_status = DMA_COMPLETE;
                dma_cookie_complete(&dma_desc->txd);
                if (!dma_desc->cb_count)
                        list_add_tail(&dma_desc->cb_node, &tdc->cb_desc);
@@ -768,7 +768,7 @@ static enum dma_status tegra_dma_tx_status(struct dma_chan *dc,
        unsigned int residual;
 
        ret = dma_cookie_status(dc, cookie, txstate);
-       if (ret == DMA_SUCCESS)
+       if (ret == DMA_COMPLETE)
                return ret;
 
        spin_lock_irqsave(&tdc->lock, flags);
@@ -1018,7 +1018,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
        return &dma_desc->txd;
 }
 
-struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
+static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
        struct dma_chan *dc, dma_addr_t buf_addr, size_t buf_len,
        size_t period_len, enum dma_transfer_direction direction,
        unsigned long flags, void *context)
index 28af214fce049db85fc02fb903a748fdbef6e0a1..4506a7b4f972319c761ff4ee459a0a38bb7139dd 100644 (file)
@@ -154,38 +154,6 @@ static bool __td_dma_done_ack(struct timb_dma_chan *td_chan)
        return done;
 }
 
-static void __td_unmap_desc(struct timb_dma_chan *td_chan, const u8 *dma_desc,
-       bool single)
-{
-       dma_addr_t addr;
-       int len;
-
-       addr = (dma_desc[7] << 24) | (dma_desc[6] << 16) | (dma_desc[5] << 8) |
-               dma_desc[4];
-
-       len = (dma_desc[3] << 8) | dma_desc[2];
-
-       if (single)
-               dma_unmap_single(chan2dev(&td_chan->chan), addr, len,
-                       DMA_TO_DEVICE);
-       else
-               dma_unmap_page(chan2dev(&td_chan->chan), addr, len,
-                       DMA_TO_DEVICE);
-}
-
-static void __td_unmap_descs(struct timb_dma_desc *td_desc, bool single)
-{
-       struct timb_dma_chan *td_chan = container_of(td_desc->txd.chan,
-               struct timb_dma_chan, chan);
-       u8 *descs;
-
-       for (descs = td_desc->desc_list; ; descs += TIMB_DMA_DESC_SIZE) {
-               __td_unmap_desc(td_chan, descs, single);
-               if (descs[0] & 0x02)
-                       break;
-       }
-}
-
 static int td_fill_desc(struct timb_dma_chan *td_chan, u8 *dma_desc,
        struct scatterlist *sg, bool last)
 {
@@ -293,10 +261,7 @@ static void __td_finish(struct timb_dma_chan *td_chan)
 
        list_move(&td_desc->desc_node, &td_chan->free_list);
 
-       if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP))
-               __td_unmap_descs(td_desc,
-                       txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE);
-
+       dma_descriptor_unmap(txd);
        /*
         * The API requires that no submissions are done from a
         * callback, so we don't need to drop the lock here
index 71e8e775189e0df5568d474ea00157a2675f9260..bae6c29f5502ab951f7926bdf621977703bc96b1 100644 (file)
@@ -419,30 +419,7 @@ txx9dmac_descriptor_complete(struct txx9dmac_chan *dc,
        list_splice_init(&desc->tx_list, &dc->free_list);
        list_move(&desc->desc_node, &dc->free_list);
 
-       if (!ds) {
-               dma_addr_t dmaaddr;
-               if (!(txd->flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
-                       dmaaddr = is_dmac64(dc) ?
-                               desc->hwdesc.DAR : desc->hwdesc32.DAR;
-                       if (txd->flags & DMA_COMPL_DEST_UNMAP_SINGLE)
-                               dma_unmap_single(chan2parent(&dc->chan),
-                                       dmaaddr, desc->len, DMA_FROM_DEVICE);
-                       else
-                               dma_unmap_page(chan2parent(&dc->chan),
-                                       dmaaddr, desc->len, DMA_FROM_DEVICE);
-               }
-               if (!(txd->flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
-                       dmaaddr = is_dmac64(dc) ?
-                               desc->hwdesc.SAR : desc->hwdesc32.SAR;
-                       if (txd->flags & DMA_COMPL_SRC_UNMAP_SINGLE)
-                               dma_unmap_single(chan2parent(&dc->chan),
-                                       dmaaddr, desc->len, DMA_TO_DEVICE);
-                       else
-                               dma_unmap_page(chan2parent(&dc->chan),
-                                       dmaaddr, desc->len, DMA_TO_DEVICE);
-               }
-       }
-
+       dma_descriptor_unmap(txd);
        /*
         * The API requires that no submissions are done from a
         * callback, so we don't need to drop the lock here
@@ -962,8 +939,8 @@ txx9dmac_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
        enum dma_status ret;
 
        ret = dma_cookie_status(chan, cookie, txstate);
-       if (ret == DMA_SUCCESS)
-               return DMA_SUCCESS;
+       if (ret == DMA_COMPLETE)
+               return DMA_COMPLETE;
 
        spin_lock_bh(&dc->lock);
        txx9dmac_scan_descriptors(dc);
index 9ee1c76da7b9110cd7e9842ba571a18b371df37e..374b57fc596d87db7e9e252c2ca4fbe57cb423f6 100644 (file)
@@ -163,6 +163,7 @@ static void cell_edac_init_csrows(struct mem_ctl_info *mci)
                        csrow->first_page, nr_pages);
                break;
        }
+       of_node_put(np);
 }
 
 static int cell_edac_probe(struct platform_device *pdev)
index 211021dfec734a5e5466e2155eaf108ee4ec997c..102674346035e13bc28d6f3f001ea0d4a5e57e29 100644 (file)
@@ -530,12 +530,9 @@ int edac_device_add_device(struct edac_device_ctl_info *edac_dev)
 
        /* Report action taken */
        edac_device_printk(edac_dev, KERN_INFO,
-                               "Giving out device to module '%s' controller "
-                               "'%s': DEV '%s' (%s)\n",
-                               edac_dev->mod_name,
-                               edac_dev->ctl_name,
-                               edac_dev_name(edac_dev),
-                               edac_op_state_to_string(edac_dev->op_state));
+               "Giving out device to module %s controller %s: DEV %s (%s)\n",
+               edac_dev->mod_name, edac_dev->ctl_name, edac_dev->dev_name,
+               edac_op_state_to_string(edac_dev->op_state));
 
        mutex_unlock(&device_ctls_mutex);
        return 0;
index 89e109022d78a27cf506d995c1c16de2feffea0f..e8c9ef03495be4a450944ec996cbe85bb11156e3 100644 (file)
@@ -788,8 +788,10 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)
        }
 
        /* Report action taken */
-       edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':"
-               " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci));
+       edac_mc_printk(mci, KERN_INFO,
+               "Giving out device to module %s controller %s: DEV %s (%s)\n",
+               mci->mod_name, mci->ctl_name, mci->dev_name,
+               edac_op_state_to_string(mci->op_state));
 
        edac_mc_owner = mci->mod_name;
 
index dd370f92ace3402321bbc6f94cfd6814cbb3fb4f..2cf44b4db80c8beac0a5575cf00d1ed4cca32c4d 100644 (file)
@@ -358,11 +358,9 @@ int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx)
        }
 
        edac_pci_printk(pci, KERN_INFO,
-                       "Giving out device to module '%s' controller '%s':"
-                       " DEV '%s' (%s)\n",
-                       pci->mod_name,
-                       pci->ctl_name,
-                       edac_dev_name(pci), edac_op_state_to_string(pci->op_state));
+               "Giving out device to module %s controller %s: DEV %s (%s)\n",
+               pci->mod_name, pci->ctl_name, pci->dev_name,
+               edac_op_state_to_string(pci->op_state));
 
        mutex_unlock(&edac_pci_ctls_mutex);
        return 0;
index c2bd8c6a43499b74d4c29a0490a49a89a6ead12b..2f193668ebc75b7a75d4eb9ceebaa5f89a1eaba8 100644 (file)
@@ -50,8 +50,15 @@ static irqreturn_t highbank_l2_err_handler(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+static const struct of_device_id hb_l2_err_of_match[] = {
+       { .compatible = "calxeda,hb-sregs-l2-ecc", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
+
 static int highbank_l2_err_probe(struct platform_device *pdev)
 {
+       const struct of_device_id *id;
        struct edac_device_ctl_info *dci;
        struct hb_l2_drvdata *drvdata;
        struct resource *r;
@@ -90,28 +97,32 @@ static int highbank_l2_err_probe(struct platform_device *pdev)
                goto err;
        }
 
+       id = of_match_device(hb_l2_err_of_match, &pdev->dev);
+       dci->mod_name = pdev->dev.driver->name;
+       dci->ctl_name = id ? id->compatible : "unknown";
+       dci->dev_name = dev_name(&pdev->dev);
+
+       if (edac_device_add_device(dci))
+               goto err;
+
        drvdata->db_irq = platform_get_irq(pdev, 0);
        res = devm_request_irq(&pdev->dev, drvdata->db_irq,
                               highbank_l2_err_handler,
                               0, dev_name(&pdev->dev), dci);
        if (res < 0)
-               goto err;
+               goto err2;
 
        drvdata->sb_irq = platform_get_irq(pdev, 1);
        res = devm_request_irq(&pdev->dev, drvdata->sb_irq,
                               highbank_l2_err_handler,
                               0, dev_name(&pdev->dev), dci);
        if (res < 0)
-               goto err;
-
-       dci->mod_name = dev_name(&pdev->dev);
-       dci->dev_name = dev_name(&pdev->dev);
-
-       if (edac_device_add_device(dci))
-               goto err;
+               goto err2;
 
        devres_close_group(&pdev->dev, NULL);
        return 0;
+err2:
+       edac_device_del_device(&pdev->dev);
 err:
        devres_release_group(&pdev->dev, NULL);
        edac_device_free_ctl_info(dci);
@@ -127,12 +138,6 @@ static int highbank_l2_err_remove(struct platform_device *pdev)
        return 0;
 }
 
-static const struct of_device_id hb_l2_err_of_match[] = {
-       { .compatible = "calxeda,hb-sregs-l2-ecc", },
-       {},
-};
-MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
-
 static struct platform_driver highbank_l2_edac_driver = {
        .probe = highbank_l2_err_probe,
        .remove = highbank_l2_err_remove,
index 4695dd2d71fd87b6886a4947786ce9290c540127..f784de1dc7937f097265050b3336bcebf4534ef7 100644 (file)
 #include "edac_module.h"
 
 /* DDR Ctrlr Error Registers */
-#define HB_DDR_ECC_OPT                 0x128
-#define HB_DDR_ECC_U_ERR_ADDR          0x130
-#define HB_DDR_ECC_U_ERR_STAT          0x134
-#define HB_DDR_ECC_U_ERR_DATAL         0x138
-#define HB_DDR_ECC_U_ERR_DATAH         0x13c
-#define HB_DDR_ECC_C_ERR_ADDR          0x140
-#define HB_DDR_ECC_C_ERR_STAT          0x144
-#define HB_DDR_ECC_C_ERR_DATAL         0x148
-#define HB_DDR_ECC_C_ERR_DATAH         0x14c
-#define HB_DDR_ECC_INT_STATUS          0x180
-#define HB_DDR_ECC_INT_ACK             0x184
-#define HB_DDR_ECC_U_ERR_ID            0x424
-#define HB_DDR_ECC_C_ERR_ID            0x428
 
-#define HB_DDR_ECC_INT_STAT_CE         0x8
-#define HB_DDR_ECC_INT_STAT_DOUBLE_CE  0x10
-#define HB_DDR_ECC_INT_STAT_UE         0x20
-#define HB_DDR_ECC_INT_STAT_DOUBLE_UE  0x40
+#define HB_DDR_ECC_ERR_BASE            0x128
+#define MW_DDR_ECC_ERR_BASE            0x1b4
+
+#define HB_DDR_ECC_OPT                 0x00
+#define HB_DDR_ECC_U_ERR_ADDR          0x08
+#define HB_DDR_ECC_U_ERR_STAT          0x0c
+#define HB_DDR_ECC_U_ERR_DATAL         0x10
+#define HB_DDR_ECC_U_ERR_DATAH         0x14
+#define HB_DDR_ECC_C_ERR_ADDR          0x18
+#define HB_DDR_ECC_C_ERR_STAT          0x1c
+#define HB_DDR_ECC_C_ERR_DATAL         0x20
+#define HB_DDR_ECC_C_ERR_DATAH         0x24
 
 #define HB_DDR_ECC_OPT_MODE_MASK       0x3
 #define HB_DDR_ECC_OPT_FWC             0x100
 #define HB_DDR_ECC_OPT_XOR_SHIFT       16
 
+/* DDR Ctrlr Interrupt Registers */
+
+#define HB_DDR_ECC_INT_BASE            0x180
+#define MW_DDR_ECC_INT_BASE            0x218
+
+#define HB_DDR_ECC_INT_STATUS          0x00
+#define HB_DDR_ECC_INT_ACK             0x04
+
+#define HB_DDR_ECC_INT_STAT_CE         0x8
+#define HB_DDR_ECC_INT_STAT_DOUBLE_CE  0x10
+#define HB_DDR_ECC_INT_STAT_UE         0x20
+#define HB_DDR_ECC_INT_STAT_DOUBLE_UE  0x40
+
 struct hb_mc_drvdata {
-       void __iomem *mc_vbase;
+       void __iomem *mc_err_base;
+       void __iomem *mc_int_base;
 };
 
 static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
@@ -60,10 +69,10 @@ static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
        u32 status, err_addr;
 
        /* Read the interrupt status register */
-       status = readl(drvdata->mc_vbase + HB_DDR_ECC_INT_STATUS);
+       status = readl(drvdata->mc_int_base + HB_DDR_ECC_INT_STATUS);
 
        if (status & HB_DDR_ECC_INT_STAT_UE) {
-               err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_U_ERR_ADDR);
+               err_addr = readl(drvdata->mc_err_base + HB_DDR_ECC_U_ERR_ADDR);
                edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
                                     err_addr >> PAGE_SHIFT,
                                     err_addr & ~PAGE_MASK, 0,
@@ -71,9 +80,9 @@ static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
                                     mci->ctl_name, "");
        }
        if (status & HB_DDR_ECC_INT_STAT_CE) {
-               u32 syndrome = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_STAT);
+               u32 syndrome = readl(drvdata->mc_err_base + HB_DDR_ECC_C_ERR_STAT);
                syndrome = (syndrome >> 8) & 0xff;
-               err_addr = readl(drvdata->mc_vbase + HB_DDR_ECC_C_ERR_ADDR);
+               err_addr = readl(drvdata->mc_err_base + HB_DDR_ECC_C_ERR_ADDR);
                edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
                                     err_addr >> PAGE_SHIFT,
                                     err_addr & ~PAGE_MASK, syndrome,
@@ -82,66 +91,79 @@ static irqreturn_t highbank_mc_err_handler(int irq, void *dev_id)
        }
 
        /* clear the error, clears the interrupt */
-       writel(status, drvdata->mc_vbase + HB_DDR_ECC_INT_ACK);
+       writel(status, drvdata->mc_int_base + HB_DDR_ECC_INT_ACK);
        return IRQ_HANDLED;
 }
 
-#ifdef CONFIG_EDAC_DEBUG
-static ssize_t highbank_mc_err_inject_write(struct file *file,
-                                     const char __user *data,
-                                     size_t count, loff_t *ppos)
+static void highbank_mc_err_inject(struct mem_ctl_info *mci, u8 synd)
 {
-       struct mem_ctl_info *mci = file->private_data;
        struct hb_mc_drvdata *pdata = mci->pvt_info;
-       char buf[32];
-       size_t buf_size;
        u32 reg;
+
+       reg = readl(pdata->mc_err_base + HB_DDR_ECC_OPT);
+       reg &= HB_DDR_ECC_OPT_MODE_MASK;
+       reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
+       writel(reg, pdata->mc_err_base + HB_DDR_ECC_OPT);
+}
+
+#define to_mci(k) container_of(k, struct mem_ctl_info, dev)
+
+static ssize_t highbank_mc_inject_ctrl(struct device *dev,
+       struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct mem_ctl_info *mci = to_mci(dev);
        u8 synd;
 
-       buf_size = min(count, (sizeof(buf)-1));
-       if (copy_from_user(buf, data, buf_size))
-               return -EFAULT;
-       buf[buf_size] = 0;
+       if (kstrtou8(buf, 16, &synd))
+               return -EINVAL;
 
-       if (!kstrtou8(buf, 16, &synd)) {
-               reg = readl(pdata->mc_vbase + HB_DDR_ECC_OPT);
-               reg &= HB_DDR_ECC_OPT_MODE_MASK;
-               reg |= (synd << HB_DDR_ECC_OPT_XOR_SHIFT) | HB_DDR_ECC_OPT_FWC;
-               writel(reg, pdata->mc_vbase + HB_DDR_ECC_OPT);
-       }
+       highbank_mc_err_inject(mci, synd);
 
        return count;
 }
 
-static const struct file_operations highbank_mc_debug_inject_fops = {
-       .open = simple_open,
-       .write = highbank_mc_err_inject_write,
-       .llseek = generic_file_llseek,
+static DEVICE_ATTR(inject_ctrl, S_IWUSR, NULL, highbank_mc_inject_ctrl);
+
+struct hb_mc_settings {
+       int     err_offset;
+       int     int_offset;
 };
 
-static void highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
-{
-       if (mci->debugfs)
-               debugfs_create_file("inject_ctrl", S_IWUSR, mci->debugfs, mci,
-                                   &highbank_mc_debug_inject_fops);
-;
-}
-#else
-static void highbank_mc_create_debugfs_nodes(struct mem_ctl_info *mci)
-{}
-#endif
+static struct hb_mc_settings hb_settings = {
+       .err_offset = HB_DDR_ECC_ERR_BASE,
+       .int_offset = HB_DDR_ECC_INT_BASE,
+};
+
+static struct hb_mc_settings mw_settings = {
+       .err_offset = MW_DDR_ECC_ERR_BASE,
+       .int_offset = MW_DDR_ECC_INT_BASE,
+};
+
+static struct of_device_id hb_ddr_ctrl_of_match[] = {
+       { .compatible = "calxeda,hb-ddr-ctrl",          .data = &hb_settings },
+       { .compatible = "calxeda,ecx-2000-ddr-ctrl",    .data = &mw_settings },
+       {},
+};
+MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
 
 static int highbank_mc_probe(struct platform_device *pdev)
 {
+       const struct of_device_id *id;
+       const struct hb_mc_settings *settings;
        struct edac_mc_layer layers[2];
        struct mem_ctl_info *mci;
        struct hb_mc_drvdata *drvdata;
        struct dimm_info *dimm;
        struct resource *r;
+       void __iomem *base;
        u32 control;
        int irq;
        int res = 0;
 
+       id = of_match_device(hb_ddr_ctrl_of_match, &pdev->dev);
+       if (!id)
+               return -ENODEV;
+
        layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
        layers[0].size = 1;
        layers[0].is_virt_csrow = true;
@@ -174,35 +196,31 @@ static int highbank_mc_probe(struct platform_device *pdev)
                goto err;
        }
 
-       drvdata->mc_vbase = devm_ioremap(&pdev->dev,
-                                         r->start, resource_size(r));
-       if (!drvdata->mc_vbase) {
+       base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
+       if (!base) {
                dev_err(&pdev->dev, "Unable to map regs\n");
                res = -ENOMEM;
                goto err;
        }
 
-       control = readl(drvdata->mc_vbase + HB_DDR_ECC_OPT) & 0x3;
+       settings = id->data;
+       drvdata->mc_err_base = base + settings->err_offset;
+       drvdata->mc_int_base = base + settings->int_offset;
+
+       control = readl(drvdata->mc_err_base + HB_DDR_ECC_OPT) & 0x3;
        if (!control || (control == 0x2)) {
                dev_err(&pdev->dev, "No ECC present, or ECC disabled\n");
                res = -ENODEV;
                goto err;
        }
 
-       irq = platform_get_irq(pdev, 0);
-       res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
-                              0, dev_name(&pdev->dev), mci);
-       if (res < 0) {
-               dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
-               goto err;
-       }
-
        mci->mtype_cap = MEM_FLAG_DDR3;
        mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
        mci->edac_cap = EDAC_FLAG_SECDED;
-       mci->mod_name = dev_name(&pdev->dev);
+       mci->mod_name = pdev->dev.driver->name;
        mci->mod_ver = "1";
-       mci->ctl_name = dev_name(&pdev->dev);
+       mci->ctl_name = id->compatible;
+       mci->dev_name = dev_name(&pdev->dev);
        mci->scrub_mode = SCRUB_SW_SRC;
 
        /* Only a single 4GB DIMM is supported */
@@ -217,10 +235,20 @@ static int highbank_mc_probe(struct platform_device *pdev)
        if (res < 0)
                goto err;
 
-       highbank_mc_create_debugfs_nodes(mci);
+       irq = platform_get_irq(pdev, 0);
+       res = devm_request_irq(&pdev->dev, irq, highbank_mc_err_handler,
+                              0, dev_name(&pdev->dev), mci);
+       if (res < 0) {
+               dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
+               goto err2;
+       }
+
+       device_create_file(&mci->dev, &dev_attr_inject_ctrl);
 
        devres_close_group(&pdev->dev, NULL);
        return 0;
+err2:
+       edac_mc_del_mc(&pdev->dev);
 err:
        devres_release_group(&pdev->dev, NULL);
        edac_mc_free(mci);
@@ -231,17 +259,12 @@ static int highbank_mc_remove(struct platform_device *pdev)
 {
        struct mem_ctl_info *mci = platform_get_drvdata(pdev);
 
+       device_remove_file(&mci->dev, &dev_attr_inject_ctrl);
        edac_mc_del_mc(&pdev->dev);
        edac_mc_free(mci);
        return 0;
 }
 
-static const struct of_device_id hb_ddr_ctrl_of_match[] = {
-       { .compatible = "calxeda,hb-ddr-ctrl", },
-       {},
-};
-MODULE_DEVICE_TABLE(of, hb_ddr_ctrl_of_match);
-
 static struct platform_driver highbank_mc_edac_driver = {
        .probe = highbank_mc_probe,
        .remove = highbank_mc_remove,
index 3eb32f62d72a415c30a37e040540a487bf3676d8..fd46b0bd5f2ae273cec5cad4a42b621613b307da 100644 (file)
@@ -327,28 +327,6 @@ err:
 }
 EXPORT_SYMBOL(mpc85xx_pci_err_probe);
 
-static int mpc85xx_pci_err_remove(struct platform_device *op)
-{
-       struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev);
-       struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
-
-       edac_dbg(0, "\n");
-
-       out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR,
-                orig_pci_err_cap_dr);
-
-       out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, orig_pci_err_en);
-
-       edac_pci_del_device(pci->dev);
-
-       if (edac_op_state == EDAC_OPSTATE_INT)
-               irq_dispose_mapping(pdata->irq);
-
-       edac_pci_free_ctl_info(pci);
-
-       return 0;
-}
-
 #endif                         /* CONFIG_PCI */
 
 /**************************** L2 Err device ***************************/
index 88f60c5fecbc8decfa54d4278de7a54b13c41483..8472405c558612e949e5be4caa6a6ac7c889c335 100644 (file)
@@ -34,7 +34,7 @@ static int probed;
 /*
  * Alter this version for the module when modifications are made
  */
-#define SBRIDGE_REVISION    " Ver: 1.0.0 "
+#define SBRIDGE_REVISION    " Ver: 1.1.0 "
 #define EDAC_MOD_STR      "sbridge_edac"
 
 /*
@@ -83,11 +83,17 @@ static int probed;
 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR3   0x3c77  /* 16.7 */
 
 /* Devices 12 Function 6, Offsets 0x80 to 0xcc */
-static const u32 dram_rule[] = {
+static const u32 sbridge_dram_rule[] = {
        0x80, 0x88, 0x90, 0x98, 0xa0,
        0xa8, 0xb0, 0xb8, 0xc0, 0xc8,
 };
-#define MAX_SAD                ARRAY_SIZE(dram_rule)
+
+static const u32 ibridge_dram_rule[] = {
+       0x60, 0x68, 0x70, 0x78, 0x80,
+       0x88, 0x90, 0x98, 0xa0, 0xa8,
+       0xb0, 0xb8, 0xc0, 0xc8, 0xd0,
+       0xd8, 0xe0, 0xe8, 0xf0, 0xf8,
+};
 
 #define SAD_LIMIT(reg)         ((GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff)
 #define DRAM_ATTR(reg)         GET_BITFIELD(reg, 2,  3)
@@ -108,43 +114,50 @@ static char *get_dram_attr(u32 reg)
        }
 }
 
-static const u32 interleave_list[] = {
+static const u32 sbridge_interleave_list[] = {
        0x84, 0x8c, 0x94, 0x9c, 0xa4,
        0xac, 0xb4, 0xbc, 0xc4, 0xcc,
 };
-#define MAX_INTERLEAVE ARRAY_SIZE(interleave_list)
-
-#define SAD_PKG0(reg)          GET_BITFIELD(reg, 0, 2)
-#define SAD_PKG1(reg)          GET_BITFIELD(reg, 3, 5)
-#define SAD_PKG2(reg)          GET_BITFIELD(reg, 8, 10)
-#define SAD_PKG3(reg)          GET_BITFIELD(reg, 11, 13)
-#define SAD_PKG4(reg)          GET_BITFIELD(reg, 16, 18)
-#define SAD_PKG5(reg)          GET_BITFIELD(reg, 19, 21)
-#define SAD_PKG6(reg)          GET_BITFIELD(reg, 24, 26)
-#define SAD_PKG7(reg)          GET_BITFIELD(reg, 27, 29)
-
-static inline int sad_pkg(u32 reg, int interleave)
+
+static const u32 ibridge_interleave_list[] = {
+       0x64, 0x6c, 0x74, 0x7c, 0x84,
+       0x8c, 0x94, 0x9c, 0xa4, 0xac,
+       0xb4, 0xbc, 0xc4, 0xcc, 0xd4,
+       0xdc, 0xe4, 0xec, 0xf4, 0xfc,
+};
+
+struct interleave_pkg {
+       unsigned char start;
+       unsigned char end;
+};
+
+static const struct interleave_pkg sbridge_interleave_pkg[] = {
+       { 0, 2 },
+       { 3, 5 },
+       { 8, 10 },
+       { 11, 13 },
+       { 16, 18 },
+       { 19, 21 },
+       { 24, 26 },
+       { 27, 29 },
+};
+
+static const struct interleave_pkg ibridge_interleave_pkg[] = {
+       { 0, 3 },
+       { 4, 7 },
+       { 8, 11 },
+       { 12, 15 },
+       { 16, 19 },
+       { 20, 23 },
+       { 24, 27 },
+       { 28, 31 },
+};
+
+static inline int sad_pkg(const struct interleave_pkg *table, u32 reg,
+                         int interleave)
 {
-       switch (interleave) {
-       case 0:
-               return SAD_PKG0(reg);
-       case 1:
-               return SAD_PKG1(reg);
-       case 2:
-               return SAD_PKG2(reg);
-       case 3:
-               return SAD_PKG3(reg);
-       case 4:
-               return SAD_PKG4(reg);
-       case 5:
-               return SAD_PKG5(reg);
-       case 6:
-               return SAD_PKG6(reg);
-       case 7:
-               return SAD_PKG7(reg);
-       default:
-               return -EINVAL;
-       }
+       return GET_BITFIELD(reg, table[interleave].start,
+                           table[interleave].end);
 }
 
 /* Devices 12 Function 7 */
@@ -262,7 +275,9 @@ static const u32 correrrthrsld[] = {
 
 /* Device 17, function 0 */
 
-#define RANK_CFG_A             0x0328
+#define SB_RANK_CFG_A          0x0328
+
+#define IB_RANK_CFG_A          0x0320
 
 #define IS_RDIMM_ENABLED(reg)          GET_BITFIELD(reg, 11, 11)
 
@@ -273,8 +288,23 @@ static const u32 correrrthrsld[] = {
 #define NUM_CHANNELS   4
 #define MAX_DIMMS      3               /* Max DIMMS per channel */
 
+enum type {
+       SANDY_BRIDGE,
+       IVY_BRIDGE,
+};
+
+struct sbridge_pvt;
 struct sbridge_info {
-       u32     mcmtr;
+       enum type       type;
+       u32             mcmtr;
+       u32             rankcfgr;
+       u64             (*get_tolm)(struct sbridge_pvt *pvt);
+       u64             (*get_tohm)(struct sbridge_pvt *pvt);
+       const u32       *dram_rule;
+       const u32       *interleave_list;
+       const struct interleave_pkg *interleave_pkg;
+       u8              max_sad;
+       u8              max_interleave;
 };
 
 struct sbridge_channel {
@@ -305,8 +335,9 @@ struct sbridge_dev {
 
 struct sbridge_pvt {
        struct pci_dev          *pci_ta, *pci_ddrio, *pci_ras;
-       struct pci_dev          *pci_sad0, *pci_sad1, *pci_ha0;
-       struct pci_dev          *pci_br;
+       struct pci_dev          *pci_sad0, *pci_sad1;
+       struct pci_dev          *pci_ha0, *pci_ha1;
+       struct pci_dev          *pci_br0, *pci_br1;
        struct pci_dev          *pci_tad[NUM_CHANNELS];
 
        struct sbridge_dev      *sbridge_dev;
@@ -364,11 +395,75 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
        {0,}                    /* 0 terminated list. */
 };
 
+/* This changes depending if 1HA or 2HA:
+ * 1HA:
+ *     0x0eb8 (17.0) is DDRIO0
+ * 2HA:
+ *     0x0ebc (17.4) is DDRIO0
+ */
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0     0x0eb8
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0     0x0ebc
+
+/* pci ids */
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0            0x0ea0
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA         0x0ea8
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS                0x0e71
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0       0x0eaa
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1       0x0eab
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2       0x0eac
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3       0x0ead
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_SAD                        0x0ec8
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_BR0                        0x0ec9
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_BR1                        0x0eca
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1            0x0e60
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA         0x0e68
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS                0x0e79
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0       0x0e6a
+#define PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1       0x0e6b
+
+static const struct pci_id_descr pci_dev_descr_ibridge[] = {
+               /* Processor Home Agent */
+       { PCI_DESCR(14, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0, 0)      },
+
+               /* Memory controller */
+       { PCI_DESCR(15, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA, 0)   },
+       { PCI_DESCR(15, 1, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_RAS, 0)  },
+       { PCI_DESCR(15, 2, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD0, 0) },
+       { PCI_DESCR(15, 3, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD1, 0) },
+       { PCI_DESCR(15, 4, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD2, 0) },
+       { PCI_DESCR(15, 5, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TAD3, 0) },
+
+               /* System Address Decoder */
+       { PCI_DESCR(22, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_SAD, 0)          },
+
+               /* Broadcast Registers */
+       { PCI_DESCR(22, 1, PCI_DEVICE_ID_INTEL_IBRIDGE_BR0, 1)          },
+       { PCI_DESCR(22, 2, PCI_DEVICE_ID_INTEL_IBRIDGE_BR1, 0)          },
+
+               /* Optional, mode 2HA */
+       { PCI_DESCR(28, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, 1)      },
+#if 0
+       { PCI_DESCR(29, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TA, 1)   },
+       { PCI_DESCR(29, 1, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_RAS, 1)  },
+#endif
+       { PCI_DESCR(29, 2, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD0, 1) },
+       { PCI_DESCR(29, 3, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1_TAD1, 1) },
+
+       { PCI_DESCR(17, 0, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_1HA_DDRIO0, 1) },
+       { PCI_DESCR(17, 4, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_2HA_DDRIO0, 1) },
+};
+
+static const struct pci_id_table pci_dev_descr_ibridge_table[] = {
+       PCI_ID_TABLE_ENTRY(pci_dev_descr_ibridge),
+       {0,}                    /* 0 terminated list. */
+};
+
 /*
  *     pci_device_id   table for which devices we are looking for
  */
 static DEFINE_PCI_DEVICE_TABLE(sbridge_pci_tbl) = {
        {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
+       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA)},
        {0,}                    /* 0 terminated list. */
 };
 
@@ -458,6 +553,52 @@ static void free_sbridge_dev(struct sbridge_dev *sbridge_dev)
        kfree(sbridge_dev);
 }
 
+static u64 sbridge_get_tolm(struct sbridge_pvt *pvt)
+{
+       u32 reg;
+
+       /* Address range is 32:28 */
+       pci_read_config_dword(pvt->pci_sad1, TOLM, &reg);
+       return GET_TOLM(reg);
+}
+
+static u64 sbridge_get_tohm(struct sbridge_pvt *pvt)
+{
+       u32 reg;
+
+       pci_read_config_dword(pvt->pci_sad1, TOHM, &reg);
+       return GET_TOHM(reg);
+}
+
+static u64 ibridge_get_tolm(struct sbridge_pvt *pvt)
+{
+       u32 reg;
+
+       pci_read_config_dword(pvt->pci_br1, TOLM, &reg);
+
+       return GET_TOLM(reg);
+}
+
+static u64 ibridge_get_tohm(struct sbridge_pvt *pvt)
+{
+       u32 reg;
+
+       pci_read_config_dword(pvt->pci_br1, TOHM, &reg);
+
+       return GET_TOHM(reg);
+}
+
+static inline u8 sad_pkg_socket(u8 pkg)
+{
+       /* on Ivy Bridge, nodeID is SASS, where A is HA and S is node id */
+       return (pkg >> 3) | (pkg & 0x3);
+}
+
+static inline u8 sad_pkg_ha(u8 pkg)
+{
+       return (pkg >> 2) & 0x1;
+}
+
 /****************************************************************************
                        Memory check routines
  ****************************************************************************/
@@ -520,10 +661,10 @@ static int get_dimm_config(struct mem_ctl_info *mci)
        enum edac_type mode;
        enum mem_type mtype;
 
-       pci_read_config_dword(pvt->pci_br, SAD_TARGET, &reg);
+       pci_read_config_dword(pvt->pci_br0, SAD_TARGET, &reg);
        pvt->sbridge_dev->source_id = SOURCE_ID(reg);
 
-       pci_read_config_dword(pvt->pci_br, SAD_CONTROL, &reg);
+       pci_read_config_dword(pvt->pci_br0, SAD_CONTROL, &reg);
        pvt->sbridge_dev->node_id = NODE_ID(reg);
        edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n",
                 pvt->sbridge_dev->mc,
@@ -558,7 +699,8 @@ static int get_dimm_config(struct mem_ctl_info *mci)
        }
 
        if (pvt->pci_ddrio) {
-               pci_read_config_dword(pvt->pci_ddrio, RANK_CFG_A, &reg);
+               pci_read_config_dword(pvt->pci_ddrio, pvt->info.rankcfgr,
+                                     &reg);
                if (IS_RDIMM_ENABLED(reg)) {
                        /* FIXME: Can also be LRDIMM */
                        edac_dbg(0, "Memory is registered\n");
@@ -629,19 +771,14 @@ static void get_memory_layout(const struct mem_ctl_info *mci)
         * Step 1) Get TOLM/TOHM ranges
         */
 
-       /* Address range is 32:28 */
-       pci_read_config_dword(pvt->pci_sad1, TOLM,
-                             &reg);
-       pvt->tolm = GET_TOLM(reg);
+       pvt->tolm = pvt->info.get_tolm(pvt);
        tmp_mb = (1 + pvt->tolm) >> 20;
 
        mb = div_u64_rem(tmp_mb, 1000, &kb);
        edac_dbg(0, "TOLM: %u.%03u GB (0x%016Lx)\n", mb, kb, (u64)pvt->tolm);
 
        /* Address range is already 45:25 */
-       pci_read_config_dword(pvt->pci_sad1, TOHM,
-                             &reg);
-       pvt->tohm = GET_TOHM(reg);
+       pvt->tohm = pvt->info.get_tohm(pvt);
        tmp_mb = (1 + pvt->tohm) >> 20;
 
        mb = div_u64_rem(tmp_mb, 1000, &kb);
@@ -654,9 +791,9 @@ static void get_memory_layout(const struct mem_ctl_info *mci)
         * algorithm bellow.
         */
        prv = 0;
-       for (n_sads = 0; n_sads < MAX_SAD; n_sads++) {
+       for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) {
                /* SAD_LIMIT Address range is 45:26 */
-               pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads],
+               pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads],
                                      &reg);
                limit = SAD_LIMIT(reg);
 
@@ -677,15 +814,16 @@ static void get_memory_layout(const struct mem_ctl_info *mci)
                         reg);
                prv = limit;
 
-               pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads],
+               pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads],
                                      &reg);
-               sad_interl = sad_pkg(reg, 0);
+               sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0);
                for (j = 0; j < 8; j++) {
-                       if (j > 0 && sad_interl == sad_pkg(reg, j))
+                       u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, j);
+                       if (j > 0 && sad_interl == pkg)
                                break;
 
                        edac_dbg(0, "SAD#%d, interleave #%d: %d\n",
-                                n_sads, j, sad_pkg(reg, j));
+                                n_sads, j, pkg);
                }
        }
 
@@ -797,12 +935,13 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
 {
        struct mem_ctl_info     *new_mci;
        struct sbridge_pvt *pvt = mci->pvt_info;
+       struct pci_dev          *pci_ha;
        int                     n_rir, n_sads, n_tads, sad_way, sck_xch;
        int                     sad_interl, idx, base_ch;
        int                     interleave_mode;
-       unsigned                sad_interleave[MAX_INTERLEAVE];
+       unsigned                sad_interleave[pvt->info.max_interleave];
        u32                     reg;
-       u8                      ch_way,sck_way;
+       u8                      ch_way, sck_way, pkg, sad_ha = 0;
        u32                     tad_offset;
        u32                     rir_way;
        u32                     mb, kb;
@@ -828,8 +967,8 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
        /*
         * Step 1) Get socket
         */
-       for (n_sads = 0; n_sads < MAX_SAD; n_sads++) {
-               pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads],
+       for (n_sads = 0; n_sads < pvt->info.max_sad; n_sads++) {
+               pci_read_config_dword(pvt->pci_sad0, pvt->info.dram_rule[n_sads],
                                      &reg);
 
                if (!DRAM_RULE_ENABLE(reg))
@@ -844,53 +983,65 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
                        break;
                prv = limit;
        }
-       if (n_sads == MAX_SAD) {
+       if (n_sads == pvt->info.max_sad) {
                sprintf(msg, "Can't discover the memory socket");
                return -EINVAL;
        }
        *area_type = get_dram_attr(reg);
        interleave_mode = INTERLEAVE_MODE(reg);
 
-       pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads],
+       pci_read_config_dword(pvt->pci_sad0, pvt->info.interleave_list[n_sads],
                              &reg);
-       sad_interl = sad_pkg(reg, 0);
-       for (sad_way = 0; sad_way < 8; sad_way++) {
-               if (sad_way > 0 && sad_interl == sad_pkg(reg, sad_way))
+
+       if (pvt->info.type == SANDY_BRIDGE) {
+               sad_interl = sad_pkg(pvt->info.interleave_pkg, reg, 0);
+               for (sad_way = 0; sad_way < 8; sad_way++) {
+                       u32 pkg = sad_pkg(pvt->info.interleave_pkg, reg, sad_way);
+                       if (sad_way > 0 && sad_interl == pkg)
+                               break;
+                       sad_interleave[sad_way] = pkg;
+                       edac_dbg(0, "SAD interleave #%d: %d\n",
+                                sad_way, sad_interleave[sad_way]);
+               }
+               edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
+                        pvt->sbridge_dev->mc,
+                        n_sads,
+                        addr,
+                        limit,
+                        sad_way + 7,
+                        !interleave_mode ? "" : "XOR[18:16]");
+               if (interleave_mode)
+                       idx = ((addr >> 6) ^ (addr >> 16)) & 7;
+               else
+                       idx = (addr >> 6) & 7;
+               switch (sad_way) {
+               case 1:
+                       idx = 0;
                        break;
-               sad_interleave[sad_way] = sad_pkg(reg, sad_way);
-               edac_dbg(0, "SAD interleave #%d: %d\n",
-                        sad_way, sad_interleave[sad_way]);
-       }
-       edac_dbg(0, "mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
-                pvt->sbridge_dev->mc,
-                n_sads,
-                addr,
-                limit,
-                sad_way + 7,
-                interleave_mode ? "" : "XOR[18:16]");
-       if (interleave_mode)
-               idx = ((addr >> 6) ^ (addr >> 16)) & 7;
-       else
+               case 2:
+                       idx = idx & 1;
+                       break;
+               case 4:
+                       idx = idx & 3;
+                       break;
+               case 8:
+                       break;
+               default:
+                       sprintf(msg, "Can't discover socket interleave");
+                       return -EINVAL;
+               }
+               *socket = sad_interleave[idx];
+               edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n",
+                        idx, sad_way, *socket);
+       } else {
+               /* Ivy Bridge's SAD mode doesn't support XOR interleave mode */
                idx = (addr >> 6) & 7;
-       switch (sad_way) {
-       case 1:
-               idx = 0;
-               break;
-       case 2:
-               idx = idx & 1;
-               break;
-       case 4:
-               idx = idx & 3;
-               break;
-       case 8:
-               break;
-       default:
-               sprintf(msg, "Can't discover socket interleave");
-               return -EINVAL;
+               pkg = sad_pkg(pvt->info.interleave_pkg, reg, idx);
+               *socket = sad_pkg_socket(pkg);
+               sad_ha = sad_pkg_ha(pkg);
+               edac_dbg(0, "SAD interleave package: %d = CPU socket %d, HA %d\n",
+                        idx, *socket, sad_ha);
        }
-       *socket = sad_interleave[idx];
-       edac_dbg(0, "SAD interleave index: %d (wayness %d) = CPU socket %d\n",
-                idx, sad_way, *socket);
 
        /*
         * Move to the proper node structure, in order to access the
@@ -909,9 +1060,16 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
         * Step 2) Get memory channel
         */
        prv = 0;
+       if (pvt->info.type == SANDY_BRIDGE)
+               pci_ha = pvt->pci_ha0;
+       else {
+               if (sad_ha)
+                       pci_ha = pvt->pci_ha1;
+               else
+                       pci_ha = pvt->pci_ha0;
+       }
        for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
-               pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads],
-                                     &reg);
+               pci_read_config_dword(pci_ha, tad_dram_rule[n_tads], &reg);
                limit = TAD_LIMIT(reg);
                if (limit <= prv) {
                        sprintf(msg, "Can't discover the memory channel");
@@ -921,14 +1079,13 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
                        break;
                prv = limit;
        }
+       if (n_tads == MAX_TAD) {
+               sprintf(msg, "Can't discover the memory channel");
+               return -EINVAL;
+       }
+
        ch_way = TAD_CH(reg) + 1;
        sck_way = TAD_SOCK(reg) + 1;
-       /*
-        * FIXME: Is it right to always use channel 0 for offsets?
-        */
-       pci_read_config_dword(pvt->pci_tad[0],
-                               tad_ch_nilv_offset[n_tads],
-                               &tad_offset);
 
        if (ch_way == 3)
                idx = addr >> 6;
@@ -958,6 +1115,10 @@ static int get_memory_error_data(struct mem_ctl_info *mci,
        }
        *channel_mask = 1 << base_ch;
 
+       pci_read_config_dword(pvt->pci_tad[base_ch],
+                               tad_ch_nilv_offset[n_tads],
+                               &tad_offset);
+
        if (pvt->is_mirrored) {
                *channel_mask |= 1 << ((base_ch + 2) % 4);
                switch(ch_way) {
@@ -1091,12 +1252,6 @@ static void sbridge_put_all_devices(void)
        }
 }
 
-/*
- *     sbridge_get_all_devices Find and perform 'get' operation on the MCH's
- *                     device/functions we want to reference for this driver
- *
- *                     Need to 'get' device 16 func 1 and func 2
- */
 static int sbridge_get_onedevice(struct pci_dev **prev,
                                 u8 *num_mc,
                                 const struct pci_id_table *table,
@@ -1198,11 +1353,21 @@ static int sbridge_get_onedevice(struct pci_dev **prev,
        return 0;
 }
 
-static int sbridge_get_all_devices(u8 *num_mc)
+/*
+ * sbridge_get_all_devices - Find and perform 'get' operation on the MCH's
+ *                          device/functions we want to reference for this driver.
+ *                          Need to 'get' device 16 func 1 and func 2.
+ * @num_mc: pointer to the memory controllers count, to be incremented in case
+ *         of success.
+ * @table: model specific table
+ *
+ * returns 0 in case of success or error code
+ */
+static int sbridge_get_all_devices(u8 *num_mc,
+                                  const struct pci_id_table *table)
 {
        int i, rc;
        struct pci_dev *pdev = NULL;
-       const struct pci_id_table *table = pci_dev_descr_sbridge_table;
 
        while (table && table->descr) {
                for (i = 0; i < table->n_devs; i++) {
@@ -1226,8 +1391,8 @@ static int sbridge_get_all_devices(u8 *num_mc)
        return 0;
 }
 
-static int mci_bind_devs(struct mem_ctl_info *mci,
-                        struct sbridge_dev *sbridge_dev)
+static int sbridge_mci_bind_devs(struct mem_ctl_info *mci,
+                                struct sbridge_dev *sbridge_dev)
 {
        struct sbridge_pvt *pvt = mci->pvt_info;
        struct pci_dev *pdev;
@@ -1255,7 +1420,7 @@ static int mci_bind_devs(struct mem_ctl_info *mci,
                case 13:
                        switch (func) {
                        case 6:
-                               pvt->pci_br = pdev;
+                               pvt->pci_br0 = pdev;
                                break;
                        default:
                                goto error;
@@ -1329,6 +1494,131 @@ error:
        return -EINVAL;
 }
 
+static int ibridge_mci_bind_devs(struct mem_ctl_info *mci,
+                                struct sbridge_dev *sbridge_dev)
+{
+       struct sbridge_pvt *pvt = mci->pvt_info;
+       struct pci_dev *pdev, *tmp;
+       int i, func, slot;
+       bool mode_2ha = false;
+
+       tmp = pci_get_device(PCI_VENDOR_ID_INTEL,
+                            PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA1, NULL);
+       if (tmp) {
+               mode_2ha = true;
+               pci_dev_put(tmp);
+       }
+
+       for (i = 0; i < sbridge_dev->n_devs; i++) {
+               pdev = sbridge_dev->pdev[i];
+               if (!pdev)
+                       continue;
+               slot = PCI_SLOT(pdev->devfn);
+               func = PCI_FUNC(pdev->devfn);
+
+               switch (slot) {
+               case 14:
+                       if (func == 0) {
+                               pvt->pci_ha0 = pdev;
+                               break;
+                       }
+                       goto error;
+               case 15:
+                       switch (func) {
+                       case 0:
+                               pvt->pci_ta = pdev;
+                               break;
+                       case 1:
+                               pvt->pci_ras = pdev;
+                               break;
+                       case 4:
+                       case 5:
+                               /* if we have 2 HAs active, channels 2 and 3
+                                * are in other device */
+                               if (mode_2ha)
+                                       break;
+                               /* fall through */
+                       case 2:
+                       case 3:
+                               pvt->pci_tad[func - 2] = pdev;
+                               break;
+                       default:
+                               goto error;
+                       }
+                       break;
+               case 17:
+                       if (func == 4) {
+                               pvt->pci_ddrio = pdev;
+                               break;
+                       } else if (func == 0) {
+                               if (!mode_2ha)
+                                       pvt->pci_ddrio = pdev;
+                               break;
+                       }
+                       goto error;
+               case 22:
+                       switch (func) {
+                       case 0:
+                               pvt->pci_sad0 = pdev;
+                               break;
+                       case 1:
+                               pvt->pci_br0 = pdev;
+                               break;
+                       case 2:
+                               pvt->pci_br1 = pdev;
+                               break;
+                       default:
+                               goto error;
+                       }
+                       break;
+               case 28:
+                       if (func == 0) {
+                               pvt->pci_ha1 = pdev;
+                               break;
+                       }
+                       goto error;
+               case 29:
+                       /* we shouldn't have this device if we have just one
+                        * HA present */
+                       WARN_ON(!mode_2ha);
+                       if (func == 2 || func == 3) {
+                               pvt->pci_tad[func] = pdev;
+                               break;
+                       }
+                       goto error;
+               default:
+                       goto error;
+               }
+
+               edac_dbg(0, "Associated PCI %02x.%02d.%d with dev = %p\n",
+                        sbridge_dev->bus,
+                        PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                        pdev);
+       }
+
+       /* Check if everything were registered */
+       if (!pvt->pci_sad0 || !pvt->pci_ha0 || !pvt->pci_br0 ||
+           !pvt->pci_br1 || !pvt->pci_tad || !pvt->pci_ras  ||
+           !pvt->pci_ta)
+               goto enodev;
+
+       for (i = 0; i < NUM_CHANNELS; i++) {
+               if (!pvt->pci_tad[i])
+                       goto enodev;
+       }
+       return 0;
+
+enodev:
+       sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
+       return -ENODEV;
+
+error:
+       sbridge_printk(KERN_ERR,
+                      "Device %d, function %d is out of the expected range\n",
+                      slot, func);
+       return -EINVAL;
+}
+
 /****************************************************************************
                        Error check routines
  ****************************************************************************/
@@ -1349,7 +1639,7 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
        bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0);
        bool overflow = GET_BITFIELD(m->status, 62, 62);
        bool uncorrected_error = GET_BITFIELD(m->status, 61, 61);
-       bool recoverable = GET_BITFIELD(m->status, 56, 56);
+       bool recoverable;
        u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52);
        u32 mscod = GET_BITFIELD(m->status, 16, 31);
        u32 errcode = GET_BITFIELD(m->status, 0, 15);
@@ -1360,6 +1650,11 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
        int rc, dimm;
        char *area_type = NULL;
 
+       if (pvt->info.type == IVY_BRIDGE)
+               recoverable = true;
+       else
+               recoverable = GET_BITFIELD(m->status, 56, 56);
+
        if (uncorrected_error) {
                if (ripv) {
                        type = "FATAL";
@@ -1409,6 +1704,10 @@ static void sbridge_mce_output_error(struct mem_ctl_info *mci,
                }
        }
 
+       /* Only decode errors with an valid address (ADDRV) */
+       if (!GET_BITFIELD(m->status, 58, 58))
+               return;
+
        rc = get_memory_error_data(mci, m->addr, &socket,
                                   &channel_mask, &rank, &area_type, msg);
        if (rc < 0)
@@ -1614,11 +1913,12 @@ static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev)
        sbridge_dev->mci = NULL;
 }
 
-static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
+static int sbridge_register_mci(struct sbridge_dev *sbridge_dev, enum type type)
 {
        struct mem_ctl_info *mci;
        struct edac_mc_layer layers[2];
        struct sbridge_pvt *pvt;
+       struct pci_dev *pdev = sbridge_dev->pdev[0];
        int rc;
 
        /* Check the number of active and not disabled channels */
@@ -1640,7 +1940,7 @@ static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
                return -ENOMEM;
 
        edac_dbg(0, "MC: mci = %p, dev = %p\n",
-                mci, &sbridge_dev->pdev[0]->dev);
+                mci, &pdev->dev);
 
        pvt = mci->pvt_info;
        memset(pvt, 0, sizeof(*pvt));
@@ -1654,24 +1954,52 @@ static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
        mci->edac_cap = EDAC_FLAG_NONE;
        mci->mod_name = "sbridge_edac.c";
        mci->mod_ver = SBRIDGE_REVISION;
-       mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx);
-       mci->dev_name = pci_name(sbridge_dev->pdev[0]);
+       mci->dev_name = pci_name(pdev);
        mci->ctl_page_to_phys = NULL;
 
        /* Set the function pointer to an actual operation function */
        mci->edac_check = sbridge_check_error;
 
-       /* Store pci devices at mci for faster access */
-       rc = mci_bind_devs(mci, sbridge_dev);
-       if (unlikely(rc < 0))
-               goto fail0;
+       pvt->info.type = type;
+       if (type == IVY_BRIDGE) {
+               pvt->info.rankcfgr = IB_RANK_CFG_A;
+               pvt->info.get_tolm = ibridge_get_tolm;
+               pvt->info.get_tohm = ibridge_get_tohm;
+               pvt->info.dram_rule = ibridge_dram_rule;
+               pvt->info.max_sad = ARRAY_SIZE(ibridge_dram_rule);
+               pvt->info.interleave_list = ibridge_interleave_list;
+               pvt->info.max_interleave = ARRAY_SIZE(ibridge_interleave_list);
+               pvt->info.interleave_pkg = ibridge_interleave_pkg;
+               mci->ctl_name = kasprintf(GFP_KERNEL, "Ivy Bridge Socket#%d", mci->mc_idx);
+
+               /* Store pci devices at mci for faster access */
+               rc = ibridge_mci_bind_devs(mci, sbridge_dev);
+               if (unlikely(rc < 0))
+                       goto fail0;
+       } else {
+               pvt->info.rankcfgr = SB_RANK_CFG_A;
+               pvt->info.get_tolm = sbridge_get_tolm;
+               pvt->info.get_tohm = sbridge_get_tohm;
+               pvt->info.dram_rule = sbridge_dram_rule;
+               pvt->info.max_sad = ARRAY_SIZE(sbridge_dram_rule);
+               pvt->info.interleave_list = sbridge_interleave_list;
+               pvt->info.max_interleave = ARRAY_SIZE(sbridge_interleave_list);
+               pvt->info.interleave_pkg = sbridge_interleave_pkg;
+               mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx);
+
+               /* Store pci devices at mci for faster access */
+               rc = sbridge_mci_bind_devs(mci, sbridge_dev);
+               if (unlikely(rc < 0))
+                       goto fail0;
+       }
+
 
        /* Get dimm basic config and the memory layout */
        get_dimm_config(mci);
        get_memory_layout(mci);
 
        /* record ptr to the generic device */
-       mci->pdev = &sbridge_dev->pdev[0]->dev;
+       mci->pdev = &pdev->dev;
 
        /* add this new MC control structure to EDAC's list of MCs */
        if (unlikely(edac_mc_add_mc(mci))) {
@@ -1702,6 +2030,7 @@ static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        int rc;
        u8 mc, num_mc = 0;
        struct sbridge_dev *sbridge_dev;
+       enum type type;
 
        /* get the pci devices we want to reserve for our use */
        mutex_lock(&sbridge_edac_lock);
@@ -1715,7 +2044,13 @@ static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        }
        probed++;
 
-       rc = sbridge_get_all_devices(&num_mc);
+       if (pdev->device == PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA) {
+               rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_ibridge_table);
+               type = IVY_BRIDGE;
+       } else {
+               rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_sbridge_table);
+               type = SANDY_BRIDGE;
+       }
        if (unlikely(rc < 0))
                goto fail0;
        mc = 0;
@@ -1724,7 +2059,7 @@ static int sbridge_probe(struct pci_dev *pdev, const struct pci_device_id *id)
                edac_dbg(0, "Registering MC#%d (%d of %d)\n",
                         mc, mc + 1, num_mc);
                sbridge_dev->mc = mc++;
-               rc = sbridge_register_mci(sbridge_dev);
+               rc = sbridge_register_mci(sbridge_dev, type);
                if (unlikely(rc < 0))
                        goto fail1;
        }
@@ -1839,5 +2174,5 @@ MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
-MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge memory controllers - "
+MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge and Ivy Bridge memory controllers - "
                   SBRIDGE_REVISION);
index c01cf45bc3d8eaa4ac7909dd793cc35df226b5bd..3a75f4256d08ab7ce67305973b9be6d76aba19fc 100644 (file)
@@ -46,6 +46,6 @@ config FMC_CHARDEV
          This driver matches every mezzanine device and allows user
          space to read and write registers using a char device. It
          can be used to write user-space drivers, or just get
-         aquainted with a mezzanine before writing its specific driver.
+         acquainted with a mezzanine before writing its specific driver.
 
 endif # FMC
index 7dd4461502940952ebf6323dbb04e1af7e6a5230..4e10b10d3ddde47332f525285e1c549bd9a2c22f 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/acpi_gpio.h>
 #include <linux/idr.h>
 #include <linux/slab.h>
+#include <linux/acpi.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/gpio.h>
index 0cfb60f5476655edc097ca71c648d11544f3357e..d18b88b755c34f876dc2d4b9f0a202709dc87f5d 100644 (file)
@@ -67,12 +67,12 @@ int drm_i2c_encoder_init(struct drm_device *dev,
                goto fail;
        }
 
-       if (!client->driver) {
+       if (!client->dev.driver) {
                err = -ENODEV;
                goto fail_unregister;
        }
 
-       module = client->driver->driver.owner;
+       module = client->dev.driver->owner;
        if (!try_module_get(module)) {
                err = -ENODEV;
                goto fail_unregister;
@@ -80,7 +80,7 @@ int drm_i2c_encoder_init(struct drm_device *dev,
 
        encoder->bus_priv = client;
 
-       encoder_drv = to_drm_i2c_encoder_driver(client->driver);
+       encoder_drv = to_drm_i2c_encoder_driver(to_i2c_driver(client->dev.driver));
 
        err = encoder_drv->encoder_init(client, dev, encoder);
        if (err)
@@ -111,7 +111,7 @@ void drm_i2c_encoder_destroy(struct drm_encoder *drm_encoder)
 {
        struct drm_encoder_slave *encoder = to_encoder_slave(drm_encoder);
        struct i2c_client *client = drm_i2c_encoder_get_client(drm_encoder);
-       struct module *module = client->driver->driver.owner;
+       struct module *module = client->dev.driver->owner;
 
        i2c_unregister_device(client);
        encoder->bus_priv = NULL;
index d80d95289e100e05cefd72dd87323618b69f0634..64c34d5876ffc7c8378b3df4a389db203dd1c576 100644 (file)
@@ -455,8 +455,8 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc)
        /* Dot clock in Hz: */
        dotclock = (u64) crtc->hwmode.clock * 1000;
 
-       /* Fields of interlaced scanout modes are only halve a frame duration.
-        * Double the dotclock to get halve the frame-/line-/pixelduration.
+       /* Fields of interlaced scanout modes are only half a frame duration.
+        * Double the dotclock to get half the frame-/line-/pixelduration.
         */
        if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
                dotclock *= 2;
index c200136a5d8e34dc7e53e98d693cafdae7b118ff..f53d5246979c386ed632b21c08decb3ab1296f9e 100644 (file)
@@ -338,7 +338,7 @@ err_idr:
  */
 static void drm_unplug_minor(struct drm_minor *minor)
 {
-       if (!minor || !device_is_registered(minor->kdev))
+       if (!minor || !minor->kdev)
                return;
 
 #if defined(CONFIG_DEBUG_FS)
index 43959edd4291193a538449c1d4f75bba8d30ea8a..dfff0907f70e53643093c3f6aa8d9258ab8dc5d5 100644 (file)
@@ -196,7 +196,7 @@ static bool intel_dsm_pci_probe(struct pci_dev *pdev)
        acpi_handle dhandle;
        int ret;
 
-       dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
+       dhandle = ACPI_HANDLE(&pdev->dev);
        if (!dhandle)
                return false;
 
index 1b2f41c3f19122c731356aff91f3b490959bde60..6d69a9bad86545c6a8cfc8e8ff86480d462c2132 100644 (file)
@@ -638,7 +638,7 @@ static void intel_didl_outputs(struct drm_device *dev)
        u32 temp;
        int i = 0;
 
-       handle = DEVICE_ACPI_HANDLE(&dev->pdev->dev);
+       handle = ACPI_HANDLE(&dev->pdev->dev);
        if (!handle || acpi_bus_get_device(handle, &acpi_dev))
                return;
 
index e286e132c7e7d744d88d99522cf2ce733b4899a6..129120473f6c67bb0d90fcc366e3f140c558f79d 100644 (file)
@@ -116,7 +116,7 @@ mxm_shadow_dsm(struct nouveau_mxm *mxm, u8 version)
        acpi_handle handle;
        int ret;
 
-       handle = DEVICE_ACPI_HANDLE(&device->pdev->dev);
+       handle = ACPI_HANDLE(&device->pdev->dev);
        if (!handle)
                return false;
 
index 13b850076443a82e30e8cf081c25c615e73bb9ac..e44ed7b93c6d88db3826a6c6dcb13efd5429385a 100644 (file)
@@ -41,7 +41,8 @@ probe_monitoring_device(struct nouveau_i2c_port *i2c,
        if (!client)
                return false;
 
-       if (!client->driver || client->driver->detect(client, info)) {
+       if (!client->dev.driver ||
+           to_i2c_driver(client->dev.driver)->detect(client, info)) {
                i2c_unregister_device(client);
                return false;
        }
index 07273a2ae62f2df8dd2b0f41916feeb4d89bd3cd..95c740454049ad1b4a4cf23c2bc63d7038c7a362 100644 (file)
@@ -256,7 +256,7 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
        acpi_handle dhandle;
        int retval = 0;
 
-       dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
+       dhandle = ACPI_HANDLE(&pdev->dev);
        if (!dhandle)
                return false;
 
@@ -414,7 +414,7 @@ bool nouveau_acpi_rom_supported(struct pci_dev *pdev)
        if (!nouveau_dsm_priv.dsm_detected && !nouveau_dsm_priv.optimus_detected)
                return false;
 
-       dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
+       dhandle = ACPI_HANDLE(&pdev->dev);
        if (!dhandle)
                return false;
 
@@ -448,7 +448,7 @@ nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
                return NULL;
        }
 
-       handle = DEVICE_ACPI_HANDLE(&dev->pdev->dev);
+       handle = ACPI_HANDLE(&dev->pdev->dev);
        if (!handle)
                return NULL;
 
index 10f98c7742d8c87289e8bbf677857c781fcebbee..98a9074b306b640644f576e928d4e28701495bb4 100644 (file)
@@ -369,7 +369,7 @@ int radeon_atif_handler(struct radeon_device *rdev,
                return NOTIFY_DONE;
 
        /* Check pending SBIOS requests */
-       handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
+       handle = ACPI_HANDLE(&rdev->pdev->dev);
        count = radeon_atif_get_sbios_requests(handle, &req);
 
        if (count <= 0)
@@ -556,7 +556,7 @@ int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev)
        struct radeon_atcs *atcs = &rdev->atcs;
 
        /* Get the device handle */
-       handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
+       handle = ACPI_HANDLE(&rdev->pdev->dev);
        if (!handle)
                return -EINVAL;
 
@@ -596,7 +596,7 @@ int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
        u32 retry = 3;
 
        /* Get the device handle */
-       handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
+       handle = ACPI_HANDLE(&rdev->pdev->dev);
        if (!handle)
                return -EINVAL;
 
@@ -699,7 +699,7 @@ int radeon_acpi_init(struct radeon_device *rdev)
        int ret;
 
        /* Get the device handle */
-       handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
+       handle = ACPI_HANDLE(&rdev->pdev->dev);
 
        /* No need to proceed if we're sure that ATIF is not supported */
        if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle)
index 6153ec18943aabb7034010ff1c1abc2ba0a761fe..9d302eaeea1587b6fdb5439119b6f45c0de961db 100644 (file)
@@ -8,8 +8,7 @@
  */
 #include <linux/vga_switcheroo.h>
 #include <linux/slab.h>
-#include <acpi/acpi.h>
-#include <acpi/acpi_bus.h>
+#include <linux/acpi.h>
 #include <linux/pci.h>
 
 #include "radeon_acpi.h"
@@ -447,7 +446,7 @@ static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev)
        acpi_handle dhandle, atpx_handle;
        acpi_status status;
 
-       dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
+       dhandle = ACPI_HANDLE(&pdev->dev);
        if (!dhandle)
                return false;
 
@@ -493,7 +492,7 @@ static int radeon_atpx_init(void)
  */
 static int radeon_atpx_get_client_id(struct pci_dev *pdev)
 {
-       if (radeon_atpx_priv.dhandle == DEVICE_ACPI_HANDLE(&pdev->dev))
+       if (radeon_atpx_priv.dhandle == ACPI_HANDLE(&pdev->dev))
                return VGA_SWITCHEROO_IGD;
        else
                return VGA_SWITCHEROO_DIS;
index c155d6f3fa68cad15102af67bfd348677c74d6fa..b3633d9a531703a1cd4189c061a0907e89ee1085 100644 (file)
@@ -185,7 +185,7 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev)
                return false;
 
        while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
-               dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
+               dhandle = ACPI_HANDLE(&pdev->dev);
                if (!dhandle)
                        continue;
 
index c91d547191dd2b7a511b1564523c8f649ec6ac2d..329fbb9b59766f82af6c744e4e85a6ee1dc88208 100644 (file)
@@ -242,6 +242,7 @@ config HID_HOLTEK
          - Tracer Sniper TRM-503 / NOVA Gaming Slider X200 /
            Zalman ZM-GM1
          - SHARKOON DarkGlider Gaming mouse
+         - LEETGION Hellion Gaming Mouse
 
 config HOLTEK_FF
        bool "Holtek On Line Grip force feedback support"
@@ -323,7 +324,7 @@ config HID_LCPOWER
 
 config HID_LENOVO_TPKBD
        tristate "Lenovo ThinkPad USB Keyboard with TrackPoint"
-       depends on USB_HID
+       depends on HID
        select NEW_LEDS
        select LEDS_CLASS
        ---help---
@@ -362,19 +363,20 @@ config LOGITECH_FF
          - Logitech WingMan Force 3D
          - Logitech Formula Force EX
          - Logitech WingMan Formula Force GP
-         - Logitech MOMO Force wheel
 
          and if you want to enable force feedback for them.
          Note: if you say N here, this device will still be supported, but without
          force feedback.
 
 config LOGIRUMBLEPAD2_FF
-       bool "Logitech RumblePad/Rumblepad 2 force feedback support"
+       bool "Logitech force feedback support (variant 2)"
        depends on HID_LOGITECH
        select INPUT_FF_MEMLESS
        help
-         Say Y here if you want to enable force feedback support for Logitech
-         RumblePad and Rumblepad 2 devices.
+         Say Y here if you want to enable force feedback support for:
+         - Logitech RumblePad
+         - Logitech Rumblepad 2
+         - Logitech Formula Vibration Feedback Wheel
 
 config LOGIG940_FF
        bool "Logitech Flight System G940 force feedback support"
@@ -437,6 +439,7 @@ config HID_MULTITOUCH
          - Chunghwa panels
          - CVTouch panels
          - Cypress TrueTouch panels
+         - Elan Microelectronics touch panels
          - Elo TouchSystems IntelliTouch Plus panels
          - GeneralTouch 'Sensing Win7-TwoFinger' panels
          - GoodTouch panels
@@ -453,6 +456,7 @@ config HID_MULTITOUCH
          - Pixcir dual touch panels
          - Quanta panels
          - eGalax dual-touch panels, including the Joojoo and Wetab tablets
+         - SiS multitouch panels
          - Stantum multitouch panels
          - Touch International Panels
          - Unitec Panels
@@ -614,6 +618,14 @@ config HID_SONY
          * Sony PS3 Blue-ray Disk Remote Control (Bluetooth)
          * Logitech Harmony adapter for Sony Playstation 3 (Bluetooth)
 
+config SONY_FF
+       bool "Sony PS2/3 accessories force feedback support"
+       depends on HID_SONY
+       select INPUT_FF_MEMLESS
+       ---help---
+       Say Y here if you have a Sony PS2/3 accessory and want to enable force
+       feedback support for it.
+
 config HID_SPEEDLINK
        tristate "Speedlink VAD Cezanne mouse support"
        depends on HID
index a959f4aecaf5754d1fd9499b1bad386e57615df5..30e44318f87f6c72742f6b6f21584a7ac3af200e 100644 (file)
@@ -95,7 +95,7 @@ obj-$(CONFIG_HID_PRIMAX)      += hid-primax.o
 obj-$(CONFIG_HID_ROCCAT)       += hid-roccat.o hid-roccat-common.o \
        hid-roccat-arvo.o hid-roccat-isku.o hid-roccat-kone.o \
        hid-roccat-koneplus.o hid-roccat-konepure.o hid-roccat-kovaplus.o \
-       hid-roccat-lua.o hid-roccat-pyra.o hid-roccat-savu.o
+       hid-roccat-lua.o hid-roccat-pyra.o hid-roccat-ryos.o hid-roccat-savu.o
 obj-$(CONFIG_HID_SAITEK)       += hid-saitek.o
 obj-$(CONFIG_HID_SAMSUNG)      += hid-samsung.o
 obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o
index 881cf7b4f9a433f8ae3e0f6721b3789aa66731f7..497558127bb3e63609af2b5e1f75265f9e7b1423 100644 (file)
@@ -46,6 +46,12 @@ module_param(iso_layout, uint, 0644);
 MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
                "(0 = disabled, [1] = enabled)");
 
+static unsigned int swap_opt_cmd;
+module_param(swap_opt_cmd, uint, 0644);
+MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
+               "(For people who want to keep Windows PC keyboard muscle memory. "
+               "[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");
+
 struct apple_sc {
        unsigned long quirks;
        unsigned int fn_on;
@@ -150,6 +156,14 @@ static const struct apple_key_translation apple_iso_keyboard[] = {
        { }
 };
 
+static const struct apple_key_translation swapped_option_cmd_keys[] = {
+       { KEY_LEFTALT,  KEY_LEFTMETA },
+       { KEY_LEFTMETA, KEY_LEFTALT },
+       { KEY_RIGHTALT, KEY_RIGHTMETA },
+       { KEY_RIGHTMETA,KEY_RIGHTALT },
+       { }
+};
+
 static const struct apple_key_translation *apple_find_translation(
                const struct apple_key_translation *table, u16 from)
 {
@@ -242,6 +256,14 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
                }
        }
 
+       if (swap_opt_cmd) {
+               trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
+               if (trans) {
+                       input_event(input, usage->type, trans->to, value);
+                       return 1;
+               }
+       }
+
        return 0;
 }
 
index 64ab94a55aa796515958206986a991003a750069..a594e478a1e218abd629b69f8ca9b19b9335e753 100644 (file)
@@ -95,7 +95,7 @@ static int axff_init(struct hid_device *hid)
                }
        }
 
-       if (field_count < 4) {
+       if (field_count < 4 && hid->product != 0xf705) {
                hid_err(hid, "not enough fields in the report: %d\n",
                        field_count);
                return -ENODEV;
@@ -180,6 +180,7 @@ static void ax_remove(struct hid_device *hdev)
 
 static const struct hid_device_id ax_devices[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705), },
        { }
 };
 MODULE_DEVICE_TABLE(hid, ax_devices);
index e80da62363bc2c96d6be419f89d002f3a55e4d36..8c10f2742233e2f731aa7b798f49b178cee93279 100644 (file)
@@ -1418,10 +1418,8 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
 
        if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
                ret = hdrv->raw_event(hid, report, data, size);
-               if (ret < 0) {
-                       ret = ret < 0 ? ret : 0;
+               if (ret < 0)
                        goto unlock;
-               }
        }
 
        ret = hid_report_raw_event(hid, type, data, size, interrupt);
@@ -1605,6 +1603,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
        { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705) },
        { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
        { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
        { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
@@ -1716,6 +1715,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_580) },
        { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
@@ -1754,6 +1754,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
@@ -1801,21 +1802,28 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
 #if IS_ENABLED(CONFIG_HID_ROCCAT)
-       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKUFX) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEXTD) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO) },
        { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
 #endif
        { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_SIS2_TOUCH, USB_DEVICE_ID_SIS9200_TOUCH) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_SIS2_TOUCH, USB_DEVICE_ID_SIS817_TOUCH) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) },
        { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) },
@@ -2376,15 +2384,6 @@ bool hid_ignore(struct hid_device *hdev)
                                hdev->type == HID_TYPE_USBNONE)
                        return true;
                break;
-       case USB_VENDOR_ID_DWAV:
-               /* These are handled by usbtouchscreen. hdev->type is probably
-                * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match
-                * usbtouchscreen. */
-               if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER ||
-                    hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) &&
-                   hdev->type != HID_TYPE_USBMOUSE)
-                       return true;
-               break;
        case USB_VENDOR_ID_VELLEMAN:
                /* These are not HID devices.  They are handled by comedi. */
                if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
index f042a6cf8b18c897fce2586f108bd91daaf9d33e..4e49462870abdf2f265c1528ae6c07fa4f783ec8 100644 (file)
@@ -181,7 +181,40 @@ fail:
  */
 static bool elo_broken_firmware(struct usb_device *dev)
 {
-       return use_fw_quirk && le16_to_cpu(dev->descriptor.bcdDevice) == 0x10d;
+       struct usb_device *hub = dev->parent;
+       struct usb_device *child = NULL;
+       u16 fw_lvl = le16_to_cpu(dev->descriptor.bcdDevice);
+       u16 child_vid, child_pid;
+       int i;
+    
+       if (!use_fw_quirk)
+               return false;
+       if (fw_lvl != 0x10d)
+               return false;
+
+       /* iterate sibling devices of the touch controller */
+       usb_hub_for_each_child(hub, i, child) {
+               child_vid = le16_to_cpu(child->descriptor.idVendor);
+               child_pid = le16_to_cpu(child->descriptor.idProduct);
+
+               /*
+                * If one of the devices below is present attached as a sibling of 
+                * the touch controller then  this is a newer IBM 4820 monitor that 
+                * does not need the IBM-requested workaround if fw level is
+                * 0x010d - aka 'M'.
+                * No other HW can have this combination.
+                */
+               if (child_vid==0x04b3) {
+                       switch (child_pid) {
+                       case 0x4676: /* 4820 21x Video */
+                       case 0x4677: /* 4820 51x Video */
+                       case 0x4678: /* 4820 2Lx Video */
+                       case 0x4679: /* 4820 5Lx Video */
+                               return false;
+                       }
+               }
+       }
+       return true;
 }
 
 static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
index e696566cde46420334d1f416b53c2675ec581a7b..0caa676de622fb03e2126ffe1f512e47b3c86567 100644 (file)
@@ -28,6 +28,7 @@
  * - USB ID 04d9:a04a, sold as Tracer Sniper TRM-503, NOVA Gaming Slider X200
  *   and Zalman ZM-GM1
  * - USB ID 04d9:a081, sold as SHARKOON DarkGlider Gaming mouse
+ * - USB ID 04d9:a072, sold as LEETGION Hellion Gaming Mouse
  */
 
 static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
@@ -40,6 +41,7 @@ static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
                 * 0x2fff, so they don't exceed HID_MAX_USAGES */
                switch (hdev->product) {
                case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067:
+               case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072:
                        if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
                                        && rdesc[120] == 0xff && rdesc[121] == 0x7f) {
                                hid_info(hdev, "Fixing up report descriptor\n");
@@ -65,6 +67,8 @@ static const struct hid_device_id holtek_mouse_devices[] = {
                        USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
                        USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
+                       USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
                        USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
        { }
index f0296a50be5f754fc7be2b8f593bf2b2beca1e22..76559629568c44dc2fd5b38c072faf446c063b17 100644 (file)
 #define USB_VENDOR_ID_GENERAL_TOUCH    0x0dfc
 #define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0003
 #define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS 0x0100
+#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101 0x0101
+#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102 0x0102
+#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106 0x0106
+#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A 0x010a
+#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100 0xe100
 
 #define USB_VENDOR_ID_GLAB             0x06c2
 #define USB_DEVICE_ID_4_PHIDGETSERVO_30        0x0038
 
 #define USB_VENDOR_ID_HOLTEK_ALT               0x04d9
 #define USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD      0xa055
-#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067    0xa067
 #define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A    0xa04a
+#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067    0xa067
+#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072    0xa072
 #define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081    0xa081
 
 #define USB_VENDOR_ID_IMATION          0x0718
 #define USB_DEVICE_ID_DINOVO_EDGE      0xc714
 #define USB_DEVICE_ID_DINOVO_MINI      0xc71f
 #define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2     0xca03
+#define USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL 0xca04
 
 #define USB_VENDOR_ID_LUMIO            0x202e
 #define USB_DEVICE_ID_CRYSTALTOUCH     0x0006
 #define USB_DEVICE_ID_ROCCAT_LUA       0x2c2e
 #define USB_DEVICE_ID_ROCCAT_PYRA_WIRED        0x2c24
 #define USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS     0x2cf6
+#define USB_DEVICE_ID_ROCCAT_RYOS_MK   0x3138
+#define USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW      0x31ce
+#define USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO       0x3232
 #define USB_DEVICE_ID_ROCCAT_SAVU      0x2d5a
 
 #define USB_VENDOR_ID_SAITEK           0x06a3
 #define USB_VENDOR_ID_SIGMATEL         0x066F
 #define USB_DEVICE_ID_SIGMATEL_STMP3780        0x3780
 
+#define USB_VENDOR_ID_SIS2_TOUCH       0x0457
+#define USB_DEVICE_ID_SIS9200_TOUCH    0x9200
+#define USB_DEVICE_ID_SIS817_TOUCH     0x0817
+
 #define USB_VENDOR_ID_SKYCABLE                 0x1223
 #define        USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER       0x3F07
 
index 31cf29a6ba17551ff5244a0f243d48a4719e662c..2d25b6cbbc051910a8eeaaab0525605c77a88da1 100644 (file)
 #include <linux/module.h>
 #include <linux/sysfs.h>
 #include <linux/device.h>
-#include <linux/usb.h>
 #include <linux/hid.h>
 #include <linux/input.h>
 #include <linux/leds.h>
-#include "usbhid/usbhid.h"
 
 #include "hid-ids.h"
 
@@ -41,10 +39,9 @@ static int tpkbd_input_mapping(struct hid_device *hdev,
                struct hid_input *hi, struct hid_field *field,
                struct hid_usage *usage, unsigned long **bit, int *max)
 {
-       struct usbhid_device *uhdev;
-
-       uhdev = (struct usbhid_device *) hdev->driver_data;
-       if (uhdev->ifnum == 1 && usage->hid == (HID_UP_BUTTON | 0x0010)) {
+       if (usage->hid == (HID_UP_BUTTON | 0x0010)) {
+               /* mark the device as pointer */
+               hid_set_drvdata(hdev, (void *)1);
                map_key_clear(KEY_MICMUTE);
                return 1;
        }
@@ -339,7 +336,7 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
        struct tpkbd_data_pointer *data_pointer;
        size_t name_sz = strlen(dev_name(dev)) + 16;
        char *name_mute, *name_micmute;
-       int i, ret;
+       int i;
 
        /* Validate required reports. */
        for (i = 0; i < 4; i++) {
@@ -354,7 +351,9 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
                hid_warn(hdev, "Could not create sysfs group\n");
        }
 
-       data_pointer = kzalloc(sizeof(struct tpkbd_data_pointer), GFP_KERNEL);
+       data_pointer = devm_kzalloc(&hdev->dev,
+                                   sizeof(struct tpkbd_data_pointer),
+                                   GFP_KERNEL);
        if (data_pointer == NULL) {
                hid_err(hdev, "Could not allocate memory for driver data\n");
                return -ENOMEM;
@@ -364,20 +363,13 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
        data_pointer->sensitivity = 0xa0;
        data_pointer->press_speed = 0x38;
 
-       name_mute = kzalloc(name_sz, GFP_KERNEL);
-       if (name_mute == NULL) {
+       name_mute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL);
+       name_micmute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL);
+       if (name_mute == NULL || name_micmute == NULL) {
                hid_err(hdev, "Could not allocate memory for led data\n");
-               ret = -ENOMEM;
-               goto err;
+               return -ENOMEM;
        }
        snprintf(name_mute, name_sz, "%s:amber:mute", dev_name(dev));
-
-       name_micmute = kzalloc(name_sz, GFP_KERNEL);
-       if (name_micmute == NULL) {
-               hid_err(hdev, "Could not allocate memory for led data\n");
-               ret = -ENOMEM;
-               goto err2;
-       }
        snprintf(name_micmute, name_sz, "%s:amber:micmute", dev_name(dev));
 
        hid_set_drvdata(hdev, data_pointer);
@@ -397,19 +389,12 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
        tpkbd_features_set(hdev);
 
        return 0;
-
-err2:
-       kfree(name_mute);
-err:
-       kfree(data_pointer);
-       return ret;
 }
 
 static int tpkbd_probe(struct hid_device *hdev,
                const struct hid_device_id *id)
 {
        int ret;
-       struct usbhid_device *uhdev;
 
        ret = hid_parse(hdev);
        if (ret) {
@@ -423,9 +408,8 @@ static int tpkbd_probe(struct hid_device *hdev,
                goto err;
        }
 
-       uhdev = (struct usbhid_device *) hdev->driver_data;
-
-       if (uhdev->ifnum == 1) {
+       if (hid_get_drvdata(hdev)) {
+               hid_set_drvdata(hdev, NULL);
                ret = tpkbd_probe_tp(hdev);
                if (ret)
                        goto err_hid;
@@ -449,17 +433,11 @@ static void tpkbd_remove_tp(struct hid_device *hdev)
        led_classdev_unregister(&data_pointer->led_mute);
 
        hid_set_drvdata(hdev, NULL);
-       kfree(data_pointer->led_micmute.name);
-       kfree(data_pointer->led_mute.name);
-       kfree(data_pointer);
 }
 
 static void tpkbd_remove(struct hid_device *hdev)
 {
-       struct usbhid_device *uhdev;
-
-       uhdev = (struct usbhid_device *) hdev->driver_data;
-       if (uhdev->ifnum == 1)
+       if (hid_get_drvdata(hdev))
                tpkbd_remove_tp(hdev);
 
        hid_hw_stop(hdev);
index 6f12ecd36c8834fa9c9cb77b79d883dd4c246dc8..06eb45fa6331fee64152754a5ab9bb2275e3a61c 100644 (file)
@@ -45,7 +45,9 @@
 /* Size of the original descriptors of the Driving Force (and Pro) wheels */
 #define DF_RDESC_ORIG_SIZE     130
 #define DFP_RDESC_ORIG_SIZE    97
+#define FV_RDESC_ORIG_SIZE     130
 #define MOMO_RDESC_ORIG_SIZE   87
+#define MOMO2_RDESC_ORIG_SIZE  87
 
 /* Fixed report descriptors for Logitech Driving Force (and Pro)
  * wheel controllers
@@ -170,6 +172,73 @@ static __u8 dfp_rdesc_fixed[] = {
 0xC0                /*  End Collection                          */
 };
 
+static __u8 fv_rdesc_fixed[] = {
+0x05, 0x01,         /*  Usage Page (Desktop),                   */
+0x09, 0x04,         /*  Usage (Joystik),                        */
+0xA1, 0x01,         /*  Collection (Application),               */
+0xA1, 0x02,         /*      Collection (Logical),               */
+0x95, 0x01,         /*          Report Count (1),               */
+0x75, 0x0A,         /*          Report Size (10),               */
+0x15, 0x00,         /*          Logical Minimum (0),            */
+0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),         */
+0x35, 0x00,         /*          Physical Minimum (0),           */
+0x46, 0xFF, 0x03,   /*          Physical Maximum (1023),        */
+0x09, 0x30,         /*          Usage (X),                      */
+0x81, 0x02,         /*          Input (Variable),               */
+0x95, 0x0C,         /*          Report Count (12),              */
+0x75, 0x01,         /*          Report Size (1),                */
+0x25, 0x01,         /*          Logical Maximum (1),            */
+0x45, 0x01,         /*          Physical Maximum (1),           */
+0x05, 0x09,         /*          Usage Page (Button),            */
+0x19, 0x01,         /*          Usage Minimum (01h),            */
+0x29, 0x0C,         /*          Usage Maximum (0Ch),            */
+0x81, 0x02,         /*          Input (Variable),               */
+0x95, 0x02,         /*          Report Count (2),               */
+0x06, 0x00, 0xFF,   /*          Usage Page (FF00h),             */
+0x09, 0x01,         /*          Usage (01h),                    */
+0x81, 0x02,         /*          Input (Variable),               */
+0x09, 0x02,         /*          Usage (02h),                    */
+0x26, 0xFF, 0x00,   /*          Logical Maximum (255),          */
+0x46, 0xFF, 0x00,   /*          Physical Maximum (255),         */
+0x95, 0x01,         /*          Report Count (1),               */
+0x75, 0x08,         /*          Report Size (8),                */
+0x81, 0x02,         /*          Input (Variable),               */
+0x05, 0x01,         /*          Usage Page (Desktop),           */
+0x25, 0x07,         /*          Logical Maximum (7),            */
+0x46, 0x3B, 0x01,   /*          Physical Maximum (315),         */
+0x75, 0x04,         /*          Report Size (4),                */
+0x65, 0x14,         /*          Unit (Degrees),                 */
+0x09, 0x39,         /*          Usage (Hat Switch),             */
+0x81, 0x42,         /*          Input (Variable, Null State),   */
+0x75, 0x01,         /*          Report Size (1),                */
+0x95, 0x04,         /*          Report Count (4),               */
+0x65, 0x00,         /*          Unit,                           */
+0x06, 0x00, 0xFF,   /*          Usage Page (FF00h),             */
+0x09, 0x01,         /*          Usage (01h),                    */
+0x25, 0x01,         /*          Logical Maximum (1),            */
+0x45, 0x01,         /*          Physical Maximum (1),           */
+0x81, 0x02,         /*          Input (Variable),               */
+0x05, 0x01,         /*          Usage Page (Desktop),           */
+0x95, 0x01,         /*          Report Count (1),               */
+0x75, 0x08,         /*          Report Size (8),                */
+0x26, 0xFF, 0x00,   /*          Logical Maximum (255),          */
+0x46, 0xFF, 0x00,   /*          Physical Maximum (255),         */
+0x09, 0x31,         /*          Usage (Y),                      */
+0x81, 0x02,         /*          Input (Variable),               */
+0x09, 0x32,         /*          Usage (Z),                      */
+0x81, 0x02,         /*          Input (Variable),               */
+0xC0,               /*      End Collection,                     */
+0xA1, 0x02,         /*      Collection (Logical),               */
+0x26, 0xFF, 0x00,   /*          Logical Maximum (255),          */
+0x46, 0xFF, 0x00,   /*          Physical Maximum (255),         */
+0x95, 0x07,         /*          Report Count (7),               */
+0x75, 0x08,         /*          Report Size (8),                */
+0x09, 0x03,         /*          Usage (03h),                    */
+0x91, 0x02,         /*          Output (Variable),              */
+0xC0,               /*      End Collection,                     */
+0xC0                /*  End Collection                          */
+};
+
 static __u8 momo_rdesc_fixed[] = {
 0x05, 0x01,         /*  Usage Page (Desktop),               */
 0x09, 0x04,         /*  Usage (Joystik),                    */
@@ -216,6 +285,54 @@ static __u8 momo_rdesc_fixed[] = {
 0xC0                /*  End Collection                      */
 };
 
+static __u8 momo2_rdesc_fixed[] = {
+0x05, 0x01,         /*  Usage Page (Desktop),               */
+0x09, 0x04,         /*  Usage (Joystik),                    */
+0xA1, 0x01,         /*  Collection (Application),           */
+0xA1, 0x02,         /*      Collection (Logical),           */
+0x95, 0x01,         /*          Report Count (1),           */
+0x75, 0x0A,         /*          Report Size (10),           */
+0x15, 0x00,         /*          Logical Minimum (0),        */
+0x26, 0xFF, 0x03,   /*          Logical Maximum (1023),     */
+0x35, 0x00,         /*          Physical Minimum (0),       */
+0x46, 0xFF, 0x03,   /*          Physical Maximum (1023),    */
+0x09, 0x30,         /*          Usage (X),                  */
+0x81, 0x02,         /*          Input (Variable),           */
+0x95, 0x0A,         /*          Report Count (10),          */
+0x75, 0x01,         /*          Report Size (1),            */
+0x25, 0x01,         /*          Logical Maximum (1),        */
+0x45, 0x01,         /*          Physical Maximum (1),       */
+0x05, 0x09,         /*          Usage Page (Button),        */
+0x19, 0x01,         /*          Usage Minimum (01h),        */
+0x29, 0x0A,         /*          Usage Maximum (0Ah),        */
+0x81, 0x02,         /*          Input (Variable),           */
+0x06, 0x00, 0xFF,   /*          Usage Page (FF00h),         */
+0x09, 0x00,         /*          Usage (00h),                */
+0x95, 0x04,         /*          Report Count (4),           */
+0x81, 0x02,         /*          Input (Variable),           */
+0x95, 0x01,         /*          Report Count (1),           */
+0x75, 0x08,         /*          Report Size (8),            */
+0x26, 0xFF, 0x00,   /*          Logical Maximum (255),      */
+0x46, 0xFF, 0x00,   /*          Physical Maximum (255),     */
+0x09, 0x01,         /*          Usage (01h),                */
+0x81, 0x02,         /*          Input (Variable),           */
+0x05, 0x01,         /*          Usage Page (Desktop),       */
+0x09, 0x31,         /*          Usage (Y),                  */
+0x81, 0x02,         /*          Input (Variable),           */
+0x09, 0x32,         /*          Usage (Z),                  */
+0x81, 0x02,         /*          Input (Variable),           */
+0x06, 0x00, 0xFF,   /*          Usage Page (FF00h),         */
+0x09, 0x00,         /*          Usage (00h),                */
+0x81, 0x02,         /*          Input (Variable),           */
+0xC0,               /*      End Collection,                 */
+0xA1, 0x02,         /*      Collection (Logical),           */
+0x09, 0x02,         /*          Usage (02h),                */
+0x95, 0x07,         /*          Report Count (7),           */
+0x91, 0x02,         /*          Output (Variable),          */
+0xC0,               /*      End Collection,                 */
+0xC0                /*  End Collection                      */
+};
+
 /*
  * Certain Logitech keyboards send in report #3 keys which are far
  * above the logical maximum described in descriptor. This extends
@@ -275,6 +392,24 @@ static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
                }
                break;
 
+       case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
+               if (*rsize == MOMO2_RDESC_ORIG_SIZE) {
+                       hid_info(hdev,
+                               "fixing up Logitech Momo Racing Force (Black) report descriptor\n");
+                       rdesc = momo2_rdesc_fixed;
+                       *rsize = sizeof(momo2_rdesc_fixed);
+               }
+               break;
+
+       case USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL:
+               if (*rsize == FV_RDESC_ORIG_SIZE) {
+                       hid_info(hdev,
+                               "fixing up Logitech Formula Vibration report descriptor\n");
+                       rdesc = fv_rdesc_fixed;
+                       *rsize = sizeof(fv_rdesc_fixed);
+               }
+               break;
+
        case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
                if (*rsize == DFP_RDESC_ORIG_SIZE) {
                        hid_info(hdev,
@@ -492,6 +627,7 @@ static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
                case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
                case USB_DEVICE_ID_LOGITECH_WII_WHEEL:
                case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
+               case USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL:
                        field->application = HID_GD_MULTIAXIS;
                        break;
                default:
@@ -639,6 +775,8 @@ static const struct hid_device_id lg_devices[] = {
                .driver_data = LG_NOGET | LG_FF4 },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2),
                .driver_data = LG_FF4 },
+       { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL),
+               .driver_data = LG_FF2 },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL),
                .driver_data = LG_FF4 },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL),
index 1a42eaa6ca0234a054631544732db69484c5eb82..0e3fb1a7e42174dd1dfb953e7209fc14ab50ed7a 100644 (file)
@@ -95,7 +95,7 @@ int lg2ff_init(struct hid_device *hid)
 
        hid_hw_request(hid, report, HID_REQ_SET_REPORT);
 
-       hid_info(hid, "Force feedback for Logitech RumblePad/Rumblepad 2 by Anssi Hannula <anssi.hannula@gmail.com>\n");
+       hid_info(hid, "Force feedback for Logitech variant 2 rumble devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
 
        return 0;
 }
index 8782fe1aaa0796e42d17f1ad39d1c72c652d58c5..befe0e336471b0f36e34473ee97c3ba72759ddf9 100644 (file)
@@ -196,6 +196,21 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e
        case FF_CONSTANT:
                x = effect->u.ramp.start_level + 0x80;  /* 0x80 is no force */
                CLAMP(x);
+
+               if (x == 0x80) {
+                       /* De-activate force in slot-1*/
+                       value[0] = 0x13;
+                       value[1] = 0x00;
+                       value[2] = 0x00;
+                       value[3] = 0x00;
+                       value[4] = 0x00;
+                       value[5] = 0x00;
+                       value[6] = 0x00;
+
+                       hid_hw_request(hid, report, HID_REQ_SET_REPORT);
+                       return 0;
+               }
+
                value[0] = 0x11;        /* Slot 1 */
                value[1] = 0x08;
                value[2] = x;
@@ -218,12 +233,70 @@ static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitud
        struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
        struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
        __s32 *value = report->field[0]->value;
+       __u32 expand_a, expand_b;
+       struct lg4ff_device_entry *entry;
+       struct lg_drv_data *drv_data;
+
+       drv_data = hid_get_drvdata(hid);
+       if (!drv_data) {
+               hid_err(hid, "Private driver data not found!\n");
+               return;
+       }
+
+       entry = drv_data->device_props;
+       if (!entry) {
+               hid_err(hid, "Device properties not found!\n");
+               return;
+       }
+
+       /* De-activate Auto-Center */
+       if (magnitude == 0) {
+               value[0] = 0xf5;
+               value[1] = 0x00;
+               value[2] = 0x00;
+               value[3] = 0x00;
+               value[4] = 0x00;
+               value[5] = 0x00;
+               value[6] = 0x00;
+
+               hid_hw_request(hid, report, HID_REQ_SET_REPORT);
+               return;
+       }
+
+       if (magnitude <= 0xaaaa) {
+               expand_a = 0x0c * magnitude;
+               expand_b = 0x80 * magnitude;
+       } else {
+               expand_a = (0x0c * 0xaaaa) + 0x06 * (magnitude - 0xaaaa);
+               expand_b = (0x80 * 0xaaaa) + 0xff * (magnitude - 0xaaaa);
+       }
+
+       /* Adjust for non-MOMO wheels */
+       switch (entry->product_id) {
+       case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL:
+       case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
+               break;
+       default:
+               expand_a = expand_a >> 1;
+               break;
+       }
 
        value[0] = 0xfe;
        value[1] = 0x0d;
-       value[2] = magnitude >> 13;
-       value[3] = magnitude >> 13;
-       value[4] = magnitude >> 8;
+       value[2] = expand_a / 0xaaaa;
+       value[3] = expand_a / 0xaaaa;
+       value[4] = expand_b / 0xaaaa;
+       value[5] = 0x00;
+       value[6] = 0x00;
+
+       hid_hw_request(hid, report, HID_REQ_SET_REPORT);
+
+       /* Activate Auto-Center */
+       value[0] = 0x14;
+       value[1] = 0x00;
+       value[2] = 0x00;
+       value[3] = 0x00;
+       value[4] = 0x00;
        value[5] = 0x00;
        value[6] = 0x00;
 
@@ -540,17 +613,6 @@ int lg4ff_init(struct hid_device *hid)
        if (error)
                return error;
 
-       /* Check if autocentering is available and
-        * set the centering force to zero by default */
-       if (test_bit(FF_AUTOCENTER, dev->ffbit)) {
-               if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */
-                       dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex;
-               else
-                       dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default;
-
-               dev->ff->set_autocenter(dev, 0);
-       }
-
        /* Get private driver data */
        drv_data = hid_get_drvdata(hid);
        if (!drv_data) {
@@ -571,6 +633,17 @@ int lg4ff_init(struct hid_device *hid)
        entry->max_range = lg4ff_devices[i].max_range;
        entry->set_range = lg4ff_devices[i].set_range;
 
+       /* Check if autocentering is available and
+        * set the centering force to zero by default */
+       if (test_bit(FF_AUTOCENTER, dev->ffbit)) {
+               if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */
+                       dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex;
+               else
+                       dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default;
+
+               dev->ff->set_autocenter(dev, 0);
+       }
+
        /* Create sysfs interface */
        error = device_create_file(&hid->dev, &dev_attr_range);
        if (error)
index 2e5302462efb088b3f3019b26fedfc816ca493f5..a7947d8251a88af3ecb017a7e597556cd0c046ff 100644 (file)
@@ -542,9 +542,9 @@ static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf,
        return 0;
 }
 
-static void rdcat(char **rdesc, unsigned int *rsize, const char *data, unsigned int size)
+static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size)
 {
-       memcpy(*rdesc + *rsize, data, size);
+       memcpy(rdesc + *rsize, data, size);
        *rsize += size;
 }
 
@@ -567,31 +567,31 @@ static int logi_dj_ll_parse(struct hid_device *hid)
        if (djdev->reports_supported & STD_KEYBOARD) {
                dbg_hid("%s: sending a kbd descriptor, reports_supported: %x\n",
                        __func__, djdev->reports_supported);
-               rdcat(&rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
+               rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
        }
 
        if (djdev->reports_supported & STD_MOUSE) {
                dbg_hid("%s: sending a mouse descriptor, reports_supported: "
                        "%x\n", __func__, djdev->reports_supported);
-               rdcat(&rdesc, &rsize, mse_descriptor, sizeof(mse_descriptor));
+               rdcat(rdesc, &rsize, mse_descriptor, sizeof(mse_descriptor));
        }
 
        if (djdev->reports_supported & MULTIMEDIA) {
                dbg_hid("%s: sending a multimedia report descriptor: %x\n",
                        __func__, djdev->reports_supported);
-               rdcat(&rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));
+               rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));
        }
 
        if (djdev->reports_supported & POWER_KEYS) {
                dbg_hid("%s: sending a power keys report descriptor: %x\n",
                        __func__, djdev->reports_supported);
-               rdcat(&rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));
+               rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));
        }
 
        if (djdev->reports_supported & MEDIA_CENTER) {
                dbg_hid("%s: sending a media center report descriptor: %x\n",
                        __func__, djdev->reports_supported);
-               rdcat(&rdesc, &rsize, media_descriptor, sizeof(media_descriptor));
+               rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor));
        }
 
        if (djdev->reports_supported & KBD_LEDS) {
index 5e5fe1b8eebb73e5d4533997a889eee87d637150..a2cedb8ae1c0cf57c98e185e7b285d7555834b1a 100644 (file)
@@ -250,12 +250,12 @@ static struct mt_class mt_classes[] = {
        { .name = MT_CLS_GENERALTOUCH_TWOFINGERS,
                .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
                        MT_QUIRK_VALID_IS_INRANGE |
-                       MT_QUIRK_SLOT_IS_CONTACTNUMBER,
+                       MT_QUIRK_SLOT_IS_CONTACTID,
                .maxcontacts = 2
        },
        { .name = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
                .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
-                       MT_QUIRK_SLOT_IS_CONTACTNUMBER
+                       MT_QUIRK_SLOT_IS_CONTACTID
        },
 
        { .name = MT_CLS_FLATFROG,
@@ -1173,6 +1173,21 @@ static const struct hid_device_id mt_devices[] = {
        { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
                MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
                        USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS) },
+       { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS,
+               MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
+                       USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0101) },
+       { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
+               MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
+                       USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0102) },
+       { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
+               MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
+                       USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_0106) },
+       { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
+               MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
+                       USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A) },
+       { .driver_data = MT_CLS_GENERALTOUCH_PWT_TENFINGERS,
+               MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH,
+                       USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100) },
 
        /* Gametel game controller */
        { .driver_data = MT_CLS_NSMU,
@@ -1284,6 +1299,14 @@ static const struct hid_device_id mt_devices[] = {
                MT_USB_DEVICE(USB_VENDOR_ID_QUANTA,
                        USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008) },
 
+       /* SiS panels */
+       { .driver_data = MT_CLS_DEFAULT,
+               HID_USB_DEVICE(USB_VENDOR_ID_SIS2_TOUCH,
+               USB_DEVICE_ID_SIS9200_TOUCH) },
+       { .driver_data = MT_CLS_DEFAULT,
+               HID_USB_DEVICE(USB_VENDOR_ID_SIS2_TOUCH,
+               USB_DEVICE_ID_SIS817_TOUCH) },
+
        /* Stantum panels */
        { .driver_data = MT_CLS_CONFIDENCE,
                MT_USB_DEVICE(USB_VENDOR_ID_STANTUM,
index 74f704032627eb0a30920f69de78c1d3b9df4263..02e28e9f4ea7dcb64165df74ee20be1faccc92ac 100644 (file)
@@ -65,10 +65,11 @@ int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
 EXPORT_SYMBOL_GPL(roccat_common2_send);
 
 enum roccat_common2_control_states {
-       ROCCAT_COMMON_CONTROL_STATUS_OVERLOAD = 0,
+       ROCCAT_COMMON_CONTROL_STATUS_CRITICAL = 0,
        ROCCAT_COMMON_CONTROL_STATUS_OK = 1,
        ROCCAT_COMMON_CONTROL_STATUS_INVALID = 2,
-       ROCCAT_COMMON_CONTROL_STATUS_WAIT = 3,
+       ROCCAT_COMMON_CONTROL_STATUS_BUSY = 3,
+       ROCCAT_COMMON_CONTROL_STATUS_CRITICAL_NEW = 4,
 };
 
 static int roccat_common2_receive_control_status(struct usb_device *usb_dev)
@@ -88,13 +89,12 @@ static int roccat_common2_receive_control_status(struct usb_device *usb_dev)
                switch (control.value) {
                case ROCCAT_COMMON_CONTROL_STATUS_OK:
                        return 0;
-               case ROCCAT_COMMON_CONTROL_STATUS_WAIT:
+               case ROCCAT_COMMON_CONTROL_STATUS_BUSY:
                        msleep(500);
                        continue;
                case ROCCAT_COMMON_CONTROL_STATUS_INVALID:
-
-               case ROCCAT_COMMON_CONTROL_STATUS_OVERLOAD:
-                       /* seems to be critical - replug necessary */
+               case ROCCAT_COMMON_CONTROL_STATUS_CRITICAL:
+               case ROCCAT_COMMON_CONTROL_STATUS_CRITICAL_NEW:
                        return -EINVAL;
                default:
                        dev_err(&usb_dev->dev,
@@ -122,6 +122,59 @@ int roccat_common2_send_with_status(struct usb_device *usb_dev,
 }
 EXPORT_SYMBOL_GPL(roccat_common2_send_with_status);
 
+int roccat_common2_device_init_struct(struct usb_device *usb_dev,
+               struct roccat_common2_device *dev)
+{
+       mutex_init(&dev->lock);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(roccat_common2_device_init_struct);
+
+ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
+               char *buf, loff_t off, size_t count,
+               size_t real_size, uint command)
+{
+       struct device *dev =
+                       container_of(kobj, struct device, kobj)->parent->parent;
+       struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev));
+       struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
+       int retval;
+
+       if (off >= real_size)
+               return 0;
+
+       if (off != 0 || count != real_size)
+               return -EINVAL;
+
+       mutex_lock(&roccat_dev->lock);
+       retval = roccat_common2_receive(usb_dev, command, buf, real_size);
+       mutex_unlock(&roccat_dev->lock);
+
+       return retval ? retval : real_size;
+}
+EXPORT_SYMBOL_GPL(roccat_common2_sysfs_read);
+
+ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
+               void const *buf, loff_t off, size_t count,
+               size_t real_size, uint command)
+{
+       struct device *dev =
+                       container_of(kobj, struct device, kobj)->parent->parent;
+       struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev));
+       struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
+       int retval;
+
+       if (off != 0 || count != real_size)
+               return -EINVAL;
+
+       mutex_lock(&roccat_dev->lock);
+       retval = roccat_common2_send_with_status(usb_dev, command, buf, real_size);
+       mutex_unlock(&roccat_dev->lock);
+
+       return retval ? retval : real_size;
+}
+EXPORT_SYMBOL_GPL(roccat_common2_sysfs_write);
+
 MODULE_AUTHOR("Stefan Achatz");
 MODULE_DESCRIPTION("USB Roccat common driver");
 MODULE_LICENSE("GPL v2");
index a97746a63b7020a7cdb999ee8bf9ae5f3af47a66..eaa56eb7d5d18e454c01aea3b2536dbc0ff4f3a9 100644 (file)
@@ -32,4 +32,66 @@ int roccat_common2_send(struct usb_device *usb_dev, uint report_id,
 int roccat_common2_send_with_status(struct usb_device *usb_dev,
                uint command, void const *buf, uint size);
 
+struct roccat_common2_device {
+       int roccat_claimed;
+       int chrdev_minor;
+       struct mutex lock;
+};
+
+int roccat_common2_device_init_struct(struct usb_device *usb_dev,
+               struct roccat_common2_device *dev);
+ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
+               char *buf, loff_t off, size_t count,
+               size_t real_size, uint command);
+ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
+               void const *buf, loff_t off, size_t count,
+               size_t real_size, uint command);
+
+#define ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
+static ssize_t roccat_common2_sysfs_write_ ## thingy(struct file *fp, \
+               struct kobject *kobj, struct bin_attribute *attr, char *buf, \
+               loff_t off, size_t count) \
+{ \
+       return roccat_common2_sysfs_write(fp, kobj, buf, off, count, \
+                       SIZE, COMMAND); \
+}
+
+#define ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE) \
+static ssize_t roccat_common2_sysfs_read_ ## thingy(struct file *fp, \
+               struct kobject *kobj, struct bin_attribute *attr, char *buf, \
+               loff_t off, size_t count) \
+{ \
+       return roccat_common2_sysfs_read(fp, kobj, buf, off, count, \
+                       SIZE, COMMAND); \
+}
+
+#define ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE) \
+ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE) \
+ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE)
+
+#define ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(thingy, COMMAND, SIZE) \
+ROCCAT_COMMON2_SYSFS_RW(thingy, COMMAND, SIZE); \
+static struct bin_attribute bin_attr_ ## thingy = { \
+       .attr = { .name = #thingy, .mode = 0660 }, \
+       .size = SIZE, \
+       .read = roccat_common2_sysfs_read_ ## thingy, \
+       .write = roccat_common2_sysfs_write_ ## thingy \
+}
+
+#define ROCCAT_COMMON2_BIN_ATTRIBUTE_R(thingy, COMMAND, SIZE) \
+ROCCAT_COMMON2_SYSFS_R(thingy, COMMAND, SIZE); \
+static struct bin_attribute bin_attr_ ## thingy = { \
+       .attr = { .name = #thingy, .mode = 0440 }, \
+       .size = SIZE, \
+       .read = roccat_common2_sysfs_read_ ## thingy, \
+}
+
+#define ROCCAT_COMMON2_BIN_ATTRIBUTE_W(thingy, COMMAND, SIZE) \
+ROCCAT_COMMON2_SYSFS_W(thingy, COMMAND, SIZE); \
+static struct bin_attribute bin_attr_ ## thingy = { \
+       .attr = { .name = #thingy, .mode = 0220 }, \
+       .size = SIZE, \
+       .write = roccat_common2_sysfs_write_ ## thingy \
+}
+
 #endif
index 99a605ebb665b6eb952f99922bc7103a0536819f..07de2f9014c67f914209a5dfc08185892955bd79 100644 (file)
@@ -15,6 +15,7 @@
  * Roccat KonePure is a smaller version of KoneXTD with less buttons and lights.
  */
 
+#include <linux/types.h>
 #include <linux/device.h>
 #include <linux/input.h>
 #include <linux/hid.h>
 #include <linux/hid-roccat.h>
 #include "hid-ids.h"
 #include "hid-roccat-common.h"
-#include "hid-roccat-konepure.h"
 
-static struct class *konepure_class;
-
-static ssize_t konepure_sysfs_read(struct file *fp, struct kobject *kobj,
-               char *buf, loff_t off, size_t count,
-               size_t real_size, uint command)
-{
-       struct device *dev =
-                       container_of(kobj, struct device, kobj)->parent->parent;
-       struct konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev));
-       struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
-       int retval;
-
-       if (off >= real_size)
-               return 0;
-
-       if (off != 0 || count != real_size)
-               return -EINVAL;
-
-       mutex_lock(&konepure->konepure_lock);
-       retval = roccat_common2_receive(usb_dev, command, buf, real_size);
-       mutex_unlock(&konepure->konepure_lock);
-
-       return retval ? retval : real_size;
-}
-
-static ssize_t konepure_sysfs_write(struct file *fp, struct kobject *kobj,
-               void const *buf, loff_t off, size_t count,
-               size_t real_size, uint command)
-{
-       struct device *dev =
-                       container_of(kobj, struct device, kobj)->parent->parent;
-       struct konepure_device *konepure = hid_get_drvdata(dev_get_drvdata(dev));
-       struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
-       int retval;
-
-       if (off != 0 || count != real_size)
-               return -EINVAL;
-
-       mutex_lock(&konepure->konepure_lock);
-       retval = roccat_common2_send_with_status(usb_dev, command,
-                       (void *)buf, real_size);
-       mutex_unlock(&konepure->konepure_lock);
-
-       return retval ? retval : real_size;
-}
-
-#define KONEPURE_SYSFS_W(thingy, THINGY) \
-static ssize_t konepure_sysfs_write_ ## thingy(struct file *fp, \
-               struct kobject *kobj, struct bin_attribute *attr, char *buf, \
-               loff_t off, size_t count) \
-{ \
-       return konepure_sysfs_write(fp, kobj, buf, off, count, \
-                       KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \
-}
-
-#define KONEPURE_SYSFS_R(thingy, THINGY) \
-static ssize_t konepure_sysfs_read_ ## thingy(struct file *fp, \
-               struct kobject *kobj, struct bin_attribute *attr, char *buf, \
-               loff_t off, size_t count) \
-{ \
-       return konepure_sysfs_read(fp, kobj, buf, off, count, \
-                       KONEPURE_SIZE_ ## THINGY, KONEPURE_COMMAND_ ## THINGY); \
-}
+enum {
+       KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3,
+};
 
-#define KONEPURE_SYSFS_RW(thingy, THINGY) \
-KONEPURE_SYSFS_W(thingy, THINGY) \
-KONEPURE_SYSFS_R(thingy, THINGY)
-
-#define KONEPURE_BIN_ATTRIBUTE_RW(thingy, THINGY) \
-KONEPURE_SYSFS_RW(thingy, THINGY); \
-static struct bin_attribute bin_attr_##thingy = { \
-       .attr = { .name = #thingy, .mode = 0660 }, \
-       .size = KONEPURE_SIZE_ ## THINGY, \
-       .read = konepure_sysfs_read_ ## thingy, \
-       .write = konepure_sysfs_write_ ## thingy \
-}
+struct konepure_mouse_report_button {
+       uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */
+       uint8_t zero;
+       uint8_t type;
+       uint8_t data1;
+       uint8_t data2;
+       uint8_t zero2;
+       uint8_t unknown[2];
+} __packed;
 
-#define KONEPURE_BIN_ATTRIBUTE_R(thingy, THINGY) \
-KONEPURE_SYSFS_R(thingy, THINGY); \
-static struct bin_attribute bin_attr_##thingy = { \
-       .attr = { .name = #thingy, .mode = 0440 }, \
-       .size = KONEPURE_SIZE_ ## THINGY, \
-       .read = konepure_sysfs_read_ ## thingy, \
-}
-
-#define KONEPURE_BIN_ATTRIBUTE_W(thingy, THINGY) \
-KONEPURE_SYSFS_W(thingy, THINGY); \
-static struct bin_attribute bin_attr_##thingy = { \
-       .attr = { .name = #thingy, .mode = 0220 }, \
-       .size = KONEPURE_SIZE_ ## THINGY, \
-       .write = konepure_sysfs_write_ ## thingy \
-}
+static struct class *konepure_class;
 
-KONEPURE_BIN_ATTRIBUTE_RW(actual_profile, ACTUAL_PROFILE);
-KONEPURE_BIN_ATTRIBUTE_RW(info, INFO);
-KONEPURE_BIN_ATTRIBUTE_RW(sensor, SENSOR);
-KONEPURE_BIN_ATTRIBUTE_RW(tcu, TCU);
-KONEPURE_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
-KONEPURE_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
-KONEPURE_BIN_ATTRIBUTE_W(control, CONTROL);
-KONEPURE_BIN_ATTRIBUTE_W(talk, TALK);
-KONEPURE_BIN_ATTRIBUTE_W(macro, MACRO);
-KONEPURE_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE);
-
-static struct bin_attribute *konepure_bin_attributes[] = {
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(actual_profile, 0x05, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_settings, 0x06, 0x1f);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile_buttons, 0x07, 0x3b);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(macro, 0x08, 0x0822);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x09, 0x06);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(tcu, 0x0c, 0x04);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_R(tcu_image, 0x0c, 0x0404);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0x0f, 0x06);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x10, 0x10);
+
+static struct bin_attribute *konepure_bin_attrs[] = {
        &bin_attr_actual_profile,
+       &bin_attr_control,
        &bin_attr_info,
+       &bin_attr_talk,
+       &bin_attr_macro,
        &bin_attr_sensor,
        &bin_attr_tcu,
+       &bin_attr_tcu_image,
        &bin_attr_profile_settings,
        &bin_attr_profile_buttons,
-       &bin_attr_control,
-       &bin_attr_talk,
-       &bin_attr_macro,
-       &bin_attr_tcu_image,
        NULL,
 };
 
 static const struct attribute_group konepure_group = {
-       .bin_attrs = konepure_bin_attributes,
+       .bin_attrs = konepure_bin_attrs,
 };
 
 static const struct attribute_group *konepure_groups[] = {
@@ -152,20 +75,11 @@ static const struct attribute_group *konepure_groups[] = {
        NULL,
 };
 
-
-static int konepure_init_konepure_device_struct(struct usb_device *usb_dev,
-               struct konepure_device *konepure)
-{
-       mutex_init(&konepure->konepure_lock);
-
-       return 0;
-}
-
 static int konepure_init_specials(struct hid_device *hdev)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
        struct usb_device *usb_dev = interface_to_usbdev(intf);
-       struct konepure_device *konepure;
+       struct roccat_common2_device *konepure;
        int retval;
 
        if (intf->cur_altsetting->desc.bInterfaceProtocol
@@ -181,9 +95,9 @@ static int konepure_init_specials(struct hid_device *hdev)
        }
        hid_set_drvdata(hdev, konepure);
 
-       retval = konepure_init_konepure_device_struct(usb_dev, konepure);
+       retval = roccat_common2_device_init_struct(usb_dev, konepure);
        if (retval) {
-               hid_err(hdev, "couldn't init struct konepure_device\n");
+               hid_err(hdev, "couldn't init KonePure device\n");
                goto exit_free;
        }
 
@@ -205,7 +119,7 @@ exit_free:
 static void konepure_remove_specials(struct hid_device *hdev)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
-       struct konepure_device *konepure;
+       struct roccat_common2_device *konepure;
 
        if (intf->cur_altsetting->desc.bInterfaceProtocol
                        != USB_INTERFACE_PROTOCOL_MOUSE)
@@ -258,7 +172,7 @@ static int konepure_raw_event(struct hid_device *hdev,
                struct hid_report *report, u8 *data, int size)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
-       struct konepure_device *konepure = hid_get_drvdata(hdev);
+       struct roccat_common2_device *konepure = hid_get_drvdata(hdev);
 
        if (intf->cur_altsetting->desc.bInterfaceProtocol
                        != USB_INTERFACE_PROTOCOL_MOUSE)
diff --git a/drivers/hid/hid-roccat-konepure.h b/drivers/hid/hid-roccat-konepure.h
deleted file mode 100644 (file)
index 2cd24e9..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef __HID_ROCCAT_KONEPURE_H
-#define __HID_ROCCAT_KONEPURE_H
-
-/*
- * Copyright (c) 2012 Stefan Achatz <erazor_de@users.sourceforge.net>
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- */
-
-#include <linux/types.h>
-
-enum {
-       KONEPURE_SIZE_ACTUAL_PROFILE = 0x03,
-       KONEPURE_SIZE_CONTROL = 0x03,
-       KONEPURE_SIZE_FIRMWARE_WRITE = 0x0402,
-       KONEPURE_SIZE_INFO = 0x06,
-       KONEPURE_SIZE_MACRO = 0x0822,
-       KONEPURE_SIZE_PROFILE_SETTINGS = 0x1f,
-       KONEPURE_SIZE_PROFILE_BUTTONS = 0x3b,
-       KONEPURE_SIZE_SENSOR = 0x06,
-       KONEPURE_SIZE_TALK = 0x10,
-       KONEPURE_SIZE_TCU = 0x04,
-       KONEPURE_SIZE_TCU_IMAGE = 0x0404,
-};
-
-enum konepure_control_requests {
-       KONEPURE_CONTROL_REQUEST_GENERAL = 0x80,
-       KONEPURE_CONTROL_REQUEST_BUTTONS = 0x90,
-};
-
-enum konepure_commands {
-       KONEPURE_COMMAND_CONTROL = 0x04,
-       KONEPURE_COMMAND_ACTUAL_PROFILE = 0x05,
-       KONEPURE_COMMAND_PROFILE_SETTINGS = 0x06,
-       KONEPURE_COMMAND_PROFILE_BUTTONS = 0x07,
-       KONEPURE_COMMAND_MACRO = 0x08,
-       KONEPURE_COMMAND_INFO = 0x09,
-       KONEPURE_COMMAND_TCU = 0x0c,
-       KONEPURE_COMMAND_TCU_IMAGE = 0x0c,
-       KONEPURE_COMMAND_E = 0x0e,
-       KONEPURE_COMMAND_SENSOR = 0x0f,
-       KONEPURE_COMMAND_TALK = 0x10,
-       KONEPURE_COMMAND_FIRMWARE_WRITE = 0x1b,
-       KONEPURE_COMMAND_FIRMWARE_WRITE_CONTROL = 0x1c,
-};
-
-enum {
-       KONEPURE_MOUSE_REPORT_NUMBER_BUTTON = 3,
-};
-
-struct konepure_mouse_report_button {
-       uint8_t report_number; /* always KONEPURE_MOUSE_REPORT_NUMBER_BUTTON */
-       uint8_t zero;
-       uint8_t type;
-       uint8_t data1;
-       uint8_t data2;
-       uint8_t zero2;
-       uint8_t unknown[2];
-} __packed;
-
-struct konepure_device {
-       int roccat_claimed;
-       int chrdev_minor;
-       struct mutex konepure_lock;
-};
-
-#endif
index 0c8e1ef0b67d14fdb1c3bf2a6b575fdea94faf8e..966047711fbfc91038912382d0303291c937070e 100644 (file)
@@ -554,9 +554,13 @@ static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus,
                break;
        case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI:
                kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1);
+               break;
        case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY:
                kovaplus->actual_x_sensitivity = button_report->data1;
                kovaplus->actual_y_sensitivity = button_report->data2;
+               break;
+       default:
+               break;
        }
 }
 
diff --git a/drivers/hid/hid-roccat-ryos.c b/drivers/hid/hid-roccat-ryos.c
new file mode 100644 (file)
index 0000000..47cc8f3
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * Roccat Ryos driver for Linux
+ *
+ * Copyright (c) 2013 Stefan Achatz <erazor_de@users.sourceforge.net>
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/input.h>
+#include <linux/hid.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/hid-roccat.h>
+#include "hid-ids.h"
+#include "hid-roccat-common.h"
+
+enum {
+       RYOS_REPORT_NUMBER_SPECIAL = 3,
+       RYOS_USB_INTERFACE_PROTOCOL = 0,
+};
+
+struct ryos_report_special {
+       uint8_t number; /* RYOS_REPORT_NUMBER_SPECIAL */
+       uint8_t data[4];
+} __packed;
+
+static struct class *ryos_class;
+
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x04, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile, 0x05, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(keys_primary, 0x06, 0x7d);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(keys_function, 0x07, 0x5f);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(keys_macro, 0x08, 0x23);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(keys_thumbster, 0x09, 0x17);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(keys_extra, 0x0a, 0x08);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(keys_easyzone, 0x0b, 0x126);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(key_mask, 0x0c, 0x06);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(light, 0x0d, 0x10);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro, 0x0e, 0x7d2);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_R(info, 0x0f, 0x08);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(reset, 0x11, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(light_control, 0x13, 0x08);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(talk, 0x16, 0x10);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(stored_lights, 0x17, 0x0566);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(custom_lights, 0x18, 0x14);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(light_macro, 0x19, 0x07d2);
+
+static struct bin_attribute *ryos_bin_attrs[] = {
+       &bin_attr_control,
+       &bin_attr_profile,
+       &bin_attr_keys_primary,
+       &bin_attr_keys_function,
+       &bin_attr_keys_macro,
+       &bin_attr_keys_thumbster,
+       &bin_attr_keys_extra,
+       &bin_attr_keys_easyzone,
+       &bin_attr_key_mask,
+       &bin_attr_light,
+       &bin_attr_macro,
+       &bin_attr_info,
+       &bin_attr_reset,
+       &bin_attr_light_control,
+       &bin_attr_talk,
+       &bin_attr_stored_lights,
+       &bin_attr_custom_lights,
+       &bin_attr_light_macro,
+       NULL,
+};
+
+static const struct attribute_group ryos_group = {
+       .bin_attrs = ryos_bin_attrs,
+};
+
+static const struct attribute_group *ryos_groups[] = {
+       &ryos_group,
+       NULL,
+};
+
+static int ryos_init_specials(struct hid_device *hdev)
+{
+       struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
+       struct usb_device *usb_dev = interface_to_usbdev(intf);
+       struct roccat_common2_device *ryos;
+       int retval;
+
+       if (intf->cur_altsetting->desc.bInterfaceProtocol
+                       != RYOS_USB_INTERFACE_PROTOCOL) {
+               hid_set_drvdata(hdev, NULL);
+               return 0;
+       }
+
+       ryos = kzalloc(sizeof(*ryos), GFP_KERNEL);
+       if (!ryos) {
+               hid_err(hdev, "can't alloc device descriptor\n");
+               return -ENOMEM;
+       }
+       hid_set_drvdata(hdev, ryos);
+
+       retval = roccat_common2_device_init_struct(usb_dev, ryos);
+       if (retval) {
+               hid_err(hdev, "couldn't init Ryos device\n");
+               goto exit_free;
+       }
+
+       retval = roccat_connect(ryos_class, hdev,
+                       sizeof(struct ryos_report_special));
+       if (retval < 0) {
+               hid_err(hdev, "couldn't init char dev\n");
+       } else {
+               ryos->chrdev_minor = retval;
+               ryos->roccat_claimed = 1;
+       }
+
+       return 0;
+exit_free:
+       kfree(ryos);
+       return retval;
+}
+
+static void ryos_remove_specials(struct hid_device *hdev)
+{
+       struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
+       struct roccat_common2_device *ryos;
+
+       if (intf->cur_altsetting->desc.bInterfaceProtocol
+                       != RYOS_USB_INTERFACE_PROTOCOL)
+               return;
+
+       ryos = hid_get_drvdata(hdev);
+       if (ryos->roccat_claimed)
+               roccat_disconnect(ryos->chrdev_minor);
+       kfree(ryos);
+}
+
+static int ryos_probe(struct hid_device *hdev,
+               const struct hid_device_id *id)
+{
+       int retval;
+
+       retval = hid_parse(hdev);
+       if (retval) {
+               hid_err(hdev, "parse failed\n");
+               goto exit;
+       }
+
+       retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+       if (retval) {
+               hid_err(hdev, "hw start failed\n");
+               goto exit;
+       }
+
+       retval = ryos_init_specials(hdev);
+       if (retval) {
+               hid_err(hdev, "couldn't install mouse\n");
+               goto exit_stop;
+       }
+
+       return 0;
+
+exit_stop:
+       hid_hw_stop(hdev);
+exit:
+       return retval;
+}
+
+static void ryos_remove(struct hid_device *hdev)
+{
+       ryos_remove_specials(hdev);
+       hid_hw_stop(hdev);
+}
+
+static int ryos_raw_event(struct hid_device *hdev,
+               struct hid_report *report, u8 *data, int size)
+{
+       struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
+       struct roccat_common2_device *ryos = hid_get_drvdata(hdev);
+
+       if (intf->cur_altsetting->desc.bInterfaceProtocol
+                       != RYOS_USB_INTERFACE_PROTOCOL)
+               return 0;
+
+       if (data[0] != RYOS_REPORT_NUMBER_SPECIAL)
+               return 0;
+
+       if (ryos != NULL && ryos->roccat_claimed)
+               roccat_report_event(ryos->chrdev_minor, data);
+
+       return 0;
+}
+
+static const struct hid_device_id ryos_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_GLOW) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_RYOS_MK_PRO) },
+       { }
+};
+
+MODULE_DEVICE_TABLE(hid, ryos_devices);
+
+static struct hid_driver ryos_driver = {
+               .name = "ryos",
+               .id_table = ryos_devices,
+               .probe = ryos_probe,
+               .remove = ryos_remove,
+               .raw_event = ryos_raw_event
+};
+
+static int __init ryos_init(void)
+{
+       int retval;
+
+       ryos_class = class_create(THIS_MODULE, "ryos");
+       if (IS_ERR(ryos_class))
+               return PTR_ERR(ryos_class);
+       ryos_class->dev_groups = ryos_groups;
+
+       retval = hid_register_driver(&ryos_driver);
+       if (retval)
+               class_destroy(ryos_class);
+       return retval;
+}
+
+static void __exit ryos_exit(void)
+{
+       hid_unregister_driver(&ryos_driver);
+       class_destroy(ryos_class);
+}
+
+module_init(ryos_init);
+module_exit(ryos_exit);
+
+MODULE_AUTHOR("Stefan Achatz");
+MODULE_DESCRIPTION("USB Roccat Ryos MK/Glow/Pro driver");
+MODULE_LICENSE("GPL v2");
index 0332267199d5bd058becaf8c2d295628e0ba29ac..6dbf6e04dce75c82dd32109d46b330d5a60cd043 100644 (file)
 
 static struct class *savu_class;
 
-static ssize_t savu_sysfs_read(struct file *fp, struct kobject *kobj,
-               char *buf, loff_t off, size_t count,
-               size_t real_size, uint command)
-{
-       struct device *dev =
-                       container_of(kobj, struct device, kobj)->parent->parent;
-       struct savu_device *savu = hid_get_drvdata(dev_get_drvdata(dev));
-       struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
-       int retval;
-
-       if (off >= real_size)
-               return 0;
-
-       if (off != 0 || count != real_size)
-               return -EINVAL;
-
-       mutex_lock(&savu->savu_lock);
-       retval = roccat_common2_receive(usb_dev, command, buf, real_size);
-       mutex_unlock(&savu->savu_lock);
-
-       return retval ? retval : real_size;
-}
-
-static ssize_t savu_sysfs_write(struct file *fp, struct kobject *kobj,
-               void const *buf, loff_t off, size_t count,
-               size_t real_size, uint command)
-{
-       struct device *dev =
-                       container_of(kobj, struct device, kobj)->parent->parent;
-       struct savu_device *savu = hid_get_drvdata(dev_get_drvdata(dev));
-       struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
-       int retval;
-
-       if (off != 0 || count != real_size)
-               return -EINVAL;
-
-       mutex_lock(&savu->savu_lock);
-       retval = roccat_common2_send_with_status(usb_dev, command,
-                       (void *)buf, real_size);
-       mutex_unlock(&savu->savu_lock);
-
-       return retval ? retval : real_size;
-}
-
-#define SAVU_SYSFS_W(thingy, THINGY) \
-static ssize_t savu_sysfs_write_ ## thingy(struct file *fp, \
-               struct kobject *kobj, struct bin_attribute *attr, char *buf, \
-               loff_t off, size_t count) \
-{ \
-       return savu_sysfs_write(fp, kobj, buf, off, count, \
-                       SAVU_SIZE_ ## THINGY, SAVU_COMMAND_ ## THINGY); \
-}
-
-#define SAVU_SYSFS_R(thingy, THINGY) \
-static ssize_t savu_sysfs_read_ ## thingy(struct file *fp, \
-               struct kobject *kobj, struct bin_attribute *attr, char *buf, \
-               loff_t off, size_t count) \
-{ \
-       return savu_sysfs_read(fp, kobj, buf, off, count, \
-                       SAVU_SIZE_ ## THINGY, SAVU_COMMAND_ ## THINGY); \
-}
-
-#define SAVU_SYSFS_RW(thingy, THINGY) \
-SAVU_SYSFS_W(thingy, THINGY) \
-SAVU_SYSFS_R(thingy, THINGY)
-
-#define SAVU_BIN_ATTRIBUTE_RW(thingy, THINGY) \
-SAVU_SYSFS_RW(thingy, THINGY); \
-static struct bin_attribute bin_attr_##thingy = { \
-       .attr = { .name = #thingy, .mode = 0660 }, \
-       .size = SAVU_SIZE_ ## THINGY, \
-       .read = savu_sysfs_read_ ## thingy, \
-       .write = savu_sysfs_write_ ## thingy \
-}
-
-#define SAVU_BIN_ATTRIBUTE_W(thingy, THINGY) \
-SAVU_SYSFS_W(thingy, THINGY); \
-static struct bin_attribute bin_attr_##thingy = { \
-       .attr = { .name = #thingy, .mode = 0220 }, \
-       .size = SAVU_SIZE_ ## THINGY, \
-       .write = savu_sysfs_write_ ## thingy \
-}
-
-SAVU_BIN_ATTRIBUTE_W(control, CONTROL);
-SAVU_BIN_ATTRIBUTE_RW(profile, PROFILE);
-SAVU_BIN_ATTRIBUTE_RW(general, GENERAL);
-SAVU_BIN_ATTRIBUTE_RW(buttons, BUTTONS);
-SAVU_BIN_ATTRIBUTE_RW(macro, MACRO);
-SAVU_BIN_ATTRIBUTE_RW(info, INFO);
-SAVU_BIN_ATTRIBUTE_RW(sensor, SENSOR);
-
-static struct bin_attribute *savu_bin_attributes[] = {
+ROCCAT_COMMON2_BIN_ATTRIBUTE_W(control, 0x4, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(profile, 0x5, 0x03);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(general, 0x6, 0x10);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(buttons, 0x7, 0x2f);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(macro, 0x8, 0x0823);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(info, 0x9, 0x08);
+ROCCAT_COMMON2_BIN_ATTRIBUTE_RW(sensor, 0xc, 0x04);
+
+static struct bin_attribute *savu_bin_attrs[] = {
        &bin_attr_control,
        &bin_attr_profile,
        &bin_attr_general,
@@ -130,7 +47,7 @@ static struct bin_attribute *savu_bin_attributes[] = {
 };
 
 static const struct attribute_group savu_group = {
-       .bin_attrs = savu_bin_attributes,
+       .bin_attrs = savu_bin_attrs,
 };
 
 static const struct attribute_group *savu_groups[] = {
@@ -138,19 +55,11 @@ static const struct attribute_group *savu_groups[] = {
        NULL,
 };
 
-static int savu_init_savu_device_struct(struct usb_device *usb_dev,
-               struct savu_device *savu)
-{
-       mutex_init(&savu->savu_lock);
-
-       return 0;
-}
-
 static int savu_init_specials(struct hid_device *hdev)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
        struct usb_device *usb_dev = interface_to_usbdev(intf);
-       struct savu_device *savu;
+       struct roccat_common2_device *savu;
        int retval;
 
        if (intf->cur_altsetting->desc.bInterfaceProtocol
@@ -166,9 +75,9 @@ static int savu_init_specials(struct hid_device *hdev)
        }
        hid_set_drvdata(hdev, savu);
 
-       retval = savu_init_savu_device_struct(usb_dev, savu);
+       retval = roccat_common2_device_init_struct(usb_dev, savu);
        if (retval) {
-               hid_err(hdev, "couldn't init struct savu_device\n");
+               hid_err(hdev, "couldn't init Savu device\n");
                goto exit_free;
        }
 
@@ -190,7 +99,7 @@ exit_free:
 static void savu_remove_specials(struct hid_device *hdev)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
-       struct savu_device *savu;
+       struct roccat_common2_device *savu;
 
        if (intf->cur_altsetting->desc.bInterfaceProtocol
                        != USB_INTERFACE_PROTOCOL_MOUSE)
@@ -239,7 +148,7 @@ static void savu_remove(struct hid_device *hdev)
        hid_hw_stop(hdev);
 }
 
-static void savu_report_to_chrdev(struct savu_device const *savu,
+static void savu_report_to_chrdev(struct roccat_common2_device const *savu,
                u8 const *data)
 {
        struct savu_roccat_report roccat_report;
@@ -261,7 +170,7 @@ static int savu_raw_event(struct hid_device *hdev,
                struct hid_report *report, u8 *data, int size)
 {
        struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
-       struct savu_device *savu = hid_get_drvdata(hdev);
+       struct roccat_common2_device *savu = hid_get_drvdata(hdev);
 
        if (intf->cur_altsetting->desc.bInterfaceProtocol
                        != USB_INTERFACE_PROTOCOL_MOUSE)
index 9120ba72087f7d7e024dce882a1013e9646cb01b..d23217bd2b868aa437d726cfe13754d0c167cfee 100644 (file)
 
 #include <linux/types.h>
 
-enum {
-       SAVU_SIZE_CONTROL = 0x03,
-       SAVU_SIZE_PROFILE = 0x03,
-       SAVU_SIZE_GENERAL = 0x10,
-       SAVU_SIZE_BUTTONS = 0x2f,
-       SAVU_SIZE_MACRO = 0x0823,
-       SAVU_SIZE_INFO = 0x08,
-       SAVU_SIZE_SENSOR = 0x04,
-};
-
-enum savu_control_requests {
-       SAVU_CONTROL_REQUEST_GENERAL = 0x80,
-       SAVU_CONTROL_REQUEST_BUTTONS = 0x90,
-};
-
-enum savu_commands {
-       SAVU_COMMAND_CONTROL = 0x4,
-       SAVU_COMMAND_PROFILE = 0x5,
-       SAVU_COMMAND_GENERAL = 0x6,
-       SAVU_COMMAND_BUTTONS = 0x7,
-       SAVU_COMMAND_MACRO = 0x8,
-       SAVU_COMMAND_INFO = 0x9,
-       SAVU_COMMAND_SENSOR = 0xc,
-};
-
 struct savu_mouse_report_special {
        uint8_t report_number; /* always 3 */
        uint8_t zero;
@@ -77,11 +52,4 @@ struct savu_roccat_report {
        uint8_t data[2];
 } __packed;
 
-struct savu_device {
-       int roccat_claimed;
-       int chrdev_minor;
-
-       struct mutex savu_lock;
-};
-
 #endif
index 88fc5aefcd964b2f8b6c83476ca7d308066069f1..a184e1921c11190ffce1033e5b7d4f512d55f798 100644 (file)
@@ -326,7 +326,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
                                field->logical == attr_usage_id) {
                                sensor_hub_fill_attr_info(info, i, report->id,
                                        field->unit, field->unit_exponent,
-                                       field->report_size);
+                                       field->report_size *
+                                                       field->report_count);
                                ret = 0;
                        } else {
                                for (j = 0; j < field->maxusage; ++j) {
@@ -338,7 +339,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
                                                        i, report->id,
                                                        field->unit,
                                                        field->unit_exponent,
-                                                       field->report_size);
+                                                       field->report_size *
+                                                       field->report_count);
                                                ret = 0;
                                                break;
                                        }
@@ -425,9 +427,10 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
                hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
                                i, report->field[i]->usage->collection_index,
                                report->field[i]->usage->hid,
-                               report->field[i]->report_size/8);
-
-               sz = report->field[i]->report_size/8;
+                               (report->field[i]->report_size *
+                                       report->field[i]->report_count)/8);
+               sz = (report->field[i]->report_size *
+                                       report->field[i]->report_count)/8;
                if (pdata->pending.status && pdata->pending.attr_usage_id ==
                                report->field[i]->usage->hid) {
                        hid_dbg(hdev, "data was pending ...\n");
index b18320db5f7d18cba708ecd306ee3f394abebddb..da551d11376257a328419e22ad7cd487784bea51 100644 (file)
@@ -419,21 +419,14 @@ static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf,
  */
 static int sixaxis_set_operational_usb(struct hid_device *hdev)
 {
-       struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
-       struct usb_device *dev = interface_to_usbdev(intf);
-       __u16 ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
        int ret;
        char *buf = kmalloc(18, GFP_KERNEL);
 
        if (!buf)
                return -ENOMEM;
 
-       ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-                                HID_REQ_GET_REPORT,
-                                USB_DIR_IN | USB_TYPE_CLASS |
-                                USB_RECIP_INTERFACE,
-                                (3 << 8) | 0xf2, ifnum, buf, 17,
-                                USB_CTRL_GET_TIMEOUT);
+       ret = hdev->hid_get_raw_report(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT);
+
        if (ret < 0)
                hid_err(hdev, "can't set operational mode\n");
 
@@ -621,6 +614,54 @@ static void buzz_remove(struct hid_device *hdev)
        drv_data->extra = NULL;
 }
 
+#ifdef CONFIG_SONY_FF
+static int sony_play_effect(struct input_dev *dev, void *data,
+                           struct ff_effect *effect)
+{
+       unsigned char buf[] = {
+               0x01,
+               0x00, 0xff, 0x00, 0xff, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x03,
+               0xff, 0x27, 0x10, 0x00, 0x32,
+               0xff, 0x27, 0x10, 0x00, 0x32,
+               0xff, 0x27, 0x10, 0x00, 0x32,
+               0xff, 0x27, 0x10, 0x00, 0x32,
+               0x00, 0x00, 0x00, 0x00, 0x00
+       };
+       __u8 left;
+       __u8 right;
+       struct hid_device *hid = input_get_drvdata(dev);
+
+       if (effect->type != FF_RUMBLE)
+               return 0;
+
+       left = effect->u.rumble.strong_magnitude / 256;
+       right = effect->u.rumble.weak_magnitude ? 1 : 0;
+
+       buf[3] = right;
+       buf[5] = left;
+
+       return hid->hid_output_raw_report(hid, buf, sizeof(buf),
+                                         HID_OUTPUT_REPORT);
+}
+
+static int sony_init_ff(struct hid_device *hdev)
+{
+       struct hid_input *hidinput = list_entry(hdev->inputs.next,
+                                               struct hid_input, list);
+       struct input_dev *input_dev = hidinput->input;
+
+       input_set_capability(input_dev, EV_FF, FF_RUMBLE);
+       return input_ff_create_memless(input_dev, NULL, sony_play_effect);
+}
+
+#else
+static int sony_init_ff(struct hid_device *hdev)
+{
+       return 0;
+}
+#endif
+
 static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
 {
        int ret;
@@ -670,6 +711,10 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
        if (ret < 0)
                goto err_stop;
 
+       ret = sony_init_ff(hdev);
+       if (ret < 0)
+               goto err_stop;
+
        return 0;
 err_stop:
        hid_hw_stop(hdev);
index 71adf9e60b13f4aafa22ba94183bb4dcb8a3a21d..6b61f01e01e7fad839f8dd960050596a26a9abfe 100644 (file)
@@ -1655,10 +1655,39 @@ static void wiimod_pro_in_ext(struct wiimote_data *wdata, const __u8 *ext)
        ly = (ext[4] & 0xff) | ((ext[5] & 0x0f) << 8);
        ry = (ext[6] & 0xff) | ((ext[7] & 0x0f) << 8);
 
-       input_report_abs(wdata->extension.input, ABS_X, lx - 0x800);
-       input_report_abs(wdata->extension.input, ABS_Y, ly - 0x800);
-       input_report_abs(wdata->extension.input, ABS_RX, rx - 0x800);
-       input_report_abs(wdata->extension.input, ABS_RY, ry - 0x800);
+       /* zero-point offsets */
+       lx -= 0x800;
+       ly = 0x800 - ly;
+       rx -= 0x800;
+       ry = 0x800 - ry;
+
+       /* Trivial automatic calibration. We don't know any calibration data
+        * in the EEPROM so we must use the first report to calibrate the
+        * null-position of the analog sticks. Users can retrigger calibration
+        * via sysfs, or set it explicitly. If data is off more than abs(500),
+        * we skip calibration as the sticks are likely to be moved already. */
+       if (!(wdata->state.flags & WIIPROTO_FLAG_PRO_CALIB_DONE)) {
+               wdata->state.flags |= WIIPROTO_FLAG_PRO_CALIB_DONE;
+               if (abs(lx) < 500)
+                       wdata->state.calib_pro_sticks[0] = -lx;
+               if (abs(ly) < 500)
+                       wdata->state.calib_pro_sticks[1] = -ly;
+               if (abs(rx) < 500)
+                       wdata->state.calib_pro_sticks[2] = -rx;
+               if (abs(ry) < 500)
+                       wdata->state.calib_pro_sticks[3] = -ry;
+       }
+
+       /* apply calibration data */
+       lx += wdata->state.calib_pro_sticks[0];
+       ly += wdata->state.calib_pro_sticks[1];
+       rx += wdata->state.calib_pro_sticks[2];
+       ry += wdata->state.calib_pro_sticks[3];
+
+       input_report_abs(wdata->extension.input, ABS_X, lx);
+       input_report_abs(wdata->extension.input, ABS_Y, ly);
+       input_report_abs(wdata->extension.input, ABS_RX, rx);
+       input_report_abs(wdata->extension.input, ABS_RY, ry);
 
        input_report_key(wdata->extension.input,
                         wiimod_pro_map[WIIMOD_PRO_KEY_RIGHT],
@@ -1766,12 +1795,70 @@ static int wiimod_pro_play(struct input_dev *dev, void *data,
        return 0;
 }
 
+static ssize_t wiimod_pro_calib_show(struct device *dev,
+                                    struct device_attribute *attr,
+                                    char *out)
+{
+       struct wiimote_data *wdata = dev_to_wii(dev);
+       int r;
+
+       r = 0;
+       r += sprintf(&out[r], "%+06hd:", wdata->state.calib_pro_sticks[0]);
+       r += sprintf(&out[r], "%+06hd ", wdata->state.calib_pro_sticks[1]);
+       r += sprintf(&out[r], "%+06hd:", wdata->state.calib_pro_sticks[2]);
+       r += sprintf(&out[r], "%+06hd\n", wdata->state.calib_pro_sticks[3]);
+
+       return r;
+}
+
+static ssize_t wiimod_pro_calib_store(struct device *dev,
+                                     struct device_attribute *attr,
+                                     const char *buf, size_t count)
+{
+       struct wiimote_data *wdata = dev_to_wii(dev);
+       int r;
+       s16 x1, y1, x2, y2;
+
+       if (!strncmp(buf, "scan\n", 5)) {
+               spin_lock_irq(&wdata->state.lock);
+               wdata->state.flags &= ~WIIPROTO_FLAG_PRO_CALIB_DONE;
+               spin_unlock_irq(&wdata->state.lock);
+       } else {
+               r = sscanf(buf, "%hd:%hd %hd:%hd", &x1, &y1, &x2, &y2);
+               if (r != 4)
+                       return -EINVAL;
+
+               spin_lock_irq(&wdata->state.lock);
+               wdata->state.flags |= WIIPROTO_FLAG_PRO_CALIB_DONE;
+               spin_unlock_irq(&wdata->state.lock);
+
+               wdata->state.calib_pro_sticks[0] = x1;
+               wdata->state.calib_pro_sticks[1] = y1;
+               wdata->state.calib_pro_sticks[2] = x2;
+               wdata->state.calib_pro_sticks[3] = y2;
+       }
+
+       return strnlen(buf, PAGE_SIZE);
+}
+
+static DEVICE_ATTR(pro_calib, S_IRUGO|S_IWUSR|S_IWGRP, wiimod_pro_calib_show,
+                  wiimod_pro_calib_store);
+
 static int wiimod_pro_probe(const struct wiimod_ops *ops,
                            struct wiimote_data *wdata)
 {
        int ret, i;
+       unsigned long flags;
 
        INIT_WORK(&wdata->rumble_worker, wiimod_rumble_worker);
+       wdata->state.calib_pro_sticks[0] = 0;
+       wdata->state.calib_pro_sticks[1] = 0;
+       wdata->state.calib_pro_sticks[2] = 0;
+       wdata->state.calib_pro_sticks[3] = 0;
+
+       spin_lock_irqsave(&wdata->state.lock, flags);
+       wdata->state.flags &= ~WIIPROTO_FLAG_PRO_CALIB_DONE;
+       spin_unlock_irqrestore(&wdata->state.lock, flags);
 
        wdata->extension.input = input_allocate_device();
        if (!wdata->extension.input)
@@ -1786,6 +1873,13 @@ static int wiimod_pro_probe(const struct wiimod_ops *ops,
                goto err_free;
        }
 
+       ret = device_create_file(&wdata->hdev->dev,
+                                &dev_attr_pro_calib);
+       if (ret) {
+               hid_err(wdata->hdev, "cannot create sysfs attribute\n");
+               goto err_free;
+       }
+
        wdata->extension.input->open = wiimod_pro_open;
        wdata->extension.input->close = wiimod_pro_close;
        wdata->extension.input->dev.parent = &wdata->hdev->dev;
@@ -1806,20 +1900,23 @@ static int wiimod_pro_probe(const struct wiimod_ops *ops,
        set_bit(ABS_RX, wdata->extension.input->absbit);
        set_bit(ABS_RY, wdata->extension.input->absbit);
        input_set_abs_params(wdata->extension.input,
-                            ABS_X, -0x800, 0x800, 2, 4);
+                            ABS_X, -0x400, 0x400, 4, 100);
        input_set_abs_params(wdata->extension.input,
-                            ABS_Y, -0x800, 0x800, 2, 4);
+                            ABS_Y, -0x400, 0x400, 4, 100);
        input_set_abs_params(wdata->extension.input,
-                            ABS_RX, -0x800, 0x800, 2, 4);
+                            ABS_RX, -0x400, 0x400, 4, 100);
        input_set_abs_params(wdata->extension.input,
-                            ABS_RY, -0x800, 0x800, 2, 4);
+                            ABS_RY, -0x400, 0x400, 4, 100);
 
        ret = input_register_device(wdata->extension.input);
        if (ret)
-               goto err_free;
+               goto err_file;
 
        return 0;
 
+err_file:
+       device_remove_file(&wdata->hdev->dev,
+                          &dev_attr_pro_calib);
 err_free:
        input_free_device(wdata->extension.input);
        wdata->extension.input = NULL;
@@ -1837,6 +1934,8 @@ static void wiimod_pro_remove(const struct wiimod_ops *ops,
        input_unregister_device(wdata->extension.input);
        wdata->extension.input = NULL;
        cancel_work_sync(&wdata->rumble_worker);
+       device_remove_file(&wdata->hdev->dev,
+                          &dev_attr_pro_calib);
 
        spin_lock_irqsave(&wdata->state.lock, flags);
        wiiproto_req_rumble(wdata, 0);
index cfa63b0825b056570e18c799e5f8b5c7ad77ed6c..10934aa129fbb7743d90dadbd540e9b164b14c38 100644 (file)
@@ -46,6 +46,7 @@
 #define WIIPROTO_FLAG_DRM_LOCKED       0x8000
 #define WIIPROTO_FLAG_BUILTIN_MP       0x010000
 #define WIIPROTO_FLAG_NO_MP            0x020000
+#define WIIPROTO_FLAG_PRO_CALIB_DONE   0x040000
 
 #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \
                                        WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4)
@@ -135,6 +136,7 @@ struct wiimote_state {
 
        /* calibration/cache data */
        __u16 calib_bboard[4][3];
+       __s16 calib_pro_sticks[4];
        __u8 cache_rumble;
 };
 
index fd7ce374f812ead7960b72a5d00ac3b5908ab221..5f7e55f4b7f052e29f754f78cabe8dd6a4593fb4 100644 (file)
@@ -454,10 +454,6 @@ static void i2c_hid_init_reports(struct hid_device *hid)
                return;
        }
 
-       list_for_each_entry(report,
-               &hid->report_enum[HID_INPUT_REPORT].report_list, list)
-               i2c_hid_init_report(report, inbuf, ihid->bufsize);
-
        list_for_each_entry(report,
                &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
                i2c_hid_init_report(report, inbuf, ihid->bufsize);
@@ -1012,7 +1008,7 @@ static int i2c_hid_probe(struct i2c_client *client,
        hid->hid_get_raw_report = i2c_hid_get_raw_report;
        hid->hid_output_raw_report = i2c_hid_output_raw_report;
        hid->dev.parent = &client->dev;
-       ACPI_HANDLE_SET(&hid->dev, ACPI_HANDLE(&client->dev));
+       ACPI_COMPANION_SET(&hid->dev, ACPI_COMPANION(&client->dev));
        hid->bus = BUS_I2C;
        hid->version = le16_to_cpu(ihid->hdesc.bcdVersion);
        hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID);
index 3fca3be08337d76fdd8ecaec09c3d1693b0ac4ef..0db9a67278ba21d3d574b3f209311d5f54fecbac 100644 (file)
@@ -84,6 +84,8 @@ static const struct hid_blacklist {
        { USB_VENDOR_ID_REALTEK, USB_DEVICE_ID_REALTEK_READER, HID_QUIRK_NO_INIT_REPORTS },
        { USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB, HID_QUIRK_NOGET },
        { USB_VENDOR_ID_SIGMATEL, USB_DEVICE_ID_SIGMATEL_STMP3780, HID_QUIRK_NOGET },
+       { USB_VENDOR_ID_SIS2_TOUCH, USB_DEVICE_ID_SIS9200_TOUCH, HID_QUIRK_NOGET },
+       { USB_VENDOR_ID_SIS2_TOUCH, USB_DEVICE_ID_SIS817_TOUCH, HID_QUIRK_NOGET },
        { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
        { USB_VENDOR_ID_SYMBOL, USB_DEVICE_ID_SYMBOL_SCANNER_1, HID_QUIRK_NOGET },
        { USB_VENDOR_ID_SYMBOL, USB_DEVICE_ID_SYMBOL_SCANNER_2, HID_QUIRK_NOGET },
index cdff74282955a9005fa2d8ea648866f21b59055c..4c4c1421bf28f66462d8d0bf5f2ee70947005ac0 100644 (file)
  * This driver also supports the G781 from GMT. This device is compatible
  * with the ADM1032.
  *
+ * This driver also supports TMP451 from Texas Instruments. This device is
+ * supported in both compatibility and extended mode. It's mostly compatible
+ * with ADT7461 except for local temperature low byte register and max
+ * conversion rate.
+ *
  * Since the LM90 was the first chipset supported by this driver, most
  * comments will refer to this chipset, but are actually general and
  * concern all supported chipsets, unless mentioned otherwise.
@@ -89,6 +94,8 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/interrupt.h>
+#include <linux/regulator/consumer.h>
 
 /*
  * Addresses to scan
@@ -110,7 +117,7 @@ static const unsigned short normal_i2c[] = {
        0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
 
 enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
-       max6646, w83l771, max6696, sa56004, g781 };
+       max6646, w83l771, max6696, sa56004, g781, tmp451 };
 
 /*
  * The LM90 registers
@@ -167,6 +174,9 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
 #define LM90_DEF_CONVRATE_RVAL 6       /* Def conversion rate register value */
 #define LM90_MAX_CONVRATE_MS   16000   /* Maximum conversion rate in ms */
 
+/* TMP451 registers */
+#define TMP451_REG_R_LOCAL_TEMPL       0x15
+
 /*
  * Device flags
  */
@@ -179,6 +189,23 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
 #define LM90_HAVE_TEMP3                (1 << 6) /* 3rd temperature sensor      */
 #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert                */
 
+/* LM90 status */
+#define LM90_STATUS_LTHRM      (1 << 0) /* local THERM limit tripped */
+#define LM90_STATUS_RTHRM      (1 << 1) /* remote THERM limit tripped */
+#define LM90_STATUS_ROPEN      (1 << 2) /* remote is an open circuit */
+#define LM90_STATUS_RLOW       (1 << 3) /* remote low temp limit tripped */
+#define LM90_STATUS_RHIGH      (1 << 4) /* remote high temp limit tripped */
+#define LM90_STATUS_LLOW       (1 << 5) /* local low temp limit tripped */
+#define LM90_STATUS_LHIGH      (1 << 6) /* local high temp limit tripped */
+
+#define MAX6696_STATUS2_R2THRM (1 << 1) /* remote2 THERM limit tripped */
+#define MAX6696_STATUS2_R2OPEN (1 << 2) /* remote2 is an open circuit */
+#define MAX6696_STATUS2_R2LOW  (1 << 3) /* remote2 low temp limit tripped */
+#define MAX6696_STATUS2_R2HIGH (1 << 4) /* remote2 high temp limit tripped */
+#define MAX6696_STATUS2_ROT2   (1 << 5) /* remote emergency limit tripped */
+#define MAX6696_STATUS2_R2OT2  (1 << 6) /* remote2 emergency limit tripped */
+#define MAX6696_STATUS2_LOT2   (1 << 7) /* local emergency limit tripped */
+
 /*
  * Driver data (common to all clients)
  */
@@ -205,6 +232,7 @@ static const struct i2c_device_id lm90_id[] = {
        { "nct1008", adt7461 },
        { "w83l771", w83l771 },
        { "sa56004", sa56004 },
+       { "tmp451", tmp451 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, lm90_id);
@@ -278,7 +306,7 @@ static const struct lm90_params lm90_params[] = {
        [max6696] = {
                .flags = LM90_HAVE_EMERGENCY
                  | LM90_HAVE_EMERGENCY_ALARM | LM90_HAVE_TEMP3,
-               .alert_alarms = 0x187c,
+               .alert_alarms = 0x1c7c,
                .max_convrate = 6,
                .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL,
        },
@@ -293,6 +321,43 @@ static const struct lm90_params lm90_params[] = {
                .max_convrate = 9,
                .reg_local_ext = SA56004_REG_R_LOCAL_TEMPL,
        },
+       [tmp451] = {
+               .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT
+                 | LM90_HAVE_BROKEN_ALERT,
+               .alert_alarms = 0x7c,
+               .max_convrate = 9,
+               .reg_local_ext = TMP451_REG_R_LOCAL_TEMPL,
+       }
+};
+
+/*
+ * TEMP8 register index
+ */
+enum lm90_temp8_reg_index {
+       LOCAL_LOW = 0,
+       LOCAL_HIGH,
+       LOCAL_CRIT,
+       REMOTE_CRIT,
+       LOCAL_EMERG,    /* max6659 and max6695/96 */
+       REMOTE_EMERG,   /* max6659 and max6695/96 */
+       REMOTE2_CRIT,   /* max6695/96 only */
+       REMOTE2_EMERG,  /* max6695/96 only */
+       TEMP8_REG_NUM
+};
+
+/*
+ * TEMP11 register index
+ */
+enum lm90_temp11_reg_index {
+       REMOTE_TEMP = 0,
+       REMOTE_LOW,
+       REMOTE_HIGH,
+       REMOTE_OFFSET,  /* except max6646, max6657/58/59, and max6695/96 */
+       LOCAL_TEMP,
+       REMOTE2_TEMP,   /* max6695/96 only */
+       REMOTE2_LOW,    /* max6695/96 only */
+       REMOTE2_HIGH,   /* max6695/96 only */
+       TEMP11_REG_NUM
 };
 
 /*
@@ -302,6 +367,7 @@ static const struct lm90_params lm90_params[] = {
 struct lm90_data {
        struct device *hwmon_dev;
        struct mutex update_lock;
+       struct regulator *regulator;
        char valid; /* zero until following fields are valid */
        unsigned long last_updated; /* in jiffies */
        int kind;
@@ -317,25 +383,8 @@ struct lm90_data {
        u8 reg_local_ext;       /* local extension register offset */
 
        /* registers values */
-       s8 temp8[8];    /* 0: local low limit
-                        * 1: local high limit
-                        * 2: local critical limit
-                        * 3: remote critical limit
-                        * 4: local emergency limit (max6659 and max6695/96)
-                        * 5: remote emergency limit (max6659 and max6695/96)
-                        * 6: remote 2 critical limit (max6695/96 only)
-                        * 7: remote 2 emergency limit (max6695/96 only)
-                        */
-       s16 temp11[8];  /* 0: remote input
-                        * 1: remote low limit
-                        * 2: remote high limit
-                        * 3: remote offset (except max6646, max6657/58/59,
-                        *                   and max6695/96)
-                        * 4: local input
-                        * 5: remote 2 input (max6695/96 only)
-                        * 6: remote 2 low limit (max6695/96 only)
-                        * 7: remote 2 high limit (max6695/96 only)
-                        */
+       s8 temp8[TEMP8_REG_NUM];
+       s16 temp11[TEMP11_REG_NUM];
        u8 temp_hyst;
        u16 alarms; /* bitvector (upper 8 bits for max6695/96) */
 };
@@ -477,37 +526,42 @@ static struct lm90_data *lm90_update_device(struct device *dev)
                u8 alarms;
 
                dev_dbg(&client->dev, "Updating lm90 data.\n");
-               lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]);
-               lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]);
-               lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]);
-               lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
+               lm90_read_reg(client, LM90_REG_R_LOCAL_LOW,
+                             &data->temp8[LOCAL_LOW]);
+               lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH,
+                             &data->temp8[LOCAL_HIGH]);
+               lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT,
+                             &data->temp8[LOCAL_CRIT]);
+               lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
+                             &data->temp8[REMOTE_CRIT]);
                lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
 
                if (data->reg_local_ext) {
                        lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
                                    data->reg_local_ext,
-                                   &data->temp11[4]);
+                                   &data->temp11[LOCAL_TEMP]);
                } else {
                        if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
                                          &h) == 0)
-                               data->temp11[4] = h << 8;
+                               data->temp11[LOCAL_TEMP] = h << 8;
                }
                lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
-                           LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]);
+                           LM90_REG_R_REMOTE_TEMPL,
+                           &data->temp11[REMOTE_TEMP]);
 
                if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
-                       data->temp11[1] = h << 8;
+                       data->temp11[REMOTE_LOW] = h << 8;
                        if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
                         && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
                                          &l) == 0)
-                               data->temp11[1] |= l;
+                               data->temp11[REMOTE_LOW] |= l;
                }
                if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
-                       data->temp11[2] = h << 8;
+                       data->temp11[REMOTE_HIGH] = h << 8;
                        if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
                         && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
                                          &l) == 0)
-                               data->temp11[2] |= l;
+                               data->temp11[REMOTE_HIGH] |= l;
                }
 
                if (data->flags & LM90_HAVE_OFFSET) {
@@ -515,13 +569,13 @@ static struct lm90_data *lm90_update_device(struct device *dev)
                                          &h) == 0
                         && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
                                          &l) == 0)
-                               data->temp11[3] = (h << 8) | l;
+                               data->temp11[REMOTE_OFFSET] = (h << 8) | l;
                }
                if (data->flags & LM90_HAVE_EMERGENCY) {
                        lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG,
-                                     &data->temp8[4]);
+                                     &data->temp8[LOCAL_EMERG]);
                        lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
-                                     &data->temp8[5]);
+                                     &data->temp8[REMOTE_EMERG]);
                }
                lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
                data->alarms = alarms;  /* save as 16 bit value */
@@ -529,15 +583,16 @@ static struct lm90_data *lm90_update_device(struct device *dev)
                if (data->kind == max6696) {
                        lm90_select_remote_channel(client, data, 1);
                        lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
-                                     &data->temp8[6]);
+                                     &data->temp8[REMOTE2_CRIT]);
                        lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
-                                     &data->temp8[7]);
+                                     &data->temp8[REMOTE2_EMERG]);
                        lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
-                                   LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]);
+                                   LM90_REG_R_REMOTE_TEMPL,
+                                   &data->temp11[REMOTE2_TEMP]);
                        if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h))
-                               data->temp11[6] = h << 8;
+                               data->temp11[REMOTE2_LOW] = h << 8;
                        if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h))
-                               data->temp11[7] = h << 8;
+                               data->temp11[REMOTE2_HIGH] = h << 8;
                        lm90_select_remote_channel(client, data, 0);
 
                        if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2,
@@ -709,7 +764,7 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
        struct lm90_data *data = lm90_update_device(dev);
        int temp;
 
-       if (data->kind == adt7461)
+       if (data->kind == adt7461 || data->kind == tmp451)
                temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
        else if (data->kind == max6646)
                temp = temp_from_u8(data->temp8[attr->index]);
@@ -726,7 +781,7 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
 static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
                         const char *buf, size_t count)
 {
-       static const u8 reg[8] = {
+       static const u8 reg[TEMP8_REG_NUM] = {
                LM90_REG_W_LOCAL_LOW,
                LM90_REG_W_LOCAL_HIGH,
                LM90_REG_W_LOCAL_CRIT,
@@ -753,7 +808,7 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
                val -= 16000;
 
        mutex_lock(&data->update_lock);
-       if (data->kind == adt7461)
+       if (data->kind == adt7461 || data->kind == tmp451)
                data->temp8[nr] = temp_to_u8_adt7461(data, val);
        else if (data->kind == max6646)
                data->temp8[nr] = temp_to_u8(val);
@@ -775,7 +830,7 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
        struct lm90_data *data = lm90_update_device(dev);
        int temp;
 
-       if (data->kind == adt7461)
+       if (data->kind == adt7461 || data->kind == tmp451)
                temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
        else if (data->kind == max6646)
                temp = temp_from_u16(data->temp11[attr->index]);
@@ -821,7 +876,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
                val -= 16000;
 
        mutex_lock(&data->update_lock);
-       if (data->kind == adt7461)
+       if (data->kind == adt7461 || data->kind == tmp451)
                data->temp11[index] = temp_to_u16_adt7461(data, val);
        else if (data->kind == max6646)
                data->temp11[index] = temp_to_u8(val) << 8;
@@ -850,7 +905,7 @@ static ssize_t show_temphyst(struct device *dev,
        struct lm90_data *data = lm90_update_device(dev);
        int temp;
 
-       if (data->kind == adt7461)
+       if (data->kind == adt7461 || data->kind == tmp451)
                temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
        else if (data->kind == max6646)
                temp = temp_from_u8(data->temp8[attr->index]);
@@ -878,12 +933,12 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
                return err;
 
        mutex_lock(&data->update_lock);
-       if (data->kind == adt7461)
-               temp = temp_from_u8_adt7461(data, data->temp8[2]);
+       if (data->kind == adt7461 || data->kind == tmp451)
+               temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]);
        else if (data->kind == max6646)
-               temp = temp_from_u8(data->temp8[2]);
+               temp = temp_from_u8(data->temp8[LOCAL_CRIT]);
        else
-               temp = temp_from_s8(data->temp8[2]);
+               temp = temp_from_s8(data->temp8[LOCAL_CRIT]);
 
        data->temp_hyst = hyst_to_reg(temp - val);
        i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
@@ -937,25 +992,28 @@ static ssize_t set_update_interval(struct device *dev,
        return count;
 }
 
-static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL, 0, 4);
-static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL, 0, 0);
+static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL,
+       0, LOCAL_TEMP);
+static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL,
+       0, REMOTE_TEMP);
 static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 0);
+       set_temp8, LOCAL_LOW);
 static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
-       set_temp11, 0, 1);
+       set_temp11, 0, REMOTE_LOW);
 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 1);
+       set_temp8, LOCAL_HIGH);
 static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
-       set_temp11, 1, 2);
+       set_temp11, 1, REMOTE_HIGH);
 static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 2);
+       set_temp8, LOCAL_CRIT);
 static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 3);
+       set_temp8, REMOTE_CRIT);
 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
-       set_temphyst, 2);
-static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3);
+       set_temphyst, LOCAL_CRIT);
+static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL,
+       REMOTE_CRIT);
 static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
-       set_temp11, 2, 3);
+       set_temp11, 2, REMOTE_OFFSET);
 
 /* Individual alarm files */
 static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
@@ -1003,13 +1061,13 @@ static const struct attribute_group lm90_group = {
  * Additional attributes for devices with emergency sensors
  */
 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 4);
+       set_temp8, LOCAL_EMERG);
 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 5);
+       set_temp8, REMOTE_EMERG);
 static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO, show_temphyst,
-                         NULL, 4);
+                         NULL, LOCAL_EMERG);
 static SENSOR_DEVICE_ATTR(temp2_emergency_hyst, S_IRUGO, show_temphyst,
-                         NULL, 5);
+                         NULL, REMOTE_EMERG);
 
 static struct attribute *lm90_emergency_attributes[] = {
        &sensor_dev_attr_temp1_emergency.dev_attr.attr,
@@ -1039,18 +1097,20 @@ static const struct attribute_group lm90_emergency_alarm_group = {
 /*
  * Additional attributes for devices with 3 temperature sensors
  */
-static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL, 0, 5);
+static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL,
+       0, REMOTE2_TEMP);
 static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp11,
-       set_temp11, 3, 6);
+       set_temp11, 3, REMOTE2_LOW);
 static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp11,
-       set_temp11, 4, 7);
+       set_temp11, 4, REMOTE2_HIGH);
 static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 6);
-static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL, 6);
+       set_temp8, REMOTE2_CRIT);
+static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL,
+       REMOTE2_CRIT);
 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IWUSR | S_IRUGO, show_temp8,
-       set_temp8, 7);
+       set_temp8, REMOTE2_EMERG);
 static SENSOR_DEVICE_ATTR(temp3_emergency_hyst, S_IRUGO, show_temphyst,
-                         NULL, 7);
+                         NULL, REMOTE2_EMERG);
 
 static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
 static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 10);
@@ -1306,6 +1366,19 @@ static int lm90_detect(struct i2c_client *client,
                 && (config1 & 0x3F) == 0x00
                 && convrate <= 0x08)
                        name = "g781";
+       } else
+       if (address == 0x4C
+        && man_id == 0x55) { /* Texas Instruments */
+               int local_ext;
+
+               local_ext = i2c_smbus_read_byte_data(client,
+                                                    TMP451_REG_R_LOCAL_TEMPL);
+
+               if (chip_id == 0x00 /* TMP451 */
+                && (config1 & 0x1B) == 0x00
+                && convrate <= 0x09
+                && (local_ext & 0x0F) == 0x00)
+                       name = "tmp451";
        }
 
        if (!name) { /* identification failed */
@@ -1367,7 +1440,7 @@ static void lm90_init_client(struct i2c_client *client)
        data->config_orig = config;
 
        /* Check Temperature Range Select */
-       if (data->kind == adt7461) {
+       if (data->kind == adt7461 || data->kind == tmp451) {
                if (config & 0x04)
                        data->flags |= LM90_FLAG_ADT7461_EXT;
        }
@@ -1391,14 +1464,74 @@ static void lm90_init_client(struct i2c_client *client)
                i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
 }
 
+static bool lm90_is_tripped(struct i2c_client *client, u16 *status)
+{
+       struct lm90_data *data = i2c_get_clientdata(client);
+       u8 st, st2 = 0;
+
+       lm90_read_reg(client, LM90_REG_R_STATUS, &st);
+
+       if (data->kind == max6696)
+               lm90_read_reg(client, MAX6696_REG_R_STATUS2, &st2);
+
+       *status = st | (st2 << 8);
+
+       if ((st & 0x7f) == 0 && (st2 & 0xfe) == 0)
+               return false;
+
+       if ((st & (LM90_STATUS_LLOW | LM90_STATUS_LHIGH | LM90_STATUS_LTHRM)) ||
+           (st2 & MAX6696_STATUS2_LOT2))
+               dev_warn(&client->dev,
+                        "temp%d out of range, please check!\n", 1);
+       if ((st & (LM90_STATUS_RLOW | LM90_STATUS_RHIGH | LM90_STATUS_RTHRM)) ||
+           (st2 & MAX6696_STATUS2_ROT2))
+               dev_warn(&client->dev,
+                        "temp%d out of range, please check!\n", 2);
+       if (st & LM90_STATUS_ROPEN)
+               dev_warn(&client->dev,
+                        "temp%d diode open, please check!\n", 2);
+       if (st2 & (MAX6696_STATUS2_R2LOW | MAX6696_STATUS2_R2HIGH |
+                  MAX6696_STATUS2_R2THRM | MAX6696_STATUS2_R2OT2))
+               dev_warn(&client->dev,
+                        "temp%d out of range, please check!\n", 3);
+       if (st2 & MAX6696_STATUS2_R2OPEN)
+               dev_warn(&client->dev,
+                        "temp%d diode open, please check!\n", 3);
+
+       return true;
+}
+
+static irqreturn_t lm90_irq_thread(int irq, void *dev_id)
+{
+       struct i2c_client *client = dev_id;
+       u16 status;
+
+       if (lm90_is_tripped(client, &status))
+               return IRQ_HANDLED;
+       else
+               return IRQ_NONE;
+}
+
 static int lm90_probe(struct i2c_client *client,
                      const struct i2c_device_id *id)
 {
        struct device *dev = &client->dev;
        struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
        struct lm90_data *data;
+       struct regulator *regulator;
        int err;
 
+       regulator = devm_regulator_get(dev, "vcc");
+       if (IS_ERR(regulator))
+               return PTR_ERR(regulator);
+
+       err = regulator_enable(regulator);
+       if (err < 0) {
+               dev_err(&client->dev,
+                       "Failed to enable regulator: %d\n", err);
+               return err;
+       }
+
        data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
@@ -1406,6 +1539,8 @@ static int lm90_probe(struct i2c_client *client,
        i2c_set_clientdata(client, data);
        mutex_init(&data->update_lock);
 
+       data->regulator = regulator;
+
        /* Set the device type */
        data->kind = id->driver_data;
        if (data->kind == adm1032) {
@@ -1467,12 +1602,26 @@ static int lm90_probe(struct i2c_client *client,
                goto exit_remove_files;
        }
 
+       if (client->irq) {
+               dev_dbg(dev, "IRQ: %d\n", client->irq);
+               err = devm_request_threaded_irq(dev, client->irq,
+                                               NULL, lm90_irq_thread,
+                                               IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+                                               "lm90", client);
+               if (err < 0) {
+                       dev_err(dev, "cannot request IRQ %d\n", client->irq);
+                       goto exit_remove_files;
+               }
+       }
+
        return 0;
 
 exit_remove_files:
        lm90_remove_files(client, data);
 exit_restore:
        lm90_restore_conf(client, data);
+       regulator_disable(data->regulator);
+
        return err;
 }
 
@@ -1483,49 +1632,33 @@ static int lm90_remove(struct i2c_client *client)
        hwmon_device_unregister(data->hwmon_dev);
        lm90_remove_files(client, data);
        lm90_restore_conf(client, data);
+       regulator_disable(data->regulator);
 
        return 0;
 }
 
 static void lm90_alert(struct i2c_client *client, unsigned int flag)
 {
-       struct lm90_data *data = i2c_get_clientdata(client);
-       u8 config, alarms, alarms2 = 0;
-
-       lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
-
-       if (data->kind == max6696)
-               lm90_read_reg(client, MAX6696_REG_R_STATUS2, &alarms2);
-
-       if ((alarms & 0x7f) == 0 && (alarms2 & 0xfe) == 0) {
-               dev_info(&client->dev, "Everything OK\n");
-       } else {
-               if (alarms & 0x61)
-                       dev_warn(&client->dev,
-                                "temp%d out of range, please check!\n", 1);
-               if (alarms & 0x1a)
-                       dev_warn(&client->dev,
-                                "temp%d out of range, please check!\n", 2);
-               if (alarms & 0x04)
-                       dev_warn(&client->dev,
-                                "temp%d diode open, please check!\n", 2);
-
-               if (alarms2 & 0x18)
-                       dev_warn(&client->dev,
-                                "temp%d out of range, please check!\n", 3);
+       u16 alarms;
 
+       if (lm90_is_tripped(client, &alarms)) {
                /*
                 * Disable ALERT# output, because these chips don't implement
                 * SMBus alert correctly; they should only hold the alert line
                 * low briefly.
                 */
+               struct lm90_data *data = i2c_get_clientdata(client);
+
                if ((data->flags & LM90_HAVE_BROKEN_ALERT)
                 && (alarms & data->alert_alarms)) {
+                       u8 config;
                        dev_dbg(&client->dev, "Disabling ALERT#\n");
                        lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
                        i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
                                                  config | 0x80);
                }
+       } else {
+               dev_info(&client->dev, "Everything OK\n");
        }
 }
 
index cdcbd8368ed344d205d7edb2edcdfe90919fd42f..3b26129f605587eeead9193d7d3eb06157bce622 100644 (file)
@@ -109,6 +109,7 @@ config I2C_I801
            Avoton (SOC)
            Wellsburg (PCH)
            Coleto Creek (PCH)
+           Wildcat Point-LP (PCH)
 
          This driver can also be built as a module.  If so, the module
          will be called i2c-i801.
@@ -345,6 +346,16 @@ config I2C_BCM2835
          This support is also available as a module.  If so, the module
          will be called i2c-bcm2835.
 
+config I2C_BCM_KONA
+       tristate "BCM Kona I2C adapter"
+       depends on ARCH_BCM_MOBILE
+       default y
+       help
+         If you say yes to this option, support will be included for the
+         I2C interface on the Broadcom Kona family of processors.
+
+         If you do not need KONA I2C inteface, say N.
+
 config I2C_BLACKFIN_TWI
        tristate "Blackfin TWI I2C support"
        depends on BLACKFIN
@@ -436,6 +447,13 @@ config I2C_EG20T
          ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series.
          ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH.
 
+config I2C_EXYNOS5
+       tristate "Exynos5 high-speed I2C driver"
+       depends on ARCH_EXYNOS5 && OF
+       help
+         Say Y here to include support for high-speed I2C controller in the
+         Exynos5 based Samsung SoCs.
+
 config I2C_GPIO
        tristate "GPIO-based bitbanging I2C"
        depends on GPIOLIB
@@ -665,7 +683,7 @@ config I2C_SH7760
 
 config I2C_SH_MOBILE
        tristate "SuperH Mobile I2C Controller"
-       depends on SUPERH || ARCH_SHMOBILE
+       depends on SUPERH || ARM || COMPILE_TEST
        help
          If you say yes to this option, support will be included for the
          built-in I2C interface on the Renesas SH-Mobile processor.
@@ -695,6 +713,16 @@ config I2C_SIRF
          This driver can also be built as a module.  If so, the module
          will be called i2c-sirf.
 
+config I2C_ST
+       tristate "STMicroelectronics SSC I2C support"
+       depends on ARCH_STI
+       help
+         Enable this option to add support for STMicroelectronics SoCs
+         hardware SSC (Synchronous Serial Controller) as an I2C controller.
+
+         This driver can also be built as module. If so, the module
+         will be called i2c-st.
+
 config I2C_STU300
        tristate "ST Microelectronics DDC I2C interface"
        depends on MACH_U300
@@ -768,7 +796,7 @@ config I2C_XLR
 
 config I2C_RCAR
        tristate "Renesas R-Car I2C Controller"
-       depends on ARCH_SHMOBILE && I2C
+       depends on ARM || COMPILE_TEST
        help
          If you say yes to this option, support will be included for the
          R-Car I2C controller.
index d00997f3eb3bc650e172d7addb5a83552db8936e..c73eb0ea788e6dde96604b1e8e4401bc087eef8f 100644 (file)
@@ -42,6 +42,7 @@ i2c-designware-platform-objs := i2c-designware-platdrv.o
 obj-$(CONFIG_I2C_DESIGNWARE_PCI)       += i2c-designware-pci.o
 i2c-designware-pci-objs := i2c-designware-pcidrv.o
 obj-$(CONFIG_I2C_EG20T)                += i2c-eg20t.o
+obj-$(CONFIG_I2C_EXYNOS5)      += i2c-exynos5.o
 obj-$(CONFIG_I2C_GPIO)         += i2c-gpio.o
 obj-$(CONFIG_I2C_HIGHLANDER)   += i2c-highlander.o
 obj-$(CONFIG_I2C_IBM_IIC)      += i2c-ibm_iic.o
@@ -68,6 +69,7 @@ obj-$(CONFIG_I2C_SH7760)      += i2c-sh7760.o
 obj-$(CONFIG_I2C_SH_MOBILE)    += i2c-sh_mobile.o
 obj-$(CONFIG_I2C_SIMTEC)       += i2c-simtec.o
 obj-$(CONFIG_I2C_SIRF)         += i2c-sirf.o
+obj-$(CONFIG_I2C_ST)           += i2c-st.o
 obj-$(CONFIG_I2C_STU300)       += i2c-stu300.o
 obj-$(CONFIG_I2C_TEGRA)                += i2c-tegra.o
 obj-$(CONFIG_I2C_VERSATILE)    += i2c-versatile.o
@@ -87,6 +89,7 @@ obj-$(CONFIG_I2C_VIPERBOARD)  += i2c-viperboard.o
 
 # Other I2C/SMBus bus drivers
 obj-$(CONFIG_I2C_ACORN)                += i2c-acorn.o
+obj-$(CONFIG_I2C_BCM_KONA)     += i2c-bcm-kona.o
 obj-$(CONFIG_I2C_ELEKTOR)      += i2c-elektor.o
 obj-$(CONFIG_I2C_PCA_ISA)      += i2c-pca-isa.o
 obj-$(CONFIG_I2C_SIBYTE)       += i2c-sibyte.o
diff --git a/drivers/i2c/busses/i2c-bcm-kona.c b/drivers/i2c/busses/i2c-bcm-kona.c
new file mode 100644 (file)
index 0000000..036cf03
--- /dev/null
@@ -0,0 +1,909 @@
+/*
+ * Copyright (C) 2013 Broadcom Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/slab.h>
+
+/* Hardware register offsets and field defintions */
+#define CS_OFFSET                              0x00000020
+#define CS_ACK_SHIFT                           3
+#define CS_ACK_MASK                            0x00000008
+#define CS_ACK_CMD_GEN_START                   0x00000000
+#define CS_ACK_CMD_GEN_RESTART                 0x00000001
+#define CS_CMD_SHIFT                           1
+#define CS_CMD_CMD_NO_ACTION                   0x00000000
+#define CS_CMD_CMD_START_RESTART               0x00000001
+#define CS_CMD_CMD_STOP                                0x00000002
+#define CS_EN_SHIFT                            0
+#define CS_EN_CMD_ENABLE_BSC                   0x00000001
+
+#define TIM_OFFSET                             0x00000024
+#define TIM_PRESCALE_SHIFT                     6
+#define TIM_P_SHIFT                            3
+#define TIM_NO_DIV_SHIFT                       2
+#define TIM_DIV_SHIFT                          0
+
+#define DAT_OFFSET                             0x00000028
+
+#define TOUT_OFFSET                            0x0000002c
+
+#define TXFCR_OFFSET                           0x0000003c
+#define TXFCR_FIFO_FLUSH_MASK                  0x00000080
+#define TXFCR_FIFO_EN_MASK                     0x00000040
+
+#define IER_OFFSET                             0x00000044
+#define IER_READ_COMPLETE_INT_MASK             0x00000010
+#define IER_I2C_INT_EN_MASK                    0x00000008
+#define IER_FIFO_INT_EN_MASK                   0x00000002
+#define IER_NOACK_EN_MASK                      0x00000001
+
+#define ISR_OFFSET                             0x00000048
+#define ISR_RESERVED_MASK                      0xffffff60
+#define ISR_CMDBUSY_MASK                       0x00000080
+#define ISR_READ_COMPLETE_MASK                 0x00000010
+#define ISR_SES_DONE_MASK                      0x00000008
+#define ISR_ERR_MASK                           0x00000004
+#define ISR_TXFIFOEMPTY_MASK                   0x00000002
+#define ISR_NOACK_MASK                         0x00000001
+
+#define CLKEN_OFFSET                           0x0000004C
+#define CLKEN_AUTOSENSE_OFF_MASK               0x00000080
+#define CLKEN_M_SHIFT                          4
+#define CLKEN_N_SHIFT                          1
+#define CLKEN_CLKEN_MASK                       0x00000001
+
+#define FIFO_STATUS_OFFSET                     0x00000054
+#define FIFO_STATUS_RXFIFO_EMPTY_MASK          0x00000004
+#define FIFO_STATUS_TXFIFO_EMPTY_MASK          0x00000010
+
+#define HSTIM_OFFSET                           0x00000058
+#define HSTIM_HS_MODE_MASK                     0x00008000
+#define HSTIM_HS_HOLD_SHIFT                    10
+#define HSTIM_HS_HIGH_PHASE_SHIFT              5
+#define HSTIM_HS_SETUP_SHIFT                   0
+
+#define PADCTL_OFFSET                          0x0000005c
+#define PADCTL_PAD_OUT_EN_MASK                 0x00000004
+
+#define RXFCR_OFFSET                           0x00000068
+#define RXFCR_NACK_EN_SHIFT                    7
+#define RXFCR_READ_COUNT_SHIFT                 0
+#define RXFIFORDOUT_OFFSET                     0x0000006c
+
+/* Locally used constants */
+#define MAX_RX_FIFO_SIZE               64U /* bytes */
+#define MAX_TX_FIFO_SIZE               64U /* bytes */
+
+#define STD_EXT_CLK_FREQ               13000000UL
+#define HS_EXT_CLK_FREQ                        104000000UL
+
+#define MASTERCODE                     0x08 /* Mastercodes are 0000_1xxxb */
+
+#define I2C_TIMEOUT                    100 /* msecs */
+
+/* Operations that can be commanded to the controller */
+enum bcm_kona_cmd_t {
+       BCM_CMD_NOACTION = 0,
+       BCM_CMD_START,
+       BCM_CMD_RESTART,
+       BCM_CMD_STOP,
+};
+
+enum bus_speed_index {
+       BCM_SPD_100K = 0,
+       BCM_SPD_400K,
+       BCM_SPD_1MHZ,
+};
+
+enum hs_bus_speed_index {
+       BCM_SPD_3P4MHZ = 0,
+};
+
+/* Internal divider settings for standard mode, fast mode and fast mode plus */
+struct bus_speed_cfg {
+       uint8_t time_m;         /* Number of cycles for setup time */
+       uint8_t time_n;         /* Number of cycles for hold time */
+       uint8_t prescale;       /* Prescale divider */
+       uint8_t time_p;         /* Timing coefficient */
+       uint8_t no_div;         /* Disable clock divider */
+       uint8_t time_div;       /* Post-prescale divider */
+};
+
+/* Internal divider settings for high-speed mode */
+struct hs_bus_speed_cfg {
+       uint8_t hs_hold;        /* Number of clock cycles SCL stays low until
+                                  the end of bit period */
+       uint8_t hs_high_phase;  /* Number of clock cycles SCL stays high
+                                  before it falls */
+       uint8_t hs_setup;       /* Number of clock cycles SCL stays low
+                                  before it rises  */
+       uint8_t prescale;       /* Prescale divider */
+       uint8_t time_p;         /* Timing coefficient */
+       uint8_t no_div;         /* Disable clock divider */
+       uint8_t time_div;       /* Post-prescale divider */
+};
+
+static const struct bus_speed_cfg std_cfg_table[] = {
+       [BCM_SPD_100K] = {0x01, 0x01, 0x03, 0x06, 0x00, 0x02},
+       [BCM_SPD_400K] = {0x05, 0x01, 0x03, 0x05, 0x01, 0x02},
+       [BCM_SPD_1MHZ] = {0x01, 0x01, 0x03, 0x01, 0x01, 0x03},
+};
+
+static const struct hs_bus_speed_cfg hs_cfg_table[] = {
+       [BCM_SPD_3P4MHZ] = {0x01, 0x08, 0x14, 0x00, 0x06, 0x01, 0x00},
+};
+
+struct bcm_kona_i2c_dev {
+       struct device *device;
+
+       void __iomem *base;
+       int irq;
+       struct clk *external_clk;
+
+       struct i2c_adapter adapter;
+
+       struct completion done;
+
+       const struct bus_speed_cfg *std_cfg;
+       const struct hs_bus_speed_cfg *hs_cfg;
+};
+
+static void bcm_kona_i2c_send_cmd_to_ctrl(struct bcm_kona_i2c_dev *dev,
+                                         enum bcm_kona_cmd_t cmd)
+{
+       dev_dbg(dev->device, "%s, %d\n", __func__, cmd);
+
+       switch (cmd) {
+       case BCM_CMD_NOACTION:
+               writel((CS_CMD_CMD_NO_ACTION << CS_CMD_SHIFT) |
+                      (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
+                      dev->base + CS_OFFSET);
+               break;
+
+       case BCM_CMD_START:
+               writel((CS_ACK_CMD_GEN_START << CS_ACK_SHIFT) |
+                      (CS_CMD_CMD_START_RESTART << CS_CMD_SHIFT) |
+                      (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
+                      dev->base + CS_OFFSET);
+               break;
+
+       case BCM_CMD_RESTART:
+               writel((CS_ACK_CMD_GEN_RESTART << CS_ACK_SHIFT) |
+                      (CS_CMD_CMD_START_RESTART << CS_CMD_SHIFT) |
+                      (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
+                      dev->base + CS_OFFSET);
+               break;
+
+       case BCM_CMD_STOP:
+               writel((CS_CMD_CMD_STOP << CS_CMD_SHIFT) |
+                      (CS_EN_CMD_ENABLE_BSC << CS_EN_SHIFT),
+                      dev->base + CS_OFFSET);
+               break;
+
+       default:
+               dev_err(dev->device, "Unknown command %d\n", cmd);
+       }
+}
+
+static void bcm_kona_i2c_enable_clock(struct bcm_kona_i2c_dev *dev)
+{
+       writel(readl(dev->base + CLKEN_OFFSET) | CLKEN_CLKEN_MASK,
+              dev->base + CLKEN_OFFSET);
+}
+
+static void bcm_kona_i2c_disable_clock(struct bcm_kona_i2c_dev *dev)
+{
+       writel(readl(dev->base + CLKEN_OFFSET) & ~CLKEN_CLKEN_MASK,
+              dev->base + CLKEN_OFFSET);
+}
+
+static irqreturn_t bcm_kona_i2c_isr(int irq, void *devid)
+{
+       struct bcm_kona_i2c_dev *dev = devid;
+       uint32_t status = readl(dev->base + ISR_OFFSET);
+
+       if ((status & ~ISR_RESERVED_MASK) == 0)
+               return IRQ_NONE;
+
+       /* Must flush the TX FIFO when NAK detected */
+       if (status & ISR_NOACK_MASK)
+               writel(TXFCR_FIFO_FLUSH_MASK | TXFCR_FIFO_EN_MASK,
+                      dev->base + TXFCR_OFFSET);
+
+       writel(status & ~ISR_RESERVED_MASK, dev->base + ISR_OFFSET);
+       complete_all(&dev->done);
+
+       return IRQ_HANDLED;
+}
+
+/* Wait for ISR_CMDBUSY_MASK to go low before writing to CS, DAT, or RCD */
+static int bcm_kona_i2c_wait_if_busy(struct bcm_kona_i2c_dev *dev)
+{
+       unsigned long timeout = jiffies + msecs_to_jiffies(I2C_TIMEOUT);
+
+       while (readl(dev->base + ISR_OFFSET) & ISR_CMDBUSY_MASK)
+               if (time_after(jiffies, timeout)) {
+                       dev_err(dev->device, "CMDBUSY timeout\n");
+                       return -ETIMEDOUT;
+               }
+
+       return 0;
+}
+
+/* Send command to I2C bus */
+static int bcm_kona_send_i2c_cmd(struct bcm_kona_i2c_dev *dev,
+                                enum bcm_kona_cmd_t cmd)
+{
+       int rc;
+       unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
+
+       /* Make sure the hardware is ready */
+       rc = bcm_kona_i2c_wait_if_busy(dev);
+       if (rc < 0)
+               return rc;
+
+       /* Unmask the session done interrupt */
+       writel(IER_I2C_INT_EN_MASK, dev->base + IER_OFFSET);
+
+       /* Mark as incomplete before sending the command */
+       reinit_completion(&dev->done);
+
+       /* Send the command */
+       bcm_kona_i2c_send_cmd_to_ctrl(dev, cmd);
+
+       /* Wait for transaction to finish or timeout */
+       time_left = wait_for_completion_timeout(&dev->done, time_left);
+
+       /* Mask all interrupts */
+       writel(0, dev->base + IER_OFFSET);
+
+       if (!time_left) {
+               dev_err(dev->device, "controller timed out\n");
+               rc = -ETIMEDOUT;
+       }
+
+       /* Clear command */
+       bcm_kona_i2c_send_cmd_to_ctrl(dev, BCM_CMD_NOACTION);
+
+       return rc;
+}
+
+/* Read a single RX FIFO worth of data from the i2c bus */
+static int bcm_kona_i2c_read_fifo_single(struct bcm_kona_i2c_dev *dev,
+                                        uint8_t *buf, unsigned int len,
+                                        unsigned int last_byte_nak)
+{
+       unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
+
+       /* Mark as incomplete before starting the RX FIFO */
+       reinit_completion(&dev->done);
+
+       /* Unmask the read complete interrupt */
+       writel(IER_READ_COMPLETE_INT_MASK, dev->base + IER_OFFSET);
+
+       /* Start the RX FIFO */
+       writel((last_byte_nak << RXFCR_NACK_EN_SHIFT) |
+              (len << RXFCR_READ_COUNT_SHIFT),
+               dev->base + RXFCR_OFFSET);
+
+       /* Wait for FIFO read to complete */
+       time_left = wait_for_completion_timeout(&dev->done, time_left);
+
+       /* Mask all interrupts */
+       writel(0, dev->base + IER_OFFSET);
+
+       if (!time_left) {
+               dev_err(dev->device, "RX FIFO time out\n");
+               return -EREMOTEIO;
+       }
+
+       /* Read data from FIFO */
+       for (; len > 0; len--, buf++)
+               *buf = readl(dev->base + RXFIFORDOUT_OFFSET);
+
+       return 0;
+}
+
+/* Read any amount of data using the RX FIFO from the i2c bus */
+static int bcm_kona_i2c_read_fifo(struct bcm_kona_i2c_dev *dev,
+                                 struct i2c_msg *msg)
+{
+       unsigned int bytes_to_read = MAX_RX_FIFO_SIZE;
+       unsigned int last_byte_nak = 0;
+       unsigned int bytes_read = 0;
+       int rc;
+
+       uint8_t *tmp_buf = msg->buf;
+
+       while (bytes_read < msg->len) {
+               if (msg->len - bytes_read <= MAX_RX_FIFO_SIZE) {
+                       last_byte_nak = 1; /* NAK last byte of transfer */
+                       bytes_to_read = msg->len - bytes_read;
+               }
+
+               rc = bcm_kona_i2c_read_fifo_single(dev, tmp_buf, bytes_to_read,
+                                                  last_byte_nak);
+               if (rc < 0)
+                       return -EREMOTEIO;
+
+               bytes_read += bytes_to_read;
+               tmp_buf += bytes_to_read;
+       }
+
+       return 0;
+}
+
+/* Write a single byte of data to the i2c bus */
+static int bcm_kona_i2c_write_byte(struct bcm_kona_i2c_dev *dev, uint8_t data,
+                                  unsigned int nak_expected)
+{
+       int rc;
+       unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
+       unsigned int nak_received;
+
+       /* Make sure the hardware is ready */
+       rc = bcm_kona_i2c_wait_if_busy(dev);
+       if (rc < 0)
+               return rc;
+
+       /* Clear pending session done interrupt */
+       writel(ISR_SES_DONE_MASK, dev->base + ISR_OFFSET);
+
+       /* Unmask the session done interrupt */
+       writel(IER_I2C_INT_EN_MASK, dev->base + IER_OFFSET);
+
+       /* Mark as incomplete before sending the data */
+       reinit_completion(&dev->done);
+
+       /* Send one byte of data */
+       writel(data, dev->base + DAT_OFFSET);
+
+       /* Wait for byte to be written */
+       time_left = wait_for_completion_timeout(&dev->done, time_left);
+
+       /* Mask all interrupts */
+       writel(0, dev->base + IER_OFFSET);
+
+       if (!time_left) {
+               dev_dbg(dev->device, "controller timed out\n");
+               return -ETIMEDOUT;
+       }
+
+       nak_received = readl(dev->base + CS_OFFSET) & CS_ACK_MASK ? 1 : 0;
+
+       if (nak_received ^ nak_expected) {
+               dev_dbg(dev->device, "unexpected NAK/ACK\n");
+               return -EREMOTEIO;
+       }
+
+       return 0;
+}
+
+/* Write a single TX FIFO worth of data to the i2c bus */
+static int bcm_kona_i2c_write_fifo_single(struct bcm_kona_i2c_dev *dev,
+                                         uint8_t *buf, unsigned int len)
+{
+       int k;
+       unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT);
+       unsigned int fifo_status;
+
+       /* Mark as incomplete before sending data to the TX FIFO */
+       reinit_completion(&dev->done);
+
+       /* Unmask the fifo empty and nak interrupt */
+       writel(IER_FIFO_INT_EN_MASK | IER_NOACK_EN_MASK,
+              dev->base + IER_OFFSET);
+
+       /* Disable IRQ to load a FIFO worth of data without interruption */
+       disable_irq(dev->irq);
+
+       /* Write data into FIFO */
+       for (k = 0; k < len; k++)
+               writel(buf[k], (dev->base + DAT_OFFSET));
+
+       /* Enable IRQ now that data has been loaded */
+       enable_irq(dev->irq);
+
+       /* Wait for FIFO to empty */
+       do {
+               time_left = wait_for_completion_timeout(&dev->done, time_left);
+               fifo_status = readl(dev->base + FIFO_STATUS_OFFSET);
+       } while (time_left && !(fifo_status & FIFO_STATUS_TXFIFO_EMPTY_MASK));
+
+       /* Mask all interrupts */
+       writel(0, dev->base + IER_OFFSET);
+
+       /* Check if there was a NAK */
+       if (readl(dev->base + CS_OFFSET) & CS_ACK_MASK) {
+               dev_err(dev->device, "unexpected NAK\n");
+               return -EREMOTEIO;
+       }
+
+       /* Check if a timeout occured */
+       if (!time_left) {
+               dev_err(dev->device, "completion timed out\n");
+               return -EREMOTEIO;
+       }
+
+       return 0;
+}
+
+
+/* Write any amount of data using TX FIFO to the i2c bus */
+static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
+                                  struct i2c_msg *msg)
+{
+       unsigned int bytes_to_write = MAX_TX_FIFO_SIZE;
+       unsigned int bytes_written = 0;
+       int rc;
+
+       uint8_t *tmp_buf = msg->buf;
+
+       while (bytes_written < msg->len) {
+               if (msg->len - bytes_written <= MAX_TX_FIFO_SIZE)
+                       bytes_to_write = msg->len - bytes_written;
+
+               rc = bcm_kona_i2c_write_fifo_single(dev, tmp_buf,
+                                                   bytes_to_write);
+               if (rc < 0)
+                       return -EREMOTEIO;
+
+               bytes_written += bytes_to_write;
+               tmp_buf += bytes_to_write;
+       }
+
+       return 0;
+}
+
+/* Send i2c address */
+static int bcm_kona_i2c_do_addr(struct bcm_kona_i2c_dev *dev,
+                                    struct i2c_msg *msg)
+{
+       unsigned char addr;
+
+       if (msg->flags & I2C_M_TEN) {
+               /* First byte is 11110XX0 where XX is upper 2 bits */
+               addr = 0xF0 | ((msg->addr & 0x300) >> 7);
+               if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
+                       return -EREMOTEIO;
+
+               /* Second byte is the remaining 8 bits */
+               addr = msg->addr & 0xFF;
+               if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
+                       return -EREMOTEIO;
+
+               if (msg->flags & I2C_M_RD) {
+                       /* For read, send restart command */
+                       if (bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART) < 0)
+                               return -EREMOTEIO;
+
+                       /* Then re-send the first byte with the read bit set */
+                       addr = 0xF0 | ((msg->addr & 0x300) >> 7) | 0x01;
+                       if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
+                               return -EREMOTEIO;
+               }
+       } else {
+               addr = msg->addr << 1;
+
+               if (msg->flags & I2C_M_RD)
+                       addr |= 1;
+
+               if (bcm_kona_i2c_write_byte(dev, addr, 0) < 0)
+                       return -EREMOTEIO;
+       }
+
+       return 0;
+}
+
+static void bcm_kona_i2c_enable_autosense(struct bcm_kona_i2c_dev *dev)
+{
+       writel(readl(dev->base + CLKEN_OFFSET) & ~CLKEN_AUTOSENSE_OFF_MASK,
+              dev->base + CLKEN_OFFSET);
+}
+
+static void bcm_kona_i2c_config_timing(struct bcm_kona_i2c_dev *dev)
+{
+       writel(readl(dev->base + HSTIM_OFFSET) & ~HSTIM_HS_MODE_MASK,
+              dev->base + HSTIM_OFFSET);
+
+       writel((dev->std_cfg->prescale << TIM_PRESCALE_SHIFT) |
+              (dev->std_cfg->time_p << TIM_P_SHIFT) |
+              (dev->std_cfg->no_div << TIM_NO_DIV_SHIFT) |
+              (dev->std_cfg->time_div  << TIM_DIV_SHIFT),
+              dev->base + TIM_OFFSET);
+
+       writel((dev->std_cfg->time_m << CLKEN_M_SHIFT) |
+              (dev->std_cfg->time_n << CLKEN_N_SHIFT) |
+              CLKEN_CLKEN_MASK,
+              dev->base + CLKEN_OFFSET);
+}
+
+static void bcm_kona_i2c_config_timing_hs(struct bcm_kona_i2c_dev *dev)
+{
+       writel((dev->hs_cfg->prescale << TIM_PRESCALE_SHIFT) |
+              (dev->hs_cfg->time_p << TIM_P_SHIFT) |
+              (dev->hs_cfg->no_div << TIM_NO_DIV_SHIFT) |
+              (dev->hs_cfg->time_div << TIM_DIV_SHIFT),
+              dev->base + TIM_OFFSET);
+
+       writel((dev->hs_cfg->hs_hold << HSTIM_HS_HOLD_SHIFT) |
+              (dev->hs_cfg->hs_high_phase << HSTIM_HS_HIGH_PHASE_SHIFT) |
+              (dev->hs_cfg->hs_setup << HSTIM_HS_SETUP_SHIFT),
+              dev->base + HSTIM_OFFSET);
+
+       writel(readl(dev->base + HSTIM_OFFSET) | HSTIM_HS_MODE_MASK,
+              dev->base + HSTIM_OFFSET);
+}
+
+static int bcm_kona_i2c_switch_to_hs(struct bcm_kona_i2c_dev *dev)
+{
+       int rc;
+
+       /* Send mastercode at standard speed */
+       rc = bcm_kona_i2c_write_byte(dev, MASTERCODE, 1);
+       if (rc < 0) {
+               pr_err("High speed handshake failed\n");
+               return rc;
+       }
+
+       /* Configure external clock to higher frequency */
+       rc = clk_set_rate(dev->external_clk, HS_EXT_CLK_FREQ);
+       if (rc) {
+               dev_err(dev->device, "%s: clk_set_rate returned %d\n",
+                       __func__, rc);
+               return rc;
+       }
+
+       /* Reconfigure internal dividers */
+       bcm_kona_i2c_config_timing_hs(dev);
+
+       /* Send a restart command */
+       rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART);
+       if (rc < 0)
+               dev_err(dev->device, "High speed restart command failed\n");
+
+       return rc;
+}
+
+static int bcm_kona_i2c_switch_to_std(struct bcm_kona_i2c_dev *dev)
+{
+       int rc;
+
+       /* Reconfigure internal dividers */
+       bcm_kona_i2c_config_timing(dev);
+
+       /* Configure external clock to lower frequency */
+       rc = clk_set_rate(dev->external_clk, STD_EXT_CLK_FREQ);
+       if (rc) {
+               dev_err(dev->device, "%s: clk_set_rate returned %d\n",
+                       __func__, rc);
+       }
+
+       return rc;
+}
+
+/* Master transfer function */
+static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
+                            struct i2c_msg msgs[], int num)
+{
+       struct bcm_kona_i2c_dev *dev = i2c_get_adapdata(adapter);
+       struct i2c_msg *pmsg;
+       int rc = 0;
+       int i;
+
+       rc = clk_prepare_enable(dev->external_clk);
+       if (rc) {
+               dev_err(dev->device, "%s: peri clock enable failed. err %d\n",
+                       __func__, rc);
+               return rc;
+       }
+
+       /* Enable pad output */
+       writel(0, dev->base + PADCTL_OFFSET);
+
+       /* Enable internal clocks */
+       bcm_kona_i2c_enable_clock(dev);
+
+       /* Send start command */
+       rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_START);
+       if (rc < 0) {
+               dev_err(dev->device, "Start command failed rc = %d\n", rc);
+               goto xfer_disable_pad;
+       }
+
+       /* Switch to high speed if applicable */
+       if (dev->hs_cfg) {
+               rc = bcm_kona_i2c_switch_to_hs(dev);
+               if (rc < 0)
+                       goto xfer_send_stop;
+       }
+
+       /* Loop through all messages */
+       for (i = 0; i < num; i++) {
+               pmsg = &msgs[i];
+
+               /* Send restart for subsequent messages */
+               if ((i != 0) && ((pmsg->flags & I2C_M_NOSTART) == 0)) {
+                       rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART);
+                       if (rc < 0) {
+                               dev_err(dev->device,
+                                       "restart cmd failed rc = %d\n", rc);
+                                       goto xfer_send_stop;
+                       }
+               }
+
+               /* Send slave address */
+               if (!(pmsg->flags & I2C_M_NOSTART)) {
+                       rc = bcm_kona_i2c_do_addr(dev, pmsg);
+                       if (rc < 0) {
+                               dev_err(dev->device,
+                                       "NAK from addr %2.2x msg#%d rc = %d\n",
+                                       pmsg->addr, i, rc);
+                               goto xfer_send_stop;
+                       }
+               }
+
+               /* Perform data transfer */
+               if (pmsg->flags & I2C_M_RD) {
+                       rc = bcm_kona_i2c_read_fifo(dev, pmsg);
+                       if (rc < 0) {
+                               dev_err(dev->device, "read failure\n");
+                               goto xfer_send_stop;
+                       }
+               } else {
+                       rc = bcm_kona_i2c_write_fifo(dev, pmsg);
+                       if (rc < 0) {
+                               dev_err(dev->device, "write failure");
+                               goto xfer_send_stop;
+                       }
+               }
+       }
+
+       rc = num;
+
+xfer_send_stop:
+       /* Send a STOP command */
+       bcm_kona_send_i2c_cmd(dev, BCM_CMD_STOP);
+
+       /* Return from high speed if applicable */
+       if (dev->hs_cfg) {
+               int hs_rc = bcm_kona_i2c_switch_to_std(dev);
+
+               if (hs_rc)
+                       rc = hs_rc;
+       }
+
+xfer_disable_pad:
+       /* Disable pad output */
+       writel(PADCTL_PAD_OUT_EN_MASK, dev->base + PADCTL_OFFSET);
+
+       /* Stop internal clock */
+       bcm_kona_i2c_disable_clock(dev);
+
+       clk_disable_unprepare(dev->external_clk);
+
+       return rc;
+}
+
+static uint32_t bcm_kona_i2c_functionality(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
+           I2C_FUNC_NOSTART;
+}
+
+static const struct i2c_algorithm bcm_algo = {
+       .master_xfer = bcm_kona_i2c_xfer,
+       .functionality = bcm_kona_i2c_functionality,
+};
+
+static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
+{
+       unsigned int bus_speed;
+       int ret = of_property_read_u32(dev->device->of_node, "clock-frequency",
+                                      &bus_speed);
+       if (ret < 0) {
+               dev_err(dev->device, "missing clock-frequency property\n");
+               return -ENODEV;
+       }
+
+       switch (bus_speed) {
+       case 100000:
+               dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
+               break;
+       case 400000:
+               dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
+               break;
+       case 1000000:
+               dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
+               break;
+       case 3400000:
+               /* Send mastercode at 100k */
+               dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
+               dev->hs_cfg = &hs_cfg_table[BCM_SPD_3P4MHZ];
+               break;
+       default:
+               pr_err("%d hz bus speed not supported\n", bus_speed);
+               pr_err("Valid speeds are 100khz, 400khz, 1mhz, and 3.4mhz\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int bcm_kona_i2c_probe(struct platform_device *pdev)
+{
+       int rc = 0;
+       struct bcm_kona_i2c_dev *dev;
+       struct i2c_adapter *adap;
+       struct resource *iomem;
+
+       /* Allocate memory for private data structure */
+       dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, dev);
+       dev->device = &pdev->dev;
+       init_completion(&dev->done);
+
+       /* Map hardware registers */
+       iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       dev->base = devm_ioremap_resource(dev->device, iomem);
+       if (IS_ERR(dev->base))
+               return -ENOMEM;
+
+       /* Get and enable external clock */
+       dev->external_clk = devm_clk_get(dev->device, NULL);
+       if (IS_ERR(dev->external_clk)) {
+               dev_err(dev->device, "couldn't get clock\n");
+               return -ENODEV;
+       }
+
+       rc = clk_set_rate(dev->external_clk, STD_EXT_CLK_FREQ);
+       if (rc) {
+               dev_err(dev->device, "%s: clk_set_rate returned %d\n",
+                       __func__, rc);
+               return rc;
+       }
+
+       rc = clk_prepare_enable(dev->external_clk);
+       if (rc) {
+               dev_err(dev->device, "couldn't enable clock\n");
+               return rc;
+       }
+
+       /* Parse bus speed */
+       rc = bcm_kona_i2c_assign_bus_speed(dev);
+       if (rc)
+               goto probe_disable_clk;
+
+       /* Enable internal clocks */
+       bcm_kona_i2c_enable_clock(dev);
+
+       /* Configure internal dividers */
+       bcm_kona_i2c_config_timing(dev);
+
+       /* Disable timeout */
+       writel(0, dev->base + TOUT_OFFSET);
+
+       /* Enable autosense */
+       bcm_kona_i2c_enable_autosense(dev);
+
+       /* Enable TX FIFO */
+       writel(TXFCR_FIFO_FLUSH_MASK | TXFCR_FIFO_EN_MASK,
+              dev->base + TXFCR_OFFSET);
+
+       /* Mask all interrupts */
+       writel(0, dev->base + IER_OFFSET);
+
+       /* Clear all pending interrupts */
+       writel(ISR_CMDBUSY_MASK |
+              ISR_READ_COMPLETE_MASK |
+              ISR_SES_DONE_MASK |
+              ISR_ERR_MASK |
+              ISR_TXFIFOEMPTY_MASK |
+              ISR_NOACK_MASK,
+              dev->base + ISR_OFFSET);
+
+       /* Get the interrupt number */
+       dev->irq = platform_get_irq(pdev, 0);
+       if (dev->irq < 0) {
+               dev_err(dev->device, "no irq resource\n");
+               rc = -ENODEV;
+               goto probe_disable_clk;
+       }
+
+       /* register the ISR handler */
+       rc = devm_request_irq(&pdev->dev, dev->irq, bcm_kona_i2c_isr,
+                             IRQF_SHARED, pdev->name, dev);
+       if (rc) {
+               dev_err(dev->device, "failed to request irq %i\n", dev->irq);
+               goto probe_disable_clk;
+       }
+
+       /* Enable the controller but leave it idle */
+       bcm_kona_i2c_send_cmd_to_ctrl(dev, BCM_CMD_NOACTION);
+
+       /* Disable pad output */
+       writel(PADCTL_PAD_OUT_EN_MASK, dev->base + PADCTL_OFFSET);
+
+       /* Disable internal clock */
+       bcm_kona_i2c_disable_clock(dev);
+
+       /* Disable external clock */
+       clk_disable_unprepare(dev->external_clk);
+
+       /* Add the i2c adapter */
+       adap = &dev->adapter;
+       i2c_set_adapdata(adap, dev);
+       adap->owner = THIS_MODULE;
+       strlcpy(adap->name, "Broadcom I2C adapter", sizeof(adap->name));
+       adap->algo = &bcm_algo;
+       adap->dev.parent = &pdev->dev;
+       adap->dev.of_node = pdev->dev.of_node;
+
+       rc = i2c_add_adapter(adap);
+       if (rc) {
+               dev_err(dev->device, "failed to add adapter\n");
+               return rc;
+       }
+
+       dev_info(dev->device, "device registered successfully\n");
+
+       return 0;
+
+probe_disable_clk:
+       bcm_kona_i2c_disable_clock(dev);
+       clk_disable_unprepare(dev->external_clk);
+
+       return rc;
+}
+
+static int bcm_kona_i2c_remove(struct platform_device *pdev)
+{
+       struct bcm_kona_i2c_dev *dev = platform_get_drvdata(pdev);
+
+       i2c_del_adapter(&dev->adapter);
+
+       return 0;
+}
+
+static const struct of_device_id bcm_kona_i2c_of_match[] = {
+       {.compatible = "brcm,kona-i2c",},
+       {},
+};
+MODULE_DEVICE_TABLE(of, kona_i2c_of_match);
+
+static struct platform_driver bcm_kona_i2c_driver = {
+       .driver = {
+                  .name = "bcm-kona-i2c",
+                  .owner = THIS_MODULE,
+                  .of_match_table = bcm_kona_i2c_of_match,
+                  },
+       .probe = bcm_kona_i2c_probe,
+       .remove = bcm_kona_i2c_remove,
+};
+module_platform_driver(bcm_kona_i2c_driver);
+
+MODULE_AUTHOR("Tim Kryger <tkryger@broadcom.com>");
+MODULE_DESCRIPTION("Broadcom Kona I2C Driver");
+MODULE_LICENSE("GPL v2");
index 35a473ba3d81d5afb9cb0188f2141c2dc417c737..3b9bd9a3f2b08a0a43683c87f1801d2f330185c3 100644 (file)
@@ -675,7 +675,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
        p_adap->retries = 3;
 
        rc = peripheral_request_list(
-                       (unsigned short *)dev_get_platdata(&pdev->dev),
+                       dev_get_platdata(&pdev->dev),
                        "i2c-bfin-twi");
        if (rc) {
                dev_err(&pdev->dev, "Can't setup pin mux!\n");
@@ -723,7 +723,7 @@ out_error_add_adapter:
        free_irq(iface->irq, iface);
 out_error_req_irq:
 out_error_no_irq:
-       peripheral_free_list((unsigned short *)dev_get_platdata(&pdev->dev));
+       peripheral_free_list(dev_get_platdata(&pdev->dev));
 out_error_pin_mux:
        iounmap(iface->regs_base);
 out_error_ioremap:
@@ -739,7 +739,7 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
 
        i2c_del_adapter(&(iface->adap));
        free_irq(iface->irq, iface);
-       peripheral_free_list((unsigned short *)dev_get_platdata(&pdev->dev));
+       peripheral_free_list(dev_get_platdata(&pdev->dev));
        iounmap(iface->regs_base);
        kfree(iface);
 
index 2d46f13adfdfc965561db40bdeafa55f6c445978..ce7ffba2b0208f24fa7324c5c7ad283346e2c693 100644 (file)
@@ -246,6 +246,7 @@ static int cbus_i2c_probe(struct platform_device *pdev)
        adapter->owner          = THIS_MODULE;
        adapter->class          = I2C_CLASS_HWMON;
        adapter->dev.parent     = &pdev->dev;
+       adapter->dev.of_node    = pdev->dev.of_node;
        adapter->nr             = pdev->id;
        adapter->timeout        = HZ;
        adapter->algo           = &cbus_i2c_algo;
@@ -289,6 +290,7 @@ static struct platform_driver cbus_i2c_driver = {
        .driver = {
                .owner  = THIS_MODULE,
                .name   = "i2c-cbus-gpio",
+               .of_match_table = of_match_ptr(i2c_cbus_dt_ids),
        },
 };
 module_platform_driver(cbus_i2c_driver);
index 960dec61c64ecc582472a149e37253a3f3e3b3bf..ff05d9fef4a8ee22f40c981bd11e90e9ad24e51e 100644 (file)
@@ -795,7 +795,7 @@ static struct platform_driver davinci_i2c_driver = {
                .name   = "i2c_davinci",
                .owner  = THIS_MODULE,
                .pm     = davinci_i2c_pm_ops,
-               .of_match_table = of_match_ptr(davinci_i2c_of_match),
+               .of_match_table = davinci_i2c_of_match,
        },
 };
 
index 0aa01136f8d955148d984ac00e06ffb9e8ce1196..d0bdac0498cebafe3def932006c1380cfc318c1f 100644 (file)
@@ -103,6 +103,8 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
 static const struct acpi_device_id dw_i2c_acpi_match[] = {
        { "INT33C2", 0 },
        { "INT33C3", 0 },
+       { "INT3432", 0 },
+       { "INT3433", 0 },
        { "80860F41", 0 },
        { }
 };
index 0f3752967c4be717d3a451cda4737644939fe493..ff15ae90aaf54bb5c52585e087954338c0e40a31 100644 (file)
@@ -311,24 +311,6 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap)
        pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_START);
 }
 
-/**
- * pch_i2c_getack() - to confirm ACK/NACK
- * @adap:      Pointer to struct i2c_algo_pch_data.
- */
-static s32 pch_i2c_getack(struct i2c_algo_pch_data *adap)
-{
-       u32 reg_val;
-       void __iomem *p = adap->pch_base_address;
-       reg_val = ioread32(p + PCH_I2CSR) & PCH_GETACK;
-
-       if (reg_val != 0) {
-               pch_err(adap, "return%d\n", -EPROTO);
-               return -EPROTO;
-       }
-
-       return 0;
-}
-
 /**
  * pch_i2c_stop() - generate stop condition in normal mode.
  * @adap:      Pointer to struct i2c_algo_pch_data.
@@ -344,6 +326,7 @@ static void pch_i2c_stop(struct i2c_algo_pch_data *adap)
 static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
 {
        long ret;
+       void __iomem *p = adap->pch_base_address;
 
        ret = wait_event_timeout(pch_event,
                        (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
@@ -366,10 +349,9 @@ static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
 
        adap->pch_event_flag = 0;
 
-       if (pch_i2c_getack(adap)) {
-               pch_dbg(adap, "Receive NACK for slave address"
-                       "setting\n");
-               return -EIO;
+       if (ioread32(p + PCH_I2CSR) & PCH_GETACK) {
+               pch_dbg(adap, "Receive NACK for slave address setting\n");
+               return -ENXIO;
        }
 
        return 0;
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
new file mode 100644 (file)
index 0000000..c1ef228
--- /dev/null
@@ -0,0 +1,769 @@
+/**
+ * i2c-exynos5.c - Samsung Exynos5 I2C Controller Driver
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/spinlock.h>
+
+/*
+ * HSI2C controller from Samsung supports 2 modes of operation
+ * 1. Auto mode: Where in master automatically controls the whole transaction
+ * 2. Manual mode: Software controls the transaction by issuing commands
+ *    START, READ, WRITE, STOP, RESTART in I2C_MANUAL_CMD register.
+ *
+ * Operation mode can be selected by setting AUTO_MODE bit in I2C_CONF register
+ *
+ * Special bits are available for both modes of operation to set commands
+ * and for checking transfer status
+ */
+
+/* Register Map */
+#define HSI2C_CTL              0x00
+#define HSI2C_FIFO_CTL         0x04
+#define HSI2C_TRAILIG_CTL      0x08
+#define HSI2C_CLK_CTL          0x0C
+#define HSI2C_CLK_SLOT         0x10
+#define HSI2C_INT_ENABLE       0x20
+#define HSI2C_INT_STATUS       0x24
+#define HSI2C_ERR_STATUS       0x2C
+#define HSI2C_FIFO_STATUS      0x30
+#define HSI2C_TX_DATA          0x34
+#define HSI2C_RX_DATA          0x38
+#define HSI2C_CONF             0x40
+#define HSI2C_AUTO_CONF                0x44
+#define HSI2C_TIMEOUT          0x48
+#define HSI2C_MANUAL_CMD       0x4C
+#define HSI2C_TRANS_STATUS     0x50
+#define HSI2C_TIMING_HS1       0x54
+#define HSI2C_TIMING_HS2       0x58
+#define HSI2C_TIMING_HS3       0x5C
+#define HSI2C_TIMING_FS1       0x60
+#define HSI2C_TIMING_FS2       0x64
+#define HSI2C_TIMING_FS3       0x68
+#define HSI2C_TIMING_SLA       0x6C
+#define HSI2C_ADDR             0x70
+
+/* I2C_CTL Register bits */
+#define HSI2C_FUNC_MODE_I2C                    (1u << 0)
+#define HSI2C_MASTER                           (1u << 3)
+#define HSI2C_RXCHON                           (1u << 6)
+#define HSI2C_TXCHON                           (1u << 7)
+#define HSI2C_SW_RST                           (1u << 31)
+
+/* I2C_FIFO_CTL Register bits */
+#define HSI2C_RXFIFO_EN                                (1u << 0)
+#define HSI2C_TXFIFO_EN                                (1u << 1)
+#define HSI2C_RXFIFO_TRIGGER_LEVEL(x)          ((x) << 4)
+#define HSI2C_TXFIFO_TRIGGER_LEVEL(x)          ((x) << 16)
+
+/* As per user manual FIFO max depth is 64bytes */
+#define HSI2C_FIFO_MAX                         0x40
+/* default trigger levels for Tx and Rx FIFOs */
+#define HSI2C_DEF_TXFIFO_LVL                   (HSI2C_FIFO_MAX - 0x30)
+#define HSI2C_DEF_RXFIFO_LVL                   (HSI2C_FIFO_MAX - 0x10)
+
+/* I2C_TRAILING_CTL Register bits */
+#define HSI2C_TRAILING_COUNT                   (0xf)
+
+/* I2C_INT_EN Register bits */
+#define HSI2C_INT_TX_ALMOSTEMPTY_EN            (1u << 0)
+#define HSI2C_INT_RX_ALMOSTFULL_EN             (1u << 1)
+#define HSI2C_INT_TRAILING_EN                  (1u << 6)
+#define HSI2C_INT_I2C_EN                       (1u << 9)
+
+/* I2C_INT_STAT Register bits */
+#define HSI2C_INT_TX_ALMOSTEMPTY               (1u << 0)
+#define HSI2C_INT_RX_ALMOSTFULL                        (1u << 1)
+#define HSI2C_INT_TX_UNDERRUN                  (1u << 2)
+#define HSI2C_INT_TX_OVERRUN                   (1u << 3)
+#define HSI2C_INT_RX_UNDERRUN                  (1u << 4)
+#define HSI2C_INT_RX_OVERRUN                   (1u << 5)
+#define HSI2C_INT_TRAILING                     (1u << 6)
+#define HSI2C_INT_I2C                          (1u << 9)
+
+/* I2C_FIFO_STAT Register bits */
+#define HSI2C_RX_FIFO_EMPTY                    (1u << 24)
+#define HSI2C_RX_FIFO_FULL                     (1u << 23)
+#define HSI2C_RX_FIFO_LVL(x)                   ((x >> 16) & 0x7f)
+#define HSI2C_TX_FIFO_EMPTY                    (1u << 8)
+#define HSI2C_TX_FIFO_FULL                     (1u << 7)
+#define HSI2C_TX_FIFO_LVL(x)                   ((x >> 0) & 0x7f)
+
+/* I2C_CONF Register bits */
+#define HSI2C_AUTO_MODE                                (1u << 31)
+#define HSI2C_10BIT_ADDR_MODE                  (1u << 30)
+#define HSI2C_HS_MODE                          (1u << 29)
+
+/* I2C_AUTO_CONF Register bits */
+#define HSI2C_READ_WRITE                       (1u << 16)
+#define HSI2C_STOP_AFTER_TRANS                 (1u << 17)
+#define HSI2C_MASTER_RUN                       (1u << 31)
+
+/* I2C_TIMEOUT Register bits */
+#define HSI2C_TIMEOUT_EN                       (1u << 31)
+#define HSI2C_TIMEOUT_MASK                     0xff
+
+/* I2C_TRANS_STATUS register bits */
+#define HSI2C_MASTER_BUSY                      (1u << 17)
+#define HSI2C_SLAVE_BUSY                       (1u << 16)
+#define HSI2C_TIMEOUT_AUTO                     (1u << 4)
+#define HSI2C_NO_DEV                           (1u << 3)
+#define HSI2C_NO_DEV_ACK                       (1u << 2)
+#define HSI2C_TRANS_ABORT                      (1u << 1)
+#define HSI2C_TRANS_DONE                       (1u << 0)
+
+/* I2C_ADDR register bits */
+#define HSI2C_SLV_ADDR_SLV(x)                  ((x & 0x3ff) << 0)
+#define HSI2C_SLV_ADDR_MAS(x)                  ((x & 0x3ff) << 10)
+#define HSI2C_MASTER_ID(x)                     ((x & 0xff) << 24)
+#define MASTER_ID(x)                           ((x & 0x7) + 0x08)
+
+/*
+ * Controller operating frequency, timing values for operation
+ * are calculated against this frequency
+ */
+#define HSI2C_HS_TX_CLOCK      1000000
+#define HSI2C_FS_TX_CLOCK      100000
+#define HSI2C_HIGH_SPD         1
+#define HSI2C_FAST_SPD         0
+
+#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000))
+
+struct exynos5_i2c {
+       struct i2c_adapter      adap;
+       unsigned int            suspended:1;
+
+       struct i2c_msg          *msg;
+       struct completion       msg_complete;
+       unsigned int            msg_ptr;
+
+       unsigned int            irq;
+
+       void __iomem            *regs;
+       struct clk              *clk;
+       struct device           *dev;
+       int                     state;
+
+       spinlock_t              lock;           /* IRQ synchronization */
+
+       /*
+        * Since the TRANS_DONE bit is cleared on read, and we may read it
+        * either during an IRQ or after a transaction, keep track of its
+        * state here.
+        */
+       int                     trans_done;
+
+       /* Controller operating frequency */
+       unsigned int            fs_clock;
+       unsigned int            hs_clock;
+
+       /*
+        * HSI2C Controller can operate in
+        * 1. High speed upto 3.4Mbps
+        * 2. Fast speed upto 1Mbps
+        */
+       int                     speed_mode;
+};
+
+static const struct of_device_id exynos5_i2c_match[] = {
+       { .compatible = "samsung,exynos5-hsi2c" },
+       {},
+};
+MODULE_DEVICE_TABLE(of, exynos5_i2c_match);
+
+static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c)
+{
+       writel(readl(i2c->regs + HSI2C_INT_STATUS),
+                               i2c->regs + HSI2C_INT_STATUS);
+}
+
+/*
+ * exynos5_i2c_set_timing: updates the registers with appropriate
+ * timing values calculated
+ *
+ * Returns 0 on success, -EINVAL if the cycle length cannot
+ * be calculated.
+ */
+static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
+{
+       u32 i2c_timing_s1;
+       u32 i2c_timing_s2;
+       u32 i2c_timing_s3;
+       u32 i2c_timing_sla;
+       unsigned int t_start_su, t_start_hd;
+       unsigned int t_stop_su;
+       unsigned int t_data_su, t_data_hd;
+       unsigned int t_scl_l, t_scl_h;
+       unsigned int t_sr_release;
+       unsigned int t_ftl_cycle;
+       unsigned int clkin = clk_get_rate(i2c->clk);
+       unsigned int div, utemp0 = 0, utemp1 = 0, clk_cycle;
+       unsigned int op_clk = (mode == HSI2C_HIGH_SPD) ?
+                               i2c->hs_clock : i2c->fs_clock;
+
+       /*
+        * FPCLK / FI2C =
+        * (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) + 8 + 2 * FLT_CYCLE
+        * utemp0 = (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2)
+        * utemp1 = (TSCLK_L + TSCLK_H + 2)
+        */
+       t_ftl_cycle = (readl(i2c->regs + HSI2C_CONF) >> 16) & 0x7;
+       utemp0 = (clkin / op_clk) - 8 - 2 * t_ftl_cycle;
+
+       /* CLK_DIV max is 256 */
+       for (div = 0; div < 256; div++) {
+               utemp1 = utemp0 / (div + 1);
+
+               /*
+                * SCL_L and SCL_H each has max value of 255
+                * Hence, For the clk_cycle to the have right value
+                * utemp1 has to be less then 512 and more than 4.
+                */
+               if ((utemp1 < 512) && (utemp1 > 4)) {
+                       clk_cycle = utemp1 - 2;
+                       break;
+               } else if (div == 255) {
+                       dev_warn(i2c->dev, "Failed to calculate divisor");
+                       return -EINVAL;
+               }
+       }
+
+       t_scl_l = clk_cycle / 2;
+       t_scl_h = clk_cycle / 2;
+       t_start_su = t_scl_l;
+       t_start_hd = t_scl_l;
+       t_stop_su = t_scl_l;
+       t_data_su = t_scl_l / 2;
+       t_data_hd = t_scl_l / 2;
+       t_sr_release = clk_cycle;
+
+       i2c_timing_s1 = t_start_su << 24 | t_start_hd << 16 | t_stop_su << 8;
+       i2c_timing_s2 = t_data_su << 24 | t_scl_l << 8 | t_scl_h << 0;
+       i2c_timing_s3 = div << 16 | t_sr_release << 0;
+       i2c_timing_sla = t_data_hd << 0;
+
+       dev_dbg(i2c->dev, "tSTART_SU: %X, tSTART_HD: %X, tSTOP_SU: %X\n",
+               t_start_su, t_start_hd, t_stop_su);
+       dev_dbg(i2c->dev, "tDATA_SU: %X, tSCL_L: %X, tSCL_H: %X\n",
+               t_data_su, t_scl_l, t_scl_h);
+       dev_dbg(i2c->dev, "nClkDiv: %X, tSR_RELEASE: %X\n",
+               div, t_sr_release);
+       dev_dbg(i2c->dev, "tDATA_HD: %X\n", t_data_hd);
+
+       if (mode == HSI2C_HIGH_SPD) {
+               writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_HS1);
+               writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_HS2);
+               writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_HS3);
+       } else {
+               writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_FS1);
+               writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_FS2);
+               writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_FS3);
+       }
+       writel(i2c_timing_sla, i2c->regs + HSI2C_TIMING_SLA);
+
+       return 0;
+}
+
+static int exynos5_hsi2c_clock_setup(struct exynos5_i2c *i2c)
+{
+       /*
+        * Configure the Fast speed timing values
+        * Even the High Speed mode initially starts with Fast mode
+        */
+       if (exynos5_i2c_set_timing(i2c, HSI2C_FAST_SPD)) {
+               dev_err(i2c->dev, "HSI2C FS Clock set up failed\n");
+               return -EINVAL;
+       }
+
+       /* configure the High speed timing values */
+       if (i2c->speed_mode == HSI2C_HIGH_SPD) {
+               if (exynos5_i2c_set_timing(i2c, HSI2C_HIGH_SPD)) {
+                       dev_err(i2c->dev, "HSI2C HS Clock set up failed\n");
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * exynos5_i2c_init: configures the controller for I2C functionality
+ * Programs I2C controller for Master mode operation
+ */
+static void exynos5_i2c_init(struct exynos5_i2c *i2c)
+{
+       u32 i2c_conf = readl(i2c->regs + HSI2C_CONF);
+       u32 i2c_timeout = readl(i2c->regs + HSI2C_TIMEOUT);
+
+       /* Clear to disable Timeout */
+       i2c_timeout &= ~HSI2C_TIMEOUT_EN;
+       writel(i2c_timeout, i2c->regs + HSI2C_TIMEOUT);
+
+       writel((HSI2C_FUNC_MODE_I2C | HSI2C_MASTER),
+                                       i2c->regs + HSI2C_CTL);
+       writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL);
+
+       if (i2c->speed_mode == HSI2C_HIGH_SPD) {
+               writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)),
+                                       i2c->regs + HSI2C_ADDR);
+               i2c_conf |= HSI2C_HS_MODE;
+       }
+
+       writel(i2c_conf | HSI2C_AUTO_MODE, i2c->regs + HSI2C_CONF);
+}
+
+static void exynos5_i2c_reset(struct exynos5_i2c *i2c)
+{
+       u32 i2c_ctl;
+
+       /* Set and clear the bit for reset */
+       i2c_ctl = readl(i2c->regs + HSI2C_CTL);
+       i2c_ctl |= HSI2C_SW_RST;
+       writel(i2c_ctl, i2c->regs + HSI2C_CTL);
+
+       i2c_ctl = readl(i2c->regs + HSI2C_CTL);
+       i2c_ctl &= ~HSI2C_SW_RST;
+       writel(i2c_ctl, i2c->regs + HSI2C_CTL);
+
+       /* We don't expect calculations to fail during the run */
+       exynos5_hsi2c_clock_setup(i2c);
+       /* Initialize the configure registers */
+       exynos5_i2c_init(i2c);
+}
+
+/*
+ * exynos5_i2c_irq: top level IRQ servicing routine
+ *
+ * INT_STATUS registers gives the interrupt details. Further,
+ * FIFO_STATUS or TRANS_STATUS registers are to be check for detailed
+ * state of the bus.
+ */
+static irqreturn_t exynos5_i2c_irq(int irqno, void *dev_id)
+{
+       struct exynos5_i2c *i2c = dev_id;
+       u32 fifo_level, int_status, fifo_status, trans_status;
+       unsigned char byte;
+       int len = 0;
+
+       i2c->state = -EINVAL;
+
+       spin_lock(&i2c->lock);
+
+       int_status = readl(i2c->regs + HSI2C_INT_STATUS);
+       writel(int_status, i2c->regs + HSI2C_INT_STATUS);
+       fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
+
+       /* handle interrupt related to the transfer status */
+       if (int_status & HSI2C_INT_I2C) {
+               trans_status = readl(i2c->regs + HSI2C_TRANS_STATUS);
+               if (trans_status & HSI2C_NO_DEV_ACK) {
+                       dev_dbg(i2c->dev, "No ACK from device\n");
+                       i2c->state = -ENXIO;
+                       goto stop;
+               } else if (trans_status & HSI2C_NO_DEV) {
+                       dev_dbg(i2c->dev, "No device\n");
+                       i2c->state = -ENXIO;
+                       goto stop;
+               } else if (trans_status & HSI2C_TRANS_ABORT) {
+                       dev_dbg(i2c->dev, "Deal with arbitration lose\n");
+                       i2c->state = -EAGAIN;
+                       goto stop;
+               } else if (trans_status & HSI2C_TIMEOUT_AUTO) {
+                       dev_dbg(i2c->dev, "Accessing device timed out\n");
+                       i2c->state = -EAGAIN;
+                       goto stop;
+               } else if (trans_status & HSI2C_TRANS_DONE) {
+                       i2c->trans_done = 1;
+                       i2c->state = 0;
+               }
+       }
+
+       if ((i2c->msg->flags & I2C_M_RD) && (int_status &
+                       (HSI2C_INT_TRAILING | HSI2C_INT_RX_ALMOSTFULL))) {
+               fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
+               fifo_level = HSI2C_RX_FIFO_LVL(fifo_status);
+               len = min(fifo_level, i2c->msg->len - i2c->msg_ptr);
+
+               while (len > 0) {
+                       byte = (unsigned char)
+                               readl(i2c->regs + HSI2C_RX_DATA);
+                       i2c->msg->buf[i2c->msg_ptr++] = byte;
+                       len--;
+               }
+               i2c->state = 0;
+       } else if (int_status & HSI2C_INT_TX_ALMOSTEMPTY) {
+               fifo_status = readl(i2c->regs + HSI2C_FIFO_STATUS);
+               fifo_level = HSI2C_TX_FIFO_LVL(fifo_status);
+
+               len = HSI2C_FIFO_MAX - fifo_level;
+               if (len > (i2c->msg->len - i2c->msg_ptr))
+                       len = i2c->msg->len - i2c->msg_ptr;
+
+               while (len > 0) {
+                       byte = i2c->msg->buf[i2c->msg_ptr++];
+                       writel(byte, i2c->regs + HSI2C_TX_DATA);
+                       len--;
+               }
+               i2c->state = 0;
+       }
+
+ stop:
+       if ((i2c->trans_done && (i2c->msg->len == i2c->msg_ptr)) ||
+           (i2c->state < 0)) {
+               writel(0, i2c->regs + HSI2C_INT_ENABLE);
+               exynos5_i2c_clr_pend_irq(i2c);
+               complete(&i2c->msg_complete);
+       }
+
+       spin_unlock(&i2c->lock);
+
+       return IRQ_HANDLED;
+}
+
+/*
+ * exynos5_i2c_wait_bus_idle
+ *
+ * Wait for the bus to go idle, indicated by the MASTER_BUSY bit being
+ * cleared.
+ *
+ * Returns -EBUSY if the bus cannot be bought to idle
+ */
+static int exynos5_i2c_wait_bus_idle(struct exynos5_i2c *i2c)
+{
+       unsigned long stop_time;
+       u32 trans_status;
+
+       /* wait for 100 milli seconds for the bus to be idle */
+       stop_time = jiffies + msecs_to_jiffies(100) + 1;
+       do {
+               trans_status = readl(i2c->regs + HSI2C_TRANS_STATUS);
+               if (!(trans_status & HSI2C_MASTER_BUSY))
+                       return 0;
+
+               usleep_range(50, 200);
+       } while (time_before(jiffies, stop_time));
+
+       return -EBUSY;
+}
+
+/*
+ * exynos5_i2c_message_start: Configures the bus and starts the xfer
+ * i2c: struct exynos5_i2c pointer for the current bus
+ * stop: Enables stop after transfer if set. Set for last transfer of
+ *       in the list of messages.
+ *
+ * Configures the bus for read/write function
+ * Sets chip address to talk to, message length to be sent.
+ * Enables appropriate interrupts and sends start xfer command.
+ */
+static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
+{
+       u32 i2c_ctl;
+       u32 int_en = HSI2C_INT_I2C_EN;
+       u32 i2c_auto_conf = 0;
+       u32 fifo_ctl;
+       unsigned long flags;
+
+       i2c_ctl = readl(i2c->regs + HSI2C_CTL);
+       i2c_ctl &= ~(HSI2C_TXCHON | HSI2C_RXCHON);
+       fifo_ctl = HSI2C_RXFIFO_EN | HSI2C_TXFIFO_EN;
+
+       if (i2c->msg->flags & I2C_M_RD) {
+               i2c_ctl |= HSI2C_RXCHON;
+
+               i2c_auto_conf = HSI2C_READ_WRITE;
+
+               fifo_ctl |= HSI2C_RXFIFO_TRIGGER_LEVEL(HSI2C_DEF_TXFIFO_LVL);
+               int_en |= (HSI2C_INT_RX_ALMOSTFULL_EN |
+                       HSI2C_INT_TRAILING_EN);
+       } else {
+               i2c_ctl |= HSI2C_TXCHON;
+
+               fifo_ctl |= HSI2C_TXFIFO_TRIGGER_LEVEL(HSI2C_DEF_RXFIFO_LVL);
+               int_en |= HSI2C_INT_TX_ALMOSTEMPTY_EN;
+       }
+
+       writel(HSI2C_SLV_ADDR_MAS(i2c->msg->addr), i2c->regs + HSI2C_ADDR);
+
+       writel(fifo_ctl, i2c->regs + HSI2C_FIFO_CTL);
+       writel(i2c_ctl, i2c->regs + HSI2C_CTL);
+
+
+       /*
+        * Enable interrupts before starting the transfer so that we don't
+        * miss any INT_I2C interrupts.
+        */
+       spin_lock_irqsave(&i2c->lock, flags);
+       writel(int_en, i2c->regs + HSI2C_INT_ENABLE);
+
+       if (stop == 1)
+               i2c_auto_conf |= HSI2C_STOP_AFTER_TRANS;
+       i2c_auto_conf |= i2c->msg->len;
+       i2c_auto_conf |= HSI2C_MASTER_RUN;
+       writel(i2c_auto_conf, i2c->regs + HSI2C_AUTO_CONF);
+       spin_unlock_irqrestore(&i2c->lock, flags);
+}
+
+static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c,
+                             struct i2c_msg *msgs, int stop)
+{
+       unsigned long timeout;
+       int ret;
+
+       i2c->msg = msgs;
+       i2c->msg_ptr = 0;
+       i2c->trans_done = 0;
+
+       reinit_completion(&i2c->msg_complete);
+
+       exynos5_i2c_message_start(i2c, stop);
+
+       timeout = wait_for_completion_timeout(&i2c->msg_complete,
+                                             EXYNOS5_I2C_TIMEOUT);
+       if (timeout == 0)
+               ret = -ETIMEDOUT;
+       else
+               ret = i2c->state;
+
+       /*
+        * If this is the last message to be transfered (stop == 1)
+        * Then check if the bus can be brought back to idle.
+        */
+       if (ret == 0 && stop)
+               ret = exynos5_i2c_wait_bus_idle(i2c);
+
+       if (ret < 0) {
+               exynos5_i2c_reset(i2c);
+               if (ret == -ETIMEDOUT)
+                       dev_warn(i2c->dev, "%s timeout\n",
+                                (msgs->flags & I2C_M_RD) ? "rx" : "tx");
+       }
+
+       /* Return the state as in interrupt routine */
+       return ret;
+}
+
+static int exynos5_i2c_xfer(struct i2c_adapter *adap,
+                       struct i2c_msg *msgs, int num)
+{
+       struct exynos5_i2c *i2c = (struct exynos5_i2c *)adap->algo_data;
+       int i = 0, ret = 0, stop = 0;
+
+       if (i2c->suspended) {
+               dev_err(i2c->dev, "HS-I2C is not initialzed.\n");
+               return -EIO;
+       }
+
+       clk_prepare_enable(i2c->clk);
+
+       for (i = 0; i < num; i++, msgs++) {
+               stop = (i == num - 1);
+
+               ret = exynos5_i2c_xfer_msg(i2c, msgs, stop);
+
+               if (ret < 0)
+                       goto out;
+       }
+
+       if (i == num) {
+               ret = num;
+       } else {
+               /* Only one message, cannot access the device */
+               if (i == 1)
+                       ret = -EREMOTEIO;
+               else
+                       ret = i;
+
+               dev_warn(i2c->dev, "xfer message failed\n");
+       }
+
+ out:
+       clk_disable_unprepare(i2c->clk);
+       return ret;
+}
+
+static u32 exynos5_i2c_func(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
+}
+
+static const struct i2c_algorithm exynos5_i2c_algorithm = {
+       .master_xfer            = exynos5_i2c_xfer,
+       .functionality          = exynos5_i2c_func,
+};
+
+static int exynos5_i2c_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct exynos5_i2c *i2c;
+       struct resource *mem;
+       unsigned int op_clock;
+       int ret;
+
+       i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL);
+       if (!i2c) {
+               dev_err(&pdev->dev, "no memory for state\n");
+               return -ENOMEM;
+       }
+
+       if (of_property_read_u32(np, "clock-frequency", &op_clock)) {
+               i2c->speed_mode = HSI2C_FAST_SPD;
+               i2c->fs_clock = HSI2C_FS_TX_CLOCK;
+       } else {
+               if (op_clock >= HSI2C_HS_TX_CLOCK) {
+                       i2c->speed_mode = HSI2C_HIGH_SPD;
+                       i2c->fs_clock = HSI2C_FS_TX_CLOCK;
+                       i2c->hs_clock = op_clock;
+               } else {
+                       i2c->speed_mode = HSI2C_FAST_SPD;
+                       i2c->fs_clock = op_clock;
+               }
+       }
+
+       strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name));
+       i2c->adap.owner   = THIS_MODULE;
+       i2c->adap.algo    = &exynos5_i2c_algorithm;
+       i2c->adap.retries = 3;
+
+       i2c->dev = &pdev->dev;
+       i2c->clk = devm_clk_get(&pdev->dev, "hsi2c");
+       if (IS_ERR(i2c->clk)) {
+               dev_err(&pdev->dev, "cannot get clock\n");
+               return -ENOENT;
+       }
+
+       clk_prepare_enable(i2c->clk);
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       i2c->regs = devm_ioremap_resource(&pdev->dev, mem);
+       if (IS_ERR(i2c->regs)) {
+               ret = PTR_ERR(i2c->regs);
+               goto err_clk;
+       }
+
+       i2c->adap.dev.of_node = np;
+       i2c->adap.algo_data = i2c;
+       i2c->adap.dev.parent = &pdev->dev;
+
+       /* Clear pending interrupts from u-boot or misc causes */
+       exynos5_i2c_clr_pend_irq(i2c);
+
+       spin_lock_init(&i2c->lock);
+       init_completion(&i2c->msg_complete);
+
+       i2c->irq = ret = platform_get_irq(pdev, 0);
+       if (ret <= 0) {
+               dev_err(&pdev->dev, "cannot find HS-I2C IRQ\n");
+               ret = -EINVAL;
+               goto err_clk;
+       }
+
+       ret = devm_request_irq(&pdev->dev, i2c->irq, exynos5_i2c_irq,
+                               IRQF_NO_SUSPEND | IRQF_ONESHOT,
+                               dev_name(&pdev->dev), i2c);
+
+       if (ret != 0) {
+               dev_err(&pdev->dev, "cannot request HS-I2C IRQ %d\n", i2c->irq);
+               goto err_clk;
+       }
+
+       ret = exynos5_hsi2c_clock_setup(i2c);
+       if (ret)
+               goto err_clk;
+
+       exynos5_i2c_init(i2c);
+
+       ret = i2c_add_adapter(&i2c->adap);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed to add bus to i2c core\n");
+               goto err_clk;
+       }
+
+       platform_set_drvdata(pdev, i2c);
+
+ err_clk:
+       clk_disable_unprepare(i2c->clk);
+       return ret;
+}
+
+static int exynos5_i2c_remove(struct platform_device *pdev)
+{
+       struct exynos5_i2c *i2c = platform_get_drvdata(pdev);
+
+       i2c_del_adapter(&i2c->adap);
+
+       return 0;
+}
+
+static int exynos5_i2c_suspend_noirq(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct exynos5_i2c *i2c = platform_get_drvdata(pdev);
+
+       i2c->suspended = 1;
+
+       return 0;
+}
+
+static int exynos5_i2c_resume_noirq(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct exynos5_i2c *i2c = platform_get_drvdata(pdev);
+       int ret = 0;
+
+       clk_prepare_enable(i2c->clk);
+
+       ret = exynos5_hsi2c_clock_setup(i2c);
+       if (ret) {
+               clk_disable_unprepare(i2c->clk);
+               return ret;
+       }
+
+       exynos5_i2c_init(i2c);
+       clk_disable_unprepare(i2c->clk);
+       i2c->suspended = 0;
+
+       return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(exynos5_i2c_dev_pm_ops, exynos5_i2c_suspend_noirq,
+                        exynos5_i2c_resume_noirq);
+
+static struct platform_driver exynos5_i2c_driver = {
+       .probe          = exynos5_i2c_probe,
+       .remove         = exynos5_i2c_remove,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "exynos5-hsi2c",
+               .pm     = &exynos5_i2c_dev_pm_ops,
+               .of_match_table = exynos5_i2c_match,
+       },
+};
+
+module_platform_driver(exynos5_i2c_driver);
+
+MODULE_DESCRIPTION("Exynos5 HS-I2C Bus driver");
+MODULE_AUTHOR("Naveen Krishna Chatradhi, <ch.naveen@samsung.com>");
+MODULE_AUTHOR("Taekgyun Ko, <taeggyun.ko@samsung.com>");
+MODULE_LICENSE("GPL v2");
index bfa02c6c2ddaf01b03a9a5121c2ddcf122f9a3e2..d9f7e186a4c7577c3f77eaf3905547f4a189a7b8 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
+#include <linux/of.h>
 #include <linux/of_gpio.h>
 
 struct i2c_gpio_private_data {
index 4296d1721272bd3fa077944a63e5708000b6a4dd..737e298668878f6b0c7d7421374248b596839668 100644 (file)
@@ -59,6 +59,7 @@
   Wellsburg (PCH) MS    0x8d7e     32     hard     yes     yes     yes
   Wellsburg (PCH) MS    0x8d7f     32     hard     yes     yes     yes
   Coleto Creek (PCH)    0x23b0     32     hard     yes     yes     yes
+  Wildcat Point-LP (PCH)   0x9ca2     32     hard     yes     yes     yes
 
   Features supported by this driver:
   Software PEC                     no
 #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1        0x8d7e
 #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2        0x8d7f
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
+#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS      0x9ca2
 
 struct i801_mux_config {
        char *gpio_chip;
@@ -819,6 +821,7 @@ static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
        { 0, }
 };
 
index d3e9cc3153a973dc62f99d7d607e003179f41f9d..8be7e42aa4de88ba3f00ef2275455b27fa5cdf96 100644 (file)
@@ -911,7 +911,7 @@ static struct platform_driver mv64xxx_i2c_driver = {
        .driver = {
                .owner  = THIS_MODULE,
                .name   = MV64XXX_I2C_CTLR_NAME,
-               .of_match_table = of_match_ptr(mv64xxx_i2c_of_match_table),
+               .of_match_table = mv64xxx_i2c_of_match_table,
        },
 };
 
index 3aedd86a64682dcb775a040210a980c6f5679e12..0cde4e6ab2b2f127c450088c88f3775d337c6f6a 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Freescale MXS I2C bus driver
  *
+ * Copyright (C) 2012-2013 Marek Vasut <marex@denx.de>
  * Copyright (C) 2011-2012 Wolfram Sang, Pengutronix e.K.
  *
  * based on a (non-working) driver which was:
 
 #define MXS_I2C_CTRL0          (0x00)
 #define MXS_I2C_CTRL0_SET      (0x04)
+#define MXS_I2C_CTRL0_CLR      (0x08)
 
 #define MXS_I2C_CTRL0_SFTRST                   0x80000000
 #define MXS_I2C_CTRL0_RUN                      0x20000000
 #define MXS_I2C_CTRL0_SEND_NAK_ON_LAST         0x02000000
+#define MXS_I2C_CTRL0_PIO_MODE                 0x01000000
 #define MXS_I2C_CTRL0_RETAIN_CLOCK             0x00200000
 #define MXS_I2C_CTRL0_POST_SEND_STOP           0x00100000
 #define MXS_I2C_CTRL0_PRE_SEND_START           0x00080000
 #define MXS_I2C_CTRL1_SLAVE_IRQ                        0x01
 
 #define MXS_I2C_STAT           (0x50)
+#define MXS_I2C_STAT_GOT_A_NAK                 0x10000000
 #define MXS_I2C_STAT_BUS_BUSY                  0x00000800
 #define MXS_I2C_STAT_CLK_GEN_BUSY              0x00000400
 
-#define MXS_I2C_DATA           (0xa0)
+#define MXS_I2C_DATA(i2c)      ((i2c->dev_type == MXS_I2C_V1) ? 0x60 : 0xa0)
 
-#define MXS_I2C_DEBUG0         (0xb0)
-#define MXS_I2C_DEBUG0_CLR     (0xb8)
+#define MXS_I2C_DEBUG0_CLR(i2c)        ((i2c->dev_type == MXS_I2C_V1) ? 0x78 : 0xb8)
 
 #define MXS_I2C_DEBUG0_DMAREQ  0x80000000
 
 #define MXS_CMD_I2C_READ       (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \
                                 MXS_I2C_CTRL0_MASTER_MODE)
 
+enum mxs_i2c_devtype {
+       MXS_I2C_UNKNOWN = 0,
+       MXS_I2C_V1,
+       MXS_I2C_V2,
+};
+
 /**
  * struct mxs_i2c_dev - per device, private MXS-I2C data
  *
  * @dev: driver model device node
+ * @dev_type: distinguish i.MX23/i.MX28 features
  * @regs: IO registers pointer
  * @cmd_complete: completion object for transaction wait
  * @cmd_err: error code for last transaction
  */
 struct mxs_i2c_dev {
        struct device *dev;
+       enum mxs_i2c_devtype dev_type;
        void __iomem *regs;
        struct completion cmd_complete;
        int cmd_err;
@@ -291,48 +302,11 @@ write_init_pio_fail:
        return -EINVAL;
 }
 
-static int mxs_i2c_pio_wait_dmareq(struct mxs_i2c_dev *i2c)
+static int mxs_i2c_pio_wait_xfer_end(struct mxs_i2c_dev *i2c)
 {
        unsigned long timeout = jiffies + msecs_to_jiffies(1000);
 
-       while (!(readl(i2c->regs + MXS_I2C_DEBUG0) &
-               MXS_I2C_DEBUG0_DMAREQ)) {
-               if (time_after(jiffies, timeout))
-                       return -ETIMEDOUT;
-               cond_resched();
-       }
-
-       return 0;
-}
-
-static int mxs_i2c_pio_wait_cplt(struct mxs_i2c_dev *i2c, int last)
-{
-       unsigned long timeout = jiffies + msecs_to_jiffies(1000);
-
-       /*
-        * We do not use interrupts in the PIO mode. Due to the
-        * maximum transfer length being 8 bytes in PIO mode, the
-        * overhead of interrupt would be too large and this would
-        * neglect the gain from using the PIO mode.
-        */
-
-       while (!(readl(i2c->regs + MXS_I2C_CTRL1) &
-               MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ)) {
-               if (time_after(jiffies, timeout))
-                       return -ETIMEDOUT;
-               cond_resched();
-       }
-
-       writel(MXS_I2C_CTRL1_DATA_ENGINE_CMPLT_IRQ,
-               i2c->regs + MXS_I2C_CTRL1_CLR);
-
-       /*
-        * When ending a transfer with a stop, we have to wait for the bus to
-        * go idle before we report the transfer as completed. Otherwise the
-        * start of the next transfer may race with the end of the current one.
-        */
-       while (last && (readl(i2c->regs + MXS_I2C_STAT) &
-                       (MXS_I2C_STAT_BUS_BUSY | MXS_I2C_STAT_CLK_GEN_BUSY))) {
+       while (readl(i2c->regs + MXS_I2C_CTRL0) & MXS_I2C_CTRL0_RUN) {
                if (time_after(jiffies, timeout))
                        return -ETIMEDOUT;
                cond_resched();
@@ -370,106 +344,215 @@ static void mxs_i2c_pio_trigger_cmd(struct mxs_i2c_dev *i2c, u32 cmd)
        writel(reg, i2c->regs + MXS_I2C_CTRL0);
 }
 
+/*
+ * Start WRITE transaction on the I2C bus. By studying i.MX23 datasheet,
+ * CTRL0::PIO_MODE bit description clarifies the order in which the registers
+ * must be written during PIO mode operation. First, the CTRL0 register has
+ * to be programmed with all the necessary bits but the RUN bit. Then the
+ * payload has to be written into the DATA register. Finally, the transmission
+ * is executed by setting the RUN bit in CTRL0.
+ */
+static void mxs_i2c_pio_trigger_write_cmd(struct mxs_i2c_dev *i2c, u32 cmd,
+                                         u32 data)
+{
+       writel(cmd, i2c->regs + MXS_I2C_CTRL0);
+
+       if (i2c->dev_type == MXS_I2C_V1)
+               writel(MXS_I2C_CTRL0_PIO_MODE, i2c->regs + MXS_I2C_CTRL0_SET);
+
+       writel(data, i2c->regs + MXS_I2C_DATA(i2c));
+       writel(MXS_I2C_CTRL0_RUN, i2c->regs + MXS_I2C_CTRL0_SET);
+}
+
 static int mxs_i2c_pio_setup_xfer(struct i2c_adapter *adap,
                        struct i2c_msg *msg, uint32_t flags)
 {
        struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
        uint32_t addr_data = msg->addr << 1;
        uint32_t data = 0;
-       int i, shifts_left, ret;
+       int i, ret, xlen = 0, xmit = 0;
+       uint32_t start;
 
        /* Mute IRQs coming from this block. */
        writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_CLR);
 
+       /*
+        * MX23 idea:
+        * - Enable CTRL0::PIO_MODE (1 << 24)
+        * - Enable CTRL1::ACK_MODE (1 << 27)
+        *
+        * WARNING! The MX23 is broken in some way, even if it claims
+        * to support PIO, when we try to transfer any amount of data
+        * that is not aligned to 4 bytes, the DMA engine will have
+        * bits in DEBUG1::DMA_BYTES_ENABLES still set even after the
+        * transfer. This in turn will mess up the next transfer as
+        * the block it emit one byte write onto the bus terminated
+        * with a NAK+STOP. A possible workaround is to reset the IP
+        * block after every PIO transmission, which might just work.
+        *
+        * NOTE: The CTRL0::PIO_MODE description is important, since
+        * it outlines how the PIO mode is really supposed to work.
+        */
        if (msg->flags & I2C_M_RD) {
+               /*
+                * PIO READ transfer:
+                *
+                * This transfer MUST be limited to 4 bytes maximum. It is not
+                * possible to transfer more than four bytes via PIO, since we
+                * can not in any way make sure we can read the data from the
+                * DATA register fast enough. Besides, the RX FIFO is only four
+                * bytes deep, thus we can only really read up to four bytes at
+                * time. Finally, there is no bit indicating us that new data
+                * arrived at the FIFO and can thus be fetched from the DATA
+                * register.
+                */
+               BUG_ON(msg->len > 4);
+
                addr_data |= I2C_SMBUS_READ;
 
                /* SELECT command. */
-               mxs_i2c_pio_trigger_cmd(i2c, MXS_CMD_I2C_SELECT);
-
-               ret = mxs_i2c_pio_wait_dmareq(i2c);
-               if (ret)
-                       return ret;
-
-               writel(addr_data, i2c->regs + MXS_I2C_DATA);
-               writel(MXS_I2C_DEBUG0_DMAREQ, i2c->regs + MXS_I2C_DEBUG0_CLR);
+               mxs_i2c_pio_trigger_write_cmd(i2c, MXS_CMD_I2C_SELECT,
+                                             addr_data);
 
-               ret = mxs_i2c_pio_wait_cplt(i2c, 0);
-               if (ret)
-                       return ret;
-
-               if (mxs_i2c_pio_check_error_state(i2c))
+               ret = mxs_i2c_pio_wait_xfer_end(i2c);
+               if (ret) {
+                       dev_err(i2c->dev,
+                               "PIO: Failed to send SELECT command!\n");
                        goto cleanup;
+               }
 
                /* READ command. */
                mxs_i2c_pio_trigger_cmd(i2c,
                                        MXS_CMD_I2C_READ | flags |
                                        MXS_I2C_CTRL0_XFER_COUNT(msg->len));
 
+               ret = mxs_i2c_pio_wait_xfer_end(i2c);
+               if (ret) {
+                       dev_err(i2c->dev,
+                               "PIO: Failed to send SELECT command!\n");
+                       goto cleanup;
+               }
+
+               data = readl(i2c->regs + MXS_I2C_DATA(i2c));
                for (i = 0; i < msg->len; i++) {
-                       if ((i & 3) == 0) {
-                               ret = mxs_i2c_pio_wait_dmareq(i2c);
-                               if (ret)
-                                       return ret;
-                               data = readl(i2c->regs + MXS_I2C_DATA);
-                               writel(MXS_I2C_DEBUG0_DMAREQ,
-                                      i2c->regs + MXS_I2C_DEBUG0_CLR);
-                       }
                        msg->buf[i] = data & 0xff;
                        data >>= 8;
                }
        } else {
+               /*
+                * PIO WRITE transfer:
+                *
+                * The code below implements clock stretching to circumvent
+                * the possibility of kernel not being able to supply data
+                * fast enough. It is possible to transfer arbitrary amount
+                * of data using PIO write.
+                */
                addr_data |= I2C_SMBUS_WRITE;
 
-               /* WRITE command. */
-               mxs_i2c_pio_trigger_cmd(i2c,
-                                       MXS_CMD_I2C_WRITE | flags |
-                                       MXS_I2C_CTRL0_XFER_COUNT(msg->len + 1));
-
                /*
                 * The LSB of data buffer is the first byte blasted across
                 * the bus. Higher order bytes follow. Thus the following
                 * filling schematic.
                 */
+
                data = addr_data << 24;
+
+               /* Start the transfer with START condition. */
+               start = MXS_I2C_CTRL0_PRE_SEND_START;
+
+               /* If the transfer is long, use clock stretching. */
+               if (msg->len > 3)
+                       start |= MXS_I2C_CTRL0_RETAIN_CLOCK;
+
                for (i = 0; i < msg->len; i++) {
                        data >>= 8;
                        data |= (msg->buf[i] << 24);
-                       if ((i & 3) == 2) {
-                               ret = mxs_i2c_pio_wait_dmareq(i2c);
-                               if (ret)
-                                       return ret;
-                               writel(data, i2c->regs + MXS_I2C_DATA);
-                               writel(MXS_I2C_DEBUG0_DMAREQ,
-                                      i2c->regs + MXS_I2C_DEBUG0_CLR);
+
+                       xmit = 0;
+
+                       /* This is the last transfer of the message. */
+                       if (i + 1 == msg->len) {
+                               /* Add optional STOP flag. */
+                               start |= flags;
+                               /* Remove RETAIN_CLOCK bit. */
+                               start &= ~MXS_I2C_CTRL0_RETAIN_CLOCK;
+                               xmit = 1;
                        }
-               }
 
-               shifts_left = 24 - (i & 3) * 8;
-               if (shifts_left) {
-                       data >>= shifts_left;
-                       ret = mxs_i2c_pio_wait_dmareq(i2c);
-                       if (ret)
-                               return ret;
-                       writel(data, i2c->regs + MXS_I2C_DATA);
+                       /* Four bytes are ready in the "data" variable. */
+                       if ((i & 3) == 2)
+                               xmit = 1;
+
+                       /* Nothing interesting happened, continue stuffing. */
+                       if (!xmit)
+                               continue;
+
+                       /*
+                        * Compute the size of the transfer and shift the
+                        * data accordingly.
+                        *
+                        * i = (4k + 0) .... xlen = 2
+                        * i = (4k + 1) .... xlen = 3
+                        * i = (4k + 2) .... xlen = 4
+                        * i = (4k + 3) .... xlen = 1
+                        */
+
+                       if ((i % 4) == 3)
+                               xlen = 1;
+                       else
+                               xlen = (i % 4) + 2;
+
+                       data >>= (4 - xlen) * 8;
+
+                       dev_dbg(i2c->dev,
+                               "PIO: len=%i pos=%i total=%i [W%s%s%s]\n",
+                               xlen, i, msg->len,
+                               start & MXS_I2C_CTRL0_PRE_SEND_START ? "S" : "",
+                               start & MXS_I2C_CTRL0_POST_SEND_STOP ? "E" : "",
+                               start & MXS_I2C_CTRL0_RETAIN_CLOCK ? "C" : "");
+
                        writel(MXS_I2C_DEBUG0_DMAREQ,
-                              i2c->regs + MXS_I2C_DEBUG0_CLR);
+                              i2c->regs + MXS_I2C_DEBUG0_CLR(i2c));
+
+                       mxs_i2c_pio_trigger_write_cmd(i2c,
+                               start | MXS_I2C_CTRL0_MASTER_MODE |
+                               MXS_I2C_CTRL0_DIRECTION |
+                               MXS_I2C_CTRL0_XFER_COUNT(xlen), data);
+
+                       /* The START condition is sent only once. */
+                       start &= ~MXS_I2C_CTRL0_PRE_SEND_START;
+
+                       /* Wait for the end of the transfer. */
+                       ret = mxs_i2c_pio_wait_xfer_end(i2c);
+                       if (ret) {
+                               dev_err(i2c->dev,
+                                       "PIO: Failed to finish WRITE cmd!\n");
+                               break;
+                       }
+
+                       /* Check NAK here. */
+                       ret = readl(i2c->regs + MXS_I2C_STAT) &
+                                   MXS_I2C_STAT_GOT_A_NAK;
+                       if (ret) {
+                               ret = -ENXIO;
+                               goto cleanup;
+                       }
                }
        }
 
-       ret = mxs_i2c_pio_wait_cplt(i2c, flags & MXS_I2C_CTRL0_POST_SEND_STOP);
-       if (ret)
-               return ret;
-
        /* make sure we capture any occurred error into cmd_err */
-       mxs_i2c_pio_check_error_state(i2c);
+       ret = mxs_i2c_pio_check_error_state(i2c);
 
 cleanup:
        /* Clear any dangling IRQs and re-enable interrupts. */
        writel(MXS_I2C_IRQ_MASK, i2c->regs + MXS_I2C_CTRL1_CLR);
        writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET);
 
-       return 0;
+       /* Clear the PIO_MODE on i.MX23 */
+       if (i2c->dev_type == MXS_I2C_V1)
+               writel(MXS_I2C_CTRL0_PIO_MODE, i2c->regs + MXS_I2C_CTRL0_CLR);
+
+       return ret;
 }
 
 /*
@@ -479,8 +562,9 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
                                int stop)
 {
        struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
-       int ret, err;
+       int ret;
        int flags;
+       int use_pio = 0;
 
        flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0;
 
@@ -491,19 +575,21 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
                return -EINVAL;
 
        /*
-        * The current boundary to select between PIO/DMA transfer method
-        * is set to 8 bytes, transfers shorter than 8 bytes are transfered
-        * using PIO mode while longer transfers use DMA. The 8 byte border is
-        * based on this empirical measurement and a lot of previous frobbing.
+        * The MX28 I2C IP block can only do PIO READ for transfer of to up
+        * 4 bytes of length. The write transfer is not limited as it can use
+        * clock stretching to avoid FIFO underruns.
         */
+       if ((msg->flags & I2C_M_RD) && (msg->len <= 4))
+               use_pio = 1;
+       if (!(msg->flags & I2C_M_RD) && (msg->len < 7))
+               use_pio = 1;
+
        i2c->cmd_err = 0;
-       if (0) {        /* disable PIO mode until a proper fix is made */
+       if (use_pio) {
                ret = mxs_i2c_pio_setup_xfer(adap, msg, flags);
-               if (ret) {
-                       err = mxs_i2c_reset(i2c);
-                       if (err)
-                               return err;
-               }
+               /* No need to reset the block if NAK was received. */
+               if (ret && (ret != -ENXIO))
+                       mxs_i2c_reset(i2c);
        } else {
                reinit_completion(&i2c->cmd_complete);
                ret = mxs_i2c_dma_setup_xfer(adap, msg, flags);
@@ -514,9 +600,11 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
                                                msecs_to_jiffies(1000));
                if (ret == 0)
                        goto timeout;
+
+               ret = i2c->cmd_err;
        }
 
-       if (i2c->cmd_err == -ENXIO) {
+       if (ret == -ENXIO) {
                /*
                 * If the transfer fails with a NAK from the slave the
                 * controller halts until it gets told to return to idle state.
@@ -525,7 +613,19 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
                       i2c->regs + MXS_I2C_CTRL1_SET);
        }
 
-       ret = i2c->cmd_err;
+       /*
+        * WARNING!
+        * The i.MX23 is strange. After each and every operation, it's I2C IP
+        * block must be reset, otherwise the IP block will misbehave. This can
+        * be observed on the bus by the block sending out one single byte onto
+        * the bus. In case such an error happens, bit 27 will be set in the
+        * DEBUG0 register. This bit is not documented in the i.MX23 datasheet
+        * and is marked as "TBD" instead. To reset this bit to a correct state,
+        * reset the whole block. Since the block reset does not take long, do
+        * reset the block after every transfer to play safe.
+        */
+       if (i2c->dev_type == MXS_I2C_V1)
+               mxs_i2c_reset(i2c);
 
        dev_dbg(i2c->dev, "Done with err=%d\n", ret);
 
@@ -680,8 +780,28 @@ static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
        return 0;
 }
 
+static struct platform_device_id mxs_i2c_devtype[] = {
+       {
+               .name = "imx23-i2c",
+               .driver_data = MXS_I2C_V1,
+       }, {
+               .name = "imx28-i2c",
+               .driver_data = MXS_I2C_V2,
+       }, { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, mxs_i2c_devtype);
+
+static const struct of_device_id mxs_i2c_dt_ids[] = {
+       { .compatible = "fsl,imx23-i2c", .data = &mxs_i2c_devtype[0], },
+       { .compatible = "fsl,imx28-i2c", .data = &mxs_i2c_devtype[1], },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mxs_i2c_dt_ids);
+
 static int mxs_i2c_probe(struct platform_device *pdev)
 {
+       const struct of_device_id *of_id =
+                               of_match_device(mxs_i2c_dt_ids, &pdev->dev);
        struct device *dev = &pdev->dev;
        struct mxs_i2c_dev *i2c;
        struct i2c_adapter *adap;
@@ -693,6 +813,11 @@ static int mxs_i2c_probe(struct platform_device *pdev)
        if (!i2c)
                return -ENOMEM;
 
+       if (of_id) {
+               const struct platform_device_id *device_id = of_id->data;
+               i2c->dev_type = device_id->driver_data;
+       }
+
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        irq = platform_get_irq(pdev, 0);
 
@@ -768,12 +893,6 @@ static int mxs_i2c_remove(struct platform_device *pdev)
        return 0;
 }
 
-static const struct of_device_id mxs_i2c_dt_ids[] = {
-       { .compatible = "fsl,imx28-i2c", },
-       { /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(of, mxs_i2c_dt_ids);
-
 static struct platform_driver mxs_i2c_driver = {
        .driver = {
                   .name = DRIVER_NAME,
@@ -796,6 +915,7 @@ static void __exit mxs_i2c_exit(void)
 }
 module_exit(mxs_i2c_exit);
 
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
 MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
 MODULE_DESCRIPTION("MXS I2C Bus Driver");
 MODULE_LICENSE("GPL");
index 1a9ea25f23142847e1ea57cbd53cdb39cff34322..c9a352f0a9a50cf812aa73ba168987a98ee080ea 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #define I2C_PNX_TIMEOUT_DEFAULT                10 /* msec */
 #define I2C_PNX_SPEED_KHZ_DEFAULT      100
index d2fe11da5e82a43cdc80c9fc9446aeb1e7c7fa0b..2c2fd7c2b116624f737352fb6ea5dee55ff3cad3 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/i2c/i2c-rcar.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
@@ -102,8 +103,8 @@ enum {
 #define ID_NACK                (1 << 4)
 
 enum rcar_i2c_type {
-       I2C_RCAR_H1,
-       I2C_RCAR_H2,
+       I2C_RCAR_GEN1,
+       I2C_RCAR_GEN2,
 };
 
 struct rcar_i2c_priv {
@@ -226,22 +227,23 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
                                    u32 bus_speed,
                                    struct device *dev)
 {
-       struct clk *clkp = clk_get(NULL, "peripheral_clk");
+       struct clk *clkp = clk_get(dev, NULL);
        u32 scgd, cdf;
        u32 round, ick;
        u32 scl;
        u32 cdf_width;
+       unsigned long rate;
 
-       if (!clkp) {
-               dev_err(dev, "there is no peripheral_clk\n");
-               return -EIO;
+       if (IS_ERR(clkp)) {
+               dev_err(dev, "couldn't get clock\n");
+               return PTR_ERR(clkp);
        }
 
        switch (priv->devtype) {
-       case I2C_RCAR_H1:
+       case I2C_RCAR_GEN1:
                cdf_width = 2;
                break;
-       case I2C_RCAR_H2:
+       case I2C_RCAR_GEN2:
                cdf_width = 3;
                break;
        default:
@@ -264,15 +266,14 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
         * clkp : peripheral_clk
         * F[]  : integer up-valuation
         */
-       for (cdf = 0; cdf < (1 << cdf_width); cdf++) {
-               ick = clk_get_rate(clkp) / (1 + cdf);
-               if (ick < 20000000)
-                       goto ick_find;
+       rate = clk_get_rate(clkp);
+       cdf = rate / 20000000;
+       if (cdf >= 1 << cdf_width) {
+               dev_err(dev, "Input clock %lu too high\n", rate);
+               return -EIO;
        }
-       dev_err(dev, "there is no best CDF\n");
-       return -EIO;
+       ick = rate / (cdf + 1);
 
-ick_find:
        /*
         * it is impossible to calculate large scale
         * number on u32. separate it
@@ -290,6 +291,12 @@ ick_find:
         *
         * Calculation result (= SCL) should be less than
         * bus_speed for hardware safety
+        *
+        * We could use something along the lines of
+        *      div = ick / (bus_speed + 1) + 1;
+        *      scgd = (div - 20 - round + 7) / 8;
+        *      scl = ick / (20 + (scgd * 8) + round);
+        * (not fully verified) but that would get pretty involved
         */
        for (scgd = 0; scgd < 0x40; scgd++) {
                scl = ick / (20 + (scgd * 8) + round);
@@ -306,7 +313,7 @@ scgd_find:
        /*
         * keep icccr value
         */
-       priv->icccr = (scgd << (cdf_width) | cdf);
+       priv->icccr = scgd << cdf_width | cdf;
 
        return 0;
 }
@@ -632,6 +639,15 @@ static const struct i2c_algorithm rcar_i2c_algo = {
        .functionality  = rcar_i2c_func,
 };
 
+static const struct of_device_id rcar_i2c_dt_ids[] = {
+       { .compatible = "renesas,i2c-rcar", .data = (void *)I2C_RCAR_GEN1 },
+       { .compatible = "renesas,i2c-r8a7778", .data = (void *)I2C_RCAR_GEN1 },
+       { .compatible = "renesas,i2c-r8a7779", .data = (void *)I2C_RCAR_GEN1 },
+       { .compatible = "renesas,i2c-r8a7790", .data = (void *)I2C_RCAR_GEN2 },
+       {},
+};
+MODULE_DEVICE_TABLE(of, rcar_i2c_dt_ids);
+
 static int rcar_i2c_probe(struct platform_device *pdev)
 {
        struct i2c_rcar_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -649,10 +665,15 @@ static int rcar_i2c_probe(struct platform_device *pdev)
        }
 
        bus_speed = 100000; /* default 100 kHz */
-       if (pdata && pdata->bus_speed)
+       ret = of_property_read_u32(dev->of_node, "clock-frequency", &bus_speed);
+       if (ret < 0 && pdata && pdata->bus_speed)
                bus_speed = pdata->bus_speed;
 
-       priv->devtype = platform_get_device_id(pdev)->driver_data;
+       if (pdev->dev.of_node)
+               priv->devtype = (long)of_match_device(rcar_i2c_dt_ids,
+                                                     dev)->data;
+       else
+               priv->devtype = platform_get_device_id(pdev)->driver_data;
 
        ret = rcar_i2c_clock_calculate(priv, bus_speed, dev);
        if (ret < 0)
@@ -673,6 +694,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
        adap->class             = I2C_CLASS_HWMON | I2C_CLASS_SPD;
        adap->retries           = 3;
        adap->dev.parent        = dev;
+       adap->dev.of_node       = dev->of_node;
        i2c_set_adapdata(adap, priv);
        strlcpy(adap->name, pdev->name, sizeof(adap->name));
 
@@ -709,9 +731,9 @@ static int rcar_i2c_remove(struct platform_device *pdev)
 }
 
 static struct platform_device_id rcar_i2c_id_table[] = {
-       { "i2c-rcar",           I2C_RCAR_H1 },
-       { "i2c-rcar_h1",        I2C_RCAR_H1 },
-       { "i2c-rcar_h2",        I2C_RCAR_H2 },
+       { "i2c-rcar",           I2C_RCAR_GEN1 },
+       { "i2c-rcar_gen1",      I2C_RCAR_GEN1 },
+       { "i2c-rcar_gen2",      I2C_RCAR_GEN2 },
        {},
 };
 MODULE_DEVICE_TABLE(platform, rcar_i2c_id_table);
@@ -720,6 +742,7 @@ static struct platform_driver rcar_i2c_driver = {
        .driver = {
                .name   = "i2c-rcar",
                .owner  = THIS_MODULE,
+               .of_match_table = rcar_i2c_dt_ids,
        },
        .probe          = rcar_i2c_probe,
        .remove         = rcar_i2c_remove,
index 3747b9bf67d6440f684bcff945a2a85b93f6fe6c..bf8fb94ebc5dd116eae9eca60fa7276bdbad9b9f 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/cpufreq.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/pinctrl/consumer.h>
 
index c447e8d40b78fb5cc3d58b0fb7b48ffff066c28a..599235514138564ba2db1befc6b711655420cf16 100644 (file)
@@ -223,7 +223,7 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
                goto out;
 
        obj = pkg->package.elements + 1;
-       if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) {
+       if (obj->type != ACPI_TYPE_INTEGER) {
                ACPI_ERROR((AE_INFO, "Invalid argument type"));
                result = -EIO;
                goto out;
@@ -235,7 +235,7 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
        case I2C_SMBUS_BYTE:
        case I2C_SMBUS_BYTE_DATA:
        case I2C_SMBUS_WORD_DATA:
-               if (obj == NULL || obj->type != ACPI_TYPE_INTEGER) {
+               if (obj->type != ACPI_TYPE_INTEGER) {
                        ACPI_ERROR((AE_INFO, "Invalid argument type"));
                        result = -EIO;
                        goto out;
@@ -246,7 +246,7 @@ acpi_smbus_cmi_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
                        data->byte = obj->integer.value;
                break;
        case I2C_SMBUS_BLOCK_DATA:
-               if (obj == NULL || obj->type != ACPI_TYPE_BUFFER) {
+               if (obj->type != ACPI_TYPE_BUFFER) {
                        ACPI_ERROR((AE_INFO, "Invalid argument type"));
                        result = -EIO;
                        goto out;
index 55110ddbed1ff4163d48acf20da36b58e2ee2e43..1d79585ba4b37f6b038b3eaf523a474d493fa320 100644 (file)
@@ -235,7 +235,7 @@ static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd)
        int offset;
 
        /* Get clock rate after clock is enabled */
-       clk_enable(pd->clk);
+       clk_prepare_enable(pd->clk);
        i2c_clk_khz = clk_get_rate(pd->clk) / 1000;
        i2c_clk_khz /= pd->clks_per_count;
 
@@ -270,14 +270,14 @@ static void sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd)
                pd->icic &= ~ICIC_ICCHB8;
 
 out:
-       clk_disable(pd->clk);
+       clk_disable_unprepare(pd->clk);
 }
 
 static void activate_ch(struct sh_mobile_i2c_data *pd)
 {
        /* Wake up device and enable clock */
        pm_runtime_get_sync(pd->dev);
-       clk_enable(pd->clk);
+       clk_prepare_enable(pd->clk);
 
        /* Enable channel and configure rx ack */
        iic_set_clr(pd, ICCR, ICCR_ICE, 0);
@@ -300,7 +300,7 @@ static void deactivate_ch(struct sh_mobile_i2c_data *pd)
        iic_set_clr(pd, ICCR, 0, ICCR_ICE);
 
        /* Disable clock and mark device as idle */
-       clk_disable(pd->clk);
+       clk_disable_unprepare(pd->clk);
        pm_runtime_put_sync(pd->dev);
 }
 
diff --git a/drivers/i2c/busses/i2c-st.c b/drivers/i2c/busses/i2c-st.c
new file mode 100644 (file)
index 0000000..9cf715d
--- /dev/null
@@ -0,0 +1,872 @@
+/*
+ * Copyright (C) 2013 STMicroelectronics
+ *
+ * I2C master mode controller driver, used in STMicroelectronics devices.
+ *
+ * Author: Maxime Coquelin <maxime.coquelin@st.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+
+/* SSC registers */
+#define SSC_BRG                                0x000
+#define SSC_TBUF                       0x004
+#define SSC_RBUF                       0x008
+#define SSC_CTL                                0x00C
+#define SSC_IEN                                0x010
+#define SSC_STA                                0x014
+#define SSC_I2C                                0x018
+#define SSC_SLAD                       0x01C
+#define SSC_REP_START_HOLD             0x020
+#define SSC_START_HOLD                 0x024
+#define SSC_REP_START_SETUP            0x028
+#define SSC_DATA_SETUP                 0x02C
+#define SSC_STOP_SETUP                 0x030
+#define SSC_BUS_FREE                   0x034
+#define SSC_TX_FSTAT                   0x038
+#define SSC_RX_FSTAT                   0x03C
+#define SSC_PRE_SCALER_BRG             0x040
+#define SSC_CLR                                0x080
+#define SSC_NOISE_SUPP_WIDTH           0x100
+#define SSC_PRSCALER                   0x104
+#define SSC_NOISE_SUPP_WIDTH_DATAOUT   0x108
+#define SSC_PRSCALER_DATAOUT           0x10c
+
+/* SSC Control */
+#define SSC_CTL_DATA_WIDTH_9           0x8
+#define SSC_CTL_DATA_WIDTH_MSK         0xf
+#define SSC_CTL_BM                     0xf
+#define SSC_CTL_HB                     BIT(4)
+#define SSC_CTL_PH                     BIT(5)
+#define SSC_CTL_PO                     BIT(6)
+#define SSC_CTL_SR                     BIT(7)
+#define SSC_CTL_MS                     BIT(8)
+#define SSC_CTL_EN                     BIT(9)
+#define SSC_CTL_LPB                    BIT(10)
+#define SSC_CTL_EN_TX_FIFO             BIT(11)
+#define SSC_CTL_EN_RX_FIFO             BIT(12)
+#define SSC_CTL_EN_CLST_RX             BIT(13)
+
+/* SSC Interrupt Enable */
+#define SSC_IEN_RIEN                   BIT(0)
+#define SSC_IEN_TIEN                   BIT(1)
+#define SSC_IEN_TEEN                   BIT(2)
+#define SSC_IEN_REEN                   BIT(3)
+#define SSC_IEN_PEEN                   BIT(4)
+#define SSC_IEN_AASEN                  BIT(6)
+#define SSC_IEN_STOPEN                 BIT(7)
+#define SSC_IEN_ARBLEN                 BIT(8)
+#define SSC_IEN_NACKEN                 BIT(10)
+#define SSC_IEN_REPSTRTEN              BIT(11)
+#define SSC_IEN_TX_FIFO_HALF           BIT(12)
+#define SSC_IEN_RX_FIFO_HALF_FULL      BIT(14)
+
+/* SSC Status */
+#define SSC_STA_RIR                    BIT(0)
+#define SSC_STA_TIR                    BIT(1)
+#define SSC_STA_TE                     BIT(2)
+#define SSC_STA_RE                     BIT(3)
+#define SSC_STA_PE                     BIT(4)
+#define SSC_STA_CLST                   BIT(5)
+#define SSC_STA_AAS                    BIT(6)
+#define SSC_STA_STOP                   BIT(7)
+#define SSC_STA_ARBL                   BIT(8)
+#define SSC_STA_BUSY                   BIT(9)
+#define SSC_STA_NACK                   BIT(10)
+#define SSC_STA_REPSTRT                        BIT(11)
+#define SSC_STA_TX_FIFO_HALF           BIT(12)
+#define SSC_STA_TX_FIFO_FULL           BIT(13)
+#define SSC_STA_RX_FIFO_HALF           BIT(14)
+
+/* SSC I2C Control */
+#define SSC_I2C_I2CM                   BIT(0)
+#define SSC_I2C_STRTG                  BIT(1)
+#define SSC_I2C_STOPG                  BIT(2)
+#define SSC_I2C_ACKG                   BIT(3)
+#define SSC_I2C_AD10                   BIT(4)
+#define SSC_I2C_TXENB                  BIT(5)
+#define SSC_I2C_REPSTRTG               BIT(11)
+#define SSC_I2C_SLAVE_DISABLE          BIT(12)
+
+/* SSC Tx FIFO Status */
+#define SSC_TX_FSTAT_STATUS            0x07
+
+/* SSC Rx FIFO Status */
+#define SSC_RX_FSTAT_STATUS            0x07
+
+/* SSC Clear bit operation */
+#define SSC_CLR_SSCAAS                 BIT(6)
+#define SSC_CLR_SSCSTOP                        BIT(7)
+#define SSC_CLR_SSCARBL                        BIT(8)
+#define SSC_CLR_NACK                   BIT(10)
+#define SSC_CLR_REPSTRT                        BIT(11)
+
+/* SSC Clock Prescaler */
+#define SSC_PRSC_VALUE                 0x0f
+
+
+#define SSC_TXFIFO_SIZE                        0x8
+#define SSC_RXFIFO_SIZE                        0x8
+
+enum st_i2c_mode {
+       I2C_MODE_STANDARD,
+       I2C_MODE_FAST,
+       I2C_MODE_END,
+};
+
+/**
+ * struct st_i2c_timings - per-Mode tuning parameters
+ * @rate: I2C bus rate
+ * @rep_start_hold: I2C repeated start hold time requirement
+ * @rep_start_setup: I2C repeated start set up time requirement
+ * @start_hold: I2C start hold time requirement
+ * @data_setup_time: I2C data set up time requirement
+ * @stop_setup_time: I2C stop set up time requirement
+ * @bus_free_time: I2C bus free time requirement
+ * @sda_pulse_min_limit: I2C SDA pulse mini width limit
+ */
+struct st_i2c_timings {
+       u32 rate;
+       u32 rep_start_hold;
+       u32 rep_start_setup;
+       u32 start_hold;
+       u32 data_setup_time;
+       u32 stop_setup_time;
+       u32 bus_free_time;
+       u32 sda_pulse_min_limit;
+};
+
+/**
+ * struct st_i2c_client - client specific data
+ * @addr: 8-bit slave addr, including r/w bit
+ * @count: number of bytes to be transfered
+ * @xfered: number of bytes already transferred
+ * @buf: data buffer
+ * @result: result of the transfer
+ * @stop: last I2C msg to be sent, i.e. STOP to be generated
+ */
+struct st_i2c_client {
+       u8      addr;
+       u32     count;
+       u32     xfered;
+       u8      *buf;
+       int     result;
+       bool    stop;
+};
+
+/**
+ * struct st_i2c_dev - private data of the controller
+ * @adap: I2C adapter for this controller
+ * @dev: device for this controller
+ * @base: virtual memory area
+ * @complete: completion of I2C message
+ * @irq: interrupt line for th controller
+ * @clk: hw ssc block clock
+ * @mode: I2C mode of the controller. Standard or Fast only supported
+ * @scl_min_width_us: SCL line minimum pulse width in us
+ * @sda_min_width_us: SDA line minimum pulse width in us
+ * @client: I2C transfert information
+ * @busy: I2C transfer on-going
+ */
+struct st_i2c_dev {
+       struct i2c_adapter      adap;
+       struct device           *dev;
+       void __iomem            *base;
+       struct completion       complete;
+       int                     irq;
+       struct clk              *clk;
+       int                     mode;
+       u32                     scl_min_width_us;
+       u32                     sda_min_width_us;
+       struct st_i2c_client    client;
+       bool                    busy;
+};
+
+static inline void st_i2c_set_bits(void __iomem *reg, u32 mask)
+{
+       writel_relaxed(readl_relaxed(reg) | mask, reg);
+}
+
+static inline void st_i2c_clr_bits(void __iomem *reg, u32 mask)
+{
+       writel_relaxed(readl_relaxed(reg) & ~mask, reg);
+}
+
+/* From I2C Specifications v0.5 */
+static struct st_i2c_timings i2c_timings[] = {
+       [I2C_MODE_STANDARD] = {
+               .rate                   = 100000,
+               .rep_start_hold         = 4000,
+               .rep_start_setup        = 4700,
+               .start_hold             = 4000,
+               .data_setup_time        = 250,
+               .stop_setup_time        = 4000,
+               .bus_free_time          = 4700,
+       },
+       [I2C_MODE_FAST] = {
+               .rate                   = 400000,
+               .rep_start_hold         = 600,
+               .rep_start_setup        = 600,
+               .start_hold             = 600,
+               .data_setup_time        = 100,
+               .stop_setup_time        = 600,
+               .bus_free_time          = 1300,
+       },
+};
+
+static void st_i2c_flush_rx_fifo(struct st_i2c_dev *i2c_dev)
+{
+       int count, i;
+
+       /*
+        * Counter only counts up to 7 but fifo size is 8...
+        * When fifo is full, counter is 0 and RIR bit of status register is
+        * set
+        */
+       if (readl_relaxed(i2c_dev->base + SSC_STA) & SSC_STA_RIR)
+               count = SSC_RXFIFO_SIZE;
+       else
+               count = readl_relaxed(i2c_dev->base + SSC_RX_FSTAT) &
+                       SSC_RX_FSTAT_STATUS;
+
+       for (i = 0; i < count; i++)
+               readl_relaxed(i2c_dev->base + SSC_RBUF);
+}
+
+static void st_i2c_soft_reset(struct st_i2c_dev *i2c_dev)
+{
+       /*
+        * FIFO needs to be emptied before reseting the IP,
+        * else the controller raises a BUSY error.
+        */
+       st_i2c_flush_rx_fifo(i2c_dev);
+
+       st_i2c_set_bits(i2c_dev->base + SSC_CTL, SSC_CTL_SR);
+       st_i2c_clr_bits(i2c_dev->base + SSC_CTL, SSC_CTL_SR);
+}
+
+/**
+ * st_i2c_hw_config() - Prepare SSC block, calculate and apply tuning timings
+ * @i2c_dev: Controller's private data
+ */
+static void st_i2c_hw_config(struct st_i2c_dev *i2c_dev)
+{
+       unsigned long rate;
+       u32 val, ns_per_clk;
+       struct st_i2c_timings *t = &i2c_timings[i2c_dev->mode];
+
+       st_i2c_soft_reset(i2c_dev);
+
+       val = SSC_CLR_REPSTRT | SSC_CLR_NACK | SSC_CLR_SSCARBL |
+               SSC_CLR_SSCAAS | SSC_CLR_SSCSTOP;
+       writel_relaxed(val, i2c_dev->base + SSC_CLR);
+
+       /* SSC Control register setup */
+       val = SSC_CTL_PO | SSC_CTL_PH | SSC_CTL_HB | SSC_CTL_DATA_WIDTH_9;
+       writel_relaxed(val, i2c_dev->base + SSC_CTL);
+
+       rate = clk_get_rate(i2c_dev->clk);
+       ns_per_clk = 1000000000 / rate;
+
+       /* Baudrate */
+       val = rate / (2 * t->rate);
+       writel_relaxed(val, i2c_dev->base + SSC_BRG);
+
+       /* Pre-scaler baudrate */
+       writel_relaxed(1, i2c_dev->base + SSC_PRE_SCALER_BRG);
+
+       /* Enable I2C mode */
+       writel_relaxed(SSC_I2C_I2CM, i2c_dev->base + SSC_I2C);
+
+       /* Repeated start hold time */
+       val = t->rep_start_hold / ns_per_clk;
+       writel_relaxed(val, i2c_dev->base + SSC_REP_START_HOLD);
+
+       /* Repeated start set up time */
+       val = t->rep_start_setup / ns_per_clk;
+       writel_relaxed(val, i2c_dev->base + SSC_REP_START_SETUP);
+
+       /* Start hold time */
+       val = t->start_hold / ns_per_clk;
+       writel_relaxed(val, i2c_dev->base + SSC_START_HOLD);
+
+       /* Data set up time */
+       val = t->data_setup_time / ns_per_clk;
+       writel_relaxed(val, i2c_dev->base + SSC_DATA_SETUP);
+
+       /* Stop set up time */
+       val = t->stop_setup_time / ns_per_clk;
+       writel_relaxed(val, i2c_dev->base + SSC_STOP_SETUP);
+
+       /* Bus free time */
+       val = t->bus_free_time / ns_per_clk;
+       writel_relaxed(val, i2c_dev->base + SSC_BUS_FREE);
+
+       /* Prescalers set up */
+       val = rate / 10000000;
+       writel_relaxed(val, i2c_dev->base + SSC_PRSCALER);
+       writel_relaxed(val, i2c_dev->base + SSC_PRSCALER_DATAOUT);
+
+       /* Noise suppression witdh */
+       val = i2c_dev->scl_min_width_us * rate / 100000000;
+       writel_relaxed(val, i2c_dev->base + SSC_NOISE_SUPP_WIDTH);
+
+       /* Noise suppression max output data delay width */
+       val = i2c_dev->sda_min_width_us * rate / 100000000;
+       writel_relaxed(val, i2c_dev->base + SSC_NOISE_SUPP_WIDTH_DATAOUT);
+}
+
+static int st_i2c_wait_free_bus(struct st_i2c_dev *i2c_dev)
+{
+       u32 sta;
+       int i;
+
+       for (i = 0; i < 10; i++) {
+               sta = readl_relaxed(i2c_dev->base + SSC_STA);
+               if (!(sta & SSC_STA_BUSY))
+                       return 0;
+
+               usleep_range(2000, 4000);
+       }
+
+       dev_err(i2c_dev->dev, "bus not free (status = 0x%08x)\n", sta);
+
+       return -EBUSY;
+}
+
+/**
+ * st_i2c_write_tx_fifo() - Write a byte in the Tx FIFO
+ * @i2c_dev: Controller's private data
+ * @byte: Data to write in the Tx FIFO
+ */
+static inline void st_i2c_write_tx_fifo(struct st_i2c_dev *i2c_dev, u8 byte)
+{
+       u16 tbuf = byte << 1;
+
+       writel_relaxed(tbuf | 1, i2c_dev->base + SSC_TBUF);
+}
+
+/**
+ * st_i2c_wr_fill_tx_fifo() - Fill the Tx FIFO in write mode
+ * @i2c_dev: Controller's private data
+ *
+ * This functions fills the Tx FIFO with I2C transfert buffer when
+ * in write mode.
+ */
+static void st_i2c_wr_fill_tx_fifo(struct st_i2c_dev *i2c_dev)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+       u32 tx_fstat, sta;
+       int i;
+
+       sta = readl_relaxed(i2c_dev->base + SSC_STA);
+       if (sta & SSC_STA_TX_FIFO_FULL)
+               return;
+
+       tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
+       tx_fstat &= SSC_TX_FSTAT_STATUS;
+
+       if (c->count < (SSC_TXFIFO_SIZE - tx_fstat))
+               i = c->count;
+       else
+               i = SSC_TXFIFO_SIZE - tx_fstat;
+
+       for (; i > 0; i--, c->count--, c->buf++)
+               st_i2c_write_tx_fifo(i2c_dev, *c->buf);
+}
+
+/**
+ * st_i2c_rd_fill_tx_fifo() - Fill the Tx FIFO in read mode
+ * @i2c_dev: Controller's private data
+ *
+ * This functions fills the Tx FIFO with fixed pattern when
+ * in read mode to trigger clock.
+ */
+static void st_i2c_rd_fill_tx_fifo(struct st_i2c_dev *i2c_dev, int max)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+       u32 tx_fstat, sta;
+       int i;
+
+       sta = readl_relaxed(i2c_dev->base + SSC_STA);
+       if (sta & SSC_STA_TX_FIFO_FULL)
+               return;
+
+       tx_fstat = readl_relaxed(i2c_dev->base + SSC_TX_FSTAT);
+       tx_fstat &= SSC_TX_FSTAT_STATUS;
+
+       if (max < (SSC_TXFIFO_SIZE - tx_fstat))
+               i = max;
+       else
+               i = SSC_TXFIFO_SIZE - tx_fstat;
+
+       for (; i > 0; i--, c->xfered++)
+               st_i2c_write_tx_fifo(i2c_dev, 0xff);
+}
+
+static void st_i2c_read_rx_fifo(struct st_i2c_dev *i2c_dev)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+       u32 i, sta;
+       u16 rbuf;
+
+       sta = readl_relaxed(i2c_dev->base + SSC_STA);
+       if (sta & SSC_STA_RIR) {
+               i = SSC_RXFIFO_SIZE;
+       } else {
+               i = readl_relaxed(i2c_dev->base + SSC_RX_FSTAT);
+               i &= SSC_RX_FSTAT_STATUS;
+       }
+
+       for (; (i > 0) && (c->count > 0); i--, c->count--) {
+               rbuf = readl_relaxed(i2c_dev->base + SSC_RBUF) >> 1;
+               *c->buf++ = (u8)rbuf & 0xff;
+       }
+
+       if (i) {
+               dev_err(i2c_dev->dev, "Unexpected %d bytes in rx fifo\n", i);
+               st_i2c_flush_rx_fifo(i2c_dev);
+       }
+}
+
+/**
+ * st_i2c_terminate_xfer() - Send either STOP or REPSTART condition
+ * @i2c_dev: Controller's private data
+ */
+static void st_i2c_terminate_xfer(struct st_i2c_dev *i2c_dev)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+
+       st_i2c_clr_bits(i2c_dev->base + SSC_IEN, SSC_IEN_TEEN);
+       st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STRTG);
+
+       if (c->stop) {
+               st_i2c_set_bits(i2c_dev->base + SSC_IEN, SSC_IEN_STOPEN);
+               st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
+       } else {
+               st_i2c_set_bits(i2c_dev->base + SSC_IEN, SSC_IEN_REPSTRTEN);
+               st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_REPSTRTG);
+       }
+}
+
+/**
+ * st_i2c_handle_write() - Handle FIFO empty interrupt in case of write
+ * @i2c_dev: Controller's private data
+ */
+static void st_i2c_handle_write(struct st_i2c_dev *i2c_dev)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+
+       st_i2c_flush_rx_fifo(i2c_dev);
+
+       if (!c->count)
+               /* End of xfer, send stop or repstart */
+               st_i2c_terminate_xfer(i2c_dev);
+       else
+               st_i2c_wr_fill_tx_fifo(i2c_dev);
+}
+
+/**
+ * st_i2c_handle_write() - Handle FIFO enmpty interrupt in case of read
+ * @i2c_dev: Controller's private data
+ */
+static void st_i2c_handle_read(struct st_i2c_dev *i2c_dev)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+       u32 ien;
+
+       /* Trash the address read back */
+       if (!c->xfered) {
+               readl_relaxed(i2c_dev->base + SSC_RBUF);
+               st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_TXENB);
+       } else {
+               st_i2c_read_rx_fifo(i2c_dev);
+       }
+
+       if (!c->count) {
+               /* End of xfer, send stop or repstart */
+               st_i2c_terminate_xfer(i2c_dev);
+       } else if (c->count == 1) {
+               /* Penultimate byte to xfer, disable ACK gen. */
+               st_i2c_clr_bits(i2c_dev->base + SSC_I2C, SSC_I2C_ACKG);
+
+               /* Last received byte is to be handled by NACK interrupt */
+               ien = SSC_IEN_NACKEN | SSC_IEN_ARBLEN;
+               writel_relaxed(ien, i2c_dev->base + SSC_IEN);
+
+               st_i2c_rd_fill_tx_fifo(i2c_dev, c->count);
+       } else {
+               st_i2c_rd_fill_tx_fifo(i2c_dev, c->count - 1);
+       }
+}
+
+/**
+ * st_i2c_isr() - Interrupt routine
+ * @irq: interrupt number
+ * @data: Controller's private data
+ */
+static irqreturn_t st_i2c_isr_thread(int irq, void *data)
+{
+       struct st_i2c_dev *i2c_dev = data;
+       struct st_i2c_client *c = &i2c_dev->client;
+       u32 sta, ien;
+       int it;
+
+       ien = readl_relaxed(i2c_dev->base + SSC_IEN);
+       sta = readl_relaxed(i2c_dev->base + SSC_STA);
+
+       /* Use __fls() to check error bits first */
+       it = __fls(sta & ien);
+       if (it < 0) {
+               dev_dbg(i2c_dev->dev, "spurious it (sta=0x%04x, ien=0x%04x)\n",
+                               sta, ien);
+               return IRQ_NONE;
+       }
+
+       switch (1 << it) {
+       case SSC_STA_TE:
+               if (c->addr & I2C_M_RD)
+                       st_i2c_handle_read(i2c_dev);
+               else
+                       st_i2c_handle_write(i2c_dev);
+               break;
+
+       case SSC_STA_STOP:
+       case SSC_STA_REPSTRT:
+               writel_relaxed(0, i2c_dev->base + SSC_IEN);
+               complete(&i2c_dev->complete);
+               break;
+
+       case SSC_STA_NACK:
+               writel_relaxed(SSC_CLR_NACK, i2c_dev->base + SSC_CLR);
+
+               /* Last received byte handled by NACK interrupt */
+               if ((c->addr & I2C_M_RD) && (c->count == 1) && (c->xfered)) {
+                       st_i2c_handle_read(i2c_dev);
+                       break;
+               }
+
+               it = SSC_IEN_STOPEN | SSC_IEN_ARBLEN;
+               writel_relaxed(it, i2c_dev->base + SSC_IEN);
+
+               st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
+               c->result = -EIO;
+               break;
+
+       case SSC_STA_ARBL:
+               writel_relaxed(SSC_CLR_SSCARBL, i2c_dev->base + SSC_CLR);
+
+               it = SSC_IEN_STOPEN | SSC_IEN_ARBLEN;
+               writel_relaxed(it, i2c_dev->base + SSC_IEN);
+
+               st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STOPG);
+               c->result = -EIO;
+               break;
+
+       default:
+               dev_err(i2c_dev->dev,
+                               "it %d unhandled (sta=0x%04x)\n", it, sta);
+       }
+
+       /*
+        * Read IEN register to ensure interrupt mask write is effective
+        * before re-enabling interrupt at GIC level, and thus avoid spurious
+        * interrupts.
+        */
+       readl(i2c_dev->base + SSC_IEN);
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * st_i2c_xfer_msg() - Transfer a single I2C message
+ * @i2c_dev: Controller's private data
+ * @msg: I2C message to transfer
+ * @is_first: first message of the sequence
+ * @is_last: last message of the sequence
+ */
+static int st_i2c_xfer_msg(struct st_i2c_dev *i2c_dev, struct i2c_msg *msg,
+                           bool is_first, bool is_last)
+{
+       struct st_i2c_client *c = &i2c_dev->client;
+       u32 ctl, i2c, it;
+       unsigned long timeout;
+       int ret;
+
+       c->addr         = (u8)(msg->addr << 1);
+       c->addr         |= (msg->flags & I2C_M_RD);
+       c->buf          = msg->buf;
+       c->count        = msg->len;
+       c->xfered       = 0;
+       c->result       = 0;
+       c->stop         = is_last;
+
+       reinit_completion(&i2c_dev->complete);
+
+       ctl = SSC_CTL_EN | SSC_CTL_MS | SSC_CTL_EN_RX_FIFO | SSC_CTL_EN_TX_FIFO;
+       st_i2c_set_bits(i2c_dev->base + SSC_CTL, ctl);
+
+       i2c = SSC_I2C_TXENB;
+       if (c->addr & I2C_M_RD)
+               i2c |= SSC_I2C_ACKG;
+       st_i2c_set_bits(i2c_dev->base + SSC_I2C, i2c);
+
+       /* Write slave address */
+       st_i2c_write_tx_fifo(i2c_dev, c->addr);
+
+       /* Pre-fill Tx fifo with data in case of write */
+       if (!(c->addr & I2C_M_RD))
+               st_i2c_wr_fill_tx_fifo(i2c_dev);
+
+       it = SSC_IEN_NACKEN | SSC_IEN_TEEN | SSC_IEN_ARBLEN;
+       writel_relaxed(it, i2c_dev->base + SSC_IEN);
+
+       if (is_first) {
+               ret = st_i2c_wait_free_bus(i2c_dev);
+               if (ret)
+                       return ret;
+
+               st_i2c_set_bits(i2c_dev->base + SSC_I2C, SSC_I2C_STRTG);
+       }
+
+       timeout = wait_for_completion_timeout(&i2c_dev->complete,
+                       i2c_dev->adap.timeout);
+       ret = c->result;
+
+       if (!timeout) {
+               dev_err(i2c_dev->dev, "Write to slave 0x%x timed out\n",
+                               c->addr);
+               ret = -ETIMEDOUT;
+       }
+
+       i2c = SSC_I2C_STOPG | SSC_I2C_REPSTRTG;
+       st_i2c_clr_bits(i2c_dev->base + SSC_I2C, i2c);
+
+       writel_relaxed(SSC_CLR_SSCSTOP | SSC_CLR_REPSTRT,
+                       i2c_dev->base + SSC_CLR);
+
+       return ret;
+}
+
+/**
+ * st_i2c_xfer() - Transfer a single I2C message
+ * @i2c_adap: Adapter pointer to the controller
+ * @msgs: Pointer to data to be written.
+ * @num: Number of messages to be executed
+ */
+static int st_i2c_xfer(struct i2c_adapter *i2c_adap,
+                       struct i2c_msg msgs[], int num)
+{
+       struct st_i2c_dev *i2c_dev = i2c_get_adapdata(i2c_adap);
+       int ret, i;
+
+       i2c_dev->busy = true;
+
+       ret = clk_prepare_enable(i2c_dev->clk);
+       if (ret) {
+               dev_err(i2c_dev->dev, "Failed to prepare_enable clock\n");
+               return ret;
+       }
+
+       pinctrl_pm_select_default_state(i2c_dev->dev);
+
+       st_i2c_hw_config(i2c_dev);
+
+       for (i = 0; (i < num) && !ret; i++)
+               ret = st_i2c_xfer_msg(i2c_dev, &msgs[i], i == 0, i == num - 1);
+
+       pinctrl_pm_select_idle_state(i2c_dev->dev);
+
+       clk_disable_unprepare(i2c_dev->clk);
+
+       i2c_dev->busy = false;
+
+       return (ret < 0) ? ret : i;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int st_i2c_suspend(struct device *dev)
+{
+       struct platform_device *pdev =
+               container_of(dev, struct platform_device, dev);
+       struct st_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
+
+       if (i2c_dev->busy)
+               return -EBUSY;
+
+       pinctrl_pm_select_sleep_state(dev);
+
+       return 0;
+}
+
+static int st_i2c_resume(struct device *dev)
+{
+       pinctrl_pm_select_default_state(dev);
+       /* Go in idle state if available */
+       pinctrl_pm_select_idle_state(dev);
+
+       return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(st_i2c_pm, st_i2c_suspend, st_i2c_resume);
+#define ST_I2C_PM      (&st_i2c_pm)
+#else
+#define ST_I2C_PM      NULL
+#endif
+
+static u32 st_i2c_func(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+}
+
+static struct i2c_algorithm st_i2c_algo = {
+       .master_xfer = st_i2c_xfer,
+       .functionality = st_i2c_func,
+};
+
+static int st_i2c_of_get_deglitch(struct device_node *np,
+               struct st_i2c_dev *i2c_dev)
+{
+       int ret;
+
+       ret = of_property_read_u32(np, "st,i2c-min-scl-pulse-width-us",
+                       &i2c_dev->scl_min_width_us);
+       if ((ret == -ENODATA) || (ret == -EOVERFLOW)) {
+               dev_err(i2c_dev->dev, "st,i2c-min-scl-pulse-width-us invalid\n");
+               return ret;
+       }
+
+       ret = of_property_read_u32(np, "st,i2c-min-sda-pulse-width-us",
+                       &i2c_dev->sda_min_width_us);
+       if ((ret == -ENODATA) || (ret == -EOVERFLOW)) {
+               dev_err(i2c_dev->dev, "st,i2c-min-sda-pulse-width-us invalid\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int st_i2c_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct st_i2c_dev *i2c_dev;
+       struct resource *res;
+       u32 clk_rate;
+       struct i2c_adapter *adap;
+       int ret;
+
+       i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
+       if (!i2c_dev)
+               return -ENOMEM;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       i2c_dev->base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(i2c_dev->base))
+               return PTR_ERR(i2c_dev->base);
+
+       i2c_dev->irq = irq_of_parse_and_map(np, 0);
+       if (!i2c_dev->irq) {
+               dev_err(&pdev->dev, "IRQ missing or invalid\n");
+               return -EINVAL;
+       }
+
+       i2c_dev->clk = of_clk_get_by_name(np, "ssc");
+       if (IS_ERR(i2c_dev->clk)) {
+               dev_err(&pdev->dev, "Unable to request clock\n");
+               return PTR_ERR(i2c_dev->clk);
+       }
+
+       i2c_dev->mode = I2C_MODE_STANDARD;
+       ret = of_property_read_u32(np, "clock-frequency", &clk_rate);
+       if ((!ret) && (clk_rate == 400000))
+               i2c_dev->mode = I2C_MODE_FAST;
+
+       i2c_dev->dev = &pdev->dev;
+
+       ret = devm_request_threaded_irq(&pdev->dev, i2c_dev->irq,
+                       NULL, st_i2c_isr_thread,
+                       IRQF_ONESHOT, pdev->name, i2c_dev);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq);
+               return ret;
+       }
+
+       pinctrl_pm_select_default_state(i2c_dev->dev);
+       /* In case idle state available, select it */
+       pinctrl_pm_select_idle_state(i2c_dev->dev);
+
+       ret = st_i2c_of_get_deglitch(np, i2c_dev);
+       if (ret)
+               return ret;
+
+       adap = &i2c_dev->adap;
+       i2c_set_adapdata(adap, i2c_dev);
+       snprintf(adap->name, sizeof(adap->name), "ST I2C(0x%x)", res->start);
+       adap->owner = THIS_MODULE;
+       adap->timeout = 2 * HZ;
+       adap->retries = 0;
+       adap->algo = &st_i2c_algo;
+       adap->dev.parent = &pdev->dev;
+       adap->dev.of_node = pdev->dev.of_node;
+
+       init_completion(&i2c_dev->complete);
+
+       ret = i2c_add_adapter(adap);
+       if (ret) {
+               dev_err(&pdev->dev, "Failed to add adapter\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, i2c_dev);
+
+       dev_info(i2c_dev->dev, "%s initialized\n", adap->name);
+
+       return 0;
+}
+
+static int st_i2c_remove(struct platform_device *pdev)
+{
+       struct st_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
+
+       i2c_del_adapter(&i2c_dev->adap);
+
+       return 0;
+}
+
+static struct of_device_id st_i2c_match[] = {
+       { .compatible = "st,comms-ssc-i2c", },
+       { .compatible = "st,comms-ssc4-i2c", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, st_i2c_match);
+
+static struct platform_driver st_i2c_driver = {
+       .driver = {
+               .name = "st-i2c",
+               .owner = THIS_MODULE,
+               .of_match_table = st_i2c_match,
+               .pm = ST_I2C_PM,
+       },
+       .probe = st_i2c_probe,
+       .remove = st_i2c_remove,
+};
+
+module_platform_driver(st_i2c_driver);
+
+MODULE_AUTHOR("Maxime Coquelin <maxime.coquelin@st.com>");
+MODULE_DESCRIPTION("STMicroelectronics I2C driver");
+MODULE_LICENSE("GPL v2");
index 31395fa8121db6644a4379f2b578e419759380f5..2c8a3e4f900890e11f3fd1f14c0e15aa78d2ecce 100644 (file)
@@ -349,6 +349,7 @@ static int wmt_i2c_reset_hardware(struct wmt_i2c_dev *i2c_dev)
        err = clk_set_rate(i2c_dev->clk, 20000000);
        if (err) {
                dev_err(i2c_dev->dev, "failed to set clock = 20Mhz\n");
+               clk_disable_unprepare(i2c_dev->clk);
                return err;
        }
 
index 4c8b368d463b7c77517fb3ed314e4234bd6dafbc..fc2716afdfd91b3a053a1a37ed1db4c68be69410 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/i2c-xiic.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #define DRIVER_NAME "xiic-i2c"
 
@@ -702,7 +703,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
        if (irq < 0)
                goto resource_missing;
 
-       pdata = (struct xiic_i2c_platform_data *)dev_get_platdata(&pdev->dev);
+       pdata = dev_get_platdata(&pdev->dev);
 
        i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
        if (!i2c)
index 75ba8608383e4b1d26e65a389f099f7028e7b733..d74c0b34248ea6c38472cc401571d8f519844c4d 100644 (file)
@@ -248,7 +248,7 @@ static int i2c_device_probe(struct device *dev)
        driver = to_i2c_driver(dev->driver);
        if (!driver->probe || !driver->id_table)
                return -ENODEV;
-       client->driver = driver;
+
        if (!device_can_wakeup(&client->dev))
                device_init_wakeup(&client->dev,
                                        client->flags & I2C_CLIENT_WAKE);
@@ -257,7 +257,6 @@ static int i2c_device_probe(struct device *dev)
        acpi_dev_pm_attach(&client->dev, true);
        status = driver->probe(client, i2c_match_id(driver->id_table, client));
        if (status) {
-               client->driver = NULL;
                i2c_set_clientdata(client, NULL);
                acpi_dev_pm_detach(&client->dev, true);
        }
@@ -281,10 +280,8 @@ static int i2c_device_remove(struct device *dev)
                dev->driver = NULL;
                status = 0;
        }
-       if (status == 0) {
-               client->driver = NULL;
+       if (status == 0)
                i2c_set_clientdata(client, NULL);
-       }
        acpi_dev_pm_detach(&client->dev, true);
        return status;
 }
@@ -618,6 +615,22 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+                            struct i2c_client *client)
+{
+       struct acpi_device *adev = ACPI_COMPANION(&client->dev);
+
+       if (adev) {
+               dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
+               return;
+       }
+
+       /* For 10-bit clients, add an arbitrary offset to avoid collisions */
+       dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+                    client->addr | ((client->flags & I2C_CLIENT_TEN)
+                                    ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -674,12 +687,9 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
        client->dev.bus = &i2c_bus_type;
        client->dev.type = &i2c_client_type;
        client->dev.of_node = info->of_node;
-       ACPI_HANDLE_SET(&client->dev, info->acpi_node.handle);
+       ACPI_COMPANION_SET(&client->dev, info->acpi_node.companion);
 
-       /* For 10-bit clients, add an arbitrary offset to avoid collisions */
-       dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-                    client->addr | ((client->flags & I2C_CLIENT_TEN)
-                                    ? 0xa000 : 0));
+       i2c_dev_set_name(adap, client);
        status = device_register(&client->dev);
        if (status)
                goto out_err;
@@ -1103,7 +1113,7 @@ static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
                return AE_OK;
 
        memset(&info, 0, sizeof(info));
-       info.acpi_node.handle = handle;
+       info.acpi_node.companion = adev;
        info.irq = -1;
 
        INIT_LIST_HEAD(&resource_list);
@@ -1614,9 +1624,14 @@ static int i2c_cmd(struct device *dev, void *_arg)
 {
        struct i2c_client       *client = i2c_verify_client(dev);
        struct i2c_cmd_arg      *arg = _arg;
+       struct i2c_driver       *driver;
+
+       if (!client || !client->dev.driver)
+               return 0;
 
-       if (client && client->driver && client->driver->command)
-               client->driver->command(client, arg->cmd, arg->arg);
+       driver = to_i2c_driver(client->dev.driver);
+       if (driver->command)
+               driver->command(client, arg->cmd, arg->arg);
        return 0;
 }
 
index c3ccdea3d18059c4dd199f533932ff17f0b4f448..80b47e8ce030cef7ff6f9ab9f058b15e63f7329e 100644 (file)
@@ -102,8 +102,8 @@ static void return_i2c_dev(struct i2c_dev *i2c_dev)
        kfree(i2c_dev);
 }
 
-static ssize_t show_adapter_name(struct device *dev,
-                                struct device_attribute *attr, char *buf)
+static ssize_t name_show(struct device *dev,
+                        struct device_attribute *attr, char *buf)
 {
        struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt));
 
@@ -111,7 +111,13 @@ static ssize_t show_adapter_name(struct device *dev,
                return -ENODEV;
        return sprintf(buf, "%s\n", i2c_dev->adap->name);
 }
-static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
+static DEVICE_ATTR_RO(name);
+
+static struct attribute *i2c_attrs[] = {
+       &dev_attr_name.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(i2c);
 
 /* ------------------------------------------------------------------------- */
 
@@ -562,15 +568,10 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
                res = PTR_ERR(i2c_dev->dev);
                goto error;
        }
-       res = device_create_file(i2c_dev->dev, &dev_attr_name);
-       if (res)
-               goto error_destroy;
 
        pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
                 adap->name, adap->nr);
        return 0;
-error_destroy:
-       device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
 error:
        return_i2c_dev(i2c_dev);
        return res;
@@ -589,7 +590,6 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
        if (!i2c_dev) /* attach_adapter must have failed */
                return 0;
 
-       device_remove_file(i2c_dev->dev, &dev_attr_name);
        return_i2c_dev(i2c_dev);
        device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
 
@@ -637,6 +637,7 @@ static int __init i2c_dev_init(void)
                res = PTR_ERR(i2c_dev_class);
                goto out_unreg_chrdev;
        }
+       i2c_dev_class->dev_groups = i2c_groups;
 
        /* Keep track of adapters which will be added or removed later */
        res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
index 44d4c6071c15096e19d16433092b7428c113f34f..c99b229873665b56656a7cabd95c7dfd6acb3fb1 100644 (file)
@@ -46,6 +46,7 @@ static int smbus_do_alert(struct device *dev, void *addrp)
 {
        struct i2c_client *client = i2c_verify_client(dev);
        struct alert_data *data = addrp;
+       struct i2c_driver *driver;
 
        if (!client || client->addr != data->addr)
                return 0;
@@ -54,12 +55,13 @@ static int smbus_do_alert(struct device *dev, void *addrp)
 
        /*
         * Drivers should either disable alerts, or provide at least
-        * a minimal handler.  Lock so client->driver won't change.
+        * a minimal handler.  Lock so the driver won't change.
         */
        device_lock(dev);
-       if (client->driver) {
-               if (client->driver->alert)
-                       client->driver->alert(client, data->flag);
+       if (client->dev.driver) {
+               driver = to_i2c_driver(client->dev.driver);
+               if (driver->alert)
+                       driver->alert(client, data->flag);
                else
                        dev_warn(&client->dev, "no driver alert()!\n");
        } else
index 928656e241ddc0873613dd7a5b786be4f0e5250e..c58e093b6032480a316c1725db5f6879842cd2ef 100644 (file)
@@ -238,7 +238,7 @@ static struct platform_driver i2c_arbitrator_driver = {
        .driver = {
                .owner  = THIS_MODULE,
                .name   = "i2c-arb-gpio-challenge",
-               .of_match_table = of_match_ptr(i2c_arbitrator_of_match),
+               .of_match_table = i2c_arbitrator_of_match,
        },
 };
 
index a764da777f08027da102e244556f9bb424b59494..8a8c56f4b026d6a22e54941e9959ea633b42c321 100644 (file)
@@ -30,15 +30,15 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
        int i;
 
        for (i = 0; i < mux->data.n_gpios; i++)
-               gpio_set_value(mux->gpio_base + mux->data.gpios[i],
-                              val & (1 << i));
+               gpio_set_value_cansleep(mux->gpio_base + mux->data.gpios[i],
+                                       val & (1 << i));
 }
 
 static int i2c_mux_gpio_select(struct i2c_adapter *adap, void *data, u32 chan)
 {
        struct gpiomux *mux = data;
 
-       i2c_mux_gpio_set(mux, mux->data.values[chan]);
+       i2c_mux_gpio_set(mux, chan);
 
        return 0;
 }
@@ -228,7 +228,7 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
                unsigned int class = mux->data.classes ? mux->data.classes[i] : 0;
 
                mux->adap[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, nr,
-                                                  i, class,
+                                                  mux->data.values[i], class,
                                                   i2c_mux_gpio_select, deselect);
                if (!mux->adap[i]) {
                        ret = -ENODEV;
@@ -283,7 +283,7 @@ static struct platform_driver i2c_mux_gpio_driver = {
        .driver = {
                .owner  = THIS_MODULE,
                .name   = "i2c-mux-gpio",
-               .of_match_table = of_match_ptr(i2c_mux_gpio_of_match),
+               .of_match_table = i2c_mux_gpio_of_match,
        },
 };
 
index 68a37157377df12797b1b122ca4568d121559112..d7978dc4ad0b075a03b842bc93b52a61c952ae70 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/i2c-mux-pinctrl.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 struct i2c_mux_pinctrl {
        struct device *dev;
index 140c8ef505291129d6299d2b4d4931d3b728589e..d9e1f7ccfe6f086df549160a88ca191e52fca32f 100644 (file)
@@ -7,6 +7,7 @@
  * Copyright (C) 2006 Hannes Reinecke
  */
 
+#include <linux/acpi.h>
 #include <linux/ata.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -19,8 +20,6 @@
 #include <linux/dmi.h>
 #include <linux/module.h>
 
-#include <acpi/acpi_bus.h>
-
 #define REGS_PER_GTF           7
 
 struct GTM_buffer {
@@ -128,7 +127,7 @@ static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
 
        DEBPRINT("ENTER: pci %02x:%02x.%01x\n", bus, devnum, func);
 
-       dev_handle = DEVICE_ACPI_HANDLE(dev);
+       dev_handle = ACPI_HANDLE(dev);
        if (!dev_handle) {
                DEBPRINT("no acpi handle for device\n");
                goto err;
index 3226ce98fb184df9c0c5666129c1b699cbcc5027..cbd4e9abc47e8f47f512915d224f916166921110 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * intel_idle.c - native hardware idle loop for modern Intel processors
  *
- * Copyright (c) 2010, Intel Corporation.
+ * Copyright (c) 2013, Intel Corporation.
  * Len Brown <len.brown@intel.com>
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -329,6 +329,22 @@ static struct cpuidle_state atom_cstates[] __initdata = {
        {
                .enter = NULL }
 };
+static struct cpuidle_state avn_cstates[CPUIDLE_STATE_MAX] = {
+       {
+               .name = "C1-AVN",
+               .desc = "MWAIT 0x00",
+               .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_TIME_VALID,
+               .exit_latency = 2,
+               .target_residency = 2,
+               .enter = &intel_idle },
+       {
+               .name = "C6-AVN",
+               .desc = "MWAIT 0x51",
+               .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
+               .exit_latency = 15,
+               .target_residency = 45,
+               .enter = &intel_idle },
+};
 
 /**
  * intel_idle
@@ -462,6 +478,11 @@ static const struct idle_cpu idle_cpu_hsw = {
        .disable_promotion_to_c1e = true,
 };
 
+static const struct idle_cpu idle_cpu_avn = {
+       .state_table = avn_cstates,
+       .disable_promotion_to_c1e = true,
+};
+
 #define ICPU(model, cpu) \
        { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
 
@@ -483,6 +504,7 @@ static const struct x86_cpu_id intel_idle_ids[] = {
        ICPU(0x3f, idle_cpu_hsw),
        ICPU(0x45, idle_cpu_hsw),
        ICPU(0x46, idle_cpu_hsw),
+       ICPU(0x4D, idle_cpu_avn),
        {}
 };
 MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
index b84791f03a27f5d174b60680f77c59de06bb542a..5ceda710f516bc4721e14961a504fa7e2c3054a9 100644 (file)
@@ -31,17 +31,6 @@ config INFINIBAND_USER_ACCESS
          libibverbs, libibcm and a hardware driver library from
          <http://www.openfabrics.org/git/>.
 
-config INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-       bool "Experimental and unstable ABI for userspace access to flow steering verbs"
-       depends on INFINIBAND_USER_ACCESS
-       depends on STAGING
-       ---help---
-         The final ABI for userspace access to flow steering verbs
-         has not been defined.  To use the current ABI, *WHICH WILL
-         CHANGE IN THE FUTURE*, say Y here.
-
-         If unsure, say N.
-
 config INFINIBAND_USER_MEM
        bool
        depends on INFINIBAND_USER_ACCESS != n
index 784b97cb05b00f3f8d08786d7ef0ff22aa8434b0..f2ef7ef0f36f7c19df3a2eb53fb3e3b532716a1b 100644 (file)
@@ -383,14 +383,11 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)
 {
        unsigned long flags;
        int id;
-       static int next_id;
 
        idr_preload(GFP_KERNEL);
        spin_lock_irqsave(&cm.lock, flags);
 
-       id = idr_alloc(&cm.local_id_table, cm_id_priv, next_id, 0, GFP_NOWAIT);
-       if (id >= 0)
-               next_id = max(id + 1, 0);
+       id = idr_alloc_cyclic(&cm.local_id_table, cm_id_priv, 0, 0, GFP_NOWAIT);
 
        spin_unlock_irqrestore(&cm.lock, flags);
        idr_preload_end();
index d2172e71f985fd9f8ec1418c1c719a5491b97a44..8e49db690f33e9a67f71cbcca8b62c9d92fde9f4 100644 (file)
@@ -328,28 +328,6 @@ static int cma_set_qkey(struct rdma_id_private *id_priv, u32 qkey)
        return ret;
 }
 
-static int find_gid_port(struct ib_device *device, union ib_gid *gid, u8 port_num)
-{
-       int i;
-       int err;
-       struct ib_port_attr props;
-       union ib_gid tmp;
-
-       err = ib_query_port(device, port_num, &props);
-       if (err)
-               return err;
-
-       for (i = 0; i < props.gid_tbl_len; ++i) {
-               err = ib_query_gid(device, port_num, i, &tmp);
-               if (err)
-                       return err;
-               if (!memcmp(&tmp, gid, sizeof tmp))
-                       return 0;
-       }
-
-       return -EADDRNOTAVAIL;
-}
-
 static void cma_translate_ib(struct sockaddr_ib *sib, struct rdma_dev_addr *dev_addr)
 {
        dev_addr->dev_type = ARPHRD_INFINIBAND;
@@ -371,13 +349,14 @@ static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_a
        return ret;
 }
 
-static int cma_acquire_dev(struct rdma_id_private *id_priv)
+static int cma_acquire_dev(struct rdma_id_private *id_priv,
+                          struct rdma_id_private *listen_id_priv)
 {
        struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
        struct cma_device *cma_dev;
        union ib_gid gid, iboe_gid;
        int ret = -ENODEV;
-       u8 port;
+       u8 port, found_port;
        enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
                IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
 
@@ -389,17 +368,39 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
        iboe_addr_get_sgid(dev_addr, &iboe_gid);
        memcpy(&gid, dev_addr->src_dev_addr +
               rdma_addr_gid_offset(dev_addr), sizeof gid);
+       if (listen_id_priv &&
+           rdma_port_get_link_layer(listen_id_priv->id.device,
+                                    listen_id_priv->id.port_num) == dev_ll) {
+               cma_dev = listen_id_priv->cma_dev;
+               port = listen_id_priv->id.port_num;
+               if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
+                   rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
+                       ret = ib_find_cached_gid(cma_dev->device, &iboe_gid,
+                                                &found_port, NULL);
+               else
+                       ret = ib_find_cached_gid(cma_dev->device, &gid,
+                                                &found_port, NULL);
+
+               if (!ret && (port  == found_port)) {
+                       id_priv->id.port_num = found_port;
+                       goto out;
+               }
+       }
        list_for_each_entry(cma_dev, &dev_list, list) {
                for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
+                       if (listen_id_priv &&
+                           listen_id_priv->cma_dev == cma_dev &&
+                           listen_id_priv->id.port_num == port)
+                               continue;
                        if (rdma_port_get_link_layer(cma_dev->device, port) == dev_ll) {
                                if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
                                    rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
-                                       ret = find_gid_port(cma_dev->device, &iboe_gid, port);
+                                       ret = ib_find_cached_gid(cma_dev->device, &iboe_gid, &found_port, NULL);
                                else
-                                       ret = find_gid_port(cma_dev->device, &gid, port);
+                                       ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
 
-                               if (!ret) {
-                                       id_priv->id.port_num = port;
+                               if (!ret && (port == found_port)) {
+                                       id_priv->id.port_num = found_port;
                                        goto out;
                                }
                        }
@@ -1292,7 +1293,7 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
        }
 
        mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING);
-       ret = cma_acquire_dev(conn_id);
+       ret = cma_acquire_dev(conn_id, listen_id);
        if (ret)
                goto err2;
 
@@ -1451,7 +1452,6 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
 {
        struct rdma_cm_id *new_cm_id;
        struct rdma_id_private *listen_id, *conn_id;
-       struct net_device *dev = NULL;
        struct rdma_cm_event event;
        int ret;
        struct ib_device_attr attr;
@@ -1481,7 +1481,7 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
                goto out;
        }
 
-       ret = cma_acquire_dev(conn_id);
+       ret = cma_acquire_dev(conn_id, listen_id);
        if (ret) {
                mutex_unlock(&conn_id->handler_mutex);
                rdma_destroy_id(new_cm_id);
@@ -1529,8 +1529,6 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
        cma_deref_id(conn_id);
 
 out:
-       if (dev)
-               dev_put(dev);
        mutex_unlock(&listen_id->handler_mutex);
        return ret;
 }
@@ -2066,7 +2064,7 @@ static void addr_handler(int status, struct sockaddr *src_addr,
                goto out;
 
        if (!status && !id_priv->cma_dev)
-               status = cma_acquire_dev(id_priv);
+               status = cma_acquire_dev(id_priv, NULL);
 
        if (status) {
                if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED,
@@ -2563,7 +2561,7 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
                if (ret)
                        goto err1;
 
-               ret = cma_acquire_dev(id_priv);
+               ret = cma_acquire_dev(id_priv, NULL);
                if (ret)
                        goto err1;
        }
index da06abde9e0d557ae1536f1995cd1a84af6ab219..a1e9cba849446b1cd5ac840b66b18355451377b4 100644 (file)
@@ -148,7 +148,7 @@ static int ibnl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
        list_for_each_entry(client, &client_list, list) {
                if (client->index == index) {
                        if (op < 0 || op >= client->nops ||
-                           !client->cb_table[RDMA_NL_GET_OP(op)].dump)
+                           !client->cb_table[op].dump)
                                return -EINVAL;
 
                        {
index cde1e7b5b85ddd87b1e44e9886be0be19bf3d137..faad2caf22b1e06cbe2f7e628354f16efb686d0a 100644 (file)
@@ -612,6 +612,7 @@ static ssize_t show_node_type(struct device *device,
        switch (dev->node_type) {
        case RDMA_NODE_IB_CA:     return sprintf(buf, "%d: CA\n", dev->node_type);
        case RDMA_NODE_RNIC:      return sprintf(buf, "%d: RNIC\n", dev->node_type);
+       case RDMA_NODE_USNIC:     return sprintf(buf, "%d: usNIC\n", dev->node_type);
        case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
        case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
        default:                  return sprintf(buf, "%d: <unknown>\n", dev->node_type);
index b0f189be543bf61749bdcf37d6fd7a17f3d57fcc..ab8b1c30b36b7fb8cf70ca243a5945a14ae1e045 100644 (file)
@@ -57,7 +57,7 @@ MODULE_LICENSE("Dual BSD/GPL");
 static unsigned int max_backlog = 1024;
 
 static struct ctl_table_header *ucma_ctl_table_hdr;
-static ctl_table ucma_ctl_table[] = {
+static struct ctl_table ucma_ctl_table[] = {
        {
                .procname       = "max_backlog",
                .data           = &max_backlog,
@@ -271,7 +271,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
                        goto out;
                }
                ctx->backlog--;
-       } else if (!ctx->uid) {
+       } else if (!ctx->uid || ctx->cm_id != cm_id) {
                /*
                 * We ignore events for new connections until userspace has set
                 * their context.  This can only happen if an error occurs on a
index d8f9c6c272d732a898b334be0c3034aadf37b275..bdc842e9faefe4ba477b96c479975643bfdc6366 100644 (file)
 #include <rdma/ib_umem.h>
 #include <rdma/ib_user_verbs.h>
 
+#define INIT_UDATA(udata, ibuf, obuf, ilen, olen)                      \
+       do {                                                            \
+               (udata)->inbuf  = (void __user *) (ibuf);               \
+               (udata)->outbuf = (void __user *) (obuf);               \
+               (udata)->inlen  = (ilen);                               \
+               (udata)->outlen = (olen);                               \
+       } while (0)
+
 /*
  * Our lifetime rules for these structs are the following:
  *
@@ -178,6 +186,22 @@ void ib_uverbs_event_handler(struct ib_event_handler *handler,
                             struct ib_event *event);
 void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd);
 
+struct ib_uverbs_flow_spec {
+       union {
+               union {
+                       struct ib_uverbs_flow_spec_hdr hdr;
+                       struct {
+                               __u32 type;
+                               __u16 size;
+                               __u16 reserved;
+                       };
+               };
+               struct ib_uverbs_flow_spec_eth     eth;
+               struct ib_uverbs_flow_spec_ipv4    ipv4;
+               struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
+       };
+};
+
 #define IB_UVERBS_DECLARE_CMD(name)                                    \
        ssize_t ib_uverbs_##name(struct ib_uverbs_file *file,           \
                                 const char __user *buf, int in_len,    \
@@ -217,9 +241,13 @@ IB_UVERBS_DECLARE_CMD(destroy_srq);
 IB_UVERBS_DECLARE_CMD(create_xsrq);
 IB_UVERBS_DECLARE_CMD(open_xrcd);
 IB_UVERBS_DECLARE_CMD(close_xrcd);
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-IB_UVERBS_DECLARE_CMD(create_flow);
-IB_UVERBS_DECLARE_CMD(destroy_flow);
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
+
+#define IB_UVERBS_DECLARE_EX_CMD(name)                         \
+       int ib_uverbs_ex_##name(struct ib_uverbs_file *file,    \
+                               struct ib_udata *ucore,         \
+                               struct ib_udata *uhw)
+
+IB_UVERBS_DECLARE_EX_CMD(create_flow);
+IB_UVERBS_DECLARE_EX_CMD(destroy_flow);
 
 #endif /* UVERBS_H */
index 2f0f01b70e3bd22c538cd3a4081be0a9ec3f790f..65f6e7dc380c382cc0335e495fb2f583a4eef7b7 100644 (file)
@@ -54,17 +54,7 @@ static struct uverbs_lock_class qp_lock_class        = { .name = "QP-uobj" };
 static struct uverbs_lock_class ah_lock_class  = { .name = "AH-uobj" };
 static struct uverbs_lock_class srq_lock_class = { .name = "SRQ-uobj" };
 static struct uverbs_lock_class xrcd_lock_class = { .name = "XRCD-uobj" };
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
 static struct uverbs_lock_class rule_lock_class = { .name = "RULE-uobj" };
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
-
-#define INIT_UDATA(udata, ibuf, obuf, ilen, olen)                      \
-       do {                                                            \
-               (udata)->inbuf  = (void __user *) (ibuf);               \
-               (udata)->outbuf = (void __user *) (obuf);               \
-               (udata)->inlen  = (ilen);                               \
-               (udata)->outlen = (olen);                               \
-       } while (0)
 
 /*
  * The ib_uobject locking scheme is as follows:
@@ -939,13 +929,9 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
        if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
                return -EINVAL;
 
-       /*
-        * Local write permission is required if remote write or
-        * remote atomic permission is also requested.
-        */
-       if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
-           !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE))
-               return -EINVAL;
+       ret = ib_check_mr_access(cmd.access_flags);
+       if (ret)
+               return ret;
 
        uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
        if (!uobj)
@@ -2128,6 +2114,9 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
                        }
                        next->wr.ud.remote_qpn  = user_wr->wr.ud.remote_qpn;
                        next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey;
+                       if (next->opcode == IB_WR_SEND_WITH_IMM)
+                               next->ex.imm_data =
+                                       (__be32 __force) user_wr->ex.imm_data;
                } else {
                        switch (next->opcode) {
                        case IB_WR_RDMA_WRITE_WITH_IMM:
@@ -2601,8 +2590,7 @@ out_put:
        return ret ? ret : in_len;
 }
 
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-static int kern_spec_to_ib_spec(struct ib_kern_spec *kern_spec,
+static int kern_spec_to_ib_spec(struct ib_uverbs_flow_spec *kern_spec,
                                union ib_flow_spec *ib_spec)
 {
        ib_spec->type = kern_spec->type;
@@ -2642,28 +2630,31 @@ static int kern_spec_to_ib_spec(struct ib_kern_spec *kern_spec,
        return 0;
 }
 
-ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
-                             const char __user *buf, int in_len,
-                             int out_len)
+int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file,
+                            struct ib_udata *ucore,
+                            struct ib_udata *uhw)
 {
        struct ib_uverbs_create_flow      cmd;
        struct ib_uverbs_create_flow_resp resp;
        struct ib_uobject                 *uobj;
        struct ib_flow                    *flow_id;
-       struct ib_kern_flow_attr          *kern_flow_attr;
+       struct ib_uverbs_flow_attr        *kern_flow_attr;
        struct ib_flow_attr               *flow_attr;
        struct ib_qp                      *qp;
        int err = 0;
        void *kern_spec;
        void *ib_spec;
        int i;
-       int kern_attr_size;
 
-       if (out_len < sizeof(resp))
+       if (ucore->outlen < sizeof(resp))
                return -ENOSPC;
 
-       if (copy_from_user(&cmd, buf, sizeof(cmd)))
-               return -EFAULT;
+       err = ib_copy_from_udata(&cmd, ucore, sizeof(cmd));
+       if (err)
+               return err;
+
+       ucore->inbuf += sizeof(cmd);
+       ucore->inlen -= sizeof(cmd);
 
        if (cmd.comp_mask)
                return -EINVAL;
@@ -2672,32 +2663,27 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
             !capable(CAP_NET_ADMIN)) || !capable(CAP_NET_RAW))
                return -EPERM;
 
-       if (cmd.flow_attr.num_of_specs < 0 ||
-           cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
+       if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
                return -EINVAL;
 
-       kern_attr_size = cmd.flow_attr.size - sizeof(cmd) -
-                        sizeof(struct ib_uverbs_cmd_hdr_ex);
-
-       if (cmd.flow_attr.size < 0 || cmd.flow_attr.size > in_len ||
-           kern_attr_size < 0 || kern_attr_size >
-           (cmd.flow_attr.num_of_specs * sizeof(struct ib_kern_spec)))
+       if (cmd.flow_attr.size > ucore->inlen ||
+           cmd.flow_attr.size >
+           (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
                return -EINVAL;
 
        if (cmd.flow_attr.num_of_specs) {
-               kern_flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL);
+               kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
+                                        GFP_KERNEL);
                if (!kern_flow_attr)
                        return -ENOMEM;
 
                memcpy(kern_flow_attr, &cmd.flow_attr, sizeof(*kern_flow_attr));
-               if (copy_from_user(kern_flow_attr + 1, buf + sizeof(cmd),
-                                  kern_attr_size)) {
-                       err = -EFAULT;
+               err = ib_copy_from_udata(kern_flow_attr + 1, ucore,
+                                        cmd.flow_attr.size);
+               if (err)
                        goto err_free_attr;
-               }
        } else {
                kern_flow_attr = &cmd.flow_attr;
-               kern_attr_size = sizeof(cmd.flow_attr);
        }
 
        uobj = kmalloc(sizeof(*uobj), GFP_KERNEL);
@@ -2714,7 +2700,7 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
                goto err_uobj;
        }
 
-       flow_attr = kmalloc(cmd.flow_attr.size, GFP_KERNEL);
+       flow_attr = kmalloc(sizeof(*flow_attr) + cmd.flow_attr.size, GFP_KERNEL);
        if (!flow_attr) {
                err = -ENOMEM;
                goto err_put;
@@ -2729,19 +2715,22 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
 
        kern_spec = kern_flow_attr + 1;
        ib_spec = flow_attr + 1;
-       for (i = 0; i < flow_attr->num_of_specs && kern_attr_size > 0; i++) {
+       for (i = 0; i < flow_attr->num_of_specs &&
+            cmd.flow_attr.size > offsetof(struct ib_uverbs_flow_spec, reserved) &&
+            cmd.flow_attr.size >=
+            ((struct ib_uverbs_flow_spec *)kern_spec)->size; i++) {
                err = kern_spec_to_ib_spec(kern_spec, ib_spec);
                if (err)
                        goto err_free;
                flow_attr->size +=
                        ((union ib_flow_spec *) ib_spec)->size;
-               kern_attr_size -= ((struct ib_kern_spec *) kern_spec)->size;
-               kern_spec += ((struct ib_kern_spec *) kern_spec)->size;
+               cmd.flow_attr.size -= ((struct ib_uverbs_flow_spec *)kern_spec)->size;
+               kern_spec += ((struct ib_uverbs_flow_spec *) kern_spec)->size;
                ib_spec += ((union ib_flow_spec *) ib_spec)->size;
        }
-       if (kern_attr_size) {
-               pr_warn("create flow failed, %d bytes left from uverb cmd\n",
-                       kern_attr_size);
+       if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
+               pr_warn("create flow failed, flow %d: %d bytes left from uverb cmd\n",
+                       i, cmd.flow_attr.size);
                goto err_free;
        }
        flow_id = ib_create_flow(qp, flow_attr, IB_FLOW_DOMAIN_USER);
@@ -2760,11 +2749,10 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
        memset(&resp, 0, sizeof(resp));
        resp.flow_handle = uobj->id;
 
-       if (copy_to_user((void __user *)(unsigned long) cmd.response,
-                        &resp, sizeof(resp))) {
-               err = -EFAULT;
+       err = ib_copy_to_udata(ucore,
+                              &resp, sizeof(resp));
+       if (err)
                goto err_copy;
-       }
 
        put_qp_read(qp);
        mutex_lock(&file->mutex);
@@ -2777,7 +2765,7 @@ ssize_t ib_uverbs_create_flow(struct ib_uverbs_file *file,
        kfree(flow_attr);
        if (cmd.flow_attr.num_of_specs)
                kfree(kern_flow_attr);
-       return in_len;
+       return 0;
 err_copy:
        idr_remove_uobj(&ib_uverbs_rule_idr, uobj);
 destroy_flow:
@@ -2794,16 +2782,18 @@ err_free_attr:
        return err;
 }
 
-ssize_t ib_uverbs_destroy_flow(struct ib_uverbs_file *file,
-                              const char __user *buf, int in_len,
-                              int out_len) {
+int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file,
+                             struct ib_udata *ucore,
+                             struct ib_udata *uhw)
+{
        struct ib_uverbs_destroy_flow   cmd;
        struct ib_flow                  *flow_id;
        struct ib_uobject               *uobj;
        int                             ret;
 
-       if (copy_from_user(&cmd, buf, sizeof(cmd)))
-               return -EFAULT;
+       ret = ib_copy_from_udata(&cmd, ucore, sizeof(cmd));
+       if (ret)
+               return ret;
 
        uobj = idr_write_uobj(&ib_uverbs_rule_idr, cmd.flow_handle,
                              file->ucontext);
@@ -2825,9 +2815,8 @@ ssize_t ib_uverbs_destroy_flow(struct ib_uverbs_file *file,
 
        put_uobj(uobj);
 
-       return ret ? ret : in_len;
+       return ret;
 }
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
 
 static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
                                struct ib_uverbs_create_xsrq *cmd,
index 2df31f68ea0905ef06ac1ed054348cf669cfaa61..34386943ebcff4cf18849082add568f5fc73bc5a 100644 (file)
@@ -115,10 +115,13 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
        [IB_USER_VERBS_CMD_CLOSE_XRCD]          = ib_uverbs_close_xrcd,
        [IB_USER_VERBS_CMD_CREATE_XSRQ]         = ib_uverbs_create_xsrq,
        [IB_USER_VERBS_CMD_OPEN_QP]             = ib_uverbs_open_qp,
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-       [IB_USER_VERBS_CMD_CREATE_FLOW]         = ib_uverbs_create_flow,
-       [IB_USER_VERBS_CMD_DESTROY_FLOW]        = ib_uverbs_destroy_flow
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
+};
+
+static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file,
+                                   struct ib_udata *ucore,
+                                   struct ib_udata *uhw) = {
+       [IB_USER_VERBS_EX_CMD_CREATE_FLOW]      = ib_uverbs_ex_create_flow,
+       [IB_USER_VERBS_EX_CMD_DESTROY_FLOW]     = ib_uverbs_ex_destroy_flow
 };
 
 static void ib_uverbs_add_one(struct ib_device *device);
@@ -589,6 +592,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
 {
        struct ib_uverbs_file *file = filp->private_data;
        struct ib_uverbs_cmd_hdr hdr;
+       __u32 flags;
 
        if (count < sizeof hdr)
                return -EINVAL;
@@ -596,45 +600,105 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
        if (copy_from_user(&hdr, buf, sizeof hdr))
                return -EFAULT;
 
-       if (hdr.command >= ARRAY_SIZE(uverbs_cmd_table) ||
-           !uverbs_cmd_table[hdr.command])
-               return -EINVAL;
+       flags = (hdr.command &
+                IB_USER_VERBS_CMD_FLAGS_MASK) >> IB_USER_VERBS_CMD_FLAGS_SHIFT;
 
-       if (!file->ucontext &&
-           hdr.command != IB_USER_VERBS_CMD_GET_CONTEXT)
-               return -EINVAL;
+       if (!flags) {
+               __u32 command;
 
-       if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command)))
-               return -ENOSYS;
+               if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
+                                          IB_USER_VERBS_CMD_COMMAND_MASK))
+                       return -EINVAL;
 
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-       if (hdr.command >= IB_USER_VERBS_CMD_THRESHOLD) {
-               struct ib_uverbs_cmd_hdr_ex hdr_ex;
+               command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
 
-               if (copy_from_user(&hdr_ex, buf, sizeof(hdr_ex)))
-                       return -EFAULT;
+               if (command >= ARRAY_SIZE(uverbs_cmd_table) ||
+                   !uverbs_cmd_table[command])
+                       return -EINVAL;
 
-               if (((hdr_ex.in_words + hdr_ex.provider_in_words) * 4) != count)
+               if (!file->ucontext &&
+                   command != IB_USER_VERBS_CMD_GET_CONTEXT)
                        return -EINVAL;
 
-               return uverbs_cmd_table[hdr.command](file,
-                                                    buf + sizeof(hdr_ex),
-                                                    (hdr_ex.in_words +
-                                                     hdr_ex.provider_in_words) * 4,
-                                                    (hdr_ex.out_words +
-                                                     hdr_ex.provider_out_words) * 4);
-       } else {
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
+               if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << command)))
+                       return -ENOSYS;
+
                if (hdr.in_words * 4 != count)
                        return -EINVAL;
 
-               return uverbs_cmd_table[hdr.command](file,
-                                                    buf + sizeof(hdr),
-                                                    hdr.in_words * 4,
-                                                    hdr.out_words * 4);
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
+               return uverbs_cmd_table[command](file,
+                                                buf + sizeof(hdr),
+                                                hdr.in_words * 4,
+                                                hdr.out_words * 4);
+
+       } else if (flags == IB_USER_VERBS_CMD_FLAG_EXTENDED) {
+               __u32 command;
+
+               struct ib_uverbs_ex_cmd_hdr ex_hdr;
+               struct ib_udata ucore;
+               struct ib_udata uhw;
+               int err;
+               size_t written_count = count;
+
+               if (hdr.command & ~(__u32)(IB_USER_VERBS_CMD_FLAGS_MASK |
+                                          IB_USER_VERBS_CMD_COMMAND_MASK))
+                       return -EINVAL;
+
+               command = hdr.command & IB_USER_VERBS_CMD_COMMAND_MASK;
+
+               if (command >= ARRAY_SIZE(uverbs_ex_cmd_table) ||
+                   !uverbs_ex_cmd_table[command])
+                       return -ENOSYS;
+
+               if (!file->ucontext)
+                       return -EINVAL;
+
+               if (!(file->device->ib_dev->uverbs_ex_cmd_mask & (1ull << command)))
+                       return -ENOSYS;
+
+               if (count < (sizeof(hdr) + sizeof(ex_hdr)))
+                       return -EINVAL;
+
+               if (copy_from_user(&ex_hdr, buf + sizeof(hdr), sizeof(ex_hdr)))
+                       return -EFAULT;
+
+               count -= sizeof(hdr) + sizeof(ex_hdr);
+               buf += sizeof(hdr) + sizeof(ex_hdr);
+
+               if ((hdr.in_words + ex_hdr.provider_in_words) * 8 != count)
+                       return -EINVAL;
+
+               if (ex_hdr.response) {
+                       if (!hdr.out_words && !ex_hdr.provider_out_words)
+                               return -EINVAL;
+               } else {
+                       if (hdr.out_words || ex_hdr.provider_out_words)
+                               return -EINVAL;
+               }
+
+               INIT_UDATA(&ucore,
+                          (hdr.in_words) ? buf : 0,
+                          (unsigned long)ex_hdr.response,
+                          hdr.in_words * 8,
+                          hdr.out_words * 8);
+
+               INIT_UDATA(&uhw,
+                          (ex_hdr.provider_in_words) ? buf + ucore.inlen : 0,
+                          (ex_hdr.provider_out_words) ? (unsigned long)ex_hdr.response + ucore.outlen : 0,
+                          ex_hdr.provider_in_words * 8,
+                          ex_hdr.provider_out_words * 8);
+
+               err = uverbs_ex_cmd_table[command](file,
+                                                  &ucore,
+                                                  &uhw);
+
+               if (err)
+                       return err;
+
+               return written_count;
        }
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
+
+       return -ENOSYS;
 }
 
 static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
index a321df28bab2696404e76a365c861637867b68d2..d4f6ddf72ffa5add41bd392d6ed773386a93bdb7 100644 (file)
@@ -114,6 +114,8 @@ rdma_node_get_transport(enum rdma_node_type node_type)
                return RDMA_TRANSPORT_IB;
        case RDMA_NODE_RNIC:
                return RDMA_TRANSPORT_IWARP;
+       case RDMA_NODE_USNIC:
+               return RDMA_TRANSPORT_USNIC;
        default:
                BUG();
                return 0;
@@ -130,6 +132,7 @@ enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, u8 port_
        case RDMA_TRANSPORT_IB:
                return IB_LINK_LAYER_INFINIBAND;
        case RDMA_TRANSPORT_IWARP:
+       case RDMA_TRANSPORT_USNIC:
                return IB_LINK_LAYER_ETHERNET;
        default:
                return IB_LINK_LAYER_UNSPECIFIED;
@@ -958,6 +961,11 @@ EXPORT_SYMBOL(ib_resize_cq);
 struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags)
 {
        struct ib_mr *mr;
+       int err;
+
+       err = ib_check_mr_access(mr_access_flags);
+       if (err)
+               return ERR_PTR(err);
 
        mr = pd->device->get_dma_mr(pd, mr_access_flags);
 
@@ -980,6 +988,11 @@ struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
                             u64 *iova_start)
 {
        struct ib_mr *mr;
+       int err;
+
+       err = ib_check_mr_access(mr_access_flags);
+       if (err)
+               return ERR_PTR(err);
 
        if (!pd->device->reg_phys_mr)
                return ERR_PTR(-ENOSYS);
@@ -1010,6 +1023,10 @@ int ib_rereg_phys_mr(struct ib_mr *mr,
        struct ib_pd *old_pd;
        int ret;
 
+       ret = ib_check_mr_access(mr_access_flags);
+       if (ret)
+               return ret;
+
        if (!mr->device->rereg_phys_mr)
                return -ENOSYS;
 
index 33d2cc6ab56220bed4a49af1fb0f22e68955508d..4a033853312e52c6ff026d8e7e7892f010826255 100644 (file)
@@ -602,10 +602,10 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev)
             rdev->lldi.vr->qp.size,
             rdev->lldi.vr->cq.start,
             rdev->lldi.vr->cq.size);
-       PDBG("udb len 0x%x udb base %p db_reg %p gts_reg %p qpshift %lu "
+       PDBG("udb len 0x%x udb base %llx db_reg %p gts_reg %p qpshift %lu "
             "qpmask 0x%x cqshift %lu cqmask 0x%x\n",
             (unsigned)pci_resource_len(rdev->lldi.pdev, 2),
-            (void *)(unsigned long)pci_resource_start(rdev->lldi.pdev, 2),
+            (u64)pci_resource_start(rdev->lldi.pdev, 2),
             rdev->lldi.db_reg,
             rdev->lldi.gts_reg,
             rdev->qpshift, rdev->qpmask,
index f5cb13b2144566229c03be75e31623cb19942d45..cc04b7ba34882cc7981ec3815af73dc7a0519d91 100644 (file)
@@ -280,9 +280,7 @@ static int ipath_user_sdma_pin_pages(const struct ipath_devdata *dd,
        int j;
        int ret;
 
-       ret = get_user_pages(current, current->mm, addr,
-                            npages, 0, 1, pages, NULL);
-
+       ret = get_user_pages_fast(addr, npages, 0, pages);
        if (ret != npages) {
                int i;
 
@@ -811,10 +809,7 @@ int ipath_user_sdma_writev(struct ipath_devdata *dd,
        while (dim) {
                const int mxp = 8;
 
-               down_write(&current->mm->mmap_sem);
                ret = ipath_user_sdma_queue_pkts(dd, pq, &list, iov, dim, mxp);
-               up_write(&current->mm->mmap_sem);
-
                if (ret <= 0)
                        goto done_unlock;
                else {
index d5e60f44ba5ad7c4f5ad53d7e0fe348248ed797b..66dbf8062374784299f5e3790738a424248116c7 100644 (file)
@@ -324,7 +324,7 @@ static int mlx4_ib_get_outstanding_cqes(struct mlx4_ib_cq *cq)
        u32 i;
 
        i = cq->mcq.cons_index;
-       while (get_sw_cqe(cq, i & cq->ibcq.cqe))
+       while (get_sw_cqe(cq, i))
                ++i;
 
        return i - cq->mcq.cons_index;
@@ -365,7 +365,7 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
 
        mutex_lock(&cq->resize_mutex);
 
-       if (entries < 1 || entries > dev->dev->caps.max_cqes) {
+       if (entries < 1) {
                err = -EINVAL;
                goto out;
        }
@@ -376,6 +376,11 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
                goto out;
        }
 
+       if (entries > dev->dev->caps.max_cqes) {
+               err = -EINVAL;
+               goto out;
+       }
+
        if (ibcq->uobject) {
                err = mlx4_alloc_resize_umem(dev, cq, entries, udata);
                if (err)
index 6a0a0d29660df5fe7d3cd90bf5c74eead9da4936..1958c5ca792ad52a39ece6247040588c00b84ba6 100644 (file)
@@ -1685,11 +1685,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
                ibdev->ib_dev.create_flow       = mlx4_ib_create_flow;
                ibdev->ib_dev.destroy_flow      = mlx4_ib_destroy_flow;
 
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-               ibdev->ib_dev.uverbs_cmd_mask   |=
-                       (1ull << IB_USER_VERBS_CMD_CREATE_FLOW) |
-                       (1ull << IB_USER_VERBS_CMD_DESTROY_FLOW);
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
+               ibdev->ib_dev.uverbs_ex_cmd_mask        |=
+                       (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) |
+                       (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW);
        }
 
        mlx4_ib_alloc_eqs(dev, ibdev);
index 344ab03948a315cafc0422863f70a6e30443ff49..b726274297458e2de91b2c324881f2f83dababf6 100644 (file)
@@ -556,7 +556,7 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
                goto err_db;
        }
        mlx5_ib_populate_pas(dev, cq->buf.umem, page_shift, (*cqb)->pas, 0);
-       (*cqb)->ctx.log_pg_sz = page_shift - PAGE_SHIFT;
+       (*cqb)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT;
 
        *index = to_mucontext(context)->uuari.uars[0].index;
 
@@ -620,7 +620,7 @@ static int create_cq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_cq *cq,
        }
        mlx5_fill_page_array(&cq->buf.buf, (*cqb)->pas);
 
-       (*cqb)->ctx.log_pg_sz = cq->buf.buf.page_shift - PAGE_SHIFT;
+       (*cqb)->ctx.log_pg_sz = cq->buf.buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT;
        *index = dev->mdev.priv.uuari.uars[0].index;
 
        return 0;
@@ -653,8 +653,11 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, int entries,
        int eqn;
        int err;
 
+       if (entries < 0)
+               return ERR_PTR(-EINVAL);
+
        entries = roundup_pow_of_two(entries + 1);
-       if (entries < 1 || entries > dev->mdev.caps.max_cqes)
+       if (entries > dev->mdev.caps.max_cqes)
                return ERR_PTR(-EINVAL);
 
        cq = kzalloc(sizeof(*cq), GFP_KERNEL);
@@ -747,17 +750,9 @@ int mlx5_ib_destroy_cq(struct ib_cq *cq)
        return 0;
 }
 
-static int is_equal_rsn(struct mlx5_cqe64 *cqe64, struct mlx5_ib_srq *srq,
-                       u32 rsn)
+static int is_equal_rsn(struct mlx5_cqe64 *cqe64, u32 rsn)
 {
-       u32 lrsn;
-
-       if (srq)
-               lrsn = be32_to_cpu(cqe64->srqn) & 0xffffff;
-       else
-               lrsn = be32_to_cpu(cqe64->sop_drop_qpn) & 0xffffff;
-
-       return rsn == lrsn;
+       return rsn == (ntohl(cqe64->sop_drop_qpn) & 0xffffff);
 }
 
 void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 rsn, struct mlx5_ib_srq *srq)
@@ -787,8 +782,8 @@ void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 rsn, struct mlx5_ib_srq *srq)
        while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) {
                cqe = get_cqe(cq, prod_index & cq->ibcq.cqe);
                cqe64 = (cq->mcq.cqe_sz == 64) ? cqe : cqe + 64;
-               if (is_equal_rsn(cqe64, srq, rsn)) {
-                       if (srq)
+               if (is_equal_rsn(cqe64, rsn)) {
+                       if (srq && (ntohl(cqe64->srqn) & 0xffffff))
                                mlx5_ib_free_srq_wqe(srq, be16_to_cpu(cqe64->wqe_counter));
                        ++nfreed;
                } else if (nfreed) {
index b1a6cb3a2809282fbfab1b44b09c53e315a93466..306534109627082c36e30f270b219e1a500c5590 100644 (file)
@@ -745,7 +745,8 @@ static int alloc_pa_mkey(struct mlx5_ib_dev *dev, u32 *key, u32 pdn)
        seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
        seg->start_addr = 0;
 
-       err = mlx5_core_create_mkey(&dev->mdev, &mr, in, sizeof(*in));
+       err = mlx5_core_create_mkey(&dev->mdev, &mr, in, sizeof(*in),
+                                   NULL, NULL, NULL);
        if (err) {
                mlx5_ib_warn(dev, "failed to create mkey, %d\n", err);
                goto err_in;
index 836be91572424a9f9fd87f41b353b88f67706e06..4c134d93d4fc150ca668f69eb998b563ad3ff47a 100644 (file)
@@ -262,6 +262,9 @@ struct mlx5_ib_mr {
        int                     npages;
        struct completion       done;
        enum ib_wc_status       status;
+       struct mlx5_ib_dev     *dev;
+       struct mlx5_create_mkey_mbox_out out;
+       unsigned long           start;
 };
 
 struct mlx5_ib_fast_reg_page_list {
@@ -323,6 +326,7 @@ struct mlx5_cache_ent {
        struct mlx5_ib_dev     *dev;
        struct work_struct      work;
        struct delayed_work     dwork;
+       int                     pending;
 };
 
 struct mlx5_mr_cache {
@@ -358,6 +362,8 @@ struct mlx5_ib_dev {
        spinlock_t                      mr_lock;
        struct mlx5_ib_resources        devr;
        struct mlx5_mr_cache            cache;
+       struct timer_list               delay_timer;
+       int                             fill_delay;
 };
 
 static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
index 3453580b1eb2cc45800b8ee697157a24cf269970..039c3e40fcb4c3f36d5dba3c3ef9daf0ed5c74e0 100644 (file)
 #include <linux/random.h>
 #include <linux/debugfs.h>
 #include <linux/export.h>
+#include <linux/delay.h>
 #include <rdma/ib_umem.h>
 #include "mlx5_ib.h"
 
 enum {
-       DEF_CACHE_SIZE  = 10,
+       MAX_PENDING_REG_MR = 8,
 };
 
 enum {
@@ -63,6 +64,51 @@ static int order2idx(struct mlx5_ib_dev *dev, int order)
                return order - cache->ent[0].order;
 }
 
+static void reg_mr_callback(int status, void *context)
+{
+       struct mlx5_ib_mr *mr = context;
+       struct mlx5_ib_dev *dev = mr->dev;
+       struct mlx5_mr_cache *cache = &dev->cache;
+       int c = order2idx(dev, mr->order);
+       struct mlx5_cache_ent *ent = &cache->ent[c];
+       u8 key;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ent->lock, flags);
+       ent->pending--;
+       spin_unlock_irqrestore(&ent->lock, flags);
+       if (status) {
+               mlx5_ib_warn(dev, "async reg mr failed. status %d\n", status);
+               kfree(mr);
+               dev->fill_delay = 1;
+               mod_timer(&dev->delay_timer, jiffies + HZ);
+               return;
+       }
+
+       if (mr->out.hdr.status) {
+               mlx5_ib_warn(dev, "failed - status %d, syndorme 0x%x\n",
+                            mr->out.hdr.status,
+                            be32_to_cpu(mr->out.hdr.syndrome));
+               kfree(mr);
+               dev->fill_delay = 1;
+               mod_timer(&dev->delay_timer, jiffies + HZ);
+               return;
+       }
+
+       spin_lock_irqsave(&dev->mdev.priv.mkey_lock, flags);
+       key = dev->mdev.priv.mkey_key++;
+       spin_unlock_irqrestore(&dev->mdev.priv.mkey_lock, flags);
+       mr->mmr.key = mlx5_idx_to_mkey(be32_to_cpu(mr->out.mkey) & 0xffffff) | key;
+
+       cache->last_add = jiffies;
+
+       spin_lock_irqsave(&ent->lock, flags);
+       list_add_tail(&mr->list, &ent->head);
+       ent->cur++;
+       ent->size++;
+       spin_unlock_irqrestore(&ent->lock, flags);
+}
+
 static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
 {
        struct mlx5_mr_cache *cache = &dev->cache;
@@ -78,36 +124,39 @@ static int add_keys(struct mlx5_ib_dev *dev, int c, int num)
                return -ENOMEM;
 
        for (i = 0; i < num; i++) {
+               if (ent->pending >= MAX_PENDING_REG_MR) {
+                       err = -EAGAIN;
+                       break;
+               }
+
                mr = kzalloc(sizeof(*mr), GFP_KERNEL);
                if (!mr) {
                        err = -ENOMEM;
-                       goto out;
+                       break;
                }
                mr->order = ent->order;
                mr->umred = 1;
+               mr->dev = dev;
                in->seg.status = 1 << 6;
                in->seg.xlt_oct_size = cpu_to_be32((npages + 1) / 2);
                in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
                in->seg.flags = MLX5_ACCESS_MODE_MTT | MLX5_PERM_UMR_EN;
                in->seg.log2_page_size = 12;
 
+               spin_lock_irq(&ent->lock);
+               ent->pending++;
+               spin_unlock_irq(&ent->lock);
+               mr->start = jiffies;
                err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in,
-                                           sizeof(*in));
+                                           sizeof(*in), reg_mr_callback,
+                                           mr, &mr->out);
                if (err) {
                        mlx5_ib_warn(dev, "create mkey failed %d\n", err);
                        kfree(mr);
-                       goto out;
+                       break;
                }
-               cache->last_add = jiffies;
-
-               spin_lock(&ent->lock);
-               list_add_tail(&mr->list, &ent->head);
-               ent->cur++;
-               ent->size++;
-               spin_unlock(&ent->lock);
        }
 
-out:
        kfree(in);
        return err;
 }
@@ -121,16 +170,16 @@ static void remove_keys(struct mlx5_ib_dev *dev, int c, int num)
        int i;
 
        for (i = 0; i < num; i++) {
-               spin_lock(&ent->lock);
+               spin_lock_irq(&ent->lock);
                if (list_empty(&ent->head)) {
-                       spin_unlock(&ent->lock);
+                       spin_unlock_irq(&ent->lock);
                        return;
                }
                mr = list_first_entry(&ent->head, struct mlx5_ib_mr, list);
                list_del(&mr->list);
                ent->cur--;
                ent->size--;
-               spin_unlock(&ent->lock);
+               spin_unlock_irq(&ent->lock);
                err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr);
                if (err)
                        mlx5_ib_warn(dev, "failed destroy mkey\n");
@@ -162,9 +211,13 @@ static ssize_t size_write(struct file *filp, const char __user *buf,
                return -EINVAL;
 
        if (var > ent->size) {
-               err = add_keys(dev, c, var - ent->size);
-               if (err)
-                       return err;
+               do {
+                       err = add_keys(dev, c, var - ent->size);
+                       if (err && err != -EAGAIN)
+                               return err;
+
+                       usleep_range(3000, 5000);
+               } while (err);
        } else if (var < ent->size) {
                remove_keys(dev, c, ent->size - var);
        }
@@ -280,23 +333,37 @@ static void __cache_work_func(struct mlx5_cache_ent *ent)
        struct mlx5_ib_dev *dev = ent->dev;
        struct mlx5_mr_cache *cache = &dev->cache;
        int i = order2idx(dev, ent->order);
+       int err;
 
        if (cache->stopped)
                return;
 
        ent = &dev->cache.ent[i];
-       if (ent->cur < 2 * ent->limit) {
-               add_keys(dev, i, 1);
-               if (ent->cur < 2 * ent->limit)
-                       queue_work(cache->wq, &ent->work);
+       if (ent->cur < 2 * ent->limit && !dev->fill_delay) {
+               err = add_keys(dev, i, 1);
+               if (ent->cur < 2 * ent->limit) {
+                       if (err == -EAGAIN) {
+                               mlx5_ib_dbg(dev, "returned eagain, order %d\n",
+                                           i + 2);
+                               queue_delayed_work(cache->wq, &ent->dwork,
+                                                  msecs_to_jiffies(3));
+                       } else if (err) {
+                               mlx5_ib_warn(dev, "command failed order %d, err %d\n",
+                                            i + 2, err);
+                               queue_delayed_work(cache->wq, &ent->dwork,
+                                                  msecs_to_jiffies(1000));
+                       } else {
+                               queue_work(cache->wq, &ent->work);
+                       }
+               }
        } else if (ent->cur > 2 * ent->limit) {
                if (!someone_adding(cache) &&
-                   time_after(jiffies, cache->last_add + 60 * HZ)) {
+                   time_after(jiffies, cache->last_add + 300 * HZ)) {
                        remove_keys(dev, i, 1);
                        if (ent->cur > ent->limit)
                                queue_work(cache->wq, &ent->work);
                } else {
-                       queue_delayed_work(cache->wq, &ent->dwork, 60 * HZ);
+                       queue_delayed_work(cache->wq, &ent->dwork, 300 * HZ);
                }
        }
 }
@@ -336,18 +403,18 @@ static struct mlx5_ib_mr *alloc_cached_mr(struct mlx5_ib_dev *dev, int order)
 
                mlx5_ib_dbg(dev, "order %d, cache index %d\n", ent->order, i);
 
-               spin_lock(&ent->lock);
+               spin_lock_irq(&ent->lock);
                if (!list_empty(&ent->head)) {
                        mr = list_first_entry(&ent->head, struct mlx5_ib_mr,
                                              list);
                        list_del(&mr->list);
                        ent->cur--;
-                       spin_unlock(&ent->lock);
+                       spin_unlock_irq(&ent->lock);
                        if (ent->cur < ent->limit)
                                queue_work(cache->wq, &ent->work);
                        break;
                }
-               spin_unlock(&ent->lock);
+               spin_unlock_irq(&ent->lock);
 
                queue_work(cache->wq, &ent->work);
 
@@ -374,12 +441,12 @@ static void free_cached_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
                return;
        }
        ent = &cache->ent[c];
-       spin_lock(&ent->lock);
+       spin_lock_irq(&ent->lock);
        list_add_tail(&mr->list, &ent->head);
        ent->cur++;
        if (ent->cur > 2 * ent->limit)
                shrink = 1;
-       spin_unlock(&ent->lock);
+       spin_unlock_irq(&ent->lock);
 
        if (shrink)
                queue_work(cache->wq, &ent->work);
@@ -394,16 +461,16 @@ static void clean_keys(struct mlx5_ib_dev *dev, int c)
 
        cancel_delayed_work(&ent->dwork);
        while (1) {
-               spin_lock(&ent->lock);
+               spin_lock_irq(&ent->lock);
                if (list_empty(&ent->head)) {
-                       spin_unlock(&ent->lock);
+                       spin_unlock_irq(&ent->lock);
                        return;
                }
                mr = list_first_entry(&ent->head, struct mlx5_ib_mr, list);
                list_del(&mr->list);
                ent->cur--;
                ent->size--;
-               spin_unlock(&ent->lock);
+               spin_unlock_irq(&ent->lock);
                err = mlx5_core_destroy_mkey(&dev->mdev, &mr->mmr);
                if (err)
                        mlx5_ib_warn(dev, "failed destroy mkey\n");
@@ -464,12 +531,18 @@ static void mlx5_mr_cache_debugfs_cleanup(struct mlx5_ib_dev *dev)
        debugfs_remove_recursive(dev->cache.root);
 }
 
+static void delay_time_func(unsigned long ctx)
+{
+       struct mlx5_ib_dev *dev = (struct mlx5_ib_dev *)ctx;
+
+       dev->fill_delay = 0;
+}
+
 int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
 {
        struct mlx5_mr_cache *cache = &dev->cache;
        struct mlx5_cache_ent *ent;
        int limit;
-       int size;
        int err;
        int i;
 
@@ -479,6 +552,7 @@ int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
                return -ENOMEM;
        }
 
+       setup_timer(&dev->delay_timer, delay_time_func, (unsigned long)dev);
        for (i = 0; i < MAX_MR_CACHE_ENTRIES; i++) {
                INIT_LIST_HEAD(&cache->ent[i].head);
                spin_lock_init(&cache->ent[i].lock);
@@ -489,13 +563,11 @@ int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
                ent->order = i + 2;
                ent->dev = dev;
 
-               if (dev->mdev.profile->mask & MLX5_PROF_MASK_MR_CACHE) {
-                       size = dev->mdev.profile->mr_cache[i].size;
+               if (dev->mdev.profile->mask & MLX5_PROF_MASK_MR_CACHE)
                        limit = dev->mdev.profile->mr_cache[i].limit;
-               } else {
-                       size = DEF_CACHE_SIZE;
+               else
                        limit = 0;
-               }
+
                INIT_WORK(&ent->work, cache_work_func);
                INIT_DELAYED_WORK(&ent->dwork, delayed_cache_work_func);
                ent->limit = limit;
@@ -522,6 +594,7 @@ int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev)
                clean_keys(dev, i);
 
        destroy_workqueue(dev->cache.wq);
+       del_timer_sync(&dev->delay_timer);
 
        return 0;
 }
@@ -551,7 +624,8 @@ struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc)
        seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
        seg->start_addr = 0;
 
-       err = mlx5_core_create_mkey(mdev, &mr->mmr, in, sizeof(*in));
+       err = mlx5_core_create_mkey(mdev, &mr->mmr, in, sizeof(*in), NULL, NULL,
+                                   NULL);
        if (err)
                goto err_in;
 
@@ -660,14 +734,14 @@ static struct mlx5_ib_mr *reg_umr(struct ib_pd *pd, struct ib_umem *umem,
        int err;
        int i;
 
-       for (i = 0; i < 10; i++) {
+       for (i = 0; i < 1; i++) {
                mr = alloc_cached_mr(dev, order);
                if (mr)
                        break;
 
                err = add_keys(dev, order2idx(dev, order), 1);
-               if (err) {
-                       mlx5_ib_warn(dev, "add_keys failed\n");
+               if (err && err != -EAGAIN) {
+                       mlx5_ib_warn(dev, "add_keys failed, err %d\n", err);
                        break;
                }
        }
@@ -759,8 +833,10 @@ static struct mlx5_ib_mr *reg_create(struct ib_pd *pd, u64 virt_addr,
        in->seg.xlt_oct_size = cpu_to_be32(get_octo_len(virt_addr, length, 1 << page_shift));
        in->seg.log2_page_size = page_shift;
        in->seg.qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
-       in->xlat_oct_act_size = cpu_to_be32(get_octo_len(virt_addr, length, 1 << page_shift));
-       err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, inlen);
+       in->xlat_oct_act_size = cpu_to_be32(get_octo_len(virt_addr, length,
+                                                        1 << page_shift));
+       err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, inlen, NULL,
+                                   NULL, NULL);
        if (err) {
                mlx5_ib_warn(dev, "create mkey failed\n");
                goto err_2;
@@ -944,7 +1020,8 @@ struct ib_mr *mlx5_ib_alloc_fast_reg_mr(struct ib_pd *pd,
         * TBD not needed - issue 197292 */
        in->seg.log2_page_size = PAGE_SHIFT;
 
-       err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, sizeof(*in));
+       err = mlx5_core_create_mkey(&dev->mdev, &mr->mmr, in, sizeof(*in), NULL,
+                                   NULL, NULL);
        kfree(in);
        if (err)
                goto err_free;
index 5659ea88074108e60d9253085ce89f962326b808..7c6b4ba49bec13c920120cb775090bd153354fb5 100644 (file)
@@ -551,7 +551,7 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,
        }
        mlx5_ib_populate_pas(dev, qp->umem, page_shift, (*in)->pas, 0);
        (*in)->ctx.log_pg_sz_remote_qpn =
-               cpu_to_be32((page_shift - PAGE_SHIFT) << 24);
+               cpu_to_be32((page_shift - MLX5_ADAPTER_PAGE_SHIFT) << 24);
        (*in)->ctx.params2 = cpu_to_be32(offset << 6);
 
        (*in)->ctx.qp_counter_set_usr_page = cpu_to_be32(uar_index);
@@ -648,7 +648,8 @@ static int create_kernel_qp(struct mlx5_ib_dev *dev,
                goto err_buf;
        }
        (*in)->ctx.qp_counter_set_usr_page = cpu_to_be32(uar_index);
-       (*in)->ctx.log_pg_sz_remote_qpn = cpu_to_be32((qp->buf.page_shift - PAGE_SHIFT) << 24);
+       (*in)->ctx.log_pg_sz_remote_qpn =
+               cpu_to_be32((qp->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT) << 24);
        /* Set "fast registration enabled" for all kernel QPs */
        (*in)->ctx.params1 |= cpu_to_be32(1 << 11);
        (*in)->ctx.sq_crq_size |= cpu_to_be16(1 << 4);
@@ -1317,9 +1318,11 @@ static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_Q
                                          MLX5_QP_OPTPAR_RAE            |
                                          MLX5_QP_OPTPAR_RWE            |
                                          MLX5_QP_OPTPAR_RNR_TIMEOUT    |
-                                         MLX5_QP_OPTPAR_PM_STATE,
+                                         MLX5_QP_OPTPAR_PM_STATE       |
+                                         MLX5_QP_OPTPAR_ALT_ADDR_PATH,
                        [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE            |
-                                         MLX5_QP_OPTPAR_PM_STATE,
+                                         MLX5_QP_OPTPAR_PM_STATE       |
+                                         MLX5_QP_OPTPAR_ALT_ADDR_PATH,
                        [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY          |
                                          MLX5_QP_OPTPAR_SRQN           |
                                          MLX5_QP_OPTPAR_CQN_RCV,
@@ -1550,7 +1553,7 @@ static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
        mlx5_cur = to_mlx5_state(cur_state);
        mlx5_new = to_mlx5_state(new_state);
        mlx5_st = to_mlx5_st(ibqp->qp_type);
-       if (mlx5_cur < 0 || mlx5_new < 0 || mlx5_st < 0)
+       if (mlx5_st < 0)
                goto out;
 
        optpar = ib_mask_to_mlx5_opt(attr_mask);
@@ -1744,6 +1747,7 @@ static void set_reg_umr_segment(struct mlx5_wqe_umr_ctrl_seg *umr,
                        MLX5_MKEY_MASK_PD               |
                        MLX5_MKEY_MASK_LR               |
                        MLX5_MKEY_MASK_LW               |
+                       MLX5_MKEY_MASK_KEY              |
                        MLX5_MKEY_MASK_RR               |
                        MLX5_MKEY_MASK_RW               |
                        MLX5_MKEY_MASK_A                |
@@ -1800,7 +1804,8 @@ static void set_reg_mkey_segment(struct mlx5_mkey_seg *seg, struct ib_send_wr *w
        seg->start_addr = cpu_to_be64(wr->wr.fast_reg.iova_start);
        seg->len = cpu_to_be64(wr->wr.fast_reg.length);
        seg->log2_page_size = wr->wr.fast_reg.page_shift;
-       seg->qpn_mkey7_0 = cpu_to_be32(0xffffff << 8);
+       seg->qpn_mkey7_0 = cpu_to_be32(0xffffff00 |
+                                      mlx5_mkey_variant(wr->wr.fast_reg.rkey));
 }
 
 static void set_frwr_pages(struct mlx5_wqe_data_seg *dseg,
@@ -1913,6 +1918,10 @@ static int set_frwr_li_wr(void **seg, struct ib_send_wr *wr, int *size,
        if (unlikely((*seg == qp->sq.qend)))
                *seg = mlx5_get_send_wqe(qp, 0);
        if (!li) {
+               if (unlikely(wr->wr.fast_reg.page_list_len >
+                            wr->wr.fast_reg.page_list->max_page_list_len))
+                       return  -ENOMEM;
+
                set_frwr_pages(*seg, wr, mdev, pd, writ);
                *seg += sizeof(struct mlx5_wqe_data_seg);
                *size += (sizeof(struct mlx5_wqe_data_seg) / 16);
index 0aa478bc291ae39aec0ed8c243cce72fe7ed2bdd..210b3eaf188aa25fcf11f657cefe907c8f77f197 100644 (file)
@@ -123,7 +123,7 @@ static int create_srq_user(struct ib_pd *pd, struct mlx5_ib_srq *srq,
                goto err_in;
        }
 
-       (*in)->ctx.log_pg_sz = page_shift - PAGE_SHIFT;
+       (*in)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT;
        (*in)->ctx.pgoff_cqn = cpu_to_be32(offset << 26);
 
        return 0;
@@ -192,7 +192,7 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
        }
        srq->wq_sig = !!srq_signature;
 
-       (*in)->ctx.log_pg_sz = page_shift - PAGE_SHIFT;
+       (*in)->ctx.log_pg_sz = page_shift - MLX5_ADAPTER_PAGE_SHIFT;
 
        return 0;
 
@@ -390,9 +390,7 @@ int mlx5_ib_destroy_srq(struct ib_srq *srq)
                mlx5_ib_db_unmap_user(to_mucontext(srq->uobject->context), &msrq->db);
                ib_umem_release(msrq->umem);
        } else {
-               kfree(msrq->wrid);
-               mlx5_buf_free(&dev->mdev, &msrq->buf);
-               mlx5_db_free(&dev->mdev, &msrq->db);
+               destroy_srq_kernel(dev, msrq);
        }
 
        kfree(srq);
index 5b53ca5a22840c14e31ddb0d7e978dfac5c179b7..8308e3634767958a4a46920ca11983bf62e62e13 100644 (file)
@@ -2834,7 +2834,7 @@ static int nes_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
        init_attr->qp_context = nesqp->ibqp.qp_context;
        init_attr->send_cq = nesqp->ibqp.send_cq;
        init_attr->recv_cq = nesqp->ibqp.recv_cq;
-       init_attr->srq = nesqp->ibqp.srq = nesqp->ibqp.srq;
+       init_attr->srq = nesqp->ibqp.srq;
        init_attr->cap = attr->cap;
 
        return 0;
index adc11d14f8783faa9afcac1ee6b6faaadcb8d267..294dd27b601e0434e251b46732c66f69cfb9d242 100644 (file)
@@ -122,6 +122,32 @@ struct mqe_ctx {
        bool cmd_done;
 };
 
+struct ocrdma_hw_mr {
+       u32 lkey;
+       u8 fr_mr;
+       u8 remote_atomic;
+       u8 remote_rd;
+       u8 remote_wr;
+       u8 local_rd;
+       u8 local_wr;
+       u8 mw_bind;
+       u8 rsvd;
+       u64 len;
+       struct ocrdma_pbl *pbl_table;
+       u32 num_pbls;
+       u32 num_pbes;
+       u32 pbl_size;
+       u32 pbe_size;
+       u64 fbo;
+       u64 va;
+};
+
+struct ocrdma_mr {
+       struct ib_mr ibmr;
+       struct ib_umem *umem;
+       struct ocrdma_hw_mr hwmr;
+};
+
 struct ocrdma_dev {
        struct ib_device ibdev;
        struct ocrdma_dev_attr attr;
@@ -169,7 +195,7 @@ struct ocrdma_dev {
        struct list_head entry;
        struct rcu_head rcu;
        int id;
-       u64 stag_arr[OCRDMA_MAX_STAG];
+       struct ocrdma_mr *stag_arr[OCRDMA_MAX_STAG];
        u16 pvid;
 };
 
@@ -294,31 +320,6 @@ struct ocrdma_qp {
        u16 db_cache;
 };
 
-struct ocrdma_hw_mr {
-       u32 lkey;
-       u8 fr_mr;
-       u8 remote_atomic;
-       u8 remote_rd;
-       u8 remote_wr;
-       u8 local_rd;
-       u8 local_wr;
-       u8 mw_bind;
-       u8 rsvd;
-       u64 len;
-       struct ocrdma_pbl *pbl_table;
-       u32 num_pbls;
-       u32 num_pbes;
-       u32 pbl_size;
-       u32 pbe_size;
-       u64 fbo;
-       u64 va;
-};
-
-struct ocrdma_mr {
-       struct ib_mr ibmr;
-       struct ib_umem *umem;
-       struct ocrdma_hw_mr hwmr;
-};
 
 struct ocrdma_ucontext {
        struct ib_ucontext ibucontext;
index 50219ab2279d56ae6599e7189b06034bf12049d9..56bf32fcb62c9b8643816503eabb1d9693220c8c 100644 (file)
@@ -1783,7 +1783,7 @@ static int ocrdma_set_create_qp_sq_cmd(struct ocrdma_create_qp_req *cmd,
        u32 max_sges = attrs->cap.max_send_sge;
 
        /* QP1 may exceed 127 */
-       max_wqe_allocated = min_t(int, attrs->cap.max_send_wr + 1,
+       max_wqe_allocated = min_t(u32, attrs->cap.max_send_wr + 1,
                                dev->attr.max_wqe);
 
        status = ocrdma_build_q_conf(&max_wqe_allocated,
index 0ce7674621eaba2aa310fef332695b67f3057971..91443bcb9e0e89faf1a93d4dcacb22943f5e6e10 100644 (file)
@@ -452,9 +452,6 @@ static void ocrdma_remove_free(struct rcu_head *rcu)
 {
        struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu);
 
-       ocrdma_free_resources(dev);
-       ocrdma_cleanup_hw(dev);
-
        idr_remove(&ocrdma_dev_id, dev->id);
        kfree(dev->mbx_cmd);
        ib_dealloc_device(&dev->ibdev);
@@ -470,6 +467,10 @@ static void ocrdma_remove(struct ocrdma_dev *dev)
        spin_lock(&ocrdma_devlist_lock);
        list_del_rcu(&dev->entry);
        spin_unlock(&ocrdma_devlist_lock);
+
+       ocrdma_free_resources(dev);
+       ocrdma_cleanup_hw(dev);
+
        call_rcu(&dev->rcu, ocrdma_remove_free);
 }
 
index 69f1d1221a6bea07039fc37b5ead33f941fc74a4..7686dceadd292bf92a2a1ab273bf33a918d0967e 100644 (file)
@@ -1981,9 +1981,7 @@ static int ocrdma_build_fr(struct ocrdma_qp *qp, struct ocrdma_hdr_wqe *hdr,
 
        wqe_size = roundup(wqe_size, OCRDMA_WQE_ALIGN_BYTES);
 
-       if ((wr->wr.fast_reg.page_list_len >
-               qp->dev->attr.max_pages_per_frmr) ||
-               (wr->wr.fast_reg.length > 0xffffffffULL))
+       if (wr->wr.fast_reg.page_list_len > qp->dev->attr.max_pages_per_frmr)
                return -EINVAL;
 
        hdr->cw |= (OCRDMA_FR_MR << OCRDMA_WQE_OPCODE_SHIFT);
@@ -2839,7 +2837,7 @@ struct ib_mr *ocrdma_alloc_frmr(struct ib_pd *ibpd, int max_page_list_len)
                goto mbx_err;
        mr->ibmr.rkey = mr->hwmr.lkey;
        mr->ibmr.lkey = mr->hwmr.lkey;
-       dev->stag_arr[(mr->hwmr.lkey >> 8) & (OCRDMA_MAX_STAG - 1)] = (unsigned long) mr;
+       dev->stag_arr[(mr->hwmr.lkey >> 8) & (OCRDMA_MAX_STAG - 1)] = mr;
        return &mr->ibmr;
 mbx_err:
        ocrdma_free_mr_pbl_tbl(dev, &mr->hwmr);
index 016e7429adf66b9ffb945cb4fed168e358c57742..5bfc02f450e6a69251632db17fb6ff699dfe8c10 100644 (file)
@@ -6190,21 +6190,20 @@ static int setup_txselect(const char *str, struct kernel_param *kp)
 {
        struct qib_devdata *dd;
        unsigned long val;
-       int ret;
-
+       char *n;
        if (strlen(str) >= MAX_ATTEN_LEN) {
                pr_info("txselect_values string too long\n");
                return -ENOSPC;
        }
-       ret = kstrtoul(str, 0, &val);
-       if (ret || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
+       val = simple_strtoul(str, &n, 0);
+       if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
                                TXDDS_MFG_SZ)) {
                pr_info("txselect_values must start with a number < %d\n",
                        TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
-               return ret ? ret : -EINVAL;
+               return -EINVAL;
        }
-
        strcpy(txselect_list, str);
+
        list_for_each_entry(dd, &qib_dev_list, list)
                if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
                        set_no_qsfp_atten(dd, 1);
index 28874f8606f888ee0a7a816cf180b654f622bc32..941d4d50d8e74a76f333498c66ab9eb3da9b6246 100644 (file)
@@ -54,7 +54,7 @@ struct ib_node_info {
        __be32 revision;
        u8 local_port_num;
        u8 vendor_id[3];
-} __attribute__ ((packed));
+} __packed;
 
 struct ib_mad_notice_attr {
        u8 generic_type;
@@ -73,7 +73,7 @@ struct ib_mad_notice_attr {
                        __be16  reserved;
                        __be16  lid;            /* where violation happened */
                        u8      port_num;       /* where violation happened */
-               } __attribute__ ((packed)) ntc_129_131;
+               } __packed ntc_129_131;
 
                struct {
                        __be16  reserved;
@@ -83,14 +83,14 @@ struct ib_mad_notice_attr {
                        __be32  new_cap_mask;   /* new capability mask */
                        u8      reserved3;
                        u8      change_flags;   /* low 3 bits only */
-               } __attribute__ ((packed)) ntc_144;
+               } __packed ntc_144;
 
                struct {
                        __be16  reserved;
                        __be16  lid;            /* lid where sys guid changed */
                        __be16  reserved2;
                        __be64  new_sys_guid;
-               } __attribute__ ((packed)) ntc_145;
+               } __packed ntc_145;
 
                struct {
                        __be16  reserved;
@@ -104,7 +104,7 @@ struct ib_mad_notice_attr {
                        u8      reserved3;
                        u8      dr_trunc_hop;
                        u8      dr_rtn_path[30];
-               } __attribute__ ((packed)) ntc_256;
+               } __packed ntc_256;
 
                struct {
                        __be16          reserved;
@@ -115,7 +115,7 @@ struct ib_mad_notice_attr {
                        __be32          qp2;    /* high 8 bits reserved */
                        union ib_gid    gid1;
                        union ib_gid    gid2;
-               } __attribute__ ((packed)) ntc_257_258;
+               } __packed ntc_257_258;
 
        } details;
 };
@@ -209,7 +209,7 @@ struct ib_pma_portcounters_cong {
        __be64 port_rcv_packets;
        __be64 port_xmit_wait;
        __be64 port_adr_events;
-} __attribute__ ((packed));
+} __packed;
 
 #define IB_PMA_CONG_HW_CONTROL_TIMER            0x00
 #define IB_PMA_CONG_HW_CONTROL_SAMPLE           0x01
index d0a0ea0c14d6a965afe2bcf8d359052fdb946e26..165aee2ca8a0c38dfc1e00b1965172acf4f30193 100644 (file)
@@ -594,8 +594,7 @@ static int qib_user_sdma_pin_pages(const struct qib_devdata *dd,
                else
                        j = npages;
 
-               ret = get_user_pages(current, current->mm, addr,
-                            j, 0, 1, pages, NULL);
+               ret = get_user_pages_fast(addr, j, 0, pages);
                if (ret != j) {
                        i = 0;
                        j = ret;
@@ -1294,11 +1293,8 @@ int qib_user_sdma_writev(struct qib_ctxtdata *rcd,
                int mxp = 8;
                int ndesc = 0;
 
-               down_write(&current->mm->mmap_sem);
                ret = qib_user_sdma_queue_pkts(dd, ppd, pq,
                                iov, dim, &list, &mxp, &ndesc);
-               up_write(&current->mm->mmap_sem);
-
                if (ret < 0)
                        goto done_unlock;
                else {
index 012e2c7575ad5eb117f9542ec692f3f8d218eb71..a01c7d2cf54114def170ed8592a403b0b3d21e57 100644 (file)
@@ -150,14 +150,14 @@ struct ib_reth {
        __be64 vaddr;
        __be32 rkey;
        __be32 length;
-} __attribute__ ((packed));
+} __packed;
 
 struct ib_atomic_eth {
        __be32 vaddr[2];        /* unaligned so access as 2 32-bit words */
        __be32 rkey;
        __be64 swap_data;
        __be64 compare_data;
-} __attribute__ ((packed));
+} __packed;
 
 struct qib_other_headers {
        __be32 bth[3];
@@ -178,7 +178,7 @@ struct qib_other_headers {
                __be32 aeth;
                struct ib_atomic_eth atomic_eth;
        } u;
-} __attribute__ ((packed));
+} __packed;
 
 /*
  * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
@@ -195,12 +195,12 @@ struct qib_ib_header {
                } l;
                struct qib_other_headers oth;
        } u;
-} __attribute__ ((packed));
+} __packed;
 
 struct qib_pio_header {
        __le32 pbc[2];
        struct qib_ib_header hdr;
-} __attribute__ ((packed));
+} __packed;
 
 /*
  * There is one struct qib_mcast for each multicast GID.
index eb71aaa26a9a9345f5f4998cd30eb4d0a7f01f2f..c639f90cfda41709ce77c4051b8ed8086f4dd700 100644 (file)
@@ -101,6 +101,7 @@ enum {
        IPOIB_MCAST_FLAG_SENDONLY = 1,
        IPOIB_MCAST_FLAG_BUSY     = 2,  /* joining or already joined */
        IPOIB_MCAST_FLAG_ATTACHED = 3,
+       IPOIB_MCAST_JOIN_STARTED  = 4,
 
        MAX_SEND_CQE              = 16,
        IPOIB_CM_COPYBREAK        = 256,
@@ -151,6 +152,7 @@ struct ipoib_mcast {
        struct sk_buff_head pkt_queue;
 
        struct net_device *dev;
+       struct completion done;
 };
 
 struct ipoib_rx_buf {
@@ -299,7 +301,7 @@ struct ipoib_dev_priv {
 
        unsigned long flags;
 
-       struct mutex vlan_mutex;
+       struct rw_semaphore vlan_rwsem;
 
        struct rb_root  path_tree;
        struct list_head path_list;
index 7a3175400b2a1c6cf05b85e59f39773b5eb4db86..1377f85911c2490dc62764452856bcf680af7959 100644 (file)
@@ -140,7 +140,8 @@ static int ipoib_cm_post_receive_nonsrq(struct net_device *dev,
 static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
                                             struct ipoib_cm_rx_buf *rx_ring,
                                             int id, int frags,
-                                            u64 mapping[IPOIB_CM_RX_SG])
+                                            u64 mapping[IPOIB_CM_RX_SG],
+                                            gfp_t gfp)
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct sk_buff *skb;
@@ -164,7 +165,7 @@ static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
        }
 
        for (i = 0; i < frags; i++) {
-               struct page *page = alloc_page(GFP_ATOMIC);
+               struct page *page = alloc_page(gfp);
 
                if (!page)
                        goto partial_error;
@@ -382,7 +383,8 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i
 
        for (i = 0; i < ipoib_recvq_size; ++i) {
                if (!ipoib_cm_alloc_rx_skb(dev, rx->rx_ring, i, IPOIB_CM_RX_SG - 1,
-                                          rx->rx_ring[i].mapping)) {
+                                          rx->rx_ring[i].mapping,
+                                          GFP_KERNEL)) {
                        ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
                                ret = -ENOMEM;
                                goto err_count;
@@ -639,7 +641,8 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
        frags = PAGE_ALIGN(wc->byte_len - min(wc->byte_len,
                                              (unsigned)IPOIB_CM_HEAD_SIZE)) / PAGE_SIZE;
 
-       newskb = ipoib_cm_alloc_rx_skb(dev, rx_ring, wr_id, frags, mapping);
+       newskb = ipoib_cm_alloc_rx_skb(dev, rx_ring, wr_id, frags,
+                                      mapping, GFP_ATOMIC);
        if (unlikely(!newskb)) {
                /*
                 * If we can't allocate a new RX buffer, dump
@@ -1556,7 +1559,8 @@ int ipoib_cm_dev_init(struct net_device *dev)
                for (i = 0; i < ipoib_recvq_size; ++i) {
                        if (!ipoib_cm_alloc_rx_skb(dev, priv->cm.srq_ring, i,
                                                   priv->cm.num_frags - 1,
-                                                  priv->cm.srq_ring[i].mapping)) {
+                                                  priv->cm.srq_ring[i].mapping,
+                                                  GFP_KERNEL)) {
                                ipoib_warn(priv, "failed to allocate "
                                           "receive buffer %d\n", i);
                                ipoib_cm_dev_cleanup(dev);
index 196b1d13cbcbc09548e92a4be6c9a18cdc6aae36..6a7003ddb0be19e665220e843391bd148eb8ded4 100644 (file)
@@ -685,15 +685,13 @@ int ipoib_ib_dev_open(struct net_device *dev)
        ret = ipoib_ib_post_receives(dev);
        if (ret) {
                ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
-               ipoib_ib_dev_stop(dev, 1);
-               return -1;
+               goto dev_stop;
        }
 
        ret = ipoib_cm_dev_open(dev);
        if (ret) {
                ipoib_warn(priv, "ipoib_cm_dev_open returned %d\n", ret);
-               ipoib_ib_dev_stop(dev, 1);
-               return -1;
+               goto dev_stop;
        }
 
        clear_bit(IPOIB_STOP_REAPER, &priv->flags);
@@ -704,6 +702,11 @@ int ipoib_ib_dev_open(struct net_device *dev)
                napi_enable(&priv->napi);
 
        return 0;
+dev_stop:
+       if (!test_and_set_bit(IPOIB_FLAG_INITIALIZED, &priv->flags))
+               napi_enable(&priv->napi);
+       ipoib_ib_dev_stop(dev, 1);
+       return -1;
 }
 
 static void ipoib_pkey_dev_check_presence(struct net_device *dev)
@@ -746,10 +749,8 @@ int ipoib_ib_dev_down(struct net_device *dev, int flush)
        if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
                mutex_lock(&pkey_mutex);
                set_bit(IPOIB_PKEY_STOP, &priv->flags);
-               cancel_delayed_work(&priv->pkey_poll_task);
+               cancel_delayed_work_sync(&priv->pkey_poll_task);
                mutex_unlock(&pkey_mutex);
-               if (flush)
-                       flush_workqueue(ipoib_workqueue);
        }
 
        ipoib_mcast_stop_thread(dev, flush);
@@ -974,7 +975,7 @@ static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv,
        u16 new_index;
        int result;
 
-       mutex_lock(&priv->vlan_mutex);
+       down_read(&priv->vlan_rwsem);
 
        /*
         * Flush any child interfaces too -- they might be up even if
@@ -983,7 +984,7 @@ static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv,
        list_for_each_entry(cpriv, &priv->child_intfs, list)
                __ipoib_ib_dev_flush(cpriv, level);
 
-       mutex_unlock(&priv->vlan_mutex);
+       up_read(&priv->vlan_rwsem);
 
        if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) {
                /* for non-child devices must check/update the pkey value here */
@@ -1081,6 +1082,11 @@ void ipoib_ib_dev_cleanup(struct net_device *dev)
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
        ipoib_dbg(priv, "cleaning up ib_dev\n");
+       /*
+        * We must make sure there are no more (path) completions
+        * that may wish to touch priv fields that are no longer valid
+        */
+       ipoib_flush_paths(dev);
 
        ipoib_mcast_stop_thread(dev, 1);
        ipoib_mcast_dev_flush(dev);
index 82cec1af902cd24533ef032869cf2052fa9d4f63..d64ed05fb082f6a538b4c774c9f93a54940557ee 100644 (file)
@@ -119,7 +119,7 @@ int ipoib_open(struct net_device *dev)
                struct ipoib_dev_priv *cpriv;
 
                /* Bring up any child interfaces too */
-               mutex_lock(&priv->vlan_mutex);
+               down_read(&priv->vlan_rwsem);
                list_for_each_entry(cpriv, &priv->child_intfs, list) {
                        int flags;
 
@@ -129,7 +129,7 @@ int ipoib_open(struct net_device *dev)
 
                        dev_change_flags(cpriv->dev, flags | IFF_UP);
                }
-               mutex_unlock(&priv->vlan_mutex);
+               up_read(&priv->vlan_rwsem);
        }
 
        netif_start_queue(dev);
@@ -162,7 +162,7 @@ static int ipoib_stop(struct net_device *dev)
                struct ipoib_dev_priv *cpriv;
 
                /* Bring down any child interfaces too */
-               mutex_lock(&priv->vlan_mutex);
+               down_read(&priv->vlan_rwsem);
                list_for_each_entry(cpriv, &priv->child_intfs, list) {
                        int flags;
 
@@ -172,7 +172,7 @@ static int ipoib_stop(struct net_device *dev)
 
                        dev_change_flags(cpriv->dev, flags & ~IFF_UP);
                }
-               mutex_unlock(&priv->vlan_mutex);
+               up_read(&priv->vlan_rwsem);
        }
 
        return 0;
@@ -1350,7 +1350,7 @@ void ipoib_setup(struct net_device *dev)
 
        ipoib_set_ethtool_ops(dev);
 
-       netif_napi_add(dev, &priv->napi, ipoib_poll, 100);
+       netif_napi_add(dev, &priv->napi, ipoib_poll, NAPI_POLL_WEIGHT);
 
        dev->watchdog_timeo      = HZ;
 
@@ -1372,7 +1372,7 @@ void ipoib_setup(struct net_device *dev)
 
        spin_lock_init(&priv->lock);
 
-       mutex_init(&priv->vlan_mutex);
+       init_rwsem(&priv->vlan_rwsem);
 
        INIT_LIST_HEAD(&priv->path_list);
        INIT_LIST_HEAD(&priv->child_intfs);
index cecb98a4c662b7d82053f152a3da46d653e4d6ca..d4e005720d0181729096b4fb8a81aa21498f023b 100644 (file)
@@ -386,8 +386,10 @@ static int ipoib_mcast_join_complete(int status,
                        mcast->mcmember.mgid.raw, status);
 
        /* We trap for port events ourselves. */
-       if (status == -ENETRESET)
-               return 0;
+       if (status == -ENETRESET) {
+               status = 0;
+               goto out;
+       }
 
        if (!status)
                status = ipoib_mcast_join_finish(mcast, &multicast->rec);
@@ -407,7 +409,8 @@ static int ipoib_mcast_join_complete(int status,
                if (mcast == priv->broadcast)
                        queue_work(ipoib_workqueue, &priv->carrier_on_task);
 
-               return 0;
+               status = 0;
+               goto out;
        }
 
        if (mcast->logcount++ < 20) {
@@ -434,7 +437,8 @@ static int ipoib_mcast_join_complete(int status,
                                   mcast->backoff * HZ);
        spin_unlock_irq(&priv->lock);
        mutex_unlock(&mcast_mutex);
-
+out:
+       complete(&mcast->done);
        return status;
 }
 
@@ -484,11 +488,15 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
        }
 
        set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
+       init_completion(&mcast->done);
+       set_bit(IPOIB_MCAST_JOIN_STARTED, &mcast->flags);
+
        mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
                                         &rec, comp_mask, GFP_KERNEL,
                                         ipoib_mcast_join_complete, mcast);
        if (IS_ERR(mcast->mc)) {
                clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
+               complete(&mcast->done);
                ret = PTR_ERR(mcast->mc);
                ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
 
@@ -510,10 +518,18 @@ void ipoib_mcast_join_task(struct work_struct *work)
        struct ipoib_dev_priv *priv =
                container_of(work, struct ipoib_dev_priv, mcast_task.work);
        struct net_device *dev = priv->dev;
+       struct ib_port_attr port_attr;
 
        if (!test_bit(IPOIB_MCAST_RUN, &priv->flags))
                return;
 
+       if (ib_query_port(priv->ca, priv->port, &port_attr) ||
+           port_attr.state != IB_PORT_ACTIVE) {
+               ipoib_dbg(priv, "port state is not ACTIVE (state = %d) suspending join task\n",
+                         port_attr.state);
+               return;
+       }
+
        if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid))
                ipoib_warn(priv, "ib_query_gid() failed\n");
        else
@@ -751,6 +767,11 @@ void ipoib_mcast_dev_flush(struct net_device *dev)
 
        spin_unlock_irqrestore(&priv->lock, flags);
 
+       /* seperate between the wait to the leave*/
+       list_for_each_entry_safe(mcast, tmcast, &remove_list, list)
+               if (test_bit(IPOIB_MCAST_JOIN_STARTED, &mcast->flags))
+                       wait_for_completion(&mcast->done);
+
        list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
                ipoib_mcast_leave(dev, mcast);
                ipoib_mcast_free(mcast);
index f81abe16cf093d6c74ad31dd179f03f7dc90b997..c29b5c8388331458bb2a2caf85580d76031f1dcb 100644 (file)
@@ -142,10 +142,10 @@ static void ipoib_unregister_child_dev(struct net_device *dev, struct list_head
        priv = netdev_priv(dev);
        ppriv = netdev_priv(priv->parent);
 
-       mutex_lock(&ppriv->vlan_mutex);
+       down_write(&ppriv->vlan_rwsem);
        unregister_netdevice_queue(dev, head);
        list_del(&priv->list);
-       mutex_unlock(&ppriv->vlan_mutex);
+       up_write(&ppriv->vlan_rwsem);
 }
 
 static size_t ipoib_get_size(const struct net_device *dev)
index 8292554bccb5de2387d7e858eaaa1d27ddb6b8b4..9fad7b5ac8b91910af7e6b1527f20165323e7dc8 100644 (file)
@@ -140,7 +140,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
        if (!rtnl_trylock())
                return restart_syscall();
 
-       mutex_lock(&ppriv->vlan_mutex);
+       down_write(&ppriv->vlan_rwsem);
 
        /*
         * First ensure this isn't a duplicate. We check the parent device and
@@ -163,7 +163,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
        result = __ipoib_vlan_add(ppriv, priv, pkey, IPOIB_LEGACY_CHILD);
 
 out:
-       mutex_unlock(&ppriv->vlan_mutex);
+       up_write(&ppriv->vlan_rwsem);
 
        if (result)
                free_netdev(priv->dev);
@@ -185,7 +185,8 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
 
        if (!rtnl_trylock())
                return restart_syscall();
-       mutex_lock(&ppriv->vlan_mutex);
+
+       down_write(&ppriv->vlan_rwsem);
        list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
                if (priv->pkey == pkey &&
                    priv->child_type == IPOIB_LEGACY_CHILD) {
@@ -195,7 +196,8 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
                        break;
                }
        }
-       mutex_unlock(&ppriv->vlan_mutex);
+       up_write(&ppriv->vlan_rwsem);
+
        rtnl_unlock();
 
        if (dev) {
index ce3fd32167dcdc68c609ef9852263df65fd0b5c1..02f9759ebb1a573677993c7b17741e851eb591f7 100644 (file)
@@ -1,5 +1,5 @@
 config INFINIBAND_ISERT
-       tristate "iSCSI Extentions for RDMA (iSER) target support"
+       tristate "iSCSI Extensions for RDMA (iSER) target support"
        depends on INET && INFINIBAND_ADDR_TRANS && TARGET_CORE && ISCSI_TARGET
        ---help---
-       Support for iSCSI Extentions for RDMA (iSER) Target on Infiniband fabrics.
+       Support for iSCSI Extensions for RDMA (iSER) Target on Infiniband fabrics.
index f93baf8254c4d492065155b4b701529629260b30..a88631918e852880731c3305b009b53f0fbc9d48 100644 (file)
@@ -46,6 +46,7 @@
 #include <scsi/scsi.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_dbg.h>
+#include <scsi/scsi_tcq.h>
 #include <scsi/srp.h>
 #include <scsi/scsi_transport_srp.h>
 
@@ -86,6 +87,32 @@ module_param(topspin_workarounds, int, 0444);
 MODULE_PARM_DESC(topspin_workarounds,
                 "Enable workarounds for Topspin/Cisco SRP target bugs if != 0");
 
+static struct kernel_param_ops srp_tmo_ops;
+
+static int srp_reconnect_delay = 10;
+module_param_cb(reconnect_delay, &srp_tmo_ops, &srp_reconnect_delay,
+               S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(reconnect_delay, "Time between successive reconnect attempts");
+
+static int srp_fast_io_fail_tmo = 15;
+module_param_cb(fast_io_fail_tmo, &srp_tmo_ops, &srp_fast_io_fail_tmo,
+               S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(fast_io_fail_tmo,
+                "Number of seconds between the observation of a transport"
+                " layer error and failing all I/O. \"off\" means that this"
+                " functionality is disabled.");
+
+static int srp_dev_loss_tmo = 600;
+module_param_cb(dev_loss_tmo, &srp_tmo_ops, &srp_dev_loss_tmo,
+               S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(dev_loss_tmo,
+                "Maximum number of seconds that the SRP transport should"
+                " insulate transport layer errors. After this time has been"
+                " exceeded the SCSI host is removed. Should be"
+                " between 1 and " __stringify(SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
+                " if fast_io_fail_tmo has not been set. \"off\" means that"
+                " this functionality is disabled.");
+
 static void srp_add_one(struct ib_device *device);
 static void srp_remove_one(struct ib_device *device);
 static void srp_recv_completion(struct ib_cq *cq, void *target_ptr);
@@ -102,6 +129,48 @@ static struct ib_client srp_client = {
 
 static struct ib_sa_client srp_sa_client;
 
+static int srp_tmo_get(char *buffer, const struct kernel_param *kp)
+{
+       int tmo = *(int *)kp->arg;
+
+       if (tmo >= 0)
+               return sprintf(buffer, "%d", tmo);
+       else
+               return sprintf(buffer, "off");
+}
+
+static int srp_tmo_set(const char *val, const struct kernel_param *kp)
+{
+       int tmo, res;
+
+       if (strncmp(val, "off", 3) != 0) {
+               res = kstrtoint(val, 0, &tmo);
+               if (res)
+                       goto out;
+       } else {
+               tmo = -1;
+       }
+       if (kp->arg == &srp_reconnect_delay)
+               res = srp_tmo_valid(tmo, srp_fast_io_fail_tmo,
+                                   srp_dev_loss_tmo);
+       else if (kp->arg == &srp_fast_io_fail_tmo)
+               res = srp_tmo_valid(srp_reconnect_delay, tmo, srp_dev_loss_tmo);
+       else
+               res = srp_tmo_valid(srp_reconnect_delay, srp_fast_io_fail_tmo,
+                                   tmo);
+       if (res)
+               goto out;
+       *(int *)kp->arg = tmo;
+
+out:
+       return res;
+}
+
+static struct kernel_param_ops srp_tmo_ops = {
+       .get = srp_tmo_get,
+       .set = srp_tmo_set,
+};
+
 static inline struct srp_target_port *host_to_target(struct Scsi_Host *host)
 {
        return (struct srp_target_port *) host->hostdata;
@@ -231,16 +300,16 @@ static int srp_create_target_ib(struct srp_target_port *target)
                return -ENOMEM;
 
        recv_cq = ib_create_cq(target->srp_host->srp_dev->dev,
-                              srp_recv_completion, NULL, target, SRP_RQ_SIZE,
-                              target->comp_vector);
+                              srp_recv_completion, NULL, target,
+                              target->queue_size, target->comp_vector);
        if (IS_ERR(recv_cq)) {
                ret = PTR_ERR(recv_cq);
                goto err;
        }
 
        send_cq = ib_create_cq(target->srp_host->srp_dev->dev,
-                              srp_send_completion, NULL, target, SRP_SQ_SIZE,
-                              target->comp_vector);
+                              srp_send_completion, NULL, target,
+                              target->queue_size, target->comp_vector);
        if (IS_ERR(send_cq)) {
                ret = PTR_ERR(send_cq);
                goto err_recv_cq;
@@ -249,8 +318,8 @@ static int srp_create_target_ib(struct srp_target_port *target)
        ib_req_notify_cq(recv_cq, IB_CQ_NEXT_COMP);
 
        init_attr->event_handler       = srp_qp_event;
-       init_attr->cap.max_send_wr     = SRP_SQ_SIZE;
-       init_attr->cap.max_recv_wr     = SRP_RQ_SIZE;
+       init_attr->cap.max_send_wr     = target->queue_size;
+       init_attr->cap.max_recv_wr     = target->queue_size;
        init_attr->cap.max_recv_sge    = 1;
        init_attr->cap.max_send_sge    = 1;
        init_attr->sq_sig_type         = IB_SIGNAL_ALL_WR;
@@ -296,6 +365,10 @@ err:
        return ret;
 }
 
+/*
+ * Note: this function may be called without srp_alloc_iu_bufs() having been
+ * invoked. Hence the target->[rt]x_ring checks.
+ */
 static void srp_free_target_ib(struct srp_target_port *target)
 {
        int i;
@@ -307,10 +380,18 @@ static void srp_free_target_ib(struct srp_target_port *target)
        target->qp = NULL;
        target->send_cq = target->recv_cq = NULL;
 
-       for (i = 0; i < SRP_RQ_SIZE; ++i)
-               srp_free_iu(target->srp_host, target->rx_ring[i]);
-       for (i = 0; i < SRP_SQ_SIZE; ++i)
-               srp_free_iu(target->srp_host, target->tx_ring[i]);
+       if (target->rx_ring) {
+               for (i = 0; i < target->queue_size; ++i)
+                       srp_free_iu(target->srp_host, target->rx_ring[i]);
+               kfree(target->rx_ring);
+               target->rx_ring = NULL;
+       }
+       if (target->tx_ring) {
+               for (i = 0; i < target->queue_size; ++i)
+                       srp_free_iu(target->srp_host, target->tx_ring[i]);
+               kfree(target->tx_ring);
+               target->tx_ring = NULL;
+       }
 }
 
 static void srp_path_rec_completion(int status,
@@ -390,7 +471,7 @@ static int srp_send_req(struct srp_target_port *target)
        req->param.responder_resources        = 4;
        req->param.remote_cm_response_timeout = 20;
        req->param.local_cm_response_timeout  = 20;
-       req->param.retry_count                = 7;
+       req->param.retry_count                = target->tl_retry_count;
        req->param.rnr_retry_count            = 7;
        req->param.max_cm_retries             = 15;
 
@@ -496,7 +577,11 @@ static void srp_free_req_data(struct srp_target_port *target)
        struct srp_request *req;
        int i;
 
-       for (i = 0, req = target->req_ring; i < SRP_CMD_SQ_SIZE; ++i, ++req) {
+       if (!target->req_ring)
+               return;
+
+       for (i = 0; i < target->req_ring_size; ++i) {
+               req = &target->req_ring[i];
                kfree(req->fmr_list);
                kfree(req->map_page);
                if (req->indirect_dma_addr) {
@@ -506,6 +591,50 @@ static void srp_free_req_data(struct srp_target_port *target)
                }
                kfree(req->indirect_desc);
        }
+
+       kfree(target->req_ring);
+       target->req_ring = NULL;
+}
+
+static int srp_alloc_req_data(struct srp_target_port *target)
+{
+       struct srp_device *srp_dev = target->srp_host->srp_dev;
+       struct ib_device *ibdev = srp_dev->dev;
+       struct srp_request *req;
+       dma_addr_t dma_addr;
+       int i, ret = -ENOMEM;
+
+       INIT_LIST_HEAD(&target->free_reqs);
+
+       target->req_ring = kzalloc(target->req_ring_size *
+                                  sizeof(*target->req_ring), GFP_KERNEL);
+       if (!target->req_ring)
+               goto out;
+
+       for (i = 0; i < target->req_ring_size; ++i) {
+               req = &target->req_ring[i];
+               req->fmr_list = kmalloc(target->cmd_sg_cnt * sizeof(void *),
+                                       GFP_KERNEL);
+               req->map_page = kmalloc(SRP_FMR_SIZE * sizeof(void *),
+                                       GFP_KERNEL);
+               req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL);
+               if (!req->fmr_list || !req->map_page || !req->indirect_desc)
+                       goto out;
+
+               dma_addr = ib_dma_map_single(ibdev, req->indirect_desc,
+                                            target->indirect_size,
+                                            DMA_TO_DEVICE);
+               if (ib_dma_mapping_error(ibdev, dma_addr))
+                       goto out;
+
+               req->indirect_dma_addr = dma_addr;
+               req->index = i;
+               list_add_tail(&req->list, &target->free_reqs);
+       }
+       ret = 0;
+
+out:
+       return ret;
 }
 
 /**
@@ -528,12 +657,20 @@ static void srp_remove_target(struct srp_target_port *target)
        WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
 
        srp_del_scsi_host_attr(target->scsi_host);
+       srp_rport_get(target->rport);
        srp_remove_host(target->scsi_host);
        scsi_remove_host(target->scsi_host);
        srp_disconnect_target(target);
        ib_destroy_cm_id(target->cm_id);
        srp_free_target_ib(target);
+       cancel_work_sync(&target->tl_err_work);
+       srp_rport_put(target->rport);
        srp_free_req_data(target);
+
+       spin_lock(&target->srp_host->target_lock);
+       list_del(&target->list);
+       spin_unlock(&target->srp_host->target_lock);
+
        scsi_host_put(target->scsi_host);
 }
 
@@ -545,10 +682,6 @@ static void srp_remove_work(struct work_struct *work)
        WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
 
        srp_remove_target(target);
-
-       spin_lock(&target->srp_host->target_lock);
-       list_del(&target->list);
-       spin_unlock(&target->srp_host->target_lock);
 }
 
 static void srp_rport_delete(struct srp_rport *rport)
@@ -686,23 +819,42 @@ static void srp_free_req(struct srp_target_port *target,
        spin_unlock_irqrestore(&target->lock, flags);
 }
 
-static void srp_reset_req(struct srp_target_port *target, struct srp_request *req)
+static void srp_finish_req(struct srp_target_port *target,
+                          struct srp_request *req, int result)
 {
        struct scsi_cmnd *scmnd = srp_claim_req(target, req, NULL);
 
        if (scmnd) {
                srp_free_req(target, req, scmnd, 0);
-               scmnd->result = DID_RESET << 16;
+               scmnd->result = result;
                scmnd->scsi_done(scmnd);
        }
 }
 
-static int srp_reconnect_target(struct srp_target_port *target)
+static void srp_terminate_io(struct srp_rport *rport)
 {
-       struct Scsi_Host *shost = target->scsi_host;
-       int i, ret;
+       struct srp_target_port *target = rport->lld_data;
+       int i;
 
-       scsi_target_block(&shost->shost_gendev);
+       for (i = 0; i < target->req_ring_size; ++i) {
+               struct srp_request *req = &target->req_ring[i];
+               srp_finish_req(target, req, DID_TRANSPORT_FAILFAST << 16);
+       }
+}
+
+/*
+ * It is up to the caller to ensure that srp_rport_reconnect() calls are
+ * serialized and that no concurrent srp_queuecommand(), srp_abort(),
+ * srp_reset_device() or srp_reset_host() calls will occur while this function
+ * is in progress. One way to realize that is not to call this function
+ * directly but to call srp_reconnect_rport() instead since that last function
+ * serializes calls of this function via rport->mutex and also blocks
+ * srp_queuecommand() calls before invoking this function.
+ */
+static int srp_rport_reconnect(struct srp_rport *rport)
+{
+       struct srp_target_port *target = rport->lld_data;
+       int i, ret;
 
        srp_disconnect_target(target);
        /*
@@ -721,41 +873,21 @@ static int srp_reconnect_target(struct srp_target_port *target)
        else
                srp_create_target_ib(target);
 
-       for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) {
+       for (i = 0; i < target->req_ring_size; ++i) {
                struct srp_request *req = &target->req_ring[i];
-               if (req->scmnd)
-                       srp_reset_req(target, req);
+               srp_finish_req(target, req, DID_RESET << 16);
        }
 
        INIT_LIST_HEAD(&target->free_tx);
-       for (i = 0; i < SRP_SQ_SIZE; ++i)
+       for (i = 0; i < target->queue_size; ++i)
                list_add(&target->tx_ring[i]->list, &target->free_tx);
 
        if (ret == 0)
                ret = srp_connect_target(target);
 
-       scsi_target_unblock(&shost->shost_gendev, ret == 0 ? SDEV_RUNNING :
-                           SDEV_TRANSPORT_OFFLINE);
-       target->transport_offline = !!ret;
-
-       if (ret)
-               goto err;
-
-       shost_printk(KERN_INFO, target->scsi_host, PFX "reconnect succeeded\n");
-
-       return ret;
-
-err:
-       shost_printk(KERN_ERR, target->scsi_host,
-                    PFX "reconnect failed (%d), removing target port.\n", ret);
-
-       /*
-        * We couldn't reconnect, so kill our target port off.
-        * However, we have to defer the real removal because we
-        * are in the context of the SCSI error handler now, which
-        * will deadlock if we call scsi_remove_host().
-        */
-       srp_queue_remove_work(target);
+       if (ret == 0)
+               shost_printk(KERN_INFO, target->scsi_host,
+                            PFX "reconnect succeeded\n");
 
        return ret;
 }
@@ -1302,15 +1434,30 @@ static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
                             PFX "Recv failed with error code %d\n", res);
 }
 
-static void srp_handle_qp_err(enum ib_wc_status wc_status,
-                             enum ib_wc_opcode wc_opcode,
+/**
+ * srp_tl_err_work() - handle a transport layer error
+ *
+ * Note: This function may get invoked before the rport has been created,
+ * hence the target->rport test.
+ */
+static void srp_tl_err_work(struct work_struct *work)
+{
+       struct srp_target_port *target;
+
+       target = container_of(work, struct srp_target_port, tl_err_work);
+       if (target->rport)
+               srp_start_tl_fail_timers(target->rport);
+}
+
+static void srp_handle_qp_err(enum ib_wc_status wc_status, bool send_err,
                              struct srp_target_port *target)
 {
        if (target->connected && !target->qp_in_error) {
                shost_printk(KERN_ERR, target->scsi_host,
                             PFX "failed %s status %d\n",
-                            wc_opcode & IB_WC_RECV ? "receive" : "send",
+                            send_err ? "send" : "receive",
                             wc_status);
+               queue_work(system_long_wq, &target->tl_err_work);
        }
        target->qp_in_error = true;
 }
@@ -1325,7 +1472,7 @@ static void srp_recv_completion(struct ib_cq *cq, void *target_ptr)
                if (likely(wc.status == IB_WC_SUCCESS)) {
                        srp_handle_recv(target, &wc);
                } else {
-                       srp_handle_qp_err(wc.status, wc.opcode, target);
+                       srp_handle_qp_err(wc.status, false, target);
                }
        }
 }
@@ -1341,7 +1488,7 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
                        iu = (struct srp_iu *) (uintptr_t) wc.wr_id;
                        list_add(&iu->list, &target->free_tx);
                } else {
-                       srp_handle_qp_err(wc.status, wc.opcode, target);
+                       srp_handle_qp_err(wc.status, true, target);
                }
        }
 }
@@ -1349,17 +1496,29 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
 static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
 {
        struct srp_target_port *target = host_to_target(shost);
+       struct srp_rport *rport = target->rport;
        struct srp_request *req;
        struct srp_iu *iu;
        struct srp_cmd *cmd;
        struct ib_device *dev;
        unsigned long flags;
-       int len;
+       int len, result;
+       const bool in_scsi_eh = !in_interrupt() && current == shost->ehandler;
+
+       /*
+        * The SCSI EH thread is the only context from which srp_queuecommand()
+        * can get invoked for blocked devices (SDEV_BLOCK /
+        * SDEV_CREATED_BLOCK). Avoid racing with srp_reconnect_rport() by
+        * locking the rport mutex if invoked from inside the SCSI EH.
+        */
+       if (in_scsi_eh)
+               mutex_lock(&rport->mutex);
 
-       if (unlikely(target->transport_offline)) {
-               scmnd->result = DID_NO_CONNECT << 16;
+       result = srp_chkready(target->rport);
+       if (unlikely(result)) {
+               scmnd->result = result;
                scmnd->scsi_done(scmnd);
-               return 0;
+               goto unlock_rport;
        }
 
        spin_lock_irqsave(&target->lock, flags);
@@ -1404,6 +1563,10 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
                goto err_unmap;
        }
 
+unlock_rport:
+       if (in_scsi_eh)
+               mutex_unlock(&rport->mutex);
+
        return 0;
 
 err_unmap:
@@ -1418,14 +1581,30 @@ err_iu:
 err_unlock:
        spin_unlock_irqrestore(&target->lock, flags);
 
+       if (in_scsi_eh)
+               mutex_unlock(&rport->mutex);
+
        return SCSI_MLQUEUE_HOST_BUSY;
 }
 
+/*
+ * Note: the resources allocated in this function are freed in
+ * srp_free_target_ib().
+ */
 static int srp_alloc_iu_bufs(struct srp_target_port *target)
 {
        int i;
 
-       for (i = 0; i < SRP_RQ_SIZE; ++i) {
+       target->rx_ring = kzalloc(target->queue_size * sizeof(*target->rx_ring),
+                                 GFP_KERNEL);
+       if (!target->rx_ring)
+               goto err_no_ring;
+       target->tx_ring = kzalloc(target->queue_size * sizeof(*target->tx_ring),
+                                 GFP_KERNEL);
+       if (!target->tx_ring)
+               goto err_no_ring;
+
+       for (i = 0; i < target->queue_size; ++i) {
                target->rx_ring[i] = srp_alloc_iu(target->srp_host,
                                                  target->max_ti_iu_len,
                                                  GFP_KERNEL, DMA_FROM_DEVICE);
@@ -1433,7 +1612,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
                        goto err;
        }
 
-       for (i = 0; i < SRP_SQ_SIZE; ++i) {
+       for (i = 0; i < target->queue_size; ++i) {
                target->tx_ring[i] = srp_alloc_iu(target->srp_host,
                                                  target->max_iu_len,
                                                  GFP_KERNEL, DMA_TO_DEVICE);
@@ -1446,16 +1625,18 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
        return 0;
 
 err:
-       for (i = 0; i < SRP_RQ_SIZE; ++i) {
+       for (i = 0; i < target->queue_size; ++i) {
                srp_free_iu(target->srp_host, target->rx_ring[i]);
-               target->rx_ring[i] = NULL;
-       }
-
-       for (i = 0; i < SRP_SQ_SIZE; ++i) {
                srp_free_iu(target->srp_host, target->tx_ring[i]);
-               target->tx_ring[i] = NULL;
        }
 
+
+err_no_ring:
+       kfree(target->tx_ring);
+       target->tx_ring = NULL;
+       kfree(target->rx_ring);
+       target->rx_ring = NULL;
+
        return -ENOMEM;
 }
 
@@ -1506,6 +1687,9 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
                target->scsi_host->can_queue
                        = min(target->req_lim - SRP_TSK_MGMT_SQ_SIZE,
                              target->scsi_host->can_queue);
+               target->scsi_host->cmd_per_lun
+                       = min_t(int, target->scsi_host->can_queue,
+                               target->scsi_host->cmd_per_lun);
        } else {
                shost_printk(KERN_WARNING, target->scsi_host,
                             PFX "Unhandled RSP opcode %#x\n", lrsp->opcode);
@@ -1513,7 +1697,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
                goto error;
        }
 
-       if (!target->rx_ring[0]) {
+       if (!target->rx_ring) {
                ret = srp_alloc_iu_bufs(target);
                if (ret)
                        goto error;
@@ -1533,7 +1717,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
        if (ret)
                goto error_free;
 
-       for (i = 0; i < SRP_RQ_SIZE; i++) {
+       for (i = 0; i < target->queue_size; i++) {
                struct srp_iu *iu = target->rx_ring[i];
                ret = srp_post_recv(target, iu);
                if (ret)
@@ -1672,6 +1856,7 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
                if (ib_send_cm_drep(cm_id, NULL, 0))
                        shost_printk(KERN_ERR, target->scsi_host,
                                     PFX "Sending CM DREP failed\n");
+               queue_work(system_long_wq, &target->tl_err_work);
                break;
 
        case IB_CM_TIMEWAIT_EXIT:
@@ -1698,9 +1883,61 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
        return 0;
 }
 
+/**
+ * srp_change_queue_type - changing device queue tag type
+ * @sdev: scsi device struct
+ * @tag_type: requested tag type
+ *
+ * Returns queue tag type.
+ */
+static int
+srp_change_queue_type(struct scsi_device *sdev, int tag_type)
+{
+       if (sdev->tagged_supported) {
+               scsi_set_tag_type(sdev, tag_type);
+               if (tag_type)
+                       scsi_activate_tcq(sdev, sdev->queue_depth);
+               else
+                       scsi_deactivate_tcq(sdev, sdev->queue_depth);
+       } else
+               tag_type = 0;
+
+       return tag_type;
+}
+
+/**
+ * srp_change_queue_depth - setting device queue depth
+ * @sdev: scsi device struct
+ * @qdepth: requested queue depth
+ * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
+ * (see include/scsi/scsi_host.h for definition)
+ *
+ * Returns queue depth.
+ */
+static int
+srp_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
+{
+       struct Scsi_Host *shost = sdev->host;
+       int max_depth;
+       if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) {
+               max_depth = shost->can_queue;
+               if (!sdev->tagged_supported)
+                       max_depth = 1;
+               if (qdepth > max_depth)
+                       qdepth = max_depth;
+               scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
+       } else if (reason == SCSI_QDEPTH_QFULL)
+               scsi_track_queue_full(sdev, qdepth);
+       else
+               return -EOPNOTSUPP;
+
+       return sdev->queue_depth;
+}
+
 static int srp_send_tsk_mgmt(struct srp_target_port *target,
                             u64 req_tag, unsigned int lun, u8 func)
 {
+       struct srp_rport *rport = target->rport;
        struct ib_device *dev = target->srp_host->srp_dev->dev;
        struct srp_iu *iu;
        struct srp_tsk_mgmt *tsk_mgmt;
@@ -1710,12 +1947,20 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
 
        init_completion(&target->tsk_mgmt_done);
 
+       /*
+        * Lock the rport mutex to avoid that srp_create_target_ib() is
+        * invoked while a task management function is being sent.
+        */
+       mutex_lock(&rport->mutex);
        spin_lock_irq(&target->lock);
        iu = __srp_get_tx_iu(target, SRP_IU_TSK_MGMT);
        spin_unlock_irq(&target->lock);
 
-       if (!iu)
+       if (!iu) {
+               mutex_unlock(&rport->mutex);
+
                return -1;
+       }
 
        ib_dma_sync_single_for_cpu(dev, iu->dma, sizeof *tsk_mgmt,
                                   DMA_TO_DEVICE);
@@ -1732,8 +1977,11 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
                                      DMA_TO_DEVICE);
        if (srp_post_send(target, iu, sizeof *tsk_mgmt)) {
                srp_put_tx_iu(target, iu, SRP_IU_TSK_MGMT);
+               mutex_unlock(&rport->mutex);
+
                return -1;
        }
+       mutex_unlock(&rport->mutex);
 
        if (!wait_for_completion_timeout(&target->tsk_mgmt_done,
                                         msecs_to_jiffies(SRP_ABORT_TIMEOUT_MS)))
@@ -1751,11 +1999,11 @@ static int srp_abort(struct scsi_cmnd *scmnd)
        shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n");
 
        if (!req || !srp_claim_req(target, req, scmnd))
-               return FAILED;
+               return SUCCESS;
        if (srp_send_tsk_mgmt(target, req->index, scmnd->device->lun,
                              SRP_TSK_ABORT_TASK) == 0)
                ret = SUCCESS;
-       else if (target->transport_offline)
+       else if (target->rport->state == SRP_RPORT_LOST)
                ret = FAST_IO_FAIL;
        else
                ret = FAILED;
@@ -1779,10 +2027,10 @@ static int srp_reset_device(struct scsi_cmnd *scmnd)
        if (target->tsk_mgmt_status)
                return FAILED;
 
-       for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) {
+       for (i = 0; i < target->req_ring_size; ++i) {
                struct srp_request *req = &target->req_ring[i];
                if (req->scmnd && req->scmnd->device == scmnd->device)
-                       srp_reset_req(target, req);
+                       srp_finish_req(target, req, DID_RESET << 16);
        }
 
        return SUCCESS;
@@ -1791,14 +2039,10 @@ static int srp_reset_device(struct scsi_cmnd *scmnd)
 static int srp_reset_host(struct scsi_cmnd *scmnd)
 {
        struct srp_target_port *target = host_to_target(scmnd->device->host);
-       int ret = FAILED;
 
        shost_printk(KERN_ERR, target->scsi_host, PFX "SRP reset_host called\n");
 
-       if (!srp_reconnect_target(target))
-               ret = SUCCESS;
-
-       return ret;
+       return srp_reconnect_rport(target->rport) == 0 ? SUCCESS : FAILED;
 }
 
 static int srp_slave_configure(struct scsi_device *sdev)
@@ -1851,6 +2095,14 @@ static ssize_t show_pkey(struct device *dev, struct device_attribute *attr,
        return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey));
 }
 
+static ssize_t show_sgid(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       struct srp_target_port *target = host_to_target(class_to_shost(dev));
+
+       return sprintf(buf, "%pI6\n", target->path.sgid.raw);
+}
+
 static ssize_t show_dgid(struct device *dev, struct device_attribute *attr,
                         char *buf)
 {
@@ -1907,6 +2159,14 @@ static ssize_t show_comp_vector(struct device *dev,
        return sprintf(buf, "%d\n", target->comp_vector);
 }
 
+static ssize_t show_tl_retry_count(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct srp_target_port *target = host_to_target(class_to_shost(dev));
+
+       return sprintf(buf, "%d\n", target->tl_retry_count);
+}
+
 static ssize_t show_cmd_sg_entries(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
@@ -1927,6 +2187,7 @@ static DEVICE_ATTR(id_ext,            S_IRUGO, show_id_ext,          NULL);
 static DEVICE_ATTR(ioc_guid,       S_IRUGO, show_ioc_guid,        NULL);
 static DEVICE_ATTR(service_id,     S_IRUGO, show_service_id,      NULL);
 static DEVICE_ATTR(pkey,           S_IRUGO, show_pkey,            NULL);
+static DEVICE_ATTR(sgid,           S_IRUGO, show_sgid,            NULL);
 static DEVICE_ATTR(dgid,           S_IRUGO, show_dgid,            NULL);
 static DEVICE_ATTR(orig_dgid,      S_IRUGO, show_orig_dgid,       NULL);
 static DEVICE_ATTR(req_lim,         S_IRUGO, show_req_lim,         NULL);
@@ -1934,6 +2195,7 @@ static DEVICE_ATTR(zero_req_lim,    S_IRUGO, show_zero_req_lim,      NULL);
 static DEVICE_ATTR(local_ib_port,   S_IRUGO, show_local_ib_port,   NULL);
 static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL);
 static DEVICE_ATTR(comp_vector,     S_IRUGO, show_comp_vector,     NULL);
+static DEVICE_ATTR(tl_retry_count,  S_IRUGO, show_tl_retry_count,  NULL);
 static DEVICE_ATTR(cmd_sg_entries,  S_IRUGO, show_cmd_sg_entries,  NULL);
 static DEVICE_ATTR(allow_ext_sg,    S_IRUGO, show_allow_ext_sg,    NULL);
 
@@ -1942,6 +2204,7 @@ static struct device_attribute *srp_host_attrs[] = {
        &dev_attr_ioc_guid,
        &dev_attr_service_id,
        &dev_attr_pkey,
+       &dev_attr_sgid,
        &dev_attr_dgid,
        &dev_attr_orig_dgid,
        &dev_attr_req_lim,
@@ -1949,6 +2212,7 @@ static struct device_attribute *srp_host_attrs[] = {
        &dev_attr_local_ib_port,
        &dev_attr_local_ib_device,
        &dev_attr_comp_vector,
+       &dev_attr_tl_retry_count,
        &dev_attr_cmd_sg_entries,
        &dev_attr_allow_ext_sg,
        NULL
@@ -1961,14 +2225,16 @@ static struct scsi_host_template srp_template = {
        .slave_configure                = srp_slave_configure,
        .info                           = srp_target_info,
        .queuecommand                   = srp_queuecommand,
+       .change_queue_depth             = srp_change_queue_depth,
+       .change_queue_type              = srp_change_queue_type,
        .eh_abort_handler               = srp_abort,
        .eh_device_reset_handler        = srp_reset_device,
        .eh_host_reset_handler          = srp_reset_host,
        .skip_settle_delay              = true,
        .sg_tablesize                   = SRP_DEF_SG_TABLESIZE,
-       .can_queue                      = SRP_CMD_SQ_SIZE,
+       .can_queue                      = SRP_DEFAULT_CMD_SQ_SIZE,
        .this_id                        = -1,
-       .cmd_per_lun                    = SRP_CMD_SQ_SIZE,
+       .cmd_per_lun                    = SRP_DEFAULT_CMD_SQ_SIZE,
        .use_clustering                 = ENABLE_CLUSTERING,
        .shost_attrs                    = srp_host_attrs
 };
@@ -1994,6 +2260,7 @@ static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
        }
 
        rport->lld_data = target;
+       target->rport = rport;
 
        spin_lock(&host->target_lock);
        list_add_tail(&target->list, &host->target_list);
@@ -2073,6 +2340,8 @@ enum {
        SRP_OPT_ALLOW_EXT_SG    = 1 << 10,
        SRP_OPT_SG_TABLESIZE    = 1 << 11,
        SRP_OPT_COMP_VECTOR     = 1 << 12,
+       SRP_OPT_TL_RETRY_COUNT  = 1 << 13,
+       SRP_OPT_QUEUE_SIZE      = 1 << 14,
        SRP_OPT_ALL             = (SRP_OPT_ID_EXT       |
                                   SRP_OPT_IOC_GUID     |
                                   SRP_OPT_DGID         |
@@ -2094,6 +2363,8 @@ static const match_table_t srp_opt_tokens = {
        { SRP_OPT_ALLOW_EXT_SG,         "allow_ext_sg=%u"       },
        { SRP_OPT_SG_TABLESIZE,         "sg_tablesize=%u"       },
        { SRP_OPT_COMP_VECTOR,          "comp_vector=%u"        },
+       { SRP_OPT_TL_RETRY_COUNT,       "tl_retry_count=%u"     },
+       { SRP_OPT_QUEUE_SIZE,           "queue_size=%d"         },
        { SRP_OPT_ERR,                  NULL                    }
 };
 
@@ -2188,13 +2459,25 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
                        target->scsi_host->max_sectors = token;
                        break;
 
+               case SRP_OPT_QUEUE_SIZE:
+                       if (match_int(args, &token) || token < 1) {
+                               pr_warn("bad queue_size parameter '%s'\n", p);
+                               goto out;
+                       }
+                       target->scsi_host->can_queue = token;
+                       target->queue_size = token + SRP_RSP_SQ_SIZE +
+                                            SRP_TSK_MGMT_SQ_SIZE;
+                       if (!(opt_mask & SRP_OPT_MAX_CMD_PER_LUN))
+                               target->scsi_host->cmd_per_lun = token;
+                       break;
+
                case SRP_OPT_MAX_CMD_PER_LUN:
-                       if (match_int(args, &token)) {
+                       if (match_int(args, &token) || token < 1) {
                                pr_warn("bad max cmd_per_lun parameter '%s'\n",
                                        p);
                                goto out;
                        }
-                       target->scsi_host->cmd_per_lun = min(token, SRP_CMD_SQ_SIZE);
+                       target->scsi_host->cmd_per_lun = token;
                        break;
 
                case SRP_OPT_IO_CLASS:
@@ -2257,6 +2540,15 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
                        target->comp_vector = token;
                        break;
 
+               case SRP_OPT_TL_RETRY_COUNT:
+                       if (match_int(args, &token) || token < 2 || token > 7) {
+                               pr_warn("bad tl_retry_count parameter '%s' (must be a number between 2 and 7)\n",
+                                       p);
+                               goto out;
+                       }
+                       target->tl_retry_count = token;
+                       break;
+
                default:
                        pr_warn("unknown parameter or missing value '%s' in target creation request\n",
                                p);
@@ -2273,6 +2565,12 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
                                pr_warn("target creation request is missing parameter '%s'\n",
                                        srp_opt_tokens[i].pattern);
 
+       if (target->scsi_host->cmd_per_lun > target->scsi_host->can_queue
+           && (opt_mask & SRP_OPT_MAX_CMD_PER_LUN))
+               pr_warn("cmd_per_lun = %d > queue_size = %d\n",
+                       target->scsi_host->cmd_per_lun,
+                       target->scsi_host->can_queue);
+
 out:
        kfree(options);
        return ret;
@@ -2287,8 +2585,7 @@ static ssize_t srp_create_target(struct device *dev,
        struct Scsi_Host *target_host;
        struct srp_target_port *target;
        struct ib_device *ibdev = host->srp_dev->dev;
-       dma_addr_t dma_addr;
-       int i, ret;
+       int ret;
 
        target_host = scsi_host_alloc(&srp_template,
                                      sizeof (struct srp_target_port));
@@ -2311,11 +2608,15 @@ static ssize_t srp_create_target(struct device *dev,
        target->cmd_sg_cnt      = cmd_sg_entries;
        target->sg_tablesize    = indirect_sg_entries ? : cmd_sg_entries;
        target->allow_ext_sg    = allow_ext_sg;
+       target->tl_retry_count  = 7;
+       target->queue_size      = SRP_DEFAULT_QUEUE_SIZE;
 
        ret = srp_parse_options(buf, target);
        if (ret)
                goto err;
 
+       target->req_ring_size = target->queue_size - SRP_TSK_MGMT_SQ_SIZE;
+
        if (!srp_conn_unique(target->srp_host, target)) {
                shost_printk(KERN_INFO, target->scsi_host,
                             PFX "Already connected to target port with id_ext=%016llx;ioc_guid=%016llx;initiator_ext=%016llx\n",
@@ -2339,31 +2640,13 @@ static ssize_t srp_create_target(struct device *dev,
                             sizeof (struct srp_indirect_buf) +
                             target->cmd_sg_cnt * sizeof (struct srp_direct_buf);
 
+       INIT_WORK(&target->tl_err_work, srp_tl_err_work);
        INIT_WORK(&target->remove_work, srp_remove_work);
        spin_lock_init(&target->lock);
        INIT_LIST_HEAD(&target->free_tx);
-       INIT_LIST_HEAD(&target->free_reqs);
-       for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) {
-               struct srp_request *req = &target->req_ring[i];
-
-               req->fmr_list = kmalloc(target->cmd_sg_cnt * sizeof (void *),
-                                       GFP_KERNEL);
-               req->map_page = kmalloc(SRP_FMR_SIZE * sizeof (void *),
-                                       GFP_KERNEL);
-               req->indirect_desc = kmalloc(target->indirect_size, GFP_KERNEL);
-               if (!req->fmr_list || !req->map_page || !req->indirect_desc)
-                       goto err_free_mem;
-
-               dma_addr = ib_dma_map_single(ibdev, req->indirect_desc,
-                                            target->indirect_size,
-                                            DMA_TO_DEVICE);
-               if (ib_dma_mapping_error(ibdev, dma_addr))
-                       goto err_free_mem;
-
-               req->indirect_dma_addr = dma_addr;
-               req->index = i;
-               list_add_tail(&req->list, &target->free_reqs);
-       }
+       ret = srp_alloc_req_data(target);
+       if (ret)
+               goto err_free_mem;
 
        ib_query_gid(ibdev, host->port, 0, &target->path.sgid);
 
@@ -2612,7 +2895,14 @@ static void srp_remove_one(struct ib_device *device)
 }
 
 static struct srp_function_template ib_srp_transport_functions = {
+       .has_rport_state         = true,
+       .reset_timer_if_blocked  = true,
+       .reconnect_delay         = &srp_reconnect_delay,
+       .fast_io_fail_tmo        = &srp_fast_io_fail_tmo,
+       .dev_loss_tmo            = &srp_dev_loss_tmo,
+       .reconnect               = srp_rport_reconnect,
        .rport_delete            = srp_rport_delete,
+       .terminate_rport_io      = srp_terminate_io,
 };
 
 static int __init srp_init_module(void)
index e641088c14dc37bda98e95134b4235f151e3c0fc..575681063f38b11fac26815e7c5e2a1fe6db5b42 100644 (file)
@@ -57,14 +57,11 @@ enum {
        SRP_MAX_LUN             = 512,
        SRP_DEF_SG_TABLESIZE    = 12,
 
-       SRP_RQ_SHIFT            = 6,
-       SRP_RQ_SIZE             = 1 << SRP_RQ_SHIFT,
-
-       SRP_SQ_SIZE             = SRP_RQ_SIZE,
+       SRP_DEFAULT_QUEUE_SIZE  = 1 << 6,
        SRP_RSP_SQ_SIZE         = 1,
-       SRP_REQ_SQ_SIZE         = SRP_SQ_SIZE - SRP_RSP_SQ_SIZE,
        SRP_TSK_MGMT_SQ_SIZE    = 1,
-       SRP_CMD_SQ_SIZE         = SRP_REQ_SQ_SIZE - SRP_TSK_MGMT_SQ_SIZE,
+       SRP_DEFAULT_CMD_SQ_SIZE = SRP_DEFAULT_QUEUE_SIZE - SRP_RSP_SQ_SIZE -
+                                 SRP_TSK_MGMT_SQ_SIZE,
 
        SRP_TAG_NO_REQ          = ~0U,
        SRP_TAG_TSK_MGMT        = 1U << 31,
@@ -140,7 +137,6 @@ struct srp_target_port {
        unsigned int            cmd_sg_cnt;
        unsigned int            indirect_size;
        bool                    allow_ext_sg;
-       bool                    transport_offline;
 
        /* Everything above this point is used in the hot path of
         * command processing. Try to keep them packed into cachelines.
@@ -153,10 +149,14 @@ struct srp_target_port {
        u16                     io_class;
        struct srp_host        *srp_host;
        struct Scsi_Host       *scsi_host;
+       struct srp_rport       *rport;
        char                    target_name[32];
        unsigned int            scsi_id;
        unsigned int            sg_tablesize;
+       int                     queue_size;
+       int                     req_ring_size;
        int                     comp_vector;
+       int                     tl_retry_count;
 
        struct ib_sa_path_rec   path;
        __be16                  orig_dgid[8];
@@ -172,10 +172,11 @@ struct srp_target_port {
 
        int                     zero_req_lim;
 
-       struct srp_iu          *tx_ring[SRP_SQ_SIZE];
-       struct srp_iu          *rx_ring[SRP_RQ_SIZE];
-       struct srp_request      req_ring[SRP_CMD_SQ_SIZE];
+       struct srp_iu          **tx_ring;
+       struct srp_iu          **rx_ring;
+       struct srp_request      *req_ring;
 
+       struct work_struct      tl_err_work;
        struct work_struct      remove_work;
 
        struct list_head        list;
index 38b523a1ece0634e7855b5eae62b94b6fe7fd160..a11ff74a5127019cb6f367d07ffae32429ccf37e 100644 (file)
@@ -80,7 +80,7 @@ config INPUT_MATRIXKMAP
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
-       tristate "Mouse interface" if EXPERT
+       tristate "Mouse interface"
        default y
        help
          Say Y here if you want your mouse to be accessible as char devices
index b6ded17b3be3adda86ca93bf582f679f837442aa..a06e12552886fa57ffbe1731eb744762666cd787 100644 (file)
@@ -18,6 +18,8 @@
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/input/mt.h>
@@ -369,7 +371,11 @@ static int evdev_release(struct inode *inode, struct file *file)
        mutex_unlock(&evdev->mutex);
 
        evdev_detach_client(evdev, client);
-       kfree(client);
+
+       if (is_vmalloc_addr(client))
+               vfree(client);
+       else
+               kfree(client);
 
        evdev_close_device(evdev);
 
@@ -389,12 +395,14 @@ static int evdev_open(struct inode *inode, struct file *file)
 {
        struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev);
        unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
+       unsigned int size = sizeof(struct evdev_client) +
+                                       bufsize * sizeof(struct input_event);
        struct evdev_client *client;
        int error;
 
-       client = kzalloc(sizeof(struct evdev_client) +
-                               bufsize * sizeof(struct input_event),
-                        GFP_KERNEL);
+       client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
+       if (!client)
+               client = vzalloc(size);
        if (!client)
                return -ENOMEM;
 
index e75d015024a15c7fb6eb3074299e234a69916594..846ccdd905b19b66872762fd05db29ea0552a8cb 100644 (file)
@@ -2052,7 +2052,7 @@ int input_register_device(struct input_dev *dev)
        if (dev->hint_events_per_packet < packet_size)
                dev->hint_events_per_packet = packet_size;
 
-       dev->max_vals = max(dev->hint_events_per_packet, packet_size) + 2;
+       dev->max_vals = dev->hint_events_per_packet + 2;
        dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL);
        if (!dev->vals) {
                error = -ENOMEM;
index c1edd39bc5ba1c1c39c81cd895f3e3ab8cbb5c01..bb174c1a9886eb8a1592f347e71e20bdb6fd90b6 100644 (file)
@@ -2,7 +2,7 @@
 # Input core configuration
 #
 menuconfig INPUT_KEYBOARD
-       bool "Keyboards" if EXPERT || !X86
+       bool "Keyboards"
        default y
        help
          Say Y here, and a list of supported keyboards will be displayed.
@@ -67,7 +67,7 @@ config KEYBOARD_ATARI
          module will be called atakbd.
 
 config KEYBOARD_ATKBD
-       tristate "AT keyboard" if EXPERT || !X86
+       tristate "AT keyboard"
        default y
        select SERIO
        select SERIO_LIBPS2
@@ -525,7 +525,7 @@ config KEYBOARD_SUNKBD
 
 config KEYBOARD_SH_KEYSC
        tristate "SuperH KEYSC keypad support"
-       depends on SUPERH || ARCH_SHMOBILE
+       depends on SUPERH || ARM || COMPILE_TEST
        help
          Say Y here if you want to use a keypad attached to the KEYSC block
          on SuperH processors such as sh7722 and sh7343.
index 440ce32462baefafcabdda55c5c168c27753757c..2db13246eb8e0ba360a9cddc8c7d82b842f62ff8 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/of_gpio.h>
 #include <linux/spinlock.h>
index cd5ed9e221686625ba2ef92916c155c84732cb81..4e428199e580f36c1c9228870d8b4b1a8d02ef0f 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/of_gpio.h>
 
index 42181435fe6759f4302ac8ffdd68f0ea41d1df0f..8b1b01361ec6feb9f9670713717f72e0a57a63ff 100644 (file)
@@ -383,7 +383,7 @@ static struct platform_driver lpc32xx_kscan_driver = {
                .name   = DRV_NAME,
                .owner  = THIS_MODULE,
                .pm     = &lpc32xx_kscan_pm_ops,
-               .of_match_table = of_match_ptr(lpc32xx_kscan_match),
+               .of_match_table = lpc32xx_kscan_match,
        }
 };
 
index b3e3edab6d9f208050bf029a85c0b63ab755969b..b31064981e9687d0c448c8b7410bbf802d256cce 100644 (file)
@@ -143,8 +143,10 @@ static int nspire_keypad_open(struct input_dev *input)
                return error;
 
        error = nspire_keypad_chip_init(keypad);
-       if (error)
+       if (error) {
+               clk_disable_unprepare(keypad->clk);
                return error;
+       }
 
        return 0;
 }
@@ -267,7 +269,7 @@ static struct platform_driver nspire_keypad_driver = {
        .driver = {
                .name = "nspire-keypad",
                .owner = THIS_MODULE,
-               .of_match_table = of_match_ptr(nspire_keypad_dt_match),
+               .of_match_table = nspire_keypad_dt_match,
        },
        .probe = nspire_keypad_probe,
 };
index a2e758d27584c0117a5c941d36b8042ab20f425f..186138c720c79ebfee4ef896c61aeee78c770289 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/err.h>
 #include <linux/input/matrix_keypad.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
index 9cd20e6905a08274bff3d55a48fa7e26d8f2b2c6..8508879f6fafd2663d393cb6afad9f00340b341c 100644 (file)
@@ -614,7 +614,7 @@ static int tegra_kbc_probe(struct platform_device *pdev)
        unsigned int keymap_rows;
        const struct of_device_id *match;
 
-       match = of_match_device(of_match_ptr(tegra_kbc_of_match), &pdev->dev);
+       match = of_match_device(tegra_kbc_of_match, &pdev->dev);
 
        kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL);
        if (!kbc) {
index 5f7b427dd7ed06e48b53aa6f0ae6c236af82dcfa..8bd24d52bf1bedd0438e0737350c640b6e3b38b8 100644 (file)
@@ -60,8 +60,8 @@ struct keypad_data {
        struct clk                      *clk;
        struct device                   *dev;
        spinlock_t                      lock;
-       u32                             irq_press;
-       u32                             irq_release;
+       int                             irq_press;
+       int                             irq_release;
        int                             rows, cols, row_shift;
        int                             debounce_ms, active_low;
        u32                             prev_keys[3];
index aa51baaa9b1ec273acc95c7edcb838ed81fe5fe2..5f4967d01bc36a621655f64eea7e2c1408ef43b7 100644 (file)
@@ -156,7 +156,7 @@ config INPUT_MAX8925_ONKEY
 
 config INPUT_MAX8997_HAPTIC
        tristate "MAXIM MAX8997 haptic controller support"
-       depends on HAVE_PWM && MFD_MAX8997
+       depends on PWM && HAVE_PWM && MFD_MAX8997
        select INPUT_FF_MEMLESS
        help
          This option enables device driver support for the haptic controller
@@ -461,7 +461,7 @@ config INPUT_PCF8574
 
 config INPUT_PWM_BEEPER
        tristate "PWM beeper support"
-       depends on HAVE_PWM || PWM
+       depends on PWM && HAVE_PWM
        help
          Say Y here to get support for PWM based beeper devices.
 
index 61891486067cab2a585303398182ffb721688658..3a90b710e30960e95421c1d486058ade968fd6bc 100644 (file)
@@ -108,7 +108,6 @@ static int ad714x_spi_remove(struct spi_device *spi)
        struct ad714x_chip *chip = spi_get_drvdata(spi);
 
        ad714x_remove(chip);
-       spi_set_drvdata(spi, NULL);
 
        return 0;
 }
index 4f77f87847e805ef33abf52f72f21a2dd92b2c81..b5d71d245854684a33d8baeead24b78148a087c7 100644 (file)
@@ -131,7 +131,6 @@ static int cobalt_buttons_probe(struct platform_device *pdev)
  err_free_mem:
        input_free_polled_device(poll_dev);
        kfree(bdev);
-       dev_set_drvdata(&pdev->dev, NULL);
        return error;
 }
 
@@ -144,7 +143,6 @@ static int cobalt_buttons_remove(struct platform_device *pdev)
        input_free_polled_device(bdev->poll_dev);
        iounmap(bdev->reg);
        kfree(bdev);
-       dev_set_drvdata(dev, NULL);
 
        return 0;
 }
index f3309696d053ae0692a21e39766806fd62ab9957..59d4dcddf6de0cf4d1c5384c977a36c319d66389 100644 (file)
@@ -168,7 +168,7 @@ static void mma8450_close(struct input_polled_dev *dev)
  * I2C init/probing/exit functions
  */
 static int mma8450_probe(struct i2c_client *c,
-                                  const struct i2c_device_id *id)
+                        const struct i2c_device_id *id)
 {
        struct input_polled_dev *idev;
        struct mma8450 *m;
@@ -204,6 +204,8 @@ static int mma8450_probe(struct i2c_client *c,
                goto err_free_mem;
        }
 
+       i2c_set_clientdata(c, m);
+
        return 0;
 
 err_free_mem:
index dce0d95943c537e1041dbca8372113f87fab3efb..6983ffbbfb94ac5fa90e0147c6a19de44d32e98b 100644 (file)
@@ -383,6 +383,7 @@ static int mpu3050_probe(struct i2c_client *client,
 
        pm_runtime_enable(&client->dev);
        pm_runtime_set_autosuspend_delay(&client->dev, MPU3050_AUTO_DELAY);
+       i2c_set_clientdata(client, sensor);
 
        return 0;
 
index 2ff4d1c78ab8ff91c4338c6e40d6ff91fac349c3..940566e7be1322751689027166653845173d6004 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/input.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pwm.h>
 #include <linux/slab.h>
index fb4f8ac3343bd5c47c987e4ffb11c2540cf60267..83fff38b86b367ccdd2728095cafc769b6d00531 100644 (file)
@@ -87,7 +87,6 @@ static int rb532_button_remove(struct platform_device *pdev)
 
        input_unregister_polled_device(poll_dev);
        input_free_polled_device(poll_dev);
-       dev_set_drvdata(&pdev->dev, NULL);
 
        return 0;
 }
index 5b1aff825138a1b9db5d2b216f7389168bb7bf9f..f920ba7ab51f5e1399649fa75c158a3770ae86e7 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/gpio.h>
 #include <linux/rotary_encoder.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/of_gpio.h>
 
index 0621c367049a3e8a0183af7f9d50611c3c0f3a11..7b8b03e0d0bef905cd793a158cfaba2f135eeb5f 100644 (file)
@@ -153,7 +153,7 @@ static struct platform_driver sirfsoc_pwrc_driver = {
                .name   = "sirfsoc-pwrc",
                .owner  = THIS_MODULE,
                .pm     = &sirfsoc_pwrc_pm_ops,
-               .of_match_table = of_match_ptr(sirfsoc_pwrc_of_match),
+               .of_match_table = sirfsoc_pwrc_of_match,
        }
 };
 
index a0a4bbaef02c242a8ee16e54bdb9337e8f80407e..772835938a526ed2575f6bc187619fe962ac0e6c 100644 (file)
@@ -430,20 +430,30 @@ static int uinput_setup_device(struct uinput_device *udev,
        return retval;
 }
 
-static ssize_t uinput_inject_event(struct uinput_device *udev,
-                                  const char __user *buffer, size_t count)
+static ssize_t uinput_inject_events(struct uinput_device *udev,
+                                   const char __user *buffer, size_t count)
 {
        struct input_event ev;
+       size_t bytes = 0;
 
-       if (count < input_event_size())
+       if (count != 0 && count < input_event_size())
                return -EINVAL;
 
-       if (input_event_from_user(buffer, &ev))
-               return -EFAULT;
+       while (bytes + input_event_size() <= count) {
+               /*
+                * Note that even if some events were fetched successfully
+                * we are still going to return EFAULT instead of partial
+                * count to let userspace know that it got it's buffers
+                * all wrong.
+                */
+               if (input_event_from_user(buffer + bytes, &ev))
+                       return -EFAULT;
 
-       input_event(udev->dev, ev.type, ev.code, ev.value);
+               input_event(udev->dev, ev.type, ev.code, ev.value);
+               bytes += input_event_size();
+       }
 
-       return input_event_size();
+       return bytes;
 }
 
 static ssize_t uinput_write(struct file *file, const char __user *buffer,
@@ -460,7 +470,7 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer,
                return retval;
 
        retval = udev->state == UIST_CREATED ?
-                       uinput_inject_event(udev, buffer, count) :
+                       uinput_inject_events(udev, buffer, count) :
                        uinput_setup_device(udev, buffer, count);
 
        mutex_unlock(&udev->mutex);
index 83658472ad2511735b2e02c8ee645858385d58f0..ca7a26f1dce81c37c6cd8524f8c4698effbfd739 100644 (file)
@@ -103,7 +103,6 @@ static const struct alps_model_info alps_model_data[] = {
        /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
        { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
                ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
-       { { 0x73, 0x00, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_DUALPOINT },              /* Dell XT2 */
        { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS },           /* Dell Vostro 1400 */
        { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
                ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },                            /* Toshiba Tecra A11-11L */
@@ -1793,7 +1792,7 @@ int alps_init(struct psmouse *psmouse)
        snprintf(priv->phys, sizeof(priv->phys), "%s/input1", psmouse->ps2dev.serio->phys);
        dev2->phys = priv->phys;
        dev2->name = (priv->flags & ALPS_DUALPOINT) ?
-                    "DualPoint Stick" : "PS/2 Mouse";
+                    "DualPoint Stick" : "ALPS PS/2 Device";
        dev2->id.bustype = BUS_I8042;
        dev2->id.vendor  = 0x0002;
        dev2->id.product = PSMOUSE_ALPS;
index f51765fff0545e91be567942255cf19532f94a71..a5869a856ea5ca3fff3a0c5bda49d0f81132b640 100644 (file)
@@ -439,7 +439,7 @@ static int cypress_get_finger_count(unsigned char header_byte)
                        case 2: return 5;
                        default:
                                /* Invalid contact (e.g. palm). Ignore it. */
-                               return -1;
+                               return 0;
                }
        }
 
@@ -452,17 +452,10 @@ static int cypress_parse_packet(struct psmouse *psmouse,
 {
        unsigned char *packet = psmouse->packet;
        unsigned char header_byte = packet[0];
-       int contact_cnt;
 
        memset(report_data, 0, sizeof(struct cytp_report_data));
 
-       contact_cnt = cypress_get_finger_count(header_byte);
-
-       if (contact_cnt < 0) /* e.g. palm detect */
-               return -EINVAL;
-
-       report_data->contact_cnt = contact_cnt;
-
+       report_data->contact_cnt = cypress_get_finger_count(header_byte);
        report_data->tap = (header_byte & ABS_MULTIFINGER_TAP) ? 1 : 0;
 
        if (report_data->contact_cnt == 1) {
@@ -535,11 +528,9 @@ static void cypress_process_packet(struct psmouse *psmouse, bool zero_pkt)
        int slots[CYTP_MAX_MT_SLOTS];
        int n;
 
-       if (cypress_parse_packet(psmouse, cytp, &report_data))
-               return;
+       cypress_parse_packet(psmouse, cytp, &report_data);
 
        n = report_data.contact_cnt;
-
        if (n > CYTP_MAX_MT_SLOTS)
                n = CYTP_MAX_MT_SLOTS;
 
@@ -605,10 +596,6 @@ static psmouse_ret_t cypress_validate_byte(struct psmouse *psmouse)
                return PSMOUSE_BAD_DATA;
 
        contact_cnt = cypress_get_finger_count(packet[0]);
-
-       if (contact_cnt < 0)
-               return PSMOUSE_BAD_DATA;
-
        if (cytp->mode & CYTP_BIT_ABS_NO_PRESSURE)
                cypress_set_packet_size(psmouse, contact_cnt == 2 ? 7 : 4);
        else
@@ -679,15 +666,15 @@ int cypress_init(struct psmouse *psmouse)
 {
        struct cytp_data *cytp;
 
-       cytp = (struct cytp_data *)kzalloc(sizeof(struct cytp_data), GFP_KERNEL);
-       psmouse->private = (void *)cytp;
-       if (cytp == NULL)
+       cytp = kzalloc(sizeof(struct cytp_data), GFP_KERNEL);
+       if (!cytp)
                return -ENOMEM;
 
-       cypress_reset(psmouse);
-
+       psmouse->private = cytp;
        psmouse->pktsize = 8;
 
+       cypress_reset(psmouse);
+
        if (cypress_query_hardware(psmouse)) {
                psmouse_err(psmouse, "Unable to query Trackpad hardware.\n");
                goto err_exit;
index 1de1e5f8f7956dad40a745a08c7d4026f1370e28..8541f949778dc16953bdd269418113f0aa132e04 100644 (file)
@@ -2,7 +2,7 @@
 # Input core configuration
 #
 config SERIO
-       tristate "Serial I/O support" if EXPERT || !X86
+       tristate "Serial I/O support"
        default y
        help
          Say Yes here if you have any input device that uses serial I/O to
@@ -19,7 +19,7 @@ config SERIO
 if SERIO
 
 config SERIO_I8042
-       tristate "i8042 PC Keyboard controller" if EXPERT || !X86
+       tristate "i8042 PC Keyboard controller"
        default y
        depends on !PARISC && (!ARM || FOOTBRIDGE_HOST) && \
                   (!SUPERH || SH_CAYMAN) && !M68K && !BLACKFIN && !S390 && \
@@ -170,7 +170,7 @@ config SERIO_MACEPS2
          module will be called maceps2.
 
 config SERIO_LIBPS2
-       tristate "PS/2 driver library" if EXPERT
+       tristate "PS/2 driver library"
        depends on SERIO_I8042 || SERIO_I8042=n
        help
          Say Y here if you are using a driver for device connected
@@ -266,4 +266,14 @@ config SERIO_OLPC_APSP
          To compile this driver as a module, choose M here: the module will
          be called olpc_apsp.
 
+config HYPERV_KEYBOARD
+       tristate "Microsoft Synthetic Keyboard driver"
+       depends on HYPERV
+       default HYPERV
+       help
+         Select this option to enable the Hyper-V Keyboard driver.
+
+         To compile this driver as a module, choose M here: the module will
+         be called hyperv_keyboard.
+
 endif
index 12298b1c0e716b62a771b9255b9f4f5c24b9e08e..815d874fe72469bd49a93edda8ea28c6aa3c7e58 100644 (file)
@@ -28,3 +28,4 @@ obj-$(CONFIG_SERIO_ALTERA_PS2)        += altera_ps2.o
 obj-$(CONFIG_SERIO_ARC_PS2)    += arc_ps2.o
 obj-$(CONFIG_SERIO_APBPS2)     += apbps2.o
 obj-$(CONFIG_SERIO_OLPC_APSP)  += olpc_apsp.o
+obj-$(CONFIG_HYPERV_KEYBOARD)  += hyperv-keyboard.o
diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c
new file mode 100644 (file)
index 0000000..3a83c3c
--- /dev/null
@@ -0,0 +1,437 @@
+/*
+ *  Copyright (c) 2013, Microsoft Corporation.
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms and conditions of the GNU General Public License,
+ *  version 2, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ *  more details.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/completion.h>
+#include <linux/hyperv.h>
+#include <linux/serio.h>
+#include <linux/slab.h>
+
+/*
+ * Current version 1.0
+ *
+ */
+#define SYNTH_KBD_VERSION_MAJOR 1
+#define SYNTH_KBD_VERSION_MINOR        0
+#define SYNTH_KBD_VERSION              (SYNTH_KBD_VERSION_MINOR | \
+                                        (SYNTH_KBD_VERSION_MAJOR << 16))
+
+
+/*
+ * Message types in the synthetic input protocol
+ */
+enum synth_kbd_msg_type {
+       SYNTH_KBD_PROTOCOL_REQUEST = 1,
+       SYNTH_KBD_PROTOCOL_RESPONSE = 2,
+       SYNTH_KBD_EVENT = 3,
+       SYNTH_KBD_LED_INDICATORS = 4,
+};
+
+/*
+ * Basic message structures.
+ */
+struct synth_kbd_msg_hdr {
+       __le32 type;
+};
+
+struct synth_kbd_msg {
+       struct synth_kbd_msg_hdr header;
+       char data[]; /* Enclosed message */
+};
+
+union synth_kbd_version {
+       __le32 version;
+};
+
+/*
+ * Protocol messages
+ */
+struct synth_kbd_protocol_request {
+       struct synth_kbd_msg_hdr header;
+       union synth_kbd_version version_requested;
+};
+
+#define PROTOCOL_ACCEPTED      BIT(0)
+struct synth_kbd_protocol_response {
+       struct synth_kbd_msg_hdr header;
+       __le32 proto_status;
+};
+
+#define IS_UNICODE     BIT(0)
+#define IS_BREAK       BIT(1)
+#define IS_E0          BIT(2)
+#define IS_E1          BIT(3)
+struct synth_kbd_keystroke {
+       struct synth_kbd_msg_hdr header;
+       __le16 make_code;
+       __le16 reserved0;
+       __le32 info; /* Additional information */
+};
+
+
+#define HK_MAXIMUM_MESSAGE_SIZE 256
+
+#define KBD_VSC_SEND_RING_BUFFER_SIZE          (10 * PAGE_SIZE)
+#define KBD_VSC_RECV_RING_BUFFER_SIZE          (10 * PAGE_SIZE)
+
+#define XTKBD_EMUL0     0xe0
+#define XTKBD_EMUL1     0xe1
+#define XTKBD_RELEASE   0x80
+
+
+/*
+ * Represents a keyboard device
+ */
+struct hv_kbd_dev {
+       struct hv_device *hv_dev;
+       struct serio *hv_serio;
+       struct synth_kbd_protocol_request protocol_req;
+       struct synth_kbd_protocol_response protocol_resp;
+       /* Synchronize the request/response if needed */
+       struct completion wait_event;
+       spinlock_t lock; /* protects 'started' field */
+       bool started;
+};
+
+static void hv_kbd_on_receive(struct hv_device *hv_dev,
+                             struct synth_kbd_msg *msg, u32 msg_length)
+{
+       struct hv_kbd_dev *kbd_dev = hv_get_drvdata(hv_dev);
+       struct synth_kbd_keystroke *ks_msg;
+       unsigned long flags;
+       u32 msg_type = __le32_to_cpu(msg->header.type);
+       u32 info;
+       u16 scan_code;
+
+       switch (msg_type) {
+       case SYNTH_KBD_PROTOCOL_RESPONSE:
+               /*
+                * Validate the information provided by the host.
+                * If the host is giving us a bogus packet,
+                * drop the packet (hoping the problem
+                * goes away).
+                */
+               if (msg_length < sizeof(struct synth_kbd_protocol_response)) {
+                       dev_err(&hv_dev->device,
+                               "Illegal protocol response packet (len: %d)\n",
+                               msg_length);
+                       break;
+               }
+
+               memcpy(&kbd_dev->protocol_resp, msg,
+                       sizeof(struct synth_kbd_protocol_response));
+               complete(&kbd_dev->wait_event);
+               break;
+
+       case SYNTH_KBD_EVENT:
+               /*
+                * Validate the information provided by the host.
+                * If the host is giving us a bogus packet,
+                * drop the packet (hoping the problem
+                * goes away).
+                */
+               if (msg_length < sizeof(struct  synth_kbd_keystroke)) {
+                       dev_err(&hv_dev->device,
+                               "Illegal keyboard event packet (len: %d)\n",
+                               msg_length);
+                       break;
+               }
+
+               ks_msg = (struct synth_kbd_keystroke *)msg;
+               info = __le32_to_cpu(ks_msg->info);
+
+               /*
+                * Inject the information through the serio interrupt.
+                */
+               spin_lock_irqsave(&kbd_dev->lock, flags);
+               if (kbd_dev->started) {
+                       if (info & IS_E0)
+                               serio_interrupt(kbd_dev->hv_serio,
+                                               XTKBD_EMUL0, 0);
+
+                       scan_code = __le16_to_cpu(ks_msg->make_code);
+                       if (info & IS_BREAK)
+                               scan_code |= XTKBD_RELEASE;
+
+                       serio_interrupt(kbd_dev->hv_serio, scan_code, 0);
+               }
+               spin_unlock_irqrestore(&kbd_dev->lock, flags);
+               break;
+
+       default:
+               dev_err(&hv_dev->device,
+                       "unhandled message type %d\n", msg_type);
+       }
+}
+
+static void hv_kbd_handle_received_packet(struct hv_device *hv_dev,
+                                         struct vmpacket_descriptor *desc,
+                                         u32 bytes_recvd,
+                                         u64 req_id)
+{
+       struct synth_kbd_msg *msg;
+       u32 msg_sz;
+
+       switch (desc->type) {
+       case VM_PKT_COMP:
+               break;
+
+       case VM_PKT_DATA_INBAND:
+               /*
+                * We have a packet that has "inband" data. The API used
+                * for retrieving the packet guarantees that the complete
+                * packet is read. So, minimally, we should be able to
+                * parse the payload header safely (assuming that the host
+                * can be trusted.  Trusting the host seems to be a
+                * reasonable assumption because in a virtualized
+                * environment there is not whole lot you can do if you
+                * don't trust the host.
+                *
+                * Nonetheless, let us validate if the host can be trusted
+                * (in a trivial way).  The interesting aspect of this
+                * validation is how do you recover if we discover that the
+                * host is not to be trusted? Simply dropping the packet, I
+                * don't think is an appropriate recovery.  In the interest
+                * of failing fast, it may be better to crash the guest.
+                * For now, I will just drop the packet!
+                */
+
+               msg_sz = bytes_recvd - (desc->offset8 << 3);
+               if (msg_sz <= sizeof(struct synth_kbd_msg_hdr)) {
+                       /*
+                        * Drop the packet and hope
+                        * the problem magically goes away.
+                        */
+                       dev_err(&hv_dev->device,
+                               "Illegal packet (type: %d, tid: %llx, size: %d)\n",
+                               desc->type, req_id, msg_sz);
+                       break;
+               }
+
+               msg = (void *)desc + (desc->offset8 << 3);
+               hv_kbd_on_receive(hv_dev, msg, msg_sz);
+               break;
+
+       default:
+               dev_err(&hv_dev->device,
+                       "unhandled packet type %d, tid %llx len %d\n",
+                       desc->type, req_id, bytes_recvd);
+               break;
+       }
+}
+
+static void hv_kbd_on_channel_callback(void *context)
+{
+       struct hv_device *hv_dev = context;
+       void *buffer;
+       int bufferlen = 0x100; /* Start with sensible size */
+       u32 bytes_recvd;
+       u64 req_id;
+       int error;
+
+       buffer = kmalloc(bufferlen, GFP_ATOMIC);
+       if (!buffer)
+               return;
+
+       while (1) {
+               error = vmbus_recvpacket_raw(hv_dev->channel, buffer, bufferlen,
+                                            &bytes_recvd, &req_id);
+               switch (error) {
+               case 0:
+                       if (bytes_recvd == 0) {
+                               kfree(buffer);
+                               return;
+                       }
+
+                       hv_kbd_handle_received_packet(hv_dev, buffer,
+                                                     bytes_recvd, req_id);
+                       break;
+
+               case -ENOBUFS:
+                       kfree(buffer);
+                       /* Handle large packet */
+                       bufferlen = bytes_recvd;
+                       buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
+                       if (!buffer)
+                               return;
+                       break;
+               }
+       }
+}
+
+static int hv_kbd_connect_to_vsp(struct hv_device *hv_dev)
+{
+       struct hv_kbd_dev *kbd_dev = hv_get_drvdata(hv_dev);
+       struct synth_kbd_protocol_request *request;
+       struct synth_kbd_protocol_response *response;
+       u32 proto_status;
+       int error;
+
+       request = &kbd_dev->protocol_req;
+       memset(request, 0, sizeof(struct synth_kbd_protocol_request));
+       request->header.type = __cpu_to_le32(SYNTH_KBD_PROTOCOL_REQUEST);
+       request->version_requested.version = __cpu_to_le32(SYNTH_KBD_VERSION);
+
+       error = vmbus_sendpacket(hv_dev->channel, request,
+                                sizeof(struct synth_kbd_protocol_request),
+                                (unsigned long)request,
+                                VM_PKT_DATA_INBAND,
+                                VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
+       if (error)
+               return error;
+
+       if (!wait_for_completion_timeout(&kbd_dev->wait_event, 10 * HZ))
+               return -ETIMEDOUT;
+
+       response = &kbd_dev->protocol_resp;
+       proto_status = __le32_to_cpu(response->proto_status);
+       if (!(proto_status & PROTOCOL_ACCEPTED)) {
+               dev_err(&hv_dev->device,
+                       "synth_kbd protocol request failed (version %d)\n",
+                       SYNTH_KBD_VERSION);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static int hv_kbd_start(struct serio *serio)
+{
+       struct hv_kbd_dev *kbd_dev = serio->port_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&kbd_dev->lock, flags);
+       kbd_dev->started = true;
+       spin_unlock_irqrestore(&kbd_dev->lock, flags);
+
+       return 0;
+}
+
+static void hv_kbd_stop(struct serio *serio)
+{
+       struct hv_kbd_dev *kbd_dev = serio->port_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&kbd_dev->lock, flags);
+       kbd_dev->started = false;
+       spin_unlock_irqrestore(&kbd_dev->lock, flags);
+}
+
+static int hv_kbd_probe(struct hv_device *hv_dev,
+                       const struct hv_vmbus_device_id *dev_id)
+{
+       struct hv_kbd_dev *kbd_dev;
+       struct serio *hv_serio;
+       int error;
+
+       kbd_dev = kzalloc(sizeof(struct hv_kbd_dev), GFP_KERNEL);
+       hv_serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
+       if (!kbd_dev || !hv_serio) {
+               error = -ENOMEM;
+               goto err_free_mem;
+       }
+
+       kbd_dev->hv_dev = hv_dev;
+       kbd_dev->hv_serio = hv_serio;
+       spin_lock_init(&kbd_dev->lock);
+       init_completion(&kbd_dev->wait_event);
+       hv_set_drvdata(hv_dev, kbd_dev);
+
+       hv_serio->dev.parent  = &hv_dev->device;
+       hv_serio->id.type = SERIO_8042_XL;
+       hv_serio->port_data = kbd_dev;
+       strlcpy(hv_serio->name, dev_name(&hv_dev->device),
+               sizeof(hv_serio->name));
+       strlcpy(hv_serio->phys, dev_name(&hv_dev->device),
+               sizeof(hv_serio->phys));
+
+       hv_serio->start = hv_kbd_start;
+       hv_serio->stop = hv_kbd_stop;
+
+       error = vmbus_open(hv_dev->channel,
+                          KBD_VSC_SEND_RING_BUFFER_SIZE,
+                          KBD_VSC_RECV_RING_BUFFER_SIZE,
+                          NULL, 0,
+                          hv_kbd_on_channel_callback,
+                          hv_dev);
+       if (error)
+               goto err_free_mem;
+
+       error = hv_kbd_connect_to_vsp(hv_dev);
+       if (error)
+               goto err_close_vmbus;
+
+       serio_register_port(kbd_dev->hv_serio);
+       return 0;
+
+err_close_vmbus:
+       vmbus_close(hv_dev->channel);
+err_free_mem:
+       kfree(hv_serio);
+       kfree(kbd_dev);
+       return error;
+}
+
+static int hv_kbd_remove(struct hv_device *hv_dev)
+{
+       struct hv_kbd_dev *kbd_dev = hv_get_drvdata(hv_dev);
+
+       serio_unregister_port(kbd_dev->hv_serio);
+       vmbus_close(hv_dev->channel);
+       kfree(kbd_dev);
+
+       hv_set_drvdata(hv_dev, NULL);
+
+       return 0;
+}
+
+/*
+ * Keyboard GUID
+ * {f912ad6d-2b17-48ea-bd65-f927a61c7684}
+ */
+#define HV_KBD_GUID \
+       .guid = { \
+                       0x6d, 0xad, 0x12, 0xf9, 0x17, 0x2b, 0xea, 0x48, \
+                       0xbd, 0x65, 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84 \
+       }
+
+static const struct hv_vmbus_device_id id_table[] = {
+       /* Keyboard guid */
+       { HV_KBD_GUID, },
+       { },
+};
+
+MODULE_DEVICE_TABLE(vmbus, id_table);
+
+static struct  hv_driver hv_kbd_drv = {
+       .name = KBUILD_MODNAME,
+       .id_table = id_table,
+       .probe = hv_kbd_probe,
+       .remove = hv_kbd_remove,
+};
+
+static int __init hv_kbd_init(void)
+{
+       return vmbus_driver_register(&hv_kbd_drv);
+}
+
+static void __exit hv_kbd_exit(void)
+{
+       vmbus_driver_unregister(&hv_kbd_drv);
+}
+
+MODULE_LICENSE("GPL");
+module_init(hv_kbd_init);
+module_exit(hv_kbd_exit);
index 5f306f79da0cecaebd986f0fe39595c451b2ad9b..0ec9abbe31fec3af5248808fce517fc863ff75b2 100644 (file)
@@ -765,6 +765,7 @@ static struct pnp_device_id pnp_kbd_devids[] = {
        { .id = "CPQA0D7", .driver_data = 0 },
        { .id = "", },
 };
+MODULE_DEVICE_TABLE(pnp, pnp_kbd_devids);
 
 static struct pnp_driver i8042_pnp_kbd_driver = {
        .name           = "i8042 kbd",
@@ -786,6 +787,7 @@ static struct pnp_device_id pnp_aux_devids[] = {
        { .id = "SYN0801", .driver_data = 0 },
        { .id = "", },
 };
+MODULE_DEVICE_TABLE(pnp, pnp_aux_devids);
 
 static struct pnp_driver i8042_pnp_aux_driver = {
        .name           = "i8042 aux",
index 52c9ebf94729ff5bf6531cc7773902ece632d03b..020053fa5aaa38fce82b5fc2d6ced8546661c9df 100644 (file)
@@ -1036,7 +1036,7 @@ static void i8042_controller_reset(bool force_reset)
 /*
  * i8042_panic_blink() will turn the keyboard LEDs on or off and is called
  * when kernel panics. Flashing LEDs is useful for users running X who may
- * not see the console and will help distingushing panics from "real"
+ * not see the console and will help distinguishing panics from "real"
  * lockups.
  *
  * Note that DELAY has a limit of 10ms so we will not get stuck here
index e53416a4d7f3275ea2fd8f53f6a55dcbb6de02ad..867e7c33ac55072b19f2ff339705c4e90f6b428d 100644 (file)
@@ -524,9 +524,6 @@ static int wacom_set_device_mode(struct usb_interface *intf, int report_id, int
 
                error = wacom_set_report(intf, WAC_HID_FEATURE_REPORT,
                                         report_id, rep_data, length, 1);
-               if (error >= 0)
-                       error = wacom_get_report(intf, WAC_HID_FEATURE_REPORT,
-                                                report_id, rep_data, length, 1);
        } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
 
        kfree(rep_data);
@@ -548,7 +545,7 @@ static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_feat
                        /* MT Tablet PC touch */
                        return wacom_set_device_mode(intf, 3, 4, 4);
                }
-               else if (features->type == WACOM_24HDT) {
+               else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) {
                        return wacom_set_device_mode(intf, 18, 3, 2);
                }
        } else if (features->device_type == BTN_TOOL_PEN) {
@@ -719,7 +716,7 @@ static int wacom_led_control(struct wacom *wacom)
                return -ENOMEM;
 
        if (wacom->wacom_wac.features.type >= INTUOS5S &&
-           wacom->wacom_wac.features.type <= INTUOS5L) {
+           wacom->wacom_wac.features.type <= INTUOSPL) {
                /*
                 * Touch Ring and crop mark LED luminance may take on
                 * one of four values:
@@ -981,14 +978,20 @@ static int wacom_initialize_leds(struct wacom *wacom)
        case INTUOS5S:
        case INTUOS5:
        case INTUOS5L:
-               wacom->led.select[0] = 0;
-               wacom->led.select[1] = 0;
-               wacom->led.llv = 32;
-               wacom->led.hlv = 0;
-               wacom->led.img_lum = 0;
-
-               error = sysfs_create_group(&wacom->intf->dev.kobj,
-                                          &intuos5_led_attr_group);
+       case INTUOSPS:
+       case INTUOSPM:
+       case INTUOSPL:
+               if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) {
+                       wacom->led.select[0] = 0;
+                       wacom->led.select[1] = 0;
+                       wacom->led.llv = 32;
+                       wacom->led.hlv = 0;
+                       wacom->led.img_lum = 0;
+
+                       error = sysfs_create_group(&wacom->intf->dev.kobj,
+                                                 &intuos5_led_attr_group);
+               } else
+                       return 0;
                break;
 
        default:
@@ -1024,8 +1027,12 @@ static void wacom_destroy_leds(struct wacom *wacom)
        case INTUOS5S:
        case INTUOS5:
        case INTUOS5L:
-               sysfs_remove_group(&wacom->intf->dev.kobj,
-                                  &intuos5_led_attr_group);
+       case INTUOSPS:
+       case INTUOSPM:
+       case INTUOSPL:
+               if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN)
+                       sysfs_remove_group(&wacom->intf->dev.kobj,
+                                          &intuos5_led_attr_group);
                break;
        }
 }
@@ -1185,34 +1192,47 @@ static void wacom_wireless_work(struct work_struct *work)
                wacom_wac1->features =
                        *((struct wacom_features *)id->driver_info);
                wacom_wac1->features.device_type = BTN_TOOL_PEN;
+               snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen",
+                        wacom_wac1->features.name);
                error = wacom_register_input(wacom1);
                if (error)
-                       goto fail1;
+                       goto fail;
 
                /* Touch interface */
-               wacom_wac2->features =
-                       *((struct wacom_features *)id->driver_info);
-               wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
-               wacom_wac2->features.device_type = BTN_TOOL_FINGER;
-               wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
-               error = wacom_register_input(wacom2);
-               if (error)
-                       goto fail2;
+               if (wacom_wac1->features.touch_max) {
+                       wacom_wac2->features =
+                               *((struct wacom_features *)id->driver_info);
+                       wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
+                       wacom_wac2->features.device_type = BTN_TOOL_FINGER;
+                       wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
+                       if (wacom_wac2->features.touch_max)
+                               snprintf(wacom_wac2->name, WACOM_NAME_MAX,
+                                        "%s (WL) Finger",wacom_wac2->features.name);
+                       else
+                               snprintf(wacom_wac2->name, WACOM_NAME_MAX,
+                                        "%s (WL) Pad",wacom_wac2->features.name);
+                       error = wacom_register_input(wacom2);
+                       if (error)
+                               goto fail;
+               }
 
                error = wacom_initialize_battery(wacom);
                if (error)
-                       goto fail3;
+                       goto fail;
        }
 
        return;
 
-fail3:
-       input_unregister_device(wacom_wac2->input);
-       wacom_wac2->input = NULL;
-fail2:
-       input_unregister_device(wacom_wac1->input);
-       wacom_wac1->input = NULL;
-fail1:
+fail:
+       if (wacom_wac2->input) {
+               input_unregister_device(wacom_wac2->input);
+               wacom_wac2->input = NULL;
+       }
+
+       if (wacom_wac1->input) {
+               input_unregister_device(wacom_wac1->input);
+               wacom_wac1->input = NULL;
+       }
        return;
 }
 
@@ -1302,7 +1322,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
         * HID descriptor. If this is the touch interface (wMaxPacketSize
         * of WACOM_PKGLEN_BBTOUCH3), override the table values.
         */
-       if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
+       if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
                if (endpoint->wMaxPacketSize == WACOM_PKGLEN_BBTOUCH3) {
                        features->device_type = BTN_TOOL_FINGER;
                        features->pktlen = WACOM_PKGLEN_BBTOUCH3;
@@ -1329,10 +1349,12 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
                struct usb_device *other_dev;
 
                /* Append the device type to the name */
-               strlcat(wacom_wac->name,
-                       features->device_type == BTN_TOOL_PEN ?
-                               " Pen" : " Finger",
-                       sizeof(wacom_wac->name));
+               if (features->device_type != BTN_TOOL_FINGER)
+                       strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
+               else if (features->touch_max)
+                       strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
+               else
+                       strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
 
                other_dev = wacom_get_sibling(dev, features->oVid, features->oPid);
                if (other_dev == NULL || wacom_get_usbdev_data(other_dev) == NULL)
index c59b797eeafaa4f6258552389437cb8d113e1642..782c2535f1d81a26db96716ac406405b2b03a78b 100644 (file)
@@ -427,6 +427,13 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
                        (features->type == WACOM_21UX2))
                return 1;
 
+       /* Range Report */
+       if ((data[1] & 0xfe) == 0x20) {
+               input_report_key(input, BTN_TOUCH, 0);
+               input_report_abs(input, ABS_PRESSURE, 0);
+               input_report_abs(input, ABS_DISTANCE, wacom->features.distance_max);
+       }
+
        /* Exit report */
        if ((data[1] & 0xfe) == 0x80) {
                if (features->quirks == WACOM_QUIRK_MULTI_INPUT)
@@ -477,7 +484,7 @@ static void wacom_intuos_general(struct wacom_wac *wacom)
        /* general pen packet */
        if ((data[1] & 0xb8) == 0xa0) {
                t = (data[6] << 2) | ((data[7] >> 6) & 3);
-               if (features->type >= INTUOS4S && features->type <= WACOM_24HD) {
+               if (features->type >= INTUOS4S && features->type <= CINTIQ_HYBRID) {
                        t = (t << 1) | (data[1] & 1);
                }
                input_report_abs(input, ABS_PRESSURE, t);
@@ -621,14 +628,30 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
                        } else {
                                input_report_abs(input, ABS_MISC, 0);
                        }
-               } else if (features->type >= INTUOS5S && features->type <= INTUOS5L) {
+               } else if (features->type == CINTIQ_HYBRID) {
+                       /*
+                        * Do not send hardware buttons under Android. They
+                        * are already sent to the system through GPIO (and
+                        * have different meaning).
+                        */
+                       input_report_key(input, BTN_1, (data[4] & 0x01));
+                       input_report_key(input, BTN_2, (data[4] & 0x02));
+                       input_report_key(input, BTN_3, (data[4] & 0x04));
+                       input_report_key(input, BTN_4, (data[4] & 0x08));
+
+                       input_report_key(input, BTN_5, (data[4] & 0x10));  /* Right  */
+                       input_report_key(input, BTN_6, (data[4] & 0x20));  /* Up     */
+                       input_report_key(input, BTN_7, (data[4] & 0x40));  /* Left   */
+                       input_report_key(input, BTN_8, (data[4] & 0x80));  /* Down   */
+                       input_report_key(input, BTN_0, (data[3] & 0x01));  /* Center */
+               } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
                        int i;
 
                        /* Touch ring mode switch has no capacitive sensor */
                        input_report_key(input, BTN_0, (data[3] & 0x01));
 
                        /*
-                        * ExpressKeys on Intuos5 have a capacitive sensor in
+                        * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
                         * addition to the mechanical switch. Switch data is
                         * stored in data[4], capacitive data in data[5].
                         */
@@ -716,7 +739,9 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
             features->type == INTUOS4 ||
             features->type == INTUOS4S ||
             features->type == INTUOS5 ||
-            features->type == INTUOS5S)) {
+            features->type == INTUOS5S ||
+            features->type == INTUOSPM ||
+            features->type == INTUOSPS)) {
 
                return 0;
        }
@@ -769,8 +794,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
 
                } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
                        /* I4 mouse */
-                       if ((features->type >= INTUOS4S && features->type <= INTUOS4L) ||
-                           (features->type >= INTUOS5S && features->type <= INTUOS5L)) {
+                       if (features->type >= INTUOS4S && features->type <= INTUOSPL) {
                                input_report_key(input, BTN_LEFT,   data[6] & 0x01);
                                input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
                                input_report_key(input, BTN_RIGHT,  data[6] & 0x04);
@@ -797,7 +821,8 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
                                }
                        }
                } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
-                               features->type == INTUOS4L || features->type == INTUOS5L) &&
+                               features->type == INTUOS4L || features->type == INTUOS5L ||
+                               features->type == INTUOSPL) &&
                           wacom->tool[idx] == BTN_TOOL_LENS) {
                        /* Lens cursor packets */
                        input_report_key(input, BTN_LEFT,   data[8] & 0x01);
@@ -1107,6 +1132,7 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
 
 static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
 {
+       struct wacom_features *features = &wacom->features;
        struct input_dev *input = wacom->input;
        bool touch = data[1] & 0x80;
        int slot = input_mt_get_slot_by_key(input, data[0]);
@@ -1122,14 +1148,23 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
        if (touch) {
                int x = (data[2] << 4) | (data[4] >> 4);
                int y = (data[3] << 4) | (data[4] & 0x0f);
-               int a = data[5];
+               int width, height;
 
-               // "a" is a scaled-down area which we assume is roughly
-               // circular and which can be described as: a=(pi*r^2)/C.
-               int x_res  = input_abs_get_res(input, ABS_X);
-               int y_res  = input_abs_get_res(input, ABS_Y);
-               int width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
-               int height = width * y_res / x_res;
+               if (features->type >= INTUOSPS && features->type <= INTUOSPL) {
+                       width  = data[5];
+                       height = data[6];
+               } else {
+                       /*
+                        * "a" is a scaled-down area which we assume is
+                        * roughly circular and which can be described as:
+                        * a=(pi*r^2)/C.
+                        */
+                       int a = data[5];
+                       int x_res  = input_abs_get_res(input, ABS_X);
+                       int y_res  = input_abs_get_res(input, ABS_Y);
+                       width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
+                       height = width * y_res / x_res;
+               }
 
                input_report_abs(input, ABS_MT_POSITION_X, x);
                input_report_abs(input, ABS_MT_POSITION_Y, y);
@@ -1327,6 +1362,7 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
        case WACOM_22HD:
        case WACOM_24HD:
        case DTK:
+       case CINTIQ_HYBRID:
                sync = wacom_intuos_irq(wacom_wac);
                break;
 
@@ -1337,6 +1373,9 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
        case INTUOS5S:
        case INTUOS5:
        case INTUOS5L:
+       case INTUOSPS:
+       case INTUOSPM:
+       case INTUOSPL:
                if (len == WACOM_PKGLEN_BBTOUCH3)
                        sync = wacom_bpt3_touch(wacom_wac);
                else
@@ -1420,7 +1459,7 @@ void wacom_setup_device_quirks(struct wacom_features *features)
 
        /* these device have multiple inputs */
        if (features->type >= WIRELESS ||
-           (features->type >= INTUOS5S && features->type <= INTUOS5L) ||
+           (features->type >= INTUOS5S && features->type <= INTUOSPL) ||
            (features->oVid && features->oPid))
                features->quirks |= WACOM_QUIRK_MULTI_INPUT;
 
@@ -1627,6 +1666,8 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
 
        case INTUOS5:
        case INTUOS5L:
+       case INTUOSPM:
+       case INTUOSPL:
                if (features->device_type == BTN_TOOL_PEN) {
                        __set_bit(BTN_7, input_dev->keybit);
                        __set_bit(BTN_8, input_dev->keybit);
@@ -1634,6 +1675,7 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
                /* fall through */
 
        case INTUOS5S:
+       case INTUOSPS:
                __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
 
                if (features->device_type == BTN_TOOL_PEN) {
@@ -1765,6 +1807,24 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
                                              0, 0);
                }
                break;
+
+       case CINTIQ_HYBRID:
+               __set_bit(BTN_1, input_dev->keybit);
+               __set_bit(BTN_2, input_dev->keybit);
+               __set_bit(BTN_3, input_dev->keybit);
+               __set_bit(BTN_4, input_dev->keybit);
+
+               __set_bit(BTN_5, input_dev->keybit);
+               __set_bit(BTN_6, input_dev->keybit);
+               __set_bit(BTN_7, input_dev->keybit);
+               __set_bit(BTN_8, input_dev->keybit);
+               __set_bit(BTN_0, input_dev->keybit);
+
+               input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
+               __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
+
+               wacom_setup_cintiq(wacom_wac);
+               break;
        }
        return 0;
 }
@@ -1952,6 +2012,18 @@ static const struct wacom_features wacom_features_0x29 =
 static const struct wacom_features wacom_features_0x2A =
        { "Wacom Intuos5 M", WACOM_PKGLEN_INTUOS,  44704, 27940, 2047,
          63, INTUOS5, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
+static const struct wacom_features wacom_features_0x314 =
+       { "Wacom Intuos Pro S", WACOM_PKGLEN_INTUOS,  31496, 19685, 2047,
+         63, INTUOSPS, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
+         .touch_max = 16 };
+static const struct wacom_features wacom_features_0x315 =
+       { "Wacom Intuos Pro M", WACOM_PKGLEN_INTUOS,  44704, 27940, 2047,
+         63, INTUOSPM, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
+         .touch_max = 16 };
+static const struct wacom_features wacom_features_0x317 =
+       { "Wacom Intuos Pro L", WACOM_PKGLEN_INTUOS,  65024, 40640, 2047,
+         63, INTUOSPL, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
+         .touch_max = 16 };
 static const struct wacom_features wacom_features_0xF4 =
        { "Wacom Cintiq 24HD",       WACOM_PKGLEN_INTUOS,   104480, 65600, 2047,
          63, WACOM_24HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES };
@@ -2131,6 +2203,13 @@ static const struct wacom_features wacom_features_0x301 =
 static const struct wacom_features wacom_features_0x6004 =
        { "ISD-V4",               WACOM_PKGLEN_GRAPHIRE,  12800,  8000,  255,
          0, TABLETPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
+static const struct wacom_features wacom_features_0x0307 =
+       { "Wacom ISDv5 307", WACOM_PKGLEN_INTUOS,  59552,  33848, 2047,
+         63, CINTIQ_HYBRID, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
+         .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x309 };
+static const struct wacom_features wacom_features_0x0309 =
+       { "Wacom ISDv5 309", .type = WACOM_24HDT, /* Touch */
+         .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x0307, .touch_max = 10 };
 
 #define USB_DEVICE_WACOM(prod)                                 \
        USB_DEVICE(USB_VENDOR_ID_WACOM, prod),                  \
@@ -2259,12 +2338,17 @@ const struct usb_device_id wacom_ids[] = {
        { USB_DEVICE_WACOM(0x300) },
        { USB_DEVICE_WACOM(0x301) },
        { USB_DEVICE_WACOM(0x304) },
+       { USB_DEVICE_DETAILED(0x314, USB_CLASS_HID, 0, 0) },
+       { USB_DEVICE_DETAILED(0x315, USB_CLASS_HID, 0, 0) },
+       { USB_DEVICE_DETAILED(0x317, USB_CLASS_HID, 0, 0) },
        { USB_DEVICE_WACOM(0x4001) },
        { USB_DEVICE_WACOM(0x47) },
        { USB_DEVICE_WACOM(0xF4) },
        { USB_DEVICE_WACOM(0xF8) },
        { USB_DEVICE_DETAILED(0xF6, USB_CLASS_HID, 0, 0) },
        { USB_DEVICE_WACOM(0xFA) },
+       { USB_DEVICE_WACOM(0x0307) },
+       { USB_DEVICE_DETAILED(0x0309, USB_CLASS_HID, 0, 0) },
        { USB_DEVICE_LENOVO(0x6004) },
        { }
 };
index dfc9e08e7f70458c0a41378ae7034a027e52d0ea..fd23a3790605070a41ec37f19eff051b0e89be5a 100644 (file)
@@ -14,6 +14,8 @@
 /* maximum packet length for USB devices */
 #define WACOM_PKGLEN_MAX       64
 
+#define WACOM_NAME_MAX         64
+
 /* packet length for individual models */
 #define WACOM_PKGLEN_PENPRTN    7
 #define WACOM_PKGLEN_GRAPHIRE   8
@@ -76,10 +78,14 @@ enum {
        INTUOS5S,
        INTUOS5,
        INTUOS5L,
+       INTUOSPS,
+       INTUOSPM,
+       INTUOSPL,
        WACOM_21UX2,
        WACOM_22HD,
        DTK,
        WACOM_24HD,
+       CINTIQ_HYBRID,
        CINTIQ,
        WACOM_BEE,
        WACOM_13HD,
@@ -126,7 +132,7 @@ struct wacom_shared {
 };
 
 struct wacom_wac {
-       char name[64];
+       char name[WACOM_NAME_MAX];
        unsigned char *data;
        int tool[2];
        int id[2];
index e09ec67957a3c32b185dd451fedba467729d0b77..00d1e547b21119bb72e723633a08023f3eb2052f 100644 (file)
@@ -919,4 +919,17 @@ config TOUCHSCREEN_TPS6507X
          To compile this driver as a module, choose M here: the
          module will be called tps6507x_ts.
 
+config TOUCHSCREEN_ZFORCE
+       tristate "Neonode zForce infrared touchscreens"
+       depends on I2C
+       depends on GPIOLIB
+       help
+         Say Y here if you have a touchscreen using the zforce
+         infraread technology from Neonode.
+
+         If unsure, say N.
+
+         To compile this driver as a module, choose M here: the
+         module will be called zforce_ts.
+
 endif
index f5216c1bf53e7faa637f34e3570f8d9ba104c291..7587883b8d387b30cbcf63be49f2c8cc55e58974 100644 (file)
@@ -75,3 +75,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE)    += mainstone-wm97xx.o
 obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE)      += zylonite-wm97xx.o
 obj-$(CONFIG_TOUCHSCREEN_W90X900)      += w90p910_ts.o
 obj-$(CONFIG_TOUCHSCREEN_TPS6507X)     += tps6507x-ts.o
+obj-$(CONFIG_TOUCHSCREEN_ZFORCE)       += zforce_ts.o
index f3a174a83c82ced113c265ba1b1601774f23e765..69834dd3c313b95dcab54dcd23d51a6730727868 100644 (file)
@@ -806,7 +806,6 @@ err_free_irq:
 err_free_mem:
        input_free_device(input_dev);
        kfree(ts);
-       spi_set_drvdata(spi, NULL);
        return err;
 }
 
@@ -823,7 +822,6 @@ static int ad7877_remove(struct spi_device *spi)
        kfree(ts);
 
        dev_dbg(&spi->dev, "unregistered touchscreen\n");
-       spi_set_drvdata(spi, NULL);
 
        return 0;
 }
index 606da5bd61150958afca42a472c230a6e70ad26e..1a7b1143536e1d4a68dd6fb9e1c85cf992afee04 100644 (file)
@@ -142,7 +142,6 @@ static int ad7879_spi_remove(struct spi_device *spi)
        struct ad7879 *ts = spi_get_drvdata(spi);
 
        ad7879_remove(ts);
-       spi_set_drvdata(spi, NULL);
 
        return 0;
 }
index d038575f49db3a6d70e16ee640fb67cfbcab24be..42d830efa316ec9c44f53306123e0ffb2a2d04b5 100644 (file)
@@ -2113,7 +2113,6 @@ error_startup:
 error_request_irq:
        if (cd->cpdata->init)
                cd->cpdata->init(cd->cpdata, 0, dev);
-       dev_set_drvdata(dev, NULL);
 error_free_xfer:
        kfree(cd->xfer_buf);
 error_free_cd:
@@ -2151,7 +2150,6 @@ int cyttsp4_remove(struct cyttsp4 *cd)
        free_irq(cd->irq, cd);
        if (cd->cpdata->init)
                cd->cpdata->init(cd->cpdata, 0, dev);
-       dev_set_drvdata(dev, NULL);
        cyttsp4_free_si_ptrs(cd);
        kfree(cd);
        return 0;
index a71e1141d6386f9546fe32e5496437e72e393885..b19434cebbf6ac56d18ff13fc408108d119d7843 100644 (file)
@@ -171,10 +171,7 @@ static int cyttsp4_spi_probe(struct spi_device *spi)
        ts = cyttsp4_probe(&cyttsp_spi_bus_ops, &spi->dev, spi->irq,
                          CY_SPI_DATA_BUF_SIZE);
 
-       if (IS_ERR(ts))
-               return PTR_ERR(ts);
-
-       return 0;
+       return PTR_ERR_OR_ZERO(ts);
 }
 
 static int cyttsp4_spi_remove(struct spi_device *spi)
index ef5fcb0945e910b11918b26159a2860cec2cba2a..054d22583248386a5d392c0df90fed81d950e083 100644 (file)
@@ -273,7 +273,7 @@ static struct i2c_driver egalax_ts_driver = {
                .name   = "egalax_ts",
                .owner  = THIS_MODULE,
                .pm     = &egalax_ts_pm_ops,
-               .of_match_table = of_match_ptr(egalax_ts_dt_ids),
+               .of_match_table = egalax_ts_dt_ids,
        },
        .id_table       = egalax_ts_id,
        .probe          = egalax_ts_probe,
index 66500852341b66319b634133b3f0930f3dc3f2ec..92e2243fb77d9a3b1b3e13316ea38e0072aed7aa 100644 (file)
@@ -186,8 +186,6 @@ static int htcpen_isa_remove(struct device *dev, unsigned int id)
        release_region(HTCPEN_PORT_INIT, 1);
        release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
 
-       dev_set_drvdata(dev, NULL);
-
        return 0;
 }
 
index 1740a2496371d5988d2d550a4312988bafcf850b..2f03b2f289dd365fe3053338d09d049b7d724244 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/input.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/pm_qos.h>
 #include <linux/slab.h>
index 24e625c0b5314217accaee7886f2d05e2652901d..68beadaabcebb134adc4ad1e9a9a8fdc6ec590d6 100644 (file)
@@ -354,8 +354,15 @@ static int titsc_parse_dt(struct platform_device *pdev,
        if (err < 0)
                return err;
 
-       err = of_property_read_u32(node, "ti,coordiante-readouts",
+       /*
+        * Try with the new binding first. If it fails, try again with
+        * bogus, miss-spelled version.
+        */
+       err = of_property_read_u32(node, "ti,coordinate-readouts",
                        &ts_dev->coordinate_readouts);
+       if (err < 0)
+               err = of_property_read_u32(node, "ti,coordiante-readouts",
+                               &ts_dev->coordinate_readouts);
        if (err < 0)
                return err;
 
@@ -511,7 +518,7 @@ static struct platform_driver ti_tsc_driver = {
                .name   = "TI-am335x-tsc",
                .owner  = THIS_MODULE,
                .pm     = TITSC_PM_OPS,
-               .of_match_table = of_match_ptr(ti_tsc_dt_ids),
+               .of_match_table = ti_tsc_dt_ids,
        },
 };
 module_platform_driver(ti_tsc_driver);
index 7213e8b07e79bfa48d8b0e5d1f89d5684fee711c..811353353917d2b5f0440b8c5a5f5a704cd6c1e9 100644 (file)
@@ -678,7 +678,6 @@ static int tsc2005_probe(struct spi_device *spi)
 err_remove_sysfs:
        sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group);
 err_clear_drvdata:
-       spi_set_drvdata(spi, NULL);
        free_irq(spi->irq, ts);
 err_free_mem:
        input_free_device(input_dev);
@@ -696,7 +695,6 @@ static int tsc2005_remove(struct spi_device *spi)
        input_unregister_device(ts->idev);
        kfree(ts);
 
-       spi_set_drvdata(spi, NULL);
        return 0;
 }
 
index 721fdb3597ca9d9ecb3f971f389f6852395ff39c..ae4b6b9036292c23387fafb1124247fc377c3f72 100644 (file)
@@ -146,12 +146,10 @@ enum {
 
 #define USB_DEVICE_HID_CLASS(vend, prod) \
        .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \
-               | USB_DEVICE_ID_MATCH_INT_PROTOCOL \
                | USB_DEVICE_ID_MATCH_DEVICE, \
        .idVendor = (vend), \
        .idProduct = (prod), \
-       .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
-       .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
+       .bInterfaceClass = USB_INTERFACE_CLASS_HID
 
 static const struct usb_device_id usbtouch_devices[] = {
 #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
diff --git a/drivers/input/touchscreen/zforce_ts.c b/drivers/input/touchscreen/zforce_ts.c
new file mode 100644 (file)
index 0000000..75762d6
--- /dev/null
@@ -0,0 +1,836 @@
+/*
+ * Copyright (C) 2012-2013 MundoReader S.L.
+ * Author: Heiko Stuebner <heiko@sntech.de>
+ *
+ * based in parts on Nook zforce driver
+ *
+ * Copyright (C) 2010 Barnes & Noble, Inc.
+ * Author: Pieter Truter<ptruter@intrinsyc.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/hrtimer.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/input/mt.h>
+#include <linux/platform_data/zforce_ts.h>
+
+#define WAIT_TIMEOUT           msecs_to_jiffies(1000)
+
+#define FRAME_START            0xee
+
+/* Offsets of the different parts of the payload the controller sends */
+#define PAYLOAD_HEADER         0
+#define PAYLOAD_LENGTH         1
+#define PAYLOAD_BODY           2
+
+/* Response offsets */
+#define RESPONSE_ID            0
+#define RESPONSE_DATA          1
+
+/* Commands */
+#define COMMAND_DEACTIVATE     0x00
+#define COMMAND_INITIALIZE     0x01
+#define COMMAND_RESOLUTION     0x02
+#define COMMAND_SETCONFIG      0x03
+#define COMMAND_DATAREQUEST    0x04
+#define COMMAND_SCANFREQ       0x08
+#define COMMAND_STATUS         0X1e
+
+/*
+ * Responses the controller sends as a result of
+ * command requests
+ */
+#define RESPONSE_DEACTIVATE    0x00
+#define RESPONSE_INITIALIZE    0x01
+#define RESPONSE_RESOLUTION    0x02
+#define RESPONSE_SETCONFIG     0x03
+#define RESPONSE_SCANFREQ      0x08
+#define RESPONSE_STATUS                0X1e
+
+/*
+ * Notifications are send by the touch controller without
+ * being requested by the driver and include for example
+ * touch indications
+ */
+#define NOTIFICATION_TOUCH             0x04
+#define NOTIFICATION_BOOTCOMPLETE      0x07
+#define NOTIFICATION_OVERRUN           0x25
+#define NOTIFICATION_PROXIMITY         0x26
+#define NOTIFICATION_INVALID_COMMAND   0xfe
+
+#define ZFORCE_REPORT_POINTS           2
+#define ZFORCE_MAX_AREA                        0xff
+
+#define STATE_DOWN                     0
+#define STATE_MOVE                     1
+#define STATE_UP                       2
+
+#define SETCONFIG_DUALTOUCH            (1 << 0)
+
+struct zforce_point {
+       int coord_x;
+       int coord_y;
+       int state;
+       int id;
+       int area_major;
+       int area_minor;
+       int orientation;
+       int pressure;
+       int prblty;
+};
+
+/*
+ * @client             the i2c_client
+ * @input              the input device
+ * @suspending         in the process of going to suspend (don't emit wakeup
+ *                     events for commands executed to suspend the device)
+ * @suspended          device suspended
+ * @access_mutex       serialize i2c-access, to keep multipart reads together
+ * @command_done       completion to wait for the command result
+ * @command_mutex      serialize commands send to the ic
+ * @command_waiting    the id of the command that that is currently waiting
+ *                     for a result
+ * @command_result     returned result of the command
+ */
+struct zforce_ts {
+       struct i2c_client       *client;
+       struct input_dev        *input;
+       const struct zforce_ts_platdata *pdata;
+       char                    phys[32];
+
+       bool                    suspending;
+       bool                    suspended;
+       bool                    boot_complete;
+
+       /* Firmware version information */
+       u16                     version_major;
+       u16                     version_minor;
+       u16                     version_build;
+       u16                     version_rev;
+
+       struct mutex            access_mutex;
+
+       struct completion       command_done;
+       struct mutex            command_mutex;
+       int                     command_waiting;
+       int                     command_result;
+};
+
+static int zforce_command(struct zforce_ts *ts, u8 cmd)
+{
+       struct i2c_client *client = ts->client;
+       char buf[3];
+       int ret;
+
+       dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd);
+
+       buf[0] = FRAME_START;
+       buf[1] = 1; /* data size, command only */
+       buf[2] = cmd;
+
+       mutex_lock(&ts->access_mutex);
+       ret = i2c_master_send(client, &buf[0], ARRAY_SIZE(buf));
+       mutex_unlock(&ts->access_mutex);
+       if (ret < 0) {
+               dev_err(&client->dev, "i2c send data request error: %d\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len)
+{
+       struct i2c_client *client = ts->client;
+       int ret;
+
+       ret = mutex_trylock(&ts->command_mutex);
+       if (!ret) {
+               dev_err(&client->dev, "already waiting for a command\n");
+               return -EBUSY;
+       }
+
+       dev_dbg(&client->dev, "sending %d bytes for command 0x%x\n",
+               buf[1], buf[2]);
+
+       ts->command_waiting = buf[2];
+
+       mutex_lock(&ts->access_mutex);
+       ret = i2c_master_send(client, buf, len);
+       mutex_unlock(&ts->access_mutex);
+       if (ret < 0) {
+               dev_err(&client->dev, "i2c send data request error: %d\n", ret);
+               goto unlock;
+       }
+
+       dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]);
+
+       if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) {
+               ret = -ETIME;
+               goto unlock;
+       }
+
+       ret = ts->command_result;
+
+unlock:
+       mutex_unlock(&ts->command_mutex);
+       return ret;
+}
+
+static int zforce_command_wait(struct zforce_ts *ts, u8 cmd)
+{
+       struct i2c_client *client = ts->client;
+       char buf[3];
+       int ret;
+
+       dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd);
+
+       buf[0] = FRAME_START;
+       buf[1] = 1; /* data size, command only */
+       buf[2] = cmd;
+
+       ret = zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
+       if (ret < 0) {
+               dev_err(&client->dev, "i2c send data request error: %d\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int zforce_resolution(struct zforce_ts *ts, u16 x, u16 y)
+{
+       struct i2c_client *client = ts->client;
+       char buf[7] = { FRAME_START, 5, COMMAND_RESOLUTION,
+                       (x & 0xff), ((x >> 8) & 0xff),
+                       (y & 0xff), ((y >> 8) & 0xff) };
+
+       dev_dbg(&client->dev, "set resolution to (%d,%d)\n", x, y);
+
+       return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
+}
+
+static int zforce_scan_frequency(struct zforce_ts *ts, u16 idle, u16 finger,
+                                u16 stylus)
+{
+       struct i2c_client *client = ts->client;
+       char buf[9] = { FRAME_START, 7, COMMAND_SCANFREQ,
+                       (idle & 0xff), ((idle >> 8) & 0xff),
+                       (finger & 0xff), ((finger >> 8) & 0xff),
+                       (stylus & 0xff), ((stylus >> 8) & 0xff) };
+
+       dev_dbg(&client->dev, "set scan frequency to (idle: %d, finger: %d, stylus: %d)\n",
+               idle, finger, stylus);
+
+       return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
+}
+
+static int zforce_setconfig(struct zforce_ts *ts, char b1)
+{
+       struct i2c_client *client = ts->client;
+       char buf[7] = { FRAME_START, 5, COMMAND_SETCONFIG,
+                       b1, 0, 0, 0 };
+
+       dev_dbg(&client->dev, "set config to (%d)\n", b1);
+
+       return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
+}
+
+static int zforce_start(struct zforce_ts *ts)
+{
+       struct i2c_client *client = ts->client;
+       const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev);
+       int ret;
+
+       dev_dbg(&client->dev, "starting device\n");
+
+       ret = zforce_command_wait(ts, COMMAND_INITIALIZE);
+       if (ret) {
+               dev_err(&client->dev, "Unable to initialize, %d\n", ret);
+               return ret;
+       }
+
+       ret = zforce_resolution(ts, pdata->x_max, pdata->y_max);
+       if (ret) {
+               dev_err(&client->dev, "Unable to set resolution, %d\n", ret);
+               goto error;
+       }
+
+       ret = zforce_scan_frequency(ts, 10, 50, 50);
+       if (ret) {
+               dev_err(&client->dev, "Unable to set scan frequency, %d\n",
+                       ret);
+               goto error;
+       }
+
+       if (zforce_setconfig(ts, SETCONFIG_DUALTOUCH)) {
+               dev_err(&client->dev, "Unable to set config\n");
+               goto error;
+       }
+
+       /* start sending touch events */
+       ret = zforce_command(ts, COMMAND_DATAREQUEST);
+       if (ret) {
+               dev_err(&client->dev, "Unable to request data\n");
+               goto error;
+       }
+
+       /*
+        * Per NN, initial cal. take max. of 200msec.
+        * Allow time to complete this calibration
+        */
+       msleep(200);
+
+       return 0;
+
+error:
+       zforce_command_wait(ts, COMMAND_DEACTIVATE);
+       return ret;
+}
+
+static int zforce_stop(struct zforce_ts *ts)
+{
+       struct i2c_client *client = ts->client;
+       int ret;
+
+       dev_dbg(&client->dev, "stopping device\n");
+
+       /* Deactivates touch sensing and puts the device into sleep. */
+       ret = zforce_command_wait(ts, COMMAND_DEACTIVATE);
+       if (ret != 0) {
+               dev_err(&client->dev, "could not deactivate device, %d\n",
+                       ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int zforce_touch_event(struct zforce_ts *ts, u8 *payload)
+{
+       struct i2c_client *client = ts->client;
+       const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev);
+       struct zforce_point point;
+       int count, i, num = 0;
+
+       count = payload[0];
+       if (count > ZFORCE_REPORT_POINTS) {
+               dev_warn(&client->dev, "to many coordinates %d, expected max %d\n",
+                        count, ZFORCE_REPORT_POINTS);
+               count = ZFORCE_REPORT_POINTS;
+       }
+
+       for (i = 0; i < count; i++) {
+               point.coord_x =
+                       payload[9 * i + 2] << 8 | payload[9 * i + 1];
+               point.coord_y =
+                       payload[9 * i + 4] << 8 | payload[9 * i + 3];
+
+               if (point.coord_x > pdata->x_max ||
+                   point.coord_y > pdata->y_max) {
+                       dev_warn(&client->dev, "coordinates (%d,%d) invalid\n",
+                               point.coord_x, point.coord_y);
+                       point.coord_x = point.coord_y = 0;
+               }
+
+               point.state = payload[9 * i + 5] & 0x03;
+               point.id = (payload[9 * i + 5] & 0xfc) >> 2;
+
+               /* determine touch major, minor and orientation */
+               point.area_major = max(payload[9 * i + 6],
+                                         payload[9 * i + 7]);
+               point.area_minor = min(payload[9 * i + 6],
+                                         payload[9 * i + 7]);
+               point.orientation = payload[9 * i + 6] > payload[9 * i + 7];
+
+               point.pressure = payload[9 * i + 8];
+               point.prblty = payload[9 * i + 9];
+
+               dev_dbg(&client->dev,
+                       "point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n",
+                       i, count, point.state, point.id,
+                       point.pressure, point.prblty,
+                       point.coord_x, point.coord_y,
+                       point.area_major, point.area_minor,
+                       point.orientation);
+
+               /* the zforce id starts with "1", so needs to be decreased */
+               input_mt_slot(ts->input, point.id - 1);
+
+               input_mt_report_slot_state(ts->input, MT_TOOL_FINGER,
+                                               point.state != STATE_UP);
+
+               if (point.state != STATE_UP) {
+                       input_report_abs(ts->input, ABS_MT_POSITION_X,
+                                        point.coord_x);
+                       input_report_abs(ts->input, ABS_MT_POSITION_Y,
+                                        point.coord_y);
+                       input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
+                                        point.area_major);
+                       input_report_abs(ts->input, ABS_MT_TOUCH_MINOR,
+                                        point.area_minor);
+                       input_report_abs(ts->input, ABS_MT_ORIENTATION,
+                                        point.orientation);
+                       num++;
+               }
+       }
+
+       input_mt_sync_frame(ts->input);
+
+       input_mt_report_finger_count(ts->input, num);
+
+       input_sync(ts->input);
+
+       return 0;
+}
+
+static int zforce_read_packet(struct zforce_ts *ts, u8 *buf)
+{
+       struct i2c_client *client = ts->client;
+       int ret;
+
+       mutex_lock(&ts->access_mutex);
+
+       /* read 2 byte message header */
+       ret = i2c_master_recv(client, buf, 2);
+       if (ret < 0) {
+               dev_err(&client->dev, "error reading header: %d\n", ret);
+               goto unlock;
+       }
+
+       if (buf[PAYLOAD_HEADER] != FRAME_START) {
+               dev_err(&client->dev, "invalid frame start: %d\n", buf[0]);
+               ret = -EIO;
+               goto unlock;
+       }
+
+       if (buf[PAYLOAD_LENGTH] <= 0 || buf[PAYLOAD_LENGTH] > 255) {
+               dev_err(&client->dev, "invalid payload length: %d\n",
+                       buf[PAYLOAD_LENGTH]);
+               ret = -EIO;
+               goto unlock;
+       }
+
+       /* read the message */
+       ret = i2c_master_recv(client, &buf[PAYLOAD_BODY], buf[PAYLOAD_LENGTH]);
+       if (ret < 0) {
+               dev_err(&client->dev, "error reading payload: %d\n", ret);
+               goto unlock;
+       }
+
+       dev_dbg(&client->dev, "read %d bytes for response command 0x%x\n",
+               buf[PAYLOAD_LENGTH], buf[PAYLOAD_BODY]);
+
+unlock:
+       mutex_unlock(&ts->access_mutex);
+       return ret;
+}
+
+static void zforce_complete(struct zforce_ts *ts, int cmd, int result)
+{
+       struct i2c_client *client = ts->client;
+
+       if (ts->command_waiting == cmd) {
+               dev_dbg(&client->dev, "completing command 0x%x\n", cmd);
+               ts->command_result = result;
+               complete(&ts->command_done);
+       } else {
+               dev_dbg(&client->dev, "command %d not for us\n", cmd);
+       }
+}
+
+static irqreturn_t zforce_interrupt(int irq, void *dev_id)
+{
+       struct zforce_ts *ts = dev_id;
+       struct i2c_client *client = ts->client;
+       const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev);
+       int ret;
+       u8 payload_buffer[512];
+       u8 *payload;
+
+       /*
+        * When suspended, emit a wakeup signal if necessary and return.
+        * Due to the level-interrupt we will get re-triggered later.
+        */
+       if (ts->suspended) {
+               if (device_may_wakeup(&client->dev))
+                       pm_wakeup_event(&client->dev, 500);
+               msleep(20);
+               return IRQ_HANDLED;
+       }
+
+       dev_dbg(&client->dev, "handling interrupt\n");
+
+       /* Don't emit wakeup events from commands run by zforce_suspend */
+       if (!ts->suspending && device_may_wakeup(&client->dev))
+               pm_stay_awake(&client->dev);
+
+       while (!gpio_get_value(pdata->gpio_int)) {
+               ret = zforce_read_packet(ts, payload_buffer);
+               if (ret < 0) {
+                       dev_err(&client->dev, "could not read packet, ret: %d\n",
+                               ret);
+                       break;
+               }
+
+               payload =  &payload_buffer[PAYLOAD_BODY];
+
+               switch (payload[RESPONSE_ID]) {
+               case NOTIFICATION_TOUCH:
+                       /*
+                        * Always report touch-events received while
+                        * suspending, when being a wakeup source
+                        */
+                       if (ts->suspending && device_may_wakeup(&client->dev))
+                               pm_wakeup_event(&client->dev, 500);
+                       zforce_touch_event(ts, &payload[RESPONSE_DATA]);
+                       break;
+
+               case NOTIFICATION_BOOTCOMPLETE:
+                       ts->boot_complete = payload[RESPONSE_DATA];
+                       zforce_complete(ts, payload[RESPONSE_ID], 0);
+                       break;
+
+               case RESPONSE_INITIALIZE:
+               case RESPONSE_DEACTIVATE:
+               case RESPONSE_SETCONFIG:
+               case RESPONSE_RESOLUTION:
+               case RESPONSE_SCANFREQ:
+                       zforce_complete(ts, payload[RESPONSE_ID],
+                                       payload[RESPONSE_DATA]);
+                       break;
+
+               case RESPONSE_STATUS:
+                       /*
+                        * Version Payload Results
+                        * [2:major] [2:minor] [2:build] [2:rev]
+                        */
+                       ts->version_major = (payload[RESPONSE_DATA + 1] << 8) |
+                                               payload[RESPONSE_DATA];
+                       ts->version_minor = (payload[RESPONSE_DATA + 3] << 8) |
+                                               payload[RESPONSE_DATA + 2];
+                       ts->version_build = (payload[RESPONSE_DATA + 5] << 8) |
+                                               payload[RESPONSE_DATA + 4];
+                       ts->version_rev   = (payload[RESPONSE_DATA + 7] << 8) |
+                                               payload[RESPONSE_DATA + 6];
+                       dev_dbg(&ts->client->dev, "Firmware Version %04x:%04x %04x:%04x\n",
+                               ts->version_major, ts->version_minor,
+                               ts->version_build, ts->version_rev);
+
+                       zforce_complete(ts, payload[RESPONSE_ID], 0);
+                       break;
+
+               case NOTIFICATION_INVALID_COMMAND:
+                       dev_err(&ts->client->dev, "invalid command: 0x%x\n",
+                               payload[RESPONSE_DATA]);
+                       break;
+
+               default:
+                       dev_err(&ts->client->dev, "unrecognized response id: 0x%x\n",
+                               payload[RESPONSE_ID]);
+                       break;
+               }
+       }
+
+       if (!ts->suspending && device_may_wakeup(&client->dev))
+               pm_relax(&client->dev);
+
+       dev_dbg(&client->dev, "finished interrupt\n");
+
+       return IRQ_HANDLED;
+}
+
+static int zforce_input_open(struct input_dev *dev)
+{
+       struct zforce_ts *ts = input_get_drvdata(dev);
+       int ret;
+
+       ret = zforce_start(ts);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static void zforce_input_close(struct input_dev *dev)
+{
+       struct zforce_ts *ts = input_get_drvdata(dev);
+       struct i2c_client *client = ts->client;
+       int ret;
+
+       ret = zforce_stop(ts);
+       if (ret)
+               dev_warn(&client->dev, "stopping zforce failed\n");
+
+       return;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int zforce_suspend(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct zforce_ts *ts = i2c_get_clientdata(client);
+       struct input_dev *input = ts->input;
+       int ret = 0;
+
+       mutex_lock(&input->mutex);
+       ts->suspending = true;
+
+       /*
+        * When configured as a wakeup source device should always wake
+        * the system, therefore start device if necessary.
+        */
+       if (device_may_wakeup(&client->dev)) {
+               dev_dbg(&client->dev, "suspend while being a wakeup source\n");
+
+               /* Need to start device, if not open, to be a wakeup source. */
+               if (!input->users) {
+                       ret = zforce_start(ts);
+                       if (ret)
+                               goto unlock;
+               }
+
+               enable_irq_wake(client->irq);
+       } else if (input->users) {
+               dev_dbg(&client->dev, "suspend without being a wakeup source\n");
+
+               ret = zforce_stop(ts);
+               if (ret)
+                       goto unlock;
+
+               disable_irq(client->irq);
+       }
+
+       ts->suspended = true;
+
+unlock:
+       ts->suspending = false;
+       mutex_unlock(&input->mutex);
+
+       return ret;
+}
+
+static int zforce_resume(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct zforce_ts *ts = i2c_get_clientdata(client);
+       struct input_dev *input = ts->input;
+       int ret = 0;
+
+       mutex_lock(&input->mutex);
+
+       ts->suspended = false;
+
+       if (device_may_wakeup(&client->dev)) {
+               dev_dbg(&client->dev, "resume from being a wakeup source\n");
+
+               disable_irq_wake(client->irq);
+
+               /* need to stop device if it was not open on suspend */
+               if (!input->users) {
+                       ret = zforce_stop(ts);
+                       if (ret)
+                               goto unlock;
+               }
+       } else if (input->users) {
+               dev_dbg(&client->dev, "resume without being a wakeup source\n");
+
+               enable_irq(client->irq);
+
+               ret = zforce_start(ts);
+               if (ret < 0)
+                       goto unlock;
+       }
+
+unlock:
+       mutex_unlock(&input->mutex);
+
+       return ret;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume);
+
+static void zforce_reset(void *data)
+{
+       struct zforce_ts *ts = data;
+
+       gpio_set_value(ts->pdata->gpio_rst, 0);
+}
+
+static int zforce_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev);
+       struct zforce_ts *ts;
+       struct input_dev *input_dev;
+       int ret;
+
+       if (!pdata)
+               return -EINVAL;
+
+       ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL);
+       if (!ts)
+               return -ENOMEM;
+
+       ret = devm_gpio_request_one(&client->dev, pdata->gpio_int, GPIOF_IN,
+                                   "zforce_ts_int");
+       if (ret) {
+               dev_err(&client->dev, "request of gpio %d failed, %d\n",
+                       pdata->gpio_int, ret);
+               return ret;
+       }
+
+       ret = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
+                                   GPIOF_OUT_INIT_LOW, "zforce_ts_rst");
+       if (ret) {
+               dev_err(&client->dev, "request of gpio %d failed, %d\n",
+                       pdata->gpio_rst, ret);
+               return ret;
+       }
+
+       ret = devm_add_action(&client->dev, zforce_reset, ts);
+       if (ret) {
+               dev_err(&client->dev, "failed to register reset action, %d\n",
+                       ret);
+               return ret;
+       }
+
+       snprintf(ts->phys, sizeof(ts->phys),
+                "%s/input0", dev_name(&client->dev));
+
+       input_dev = devm_input_allocate_device(&client->dev);
+       if (!input_dev) {
+               dev_err(&client->dev, "could not allocate input device\n");
+               return -ENOMEM;
+       }
+
+       mutex_init(&ts->access_mutex);
+       mutex_init(&ts->command_mutex);
+
+       ts->pdata = pdata;
+       ts->client = client;
+       ts->input = input_dev;
+
+       input_dev->name = "Neonode zForce touchscreen";
+       input_dev->phys = ts->phys;
+       input_dev->id.bustype = BUS_I2C;
+
+       input_dev->open = zforce_input_open;
+       input_dev->close = zforce_input_close;
+
+       __set_bit(EV_KEY, input_dev->evbit);
+       __set_bit(EV_SYN, input_dev->evbit);
+       __set_bit(EV_ABS, input_dev->evbit);
+
+       /* For multi touch */
+       input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
+                            pdata->x_max, 0, 0);
+       input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
+                            pdata->y_max, 0, 0);
+
+       input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
+                            ZFORCE_MAX_AREA, 0, 0);
+       input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
+                            ZFORCE_MAX_AREA, 0, 0);
+       input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
+       input_mt_init_slots(input_dev, ZFORCE_REPORT_POINTS, INPUT_MT_DIRECT);
+
+       input_set_drvdata(ts->input, ts);
+
+       init_completion(&ts->command_done);
+
+       /*
+        * The zforce pulls the interrupt low when it has data ready.
+        * After it is triggered the isr thread runs until all the available
+        * packets have been read and the interrupt is high again.
+        * Therefore we can trigger the interrupt anytime it is low and do
+        * not need to limit it to the interrupt edge.
+        */
+       ret = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+                                       zforce_interrupt,
+                                       IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+                                       input_dev->name, ts);
+       if (ret) {
+               dev_err(&client->dev, "irq %d request failed\n", client->irq);
+               return ret;
+       }
+
+       i2c_set_clientdata(client, ts);
+
+       /* let the controller boot */
+       gpio_set_value(pdata->gpio_rst, 1);
+
+       ts->command_waiting = NOTIFICATION_BOOTCOMPLETE;
+       if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0)
+               dev_warn(&client->dev, "bootcomplete timed out\n");
+
+       /* need to start device to get version information */
+       ret = zforce_command_wait(ts, COMMAND_INITIALIZE);
+       if (ret) {
+               dev_err(&client->dev, "unable to initialize, %d\n", ret);
+               return ret;
+       }
+
+       /* this gets the firmware version among other informations */
+       ret = zforce_command_wait(ts, COMMAND_STATUS);
+       if (ret < 0) {
+               dev_err(&client->dev, "couldn't get status, %d\n", ret);
+               zforce_stop(ts);
+               return ret;
+       }
+
+       /* stop device and put it into sleep until it is opened */
+       ret = zforce_stop(ts);
+       if (ret < 0)
+               return ret;
+
+       device_set_wakeup_capable(&client->dev, true);
+
+       ret = input_register_device(input_dev);
+       if (ret) {
+               dev_err(&client->dev, "could not register input device, %d\n",
+                       ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static struct i2c_device_id zforce_idtable[] = {
+       { "zforce-ts", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, zforce_idtable);
+
+static struct i2c_driver zforce_driver = {
+       .driver = {
+               .owner  = THIS_MODULE,
+               .name   = "zforce-ts",
+               .pm     = &zforce_pm_ops,
+       },
+       .probe          = zforce_probe,
+       .id_table       = zforce_idtable,
+};
+
+module_i2c_driver(zforce_driver);
+
+MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
+MODULE_DESCRIPTION("zForce TouchScreen Driver");
+MODULE_LICENSE("GPL");
index 9fd51e51e78be807fa6a0157dfb20591d30fb94d..3e7fdbb4916b1c810314acb77fe9f3b0a2c7cdf1 100644 (file)
@@ -206,7 +206,7 @@ config SHMOBILE_IPMMU_TLB
 config SHMOBILE_IOMMU
        bool "IOMMU for Renesas IPMMU/IPMMUI"
        default n
-       depends on ARM || COMPILE_TEST
+       depends on ARM
        select IOMMU_API
        select ARM_DMA_USE_IOMMU
        select SHMOBILE_IPMMU
index baf2686aa8eb0cb027044e815dafa8b2aa6afae4..02125e6a91093e22bda1849bad209f6d3ebe8962 100644 (file)
@@ -1083,8 +1083,10 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
                        spin_unlock_irqrestore(&card->isdnloop_lock, flags);
                        return -ENOMEM;
                }
-               for (i = 0; i < 3; i++)
-                       strcpy(card->s0num[i], sdef.num[i]);
+               for (i = 0; i < 3; i++) {
+                       strlcpy(card->s0num[i], sdef.num[i],
+                               sizeof(card->s0num[0]));
+               }
                break;
        case ISDN_PTYPE_1TR6:
                if (isdnloop_fake(card, "DRV1.04TC-1TR6-CAPI-CNS-BASIS-29.11.95",
@@ -1097,7 +1099,7 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
                        spin_unlock_irqrestore(&card->isdnloop_lock, flags);
                        return -ENOMEM;
                }
-               strcpy(card->s0num[0], sdef.num[0]);
+               strlcpy(card->s0num[0], sdef.num[0], sizeof(card->s0num[0]));
                card->s0num[1][0] = '\0';
                card->s0num[2][0] = '\0';
                break;
index f950c9d29f3e5400a97b7eb43400d6e2a79b9e19..2638417b19aa74d1207de209b93bbb1dfc2689e8 100644 (file)
@@ -13,15 +13,8 @@ config BCACHE_DEBUG
        ---help---
        Don't select this option unless you're a developer
 
-       Enables extra debugging tools (primarily a fuzz tester)
-
-config BCACHE_EDEBUG
-       bool "Extended runtime checks"
-       depends on BCACHE
-       ---help---
-       Don't select this option unless you're a developer
-
-       Enables extra runtime checks which significantly affect performance
+       Enables extra debugging tools, allows expensive runtime checks to be
+       turned on.
 
 config BCACHE_CLOSURES_DEBUG
        bool "Debug closures"
index e45f5575fd4dde8d2768daaa553ab57b9d0023b1..2b46bf1d7e40ca7375517ebb97a2225475844a91 100644 (file)
 #include "bcache.h"
 #include "btree.h"
 
+#include <linux/blkdev.h>
 #include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/random.h>
 #include <trace/events/bcache.h>
 
-#define MAX_IN_FLIGHT_DISCARDS         8U
-
 /* Bucket heap / gen */
 
 uint8_t bch_inc_gen(struct cache *ca, struct bucket *b)
@@ -121,75 +120,6 @@ void bch_rescale_priorities(struct cache_set *c, int sectors)
        mutex_unlock(&c->bucket_lock);
 }
 
-/* Discard/TRIM */
-
-struct discard {
-       struct list_head        list;
-       struct work_struct      work;
-       struct cache            *ca;
-       long                    bucket;
-
-       struct bio              bio;
-       struct bio_vec          bv;
-};
-
-static void discard_finish(struct work_struct *w)
-{
-       struct discard *d = container_of(w, struct discard, work);
-       struct cache *ca = d->ca;
-       char buf[BDEVNAME_SIZE];
-
-       if (!test_bit(BIO_UPTODATE, &d->bio.bi_flags)) {
-               pr_notice("discard error on %s, disabling",
-                        bdevname(ca->bdev, buf));
-               d->ca->discard = 0;
-       }
-
-       mutex_lock(&ca->set->bucket_lock);
-
-       fifo_push(&ca->free, d->bucket);
-       list_add(&d->list, &ca->discards);
-       atomic_dec(&ca->discards_in_flight);
-
-       mutex_unlock(&ca->set->bucket_lock);
-
-       closure_wake_up(&ca->set->bucket_wait);
-       wake_up_process(ca->alloc_thread);
-
-       closure_put(&ca->set->cl);
-}
-
-static void discard_endio(struct bio *bio, int error)
-{
-       struct discard *d = container_of(bio, struct discard, bio);
-       schedule_work(&d->work);
-}
-
-static void do_discard(struct cache *ca, long bucket)
-{
-       struct discard *d = list_first_entry(&ca->discards,
-                                            struct discard, list);
-
-       list_del(&d->list);
-       d->bucket = bucket;
-
-       atomic_inc(&ca->discards_in_flight);
-       closure_get(&ca->set->cl);
-
-       bio_init(&d->bio);
-
-       d->bio.bi_sector        = bucket_to_sector(ca->set, d->bucket);
-       d->bio.bi_bdev          = ca->bdev;
-       d->bio.bi_rw            = REQ_WRITE|REQ_DISCARD;
-       d->bio.bi_max_vecs      = 1;
-       d->bio.bi_io_vec        = d->bio.bi_inline_vecs;
-       d->bio.bi_size          = bucket_bytes(ca);
-       d->bio.bi_end_io        = discard_endio;
-       bio_set_prio(&d->bio, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
-
-       submit_bio(0, &d->bio);
-}
-
 /* Allocation */
 
 static inline bool can_inc_bucket_gen(struct bucket *b)
@@ -280,7 +210,7 @@ static void invalidate_buckets_lru(struct cache *ca)
                         * multiple times when it can't do anything
                         */
                        ca->invalidate_needs_gc = 1;
-                       bch_queue_gc(ca->set);
+                       wake_up_gc(ca->set);
                        return;
                }
 
@@ -305,7 +235,7 @@ static void invalidate_buckets_fifo(struct cache *ca)
 
                if (++checked >= ca->sb.nbuckets) {
                        ca->invalidate_needs_gc = 1;
-                       bch_queue_gc(ca->set);
+                       wake_up_gc(ca->set);
                        return;
                }
        }
@@ -330,7 +260,7 @@ static void invalidate_buckets_random(struct cache *ca)
 
                if (++checked >= ca->sb.nbuckets / 2) {
                        ca->invalidate_needs_gc = 1;
-                       bch_queue_gc(ca->set);
+                       wake_up_gc(ca->set);
                        return;
                }
        }
@@ -398,16 +328,18 @@ static int bch_allocator_thread(void *arg)
                        else
                                break;
 
-                       allocator_wait(ca, (int) fifo_free(&ca->free) >
-                                      atomic_read(&ca->discards_in_flight));
-
                        if (ca->discard) {
-                               allocator_wait(ca, !list_empty(&ca->discards));
-                               do_discard(ca, bucket);
-                       } else {
-                               fifo_push(&ca->free, bucket);
-                               closure_wake_up(&ca->set->bucket_wait);
+                               mutex_unlock(&ca->set->bucket_lock);
+                               blkdev_issue_discard(ca->bdev,
+                                       bucket_to_sector(ca->set, bucket),
+                                       ca->sb.block_size, GFP_KERNEL, 0);
+                               mutex_lock(&ca->set->bucket_lock);
                        }
+
+                       allocator_wait(ca, !fifo_full(&ca->free));
+
+                       fifo_push(&ca->free, bucket);
+                       wake_up(&ca->set->bucket_wait);
                }
 
                /*
@@ -433,16 +365,40 @@ static int bch_allocator_thread(void *arg)
        }
 }
 
-long bch_bucket_alloc(struct cache *ca, unsigned watermark, struct closure *cl)
+long bch_bucket_alloc(struct cache *ca, unsigned watermark, bool wait)
 {
-       long r = -1;
-again:
+       DEFINE_WAIT(w);
+       struct bucket *b;
+       long r;
+
+       /* fastpath */
+       if (fifo_used(&ca->free) > ca->watermark[watermark]) {
+               fifo_pop(&ca->free, r);
+               goto out;
+       }
+
+       if (!wait)
+               return -1;
+
+       while (1) {
+               if (fifo_used(&ca->free) > ca->watermark[watermark]) {
+                       fifo_pop(&ca->free, r);
+                       break;
+               }
+
+               prepare_to_wait(&ca->set->bucket_wait, &w,
+                               TASK_UNINTERRUPTIBLE);
+
+               mutex_unlock(&ca->set->bucket_lock);
+               schedule();
+               mutex_lock(&ca->set->bucket_lock);
+       }
+
+       finish_wait(&ca->set->bucket_wait, &w);
+out:
        wake_up_process(ca->alloc_thread);
 
-       if (fifo_used(&ca->free) > ca->watermark[watermark] &&
-           fifo_pop(&ca->free, r)) {
-               struct bucket *b = ca->buckets + r;
-#ifdef CONFIG_BCACHE_EDEBUG
+       if (expensive_debug_checks(ca->set)) {
                size_t iter;
                long i;
 
@@ -455,36 +411,23 @@ again:
                        BUG_ON(i == r);
                fifo_for_each(i, &ca->unused, iter)
                        BUG_ON(i == r);
-#endif
-               BUG_ON(atomic_read(&b->pin) != 1);
-
-               SET_GC_SECTORS_USED(b, ca->sb.bucket_size);
-
-               if (watermark <= WATERMARK_METADATA) {
-                       SET_GC_MARK(b, GC_MARK_METADATA);
-                       b->prio = BTREE_PRIO;
-               } else {
-                       SET_GC_MARK(b, GC_MARK_RECLAIMABLE);
-                       b->prio = INITIAL_PRIO;
-               }
-
-               return r;
        }
 
-       trace_bcache_alloc_fail(ca);
+       b = ca->buckets + r;
 
-       if (cl) {
-               closure_wait(&ca->set->bucket_wait, cl);
+       BUG_ON(atomic_read(&b->pin) != 1);
 
-               if (closure_blocking(cl)) {
-                       mutex_unlock(&ca->set->bucket_lock);
-                       closure_sync(cl);
-                       mutex_lock(&ca->set->bucket_lock);
-                       goto again;
-               }
+       SET_GC_SECTORS_USED(b, ca->sb.bucket_size);
+
+       if (watermark <= WATERMARK_METADATA) {
+               SET_GC_MARK(b, GC_MARK_METADATA);
+               b->prio = BTREE_PRIO;
+       } else {
+               SET_GC_MARK(b, GC_MARK_RECLAIMABLE);
+               b->prio = INITIAL_PRIO;
        }
 
-       return -1;
+       return r;
 }
 
 void bch_bucket_free(struct cache_set *c, struct bkey *k)
@@ -501,7 +444,7 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k)
 }
 
 int __bch_bucket_alloc_set(struct cache_set *c, unsigned watermark,
-                          struct bkey *k, int n, struct closure *cl)
+                          struct bkey *k, int n, bool wait)
 {
        int i;
 
@@ -514,7 +457,7 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned watermark,
 
        for (i = 0; i < n; i++) {
                struct cache *ca = c->cache_by_alloc[i];
-               long b = bch_bucket_alloc(ca, watermark, cl);
+               long b = bch_bucket_alloc(ca, watermark, wait);
 
                if (b == -1)
                        goto err;
@@ -529,22 +472,202 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned watermark,
        return 0;
 err:
        bch_bucket_free(c, k);
-       __bkey_put(c, k);
+       bkey_put(c, k);
        return -1;
 }
 
 int bch_bucket_alloc_set(struct cache_set *c, unsigned watermark,
-                        struct bkey *k, int n, struct closure *cl)
+                        struct bkey *k, int n, bool wait)
 {
        int ret;
        mutex_lock(&c->bucket_lock);
-       ret = __bch_bucket_alloc_set(c, watermark, k, n, cl);
+       ret = __bch_bucket_alloc_set(c, watermark, k, n, wait);
        mutex_unlock(&c->bucket_lock);
        return ret;
 }
 
+/* Sector allocator */
+
+struct open_bucket {
+       struct list_head        list;
+       unsigned                last_write_point;
+       unsigned                sectors_free;
+       BKEY_PADDED(key);
+};
+
+/*
+ * We keep multiple buckets open for writes, and try to segregate different
+ * write streams for better cache utilization: first we look for a bucket where
+ * the last write to it was sequential with the current write, and failing that
+ * we look for a bucket that was last used by the same task.
+ *
+ * The ideas is if you've got multiple tasks pulling data into the cache at the
+ * same time, you'll get better cache utilization if you try to segregate their
+ * data and preserve locality.
+ *
+ * For example, say you've starting Firefox at the same time you're copying a
+ * bunch of files. Firefox will likely end up being fairly hot and stay in the
+ * cache awhile, but the data you copied might not be; if you wrote all that
+ * data to the same buckets it'd get invalidated at the same time.
+ *
+ * Both of those tasks will be doing fairly random IO so we can't rely on
+ * detecting sequential IO to segregate their data, but going off of the task
+ * should be a sane heuristic.
+ */
+static struct open_bucket *pick_data_bucket(struct cache_set *c,
+                                           const struct bkey *search,
+                                           unsigned write_point,
+                                           struct bkey *alloc)
+{
+       struct open_bucket *ret, *ret_task = NULL;
+
+       list_for_each_entry_reverse(ret, &c->data_buckets, list)
+               if (!bkey_cmp(&ret->key, search))
+                       goto found;
+               else if (ret->last_write_point == write_point)
+                       ret_task = ret;
+
+       ret = ret_task ?: list_first_entry(&c->data_buckets,
+                                          struct open_bucket, list);
+found:
+       if (!ret->sectors_free && KEY_PTRS(alloc)) {
+               ret->sectors_free = c->sb.bucket_size;
+               bkey_copy(&ret->key, alloc);
+               bkey_init(alloc);
+       }
+
+       if (!ret->sectors_free)
+               ret = NULL;
+
+       return ret;
+}
+
+/*
+ * Allocates some space in the cache to write to, and k to point to the newly
+ * allocated space, and updates KEY_SIZE(k) and KEY_OFFSET(k) (to point to the
+ * end of the newly allocated space).
+ *
+ * May allocate fewer sectors than @sectors, KEY_SIZE(k) indicates how many
+ * sectors were actually allocated.
+ *
+ * If s->writeback is true, will not fail.
+ */
+bool bch_alloc_sectors(struct cache_set *c, struct bkey *k, unsigned sectors,
+                      unsigned write_point, unsigned write_prio, bool wait)
+{
+       struct open_bucket *b;
+       BKEY_PADDED(key) alloc;
+       unsigned i;
+
+       /*
+        * We might have to allocate a new bucket, which we can't do with a
+        * spinlock held. So if we have to allocate, we drop the lock, allocate
+        * and then retry. KEY_PTRS() indicates whether alloc points to
+        * allocated bucket(s).
+        */
+
+       bkey_init(&alloc.key);
+       spin_lock(&c->data_bucket_lock);
+
+       while (!(b = pick_data_bucket(c, k, write_point, &alloc.key))) {
+               unsigned watermark = write_prio
+                       ? WATERMARK_MOVINGGC
+                       : WATERMARK_NONE;
+
+               spin_unlock(&c->data_bucket_lock);
+
+               if (bch_bucket_alloc_set(c, watermark, &alloc.key, 1, wait))
+                       return false;
+
+               spin_lock(&c->data_bucket_lock);
+       }
+
+       /*
+        * If we had to allocate, we might race and not need to allocate the
+        * second time we call find_data_bucket(). If we allocated a bucket but
+        * didn't use it, drop the refcount bch_bucket_alloc_set() took:
+        */
+       if (KEY_PTRS(&alloc.key))
+               bkey_put(c, &alloc.key);
+
+       for (i = 0; i < KEY_PTRS(&b->key); i++)
+               EBUG_ON(ptr_stale(c, &b->key, i));
+
+       /* Set up the pointer to the space we're allocating: */
+
+       for (i = 0; i < KEY_PTRS(&b->key); i++)
+               k->ptr[i] = b->key.ptr[i];
+
+       sectors = min(sectors, b->sectors_free);
+
+       SET_KEY_OFFSET(k, KEY_OFFSET(k) + sectors);
+       SET_KEY_SIZE(k, sectors);
+       SET_KEY_PTRS(k, KEY_PTRS(&b->key));
+
+       /*
+        * Move b to the end of the lru, and keep track of what this bucket was
+        * last used for:
+        */
+       list_move_tail(&b->list, &c->data_buckets);
+       bkey_copy_key(&b->key, k);
+       b->last_write_point = write_point;
+
+       b->sectors_free -= sectors;
+
+       for (i = 0; i < KEY_PTRS(&b->key); i++) {
+               SET_PTR_OFFSET(&b->key, i, PTR_OFFSET(&b->key, i) + sectors);
+
+               atomic_long_add(sectors,
+                               &PTR_CACHE(c, &b->key, i)->sectors_written);
+       }
+
+       if (b->sectors_free < c->sb.block_size)
+               b->sectors_free = 0;
+
+       /*
+        * k takes refcounts on the buckets it points to until it's inserted
+        * into the btree, but if we're done with this bucket we just transfer
+        * get_data_bucket()'s refcount.
+        */
+       if (b->sectors_free)
+               for (i = 0; i < KEY_PTRS(&b->key); i++)
+                       atomic_inc(&PTR_BUCKET(c, &b->key, i)->pin);
+
+       spin_unlock(&c->data_bucket_lock);
+       return true;
+}
+
 /* Init */
 
+void bch_open_buckets_free(struct cache_set *c)
+{
+       struct open_bucket *b;
+
+       while (!list_empty(&c->data_buckets)) {
+               b = list_first_entry(&c->data_buckets,
+                                    struct open_bucket, list);
+               list_del(&b->list);
+               kfree(b);
+       }
+}
+
+int bch_open_buckets_alloc(struct cache_set *c)
+{
+       int i;
+
+       spin_lock_init(&c->data_bucket_lock);
+
+       for (i = 0; i < 6; i++) {
+               struct open_bucket *b = kzalloc(sizeof(*b), GFP_KERNEL);
+               if (!b)
+                       return -ENOMEM;
+
+               list_add(&b->list, &c->data_buckets);
+       }
+
+       return 0;
+}
+
 int bch_cache_allocator_start(struct cache *ca)
 {
        struct task_struct *k = kthread_run(bch_allocator_thread,
@@ -556,22 +679,8 @@ int bch_cache_allocator_start(struct cache *ca)
        return 0;
 }
 
-void bch_cache_allocator_exit(struct cache *ca)
-{
-       struct discard *d;
-
-       while (!list_empty(&ca->discards)) {
-               d = list_first_entry(&ca->discards, struct discard, list);
-               cancel_work_sync(&d->work);
-               list_del(&d->list);
-               kfree(d);
-       }
-}
-
 int bch_cache_allocator_init(struct cache *ca)
 {
-       unsigned i;
-
        /*
         * Reserve:
         * Prio/gen writes first
@@ -589,15 +698,5 @@ int bch_cache_allocator_init(struct cache *ca)
        ca->watermark[WATERMARK_NONE] = ca->free.size / 2 +
                ca->watermark[WATERMARK_MOVINGGC];
 
-       for (i = 0; i < MAX_IN_FLIGHT_DISCARDS; i++) {
-               struct discard *d = kzalloc(sizeof(*d), GFP_KERNEL);
-               if (!d)
-                       return -ENOMEM;
-
-               d->ca = ca;
-               INIT_WORK(&d->work, discard_finish);
-               list_add(&d->list, &ca->discards);
-       }
-
        return 0;
 }
index 0f12382aa35d6c939b53967b205639134e181eae..4beb55a0ff30dc9da10c340270e9cbd1c0e1c0b0 100644 (file)
 
 #define pr_fmt(fmt) "bcache: %s() " fmt "\n", __func__
 
+#include <linux/bcache.h>
 #include <linux/bio.h>
 #include <linux/kobject.h>
 #include <linux/list.h>
@@ -210,168 +211,6 @@ BITMASK(GC_MARK,   struct bucket, gc_mark, 0, 2);
 #define GC_MARK_METADATA       2
 BITMASK(GC_SECTORS_USED, struct bucket, gc_mark, 2, 14);
 
-struct bkey {
-       uint64_t        high;
-       uint64_t        low;
-       uint64_t        ptr[];
-};
-
-/* Enough for a key with 6 pointers */
-#define BKEY_PAD               8
-
-#define BKEY_PADDED(key)                                       \
-       union { struct bkey key; uint64_t key ## _pad[BKEY_PAD]; }
-
-/* Version 0: Cache device
- * Version 1: Backing device
- * Version 2: Seed pointer into btree node checksum
- * Version 3: Cache device with new UUID format
- * Version 4: Backing device with data offset
- */
-#define BCACHE_SB_VERSION_CDEV                 0
-#define BCACHE_SB_VERSION_BDEV                 1
-#define BCACHE_SB_VERSION_CDEV_WITH_UUID       3
-#define BCACHE_SB_VERSION_BDEV_WITH_OFFSET     4
-#define BCACHE_SB_MAX_VERSION                  4
-
-#define SB_SECTOR              8
-#define SB_SIZE                        4096
-#define SB_LABEL_SIZE          32
-#define SB_JOURNAL_BUCKETS     256U
-/* SB_JOURNAL_BUCKETS must be divisible by BITS_PER_LONG */
-#define MAX_CACHES_PER_SET     8
-
-#define BDEV_DATA_START_DEFAULT        16      /* sectors */
-
-struct cache_sb {
-       uint64_t                csum;
-       uint64_t                offset; /* sector where this sb was written */
-       uint64_t                version;
-
-       uint8_t                 magic[16];
-
-       uint8_t                 uuid[16];
-       union {
-               uint8_t         set_uuid[16];
-               uint64_t        set_magic;
-       };
-       uint8_t                 label[SB_LABEL_SIZE];
-
-       uint64_t                flags;
-       uint64_t                seq;
-       uint64_t                pad[8];
-
-       union {
-       struct {
-               /* Cache devices */
-               uint64_t        nbuckets;       /* device size */
-
-               uint16_t        block_size;     /* sectors */
-               uint16_t        bucket_size;    /* sectors */
-
-               uint16_t        nr_in_set;
-               uint16_t        nr_this_dev;
-       };
-       struct {
-               /* Backing devices */
-               uint64_t        data_offset;
-
-               /*
-                * block_size from the cache device section is still used by
-                * backing devices, so don't add anything here until we fix
-                * things to not need it for backing devices anymore
-                */
-       };
-       };
-
-       uint32_t                last_mount;     /* time_t */
-
-       uint16_t                first_bucket;
-       union {
-               uint16_t        njournal_buckets;
-               uint16_t        keys;
-       };
-       uint64_t                d[SB_JOURNAL_BUCKETS];  /* journal buckets */
-};
-
-BITMASK(CACHE_SYNC,            struct cache_sb, flags, 0, 1);
-BITMASK(CACHE_DISCARD,         struct cache_sb, flags, 1, 1);
-BITMASK(CACHE_REPLACEMENT,     struct cache_sb, flags, 2, 3);
-#define CACHE_REPLACEMENT_LRU  0U
-#define CACHE_REPLACEMENT_FIFO 1U
-#define CACHE_REPLACEMENT_RANDOM 2U
-
-BITMASK(BDEV_CACHE_MODE,       struct cache_sb, flags, 0, 4);
-#define CACHE_MODE_WRITETHROUGH        0U
-#define CACHE_MODE_WRITEBACK   1U
-#define CACHE_MODE_WRITEAROUND 2U
-#define CACHE_MODE_NONE                3U
-BITMASK(BDEV_STATE,            struct cache_sb, flags, 61, 2);
-#define BDEV_STATE_NONE                0U
-#define BDEV_STATE_CLEAN       1U
-#define BDEV_STATE_DIRTY       2U
-#define BDEV_STATE_STALE       3U
-
-/* Version 1: Seed pointer into btree node checksum
- */
-#define BCACHE_BSET_VERSION    1
-
-/*
- * This is the on disk format for btree nodes - a btree node on disk is a list
- * of these; within each set the keys are sorted
- */
-struct bset {
-       uint64_t                csum;
-       uint64_t                magic;
-       uint64_t                seq;
-       uint32_t                version;
-       uint32_t                keys;
-
-       union {
-               struct bkey     start[0];
-               uint64_t        d[0];
-       };
-};
-
-/*
- * On disk format for priorities and gens - see super.c near prio_write() for
- * more.
- */
-struct prio_set {
-       uint64_t                csum;
-       uint64_t                magic;
-       uint64_t                seq;
-       uint32_t                version;
-       uint32_t                pad;
-
-       uint64_t                next_bucket;
-
-       struct bucket_disk {
-               uint16_t        prio;
-               uint8_t         gen;
-       } __attribute((packed)) data[];
-};
-
-struct uuid_entry {
-       union {
-               struct {
-                       uint8_t         uuid[16];
-                       uint8_t         label[32];
-                       uint32_t        first_reg;
-                       uint32_t        last_reg;
-                       uint32_t        invalidated;
-
-                       uint32_t        flags;
-                       /* Size of flash only volumes */
-                       uint64_t        sectors;
-               };
-
-               uint8_t pad[128];
-       };
-};
-
-BITMASK(UUID_FLASH_ONLY,       struct uuid_entry, flags, 0, 1);
-
 #include "journal.h"
 #include "stats.h"
 struct search;
@@ -384,8 +223,6 @@ struct keybuf_key {
        void                    *private;
 };
 
-typedef bool (keybuf_pred_fn)(struct keybuf *, struct bkey *);
-
 struct keybuf {
        struct bkey             last_scanned;
        spinlock_t              lock;
@@ -400,7 +237,7 @@ struct keybuf {
 
        struct rb_root          keys;
 
-#define KEYBUF_NR              100
+#define KEYBUF_NR              500
        DECLARE_ARRAY_ALLOCATOR(struct keybuf_key, freelist, KEYBUF_NR);
 };
 
@@ -429,16 +266,15 @@ struct bcache_device {
 
        struct gendisk          *disk;
 
-       /* If nonzero, we're closing */
-       atomic_t                closing;
-
-       /* If nonzero, we're detaching/unregistering from cache set */
-       atomic_t                detaching;
-       int                     flush_done;
+       unsigned long           flags;
+#define BCACHE_DEV_CLOSING     0
+#define BCACHE_DEV_DETACHING   1
+#define BCACHE_DEV_UNLINK_DONE 2
 
-       uint64_t                nr_stripes;
-       unsigned                stripe_size_bits;
+       unsigned                nr_stripes;
+       unsigned                stripe_size;
        atomic_t                *stripe_sectors_dirty;
+       unsigned long           *full_dirty_stripes;
 
        unsigned long           sectors_dirty_last;
        long                    sectors_dirty_derivative;
@@ -509,7 +345,7 @@ struct cached_dev {
 
        /* Limit number of writeback bios in flight */
        struct semaphore        in_flight;
-       struct closure_with_timer writeback;
+       struct task_struct      *writeback_thread;
 
        struct keybuf           writeback_keys;
 
@@ -527,8 +363,8 @@ struct cached_dev {
        unsigned                sequential_cutoff;
        unsigned                readahead;
 
-       unsigned                sequential_merge:1;
        unsigned                verify:1;
+       unsigned                bypass_torture_test:1;
 
        unsigned                partial_stripes_expensive:1;
        unsigned                writeback_metadata:1;
@@ -620,15 +456,6 @@ struct cache {
 
        bool                    discard; /* Get rid of? */
 
-       /*
-        * We preallocate structs for issuing discards to buckets, and keep them
-        * on this list when they're not in use; do_discard() issues discards
-        * whenever there's work to do and is called by free_some_buckets() and
-        * when a discard finishes.
-        */
-       atomic_t                discards_in_flight;
-       struct list_head        discards;
-
        struct journal_device   journal;
 
        /* The rest of this all shows up in sysfs */
@@ -649,7 +476,6 @@ struct gc_stat {
 
        size_t                  nkeys;
        uint64_t                data;   /* sectors */
-       uint64_t                dirty;  /* sectors */
        unsigned                in_use; /* percent */
 };
 
@@ -744,8 +570,8 @@ struct cache_set {
         * basically a lock for this that we can wait on asynchronously. The
         * btree_root() macro releases the lock when it returns.
         */
-       struct closure          *try_harder;
-       struct closure_waitlist try_wait;
+       struct task_struct      *try_harder;
+       wait_queue_head_t       try_wait;
        uint64_t                try_harder_start;
 
        /*
@@ -759,7 +585,7 @@ struct cache_set {
         * written.
         */
        atomic_t                prio_blocked;
-       struct closure_waitlist bucket_wait;
+       wait_queue_head_t       bucket_wait;
 
        /*
         * For any bio we don't skip we subtract the number of sectors from
@@ -782,7 +608,7 @@ struct cache_set {
        struct gc_stat          gc_stats;
        size_t                  nbuckets;
 
-       struct closure_with_waitlist gc;
+       struct task_struct      *gc_thread;
        /* Where in the btree gc currently is */
        struct bkey             gc_done;
 
@@ -795,11 +621,10 @@ struct cache_set {
        /* Counts how many sectors bio_insert has added to the cache */
        atomic_t                sectors_to_gc;
 
-       struct closure          moving_gc;
-       struct closure_waitlist moving_gc_wait;
+       wait_queue_head_t       moving_gc_wait;
        struct keybuf           moving_gc_keys;
        /* Number of moving GC bios in flight */
-       atomic_t                in_flight;
+       struct semaphore        moving_in_flight;
 
        struct btree            *root;
 
@@ -841,22 +666,27 @@ struct cache_set {
        unsigned                congested_read_threshold_us;
        unsigned                congested_write_threshold_us;
 
-       spinlock_t              sort_time_lock;
        struct time_stats       sort_time;
        struct time_stats       btree_gc_time;
        struct time_stats       btree_split_time;
-       spinlock_t              btree_read_time_lock;
        struct time_stats       btree_read_time;
        struct time_stats       try_harder_time;
 
        atomic_long_t           cache_read_races;
        atomic_long_t           writeback_keys_done;
        atomic_long_t           writeback_keys_failed;
+
+       enum                    {
+               ON_ERROR_UNREGISTER,
+               ON_ERROR_PANIC,
+       }                       on_error;
        unsigned                error_limit;
        unsigned                error_decay;
+
        unsigned short          journal_delay_ms;
        unsigned                verify:1;
        unsigned                key_merging_disabled:1;
+       unsigned                expensive_debug_checks:1;
        unsigned                gc_always_rewrite:1;
        unsigned                shrinker_disabled:1;
        unsigned                copy_gc_enabled:1;
@@ -865,21 +695,6 @@ struct cache_set {
        struct hlist_head       bucket_hash[1 << BUCKET_HASH_BITS];
 };
 
-static inline bool key_merging_disabled(struct cache_set *c)
-{
-#ifdef CONFIG_BCACHE_DEBUG
-       return c->key_merging_disabled;
-#else
-       return 0;
-#endif
-}
-
-static inline bool SB_IS_BDEV(const struct cache_sb *sb)
-{
-       return sb->version == BCACHE_SB_VERSION_BDEV
-               || sb->version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
-}
-
 struct bbio {
        unsigned                submit_time_us;
        union {
@@ -933,59 +748,6 @@ static inline unsigned local_clock_us(void)
 #define prio_buckets(c)                                        \
        DIV_ROUND_UP((size_t) (c)->sb.nbuckets, prios_per_bucket(c))
 
-#define JSET_MAGIC             0x245235c1a3625032ULL
-#define PSET_MAGIC             0x6750e15f87337f91ULL
-#define BSET_MAGIC             0x90135c78b99e07f5ULL
-
-#define jset_magic(c)          ((c)->sb.set_magic ^ JSET_MAGIC)
-#define pset_magic(c)          ((c)->sb.set_magic ^ PSET_MAGIC)
-#define bset_magic(c)          ((c)->sb.set_magic ^ BSET_MAGIC)
-
-/* Bkey fields: all units are in sectors */
-
-#define KEY_FIELD(name, field, offset, size)                           \
-       BITMASK(name, struct bkey, field, offset, size)
-
-#define PTR_FIELD(name, offset, size)                                  \
-       static inline uint64_t name(const struct bkey *k, unsigned i)   \
-       { return (k->ptr[i] >> offset) & ~(((uint64_t) ~0) << size); }  \
-                                                                       \
-       static inline void SET_##name(struct bkey *k, unsigned i, uint64_t v)\
-       {                                                               \
-               k->ptr[i] &= ~(~((uint64_t) ~0 << size) << offset);     \
-               k->ptr[i] |= v << offset;                               \
-       }
-
-KEY_FIELD(KEY_PTRS,    high, 60, 3)
-KEY_FIELD(HEADER_SIZE, high, 58, 2)
-KEY_FIELD(KEY_CSUM,    high, 56, 2)
-KEY_FIELD(KEY_PINNED,  high, 55, 1)
-KEY_FIELD(KEY_DIRTY,   high, 36, 1)
-
-KEY_FIELD(KEY_SIZE,    high, 20, 16)
-KEY_FIELD(KEY_INODE,   high, 0,  20)
-
-/* Next time I change the on disk format, KEY_OFFSET() won't be 64 bits */
-
-static inline uint64_t KEY_OFFSET(const struct bkey *k)
-{
-       return k->low;
-}
-
-static inline void SET_KEY_OFFSET(struct bkey *k, uint64_t v)
-{
-       k->low = v;
-}
-
-PTR_FIELD(PTR_DEV,             51, 12)
-PTR_FIELD(PTR_OFFSET,          8,  43)
-PTR_FIELD(PTR_GEN,             0,  8)
-
-#define PTR_CHECK_DEV          ((1 << 12) - 1)
-
-#define PTR(gen, offset, dev)                                          \
-       ((((uint64_t) dev) << 51) | ((uint64_t) offset) << 8 | gen)
-
 static inline size_t sector_to_bucket(struct cache_set *c, sector_t s)
 {
        return s >> c->bucket_bits;
@@ -1024,27 +786,11 @@ static inline struct bucket *PTR_BUCKET(struct cache_set *c,
 
 /* Btree key macros */
 
-/*
- * The high bit being set is a relic from when we used it to do binary
- * searches - it told you where a key started. It's not used anymore,
- * and can probably be safely dropped.
- */
-#define KEY(dev, sector, len)                                          \
-((struct bkey) {                                                       \
-       .high = (1ULL << 63) | ((uint64_t) (len) << 20) | (dev),        \
-       .low = (sector)                                                 \
-})
-
 static inline void bkey_init(struct bkey *k)
 {
-       *k = KEY(0, 0, 0);
+       *k = ZERO_KEY;
 }
 
-#define KEY_START(k)           (KEY_OFFSET(k) - KEY_SIZE(k))
-#define START_KEY(k)           KEY(KEY_INODE(k), KEY_START(k), 0)
-#define MAX_KEY                        KEY(~(~0 << 20), ((uint64_t) ~0) >> 1, 0)
-#define ZERO_KEY               KEY(0, 0, 0)
-
 /*
  * This is used for various on disk data structures - cache_sb, prio_set, bset,
  * jset: The checksum is _always_ the first 8 bytes of these structs
@@ -1094,14 +840,6 @@ do {                                                                      \
        for (b = (ca)->buckets + (ca)->sb.first_bucket;                 \
             b < (ca)->buckets + (ca)->sb.nbuckets; b++)
 
-static inline void __bkey_put(struct cache_set *c, struct bkey *k)
-{
-       unsigned i;
-
-       for (i = 0; i < KEY_PTRS(k); i++)
-               atomic_dec_bug(&PTR_BUCKET(c, k, i)->pin);
-}
-
 static inline void cached_dev_put(struct cached_dev *dc)
 {
        if (atomic_dec_and_test(&dc->count))
@@ -1173,13 +911,15 @@ uint8_t bch_inc_gen(struct cache *, struct bucket *);
 void bch_rescale_priorities(struct cache_set *, int);
 bool bch_bucket_add_unused(struct cache *, struct bucket *);
 
-long bch_bucket_alloc(struct cache *, unsigned, struct closure *);
+long bch_bucket_alloc(struct cache *, unsigned, bool);
 void bch_bucket_free(struct cache_set *, struct bkey *);
 
 int __bch_bucket_alloc_set(struct cache_set *, unsigned,
-                          struct bkey *, int, struct closure *);
+                          struct bkey *, int, bool);
 int bch_bucket_alloc_set(struct cache_set *, unsigned,
-                        struct bkey *, int, struct closure *);
+                        struct bkey *, int, bool);
+bool bch_alloc_sectors(struct cache_set *, struct bkey *, unsigned,
+                      unsigned, unsigned, bool);
 
 __printf(2, 3)
 bool bch_cache_set_error(struct cache_set *, const char *, ...);
@@ -1187,7 +927,7 @@ bool bch_cache_set_error(struct cache_set *, const char *, ...);
 void bch_prio_write(struct cache *);
 void bch_write_bdev_super(struct cached_dev *, struct closure *);
 
-extern struct workqueue_struct *bcache_wq, *bch_gc_wq;
+extern struct workqueue_struct *bcache_wq;
 extern const char * const bch_cache_modes[];
 extern struct mutex bch_register_lock;
 extern struct list_head bch_cache_sets;
@@ -1220,15 +960,14 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *);
 void bch_btree_cache_free(struct cache_set *);
 int bch_btree_cache_alloc(struct cache_set *);
 void bch_moving_init_cache_set(struct cache_set *);
+int bch_open_buckets_alloc(struct cache_set *);
+void bch_open_buckets_free(struct cache_set *);
 
 int bch_cache_allocator_start(struct cache *ca);
-void bch_cache_allocator_exit(struct cache *ca);
 int bch_cache_allocator_init(struct cache *ca);
 
 void bch_debug_exit(void);
 int bch_debug_init(struct kobject *);
-void bch_writeback_exit(void);
-int bch_writeback_init(void);
 void bch_request_exit(void);
 int bch_request_init(void);
 void bch_btree_exit(void);
index 22d1ae72c2826a53b67656a59ea717a62a3b95a4..7d388b8bb50e35cf154d7c082ea492a5de08235d 100644 (file)
 
 /* Keylists */
 
-void bch_keylist_copy(struct keylist *dest, struct keylist *src)
-{
-       *dest = *src;
-
-       if (src->list == src->d) {
-               size_t n = (uint64_t *) src->top - src->d;
-               dest->top = (struct bkey *) &dest->d[n];
-               dest->list = dest->d;
-       }
-}
-
 int bch_keylist_realloc(struct keylist *l, int nptrs, struct cache_set *c)
 {
-       unsigned oldsize = (uint64_t *) l->top - l->list;
-       unsigned newsize = oldsize + 2 + nptrs;
-       uint64_t *new;
+       size_t oldsize = bch_keylist_nkeys(l);
+       size_t newsize = oldsize + 2 + nptrs;
+       uint64_t *old_keys = l->keys_p == l->inline_keys ? NULL : l->keys_p;
+       uint64_t *new_keys;
 
        /* The journalling code doesn't handle the case where the keys to insert
         * is bigger than an empty write: If we just return -ENOMEM here,
@@ -45,24 +35,23 @@ int bch_keylist_realloc(struct keylist *l, int nptrs, struct cache_set *c)
            roundup_pow_of_two(oldsize) == newsize)
                return 0;
 
-       new = krealloc(l->list == l->d ? NULL : l->list,
-                      sizeof(uint64_t) * newsize, GFP_NOIO);
+       new_keys = krealloc(old_keys, sizeof(uint64_t) * newsize, GFP_NOIO);
 
-       if (!new)
+       if (!new_keys)
                return -ENOMEM;
 
-       if (l->list == l->d)
-               memcpy(new, l->list, sizeof(uint64_t) * KEYLIST_INLINE);
+       if (!old_keys)
+               memcpy(new_keys, l->inline_keys, sizeof(uint64_t) * oldsize);
 
-       l->list = new;
-       l->top = (struct bkey *) (&l->list[oldsize]);
+       l->keys_p = new_keys;
+       l->top_p = new_keys + oldsize;
 
        return 0;
 }
 
 struct bkey *bch_keylist_pop(struct keylist *l)
 {
-       struct bkey *k = l->bottom;
+       struct bkey *k = l->keys;
 
        if (k == l->top)
                return NULL;
@@ -73,21 +62,20 @@ struct bkey *bch_keylist_pop(struct keylist *l)
        return l->top = k;
 }
 
-/* Pointer validation */
-
-bool __bch_ptr_invalid(struct cache_set *c, int level, const struct bkey *k)
+void bch_keylist_pop_front(struct keylist *l)
 {
-       unsigned i;
-       char buf[80];
+       l->top_p -= bkey_u64s(l->keys);
 
-       if (level && (!KEY_PTRS(k) || !KEY_SIZE(k) || KEY_DIRTY(k)))
-               goto bad;
+       memmove(l->keys,
+               bkey_next(l->keys),
+               bch_keylist_bytes(l));
+}
 
-       if (!level && KEY_SIZE(k) > KEY_OFFSET(k))
-               goto bad;
+/* Pointer validation */
 
-       if (!KEY_SIZE(k))
-               return true;
+static bool __ptr_invalid(struct cache_set *c, const struct bkey *k)
+{
+       unsigned i;
 
        for (i = 0; i < KEY_PTRS(k); i++)
                if (ptr_available(c, k, i)) {
@@ -98,13 +86,83 @@ bool __bch_ptr_invalid(struct cache_set *c, int level, const struct bkey *k)
                        if (KEY_SIZE(k) + r > c->sb.bucket_size ||
                            bucket <  ca->sb.first_bucket ||
                            bucket >= ca->sb.nbuckets)
-                               goto bad;
+                               return true;
                }
 
+       return false;
+}
+
+bool bch_btree_ptr_invalid(struct cache_set *c, const struct bkey *k)
+{
+       char buf[80];
+
+       if (!KEY_PTRS(k) || !KEY_SIZE(k) || KEY_DIRTY(k))
+               goto bad;
+
+       if (__ptr_invalid(c, k))
+               goto bad;
+
+       return false;
+bad:
+       bch_bkey_to_text(buf, sizeof(buf), k);
+       cache_bug(c, "spotted btree ptr %s: %s", buf, bch_ptr_status(c, k));
+       return true;
+}
+
+bool bch_extent_ptr_invalid(struct cache_set *c, const struct bkey *k)
+{
+       char buf[80];
+
+       if (!KEY_SIZE(k))
+               return true;
+
+       if (KEY_SIZE(k) > KEY_OFFSET(k))
+               goto bad;
+
+       if (__ptr_invalid(c, k))
+               goto bad;
+
        return false;
 bad:
        bch_bkey_to_text(buf, sizeof(buf), k);
-       cache_bug(c, "spotted bad key %s: %s", buf, bch_ptr_status(c, k));
+       cache_bug(c, "spotted extent %s: %s", buf, bch_ptr_status(c, k));
+       return true;
+}
+
+static bool ptr_bad_expensive_checks(struct btree *b, const struct bkey *k,
+                                    unsigned ptr)
+{
+       struct bucket *g = PTR_BUCKET(b->c, k, ptr);
+       char buf[80];
+
+       if (mutex_trylock(&b->c->bucket_lock)) {
+               if (b->level) {
+                       if (KEY_DIRTY(k) ||
+                           g->prio != BTREE_PRIO ||
+                           (b->c->gc_mark_valid &&
+                            GC_MARK(g) != GC_MARK_METADATA))
+                               goto err;
+
+               } else {
+                       if (g->prio == BTREE_PRIO)
+                               goto err;
+
+                       if (KEY_DIRTY(k) &&
+                           b->c->gc_mark_valid &&
+                           GC_MARK(g) != GC_MARK_DIRTY)
+                               goto err;
+               }
+               mutex_unlock(&b->c->bucket_lock);
+       }
+
+       return false;
+err:
+       mutex_unlock(&b->c->bucket_lock);
+       bch_bkey_to_text(buf, sizeof(buf), k);
+       btree_bug(b,
+"inconsistent pointer %s: bucket %zu pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i",
+                 buf, PTR_BUCKET_NR(b->c, k, ptr), atomic_read(&g->pin),
+                 g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen);
        return true;
 }
 
@@ -118,64 +176,29 @@ bool bch_ptr_bad(struct btree *b, const struct bkey *k)
            bch_ptr_invalid(b, k))
                return true;
 
-       if (KEY_PTRS(k) && PTR_DEV(k, 0) == PTR_CHECK_DEV)
-               return true;
+       for (i = 0; i < KEY_PTRS(k); i++) {
+               if (!ptr_available(b->c, k, i))
+                       return true;
 
-       for (i = 0; i < KEY_PTRS(k); i++)
-               if (ptr_available(b->c, k, i)) {
-                       g = PTR_BUCKET(b->c, k, i);
-                       stale = ptr_stale(b->c, k, i);
+               g = PTR_BUCKET(b->c, k, i);
+               stale = ptr_stale(b->c, k, i);
 
-                       btree_bug_on(stale > 96, b,
-                                    "key too stale: %i, need_gc %u",
-                                    stale, b->c->need_gc);
+               btree_bug_on(stale > 96, b,
+                            "key too stale: %i, need_gc %u",
+                            stale, b->c->need_gc);
 
-                       btree_bug_on(stale && KEY_DIRTY(k) && KEY_SIZE(k),
-                                    b, "stale dirty pointer");
+               btree_bug_on(stale && KEY_DIRTY(k) && KEY_SIZE(k),
+                            b, "stale dirty pointer");
 
-                       if (stale)
-                               return true;
+               if (stale)
+                       return true;
 
-#ifdef CONFIG_BCACHE_EDEBUG
-                       if (!mutex_trylock(&b->c->bucket_lock))
-                               continue;
-
-                       if (b->level) {
-                               if (KEY_DIRTY(k) ||
-                                   g->prio != BTREE_PRIO ||
-                                   (b->c->gc_mark_valid &&
-                                    GC_MARK(g) != GC_MARK_METADATA))
-                                       goto bug;
-
-                       } else {
-                               if (g->prio == BTREE_PRIO)
-                                       goto bug;
-
-                               if (KEY_DIRTY(k) &&
-                                   b->c->gc_mark_valid &&
-                                   GC_MARK(g) != GC_MARK_DIRTY)
-                                       goto bug;
-                       }
-                       mutex_unlock(&b->c->bucket_lock);
-#endif
-               }
+               if (expensive_debug_checks(b->c) &&
+                   ptr_bad_expensive_checks(b, k, i))
+                       return true;
+       }
 
        return false;
-#ifdef CONFIG_BCACHE_EDEBUG
-bug:
-       mutex_unlock(&b->c->bucket_lock);
-
-       {
-               char buf[80];
-
-               bch_bkey_to_text(buf, sizeof(buf), k);
-               btree_bug(b,
-"inconsistent pointer %s: bucket %zu pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i",
-                         buf, PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin),
-                         g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen);
-       }
-       return true;
-#endif
 }
 
 /* Key/pointer manipulation */
@@ -458,16 +481,8 @@ static struct bkey *table_to_bkey(struct bset_tree *t, unsigned cacheline)
 
 static inline uint64_t shrd128(uint64_t high, uint64_t low, uint8_t shift)
 {
-#ifdef CONFIG_X86_64
-       asm("shrd %[shift],%[high],%[low]"
-           : [low] "+Rm" (low)
-           : [high] "R" (high),
-           [shift] "ci" (shift)
-           : "cc");
-#else
        low >>= shift;
        low  |= (high << 1) << (63U - shift);
-#endif
        return low;
 }
 
@@ -686,7 +701,7 @@ void bch_bset_init_next(struct btree *b)
        } else
                get_random_bytes(&i->seq, sizeof(uint64_t));
 
-       i->magic        = bset_magic(b->c);
+       i->magic        = bset_magic(&b->c->sb);
        i->version      = 0;
        i->keys         = 0;
 
@@ -824,16 +839,16 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t,
        } else
                i = bset_search_write_set(b, t, search);
 
-#ifdef CONFIG_BCACHE_EDEBUG
-       BUG_ON(bset_written(b, t) &&
-              i.l != t->data->start &&
-              bkey_cmp(tree_to_prev_bkey(t,
-                 inorder_to_tree(bkey_to_cacheline(t, i.l), t)),
-                       search) > 0);
+       if (expensive_debug_checks(b->c)) {
+               BUG_ON(bset_written(b, t) &&
+                      i.l != t->data->start &&
+                      bkey_cmp(tree_to_prev_bkey(t,
+                         inorder_to_tree(bkey_to_cacheline(t, i.l), t)),
+                               search) > 0);
 
-       BUG_ON(i.r != end(t->data) &&
-              bkey_cmp(i.r, search) <= 0);
-#endif
+               BUG_ON(i.r != end(t->data) &&
+                      bkey_cmp(i.r, search) <= 0);
+       }
 
        while (likely(i.l != i.r) &&
               bkey_cmp(i.l, search) <= 0)
@@ -844,6 +859,13 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t,
 
 /* Btree iterator */
 
+/*
+ * Returns true if l > r - unless l == r, in which case returns true if l is
+ * older than r.
+ *
+ * Necessary for btree_sort_fixup() - if there are multiple keys that compare
+ * equal in different sets, we have to process them newest to oldest.
+ */
 static inline bool btree_iter_cmp(struct btree_iter_set l,
                                  struct btree_iter_set r)
 {
@@ -867,12 +889,16 @@ void bch_btree_iter_push(struct btree_iter *iter, struct bkey *k,
 }
 
 struct bkey *__bch_btree_iter_init(struct btree *b, struct btree_iter *iter,
-                              struct bkey *search, struct bset_tree *start)
+                                  struct bkey *search, struct bset_tree *start)
 {
        struct bkey *ret = NULL;
        iter->size = ARRAY_SIZE(iter->data);
        iter->used = 0;
 
+#ifdef CONFIG_BCACHE_DEBUG
+       iter->b = b;
+#endif
+
        for (; start <= &b->sets[b->nsets]; start++) {
                ret = bch_bset_search(b, start, search);
                bch_btree_iter_push(iter, ret, end(start->data));
@@ -887,6 +913,8 @@ struct bkey *bch_btree_iter_next(struct btree_iter *iter)
        struct bkey *ret = NULL;
 
        if (!btree_iter_end(iter)) {
+               bch_btree_iter_next_check(iter);
+
                ret = iter->data->k;
                iter->data->k = bkey_next(iter->data->k);
 
@@ -916,14 +944,6 @@ struct bkey *bch_btree_iter_next_filter(struct btree_iter *iter,
        return ret;
 }
 
-struct bkey *bch_next_recurse_key(struct btree *b, struct bkey *search)
-{
-       struct btree_iter iter;
-
-       bch_btree_iter_init(b, &iter, search);
-       return bch_btree_iter_next_filter(&iter, b, bch_ptr_bad);
-}
-
 /* Mergesort */
 
 static void sort_key_next(struct btree_iter *iter,
@@ -998,7 +1018,6 @@ static void btree_mergesort(struct btree *b, struct bset *out,
        out->keys = last ? (uint64_t *) bkey_next(last) - out->d : 0;
 
        pr_debug("sorted %i keys", out->keys);
-       bch_check_key_order(b, out);
 }
 
 static void __btree_sort(struct btree *b, struct btree_iter *iter,
@@ -1029,7 +1048,7 @@ static void __btree_sort(struct btree *b, struct btree_iter *iter,
                 * memcpy()
                 */
 
-               out->magic      = bset_magic(b->c);
+               out->magic      = bset_magic(&b->c->sb);
                out->seq        = b->sets[0].data->seq;
                out->version    = b->sets[0].data->version;
                swap(out, b->sets[0].data);
@@ -1050,24 +1069,21 @@ static void __btree_sort(struct btree *b, struct btree_iter *iter,
        if (b->written)
                bset_build_written_tree(b);
 
-       if (!start) {
-               spin_lock(&b->c->sort_time_lock);
+       if (!start)
                bch_time_stats_update(&b->c->sort_time, start_time);
-               spin_unlock(&b->c->sort_time_lock);
-       }
 }
 
 void bch_btree_sort_partial(struct btree *b, unsigned start)
 {
-       size_t oldsize = 0, order = b->page_order, keys = 0;
+       size_t order = b->page_order, keys = 0;
        struct btree_iter iter;
+       int oldsize = bch_count_data(b);
+
        __bch_btree_iter_init(b, &iter, NULL, &b->sets[start]);
 
        BUG_ON(b->sets[b->nsets].data == write_block(b) &&
               (b->sets[b->nsets].size || b->nsets));
 
-       if (b->written)
-               oldsize = bch_count_data(b);
 
        if (start) {
                unsigned i;
@@ -1083,7 +1099,7 @@ void bch_btree_sort_partial(struct btree *b, unsigned start)
 
        __btree_sort(b, &iter, start, order, false);
 
-       EBUG_ON(b->written && bch_count_data(b) != oldsize);
+       EBUG_ON(b->written && oldsize >= 0 && bch_count_data(b) != oldsize);
 }
 
 void bch_btree_sort_and_fix_extents(struct btree *b, struct btree_iter *iter)
@@ -1101,9 +1117,7 @@ void bch_btree_sort_into(struct btree *b, struct btree *new)
 
        btree_mergesort(b, new->sets->data, &iter, false, true);
 
-       spin_lock(&b->c->sort_time_lock);
        bch_time_stats_update(&b->c->sort_time, start_time);
-       spin_unlock(&b->c->sort_time_lock);
 
        bkey_copy_key(&new->key, &b->key);
        new->sets->size = 0;
@@ -1148,16 +1162,16 @@ out:
 /* Sysfs stuff */
 
 struct bset_stats {
+       struct btree_op op;
        size_t nodes;
        size_t sets_written, sets_unwritten;
        size_t bytes_written, bytes_unwritten;
        size_t floats, failed;
 };
 
-static int bch_btree_bset_stats(struct btree *b, struct btree_op *op,
-                           struct bset_stats *stats)
+static int btree_bset_stats(struct btree_op *op, struct btree *b)
 {
-       struct bkey *k;
+       struct bset_stats *stats = container_of(op, struct bset_stats, op);
        unsigned i;
 
        stats->nodes++;
@@ -1182,30 +1196,19 @@ static int bch_btree_bset_stats(struct btree *b, struct btree_op *op,
                }
        }
 
-       if (b->level) {
-               struct btree_iter iter;
-
-               for_each_key_filter(b, k, &iter, bch_ptr_bad) {
-                       int ret = btree(bset_stats, k, b, op, stats);
-                       if (ret)
-                               return ret;
-               }
-       }
-
-       return 0;
+       return MAP_CONTINUE;
 }
 
 int bch_bset_print_stats(struct cache_set *c, char *buf)
 {
-       struct btree_op op;
        struct bset_stats t;
        int ret;
 
-       bch_btree_op_init_stack(&op);
        memset(&t, 0, sizeof(struct bset_stats));
+       bch_btree_op_init(&t.op, -1);
 
-       ret = btree_root(bset_stats, c, &op, &t);
-       if (ret)
+       ret = bch_btree_map_nodes(&t.op, c, &ZERO_KEY, btree_bset_stats);
+       if (ret < 0)
                return ret;
 
        return snprintf(buf, PAGE_SIZE,
index ae115a253d7312f81422a4b162e2ca4952556a44..1d3c24f9fa0e95fbb20c03fcb825559b0736de1b 100644 (file)
 
 struct btree_iter {
        size_t size, used;
+#ifdef CONFIG_BCACHE_DEBUG
+       struct btree *b;
+#endif
        struct btree_iter_set {
                struct bkey *k, *end;
        } data[MAX_BSETS];
@@ -193,54 +196,26 @@ static __always_inline int64_t bkey_cmp(const struct bkey *l,
                : (int64_t) KEY_OFFSET(l) - (int64_t) KEY_OFFSET(r);
 }
 
-static inline size_t bkey_u64s(const struct bkey *k)
-{
-       BUG_ON(KEY_CSUM(k) > 1);
-       return 2 + KEY_PTRS(k) + (KEY_CSUM(k) ? 1 : 0);
-}
-
-static inline size_t bkey_bytes(const struct bkey *k)
-{
-       return bkey_u64s(k) * sizeof(uint64_t);
-}
-
-static inline void bkey_copy(struct bkey *dest, const struct bkey *src)
-{
-       memcpy(dest, src, bkey_bytes(src));
-}
-
-static inline void bkey_copy_key(struct bkey *dest, const struct bkey *src)
-{
-       if (!src)
-               src = &KEY(0, 0, 0);
-
-       SET_KEY_INODE(dest, KEY_INODE(src));
-       SET_KEY_OFFSET(dest, KEY_OFFSET(src));
-}
-
-static inline struct bkey *bkey_next(const struct bkey *k)
-{
-       uint64_t *d = (void *) k;
-       return (struct bkey *) (d + bkey_u64s(k));
-}
-
 /* Keylists */
 
 struct keylist {
-       struct bkey             *top;
        union {
-               uint64_t                *list;
-               struct bkey             *bottom;
+               struct bkey             *keys;
+               uint64_t                *keys_p;
+       };
+       union {
+               struct bkey             *top;
+               uint64_t                *top_p;
        };
 
        /* Enough room for btree_split's keys without realloc */
 #define KEYLIST_INLINE         16
-       uint64_t                d[KEYLIST_INLINE];
+       uint64_t                inline_keys[KEYLIST_INLINE];
 };
 
 static inline void bch_keylist_init(struct keylist *l)
 {
-       l->top = (void *) (l->list = l->d);
+       l->top_p = l->keys_p = l->inline_keys;
 }
 
 static inline void bch_keylist_push(struct keylist *l)
@@ -256,17 +231,32 @@ static inline void bch_keylist_add(struct keylist *l, struct bkey *k)
 
 static inline bool bch_keylist_empty(struct keylist *l)
 {
-       return l->top == (void *) l->list;
+       return l->top == l->keys;
+}
+
+static inline void bch_keylist_reset(struct keylist *l)
+{
+       l->top = l->keys;
 }
 
 static inline void bch_keylist_free(struct keylist *l)
 {
-       if (l->list != l->d)
-               kfree(l->list);
+       if (l->keys_p != l->inline_keys)
+               kfree(l->keys_p);
+}
+
+static inline size_t bch_keylist_nkeys(struct keylist *l)
+{
+       return l->top_p - l->keys_p;
+}
+
+static inline size_t bch_keylist_bytes(struct keylist *l)
+{
+       return bch_keylist_nkeys(l) * sizeof(uint64_t);
 }
 
-void bch_keylist_copy(struct keylist *, struct keylist *);
 struct bkey *bch_keylist_pop(struct keylist *);
+void bch_keylist_pop_front(struct keylist *);
 int bch_keylist_realloc(struct keylist *, int, struct cache_set *);
 
 void bch_bkey_copy_single_ptr(struct bkey *, const struct bkey *,
@@ -287,7 +277,9 @@ static inline bool bch_cut_back(const struct bkey *where, struct bkey *k)
 }
 
 const char *bch_ptr_status(struct cache_set *, const struct bkey *);
-bool __bch_ptr_invalid(struct cache_set *, int level, const struct bkey *);
+bool bch_btree_ptr_invalid(struct cache_set *, const struct bkey *);
+bool bch_extent_ptr_invalid(struct cache_set *, const struct bkey *);
+
 bool bch_ptr_bad(struct btree *, const struct bkey *);
 
 static inline uint8_t gen_after(uint8_t a, uint8_t b)
@@ -311,7 +303,6 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
 
 typedef bool (*ptr_filter_fn)(struct btree *, const struct bkey *);
 
-struct bkey *bch_next_recurse_key(struct btree *, struct bkey *);
 struct bkey *bch_btree_iter_next(struct btree_iter *);
 struct bkey *bch_btree_iter_next_filter(struct btree_iter *,
                                        struct btree *, ptr_filter_fn);
@@ -361,12 +352,30 @@ void bch_bset_fix_lookup_table(struct btree *, struct bkey *);
 struct bkey *__bch_bset_search(struct btree *, struct bset_tree *,
                           const struct bkey *);
 
+/*
+ * Returns the first key that is strictly greater than search
+ */
 static inline struct bkey *bch_bset_search(struct btree *b, struct bset_tree *t,
                                           const struct bkey *search)
 {
        return search ? __bch_bset_search(b, t, search) : t->data->start;
 }
 
+#define PRECEDING_KEY(_k)                                      \
+({                                                             \
+       struct bkey *_ret = NULL;                               \
+                                                               \
+       if (KEY_INODE(_k) || KEY_OFFSET(_k)) {                  \
+               _ret = &KEY(KEY_INODE(_k), KEY_OFFSET(_k), 0);  \
+                                                               \
+               if (!_ret->low)                                 \
+                       _ret->high--;                           \
+               _ret->low--;                                    \
+       }                                                       \
+                                                               \
+       _ret;                                                   \
+})
+
 bool bch_bkey_try_merge(struct btree *, struct bkey *, struct bkey *);
 void bch_btree_sort_lazy(struct btree *);
 void bch_btree_sort_into(struct btree *, struct btree *);
index f42fc7ed9cd63b14fd4cf54a879dfd9d046584d1..5e2765aadce174e9b7cffd479667a2c48bcf500f 100644 (file)
 #include "bcache.h"
 #include "btree.h"
 #include "debug.h"
-#include "request.h"
 #include "writeback.h"
 
 #include <linux/slab.h>
 #include <linux/bitops.h>
+#include <linux/freezer.h>
 #include <linux/hash.h>
+#include <linux/kthread.h>
 #include <linux/prefetch.h>
 #include <linux/random.h>
 #include <linux/rcupdate.h>
  * Test module load/unload
  */
 
-static const char * const op_types[] = {
-       "insert", "replace"
+enum {
+       BTREE_INSERT_STATUS_INSERT,
+       BTREE_INSERT_STATUS_BACK_MERGE,
+       BTREE_INSERT_STATUS_OVERWROTE,
+       BTREE_INSERT_STATUS_FRONT_MERGE,
 };
 
-static const char *op_type(struct btree_op *op)
-{
-       return op_types[op->type];
-}
-
 #define MAX_NEED_GC            64
 #define MAX_SAVE_PRIO          72
 
@@ -105,23 +104,89 @@ static const char *op_type(struct btree_op *op)
 #define PTR_HASH(c, k)                                                 \
        (((k)->ptr[0] >> c->bucket_bits) | PTR_GEN(k, 0))
 
-struct workqueue_struct *bch_gc_wq;
 static struct workqueue_struct *btree_io_wq;
 
-void bch_btree_op_init_stack(struct btree_op *op)
+static inline bool should_split(struct btree *b)
 {
-       memset(op, 0, sizeof(struct btree_op));
-       closure_init_stack(&op->cl);
-       op->lock = -1;
-       bch_keylist_init(&op->keys);
+       struct bset *i = write_block(b);
+       return b->written >= btree_blocks(b) ||
+               (b->written + __set_blocks(i, i->keys + 15, b->c)
+                > btree_blocks(b));
 }
 
+#define insert_lock(s, b)      ((b)->level <= (s)->lock)
+
+/*
+ * These macros are for recursing down the btree - they handle the details of
+ * locking and looking up nodes in the cache for you. They're best treated as
+ * mere syntax when reading code that uses them.
+ *
+ * op->lock determines whether we take a read or a write lock at a given depth.
+ * If you've got a read lock and find that you need a write lock (i.e. you're
+ * going to have to split), set op->lock and return -EINTR; btree_root() will
+ * call you again and you'll have the correct lock.
+ */
+
+/**
+ * btree - recurse down the btree on a specified key
+ * @fn:                function to call, which will be passed the child node
+ * @key:       key to recurse on
+ * @b:         parent btree node
+ * @op:                pointer to struct btree_op
+ */
+#define btree(fn, key, b, op, ...)                                     \
+({                                                                     \
+       int _r, l = (b)->level - 1;                                     \
+       bool _w = l <= (op)->lock;                                      \
+       struct btree *_child = bch_btree_node_get((b)->c, key, l, _w);  \
+       if (!IS_ERR(_child)) {                                          \
+               _child->parent = (b);                                   \
+               _r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__);       \
+               rw_unlock(_w, _child);                                  \
+       } else                                                          \
+               _r = PTR_ERR(_child);                                   \
+       _r;                                                             \
+})
+
+/**
+ * btree_root - call a function on the root of the btree
+ * @fn:                function to call, which will be passed the child node
+ * @c:         cache set
+ * @op:                pointer to struct btree_op
+ */
+#define btree_root(fn, c, op, ...)                                     \
+({                                                                     \
+       int _r = -EINTR;                                                \
+       do {                                                            \
+               struct btree *_b = (c)->root;                           \
+               bool _w = insert_lock(op, _b);                          \
+               rw_lock(_w, _b, _b->level);                             \
+               if (_b == (c)->root &&                                  \
+                   _w == insert_lock(op, _b)) {                        \
+                       _b->parent = NULL;                              \
+                       _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__);   \
+               }                                                       \
+               rw_unlock(_w, _b);                                      \
+               bch_cannibalize_unlock(c);                              \
+               if (_r == -ENOSPC) {                                    \
+                       wait_event((c)->try_wait,                       \
+                                  !(c)->try_harder);                   \
+                       _r = -EINTR;                                    \
+               }                                                       \
+       } while (_r == -EINTR);                                         \
+                                                                       \
+       _r;                                                             \
+})
+
 /* Btree key manipulation */
 
-static void bkey_put(struct cache_set *c, struct bkey *k, int level)
+void bkey_put(struct cache_set *c, struct bkey *k)
 {
-       if ((level && KEY_OFFSET(k)) || !level)
-               __bkey_put(c, k);
+       unsigned i;
+
+       for (i = 0; i < KEY_PTRS(k); i++)
+               if (ptr_available(c, k, i))
+                       atomic_dec_bug(&PTR_BUCKET(c, k, i)->pin);
 }
 
 /* Btree IO */
@@ -145,6 +210,10 @@ static void bch_btree_node_read_done(struct btree *b)
        iter->size = b->c->sb.bucket_size / b->c->sb.block_size;
        iter->used = 0;
 
+#ifdef CONFIG_BCACHE_DEBUG
+       iter->b = b;
+#endif
+
        if (!i->seq)
                goto err;
 
@@ -160,7 +229,7 @@ static void bch_btree_node_read_done(struct btree *b)
                        goto err;
 
                err = "bad magic";
-               if (i->magic != bset_magic(b->c))
+               if (i->magic != bset_magic(&b->c->sb))
                        goto err;
 
                err = "bad checksum";
@@ -248,10 +317,7 @@ void bch_btree_node_read(struct btree *b)
                goto err;
 
        bch_btree_node_read_done(b);
-
-       spin_lock(&b->c->btree_read_time_lock);
        bch_time_stats_update(&b->c->btree_read_time, start_time);
-       spin_unlock(&b->c->btree_read_time_lock);
 
        return;
 err:
@@ -327,7 +393,7 @@ static void do_btree_node_write(struct btree *b)
        b->bio = bch_bbio_alloc(b->c);
 
        b->bio->bi_end_io       = btree_node_write_endio;
-       b->bio->bi_private      = &b->io.cl;
+       b->bio->bi_private      = cl;
        b->bio->bi_rw           = REQ_META|WRITE_SYNC|REQ_FUA;
        b->bio->bi_size         = set_blocks(i, b->c) * block_bytes(b->c);
        bch_bio_map(b->bio, i);
@@ -383,7 +449,7 @@ void bch_btree_node_write(struct btree *b, struct closure *parent)
        BUG_ON(b->written >= btree_blocks(b));
        BUG_ON(b->written && !i->keys);
        BUG_ON(b->sets->data->seq != i->seq);
-       bch_check_key_order(b, i);
+       bch_check_keys(b, "writing");
 
        cancel_delayed_work(&b->work);
 
@@ -405,6 +471,15 @@ void bch_btree_node_write(struct btree *b, struct closure *parent)
                bch_bset_init_next(b);
 }
 
+static void bch_btree_node_write_sync(struct btree *b)
+{
+       struct closure cl;
+
+       closure_init_stack(&cl);
+       bch_btree_node_write(b, &cl);
+       closure_sync(&cl);
+}
+
 static void btree_node_write_work(struct work_struct *w)
 {
        struct btree *b = container_of(to_delayed_work(w), struct btree, work);
@@ -416,7 +491,7 @@ static void btree_node_write_work(struct work_struct *w)
        rw_unlock(true, b);
 }
 
-static void bch_btree_leaf_dirty(struct btree *b, struct btree_op *op)
+static void bch_btree_leaf_dirty(struct btree *b, atomic_t *journal_ref)
 {
        struct bset *i = b->sets[b->nsets].data;
        struct btree_write *w = btree_current_write(b);
@@ -429,15 +504,15 @@ static void bch_btree_leaf_dirty(struct btree *b, struct btree_op *op)
 
        set_btree_node_dirty(b);
 
-       if (op && op->journal) {
+       if (journal_ref) {
                if (w->journal &&
-                   journal_pin_cmp(b->c, w, op)) {
+                   journal_pin_cmp(b->c, w->journal, journal_ref)) {
                        atomic_dec_bug(w->journal);
                        w->journal = NULL;
                }
 
                if (!w->journal) {
-                       w->journal = op->journal;
+                       w->journal = journal_ref;
                        atomic_inc(w->journal);
                }
        }
@@ -566,33 +641,32 @@ static struct btree *mca_bucket_alloc(struct cache_set *c,
        return b;
 }
 
-static int mca_reap(struct btree *b, struct closure *cl, unsigned min_order)
+static int mca_reap(struct btree *b, unsigned min_order, bool flush)
 {
+       struct closure cl;
+
+       closure_init_stack(&cl);
        lockdep_assert_held(&b->c->bucket_lock);
 
        if (!down_write_trylock(&b->lock))
                return -ENOMEM;
 
-       if (b->page_order < min_order) {
+       BUG_ON(btree_node_dirty(b) && !b->sets[0].data);
+
+       if (b->page_order < min_order ||
+           (!flush &&
+            (btree_node_dirty(b) ||
+             atomic_read(&b->io.cl.remaining) != -1))) {
                rw_unlock(true, b);
                return -ENOMEM;
        }
 
-       BUG_ON(btree_node_dirty(b) && !b->sets[0].data);
-
-       if (cl && btree_node_dirty(b))
-               bch_btree_node_write(b, NULL);
-
-       if (cl)
-               closure_wait_event_async(&b->io.wait, cl,
-                        atomic_read(&b->io.cl.remaining) == -1);
+       if (btree_node_dirty(b))
+               bch_btree_node_write_sync(b);
 
-       if (btree_node_dirty(b) ||
-           !closure_is_unlocked(&b->io.cl) ||
-           work_pending(&b->work.work)) {
-               rw_unlock(true, b);
-               return -EAGAIN;
-       }
+       /* wait for any in flight btree write */
+       closure_wait_event(&b->io.wait, &cl,
+                          atomic_read(&b->io.cl.remaining) == -1);
 
        return 0;
 }
@@ -633,7 +707,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
                        break;
 
                if (++i > 3 &&
-                   !mca_reap(b, NULL, 0)) {
+                   !mca_reap(b, 0, false)) {
                        mca_data_free(b);
                        rw_unlock(true, b);
                        freed++;
@@ -652,7 +726,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink,
                list_rotate_left(&c->btree_cache);
 
                if (!b->accessed &&
-                   !mca_reap(b, NULL, 0)) {
+                   !mca_reap(b, 0, false)) {
                        mca_bucket_free(b);
                        mca_data_free(b);
                        rw_unlock(true, b);
@@ -723,12 +797,9 @@ int bch_btree_cache_alloc(struct cache_set *c)
 {
        unsigned i;
 
-       /* XXX: doesn't check for errors */
-
-       closure_init_unlocked(&c->gc);
-
        for (i = 0; i < mca_reserve(c); i++)
-               mca_bucket_alloc(c, &ZERO_KEY, GFP_KERNEL);
+               if (!mca_bucket_alloc(c, &ZERO_KEY, GFP_KERNEL))
+                       return -ENOMEM;
 
        list_splice_init(&c->btree_cache,
                         &c->btree_cache_freeable);
@@ -775,52 +846,27 @@ out:
        return b;
 }
 
-static struct btree *mca_cannibalize(struct cache_set *c, struct bkey *k,
-                                    int level, struct closure *cl)
+static struct btree *mca_cannibalize(struct cache_set *c, struct bkey *k)
 {
-       int ret = -ENOMEM;
-       struct btree *i;
+       struct btree *b;
 
        trace_bcache_btree_cache_cannibalize(c);
 
-       if (!cl)
-               return ERR_PTR(-ENOMEM);
-
-       /*
-        * Trying to free up some memory - i.e. reuse some btree nodes - may
-        * require initiating IO to flush the dirty part of the node. If we're
-        * running under generic_make_request(), that IO will never finish and
-        * we would deadlock. Returning -EAGAIN causes the cache lookup code to
-        * punt to workqueue and retry.
-        */
-       if (current->bio_list)
-               return ERR_PTR(-EAGAIN);
-
-       if (c->try_harder && c->try_harder != cl) {
-               closure_wait_event_async(&c->try_wait, cl, !c->try_harder);
-               return ERR_PTR(-EAGAIN);
-       }
+       if (!c->try_harder) {
+               c->try_harder = current;
+               c->try_harder_start = local_clock();
+       } else if (c->try_harder != current)
+               return ERR_PTR(-ENOSPC);
 
-       c->try_harder = cl;
-       c->try_harder_start = local_clock();
-retry:
-       list_for_each_entry_reverse(i, &c->btree_cache, list) {
-               int r = mca_reap(i, cl, btree_order(k));
-               if (!r)
-                       return i;
-               if (r != -ENOMEM)
-                       ret = r;
-       }
+       list_for_each_entry_reverse(b, &c->btree_cache, list)
+               if (!mca_reap(b, btree_order(k), false))
+                       return b;
 
-       if (ret == -EAGAIN &&
-           closure_blocking(cl)) {
-               mutex_unlock(&c->bucket_lock);
-               closure_sync(cl);
-               mutex_lock(&c->bucket_lock);
-               goto retry;
-       }
+       list_for_each_entry_reverse(b, &c->btree_cache, list)
+               if (!mca_reap(b, btree_order(k), true))
+                       return b;
 
-       return ERR_PTR(ret);
+       return ERR_PTR(-ENOMEM);
 }
 
 /*
@@ -829,20 +875,21 @@ retry:
  * cannibalize_bucket() will take. This means every time we unlock the root of
  * the btree, we need to release this lock if we have it held.
  */
-void bch_cannibalize_unlock(struct cache_set *c, struct closure *cl)
+static void bch_cannibalize_unlock(struct cache_set *c)
 {
-       if (c->try_harder == cl) {
+       if (c->try_harder == current) {
                bch_time_stats_update(&c->try_harder_time, c->try_harder_start);
                c->try_harder = NULL;
-               __closure_wake_up(&c->try_wait);
+               wake_up(&c->try_wait);
        }
 }
 
-static struct btree *mca_alloc(struct cache_set *c, struct bkey *k,
-                              int level, struct closure *cl)
+static struct btree *mca_alloc(struct cache_set *c, struct bkey *k, int level)
 {
        struct btree *b;
 
+       BUG_ON(current->bio_list);
+
        lockdep_assert_held(&c->bucket_lock);
 
        if (mca_find(c, k))
@@ -852,14 +899,14 @@ static struct btree *mca_alloc(struct cache_set *c, struct bkey *k,
         * the list. Check if there's any freed nodes there:
         */
        list_for_each_entry(b, &c->btree_cache_freeable, list)
-               if (!mca_reap(b, NULL, btree_order(k)))
+               if (!mca_reap(b, btree_order(k), false))
                        goto out;
 
        /* We never free struct btree itself, just the memory that holds the on
         * disk node. Check the freed list before allocating a new one:
         */
        list_for_each_entry(b, &c->btree_cache_freed, list)
-               if (!mca_reap(b, NULL, 0)) {
+               if (!mca_reap(b, 0, false)) {
                        mca_data_alloc(b, k, __GFP_NOWARN|GFP_NOIO);
                        if (!b->sets[0].data)
                                goto err;
@@ -884,6 +931,7 @@ out:
 
        lock_set_subclass(&b->lock.dep_map, level + 1, _THIS_IP_);
        b->level        = level;
+       b->parent       = (void *) ~0UL;
 
        mca_reinit(b);
 
@@ -892,7 +940,7 @@ err:
        if (b)
                rw_unlock(true, b);
 
-       b = mca_cannibalize(c, k, level, cl);
+       b = mca_cannibalize(c, k);
        if (!IS_ERR(b))
                goto out;
 
@@ -903,17 +951,15 @@ err:
  * bch_btree_node_get - find a btree node in the cache and lock it, reading it
  * in from disk if necessary.
  *
- * If IO is necessary, it uses the closure embedded in struct btree_op to wait;
- * if that closure is in non blocking mode, will return -EAGAIN.
+ * If IO is necessary and running under generic_make_request, returns -EAGAIN.
  *
  * The btree node will have either a read or a write lock held, depending on
  * level and op->lock.
  */
 struct btree *bch_btree_node_get(struct cache_set *c, struct bkey *k,
-                                int level, struct btree_op *op)
+                                int level, bool write)
 {
        int i = 0;
-       bool write = level <= op->lock;
        struct btree *b;
 
        BUG_ON(level < 0);
@@ -925,7 +971,7 @@ retry:
                        return ERR_PTR(-EAGAIN);
 
                mutex_lock(&c->bucket_lock);
-               b = mca_alloc(c, k, level, &op->cl);
+               b = mca_alloc(c, k, level);
                mutex_unlock(&c->bucket_lock);
 
                if (!b)
@@ -971,7 +1017,7 @@ static void btree_node_prefetch(struct cache_set *c, struct bkey *k, int level)
        struct btree *b;
 
        mutex_lock(&c->bucket_lock);
-       b = mca_alloc(c, k, level, NULL);
+       b = mca_alloc(c, k, level);
        mutex_unlock(&c->bucket_lock);
 
        if (!IS_ERR_OR_NULL(b)) {
@@ -982,17 +1028,12 @@ static void btree_node_prefetch(struct cache_set *c, struct bkey *k, int level)
 
 /* Btree alloc */
 
-static void btree_node_free(struct btree *b, struct btree_op *op)
+static void btree_node_free(struct btree *b)
 {
        unsigned i;
 
        trace_bcache_btree_node_free(b);
 
-       /*
-        * The BUG_ON() in btree_node_get() implies that we must have a write
-        * lock on parent to free or even invalidate a node
-        */
-       BUG_ON(op->lock <= b->level);
        BUG_ON(b == b->c->root);
 
        if (btree_node_dirty(b))
@@ -1015,27 +1056,26 @@ static void btree_node_free(struct btree *b, struct btree_op *op)
        mutex_unlock(&b->c->bucket_lock);
 }
 
-struct btree *bch_btree_node_alloc(struct cache_set *c, int level,
-                                  struct closure *cl)
+struct btree *bch_btree_node_alloc(struct cache_set *c, int level, bool wait)
 {
        BKEY_PADDED(key) k;
        struct btree *b = ERR_PTR(-EAGAIN);
 
        mutex_lock(&c->bucket_lock);
 retry:
-       if (__bch_bucket_alloc_set(c, WATERMARK_METADATA, &k.key, 1, cl))
+       if (__bch_bucket_alloc_set(c, WATERMARK_METADATA, &k.key, 1, wait))
                goto err;
 
+       bkey_put(c, &k.key);
        SET_KEY_SIZE(&k.key, c->btree_pages * PAGE_SECTORS);
 
-       b = mca_alloc(c, &k.key, level, cl);
+       b = mca_alloc(c, &k.key, level);
        if (IS_ERR(b))
                goto err_free;
 
        if (!b) {
                cache_bug(c,
                        "Tried to allocate bucket that was in btree cache");
-               __bkey_put(c, &k.key);
                goto retry;
        }
 
@@ -1048,7 +1088,6 @@ retry:
        return b;
 err_free:
        bch_bucket_free(c, &k.key);
-       __bkey_put(c, &k.key);
 err:
        mutex_unlock(&c->bucket_lock);
 
@@ -1056,16 +1095,31 @@ err:
        return b;
 }
 
-static struct btree *btree_node_alloc_replacement(struct btree *b,
-                                                 struct closure *cl)
+static struct btree *btree_node_alloc_replacement(struct btree *b, bool wait)
 {
-       struct btree *n = bch_btree_node_alloc(b->c, b->level, cl);
+       struct btree *n = bch_btree_node_alloc(b->c, b->level, wait);
        if (!IS_ERR_OR_NULL(n))
                bch_btree_sort_into(b, n);
 
        return n;
 }
 
+static void make_btree_freeing_key(struct btree *b, struct bkey *k)
+{
+       unsigned i;
+
+       bkey_copy(k, &b->key);
+       bkey_copy_key(k, &ZERO_KEY);
+
+       for (i = 0; i < KEY_PTRS(k); i++) {
+               uint8_t g = PTR_BUCKET(b->c, k, i)->gen + 1;
+
+               SET_PTR_GEN(k, i, g);
+       }
+
+       atomic_inc(&b->c->prio_blocked);
+}
+
 /* Garbage collection */
 
 uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k)
@@ -1119,12 +1173,10 @@ uint8_t __bch_btree_mark_key(struct cache_set *c, int level, struct bkey *k)
 
 #define btree_mark_key(b, k)   __bch_btree_mark_key(b->c, b->level, k)
 
-static int btree_gc_mark_node(struct btree *b, unsigned *keys,
-                             struct gc_stat *gc)
+static bool btree_gc_mark_node(struct btree *b, struct gc_stat *gc)
 {
        uint8_t stale = 0;
-       unsigned last_dev = -1;
-       struct bcache_device *d = NULL;
+       unsigned keys = 0, good_keys = 0;
        struct bkey *k;
        struct btree_iter iter;
        struct bset_tree *t;
@@ -1132,27 +1184,17 @@ static int btree_gc_mark_node(struct btree *b, unsigned *keys,
        gc->nodes++;
 
        for_each_key_filter(b, k, &iter, bch_ptr_invalid) {
-               if (last_dev != KEY_INODE(k)) {
-                       last_dev = KEY_INODE(k);
-
-                       d = KEY_INODE(k) < b->c->nr_uuids
-                               ? b->c->devices[last_dev]
-                               : NULL;
-               }
-
                stale = max(stale, btree_mark_key(b, k));
+               keys++;
 
                if (bch_ptr_bad(b, k))
                        continue;
 
-               *keys += bkey_u64s(k);
-
                gc->key_bytes += bkey_u64s(k);
                gc->nkeys++;
+               good_keys++;
 
                gc->data += KEY_SIZE(k);
-               if (KEY_DIRTY(k))
-                       gc->dirty += KEY_SIZE(k);
        }
 
        for (t = b->sets; t <= &b->sets[b->nsets]; t++)
@@ -1161,78 +1203,74 @@ static int btree_gc_mark_node(struct btree *b, unsigned *keys,
                             bkey_cmp(&b->key, &t->end) < 0,
                             b, "found short btree key in gc");
 
-       return stale;
-}
-
-static struct btree *btree_gc_alloc(struct btree *b, struct bkey *k,
-                                   struct btree_op *op)
-{
-       /*
-        * We block priorities from being written for the duration of garbage
-        * collection, so we can't sleep in btree_alloc() ->
-        * bch_bucket_alloc_set(), or we'd risk deadlock - so we don't pass it
-        * our closure.
-        */
-       struct btree *n = btree_node_alloc_replacement(b, NULL);
-
-       if (!IS_ERR_OR_NULL(n)) {
-               swap(b, n);
-               __bkey_put(b->c, &b->key);
+       if (b->c->gc_always_rewrite)
+               return true;
 
-               memcpy(k->ptr, b->key.ptr,
-                      sizeof(uint64_t) * KEY_PTRS(&b->key));
+       if (stale > 10)
+               return true;
 
-               btree_node_free(n, op);
-               up_write(&n->lock);
-       }
+       if ((keys - good_keys) * 2 > keys)
+               return true;
 
-       return b;
+       return false;
 }
 
-/*
- * Leaving this at 2 until we've got incremental garbage collection done; it
- * could be higher (and has been tested with 4) except that garbage collection
- * could take much longer, adversely affecting latency.
- */
-#define GC_MERGE_NODES 2U
+#define GC_MERGE_NODES 4U
 
 struct gc_merge_info {
        struct btree    *b;
-       struct bkey     *k;
        unsigned        keys;
 };
 
-static void btree_gc_coalesce(struct btree *b, struct btree_op *op,
-                             struct gc_stat *gc, struct gc_merge_info *r)
+static int bch_btree_insert_node(struct btree *, struct btree_op *,
+                                struct keylist *, atomic_t *, struct bkey *);
+
+static int btree_gc_coalesce(struct btree *b, struct btree_op *op,
+                            struct keylist *keylist, struct gc_stat *gc,
+                            struct gc_merge_info *r)
 {
-       unsigned nodes = 0, keys = 0, blocks;
-       int i;
+       unsigned i, nodes = 0, keys = 0, blocks;
+       struct btree *new_nodes[GC_MERGE_NODES];
+       struct closure cl;
+       struct bkey *k;
+
+       memset(new_nodes, 0, sizeof(new_nodes));
+       closure_init_stack(&cl);
 
-       while (nodes < GC_MERGE_NODES && r[nodes].b)
+       while (nodes < GC_MERGE_NODES && !IS_ERR_OR_NULL(r[nodes].b))
                keys += r[nodes++].keys;
 
        blocks = btree_default_blocks(b->c) * 2 / 3;
 
        if (nodes < 2 ||
            __set_blocks(b->sets[0].data, keys, b->c) > blocks * (nodes - 1))
-               return;
-
-       for (i = nodes - 1; i >= 0; --i) {
-               if (r[i].b->written)
-                       r[i].b = btree_gc_alloc(r[i].b, r[i].k, op);
+               return 0;
 
-               if (r[i].b->written)
-                       return;
+       for (i = 0; i < nodes; i++) {
+               new_nodes[i] = btree_node_alloc_replacement(r[i].b, false);
+               if (IS_ERR_OR_NULL(new_nodes[i]))
+                       goto out_nocoalesce;
        }
 
        for (i = nodes - 1; i > 0; --i) {
-               struct bset *n1 = r[i].b->sets->data;
-               struct bset *n2 = r[i - 1].b->sets->data;
+               struct bset *n1 = new_nodes[i]->sets->data;
+               struct bset *n2 = new_nodes[i - 1]->sets->data;
                struct bkey *k, *last = NULL;
 
                keys = 0;
 
-               if (i == 1) {
+               if (i > 1) {
+                       for (k = n2->start;
+                            k < end(n2);
+                            k = bkey_next(k)) {
+                               if (__set_blocks(n1, n1->keys + keys +
+                                                bkey_u64s(k), b->c) > blocks)
+                                       break;
+
+                               last = k;
+                               keys += bkey_u64s(k);
+                       }
+               } else {
                        /*
                         * Last node we're not getting rid of - we're getting
                         * rid of the node at r[0]. Have to try and fit all of
@@ -1241,37 +1279,27 @@ static void btree_gc_coalesce(struct btree *b, struct btree_op *op,
                         * length keys (shouldn't be possible in practice,
                         * though)
                         */
-                       if (__set_blocks(n1, n1->keys + r->keys,
-                                        b->c) > btree_blocks(r[i].b))
-                               return;
+                       if (__set_blocks(n1, n1->keys + n2->keys,
+                                        b->c) > btree_blocks(new_nodes[i]))
+                               goto out_nocoalesce;
 
                        keys = n2->keys;
+                       /* Take the key of the node we're getting rid of */
                        last = &r->b->key;
-               } else
-                       for (k = n2->start;
-                            k < end(n2);
-                            k = bkey_next(k)) {
-                               if (__set_blocks(n1, n1->keys + keys +
-                                                bkey_u64s(k), b->c) > blocks)
-                                       break;
-
-                               last = k;
-                               keys += bkey_u64s(k);
-                       }
+               }
 
                BUG_ON(__set_blocks(n1, n1->keys + keys,
-                                   b->c) > btree_blocks(r[i].b));
+                                   b->c) > btree_blocks(new_nodes[i]));
 
-               if (last) {
-                       bkey_copy_key(&r[i].b->key, last);
-                       bkey_copy_key(r[i].k, last);
-               }
+               if (last)
+                       bkey_copy_key(&new_nodes[i]->key, last);
 
                memcpy(end(n1),
                       n2->start,
                       (void *) node(n2, keys) - (void *) n2->start);
 
                n1->keys += keys;
+               r[i].keys = n1->keys;
 
                memmove(n2->start,
                        node(n2, keys),
@@ -1279,95 +1307,176 @@ static void btree_gc_coalesce(struct btree *b, struct btree_op *op,
 
                n2->keys -= keys;
 
-               r[i].keys       = n1->keys;
-               r[i - 1].keys   = n2->keys;
+               if (bch_keylist_realloc(keylist,
+                                       KEY_PTRS(&new_nodes[i]->key), b->c))
+                       goto out_nocoalesce;
+
+               bch_btree_node_write(new_nodes[i], &cl);
+               bch_keylist_add(keylist, &new_nodes[i]->key);
        }
 
-       btree_node_free(r->b, op);
-       up_write(&r->b->lock);
+       for (i = 0; i < nodes; i++) {
+               if (bch_keylist_realloc(keylist, KEY_PTRS(&r[i].b->key), b->c))
+                       goto out_nocoalesce;
 
-       trace_bcache_btree_gc_coalesce(nodes);
+               make_btree_freeing_key(r[i].b, keylist->top);
+               bch_keylist_push(keylist);
+       }
+
+       /* We emptied out this node */
+       BUG_ON(new_nodes[0]->sets->data->keys);
+       btree_node_free(new_nodes[0]);
+       rw_unlock(true, new_nodes[0]);
+
+       closure_sync(&cl);
+
+       for (i = 0; i < nodes; i++) {
+               btree_node_free(r[i].b);
+               rw_unlock(true, r[i].b);
+
+               r[i].b = new_nodes[i];
+       }
+
+       bch_btree_insert_node(b, op, keylist, NULL, NULL);
+       BUG_ON(!bch_keylist_empty(keylist));
+
+       memmove(r, r + 1, sizeof(r[0]) * (nodes - 1));
+       r[nodes - 1].b = ERR_PTR(-EINTR);
 
+       trace_bcache_btree_gc_coalesce(nodes);
        gc->nodes--;
-       nodes--;
 
-       memmove(&r[0], &r[1], sizeof(struct gc_merge_info) * nodes);
-       memset(&r[nodes], 0, sizeof(struct gc_merge_info));
+       /* Invalidated our iterator */
+       return -EINTR;
+
+out_nocoalesce:
+       closure_sync(&cl);
+
+       while ((k = bch_keylist_pop(keylist)))
+               if (!bkey_cmp(k, &ZERO_KEY))
+                       atomic_dec(&b->c->prio_blocked);
+
+       for (i = 0; i < nodes; i++)
+               if (!IS_ERR_OR_NULL(new_nodes[i])) {
+                       btree_node_free(new_nodes[i]);
+                       rw_unlock(true, new_nodes[i]);
+               }
+       return 0;
 }
 
-static int btree_gc_recurse(struct btree *b, struct btree_op *op,
-                           struct closure *writes, struct gc_stat *gc)
+static unsigned btree_gc_count_keys(struct btree *b)
 {
-       void write(struct btree *r)
-       {
-               if (!r->written)
-                       bch_btree_node_write(r, &op->cl);
-               else if (btree_node_dirty(r))
-                       bch_btree_node_write(r, writes);
+       struct bkey *k;
+       struct btree_iter iter;
+       unsigned ret = 0;
 
-               up_write(&r->lock);
-       }
+       for_each_key_filter(b, k, &iter, bch_ptr_bad)
+               ret += bkey_u64s(k);
+
+       return ret;
+}
 
-       int ret = 0, stale;
+static int btree_gc_recurse(struct btree *b, struct btree_op *op,
+                           struct closure *writes, struct gc_stat *gc)
+{
        unsigned i;
+       int ret = 0;
+       bool should_rewrite;
+       struct btree *n;
+       struct bkey *k;
+       struct keylist keys;
+       struct btree_iter iter;
        struct gc_merge_info r[GC_MERGE_NODES];
+       struct gc_merge_info *last = r + GC_MERGE_NODES - 1;
 
-       memset(r, 0, sizeof(r));
+       bch_keylist_init(&keys);
+       bch_btree_iter_init(b, &iter, &b->c->gc_done);
 
-       while ((r->k = bch_next_recurse_key(b, &b->c->gc_done))) {
-               r->b = bch_btree_node_get(b->c, r->k, b->level - 1, op);
+       for (i = 0; i < GC_MERGE_NODES; i++)
+               r[i].b = ERR_PTR(-EINTR);
 
-               if (IS_ERR(r->b)) {
-                       ret = PTR_ERR(r->b);
-                       break;
+       while (1) {
+               k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad);
+               if (k) {
+                       r->b = bch_btree_node_get(b->c, k, b->level - 1, true);
+                       if (IS_ERR(r->b)) {
+                               ret = PTR_ERR(r->b);
+                               break;
+                       }
+
+                       r->keys = btree_gc_count_keys(r->b);
+
+                       ret = btree_gc_coalesce(b, op, &keys, gc, r);
+                       if (ret)
+                               break;
                }
 
-               r->keys = 0;
-               stale = btree_gc_mark_node(r->b, &r->keys, gc);
+               if (!last->b)
+                       break;
 
-               if (!b->written &&
-                   (r->b->level || stale > 10 ||
-                    b->c->gc_always_rewrite))
-                       r->b = btree_gc_alloc(r->b, r->k, op);
+               if (!IS_ERR(last->b)) {
+                       should_rewrite = btree_gc_mark_node(last->b, gc);
+                       if (should_rewrite) {
+                               n = btree_node_alloc_replacement(last->b,
+                                                                false);
 
-               if (r->b->level)
-                       ret = btree_gc_recurse(r->b, op, writes, gc);
+                               if (!IS_ERR_OR_NULL(n)) {
+                                       bch_btree_node_write_sync(n);
+                                       bch_keylist_add(&keys, &n->key);
 
-               if (ret) {
-                       write(r->b);
-                       break;
-               }
+                                       make_btree_freeing_key(last->b,
+                                                              keys.top);
+                                       bch_keylist_push(&keys);
+
+                                       btree_node_free(last->b);
+
+                                       bch_btree_insert_node(b, op, &keys,
+                                                             NULL, NULL);
+                                       BUG_ON(!bch_keylist_empty(&keys));
 
-               bkey_copy_key(&b->c->gc_done, r->k);
+                                       rw_unlock(true, last->b);
+                                       last->b = n;
 
-               if (!b->written)
-                       btree_gc_coalesce(b, op, gc, r);
+                                       /* Invalidated our iterator */
+                                       ret = -EINTR;
+                                       break;
+                               }
+                       }
 
-               if (r[GC_MERGE_NODES - 1].b)
-                       write(r[GC_MERGE_NODES - 1].b);
+                       if (last->b->level) {
+                               ret = btree_gc_recurse(last->b, op, writes, gc);
+                               if (ret)
+                                       break;
+                       }
 
-               memmove(&r[1], &r[0],
-                       sizeof(struct gc_merge_info) * (GC_MERGE_NODES - 1));
+                       bkey_copy_key(&b->c->gc_done, &last->b->key);
+
+                       /*
+                        * Must flush leaf nodes before gc ends, since replace
+                        * operations aren't journalled
+                        */
+                       if (btree_node_dirty(last->b))
+                               bch_btree_node_write(last->b, writes);
+                       rw_unlock(true, last->b);
+               }
+
+               memmove(r + 1, r, sizeof(r[0]) * (GC_MERGE_NODES - 1));
+               r->b = NULL;
 
-               /* When we've got incremental GC working, we'll want to do
-                * if (should_resched())
-                *      return -EAGAIN;
-                */
-               cond_resched();
-#if 0
                if (need_resched()) {
                        ret = -EAGAIN;
                        break;
                }
-#endif
        }
 
-       for (i = 1; i < GC_MERGE_NODES && r[i].b; i++)
-               write(r[i].b);
+       for (i = 0; i < GC_MERGE_NODES; i++)
+               if (!IS_ERR_OR_NULL(r[i].b)) {
+                       if (btree_node_dirty(r[i].b))
+                               bch_btree_node_write(r[i].b, writes);
+                       rw_unlock(true, r[i].b);
+               }
 
-       /* Might have freed some children, must remove their keys */
-       if (!b->written)
-               bch_btree_sort(b);
+       bch_keylist_free(&keys);
 
        return ret;
 }
@@ -1376,29 +1485,31 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op,
                             struct closure *writes, struct gc_stat *gc)
 {
        struct btree *n = NULL;
-       unsigned keys = 0;
-       int ret = 0, stale = btree_gc_mark_node(b, &keys, gc);
-
-       if (b->level || stale > 10)
-               n = btree_node_alloc_replacement(b, NULL);
+       int ret = 0;
+       bool should_rewrite;
 
-       if (!IS_ERR_OR_NULL(n))
-               swap(b, n);
+       should_rewrite = btree_gc_mark_node(b, gc);
+       if (should_rewrite) {
+               n = btree_node_alloc_replacement(b, false);
 
-       if (b->level)
-               ret = btree_gc_recurse(b, op, writes, gc);
+               if (!IS_ERR_OR_NULL(n)) {
+                       bch_btree_node_write_sync(n);
+                       bch_btree_set_root(n);
+                       btree_node_free(b);
+                       rw_unlock(true, n);
 
-       if (!b->written || btree_node_dirty(b)) {
-               bch_btree_node_write(b, n ? &op->cl : NULL);
+                       return -EINTR;
+               }
        }
 
-       if (!IS_ERR_OR_NULL(n)) {
-               closure_sync(&op->cl);
-               bch_btree_set_root(b);
-               btree_node_free(n, op);
-               rw_unlock(true, b);
+       if (b->level) {
+               ret = btree_gc_recurse(b, op, writes, gc);
+               if (ret)
+                       return ret;
        }
 
+       bkey_copy_key(&b->c->gc_done, &b->key);
+
        return ret;
 }
 
@@ -1479,9 +1590,8 @@ size_t bch_btree_gc_finish(struct cache_set *c)
        return available;
 }
 
-static void bch_btree_gc(struct closure *cl)
+static void bch_btree_gc(struct cache_set *c)
 {
-       struct cache_set *c = container_of(cl, struct cache_set, gc.cl);
        int ret;
        unsigned long available;
        struct gc_stat stats;
@@ -1493,47 +1603,73 @@ static void bch_btree_gc(struct closure *cl)
 
        memset(&stats, 0, sizeof(struct gc_stat));
        closure_init_stack(&writes);
-       bch_btree_op_init_stack(&op);
-       op.lock = SHRT_MAX;
+       bch_btree_op_init(&op, SHRT_MAX);
 
        btree_gc_start(c);
 
-       atomic_inc(&c->prio_blocked);
-
-       ret = btree_root(gc_root, c, &op, &writes, &stats);
-       closure_sync(&op.cl);
-       closure_sync(&writes);
-
-       if (ret) {
-               pr_warn("gc failed!");
-               continue_at(cl, bch_btree_gc, bch_gc_wq);
-       }
+       do {
+               ret = btree_root(gc_root, c, &op, &writes, &stats);
+               closure_sync(&writes);
 
-       /* Possibly wait for new UUIDs or whatever to hit disk */
-       bch_journal_meta(c, &op.cl);
-       closure_sync(&op.cl);
+               if (ret && ret != -EAGAIN)
+                       pr_warn("gc failed!");
+       } while (ret);
 
        available = bch_btree_gc_finish(c);
-
-       atomic_dec(&c->prio_blocked);
        wake_up_allocators(c);
 
        bch_time_stats_update(&c->btree_gc_time, start_time);
 
        stats.key_bytes *= sizeof(uint64_t);
-       stats.dirty     <<= 9;
        stats.data      <<= 9;
        stats.in_use    = (c->nbuckets - available) * 100 / c->nbuckets;
        memcpy(&c->gc_stats, &stats, sizeof(struct gc_stat));
 
        trace_bcache_gc_end(c);
 
-       continue_at(cl, bch_moving_gc, bch_gc_wq);
+       bch_moving_gc(c);
+}
+
+static int bch_gc_thread(void *arg)
+{
+       struct cache_set *c = arg;
+       struct cache *ca;
+       unsigned i;
+
+       while (1) {
+again:
+               bch_btree_gc(c);
+
+               set_current_state(TASK_INTERRUPTIBLE);
+               if (kthread_should_stop())
+                       break;
+
+               mutex_lock(&c->bucket_lock);
+
+               for_each_cache(ca, c, i)
+                       if (ca->invalidate_needs_gc) {
+                               mutex_unlock(&c->bucket_lock);
+                               set_current_state(TASK_RUNNING);
+                               goto again;
+                       }
+
+               mutex_unlock(&c->bucket_lock);
+
+               try_to_freeze();
+               schedule();
+       }
+
+       return 0;
 }
 
-void bch_queue_gc(struct cache_set *c)
+int bch_gc_thread_start(struct cache_set *c)
 {
-       closure_trylock_call(&c->gc.cl, bch_btree_gc, bch_gc_wq, &c->cl);
+       c->gc_thread = kthread_create(bch_gc_thread, c, "bcache_gc");
+       if (IS_ERR(c->gc_thread))
+               return PTR_ERR(c->gc_thread);
+
+       set_task_state(c->gc_thread, TASK_INTERRUPTIBLE);
+       return 0;
 }
 
 /* Initial partial gc */
@@ -1541,9 +1677,9 @@ void bch_queue_gc(struct cache_set *c)
 static int bch_btree_check_recurse(struct btree *b, struct btree_op *op,
                                   unsigned long **seen)
 {
-       int ret;
+       int ret = 0;
        unsigned i;
-       struct bkey *k;
+       struct bkey *k, *p = NULL;
        struct bucket *g;
        struct btree_iter iter;
 
@@ -1570,31 +1706,32 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op,
        }
 
        if (b->level) {
-               k = bch_next_recurse_key(b, &ZERO_KEY);
+               bch_btree_iter_init(b, &iter, NULL);
 
-               while (k) {
-                       struct bkey *p = bch_next_recurse_key(b, k);
-                       if (p)
-                               btree_node_prefetch(b->c, p, b->level - 1);
+               do {
+                       k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad);
+                       if (k)
+                               btree_node_prefetch(b->c, k, b->level - 1);
 
-                       ret = btree(check_recurse, k, b, op, seen);
-                       if (ret)
-                               return ret;
+                       if (p)
+                               ret = btree(check_recurse, p, b, op, seen);
 
-                       k = p;
-               }
+                       p = k;
+               } while (p && !ret);
        }
 
        return 0;
 }
 
-int bch_btree_check(struct cache_set *c, struct btree_op *op)
+int bch_btree_check(struct cache_set *c)
 {
        int ret = -ENOMEM;
        unsigned i;
        unsigned long *seen[MAX_CACHES_PER_SET];
+       struct btree_op op;
 
        memset(seen, 0, sizeof(seen));
+       bch_btree_op_init(&op, SHRT_MAX);
 
        for (i = 0; c->cache[i]; i++) {
                size_t n = DIV_ROUND_UP(c->cache[i]->sb.nbuckets, 8);
@@ -1606,7 +1743,7 @@ int bch_btree_check(struct cache_set *c, struct btree_op *op)
                memset(seen[i], 0xFF, n);
        }
 
-       ret = btree_root(check_recurse, c, op, seen);
+       ret = btree_root(check_recurse, c, &op, seen);
 err:
        for (i = 0; i < MAX_CACHES_PER_SET; i++)
                kfree(seen[i]);
@@ -1628,10 +1765,9 @@ static void shift_keys(struct btree *b, struct bkey *where, struct bkey *insert)
        bch_bset_fix_lookup_table(b, where);
 }
 
-static bool fix_overlapping_extents(struct btree *b,
-                                   struct bkey *insert,
+static bool fix_overlapping_extents(struct btree *b, struct bkey *insert,
                                    struct btree_iter *iter,
-                                   struct btree_op *op)
+                                   struct bkey *replace_key)
 {
        void subtract_dirty(struct bkey *k, uint64_t offset, int sectors)
        {
@@ -1659,39 +1795,38 @@ static bool fix_overlapping_extents(struct btree *b,
                 * We might overlap with 0 size extents; we can't skip these
                 * because if they're in the set we're inserting to we have to
                 * adjust them so they don't overlap with the key we're
-                * inserting. But we don't want to check them for BTREE_REPLACE
+                * inserting. But we don't want to check them for replace
                 * operations.
                 */
 
-               if (op->type == BTREE_REPLACE &&
-                   KEY_SIZE(k)) {
+               if (replace_key && KEY_SIZE(k)) {
                        /*
                         * k might have been split since we inserted/found the
                         * key we're replacing
                         */
                        unsigned i;
                        uint64_t offset = KEY_START(k) -
-                               KEY_START(&op->replace);
+                               KEY_START(replace_key);
 
                        /* But it must be a subset of the replace key */
-                       if (KEY_START(k) < KEY_START(&op->replace) ||
-                           KEY_OFFSET(k) > KEY_OFFSET(&op->replace))
+                       if (KEY_START(k) < KEY_START(replace_key) ||
+                           KEY_OFFSET(k) > KEY_OFFSET(replace_key))
                                goto check_failed;
 
                        /* We didn't find a key that we were supposed to */
                        if (KEY_START(k) > KEY_START(insert) + sectors_found)
                                goto check_failed;
 
-                       if (KEY_PTRS(&op->replace) != KEY_PTRS(k))
+                       if (KEY_PTRS(replace_key) != KEY_PTRS(k))
                                goto check_failed;
 
                        /* skip past gen */
                        offset <<= 8;
 
-                       BUG_ON(!KEY_PTRS(&op->replace));
+                       BUG_ON(!KEY_PTRS(replace_key));
 
-                       for (i = 0; i < KEY_PTRS(&op->replace); i++)
-                               if (k->ptr[i] != op->replace.ptr[i] + offset)
+                       for (i = 0; i < KEY_PTRS(replace_key); i++)
+                               if (k->ptr[i] != replace_key->ptr[i] + offset)
                                        goto check_failed;
 
                        sectors_found = KEY_OFFSET(k) - KEY_START(insert);
@@ -1742,6 +1877,9 @@ static bool fix_overlapping_extents(struct btree *b,
                if (bkey_cmp(insert, k) < 0) {
                        bch_cut_front(insert, k);
                } else {
+                       if (bkey_cmp(&START_KEY(insert), &START_KEY(k)) > 0)
+                               old_offset = KEY_START(insert);
+
                        if (bkey_written(b, k) &&
                            bkey_cmp(&START_KEY(insert), &START_KEY(k)) <= 0) {
                                /*
@@ -1759,9 +1897,8 @@ static bool fix_overlapping_extents(struct btree *b,
        }
 
 check_failed:
-       if (op->type == BTREE_REPLACE) {
+       if (replace_key) {
                if (!sectors_found) {
-                       op->insert_collision = true;
                        return true;
                } else if (sectors_found < KEY_SIZE(insert)) {
                        SET_KEY_OFFSET(insert, KEY_OFFSET(insert) -
@@ -1774,7 +1911,7 @@ check_failed:
 }
 
 static bool btree_insert_key(struct btree *b, struct btree_op *op,
-                            struct bkey *k)
+                            struct bkey *k, struct bkey *replace_key)
 {
        struct bset *i = b->sets[b->nsets].data;
        struct bkey *m, *prev;
@@ -1786,22 +1923,23 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
 
        if (!b->level) {
                struct btree_iter iter;
-               struct bkey search = KEY(KEY_INODE(k), KEY_START(k), 0);
 
                /*
                 * bset_search() returns the first key that is strictly greater
                 * than the search key - but for back merging, we want to find
-                * the first key that is greater than or equal to KEY_START(k) -
-                * unless KEY_START(k) is 0.
+                * the previous key.
                 */
-               if (KEY_OFFSET(&search))
-                       SET_KEY_OFFSET(&search, KEY_OFFSET(&search) - 1);
-
                prev = NULL;
-               m = bch_btree_iter_init(b, &iter, &search);
+               m = bch_btree_iter_init(b, &iter, PRECEDING_KEY(&START_KEY(k)));
 
-               if (fix_overlapping_extents(b, k, &iter, op))
+               if (fix_overlapping_extents(b, k, &iter, replace_key)) {
+                       op->insert_collision = true;
                        return false;
+               }
+
+               if (KEY_DIRTY(k))
+                       bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k),
+                                                    KEY_START(k), KEY_SIZE(k));
 
                while (m != end(i) &&
                       bkey_cmp(k, &START_KEY(m)) > 0)
@@ -1825,84 +1963,80 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
                if (m != end(i) &&
                    bch_bkey_try_merge(b, k, m))
                        goto copy;
-       } else
+       } else {
+               BUG_ON(replace_key);
                m = bch_bset_search(b, &b->sets[b->nsets], k);
+       }
 
 insert:        shift_keys(b, m, k);
 copy:  bkey_copy(m, k);
 merged:
-       if (KEY_DIRTY(k))
-               bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k),
-                                            KEY_START(k), KEY_SIZE(k));
-
-       bch_check_keys(b, "%u for %s", status, op_type(op));
+       bch_check_keys(b, "%u for %s", status,
+                      replace_key ? "replace" : "insert");
 
        if (b->level && !KEY_OFFSET(k))
                btree_current_write(b)->prio_blocked++;
 
-       trace_bcache_btree_insert_key(b, k, op->type, status);
+       trace_bcache_btree_insert_key(b, k, replace_key != NULL, status);
 
        return true;
 }
 
-static bool bch_btree_insert_keys(struct btree *b, struct btree_op *op)
+static bool bch_btree_insert_keys(struct btree *b, struct btree_op *op,
+                                 struct keylist *insert_keys,
+                                 struct bkey *replace_key)
 {
        bool ret = false;
-       struct bkey *k;
-       unsigned oldsize = bch_count_data(b);
-
-       while ((k = bch_keylist_pop(&op->keys))) {
-               bkey_put(b->c, k, b->level);
-               ret |= btree_insert_key(b, op, k);
-       }
-
-       BUG_ON(bch_count_data(b) < oldsize);
-       return ret;
-}
+       int oldsize = bch_count_data(b);
 
-bool bch_btree_insert_check_key(struct btree *b, struct btree_op *op,
-                                  struct bio *bio)
-{
-       bool ret = false;
-       uint64_t btree_ptr = b->key.ptr[0];
-       unsigned long seq = b->seq;
-       BKEY_PADDED(k) tmp;
+       while (!bch_keylist_empty(insert_keys)) {
+               struct bset *i = write_block(b);
+               struct bkey *k = insert_keys->keys;
 
-       rw_unlock(false, b);
-       rw_lock(true, b, b->level);
+               if (b->written + __set_blocks(i, i->keys + bkey_u64s(k), b->c)
+                   > btree_blocks(b))
+                       break;
 
-       if (b->key.ptr[0] != btree_ptr ||
-           b->seq != seq + 1 ||
-           should_split(b))
-               goto out;
+               if (bkey_cmp(k, &b->key) <= 0) {
+                       if (!b->level)
+                               bkey_put(b->c, k);
 
-       op->replace = KEY(op->inode, bio_end_sector(bio), bio_sectors(bio));
+                       ret |= btree_insert_key(b, op, k, replace_key);
+                       bch_keylist_pop_front(insert_keys);
+               } else if (bkey_cmp(&START_KEY(k), &b->key) < 0) {
+                       BKEY_PADDED(key) temp;
+                       bkey_copy(&temp.key, insert_keys->keys);
 
-       SET_KEY_PTRS(&op->replace, 1);
-       get_random_bytes(&op->replace.ptr[0], sizeof(uint64_t));
+                       bch_cut_back(&b->key, &temp.key);
+                       bch_cut_front(&b->key, insert_keys->keys);
 
-       SET_PTR_DEV(&op->replace, 0, PTR_CHECK_DEV);
+                       ret |= btree_insert_key(b, op, &temp.key, replace_key);
+                       break;
+               } else {
+                       break;
+               }
+       }
 
-       bkey_copy(&tmp.k, &op->replace);
+       BUG_ON(!bch_keylist_empty(insert_keys) && b->level);
 
-       BUG_ON(op->type != BTREE_INSERT);
-       BUG_ON(!btree_insert_key(b, op, &tmp.k));
-       ret = true;
-out:
-       downgrade_write(&b->lock);
+       BUG_ON(bch_count_data(b) < oldsize);
        return ret;
 }
 
-static int btree_split(struct btree *b, struct btree_op *op)
+static int btree_split(struct btree *b, struct btree_op *op,
+                      struct keylist *insert_keys,
+                      struct bkey *replace_key)
 {
-       bool split, root = b == b->c->root;
+       bool split;
        struct btree *n1, *n2 = NULL, *n3 = NULL;
        uint64_t start_time = local_clock();
+       struct closure cl;
+       struct keylist parent_keys;
 
-       if (b->level)
-               set_closure_blocking(&op->cl);
+       closure_init_stack(&cl);
+       bch_keylist_init(&parent_keys);
 
-       n1 = btree_node_alloc_replacement(b, &op->cl);
+       n1 = btree_node_alloc_replacement(b, true);
        if (IS_ERR(n1))
                goto err;
 
@@ -1913,19 +2047,20 @@ static int btree_split(struct btree *b, struct btree_op *op)
 
                trace_bcache_btree_node_split(b, n1->sets[0].data->keys);
 
-               n2 = bch_btree_node_alloc(b->c, b->level, &op->cl);
+               n2 = bch_btree_node_alloc(b->c, b->level, true);
                if (IS_ERR(n2))
                        goto err_free1;
 
-               if (root) {
-                       n3 = bch_btree_node_alloc(b->c, b->level + 1, &op->cl);
+               if (!b->parent) {
+                       n3 = bch_btree_node_alloc(b->c, b->level + 1, true);
                        if (IS_ERR(n3))
                                goto err_free2;
                }
 
-               bch_btree_insert_keys(n1, op);
+               bch_btree_insert_keys(n1, op, insert_keys, replace_key);
 
-               /* Has to be a linear search because we don't have an auxiliary
+               /*
+                * Has to be a linear search because we don't have an auxiliary
                 * search tree yet
                 */
 
@@ -1944,60 +2079,57 @@ static int btree_split(struct btree *b, struct btree_op *op)
 
                bkey_copy_key(&n2->key, &b->key);
 
-               bch_keylist_add(&op->keys, &n2->key);
-               bch_btree_node_write(n2, &op->cl);
+               bch_keylist_add(&parent_keys, &n2->key);
+               bch_btree_node_write(n2, &cl);
                rw_unlock(true, n2);
        } else {
                trace_bcache_btree_node_compact(b, n1->sets[0].data->keys);
 
-               bch_btree_insert_keys(n1, op);
+               bch_btree_insert_keys(n1, op, insert_keys, replace_key);
        }
 
-       bch_keylist_add(&op->keys, &n1->key);
-       bch_btree_node_write(n1, &op->cl);
+       bch_keylist_add(&parent_keys, &n1->key);
+       bch_btree_node_write(n1, &cl);
 
        if (n3) {
+               /* Depth increases, make a new root */
                bkey_copy_key(&n3->key, &MAX_KEY);
-               bch_btree_insert_keys(n3, op);
-               bch_btree_node_write(n3, &op->cl);
+               bch_btree_insert_keys(n3, op, &parent_keys, NULL);
+               bch_btree_node_write(n3, &cl);
 
-               closure_sync(&op->cl);
+               closure_sync(&cl);
                bch_btree_set_root(n3);
                rw_unlock(true, n3);
-       } else if (root) {
-               op->keys.top = op->keys.bottom;
-               closure_sync(&op->cl);
-               bch_btree_set_root(n1);
-       } else {
-               unsigned i;
 
-               bkey_copy(op->keys.top, &b->key);
-               bkey_copy_key(op->keys.top, &ZERO_KEY);
+               btree_node_free(b);
+       } else if (!b->parent) {
+               /* Root filled up but didn't need to be split */
+               closure_sync(&cl);
+               bch_btree_set_root(n1);
 
-               for (i = 0; i < KEY_PTRS(&b->key); i++) {
-                       uint8_t g = PTR_BUCKET(b->c, &b->key, i)->gen + 1;
+               btree_node_free(b);
+       } else {
+               /* Split a non root node */
+               closure_sync(&cl);
+               make_btree_freeing_key(b, parent_keys.top);
+               bch_keylist_push(&parent_keys);
 
-                       SET_PTR_GEN(op->keys.top, i, g);
-               }
+               btree_node_free(b);
 
-               bch_keylist_push(&op->keys);
-               closure_sync(&op->cl);
-               atomic_inc(&b->c->prio_blocked);
+               bch_btree_insert_node(b->parent, op, &parent_keys, NULL, NULL);
+               BUG_ON(!bch_keylist_empty(&parent_keys));
        }
 
        rw_unlock(true, n1);
-       btree_node_free(b, op);
 
        bch_time_stats_update(&b->c->btree_split_time, start_time);
 
        return 0;
 err_free2:
-       __bkey_put(n2->c, &n2->key);
-       btree_node_free(n2, op);
+       btree_node_free(n2);
        rw_unlock(true, n2);
 err_free1:
-       __bkey_put(n1->c, &n1->key);
-       btree_node_free(n1, op);
+       btree_node_free(n1);
        rw_unlock(true, n1);
 err:
        if (n3 == ERR_PTR(-EAGAIN) ||
@@ -2009,116 +2141,126 @@ err:
        return -ENOMEM;
 }
 
-static int bch_btree_insert_recurse(struct btree *b, struct btree_op *op,
-                                   struct keylist *stack_keys)
+static int bch_btree_insert_node(struct btree *b, struct btree_op *op,
+                                struct keylist *insert_keys,
+                                atomic_t *journal_ref,
+                                struct bkey *replace_key)
 {
-       if (b->level) {
-               int ret;
-               struct bkey *insert = op->keys.bottom;
-               struct bkey *k = bch_next_recurse_key(b, &START_KEY(insert));
-
-               if (!k) {
-                       btree_bug(b, "no key to recurse on at level %i/%i",
-                                 b->level, b->c->root->level);
+       BUG_ON(b->level && replace_key);
 
-                       op->keys.top = op->keys.bottom;
-                       return -EIO;
+       if (should_split(b)) {
+               if (current->bio_list) {
+                       op->lock = b->c->root->level + 1;
+                       return -EAGAIN;
+               } else if (op->lock <= b->c->root->level) {
+                       op->lock = b->c->root->level + 1;
+                       return -EINTR;
+               } else {
+                       /* Invalidated all iterators */
+                       return btree_split(b, op, insert_keys, replace_key) ?:
+                               -EINTR;
                }
+       } else {
+               BUG_ON(write_block(b) != b->sets[b->nsets].data);
 
-               if (bkey_cmp(insert, k) > 0) {
-                       unsigned i;
-
-                       if (op->type == BTREE_REPLACE) {
-                               __bkey_put(b->c, insert);
-                               op->keys.top = op->keys.bottom;
-                               op->insert_collision = true;
-                               return 0;
-                       }
+               if (bch_btree_insert_keys(b, op, insert_keys, replace_key)) {
+                       if (!b->level)
+                               bch_btree_leaf_dirty(b, journal_ref);
+                       else
+                               bch_btree_node_write_sync(b);
+               }
 
-                       for (i = 0; i < KEY_PTRS(insert); i++)
-                               atomic_inc(&PTR_BUCKET(b->c, insert, i)->pin);
+               return 0;
+       }
+}
 
-                       bkey_copy(stack_keys->top, insert);
+int bch_btree_insert_check_key(struct btree *b, struct btree_op *op,
+                              struct bkey *check_key)
+{
+       int ret = -EINTR;
+       uint64_t btree_ptr = b->key.ptr[0];
+       unsigned long seq = b->seq;
+       struct keylist insert;
+       bool upgrade = op->lock == -1;
 
-                       bch_cut_back(k, insert);
-                       bch_cut_front(k, stack_keys->top);
+       bch_keylist_init(&insert);
 
-                       bch_keylist_push(stack_keys);
-               }
+       if (upgrade) {
+               rw_unlock(false, b);
+               rw_lock(true, b, b->level);
 
-               ret = btree(insert_recurse, k, b, op, stack_keys);
-               if (ret)
-                       return ret;
+               if (b->key.ptr[0] != btree_ptr ||
+                   b->seq != seq + 1)
+                       goto out;
        }
 
-       if (!bch_keylist_empty(&op->keys)) {
-               if (should_split(b)) {
-                       if (op->lock <= b->c->root->level) {
-                               BUG_ON(b->level);
-                               op->lock = b->c->root->level + 1;
-                               return -EINTR;
-                       }
-                       return btree_split(b, op);
-               }
+       SET_KEY_PTRS(check_key, 1);
+       get_random_bytes(&check_key->ptr[0], sizeof(uint64_t));
 
-               BUG_ON(write_block(b) != b->sets[b->nsets].data);
+       SET_PTR_DEV(check_key, 0, PTR_CHECK_DEV);
 
-               if (bch_btree_insert_keys(b, op)) {
-                       if (!b->level)
-                               bch_btree_leaf_dirty(b, op);
-                       else
-                               bch_btree_node_write(b, &op->cl);
-               }
-       }
+       bch_keylist_add(&insert, check_key);
 
-       return 0;
+       ret = bch_btree_insert_node(b, op, &insert, NULL, NULL);
+
+       BUG_ON(!ret && !bch_keylist_empty(&insert));
+out:
+       if (upgrade)
+               downgrade_write(&b->lock);
+       return ret;
 }
 
-int bch_btree_insert(struct btree_op *op, struct cache_set *c)
+struct btree_insert_op {
+       struct btree_op op;
+       struct keylist  *keys;
+       atomic_t        *journal_ref;
+       struct bkey     *replace_key;
+};
+
+int btree_insert_fn(struct btree_op *b_op, struct btree *b)
 {
-       int ret = 0;
-       struct keylist stack_keys;
+       struct btree_insert_op *op = container_of(b_op,
+                                       struct btree_insert_op, op);
 
-       /*
-        * Don't want to block with the btree locked unless we have to,
-        * otherwise we get deadlocks with try_harder and between split/gc
-        */
-       clear_closure_blocking(&op->cl);
-
-       BUG_ON(bch_keylist_empty(&op->keys));
-       bch_keylist_copy(&stack_keys, &op->keys);
-       bch_keylist_init(&op->keys);
-
-       while (!bch_keylist_empty(&stack_keys) ||
-              !bch_keylist_empty(&op->keys)) {
-               if (bch_keylist_empty(&op->keys)) {
-                       bch_keylist_add(&op->keys,
-                                       bch_keylist_pop(&stack_keys));
-                       op->lock = 0;
-               }
+       int ret = bch_btree_insert_node(b, &op->op, op->keys,
+                                       op->journal_ref, op->replace_key);
+       if (ret && !bch_keylist_empty(op->keys))
+               return ret;
+       else
+               return MAP_DONE;
+}
 
-               ret = btree_root(insert_recurse, c, op, &stack_keys);
+int bch_btree_insert(struct cache_set *c, struct keylist *keys,
+                    atomic_t *journal_ref, struct bkey *replace_key)
+{
+       struct btree_insert_op op;
+       int ret = 0;
 
-               if (ret == -EAGAIN) {
-                       ret = 0;
-                       closure_sync(&op->cl);
-               } else if (ret) {
-                       struct bkey *k;
+       BUG_ON(current->bio_list);
+       BUG_ON(bch_keylist_empty(keys));
+
+       bch_btree_op_init(&op.op, 0);
+       op.keys         = keys;
+       op.journal_ref  = journal_ref;
+       op.replace_key  = replace_key;
+
+       while (!ret && !bch_keylist_empty(keys)) {
+               op.op.lock = 0;
+               ret = bch_btree_map_leaf_nodes(&op.op, c,
+                                              &START_KEY(keys->keys),
+                                              btree_insert_fn);
+       }
 
-                       pr_err("error %i trying to insert key for %s",
-                              ret, op_type(op));
+       if (ret) {
+               struct bkey *k;
 
-                       while ((k = bch_keylist_pop(&stack_keys) ?:
-                                   bch_keylist_pop(&op->keys)))
-                               bkey_put(c, k, 0);
-               }
-       }
+               pr_err("error %i", ret);
 
-       bch_keylist_free(&stack_keys);
+               while ((k = bch_keylist_pop(keys)))
+                       bkey_put(c, k);
+       } else if (op.op.insert_collision)
+               ret = -ESRCH;
 
-       if (op->journal)
-               atomic_dec_bug(op->journal);
-       op->journal = NULL;
        return ret;
 }
 
@@ -2141,132 +2283,81 @@ void bch_btree_set_root(struct btree *b)
        mutex_unlock(&b->c->bucket_lock);
 
        b->c->root = b;
-       __bkey_put(b->c, &b->key);
 
        bch_journal_meta(b->c, &cl);
        closure_sync(&cl);
 }
 
-/* Cache lookup */
+/* Map across nodes or keys */
 
-static int submit_partial_cache_miss(struct btree *b, struct btree_op *op,
-                                    struct bkey *k)
+static int bch_btree_map_nodes_recurse(struct btree *b, struct btree_op *op,
+                                      struct bkey *from,
+                                      btree_map_nodes_fn *fn, int flags)
 {
-       struct search *s = container_of(op, struct search, op);
-       struct bio *bio = &s->bio.bio;
-       int ret = 0;
+       int ret = MAP_CONTINUE;
+
+       if (b->level) {
+               struct bkey *k;
+               struct btree_iter iter;
 
-       while (!ret &&
-              !op->lookup_done) {
-               unsigned sectors = INT_MAX;
+               bch_btree_iter_init(b, &iter, from);
 
-               if (KEY_INODE(k) == op->inode) {
-                       if (KEY_START(k) <= bio->bi_sector)
-                               break;
+               while ((k = bch_btree_iter_next_filter(&iter, b,
+                                                      bch_ptr_bad))) {
+                       ret = btree(map_nodes_recurse, k, b,
+                                   op, from, fn, flags);
+                       from = NULL;
 
-                       sectors = min_t(uint64_t, sectors,
-                                       KEY_START(k) - bio->bi_sector);
+                       if (ret != MAP_CONTINUE)
+                               return ret;
                }
-
-               ret = s->d->cache_miss(b, s, bio, sectors);
        }
 
+       if (!b->level || flags == MAP_ALL_NODES)
+               ret = fn(op, b);
+
        return ret;
 }
 
-/*
- * Read from a single key, handling the initial cache miss if the key starts in
- * the middle of the bio
- */
-static int submit_partial_cache_hit(struct btree *b, struct btree_op *op,
-                                   struct bkey *k)
+int __bch_btree_map_nodes(struct btree_op *op, struct cache_set *c,
+                         struct bkey *from, btree_map_nodes_fn *fn, int flags)
 {
-       struct search *s = container_of(op, struct search, op);
-       struct bio *bio = &s->bio.bio;
-       unsigned ptr;
-       struct bio *n;
-
-       int ret = submit_partial_cache_miss(b, op, k);
-       if (ret || op->lookup_done)
-               return ret;
-
-       /* XXX: figure out best pointer - for multiple cache devices */
-       ptr = 0;
-
-       PTR_BUCKET(b->c, k, ptr)->prio = INITIAL_PRIO;
-
-       while (!op->lookup_done &&
-              KEY_INODE(k) == op->inode &&
-              bio->bi_sector < KEY_OFFSET(k)) {
-               struct bkey *bio_key;
-               sector_t sector = PTR_OFFSET(k, ptr) +
-                       (bio->bi_sector - KEY_START(k));
-               unsigned sectors = min_t(uint64_t, INT_MAX,
-                                        KEY_OFFSET(k) - bio->bi_sector);
-
-               n = bch_bio_split(bio, sectors, GFP_NOIO, s->d->bio_split);
-               if (n == bio)
-                       op->lookup_done = true;
-
-               bio_key = &container_of(n, struct bbio, bio)->key;
-
-               /*
-                * The bucket we're reading from might be reused while our bio
-                * is in flight, and we could then end up reading the wrong
-                * data.
-                *
-                * We guard against this by checking (in cache_read_endio()) if
-                * the pointer is stale again; if so, we treat it as an error
-                * and reread from the backing device (but we don't pass that
-                * error up anywhere).
-                */
-
-               bch_bkey_copy_single_ptr(bio_key, k, ptr);
-               SET_PTR_OFFSET(bio_key, 0, sector);
-
-               n->bi_end_io    = bch_cache_read_endio;
-               n->bi_private   = &s->cl;
-
-               __bch_submit_bbio(n, b->c);
-       }
-
-       return 0;
+       return btree_root(map_nodes_recurse, c, op, from, fn, flags);
 }
 
-int bch_btree_search_recurse(struct btree *b, struct btree_op *op)
+static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
+                                     struct bkey *from, btree_map_keys_fn *fn,
+                                     int flags)
 {
-       struct search *s = container_of(op, struct search, op);
-       struct bio *bio = &s->bio.bio;
-
-       int ret = 0;
+       int ret = MAP_CONTINUE;
        struct bkey *k;
        struct btree_iter iter;
-       bch_btree_iter_init(b, &iter, &KEY(op->inode, bio->bi_sector, 0));
 
-       do {
-               k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad);
-               if (!k) {
-                       /*
-                        * b->key would be exactly what we want, except that
-                        * pointers to btree nodes have nonzero size - we
-                        * wouldn't go far enough
-                        */
+       bch_btree_iter_init(b, &iter, from);
 
-                       ret = submit_partial_cache_miss(b, op,
-                                       &KEY(KEY_INODE(&b->key),
-                                            KEY_OFFSET(&b->key), 0));
-                       break;
-               }
+       while ((k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad))) {
+               ret = !b->level
+                       ? fn(op, b, k)
+                       : btree(map_keys_recurse, k, b, op, from, fn, flags);
+               from = NULL;
+
+               if (ret != MAP_CONTINUE)
+                       return ret;
+       }
 
-               ret = b->level
-                       ? btree(search_recurse, k, b, op)
-                       : submit_partial_cache_hit(b, op, k);
-       } while (!ret &&
-                !op->lookup_done);
+       if (!b->level && (flags & MAP_END_KEY))
+               ret = fn(op, b, &KEY(KEY_INODE(&b->key),
+                                    KEY_OFFSET(&b->key), 0));
 
        return ret;
 }
 
+int bch_btree_map_keys(struct btree_op *op, struct cache_set *c,
+                      struct bkey *from, btree_map_keys_fn *fn, int flags)
+{
+       return btree_root(map_keys_recurse, c, op, from, fn, flags);
+}
+
 /* Keybuf code */
 
 static inline int keybuf_cmp(struct keybuf_key *l, struct keybuf_key *r)
@@ -2285,80 +2376,79 @@ static inline int keybuf_nonoverlapping_cmp(struct keybuf_key *l,
        return clamp_t(int64_t, bkey_cmp(&l->key, &r->key), -1, 1);
 }
 
-static int bch_btree_refill_keybuf(struct btree *b, struct btree_op *op,
-                                  struct keybuf *buf, struct bkey *end,
-                                  keybuf_pred_fn *pred)
-{
-       struct btree_iter iter;
-       bch_btree_iter_init(b, &iter, &buf->last_scanned);
-
-       while (!array_freelist_empty(&buf->freelist)) {
-               struct bkey *k = bch_btree_iter_next_filter(&iter, b,
-                                                           bch_ptr_bad);
-
-               if (!b->level) {
-                       if (!k) {
-                               buf->last_scanned = b->key;
-                               break;
-                       }
+struct refill {
+       struct btree_op op;
+       unsigned        nr_found;
+       struct keybuf   *buf;
+       struct bkey     *end;
+       keybuf_pred_fn  *pred;
+};
 
-                       buf->last_scanned = *k;
-                       if (bkey_cmp(&buf->last_scanned, end) >= 0)
-                               break;
+static int refill_keybuf_fn(struct btree_op *op, struct btree *b,
+                           struct bkey *k)
+{
+       struct refill *refill = container_of(op, struct refill, op);
+       struct keybuf *buf = refill->buf;
+       int ret = MAP_CONTINUE;
 
-                       if (pred(buf, k)) {
-                               struct keybuf_key *w;
+       if (bkey_cmp(k, refill->end) >= 0) {
+               ret = MAP_DONE;
+               goto out;
+       }
 
-                               spin_lock(&buf->lock);
+       if (!KEY_SIZE(k)) /* end key */
+               goto out;
 
-                               w = array_alloc(&buf->freelist);
+       if (refill->pred(buf, k)) {
+               struct keybuf_key *w;
 
-                               w->private = NULL;
-                               bkey_copy(&w->key, k);
+               spin_lock(&buf->lock);
 
-                               if (RB_INSERT(&buf->keys, w, node, keybuf_cmp))
-                                       array_free(&buf->freelist, w);
+               w = array_alloc(&buf->freelist);
+               if (!w) {
+                       spin_unlock(&buf->lock);
+                       return MAP_DONE;
+               }
 
-                               spin_unlock(&buf->lock);
-                       }
-               } else {
-                       if (!k)
-                               break;
+               w->private = NULL;
+               bkey_copy(&w->key, k);
 
-                       btree(refill_keybuf, k, b, op, buf, end, pred);
-                       /*
-                        * Might get an error here, but can't really do anything
-                        * and it'll get logged elsewhere. Just read what we
-                        * can.
-                        */
+               if (RB_INSERT(&buf->keys, w, node, keybuf_cmp))
+                       array_free(&buf->freelist, w);
+               else
+                       refill->nr_found++;
 
-                       if (bkey_cmp(&buf->last_scanned, end) >= 0)
-                               break;
+               if (array_freelist_empty(&buf->freelist))
+                       ret = MAP_DONE;
 
-                       cond_resched();
-               }
+               spin_unlock(&buf->lock);
        }
-
-       return 0;
+out:
+       buf->last_scanned = *k;
+       return ret;
 }
 
 void bch_refill_keybuf(struct cache_set *c, struct keybuf *buf,
                       struct bkey *end, keybuf_pred_fn *pred)
 {
        struct bkey start = buf->last_scanned;
-       struct btree_op op;
-       bch_btree_op_init_stack(&op);
+       struct refill refill;
 
        cond_resched();
 
-       btree_root(refill_keybuf, c, &op, buf, end, pred);
-       closure_sync(&op.cl);
+       bch_btree_op_init(&refill.op, -1);
+       refill.nr_found = 0;
+       refill.buf      = buf;
+       refill.end      = end;
+       refill.pred     = pred;
+
+       bch_btree_map_keys(&refill.op, c, &buf->last_scanned,
+                          refill_keybuf_fn, MAP_END_KEY);
 
-       pr_debug("found %s keys from %llu:%llu to %llu:%llu",
-                RB_EMPTY_ROOT(&buf->keys) ? "no" :
-                array_freelist_empty(&buf->freelist) ? "some" : "a few",
-                KEY_INODE(&start), KEY_OFFSET(&start),
-                KEY_INODE(&buf->last_scanned), KEY_OFFSET(&buf->last_scanned));
+       trace_bcache_keyscan(refill.nr_found,
+                            KEY_INODE(&start), KEY_OFFSET(&start),
+                            KEY_INODE(&buf->last_scanned),
+                            KEY_OFFSET(&buf->last_scanned));
 
        spin_lock(&buf->lock);
 
@@ -2436,9 +2526,9 @@ struct keybuf_key *bch_keybuf_next(struct keybuf *buf)
 }
 
 struct keybuf_key *bch_keybuf_next_rescan(struct cache_set *c,
-                                            struct keybuf *buf,
-                                            struct bkey *end,
-                                            keybuf_pred_fn *pred)
+                                         struct keybuf *buf,
+                                         struct bkey *end,
+                                         keybuf_pred_fn *pred)
 {
        struct keybuf_key *ret;
 
@@ -2471,14 +2561,12 @@ void bch_btree_exit(void)
 {
        if (btree_io_wq)
                destroy_workqueue(btree_io_wq);
-       if (bch_gc_wq)
-               destroy_workqueue(bch_gc_wq);
 }
 
 int __init bch_btree_init(void)
 {
-       if (!(bch_gc_wq = create_singlethread_workqueue("bch_btree_gc")) ||
-           !(btree_io_wq = create_singlethread_workqueue("bch_btree_io")))
+       btree_io_wq = create_singlethread_workqueue("bch_btree_io");
+       if (!btree_io_wq)
                return -ENOMEM;
 
        return 0;
index 3333d3723633c424e0a22d51d7475969392c1130..767e755708964ce82f36dc88e28281b5c1b90177 100644 (file)
@@ -125,6 +125,7 @@ struct btree {
        unsigned long           seq;
        struct rw_semaphore     lock;
        struct cache_set        *c;
+       struct btree            *parent;
 
        unsigned long           flags;
        uint16_t                written;        /* would be nice to kill */
@@ -200,12 +201,7 @@ static inline bool bkey_written(struct btree *b, struct bkey *k)
 
 static inline void set_gc_sectors(struct cache_set *c)
 {
-       atomic_set(&c->sectors_to_gc, c->sb.bucket_size * c->nbuckets / 8);
-}
-
-static inline bool bch_ptr_invalid(struct btree *b, const struct bkey *k)
-{
-       return __bch_ptr_invalid(b->c, b->level, k);
+       atomic_set(&c->sectors_to_gc, c->sb.bucket_size * c->nbuckets / 16);
 }
 
 static inline struct bkey *bch_btree_iter_init(struct btree *b,
@@ -215,6 +211,16 @@ static inline struct bkey *bch_btree_iter_init(struct btree *b,
        return __bch_btree_iter_init(b, iter, search, b->sets);
 }
 
+static inline bool bch_ptr_invalid(struct btree *b, const struct bkey *k)
+{
+       if (b->level)
+               return bch_btree_ptr_invalid(b->c, k);
+       else
+               return bch_extent_ptr_invalid(b->c, k);
+}
+
+void bkey_put(struct cache_set *c, struct bkey *k);
+
 /* Looping macros */
 
 #define for_each_cached_btree(b, c, iter)                              \
@@ -234,51 +240,17 @@ static inline struct bkey *bch_btree_iter_init(struct btree *b,
 /* Recursing down the btree */
 
 struct btree_op {
-       struct closure          cl;
-       struct cache_set        *c;
-
-       /* Journal entry we have a refcount on */
-       atomic_t                *journal;
-
-       /* Bio to be inserted into the cache */
-       struct bio              *cache_bio;
-
-       unsigned                inode;
-
-       uint16_t                write_prio;
-
        /* Btree level at which we start taking write locks */
        short                   lock;
 
-       /* Btree insertion type */
-       enum {
-               BTREE_INSERT,
-               BTREE_REPLACE
-       } type:8;
-
-       unsigned                csum:1;
-       unsigned                skip:1;
-       unsigned                flush_journal:1;
-
-       unsigned                insert_data_done:1;
-       unsigned                lookup_done:1;
        unsigned                insert_collision:1;
-
-       /* Anything after this point won't get zeroed in do_bio_hook() */
-
-       /* Keys to be inserted */
-       struct keylist          keys;
-       BKEY_PADDED(replace);
 };
 
-enum {
-       BTREE_INSERT_STATUS_INSERT,
-       BTREE_INSERT_STATUS_BACK_MERGE,
-       BTREE_INSERT_STATUS_OVERWROTE,
-       BTREE_INSERT_STATUS_FRONT_MERGE,
-};
-
-void bch_btree_op_init_stack(struct btree_op *);
+static inline void bch_btree_op_init(struct btree_op *op, int write_lock_level)
+{
+       memset(op, 0, sizeof(struct btree_op));
+       op->lock = write_lock_level;
+}
 
 static inline void rw_lock(bool w, struct btree *b, int level)
 {
@@ -290,108 +262,71 @@ static inline void rw_lock(bool w, struct btree *b, int level)
 
 static inline void rw_unlock(bool w, struct btree *b)
 {
-#ifdef CONFIG_BCACHE_EDEBUG
-       unsigned i;
-
-       if (w && b->key.ptr[0])
-               for (i = 0; i <= b->nsets; i++)
-                       bch_check_key_order(b, b->sets[i].data);
-#endif
-
        if (w)
                b->seq++;
        (w ? up_write : up_read)(&b->lock);
 }
 
-#define insert_lock(s, b)      ((b)->level <= (s)->lock)
+void bch_btree_node_read(struct btree *);
+void bch_btree_node_write(struct btree *, struct closure *);
 
-/*
- * These macros are for recursing down the btree - they handle the details of
- * locking and looking up nodes in the cache for you. They're best treated as
- * mere syntax when reading code that uses them.
- *
- * op->lock determines whether we take a read or a write lock at a given depth.
- * If you've got a read lock and find that you need a write lock (i.e. you're
- * going to have to split), set op->lock and return -EINTR; btree_root() will
- * call you again and you'll have the correct lock.
- */
+void bch_btree_set_root(struct btree *);
+struct btree *bch_btree_node_alloc(struct cache_set *, int, bool);
+struct btree *bch_btree_node_get(struct cache_set *, struct bkey *, int, bool);
 
-/**
- * btree - recurse down the btree on a specified key
- * @fn:                function to call, which will be passed the child node
- * @key:       key to recurse on
- * @b:         parent btree node
- * @op:                pointer to struct btree_op
- */
-#define btree(fn, key, b, op, ...)                                     \
-({                                                                     \
-       int _r, l = (b)->level - 1;                                     \
-       bool _w = l <= (op)->lock;                                      \
-       struct btree *_b = bch_btree_node_get((b)->c, key, l, op);      \
-       if (!IS_ERR(_b)) {                                              \
-               _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__);           \
-               rw_unlock(_w, _b);                                      \
-       } else                                                          \
-               _r = PTR_ERR(_b);                                       \
-       _r;                                                             \
-})
-
-/**
- * btree_root - call a function on the root of the btree
- * @fn:                function to call, which will be passed the child node
- * @c:         cache set
- * @op:                pointer to struct btree_op
- */
-#define btree_root(fn, c, op, ...)                                     \
-({                                                                     \
-       int _r = -EINTR;                                                \
-       do {                                                            \
-               struct btree *_b = (c)->root;                           \
-               bool _w = insert_lock(op, _b);                          \
-               rw_lock(_w, _b, _b->level);                             \
-               if (_b == (c)->root &&                                  \
-                   _w == insert_lock(op, _b))                          \
-                       _r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__);   \
-               rw_unlock(_w, _b);                                      \
-               bch_cannibalize_unlock(c, &(op)->cl);           \
-       } while (_r == -EINTR);                                         \
-                                                                       \
-       _r;                                                             \
-})
+int bch_btree_insert_check_key(struct btree *, struct btree_op *,
+                              struct bkey *);
+int bch_btree_insert(struct cache_set *, struct keylist *,
+                    atomic_t *, struct bkey *);
+
+int bch_gc_thread_start(struct cache_set *);
+size_t bch_btree_gc_finish(struct cache_set *);
+void bch_moving_gc(struct cache_set *);
+int bch_btree_check(struct cache_set *);
+uint8_t __bch_btree_mark_key(struct cache_set *, int, struct bkey *);
 
-static inline bool should_split(struct btree *b)
+static inline void wake_up_gc(struct cache_set *c)
 {
-       struct bset *i = write_block(b);
-       return b->written >= btree_blocks(b) ||
-               (i->seq == b->sets[0].data->seq &&
-                b->written + __set_blocks(i, i->keys + 15, b->c)
-                > btree_blocks(b));
+       if (c->gc_thread)
+               wake_up_process(c->gc_thread);
 }
 
-void bch_btree_node_read(struct btree *);
-void bch_btree_node_write(struct btree *, struct closure *);
+#define MAP_DONE       0
+#define MAP_CONTINUE   1
 
-void bch_cannibalize_unlock(struct cache_set *, struct closure *);
-void bch_btree_set_root(struct btree *);
-struct btree *bch_btree_node_alloc(struct cache_set *, int, struct closure *);
-struct btree *bch_btree_node_get(struct cache_set *, struct bkey *,
-                               int, struct btree_op *);
+#define MAP_ALL_NODES  0
+#define MAP_LEAF_NODES 1
 
-bool bch_btree_insert_check_key(struct btree *, struct btree_op *,
-                                  struct bio *);
-int bch_btree_insert(struct btree_op *, struct cache_set *);
+#define MAP_END_KEY    1
 
-int bch_btree_search_recurse(struct btree *, struct btree_op *);
+typedef int (btree_map_nodes_fn)(struct btree_op *, struct btree *);
+int __bch_btree_map_nodes(struct btree_op *, struct cache_set *,
+                         struct bkey *, btree_map_nodes_fn *, int);
 
-void bch_queue_gc(struct cache_set *);
-size_t bch_btree_gc_finish(struct cache_set *);
-void bch_moving_gc(struct closure *);
-int bch_btree_check(struct cache_set *, struct btree_op *);
-uint8_t __bch_btree_mark_key(struct cache_set *, int, struct bkey *);
+static inline int bch_btree_map_nodes(struct btree_op *op, struct cache_set *c,
+                                     struct bkey *from, btree_map_nodes_fn *fn)
+{
+       return __bch_btree_map_nodes(op, c, from, fn, MAP_ALL_NODES);
+}
+
+static inline int bch_btree_map_leaf_nodes(struct btree_op *op,
+                                          struct cache_set *c,
+                                          struct bkey *from,
+                                          btree_map_nodes_fn *fn)
+{
+       return __bch_btree_map_nodes(op, c, from, fn, MAP_LEAF_NODES);
+}
+
+typedef int (btree_map_keys_fn)(struct btree_op *, struct btree *,
+                               struct bkey *);
+int bch_btree_map_keys(struct btree_op *, struct cache_set *,
+                      struct bkey *, btree_map_keys_fn *, int);
+
+typedef bool (keybuf_pred_fn)(struct keybuf *, struct bkey *);
 
 void bch_keybuf_init(struct keybuf *);
-void bch_refill_keybuf(struct cache_set *, struct keybuf *, struct bkey *,
-                      keybuf_pred_fn *);
+void bch_refill_keybuf(struct cache_set *, struct keybuf *,
+                      struct bkey *, keybuf_pred_fn *);
 bool bch_keybuf_check_overlapping(struct keybuf *, struct bkey *,
                                  struct bkey *);
 void bch_keybuf_del(struct keybuf *, struct keybuf_key *);
index 9aba2017f0d1685ac5858ccf716c1f829681c853..dfff2410322e70263ac63e6dbfd9536bd4a5dc54 100644 (file)
 
 #include "closure.h"
 
-void closure_queue(struct closure *cl)
-{
-       struct workqueue_struct *wq = cl->wq;
-       if (wq) {
-               INIT_WORK(&cl->work, cl->work.func);
-               BUG_ON(!queue_work(wq, &cl->work));
-       } else
-               cl->fn(cl);
-}
-EXPORT_SYMBOL_GPL(closure_queue);
-
 #define CL_FIELD(type, field)                                  \
        case TYPE_ ## type:                                     \
        return &container_of(cl, struct type, cl)->field
@@ -30,17 +19,6 @@ static struct closure_waitlist *closure_waitlist(struct closure *cl)
 {
        switch (cl->type) {
                CL_FIELD(closure_with_waitlist, wait);
-               CL_FIELD(closure_with_waitlist_and_timer, wait);
-       default:
-               return NULL;
-       }
-}
-
-static struct timer_list *closure_timer(struct closure *cl)
-{
-       switch (cl->type) {
-               CL_FIELD(closure_with_timer, timer);
-               CL_FIELD(closure_with_waitlist_and_timer, timer);
        default:
                return NULL;
        }
@@ -51,7 +29,7 @@ static inline void closure_put_after_sub(struct closure *cl, int flags)
        int r = flags & CLOSURE_REMAINING_MASK;
 
        BUG_ON(flags & CLOSURE_GUARD_MASK);
-       BUG_ON(!r && (flags & ~(CLOSURE_DESTRUCTOR|CLOSURE_BLOCKING)));
+       BUG_ON(!r && (flags & ~CLOSURE_DESTRUCTOR));
 
        /* Must deliver precisely one wakeup */
        if (r == 1 && (flags & CLOSURE_SLEEPING))
@@ -59,7 +37,6 @@ static inline void closure_put_after_sub(struct closure *cl, int flags)
 
        if (!r) {
                if (cl->fn && !(flags & CLOSURE_DESTRUCTOR)) {
-                       /* CLOSURE_BLOCKING might be set - clear it */
                        atomic_set(&cl->remaining,
                                   CLOSURE_REMAINING_INITIALIZER);
                        closure_queue(cl);
@@ -90,13 +67,13 @@ void closure_sub(struct closure *cl, int v)
 {
        closure_put_after_sub(cl, atomic_sub_return(v, &cl->remaining));
 }
-EXPORT_SYMBOL_GPL(closure_sub);
+EXPORT_SYMBOL(closure_sub);
 
 void closure_put(struct closure *cl)
 {
        closure_put_after_sub(cl, atomic_dec_return(&cl->remaining));
 }
-EXPORT_SYMBOL_GPL(closure_put);
+EXPORT_SYMBOL(closure_put);
 
 static void set_waiting(struct closure *cl, unsigned long f)
 {
@@ -133,7 +110,7 @@ void __closure_wake_up(struct closure_waitlist *wait_list)
                closure_sub(cl, CLOSURE_WAITING + 1);
        }
 }
-EXPORT_SYMBOL_GPL(__closure_wake_up);
+EXPORT_SYMBOL(__closure_wake_up);
 
 bool closure_wait(struct closure_waitlist *list, struct closure *cl)
 {
@@ -146,7 +123,7 @@ bool closure_wait(struct closure_waitlist *list, struct closure *cl)
 
        return true;
 }
-EXPORT_SYMBOL_GPL(closure_wait);
+EXPORT_SYMBOL(closure_wait);
 
 /**
  * closure_sync() - sleep until a closure a closure has nothing left to wait on
@@ -169,7 +146,7 @@ void closure_sync(struct closure *cl)
 
        __closure_end_sleep(cl);
 }
-EXPORT_SYMBOL_GPL(closure_sync);
+EXPORT_SYMBOL(closure_sync);
 
 /**
  * closure_trylock() - try to acquire the closure, without waiting
@@ -183,17 +160,17 @@ bool closure_trylock(struct closure *cl, struct closure *parent)
                           CLOSURE_REMAINING_INITIALIZER) != -1)
                return false;
 
-       closure_set_ret_ip(cl);
-
        smp_mb();
+
        cl->parent = parent;
        if (parent)
                closure_get(parent);
 
+       closure_set_ret_ip(cl);
        closure_debug_create(cl);
        return true;
 }
-EXPORT_SYMBOL_GPL(closure_trylock);
+EXPORT_SYMBOL(closure_trylock);
 
 void __closure_lock(struct closure *cl, struct closure *parent,
                    struct closure_waitlist *wait_list)
@@ -205,57 +182,11 @@ void __closure_lock(struct closure *cl, struct closure *parent,
                if (closure_trylock(cl, parent))
                        return;
 
-               closure_wait_event_sync(wait_list, &wait,
-                                       atomic_read(&cl->remaining) == -1);
+               closure_wait_event(wait_list, &wait,
+                                  atomic_read(&cl->remaining) == -1);
        }
 }
-EXPORT_SYMBOL_GPL(__closure_lock);
-
-static void closure_delay_timer_fn(unsigned long data)
-{
-       struct closure *cl = (struct closure *) data;
-       closure_sub(cl, CLOSURE_TIMER + 1);
-}
-
-void do_closure_timer_init(struct closure *cl)
-{
-       struct timer_list *timer = closure_timer(cl);
-
-       init_timer(timer);
-       timer->data     = (unsigned long) cl;
-       timer->function = closure_delay_timer_fn;
-}
-EXPORT_SYMBOL_GPL(do_closure_timer_init);
-
-bool __closure_delay(struct closure *cl, unsigned long delay,
-                    struct timer_list *timer)
-{
-       if (atomic_read(&cl->remaining) & CLOSURE_TIMER)
-               return false;
-
-       BUG_ON(timer_pending(timer));
-
-       timer->expires  = jiffies + delay;
-
-       atomic_add(CLOSURE_TIMER + 1, &cl->remaining);
-       add_timer(timer);
-       return true;
-}
-EXPORT_SYMBOL_GPL(__closure_delay);
-
-void __closure_flush(struct closure *cl, struct timer_list *timer)
-{
-       if (del_timer(timer))
-               closure_sub(cl, CLOSURE_TIMER + 1);
-}
-EXPORT_SYMBOL_GPL(__closure_flush);
-
-void __closure_flush_sync(struct closure *cl, struct timer_list *timer)
-{
-       if (del_timer_sync(timer))
-               closure_sub(cl, CLOSURE_TIMER + 1);
-}
-EXPORT_SYMBOL_GPL(__closure_flush_sync);
+EXPORT_SYMBOL(__closure_lock);
 
 #ifdef CONFIG_BCACHE_CLOSURES_DEBUG
 
@@ -273,7 +204,7 @@ void closure_debug_create(struct closure *cl)
        list_add(&cl->all, &closure_list);
        spin_unlock_irqrestore(&closure_list_lock, flags);
 }
-EXPORT_SYMBOL_GPL(closure_debug_create);
+EXPORT_SYMBOL(closure_debug_create);
 
 void closure_debug_destroy(struct closure *cl)
 {
@@ -286,7 +217,7 @@ void closure_debug_destroy(struct closure *cl)
        list_del(&cl->all);
        spin_unlock_irqrestore(&closure_list_lock, flags);
 }
-EXPORT_SYMBOL_GPL(closure_debug_destroy);
+EXPORT_SYMBOL(closure_debug_destroy);
 
 static struct dentry *debug;
 
@@ -304,14 +235,12 @@ static int debug_seq_show(struct seq_file *f, void *data)
                           cl, (void *) cl->ip, cl->fn, cl->parent,
                           r & CLOSURE_REMAINING_MASK);
 
-               seq_printf(f, "%s%s%s%s%s%s\n",
+               seq_printf(f, "%s%s%s%s\n",
                           test_bit(WORK_STRUCT_PENDING,
                                    work_data_bits(&cl->work)) ? "Q" : "",
                           r & CLOSURE_RUNNING  ? "R" : "",
-                          r & CLOSURE_BLOCKING ? "B" : "",
                           r & CLOSURE_STACK    ? "S" : "",
-                          r & CLOSURE_SLEEPING ? "Sl" : "",
-                          r & CLOSURE_TIMER    ? "T" : "");
+                          r & CLOSURE_SLEEPING ? "Sl" : "");
 
                if (r & CLOSURE_WAITING)
                        seq_printf(f, " W %pF\n",
index 00039924ea9dde4ff64f7510a44202d1a1330be0..9762f1be3304f1349cc21f001cfa02d5401470e9 100644 (file)
  * delayed_work embeds a work item and a timer_list. The important thing is, use
  * it exactly like you would a regular closure and closure_put() will magically
  * handle everything for you.
- *
- * We've got closures that embed timers, too. They're called, appropriately
- * enough:
- * struct closure_with_timer;
- *
- * This gives you access to closure_delay(). It takes a refcount for a specified
- * number of jiffies - you could then call closure_sync() (for a slightly
- * convoluted version of msleep()) or continue_at() - which gives you the same
- * effect as using a delayed work item, except you can reuse the work_struct
- * already embedded in struct closure.
- *
- * Lastly, there's struct closure_with_waitlist_and_timer. It does what you
- * probably expect, if you happen to need the features of both. (You don't
- * really want to know how all this is implemented, but if I've done my job
- * right you shouldn't have to care).
  */
 
 struct closure;
@@ -182,16 +167,11 @@ struct closure_waitlist {
 enum closure_type {
        TYPE_closure                            = 0,
        TYPE_closure_with_waitlist              = 1,
-       TYPE_closure_with_timer                 = 2,
-       TYPE_closure_with_waitlist_and_timer    = 3,
-       MAX_CLOSURE_TYPE                        = 3,
+       MAX_CLOSURE_TYPE                        = 1,
 };
 
 enum closure_state {
        /*
-        * CLOSURE_BLOCKING: Causes closure_wait_event() to block, instead of
-        * waiting asynchronously
-        *
         * CLOSURE_WAITING: Set iff the closure is on a waitlist. Must be set by
         * the thread that owns the closure, and cleared by the thread that's
         * waking up the closure.
@@ -200,10 +180,6 @@ enum closure_state {
         * - indicates that cl->task is valid and closure_put() may wake it up.
         * Only set or cleared by the thread that owns the closure.
         *
-        * CLOSURE_TIMER: Analagous to CLOSURE_WAITING, indicates that a closure
-        * has an outstanding timer. Must be set by the thread that owns the
-        * closure, and cleared by the timer function when the timer goes off.
-        *
         * The rest are for debugging and don't affect behaviour:
         *
         * CLOSURE_RUNNING: Set when a closure is running (i.e. by
@@ -218,19 +194,17 @@ enum closure_state {
         * closure with this flag set
         */
 
-       CLOSURE_BITS_START      = (1 << 19),
-       CLOSURE_DESTRUCTOR      = (1 << 19),
-       CLOSURE_BLOCKING        = (1 << 21),
-       CLOSURE_WAITING         = (1 << 23),
-       CLOSURE_SLEEPING        = (1 << 25),
-       CLOSURE_TIMER           = (1 << 27),
+       CLOSURE_BITS_START      = (1 << 23),
+       CLOSURE_DESTRUCTOR      = (1 << 23),
+       CLOSURE_WAITING         = (1 << 25),
+       CLOSURE_SLEEPING        = (1 << 27),
        CLOSURE_RUNNING         = (1 << 29),
        CLOSURE_STACK           = (1 << 31),
 };
 
 #define CLOSURE_GUARD_MASK                                     \
-       ((CLOSURE_DESTRUCTOR|CLOSURE_BLOCKING|CLOSURE_WAITING|  \
-         CLOSURE_SLEEPING|CLOSURE_TIMER|CLOSURE_RUNNING|CLOSURE_STACK) << 1)
+       ((CLOSURE_DESTRUCTOR|CLOSURE_WAITING|CLOSURE_SLEEPING|  \
+         CLOSURE_RUNNING|CLOSURE_STACK) << 1)
 
 #define CLOSURE_REMAINING_MASK         (CLOSURE_BITS_START - 1)
 #define CLOSURE_REMAINING_INITIALIZER  (1|CLOSURE_RUNNING)
@@ -268,17 +242,6 @@ struct closure_with_waitlist {
        struct closure_waitlist wait;
 };
 
-struct closure_with_timer {
-       struct closure          cl;
-       struct timer_list       timer;
-};
-
-struct closure_with_waitlist_and_timer {
-       struct closure          cl;
-       struct closure_waitlist wait;
-       struct timer_list       timer;
-};
-
 extern unsigned invalid_closure_type(void);
 
 #define __CLOSURE_TYPE(cl, _t)                                         \
@@ -289,14 +252,11 @@ extern unsigned invalid_closure_type(void);
 (                                                                      \
        __CLOSURE_TYPE(cl, closure)                                     \
        __CLOSURE_TYPE(cl, closure_with_waitlist)                       \
-       __CLOSURE_TYPE(cl, closure_with_timer)                          \
-       __CLOSURE_TYPE(cl, closure_with_waitlist_and_timer)             \
        invalid_closure_type()                                          \
 )
 
 void closure_sub(struct closure *cl, int v);
 void closure_put(struct closure *cl);
-void closure_queue(struct closure *cl);
 void __closure_wake_up(struct closure_waitlist *list);
 bool closure_wait(struct closure_waitlist *list, struct closure *cl);
 void closure_sync(struct closure *cl);
@@ -305,12 +265,6 @@ bool closure_trylock(struct closure *cl, struct closure *parent);
 void __closure_lock(struct closure *cl, struct closure *parent,
                    struct closure_waitlist *wait_list);
 
-void do_closure_timer_init(struct closure *cl);
-bool __closure_delay(struct closure *cl, unsigned long delay,
-                    struct timer_list *timer);
-void __closure_flush(struct closure *cl, struct timer_list *timer);
-void __closure_flush_sync(struct closure *cl, struct timer_list *timer);
-
 #ifdef CONFIG_BCACHE_CLOSURES_DEBUG
 
 void closure_debug_init(void);
@@ -354,11 +308,6 @@ static inline void closure_set_stopped(struct closure *cl)
        atomic_sub(CLOSURE_RUNNING, &cl->remaining);
 }
 
-static inline bool closure_is_stopped(struct closure *cl)
-{
-       return !(atomic_read(&cl->remaining) & CLOSURE_RUNNING);
-}
-
 static inline bool closure_is_unlocked(struct closure *cl)
 {
        return atomic_read(&cl->remaining) == -1;
@@ -367,14 +316,6 @@ static inline bool closure_is_unlocked(struct closure *cl)
 static inline void do_closure_init(struct closure *cl, struct closure *parent,
                                   bool running)
 {
-       switch (cl->type) {
-       case TYPE_closure_with_timer:
-       case TYPE_closure_with_waitlist_and_timer:
-               do_closure_timer_init(cl);
-       default:
-               break;
-       }
-
        cl->parent = parent;
        if (parent)
                closure_get(parent);
@@ -429,8 +370,7 @@ do {                                                                \
 static inline void closure_init_stack(struct closure *cl)
 {
        memset(cl, 0, sizeof(struct closure));
-       atomic_set(&cl->remaining, CLOSURE_REMAINING_INITIALIZER|
-                  CLOSURE_BLOCKING|CLOSURE_STACK);
+       atomic_set(&cl->remaining, CLOSURE_REMAINING_INITIALIZER|CLOSURE_STACK);
 }
 
 /**
@@ -461,24 +401,6 @@ do {                                                               \
 #define closure_lock(cl, parent)                               \
        __closure_lock(__to_internal_closure(cl), parent, &(cl)->wait)
 
-/**
- * closure_delay() - delay some number of jiffies
- * @cl:                the closure that will sleep
- * @delay:     the delay in jiffies
- *
- * Takes a refcount on @cl which will be released after @delay jiffies; this may
- * be used to have a function run after a delay with continue_at(), or
- * closure_sync() may be used for a convoluted version of msleep().
- */
-#define closure_delay(cl, delay)                       \
-       __closure_delay(__to_internal_closure(cl), delay, &(cl)->timer)
-
-#define closure_flush(cl)                              \
-       __closure_flush(__to_internal_closure(cl), &(cl)->timer)
-
-#define closure_flush_sync(cl)                         \
-       __closure_flush_sync(__to_internal_closure(cl), &(cl)->timer)
-
 static inline void __closure_end_sleep(struct closure *cl)
 {
        __set_current_state(TASK_RUNNING);
@@ -497,40 +419,6 @@ static inline void __closure_start_sleep(struct closure *cl)
                atomic_add(CLOSURE_SLEEPING, &cl->remaining);
 }
 
-/**
- * closure_blocking() - returns true if the closure is in blocking mode.
- *
- * If a closure is in blocking mode, closure_wait_event() will sleep until the
- * condition is true instead of waiting asynchronously.
- */
-static inline bool closure_blocking(struct closure *cl)
-{
-       return atomic_read(&cl->remaining) & CLOSURE_BLOCKING;
-}
-
-/**
- * set_closure_blocking() - put a closure in blocking mode.
- *
- * If a closure is in blocking mode, closure_wait_event() will sleep until the
- * condition is true instead of waiting asynchronously.
- *
- * Not thread safe - can only be called by the thread running the closure.
- */
-static inline void set_closure_blocking(struct closure *cl)
-{
-       if (!closure_blocking(cl))
-               atomic_add(CLOSURE_BLOCKING, &cl->remaining);
-}
-
-/*
- * Not thread safe - can only be called by the thread running the closure.
- */
-static inline void clear_closure_blocking(struct closure *cl)
-{
-       if (closure_blocking(cl))
-               atomic_sub(CLOSURE_BLOCKING, &cl->remaining);
-}
-
 /**
  * closure_wake_up() - wake up all closures on a wait list.
  */
@@ -561,63 +449,36 @@ static inline void closure_wake_up(struct closure_waitlist *list)
  * refcount on our closure. If this was a stack allocated closure, that would be
  * bad.
  */
-#define __closure_wait_event(list, cl, condition, _block)              \
+#define closure_wait_event(list, cl, condition)                                \
 ({                                                                     \
-       bool block = _block;                                            \
        typeof(condition) ret;                                          \
                                                                        \
        while (1) {                                                     \
                ret = (condition);                                      \
                if (ret) {                                              \
                        __closure_wake_up(list);                        \
-                       if (block)                                      \
-                               closure_sync(cl);                       \
-                                                                       \
+                       closure_sync(cl);                               \
                        break;                                          \
                }                                                       \
                                                                        \
-               if (block)                                              \
-                       __closure_start_sleep(cl);                      \
-                                                                       \
-               if (!closure_wait(list, cl)) {                          \
-                       if (!block)                                     \
-                               break;                                  \
+               __closure_start_sleep(cl);                              \
                                                                        \
+               if (!closure_wait(list, cl))                            \
                        schedule();                                     \
-               }                                                       \
        }                                                               \
                                                                        \
        ret;                                                            \
 })
 
-/**
- * closure_wait_event() - wait on a condition, synchronously or asynchronously.
- * @list:      the wait list to wait on
- * @cl:                the closure that is doing the waiting
- * @condition: a C expression for the event to wait for
- *
- * If the closure is in blocking mode, sleeps until the @condition evaluates to
- * true - exactly like wait_event().
- *
- * If the closure is not in blocking mode, waits asynchronously; if the
- * condition is currently false the @cl is put onto @list and returns. @list
- * owns a refcount on @cl; closure_sync() or continue_at() may be used later to
- * wait for another thread to wake up @list, which drops the refcount on @cl.
- *
- * Returns the value of @condition; @cl will be on @list iff @condition was
- * false.
- *
- * closure_wake_up(@list) must be called after changing any variable that could
- * cause @condition to become true.
- */
-#define closure_wait_event(list, cl, condition)                                \
-       __closure_wait_event(list, cl, condition, closure_blocking(cl))
-
-#define closure_wait_event_async(list, cl, condition)                  \
-       __closure_wait_event(list, cl, condition, false)
-
-#define closure_wait_event_sync(list, cl, condition)                   \
-       __closure_wait_event(list, cl, condition, true)
+static inline void closure_queue(struct closure *cl)
+{
+       struct workqueue_struct *wq = cl->wq;
+       if (wq) {
+               INIT_WORK(&cl->work, cl->work.func);
+               BUG_ON(!queue_work(wq, &cl->work));
+       } else
+               cl->fn(cl);
+}
 
 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
                                  struct workqueue_struct *wq)
@@ -642,7 +503,7 @@ do {                                                                        \
 #define continue_at_nobarrier(_cl, _fn, _wq)                           \
 do {                                                                   \
        set_closure_fn(_cl, _fn, _wq);                                  \
-       closure_queue(cl);                                              \
+       closure_queue(_cl);                                             \
        return;                                                         \
 } while (0)
 
index 88e6411eab4f15829ba22c535a7b100b370bc5a6..264fcfbd629016aa1ab890cce56de2699c49be70 100644 (file)
@@ -8,7 +8,6 @@
 #include "bcache.h"
 #include "btree.h"
 #include "debug.h"
-#include "request.h"
 
 #include <linux/console.h>
 #include <linux/debugfs.h>
@@ -77,29 +76,17 @@ int bch_bkey_to_text(char *buf, size_t size, const struct bkey *k)
        return out - buf;
 }
 
-int bch_btree_to_text(char *buf, size_t size, const struct btree *b)
-{
-       return scnprintf(buf, size, "%zu level %i/%i",
-                        PTR_BUCKET_NR(b->c, &b->key, 0),
-                        b->level, b->c->root ? b->c->root->level : -1);
-}
-
-#if defined(CONFIG_BCACHE_DEBUG) || defined(CONFIG_BCACHE_EDEBUG)
-
-static bool skipped_backwards(struct btree *b, struct bkey *k)
-{
-       return bkey_cmp(k, (!b->level)
-                       ? &START_KEY(bkey_next(k))
-                       : bkey_next(k)) > 0;
-}
+#ifdef CONFIG_BCACHE_DEBUG
 
 static void dump_bset(struct btree *b, struct bset *i)
 {
-       struct bkey *k;
+       struct bkey *k, *next;
        unsigned j;
        char buf[80];
 
-       for (k = i->start; k < end(i); k = bkey_next(k)) {
+       for (k = i->start; k < end(i); k = next) {
+               next = bkey_next(k);
+
                bch_bkey_to_text(buf, sizeof(buf), k);
                printk(KERN_ERR "block %zu key %zi/%u: %s", index(i, b),
                       (uint64_t *) k - i->d, i->keys, buf);
@@ -115,15 +102,21 @@ static void dump_bset(struct btree *b, struct bset *i)
 
                printk(" %s\n", bch_ptr_status(b->c, k));
 
-               if (bkey_next(k) < end(i) &&
-                   skipped_backwards(b, k))
+               if (next < end(i) &&
+                   bkey_cmp(k, !b->level ? &START_KEY(next) : next) > 0)
                        printk(KERN_ERR "Key skipped backwards\n");
        }
 }
 
-#endif
+static void bch_dump_bucket(struct btree *b)
+{
+       unsigned i;
 
-#ifdef CONFIG_BCACHE_DEBUG
+       console_lock();
+       for (i = 0; i <= b->nsets; i++)
+               dump_bset(b, b->sets[i].data);
+       console_unlock();
+}
 
 void bch_btree_verify(struct btree *b, struct bset *new)
 {
@@ -176,66 +169,44 @@ void bch_btree_verify(struct btree *b, struct bset *new)
        mutex_unlock(&b->c->verify_lock);
 }
 
-static void data_verify_endio(struct bio *bio, int error)
-{
-       struct closure *cl = bio->bi_private;
-       closure_put(cl);
-}
-
-void bch_data_verify(struct search *s)
+void bch_data_verify(struct cached_dev *dc, struct bio *bio)
 {
        char name[BDEVNAME_SIZE];
-       struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
-       struct closure *cl = &s->cl;
        struct bio *check;
        struct bio_vec *bv;
        int i;
 
-       if (!s->unaligned_bvec)
-               bio_for_each_segment(bv, s->orig_bio, i)
-                       bv->bv_offset = 0, bv->bv_len = PAGE_SIZE;
-
-       check = bio_clone(s->orig_bio, GFP_NOIO);
+       check = bio_clone(bio, GFP_NOIO);
        if (!check)
                return;
 
        if (bio_alloc_pages(check, GFP_NOIO))
                goto out_put;
 
-       check->bi_rw            = READ_SYNC;
-       check->bi_private       = cl;
-       check->bi_end_io        = data_verify_endio;
-
-       closure_bio_submit(check, cl, &dc->disk);
-       closure_sync(cl);
+       submit_bio_wait(READ_SYNC, check);
 
-       bio_for_each_segment(bv, s->orig_bio, i) {
-               void *p1 = kmap(bv->bv_page);
-               void *p2 = kmap(check->bi_io_vec[i].bv_page);
+       bio_for_each_segment(bv, bio, i) {
+               void *p1 = kmap_atomic(bv->bv_page);
+               void *p2 = page_address(check->bi_io_vec[i].bv_page);
 
-               if (memcmp(p1 + bv->bv_offset,
-                          p2 + bv->bv_offset,
-                          bv->bv_len))
-                       printk(KERN_ERR
-                              "bcache (%s): verify failed at sector %llu\n",
-                              bdevname(dc->bdev, name),
-                              (uint64_t) s->orig_bio->bi_sector);
+               cache_set_err_on(memcmp(p1 + bv->bv_offset,
+                                       p2 + bv->bv_offset,
+                                       bv->bv_len),
+                                dc->disk.c,
+                                "verify failed at dev %s sector %llu",
+                                bdevname(dc->bdev, name),
+                                (uint64_t) bio->bi_sector);
 
-               kunmap(bv->bv_page);
-               kunmap(check->bi_io_vec[i].bv_page);
+               kunmap_atomic(p1);
        }
 
-       __bio_for_each_segment(bv, check, i, 0)
+       bio_for_each_segment_all(bv, check, i)
                __free_page(bv->bv_page);
 out_put:
        bio_put(check);
 }
 
-#endif
-
-#ifdef CONFIG_BCACHE_EDEBUG
-
-unsigned bch_count_data(struct btree *b)
+int __bch_count_data(struct btree *b)
 {
        unsigned ret = 0;
        struct btree_iter iter;
@@ -247,72 +218,60 @@ unsigned bch_count_data(struct btree *b)
        return ret;
 }
 
-static void vdump_bucket_and_panic(struct btree *b, const char *fmt,
-                                  va_list args)
-{
-       unsigned i;
-       char buf[80];
-
-       console_lock();
-
-       for (i = 0; i <= b->nsets; i++)
-               dump_bset(b, b->sets[i].data);
-
-       vprintk(fmt, args);
-
-       console_unlock();
-
-       bch_btree_to_text(buf, sizeof(buf), b);
-       panic("at %s\n", buf);
-}
-
-void bch_check_key_order_msg(struct btree *b, struct bset *i,
-                            const char *fmt, ...)
-{
-       struct bkey *k;
-
-       if (!i->keys)
-               return;
-
-       for (k = i->start; bkey_next(k) < end(i); k = bkey_next(k))
-               if (skipped_backwards(b, k)) {
-                       va_list args;
-                       va_start(args, fmt);
-
-                       vdump_bucket_and_panic(b, fmt, args);
-                       va_end(args);
-               }
-}
-
-void bch_check_keys(struct btree *b, const char *fmt, ...)
+void __bch_check_keys(struct btree *b, const char *fmt, ...)
 {
        va_list args;
        struct bkey *k, *p = NULL;
        struct btree_iter iter;
-
-       if (b->level)
-               return;
+       const char *err;
 
        for_each_key(b, k, &iter) {
-               if (p && bkey_cmp(&START_KEY(p), &START_KEY(k)) > 0) {
-                       printk(KERN_ERR "Keys out of order:\n");
-                       goto bug;
-               }
-
-               if (bch_ptr_invalid(b, k))
-                       continue;
-
-               if (p && bkey_cmp(p, &START_KEY(k)) > 0) {
-                       printk(KERN_ERR "Overlapping keys:\n");
-                       goto bug;
+               if (!b->level) {
+                       err = "Keys out of order";
+                       if (p && bkey_cmp(&START_KEY(p), &START_KEY(k)) > 0)
+                               goto bug;
+
+                       if (bch_ptr_invalid(b, k))
+                               continue;
+
+                       err =  "Overlapping keys";
+                       if (p && bkey_cmp(p, &START_KEY(k)) > 0)
+                               goto bug;
+               } else {
+                       if (bch_ptr_bad(b, k))
+                               continue;
+
+                       err = "Duplicate keys";
+                       if (p && !bkey_cmp(p, k))
+                               goto bug;
                }
                p = k;
        }
+
+       err = "Key larger than btree node key";
+       if (p && bkey_cmp(p, &b->key) > 0)
+               goto bug;
+
        return;
 bug:
+       bch_dump_bucket(b);
+
        va_start(args, fmt);
-       vdump_bucket_and_panic(b, fmt, args);
+       vprintk(fmt, args);
        va_end(args);
+
+       panic("bcache error: %s:\n", err);
+}
+
+void bch_btree_iter_next_check(struct btree_iter *iter)
+{
+       struct bkey *k = iter->data->k, *next = bkey_next(k);
+
+       if (next < iter->data->end &&
+           bkey_cmp(k, iter->b->level ? next : &START_KEY(next)) > 0) {
+               bch_dump_bucket(iter->b);
+               panic("Key skipped backwards\n");
+       }
 }
 
 #endif
index 1c39b5a2489bd1158782f0afb1a28ef4fcb0a7a4..2ede60e3187475d114004111ef70c2ebaf4f38af 100644 (file)
@@ -4,40 +4,44 @@
 /* Btree/bkey debug printing */
 
 int bch_bkey_to_text(char *buf, size_t size, const struct bkey *k);
-int bch_btree_to_text(char *buf, size_t size, const struct btree *b);
-
-#ifdef CONFIG_BCACHE_EDEBUG
-
-unsigned bch_count_data(struct btree *);
-void bch_check_key_order_msg(struct btree *, struct bset *, const char *, ...);
-void bch_check_keys(struct btree *, const char *, ...);
-
-#define bch_check_key_order(b, i)                      \
-       bch_check_key_order_msg(b, i, "keys out of order")
-#define EBUG_ON(cond)          BUG_ON(cond)
-
-#else /* EDEBUG */
-
-#define bch_count_data(b)                              0
-#define bch_check_key_order(b, i)                      do {} while (0)
-#define bch_check_key_order_msg(b, i, ...)             do {} while (0)
-#define bch_check_keys(b, ...)                         do {} while (0)
-#define EBUG_ON(cond)                                  do {} while (0)
-
-#endif
 
 #ifdef CONFIG_BCACHE_DEBUG
 
 void bch_btree_verify(struct btree *, struct bset *);
-void bch_data_verify(struct search *);
+void bch_data_verify(struct cached_dev *, struct bio *);
+int __bch_count_data(struct btree *);
+void __bch_check_keys(struct btree *, const char *, ...);
+void bch_btree_iter_next_check(struct btree_iter *);
+
+#define EBUG_ON(cond)                  BUG_ON(cond)
+#define expensive_debug_checks(c)      ((c)->expensive_debug_checks)
+#define key_merging_disabled(c)                ((c)->key_merging_disabled)
+#define bypass_torture_test(d)         ((d)->bypass_torture_test)
 
 #else /* DEBUG */
 
 static inline void bch_btree_verify(struct btree *b, struct bset *i) {}
-static inline void bch_data_verify(struct search *s) {};
+static inline void bch_data_verify(struct cached_dev *dc, struct bio *bio) {}
+static inline int __bch_count_data(struct btree *b) { return -1; }
+static inline void __bch_check_keys(struct btree *b, const char *fmt, ...) {}
+static inline void bch_btree_iter_next_check(struct btree_iter *iter) {}
+
+#define EBUG_ON(cond)                  do { if (cond); } while (0)
+#define expensive_debug_checks(c)      0
+#define key_merging_disabled(c)                0
+#define bypass_torture_test(d)         0
 
 #endif
 
+#define bch_count_data(b)                                              \
+       (expensive_debug_checks((b)->c) ? __bch_count_data(b) : -1)
+
+#define bch_check_keys(b, ...)                                         \
+do {                                                                   \
+       if (expensive_debug_checks((b)->c))                             \
+               __bch_check_keys(b, __VA_ARGS__);                       \
+} while (0)
+
 #ifdef CONFIG_DEBUG_FS
 void bch_debug_init_cache_set(struct cache_set *);
 #else
index 8435f81e5d858012e8aca6be8204e923a34b1d01..ecdaa671bd50457bf38d1cf9f896ffd1c8352546 100644 (file)
@@ -7,7 +7,6 @@
 #include "bcache.h"
 #include "btree.h"
 #include "debug.h"
-#include "request.h"
 
 #include <trace/events/bcache.h>
 
@@ -31,17 +30,20 @@ static void journal_read_endio(struct bio *bio, int error)
 }
 
 static int journal_read_bucket(struct cache *ca, struct list_head *list,
-                              struct btree_op *op, unsigned bucket_index)
+                              unsigned bucket_index)
 {
        struct journal_device *ja = &ca->journal;
        struct bio *bio = &ja->bio;
 
        struct journal_replay *i;
        struct jset *j, *data = ca->set->journal.w[0].data;
+       struct closure cl;
        unsigned len, left, offset = 0;
        int ret = 0;
        sector_t bucket = bucket_to_sector(ca->set, ca->sb.d[bucket_index]);
 
+       closure_init_stack(&cl);
+
        pr_debug("reading %llu", (uint64_t) bucket);
 
        while (offset < ca->sb.bucket_size) {
@@ -55,11 +57,11 @@ reread:             left = ca->sb.bucket_size - offset;
                bio->bi_size    = len << 9;
 
                bio->bi_end_io  = journal_read_endio;
-               bio->bi_private = &op->cl;
+               bio->bi_private = &cl;
                bch_bio_map(bio, data);
 
-               closure_bio_submit(bio, &op->cl, ca);
-               closure_sync(&op->cl);
+               closure_bio_submit(bio, &cl, ca);
+               closure_sync(&cl);
 
                /* This function could be simpler now since we no longer write
                 * journal entries that overlap bucket boundaries; this means
@@ -72,7 +74,7 @@ reread:               left = ca->sb.bucket_size - offset;
                        struct list_head *where;
                        size_t blocks, bytes = set_bytes(j);
 
-                       if (j->magic != jset_magic(ca->set))
+                       if (j->magic != jset_magic(&ca->sb))
                                return ret;
 
                        if (bytes > left << 9)
@@ -129,12 +131,11 @@ next_set:
        return ret;
 }
 
-int bch_journal_read(struct cache_set *c, struct list_head *list,
-                       struct btree_op *op)
+int bch_journal_read(struct cache_set *c, struct list_head *list)
 {
 #define read_bucket(b)                                                 \
        ({                                                              \
-               int ret = journal_read_bucket(ca, list, op, b);         \
+               int ret = journal_read_bucket(ca, list, b);             \
                __set_bit(b, bitmap);                                   \
                if (ret < 0)                                            \
                        return ret;                                     \
@@ -292,8 +293,7 @@ void bch_journal_mark(struct cache_set *c, struct list_head *list)
        }
 }
 
-int bch_journal_replay(struct cache_set *s, struct list_head *list,
-                         struct btree_op *op)
+int bch_journal_replay(struct cache_set *s, struct list_head *list)
 {
        int ret = 0, keys = 0, entries = 0;
        struct bkey *k;
@@ -301,31 +301,30 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list,
                list_entry(list->prev, struct journal_replay, list);
 
        uint64_t start = i->j.last_seq, end = i->j.seq, n = start;
+       struct keylist keylist;
+
+       bch_keylist_init(&keylist);
 
        list_for_each_entry(i, list, list) {
                BUG_ON(i->pin && atomic_read(i->pin) != 1);
 
-               if (n != i->j.seq)
-                       pr_err(
-               "journal entries %llu-%llu missing! (replaying %llu-%llu)\n",
-               n, i->j.seq - 1, start, end);
+               cache_set_err_on(n != i->j.seq, s,
+"bcache: journal entries %llu-%llu missing! (replaying %llu-%llu)",
+                                n, i->j.seq - 1, start, end);
 
                for (k = i->j.start;
                     k < end(&i->j);
                     k = bkey_next(k)) {
                        trace_bcache_journal_replay_key(k);
 
-                       bkey_copy(op->keys.top, k);
-                       bch_keylist_push(&op->keys);
-
-                       op->journal = i->pin;
-                       atomic_inc(op->journal);
+                       bkey_copy(keylist.top, k);
+                       bch_keylist_push(&keylist);
 
-                       ret = bch_btree_insert(op, s);
+                       ret = bch_btree_insert(s, &keylist, i->pin, NULL);
                        if (ret)
                                goto err;
 
-                       BUG_ON(!bch_keylist_empty(&op->keys));
+                       BUG_ON(!bch_keylist_empty(&keylist));
                        keys++;
 
                        cond_resched();
@@ -339,14 +338,13 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list,
 
        pr_info("journal replay done, %i keys in %i entries, seq %llu",
                keys, entries, end);
-
+err:
        while (!list_empty(list)) {
                i = list_first_entry(list, struct journal_replay, list);
                list_del(&i->list);
                kfree(i);
        }
-err:
-       closure_sync(&op->cl);
+
        return ret;
 }
 
@@ -358,48 +356,35 @@ static void btree_flush_write(struct cache_set *c)
         * Try to find the btree node with that references the oldest journal
         * entry, best is our current candidate and is locked if non NULL:
         */
-       struct btree *b, *best = NULL;
-       unsigned iter;
+       struct btree *b, *best;
+       unsigned i;
+retry:
+       best = NULL;
+
+       for_each_cached_btree(b, c, i)
+               if (btree_current_write(b)->journal) {
+                       if (!best)
+                               best = b;
+                       else if (journal_pin_cmp(c,
+                                       btree_current_write(best)->journal,
+                                       btree_current_write(b)->journal)) {
+                               best = b;
+                       }
+               }
 
-       for_each_cached_btree(b, c, iter) {
-               if (!down_write_trylock(&b->lock))
-                       continue;
+       b = best;
+       if (b) {
+               rw_lock(true, b, b->level);
 
-               if (!btree_node_dirty(b) ||
-                   !btree_current_write(b)->journal) {
+               if (!btree_current_write(b)->journal) {
                        rw_unlock(true, b);
-                       continue;
+                       /* We raced */
+                       goto retry;
                }
 
-               if (!best)
-                       best = b;
-               else if (journal_pin_cmp(c,
-                                        btree_current_write(best),
-                                        btree_current_write(b))) {
-                       rw_unlock(true, best);
-                       best = b;
-               } else
-                       rw_unlock(true, b);
+               bch_btree_node_write(b, NULL);
+               rw_unlock(true, b);
        }
-
-       if (best)
-               goto out;
-
-       /* We can't find the best btree node, just pick the first */
-       list_for_each_entry(b, &c->btree_cache, list)
-               if (!b->level && btree_node_dirty(b)) {
-                       best = b;
-                       rw_lock(true, best, best->level);
-                       goto found;
-               }
-
-out:
-       if (!best)
-               return;
-found:
-       if (btree_node_dirty(best))
-               bch_btree_node_write(best, NULL);
-       rw_unlock(true, best);
 }
 
 #define last_seq(j)    ((j)->seq - fifo_used(&(j)->pin) + 1)
@@ -495,7 +480,7 @@ static void journal_reclaim(struct cache_set *c)
                do_journal_discard(ca);
 
        if (c->journal.blocks_free)
-               return;
+               goto out;
 
        /*
         * Allocate:
@@ -521,7 +506,7 @@ static void journal_reclaim(struct cache_set *c)
 
        if (n)
                c->journal.blocks_free = c->sb.bucket_size >> c->block_bits;
-
+out:
        if (!journal_full(&c->journal))
                __closure_wake_up(&c->journal.wait);
 }
@@ -554,32 +539,26 @@ static void journal_write_endio(struct bio *bio, int error)
        struct journal_write *w = bio->bi_private;
 
        cache_set_err_on(error, w->c, "journal io error");
-       closure_put(&w->c->journal.io.cl);
+       closure_put(&w->c->journal.io);
 }
 
 static void journal_write(struct closure *);
 
 static void journal_write_done(struct closure *cl)
 {
-       struct journal *j = container_of(cl, struct journal, io.cl);
-       struct cache_set *c = container_of(j, struct cache_set, journal);
-
+       struct journal *j = container_of(cl, struct journal, io);
        struct journal_write *w = (j->cur == j->w)
                ? &j->w[1]
                : &j->w[0];
 
        __closure_wake_up(&w->wait);
-
-       if (c->journal_delay_ms)
-               closure_delay(&j->io, msecs_to_jiffies(c->journal_delay_ms));
-
-       continue_at(cl, journal_write, system_wq);
+       continue_at_nobarrier(cl, journal_write, system_wq);
 }
 
 static void journal_write_unlocked(struct closure *cl)
        __releases(c->journal.lock)
 {
-       struct cache_set *c = container_of(cl, struct cache_set, journal.io.cl);
+       struct cache_set *c = container_of(cl, struct cache_set, journal.io);
        struct cache *ca;
        struct journal_write *w = c->journal.cur;
        struct bkey *k = &c->journal.key;
@@ -617,7 +596,7 @@ static void journal_write_unlocked(struct closure *cl)
        for_each_cache(ca, c, i)
                w->data->prio_bucket[ca->sb.nr_this_dev] = ca->prio_buckets[0];
 
-       w->data->magic          = jset_magic(c);
+       w->data->magic          = jset_magic(&c->sb);
        w->data->version        = BCACHE_JSET_VERSION;
        w->data->last_seq       = last_seq(&c->journal);
        w->data->csum           = csum_set(w->data);
@@ -660,121 +639,134 @@ static void journal_write_unlocked(struct closure *cl)
 
 static void journal_write(struct closure *cl)
 {
-       struct cache_set *c = container_of(cl, struct cache_set, journal.io.cl);
+       struct cache_set *c = container_of(cl, struct cache_set, journal.io);
 
        spin_lock(&c->journal.lock);
        journal_write_unlocked(cl);
 }
 
-static void __journal_try_write(struct cache_set *c, bool noflush)
+static void journal_try_write(struct cache_set *c)
        __releases(c->journal.lock)
 {
-       struct closure *cl = &c->journal.io.cl;
+       struct closure *cl = &c->journal.io;
+       struct journal_write *w = c->journal.cur;
 
-       if (!closure_trylock(cl, &c->cl))
-               spin_unlock(&c->journal.lock);
-       else if (noflush && journal_full(&c->journal)) {
-               spin_unlock(&c->journal.lock);
-               continue_at(cl, journal_write, system_wq);
-       } else
+       w->need_write = true;
+
+       if (closure_trylock(cl, &c->cl))
                journal_write_unlocked(cl);
+       else
+               spin_unlock(&c->journal.lock);
 }
 
-#define journal_try_write(c)   __journal_try_write(c, false)
-
-void bch_journal_meta(struct cache_set *c, struct closure *cl)
+static struct journal_write *journal_wait_for_write(struct cache_set *c,
+                                                   unsigned nkeys)
 {
-       struct journal_write *w;
+       size_t sectors;
+       struct closure cl;
 
-       if (CACHE_SYNC(&c->sb)) {
-               spin_lock(&c->journal.lock);
+       closure_init_stack(&cl);
+
+       spin_lock(&c->journal.lock);
 
-               w = c->journal.cur;
-               w->need_write = true;
+       while (1) {
+               struct journal_write *w = c->journal.cur;
 
-               if (cl)
-                       BUG_ON(!closure_wait(&w->wait, cl));
+               sectors = __set_blocks(w->data, w->data->keys + nkeys,
+                                      c) * c->sb.block_size;
 
-               closure_flush(&c->journal.io);
-               __journal_try_write(c, true);
+               if (sectors <= min_t(size_t,
+                                    c->journal.blocks_free * c->sb.block_size,
+                                    PAGE_SECTORS << JSET_BITS))
+                       return w;
+
+               /* XXX: tracepoint */
+               if (!journal_full(&c->journal)) {
+                       trace_bcache_journal_entry_full(c);
+
+                       /*
+                        * XXX: If we were inserting so many keys that they
+                        * won't fit in an _empty_ journal write, we'll
+                        * deadlock. For now, handle this in
+                        * bch_keylist_realloc() - but something to think about.
+                        */
+                       BUG_ON(!w->data->keys);
+
+                       closure_wait(&w->wait, &cl);
+                       journal_try_write(c); /* unlocks */
+               } else {
+                       trace_bcache_journal_full(c);
+
+                       closure_wait(&c->journal.wait, &cl);
+                       journal_reclaim(c);
+                       spin_unlock(&c->journal.lock);
+
+                       btree_flush_write(c);
+               }
+
+               closure_sync(&cl);
+               spin_lock(&c->journal.lock);
        }
 }
 
+static void journal_write_work(struct work_struct *work)
+{
+       struct cache_set *c = container_of(to_delayed_work(work),
+                                          struct cache_set,
+                                          journal.work);
+       spin_lock(&c->journal.lock);
+       journal_try_write(c);
+}
+
 /*
  * Entry point to the journalling code - bio_insert() and btree_invalidate()
  * pass bch_journal() a list of keys to be journalled, and then
  * bch_journal() hands those same keys off to btree_insert_async()
  */
 
-void bch_journal(struct closure *cl)
+atomic_t *bch_journal(struct cache_set *c,
+                     struct keylist *keys,
+                     struct closure *parent)
 {
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
-       struct cache_set *c = op->c;
        struct journal_write *w;
-       size_t b, n = ((uint64_t *) op->keys.top) - op->keys.list;
-
-       if (op->type != BTREE_INSERT ||
-           !CACHE_SYNC(&c->sb))
-               goto out;
+       atomic_t *ret;
 
-       /*
-        * If we're looping because we errored, might already be waiting on
-        * another journal write:
-        */
-       while (atomic_read(&cl->parent->remaining) & CLOSURE_WAITING)
-               closure_sync(cl->parent);
+       if (!CACHE_SYNC(&c->sb))
+               return NULL;
 
-       spin_lock(&c->journal.lock);
+       w = journal_wait_for_write(c, bch_keylist_nkeys(keys));
 
-       if (journal_full(&c->journal)) {
-               trace_bcache_journal_full(c);
+       memcpy(end(w->data), keys->keys, bch_keylist_bytes(keys));
+       w->data->keys += bch_keylist_nkeys(keys);
 
-               closure_wait(&c->journal.wait, cl);
+       ret = &fifo_back(&c->journal.pin);
+       atomic_inc(ret);
 
-               journal_reclaim(c);
+       if (parent) {
+               closure_wait(&w->wait, parent);
+               journal_try_write(c);
+       } else if (!w->need_write) {
+               schedule_delayed_work(&c->journal.work,
+                                     msecs_to_jiffies(c->journal_delay_ms));
+               spin_unlock(&c->journal.lock);
+       } else {
                spin_unlock(&c->journal.lock);
-
-               btree_flush_write(c);
-               continue_at(cl, bch_journal, bcache_wq);
        }
 
-       w = c->journal.cur;
-       w->need_write = true;
-       b = __set_blocks(w->data, w->data->keys + n, c);
-
-       if (b * c->sb.block_size > PAGE_SECTORS << JSET_BITS ||
-           b > c->journal.blocks_free) {
-               trace_bcache_journal_entry_full(c);
-
-               /*
-                * XXX: If we were inserting so many keys that they won't fit in
-                * an _empty_ journal write, we'll deadlock. For now, handle
-                * this in bch_keylist_realloc() - but something to think about.
-                */
-               BUG_ON(!w->data->keys);
-
-               BUG_ON(!closure_wait(&w->wait, cl));
-
-               closure_flush(&c->journal.io);
 
-               journal_try_write(c);
-               continue_at(cl, bch_journal, bcache_wq);
-       }
-
-       memcpy(end(w->data), op->keys.list, n * sizeof(uint64_t));
-       w->data->keys += n;
+       return ret;
+}
 
-       op->journal = &fifo_back(&c->journal.pin);
-       atomic_inc(op->journal);
+void bch_journal_meta(struct cache_set *c, struct closure *cl)
+{
+       struct keylist keys;
+       atomic_t *ref;
 
-       if (op->flush_journal) {
-               closure_flush(&c->journal.io);
-               closure_wait(&w->wait, cl->parent);
-       }
+       bch_keylist_init(&keys);
 
-       journal_try_write(c);
-out:
-       bch_btree_insert_async(cl);
+       ref = bch_journal(c, &keys, cl);
+       if (ref)
+               atomic_dec_bug(ref);
 }
 
 void bch_journal_free(struct cache_set *c)
@@ -790,6 +782,7 @@ int bch_journal_alloc(struct cache_set *c)
 
        closure_init_unlocked(&j->io);
        spin_lock_init(&j->lock);
+       INIT_DELAYED_WORK(&j->work, journal_write_work);
 
        c->journal_delay_ms = 100;
 
index 3d7851274b0413d28d89dec4b82693b760982e39..a6472fda94b25c00a340bcfefd48b3ac0c762c6e 100644 (file)
  * nodes that are pinning the oldest journal entries first.
  */
 
-#define BCACHE_JSET_VERSION_UUIDv1     1
-/* Always latest UUID format */
-#define BCACHE_JSET_VERSION_UUID       1
-#define BCACHE_JSET_VERSION            1
-
-/*
- * On disk format for a journal entry:
- * seq is monotonically increasing; every journal entry has its own unique
- * sequence number.
- *
- * last_seq is the oldest journal entry that still has keys the btree hasn't
- * flushed to disk yet.
- *
- * version is for on disk format changes.
- */
-struct jset {
-       uint64_t                csum;
-       uint64_t                magic;
-       uint64_t                seq;
-       uint32_t                version;
-       uint32_t                keys;
-
-       uint64_t                last_seq;
-
-       BKEY_PADDED(uuid_bucket);
-       BKEY_PADDED(btree_root);
-       uint16_t                btree_level;
-       uint16_t                pad[3];
-
-       uint64_t                prio_bucket[MAX_CACHES_PER_SET];
-
-       union {
-               struct bkey     start[0];
-               uint64_t        d[0];
-       };
-};
-
 /*
  * Only used for holding the journal entries we read in btree_journal_read()
  * during cache_registration
@@ -140,7 +103,8 @@ struct journal {
        spinlock_t              lock;
        /* used when waiting because the journal was full */
        struct closure_waitlist wait;
-       struct closure_with_timer io;
+       struct closure          io;
+       struct delayed_work     work;
 
        /* Number of blocks free in the bucket(s) we're currently writing to */
        unsigned                blocks_free;
@@ -188,8 +152,7 @@ struct journal_device {
 };
 
 #define journal_pin_cmp(c, l, r)                               \
-       (fifo_idx(&(c)->journal.pin, (l)->journal) >            \
-        fifo_idx(&(c)->journal.pin, (r)->journal))
+       (fifo_idx(&(c)->journal.pin, (l)) > fifo_idx(&(c)->journal.pin, (r)))
 
 #define JOURNAL_PIN    20000
 
@@ -199,15 +162,14 @@ struct journal_device {
 struct closure;
 struct cache_set;
 struct btree_op;
+struct keylist;
 
-void bch_journal(struct closure *);
+atomic_t *bch_journal(struct cache_set *, struct keylist *, struct closure *);
 void bch_journal_next(struct journal *);
 void bch_journal_mark(struct cache_set *, struct list_head *);
 void bch_journal_meta(struct cache_set *, struct closure *);
-int bch_journal_read(struct cache_set *, struct list_head *,
-                       struct btree_op *);
-int bch_journal_replay(struct cache_set *, struct list_head *,
-                         struct btree_op *);
+int bch_journal_read(struct cache_set *, struct list_head *);
+int bch_journal_replay(struct cache_set *, struct list_head *);
 
 void bch_journal_free(struct cache_set *);
 int bch_journal_alloc(struct cache_set *);
index 1a3b4f4786c3cee411d16c3a9a453e1fcd33b681..7c1275e66025b691ec8ee4896448d46e28a2c5d9 100644 (file)
@@ -12,8 +12,9 @@
 #include <trace/events/bcache.h>
 
 struct moving_io {
+       struct closure          cl;
        struct keybuf_key       *w;
-       struct search           s;
+       struct data_insert_op   op;
        struct bbio             bio;
 };
 
@@ -38,13 +39,13 @@ static bool moving_pred(struct keybuf *buf, struct bkey *k)
 
 static void moving_io_destructor(struct closure *cl)
 {
-       struct moving_io *io = container_of(cl, struct moving_io, s.cl);
+       struct moving_io *io = container_of(cl, struct moving_io, cl);
        kfree(io);
 }
 
 static void write_moving_finish(struct closure *cl)
 {
-       struct moving_io *io = container_of(cl, struct moving_io, s.cl);
+       struct moving_io *io = container_of(cl, struct moving_io, cl);
        struct bio *bio = &io->bio.bio;
        struct bio_vec *bv;
        int i;
@@ -52,13 +53,12 @@ static void write_moving_finish(struct closure *cl)
        bio_for_each_segment_all(bv, bio, i)
                __free_page(bv->bv_page);
 
-       if (io->s.op.insert_collision)
+       if (io->op.replace_collision)
                trace_bcache_gc_copy_collision(&io->w->key);
 
-       bch_keybuf_del(&io->s.op.c->moving_gc_keys, io->w);
+       bch_keybuf_del(&io->op.c->moving_gc_keys, io->w);
 
-       atomic_dec_bug(&io->s.op.c->in_flight);
-       closure_wake_up(&io->s.op.c->moving_gc_wait);
+       up(&io->op.c->moving_in_flight);
 
        closure_return_with_destructor(cl, moving_io_destructor);
 }
@@ -66,12 +66,12 @@ static void write_moving_finish(struct closure *cl)
 static void read_moving_endio(struct bio *bio, int error)
 {
        struct moving_io *io = container_of(bio->bi_private,
-                                           struct moving_io, s.cl);
+                                           struct moving_io, cl);
 
        if (error)
-               io->s.error = error;
+               io->op.error = error;
 
-       bch_bbio_endio(io->s.op.c, bio, error, "reading data to move");
+       bch_bbio_endio(io->op.c, bio, error, "reading data to move");
 }
 
 static void moving_init(struct moving_io *io)
@@ -85,54 +85,53 @@ static void moving_init(struct moving_io *io)
        bio->bi_size            = KEY_SIZE(&io->w->key) << 9;
        bio->bi_max_vecs        = DIV_ROUND_UP(KEY_SIZE(&io->w->key),
                                               PAGE_SECTORS);
-       bio->bi_private         = &io->s.cl;
+       bio->bi_private         = &io->cl;
        bio->bi_io_vec          = bio->bi_inline_vecs;
        bch_bio_map(bio, NULL);
 }
 
 static void write_moving(struct closure *cl)
 {
-       struct search *s = container_of(cl, struct search, cl);
-       struct moving_io *io = container_of(s, struct moving_io, s);
+       struct moving_io *io = container_of(cl, struct moving_io, cl);
+       struct data_insert_op *op = &io->op;
 
-       if (!s->error) {
+       if (!op->error) {
                moving_init(io);
 
-               io->bio.bio.bi_sector   = KEY_START(&io->w->key);
-               s->op.lock              = -1;
-               s->op.write_prio        = 1;
-               s->op.cache_bio         = &io->bio.bio;
+               io->bio.bio.bi_sector = KEY_START(&io->w->key);
+               op->write_prio          = 1;
+               op->bio                 = &io->bio.bio;
 
-               s->writeback            = KEY_DIRTY(&io->w->key);
-               s->op.csum              = KEY_CSUM(&io->w->key);
+               op->writeback           = KEY_DIRTY(&io->w->key);
+               op->csum                = KEY_CSUM(&io->w->key);
 
-               s->op.type = BTREE_REPLACE;
-               bkey_copy(&s->op.replace, &io->w->key);
+               bkey_copy(&op->replace_key, &io->w->key);
+               op->replace             = true;
 
-               closure_init(&s->op.cl, cl);
-               bch_insert_data(&s->op.cl);
+               closure_call(&op->cl, bch_data_insert, NULL, cl);
        }
 
-       continue_at(cl, write_moving_finish, NULL);
+       continue_at(cl, write_moving_finish, system_wq);
 }
 
 static void read_moving_submit(struct closure *cl)
 {
-       struct search *s = container_of(cl, struct search, cl);
-       struct moving_io *io = container_of(s, struct moving_io, s);
+       struct moving_io *io = container_of(cl, struct moving_io, cl);
        struct bio *bio = &io->bio.bio;
 
-       bch_submit_bbio(bio, s->op.c, &io->w->key, 0);
+       bch_submit_bbio(bio, io->op.c, &io->w->key, 0);
 
-       continue_at(cl, write_moving, bch_gc_wq);
+       continue_at(cl, write_moving, system_wq);
 }
 
-static void read_moving(struct closure *cl)
+static void read_moving(struct cache_set *c)
 {
-       struct cache_set *c = container_of(cl, struct cache_set, moving_gc);
        struct keybuf_key *w;
        struct moving_io *io;
        struct bio *bio;
+       struct closure cl;
+
+       closure_init_stack(&cl);
 
        /* XXX: if we error, background writeback could stall indefinitely */
 
@@ -150,8 +149,8 @@ static void read_moving(struct closure *cl)
 
                w->private      = io;
                io->w           = w;
-               io->s.op.inode  = KEY_INODE(&w->key);
-               io->s.op.c      = c;
+               io->op.inode    = KEY_INODE(&w->key);
+               io->op.c        = c;
 
                moving_init(io);
                bio = &io->bio.bio;
@@ -164,13 +163,8 @@ static void read_moving(struct closure *cl)
 
                trace_bcache_gc_copy(&w->key);
 
-               closure_call(&io->s.cl, read_moving_submit, NULL, &c->gc.cl);
-
-               if (atomic_inc_return(&c->in_flight) >= 64) {
-                       closure_wait_event(&c->moving_gc_wait, cl,
-                                          atomic_read(&c->in_flight) < 64);
-                       continue_at(cl, read_moving, bch_gc_wq);
-               }
+               down(&c->moving_in_flight);
+               closure_call(&io->cl, read_moving_submit, NULL, &cl);
        }
 
        if (0) {
@@ -180,7 +174,7 @@ err:                if (!IS_ERR_OR_NULL(w->private))
                bch_keybuf_del(&c->moving_gc_keys, w);
        }
 
-       closure_return(cl);
+       closure_sync(&cl);
 }
 
 static bool bucket_cmp(struct bucket *l, struct bucket *r)
@@ -193,15 +187,14 @@ static unsigned bucket_heap_top(struct cache *ca)
        return GC_SECTORS_USED(heap_peek(&ca->heap));
 }
 
-void bch_moving_gc(struct closure *cl)
+void bch_moving_gc(struct cache_set *c)
 {
-       struct cache_set *c = container_of(cl, struct cache_set, gc.cl);
        struct cache *ca;
        struct bucket *b;
        unsigned i;
 
        if (!c->copy_gc_enabled)
-               closure_return(cl);
+               return;
 
        mutex_lock(&c->bucket_lock);
 
@@ -242,13 +235,11 @@ void bch_moving_gc(struct closure *cl)
 
        c->moving_gc_keys.last_scanned = ZERO_KEY;
 
-       closure_init(&c->moving_gc, cl);
-       read_moving(&c->moving_gc);
-
-       closure_return(cl);
+       read_moving(c);
 }
 
 void bch_moving_init_cache_set(struct cache_set *c)
 {
        bch_keybuf_init(&c->moving_gc_keys);
+       sema_init(&c->moving_in_flight, 64);
 }
index 2a7f0dd6abab4d6bb21ba028b5b3a25721080a2c..fbcc851ed5a5a74b09d763c455d132dee68e7eb3 100644 (file)
@@ -25,7 +25,7 @@
 
 struct kmem_cache *bch_search_cache;
 
-static void check_should_skip(struct cached_dev *, struct search *);
+static void bch_data_insert_start(struct closure *);
 
 /* Cgroup interface */
 
@@ -213,221 +213,79 @@ static void bio_csum(struct bio *bio, struct bkey *k)
 
 /* Insert data into cache */
 
-static void bio_invalidate(struct closure *cl)
+static void bch_data_insert_keys(struct closure *cl)
 {
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
-       struct bio *bio = op->cache_bio;
-
-       pr_debug("invalidating %i sectors from %llu",
-                bio_sectors(bio), (uint64_t) bio->bi_sector);
-
-       while (bio_sectors(bio)) {
-               unsigned len = min(bio_sectors(bio), 1U << 14);
-
-               if (bch_keylist_realloc(&op->keys, 0, op->c))
-                       goto out;
-
-               bio->bi_sector  += len;
-               bio->bi_size    -= len << 9;
-
-               bch_keylist_add(&op->keys,
-                               &KEY(op->inode, bio->bi_sector, len));
-       }
-
-       op->insert_data_done = true;
-       bio_put(bio);
-out:
-       continue_at(cl, bch_journal, bcache_wq);
-}
-
-struct open_bucket {
-       struct list_head        list;
-       struct task_struct      *last;
-       unsigned                sectors_free;
-       BKEY_PADDED(key);
-};
-
-void bch_open_buckets_free(struct cache_set *c)
-{
-       struct open_bucket *b;
-
-       while (!list_empty(&c->data_buckets)) {
-               b = list_first_entry(&c->data_buckets,
-                                    struct open_bucket, list);
-               list_del(&b->list);
-               kfree(b);
-       }
-}
-
-int bch_open_buckets_alloc(struct cache_set *c)
-{
-       int i;
-
-       spin_lock_init(&c->data_bucket_lock);
-
-       for (i = 0; i < 6; i++) {
-               struct open_bucket *b = kzalloc(sizeof(*b), GFP_KERNEL);
-               if (!b)
-                       return -ENOMEM;
-
-               list_add(&b->list, &c->data_buckets);
-       }
-
-       return 0;
-}
-
-/*
- * We keep multiple buckets open for writes, and try to segregate different
- * write streams for better cache utilization: first we look for a bucket where
- * the last write to it was sequential with the current write, and failing that
- * we look for a bucket that was last used by the same task.
- *
- * The ideas is if you've got multiple tasks pulling data into the cache at the
- * same time, you'll get better cache utilization if you try to segregate their
- * data and preserve locality.
- *
- * For example, say you've starting Firefox at the same time you're copying a
- * bunch of files. Firefox will likely end up being fairly hot and stay in the
- * cache awhile, but the data you copied might not be; if you wrote all that
- * data to the same buckets it'd get invalidated at the same time.
- *
- * Both of those tasks will be doing fairly random IO so we can't rely on
- * detecting sequential IO to segregate their data, but going off of the task
- * should be a sane heuristic.
- */
-static struct open_bucket *pick_data_bucket(struct cache_set *c,
-                                           const struct bkey *search,
-                                           struct task_struct *task,
-                                           struct bkey *alloc)
-{
-       struct open_bucket *ret, *ret_task = NULL;
-
-       list_for_each_entry_reverse(ret, &c->data_buckets, list)
-               if (!bkey_cmp(&ret->key, search))
-                       goto found;
-               else if (ret->last == task)
-                       ret_task = ret;
-
-       ret = ret_task ?: list_first_entry(&c->data_buckets,
-                                          struct open_bucket, list);
-found:
-       if (!ret->sectors_free && KEY_PTRS(alloc)) {
-               ret->sectors_free = c->sb.bucket_size;
-               bkey_copy(&ret->key, alloc);
-               bkey_init(alloc);
-       }
-
-       if (!ret->sectors_free)
-               ret = NULL;
-
-       return ret;
-}
-
-/*
- * Allocates some space in the cache to write to, and k to point to the newly
- * allocated space, and updates KEY_SIZE(k) and KEY_OFFSET(k) (to point to the
- * end of the newly allocated space).
- *
- * May allocate fewer sectors than @sectors, KEY_SIZE(k) indicates how many
- * sectors were actually allocated.
- *
- * If s->writeback is true, will not fail.
- */
-static bool bch_alloc_sectors(struct bkey *k, unsigned sectors,
-                             struct search *s)
-{
-       struct cache_set *c = s->op.c;
-       struct open_bucket *b;
-       BKEY_PADDED(key) alloc;
-       struct closure cl, *w = NULL;
-       unsigned i;
-
-       if (s->writeback) {
-               closure_init_stack(&cl);
-               w = &cl;
-       }
+       struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
+       atomic_t *journal_ref = NULL;
+       struct bkey *replace_key = op->replace ? &op->replace_key : NULL;
+       int ret;
 
        /*
-        * We might have to allocate a new bucket, which we can't do with a
-        * spinlock held. So if we have to allocate, we drop the lock, allocate
-        * and then retry. KEY_PTRS() indicates whether alloc points to
-        * allocated bucket(s).
+        * If we're looping, might already be waiting on
+        * another journal write - can't wait on more than one journal write at
+        * a time
+        *
+        * XXX: this looks wrong
         */
+#if 0
+       while (atomic_read(&s->cl.remaining) & CLOSURE_WAITING)
+               closure_sync(&s->cl);
+#endif
 
-       bkey_init(&alloc.key);
-       spin_lock(&c->data_bucket_lock);
-
-       while (!(b = pick_data_bucket(c, k, s->task, &alloc.key))) {
-               unsigned watermark = s->op.write_prio
-                       ? WATERMARK_MOVINGGC
-                       : WATERMARK_NONE;
-
-               spin_unlock(&c->data_bucket_lock);
-
-               if (bch_bucket_alloc_set(c, watermark, &alloc.key, 1, w))
-                       return false;
+       if (!op->replace)
+               journal_ref = bch_journal(op->c, &op->insert_keys,
+                                         op->flush_journal ? cl : NULL);
 
-               spin_lock(&c->data_bucket_lock);
+       ret = bch_btree_insert(op->c, &op->insert_keys,
+                              journal_ref, replace_key);
+       if (ret == -ESRCH) {
+               op->replace_collision = true;
+       } else if (ret) {
+               op->error               = -ENOMEM;
+               op->insert_data_done    = true;
        }
 
-       /*
-        * If we had to allocate, we might race and not need to allocate the
-        * second time we call find_data_bucket(). If we allocated a bucket but
-        * didn't use it, drop the refcount bch_bucket_alloc_set() took:
-        */
-       if (KEY_PTRS(&alloc.key))
-               __bkey_put(c, &alloc.key);
-
-       for (i = 0; i < KEY_PTRS(&b->key); i++)
-               EBUG_ON(ptr_stale(c, &b->key, i));
+       if (journal_ref)
+               atomic_dec_bug(journal_ref);
 
-       /* Set up the pointer to the space we're allocating: */
+       if (!op->insert_data_done)
+               continue_at(cl, bch_data_insert_start, bcache_wq);
 
-       for (i = 0; i < KEY_PTRS(&b->key); i++)
-               k->ptr[i] = b->key.ptr[i];
+       bch_keylist_free(&op->insert_keys);
+       closure_return(cl);
+}
 
-       sectors = min(sectors, b->sectors_free);
+static void bch_data_invalidate(struct closure *cl)
+{
+       struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
+       struct bio *bio = op->bio;
 
-       SET_KEY_OFFSET(k, KEY_OFFSET(k) + sectors);
-       SET_KEY_SIZE(k, sectors);
-       SET_KEY_PTRS(k, KEY_PTRS(&b->key));
+       pr_debug("invalidating %i sectors from %llu",
+                bio_sectors(bio), (uint64_t) bio->bi_sector);
 
-       /*
-        * Move b to the end of the lru, and keep track of what this bucket was
-        * last used for:
-        */
-       list_move_tail(&b->list, &c->data_buckets);
-       bkey_copy_key(&b->key, k);
-       b->last = s->task;
+       while (bio_sectors(bio)) {
+               unsigned sectors = min(bio_sectors(bio),
+                                      1U << (KEY_SIZE_BITS - 1));
 
-       b->sectors_free -= sectors;
+               if (bch_keylist_realloc(&op->insert_keys, 0, op->c))
+                       goto out;
 
-       for (i = 0; i < KEY_PTRS(&b->key); i++) {
-               SET_PTR_OFFSET(&b->key, i, PTR_OFFSET(&b->key, i) + sectors);
+               bio->bi_sector  += sectors;
+               bio->bi_size    -= sectors << 9;
 
-               atomic_long_add(sectors,
-                               &PTR_CACHE(c, &b->key, i)->sectors_written);
+               bch_keylist_add(&op->insert_keys,
+                               &KEY(op->inode, bio->bi_sector, sectors));
        }
 
-       if (b->sectors_free < c->sb.block_size)
-               b->sectors_free = 0;
-
-       /*
-        * k takes refcounts on the buckets it points to until it's inserted
-        * into the btree, but if we're done with this bucket we just transfer
-        * get_data_bucket()'s refcount.
-        */
-       if (b->sectors_free)
-               for (i = 0; i < KEY_PTRS(&b->key); i++)
-                       atomic_inc(&PTR_BUCKET(c, &b->key, i)->pin);
-
-       spin_unlock(&c->data_bucket_lock);
-       return true;
+       op->insert_data_done = true;
+       bio_put(bio);
+out:
+       continue_at(cl, bch_data_insert_keys, bcache_wq);
 }
 
-static void bch_insert_data_error(struct closure *cl)
+static void bch_data_insert_error(struct closure *cl)
 {
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
+       struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
 
        /*
         * Our data write just errored, which means we've got a bunch of keys to
@@ -438,35 +296,34 @@ static void bch_insert_data_error(struct closure *cl)
         * from the keys we'll accomplish just that.
         */
 
-       struct bkey *src = op->keys.bottom, *dst = op->keys.bottom;
+       struct bkey *src = op->insert_keys.keys, *dst = op->insert_keys.keys;
 
-       while (src != op->keys.top) {
+       while (src != op->insert_keys.top) {
                struct bkey *n = bkey_next(src);
 
                SET_KEY_PTRS(src, 0);
-               bkey_copy(dst, src);
+               memmove(dst, src, bkey_bytes(src));
 
                dst = bkey_next(dst);
                src = n;
        }
 
-       op->keys.top = dst;
+       op->insert_keys.top = dst;
 
-       bch_journal(cl);
+       bch_data_insert_keys(cl);
 }
 
-static void bch_insert_data_endio(struct bio *bio, int error)
+static void bch_data_insert_endio(struct bio *bio, int error)
 {
        struct closure *cl = bio->bi_private;
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
-       struct search *s = container_of(op, struct search, op);
+       struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
 
        if (error) {
                /* TODO: We could try to recover from this. */
-               if (s->writeback)
-                       s->error = error;
-               else if (s->write)
-                       set_closure_fn(cl, bch_insert_data_error, bcache_wq);
+               if (op->writeback)
+                       op->error = error;
+               else if (!op->replace)
+                       set_closure_fn(cl, bch_data_insert_error, bcache_wq);
                else
                        set_closure_fn(cl, NULL, NULL);
        }
@@ -474,18 +331,17 @@ static void bch_insert_data_endio(struct bio *bio, int error)
        bch_bbio_endio(op->c, bio, error, "writing data to cache");
 }
 
-static void bch_insert_data_loop(struct closure *cl)
+static void bch_data_insert_start(struct closure *cl)
 {
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
-       struct search *s = container_of(op, struct search, op);
-       struct bio *bio = op->cache_bio, *n;
+       struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
+       struct bio *bio = op->bio, *n;
 
-       if (op->skip)
-               return bio_invalidate(cl);
+       if (op->bypass)
+               return bch_data_invalidate(cl);
 
        if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0) {
                set_gc_sectors(op->c);
-               bch_queue_gc(op->c);
+               wake_up_gc(op->c);
        }
 
        /*
@@ -497,29 +353,30 @@ static void bch_insert_data_loop(struct closure *cl)
        do {
                unsigned i;
                struct bkey *k;
-               struct bio_set *split = s->d
-                       ? s->d->bio_split : op->c->bio_split;
+               struct bio_set *split = op->c->bio_split;
 
                /* 1 for the device pointer and 1 for the chksum */
-               if (bch_keylist_realloc(&op->keys,
+               if (bch_keylist_realloc(&op->insert_keys,
                                        1 + (op->csum ? 1 : 0),
                                        op->c))
-                       continue_at(cl, bch_journal, bcache_wq);
+                       continue_at(cl, bch_data_insert_keys, bcache_wq);
 
-               k = op->keys.top;
+               k = op->insert_keys.top;
                bkey_init(k);
                SET_KEY_INODE(k, op->inode);
                SET_KEY_OFFSET(k, bio->bi_sector);
 
-               if (!bch_alloc_sectors(k, bio_sectors(bio), s))
+               if (!bch_alloc_sectors(op->c, k, bio_sectors(bio),
+                                      op->write_point, op->write_prio,
+                                      op->writeback))
                        goto err;
 
                n = bch_bio_split(bio, KEY_SIZE(k), GFP_NOIO, split);
 
-               n->bi_end_io    = bch_insert_data_endio;
+               n->bi_end_io    = bch_data_insert_endio;
                n->bi_private   = cl;
 
-               if (s->writeback) {
+               if (op->writeback) {
                        SET_KEY_DIRTY(k, true);
 
                        for (i = 0; i < KEY_PTRS(k); i++)
@@ -532,17 +389,17 @@ static void bch_insert_data_loop(struct closure *cl)
                        bio_csum(n, k);
 
                trace_bcache_cache_insert(k);
-               bch_keylist_push(&op->keys);
+               bch_keylist_push(&op->insert_keys);
 
                n->bi_rw |= REQ_WRITE;
                bch_submit_bbio(n, op->c, k, 0);
        } while (n != bio);
 
        op->insert_data_done = true;
-       continue_at(cl, bch_journal, bcache_wq);
+       continue_at(cl, bch_data_insert_keys, bcache_wq);
 err:
        /* bch_alloc_sectors() blocks if s->writeback = true */
-       BUG_ON(s->writeback);
+       BUG_ON(op->writeback);
 
        /*
         * But if it's not a writeback write we'd rather just bail out if
@@ -550,15 +407,15 @@ err:
         * we might be starving btree writes for gc or something.
         */
 
-       if (s->write) {
+       if (!op->replace) {
                /*
                 * Writethrough write: We can't complete the write until we've
                 * updated the index. But we don't want to delay the write while
                 * we wait for buckets to be freed up, so just invalidate the
                 * rest of the write.
                 */
-               op->skip = true;
-               return bio_invalidate(cl);
+               op->bypass = true;
+               return bch_data_invalidate(cl);
        } else {
                /*
                 * From a cache miss, we can just insert the keys for the data
@@ -567,15 +424,15 @@ err:
                op->insert_data_done = true;
                bio_put(bio);
 
-               if (!bch_keylist_empty(&op->keys))
-                       continue_at(cl, bch_journal, bcache_wq);
+               if (!bch_keylist_empty(&op->insert_keys))
+                       continue_at(cl, bch_data_insert_keys, bcache_wq);
                else
                        closure_return(cl);
        }
 }
 
 /**
- * bch_insert_data - stick some data in the cache
+ * bch_data_insert - stick some data in the cache
  *
  * This is the starting point for any data to end up in a cache device; it could
  * be from a normal write, or a writeback write, or a write to a flash only
@@ -587,56 +444,179 @@ err:
  * data is written it calls bch_journal, and after the keys have been added to
  * the next journal write they're inserted into the btree.
  *
- * It inserts the data in op->cache_bio; bi_sector is used for the key offset,
+ * It inserts the data in s->cache_bio; bi_sector is used for the key offset,
  * and op->inode is used for the key inode.
  *
- * If op->skip is true, instead of inserting the data it invalidates the region
- * of the cache represented by op->cache_bio and op->inode.
+ * If s->bypass is true, instead of inserting the data it invalidates the
+ * region of the cache represented by s->cache_bio and op->inode.
  */
-void bch_insert_data(struct closure *cl)
+void bch_data_insert(struct closure *cl)
 {
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
+       struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
+
+       trace_bcache_write(op->bio, op->writeback, op->bypass);
 
-       bch_keylist_init(&op->keys);
-       bio_get(op->cache_bio);
-       bch_insert_data_loop(cl);
+       bch_keylist_init(&op->insert_keys);
+       bio_get(op->bio);
+       bch_data_insert_start(cl);
 }
 
-void bch_btree_insert_async(struct closure *cl)
+/* Congested? */
+
+unsigned bch_get_congested(struct cache_set *c)
 {
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
-       struct search *s = container_of(op, struct search, op);
+       int i;
+       long rand;
 
-       if (bch_btree_insert(op, op->c)) {
-               s->error                = -ENOMEM;
-               op->insert_data_done    = true;
-       }
+       if (!c->congested_read_threshold_us &&
+           !c->congested_write_threshold_us)
+               return 0;
+
+       i = (local_clock_us() - c->congested_last_us) / 1024;
+       if (i < 0)
+               return 0;
+
+       i += atomic_read(&c->congested);
+       if (i >= 0)
+               return 0;
 
-       if (op->insert_data_done) {
-               bch_keylist_free(&op->keys);
-               closure_return(cl);
-       } else
-               continue_at(cl, bch_insert_data_loop, bcache_wq);
+       i += CONGESTED_MAX;
+
+       if (i > 0)
+               i = fract_exp_two(i, 6);
+
+       rand = get_random_int();
+       i -= bitmap_weight(&rand, BITS_PER_LONG);
+
+       return i > 0 ? i : 1;
 }
 
-/* Common code for the make_request functions */
+static void add_sequential(struct task_struct *t)
+{
+       ewma_add(t->sequential_io_avg,
+                t->sequential_io, 8, 0);
 
-static void request_endio(struct bio *bio, int error)
+       t->sequential_io = 0;
+}
+
+static struct hlist_head *iohash(struct cached_dev *dc, uint64_t k)
 {
-       struct closure *cl = bio->bi_private;
+       return &dc->io_hash[hash_64(k, RECENT_IO_BITS)];
+}
 
-       if (error) {
-               struct search *s = container_of(cl, struct search, cl);
-               s->error = error;
-               /* Only cache read errors are recoverable */
-               s->recoverable = false;
+static bool check_should_bypass(struct cached_dev *dc, struct bio *bio)
+{
+       struct cache_set *c = dc->disk.c;
+       unsigned mode = cache_mode(dc, bio);
+       unsigned sectors, congested = bch_get_congested(c);
+       struct task_struct *task = current;
+       struct io *i;
+
+       if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) ||
+           c->gc_stats.in_use > CUTOFF_CACHE_ADD ||
+           (bio->bi_rw & REQ_DISCARD))
+               goto skip;
+
+       if (mode == CACHE_MODE_NONE ||
+           (mode == CACHE_MODE_WRITEAROUND &&
+            (bio->bi_rw & REQ_WRITE)))
+               goto skip;
+
+       if (bio->bi_sector & (c->sb.block_size - 1) ||
+           bio_sectors(bio) & (c->sb.block_size - 1)) {
+               pr_debug("skipping unaligned io");
+               goto skip;
        }
 
-       bio_put(bio);
-       closure_put(cl);
+       if (bypass_torture_test(dc)) {
+               if ((get_random_int() & 3) == 3)
+                       goto skip;
+               else
+                       goto rescale;
+       }
+
+       if (!congested && !dc->sequential_cutoff)
+               goto rescale;
+
+       if (!congested &&
+           mode == CACHE_MODE_WRITEBACK &&
+           (bio->bi_rw & REQ_WRITE) &&
+           (bio->bi_rw & REQ_SYNC))
+               goto rescale;
+
+       spin_lock(&dc->io_lock);
+
+       hlist_for_each_entry(i, iohash(dc, bio->bi_sector), hash)
+               if (i->last == bio->bi_sector &&
+                   time_before(jiffies, i->jiffies))
+                       goto found;
+
+       i = list_first_entry(&dc->io_lru, struct io, lru);
+
+       add_sequential(task);
+       i->sequential = 0;
+found:
+       if (i->sequential + bio->bi_size > i->sequential)
+               i->sequential   += bio->bi_size;
+
+       i->last                  = bio_end_sector(bio);
+       i->jiffies               = jiffies + msecs_to_jiffies(5000);
+       task->sequential_io      = i->sequential;
+
+       hlist_del(&i->hash);
+       hlist_add_head(&i->hash, iohash(dc, i->last));
+       list_move_tail(&i->lru, &dc->io_lru);
+
+       spin_unlock(&dc->io_lock);
+
+       sectors = max(task->sequential_io,
+                     task->sequential_io_avg) >> 9;
+
+       if (dc->sequential_cutoff &&
+           sectors >= dc->sequential_cutoff >> 9) {
+               trace_bcache_bypass_sequential(bio);
+               goto skip;
+       }
+
+       if (congested && sectors >= congested) {
+               trace_bcache_bypass_congested(bio);
+               goto skip;
+       }
+
+rescale:
+       bch_rescale_priorities(c, bio_sectors(bio));
+       return false;
+skip:
+       bch_mark_sectors_bypassed(c, dc, bio_sectors(bio));
+       return true;
 }
 
-void bch_cache_read_endio(struct bio *bio, int error)
+/* Cache lookup */
+
+struct search {
+       /* Stack frame for bio_complete */
+       struct closure          cl;
+
+       struct bcache_device    *d;
+
+       struct bbio             bio;
+       struct bio              *orig_bio;
+       struct bio              *cache_miss;
+
+       unsigned                insert_bio_sectors;
+
+       unsigned                recoverable:1;
+       unsigned                unaligned_bvec:1;
+       unsigned                write:1;
+       unsigned                read_dirty_data:1;
+
+       unsigned long           start_time;
+
+       struct btree_op         op;
+       struct data_insert_op   iop;
+};
+
+static void bch_cache_read_endio(struct bio *bio, int error)
 {
        struct bbio *b = container_of(bio, struct bbio, bio);
        struct closure *cl = bio->bi_private;
@@ -650,13 +630,113 @@ void bch_cache_read_endio(struct bio *bio, int error)
         */
 
        if (error)
-               s->error = error;
-       else if (ptr_stale(s->op.c, &b->key, 0)) {
-               atomic_long_inc(&s->op.c->cache_read_races);
-               s->error = -EINTR;
+               s->iop.error = error;
+       else if (ptr_stale(s->iop.c, &b->key, 0)) {
+               atomic_long_inc(&s->iop.c->cache_read_races);
+               s->iop.error = -EINTR;
        }
 
-       bch_bbio_endio(s->op.c, bio, error, "reading from cache");
+       bch_bbio_endio(s->iop.c, bio, error, "reading from cache");
+}
+
+/*
+ * Read from a single key, handling the initial cache miss if the key starts in
+ * the middle of the bio
+ */
+static int cache_lookup_fn(struct btree_op *op, struct btree *b, struct bkey *k)
+{
+       struct search *s = container_of(op, struct search, op);
+       struct bio *n, *bio = &s->bio.bio;
+       struct bkey *bio_key;
+       unsigned ptr;
+
+       if (bkey_cmp(k, &KEY(s->iop.inode, bio->bi_sector, 0)) <= 0)
+               return MAP_CONTINUE;
+
+       if (KEY_INODE(k) != s->iop.inode ||
+           KEY_START(k) > bio->bi_sector) {
+               unsigned bio_sectors = bio_sectors(bio);
+               unsigned sectors = KEY_INODE(k) == s->iop.inode
+                       ? min_t(uint64_t, INT_MAX,
+                               KEY_START(k) - bio->bi_sector)
+                       : INT_MAX;
+
+               int ret = s->d->cache_miss(b, s, bio, sectors);
+               if (ret != MAP_CONTINUE)
+                       return ret;
+
+               /* if this was a complete miss we shouldn't get here */
+               BUG_ON(bio_sectors <= sectors);
+       }
+
+       if (!KEY_SIZE(k))
+               return MAP_CONTINUE;
+
+       /* XXX: figure out best pointer - for multiple cache devices */
+       ptr = 0;
+
+       PTR_BUCKET(b->c, k, ptr)->prio = INITIAL_PRIO;
+
+       if (KEY_DIRTY(k))
+               s->read_dirty_data = true;
+
+       n = bch_bio_split(bio, min_t(uint64_t, INT_MAX,
+                                    KEY_OFFSET(k) - bio->bi_sector),
+                         GFP_NOIO, s->d->bio_split);
+
+       bio_key = &container_of(n, struct bbio, bio)->key;
+       bch_bkey_copy_single_ptr(bio_key, k, ptr);
+
+       bch_cut_front(&KEY(s->iop.inode, n->bi_sector, 0), bio_key);
+       bch_cut_back(&KEY(s->iop.inode, bio_end_sector(n), 0), bio_key);
+
+       n->bi_end_io    = bch_cache_read_endio;
+       n->bi_private   = &s->cl;
+
+       /*
+        * The bucket we're reading from might be reused while our bio
+        * is in flight, and we could then end up reading the wrong
+        * data.
+        *
+        * We guard against this by checking (in cache_read_endio()) if
+        * the pointer is stale again; if so, we treat it as an error
+        * and reread from the backing device (but we don't pass that
+        * error up anywhere).
+        */
+
+       __bch_submit_bbio(n, b->c);
+       return n == bio ? MAP_DONE : MAP_CONTINUE;
+}
+
+static void cache_lookup(struct closure *cl)
+{
+       struct search *s = container_of(cl, struct search, iop.cl);
+       struct bio *bio = &s->bio.bio;
+
+       int ret = bch_btree_map_keys(&s->op, s->iop.c,
+                                    &KEY(s->iop.inode, bio->bi_sector, 0),
+                                    cache_lookup_fn, MAP_END_KEY);
+       if (ret == -EAGAIN)
+               continue_at(cl, cache_lookup, bcache_wq);
+
+       closure_return(cl);
+}
+
+/* Common code for the make_request functions */
+
+static void request_endio(struct bio *bio, int error)
+{
+       struct closure *cl = bio->bi_private;
+
+       if (error) {
+               struct search *s = container_of(cl, struct search, cl);
+               s->iop.error = error;
+               /* Only cache read errors are recoverable */
+               s->recoverable = false;
+       }
+
+       bio_put(bio);
+       closure_put(cl);
 }
 
 static void bio_complete(struct search *s)
@@ -670,8 +750,8 @@ static void bio_complete(struct search *s)
                part_stat_add(cpu, &s->d->disk->part0, ticks[rw], duration);
                part_stat_unlock();
 
-               trace_bcache_request_end(s, s->orig_bio);
-               bio_endio(s->orig_bio, s->error);
+               trace_bcache_request_end(s->d, s->orig_bio);
+               bio_endio(s->orig_bio, s->iop.error);
                s->orig_bio = NULL;
        }
 }
@@ -691,8 +771,8 @@ static void search_free(struct closure *cl)
        struct search *s = container_of(cl, struct search, cl);
        bio_complete(s);
 
-       if (s->op.cache_bio)
-               bio_put(s->op.cache_bio);
+       if (s->iop.bio)
+               bio_put(s->iop.bio);
 
        if (s->unaligned_bvec)
                mempool_free(s->bio.bio.bi_io_vec, s->d->unaligned_bvec);
@@ -703,21 +783,22 @@ static void search_free(struct closure *cl)
 
 static struct search *search_alloc(struct bio *bio, struct bcache_device *d)
 {
+       struct search *s;
        struct bio_vec *bv;
-       struct search *s = mempool_alloc(d->c->search, GFP_NOIO);
-       memset(s, 0, offsetof(struct search, op.keys));
+
+       s = mempool_alloc(d->c->search, GFP_NOIO);
+       memset(s, 0, offsetof(struct search, iop.insert_keys));
 
        __closure_init(&s->cl, NULL);
 
-       s->op.inode             = d->id;
-       s->op.c                 = d->c;
+       s->iop.inode            = d->id;
+       s->iop.c                = d->c;
        s->d                    = d;
        s->op.lock              = -1;
-       s->task                 = current;
+       s->iop.write_point      = hash_long((unsigned long) current, 16);
        s->orig_bio             = bio;
        s->write                = (bio->bi_rw & REQ_WRITE) != 0;
-       s->op.flush_journal     = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0;
-       s->op.skip              = (bio->bi_rw & REQ_DISCARD) != 0;
+       s->iop.flush_journal    = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0;
        s->recoverable          = 1;
        s->start_time           = jiffies;
        do_bio_hook(s);
@@ -734,18 +815,6 @@ static struct search *search_alloc(struct bio *bio, struct bcache_device *d)
        return s;
 }
 
-static void btree_read_async(struct closure *cl)
-{
-       struct btree_op *op = container_of(cl, struct btree_op, cl);
-
-       int ret = btree_root(search_recurse, op->c, op);
-
-       if (ret == -EAGAIN)
-               continue_at(cl, btree_read_async, bcache_wq);
-
-       closure_return(cl);
-}
-
 /* Cached devices */
 
 static void cached_dev_bio_complete(struct closure *cl)
@@ -759,27 +828,28 @@ static void cached_dev_bio_complete(struct closure *cl)
 
 /* Process reads */
 
-static void cached_dev_read_complete(struct closure *cl)
+static void cached_dev_cache_miss_done(struct closure *cl)
 {
        struct search *s = container_of(cl, struct search, cl);
 
-       if (s->op.insert_collision)
-               bch_mark_cache_miss_collision(s);
+       if (s->iop.replace_collision)
+               bch_mark_cache_miss_collision(s->iop.c, s->d);
 
-       if (s->op.cache_bio) {
+       if (s->iop.bio) {
                int i;
                struct bio_vec *bv;
 
-               __bio_for_each_segment(bv, s->op.cache_bio, i, 0)
+               bio_for_each_segment_all(bv, s->iop.bio, i)
                        __free_page(bv->bv_page);
        }
 
        cached_dev_bio_complete(cl);
 }
 
-static void request_read_error(struct closure *cl)
+static void cached_dev_read_error(struct closure *cl)
 {
        struct search *s = container_of(cl, struct search, cl);
+       struct bio *bio = &s->bio.bio;
        struct bio_vec *bv;
        int i;
 
@@ -787,7 +857,7 @@ static void request_read_error(struct closure *cl)
                /* Retry from the backing device: */
                trace_bcache_read_retry(s->orig_bio);
 
-               s->error = 0;
+               s->iop.error = 0;
                bv = s->bio.bio.bi_io_vec;
                do_bio_hook(s);
                s->bio.bio.bi_io_vec = bv;
@@ -803,146 +873,148 @@ static void request_read_error(struct closure *cl)
 
                /* XXX: invalidate cache */
 
-               closure_bio_submit(&s->bio.bio, &s->cl, s->d);
+               closure_bio_submit(bio, cl, s->d);
        }
 
-       continue_at(cl, cached_dev_read_complete, NULL);
+       continue_at(cl, cached_dev_cache_miss_done, NULL);
 }
 
-static void request_read_done(struct closure *cl)
+static void cached_dev_read_done(struct closure *cl)
 {
        struct search *s = container_of(cl, struct search, cl);
        struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
 
        /*
-        * s->cache_bio != NULL implies that we had a cache miss; cache_bio now
-        * contains data ready to be inserted into the cache.
+        * We had a cache miss; cache_bio now contains data ready to be inserted
+        * into the cache.
         *
         * First, we copy the data we just read from cache_bio's bounce buffers
         * to the buffers the original bio pointed to:
         */
 
-       if (s->op.cache_bio) {
-               bio_reset(s->op.cache_bio);
-               s->op.cache_bio->bi_sector      = s->cache_miss->bi_sector;
-               s->op.cache_bio->bi_bdev        = s->cache_miss->bi_bdev;
-               s->op.cache_bio->bi_size        = s->cache_bio_sectors << 9;
-               bch_bio_map(s->op.cache_bio, NULL);
+       if (s->iop.bio) {
+               bio_reset(s->iop.bio);
+               s->iop.bio->bi_sector = s->cache_miss->bi_sector;
+               s->iop.bio->bi_bdev = s->cache_miss->bi_bdev;
+               s->iop.bio->bi_size = s->insert_bio_sectors << 9;
+               bch_bio_map(s->iop.bio, NULL);
 
-               bio_copy_data(s->cache_miss, s->op.cache_bio);
+               bio_copy_data(s->cache_miss, s->iop.bio);
 
                bio_put(s->cache_miss);
                s->cache_miss = NULL;
        }
 
-       if (verify(dc, &s->bio.bio) && s->recoverable)
-               bch_data_verify(s);
+       if (verify(dc, &s->bio.bio) && s->recoverable &&
+           !s->unaligned_bvec && !s->read_dirty_data)
+               bch_data_verify(dc, s->orig_bio);
 
        bio_complete(s);
 
-       if (s->op.cache_bio &&
-           !test_bit(CACHE_SET_STOPPING, &s->op.c->flags)) {
-               s->op.type = BTREE_REPLACE;
-               closure_call(&s->op.cl, bch_insert_data, NULL, cl);
+       if (s->iop.bio &&
+           !test_bit(CACHE_SET_STOPPING, &s->iop.c->flags)) {
+               BUG_ON(!s->iop.replace);
+               closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
        }
 
-       continue_at(cl, cached_dev_read_complete, NULL);
+       continue_at(cl, cached_dev_cache_miss_done, NULL);
 }
 
-static void request_read_done_bh(struct closure *cl)
+static void cached_dev_read_done_bh(struct closure *cl)
 {
        struct search *s = container_of(cl, struct search, cl);
        struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
 
-       bch_mark_cache_accounting(s, !s->cache_miss, s->op.skip);
-       trace_bcache_read(s->orig_bio, !s->cache_miss, s->op.skip);
+       bch_mark_cache_accounting(s->iop.c, s->d,
+                                 !s->cache_miss, s->iop.bypass);
+       trace_bcache_read(s->orig_bio, !s->cache_miss, s->iop.bypass);
 
-       if (s->error)
-               continue_at_nobarrier(cl, request_read_error, bcache_wq);
-       else if (s->op.cache_bio || verify(dc, &s->bio.bio))
-               continue_at_nobarrier(cl, request_read_done, bcache_wq);
+       if (s->iop.error)
+               continue_at_nobarrier(cl, cached_dev_read_error, bcache_wq);
+       else if (s->iop.bio || verify(dc, &s->bio.bio))
+               continue_at_nobarrier(cl, cached_dev_read_done, bcache_wq);
        else
-               continue_at_nobarrier(cl, cached_dev_read_complete, NULL);
+               continue_at_nobarrier(cl, cached_dev_bio_complete, NULL);
 }
 
 static int cached_dev_cache_miss(struct btree *b, struct search *s,
                                 struct bio *bio, unsigned sectors)
 {
-       int ret = 0;
-       unsigned reada;
+       int ret = MAP_CONTINUE;
+       unsigned reada = 0;
        struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
-       struct bio *miss;
-
-       miss = bch_bio_split(bio, sectors, GFP_NOIO, s->d->bio_split);
-       if (miss == bio)
-               s->op.lookup_done = true;
+       struct bio *miss, *cache_bio;
 
-       miss->bi_end_io         = request_endio;
-       miss->bi_private        = &s->cl;
-
-       if (s->cache_miss || s->op.skip)
+       if (s->cache_miss || s->iop.bypass) {
+               miss = bch_bio_split(bio, sectors, GFP_NOIO, s->d->bio_split);
+               ret = miss == bio ? MAP_DONE : MAP_CONTINUE;
                goto out_submit;
-
-       if (miss != bio ||
-           (bio->bi_rw & REQ_RAHEAD) ||
-           (bio->bi_rw & REQ_META) ||
-           s->op.c->gc_stats.in_use >= CUTOFF_CACHE_READA)
-               reada = 0;
-       else {
-               reada = min(dc->readahead >> 9,
-                           sectors - bio_sectors(miss));
-
-               if (bio_end_sector(miss) + reada > bdev_sectors(miss->bi_bdev))
-                       reada = bdev_sectors(miss->bi_bdev) -
-                               bio_end_sector(miss);
        }
 
-       s->cache_bio_sectors = bio_sectors(miss) + reada;
-       s->op.cache_bio = bio_alloc_bioset(GFP_NOWAIT,
-                       DIV_ROUND_UP(s->cache_bio_sectors, PAGE_SECTORS),
-                       dc->disk.bio_split);
+       if (!(bio->bi_rw & REQ_RAHEAD) &&
+           !(bio->bi_rw & REQ_META) &&
+           s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA)
+               reada = min_t(sector_t, dc->readahead >> 9,
+                             bdev_sectors(bio->bi_bdev) - bio_end_sector(bio));
 
-       if (!s->op.cache_bio)
-               goto out_submit;
+       s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada);
 
-       s->op.cache_bio->bi_sector      = miss->bi_sector;
-       s->op.cache_bio->bi_bdev        = miss->bi_bdev;
-       s->op.cache_bio->bi_size        = s->cache_bio_sectors << 9;
+       s->iop.replace_key = KEY(s->iop.inode,
+                                bio->bi_sector + s->insert_bio_sectors,
+                                s->insert_bio_sectors);
 
-       s->op.cache_bio->bi_end_io      = request_endio;
-       s->op.cache_bio->bi_private     = &s->cl;
+       ret = bch_btree_insert_check_key(b, &s->op, &s->iop.replace_key);
+       if (ret)
+               return ret;
+
+       s->iop.replace = true;
+
+       miss = bch_bio_split(bio, sectors, GFP_NOIO, s->d->bio_split);
 
        /* btree_search_recurse()'s btree iterator is no good anymore */
-       ret = -EINTR;
-       if (!bch_btree_insert_check_key(b, &s->op, s->op.cache_bio))
-               goto out_put;
+       ret = miss == bio ? MAP_DONE : -EINTR;
+
+       cache_bio = bio_alloc_bioset(GFP_NOWAIT,
+                       DIV_ROUND_UP(s->insert_bio_sectors, PAGE_SECTORS),
+                       dc->disk.bio_split);
+       if (!cache_bio)
+               goto out_submit;
+
+       cache_bio->bi_sector    = miss->bi_sector;
+       cache_bio->bi_bdev      = miss->bi_bdev;
+       cache_bio->bi_size      = s->insert_bio_sectors << 9;
+
+       cache_bio->bi_end_io    = request_endio;
+       cache_bio->bi_private   = &s->cl;
 
-       bch_bio_map(s->op.cache_bio, NULL);
-       if (bio_alloc_pages(s->op.cache_bio, __GFP_NOWARN|GFP_NOIO))
+       bch_bio_map(cache_bio, NULL);
+       if (bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO))
                goto out_put;
 
-       s->cache_miss = miss;
-       bio_get(s->op.cache_bio);
+       if (reada)
+               bch_mark_cache_readahead(s->iop.c, s->d);
 
-       closure_bio_submit(s->op.cache_bio, &s->cl, s->d);
+       s->cache_miss   = miss;
+       s->iop.bio      = cache_bio;
+       bio_get(cache_bio);
+       closure_bio_submit(cache_bio, &s->cl, s->d);
 
        return ret;
 out_put:
-       bio_put(s->op.cache_bio);
-       s->op.cache_bio = NULL;
+       bio_put(cache_bio);
 out_submit:
+       miss->bi_end_io         = request_endio;
+       miss->bi_private        = &s->cl;
        closure_bio_submit(miss, &s->cl, s->d);
        return ret;
 }
 
-static void request_read(struct cached_dev *dc, struct search *s)
+static void cached_dev_read(struct cached_dev *dc, struct search *s)
 {
        struct closure *cl = &s->cl;
 
-       check_should_skip(dc, s);
-       closure_call(&s->op.cl, btree_read_async, NULL, cl);
-
-       continue_at(cl, request_read_done_bh, NULL);
+       closure_call(&s->iop.cl, cache_lookup, NULL, cl);
+       continue_at(cl, cached_dev_read_done_bh, NULL);
 }
 
 /* Process writes */
@@ -956,47 +1028,52 @@ static void cached_dev_write_complete(struct closure *cl)
        cached_dev_bio_complete(cl);
 }
 
-static void request_write(struct cached_dev *dc, struct search *s)
+static void cached_dev_write(struct cached_dev *dc, struct search *s)
 {
        struct closure *cl = &s->cl;
        struct bio *bio = &s->bio.bio;
-       struct bkey start, end;
-       start = KEY(dc->disk.id, bio->bi_sector, 0);
-       end = KEY(dc->disk.id, bio_end_sector(bio), 0);
+       struct bkey start = KEY(dc->disk.id, bio->bi_sector, 0);
+       struct bkey end = KEY(dc->disk.id, bio_end_sector(bio), 0);
 
-       bch_keybuf_check_overlapping(&s->op.c->moving_gc_keys, &start, &end);
+       bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end);
 
-       check_should_skip(dc, s);
        down_read_non_owner(&dc->writeback_lock);
-
        if (bch_keybuf_check_overlapping(&dc->writeback_keys, &start, &end)) {
-               s->op.skip      = false;
-               s->writeback    = true;
+               /*
+                * We overlap with some dirty data undergoing background
+                * writeback, force this write to writeback
+                */
+               s->iop.bypass = false;
+               s->iop.writeback = true;
        }
 
+       /*
+        * Discards aren't _required_ to do anything, so skipping if
+        * check_overlapping returned true is ok
+        *
+        * But check_overlapping drops dirty keys for which io hasn't started,
+        * so we still want to call it.
+        */
        if (bio->bi_rw & REQ_DISCARD)
-               goto skip;
+               s->iop.bypass = true;
 
        if (should_writeback(dc, s->orig_bio,
                             cache_mode(dc, bio),
-                            s->op.skip)) {
-               s->op.skip = false;
-               s->writeback = true;
+                            s->iop.bypass)) {
+               s->iop.bypass = false;
+               s->iop.writeback = true;
        }
 
-       if (s->op.skip)
-               goto skip;
-
-       trace_bcache_write(s->orig_bio, s->writeback, s->op.skip);
+       if (s->iop.bypass) {
+               s->iop.bio = s->orig_bio;
+               bio_get(s->iop.bio);
 
-       if (!s->writeback) {
-               s->op.cache_bio = bio_clone_bioset(bio, GFP_NOIO,
-                                                  dc->disk.bio_split);
-
-               closure_bio_submit(bio, cl, s->d);
-       } else {
+               if (!(bio->bi_rw & REQ_DISCARD) ||
+                   blk_queue_discard(bdev_get_queue(dc->bdev)))
+                       closure_bio_submit(bio, cl, s->d);
+       } else if (s->iop.writeback) {
                bch_writeback_add(dc);
-               s->op.cache_bio = bio;
+               s->iop.bio = bio;
 
                if (bio->bi_rw & REQ_FLUSH) {
                        /* Also need to send a flush to the backing device */
@@ -1010,36 +1087,26 @@ static void request_write(struct cached_dev *dc, struct search *s)
 
                        closure_bio_submit(flush, cl, s->d);
                }
-       }
-out:
-       closure_call(&s->op.cl, bch_insert_data, NULL, cl);
-       continue_at(cl, cached_dev_write_complete, NULL);
-skip:
-       s->op.skip = true;
-       s->op.cache_bio = s->orig_bio;
-       bio_get(s->op.cache_bio);
+       } else {
+               s->iop.bio = bio_clone_bioset(bio, GFP_NOIO,
+                                             dc->disk.bio_split);
 
-       if ((bio->bi_rw & REQ_DISCARD) &&
-           !blk_queue_discard(bdev_get_queue(dc->bdev)))
-               goto out;
+               closure_bio_submit(bio, cl, s->d);
+       }
 
-       closure_bio_submit(bio, cl, s->d);
-       goto out;
+       closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
+       continue_at(cl, cached_dev_write_complete, NULL);
 }
 
-static void request_nodata(struct cached_dev *dc, struct search *s)
+static void cached_dev_nodata(struct closure *cl)
 {
-       struct closure *cl = &s->cl;
+       struct search *s = container_of(cl, struct search, cl);
        struct bio *bio = &s->bio.bio;
 
-       if (bio->bi_rw & REQ_DISCARD) {
-               request_write(dc, s);
-               return;
-       }
-
-       if (s->op.flush_journal)
-               bch_journal_meta(s->op.c, cl);
+       if (s->iop.flush_journal)
+               bch_journal_meta(s->iop.c, cl);
 
+       /* If it's a flush, we send the flush to the backing device too */
        closure_bio_submit(bio, cl, s->d);
 
        continue_at(cl, cached_dev_bio_complete, NULL);
@@ -1047,134 +1114,6 @@ static void request_nodata(struct cached_dev *dc, struct search *s)
 
 /* Cached devices - read & write stuff */
 
-unsigned bch_get_congested(struct cache_set *c)
-{
-       int i;
-       long rand;
-
-       if (!c->congested_read_threshold_us &&
-           !c->congested_write_threshold_us)
-               return 0;
-
-       i = (local_clock_us() - c->congested_last_us) / 1024;
-       if (i < 0)
-               return 0;
-
-       i += atomic_read(&c->congested);
-       if (i >= 0)
-               return 0;
-
-       i += CONGESTED_MAX;
-
-       if (i > 0)
-               i = fract_exp_two(i, 6);
-
-       rand = get_random_int();
-       i -= bitmap_weight(&rand, BITS_PER_LONG);
-
-       return i > 0 ? i : 1;
-}
-
-static void add_sequential(struct task_struct *t)
-{
-       ewma_add(t->sequential_io_avg,
-                t->sequential_io, 8, 0);
-
-       t->sequential_io = 0;
-}
-
-static struct hlist_head *iohash(struct cached_dev *dc, uint64_t k)
-{
-       return &dc->io_hash[hash_64(k, RECENT_IO_BITS)];
-}
-
-static void check_should_skip(struct cached_dev *dc, struct search *s)
-{
-       struct cache_set *c = s->op.c;
-       struct bio *bio = &s->bio.bio;
-       unsigned mode = cache_mode(dc, bio);
-       unsigned sectors, congested = bch_get_congested(c);
-
-       if (atomic_read(&dc->disk.detaching) ||
-           c->gc_stats.in_use > CUTOFF_CACHE_ADD ||
-           (bio->bi_rw & REQ_DISCARD))
-               goto skip;
-
-       if (mode == CACHE_MODE_NONE ||
-           (mode == CACHE_MODE_WRITEAROUND &&
-            (bio->bi_rw & REQ_WRITE)))
-               goto skip;
-
-       if (bio->bi_sector   & (c->sb.block_size - 1) ||
-           bio_sectors(bio) & (c->sb.block_size - 1)) {
-               pr_debug("skipping unaligned io");
-               goto skip;
-       }
-
-       if (!congested && !dc->sequential_cutoff)
-               goto rescale;
-
-       if (!congested &&
-           mode == CACHE_MODE_WRITEBACK &&
-           (bio->bi_rw & REQ_WRITE) &&
-           (bio->bi_rw & REQ_SYNC))
-               goto rescale;
-
-       if (dc->sequential_merge) {
-               struct io *i;
-
-               spin_lock(&dc->io_lock);
-
-               hlist_for_each_entry(i, iohash(dc, bio->bi_sector), hash)
-                       if (i->last == bio->bi_sector &&
-                           time_before(jiffies, i->jiffies))
-                               goto found;
-
-               i = list_first_entry(&dc->io_lru, struct io, lru);
-
-               add_sequential(s->task);
-               i->sequential = 0;
-found:
-               if (i->sequential + bio->bi_size > i->sequential)
-                       i->sequential   += bio->bi_size;
-
-               i->last                  = bio_end_sector(bio);
-               i->jiffies               = jiffies + msecs_to_jiffies(5000);
-               s->task->sequential_io   = i->sequential;
-
-               hlist_del(&i->hash);
-               hlist_add_head(&i->hash, iohash(dc, i->last));
-               list_move_tail(&i->lru, &dc->io_lru);
-
-               spin_unlock(&dc->io_lock);
-       } else {
-               s->task->sequential_io = bio->bi_size;
-
-               add_sequential(s->task);
-       }
-
-       sectors = max(s->task->sequential_io,
-                     s->task->sequential_io_avg) >> 9;
-
-       if (dc->sequential_cutoff &&
-           sectors >= dc->sequential_cutoff >> 9) {
-               trace_bcache_bypass_sequential(s->orig_bio);
-               goto skip;
-       }
-
-       if (congested && sectors >= congested) {
-               trace_bcache_bypass_congested(s->orig_bio);
-               goto skip;
-       }
-
-rescale:
-       bch_rescale_priorities(c, bio_sectors(bio));
-       return;
-skip:
-       bch_mark_sectors_bypassed(s, bio_sectors(bio));
-       s->op.skip = true;
-}
-
 static void cached_dev_make_request(struct request_queue *q, struct bio *bio)
 {
        struct search *s;
@@ -1192,14 +1131,24 @@ static void cached_dev_make_request(struct request_queue *q, struct bio *bio)
 
        if (cached_dev_get(dc)) {
                s = search_alloc(bio, d);
-               trace_bcache_request_start(s, bio);
-
-               if (!bio_has_data(bio))
-                       request_nodata(dc, s);
-               else if (rw)
-                       request_write(dc, s);
-               else
-                       request_read(dc, s);
+               trace_bcache_request_start(s->d, bio);
+
+               if (!bio->bi_size) {
+                       /*
+                        * can't call bch_journal_meta from under
+                        * generic_make_request
+                        */
+                       continue_at_nobarrier(&s->cl,
+                                             cached_dev_nodata,
+                                             bcache_wq);
+               } else {
+                       s->iop.bypass = check_should_bypass(dc, bio);
+
+                       if (rw)
+                               cached_dev_write(dc, s);
+                       else
+                               cached_dev_read(dc, s);
+               }
        } else {
                if ((bio->bi_rw & REQ_DISCARD) &&
                    !blk_queue_discard(bdev_get_queue(dc->bdev)))
@@ -1274,9 +1223,19 @@ static int flash_dev_cache_miss(struct btree *b, struct search *s,
        bio_advance(bio, min(sectors << 9, bio->bi_size));
 
        if (!bio->bi_size)
-               s->op.lookup_done = true;
+               return MAP_DONE;
 
-       return 0;
+       return MAP_CONTINUE;
+}
+
+static void flash_dev_nodata(struct closure *cl)
+{
+       struct search *s = container_of(cl, struct search, cl);
+
+       if (s->iop.flush_journal)
+               bch_journal_meta(s->iop.c, cl);
+
+       continue_at(cl, search_free, NULL);
 }
 
 static void flash_dev_make_request(struct request_queue *q, struct bio *bio)
@@ -1295,23 +1254,28 @@ static void flash_dev_make_request(struct request_queue *q, struct bio *bio)
        cl = &s->cl;
        bio = &s->bio.bio;
 
-       trace_bcache_request_start(s, bio);
+       trace_bcache_request_start(s->d, bio);
 
-       if (bio_has_data(bio) && !rw) {
-               closure_call(&s->op.cl, btree_read_async, NULL, cl);
-       } else if (bio_has_data(bio) || s->op.skip) {
-               bch_keybuf_check_overlapping(&s->op.c->moving_gc_keys,
+       if (!bio->bi_size) {
+               /*
+                * can't call bch_journal_meta from under
+                * generic_make_request
+                */
+               continue_at_nobarrier(&s->cl,
+                                     flash_dev_nodata,
+                                     bcache_wq);
+       } else if (rw) {
+               bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys,
                                        &KEY(d->id, bio->bi_sector, 0),
                                        &KEY(d->id, bio_end_sector(bio), 0));
 
-               s->writeback    = true;
-               s->op.cache_bio = bio;
+               s->iop.bypass           = (bio->bi_rw & REQ_DISCARD) != 0;
+               s->iop.writeback        = true;
+               s->iop.bio              = bio;
 
-               closure_call(&s->op.cl, bch_insert_data, NULL, cl);
+               closure_call(&s->iop.cl, bch_data_insert, NULL, cl);
        } else {
-               /* No data - probably a cache flush */
-               if (s->op.flush_journal)
-                       bch_journal_meta(s->op.c, cl);
+               closure_call(&s->iop.cl, cache_lookup, NULL, cl);
        }
 
        continue_at(cl, search_free, NULL);
index 57dc4784f4f48c06b6816232d352d4992e45cee1..2cd65bf073c24689542d78f0ef316f81ed21ba1c 100644 (file)
@@ -3,40 +3,33 @@
 
 #include <linux/cgroup.h>
 
-struct search {
-       /* Stack frame for bio_complete */
+struct data_insert_op {
        struct closure          cl;
+       struct cache_set        *c;
+       struct bio              *bio;
 
-       struct bcache_device    *d;
-       struct task_struct      *task;
-
-       struct bbio             bio;
-       struct bio              *orig_bio;
-       struct bio              *cache_miss;
-       unsigned                cache_bio_sectors;
-
-       unsigned                recoverable:1;
-       unsigned                unaligned_bvec:1;
+       unsigned                inode;
+       uint16_t                write_point;
+       uint16_t                write_prio;
+       short                   error;
 
-       unsigned                write:1;
+       unsigned                bypass:1;
        unsigned                writeback:1;
+       unsigned                flush_journal:1;
+       unsigned                csum:1;
 
-       /* IO error returned to s->bio */
-       short                   error;
-       unsigned long           start_time;
+       unsigned                replace:1;
+       unsigned                replace_collision:1;
+
+       unsigned                insert_data_done:1;
 
-       /* Anything past op->keys won't get zeroed in do_bio_hook */
-       struct btree_op         op;
+       /* Anything past this point won't get zeroed in search_alloc() */
+       struct keylist          insert_keys;
+       BKEY_PADDED(replace_key);
 };
 
-void bch_cache_read_endio(struct bio *, int);
 unsigned bch_get_congested(struct cache_set *);
-void bch_insert_data(struct closure *cl);
-void bch_btree_insert_async(struct closure *);
-void bch_cache_read_endio(struct bio *, int);
-
-void bch_open_buckets_free(struct cache_set *);
-int bch_open_buckets_alloc(struct cache_set *);
+void bch_data_insert(struct closure *cl);
 
 void bch_cached_dev_request_init(struct cached_dev *dc);
 void bch_flash_dev_request_init(struct bcache_device *d);
index b8730e714d6930d77eb5ada556b9e4a341d46ab6..84d0782f702eac3e09d790077a4e353fa6a265e7 100644 (file)
@@ -7,7 +7,6 @@
 #include "bcache.h"
 #include "stats.h"
 #include "btree.h"
-#include "request.h"
 #include "sysfs.h"
 
 /*
@@ -196,35 +195,36 @@ static void mark_cache_stats(struct cache_stat_collector *stats,
                        atomic_inc(&stats->cache_bypass_misses);
 }
 
-void bch_mark_cache_accounting(struct search *s, bool hit, bool bypass)
+void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
+                              bool hit, bool bypass)
 {
-       struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
+       struct cached_dev *dc = container_of(d, struct cached_dev, disk);
        mark_cache_stats(&dc->accounting.collector, hit, bypass);
-       mark_cache_stats(&s->op.c->accounting.collector, hit, bypass);
+       mark_cache_stats(&c->accounting.collector, hit, bypass);
 #ifdef CONFIG_CGROUP_BCACHE
        mark_cache_stats(&(bch_bio_to_cgroup(s->orig_bio)->stats), hit, bypass);
 #endif
 }
 
-void bch_mark_cache_readahead(struct search *s)
+void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d)
 {
-       struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
+       struct cached_dev *dc = container_of(d, struct cached_dev, disk);
        atomic_inc(&dc->accounting.collector.cache_readaheads);
-       atomic_inc(&s->op.c->accounting.collector.cache_readaheads);
+       atomic_inc(&c->accounting.collector.cache_readaheads);
 }
 
-void bch_mark_cache_miss_collision(struct search *s)
+void bch_mark_cache_miss_collision(struct cache_set *c, struct bcache_device *d)
 {
-       struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
+       struct cached_dev *dc = container_of(d, struct cached_dev, disk);
        atomic_inc(&dc->accounting.collector.cache_miss_collisions);
-       atomic_inc(&s->op.c->accounting.collector.cache_miss_collisions);
+       atomic_inc(&c->accounting.collector.cache_miss_collisions);
 }
 
-void bch_mark_sectors_bypassed(struct search *s, int sectors)
+void bch_mark_sectors_bypassed(struct cache_set *c, struct cached_dev *dc,
+                              int sectors)
 {
-       struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
        atomic_add(sectors, &dc->accounting.collector.sectors_bypassed);
-       atomic_add(sectors, &s->op.c->accounting.collector.sectors_bypassed);
+       atomic_add(sectors, &c->accounting.collector.sectors_bypassed);
 }
 
 void bch_cache_accounting_init(struct cache_accounting *acc,
index c7c7a8fd29fe4ba1377420d1e7f51d4aa0c57d5c..adbff141c88786c0dd7c3926d682322dd7dfb6ec 100644 (file)
@@ -38,7 +38,9 @@ struct cache_accounting {
        struct cache_stats day;
 };
 
-struct search;
+struct cache_set;
+struct cached_dev;
+struct bcache_device;
 
 void bch_cache_accounting_init(struct cache_accounting *acc,
                               struct closure *parent);
@@ -50,9 +52,10 @@ void bch_cache_accounting_clear(struct cache_accounting *acc);
 
 void bch_cache_accounting_destroy(struct cache_accounting *acc);
 
-void bch_mark_cache_accounting(struct search *s, bool hit, bool bypass);
-void bch_mark_cache_readahead(struct search *s);
-void bch_mark_cache_miss_collision(struct search *s);
-void bch_mark_sectors_bypassed(struct search *s, int sectors);
+void bch_mark_cache_accounting(struct cache_set *, struct bcache_device *,
+                              bool, bool);
+void bch_mark_cache_readahead(struct cache_set *, struct bcache_device *);
+void bch_mark_cache_miss_collision(struct cache_set *, struct bcache_device *);
+void bch_mark_sectors_bypassed(struct cache_set *, struct cached_dev *, int);
 
 #endif /* _BCACHE_STATS_H_ */
index 547c4c57b052efbb6fcd3df67c4b52c505023606..dec15cd2d797eaaa7fa0585abf8867c9f70a4cef 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/buffer_head.h>
 #include <linux/debugfs.h>
 #include <linux/genhd.h>
+#include <linux/idr.h>
 #include <linux/kthread.h>
 #include <linux/module.h>
 #include <linux/random.h>
@@ -45,21 +46,13 @@ const char * const bch_cache_modes[] = {
        NULL
 };
 
-struct uuid_entry_v0 {
-       uint8_t         uuid[16];
-       uint8_t         label[32];
-       uint32_t        first_reg;
-       uint32_t        last_reg;
-       uint32_t        invalidated;
-       uint32_t        pad;
-};
-
 static struct kobject *bcache_kobj;
 struct mutex bch_register_lock;
 LIST_HEAD(bch_cache_sets);
 static LIST_HEAD(uncached_devices);
 
-static int bcache_major, bcache_minor;
+static int bcache_major;
+static DEFINE_IDA(bcache_minor);
 static wait_queue_head_t unregister_wait;
 struct workqueue_struct *bcache_wq;
 
@@ -382,7 +375,7 @@ static char *uuid_read(struct cache_set *c, struct jset *j, struct closure *cl)
 {
        struct bkey *k = &j->uuid_bucket;
 
-       if (__bch_ptr_invalid(c, 1, k))
+       if (bch_btree_ptr_invalid(c, k))
                return "bad uuid pointer";
 
        bkey_copy(&c->uuid_bucket, k);
@@ -427,7 +420,7 @@ static int __uuid_write(struct cache_set *c)
 
        lockdep_assert_held(&bch_register_lock);
 
-       if (bch_bucket_alloc_set(c, WATERMARK_METADATA, &k.key, 1, &cl))
+       if (bch_bucket_alloc_set(c, WATERMARK_METADATA, &k.key, 1, true))
                return 1;
 
        SET_KEY_SIZE(&k.key, c->sb.bucket_size);
@@ -435,7 +428,7 @@ static int __uuid_write(struct cache_set *c)
        closure_sync(&cl);
 
        bkey_copy(&c->uuid_bucket, &k.key);
-       __bkey_put(c, &k.key);
+       bkey_put(c, &k.key);
        return 0;
 }
 
@@ -562,10 +555,10 @@ void bch_prio_write(struct cache *ca)
                }
 
                p->next_bucket  = ca->prio_buckets[i + 1];
-               p->magic        = pset_magic(ca);
+               p->magic        = pset_magic(&ca->sb);
                p->csum         = bch_crc64(&p->magic, bucket_bytes(ca) - 8);
 
-               bucket = bch_bucket_alloc(ca, WATERMARK_PRIO, &cl);
+               bucket = bch_bucket_alloc(ca, WATERMARK_PRIO, true);
                BUG_ON(bucket == -1);
 
                mutex_unlock(&ca->set->bucket_lock);
@@ -613,7 +606,7 @@ static void prio_read(struct cache *ca, uint64_t bucket)
                        if (p->csum != bch_crc64(&p->magic, bucket_bytes(ca) - 8))
                                pr_warn("bad csum reading priorities");
 
-                       if (p->magic != pset_magic(ca))
+                       if (p->magic != pset_magic(&ca->sb))
                                pr_warn("bad magic reading priorities");
 
                        bucket = p->next_bucket;
@@ -630,7 +623,7 @@ static void prio_read(struct cache *ca, uint64_t bucket)
 static int open_dev(struct block_device *b, fmode_t mode)
 {
        struct bcache_device *d = b->bd_disk->private_data;
-       if (atomic_read(&d->closing))
+       if (test_bit(BCACHE_DEV_CLOSING, &d->flags))
                return -ENXIO;
 
        closure_get(&d->cl);
@@ -659,20 +652,24 @@ static const struct block_device_operations bcache_ops = {
 
 void bcache_device_stop(struct bcache_device *d)
 {
-       if (!atomic_xchg(&d->closing, 1))
+       if (!test_and_set_bit(BCACHE_DEV_CLOSING, &d->flags))
                closure_queue(&d->cl);
 }
 
 static void bcache_device_unlink(struct bcache_device *d)
 {
-       unsigned i;
-       struct cache *ca;
+       lockdep_assert_held(&bch_register_lock);
 
-       sysfs_remove_link(&d->c->kobj, d->name);
-       sysfs_remove_link(&d->kobj, "cache");
+       if (d->c && !test_and_set_bit(BCACHE_DEV_UNLINK_DONE, &d->flags)) {
+               unsigned i;
+               struct cache *ca;
 
-       for_each_cache(ca, d->c, i)
-               bd_unlink_disk_holder(ca->bdev, d->disk);
+               sysfs_remove_link(&d->c->kobj, d->name);
+               sysfs_remove_link(&d->kobj, "cache");
+
+               for_each_cache(ca, d->c, i)
+                       bd_unlink_disk_holder(ca->bdev, d->disk);
+       }
 }
 
 static void bcache_device_link(struct bcache_device *d, struct cache_set *c,
@@ -696,19 +693,16 @@ static void bcache_device_detach(struct bcache_device *d)
 {
        lockdep_assert_held(&bch_register_lock);
 
-       if (atomic_read(&d->detaching)) {
+       if (test_bit(BCACHE_DEV_DETACHING, &d->flags)) {
                struct uuid_entry *u = d->c->uuids + d->id;
 
                SET_UUID_FLASH_ONLY(u, 0);
                memcpy(u->uuid, invalid_uuid, 16);
                u->invalidated = cpu_to_le32(get_seconds());
                bch_uuid_write(d->c);
-
-               atomic_set(&d->detaching, 0);
        }
 
-       if (!d->flush_done)
-               bcache_device_unlink(d);
+       bcache_device_unlink(d);
 
        d->c->devices[d->id] = NULL;
        closure_put(&d->c->caching);
@@ -739,14 +733,20 @@ static void bcache_device_free(struct bcache_device *d)
                del_gendisk(d->disk);
        if (d->disk && d->disk->queue)
                blk_cleanup_queue(d->disk->queue);
-       if (d->disk)
+       if (d->disk) {
+               ida_simple_remove(&bcache_minor, d->disk->first_minor);
                put_disk(d->disk);
+       }
 
        bio_split_pool_free(&d->bio_split_hook);
        if (d->unaligned_bvec)
                mempool_destroy(d->unaligned_bvec);
        if (d->bio_split)
                bioset_free(d->bio_split);
+       if (is_vmalloc_addr(d->full_dirty_stripes))
+               vfree(d->full_dirty_stripes);
+       else
+               kfree(d->full_dirty_stripes);
        if (is_vmalloc_addr(d->stripe_sectors_dirty))
                vfree(d->stripe_sectors_dirty);
        else
@@ -760,15 +760,19 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 {
        struct request_queue *q;
        size_t n;
+       int minor;
 
-       if (!d->stripe_size_bits)
-               d->stripe_size_bits = 31;
+       if (!d->stripe_size)
+               d->stripe_size = 1 << 31;
 
-       d->nr_stripes = round_up(sectors, 1 << d->stripe_size_bits) >>
-               d->stripe_size_bits;
+       d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
 
-       if (!d->nr_stripes || d->nr_stripes > SIZE_MAX / sizeof(atomic_t))
+       if (!d->nr_stripes ||
+           d->nr_stripes > INT_MAX ||
+           d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
+               pr_err("nr_stripes too large");
                return -ENOMEM;
+       }
 
        n = d->nr_stripes * sizeof(atomic_t);
        d->stripe_sectors_dirty = n < PAGE_SIZE << 6
@@ -777,22 +781,38 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
        if (!d->stripe_sectors_dirty)
                return -ENOMEM;
 
+       n = BITS_TO_LONGS(d->nr_stripes) * sizeof(unsigned long);
+       d->full_dirty_stripes = n < PAGE_SIZE << 6
+               ? kzalloc(n, GFP_KERNEL)
+               : vzalloc(n);
+       if (!d->full_dirty_stripes)
+               return -ENOMEM;
+
+       minor = ida_simple_get(&bcache_minor, 0, MINORMASK + 1, GFP_KERNEL);
+       if (minor < 0)
+               return minor;
+
        if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
            !(d->unaligned_bvec = mempool_create_kmalloc_pool(1,
                                sizeof(struct bio_vec) * BIO_MAX_PAGES)) ||
            bio_split_pool_init(&d->bio_split_hook) ||
-           !(d->disk = alloc_disk(1)) ||
-           !(q = blk_alloc_queue(GFP_KERNEL)))
+           !(d->disk = alloc_disk(1))) {
+               ida_simple_remove(&bcache_minor, minor);
                return -ENOMEM;
+       }
 
        set_capacity(d->disk, sectors);
-       snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", bcache_minor);
+       snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", minor);
 
        d->disk->major          = bcache_major;
-       d->disk->first_minor    = bcache_minor++;
+       d->disk->first_minor    = minor;
        d->disk->fops           = &bcache_ops;
        d->disk->private_data   = d;
 
+       q = blk_alloc_queue(GFP_KERNEL);
+       if (!q)
+               return -ENOMEM;
+
        blk_queue_make_request(q, NULL);
        d->disk->queue                  = q;
        q->queuedata                    = d;
@@ -874,7 +894,7 @@ static void cached_dev_detach_finish(struct work_struct *w)
        struct closure cl;
        closure_init_stack(&cl);
 
-       BUG_ON(!atomic_read(&dc->disk.detaching));
+       BUG_ON(!test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags));
        BUG_ON(atomic_read(&dc->count));
 
        mutex_lock(&bch_register_lock);
@@ -888,6 +908,8 @@ static void cached_dev_detach_finish(struct work_struct *w)
        bcache_device_detach(&dc->disk);
        list_move(&dc->list, &uncached_devices);
 
+       clear_bit(BCACHE_DEV_DETACHING, &dc->disk.flags);
+
        mutex_unlock(&bch_register_lock);
 
        pr_info("Caching disabled for %s", bdevname(dc->bdev, buf));
@@ -900,10 +922,10 @@ void bch_cached_dev_detach(struct cached_dev *dc)
 {
        lockdep_assert_held(&bch_register_lock);
 
-       if (atomic_read(&dc->disk.closing))
+       if (test_bit(BCACHE_DEV_CLOSING, &dc->disk.flags))
                return;
 
-       if (atomic_xchg(&dc->disk.detaching, 1))
+       if (test_and_set_bit(BCACHE_DEV_DETACHING, &dc->disk.flags))
                return;
 
        /*
@@ -1030,6 +1052,7 @@ static void cached_dev_free(struct closure *cl)
        struct cached_dev *dc = container_of(cl, struct cached_dev, disk.cl);
 
        cancel_delayed_work_sync(&dc->writeback_rate_update);
+       kthread_stop(dc->writeback_thread);
 
        mutex_lock(&bch_register_lock);
 
@@ -1058,11 +1081,7 @@ static void cached_dev_flush(struct closure *cl)
        struct bcache_device *d = &dc->disk;
 
        mutex_lock(&bch_register_lock);
-       d->flush_done = 1;
-
-       if (d->c)
-               bcache_device_unlink(d);
-
+       bcache_device_unlink(d);
        mutex_unlock(&bch_register_lock);
 
        bch_cache_accounting_destroy(&dc->accounting);
@@ -1088,7 +1107,6 @@ static int cached_dev_init(struct cached_dev *dc, unsigned block_size)
        spin_lock_init(&dc->io_lock);
        bch_cache_accounting_init(&dc->accounting, &dc->disk.cl);
 
-       dc->sequential_merge            = true;
        dc->sequential_cutoff           = 4 << 20;
 
        for (io = dc->io; io < dc->io + RECENT_IO; io++) {
@@ -1260,7 +1278,8 @@ bool bch_cache_set_error(struct cache_set *c, const char *fmt, ...)
 {
        va_list args;
 
-       if (test_bit(CACHE_SET_STOPPING, &c->flags))
+       if (c->on_error != ON_ERROR_PANIC &&
+           test_bit(CACHE_SET_STOPPING, &c->flags))
                return false;
 
        /* XXX: we can be called from atomic context
@@ -1275,6 +1294,9 @@ bool bch_cache_set_error(struct cache_set *c, const char *fmt, ...)
 
        printk(", disabling caching\n");
 
+       if (c->on_error == ON_ERROR_PANIC)
+               panic("panic forced after error\n");
+
        bch_cache_set_unregister(c);
        return true;
 }
@@ -1339,6 +1361,9 @@ static void cache_set_flush(struct closure *cl)
        kobject_put(&c->internal);
        kobject_del(&c->kobj);
 
+       if (c->gc_thread)
+               kthread_stop(c->gc_thread);
+
        if (!IS_ERR_OR_NULL(c->root))
                list_add(&c->root->list, &c->btree_cache);
 
@@ -1433,12 +1458,19 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
 
        c->sort_crit_factor = int_sqrt(c->btree_pages);
 
-       mutex_init(&c->bucket_lock);
-       mutex_init(&c->sort_lock);
-       spin_lock_init(&c->sort_time_lock);
        closure_init_unlocked(&c->sb_write);
+       mutex_init(&c->bucket_lock);
+       init_waitqueue_head(&c->try_wait);
+       init_waitqueue_head(&c->bucket_wait);
        closure_init_unlocked(&c->uuid_write);
-       spin_lock_init(&c->btree_read_time_lock);
+       mutex_init(&c->sort_lock);
+
+       spin_lock_init(&c->sort_time.lock);
+       spin_lock_init(&c->btree_gc_time.lock);
+       spin_lock_init(&c->btree_split_time.lock);
+       spin_lock_init(&c->btree_read_time.lock);
+       spin_lock_init(&c->try_harder_time.lock);
+
        bch_moving_init_cache_set(c);
 
        INIT_LIST_HEAD(&c->list);
@@ -1483,11 +1515,10 @@ static void run_cache_set(struct cache_set *c)
        const char *err = "cannot allocate memory";
        struct cached_dev *dc, *t;
        struct cache *ca;
+       struct closure cl;
        unsigned i;
 
-       struct btree_op op;
-       bch_btree_op_init_stack(&op);
-       op.lock = SHRT_MAX;
+       closure_init_stack(&cl);
 
        for_each_cache(ca, c, i)
                c->nbuckets += ca->sb.nbuckets;
@@ -1498,7 +1529,7 @@ static void run_cache_set(struct cache_set *c)
                struct jset *j;
 
                err = "cannot allocate memory for journal";
-               if (bch_journal_read(c, &journal, &op))
+               if (bch_journal_read(c, &journal))
                        goto err;
 
                pr_debug("btree_journal_read() done");
@@ -1522,23 +1553,23 @@ static void run_cache_set(struct cache_set *c)
                k = &j->btree_root;
 
                err = "bad btree root";
-               if (__bch_ptr_invalid(c, j->btree_level + 1, k))
+               if (bch_btree_ptr_invalid(c, k))
                        goto err;
 
                err = "error reading btree root";
-               c->root = bch_btree_node_get(c, k, j->btree_level, &op);
+               c->root = bch_btree_node_get(c, k, j->btree_level, true);
                if (IS_ERR_OR_NULL(c->root))
                        goto err;
 
                list_del_init(&c->root->list);
                rw_unlock(true, c->root);
 
-               err = uuid_read(c, j, &op.cl);
+               err = uuid_read(c, j, &cl);
                if (err)
                        goto err;
 
                err = "error in recovery";
-               if (bch_btree_check(c, &op))
+               if (bch_btree_check(c))
                        goto err;
 
                bch_journal_mark(c, &journal);
@@ -1570,11 +1601,9 @@ static void run_cache_set(struct cache_set *c)
                if (j->version < BCACHE_JSET_VERSION_UUID)
                        __uuid_write(c);
 
-               bch_journal_replay(c, &journal, &op);
+               bch_journal_replay(c, &journal);
        } else {
                pr_notice("invalidating existing data");
-               /* Don't want invalidate_buckets() to queue a gc yet */
-               closure_lock(&c->gc, NULL);
 
                for_each_cache(ca, c, i) {
                        unsigned j;
@@ -1600,15 +1629,15 @@ static void run_cache_set(struct cache_set *c)
 
                err = "cannot allocate new UUID bucket";
                if (__uuid_write(c))
-                       goto err_unlock_gc;
+                       goto err;
 
                err = "cannot allocate new btree root";
-               c->root = bch_btree_node_alloc(c, 0, &op.cl);
+               c->root = bch_btree_node_alloc(c, 0, true);
                if (IS_ERR_OR_NULL(c->root))
-                       goto err_unlock_gc;
+                       goto err;
 
                bkey_copy_key(&c->root->key, &MAX_KEY);
-               bch_btree_node_write(c->root, &op.cl);
+               bch_btree_node_write(c->root, &cl);
 
                bch_btree_set_root(c->root);
                rw_unlock(true, c->root);
@@ -1621,14 +1650,14 @@ static void run_cache_set(struct cache_set *c)
                SET_CACHE_SYNC(&c->sb, true);
 
                bch_journal_next(&c->journal);
-               bch_journal_meta(c, &op.cl);
-
-               /* Unlock */
-               closure_set_stopped(&c->gc.cl);
-               closure_put(&c->gc.cl);
+               bch_journal_meta(c, &cl);
        }
 
-       closure_sync(&op.cl);
+       err = "error starting gc thread";
+       if (bch_gc_thread_start(c))
+               goto err;
+
+       closure_sync(&cl);
        c->sb.last_mount = get_seconds();
        bcache_write_super(c);
 
@@ -1638,13 +1667,10 @@ static void run_cache_set(struct cache_set *c)
        flash_devs_run(c);
 
        return;
-err_unlock_gc:
-       closure_set_stopped(&c->gc.cl);
-       closure_put(&c->gc.cl);
 err:
-       closure_sync(&op.cl);
+       closure_sync(&cl);
        /* XXX: test this, it's broken */
-       bch_cache_set_error(c, err);
+       bch_cache_set_error(c, "%s", err);
 }
 
 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
@@ -1725,8 +1751,6 @@ void bch_cache_release(struct kobject *kobj)
        if (ca->set)
                ca->set->cache[ca->sb.nr_this_dev] = NULL;
 
-       bch_cache_allocator_exit(ca);
-
        bio_split_pool_free(&ca->bio_split_hook);
 
        free_pages((unsigned long) ca->disk_buckets, ilog2(bucket_pages(ca)));
@@ -1758,8 +1782,6 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca)
        __module_get(THIS_MODULE);
        kobject_init(&ca->kobj, &bch_cache_ktype);
 
-       INIT_LIST_HEAD(&ca->discards);
-
        bio_init(&ca->journal.bio);
        ca->journal.bio.bi_max_vecs = 8;
        ca->journal.bio.bi_io_vec = ca->journal.bio.bi_inline_vecs;
@@ -2006,7 +2028,6 @@ static struct notifier_block reboot = {
 static void bcache_exit(void)
 {
        bch_debug_exit();
-       bch_writeback_exit();
        bch_request_exit();
        bch_btree_exit();
        if (bcache_kobj)
@@ -2039,7 +2060,6 @@ static int __init bcache_init(void)
            sysfs_create_files(bcache_kobj, files) ||
            bch_btree_init() ||
            bch_request_init() ||
-           bch_writeback_init() ||
            bch_debug_init(bcache_kobj))
                goto err;
 
index 924dcfdae11102256e1ce193eefc01d82cc173cc..80d4c2bee18aa3fd1af0f58c050145af8e0a1c98 100644 (file)
@@ -21,6 +21,12 @@ static const char * const cache_replacement_policies[] = {
        NULL
 };
 
+static const char * const error_actions[] = {
+       "unregister",
+       "panic",
+       NULL
+};
+
 write_attribute(attach);
 write_attribute(detach);
 write_attribute(unregister);
@@ -66,7 +72,6 @@ rw_attribute(congested_read_threshold_us);
 rw_attribute(congested_write_threshold_us);
 
 rw_attribute(sequential_cutoff);
-rw_attribute(sequential_merge);
 rw_attribute(data_csum);
 rw_attribute(cache_mode);
 rw_attribute(writeback_metadata);
@@ -90,11 +95,14 @@ rw_attribute(discard);
 rw_attribute(running);
 rw_attribute(label);
 rw_attribute(readahead);
+rw_attribute(errors);
 rw_attribute(io_error_limit);
 rw_attribute(io_error_halflife);
 rw_attribute(verify);
+rw_attribute(bypass_torture_test);
 rw_attribute(key_merging_disabled);
 rw_attribute(gc_always_rewrite);
+rw_attribute(expensive_debug_checks);
 rw_attribute(freelist_percent);
 rw_attribute(cache_replacement_policy);
 rw_attribute(btree_shrinker_disabled);
@@ -116,6 +124,7 @@ SHOW(__bch_cached_dev)
 
        sysfs_printf(data_csum,         "%i", dc->disk.data_csum);
        var_printf(verify,              "%i");
+       var_printf(bypass_torture_test, "%i");
        var_printf(writeback_metadata,  "%i");
        var_printf(writeback_running,   "%i");
        var_print(writeback_delay);
@@ -150,10 +159,9 @@ SHOW(__bch_cached_dev)
        sysfs_hprint(dirty_data,
                     bcache_dev_sectors_dirty(&dc->disk) << 9);
 
-       sysfs_hprint(stripe_size,       (1 << dc->disk.stripe_size_bits) << 9);
+       sysfs_hprint(stripe_size,       dc->disk.stripe_size << 9);
        var_printf(partial_stripes_expensive,   "%u");
 
-       var_printf(sequential_merge,    "%i");
        var_hprint(sequential_cutoff);
        var_hprint(readahead);
 
@@ -185,6 +193,7 @@ STORE(__cached_dev)
 
        sysfs_strtoul(data_csum,        dc->disk.data_csum);
        d_strtoul(verify);
+       d_strtoul(bypass_torture_test);
        d_strtoul(writeback_metadata);
        d_strtoul(writeback_running);
        d_strtoul(writeback_delay);
@@ -199,7 +208,6 @@ STORE(__cached_dev)
                            dc->writeback_rate_p_term_inverse, 1, INT_MAX);
        d_strtoul(writeback_rate_d_smooth);
 
-       d_strtoul(sequential_merge);
        d_strtoi_h(sequential_cutoff);
        d_strtoi_h(readahead);
 
@@ -311,7 +319,6 @@ static struct attribute *bch_cached_dev_files[] = {
        &sysfs_stripe_size,
        &sysfs_partial_stripes_expensive,
        &sysfs_sequential_cutoff,
-       &sysfs_sequential_merge,
        &sysfs_clear_stats,
        &sysfs_running,
        &sysfs_state,
@@ -319,6 +326,7 @@ static struct attribute *bch_cached_dev_files[] = {
        &sysfs_readahead,
 #ifdef CONFIG_BCACHE_DEBUG
        &sysfs_verify,
+       &sysfs_bypass_torture_test,
 #endif
        NULL
 };
@@ -366,7 +374,7 @@ STORE(__bch_flash_dev)
        }
 
        if (attr == &sysfs_unregister) {
-               atomic_set(&d->detaching, 1);
+               set_bit(BCACHE_DEV_DETACHING, &d->flags);
                bcache_device_stop(d);
        }
 
@@ -481,7 +489,6 @@ lock_root:
 
        sysfs_print(btree_used_percent, btree_used(c));
        sysfs_print(btree_nodes,        c->gc_stats.nodes);
-       sysfs_hprint(dirty_data,        c->gc_stats.dirty);
        sysfs_hprint(average_key_size,  average_key_size(c));
 
        sysfs_print(cache_read_races,
@@ -492,6 +499,10 @@ lock_root:
        sysfs_print(writeback_keys_failed,
                    atomic_long_read(&c->writeback_keys_failed));
 
+       if (attr == &sysfs_errors)
+               return bch_snprint_string_list(buf, PAGE_SIZE, error_actions,
+                                              c->on_error);
+
        /* See count_io_errors for why 88 */
        sysfs_print(io_error_halflife,  c->error_decay * 88);
        sysfs_print(io_error_limit,     c->error_limit >> IO_ERROR_SHIFT);
@@ -506,6 +517,8 @@ lock_root:
        sysfs_print(active_journal_entries,     fifo_used(&c->journal.pin));
        sysfs_printf(verify,                    "%i", c->verify);
        sysfs_printf(key_merging_disabled,      "%i", c->key_merging_disabled);
+       sysfs_printf(expensive_debug_checks,
+                    "%i", c->expensive_debug_checks);
        sysfs_printf(gc_always_rewrite,         "%i", c->gc_always_rewrite);
        sysfs_printf(btree_shrinker_disabled,   "%i", c->shrinker_disabled);
        sysfs_printf(copy_gc_enabled,           "%i", c->copy_gc_enabled);
@@ -555,7 +568,7 @@ STORE(__bch_cache_set)
        }
 
        if (attr == &sysfs_trigger_gc)
-               bch_queue_gc(c);
+               wake_up_gc(c);
 
        if (attr == &sysfs_prune_cache) {
                struct shrink_control sc;
@@ -569,6 +582,15 @@ STORE(__bch_cache_set)
        sysfs_strtoul(congested_write_threshold_us,
                      c->congested_write_threshold_us);
 
+       if (attr == &sysfs_errors) {
+               ssize_t v = bch_read_string_list(buf, error_actions);
+
+               if (v < 0)
+                       return v;
+
+               c->on_error = v;
+       }
+
        if (attr == &sysfs_io_error_limit)
                c->error_limit = strtoul_or_return(buf) << IO_ERROR_SHIFT;
 
@@ -579,6 +601,7 @@ STORE(__bch_cache_set)
        sysfs_strtoul(journal_delay_ms,         c->journal_delay_ms);
        sysfs_strtoul(verify,                   c->verify);
        sysfs_strtoul(key_merging_disabled,     c->key_merging_disabled);
+       sysfs_strtoul(expensive_debug_checks,   c->expensive_debug_checks);
        sysfs_strtoul(gc_always_rewrite,        c->gc_always_rewrite);
        sysfs_strtoul(btree_shrinker_disabled,  c->shrinker_disabled);
        sysfs_strtoul(copy_gc_enabled,          c->copy_gc_enabled);
@@ -618,8 +641,8 @@ static struct attribute *bch_cache_set_files[] = {
        &sysfs_cache_available_percent,
 
        &sysfs_average_key_size,
-       &sysfs_dirty_data,
 
+       &sysfs_errors,
        &sysfs_io_error_limit,
        &sysfs_io_error_halflife,
        &sysfs_congested,
@@ -653,6 +676,7 @@ static struct attribute *bch_cache_set_internal_files[] = {
 #ifdef CONFIG_BCACHE_DEBUG
        &sysfs_verify,
        &sysfs_key_merging_disabled,
+       &sysfs_expensive_debug_checks,
 #endif
        &sysfs_gc_always_rewrite,
        &sysfs_btree_shrinker_disabled,
index f7b6c197f90f94f6aeb8ec59159265962af663c1..adbc3df17a8063933fd395de7763c5e9d560ea67 100644 (file)
@@ -1,6 +1,5 @@
 #include "bcache.h"
 #include "btree.h"
-#include "request.h"
 
 #include <linux/blktrace_api.h>
 #include <linux/module.h>
index 420dad545c7d8a01e8b5c18d26db4b25677fd334..462214eeacbedbd9548e725be2e625723cda0d7e 100644 (file)
@@ -168,10 +168,14 @@ int bch_parse_uuid(const char *s, char *uuid)
 
 void bch_time_stats_update(struct time_stats *stats, uint64_t start_time)
 {
-       uint64_t now            = local_clock();
-       uint64_t duration       = time_after64(now, start_time)
+       uint64_t now, duration, last;
+
+       spin_lock(&stats->lock);
+
+       now             = local_clock();
+       duration        = time_after64(now, start_time)
                ? now - start_time : 0;
-       uint64_t last           = time_after64(now, stats->last)
+       last            = time_after64(now, stats->last)
                ? now - stats->last : 0;
 
        stats->max_duration = max(stats->max_duration, duration);
@@ -188,6 +192,8 @@ void bch_time_stats_update(struct time_stats *stats, uint64_t start_time)
        }
 
        stats->last = now ?: 1;
+
+       spin_unlock(&stats->lock);
 }
 
 /**
index ea345c6896f47777942b64f88810c99d4cbc278e..362c4b3f8b4a00e70d2e36af9ee7ec8cbe67e39e 100644 (file)
 
 struct closure;
 
-#ifdef CONFIG_BCACHE_EDEBUG
+#ifdef CONFIG_BCACHE_DEBUG
 
 #define atomic_dec_bug(v)      BUG_ON(atomic_dec_return(v) < 0)
 #define atomic_inc_bug(v, i)   BUG_ON(atomic_inc_return(v) <= i)
 
-#else /* EDEBUG */
+#else /* DEBUG */
 
 #define atomic_dec_bug(v)      atomic_dec(v)
 #define atomic_inc_bug(v, i)   atomic_inc(v)
 
 #endif
 
-#define BITMASK(name, type, field, offset, size)               \
-static inline uint64_t name(const type *k)                     \
-{ return (k->field >> offset) & ~(((uint64_t) ~0) << size); }  \
-                                                               \
-static inline void SET_##name(type *k, uint64_t v)             \
-{                                                              \
-       k->field &= ~(~((uint64_t) ~0 << size) << offset);      \
-       k->field |= v << offset;                                \
-}
-
 #define DECLARE_HEAP(type, name)                                       \
        struct {                                                        \
                size_t size, used;                                      \
@@ -388,6 +378,7 @@ ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[
 ssize_t bch_read_string_list(const char *buf, const char * const list[]);
 
 struct time_stats {
+       spinlock_t      lock;
        /*
         * all fields are in nanoseconds, averages are ewmas stored left shifted
         * by 8
index ba3ee48320f2a38509adb2603f766c55e67f1da1..99053b1251bea1049c627580f3614d1c18f89b60 100644 (file)
 #include "debug.h"
 #include "writeback.h"
 
+#include <linux/delay.h>
+#include <linux/freezer.h>
+#include <linux/kthread.h>
 #include <trace/events/bcache.h>
 
-static struct workqueue_struct *dirty_wq;
-
-static void read_dirty(struct closure *);
-
-struct dirty_io {
-       struct closure          cl;
-       struct cached_dev       *dc;
-       struct bio              bio;
-};
-
 /* Rate limiting */
 
 static void __update_writeback_rate(struct cached_dev *dc)
@@ -72,9 +65,6 @@ out:
        dc->writeback_rate_derivative = derivative;
        dc->writeback_rate_change = change;
        dc->writeback_rate_target = target;
-
-       schedule_delayed_work(&dc->writeback_rate_update,
-                             dc->writeback_rate_update_seconds * HZ);
 }
 
 static void update_writeback_rate(struct work_struct *work)
@@ -90,13 +80,16 @@ static void update_writeback_rate(struct work_struct *work)
                __update_writeback_rate(dc);
 
        up_read(&dc->writeback_lock);
+
+       schedule_delayed_work(&dc->writeback_rate_update,
+                             dc->writeback_rate_update_seconds * HZ);
 }
 
 static unsigned writeback_delay(struct cached_dev *dc, unsigned sectors)
 {
        uint64_t ret;
 
-       if (atomic_read(&dc->disk.detaching) ||
+       if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) ||
            !dc->writeback_percent)
                return 0;
 
@@ -105,37 +98,11 @@ static unsigned writeback_delay(struct cached_dev *dc, unsigned sectors)
        return min_t(uint64_t, ret, HZ);
 }
 
-/* Background writeback */
-
-static bool dirty_pred(struct keybuf *buf, struct bkey *k)
-{
-       return KEY_DIRTY(k);
-}
-
-static bool dirty_full_stripe_pred(struct keybuf *buf, struct bkey *k)
-{
-       uint64_t stripe;
-       unsigned nr_sectors = KEY_SIZE(k);
-       struct cached_dev *dc = container_of(buf, struct cached_dev,
-                                            writeback_keys);
-       unsigned stripe_size = 1 << dc->disk.stripe_size_bits;
-
-       if (!KEY_DIRTY(k))
-               return false;
-
-       stripe = KEY_START(k) >> dc->disk.stripe_size_bits;
-       while (1) {
-               if (atomic_read(dc->disk.stripe_sectors_dirty + stripe) !=
-                   stripe_size)
-                       return false;
-
-               if (nr_sectors <= stripe_size)
-                       return true;
-
-               nr_sectors -= stripe_size;
-               stripe++;
-       }
-}
+struct dirty_io {
+       struct closure          cl;
+       struct cached_dev       *dc;
+       struct bio              bio;
+};
 
 static void dirty_init(struct keybuf_key *w)
 {
@@ -153,131 +120,6 @@ static void dirty_init(struct keybuf_key *w)
        bch_bio_map(bio, NULL);
 }
 
-static void refill_dirty(struct closure *cl)
-{
-       struct cached_dev *dc = container_of(cl, struct cached_dev,
-                                            writeback.cl);
-       struct keybuf *buf = &dc->writeback_keys;
-       bool searched_from_start = false;
-       struct bkey end = MAX_KEY;
-       SET_KEY_INODE(&end, dc->disk.id);
-
-       if (!atomic_read(&dc->disk.detaching) &&
-           !dc->writeback_running)
-               closure_return(cl);
-
-       down_write(&dc->writeback_lock);
-
-       if (!atomic_read(&dc->has_dirty)) {
-               SET_BDEV_STATE(&dc->sb, BDEV_STATE_CLEAN);
-               bch_write_bdev_super(dc, NULL);
-
-               up_write(&dc->writeback_lock);
-               closure_return(cl);
-       }
-
-       if (bkey_cmp(&buf->last_scanned, &end) >= 0) {
-               buf->last_scanned = KEY(dc->disk.id, 0, 0);
-               searched_from_start = true;
-       }
-
-       if (dc->partial_stripes_expensive) {
-               uint64_t i;
-
-               for (i = 0; i < dc->disk.nr_stripes; i++)
-                       if (atomic_read(dc->disk.stripe_sectors_dirty + i) ==
-                           1 << dc->disk.stripe_size_bits)
-                               goto full_stripes;
-
-               goto normal_refill;
-full_stripes:
-               bch_refill_keybuf(dc->disk.c, buf, &end,
-                                 dirty_full_stripe_pred);
-       } else {
-normal_refill:
-               bch_refill_keybuf(dc->disk.c, buf, &end, dirty_pred);
-       }
-
-       if (bkey_cmp(&buf->last_scanned, &end) >= 0 && searched_from_start) {
-               /* Searched the entire btree  - delay awhile */
-
-               if (RB_EMPTY_ROOT(&buf->keys)) {
-                       atomic_set(&dc->has_dirty, 0);
-                       cached_dev_put(dc);
-               }
-
-               if (!atomic_read(&dc->disk.detaching))
-                       closure_delay(&dc->writeback, dc->writeback_delay * HZ);
-       }
-
-       up_write(&dc->writeback_lock);
-
-       bch_ratelimit_reset(&dc->writeback_rate);
-
-       /* Punt to workqueue only so we don't recurse and blow the stack */
-       continue_at(cl, read_dirty, dirty_wq);
-}
-
-void bch_writeback_queue(struct cached_dev *dc)
-{
-       if (closure_trylock(&dc->writeback.cl, &dc->disk.cl)) {
-               if (!atomic_read(&dc->disk.detaching))
-                       closure_delay(&dc->writeback, dc->writeback_delay * HZ);
-
-               continue_at(&dc->writeback.cl, refill_dirty, dirty_wq);
-       }
-}
-
-void bch_writeback_add(struct cached_dev *dc)
-{
-       if (!atomic_read(&dc->has_dirty) &&
-           !atomic_xchg(&dc->has_dirty, 1)) {
-               atomic_inc(&dc->count);
-
-               if (BDEV_STATE(&dc->sb) != BDEV_STATE_DIRTY) {
-                       SET_BDEV_STATE(&dc->sb, BDEV_STATE_DIRTY);
-                       /* XXX: should do this synchronously */
-                       bch_write_bdev_super(dc, NULL);
-               }
-
-               bch_writeback_queue(dc);
-
-               if (dc->writeback_percent)
-                       schedule_delayed_work(&dc->writeback_rate_update,
-                                     dc->writeback_rate_update_seconds * HZ);
-       }
-}
-
-void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned inode,
-                                 uint64_t offset, int nr_sectors)
-{
-       struct bcache_device *d = c->devices[inode];
-       unsigned stripe_size, stripe_offset;
-       uint64_t stripe;
-
-       if (!d)
-               return;
-
-       stripe_size = 1 << d->stripe_size_bits;
-       stripe = offset >> d->stripe_size_bits;
-       stripe_offset = offset & (stripe_size - 1);
-
-       while (nr_sectors) {
-               int s = min_t(unsigned, abs(nr_sectors),
-                             stripe_size - stripe_offset);
-
-               if (nr_sectors < 0)
-                       s = -s;
-
-               atomic_add(s, d->stripe_sectors_dirty + stripe);
-               nr_sectors -= s;
-               stripe_offset = 0;
-               stripe++;
-       }
-}
-
-/* Background writeback - IO loop */
-
 static void dirty_io_destructor(struct closure *cl)
 {
        struct dirty_io *io = container_of(cl, struct dirty_io, cl);
@@ -297,26 +139,25 @@ static void write_dirty_finish(struct closure *cl)
 
        /* This is kind of a dumb way of signalling errors. */
        if (KEY_DIRTY(&w->key)) {
+               int ret;
                unsigned i;
-               struct btree_op op;
-               bch_btree_op_init_stack(&op);
+               struct keylist keys;
 
-               op.type = BTREE_REPLACE;
-               bkey_copy(&op.replace, &w->key);
+               bch_keylist_init(&keys);
 
-               SET_KEY_DIRTY(&w->key, false);
-               bch_keylist_add(&op.keys, &w->key);
+               bkey_copy(keys.top, &w->key);
+               SET_KEY_DIRTY(keys.top, false);
+               bch_keylist_push(&keys);
 
                for (i = 0; i < KEY_PTRS(&w->key); i++)
                        atomic_inc(&PTR_BUCKET(dc->disk.c, &w->key, i)->pin);
 
-               bch_btree_insert(&op, dc->disk.c);
-               closure_sync(&op.cl);
+               ret = bch_btree_insert(dc->disk.c, &keys, NULL, &w->key);
 
-               if (op.insert_collision)
+               if (ret)
                        trace_bcache_writeback_collision(&w->key);
 
-               atomic_long_inc(op.insert_collision
+               atomic_long_inc(ret
                                ? &dc->disk.c->writeback_keys_failed
                                : &dc->disk.c->writeback_keys_done);
        }
@@ -374,30 +215,33 @@ static void read_dirty_submit(struct closure *cl)
        continue_at(cl, write_dirty, system_wq);
 }
 
-static void read_dirty(struct closure *cl)
+static void read_dirty(struct cached_dev *dc)
 {
-       struct cached_dev *dc = container_of(cl, struct cached_dev,
-                                            writeback.cl);
-       unsigned delay = writeback_delay(dc, 0);
+       unsigned delay = 0;
        struct keybuf_key *w;
        struct dirty_io *io;
+       struct closure cl;
+
+       closure_init_stack(&cl);
 
        /*
         * XXX: if we error, background writeback just spins. Should use some
         * mempools.
         */
 
-       while (1) {
+       while (!kthread_should_stop()) {
+               try_to_freeze();
+
                w = bch_keybuf_next(&dc->writeback_keys);
                if (!w)
                        break;
 
                BUG_ON(ptr_stale(dc->disk.c, &w->key, 0));
 
-               if (delay > 0 &&
-                   (KEY_START(&w->key) != dc->last_read ||
-                    jiffies_to_msecs(delay) > 50))
-                       delay = schedule_timeout_uninterruptible(delay);
+               if (KEY_START(&w->key) != dc->last_read ||
+                   jiffies_to_msecs(delay) > 50)
+                       while (!kthread_should_stop() && delay)
+                               delay = schedule_timeout_interruptible(delay);
 
                dc->last_read   = KEY_OFFSET(&w->key);
 
@@ -423,7 +267,7 @@ static void read_dirty(struct closure *cl)
                trace_bcache_writeback(&w->key);
 
                down(&dc->in_flight);
-               closure_call(&io->cl, read_dirty_submit, NULL, cl);
+               closure_call(&io->cl, read_dirty_submit, NULL, &cl);
 
                delay = writeback_delay(dc, KEY_SIZE(&w->key));
        }
@@ -439,52 +283,205 @@ err:
         * Wait for outstanding writeback IOs to finish (and keybuf slots to be
         * freed) before refilling again
         */
-       continue_at(cl, refill_dirty, dirty_wq);
+       closure_sync(&cl);
 }
 
-/* Init */
+/* Scan for dirty data */
+
+void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned inode,
+                                 uint64_t offset, int nr_sectors)
+{
+       struct bcache_device *d = c->devices[inode];
+       unsigned stripe_offset, stripe, sectors_dirty;
+
+       if (!d)
+               return;
+
+       stripe = offset_to_stripe(d, offset);
+       stripe_offset = offset & (d->stripe_size - 1);
+
+       while (nr_sectors) {
+               int s = min_t(unsigned, abs(nr_sectors),
+                             d->stripe_size - stripe_offset);
+
+               if (nr_sectors < 0)
+                       s = -s;
+
+               if (stripe >= d->nr_stripes)
+                       return;
+
+               sectors_dirty = atomic_add_return(s,
+                                       d->stripe_sectors_dirty + stripe);
+               if (sectors_dirty == d->stripe_size)
+                       set_bit(stripe, d->full_dirty_stripes);
+               else
+                       clear_bit(stripe, d->full_dirty_stripes);
+
+               nr_sectors -= s;
+               stripe_offset = 0;
+               stripe++;
+       }
+}
 
-static int bch_btree_sectors_dirty_init(struct btree *b, struct btree_op *op,
-                                       struct cached_dev *dc)
+static bool dirty_pred(struct keybuf *buf, struct bkey *k)
 {
-       struct bkey *k;
-       struct btree_iter iter;
-
-       bch_btree_iter_init(b, &iter, &KEY(dc->disk.id, 0, 0));
-       while ((k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad)))
-               if (!b->level) {
-                       if (KEY_INODE(k) > dc->disk.id)
-                               break;
-
-                       if (KEY_DIRTY(k))
-                               bcache_dev_sectors_dirty_add(b->c, dc->disk.id,
-                                                            KEY_START(k),
-                                                            KEY_SIZE(k));
-               } else {
-                       btree(sectors_dirty_init, k, b, op, dc);
-                       if (KEY_INODE(k) > dc->disk.id)
-                               break;
-
-                       cond_resched();
+       return KEY_DIRTY(k);
+}
+
+static void refill_full_stripes(struct cached_dev *dc)
+{
+       struct keybuf *buf = &dc->writeback_keys;
+       unsigned start_stripe, stripe, next_stripe;
+       bool wrapped = false;
+
+       stripe = offset_to_stripe(&dc->disk, KEY_OFFSET(&buf->last_scanned));
+
+       if (stripe >= dc->disk.nr_stripes)
+               stripe = 0;
+
+       start_stripe = stripe;
+
+       while (1) {
+               stripe = find_next_bit(dc->disk.full_dirty_stripes,
+                                      dc->disk.nr_stripes, stripe);
+
+               if (stripe == dc->disk.nr_stripes)
+                       goto next;
+
+               next_stripe = find_next_zero_bit(dc->disk.full_dirty_stripes,
+                                                dc->disk.nr_stripes, stripe);
+
+               buf->last_scanned = KEY(dc->disk.id,
+                                       stripe * dc->disk.stripe_size, 0);
+
+               bch_refill_keybuf(dc->disk.c, buf,
+                                 &KEY(dc->disk.id,
+                                      next_stripe * dc->disk.stripe_size, 0),
+                                 dirty_pred);
+
+               if (array_freelist_empty(&buf->freelist))
+                       return;
+
+               stripe = next_stripe;
+next:
+               if (wrapped && stripe > start_stripe)
+                       return;
+
+               if (stripe == dc->disk.nr_stripes) {
+                       stripe = 0;
+                       wrapped = true;
                }
+       }
+}
+
+static bool refill_dirty(struct cached_dev *dc)
+{
+       struct keybuf *buf = &dc->writeback_keys;
+       struct bkey end = KEY(dc->disk.id, MAX_KEY_OFFSET, 0);
+       bool searched_from_start = false;
+
+       if (dc->partial_stripes_expensive) {
+               refill_full_stripes(dc);
+               if (array_freelist_empty(&buf->freelist))
+                       return false;
+       }
+
+       if (bkey_cmp(&buf->last_scanned, &end) >= 0) {
+               buf->last_scanned = KEY(dc->disk.id, 0, 0);
+               searched_from_start = true;
+       }
+
+       bch_refill_keybuf(dc->disk.c, buf, &end, dirty_pred);
+
+       return bkey_cmp(&buf->last_scanned, &end) >= 0 && searched_from_start;
+}
+
+static int bch_writeback_thread(void *arg)
+{
+       struct cached_dev *dc = arg;
+       bool searched_full_index;
+
+       while (!kthread_should_stop()) {
+               down_write(&dc->writeback_lock);
+               if (!atomic_read(&dc->has_dirty) ||
+                   (!test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) &&
+                    !dc->writeback_running)) {
+                       up_write(&dc->writeback_lock);
+                       set_current_state(TASK_INTERRUPTIBLE);
+
+                       if (kthread_should_stop())
+                               return 0;
+
+                       try_to_freeze();
+                       schedule();
+                       continue;
+               }
+
+               searched_full_index = refill_dirty(dc);
+
+               if (searched_full_index &&
+                   RB_EMPTY_ROOT(&dc->writeback_keys.keys)) {
+                       atomic_set(&dc->has_dirty, 0);
+                       cached_dev_put(dc);
+                       SET_BDEV_STATE(&dc->sb, BDEV_STATE_CLEAN);
+                       bch_write_bdev_super(dc, NULL);
+               }
+
+               up_write(&dc->writeback_lock);
+
+               bch_ratelimit_reset(&dc->writeback_rate);
+               read_dirty(dc);
+
+               if (searched_full_index) {
+                       unsigned delay = dc->writeback_delay * HZ;
+
+                       while (delay &&
+                              !kthread_should_stop() &&
+                              !test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags))
+                               delay = schedule_timeout_interruptible(delay);
+               }
+       }
 
        return 0;
 }
 
+/* Init */
+
+struct sectors_dirty_init {
+       struct btree_op op;
+       unsigned        inode;
+};
+
+static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b,
+                                struct bkey *k)
+{
+       struct sectors_dirty_init *op = container_of(_op,
+                                               struct sectors_dirty_init, op);
+       if (KEY_INODE(k) > op->inode)
+               return MAP_DONE;
+
+       if (KEY_DIRTY(k))
+               bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k),
+                                            KEY_START(k), KEY_SIZE(k));
+
+       return MAP_CONTINUE;
+}
+
 void bch_sectors_dirty_init(struct cached_dev *dc)
 {
-       struct btree_op op;
+       struct sectors_dirty_init op;
+
+       bch_btree_op_init(&op.op, -1);
+       op.inode = dc->disk.id;
 
-       bch_btree_op_init_stack(&op);
-       btree_root(sectors_dirty_init, dc->disk.c, &op, dc);
+       bch_btree_map_keys(&op.op, dc->disk.c, &KEY(op.inode, 0, 0),
+                          sectors_dirty_init_fn, 0);
 }
 
-void bch_cached_dev_writeback_init(struct cached_dev *dc)
+int bch_cached_dev_writeback_init(struct cached_dev *dc)
 {
        sema_init(&dc->in_flight, 64);
-       closure_init_unlocked(&dc->writeback);
        init_rwsem(&dc->writeback_lock);
-
        bch_keybuf_init(&dc->writeback_keys);
 
        dc->writeback_metadata          = true;
@@ -498,22 +495,16 @@ void bch_cached_dev_writeback_init(struct cached_dev *dc)
        dc->writeback_rate_p_term_inverse = 64;
        dc->writeback_rate_d_smooth     = 8;
 
+       dc->writeback_thread = kthread_create(bch_writeback_thread, dc,
+                                             "bcache_writeback");
+       if (IS_ERR(dc->writeback_thread))
+               return PTR_ERR(dc->writeback_thread);
+
+       set_task_state(dc->writeback_thread, TASK_INTERRUPTIBLE);
+
        INIT_DELAYED_WORK(&dc->writeback_rate_update, update_writeback_rate);
        schedule_delayed_work(&dc->writeback_rate_update,
                              dc->writeback_rate_update_seconds * HZ);
-}
-
-void bch_writeback_exit(void)
-{
-       if (dirty_wq)
-               destroy_workqueue(dirty_wq);
-}
-
-int __init bch_writeback_init(void)
-{
-       dirty_wq = create_workqueue("bcache_writeback");
-       if (!dirty_wq)
-               return -ENOMEM;
 
        return 0;
 }
index c91f61bb95b60bc95b4f5462602c3e0cd357ccec..c9ddcf4614b9300701c9867033c82bc13cadf472 100644 (file)
@@ -14,20 +14,27 @@ static inline uint64_t bcache_dev_sectors_dirty(struct bcache_device *d)
        return ret;
 }
 
-static inline bool bcache_dev_stripe_dirty(struct bcache_device *d,
+static inline unsigned offset_to_stripe(struct bcache_device *d,
+                                       uint64_t offset)
+{
+       do_div(offset, d->stripe_size);
+       return offset;
+}
+
+static inline bool bcache_dev_stripe_dirty(struct cached_dev *dc,
                                           uint64_t offset,
                                           unsigned nr_sectors)
 {
-       uint64_t stripe = offset >> d->stripe_size_bits;
+       unsigned stripe = offset_to_stripe(&dc->disk, offset);
 
        while (1) {
-               if (atomic_read(d->stripe_sectors_dirty + stripe))
+               if (atomic_read(dc->disk.stripe_sectors_dirty + stripe))
                        return true;
 
-               if (nr_sectors <= 1 << d->stripe_size_bits)
+               if (nr_sectors <= dc->disk.stripe_size)
                        return false;
 
-               nr_sectors -= 1 << d->stripe_size_bits;
+               nr_sectors -= dc->disk.stripe_size;
                stripe++;
        }
 }
@@ -38,12 +45,12 @@ static inline bool should_writeback(struct cached_dev *dc, struct bio *bio,
        unsigned in_use = dc->disk.c->gc_stats.in_use;
 
        if (cache_mode != CACHE_MODE_WRITEBACK ||
-           atomic_read(&dc->disk.detaching) ||
+           test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) ||
            in_use > CUTOFF_WRITEBACK_SYNC)
                return false;
 
        if (dc->partial_stripes_expensive &&
-           bcache_dev_stripe_dirty(&dc->disk, bio->bi_sector,
+           bcache_dev_stripe_dirty(dc, bio->bi_sector,
                                    bio_sectors(bio)))
                return true;
 
@@ -54,11 +61,30 @@ static inline bool should_writeback(struct cached_dev *dc, struct bio *bio,
                in_use <= CUTOFF_WRITEBACK;
 }
 
+static inline void bch_writeback_queue(struct cached_dev *dc)
+{
+       wake_up_process(dc->writeback_thread);
+}
+
+static inline void bch_writeback_add(struct cached_dev *dc)
+{
+       if (!atomic_read(&dc->has_dirty) &&
+           !atomic_xchg(&dc->has_dirty, 1)) {
+               atomic_inc(&dc->count);
+
+               if (BDEV_STATE(&dc->sb) != BDEV_STATE_DIRTY) {
+                       SET_BDEV_STATE(&dc->sb, BDEV_STATE_DIRTY);
+                       /* XXX: should do this synchronously */
+                       bch_write_bdev_super(dc, NULL);
+               }
+
+               bch_writeback_queue(dc);
+       }
+}
+
 void bcache_dev_sectors_dirty_add(struct cache_set *, unsigned, uint64_t, int);
-void bch_writeback_queue(struct cached_dev *);
-void bch_writeback_add(struct cached_dev *);
 
 void bch_sectors_dirty_init(struct cached_dev *dc);
-void bch_cached_dev_writeback_init(struct cached_dev *);
+int bch_cached_dev_writeback_init(struct cached_dev *);
 
 #endif
index 8766eabb0014a075e5ace35860806fb3bf31be3f..b6b7a2866c9e99533afd59a0a142712f58febe63 100644 (file)
@@ -112,7 +112,7 @@ static inline int speed_max(struct mddev *mddev)
 
 static struct ctl_table_header *raid_table_header;
 
-static ctl_table raid_table[] = {
+static struct ctl_table raid_table[] = {
        {
                .procname       = "speed_limit_min",
                .data           = &sysctl_speed_limit_min,
@@ -130,7 +130,7 @@ static ctl_table raid_table[] = {
        { }
 };
 
-static ctl_table raid_dir_table[] = {
+static struct ctl_table raid_dir_table[] = {
        {
                .procname       = "raid",
                .maxlen         = 0,
@@ -140,7 +140,7 @@ static ctl_table raid_dir_table[] = {
        { }
 };
 
-static ctl_table raid_root_table[] = {
+static struct ctl_table raid_root_table[] = {
        {
                .procname       = "dev",
                .maxlen         = 0,
@@ -562,11 +562,19 @@ static struct mddev * mddev_find(dev_t unit)
        goto retry;
 }
 
-static inline int mddev_lock(struct mddev * mddev)
+static inline int __must_check mddev_lock(struct mddev * mddev)
 {
        return mutex_lock_interruptible(&mddev->reconfig_mutex);
 }
 
+/* Sometimes we need to take the lock in a situation where
+ * failure due to interrupts is not acceptable.
+ */
+static inline void mddev_lock_nointr(struct mddev * mddev)
+{
+       mutex_lock(&mddev->reconfig_mutex);
+}
+
 static inline int mddev_is_locked(struct mddev *mddev)
 {
        return mutex_is_locked(&mddev->reconfig_mutex);
@@ -2978,7 +2986,7 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
                for_each_mddev(mddev, tmp) {
                        struct md_rdev *rdev2;
 
-                       mddev_lock(mddev);
+                       mddev_lock_nointr(mddev);
                        rdev_for_each(rdev2, mddev)
                                if (rdev->bdev == rdev2->bdev &&
                                    rdev != rdev2 &&
@@ -2994,7 +3002,7 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len)
                                break;
                        }
                }
-               mddev_lock(my_mddev);
+               mddev_lock_nointr(my_mddev);
                if (overlap) {
                        /* Someone else could have slipped in a size
                         * change here, but doing so is just silly.
@@ -3580,6 +3588,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
                mddev->in_sync = 1;
                del_timer_sync(&mddev->safemode_timer);
        }
+       blk_set_stacking_limits(&mddev->queue->limits);
        pers->run(mddev);
        set_bit(MD_CHANGE_DEVS, &mddev->flags);
        mddev_resume(mddev);
@@ -5258,7 +5267,7 @@ static void __md_stop_writes(struct mddev *mddev)
 
 void md_stop_writes(struct mddev *mddev)
 {
-       mddev_lock(mddev);
+       mddev_lock_nointr(mddev);
        __md_stop_writes(mddev);
        mddev_unlock(mddev);
 }
@@ -5291,20 +5300,35 @@ EXPORT_SYMBOL_GPL(md_stop);
 static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
 {
        int err = 0;
+       int did_freeze = 0;
+
+       if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) {
+               did_freeze = 1;
+               set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
+               md_wakeup_thread(mddev->thread);
+       }
+       if (mddev->sync_thread) {
+               set_bit(MD_RECOVERY_INTR, &mddev->recovery);
+               /* Thread might be blocked waiting for metadata update
+                * which will now never happen */
+               wake_up_process(mddev->sync_thread->tsk);
+       }
+       mddev_unlock(mddev);
+       wait_event(resync_wait, mddev->sync_thread == NULL);
+       mddev_lock_nointr(mddev);
+
        mutex_lock(&mddev->open_mutex);
-       if (atomic_read(&mddev->openers) > !!bdev) {
+       if (atomic_read(&mddev->openers) > !!bdev ||
+           mddev->sync_thread ||
+           (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
                printk("md: %s still in use.\n",mdname(mddev));
+               if (did_freeze) {
+                       clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
+                       md_wakeup_thread(mddev->thread);
+               }
                err = -EBUSY;
                goto out;
        }
-       if (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags)) {
-               /* Someone opened the device since we flushed it
-                * so page cache could be dirty and it is too late
-                * to flush.  So abort
-                */
-               mutex_unlock(&mddev->open_mutex);
-               return -EBUSY;
-       }
        if (mddev->pers) {
                __md_stop_writes(mddev);
 
@@ -5315,7 +5339,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
                set_disk_ro(mddev->gendisk, 1);
                clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
                sysfs_notify_dirent_safe(mddev->sysfs_state);
-               err = 0;        
+               err = 0;
        }
 out:
        mutex_unlock(&mddev->open_mutex);
@@ -5331,20 +5355,34 @@ static int do_md_stop(struct mddev * mddev, int mode,
 {
        struct gendisk *disk = mddev->gendisk;
        struct md_rdev *rdev;
+       int did_freeze = 0;
+
+       if (!test_bit(MD_RECOVERY_FROZEN, &mddev->recovery)) {
+               did_freeze = 1;
+               set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
+               md_wakeup_thread(mddev->thread);
+       }
+       if (mddev->sync_thread) {
+               set_bit(MD_RECOVERY_INTR, &mddev->recovery);
+               /* Thread might be blocked waiting for metadata update
+                * which will now never happen */
+               wake_up_process(mddev->sync_thread->tsk);
+       }
+       mddev_unlock(mddev);
+       wait_event(resync_wait, mddev->sync_thread == NULL);
+       mddev_lock_nointr(mddev);
 
        mutex_lock(&mddev->open_mutex);
        if (atomic_read(&mddev->openers) > !!bdev ||
-           mddev->sysfs_active) {
+           mddev->sysfs_active ||
+           mddev->sync_thread ||
+           (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
                printk("md: %s still in use.\n",mdname(mddev));
                mutex_unlock(&mddev->open_mutex);
-               return -EBUSY;
-       }
-       if (bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags)) {
-               /* Someone opened the device since we flushed it
-                * so page cache could be dirty and it is too late
-                * to flush.  So abort
-                */
-               mutex_unlock(&mddev->open_mutex);
+               if (did_freeze) {
+                       clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
+                       md_wakeup_thread(mddev->thread);
+               }
                return -EBUSY;
        }
        if (mddev->pers) {
@@ -6551,7 +6589,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
                                wait_event(mddev->sb_wait,
                                           !test_bit(MD_CHANGE_DEVS, &mddev->flags) &&
                                           !test_bit(MD_CHANGE_PENDING, &mddev->flags));
-                               mddev_lock(mddev);
+                               mddev_lock_nointr(mddev);
                        }
                } else {
                        err = -EROFS;
@@ -7361,9 +7399,6 @@ void md_do_sync(struct md_thread *thread)
                mddev->curr_resync = 2;
 
        try_again:
-               if (kthread_should_stop())
-                       set_bit(MD_RECOVERY_INTR, &mddev->recovery);
-
                if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
                        goto skip;
                for_each_mddev(mddev2, tmp) {
@@ -7388,7 +7423,7 @@ void md_do_sync(struct md_thread *thread)
                                 * be caught by 'softlockup'
                                 */
                                prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE);
-                               if (!kthread_should_stop() &&
+                               if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
                                    mddev2->curr_resync >= mddev->curr_resync) {
                                        printk(KERN_INFO "md: delaying %s of %s"
                                               " until %s has finished (they"
@@ -7464,7 +7499,7 @@ void md_do_sync(struct md_thread *thread)
        last_check = 0;
 
        if (j>2) {
-               printk(KERN_INFO 
+               printk(KERN_INFO
                       "md: resuming %s of %s from checkpoint.\n",
                       desc, mdname(mddev));
                mddev->curr_resync = j;
@@ -7501,7 +7536,8 @@ void md_do_sync(struct md_thread *thread)
                        sysfs_notify(&mddev->kobj, NULL, "sync_completed");
                }
 
-               while (j >= mddev->resync_max && !kthread_should_stop()) {
+               while (j >= mddev->resync_max &&
+                      !test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
                        /* As this condition is controlled by user-space,
                         * we can block indefinitely, so use '_interruptible'
                         * to avoid triggering warnings.
@@ -7509,17 +7545,18 @@ void md_do_sync(struct md_thread *thread)
                        flush_signals(current); /* just in case */
                        wait_event_interruptible(mddev->recovery_wait,
                                                 mddev->resync_max > j
-                                                || kthread_should_stop());
+                                                || test_bit(MD_RECOVERY_INTR,
+                                                            &mddev->recovery));
                }
 
-               if (kthread_should_stop())
-                       goto interrupted;
+               if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
+                       break;
 
                sectors = mddev->pers->sync_request(mddev, j, &skipped,
                                                  currspeed < speed_min(mddev));
                if (sectors == 0) {
                        set_bit(MD_RECOVERY_INTR, &mddev->recovery);
-                       goto out;
+                       break;
                }
 
                if (!skipped) { /* actual IO requested */
@@ -7556,10 +7593,8 @@ void md_do_sync(struct md_thread *thread)
                        last_mark = next;
                }
 
-
-               if (kthread_should_stop())
-                       goto interrupted;
-
+               if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
+                       break;
 
                /*
                 * this loop exits only if either when we are slower than
@@ -7582,11 +7617,12 @@ void md_do_sync(struct md_thread *thread)
                        }
                }
        }
-       printk(KERN_INFO "md: %s: %s done.\n",mdname(mddev), desc);
+       printk(KERN_INFO "md: %s: %s %s.\n",mdname(mddev), desc,
+              test_bit(MD_RECOVERY_INTR, &mddev->recovery)
+              ? "interrupted" : "done");
        /*
         * this also signals 'finished resyncing' to md_stop
         */
- out:
        blk_finish_plug(&plug);
        wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active));
 
@@ -7640,16 +7676,6 @@ void md_do_sync(struct md_thread *thread)
        set_bit(MD_RECOVERY_DONE, &mddev->recovery);
        md_wakeup_thread(mddev->thread);
        return;
-
- interrupted:
-       /*
-        * got a signal, exit.
-        */
-       printk(KERN_INFO
-              "md: md_do_sync() got signal ... exiting\n");
-       set_bit(MD_RECOVERY_INTR, &mddev->recovery);
-       goto out;
-
 }
 EXPORT_SYMBOL_GPL(md_do_sync);
 
@@ -7894,6 +7920,7 @@ void md_reap_sync_thread(struct mddev *mddev)
 
        /* resync has finished, collect result */
        md_unregister_thread(&mddev->sync_thread);
+       wake_up(&resync_wait);
        if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
            !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
                /* success...*/
index af6681b19776d2f695030452a9d6ab42821ed0df..1e5a540995e932852df5ff484a96bfcc8636a432 100644 (file)
@@ -66,7 +66,8 @@
  */
 static int max_queued_requests = 1024;
 
-static void allow_barrier(struct r1conf *conf);
+static void allow_barrier(struct r1conf *conf, sector_t start_next_window,
+                         sector_t bi_sector);
 static void lower_barrier(struct r1conf *conf);
 
 static void * r1bio_pool_alloc(gfp_t gfp_flags, void *data)
@@ -84,10 +85,12 @@ static void r1bio_pool_free(void *r1_bio, void *data)
 }
 
 #define RESYNC_BLOCK_SIZE (64*1024)
-//#define RESYNC_BLOCK_SIZE PAGE_SIZE
+#define RESYNC_DEPTH 32
 #define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
 #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
-#define RESYNC_WINDOW (2048*1024)
+#define RESYNC_WINDOW (RESYNC_BLOCK_SIZE * RESYNC_DEPTH)
+#define RESYNC_WINDOW_SECTORS (RESYNC_WINDOW >> 9)
+#define NEXT_NORMALIO_DISTANCE (3 * RESYNC_WINDOW_SECTORS)
 
 static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
 {
@@ -225,6 +228,8 @@ static void call_bio_endio(struct r1bio *r1_bio)
        struct bio *bio = r1_bio->master_bio;
        int done;
        struct r1conf *conf = r1_bio->mddev->private;
+       sector_t start_next_window = r1_bio->start_next_window;
+       sector_t bi_sector = bio->bi_sector;
 
        if (bio->bi_phys_segments) {
                unsigned long flags;
@@ -232,6 +237,11 @@ static void call_bio_endio(struct r1bio *r1_bio)
                bio->bi_phys_segments--;
                done = (bio->bi_phys_segments == 0);
                spin_unlock_irqrestore(&conf->device_lock, flags);
+               /*
+                * make_request() might be waiting for
+                * bi_phys_segments to decrease
+                */
+               wake_up(&conf->wait_barrier);
        } else
                done = 1;
 
@@ -243,7 +253,7 @@ static void call_bio_endio(struct r1bio *r1_bio)
                 * Wake up any possible resync thread that waits for the device
                 * to go idle.
                 */
-               allow_barrier(conf);
+               allow_barrier(conf, start_next_window, bi_sector);
        }
 }
 
@@ -814,8 +824,6 @@ static void flush_pending_writes(struct r1conf *conf)
  *    there is no normal IO happeing.  It must arrange to call
  *    lower_barrier when the particular background IO completes.
  */
-#define RESYNC_DEPTH 32
-
 static void raise_barrier(struct r1conf *conf)
 {
        spin_lock_irq(&conf->resync_lock);
@@ -827,9 +835,19 @@ static void raise_barrier(struct r1conf *conf)
        /* block any new IO from starting */
        conf->barrier++;
 
-       /* Now wait for all pending IO to complete */
+       /* For these conditions we must wait:
+        * A: while the array is in frozen state
+        * B: while barrier >= RESYNC_DEPTH, meaning resync reach
+        *    the max count which allowed.
+        * C: next_resync + RESYNC_SECTORS > start_next_window, meaning
+        *    next resync will reach to the window which normal bios are
+        *    handling.
+        */
        wait_event_lock_irq(conf->wait_barrier,
-                           !conf->nr_pending && conf->barrier < RESYNC_DEPTH,
+                           !conf->array_frozen &&
+                           conf->barrier < RESYNC_DEPTH &&
+                           (conf->start_next_window >=
+                            conf->next_resync + RESYNC_SECTORS),
                            conf->resync_lock);
 
        spin_unlock_irq(&conf->resync_lock);
@@ -845,10 +863,33 @@ static void lower_barrier(struct r1conf *conf)
        wake_up(&conf->wait_barrier);
 }
 
-static void wait_barrier(struct r1conf *conf)
+static bool need_to_wait_for_sync(struct r1conf *conf, struct bio *bio)
 {
+       bool wait = false;
+
+       if (conf->array_frozen || !bio)
+               wait = true;
+       else if (conf->barrier && bio_data_dir(bio) == WRITE) {
+               if (conf->next_resync < RESYNC_WINDOW_SECTORS)
+                       wait = true;
+               else if ((conf->next_resync - RESYNC_WINDOW_SECTORS
+                               >= bio_end_sector(bio)) ||
+                        (conf->next_resync + NEXT_NORMALIO_DISTANCE
+                               <= bio->bi_sector))
+                       wait = false;
+               else
+                       wait = true;
+       }
+
+       return wait;
+}
+
+static sector_t wait_barrier(struct r1conf *conf, struct bio *bio)
+{
+       sector_t sector = 0;
+
        spin_lock_irq(&conf->resync_lock);
-       if (conf->barrier) {
+       if (need_to_wait_for_sync(conf, bio)) {
                conf->nr_waiting++;
                /* Wait for the barrier to drop.
                 * However if there are already pending
@@ -860,22 +901,67 @@ static void wait_barrier(struct r1conf *conf)
                 * count down.
                 */
                wait_event_lock_irq(conf->wait_barrier,
-                                   !conf->barrier ||
-                                   (conf->nr_pending &&
+                                   !conf->array_frozen &&
+                                   (!conf->barrier ||
+                                   ((conf->start_next_window <
+                                     conf->next_resync + RESYNC_SECTORS) &&
                                     current->bio_list &&
-                                    !bio_list_empty(current->bio_list)),
+                                    !bio_list_empty(current->bio_list))),
                                    conf->resync_lock);
                conf->nr_waiting--;
        }
+
+       if (bio && bio_data_dir(bio) == WRITE) {
+               if (conf->next_resync + NEXT_NORMALIO_DISTANCE
+                   <= bio->bi_sector) {
+                       if (conf->start_next_window == MaxSector)
+                               conf->start_next_window =
+                                       conf->next_resync +
+                                       NEXT_NORMALIO_DISTANCE;
+
+                       if ((conf->start_next_window + NEXT_NORMALIO_DISTANCE)
+                           <= bio->bi_sector)
+                               conf->next_window_requests++;
+                       else
+                               conf->current_window_requests++;
+               }
+               if (bio->bi_sector >= conf->start_next_window)
+                       sector = conf->start_next_window;
+       }
+
        conf->nr_pending++;
        spin_unlock_irq(&conf->resync_lock);
+       return sector;
 }
 
-static void allow_barrier(struct r1conf *conf)
+static void allow_barrier(struct r1conf *conf, sector_t start_next_window,
+                         sector_t bi_sector)
 {
        unsigned long flags;
+
        spin_lock_irqsave(&conf->resync_lock, flags);
        conf->nr_pending--;
+       if (start_next_window) {
+               if (start_next_window == conf->start_next_window) {
+                       if (conf->start_next_window + NEXT_NORMALIO_DISTANCE
+                           <= bi_sector)
+                               conf->next_window_requests--;
+                       else
+                               conf->current_window_requests--;
+               } else
+                       conf->current_window_requests--;
+
+               if (!conf->current_window_requests) {
+                       if (conf->next_window_requests) {
+                               conf->current_window_requests =
+                                       conf->next_window_requests;
+                               conf->next_window_requests = 0;
+                               conf->start_next_window +=
+                                       NEXT_NORMALIO_DISTANCE;
+                       } else
+                               conf->start_next_window = MaxSector;
+               }
+       }
        spin_unlock_irqrestore(&conf->resync_lock, flags);
        wake_up(&conf->wait_barrier);
 }
@@ -884,8 +970,7 @@ static void freeze_array(struct r1conf *conf, int extra)
 {
        /* stop syncio and normal IO and wait for everything to
         * go quite.
-        * We increment barrier and nr_waiting, and then
-        * wait until nr_pending match nr_queued+extra
+        * We wait until nr_pending match nr_queued+extra
         * This is called in the context of one normal IO request
         * that has failed. Thus any sync request that might be pending
         * will be blocked by nr_pending, and we need to wait for
@@ -895,8 +980,7 @@ static void freeze_array(struct r1conf *conf, int extra)
         * we continue.
         */
        spin_lock_irq(&conf->resync_lock);
-       conf->barrier++;
-       conf->nr_waiting++;
+       conf->array_frozen = 1;
        wait_event_lock_irq_cmd(conf->wait_barrier,
                                conf->nr_pending == conf->nr_queued+extra,
                                conf->resync_lock,
@@ -907,8 +991,7 @@ static void unfreeze_array(struct r1conf *conf)
 {
        /* reverse the effect of the freeze */
        spin_lock_irq(&conf->resync_lock);
-       conf->barrier--;
-       conf->nr_waiting--;
+       conf->array_frozen = 0;
        wake_up(&conf->wait_barrier);
        spin_unlock_irq(&conf->resync_lock);
 }
@@ -1013,6 +1096,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
        int first_clone;
        int sectors_handled;
        int max_sectors;
+       sector_t start_next_window;
 
        /*
         * Register the new request and wait if the reconstruction
@@ -1042,7 +1126,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
                finish_wait(&conf->wait_barrier, &w);
        }
 
-       wait_barrier(conf);
+       start_next_window = wait_barrier(conf, bio);
 
        bitmap = mddev->bitmap;
 
@@ -1163,6 +1247,7 @@ read_again:
 
        disks = conf->raid_disks * 2;
  retry_write:
+       r1_bio->start_next_window = start_next_window;
        blocked_rdev = NULL;
        rcu_read_lock();
        max_sectors = r1_bio->sectors;
@@ -1231,14 +1316,24 @@ read_again:
        if (unlikely(blocked_rdev)) {
                /* Wait for this device to become unblocked */
                int j;
+               sector_t old = start_next_window;
 
                for (j = 0; j < i; j++)
                        if (r1_bio->bios[j])
                                rdev_dec_pending(conf->mirrors[j].rdev, mddev);
                r1_bio->state = 0;
-               allow_barrier(conf);
+               allow_barrier(conf, start_next_window, bio->bi_sector);
                md_wait_for_blocked_rdev(blocked_rdev, mddev);
-               wait_barrier(conf);
+               start_next_window = wait_barrier(conf, bio);
+               /*
+                * We must make sure the multi r1bios of bio have
+                * the same value of bi_phys_segments
+                */
+               if (bio->bi_phys_segments && old &&
+                   old != start_next_window)
+                       /* Wait for the former r1bio(s) to complete */
+                       wait_event(conf->wait_barrier,
+                                  bio->bi_phys_segments == 1);
                goto retry_write;
        }
 
@@ -1438,11 +1533,14 @@ static void print_conf(struct r1conf *conf)
 
 static void close_sync(struct r1conf *conf)
 {
-       wait_barrier(conf);
-       allow_barrier(conf);
+       wait_barrier(conf, NULL);
+       allow_barrier(conf, 0, 0);
 
        mempool_destroy(conf->r1buf_pool);
        conf->r1buf_pool = NULL;
+
+       conf->next_resync = 0;
+       conf->start_next_window = MaxSector;
 }
 
 static int raid1_spare_active(struct mddev *mddev)
@@ -2714,6 +2812,9 @@ static struct r1conf *setup_conf(struct mddev *mddev)
        conf->pending_count = 0;
        conf->recovery_disabled = mddev->recovery_disabled - 1;
 
+       conf->start_next_window = MaxSector;
+       conf->current_window_requests = conf->next_window_requests = 0;
+
        err = -EIO;
        for (i = 0; i < conf->raid_disks * 2; i++) {
 
@@ -2871,8 +2972,8 @@ static int stop(struct mddev *mddev)
                           atomic_read(&bitmap->behind_writes) == 0);
        }
 
-       raise_barrier(conf);
-       lower_barrier(conf);
+       freeze_array(conf, 0);
+       unfreeze_array(conf);
 
        md_unregister_thread(&mddev->thread);
        if (conf->r1bio_pool)
@@ -3031,10 +3132,10 @@ static void raid1_quiesce(struct mddev *mddev, int state)
                wake_up(&conf->wait_barrier);
                break;
        case 1:
-               raise_barrier(conf);
+               freeze_array(conf, 0);
                break;
        case 0:
-               lower_barrier(conf);
+               unfreeze_array(conf);
                break;
        }
 }
@@ -3051,7 +3152,8 @@ static void *raid1_takeover(struct mddev *mddev)
                mddev->new_chunk_sectors = 0;
                conf = setup_conf(mddev);
                if (!IS_ERR(conf))
-                       conf->barrier = 1;
+                       /* Array must appear to be quiesced */
+                       conf->array_frozen = 1;
                return conf;
        }
        return ERR_PTR(-EINVAL);
index 0ff3715fb7eba5ec4fed61a9922276b07b363aff..9bebca7bff2fbc4ec4780031190e6666f7abf56d 100644 (file)
@@ -41,6 +41,19 @@ struct r1conf {
         */
        sector_t                next_resync;
 
+       /* When raid1 starts resync, we divide array into four partitions
+        * |---------|--------------|---------------------|-------------|
+        *        next_resync   start_next_window       end_window
+        * start_next_window = next_resync + NEXT_NORMALIO_DISTANCE
+        * end_window = start_next_window + NEXT_NORMALIO_DISTANCE
+        * current_window_requests means the count of normalIO between
+        *   start_next_window and end_window.
+        * next_window_requests means the count of normalIO after end_window.
+        * */
+       sector_t                start_next_window;
+       int                     current_window_requests;
+       int                     next_window_requests;
+
        spinlock_t              device_lock;
 
        /* list of 'struct r1bio' that need to be processed by raid1d,
@@ -65,6 +78,7 @@ struct r1conf {
        int                     nr_waiting;
        int                     nr_queued;
        int                     barrier;
+       int                     array_frozen;
 
        /* Set to 1 if a full sync is needed, (fresh device added).
         * Cleared when a sync completes.
@@ -111,6 +125,7 @@ struct r1bio {
                                                 * in this BehindIO request
                                                 */
        sector_t                sector;
+       sector_t                start_next_window;
        int                     sectors;
        unsigned long           state;
        struct mddev            *mddev;
index 7c3508abb5e178fe310cae9d2c98352efb34f2af..c504e8389e69e3ab9ad717b9f83d0c19c2008d68 100644 (file)
@@ -4384,7 +4384,11 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr,
                set_bit(MD_CHANGE_DEVS, &mddev->flags);
                md_wakeup_thread(mddev->thread);
                wait_event(mddev->sb_wait, mddev->flags == 0 ||
-                          kthread_should_stop());
+                          test_bit(MD_RECOVERY_INTR, &mddev->recovery));
+               if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
+                       allow_barrier(conf);
+                       return sectors_done;
+               }
                conf->reshape_safe = mddev->reshape_position;
                allow_barrier(conf);
        }
index 7f0e17a27aebcd3b448dca34290ab1c735c89eb1..47da0af6322be1bd7930f902c96c57875799a358 100644 (file)
@@ -85,6 +85,42 @@ static inline struct hlist_head *stripe_hash(struct r5conf *conf, sector_t sect)
        return &conf->stripe_hashtbl[hash];
 }
 
+static inline int stripe_hash_locks_hash(sector_t sect)
+{
+       return (sect >> STRIPE_SHIFT) & STRIPE_HASH_LOCKS_MASK;
+}
+
+static inline void lock_device_hash_lock(struct r5conf *conf, int hash)
+{
+       spin_lock_irq(conf->hash_locks + hash);
+       spin_lock(&conf->device_lock);
+}
+
+static inline void unlock_device_hash_lock(struct r5conf *conf, int hash)
+{
+       spin_unlock(&conf->device_lock);
+       spin_unlock_irq(conf->hash_locks + hash);
+}
+
+static inline void lock_all_device_hash_locks_irq(struct r5conf *conf)
+{
+       int i;
+       local_irq_disable();
+       spin_lock(conf->hash_locks);
+       for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++)
+               spin_lock_nest_lock(conf->hash_locks + i, conf->hash_locks);
+       spin_lock(&conf->device_lock);
+}
+
+static inline void unlock_all_device_hash_locks_irq(struct r5conf *conf)
+{
+       int i;
+       spin_unlock(&conf->device_lock);
+       for (i = NR_STRIPE_HASH_LOCKS; i; i--)
+               spin_unlock(conf->hash_locks + i - 1);
+       local_irq_enable();
+}
+
 /* bio's attached to a stripe+device for I/O are linked together in bi_sector
  * order without overlap.  There may be several bio's per stripe+device, and
  * a bio could span several devices.
@@ -249,7 +285,8 @@ static void raid5_wakeup_stripe_thread(struct stripe_head *sh)
        }
 }
 
-static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh)
+static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh,
+                             struct list_head *temp_inactive_list)
 {
        BUG_ON(!list_empty(&sh->lru));
        BUG_ON(atomic_read(&conf->active_stripes)==0);
@@ -278,23 +315,68 @@ static void do_release_stripe(struct r5conf *conf, struct stripe_head *sh)
                            < IO_THRESHOLD)
                                md_wakeup_thread(conf->mddev->thread);
                atomic_dec(&conf->active_stripes);
-               if (!test_bit(STRIPE_EXPANDING, &sh->state)) {
-                       list_add_tail(&sh->lru, &conf->inactive_list);
-                       wake_up(&conf->wait_for_stripe);
-                       if (conf->retry_read_aligned)
-                               md_wakeup_thread(conf->mddev->thread);
-               }
+               if (!test_bit(STRIPE_EXPANDING, &sh->state))
+                       list_add_tail(&sh->lru, temp_inactive_list);
        }
 }
 
-static void __release_stripe(struct r5conf *conf, struct stripe_head *sh)
+static void __release_stripe(struct r5conf *conf, struct stripe_head *sh,
+                            struct list_head *temp_inactive_list)
 {
        if (atomic_dec_and_test(&sh->count))
-               do_release_stripe(conf, sh);
+               do_release_stripe(conf, sh, temp_inactive_list);
+}
+
+/*
+ * @hash could be NR_STRIPE_HASH_LOCKS, then we have a list of inactive_list
+ *
+ * Be careful: Only one task can add/delete stripes from temp_inactive_list at
+ * given time. Adding stripes only takes device lock, while deleting stripes
+ * only takes hash lock.
+ */
+static void release_inactive_stripe_list(struct r5conf *conf,
+                                        struct list_head *temp_inactive_list,
+                                        int hash)
+{
+       int size;
+       bool do_wakeup = false;
+       unsigned long flags;
+
+       if (hash == NR_STRIPE_HASH_LOCKS) {
+               size = NR_STRIPE_HASH_LOCKS;
+               hash = NR_STRIPE_HASH_LOCKS - 1;
+       } else
+               size = 1;
+       while (size) {
+               struct list_head *list = &temp_inactive_list[size - 1];
+
+               /*
+                * We don't hold any lock here yet, get_active_stripe() might
+                * remove stripes from the list
+                */
+               if (!list_empty_careful(list)) {
+                       spin_lock_irqsave(conf->hash_locks + hash, flags);
+                       if (list_empty(conf->inactive_list + hash) &&
+                           !list_empty(list))
+                               atomic_dec(&conf->empty_inactive_list_nr);
+                       list_splice_tail_init(list, conf->inactive_list + hash);
+                       do_wakeup = true;
+                       spin_unlock_irqrestore(conf->hash_locks + hash, flags);
+               }
+               size--;
+               hash--;
+       }
+
+       if (do_wakeup) {
+               wake_up(&conf->wait_for_stripe);
+               if (conf->retry_read_aligned)
+                       md_wakeup_thread(conf->mddev->thread);
+       }
 }
 
 /* should hold conf->device_lock already */
-static int release_stripe_list(struct r5conf *conf)
+static int release_stripe_list(struct r5conf *conf,
+                              struct list_head *temp_inactive_list)
 {
        struct stripe_head *sh;
        int count = 0;
@@ -303,6 +385,8 @@ static int release_stripe_list(struct r5conf *conf)
        head = llist_del_all(&conf->released_stripes);
        head = llist_reverse_order(head);
        while (head) {
+               int hash;
+
                sh = llist_entry(head, struct stripe_head, release_list);
                head = llist_next(head);
                /* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */
@@ -313,7 +397,8 @@ static int release_stripe_list(struct r5conf *conf)
                 * again, the count is always > 1. This is true for
                 * STRIPE_ON_UNPLUG_LIST bit too.
                 */
-               __release_stripe(conf, sh);
+               hash = sh->hash_lock_index;
+               __release_stripe(conf, sh, &temp_inactive_list[hash]);
                count++;
        }
 
@@ -324,9 +409,12 @@ static void release_stripe(struct stripe_head *sh)
 {
        struct r5conf *conf = sh->raid_conf;
        unsigned long flags;
+       struct list_head list;
+       int hash;
        bool wakeup;
 
-       if (test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state))
+       if (unlikely(!conf->mddev->thread) ||
+               test_and_set_bit(STRIPE_ON_RELEASE_LIST, &sh->state))
                goto slow_path;
        wakeup = llist_add(&sh->release_list, &conf->released_stripes);
        if (wakeup)
@@ -336,8 +424,11 @@ slow_path:
        local_irq_save(flags);
        /* we are ok here if STRIPE_ON_RELEASE_LIST is set or not */
        if (atomic_dec_and_lock(&sh->count, &conf->device_lock)) {
-               do_release_stripe(conf, sh);
+               INIT_LIST_HEAD(&list);
+               hash = sh->hash_lock_index;
+               do_release_stripe(conf, sh, &list);
                spin_unlock(&conf->device_lock);
+               release_inactive_stripe_list(conf, &list, hash);
        }
        local_irq_restore(flags);
 }
@@ -362,18 +453,21 @@ static inline void insert_hash(struct r5conf *conf, struct stripe_head *sh)
 
 
 /* find an idle stripe, make sure it is unhashed, and return it. */
-static struct stripe_head *get_free_stripe(struct r5conf *conf)
+static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
 {
        struct stripe_head *sh = NULL;
        struct list_head *first;
 
-       if (list_empty(&conf->inactive_list))
+       if (list_empty(conf->inactive_list + hash))
                goto out;
-       first = conf->inactive_list.next;
+       first = (conf->inactive_list + hash)->next;
        sh = list_entry(first, struct stripe_head, lru);
        list_del_init(first);
        remove_hash(sh);
        atomic_inc(&conf->active_stripes);
+       BUG_ON(hash != sh->hash_lock_index);
+       if (list_empty(conf->inactive_list + hash))
+               atomic_inc(&conf->empty_inactive_list_nr);
 out:
        return sh;
 }
@@ -416,7 +510,7 @@ static void stripe_set_idx(sector_t stripe, struct r5conf *conf, int previous,
 static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
 {
        struct r5conf *conf = sh->raid_conf;
-       int i;
+       int i, seq;
 
        BUG_ON(atomic_read(&sh->count) != 0);
        BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
@@ -426,7 +520,8 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
                (unsigned long long)sh->sector);
 
        remove_hash(sh);
-
+retry:
+       seq = read_seqcount_begin(&conf->gen_lock);
        sh->generation = conf->generation - previous;
        sh->disks = previous ? conf->previous_raid_disks : conf->raid_disks;
        sh->sector = sector;
@@ -448,6 +543,8 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int previous)
                dev->flags = 0;
                raid5_build_block(sh, i, previous);
        }
+       if (read_seqcount_retry(&conf->gen_lock, seq))
+               goto retry;
        insert_hash(conf, sh);
        sh->cpu = smp_processor_id();
 }
@@ -552,29 +649,31 @@ get_active_stripe(struct r5conf *conf, sector_t sector,
                  int previous, int noblock, int noquiesce)
 {
        struct stripe_head *sh;
+       int hash = stripe_hash_locks_hash(sector);
 
        pr_debug("get_stripe, sector %llu\n", (unsigned long long)sector);
 
-       spin_lock_irq(&conf->device_lock);
+       spin_lock_irq(conf->hash_locks + hash);
 
        do {
                wait_event_lock_irq(conf->wait_for_stripe,
                                    conf->quiesce == 0 || noquiesce,
-                                   conf->device_lock);
+                                   *(conf->hash_locks + hash));
                sh = __find_stripe(conf, sector, conf->generation - previous);
                if (!sh) {
                        if (!conf->inactive_blocked)
-                               sh = get_free_stripe(conf);
+                               sh = get_free_stripe(conf, hash);
                        if (noblock && sh == NULL)
                                break;
                        if (!sh) {
                                conf->inactive_blocked = 1;
-                               wait_event_lock_irq(conf->wait_for_stripe,
-                                                   !list_empty(&conf->inactive_list) &&
-                                                   (atomic_read(&conf->active_stripes)
-                                                    < (conf->max_nr_stripes *3/4)
-                                                    || !conf->inactive_blocked),
-                                                   conf->device_lock);
+                               wait_event_lock_irq(
+                                       conf->wait_for_stripe,
+                                       !list_empty(conf->inactive_list + hash) &&
+                                       (atomic_read(&conf->active_stripes)
+                                        < (conf->max_nr_stripes * 3 / 4)
+                                        || !conf->inactive_blocked),
+                                       *(conf->hash_locks + hash));
                                conf->inactive_blocked = 0;
                        } else
                                init_stripe(sh, sector, previous);
@@ -585,9 +684,11 @@ get_active_stripe(struct r5conf *conf, sector_t sector,
                                    && !test_bit(STRIPE_ON_UNPLUG_LIST, &sh->state)
                                    && !test_bit(STRIPE_ON_RELEASE_LIST, &sh->state));
                        } else {
+                               spin_lock(&conf->device_lock);
                                if (!test_bit(STRIPE_HANDLE, &sh->state))
                                        atomic_inc(&conf->active_stripes);
                                if (list_empty(&sh->lru) &&
+                                   !test_bit(STRIPE_ON_RELEASE_LIST, &sh->state) &&
                                    !test_bit(STRIPE_EXPANDING, &sh->state))
                                        BUG();
                                list_del_init(&sh->lru);
@@ -595,6 +696,7 @@ get_active_stripe(struct r5conf *conf, sector_t sector,
                                        sh->group->stripes_cnt--;
                                        sh->group = NULL;
                                }
+                               spin_unlock(&conf->device_lock);
                        }
                }
        } while (sh == NULL);
@@ -602,7 +704,7 @@ get_active_stripe(struct r5conf *conf, sector_t sector,
        if (sh)
                atomic_inc(&sh->count);
 
-       spin_unlock_irq(&conf->device_lock);
+       spin_unlock_irq(conf->hash_locks + hash);
        return sh;
 }
 
@@ -758,7 +860,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
                                bi->bi_sector = (sh->sector
                                                 + rdev->data_offset);
                        if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
-                               bi->bi_rw |= REQ_FLUSH;
+                               bi->bi_rw |= REQ_NOMERGE;
 
                        bi->bi_vcnt = 1;
                        bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
@@ -1582,7 +1684,7 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
        put_cpu();
 }
 
-static int grow_one_stripe(struct r5conf *conf)
+static int grow_one_stripe(struct r5conf *conf, int hash)
 {
        struct stripe_head *sh;
        sh = kmem_cache_zalloc(conf->slab_cache, GFP_KERNEL);
@@ -1598,6 +1700,7 @@ static int grow_one_stripe(struct r5conf *conf)
                kmem_cache_free(conf->slab_cache, sh);
                return 0;
        }
+       sh->hash_lock_index = hash;
        /* we just created an active stripe so... */
        atomic_set(&sh->count, 1);
        atomic_inc(&conf->active_stripes);
@@ -1610,6 +1713,7 @@ static int grow_stripes(struct r5conf *conf, int num)
 {
        struct kmem_cache *sc;
        int devs = max(conf->raid_disks, conf->previous_raid_disks);
+       int hash;
 
        if (conf->mddev->gendisk)
                sprintf(conf->cache_name[0],
@@ -1627,9 +1731,13 @@ static int grow_stripes(struct r5conf *conf, int num)
                return 1;
        conf->slab_cache = sc;
        conf->pool_size = devs;
-       while (num--)
-               if (!grow_one_stripe(conf))
+       hash = conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS;
+       while (num--) {
+               if (!grow_one_stripe(conf, hash))
                        return 1;
+               conf->max_nr_stripes++;
+               hash = (hash + 1) % NR_STRIPE_HASH_LOCKS;
+       }
        return 0;
 }
 
@@ -1687,6 +1795,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
        int err;
        struct kmem_cache *sc;
        int i;
+       int hash, cnt;
 
        if (newsize <= conf->pool_size)
                return 0; /* never bother to shrink */
@@ -1726,19 +1835,29 @@ static int resize_stripes(struct r5conf *conf, int newsize)
         * OK, we have enough stripes, start collecting inactive
         * stripes and copying them over
         */
+       hash = 0;
+       cnt = 0;
        list_for_each_entry(nsh, &newstripes, lru) {
-               spin_lock_irq(&conf->device_lock);
-               wait_event_lock_irq(conf->wait_for_stripe,
-                                   !list_empty(&conf->inactive_list),
-                                   conf->device_lock);
-               osh = get_free_stripe(conf);
-               spin_unlock_irq(&conf->device_lock);
+               lock_device_hash_lock(conf, hash);
+               wait_event_cmd(conf->wait_for_stripe,
+                                   !list_empty(conf->inactive_list + hash),
+                                   unlock_device_hash_lock(conf, hash),
+                                   lock_device_hash_lock(conf, hash));
+               osh = get_free_stripe(conf, hash);
+               unlock_device_hash_lock(conf, hash);
                atomic_set(&nsh->count, 1);
                for(i=0; i<conf->pool_size; i++)
                        nsh->dev[i].page = osh->dev[i].page;
                for( ; i<newsize; i++)
                        nsh->dev[i].page = NULL;
+               nsh->hash_lock_index = hash;
                kmem_cache_free(conf->slab_cache, osh);
+               cnt++;
+               if (cnt >= conf->max_nr_stripes / NR_STRIPE_HASH_LOCKS +
+                   !!((conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS) > hash)) {
+                       hash++;
+                       cnt = 0;
+               }
        }
        kmem_cache_destroy(conf->slab_cache);
 
@@ -1797,13 +1916,13 @@ static int resize_stripes(struct r5conf *conf, int newsize)
        return err;
 }
 
-static int drop_one_stripe(struct r5conf *conf)
+static int drop_one_stripe(struct r5conf *conf, int hash)
 {
        struct stripe_head *sh;
 
-       spin_lock_irq(&conf->device_lock);
-       sh = get_free_stripe(conf);
-       spin_unlock_irq(&conf->device_lock);
+       spin_lock_irq(conf->hash_locks + hash);
+       sh = get_free_stripe(conf, hash);
+       spin_unlock_irq(conf->hash_locks + hash);
        if (!sh)
                return 0;
        BUG_ON(atomic_read(&sh->count));
@@ -1815,8 +1934,10 @@ static int drop_one_stripe(struct r5conf *conf)
 
 static void shrink_stripes(struct r5conf *conf)
 {
-       while (drop_one_stripe(conf))
-               ;
+       int hash;
+       for (hash = 0; hash < NR_STRIPE_HASH_LOCKS; hash++)
+               while (drop_one_stripe(conf, hash))
+                       ;
 
        if (conf->slab_cache)
                kmem_cache_destroy(conf->slab_cache);
@@ -1921,6 +2042,9 @@ static void raid5_end_read_request(struct bio * bi, int error)
                               mdname(conf->mddev), bdn);
                else
                        retry = 1;
+               if (set_bad && test_bit(In_sync, &rdev->flags)
+                   && !test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
+                       retry = 1;
                if (retry)
                        if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) {
                                set_bit(R5_ReadError, &sh->dev[i].flags);
@@ -3900,7 +4024,8 @@ static void raid5_activate_delayed(struct r5conf *conf)
        }
 }
 
-static void activate_bit_delay(struct r5conf *conf)
+static void activate_bit_delay(struct r5conf *conf,
+       struct list_head *temp_inactive_list)
 {
        /* device_lock is held */
        struct list_head head;
@@ -3908,9 +4033,11 @@ static void activate_bit_delay(struct r5conf *conf)
        list_del_init(&conf->bitmap_list);
        while (!list_empty(&head)) {
                struct stripe_head *sh = list_entry(head.next, struct stripe_head, lru);
+               int hash;
                list_del_init(&sh->lru);
                atomic_inc(&sh->count);
-               __release_stripe(conf, sh);
+               hash = sh->hash_lock_index;
+               __release_stripe(conf, sh, &temp_inactive_list[hash]);
        }
 }
 
@@ -3926,7 +4053,7 @@ int md_raid5_congested(struct mddev *mddev, int bits)
                return 1;
        if (conf->quiesce)
                return 1;
-       if (list_empty_careful(&conf->inactive_list))
+       if (atomic_read(&conf->empty_inactive_list_nr))
                return 1;
 
        return 0;
@@ -4256,6 +4383,7 @@ static struct stripe_head *__get_priority_stripe(struct r5conf *conf, int group)
 struct raid5_plug_cb {
        struct blk_plug_cb      cb;
        struct list_head        list;
+       struct list_head        temp_inactive_list[NR_STRIPE_HASH_LOCKS];
 };
 
 static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule)
@@ -4266,6 +4394,7 @@ static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule)
        struct mddev *mddev = cb->cb.data;
        struct r5conf *conf = mddev->private;
        int cnt = 0;
+       int hash;
 
        if (cb->list.next && !list_empty(&cb->list)) {
                spin_lock_irq(&conf->device_lock);
@@ -4283,11 +4412,14 @@ static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule)
                         * STRIPE_ON_RELEASE_LIST could be set here. In that
                         * case, the count is always > 1 here
                         */
-                       __release_stripe(conf, sh);
+                       hash = sh->hash_lock_index;
+                       __release_stripe(conf, sh, &cb->temp_inactive_list[hash]);
                        cnt++;
                }
                spin_unlock_irq(&conf->device_lock);
        }
+       release_inactive_stripe_list(conf, cb->temp_inactive_list,
+                                    NR_STRIPE_HASH_LOCKS);
        if (mddev->queue)
                trace_block_unplug(mddev->queue, cnt, !from_schedule);
        kfree(cb);
@@ -4308,8 +4440,12 @@ static void release_stripe_plug(struct mddev *mddev,
 
        cb = container_of(blk_cb, struct raid5_plug_cb, cb);
 
-       if (cb->list.next == NULL)
+       if (cb->list.next == NULL) {
+               int i;
                INIT_LIST_HEAD(&cb->list);
+               for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
+                       INIT_LIST_HEAD(cb->temp_inactive_list + i);
+       }
 
        if (!test_and_set_bit(STRIPE_ON_UNPLUG_LIST, &sh->state))
                list_add_tail(&sh->lru, &cb->list);
@@ -4692,14 +4828,19 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
            time_after(jiffies, conf->reshape_checkpoint + 10*HZ)) {
                /* Cannot proceed until we've updated the superblock... */
                wait_event(conf->wait_for_overlap,
-                          atomic_read(&conf->reshape_stripes)==0);
+                          atomic_read(&conf->reshape_stripes)==0
+                          || test_bit(MD_RECOVERY_INTR, &mddev->recovery));
+               if (atomic_read(&conf->reshape_stripes) != 0)
+                       return 0;
                mddev->reshape_position = conf->reshape_progress;
                mddev->curr_resync_completed = sector_nr;
                conf->reshape_checkpoint = jiffies;
                set_bit(MD_CHANGE_DEVS, &mddev->flags);
                md_wakeup_thread(mddev->thread);
                wait_event(mddev->sb_wait, mddev->flags == 0 ||
-                          kthread_should_stop());
+                          test_bit(MD_RECOVERY_INTR, &mddev->recovery));
+               if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
+                       return 0;
                spin_lock_irq(&conf->device_lock);
                conf->reshape_safe = mddev->reshape_position;
                spin_unlock_irq(&conf->device_lock);
@@ -4782,7 +4923,10 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
            >= mddev->resync_max - mddev->curr_resync_completed) {
                /* Cannot proceed until we've updated the superblock... */
                wait_event(conf->wait_for_overlap,
-                          atomic_read(&conf->reshape_stripes) == 0);
+                          atomic_read(&conf->reshape_stripes) == 0
+                          || test_bit(MD_RECOVERY_INTR, &mddev->recovery));
+               if (atomic_read(&conf->reshape_stripes) != 0)
+                       goto ret;
                mddev->reshape_position = conf->reshape_progress;
                mddev->curr_resync_completed = sector_nr;
                conf->reshape_checkpoint = jiffies;
@@ -4790,13 +4934,16 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, int *sk
                md_wakeup_thread(mddev->thread);
                wait_event(mddev->sb_wait,
                           !test_bit(MD_CHANGE_DEVS, &mddev->flags)
-                          || kthread_should_stop());
+                          || test_bit(MD_RECOVERY_INTR, &mddev->recovery));
+               if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
+                       goto ret;
                spin_lock_irq(&conf->device_lock);
                conf->reshape_safe = mddev->reshape_position;
                spin_unlock_irq(&conf->device_lock);
                wake_up(&conf->wait_for_overlap);
                sysfs_notify(&mddev->kobj, NULL, "sync_completed");
        }
+ret:
        return reshape_sectors;
 }
 
@@ -4954,27 +5101,45 @@ static int  retry_aligned_read(struct r5conf *conf, struct bio *raid_bio)
 }
 
 static int handle_active_stripes(struct r5conf *conf, int group,
-                                struct r5worker *worker)
+                                struct r5worker *worker,
+                                struct list_head *temp_inactive_list)
 {
        struct stripe_head *batch[MAX_STRIPE_BATCH], *sh;
-       int i, batch_size = 0;
+       int i, batch_size = 0, hash;
+       bool release_inactive = false;
 
        while (batch_size < MAX_STRIPE_BATCH &&
                        (sh = __get_priority_stripe(conf, group)) != NULL)
                batch[batch_size++] = sh;
 
-       if (batch_size == 0)
-               return batch_size;
+       if (batch_size == 0) {
+               for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
+                       if (!list_empty(temp_inactive_list + i))
+                               break;
+               if (i == NR_STRIPE_HASH_LOCKS)
+                       return batch_size;
+               release_inactive = true;
+       }
        spin_unlock_irq(&conf->device_lock);
 
+       release_inactive_stripe_list(conf, temp_inactive_list,
+                                    NR_STRIPE_HASH_LOCKS);
+
+       if (release_inactive) {
+               spin_lock_irq(&conf->device_lock);
+               return 0;
+       }
+
        for (i = 0; i < batch_size; i++)
                handle_stripe(batch[i]);
 
        cond_resched();
 
        spin_lock_irq(&conf->device_lock);
-       for (i = 0; i < batch_size; i++)
-               __release_stripe(conf, batch[i]);
+       for (i = 0; i < batch_size; i++) {
+               hash = batch[i]->hash_lock_index;
+               __release_stripe(conf, batch[i], &temp_inactive_list[hash]);
+       }
        return batch_size;
 }
 
@@ -4995,9 +5160,10 @@ static void raid5_do_work(struct work_struct *work)
        while (1) {
                int batch_size, released;
 
-               released = release_stripe_list(conf);
+               released = release_stripe_list(conf, worker->temp_inactive_list);
 
-               batch_size = handle_active_stripes(conf, group_id, worker);
+               batch_size = handle_active_stripes(conf, group_id, worker,
+                                                  worker->temp_inactive_list);
                worker->working = false;
                if (!batch_size && !released)
                        break;
@@ -5036,7 +5202,7 @@ static void raid5d(struct md_thread *thread)
                struct bio *bio;
                int batch_size, released;
 
-               released = release_stripe_list(conf);
+               released = release_stripe_list(conf, conf->temp_inactive_list);
 
                if (
                    !list_empty(&conf->bitmap_list)) {
@@ -5046,7 +5212,7 @@ static void raid5d(struct md_thread *thread)
                        bitmap_unplug(mddev->bitmap);
                        spin_lock_irq(&conf->device_lock);
                        conf->seq_write = conf->seq_flush;
-                       activate_bit_delay(conf);
+                       activate_bit_delay(conf, conf->temp_inactive_list);
                }
                raid5_activate_delayed(conf);
 
@@ -5060,7 +5226,8 @@ static void raid5d(struct md_thread *thread)
                        handled++;
                }
 
-               batch_size = handle_active_stripes(conf, ANY_GROUP, NULL);
+               batch_size = handle_active_stripes(conf, ANY_GROUP, NULL,
+                                                  conf->temp_inactive_list);
                if (!batch_size && !released)
                        break;
                handled += batch_size;
@@ -5096,22 +5263,29 @@ raid5_set_cache_size(struct mddev *mddev, int size)
 {
        struct r5conf *conf = mddev->private;
        int err;
+       int hash;
 
        if (size <= 16 || size > 32768)
                return -EINVAL;
+       hash = (conf->max_nr_stripes - 1) % NR_STRIPE_HASH_LOCKS;
        while (size < conf->max_nr_stripes) {
-               if (drop_one_stripe(conf))
+               if (drop_one_stripe(conf, hash))
                        conf->max_nr_stripes--;
                else
                        break;
+               hash--;
+               if (hash < 0)
+                       hash = NR_STRIPE_HASH_LOCKS - 1;
        }
        err = md_allow_write(mddev);
        if (err)
                return err;
+       hash = conf->max_nr_stripes % NR_STRIPE_HASH_LOCKS;
        while (size > conf->max_nr_stripes) {
-               if (grow_one_stripe(conf))
+               if (grow_one_stripe(conf, hash))
                        conf->max_nr_stripes++;
                else break;
+               hash = (hash + 1) % NR_STRIPE_HASH_LOCKS;
        }
        return 0;
 }
@@ -5199,15 +5373,18 @@ raid5_show_group_thread_cnt(struct mddev *mddev, char *page)
                return 0;
 }
 
-static int alloc_thread_groups(struct r5conf *conf, int cnt);
+static int alloc_thread_groups(struct r5conf *conf, int cnt,
+                              int *group_cnt,
+                              int *worker_cnt_per_group,
+                              struct r5worker_group **worker_groups);
 static ssize_t
 raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len)
 {
        struct r5conf *conf = mddev->private;
        unsigned long new;
        int err;
-       struct r5worker_group *old_groups;
-       int old_group_cnt;
+       struct r5worker_group *new_groups, *old_groups;
+       int group_cnt, worker_cnt_per_group;
 
        if (len >= PAGE_SIZE)
                return -EINVAL;
@@ -5223,14 +5400,19 @@ raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len)
        mddev_suspend(mddev);
 
        old_groups = conf->worker_groups;
-       old_group_cnt = conf->worker_cnt_per_group;
+       if (old_groups)
+               flush_workqueue(raid5_wq);
+
+       err = alloc_thread_groups(conf, new,
+                                 &group_cnt, &worker_cnt_per_group,
+                                 &new_groups);
+       if (!err) {
+               spin_lock_irq(&conf->device_lock);
+               conf->group_cnt = group_cnt;
+               conf->worker_cnt_per_group = worker_cnt_per_group;
+               conf->worker_groups = new_groups;
+               spin_unlock_irq(&conf->device_lock);
 
-       conf->worker_groups = NULL;
-       err = alloc_thread_groups(conf, new);
-       if (err) {
-               conf->worker_groups = old_groups;
-               conf->worker_cnt_per_group = old_group_cnt;
-       } else {
                if (old_groups)
                        kfree(old_groups[0].workers);
                kfree(old_groups);
@@ -5260,40 +5442,47 @@ static struct attribute_group raid5_attrs_group = {
        .attrs = raid5_attrs,
 };
 
-static int alloc_thread_groups(struct r5conf *conf, int cnt)
+static int alloc_thread_groups(struct r5conf *conf, int cnt,
+                              int *group_cnt,
+                              int *worker_cnt_per_group,
+                              struct r5worker_group **worker_groups)
 {
-       int i, j;
+       int i, j, k;
        ssize_t size;
        struct r5worker *workers;
 
-       conf->worker_cnt_per_group = cnt;
+       *worker_cnt_per_group = cnt;
        if (cnt == 0) {
-               conf->worker_groups = NULL;
+               *group_cnt = 0;
+               *worker_groups = NULL;
                return 0;
        }
-       conf->group_cnt = num_possible_nodes();
+       *group_cnt = num_possible_nodes();
        size = sizeof(struct r5worker) * cnt;
-       workers = kzalloc(size * conf->group_cnt, GFP_NOIO);
-       conf->worker_groups = kzalloc(sizeof(struct r5worker_group) *
-                               conf->group_cnt, GFP_NOIO);
-       if (!conf->worker_groups || !workers) {
+       workers = kzalloc(size * *group_cnt, GFP_NOIO);
+       *worker_groups = kzalloc(sizeof(struct r5worker_group) *
+                               *group_cnt, GFP_NOIO);
+       if (!*worker_groups || !workers) {
                kfree(workers);
-               kfree(conf->worker_groups);
-               conf->worker_groups = NULL;
+               kfree(*worker_groups);
                return -ENOMEM;
        }
 
-       for (i = 0; i < conf->group_cnt; i++) {
+       for (i = 0; i < *group_cnt; i++) {
                struct r5worker_group *group;
 
-               group = &conf->worker_groups[i];
+               group = worker_groups[i];
                INIT_LIST_HEAD(&group->handle_list);
                group->conf = conf;
                group->workers = workers + i * cnt;
 
                for (j = 0; j < cnt; j++) {
-                       group->workers[j].group = group;
-                       INIT_WORK(&group->workers[j].work, raid5_do_work);
+                       struct r5worker *worker = group->workers + j;
+                       worker->group = group;
+                       INIT_WORK(&worker->work, raid5_do_work);
+
+                       for (k = 0; k < NR_STRIPE_HASH_LOCKS; k++)
+                               INIT_LIST_HEAD(worker->temp_inactive_list + k);
                }
        }
 
@@ -5444,6 +5633,9 @@ static struct r5conf *setup_conf(struct mddev *mddev)
        struct md_rdev *rdev;
        struct disk_info *disk;
        char pers_name[6];
+       int i;
+       int group_cnt, worker_cnt_per_group;
+       struct r5worker_group *new_group;
 
        if (mddev->new_level != 5
            && mddev->new_level != 4
@@ -5478,7 +5670,12 @@ static struct r5conf *setup_conf(struct mddev *mddev)
        if (conf == NULL)
                goto abort;
        /* Don't enable multi-threading by default*/
-       if (alloc_thread_groups(conf, 0))
+       if (!alloc_thread_groups(conf, 0, &group_cnt, &worker_cnt_per_group,
+                                &new_group)) {
+               conf->group_cnt = group_cnt;
+               conf->worker_cnt_per_group = worker_cnt_per_group;
+               conf->worker_groups = new_group;
+       } else
                goto abort;
        spin_lock_init(&conf->device_lock);
        seqcount_init(&conf->gen_lock);
@@ -5488,7 +5685,6 @@ static struct r5conf *setup_conf(struct mddev *mddev)
        INIT_LIST_HEAD(&conf->hold_list);
        INIT_LIST_HEAD(&conf->delayed_list);
        INIT_LIST_HEAD(&conf->bitmap_list);
-       INIT_LIST_HEAD(&conf->inactive_list);
        init_llist_head(&conf->released_stripes);
        atomic_set(&conf->active_stripes, 0);
        atomic_set(&conf->preread_active_stripes, 0);
@@ -5514,6 +5710,21 @@ static struct r5conf *setup_conf(struct mddev *mddev)
        if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
                goto abort;
 
+       /* We init hash_locks[0] separately to that it can be used
+        * as the reference lock in the spin_lock_nest_lock() call
+        * in lock_all_device_hash_locks_irq in order to convince
+        * lockdep that we know what we are doing.
+        */
+       spin_lock_init(conf->hash_locks);
+       for (i = 1; i < NR_STRIPE_HASH_LOCKS; i++)
+               spin_lock_init(conf->hash_locks + i);
+
+       for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
+               INIT_LIST_HEAD(conf->inactive_list + i);
+
+       for (i = 0; i < NR_STRIPE_HASH_LOCKS; i++)
+               INIT_LIST_HEAD(conf->temp_inactive_list + i);
+
        conf->level = mddev->new_level;
        if (raid5_alloc_percpu(conf) != 0)
                goto abort;
@@ -5554,7 +5765,6 @@ static struct r5conf *setup_conf(struct mddev *mddev)
        else
                conf->max_degraded = 1;
        conf->algorithm = mddev->new_layout;
-       conf->max_nr_stripes = NR_STRIPES;
        conf->reshape_progress = mddev->reshape_position;
        if (conf->reshape_progress != MaxSector) {
                conf->prev_chunk_sectors = mddev->chunk_sectors;
@@ -5563,7 +5773,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
 
        memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
                 max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
-       if (grow_stripes(conf, conf->max_nr_stripes)) {
+       atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS);
+       if (grow_stripes(conf, NR_STRIPES)) {
                printk(KERN_ERR
                       "md/raid:%s: couldn't allocate %dkB for buffers\n",
                       mdname(mddev), memory);
@@ -6369,12 +6580,18 @@ static int raid5_start_reshape(struct mddev *mddev)
        if (!mddev->sync_thread) {
                mddev->recovery = 0;
                spin_lock_irq(&conf->device_lock);
+               write_seqcount_begin(&conf->gen_lock);
                mddev->raid_disks = conf->raid_disks = conf->previous_raid_disks;
+               mddev->new_chunk_sectors =
+                       conf->chunk_sectors = conf->prev_chunk_sectors;
+               mddev->new_layout = conf->algorithm = conf->prev_algo;
                rdev_for_each(rdev, mddev)
                        rdev->new_data_offset = rdev->data_offset;
                smp_wmb();
+               conf->generation --;
                conf->reshape_progress = MaxSector;
                mddev->reshape_position = MaxSector;
+               write_seqcount_end(&conf->gen_lock);
                spin_unlock_irq(&conf->device_lock);
                return -EAGAIN;
        }
@@ -6462,27 +6679,28 @@ static void raid5_quiesce(struct mddev *mddev, int state)
                break;
 
        case 1: /* stop all writes */
-               spin_lock_irq(&conf->device_lock);
+               lock_all_device_hash_locks_irq(conf);
                /* '2' tells resync/reshape to pause so that all
                 * active stripes can drain
                 */
                conf->quiesce = 2;
-               wait_event_lock_irq(conf->wait_for_stripe,
+               wait_event_cmd(conf->wait_for_stripe,
                                    atomic_read(&conf->active_stripes) == 0 &&
                                    atomic_read(&conf->active_aligned_reads) == 0,
-                                   conf->device_lock);
+                                   unlock_all_device_hash_locks_irq(conf),
+                                   lock_all_device_hash_locks_irq(conf));
                conf->quiesce = 1;
-               spin_unlock_irq(&conf->device_lock);
+               unlock_all_device_hash_locks_irq(conf);
                /* allow reshape to continue */
                wake_up(&conf->wait_for_overlap);
                break;
 
        case 0: /* re-enable writes */
-               spin_lock_irq(&conf->device_lock);
+               lock_all_device_hash_locks_irq(conf);
                conf->quiesce = 0;
                wake_up(&conf->wait_for_stripe);
                wake_up(&conf->wait_for_overlap);
-               spin_unlock_irq(&conf->device_lock);
+               unlock_all_device_hash_locks_irq(conf);
                break;
        }
 }
index 2113ffa82c7a2506d21ce36076c3f6bd057d922b..01ad8ae8f57830a04de4e1e30b731f74660bda62 100644 (file)
@@ -49,7 +49,7 @@
  * can't distinguish between a clean block that has been generated
  * from parity calculations, and a clean block that has been
  * successfully written to the spare ( or to parity when resyncing).
- * To distingush these states we have a stripe bit STRIPE_INSYNC that
+ * To distinguish these states we have a stripe bit STRIPE_INSYNC that
  * is set whenever a write is scheduled to the spare, or to the parity
  * disc if there is no spare.  A sync request clears this bit, and
  * when we find it set with no buffers locked, we know the sync is
@@ -205,6 +205,7 @@ struct stripe_head {
        short                   pd_idx;         /* parity disk index */
        short                   qd_idx;         /* 'Q' disk index for raid6 */
        short                   ddf_layout;/* use DDF ordering to calculate Q */
+       short                   hash_lock_index;
        unsigned long           state;          /* state flags */
        atomic_t                count;        /* nr of active thread/requests */
        int                     bm_seq; /* sequence number for bitmap flushes */
@@ -367,9 +368,18 @@ struct disk_info {
        struct md_rdev  *rdev, *replacement;
 };
 
+/* NOTE NR_STRIPE_HASH_LOCKS must remain below 64.
+ * This is because we sometimes take all the spinlocks
+ * and creating that much locking depth can cause
+ * problems.
+ */
+#define NR_STRIPE_HASH_LOCKS 8
+#define STRIPE_HASH_LOCKS_MASK (NR_STRIPE_HASH_LOCKS - 1)
+
 struct r5worker {
        struct work_struct work;
        struct r5worker_group *group;
+       struct list_head temp_inactive_list[NR_STRIPE_HASH_LOCKS];
        bool working;
 };
 
@@ -382,6 +392,8 @@ struct r5worker_group {
 
 struct r5conf {
        struct hlist_head       *stripe_hashtbl;
+       /* only protect corresponding hash list and inactive_list */
+       spinlock_t              hash_locks[NR_STRIPE_HASH_LOCKS];
        struct mddev            *mddev;
        int                     chunk_sectors;
        int                     level, algorithm;
@@ -462,7 +474,8 @@ struct r5conf {
         * Free stripes pool
         */
        atomic_t                active_stripes;
-       struct list_head        inactive_list;
+       struct list_head        inactive_list[NR_STRIPE_HASH_LOCKS];
+       atomic_t                empty_inactive_list_nr;
        struct llist_head       released_stripes;
        wait_queue_head_t       wait_for_stripe;
        wait_queue_head_t       wait_for_overlap;
@@ -477,6 +490,7 @@ struct r5conf {
         * the new thread here until we fully activate the array.
         */
        struct md_thread        *thread;
+       struct list_head        temp_inactive_list[NR_STRIPE_HASH_LOCKS];
        struct r5worker_group   *worker_groups;
        int                     group_cnt;
        int                     worker_cnt_per_group;
index f2199e43e803594253a1ad655d93b196ecffb843..185c285f70fc99fc2b1bcf36b897c6158b8fa8d8 100644 (file)
@@ -85,7 +85,7 @@ static void flexcop_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *
                while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
                        mdelay(1);
                        retries--;
-               };
+               }
 
                if (retries == 0)
                        printk("%s: SRAM timeout\n", __func__);
@@ -110,7 +110,7 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf,
                while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
                        mdelay(1);
                        retries--;
-               };
+               }
 
                if (retries == 0)
                        printk("%s: SRAM timeout\n", __func__);
@@ -122,7 +122,7 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf,
                while (((read_reg_dw(adapter, 0x700) & 0x80000000) != 0) && (retries > 0)) {
                        mdelay(1);
                        retries--;
-               };
+               }
 
                if (retries == 0)
                        printk("%s: SRAM timeout\n", __func__);
index bb6ee5191eb183a415c6de0350a3ae02877a3fd2..34b0d0ddeef3f4003928487420e22aac5fb39d73 100644 (file)
@@ -411,7 +411,7 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
        saa7146_write(dev, MC2, 0xf8000000);
 
        /* request an interrupt for the saa7146 */
-       err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED,
+       err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED,
                          dev->name, dev);
        if (err < 0) {
                ERR("request_irq() failed\n");
@@ -524,8 +524,6 @@ static void saa7146_remove_one(struct pci_dev *pdev)
        DEB_EE("dev:%p\n", dev);
 
        dev->ext->detach(dev);
-       /* Zero the PCI drvdata after use. */
-       pci_set_drvdata(pdev, NULL);
 
        /* shut down all video dma transfers */
        saa7146_write(dev, MC1, 0x00ff0000);
index a142f7942a015c86da5a72f7401232c58a0ffe0f..050984c5b1e3701aa00ea0d074bca9700754d9d3 100644 (file)
@@ -922,8 +922,8 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
        u32 i, *ptr;
        u8 *payload = firmware->payload;
        int rc = 0;
-       firmware->start_address = le32_to_cpu(firmware->start_address);
-       firmware->length = le32_to_cpu(firmware->length);
+       firmware->start_address = le32_to_cpup((__le32 *)&firmware->start_address);
+       firmware->length = le32_to_cpup((__le32 *)&firmware->length);
 
        mem_address = firmware->start_address;
 
@@ -982,7 +982,7 @@ static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
        if (rc < 0)
                goto exit_fw_download;
 
-       sms_err("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
+       sms_debug("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
                calc_checksum);
        SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_DATA_VALIDITY_REQ,
                        sizeof(msg->x_msg_header) +
@@ -1562,7 +1562,7 @@ void smscore_onresponse(struct smscore_device_t *coredev,
                {
                        struct sms_msg_data *validity = (struct sms_msg_data *) phdr;
 
-                       sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
+                       sms_debug("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
                                validity->msg_data[0]);
                        complete(&coredev->data_validity_done);
                        break;
index 63676a8b024c874ab20c95862b5b1140e02d73b1..85151efdd94c75d96db013151ba6b6d2c0d04841 100644 (file)
@@ -44,14 +44,14 @@ module_param_named(debug, sms_dbg, int, 0644);
 MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
 
 
-u32 sms_to_guard_interval_table[] = {
+static u32 sms_to_guard_interval_table[] = {
        [0] = GUARD_INTERVAL_1_32,
        [1] = GUARD_INTERVAL_1_16,
        [2] = GUARD_INTERVAL_1_8,
        [3] = GUARD_INTERVAL_1_4,
 };
 
-u32 sms_to_code_rate_table[] = {
+static u32 sms_to_code_rate_table[] = {
        [0] = FEC_1_2,
        [1] = FEC_2_3,
        [2] = FEC_3_4,
@@ -60,14 +60,14 @@ u32 sms_to_code_rate_table[] = {
 };
 
 
-u32 sms_to_hierarchy_table[] = {
+static u32 sms_to_hierarchy_table[] = {
        [0] = HIERARCHY_NONE,
        [1] = HIERARCHY_1,
        [2] = HIERARCHY_2,
        [3] = HIERARCHY_4,
 };
 
-u32 sms_to_modulation_table[] = {
+static u32 sms_to_modulation_table[] = {
        [0] = QPSK,
        [1] = QAM_16,
        [2] = QAM_64,
index 3485655fa08297c1ea6d75e73e40c3b1797e676d..58de4410c5258a7d6009ae47b5becd7e20fa6208 100644 (file)
@@ -476,7 +476,9 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
 void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
                              size_t count)
 {
-       spin_lock(&demux->lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&demux->lock, flags);
 
        while (count--) {
                if (buf[0] == 0x47)
@@ -484,7 +486,7 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
                buf += 188;
        }
 
-       spin_unlock(&demux->lock);
+       spin_unlock_irqrestore(&demux->lock, flags);
 }
 
 EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
@@ -519,8 +521,9 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf,
 {
        int p = 0, i, j;
        const u8 *q;
+       unsigned long flags;
 
-       spin_lock(&demux->lock);
+       spin_lock_irqsave(&demux->lock, flags);
 
        if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */
                i = demux->tsbufp;
@@ -564,7 +567,7 @@ static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf,
        }
 
 bailout:
-       spin_unlock(&demux->lock);
+       spin_unlock_irqrestore(&demux->lock, flags);
 }
 
 void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
@@ -581,11 +584,13 @@ EXPORT_SYMBOL(dvb_dmx_swfilter_204);
 
 void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count)
 {
-       spin_lock(&demux->lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&demux->lock, flags);
 
        demux->feed->cb.ts(buf, count, NULL, 0, &demux->feed->feed.ts, DMX_OK);
 
-       spin_unlock(&demux->lock);
+       spin_unlock_irqrestore(&demux->lock, flags);
 }
 EXPORT_SYMBOL(dvb_dmx_swfilter_raw);
 
index 0e2ec6f73b0525583e734dcac3933da97dee8fe6..bddbab43a2df01a3f243bb5300708c09e7cf4c21 100644 (file)
@@ -200,6 +200,13 @@ config DVB_CX24116
        help
          A DVB-S/S2 tuner module. Say Y when you want to support this frontend.
 
+config DVB_CX24117
+       tristate "Conexant CX24117 based"
+       depends on DVB_CORE && I2C
+       default m if !MEDIA_SUBDRV_AUTOSELECT
+       help
+         A Dual DVB-S/S2 tuner module. Say Y when you want to support this frontend.
+
 config DVB_SI21XX
        tristate "Silicon Labs SI21XX based"
        depends on DVB_CORE && I2C
index cebc0faffab590e3404e906eb09839f3eeb5f21a..f9cb43d9aed920816413d95656a83d3dad30a096 100644 (file)
@@ -76,6 +76,7 @@ obj-$(CONFIG_DVB_ATBM8830) += atbm8830.o
 obj-$(CONFIG_DVB_DUMMY_FE) += dvb_dummy_fe.o
 obj-$(CONFIG_DVB_AF9013) += af9013.o
 obj-$(CONFIG_DVB_CX24116) += cx24116.o
+obj-$(CONFIG_DVB_CX24117) += cx24117.o
 obj-$(CONFIG_DVB_SI21XX) += si21xx.o
 obj-$(CONFIG_DVB_STV0288) += stv0288.o
 obj-$(CONFIG_DVB_STB6000) += stb6000.o
index a204f2828820412f94152928f9ba20e9126b25e6..fb504f1e912500c3f8c04a9e1e0f0472255597a6 100644 (file)
@@ -24,6 +24,9 @@
 
 #include "af9013_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 struct af9013_state {
        struct i2c_adapter *i2c;
        struct dvb_frontend fe;
@@ -50,16 +53,23 @@ static int af9013_wr_regs_i2c(struct af9013_state *priv, u8 mbox, u16 reg,
        const u8 *val, int len)
 {
        int ret;
-       u8 buf[3+len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->config.i2c_addr,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = 3 + len,
                        .buf = buf,
                }
        };
 
+       if (3 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = (reg >> 8) & 0xff;
        buf[1] = (reg >> 0) & 0xff;
        buf[2] = mbox;
index a777b4b944eb368f17ebe360ae37b989c2718e19..30ee59052157815edd50669afe2293ed4e2e8867 100644 (file)
@@ -21,6 +21,9 @@
 
 #include "af9033_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 struct af9033_state {
        struct i2c_adapter *i2c;
        struct dvb_frontend fe;
@@ -40,16 +43,23 @@ static int af9033_wr_regs(struct af9033_state *state, u32 reg, const u8 *val,
                int len)
 {
        int ret;
-       u8 buf[3 + len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = state->cfg.i2c_addr,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = 3 + len,
                        .buf = buf,
                }
        };
 
+       if (3 + len > sizeof(buf)) {
+               dev_warn(&state->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = (reg >> 16) & 0xff;
        buf[1] = (reg >>  8) & 0xff;
        buf[2] = (reg >>  0) & 0xff;
@@ -161,7 +171,14 @@ static int af9033_wr_reg_val_tab(struct af9033_state *state,
                const struct reg_val *tab, int tab_len)
 {
        int ret, i, j;
-       u8 buf[tab_len];
+       u8 buf[MAX_XFER_SIZE];
+
+       if (tab_len > sizeof(buf)) {
+               dev_warn(&state->i2c->dev,
+                        "%s: i2c wr len=%d is too big!\n",
+                        KBUILD_MODNAME, tab_len);
+               return -EINVAL;
+       }
 
        dev_dbg(&state->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len);
 
index 1b77909c0c7116c3cff03b6788912a29c2f240f3..39a29dd29519cba8573fd7ce1837e46d7df1f73b 100644 (file)
@@ -44,6 +44,9 @@
 #include "bcm3510.h"
 #include "bcm3510_priv.h"
 
+/* Max transfer size done by bcm3510_do_hab_cmd() function */
+#define MAX_XFER_SIZE  128
+
 struct bcm3510_state {
 
        struct i2c_adapter* i2c;
@@ -201,9 +204,19 @@ static int bcm3510_hab_send_request(struct bcm3510_state *st, u8 *buf, int len)
 
 static int bcm3510_do_hab_cmd(struct bcm3510_state *st, u8 cmd, u8 msgid, u8 *obuf, u8 olen, u8 *ibuf, u8 ilen)
 {
-       u8 ob[olen+2],ib[ilen+2];
+       u8 ob[MAX_XFER_SIZE], ib[MAX_XFER_SIZE];
        int ret = 0;
 
+       if (ilen + 2 > sizeof(ib)) {
+               deb_hab("do_hab_cmd: ilen=%d is too big!\n", ilen);
+               return -EINVAL;
+       }
+
+       if (olen + 2 > sizeof(ob)) {
+               deb_hab("do_hab_cmd: olen=%d is too big!\n", olen);
+               return -EINVAL;
+       }
+
        ob[0] = cmd;
        ob[1] = msgid;
        memcpy(&ob[2],obuf,olen);
index 0cd6927e654c110b804def49677b71f8b26cc1a9..95b981cd7115b451d7a52bd8c0da15118a6f582f 100644 (file)
@@ -378,7 +378,7 @@ static int cx24110_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
                return cx24110_writereg(state,0x76,(cx24110_readreg(state,0x76)&0x3b)|0x40);
        default:
                return -EINVAL;
-       };
+       }
 }
 
 static int cx24110_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
diff --git a/drivers/media/dvb-frontends/cx24117.c b/drivers/media/dvb-frontends/cx24117.c
new file mode 100644 (file)
index 0000000..476b422
--- /dev/null
@@ -0,0 +1,1650 @@
+/*
+    Conexant cx24117/cx24132 - Dual DVBS/S2 Satellite demod/tuner driver
+
+    Copyright (C) 2013 Luis Alves <ljalvs@gmail.com>
+       July, 6th 2013
+           First release based on cx24116 driver by:
+           Steven Toth and Georg Acher, Darron Broad, Igor Liplianin
+           Cards currently supported:
+               TBS6980 - Dual DVBS/S2 PCIe card
+               TBS6981 - Dual DVBS/S2 PCIe card
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/firmware.h>
+
+#include "tuner-i2c.h"
+#include "dvb_frontend.h"
+#include "cx24117.h"
+
+
+#define CX24117_DEFAULT_FIRMWARE "dvb-fe-cx24117.fw"
+#define CX24117_SEARCH_RANGE_KHZ 5000
+
+/* known registers */
+#define CX24117_REG_COMMAND      (0x00)      /* command buffer */
+#define CX24117_REG_EXECUTE      (0x1f)      /* execute command */
+
+#define CX24117_REG_FREQ3_0      (0x34)      /* frequency */
+#define CX24117_REG_FREQ2_0      (0x35)
+#define CX24117_REG_FREQ1_0      (0x36)
+#define CX24117_REG_STATE0       (0x39)
+#define CX24117_REG_SSTATUS0     (0x3a)      /* demod0 signal high / status */
+#define CX24117_REG_SIGNAL0      (0x3b)
+#define CX24117_REG_FREQ5_0      (0x3c)      /* +-freq */
+#define CX24117_REG_FREQ6_0      (0x3d)
+#define CX24117_REG_SRATE2_0     (0x3e)      /* +- 1000 * srate */
+#define CX24117_REG_SRATE1_0     (0x3f)
+#define CX24117_REG_QUALITY2_0   (0x40)
+#define CX24117_REG_QUALITY1_0   (0x41)
+
+#define CX24117_REG_BER4_0       (0x47)
+#define CX24117_REG_BER3_0       (0x48)
+#define CX24117_REG_BER2_0       (0x49)
+#define CX24117_REG_BER1_0       (0x4a)
+#define CX24117_REG_DVBS_UCB2_0  (0x4b)
+#define CX24117_REG_DVBS_UCB1_0  (0x4c)
+#define CX24117_REG_DVBS2_UCB2_0 (0x50)
+#define CX24117_REG_DVBS2_UCB1_0 (0x51)
+#define CX24117_REG_QSTATUS0     (0x93)
+#define CX24117_REG_CLKDIV0      (0xe6)
+#define CX24117_REG_RATEDIV0     (0xf0)
+
+
+#define CX24117_REG_FREQ3_1      (0x55)      /* frequency */
+#define CX24117_REG_FREQ2_1      (0x56)
+#define CX24117_REG_FREQ1_1      (0x57)
+#define CX24117_REG_STATE1       (0x5a)
+#define CX24117_REG_SSTATUS1     (0x5b)      /* demod1 signal high / status */
+#define CX24117_REG_SIGNAL1      (0x5c)
+#define CX24117_REG_FREQ5_1      (0x5d)      /* +- freq */
+#define CX24117_REG_FREQ4_1      (0x5e)
+#define CX24117_REG_SRATE2_1     (0x5f)
+#define CX24117_REG_SRATE1_1     (0x60)
+#define CX24117_REG_QUALITY2_1   (0x61)
+#define CX24117_REG_QUALITY1_1   (0x62)
+#define CX24117_REG_BER4_1       (0x68)
+#define CX24117_REG_BER3_1       (0x69)
+#define CX24117_REG_BER2_1       (0x6a)
+#define CX24117_REG_BER1_1       (0x6b)
+#define CX24117_REG_DVBS_UCB2_1  (0x6c)
+#define CX24117_REG_DVBS_UCB1_1  (0x6d)
+#define CX24117_REG_DVBS2_UCB2_1 (0x71)
+#define CX24117_REG_DVBS2_UCB1_1 (0x72)
+#define CX24117_REG_QSTATUS1     (0x9f)
+#define CX24117_REG_CLKDIV1      (0xe7)
+#define CX24117_REG_RATEDIV1     (0xf1)
+
+
+/* arg buffer size */
+#define CX24117_ARGLEN       (0x1e)
+
+/* rolloff */
+#define CX24117_ROLLOFF_020  (0x00)
+#define CX24117_ROLLOFF_025  (0x01)
+#define CX24117_ROLLOFF_035  (0x02)
+
+/* pilot bit */
+#define CX24117_PILOT_OFF    (0x00)
+#define CX24117_PILOT_ON     (0x40)
+#define CX24117_PILOT_AUTO   (0x80)
+
+/* signal status */
+#define CX24117_HAS_SIGNAL   (0x01)
+#define CX24117_HAS_CARRIER  (0x02)
+#define CX24117_HAS_VITERBI  (0x04)
+#define CX24117_HAS_SYNCLOCK (0x08)
+#define CX24117_STATUS_MASK  (0x0f)
+#define CX24117_SIGNAL_MASK  (0xc0)
+
+
+/* arg offset for DiSEqC */
+#define CX24117_DISEQC_DEMOD  (1)
+#define CX24117_DISEQC_BURST  (2)
+#define CX24117_DISEQC_ARG3_2 (3)   /* unknown value=2 */
+#define CX24117_DISEQC_ARG4_0 (4)   /* unknown value=0 */
+#define CX24117_DISEQC_ARG5_0 (5)   /* unknown value=0 */
+#define CX24117_DISEQC_MSGLEN (6)
+#define CX24117_DISEQC_MSGOFS (7)
+
+/* DiSEqC burst */
+#define CX24117_DISEQC_MINI_A (0)
+#define CX24117_DISEQC_MINI_B (1)
+
+
+#define CX24117_PNE    (0) /* 0 disabled / 2 enabled */
+#define CX24117_OCC    (1) /* 0 disabled / 1 enabled */
+
+
+enum cmds {
+       CMD_SET_VCO     = 0x10,
+       CMD_TUNEREQUEST = 0x11,
+       CMD_MPEGCONFIG  = 0x13,
+       CMD_TUNERINIT   = 0x14,
+       CMD_LNBSEND     = 0x21, /* Formerly CMD_SEND_DISEQC */
+       CMD_LNBDCLEVEL  = 0x22,
+       CMD_SET_TONE    = 0x23,
+       CMD_UPDFWVERS   = 0x35,
+       CMD_TUNERSLEEP  = 0x36,
+};
+
+static LIST_HEAD(hybrid_tuner_instance_list);
+static DEFINE_MUTEX(cx24117_list_mutex);
+
+/* The Demod/Tuner can't easily provide these, we cache them */
+struct cx24117_tuning {
+       u32 frequency;
+       u32 symbol_rate;
+       fe_spectral_inversion_t inversion;
+       fe_code_rate_t fec;
+
+       fe_delivery_system_t delsys;
+       fe_modulation_t modulation;
+       fe_pilot_t pilot;
+       fe_rolloff_t rolloff;
+
+       /* Demod values */
+       u8 fec_val;
+       u8 fec_mask;
+       u8 inversion_val;
+       u8 pilot_val;
+       u8 rolloff_val;
+};
+
+/* Basic commands that are sent to the firmware */
+struct cx24117_cmd {
+       u8 len;
+       u8 args[CX24117_ARGLEN];
+};
+
+/* common to both fe's */
+struct cx24117_priv {
+       u8 demod_address;
+       struct i2c_adapter *i2c;
+       u8 skip_fw_load;
+       struct mutex fe_lock;
+
+       /* Used for sharing this struct between demods */
+       struct tuner_i2c_props i2c_props;
+       struct list_head hybrid_tuner_instance_list;
+};
+
+/* one per each fe */
+struct cx24117_state {
+       struct cx24117_priv *priv;
+       struct dvb_frontend frontend;
+
+       struct cx24117_tuning dcur;
+       struct cx24117_tuning dnxt;
+       struct cx24117_cmd dsec_cmd;
+
+       int demod;
+};
+
+/* modfec (modulation and FEC) lookup table */
+/* Check cx24116.c for a detailed description of each field */
+static struct cx24117_modfec {
+       fe_delivery_system_t delivery_system;
+       fe_modulation_t modulation;
+       fe_code_rate_t fec;
+       u8 mask;        /* In DVBS mode this is used to autodetect */
+       u8 val;         /* Passed to the firmware to indicate mode selection */
+} cx24117_modfec_modes[] = {
+       /* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */
+
+       /*mod   fec       mask  val */
+       { SYS_DVBS, QPSK, FEC_NONE, 0xfe, 0x30 },
+       { SYS_DVBS, QPSK, FEC_1_2,  0x02, 0x2e }, /* 00000010 00101110 */
+       { SYS_DVBS, QPSK, FEC_2_3,  0x04, 0x2f }, /* 00000100 00101111 */
+       { SYS_DVBS, QPSK, FEC_3_4,  0x08, 0x30 }, /* 00001000 00110000 */
+       { SYS_DVBS, QPSK, FEC_4_5,  0xfe, 0x30 }, /* 000?0000 ?        */
+       { SYS_DVBS, QPSK, FEC_5_6,  0x20, 0x31 }, /* 00100000 00110001 */
+       { SYS_DVBS, QPSK, FEC_6_7,  0xfe, 0x30 }, /* 0?000000 ?        */
+       { SYS_DVBS, QPSK, FEC_7_8,  0x80, 0x32 }, /* 10000000 00110010 */
+       { SYS_DVBS, QPSK, FEC_8_9,  0xfe, 0x30 }, /* 0000000? ?        */
+       { SYS_DVBS, QPSK, FEC_AUTO, 0xfe, 0x30 },
+       /* NBC-QPSK */
+       { SYS_DVBS2, QPSK, FEC_NONE, 0x00, 0x00 },
+       { SYS_DVBS2, QPSK, FEC_1_2,  0x00, 0x04 },
+       { SYS_DVBS2, QPSK, FEC_3_5,  0x00, 0x05 },
+       { SYS_DVBS2, QPSK, FEC_2_3,  0x00, 0x06 },
+       { SYS_DVBS2, QPSK, FEC_3_4,  0x00, 0x07 },
+       { SYS_DVBS2, QPSK, FEC_4_5,  0x00, 0x08 },
+       { SYS_DVBS2, QPSK, FEC_5_6,  0x00, 0x09 },
+       { SYS_DVBS2, QPSK, FEC_8_9,  0x00, 0x0a },
+       { SYS_DVBS2, QPSK, FEC_9_10, 0x00, 0x0b },
+       { SYS_DVBS2, QPSK, FEC_AUTO, 0x00, 0x00 },
+       /* 8PSK */
+       { SYS_DVBS2, PSK_8, FEC_NONE, 0x00, 0x00 },
+       { SYS_DVBS2, PSK_8, FEC_3_5,  0x00, 0x0c },
+       { SYS_DVBS2, PSK_8, FEC_2_3,  0x00, 0x0d },
+       { SYS_DVBS2, PSK_8, FEC_3_4,  0x00, 0x0e },
+       { SYS_DVBS2, PSK_8, FEC_5_6,  0x00, 0x0f },
+       { SYS_DVBS2, PSK_8, FEC_8_9,  0x00, 0x10 },
+       { SYS_DVBS2, PSK_8, FEC_9_10, 0x00, 0x11 },
+       { SYS_DVBS2, PSK_8, FEC_AUTO, 0x00, 0x00 },
+       /*
+        * 'val' can be found in the FECSTATUS register when tuning.
+        * FECSTATUS will give the actual FEC in use if tuning was successful.
+        */
+};
+
+
+static int cx24117_writereg(struct cx24117_state *state, u8 reg, u8 data)
+{
+       u8 buf[] = { reg, data };
+       struct i2c_msg msg = { .addr = state->priv->demod_address,
+               .flags = 0, .buf = buf, .len = 2 };
+       int ret;
+
+       dev_dbg(&state->priv->i2c->dev,
+                       "%s() demod%d i2c wr @0x%02x=0x%02x\n",
+                       __func__, state->demod, reg, data);
+
+       ret = i2c_transfer(state->priv->i2c, &msg, 1);
+       if (ret < 0) {
+               dev_warn(&state->priv->i2c->dev,
+                       "%s: demod%d i2c wr err(%i) @0x%02x=0x%02x\n",
+                       KBUILD_MODNAME, state->demod, ret, reg, data);
+               return ret;
+       }
+       return 0;
+}
+
+static int cx24117_writecmd(struct cx24117_state *state,
+       struct cx24117_cmd *cmd)
+{
+       struct i2c_msg msg;
+       u8 buf[CX24117_ARGLEN+1];
+       int ret;
+
+       dev_dbg(&state->priv->i2c->dev,
+                       "%s() demod%d i2c wr cmd len=%d\n",
+                       __func__, state->demod, cmd->len);
+
+       buf[0] = CX24117_REG_COMMAND;
+       memcpy(&buf[1], cmd->args, cmd->len);
+
+       msg.addr = state->priv->demod_address;
+       msg.flags = 0;
+       msg.len = cmd->len+1;
+       msg.buf = buf;
+       ret = i2c_transfer(state->priv->i2c, &msg, 1);
+       if (ret < 0) {
+               dev_warn(&state->priv->i2c->dev,
+                       "%s: demod%d i2c wr cmd err(%i) len=%d\n",
+                       KBUILD_MODNAME, state->demod, ret, cmd->len);
+               return ret;
+       }
+       return 0;
+}
+
+static int cx24117_readreg(struct cx24117_state *state, u8 reg)
+{
+       int ret;
+       u8 recv = 0;
+       struct i2c_msg msg[] = {
+               { .addr = state->priv->demod_address, .flags = 0,
+                       .buf = &reg, .len = 1 },
+               { .addr = state->priv->demod_address, .flags = I2C_M_RD,
+                       .buf = &recv, .len = 1 }
+       };
+
+       ret = i2c_transfer(state->priv->i2c, msg, 2);
+       if (ret < 0) {
+               dev_warn(&state->priv->i2c->dev,
+                       "%s: demod%d i2c rd err(%d) @0x%x\n",
+                       KBUILD_MODNAME, state->demod, ret, reg);
+               return ret;
+       }
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d i2c rd @0x%02x=0x%02x\n",
+               __func__, state->demod, reg, recv);
+
+       return recv;
+}
+
+static int cx24117_readregN(struct cx24117_state *state,
+       u8 reg, u8 *buf, int len)
+{
+       int ret;
+       struct i2c_msg msg[] = {
+               { .addr = state->priv->demod_address, .flags = 0,
+                       .buf = &reg, .len = 1 },
+               { .addr = state->priv->demod_address, .flags = I2C_M_RD,
+                       .buf = buf, .len = len }
+       };
+
+       ret = i2c_transfer(state->priv->i2c, msg, 2);
+       if (ret < 0) {
+               dev_warn(&state->priv->i2c->dev,
+                       "%s: demod%d i2c rd err(%d) @0x%x\n",
+                       KBUILD_MODNAME, state->demod, ret, reg);
+               return ret;
+       }
+       return 0;
+}
+
+static int cx24117_set_inversion(struct cx24117_state *state,
+       fe_spectral_inversion_t inversion)
+{
+       dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
+               __func__, inversion, state->demod);
+
+       switch (inversion) {
+       case INVERSION_OFF:
+               state->dnxt.inversion_val = 0x00;
+               break;
+       case INVERSION_ON:
+               state->dnxt.inversion_val = 0x04;
+               break;
+       case INVERSION_AUTO:
+               state->dnxt.inversion_val = 0x0C;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       state->dnxt.inversion = inversion;
+
+       return 0;
+}
+
+static int cx24117_lookup_fecmod(struct cx24117_state *state,
+       fe_delivery_system_t d, fe_modulation_t m, fe_code_rate_t f)
+{
+       int i, ret = -EINVAL;
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s(demod(0x%02x,0x%02x) demod%d\n",
+               __func__, m, f, state->demod);
+
+       for (i = 0; i < ARRAY_SIZE(cx24117_modfec_modes); i++) {
+               if ((d == cx24117_modfec_modes[i].delivery_system) &&
+                       (m == cx24117_modfec_modes[i].modulation) &&
+                       (f == cx24117_modfec_modes[i].fec)) {
+                               ret = i;
+                               break;
+                       }
+       }
+
+       return ret;
+}
+
+static int cx24117_set_fec(struct cx24117_state *state,
+       fe_delivery_system_t delsys, fe_modulation_t mod, fe_code_rate_t fec)
+{
+       int ret;
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s(0x%02x,0x%02x) demod%d\n",
+               __func__, mod, fec, state->demod);
+
+       ret = cx24117_lookup_fecmod(state, delsys, mod, fec);
+       if (ret < 0)
+               return ret;
+
+       state->dnxt.fec = fec;
+       state->dnxt.fec_val = cx24117_modfec_modes[ret].val;
+       state->dnxt.fec_mask = cx24117_modfec_modes[ret].mask;
+       dev_dbg(&state->priv->i2c->dev,
+               "%s() demod%d mask/val = 0x%02x/0x%02x\n", __func__,
+               state->demod, state->dnxt.fec_mask, state->dnxt.fec_val);
+
+       return 0;
+}
+
+static int cx24117_set_symbolrate(struct cx24117_state *state, u32 rate)
+{
+       dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
+               __func__, rate, state->demod);
+
+       state->dnxt.symbol_rate = rate;
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s() demod%d symbol_rate = %d\n",
+               __func__, state->demod, rate);
+
+       return 0;
+}
+
+static int cx24117_load_firmware(struct dvb_frontend *fe,
+       const struct firmware *fw);
+
+static int cx24117_firmware_ondemand(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       const struct firmware *fw;
+       int ret = 0;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d skip_fw_load=%d\n",
+               __func__, state->demod, state->priv->skip_fw_load);
+
+       if (state->priv->skip_fw_load)
+               return 0;
+
+       /* check if firmware if already running */
+       if (cx24117_readreg(state, 0xeb) != 0xa) {
+               /* Load firmware */
+               /* request the firmware, this will block until loaded */
+               dev_dbg(&state->priv->i2c->dev,
+                       "%s: Waiting for firmware upload (%s)...\n",
+                       __func__, CX24117_DEFAULT_FIRMWARE);
+               ret = request_firmware(&fw, CX24117_DEFAULT_FIRMWARE,
+                       state->priv->i2c->dev.parent);
+               dev_dbg(&state->priv->i2c->dev,
+                       "%s: Waiting for firmware upload(2)...\n", __func__);
+               if (ret) {
+                       dev_err(&state->priv->i2c->dev,
+                               "%s: No firmware uploaded "
+                               "(timeout or file not found?)\n", __func__);
+                       return ret;
+               }
+
+               /* Make sure we don't recurse back through here
+                * during loading */
+               state->priv->skip_fw_load = 1;
+
+               ret = cx24117_load_firmware(fe, fw);
+               if (ret)
+                       dev_err(&state->priv->i2c->dev,
+                               "%s: Writing firmware failed\n", __func__);
+               release_firmware(fw);
+
+               dev_info(&state->priv->i2c->dev,
+                       "%s: Firmware upload %s\n", __func__,
+                       ret == 0 ? "complete" : "failed");
+
+               /* Ensure firmware is always loaded if required */
+               state->priv->skip_fw_load = 0;
+       }
+
+       return ret;
+}
+
+/* Take a basic firmware command structure, format it
+ * and forward it for processing
+ */
+static int cx24117_cmd_execute_nolock(struct dvb_frontend *fe,
+       struct cx24117_cmd *cmd)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int i, ret;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
+               __func__, state->demod);
+
+       /* Load the firmware if required */
+       ret = cx24117_firmware_ondemand(fe);
+       if (ret != 0)
+               return ret;
+
+       /* Write the command */
+       cx24117_writecmd(state, cmd);
+
+       /* Start execution and wait for cmd to terminate */
+       cx24117_writereg(state, CX24117_REG_EXECUTE, 0x01);
+       i = 0;
+       while (cx24117_readreg(state, CX24117_REG_EXECUTE)) {
+               msleep(20);
+               if (i++ > 40) {
+                       /* Avoid looping forever if the firmware does
+                               not respond */
+                       dev_warn(&state->priv->i2c->dev,
+                               "%s() Firmware not responding\n", __func__);
+                       return -EIO;
+               }
+       }
+       return 0;
+}
+
+static int cx24117_cmd_execute(struct dvb_frontend *fe, struct cx24117_cmd *cmd)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int ret;
+
+       mutex_lock(&state->priv->fe_lock);
+       ret = cx24117_cmd_execute_nolock(fe, cmd);
+       mutex_unlock(&state->priv->fe_lock);
+
+       return ret;
+}
+
+static int cx24117_load_firmware(struct dvb_frontend *fe,
+       const struct firmware *fw)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct cx24117_cmd cmd;
+       int i, ret;
+       unsigned char vers[4];
+
+       struct i2c_msg msg;
+       u8 *buf;
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s() demod%d FW is %zu bytes (%02x %02x .. %02x %02x)\n",
+               __func__, state->demod, fw->size, fw->data[0], fw->data[1],
+               fw->data[fw->size - 2], fw->data[fw->size - 1]);
+
+       cx24117_writereg(state, 0xea, 0x00);
+       cx24117_writereg(state, 0xea, 0x01);
+       cx24117_writereg(state, 0xea, 0x00);
+
+       cx24117_writereg(state, 0xce, 0x92);
+
+       cx24117_writereg(state, 0xfb, 0x00);
+       cx24117_writereg(state, 0xfc, 0x00);
+
+       cx24117_writereg(state, 0xc3, 0x04);
+       cx24117_writereg(state, 0xc4, 0x04);
+
+       cx24117_writereg(state, 0xce, 0x00);
+       cx24117_writereg(state, 0xcf, 0x00);
+
+       cx24117_writereg(state, 0xea, 0x00);
+       cx24117_writereg(state, 0xeb, 0x0c);
+       cx24117_writereg(state, 0xec, 0x06);
+       cx24117_writereg(state, 0xed, 0x05);
+       cx24117_writereg(state, 0xee, 0x03);
+       cx24117_writereg(state, 0xef, 0x05);
+
+       cx24117_writereg(state, 0xf3, 0x03);
+       cx24117_writereg(state, 0xf4, 0x44);
+
+       cx24117_writereg(state, CX24117_REG_RATEDIV0, 0x04);
+       cx24117_writereg(state, CX24117_REG_CLKDIV0, 0x02);
+
+       cx24117_writereg(state, CX24117_REG_RATEDIV1, 0x04);
+       cx24117_writereg(state, CX24117_REG_CLKDIV1, 0x02);
+
+       cx24117_writereg(state, 0xf2, 0x04);
+       cx24117_writereg(state, 0xe8, 0x02);
+       cx24117_writereg(state, 0xea, 0x01);
+       cx24117_writereg(state, 0xc8, 0x00);
+       cx24117_writereg(state, 0xc9, 0x00);
+       cx24117_writereg(state, 0xca, 0x00);
+       cx24117_writereg(state, 0xcb, 0x00);
+       cx24117_writereg(state, 0xcc, 0x00);
+       cx24117_writereg(state, 0xcd, 0x00);
+       cx24117_writereg(state, 0xe4, 0x03);
+       cx24117_writereg(state, 0xeb, 0x0a);
+
+       cx24117_writereg(state, 0xfb, 0x00);
+       cx24117_writereg(state, 0xe0, 0x76);
+       cx24117_writereg(state, 0xf7, 0x81);
+       cx24117_writereg(state, 0xf8, 0x00);
+       cx24117_writereg(state, 0xf9, 0x00);
+
+       buf = kmalloc(fw->size + 1, GFP_KERNEL);
+       if (buf == NULL) {
+               state->priv->skip_fw_load = 0;
+               return -ENOMEM;
+       }
+
+       /* fw upload reg */
+       buf[0] = 0xfa;
+       memcpy(&buf[1], fw->data, fw->size);
+
+       /* prepare i2c message to send */
+       msg.addr = state->priv->demod_address;
+       msg.flags = 0;
+       msg.len = fw->size + 1;
+       msg.buf = buf;
+
+       /* send fw */
+       ret = i2c_transfer(state->priv->i2c, &msg, 1);
+       if (ret < 0)
+               return ret;
+
+       kfree(buf);
+
+       cx24117_writereg(state, 0xf7, 0x0c);
+       cx24117_writereg(state, 0xe0, 0x00);
+
+       /* CMD 1B */
+       cmd.args[0] = 0x1b;
+       cmd.args[1] = 0x00;
+       cmd.args[2] = 0x01;
+       cmd.args[3] = 0x00;
+       cmd.len = 4;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+       if (ret != 0)
+               goto error;
+
+       /* CMD 10 */
+       cmd.args[0] = CMD_SET_VCO;
+       cmd.args[1] = 0x06;
+       cmd.args[2] = 0x2b;
+       cmd.args[3] = 0xd8;
+       cmd.args[4] = 0xa5;
+       cmd.args[5] = 0xee;
+       cmd.args[6] = 0x03;
+       cmd.args[7] = 0x9d;
+       cmd.args[8] = 0xfc;
+       cmd.args[9] = 0x06;
+       cmd.args[10] = 0x02;
+       cmd.args[11] = 0x9d;
+       cmd.args[12] = 0xfc;
+       cmd.len = 13;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+       if (ret != 0)
+               goto error;
+
+       /* CMD 15 */
+       cmd.args[0] = 0x15;
+       cmd.args[1] = 0x00;
+       cmd.args[2] = 0x01;
+       cmd.args[3] = 0x00;
+       cmd.args[4] = 0x00;
+       cmd.args[5] = 0x01;
+       cmd.args[6] = 0x01;
+       cmd.args[7] = 0x01;
+       cmd.args[8] = 0x00;
+       cmd.args[9] = 0x05;
+       cmd.args[10] = 0x02;
+       cmd.args[11] = 0x02;
+       cmd.args[12] = 0x00;
+       cmd.len = 13;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+       if (ret != 0)
+               goto error;
+
+       /* CMD 13 */
+       cmd.args[0] = CMD_MPEGCONFIG;
+       cmd.args[1] = 0x00;
+       cmd.args[2] = 0x00;
+       cmd.args[3] = 0x00;
+       cmd.args[4] = 0x01;
+       cmd.args[5] = 0x00;
+       cmd.len = 6;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+       if (ret != 0)
+               goto error;
+
+       /* CMD 14 */
+       for (i = 0; i < 2; i++) {
+               cmd.args[0] = CMD_TUNERINIT;
+               cmd.args[1] = (u8) i;
+               cmd.args[2] = 0x00;
+               cmd.args[3] = 0x05;
+               cmd.args[4] = 0x00;
+               cmd.args[5] = 0x00;
+               cmd.args[6] = 0x55;
+               cmd.args[7] = 0x00;
+               cmd.len = 8;
+               ret = cx24117_cmd_execute_nolock(fe, &cmd);
+               if (ret != 0)
+                       goto error;
+       }
+
+       cx24117_writereg(state, 0xce, 0xc0);
+       cx24117_writereg(state, 0xcf, 0x00);
+       cx24117_writereg(state, 0xe5, 0x04);
+
+       /* Firmware CMD 35: Get firmware version */
+       cmd.args[0] = CMD_UPDFWVERS;
+       cmd.len = 2;
+       for (i = 0; i < 4; i++) {
+               cmd.args[1] = i;
+               ret = cx24117_cmd_execute_nolock(fe, &cmd);
+               if (ret != 0)
+                       goto error;
+               vers[i] = cx24117_readreg(state, 0x33);
+       }
+       dev_info(&state->priv->i2c->dev,
+               "%s: FW version %i.%i.%i.%i\n", __func__,
+               vers[0], vers[1], vers[2], vers[3]);
+       return 0;
+error:
+       state->priv->skip_fw_load = 0;
+       dev_err(&state->priv->i2c->dev, "%s() Error running FW.\n", __func__);
+       return ret;
+}
+
+static int cx24117_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int lock;
+
+       lock = cx24117_readreg(state,
+               (state->demod == 0) ? CX24117_REG_SSTATUS0 :
+                                     CX24117_REG_SSTATUS1) &
+               CX24117_STATUS_MASK;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d status = 0x%02x\n",
+               __func__, state->demod, lock);
+
+       *status = 0;
+
+       if (lock & CX24117_HAS_SIGNAL)
+               *status |= FE_HAS_SIGNAL;
+       if (lock & CX24117_HAS_CARRIER)
+               *status |= FE_HAS_CARRIER;
+       if (lock & CX24117_HAS_VITERBI)
+               *status |= FE_HAS_VITERBI;
+       if (lock & CX24117_HAS_SYNCLOCK)
+               *status |= FE_HAS_SYNC | FE_HAS_LOCK;
+
+       return 0;
+}
+
+static int cx24117_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int ret;
+       u8 buf[4];
+       u8 base_reg = (state->demod == 0) ?
+                       CX24117_REG_BER4_0 :
+                       CX24117_REG_BER4_1;
+
+       ret = cx24117_readregN(state, base_reg, buf, 4);
+       if (ret != 0)
+               return ret;
+
+       *ber = (buf[0] << 24) | (buf[1] << 16) |
+               (buf[1] << 8) | buf[0];
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d ber=0x%04x\n",
+               __func__, state->demod, *ber);
+
+       return 0;
+}
+
+static int cx24117_read_signal_strength(struct dvb_frontend *fe,
+       u16 *signal_strength)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct cx24117_cmd cmd;
+       int ret;
+       u16 sig_reading;
+       u8 buf[2];
+       u8 reg = (state->demod == 0) ?
+               CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1;
+
+       /* Firmware CMD 1A */
+       cmd.args[0] = 0x1a;
+       cmd.args[1] = (u8) state->demod;
+       cmd.len = 2;
+       ret = cx24117_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       ret = cx24117_readregN(state, reg, buf, 2);
+       if (ret != 0)
+               return ret;
+       sig_reading = ((buf[0] & CX24117_SIGNAL_MASK) << 2) | buf[1];
+
+       *signal_strength = -100 * sig_reading + 94324;
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s() demod%d raw / cooked = 0x%04x / 0x%04x\n",
+               __func__, state->demod, sig_reading, *signal_strength);
+
+       return 0;
+}
+
+static int cx24117_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int ret;
+       u8 buf[2];
+       u8 reg = (state->demod == 0) ?
+               CX24117_REG_QUALITY2_0 : CX24117_REG_QUALITY2_1;
+
+       ret = cx24117_readregN(state, reg, buf, 2);
+       if (ret != 0)
+               return ret;
+
+       *snr = (buf[0] << 8) | buf[1];
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s() demod%d snr = 0x%04x\n",
+               __func__, state->demod, *snr);
+
+       return ret;
+}
+
+static int cx24117_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       fe_delivery_system_t delsys = fe->dtv_property_cache.delivery_system;
+       int ret;
+       u8 buf[2];
+       u8 reg = (state->demod == 0) ?
+               CX24117_REG_DVBS_UCB2_0 :
+               CX24117_REG_DVBS_UCB2_1;
+
+       switch (delsys) {
+       case SYS_DVBS:
+               break;
+       case SYS_DVBS2:
+               reg += (CX24117_REG_DVBS2_UCB2_0 - CX24117_REG_DVBS_UCB2_0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       ret = cx24117_readregN(state, reg, buf, 2);
+       if (ret != 0)
+               return ret;
+       *ucblocks = (buf[0] << 8) | buf[1];
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d ucb=0x%04x\n",
+               __func__, state->demod, *ucblocks);
+
+       return 0;
+}
+
+/* Overwrite the current tuning params, we are about to tune */
+static void cx24117_clone_params(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       state->dcur = state->dnxt;
+}
+
+/* Wait for LNB */
+static int cx24117_wait_for_lnb(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int i;
+       u8 val, reg = (state->demod == 0) ? CX24117_REG_QSTATUS0 :
+                                           CX24117_REG_QSTATUS1;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d qstatus = 0x%02x\n",
+               __func__, state->demod, cx24117_readreg(state, reg));
+
+       /* Wait for up to 300 ms */
+       for (i = 0; i < 10; i++) {
+               val = cx24117_readreg(state, reg) & 0x01;
+               if (val != 0)
+                       return 0;
+               msleep(30);
+       }
+
+       dev_warn(&state->priv->i2c->dev, "%s: demod%d LNB not ready\n",
+               KBUILD_MODNAME, state->demod);
+
+       return -ETIMEDOUT; /* -EBUSY ? */
+}
+
+static int cx24117_set_voltage(struct dvb_frontend *fe,
+       fe_sec_voltage_t voltage)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct cx24117_cmd cmd;
+       int ret;
+       u8 reg = (state->demod == 0) ? 0x10 : 0x20;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d %s\n",
+               __func__, state->demod,
+               voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
+               voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" :
+               "SEC_VOLTAGE_OFF");
+
+       /* CMD 32 */
+       cmd.args[0] = 0x32;
+       cmd.args[1] = reg;
+       cmd.args[2] = reg;
+       cmd.len = 3;
+       ret = cx24117_cmd_execute(fe, &cmd);
+       if (ret)
+               return ret;
+
+       if ((voltage == SEC_VOLTAGE_13) ||
+           (voltage == SEC_VOLTAGE_18)) {
+               /* CMD 33 */
+               cmd.args[0] = 0x33;
+               cmd.args[1] = reg;
+               cmd.args[2] = reg;
+               cmd.len = 3;
+               ret = cx24117_cmd_execute(fe, &cmd);
+               if (ret != 0)
+                       return ret;
+
+               ret = cx24117_wait_for_lnb(fe);
+               if (ret != 0)
+                       return ret;
+
+               /* Wait for voltage/min repeat delay */
+               msleep(100);
+
+               /* CMD 22 - CMD_LNBDCLEVEL */
+               cmd.args[0] = CMD_LNBDCLEVEL;
+               cmd.args[1] = state->demod ? 0 : 1;
+               cmd.args[2] = (voltage == SEC_VOLTAGE_18 ? 0x01 : 0x00);
+               cmd.len = 3;
+
+               /* Min delay time before DiSEqC send */
+               msleep(20);
+       } else {
+               cmd.args[0] = 0x33;
+               cmd.args[1] = 0x00;
+               cmd.args[2] = reg;
+               cmd.len = 3;
+       }
+
+       return cx24117_cmd_execute(fe, &cmd);
+}
+
+static int cx24117_set_tone(struct dvb_frontend *fe,
+       fe_sec_tone_mode_t tone)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct cx24117_cmd cmd;
+       int ret;
+
+       dev_dbg(&state->priv->i2c->dev, "%s(%d) demod%d\n",
+               __func__, state->demod, tone);
+       if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) {
+               dev_warn(&state->priv->i2c->dev, "%s: demod%d invalid tone=%d\n",
+                       KBUILD_MODNAME, state->demod, tone);
+               return -EINVAL;
+       }
+
+       /* Wait for LNB ready */
+       ret = cx24117_wait_for_lnb(fe);
+       if (ret != 0)
+               return ret;
+
+       /* Min delay time after DiSEqC send */
+       msleep(20);
+
+       /* Set the tone */
+       /* CMD 23 - CMD_SET_TONE */
+       cmd.args[0] = CMD_SET_TONE;
+       cmd.args[1] = (state->demod ? 0 : 1);
+       cmd.args[2] = 0x00;
+       cmd.args[3] = 0x00;
+       cmd.len = 5;
+       switch (tone) {
+       case SEC_TONE_ON:
+               cmd.args[4] = 0x01;
+               break;
+       case SEC_TONE_OFF:
+               cmd.args[4] = 0x00;
+               break;
+       }
+
+       msleep(20);
+
+       return cx24117_cmd_execute(fe, &cmd);
+}
+
+/* Initialise DiSEqC */
+static int cx24117_diseqc_init(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+
+       /* Prepare a DiSEqC command */
+       state->dsec_cmd.args[0] = CMD_LNBSEND;
+
+       /* demod */
+       state->dsec_cmd.args[CX24117_DISEQC_DEMOD] = state->demod ? 0 : 1;
+
+       /* DiSEqC burst */
+       state->dsec_cmd.args[CX24117_DISEQC_BURST] = CX24117_DISEQC_MINI_A;
+
+       /* Unknown */
+       state->dsec_cmd.args[CX24117_DISEQC_ARG3_2] = 0x02;
+       state->dsec_cmd.args[CX24117_DISEQC_ARG4_0] = 0x00;
+
+       /* Continuation flag? */
+       state->dsec_cmd.args[CX24117_DISEQC_ARG5_0] = 0x00;
+
+       /* DiSEqC message length */
+       state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] = 0x00;
+
+       /* Command length */
+       state->dsec_cmd.len = 7;
+
+       return 0;
+}
+
+/* Send DiSEqC message */
+static int cx24117_send_diseqc_msg(struct dvb_frontend *fe,
+       struct dvb_diseqc_master_cmd *d)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       int i, ret;
+
+       /* Dump DiSEqC message */
+       dev_dbg(&state->priv->i2c->dev, "%s: demod %d (",
+               __func__, state->demod);
+       for (i = 0; i < d->msg_len; i++)
+               dev_dbg(&state->priv->i2c->dev, "0x%02x ", d->msg[i]);
+       dev_dbg(&state->priv->i2c->dev, ")\n");
+
+       /* Validate length */
+       if (d->msg_len > 15)
+               return -EINVAL;
+
+       /* DiSEqC message */
+       for (i = 0; i < d->msg_len; i++)
+               state->dsec_cmd.args[CX24117_DISEQC_MSGOFS + i] = d->msg[i];
+
+       /* DiSEqC message length */
+       state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] = d->msg_len;
+
+       /* Command length */
+       state->dsec_cmd.len = CX24117_DISEQC_MSGOFS +
+               state->dsec_cmd.args[CX24117_DISEQC_MSGLEN];
+
+       /*
+        * Message is sent with derived else cached burst
+        *
+        * WRITE PORT GROUP COMMAND 38
+        *
+        * 0/A/A: E0 10 38 F0..F3
+        * 1/B/B: E0 10 38 F4..F7
+        * 2/C/A: E0 10 38 F8..FB
+        * 3/D/B: E0 10 38 FC..FF
+        *
+        * databyte[3]= 8421:8421
+        *              ABCD:WXYZ
+        *              CLR :SET
+        *
+        *              WX= PORT SELECT 0..3    (X=TONEBURST)
+        *              Y = VOLTAGE             (0=13V, 1=18V)
+        *              Z = BAND                (0=LOW, 1=HIGH(22K))
+        */
+       if (d->msg_len >= 4 && d->msg[2] == 0x38)
+               state->dsec_cmd.args[CX24117_DISEQC_BURST] =
+                       ((d->msg[3] & 4) >> 2);
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d burst=%d\n",
+               __func__, state->demod,
+               state->dsec_cmd.args[CX24117_DISEQC_BURST]);
+
+       /* Wait for LNB ready */
+       ret = cx24117_wait_for_lnb(fe);
+       if (ret != 0)
+               return ret;
+
+       /* Wait for voltage/min repeat delay */
+       msleep(100);
+
+       /* Command */
+       ret = cx24117_cmd_execute(fe, &state->dsec_cmd);
+       if (ret != 0)
+               return ret;
+       /*
+        * Wait for send
+        *
+        * Eutelsat spec:
+        * >15ms delay          + (XXX determine if FW does this, see set_tone)
+        *  13.5ms per byte     +
+        * >15ms delay          +
+        *  12.5ms burst        +
+        * >15ms delay            (XXX determine if FW does this, see set_tone)
+        */
+       msleep((state->dsec_cmd.args[CX24117_DISEQC_MSGLEN] << 4) + 60);
+
+       return 0;
+}
+
+/* Send DiSEqC burst */
+static int cx24117_diseqc_send_burst(struct dvb_frontend *fe,
+       fe_sec_mini_cmd_t burst)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+
+       dev_dbg(&state->priv->i2c->dev, "%s(%d) demod=%d\n",
+               __func__, burst, state->demod);
+
+       /* DiSEqC burst */
+       if (burst == SEC_MINI_A)
+               state->dsec_cmd.args[CX24117_DISEQC_BURST] =
+                       CX24117_DISEQC_MINI_A;
+       else if (burst == SEC_MINI_B)
+               state->dsec_cmd.args[CX24117_DISEQC_BURST] =
+                       CX24117_DISEQC_MINI_B;
+       else
+               return -EINVAL;
+
+       return 0;
+}
+
+static int cx24117_get_priv(struct cx24117_priv **priv,
+       struct i2c_adapter *i2c, u8 client_address)
+{
+       int ret;
+
+       mutex_lock(&cx24117_list_mutex);
+       ret = hybrid_tuner_request_state(struct cx24117_priv, (*priv),
+               hybrid_tuner_instance_list, i2c, client_address, "cx24117");
+       mutex_unlock(&cx24117_list_mutex);
+
+       return ret;
+}
+
+static void cx24117_release_priv(struct cx24117_priv *priv)
+{
+       mutex_lock(&cx24117_list_mutex);
+       if (priv != NULL)
+               hybrid_tuner_release_state(priv);
+       mutex_unlock(&cx24117_list_mutex);
+}
+
+static void cx24117_release(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       dev_dbg(&state->priv->i2c->dev, "%s demod%d\n",
+               __func__, state->demod);
+       cx24117_release_priv(state->priv);
+       kfree(state);
+}
+
+static struct dvb_frontend_ops cx24117_ops;
+
+struct dvb_frontend *cx24117_attach(const struct cx24117_config *config,
+       struct i2c_adapter *i2c)
+{
+       struct cx24117_state *state = NULL;
+       struct cx24117_priv *priv = NULL;
+       int demod = 0;
+
+       /* get the common data struct for both demods */
+       demod = cx24117_get_priv(&priv, i2c, config->demod_address);
+
+       switch (demod) {
+       case 0:
+               dev_err(&state->priv->i2c->dev,
+                       "%s: Error attaching frontend %d\n",
+                       KBUILD_MODNAME, demod);
+               goto error1;
+               break;
+       case 1:
+               /* new priv instance */
+               priv->i2c = i2c;
+               priv->demod_address = config->demod_address;
+               mutex_init(&priv->fe_lock);
+               break;
+       default:
+               /* existing priv instance */
+               break;
+       }
+
+       /* allocate memory for the internal state */
+       state = kzalloc(sizeof(struct cx24117_state), GFP_KERNEL);
+       if (state == NULL)
+               goto error2;
+
+       state->demod = demod - 1;
+       state->priv = priv;
+
+       /* test i2c bus for ack */
+       if (demod == 0) {
+               if (cx24117_readreg(state, 0x00) < 0)
+                       goto error3;
+       }
+
+       dev_info(&state->priv->i2c->dev,
+               "%s: Attaching frontend %d\n",
+               KBUILD_MODNAME, state->demod);
+
+       /* create dvb_frontend */
+       memcpy(&state->frontend.ops, &cx24117_ops,
+               sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+       return &state->frontend;
+
+error3:
+       kfree(state);
+error2:
+       cx24117_release_priv(priv);
+error1:
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(cx24117_attach);
+
+/*
+ * Initialise or wake up device
+ *
+ * Power config will reset and load initial firmware if required
+ */
+static int cx24117_initfe(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct cx24117_cmd cmd;
+       int ret;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
+               __func__, state->demod);
+
+       mutex_lock(&state->priv->fe_lock);
+
+       /* Firmware CMD 36: Power config */
+       cmd.args[0] = CMD_TUNERSLEEP;
+       cmd.args[1] = (state->demod ? 1 : 0);
+       cmd.args[2] = 0;
+       cmd.len = 3;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+       if (ret != 0)
+               goto exit;
+
+       ret = cx24117_diseqc_init(fe);
+       if (ret != 0)
+               goto exit;
+
+       /* CMD 3C */
+       cmd.args[0] = 0x3c;
+       cmd.args[1] = (state->demod ? 1 : 0);
+       cmd.args[2] = 0x10;
+       cmd.args[3] = 0x10;
+       cmd.len = 4;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+       if (ret != 0)
+               goto exit;
+
+       /* CMD 34 */
+       cmd.args[0] = 0x34;
+       cmd.args[1] = (state->demod ? 1 : 0);
+       cmd.args[2] = CX24117_OCC;
+       cmd.len = 3;
+       ret = cx24117_cmd_execute_nolock(fe, &cmd);
+
+exit:
+       mutex_unlock(&state->priv->fe_lock);
+
+       return ret;
+}
+
+/*
+ * Put device to sleep
+ */
+static int cx24117_sleep(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct cx24117_cmd cmd;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
+               __func__, state->demod);
+
+       /* Firmware CMD 36: Power config */
+       cmd.args[0] = CMD_TUNERSLEEP;
+       cmd.args[1] = (state->demod ? 1 : 0);
+       cmd.args[2] = 1;
+       cmd.len = 3;
+       return cx24117_cmd_execute(fe, &cmd);
+}
+
+/* dvb-core told us to tune, the tv property cache will be complete,
+ * it's safe for is to pull values and use them for tuning purposes.
+ */
+static int cx24117_set_frontend(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       struct cx24117_cmd cmd;
+       fe_status_t tunerstat;
+       int i, status, ret, retune = 1;
+       u8 reg_clkdiv, reg_ratediv;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
+               __func__, state->demod);
+
+       switch (c->delivery_system) {
+       case SYS_DVBS:
+               dev_dbg(&state->priv->i2c->dev, "%s() demod%d DVB-S\n",
+                       __func__, state->demod);
+
+               /* Only QPSK is supported for DVB-S */
+               if (c->modulation != QPSK) {
+                       dev_dbg(&state->priv->i2c->dev,
+                               "%s() demod%d unsupported modulation (%d)\n",
+                               __func__, state->demod, c->modulation);
+                       return -EINVAL;
+               }
+
+               /* Pilot doesn't exist in DVB-S, turn bit off */
+               state->dnxt.pilot_val = CX24117_PILOT_OFF;
+
+               /* DVB-S only supports 0.35 */
+               state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
+               break;
+
+       case SYS_DVBS2:
+               dev_dbg(&state->priv->i2c->dev, "%s() demod%d DVB-S2\n",
+                       __func__, state->demod);
+
+               /*
+                * NBC 8PSK/QPSK with DVB-S is supported for DVB-S2,
+                * but not hardware auto detection
+                */
+               if (c->modulation != PSK_8 && c->modulation != QPSK) {
+                       dev_dbg(&state->priv->i2c->dev,
+                               "%s() demod%d unsupported modulation (%d)\n",
+                               __func__, state->demod, c->modulation);
+                       return -EOPNOTSUPP;
+               }
+
+               switch (c->pilot) {
+               case PILOT_AUTO:
+                       state->dnxt.pilot_val = CX24117_PILOT_AUTO;
+                       break;
+               case PILOT_OFF:
+                       state->dnxt.pilot_val = CX24117_PILOT_OFF;
+                       break;
+               case PILOT_ON:
+                       state->dnxt.pilot_val = CX24117_PILOT_ON;
+                       break;
+               default:
+                       dev_dbg(&state->priv->i2c->dev,
+                               "%s() demod%d unsupported pilot mode (%d)\n",
+                               __func__, state->demod, c->pilot);
+                       return -EOPNOTSUPP;
+               }
+
+               switch (c->rolloff) {
+               case ROLLOFF_20:
+                       state->dnxt.rolloff_val = CX24117_ROLLOFF_020;
+                       break;
+               case ROLLOFF_25:
+                       state->dnxt.rolloff_val = CX24117_ROLLOFF_025;
+                       break;
+               case ROLLOFF_35:
+                       state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
+                       break;
+               case ROLLOFF_AUTO:
+                       state->dnxt.rolloff_val = CX24117_ROLLOFF_035;
+                       /* soft-auto rolloff */
+                       retune = 3;
+                       break;
+               default:
+                       dev_warn(&state->priv->i2c->dev,
+                               "%s: demod%d unsupported rolloff (%d)\n",
+                               KBUILD_MODNAME, state->demod, c->rolloff);
+                       return -EOPNOTSUPP;
+               }
+               break;
+
+       default:
+               dev_warn(&state->priv->i2c->dev,
+                       "%s: demod %d unsupported delivery system (%d)\n",
+                       KBUILD_MODNAME, state->demod, c->delivery_system);
+               return -EINVAL;
+       }
+
+       state->dnxt.delsys = c->delivery_system;
+       state->dnxt.modulation = c->modulation;
+       state->dnxt.frequency = c->frequency;
+       state->dnxt.pilot = c->pilot;
+       state->dnxt.rolloff = c->rolloff;
+
+       ret = cx24117_set_inversion(state, c->inversion);
+       if (ret !=  0)
+               return ret;
+
+       ret = cx24117_set_fec(state,
+               c->delivery_system, c->modulation, c->fec_inner);
+       if (ret !=  0)
+               return ret;
+
+       ret = cx24117_set_symbolrate(state, c->symbol_rate);
+       if (ret !=  0)
+               return ret;
+
+       /* discard the 'current' tuning parameters and prepare to tune */
+       cx24117_clone_params(fe);
+
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: delsys      = %d\n", __func__, state->dcur.delsys);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: modulation  = %d\n", __func__, state->dcur.modulation);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: frequency   = %d\n", __func__, state->dcur.frequency);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: pilot       = %d (val = 0x%02x)\n", __func__,
+               state->dcur.pilot, state->dcur.pilot_val);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: retune      = %d\n", __func__, retune);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: rolloff     = %d (val = 0x%02x)\n", __func__,
+               state->dcur.rolloff, state->dcur.rolloff_val);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: symbol_rate = %d\n", __func__, state->dcur.symbol_rate);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: FEC         = %d (mask/val = 0x%02x/0x%02x)\n", __func__,
+               state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
+       dev_dbg(&state->priv->i2c->dev,
+               "%s: Inversion   = %d (val = 0x%02x)\n", __func__,
+               state->dcur.inversion, state->dcur.inversion_val);
+
+       /* Prepare a tune request */
+       cmd.args[0] = CMD_TUNEREQUEST;
+
+       /* demod */
+       cmd.args[1] = state->demod;
+
+       /* Frequency */
+       cmd.args[2] = (state->dcur.frequency & 0xff0000) >> 16;
+       cmd.args[3] = (state->dcur.frequency & 0x00ff00) >> 8;
+       cmd.args[4] = (state->dcur.frequency & 0x0000ff);
+
+       /* Symbol Rate */
+       cmd.args[5] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;
+       cmd.args[6] = ((state->dcur.symbol_rate / 1000) & 0x00ff);
+
+       /* Automatic Inversion */
+       cmd.args[7] = state->dcur.inversion_val;
+
+       /* Modulation / FEC / Pilot */
+       cmd.args[8] = state->dcur.fec_val | state->dcur.pilot_val;
+
+       cmd.args[9] = CX24117_SEARCH_RANGE_KHZ >> 8;
+       cmd.args[10] = CX24117_SEARCH_RANGE_KHZ & 0xff;
+
+       cmd.args[11] = state->dcur.rolloff_val;
+       cmd.args[12] = state->dcur.fec_mask;
+
+       if (state->dcur.symbol_rate > 30000000) {
+               reg_ratediv = 0x04;
+               reg_clkdiv = 0x02;
+       } else if (state->dcur.symbol_rate > 10000000) {
+               reg_ratediv = 0x06;
+               reg_clkdiv = 0x03;
+       } else {
+               reg_ratediv = 0x0a;
+               reg_clkdiv = 0x05;
+       }
+
+       cmd.args[13] = reg_ratediv;
+       cmd.args[14] = reg_clkdiv;
+
+       cx24117_writereg(state, (state->demod == 0) ?
+               CX24117_REG_CLKDIV0 : CX24117_REG_CLKDIV1, reg_clkdiv);
+       cx24117_writereg(state, (state->demod == 0) ?
+               CX24117_REG_RATEDIV0 : CX24117_REG_RATEDIV1, reg_ratediv);
+
+       cmd.args[15] = CX24117_PNE;
+       cmd.len = 16;
+
+       do {
+               /* Reset status register */
+               status = cx24117_readreg(state, (state->demod == 0) ?
+                       CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1) &
+                       CX24117_SIGNAL_MASK;
+
+               dev_dbg(&state->priv->i2c->dev,
+                       "%s() demod%d status_setfe = %02x\n",
+                       __func__, state->demod, status);
+
+               cx24117_writereg(state, (state->demod == 0) ?
+                       CX24117_REG_SSTATUS0 : CX24117_REG_SSTATUS1, status);
+
+               /* Tune */
+               ret = cx24117_cmd_execute(fe, &cmd);
+               if (ret != 0)
+                       break;
+
+               /*
+                * Wait for up to 500 ms before retrying
+                *
+                * If we are able to tune then generally it occurs within 100ms.
+                * If it takes longer, try a different rolloff setting.
+                */
+               for (i = 0; i < 50; i++) {
+                       cx24117_read_status(fe, &tunerstat);
+                       status = tunerstat & (FE_HAS_SIGNAL | FE_HAS_SYNC);
+                       if (status == (FE_HAS_SIGNAL | FE_HAS_SYNC)) {
+                               dev_dbg(&state->priv->i2c->dev,
+                                       "%s() demod%d tuned\n",
+                                       __func__, state->demod);
+                               return 0;
+                       }
+                       msleep(20);
+               }
+
+               dev_dbg(&state->priv->i2c->dev, "%s() demod%d not tuned\n",
+                       __func__, state->demod);
+
+               /* try next rolloff value */
+               if (state->dcur.rolloff == 3)
+                       cmd.args[11]--;
+
+       } while (--retune);
+       return -EINVAL;
+}
+
+static int cx24117_tune(struct dvb_frontend *fe, bool re_tune,
+       unsigned int mode_flags, unsigned int *delay, fe_status_t *status)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+
+       dev_dbg(&state->priv->i2c->dev, "%s() demod%d\n",
+               __func__, state->demod);
+
+       *delay = HZ / 5;
+       if (re_tune) {
+               int ret = cx24117_set_frontend(fe);
+               if (ret)
+                       return ret;
+       }
+       return cx24117_read_status(fe, status);
+}
+
+static int cx24117_get_algo(struct dvb_frontend *fe)
+{
+       return DVBFE_ALGO_HW;
+}
+
+static int cx24117_get_frontend(struct dvb_frontend *fe)
+{
+       struct cx24117_state *state = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       struct cx24117_cmd cmd;
+       u8 reg, st, inv;
+       int ret, idx;
+       unsigned int freq;
+       short srate_os, freq_os;
+
+       u8 buf[0x1f-4];
+
+       cmd.args[0] = 0x1c;
+       cmd.args[1] = (u8) state->demod;
+       cmd.len = 2;
+       ret = cx24117_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       /* read all required regs at once */
+       reg = (state->demod == 0) ? CX24117_REG_FREQ3_0 : CX24117_REG_FREQ3_1;
+       ret = cx24117_readregN(state, reg, buf, 0x1f-4);
+       if (ret != 0)
+               return ret;
+
+       st = buf[5];
+
+       /* get spectral inversion */
+       inv = (((state->demod == 0) ? ~st : st) >> 6) & 1;
+       if (inv == 0)
+               c->inversion = INVERSION_OFF;
+       else
+               c->inversion = INVERSION_ON;
+
+       /* modulation and fec */
+       idx = st & 0x3f;
+       if (c->delivery_system == SYS_DVBS2) {
+               if (idx > 11)
+                       idx += 9;
+               else
+                       idx += 7;
+       }
+
+       c->modulation = cx24117_modfec_modes[idx].modulation;
+       c->fec_inner = cx24117_modfec_modes[idx].fec;
+
+       /* frequency */
+       freq = (buf[0] << 16) | (buf[1] << 8) | buf[2];
+       freq_os = (buf[8] << 8) | buf[9];
+       c->frequency = freq + freq_os;
+
+       /* symbol rate */
+       srate_os = (buf[10] << 8) | buf[11];
+       c->symbol_rate = -1000 * srate_os + state->dcur.symbol_rate;
+       return 0;
+}
+
+static struct dvb_frontend_ops cx24117_ops = {
+       .delsys = { SYS_DVBS, SYS_DVBS2 },
+       .info = {
+               .name = "Conexant CX24117/CX24132",
+               .frequency_min = 950000,
+               .frequency_max = 2150000,
+               .frequency_stepsize = 1011, /* kHz for QPSK frontends */
+               .frequency_tolerance = 5000,
+               .symbol_rate_min = 1000000,
+               .symbol_rate_max = 45000000,
+               .caps = FE_CAN_INVERSION_AUTO |
+                       FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
+                       FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
+                       FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
+                       FE_CAN_2G_MODULATION |
+                       FE_CAN_QPSK | FE_CAN_RECOVER
+       },
+
+       .release = cx24117_release,
+
+       .init = cx24117_initfe,
+       .sleep = cx24117_sleep,
+       .read_status = cx24117_read_status,
+       .read_ber = cx24117_read_ber,
+       .read_signal_strength = cx24117_read_signal_strength,
+       .read_snr = cx24117_read_snr,
+       .read_ucblocks = cx24117_read_ucblocks,
+       .set_tone = cx24117_set_tone,
+       .set_voltage = cx24117_set_voltage,
+       .diseqc_send_master_cmd = cx24117_send_diseqc_msg,
+       .diseqc_send_burst = cx24117_diseqc_send_burst,
+       .get_frontend_algo = cx24117_get_algo,
+       .tune = cx24117_tune,
+
+       .set_frontend = cx24117_set_frontend,
+       .get_frontend = cx24117_get_frontend,
+};
+
+
+MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24117/cx24132 hardware");
+MODULE_AUTHOR("Luis Alves (ljalvs@gmail.com)");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("1.1");
+MODULE_FIRMWARE(CX24117_DEFAULT_FIRMWARE);
+
diff --git a/drivers/media/dvb-frontends/cx24117.h b/drivers/media/dvb-frontends/cx24117.h
new file mode 100644 (file)
index 0000000..4e59e95
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+    Conexant cx24117/cx24132 - Dual DVBS/S2 Satellite demod/tuner driver
+
+    Copyright (C) 2013 Luis Alves <ljalvs@gmail.com>
+       (based on cx24116.h by Steven Toth)
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef CX24117_H
+#define CX24117_H
+
+#include <linux/kconfig.h>
+#include <linux/dvb/frontend.h>
+
+struct cx24117_config {
+       /* the demodulator's i2c address */
+       u8 demod_address;
+};
+
+#if IS_ENABLED(CONFIG_DVB_CX24117)
+extern struct dvb_frontend *cx24117_attach(
+       const struct cx24117_config *config,
+       struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *cx24117_attach(
+       const struct cx24117_config *config,
+       struct i2c_adapter *i2c)
+{
+       dev_warn(&i2c->dev, "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif
+
+#endif /* CX24117_H */
index a771da3e9f99afc53d8c21179417df8e2feb539c..72fb5838cae0d7aec7f51bd83bebe5b0afe459b6 100644 (file)
@@ -739,7 +739,7 @@ static int cx24123_set_voltage(struct dvb_frontend *fe,
                return 0;
        default:
                return -EINVAL;
-       };
+       }
 
        return 0;
 }
index 7ca5c69dd2007202c2f3492615019f0055393558..03930d5e9fea4cbf2a5787aad71d08af809544fa 100644 (file)
 
 #include "cxd2820r_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /* write multiple registers */
 static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
        u8 *val, int len)
 {
        int ret;
-       u8 buf[len+1];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = i2c,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = len + 1,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
@@ -55,7 +65,7 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
        u8 *val, int len)
 {
        int ret;
-       u8 buf[len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[2] = {
                {
                        .addr = i2c,
@@ -65,11 +75,18 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
                }, {
                        .addr = i2c,
                        .flags = I2C_M_RD,
-                       .len = sizeof(buf),
+                       .len = len,
                        .buf = buf,
                }
        };
 
+       if (len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        ret = i2c_transfer(priv->i2c, msg, 2);
        if (ret == 2) {
                memcpy(val, buf, len);
index 6201c59a78dd6ad24de4b27ee191b79c4aafdab7..e540cfb13bac4b15dbfa06d1c050e0ad1246fcd0 100644 (file)
@@ -649,9 +649,9 @@ static int dib9000_risc_debug_buf(struct dib9000_state *state, u16 * data, u8 si
        b[2 * (size - 2) - 1] = '\0';   /* Bullet proof the buffer */
        if (*b == '~') {
                b++;
-               dprintk(b);
+               dprintk("%s", b);
        } else
-               dprintk("RISC%d: %d.%04d %s", state->fe_id, ts / 10000, ts % 10000, *b ? b : "<emtpy>");
+               dprintk("RISC%d: %d.%04d %s", state->fe_id, ts / 10000, ts % 10000, *b ? b : "<empty>");
        return 1;
 }
 
index 9a2134792cfae676d29a02e57acdc58d7c2d34de..959ae36403b827263d6b028f919f2fe9fe2fa224 100644 (file)
 #define DRX_I2C_MODEFLAGS     0xC0
 #define DRX_I2C_FLAGS         0xF0
 
-#ifndef SIZEOF_ARRAY
-#define SIZEOF_ARRAY(array) (sizeof((array))/sizeof((array)[0]))
-#endif
-
 #define DEFAULT_LOCK_TIMEOUT    1100
 
 #define DRX_CHANNEL_AUTO 0
@@ -1018,7 +1014,7 @@ static int HI_CfgCommand(struct drxd_state *state)
                status = Write16(state, HI_RA_RAM_SRV_CMD__A,
                                 HI_RA_RAM_SRV_CMD_CONFIG, 0);
        else
-               status = HI_Command(state, HI_RA_RAM_SRV_CMD_CONFIG, 0);
+               status = HI_Command(state, HI_RA_RAM_SRV_CMD_CONFIG, NULL);
        mutex_unlock(&state->mutex);
        return status;
 }
@@ -1039,7 +1035,7 @@ static int HI_ResetCommand(struct drxd_state *state)
        status = Write16(state, HI_RA_RAM_SRV_RST_KEY__A,
                         HI_RA_RAM_SRV_RST_KEY_ACT, 0);
        if (status == 0)
-               status = HI_Command(state, HI_RA_RAM_SRV_CMD_RESET, 0);
+               status = HI_Command(state, HI_RA_RAM_SRV_CMD_RESET, NULL);
        mutex_unlock(&state->mutex);
        msleep(1);
        return status;
@@ -2837,7 +2833,7 @@ static int drxd_init(struct dvb_frontend *fe)
        int err = 0;
 
 /*     if (request_firmware(&state->fw, "drxd.fw", state->dev)<0) */
-       return DRXD_init(state, 0, 0);
+       return DRXD_init(state, NULL, 0);
 
        err = DRXD_init(state, state->fw->data, state->fw->size);
        release_firmware(state->fw);
@@ -2973,7 +2969,7 @@ struct dvb_frontend *drxd_attach(const struct drxd_config *config,
 
        mutex_init(&state->mutex);
 
-       if (Read16(state, 0, 0, 0) < 0)
+       if (Read16(state, 0, NULL, 0) < 0)
                goto error;
 
        state->frontend.ops = drxd_ops;
index 082014de6875ed26a800bc15844bde5a0199c7f3..d416c15691dadd69b49eda6f26c70892c3a02652 100644 (file)
@@ -1083,7 +1083,7 @@ static int hi_cfg_command(struct drxk_state *state)
                         SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY);
        if (status < 0)
                goto error;
-       status = hi_command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0);
+       status = hi_command(state, SIO_HI_RA_RAM_CMD_CONFIG, NULL);
        if (status < 0)
                goto error;
 
@@ -2781,7 +2781,7 @@ static int ConfigureI2CBridge(struct drxk_state *state, bool b_enable_bridge)
                        goto error;
        }
 
-       status = hi_command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0);
+       status = hi_command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, NULL);
 
 error:
        if (status < 0)
index c1c3400b2173508d3ce2ba77b236d16c2eec48c9..cadcae4cff89122dbf90cad2d02cfa9fa13854b4 100644 (file)
@@ -31,6 +31,9 @@
 #include "itd1000.h"
 #include "itd1000_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static int debug;
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
@@ -52,10 +55,18 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
 /* don't write more than one byte with flexcop behind */
 static int itd1000_write_regs(struct itd1000_state *state, u8 reg, u8 v[], u8 len)
 {
-       u8 buf[1+len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg = {
                .addr = state->cfg->i2c_address, .flags = 0, .buf = buf, .len = len+1
        };
+
+       if (1 + len > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "itd1000: i2c wr reg=%04x: len=%d is too big!\n",
+                      reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], v, len);
 
index ec388c1d6913c73c9458d43695793ff833fcbd67..a74ac0ddb83310ab619870a0f465771ca451eb7a 100644 (file)
@@ -36,6 +36,8 @@
 #include "mt312_priv.h"
 #include "mt312.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
 
 struct mt312_state {
        struct i2c_adapter *i2c;
@@ -96,9 +98,15 @@ static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
                       const u8 *src, const size_t count)
 {
        int ret;
-       u8 buf[count + 1];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg;
 
+       if (1 + count > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "mt312: write: len=%zd is too big!\n", count);
+               return -EINVAL;
+       }
+
        if (debug) {
                int i;
                dprintk("W(%d):", reg & 0x7f);
index 8e288940a61fcb0654034dde41457de506e25a8f..fbca9856313a8b8a0cfb9fe34705c1f350e31a3e 100644 (file)
@@ -39,6 +39,9 @@
  */
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 #define NXT2002_DEFAULT_FIRMWARE "dvb-fe-nxt2002.fw"
 #define NXT2004_DEFAULT_FIRMWARE "dvb-fe-nxt2004.fw"
 #define CRC_CCIT_MASK 0x1021
@@ -95,10 +98,16 @@ static int i2c_readbytes(struct nxt200x_state *state, u8 addr, u8 *buf, u8 len)
 static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg,
                               const u8 *buf, u8 len)
 {
-       u8 buf2 [len+1];
+       u8 buf2[MAX_XFER_SIZE];
        int err;
        struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf2, .len = len + 1 };
 
+       if (1 + len > sizeof(buf2)) {
+               pr_warn("%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        __func__, reg, len);
+               return -EINVAL;
+       }
+
        buf2[0] = reg;
        memcpy(&buf2[1], buf, len);
 
index 362d26d11e82a4d1f975db097679c7d4bb7ddb97..7efb796c472c475bed62f1a0bb783f5b991a5b1e 100644 (file)
 
 #include "rtl2830_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /* write multiple hardware registers */
 static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len)
 {
        int ret;
-       u8 buf[1+len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg.i2c_addr,
                        .flags = 0,
-                       .len = 1+len,
+                       .len = 1 + len,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
index facb84841518e66cd274308af34009a16a8a7390..ff73da9365e3c7083a6dea2343f0de0bb27a3bb6 100644 (file)
@@ -22,6 +22,9 @@
 #include "dvb_math.h"
 #include <linux/bitops.h>
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 int rtl2832_debug;
 module_param_named(debug, rtl2832_debug, int, 0644);
 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
@@ -162,16 +165,23 @@ static const struct rtl2832_reg_entry registers[] = {
 static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len)
 {
        int ret;
-       u8 buf[1+len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg.i2c_addr,
                        .flags = 0,
-                       .len = 1+len,
+                       .len = 1 + len,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
@@ -489,6 +499,7 @@ static int rtl2832_init(struct dvb_frontend *fe)
                init = rtl2832_tuner_init_e4000;
                break;
        case RTL2832_TUNER_R820T:
+       case RTL2832_TUNER_R828D:
                len = ARRAY_SIZE(rtl2832_tuner_init_r820t);
                init = rtl2832_tuner_init_r820t;
                break;
index 91b2dcf5a6eaa429366de319ad58c405d708b398..2cfbb6a97061b166bac354c964a64a0e5a227eaa 100644 (file)
@@ -53,6 +53,7 @@ struct rtl2832_config {
 #define RTL2832_TUNER_E4000     0x27
 #define RTL2832_TUNER_FC0013    0x29
 #define RTL2832_TUNER_R820T    0x2a
+#define RTL2832_TUNER_R828D    0x2b
        u8 tuner;
 };
 
index e2fec9ebf947d6b5c0ca03eeb50befd233f6f19a..93eeaf7118fd0178a3dac53053f413bf4b733e3b 100644 (file)
@@ -836,9 +836,16 @@ static u32 s5h1420_tuner_i2c_func(struct i2c_adapter *adapter)
 static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
 {
        struct s5h1420_state *state = i2c_get_adapdata(i2c_adap);
-       struct i2c_msg m[1 + num];
+       struct i2c_msg m[3];
        u8 tx_open[2] = { CON_1, state->CON_1_val | 1 }; /* repeater stops once there was a stop condition */
 
+       if (1 + num > ARRAY_SIZE(m)) {
+               printk(KERN_WARNING
+                      "%s: i2c xfer: num=%d is too big!\n",
+                      KBUILD_MODNAME, num);
+               return  -EOPNOTSUPP;
+       }
+
        memset(m, 0, sizeof(struct i2c_msg) * (1 + num));
 
        m[0].addr = state->config->demod_address;
@@ -847,7 +854,7 @@ static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c
 
        memcpy(&m[1], msg, sizeof(struct i2c_msg) * num);
 
-       return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
+       return i2c_transfer(state->i2c, m, 1 + num) == 1 + num ? num : -EIO;
 }
 
 static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
index 3dd5714eadba579c62e347718a073db83889a13a..07cd5ea7a03811c1c01204ac9eb6b42458bb2a6f 100644 (file)
@@ -32,6 +32,9 @@
 #include "stb0899_priv.h"
 #include "stb0899_reg.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static unsigned int verbose = 0;//1;
 module_param(verbose, int, 0644);
 
@@ -499,7 +502,7 @@ err:
 int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count)
 {
        int ret;
-       u8 buf[2 + count];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg i2c_msg = {
                .addr   = state->config->demod_address,
                .flags  = 0,
@@ -507,6 +510,13 @@ int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data,
                .len    = 2 + count
        };
 
+       if (2 + count > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                      KBUILD_MODNAME, reg, count);
+               return -EINVAL;
+       }
+
        buf[0] = reg >> 8;
        buf[1] = reg & 0xff;
        memcpy(&buf[2], data, count);
index 45f9523f968f903d463d56f5baf927662b7ffbc0..cea175d1989076e8f53cc3550efefe7a48dabf88 100644 (file)
@@ -31,6 +31,8 @@
 static unsigned int verbose;
 module_param(verbose, int, 0644);
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
 
 #define FE_ERROR               0
 #define FE_NOTICE              1
@@ -183,7 +185,7 @@ static int stb6100_read_reg(struct stb6100_state *state, u8 reg)
 static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len)
 {
        int rc;
-       u8 cmdbuf[len + 1];
+       u8 cmdbuf[MAX_XFER_SIZE];
        struct i2c_msg msg = {
                .addr   = state->config->tuner_address,
                .flags  = 0,
@@ -191,6 +193,13 @@ static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int st
                .len    = len + 1
        };
 
+       if (1 + len > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr: len=%d is too big!\n",
+                      KBUILD_MODNAME, len);
+               return -EINVAL;
+       }
+
        if (unlikely(start < 1 || start + len > STB6100_NUMREGS)) {
                dprintk(verbose, FE_ERROR, 1, "Invalid register range %d:%d",
                        start, len);
index 7b6dba3ce55e2d0c3503fb1141c9d70d1b1f52a2..458772739423234388c50940bccbae9c3bb63bb6 100644 (file)
@@ -33,6 +33,9 @@
 #include "stv0367_regs.h"
 #include "stv0367_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static int stvdebug;
 module_param_named(debug, stvdebug, int, 0644);
 
@@ -767,7 +770,7 @@ static struct st_register def0367cab[STV0367CAB_NBREGS] = {
 static
 int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len)
 {
-       u8 buf[len + 2];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg = {
                .addr = state->config->demod_address,
                .flags = 0,
@@ -776,6 +779,14 @@ int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len)
        };
        int ret;
 
+       if (2 + len > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                      KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
+
        buf[0] = MSB(reg);
        buf[1] = LSB(reg);
        memcpy(buf + 2, data, len);
index 56d470ad5a823ae9825d7d36dcff383a6dfb87a4..23e872f8474286b205d6324a70b7a3637618e50c 100644 (file)
@@ -35,6 +35,9 @@
 #include "stv090x.h"
 #include "stv090x_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static unsigned int verbose;
 module_param(verbose, int, 0644);
 
@@ -722,9 +725,16 @@ static int stv090x_write_regs(struct stv090x_state *state, unsigned int reg, u8
 {
        const struct stv090x_config *config = state->config;
        int ret;
-       u8 buf[2 + count];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg i2c_msg = { .addr = config->address, .flags = 0, .buf = buf, .len = 2 + count };
 
+       if (2 + count > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                      KBUILD_MODNAME, reg, count);
+               return -EINVAL;
+       }
+
        buf[0] = reg >> 8;
        buf[1] = reg & 0xff;
        memcpy(&buf[2], data, count);
index 20b5fa92c53e7374977b55800ec95c831239966c..b1425830a24ea37fb0a081fcf95788e7891edfca 100644 (file)
@@ -30,6 +30,9 @@
 
 #include "stv6110.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static int debug;
 
 struct stv6110_priv {
@@ -68,7 +71,7 @@ static int stv6110_write_regs(struct dvb_frontend *fe, u8 buf[],
 {
        struct stv6110_priv *priv = fe->tuner_priv;
        int rc;
-       u8 cmdbuf[len + 1];
+       u8 cmdbuf[MAX_XFER_SIZE];
        struct i2c_msg msg = {
                .addr   = priv->i2c_address,
                .flags  = 0,
@@ -78,6 +81,13 @@ static int stv6110_write_regs(struct dvb_frontend *fe, u8 buf[],
 
        dprintk("%s\n", __func__);
 
+       if (1 + len > sizeof(cmdbuf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr: len=%d is too big!\n",
+                      KBUILD_MODNAME, len);
+               return -EINVAL;
+       }
+
        if (start + len > 8)
                return -EINVAL;
 
index f36cab12bdc71964a463a79e4553738f00126dca..e66154e5c1d7710e0ddcc8c6183f707be0e388ea 100644 (file)
@@ -32,6 +32,9 @@
 #include "stv6110x.h"
 #include "stv6110x_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static unsigned int verbose;
 module_param(verbose, int, 0644);
 MODULE_PARM_DESC(verbose, "Set Verbosity level");
@@ -61,7 +64,8 @@ static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 da
 {
        int ret;
        const struct stv6110x_config *config = stv6110x->config;
-       u8 buf[len + 1];
+       u8 buf[MAX_XFER_SIZE];
+
        struct i2c_msg msg = {
                .addr = config->addr,
                .flags = 0,
@@ -69,6 +73,13 @@ static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 da
                .len = len + 1
        };
 
+       if (1 + len > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr: len=%d is too big!\n",
+                      KBUILD_MODNAME, len);
+               return -EINVAL;
+       }
+
        if (start + len > 8)
                return -EINVAL;
 
index e79749cfec814b75f0ac84d2f5ad881399a79a75..8ad3a57cf64032446fb50fc28d2cfce6739bb18b 100644 (file)
@@ -20,6 +20,9 @@
 
 #include "tda10071_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static struct dvb_frontend_ops tda10071_ops;
 
 /* write multiple registers */
@@ -27,16 +30,23 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
        int len)
 {
        int ret;
-       u8 buf[len+1];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg.demod_i2c_addr,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = 1 + len,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
@@ -56,7 +66,7 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
        int len)
 {
        int ret;
-       u8 buf[len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[2] = {
                {
                        .addr = priv->cfg.demod_i2c_addr,
@@ -66,11 +76,18 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
                }, {
                        .addr = priv->cfg.demod_i2c_addr,
                        .flags = I2C_M_RD,
-                       .len = sizeof(buf),
+                       .len = len,
                        .buf = buf,
                }
        };
 
+       if (len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        ret = i2c_transfer(priv->i2c, msg, 2);
        if (ret == 2) {
                memcpy(val, buf, len);
index d281f77d5c2898e7d5da365afea9ca5e7bba8a7e..2c54586ac07f05d70b9afb95f993e7810ce5abce 100644 (file)
@@ -34,6 +34,9 @@
 #include "dvb_frontend.h"
 #include "tda18271c2dd.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 struct SStandardParam {
        s32   m_IFFrequency;
        u32   m_BandWidth;
@@ -139,11 +142,18 @@ static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 *data, int len)
 static int WriteRegs(struct tda_state *state,
                     u8 SubAddr, u8 *Regs, u16 nRegs)
 {
-       u8 data[nRegs+1];
+       u8 data[MAX_XFER_SIZE];
+
+       if (1 + nRegs > sizeof(data)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr: len=%d is too big!\n",
+                      KBUILD_MODNAME, nRegs);
+               return -EINVAL;
+       }
 
        data[0] = SubAddr;
        memcpy(data + 1, Regs, nRegs);
-       return i2c_write(state->i2c, state->adr, data, nRegs+1);
+       return i2c_write(state->i2c, state->adr, data, nRegs + 1);
 }
 
 static int WriteReg(struct tda_state *state, u8 SubAddr, u8 Reg)
index 9d08350fe4b035cca635d3368d75591897e4e035..69e62f42e2e1388c7d99ad15bffcd95c234d5d40 100644 (file)
@@ -189,7 +189,7 @@ static int tda8083_set_tone (struct tda8083_state* state, fe_sec_tone_mode_t ton
                return tda8083_writereg (state, 0x29, 0x80);
        default:
                return -EINVAL;
-       };
+       }
 }
 
 static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t voltage)
@@ -201,7 +201,7 @@ static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t vo
                return tda8083_writereg (state, 0x20, 0x11);
        default:
                return -EINVAL;
-       };
+       }
 }
 
 static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_cmd_t burst)
index ad7ad857ab2a9effdfc9a087c8c03ec3076db976..9aba044dabedbb1fe0610560854e3b7ecd28ac44 100644 (file)
@@ -31,6 +31,7 @@ struct ts2020_priv {
        struct i2c_adapter *i2c;
        u8 clk_out_div;
        u32 frequency;
+       u32 frequency_div;
 };
 
 static int ts2020_release(struct dvb_frontend *fe)
@@ -193,7 +194,7 @@ static int ts2020_set_params(struct dvb_frontend *fe)
        u8 lo = 0x01, div4 = 0x0;
 
        /* Calculate frequency divider */
-       if (frequency < 1060000) {
+       if (frequency < priv->frequency_div) {
                lo |= 0x10;
                div4 = 0x1;
                ndiv = (frequency * 14 * 4) / TS2020_XTAL_FREQ;
@@ -340,8 +341,12 @@ struct dvb_frontend *ts2020_attach(struct dvb_frontend *fe,
        priv->i2c_address = config->tuner_address;
        priv->i2c = i2c;
        priv->clk_out_div = config->clk_out_div;
+       priv->frequency_div = config->frequency_div;
        fe->tuner_priv = priv;
 
+       if (!priv->frequency_div)
+               priv->frequency_div = 1060000;
+
        /* Wake Up the tuner */
        if ((0x03 & ts2020_readreg(fe, 0x00)) == 0x00) {
                ts2020_writereg(fe, 0x00, 0x01);
index 5bcb9a71ca80ea6bca28ec1f3b12a47aa13eb13e..b2fe6bb3a38b0c425d2d31b167351382f1cae2dd 100644 (file)
@@ -28,6 +28,7 @@
 struct ts2020_config {
        u8 tuner_address;
        u8 clk_out_div;
+       u32 frequency_div;
 };
 
 #if IS_ENABLED(CONFIG_DVB_TS2020)
index eff9c5fde50ad65662948cb9109341a0c25a7e0f..91b6b2e9b79228b6c497f7c7aba65dd36415f9da 100644 (file)
@@ -30,6 +30,9 @@
 
 static int debug;
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 #define dprintk(args...) \
        do { \
                if (debug) \
@@ -98,7 +101,7 @@ static int zl10039_write(struct zl10039_state *state,
                        const enum zl10039_reg_addr reg, const u8 *src,
                        const size_t count)
 {
-       u8 buf[count + 1];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg = {
                .addr = state->i2c_addr,
                .flags = 0,
@@ -106,6 +109,13 @@ static int zl10039_write(struct zl10039_state *state,
                .len = count + 1,
        };
 
+       if (1 + count > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr reg=%04x: len=%zd is too big!\n",
+                      KBUILD_MODNAME, reg, count);
+               return -EINVAL;
+       }
+
        dprintk("%s\n", __func__);
        /* Write register address and data in one go */
        buf[0] = reg;
index d18be19c96cd3892ea070bf4b48bb32cde4aa817..842654d333177ad197326b8655b80b54bbdeae23 100644 (file)
@@ -621,6 +621,15 @@ config VIDEO_AS3645A
          This is a driver for the AS3645A and LM3555 flash controllers. It has
          build in control for flash, torch and indicator LEDs.
 
+config VIDEO_LM3560
+       tristate "LM3560 dual flash driver support"
+       depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+       depends on MEDIA_CAMERA_SUPPORT
+       select REGMAP_I2C
+       ---help---
+         This is a driver for the lm3560 dual flash controllers. It controls
+         flash, torch LEDs.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
@@ -646,7 +655,7 @@ config VIDEO_UPD64083
          To compile this driver as a module, choose M here: the
          module will be called upd64083.
 
-comment "Miscelaneous helper chips"
+comment "Miscellaneous helper chips"
 
 config VIDEO_THS7303
        tristate "THS7303/53 Video Amplifier"
index 9f462df77b4aee13ba756fa97500e435ef801bb5..e03f1776f4f4f416c2bd5a1d0ff63f503e976837 100644 (file)
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_S5K4ECGX)  += s5k4ecgx.o
 obj-$(CONFIG_VIDEO_S5C73M3)    += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)    += adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)    += as3645a.o
+obj-$(CONFIG_VIDEO_LM3560)     += lm3560.o
 obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
 obj-$(CONFIG_VIDEO_AK881X)             += ak881x.o
 obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
index 6f738d8e3a8f3ef708451ba99df2574c1ef488fe..d45e0e3a781de88a72425379a1390109aa795968 100644 (file)
@@ -178,7 +178,7 @@ static int adv7183_log_status(struct v4l2_subdev *sd)
                        adv7183_read(sd, ADV7183_VS_FIELD_CTRL_1),
                        adv7183_read(sd, ADV7183_VS_FIELD_CTRL_2),
                        adv7183_read(sd, ADV7183_VS_FIELD_CTRL_3));
-       v4l2_info(sd, "adv7183: Hsync positon control 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n",
+       v4l2_info(sd, "adv7183: Hsync position control 1 2 and 3 = 0x%02x 0x%02x 0x%02x\n",
                        adv7183_read(sd, ADV7183_HS_POS_CTRL_1),
                        adv7183_read(sd, ADV7183_HS_POS_CTRL_2),
                        adv7183_read(sd, ADV7183_HS_POS_CTRL_3));
index aeb56c53e39f563dea2768c005f2df33ad90df6c..d4e15a617c3b1b3b62128ba5e6ed236620bb40b6 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/videodev2.h>
 #include <linux/uaccess.h>
+#include <linux/of.h>
 
 #include <media/adv7343.h>
 #include <media/v4l2-async.h>
diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
new file mode 100644 (file)
index 0000000..3317a9a
--- /dev/null
@@ -0,0 +1,488 @@
+/*
+ * drivers/media/i2c/lm3560.c
+ * General device driver for TI lm3560, FLASH LED Driver
+ *
+ * Copyright (C) 2013 Texas Instruments
+ *
+ * Contact: Daniel Jeong <gshark.jeong@gmail.com>
+ *                     Ldd-Mlp <ldd-mlp@list.ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/videodev2.h>
+#include <media/lm3560.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+
+/* registers definitions */
+#define REG_ENABLE             0x10
+#define REG_TORCH_BR   0xa0
+#define REG_FLASH_BR   0xb0
+#define REG_FLASH_TOUT 0xc0
+#define REG_FLAG               0xd0
+#define REG_CONFIG1            0xe0
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (1<<0)
+#define FAULT_OVERTEMP (1<<1)
+#define FAULT_SHORT_CIRCUIT    (1<<2)
+
+enum led_enable {
+       MODE_SHDN = 0x0,
+       MODE_TORCH = 0x2,
+       MODE_FLASH = 0x3,
+};
+
+/* struct lm3560_flash
+ *
+ * @pdata: platform data
+ * @regmap: reg. map for i2c
+ * @lock: muxtex for serial access.
+ * @led_mode: V4L2 LED mode
+ * @ctrls_led: V4L2 contols
+ * @subdev_led: V4L2 subdev
+ */
+struct lm3560_flash {
+       struct device *dev;
+       struct lm3560_platform_data *pdata;
+       struct regmap *regmap;
+       struct mutex lock;
+
+       enum v4l2_flash_led_mode led_mode;
+       struct v4l2_ctrl_handler ctrls_led[LM3560_LED_MAX];
+       struct v4l2_subdev subdev_led[LM3560_LED_MAX];
+};
+
+#define to_lm3560_flash(_ctrl, _no)    \
+       container_of(_ctrl->handler, struct lm3560_flash, ctrls_led[_no])
+
+/* enable mode control */
+static int lm3560_mode_ctrl(struct lm3560_flash *flash)
+{
+       int rval = -EINVAL;
+
+       switch (flash->led_mode) {
+       case V4L2_FLASH_LED_MODE_NONE:
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_ENABLE, 0x03, MODE_SHDN);
+               break;
+       case V4L2_FLASH_LED_MODE_TORCH:
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_ENABLE, 0x03, MODE_TORCH);
+               break;
+       case V4L2_FLASH_LED_MODE_FLASH:
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_ENABLE, 0x03, MODE_FLASH);
+               break;
+       }
+       return rval;
+}
+
+/* led1/2  enable/disable */
+static int lm3560_enable_ctrl(struct lm3560_flash *flash,
+                             enum lm3560_led_id led_no, bool on)
+{
+       int rval;
+
+       if (led_no == LM3560_LED0) {
+               if (on == true)
+                       rval = regmap_update_bits(flash->regmap,
+                                                 REG_ENABLE, 0x08, 0x08);
+               else
+                       rval = regmap_update_bits(flash->regmap,
+                                                 REG_ENABLE, 0x08, 0x00);
+       } else {
+               if (on == true)
+                       rval = regmap_update_bits(flash->regmap,
+                                                 REG_ENABLE, 0x10, 0x10);
+               else
+                       rval = regmap_update_bits(flash->regmap,
+                                                 REG_ENABLE, 0x10, 0x00);
+       }
+       return rval;
+}
+
+/* torch1/2 brightness control */
+static int lm3560_torch_brt_ctrl(struct lm3560_flash *flash,
+                                enum lm3560_led_id led_no, unsigned int brt)
+{
+       int rval;
+       u8 br_bits;
+
+       if (brt < LM3560_TORCH_BRT_MIN)
+               return lm3560_enable_ctrl(flash, led_no, false);
+       else
+               rval = lm3560_enable_ctrl(flash, led_no, true);
+
+       br_bits = LM3560_TORCH_BRT_uA_TO_REG(brt);
+       if (led_no == LM3560_LED0)
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_TORCH_BR, 0x07, br_bits);
+       else
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_TORCH_BR, 0x38, br_bits << 3);
+
+       return rval;
+}
+
+/* flash1/2 brightness control */
+static int lm3560_flash_brt_ctrl(struct lm3560_flash *flash,
+                                enum lm3560_led_id led_no, unsigned int brt)
+{
+       int rval;
+       u8 br_bits;
+
+       if (brt < LM3560_FLASH_BRT_MIN)
+               return lm3560_enable_ctrl(flash, led_no, false);
+       else
+               rval = lm3560_enable_ctrl(flash, led_no, true);
+
+       br_bits = LM3560_FLASH_BRT_uA_TO_REG(brt);
+       if (led_no == LM3560_LED0)
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_FLASH_BR, 0x0f, br_bits);
+       else
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_FLASH_BR, 0xf0, br_bits << 4);
+
+       return rval;
+}
+
+/* V4L2 controls  */
+static int lm3560_get_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
+{
+       struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
+
+       mutex_lock(&flash->lock);
+
+       if (ctrl->id == V4L2_CID_FLASH_FAULT) {
+               int rval;
+               s32 fault = 0;
+               unsigned int reg_val;
+               rval = regmap_read(flash->regmap, REG_FLAG, &reg_val);
+               if (rval < 0)
+                       return rval;
+               if (rval & FAULT_SHORT_CIRCUIT)
+                       fault |= V4L2_FLASH_FAULT_SHORT_CIRCUIT;
+               if (rval & FAULT_OVERTEMP)
+                       fault |= V4L2_FLASH_FAULT_OVER_TEMPERATURE;
+               if (rval & FAULT_TIMEOUT)
+                       fault |= V4L2_FLASH_FAULT_TIMEOUT;
+               ctrl->cur.val = fault;
+               return 0;
+       }
+
+       mutex_unlock(&flash->lock);
+       return -EINVAL;
+}
+
+static int lm3560_set_ctrl(struct v4l2_ctrl *ctrl, enum lm3560_led_id led_no)
+{
+       struct lm3560_flash *flash = to_lm3560_flash(ctrl, led_no);
+       u8 tout_bits;
+       int rval = -EINVAL;
+
+       mutex_lock(&flash->lock);
+
+       switch (ctrl->id) {
+       case V4L2_CID_FLASH_LED_MODE:
+               flash->led_mode = ctrl->val;
+               if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH)
+                       rval = lm3560_mode_ctrl(flash);
+               break;
+
+       case V4L2_CID_FLASH_STROBE_SOURCE:
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_CONFIG1, 0x04, (ctrl->val) << 2);
+               if (rval < 0)
+                       goto err_out;
+               break;
+
+       case V4L2_CID_FLASH_STROBE:
+               if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH)
+                       return -EBUSY;
+               flash->led_mode = V4L2_FLASH_LED_MODE_FLASH;
+               rval = lm3560_mode_ctrl(flash);
+               break;
+
+       case V4L2_CID_FLASH_STROBE_STOP:
+               if (flash->led_mode != V4L2_FLASH_LED_MODE_FLASH)
+                       return -EBUSY;
+               flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
+               rval = lm3560_mode_ctrl(flash);
+               break;
+
+       case V4L2_CID_FLASH_TIMEOUT:
+               tout_bits = LM3560_FLASH_TOUT_ms_TO_REG(ctrl->val);
+               rval = regmap_update_bits(flash->regmap,
+                                         REG_FLASH_TOUT, 0x1f, tout_bits);
+               break;
+
+       case V4L2_CID_FLASH_INTENSITY:
+               rval = lm3560_flash_brt_ctrl(flash, led_no, ctrl->val);
+               break;
+
+       case V4L2_CID_FLASH_TORCH_INTENSITY:
+               rval = lm3560_torch_brt_ctrl(flash, led_no, ctrl->val);
+               break;
+       }
+
+       mutex_unlock(&flash->lock);
+err_out:
+       return rval;
+}
+
+static int lm3560_led1_get_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3560_get_ctrl(ctrl, LM3560_LED1);
+}
+
+static int lm3560_led1_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3560_set_ctrl(ctrl, LM3560_LED1);
+}
+
+static int lm3560_led0_get_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3560_get_ctrl(ctrl, LM3560_LED0);
+}
+
+static int lm3560_led0_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+       return lm3560_set_ctrl(ctrl, LM3560_LED0);
+}
+
+static const struct v4l2_ctrl_ops lm3560_led_ctrl_ops[LM3560_LED_MAX] = {
+       [LM3560_LED0] = {
+                        .g_volatile_ctrl = lm3560_led0_get_ctrl,
+                        .s_ctrl = lm3560_led0_set_ctrl,
+                        },
+       [LM3560_LED1] = {
+                        .g_volatile_ctrl = lm3560_led1_get_ctrl,
+                        .s_ctrl = lm3560_led1_set_ctrl,
+                        }
+};
+
+static int lm3560_init_controls(struct lm3560_flash *flash,
+                               enum lm3560_led_id led_no)
+{
+       struct v4l2_ctrl *fault;
+       u32 max_flash_brt = flash->pdata->max_flash_brt[led_no];
+       u32 max_torch_brt = flash->pdata->max_torch_brt[led_no];
+       struct v4l2_ctrl_handler *hdl = &flash->ctrls_led[led_no];
+       const struct v4l2_ctrl_ops *ops = &lm3560_led_ctrl_ops[led_no];
+
+       v4l2_ctrl_handler_init(hdl, 8);
+       /* flash mode */
+       v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_FLASH_LED_MODE,
+                              V4L2_FLASH_LED_MODE_TORCH, ~0x7,
+                              V4L2_FLASH_LED_MODE_NONE);
+       flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
+
+       /* flash source */
+       v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_FLASH_STROBE_SOURCE,
+                              0x1, ~0x3, V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
+
+       /* flash strobe */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_STROBE, 0, 0, 0, 0);
+       /* flash strobe stop */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_STROBE_STOP, 0, 0, 0, 0);
+
+       /* flash strobe timeout */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TIMEOUT,
+                         LM3560_FLASH_TOUT_MIN,
+                         flash->pdata->max_flash_timeout,
+                         LM3560_FLASH_TOUT_STEP,
+                         flash->pdata->max_flash_timeout);
+
+       /* flash brt */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_INTENSITY,
+                         LM3560_FLASH_BRT_MIN, max_flash_brt,
+                         LM3560_FLASH_BRT_STEP, max_flash_brt);
+
+       /* torch brt */
+       v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_TORCH_INTENSITY,
+                         LM3560_TORCH_BRT_MIN, max_torch_brt,
+                         LM3560_TORCH_BRT_STEP, max_torch_brt);
+
+       /* fault */
+       fault = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FLASH_FAULT, 0,
+                                 V4L2_FLASH_FAULT_OVER_VOLTAGE
+                                 | V4L2_FLASH_FAULT_OVER_TEMPERATURE
+                                 | V4L2_FLASH_FAULT_SHORT_CIRCUIT
+                                 | V4L2_FLASH_FAULT_TIMEOUT, 0, 0);
+       if (fault != NULL)
+               fault->flags |= V4L2_CTRL_FLAG_VOLATILE;
+
+       if (hdl->error)
+               return hdl->error;
+
+       flash->subdev_led[led_no].ctrl_handler = hdl;
+       return 0;
+}
+
+/* initialize device */
+static const struct v4l2_subdev_ops lm3560_ops = {
+       .core = NULL,
+};
+
+static const struct regmap_config lm3560_regmap = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0xFF,
+};
+
+static int lm3560_subdev_init(struct lm3560_flash *flash,
+                             enum lm3560_led_id led_no, char *led_name)
+{
+       struct i2c_client *client = to_i2c_client(flash->dev);
+       int rval;
+
+       v4l2_i2c_subdev_init(&flash->subdev_led[led_no], client, &lm3560_ops);
+       flash->subdev_led[led_no].flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+       strcpy(flash->subdev_led[led_no].name, led_name);
+       rval = lm3560_init_controls(flash, led_no);
+       if (rval)
+               goto err_out;
+       rval = media_entity_init(&flash->subdev_led[led_no].entity, 0, NULL, 0);
+       if (rval < 0)
+               goto err_out;
+       flash->subdev_led[led_no].entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
+
+       return rval;
+
+err_out:
+       v4l2_ctrl_handler_free(&flash->ctrls_led[led_no]);
+       return rval;
+}
+
+static int lm3560_init_device(struct lm3560_flash *flash)
+{
+       int rval;
+       unsigned int reg_val;
+
+       /* set peak current */
+       rval = regmap_update_bits(flash->regmap,
+                                 REG_FLASH_TOUT, 0x60, flash->pdata->peak);
+       if (rval < 0)
+               return rval;
+       /* output disable */
+       flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
+       rval = lm3560_mode_ctrl(flash);
+       if (rval < 0)
+               return rval;
+       /* Reset faults */
+       rval = regmap_read(flash->regmap, REG_FLAG, &reg_val);
+       return rval;
+}
+
+static int lm3560_probe(struct i2c_client *client,
+                       const struct i2c_device_id *devid)
+{
+       struct lm3560_flash *flash;
+       struct lm3560_platform_data *pdata = dev_get_platdata(&client->dev);
+       int rval;
+
+       flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
+       if (flash == NULL)
+               return -ENOMEM;
+
+       flash->regmap = devm_regmap_init_i2c(client, &lm3560_regmap);
+       if (IS_ERR(flash->regmap)) {
+               rval = PTR_ERR(flash->regmap);
+               return rval;
+       }
+
+       /* if there is no platform data, use chip default value */
+       if (pdata == NULL) {
+               pdata =
+                   kzalloc(sizeof(struct lm3560_platform_data), GFP_KERNEL);
+               if (pdata == NULL)
+                       return -ENODEV;
+               pdata->peak = LM3560_PEAK_3600mA;
+               pdata->max_flash_timeout = LM3560_FLASH_TOUT_MAX;
+               /* led 1 */
+               pdata->max_flash_brt[LM3560_LED0] = LM3560_FLASH_BRT_MAX;
+               pdata->max_torch_brt[LM3560_LED0] = LM3560_TORCH_BRT_MAX;
+               /* led 2 */
+               pdata->max_flash_brt[LM3560_LED1] = LM3560_FLASH_BRT_MAX;
+               pdata->max_torch_brt[LM3560_LED1] = LM3560_TORCH_BRT_MAX;
+       }
+       flash->pdata = pdata;
+       flash->dev = &client->dev;
+       mutex_init(&flash->lock);
+
+       rval = lm3560_subdev_init(flash, LM3560_LED0, "lm3560-led0");
+       if (rval < 0)
+               return rval;
+
+       rval = lm3560_subdev_init(flash, LM3560_LED1, "lm3560-led1");
+       if (rval < 0)
+               return rval;
+
+       rval = lm3560_init_device(flash);
+       if (rval < 0)
+               return rval;
+
+       return 0;
+}
+
+static int lm3560_remove(struct i2c_client *client)
+{
+       struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+       struct lm3560_flash *flash = container_of(subdev, struct lm3560_flash,
+                                                 subdev_led[LM3560_LED_MAX]);
+       unsigned int i;
+
+       for (i = LM3560_LED0; i < LM3560_LED_MAX; i++) {
+               v4l2_device_unregister_subdev(&flash->subdev_led[i]);
+               v4l2_ctrl_handler_free(&flash->ctrls_led[i]);
+               media_entity_cleanup(&flash->subdev_led[i].entity);
+       }
+
+       return 0;
+}
+
+static const struct i2c_device_id lm3560_id_table[] = {
+       {LM3560_NAME, 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, lm3560_id_table);
+
+static struct i2c_driver lm3560_i2c_driver = {
+       .driver = {
+                  .name = LM3560_NAME,
+                  .pm = NULL,
+                  },
+       .probe = lm3560_probe,
+       .remove = lm3560_remove,
+       .id_table = lm3560_id_table,
+};
+
+module_i2c_driver(lm3560_i2c_driver);
+
+MODULE_AUTHOR("Daniel Jeong <gshark.jeong@gmail.com>");
+MODULE_AUTHOR("Ldd Mlp <ldd-mlp@list.ti.com>");
+MODULE_DESCRIPTION("Texas Instruments LM3560 LED flash driver");
+MODULE_LICENSE("GPL");
index b76ec0e7e685ee8b1fa4d3fd99180a96b595e8d0..6fec9384d86e4877d5b750a9f9a9ceec53e06bde 100644 (file)
@@ -1581,7 +1581,7 @@ static int s5c73m3_probe(struct i2c_client *client,
        oif_sd = &state->oif_sd;
 
        v4l2_subdev_init(sd, &s5c73m3_subdev_ops);
-       sd->owner = client->driver->driver.owner;
+       sd->owner = client->dev.driver->owner;
        v4l2_set_subdevdata(sd, state);
        strlcpy(sd->name, "S5C73M3", sizeof(sd->name));
 
@@ -1651,7 +1651,7 @@ static int s5c73m3_probe(struct i2c_client *client,
        if (ret < 0)
                goto out_err;
 
-       v4l2_info(sd, "%s: completed succesfully\n", __func__);
+       v4l2_info(sd, "%s: completed successfully\n", __func__);
        return 0;
 
 out_err:
index 1d384a371b41d6c82e335c617ba1a683992ed8c1..5b915936c3f3f78d79f6fbabd9feb195da4fc00e 100644 (file)
@@ -451,7 +451,9 @@ static int imx074_probe(struct i2c_client *client,
        if (ret < 0)
                goto eprobe;
 
-       return v4l2_async_register_subdev(&priv->subdev);
+       ret = v4l2_async_register_subdev(&priv->subdev);
+       if (!ret)
+               return 0;
 
 epwrinit:
 eprobe:
index e968c3fdbd9e8e63b16982ba0111401c3b93ad4a..bc74224503e7d0edbe0a704f6ab6a40ae959bd80 100644 (file)
@@ -371,7 +371,7 @@ static void ov9640_alter_regs(enum v4l2_mbus_pixelcode code,
                alt->com13      = OV9640_COM13_RGB_AVG;
                alt->com15      = OV9640_COM15_RGB_565;
                break;
-       };
+       }
 }
 
 /* Setup registers according to resolution and color encoding */
index d9f65d7e3e58b64dea5b930d5800e20921fd8778..04139eec8c4eb9ba5780d360b37bc5dbc8b204d2 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <linux/i2c.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/v4l2-dv-timings.h>
 
 #include <media/v4l2-dv-timings.h>
index 91f3dd4cda1b66926ac9ac77e50e17ee30579160..83d85df4853a226a9ef105f529628214a75426d6 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/videodev2.h>
 #include <linux/module.h>
 #include <linux/v4l2-mediabus.h>
+#include <linux/of.h>
 
 #include <media/v4l2-async.h>
 #include <media/v4l2-device.h>
index 24a08fa7e32875fe223ed3c78aef8f9d5f984376..912e1cccdd1c608b57c16b7af4d91833935e9172 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/v4l2-dv-timings.h>
 #include <media/tvp7002.h>
 #include <media/v4l2-async.h>
index 447afbd904a4bd9dc3ca1f75169083798b879e61..8b5e0b3a92a0c4a408af8bc50217279065b78803 100644 (file)
@@ -319,7 +319,6 @@ static int flexcop_pci_init(struct flexcop_pci *fc_pci)
 
 err_pci_iounmap:
        pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
-       pci_set_drvdata(fc_pci->pdev, NULL);
 err_pci_release_regions:
        pci_release_regions(fc_pci->pdev);
 err_pci_disable_device:
@@ -332,7 +331,6 @@ static void flexcop_pci_exit(struct flexcop_pci *fc_pci)
        if (fc_pci->init_state & FC_PCI_INIT) {
                free_irq(fc_pci->pdev->irq, fc_pci);
                pci_iounmap(fc_pci->pdev, fc_pci->io_mem);
-               pci_set_drvdata(fc_pci->pdev, NULL);
                pci_release_regions(fc_pci->pdev);
                pci_disable_device(fc_pci->pdev);
        }
index 66eb0baab0e9948cb4beeb88a1bac60e71c19821..d0c281f41a0aa98f368ec37fed1748e31284cb62 100644 (file)
@@ -488,8 +488,7 @@ static int bt878_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
        btwrite(0, BT848_INT_MASK);
 
        result = request_irq(bt->irq, bt878_irq,
-                            IRQF_SHARED | IRQF_DISABLED, "bt878",
-                            (void *) bt);
+                            IRQF_SHARED, "bt878", (void *) bt);
        if (result == -EINVAL) {
                printk(KERN_ERR "bt878(%d): Bad irq number or handler\n",
                       bt878_num);
@@ -563,7 +562,6 @@ static void bt878_remove(struct pci_dev *pci_dev)
        bt->shutdown = 1;
        bt878_mem_free(bt);
 
-       pci_set_drvdata(pci_dev, NULL);
        pci_disable_device(pci_dev);
        return;
 }
index c6532de0eac79652b1bbf6fefb8428cdced46fae..a3b1ee9c00d7152405e9ea0e71549f350194692e 100644 (file)
@@ -4086,7 +4086,7 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
        /* disable irqs, register irq handler */
        btwrite(0, BT848_INT_MASK);
        result = request_irq(btv->c.pci->irq, bttv_irq,
-           IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv);
+           IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv);
        if (result < 0) {
                pr_err("%d: can't get IRQ %d\n",
                       bttv_num, btv->c.pci->irq);
index 004d8ace5019a7921e1ff7e0cc189e4c260beffa..c1f8cc6f14b21ed74b024dd8c0b4425ed1425cdc 100644 (file)
@@ -324,23 +324,24 @@ static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len)
 /* Hauppauge card? get values from tveeprom */
 void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
 {
-       struct i2c_client c;
+       struct i2c_client *c;
        u8 eedata[256];
 
-       memset(&c, 0, sizeof(c));
-       strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
-       c.adapter = &cx->i2c_adap[0];
-       c.addr = 0xA0 >> 1;
+       c = kzalloc(sizeof(*c), GFP_KERNEL);
+
+       strlcpy(c->name, "cx18 tveeprom tmp", sizeof(c->name));
+       c->adapter = &cx->i2c_adap[0];
+       c->addr = 0xa0 >> 1;
 
        memset(tv, 0, sizeof(*tv));
-       if (tveeprom_read(&c, eedata, sizeof(eedata)))
-               return;
+       if (tveeprom_read(c, eedata, sizeof(eedata)))
+               goto ret;
 
        switch (cx->card->type) {
        case CX18_CARD_HVR_1600_ESMT:
        case CX18_CARD_HVR_1600_SAMSUNG:
        case CX18_CARD_HVR_1600_S5H1411:
-               tveeprom_hauppauge_analog(&c, tv, eedata);
+               tveeprom_hauppauge_analog(c, tv, eedata);
                break;
        case CX18_CARD_YUAN_MPC718:
        case CX18_CARD_GOTVIEW_PCI_DVD3:
@@ -354,6 +355,9 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
                cx18_eeprom_dump(cx, eedata, sizeof(eedata));
                break;
        }
+
+ret:
+       kfree(c);
 }
 
 static void cx18_process_eeprom(struct cx18 *cx)
@@ -1031,8 +1035,7 @@ static int cx18_probe(struct pci_dev *pci_dev,
 
        /* Register IRQ */
        retval = request_irq(cx->pci_dev->irq, cx18_irq_handler,
-                            IRQF_SHARED | IRQF_DISABLED,
-                            cx->v4l2_dev.name, (void *)cx);
+                            IRQF_SHARED, cx->v4l2_dev.name, (void *)cx);
        if (retval) {
                CX18_ERR("Failed to register irq %d\n", retval);
                goto free_i2c;
index 5104c802f72fd7d7175dc763fb72091d60b35b92..d1dcb1d2e087f43fe81a8d0f966e6f65644e7b4c 100644 (file)
@@ -23,6 +23,7 @@ config VIDEO_CX23885
        select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT
        select DVB_STV6110 if MEDIA_SUBDRV_AUTOSELECT
        select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT
+       select DVB_CX24117 if MEDIA_SUBDRV_AUTOSELECT
        select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT
        select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT
        select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
index 7344849183a77bc51e3a072dc31875dcba8fee90..16fa7ea4d4aa7d472ff9f59f6b0131ead21c2902 100644 (file)
 #include "cx23885.h"
 #include "cimax2.h"
 #include "dvb_ca_en50221.h"
+
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /**** Bit definitions for MC417_RWD and MC417_OEN registers  ***
   bits 31-16
 +-----------+
@@ -125,7 +129,7 @@ static int netup_write_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg,
                                                u8 *buf, int len)
 {
        int ret;
-       u8 buffer[len + 1];
+       u8 buffer[MAX_XFER_SIZE];
 
        struct i2c_msg msg = {
                .addr   = addr,
@@ -134,6 +138,13 @@ static int netup_write_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg,
                .len    = len + 1
        };
 
+       if (1 + len > sizeof(buffer)) {
+               printk(KERN_WARNING
+                      "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                      KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buffer[0] = reg;
        memcpy(&buffer[1], buf, len);
 
index 6a71a965e757fe50870bb45bdf2c25713a972d81..79f20c8c842ed1a1f12b34a0eeab0e133fdd3e7b 100644 (file)
@@ -223,6 +223,39 @@ struct cx23885_board cx23885_boards[] = {
                .name           = "Leadtek Winfast PxDVR3200 H",
                .portc          = CX23885_MPEG_DVB,
        },
+       [CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200] = {
+               .name           = "Leadtek Winfast PxPVR2200",
+               .porta          = CX23885_ANALOG_VIDEO,
+               .tuner_type     = TUNER_XC2028,
+               .tuner_addr     = 0x61,
+               .tuner_bus      = 1,
+               .input          = {{
+                       .type   = CX23885_VMUX_TELEVISION,
+                       .vmux   = CX25840_VIN2_CH1 |
+                                 CX25840_VIN5_CH2,
+                       .amux   = CX25840_AUDIO8,
+                       .gpio0  = 0x704040,
+               }, {
+                       .type   = CX23885_VMUX_COMPOSITE1,
+                       .vmux   = CX25840_COMPOSITE1,
+                       .amux   = CX25840_AUDIO7,
+                       .gpio0  = 0x704040,
+               }, {
+                       .type   = CX23885_VMUX_SVIDEO,
+                       .vmux   = CX25840_SVIDEO_LUMA3 |
+                                 CX25840_SVIDEO_CHROMA4,
+                       .amux   = CX25840_AUDIO7,
+                       .gpio0  = 0x704040,
+               }, {
+                       .type   = CX23885_VMUX_COMPONENT,
+                       .vmux   = CX25840_VIN7_CH1 |
+                                 CX25840_VIN6_CH2 |
+                                 CX25840_VIN8_CH3 |
+                                 CX25840_COMPONENT_ON,
+                       .amux   = CX25840_AUDIO7,
+                       .gpio0  = 0x704040,
+               } },
+       },
        [CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000] = {
                .name           = "Leadtek Winfast PxDVR3200 H XC4000",
                .porta          = CX23885_ANALOG_VIDEO,
@@ -259,6 +292,16 @@ struct cx23885_board cx23885_boards[] = {
                .name           = "TurboSight TBS 6920",
                .portb          = CX23885_MPEG_DVB,
        },
+       [CX23885_BOARD_TBS_6980] = {
+               .name           = "TurboSight TBS 6980",
+               .portb          = CX23885_MPEG_DVB,
+               .portc          = CX23885_MPEG_DVB,
+       },
+       [CX23885_BOARD_TBS_6981] = {
+               .name           = "TurboSight TBS 6981",
+               .portb          = CX23885_MPEG_DVB,
+               .portc          = CX23885_MPEG_DVB,
+       },
        [CX23885_BOARD_TEVII_S470] = {
                .name           = "TeVii S470",
                .portb          = CX23885_MPEG_DVB,
@@ -686,6 +729,10 @@ struct cx23885_subid cx23885_subids[] = {
                .subvendor = 0x107d,
                .subdevice = 0x6681,
                .card      = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H,
+       }, {
+               .subvendor = 0x107d,
+               .subdevice = 0x6f21,
+               .card      = CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200,
        }, {
                .subvendor = 0x107d,
                .subdevice = 0x6f39,
@@ -698,6 +745,14 @@ struct cx23885_subid cx23885_subids[] = {
                .subvendor = 0x6920,
                .subdevice = 0x8888,
                .card      = CX23885_BOARD_TBS_6920,
+       }, {
+               .subvendor = 0x6980,
+               .subdevice = 0x8888,
+               .card      = CX23885_BOARD_TBS_6980,
+       }, {
+               .subvendor = 0x6981,
+               .subdevice = 0x8888,
+               .card      = CX23885_BOARD_TBS_6981,
        }, {
                .subvendor = 0xd470,
                .subdevice = 0x9022,
@@ -1023,6 +1078,35 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
                        dev->name, tv.model);
 }
 
+/* Some TBS cards require initing a chip using a bitbanged SPI attached
+   to the cx23885 gpio's. If this chip doesn't get init'ed the demod
+   doesn't respond to any command. */
+static void tbs_card_init(struct cx23885_dev *dev)
+{
+       int i;
+       const u8 buf[] = {
+               0xe0, 0x06, 0x66, 0x33, 0x65,
+               0x01, 0x17, 0x06, 0xde};
+
+       switch (dev->board) {
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
+               cx_set(GP0_IO, 0x00070007);
+               usleep_range(1000, 10000);
+               cx_clear(GP0_IO, 2);
+               usleep_range(1000, 10000);
+               for (i = 0; i < 9 * 8; i++) {
+                       cx_clear(GP0_IO, 7);
+                       usleep_range(1000, 10000);
+                       cx_set(GP0_IO,
+                               ((buf[i >> 3] >> (7 - (i & 7))) & 1) | 4);
+                       usleep_range(1000, 10000);
+               }
+               cx_set(GP0_IO, 7);
+               break;
+       }
+}
+
 int cx23885_tuner_callback(void *priv, int component, int command, int arg)
 {
        struct cx23885_tsport *port = priv;
@@ -1043,6 +1127,7 @@ int cx23885_tuner_callback(void *priv, int component, int command, int arg)
        case CX23885_BOARD_HAUPPAUGE_HVR1500:
        case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+       case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
        case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
        case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
@@ -1208,6 +1293,7 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
                cx_set(GP0_IO, 0x000f000f);
                break;
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+       case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
        case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
        case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
@@ -1225,6 +1311,8 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
                cx_set(GP0_IO, 0x00040004);
                break;
        case CX23885_BOARD_TBS_6920:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
        case CX23885_BOARD_PROF_8000:
                cx_write(MC417_CTL, 0x00000036);
                cx_write(MC417_OEN, 0x00001000);
@@ -1473,6 +1561,8 @@ int cx23885_ir_init(struct cx23885_dev *dev)
        case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
        case CX23885_BOARD_TEVII_S470:
        case CX23885_BOARD_MYGICA_X8507:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
                if (!enable_885_ir)
                        break;
                dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE);
@@ -1516,6 +1606,8 @@ void cx23885_ir_fini(struct cx23885_dev *dev)
        case CX23885_BOARD_TEVII_S470:
        case CX23885_BOARD_HAUPPAUGE_HVR1250:
        case CX23885_BOARD_MYGICA_X8507:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
                cx23885_irq_remove(dev, PCI_MSK_AV_CORE);
                /* sd_ir is a duplicate pointer to the AV Core, just clear it */
                dev->sd_ir = NULL;
@@ -1561,6 +1653,8 @@ void cx23885_ir_pci_int_enable(struct cx23885_dev *dev)
        case CX23885_BOARD_TEVII_S470:
        case CX23885_BOARD_HAUPPAUGE_HVR1250:
        case CX23885_BOARD_MYGICA_X8507:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
                if (dev->sd_ir)
                        cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE);
                break;
@@ -1676,6 +1770,16 @@ void cx23885_card_setup(struct cx23885_dev *dev)
                ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
                ts2->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
                break;
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
+               ts1->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
+               ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
+               ts1->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+               ts2->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
+               ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
+               ts2->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+               tbs_card_init(dev);
+               break;
        case CX23885_BOARD_MYGICA_X8506:
        case CX23885_BOARD_MAGICPRO_PROHDTVE2:
        case CX23885_BOARD_MYGICA_X8507:
@@ -1704,6 +1808,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1700:
        case CX23885_BOARD_HAUPPAUGE_HVR1400:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+       case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
        case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
        case CX23885_BOARD_HAUPPAUGE_HVR1270:
@@ -1733,6 +1838,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
        case CX23885_BOARD_HAUPPAUGE_HVR1700:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+       case CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200:
        case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
        case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
        case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
@@ -1752,6 +1858,8 @@ void cx23885_card_setup(struct cx23885_dev *dev)
        case CX23885_BOARD_MYGICA_X8507:
        case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
        case CX23885_BOARD_AVERMEDIA_HC81R:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
                dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
                                &dev->i2c_bus[2].i2c_adap,
                                "cx25840", 0x88 >> 1, NULL);
index 9f63d93239ec9d279f1de77952e6459ee40389fc..edcd79db1e4ebc5d8ba6319b2ccb3c900a3024b4 100644 (file)
@@ -2129,7 +2129,7 @@ static int cx23885_initdev(struct pci_dev *pci_dev,
        }
 
        err = request_irq(pci_dev->irq, cx23885_irq,
-                         IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
+                         IRQF_SHARED, dev->name, dev);
        if (err < 0) {
                printk(KERN_ERR "%s: can't get IRQ %d\n",
                       dev->name, pci_dev->irq);
index 971e4ff1b87f2f159aac208884b7fc1746ad1fa8..05492053b473033da6da030fb1f64d7dcf2ea0ef 100644 (file)
@@ -51,6 +51,7 @@
 #include "stv6110.h"
 #include "lnbh24.h"
 #include "cx24116.h"
+#include "cx24117.h"
 #include "cimax2.h"
 #include "lgs8gxx.h"
 #include "netup-eeprom.h"
@@ -461,6 +462,10 @@ static struct cx24116_config tbs_cx24116_config = {
        .demod_address = 0x55,
 };
 
+static struct cx24117_config tbs_cx24117_config = {
+       .demod_address = 0x55,
+};
+
 static struct ds3000_config tevii_ds3000_config = {
        .demod_address = 0x68,
 };
@@ -1044,6 +1049,25 @@ static int dvb_register(struct cx23885_tsport *port)
                        fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
 
                break;
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
+               i2c_bus = &dev->i2c_bus[1];
+
+               switch (port->nr) {
+               /* PORT B */
+               case 1:
+                       fe0->dvb.frontend = dvb_attach(cx24117_attach,
+                                       &tbs_cx24117_config,
+                                       &i2c_bus->i2c_adap);
+                       break;
+               /* PORT C */
+               case 2:
+                       fe0->dvb.frontend = dvb_attach(cx24117_attach,
+                                       &tbs_cx24117_config,
+                                       &i2c_bus->i2c_adap);
+                       break;
+               }
+               break;
        case CX23885_BOARD_TEVII_S470:
                i2c_bus = &dev->i2c_bus[1];
 
index 7875dfbe09ffae666e8365e877022af4d16a7be2..8a49e7c9eddd76f508f8131a8533f552ad7db98b 100644 (file)
@@ -90,6 +90,8 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
        case CX23885_BOARD_TEVII_S470:
        case CX23885_BOARD_HAUPPAUGE_HVR1250:
        case CX23885_BOARD_MYGICA_X8507:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
                /*
                 * The only boards we handle right now.  However other boards
                 * using the CX2388x integrated IR controller should be similar
@@ -168,6 +170,8 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev)
                break;
        case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
        case CX23885_BOARD_TEVII_S470:
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
                /*
                 * The IR controller on this board only returns pulse widths.
                 * Any other mode setting will fail to set up the device.
@@ -298,6 +302,14 @@ int cx23885_input_init(struct cx23885_dev *dev)
                /* A guess at the remote */
                rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02;
                break;
+       case CX23885_BOARD_TBS_6980:
+       case CX23885_BOARD_TBS_6981:
+               /* Integrated CX23885 IR controller */
+               driver_type = RC_DRIVER_IR_RAW;
+               allowed_protos = RC_BIT_ALL;
+               /* A guess at the remote */
+               rc_map = RC_MAP_TBS_NEC;
+               break;
        default:
                return -ENODEV;
        }
index 161686832b2046c173756953485cda329c77b2c6..7891f34157d18806ad400051b95cd2abcdd14023 100644 (file)
@@ -1865,7 +1865,8 @@ int cx23885_video_register(struct cx23885_dev *dev)
 
                        v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
 
-                       if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) {
+                       if ((dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) ||
+                           (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200)) {
                                struct xc2028_ctrl ctrl = {
                                        .fname = XC2028_DEFAULT_FIRMWARE,
                                        .max_len = 64
index 038caf53908b5acd4160b3e5167ebd4f27a69ea0..0fa4048ab872302496925e0ce129acbdb53bc156 100644 (file)
@@ -93,6 +93,9 @@
 #define CX23885_BOARD_PROF_8000                37
 #define CX23885_BOARD_HAUPPAUGE_HVR4400        38
 #define CX23885_BOARD_AVERMEDIA_HC81R          39
+#define CX23885_BOARD_TBS_6981                 40
+#define CX23885_BOARD_TBS_6980                 41
+#define CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200 42
 
 #define GPIO_0 0x00000001
 #define GPIO_1 0x00000002
index 3b409feb03d80a4ff178effffd238bc0b03ce466..f2ebc989b30338b943e1406780a61a219db7c7fc 100644 (file)
@@ -45,5 +45,3 @@ struct cx25821_board cx25821_boards[] = {
        },
 
 };
-
-const unsigned int cx25821_bcount = ARRAY_SIZE(cx25821_boards);
index 22fa04415ccc34f0a9ece611b72f68d5a5996b5c..43bdfa4dfba11c54ecfdffc98a0ce07c77b070b7 100644 (file)
@@ -438,7 +438,7 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
                decoder_count = decoder_select + 1;
        } else {
                decoder = 0;
-               decoder_count = _num_decoders;
+               decoder_count = dev->_max_num_decoders;
        }
 
        switch (width) {
@@ -506,8 +506,6 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
                break;
        }
 
-       _display_field_cnt[decoder] = duration;
-
        /* update hardware */
        fld_cnt = cx25821_i2c_read(&dev->i2c_bus[0], disp_cnt_reg, &tmp);
 
@@ -667,8 +665,6 @@ int medusa_video_init(struct cx25821_dev *dev)
        int ret_val = 0;
        int i = 0;
 
-       _num_decoders = dev->_max_num_decoders;
-
        /* disable Auto source selection on all video decoders */
        value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
        value &= 0xFFFFF0FF;
@@ -685,8 +681,14 @@ int medusa_video_init(struct cx25821_dev *dev)
        if (ret_val < 0)
                goto error;
 
-       for (i = 0; i < _num_decoders; i++)
-               medusa_set_decoderduration(dev, i, _display_field_cnt[i]);
+       /*
+        * FIXME: due to a coding bug the duration was always 0. It's
+        * likely that it really should be something else, but due to the
+        * lack of documentation I have no idea what it should be. For
+        * now just fill in 0 as the duration.
+        */
+       for (i = 0; i < dev->_max_num_decoders; i++)
+               medusa_set_decoderduration(dev, i, 0);
 
        /* Select monitor as DENC A input, power up the DAC */
        value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp);
@@ -717,7 +719,7 @@ int medusa_video_init(struct cx25821_dev *dev)
        /* Turn on all of the data out and control output pins. */
        value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp);
        value &= 0xFEF0FE00;
-       if (_num_decoders == MAX_DECODERS) {
+       if (dev->_max_num_decoders == MAX_DECODERS) {
                /*
                 * Note: The octal board does not support control pins(bit16-19)
                 * These bits are ignored in the octal board.
index 6175e09618557ac5bbba50d9413b1e370db4d8ee..8bf602ff27b1049e9bee6f0495ce205a4d753822 100644 (file)
 #define CONTRAST_DEFAULT                5000
 #define HUE_DEFAULT                     5000
 
-unsigned short _num_decoders;
-unsigned short _num_cameras;
-
-unsigned int _video_standard;
-int _display_field_cnt[MAX_DECODERS];
-
 #endif
index 88ffef410c503f9d750bc09d5b7fcd2b8845bdaa..1f43be0b04c8e91dc5012275d3d040eb0bd92a2d 100644 (file)
@@ -159,10 +159,10 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_channel *chan, __le32
                 * For the upstream video channel, the risc engine will enable
                 * the FIFO. */
                if (fifo_enable && line == 3) {
-                       *(rp++) = RISC_WRITECR;
-                       *(rp++) = sram_ch->dma_ctl;
-                       *(rp++) = FLD_VID_FIFO_EN;
-                       *(rp++) = 0x00000001;
+                       *(rp++) = cpu_to_le32(RISC_WRITECR);
+                       *(rp++) = cpu_to_le32(sram_ch->dma_ctl);
+                       *(rp++) = cpu_to_le32(FLD_VID_FIFO_EN);
+                       *(rp++) = cpu_to_le32(0x00000001);
                }
        }
 
index aba5b1c649e693d3b205e12c2247f2c0f8a3b730..400eb1c42d3f9529a946017ec3f6dd4fcae3424c 100644 (file)
@@ -834,7 +834,7 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
 
        /* get irq */
        err = request_irq(chip->pci->irq, cx8801_irq,
-                         IRQF_SHARED | IRQF_DISABLED, chip->core->name, chip);
+                         IRQF_SHARED, chip->core->name, chip);
        if (err < 0) {
                dprintk(0, "%s: can't get IRQ %d\n",
                       chip->core->name, chip->pci->irq);
@@ -935,8 +935,6 @@ static void cx88_audio_finidev(struct pci_dev *pci)
 
        snd_card_free((void *)card);
 
-       pci_set_drvdata(pci, NULL);
-
        devno--;
 }
 
@@ -951,27 +949,4 @@ static struct pci_driver cx88_audio_pci_driver = {
        .remove   = cx88_audio_finidev,
 };
 
-/****************************************************************************
-                               LINUX MODULE INIT
- ****************************************************************************/
-
-/*
- * module init
- */
-static int __init cx88_audio_init(void)
-{
-       printk(KERN_INFO "cx2388x alsa driver version %s loaded\n",
-              CX88_VERSION);
-       return pci_register_driver(&cx88_audio_pci_driver);
-}
-
-/*
- * module remove
- */
-static void __exit cx88_audio_fini(void)
-{
-       pci_unregister_driver(&cx88_audio_pci_driver);
-}
-
-module_init(cx88_audio_init);
-module_exit(cx88_audio_fini);
+module_pci_driver(cx88_audio_pci_driver);
index 2d3507eb48972046a5baa70772fe685df64bfbec..74b7b8614c23af893b95807246b180f151bedda3 100644 (file)
@@ -499,7 +499,7 @@ static int cx8802_init_common(struct cx8802_dev *dev)
 
        /* get irq */
        err = request_irq(dev->pci->irq, cx8802_irq,
-                         IRQF_SHARED | IRQF_DISABLED, dev->core->name, dev);
+                         IRQF_SHARED, dev->core->name, dev);
        if (err < 0) {
                printk(KERN_ERR "%s: can't get IRQ %d\n",
                       dev->core->name, dev->pci->irq);
@@ -520,7 +520,6 @@ static void cx8802_fini_common(struct cx8802_dev *dev)
 
        /* unregister stuff */
        free_irq(dev->pci->irq, dev);
-       pci_set_drvdata(dev->pci, NULL);
 
        /* free memory */
        btcx_riscmem_free(dev->pci,&dev->mpegq.stopper);
@@ -903,20 +902,8 @@ static struct pci_driver cx8802_pci_driver = {
        .remove   = cx8802_remove,
 };
 
-static int __init cx8802_init(void)
-{
-       printk(KERN_INFO "cx88/2: cx2388x MPEG-TS Driver Manager version %s loaded\n",
-              CX88_VERSION);
-       return pci_register_driver(&cx8802_pci_driver);
-}
-
-static void __exit cx8802_fini(void)
-{
-       pci_unregister_driver(&cx8802_pci_driver);
-}
+module_pci_driver(cx8802_pci_driver);
 
-module_init(cx8802_init);
-module_exit(cx8802_fini);
 EXPORT_SYMBOL(cx8802_buf_prepare);
 EXPORT_SYMBOL(cx8802_buf_queue);
 EXPORT_SYMBOL(cx8802_cancel_buffers);
index ecf21d9f1f34bb1e587edbdc6283a177ceee595b..ed8cb9037b6f30f0876ea377c42db799a8dd0e51 100644 (file)
@@ -1738,7 +1738,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
 
        /* get irq */
        err = request_irq(pci_dev->irq, cx8800_irq,
-                         IRQF_SHARED | IRQF_DISABLED, core->name, dev);
+                         IRQF_SHARED, core->name, dev);
        if (err < 0) {
                printk(KERN_ERR "%s/0: can't get IRQ %d\n",
                       core->name,pci_dev->irq);
@@ -1922,7 +1922,6 @@ static void cx8800_finidev(struct pci_dev *pci_dev)
 
        free_irq(pci_dev->irq, dev);
        cx8800_unregister_video(dev);
-       pci_set_drvdata(pci_dev, NULL);
 
        /* free memory */
        btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
@@ -2039,17 +2038,4 @@ static struct pci_driver cx8800_pci_driver = {
 #endif
 };
 
-static int __init cx8800_init(void)
-{
-       printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %s loaded\n",
-              CX88_VERSION);
-       return pci_register_driver(&cx8800_pci_driver);
-}
-
-static void __exit cx8800_fini(void)
-{
-       pci_unregister_driver(&cx8800_pci_driver);
-}
-
-module_init(cx8800_init);
-module_exit(cx8800_fini);
+module_pci_driver(cx8800_pci_driver);
index 36e34522b9a80878b61e78ed10a5276f3e7b570f..9375f30d9a81bfcc5fba2a35953855f8741a6610 100644 (file)
@@ -1544,7 +1544,7 @@ static void ddb_unmap(struct ddb *dev)
 
 static void ddb_remove(struct pci_dev *pdev)
 {
-       struct ddb *dev = (struct ddb *) pci_get_drvdata(pdev);
+       struct ddb *dev = pci_get_drvdata(pdev);
 
        ddb_ports_detach(dev);
        ddb_i2c_release(dev);
index ab797fe466d2dcd6d389f3ace68e77ec17021bd5..e60ac35fc10c734dd8b31f7901a23347653dcc99 100644 (file)
@@ -1178,7 +1178,6 @@ err_pci_release_regions:
 err_pci_disable_device:
        pci_disable_device(pdev);
 err_kfree:
-       pci_set_drvdata(pdev, NULL);
        kfree(dev);
        return ret;
 }
@@ -1202,8 +1201,7 @@ static void dm1105_remove(struct pci_dev *pdev)
        dvb_dmxdev_release(&dev->dmxdev);
        dvb_dmx_release(dvbdemux);
        dvb_unregister_adapter(dvb_adapter);
-       if (&dev->i2c_adap)
-               i2c_del_adapter(&dev->i2c_adap);
+       i2c_del_adapter(&dev->i2c_adap);
 
        dm1105_hw_exit(dev);
        synchronize_irq(pdev->irq);
@@ -1211,7 +1209,6 @@ static void dm1105_remove(struct pci_dev *pdev)
        pci_iounmap(pdev, dev->io_mem);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
        dm1105_devcount--;
        kfree(dev);
 }
index c08ae3eb9554d46fc29b4dfbfbf0f314c8b90cec..802642d266438ffaaf6f136a30e141ffb452810e 100644 (file)
@@ -1261,7 +1261,7 @@ static int ivtv_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
 
        /* Register IRQ */
        retval = request_irq(itv->pdev->irq, ivtv_irq_handler,
-            IRQF_SHARED | IRQF_DISABLED, itv->v4l2_dev.name, (void *)itv);
+            IRQF_SHARED, itv->v4l2_dev.name, (void *)itv);
        if (retval) {
                IVTV_ERR("Failed to register irq %d\n", retval);
                goto free_i2c;
index a846036ea0227dfaabcc64d7e20401b495dcc424..9e89e045213a52e57e8a4b389ad0f9bc2dacfd5c 100644 (file)
@@ -143,7 +143,6 @@ fail1:
 
 fail0:
        dprintk(MANTIS_ERROR, 1, "ERROR: <%d> exiting", ret);
-       pci_set_drvdata(pdev, NULL);
        return ret;
 }
 EXPORT_SYMBOL_GPL(mantis_pci_init);
@@ -161,7 +160,6 @@ void mantis_pci_exit(struct mantis_pci *mantis)
        }
 
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
 }
 EXPORT_SYMBOL_GPL(mantis_pci_exit);
 
index 2381b05432e676da50ed335ceef75bca5f5e79cb..54d5c821007cb4280ff5a41e5fbda3bfd2f5484c 100644 (file)
@@ -1698,7 +1698,7 @@ static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
 
        meye.mchip_irq = pcidev->irq;
        if (request_irq(meye.mchip_irq, meye_irq,
-                       IRQF_DISABLED | IRQF_SHARED, "meye", meye_irq)) {
+                       IRQF_SHARED, "meye", meye_irq)) {
                v4l2_err(v4l2_dev, "request_irq failed\n");
                goto outreqirq;
        }
index 37ebc42392adb45f0de0be794548a17761be0543..970e83308525b3a0ec74cbcb5d694516d3d2d444 100644 (file)
@@ -1622,7 +1622,7 @@ static void ngene_unlink(struct ngene *dev)
 
 void ngene_shutdown(struct pci_dev *pdev)
 {
-       struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev);
+       struct ngene *dev = pci_get_drvdata(pdev);
 
        if (!dev || !shutdown_workaround)
                return;
@@ -1648,7 +1648,6 @@ void ngene_remove(struct pci_dev *pdev)
                cxd_detach(dev);
        ngene_stop(dev);
        ngene_release_buffers(dev);
-       pci_set_drvdata(pdev, NULL);
        pci_disable_device(pdev);
 }
 
@@ -1702,6 +1701,5 @@ fail1:
        ngene_release_buffers(dev);
 fail0:
        pci_disable_device(pci_dev);
-       pci_set_drvdata(pci_dev, NULL);
        return stat;
 }
index 493828500055297328376740a4e2a58d40a57a16..8164d74b46a4590af0db79f56bd8c41bacead624 100644 (file)
@@ -736,7 +736,6 @@ err_pci_release_regions:
 err_pci_disable_device:
        pci_disable_device(pdev);
 err_kfree:
-       pci_set_drvdata(pdev, NULL);
        kfree(pluto);
        goto out;
 }
@@ -765,7 +764,6 @@ static void pluto2_remove(struct pci_dev *pdev)
        pci_iounmap(pdev, pluto->io_mem);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
        kfree(pluto);
 }
 
index 75ce14229e03b6e52c70bcbd3f67cc44bd3e8be7..db887b0c37b14ff4167f2e8810ada690c6a422d6 100644 (file)
@@ -1076,7 +1076,6 @@ static void pt1_remove(struct pci_dev *pdev)
        pt1_update_power(pt1);
        pt1_cleanup_adapters(pt1);
        i2c_del_adapter(&pt1->i2c_adap);
-       pci_set_drvdata(pdev, NULL);
        kfree(pt1);
        pci_iounmap(pdev, regs);
        pci_release_regions(pdev);
@@ -1198,7 +1197,6 @@ err_i2c_del_adapter:
 err_pt1_cleanup_adapters:
        pt1_cleanup_adapters(pt1);
 err_kfree:
-       pci_set_drvdata(pdev, NULL);
        kfree(pt1);
 err_pci_iounmap:
        pci_iounmap(pdev, regs);
index dbcdfbf8aed0bdeae1f5d6ffff71bbe7a4e7d9da..dd67c8a400cc5d02f20b33967d27c9698846355b 100644 (file)
@@ -1096,7 +1096,7 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
 
 
        err = request_irq(dev->pci->irq, saa7134_alsa_irq,
-                               IRQF_SHARED | IRQF_DISABLED, dev->name,
+                               IRQF_SHARED, dev->name,
                                (void*) &dev->dmasound);
 
        if (err < 0) {
index 45f0aca597ae4c4938feaa6b18cd38d6d0abe8ca..27d7ee709c5895ddd29eb956992c6a9ebc97bff9 100644 (file)
@@ -992,7 +992,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev,
 
        /* get irq */
        err = request_irq(pci_dev->irq, saa7134_irq,
-                         IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
+                         IRQF_SHARED, dev->name, dev);
        if (err < 0) {
                printk(KERN_ERR "%s: can't get IRQ %d\n",
                       dev->name,pci_dev->irq);
index d37ee37aaefe5e4b681f402842cc33c49ddd8cb6..57ef5456f1e87e9cc042ec8dc05cdb07192bc15d 100644 (file)
@@ -1232,7 +1232,7 @@ static int saa7164_initdev(struct pci_dev *pci_dev,
        }
 
        err = request_irq(pci_dev->irq, saa7164_irq,
-               IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
+               IRQF_SHARED, dev->name, dev);
        if (err < 0) {
                printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,
                        pci_dev->irq);
@@ -1439,7 +1439,6 @@ static void saa7164_finidev(struct pci_dev *pci_dev)
 
        /* unregister stuff */
        free_irq(pci_dev->irq, dev);
-       pci_set_drvdata(pci_dev, NULL);
 
        mutex_lock(&devlist);
        list_del(&dev->devlist);
index f1cbfe5269895186372ed4ac6b30c64e728e94de..6299d5dadb822758bc4a2d9c1bb8a922bdfcd193 100644 (file)
@@ -22,7 +22,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  *
- * the project's page is at http://www.linuxtv.org/ 
+ * the project's page is at http://www.linuxtv.org/
  */
 
 /* for debugging ARM communication: */
 
 #define _NOHANDSHAKE
 
+/*
+ * Max transfer size done by av7110_fw_cmd()
+ *
+ * The maximum size passed to this function is 6 bytes. The buffer also
+ * uses two additional ones for type and size. So, 8 bytes is enough.
+ */
+#define MAX_XFER_SIZE  8
+
 /****************************************************************************
  * DEBI functions
  ****************************************************************************/
@@ -488,11 +496,18 @@ static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
 int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
 {
        va_list args;
-       u16 buf[num + 2];
+       u16 buf[MAX_XFER_SIZE];
        int i, ret;
 
 //     dprintk(4, "%p\n", av7110);
 
+       if (2 + num > sizeof(buf)) {
+               printk(KERN_WARNING
+                      "%s: %s len=%d is too big!\n",
+                      KBUILD_MODNAME, __func__, num);
+               return -EINVAL;
+       }
+
        buf[0] = ((type << 8) | com);
        buf[1] = num;
 
index 26ca8702e33f3449d1b03bd441fb1b139804b753..39ec35bd21a517f3b362c795abce5a82db27afa8 100644 (file)
@@ -1,6 +1,7 @@
 config VIDEO_ZORAN
        tristate "Zoran ZR36057/36067 Video For Linux"
        depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS
+       depends on !ALPHA
        help
          Say Y for support for MJPEG capture cards based on the Zoran
          36057/36067 PCI controller chipset. This includes the Iomega
index 923d59a321f8a9e150685447ecc12fc54044ca24..cec5b7553f284d40c0cea10a7ca3d4fb6b24cdb9 100644 (file)
@@ -1293,7 +1293,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        result = request_irq(zr->pci_dev->irq, zoran_irq,
-                            IRQF_SHARED | IRQF_DISABLED, ZR_DEVNAME(zr), zr);
+                            IRQF_SHARED, ZR_DEVNAME(zr), zr);
        if (result < 0) {
                if (result == -EINVAL) {
                        dprintk(1,
index eb70dda8cbf362c83ab53503eec1948ea5f36004..d7f0249e405004139ff1b0e42578170682ef443f 100644 (file)
@@ -143,6 +143,7 @@ if V4L_MEM2MEM_DRIVERS
 config VIDEO_CODA
        tristate "Chips&Media Coda multi-standard codec IP"
        depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MXC
+       select SRAM
        select VIDEOBUF2_DMA_CONTIG
        select V4L2_MEM2MEM_DEV
        ---help---
@@ -212,7 +213,7 @@ config VIDEO_SH_VEU
 
 config VIDEO_RENESAS_VSP1
        tristate "Renesas VSP1 Video Processing Engine"
-       depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+       depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && HAS_DMA
        select VIDEOBUF2_DMA_CONTIG
        ---help---
          This is a V4L2 driver for the Renesas VSP1 video processing engine.
@@ -220,6 +221,22 @@ config VIDEO_RENESAS_VSP1
          To compile this driver as a module, choose M here: the module
          will be called vsp1.
 
+config VIDEO_TI_VPE
+       tristate "TI VPE (Video Processing Engine) driver"
+       depends on VIDEO_DEV && VIDEO_V4L2 && SOC_DRA7XX
+       select VIDEOBUF2_DMA_CONTIG
+       select V4L2_MEM2MEM_DEV
+       default n
+       ---help---
+         Support for the TI VPE(Video Processing Engine) block
+         found on DRA7XX SoC.
+
+config VIDEO_TI_VPE_DEBUG
+       bool "VPE debug messages"
+       depends on VIDEO_TI_VPE
+       ---help---
+         Enable debug messages on VPE driver.
+
 endif # V4L_MEM2MEM_DRIVERS
 
 menuconfig V4L_TEST_DRIVERS
index 4e4da482c522a0c2617301ab8a135fe488917ca0..1348ba1faf92ad33d047d8244e2590c77cd99e2c 100644 (file)
@@ -22,6 +22,8 @@ obj-$(CONFIG_VIDEO_VIVI) += vivi.o
 
 obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
 
+obj-$(CONFIG_VIDEO_TI_VPE)             += ti-vpe/
+
 obj-$(CONFIG_VIDEO_MX2_EMMAPRP)                += mx2_emmaprp.o
 obj-$(CONFIG_VIDEO_CODA)               += coda.o
 
index 4993610051eeeb586005712060732ef2539390b2..bd72fb97fea5ab05924c4eeb4f5452534f3c3f46 100644 (file)
@@ -39,7 +39,7 @@
 
 #define CODA_NAME              "coda"
 
-#define CODA_MAX_INSTANCES     4
+#define CODADX6_MAX_INSTANCES  4
 
 #define CODA_FMO_BUF_SIZE      32
 #define CODADX6_WORK_BUF_SIZE  (288 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024)
@@ -54,8 +54,6 @@
 
 #define CODA_MAX_FRAMEBUFFERS  8
 
-#define MAX_W          8192
-#define MAX_H          8192
 #define CODA_MAX_FRAME_SIZE    0x100000
 #define FMO_SLICE_SAVE_BUF_SIZE         (32)
 #define CODA_DEFAULT_GAMMA             4096
@@ -394,14 +392,57 @@ static struct coda_codec *coda_find_codec(struct coda_dev *dev, int src_fourcc,
        return &codecs[k];
 }
 
+static void coda_get_max_dimensions(struct coda_dev *dev,
+                                   struct coda_codec *codec,
+                                   int *max_w, int *max_h)
+{
+       struct coda_codec *codecs = dev->devtype->codecs;
+       int num_codecs = dev->devtype->num_codecs;
+       unsigned int w, h;
+       int k;
+
+       if (codec) {
+               w = codec->max_w;
+               h = codec->max_h;
+       } else {
+               for (k = 0, w = 0, h = 0; k < num_codecs; k++) {
+                       w = max(w, codecs[k].max_w);
+                       h = max(h, codecs[k].max_h);
+               }
+       }
+
+       if (max_w)
+               *max_w = w;
+       if (max_h)
+               *max_h = h;
+}
+
+static char *coda_product_name(int product)
+{
+       static char buf[9];
+
+       switch (product) {
+       case CODA_DX6:
+               return "CodaDx6";
+       case CODA_7541:
+               return "CODA7541";
+       default:
+               snprintf(buf, sizeof(buf), "(0x%04x)", product);
+               return buf;
+       }
+}
+
 /*
  * V4L2 ioctl() operations.
  */
-static int vidioc_querycap(struct file *file, void *priv,
-                          struct v4l2_capability *cap)
+static int coda_querycap(struct file *file, void *priv,
+                        struct v4l2_capability *cap)
 {
+       struct coda_ctx *ctx = fh_to_ctx(priv);
+
        strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver));
-       strlcpy(cap->card, CODA_NAME, sizeof(cap->card));
+       strlcpy(cap->card, coda_product_name(ctx->dev->devtype->product),
+               sizeof(cap->card));
        strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
        /*
         * This is only a mem-to-mem video device. The capture and output
@@ -457,6 +498,8 @@ static int enum_fmt(void *priv, struct v4l2_fmtdesc *f,
                fmt = &formats[i];
                strlcpy(f->description, fmt->name, sizeof(f->description));
                f->pixelformat = fmt->fourcc;
+               if (!coda_format_is_yuv(fmt->fourcc))
+                       f->flags |= V4L2_FMT_FLAG_COMPRESSED;
                return 0;
        }
 
@@ -464,8 +507,8 @@ static int enum_fmt(void *priv, struct v4l2_fmtdesc *f,
        return -EINVAL;
 }
 
-static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
-                                  struct v4l2_fmtdesc *f)
+static int coda_enum_fmt_vid_cap(struct file *file, void *priv,
+                                struct v4l2_fmtdesc *f)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        struct vb2_queue *src_vq;
@@ -483,13 +526,14 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
        return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0);
 }
 
-static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
-                                  struct v4l2_fmtdesc *f)
+static int coda_enum_fmt_vid_out(struct file *file, void *priv,
+                                struct v4l2_fmtdesc *f)
 {
        return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_OUTPUT, 0);
 }
 
-static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
+static int coda_g_fmt(struct file *file, void *priv,
+                     struct v4l2_format *f)
 {
        struct vb2_queue *vq;
        struct coda_q_data *q_data;
@@ -516,8 +560,11 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
        return 0;
 }
 
-static int vidioc_try_fmt(struct coda_codec *codec, struct v4l2_format *f)
+static int coda_try_fmt(struct coda_ctx *ctx, struct coda_codec *codec,
+                       struct v4l2_format *f)
 {
+       struct coda_dev *dev = ctx->dev;
+       struct coda_q_data *q_data;
        unsigned int max_w, max_h;
        enum v4l2_field field;
 
@@ -531,32 +578,48 @@ static int vidioc_try_fmt(struct coda_codec *codec, struct v4l2_format *f)
         * if any of the dimensions is unsupported */
        f->fmt.pix.field = field;
 
-       if (codec) {
-               max_w = codec->max_w;
-               max_h = codec->max_h;
-       } else {
-               max_w = MAX_W;
-               max_h = MAX_H;
+       coda_get_max_dimensions(dev, codec, &max_w, &max_h);
+       v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w, W_ALIGN,
+                             &f->fmt.pix.height, MIN_H, max_h, H_ALIGN,
+                             S_ALIGN);
+
+       switch (f->fmt.pix.pixelformat) {
+       case V4L2_PIX_FMT_YUV420:
+       case V4L2_PIX_FMT_YVU420:
+       case V4L2_PIX_FMT_H264:
+       case V4L2_PIX_FMT_MPEG4:
+       case V4L2_PIX_FMT_JPEG:
+               break;
+       default:
+               q_data = get_q_data(ctx, f->type);
+               f->fmt.pix.pixelformat = q_data->fourcc;
        }
-       v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w,
-                             W_ALIGN, &f->fmt.pix.height,
-                             MIN_H, max_h, H_ALIGN, S_ALIGN);
 
-       if (coda_format_is_yuv(f->fmt.pix.pixelformat)) {
+       switch (f->fmt.pix.pixelformat) {
+       case V4L2_PIX_FMT_YUV420:
+       case V4L2_PIX_FMT_YVU420:
                /* Frame stride must be multiple of 8 */
                f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 8);
                f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
                                        f->fmt.pix.height * 3 / 2;
-       } else { /*encoded formats h.264/mpeg4 */
+               break;
+       case V4L2_PIX_FMT_H264:
+       case V4L2_PIX_FMT_MPEG4:
+       case V4L2_PIX_FMT_JPEG:
                f->fmt.pix.bytesperline = 0;
                f->fmt.pix.sizeimage = CODA_MAX_FRAME_SIZE;
+               break;
+       default:
+               BUG();
        }
 
+       f->fmt.pix.priv = 0;
+
        return 0;
 }
 
-static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
-                                 struct v4l2_format *f)
+static int coda_try_fmt_vid_cap(struct file *file, void *priv,
+                               struct v4l2_format *f)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        struct coda_codec *codec;
@@ -584,7 +647,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 
        f->fmt.pix.colorspace = ctx->colorspace;
 
-       ret = vidioc_try_fmt(codec, f);
+       ret = coda_try_fmt(ctx, codec, f);
        if (ret < 0)
                return ret;
 
@@ -600,8 +663,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
        return 0;
 }
 
-static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
-                                 struct v4l2_format *f)
+static int coda_try_fmt_vid_out(struct file *file, void *priv,
+                               struct v4l2_format *f)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        struct coda_codec *codec;
@@ -613,10 +676,10 @@ static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
        if (!f->fmt.pix.colorspace)
                f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
 
-       return vidioc_try_fmt(codec, f);
+       return coda_try_fmt(ctx, codec, f);
 }
 
-static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
+static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
 {
        struct coda_q_data *q_data;
        struct vb2_queue *vq;
@@ -646,61 +709,62 @@ static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
        return 0;
 }
 
-static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
-                               struct v4l2_format *f)
+static int coda_s_fmt_vid_cap(struct file *file, void *priv,
+                             struct v4l2_format *f)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        int ret;
 
-       ret = vidioc_try_fmt_vid_cap(file, priv, f);
+       ret = coda_try_fmt_vid_cap(file, priv, f);
        if (ret)
                return ret;
 
-       return vidioc_s_fmt(ctx, f);
+       return coda_s_fmt(ctx, f);
 }
 
-static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
-                               struct v4l2_format *f)
+static int coda_s_fmt_vid_out(struct file *file, void *priv,
+                             struct v4l2_format *f)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        int ret;
 
-       ret = vidioc_try_fmt_vid_out(file, priv, f);
+       ret = coda_try_fmt_vid_out(file, priv, f);
        if (ret)
                return ret;
 
-       ret = vidioc_s_fmt(ctx, f);
+       ret = coda_s_fmt(ctx, f);
        if (ret)
                ctx->colorspace = f->fmt.pix.colorspace;
 
        return ret;
 }
 
-static int vidioc_reqbufs(struct file *file, void *priv,
-                         struct v4l2_requestbuffers *reqbufs)
+static int coda_reqbufs(struct file *file, void *priv,
+                       struct v4l2_requestbuffers *reqbufs)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
 
        return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
 }
 
-static int vidioc_querybuf(struct file *file, void *priv,
-                          struct v4l2_buffer *buf)
+static int coda_querybuf(struct file *file, void *priv,
+                        struct v4l2_buffer *buf)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
 
        return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
 }
 
-static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+static int coda_qbuf(struct file *file, void *priv,
+                    struct v4l2_buffer *buf)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
 
        return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
 }
 
-static int vidioc_expbuf(struct file *file, void *priv,
-                        struct v4l2_exportbuffer *eb)
+static int coda_expbuf(struct file *file, void *priv,
+                      struct v4l2_exportbuffer *eb)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
 
@@ -718,7 +782,8 @@ static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
                (buf->sequence == (ctx->qsequence - 1)));
 }
 
-static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+static int coda_dqbuf(struct file *file, void *priv,
+                     struct v4l2_buffer *buf)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        int ret;
@@ -738,24 +803,24 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
        return ret;
 }
 
-static int vidioc_create_bufs(struct file *file, void *priv,
-                             struct v4l2_create_buffers *create)
+static int coda_create_bufs(struct file *file, void *priv,
+                           struct v4l2_create_buffers *create)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
 
        return v4l2_m2m_create_bufs(file, ctx->m2m_ctx, create);
 }
 
-static int vidioc_streamon(struct file *file, void *priv,
-                          enum v4l2_buf_type type)
+static int coda_streamon(struct file *file, void *priv,
+                        enum v4l2_buf_type type)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
 
        return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
 }
 
-static int vidioc_streamoff(struct file *file, void *priv,
-                           enum v4l2_buf_type type)
+static int coda_streamoff(struct file *file, void *priv,
+                         enum v4l2_buf_type type)
 {
        struct coda_ctx *ctx = fh_to_ctx(priv);
        int ret;
@@ -772,23 +837,34 @@ static int vidioc_streamoff(struct file *file, void *priv,
        return ret;
 }
 
-static int vidioc_decoder_cmd(struct file *file, void *fh,
-                             struct v4l2_decoder_cmd *dc)
+static int coda_try_decoder_cmd(struct file *file, void *fh,
+                               struct v4l2_decoder_cmd *dc)
 {
-       struct coda_ctx *ctx = fh_to_ctx(fh);
-
        if (dc->cmd != V4L2_DEC_CMD_STOP)
                return -EINVAL;
 
-       if ((dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK) ||
-           (dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY))
+       if (dc->flags & V4L2_DEC_CMD_STOP_TO_BLACK)
                return -EINVAL;
 
-       if (dc->stop.pts != 0)
+       if (!(dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY) && (dc->stop.pts != 0))
                return -EINVAL;
 
+       return 0;
+}
+
+static int coda_decoder_cmd(struct file *file, void *fh,
+                           struct v4l2_decoder_cmd *dc)
+{
+       struct coda_ctx *ctx = fh_to_ctx(fh);
+       int ret;
+
+       ret = coda_try_decoder_cmd(file, fh, dc);
+       if (ret < 0)
+               return ret;
+
+       /* Ignore decoder stop command silently in encoder context */
        if (ctx->inst_type != CODA_INST_DECODER)
-               return -EINVAL;
+               return 0;
 
        /* Set the strem-end flag on this context */
        ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG;
@@ -796,8 +872,8 @@ static int vidioc_decoder_cmd(struct file *file, void *fh,
        return 0;
 }
 
-static int vidioc_subscribe_event(struct v4l2_fh *fh,
-                                 const struct v4l2_event_subscription *sub)
+static int coda_subscribe_event(struct v4l2_fh *fh,
+                               const struct v4l2_event_subscription *sub)
 {
        switch (sub->type) {
        case V4L2_EVENT_EOS:
@@ -808,32 +884,33 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
 }
 
 static const struct v4l2_ioctl_ops coda_ioctl_ops = {
-       .vidioc_querycap        = vidioc_querycap,
+       .vidioc_querycap        = coda_querycap,
 
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap   = vidioc_g_fmt,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
-       .vidioc_s_fmt_vid_cap   = vidioc_s_fmt_vid_cap,
+       .vidioc_enum_fmt_vid_cap = coda_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap   = coda_g_fmt,
+       .vidioc_try_fmt_vid_cap = coda_try_fmt_vid_cap,
+       .vidioc_s_fmt_vid_cap   = coda_s_fmt_vid_cap,
 
-       .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
-       .vidioc_g_fmt_vid_out   = vidioc_g_fmt,
-       .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out,
-       .vidioc_s_fmt_vid_out   = vidioc_s_fmt_vid_out,
+       .vidioc_enum_fmt_vid_out = coda_enum_fmt_vid_out,
+       .vidioc_g_fmt_vid_out   = coda_g_fmt,
+       .vidioc_try_fmt_vid_out = coda_try_fmt_vid_out,
+       .vidioc_s_fmt_vid_out   = coda_s_fmt_vid_out,
 
-       .vidioc_reqbufs         = vidioc_reqbufs,
-       .vidioc_querybuf        = vidioc_querybuf,
+       .vidioc_reqbufs         = coda_reqbufs,
+       .vidioc_querybuf        = coda_querybuf,
 
-       .vidioc_qbuf            = vidioc_qbuf,
-       .vidioc_expbuf          = vidioc_expbuf,
-       .vidioc_dqbuf           = vidioc_dqbuf,
-       .vidioc_create_bufs     = vidioc_create_bufs,
+       .vidioc_qbuf            = coda_qbuf,
+       .vidioc_expbuf          = coda_expbuf,
+       .vidioc_dqbuf           = coda_dqbuf,
+       .vidioc_create_bufs     = coda_create_bufs,
 
-       .vidioc_streamon        = vidioc_streamon,
-       .vidioc_streamoff       = vidioc_streamoff,
+       .vidioc_streamon        = coda_streamon,
+       .vidioc_streamoff       = coda_streamoff,
 
-       .vidioc_decoder_cmd     = vidioc_decoder_cmd,
+       .vidioc_try_decoder_cmd = coda_try_decoder_cmd,
+       .vidioc_decoder_cmd     = coda_decoder_cmd,
 
-       .vidioc_subscribe_event = vidioc_subscribe_event,
+       .vidioc_subscribe_event = coda_subscribe_event,
        .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
 
@@ -1928,8 +2005,9 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
        if (!(ctx->streamon_out & ctx->streamon_cap))
                return 0;
 
-       /* Allow device_run with no buffers queued and after streamoff */
-       v4l2_m2m_set_src_buffered(ctx->m2m_ctx, true);
+       /* Allow decoder device_run with no new buffers queued */
+       if (ctx->inst_type == CODA_INST_DECODER)
+               v4l2_m2m_set_src_buffered(ctx->m2m_ctx, true);
 
        ctx->gopcounter = ctx->params.gop_size - 1;
        buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
@@ -2071,10 +2149,8 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
        coda_setup_iram(ctx);
 
        if (dst_fourcc == V4L2_PIX_FMT_H264) {
-               value  = (FMO_SLICE_SAVE_BUF_SIZE << 7);
-               value |= (0 & CODA_FMOPARAM_TYPE_MASK) << CODA_FMOPARAM_TYPE_OFFSET;
-               value |=  0 & CODA_FMOPARAM_SLICENUM_MASK;
                if (dev->devtype->product == CODA_DX6) {
+                       value = FMO_SLICE_SAVE_BUF_SIZE << 7;
                        coda_write(dev, value, CODADX6_CMD_ENC_SEQ_FMO);
                } else {
                        coda_write(dev, ctx->iram_info.search_ram_paddr,
@@ -2371,7 +2447,13 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
 
 static int coda_next_free_instance(struct coda_dev *dev)
 {
-       return ffz(dev->instance_mask);
+       int idx = ffz(dev->instance_mask);
+
+       if ((idx < 0) ||
+           (dev->devtype->product == CODA_DX6 && idx > CODADX6_MAX_INSTANCES))
+               return -EBUSY;
+
+       return idx;
 }
 
 static int coda_open(struct file *file)
@@ -2386,8 +2468,8 @@ static int coda_open(struct file *file)
                return -ENOMEM;
 
        idx = coda_next_free_instance(dev);
-       if (idx >= CODA_MAX_INSTANCES) {
-               ret = -EBUSY;
+       if (idx < 0) {
+               ret = idx;
                goto err_coda_max;
        }
        set_bit(idx, &dev->instance_mask);
@@ -2719,7 +2801,6 @@ static void coda_finish_encode(struct coda_ctx *ctx)
        dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
 
        /* Get results from the coda */
-       coda_read(dev, CODA_RET_ENC_PIC_TYPE);
        start_ptr = coda_read(dev, CODA_CMD_ENC_PIC_BB_START);
        wr_ptr = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx));
 
@@ -2739,7 +2820,7 @@ static void coda_finish_encode(struct coda_ctx *ctx)
        coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM);
        coda_read(dev, CODA_RET_ENC_PIC_FLAG);
 
-       if (src_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) {
+       if (coda_read(dev, CODA_RET_ENC_PIC_TYPE) == 0) {
                dst_buf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
                dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_PFRAME;
        } else {
@@ -2861,21 +2942,6 @@ static bool coda_firmware_supported(u32 vernum)
        return false;
 }
 
-static char *coda_product_name(int product)
-{
-       static char buf[9];
-
-       switch (product) {
-       case CODA_DX6:
-               return "CodaDx6";
-       case CODA_7541:
-               return "CODA7541";
-       default:
-               snprintf(buf, sizeof(buf), "(0x%04x)", product);
-               return buf;
-       }
-}
-
 static int coda_hw_init(struct coda_dev *dev)
 {
        u16 product, major, minor, release;
index 04609cc6eba70a3a5ad40c04a01a4308bccb8403..eac472b5ae83baf0cdefb0fb2920a1e99b925094 100644 (file)
@@ -1785,7 +1785,7 @@ static int vpbe_display_probe(struct platform_device *pdev)
        }
 
        irq = res->start;
-       err = devm_request_irq(&pdev->dev, irq, venc_isr, IRQF_DISABLED,
+       err = devm_request_irq(&pdev->dev, irq, venc_isr, 0,
                               VPBE_DISPLAY_DRIVER, disp_dev);
        if (err) {
                v4l2_err(&disp_dev->vpbe_dev->v4l2_dev,
index 93609091cb237d837b513ed8661a40cbce0e17bc..d762246eabf5a3b78a8c348e7a5e5f149580e143 100644 (file)
@@ -688,7 +688,7 @@ static int vpfe_attach_irq(struct vpfe_device *vpfe_dev)
        frame_format = ccdc_dev->hw_ops.get_frame_format();
        if (frame_format == CCDC_FRMFMT_PROGRESSIVE) {
                return request_irq(vpfe_dev->ccdc_irq1, vdint1_isr,
-                                   IRQF_DISABLED, "vpfe_capture1",
+                                   0, "vpfe_capture1",
                                    vpfe_dev);
        }
        return 0;
@@ -1863,7 +1863,7 @@ static int vpfe_probe(struct platform_device *pdev)
        }
        vpfe_dev->ccdc_irq1 = res1->start;
 
-       ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, IRQF_DISABLED,
+       ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, 0,
                          "vpfe_capture0", vpfe_dev);
 
        if (0 != ret) {
index 1089834a4efe8fec9845b13a27a06f1f7564c720..52ac5e6c86254d0bd7ba5a4dadee4ba6ca70d08e 100644 (file)
@@ -2154,7 +2154,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 
                        if (!vpif_obj.sd[i]) {
                                vpif_err("Error registering v4l2 subdevice\n");
-                               err = -ENOMEM;
+                               err = -ENODEV;
                                goto probe_subdev_out;
                        }
                        v4l2_info(&vpif_obj.v4l2_dev,
index 76435d3bf62d8a735c277c66724995ca78b8ab03..ef0a6564cef910c608684f1b9294c53212a36637 100644 (file)
@@ -45,6 +45,7 @@
 #define GSC_DST_FMT                    (1 << 2)
 #define GSC_CTX_M2M                    (1 << 3)
 #define GSC_CTX_STOP_REQ               (1 << 6)
+#define        GSC_CTX_ABORT                   (1 << 7)
 
 enum gsc_dev_flags {
        /* for global */
index e576ff2de3de033cfc888d2afea783d72dfd93bb..810c3e13970caec5787cfda77ff5c3c30314997d 100644 (file)
@@ -46,6 +46,17 @@ static int gsc_m2m_ctx_stop_req(struct gsc_ctx *ctx)
        return ret == 0 ? -ETIMEDOUT : ret;
 }
 
+static void __gsc_m2m_job_abort(struct gsc_ctx *ctx)
+{
+       int ret;
+
+       ret = gsc_m2m_ctx_stop_req(ctx);
+       if ((ret == -ETIMEDOUT) || (ctx->state & GSC_CTX_ABORT)) {
+               gsc_ctx_state_lock_clear(GSC_CTX_STOP_REQ | GSC_CTX_ABORT, ctx);
+               gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
+       }
+}
+
 static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 {
        struct gsc_ctx *ctx = q->drv_priv;
@@ -58,11 +69,8 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 static int gsc_m2m_stop_streaming(struct vb2_queue *q)
 {
        struct gsc_ctx *ctx = q->drv_priv;
-       int ret;
 
-       ret = gsc_m2m_ctx_stop_req(ctx);
-       if (ret == -ETIMEDOUT)
-               gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
+       __gsc_m2m_job_abort(ctx);
 
        pm_runtime_put(&ctx->gsc_dev->pdev->dev);
 
@@ -91,15 +99,9 @@ void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state)
        }
 }
 
-
 static void gsc_m2m_job_abort(void *priv)
 {
-       struct gsc_ctx *ctx = priv;
-       int ret;
-
-       ret = gsc_m2m_ctx_stop_req(ctx);
-       if (ret == -ETIMEDOUT)
-               gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
+       __gsc_m2m_job_abort((struct gsc_ctx *)priv);
 }
 
 static int gsc_get_bufs(struct gsc_ctx *ctx)
@@ -150,9 +152,10 @@ static void gsc_m2m_device_run(void *priv)
                gsc->m2m.ctx = ctx;
        }
 
-       is_set = (ctx->state & GSC_CTX_STOP_REQ) ? 1 : 0;
-       ctx->state &= ~GSC_CTX_STOP_REQ;
+       is_set = ctx->state & GSC_CTX_STOP_REQ;
        if (is_set) {
+               ctx->state &= ~GSC_CTX_STOP_REQ;
+               ctx->state |= GSC_CTX_ABORT;
                wake_up(&gsc->irq_queue);
                goto put_device;
        }
index d2e6cba3566da5a1462c648c05d6d796315cc272..f3c6136aa5b4767af56e4de4078af6cddfa48735 100644 (file)
@@ -511,7 +511,7 @@ static int __ctrl_set_metering(struct fimc_is *is, unsigned int value)
                break;
        default:
                return -EINVAL;
-       };
+       }
 
        __is_set_isp_metering(is, IS_METERING_CONFIG_CMD, val);
        return 0;
index a8351127831726bea95214d5e55d7f75535ac6d2..7a4ee4c0449deea95dc86e82a85af8412a1d5aad 100644 (file)
@@ -411,8 +411,8 @@ static int fimc_md_of_add_sensor(struct fimc_md *fmd,
 
        device_lock(&client->dev);
 
-       if (!client->driver ||
-           !try_module_get(client->driver->driver.owner)) {
+       if (!client->dev.driver ||
+           !try_module_get(client->dev.driver->owner)) {
                ret = -EPROBE_DEFER;
                v4l2_info(&fmd->v4l2_dev, "No driver found for %s\n",
                                                node->full_name);
@@ -442,7 +442,7 @@ static int fimc_md_of_add_sensor(struct fimc_md *fmd,
        fmd->num_sensors++;
 
 mod_put:
-       module_put(client->driver->driver.owner);
+       module_put(client->dev.driver->owner);
 dev_put:
        device_unlock(&client->dev);
        put_device(&client->dev);
index 540516ca872c53a05d3bce4dbcf3cb9b3a87b4e3..65cab70fefcb067e3de0a404d47bd41feaafd38b 100644 (file)
@@ -341,8 +341,7 @@ static void deinterlace_issue_dma(struct deinterlace_ctx *ctx, int op,
        ctx->xt->dir = DMA_MEM_TO_MEM;
        ctx->xt->src_sgl = false;
        ctx->xt->dst_sgl = true;
-       flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT |
-               DMA_COMPL_SKIP_DEST_UNMAP | DMA_COMPL_SKIP_SRC_UNMAP;
+       flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
 
        tx = dmadev->device_prep_interleaved_dma(chan, ctx->xt, flags);
        if (tx == NULL) {
@@ -1084,8 +1083,7 @@ free_dev:
 
 static int deinterlace_remove(struct platform_device *pdev)
 {
-       struct deinterlace_dev *pcdev =
-               (struct deinterlace_dev *)platform_get_drvdata(pdev);
+       struct deinterlace_dev *pcdev = platform_get_drvdata(pdev);
 
        v4l2_info(&pcdev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME);
        v4l2_m2m_release(pcdev->m2m_dev);
index 5184887b155c7098415b1a3470619be336023f87..32fab30a910590ba290ef987aaad8ed1df78e74f 100644 (file)
@@ -1221,16 +1221,16 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
 {
        struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
        struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
-       struct vb2_dma_sg_desc *sgd = vb2_dma_sg_plane_desc(vb, 0);
+       struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
        struct mcam_dma_desc *desc = mvb->dma_desc;
        struct scatterlist *sg;
        int i;
 
-       mvb->dma_desc_nent = dma_map_sg(cam->dev, sgd->sglist, sgd->num_pages,
-                       DMA_FROM_DEVICE);
+       mvb->dma_desc_nent = dma_map_sg(cam->dev, sg_table->sgl,
+                       sg_table->nents, DMA_FROM_DEVICE);
        if (mvb->dma_desc_nent <= 0)
                return -EIO;  /* Not sure what's right here */
-       for_each_sg(sgd->sglist, sg, mvb->dma_desc_nent, i) {
+       for_each_sg(sg_table->sgl, sg, mvb->dma_desc_nent, i) {
                desc->dma_addr = sg_dma_address(sg);
                desc->segment_len = sg_dma_len(sg);
                desc++;
@@ -1241,9 +1241,11 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
 static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
 {
        struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
-       struct vb2_dma_sg_desc *sgd = vb2_dma_sg_plane_desc(vb, 0);
+       struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
 
-       dma_unmap_sg(cam->dev, sgd->sglist, sgd->num_pages, DMA_FROM_DEVICE);
+       if (sg_table)
+               dma_unmap_sg(cam->dev, sg_table->sgl,
+                               sg_table->nents, DMA_FROM_DEVICE);
        return 0;
 }
 
index b5a19af5c587103c1c134b8b5fd0e19a13dc8853..3458fa0e2fd537916270fd9fbb0908d2b1610821 100644 (file)
@@ -481,7 +481,6 @@ static int mmpcam_remove(struct mmp_camera *cam)
        struct mmp_camera_platform_data *pdata;
 
        mmpcam_remove_device(cam);
-       free_irq(cam->irq, mcam);
        mccic_shutdown(mcam);
        mmpcam_power_down(mcam);
        pdata = cam->pdev->dev.platform_data;
index 6a17676f9d7227063fd4d22d9650d752e2695ba1..8df5975b700a01c8f433fb902e1d10e2983de5aa 100644 (file)
@@ -1090,8 +1090,7 @@ unreg_dev:
 
 static int m2mtest_remove(struct platform_device *pdev)
 {
-       struct m2mtest_dev *dev =
-               (struct m2mtest_dev *)platform_get_drvdata(pdev);
+       struct m2mtest_dev *dev = platform_get_drvdata(pdev);
 
        v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME);
        v4l2_m2m_release(dev->m2m_dev);
index fd6289d60cde2c8a25450f6cb6d24c18923f0e81..0b2948376aee9d3715c67d97346d6e775d48ab48 100644 (file)
@@ -840,7 +840,7 @@ put_clk:
 
 static int g2d_remove(struct platform_device *pdev)
 {
-       struct g2d_dev *dev = (struct g2d_dev *)platform_get_drvdata(pdev);
+       struct g2d_dev *dev = platform_get_drvdata(pdev);
 
        v4l2_info(&dev->v4l2_dev, "Removing " G2D_NAME);
        v4l2_m2m_release(dev->m2m_dev);
index 084263dd126f08bd235a46a7a54e3d855516050e..5f2c4ad6c2cb3427835ed2f40ec9ba5432ae3221 100644 (file)
@@ -404,7 +404,11 @@ leave_handle_frame:
        if (test_and_clear_bit(0, &dev->hw_lock) == 0)
                BUG();
        s5p_mfc_clock_off();
-       s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
+       /* if suspending, wake up device and do not try_run again*/
+       if (test_bit(0, &dev->enter_suspend))
+               wake_up_dev(dev, reason, err);
+       else
+               s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
 }
 
 /* Error handling for interrupt */
@@ -1101,7 +1105,7 @@ static int s5p_mfc_probe(struct platform_device *pdev)
        }
        dev->irq = res->start;
        ret = devm_request_irq(&pdev->dev, dev->irq, s5p_mfc_irq,
-                                       IRQF_DISABLED, pdev->name, dev);
+                                       0, pdev->name, dev);
        if (ret) {
                dev_err(&pdev->dev, "Failed to install irq (%d)\n", ret);
                goto err_res;
@@ -1286,9 +1290,7 @@ static int s5p_mfc_suspend(struct device *dev)
                /* Try and lock the HW */
                /* Wait on the interrupt waitqueue */
                ret = wait_event_interruptible_timeout(m_dev->queue,
-                       m_dev->int_cond || m_dev->ctx[m_dev->curr_ctx]->int_cond,
-                       msecs_to_jiffies(MFC_INT_TIMEOUT));
-
+                       m_dev->int_cond, msecs_to_jiffies(MFC_INT_TIMEOUT));
                if (ret == 0) {
                        mfc_err("Waiting for hardware to finish timed out\n");
                        return -EIO;
index ad4f1df0a18efae5c198888c5198f3de7994c205..9a6efd6c13292dec6ab9ba3ba3c052ea9772f24c 100644 (file)
@@ -111,7 +111,7 @@ static int s5p_mfc_open_inst_cmd_v5(struct s5p_mfc_ctx *ctx)
                break;
        default:
                h2r_args.arg[0] = S5P_FIMV_CODEC_NONE;
-       };
+       }
        h2r_args.arg[1] = 0; /* no crc & no pixelcache */
        h2r_args.arg[2] = ctx->ctx.ofs;
        h2r_args.arg[3] = ctx->ctx.size;
index db796c8e78747347b405debefa01f9bac17b8489..ec1a5947ed7d00649dcdaf3a7e8b151695fd6902 100644 (file)
@@ -113,7 +113,7 @@ static int s5p_mfc_open_inst_cmd_v6(struct s5p_mfc_ctx *ctx)
                break;
        default:
                codec_type = S5P_FIMV_CODEC_NONE_V6;
-       };
+       }
        mfc_write(dev, codec_type, S5P_FIMV_CODEC_TYPE_V6);
        mfc_write(dev, ctx->ctx.dma, S5P_FIMV_CONTEXT_MEM_ADDR_V6);
        mfc_write(dev, ctx->ctx.size, S5P_FIMV_CONTEXT_MEM_SIZE_V6);
index 41f5a3c10dbdd1cc9a7b6a1a4441f80e8109379d..4ff3b6cd684274a33f14bbce053657db4237f220 100644 (file)
@@ -113,7 +113,7 @@ static struct mfc_control controls[] = {
                .minimum = 0,
                .maximum = (1 << 16) - 1,
                .step = 1,
-               .default_value = 0,
+               .default_value = 12,
        },
        {
                .id = V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
@@ -356,7 +356,7 @@ static struct mfc_control controls[] = {
                .minimum = 0,
                .maximum = 51,
                .step = 1,
-               .default_value = 1,
+               .default_value = 51,
        },
        {
                .id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP,
@@ -399,7 +399,7 @@ static struct mfc_control controls[] = {
                .minimum = 1,
                .maximum = 31,
                .step = 1,
-               .default_value = 1,
+               .default_value = 31,
        },
        {
                .id = V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP,
@@ -444,7 +444,7 @@ static struct mfc_control controls[] = {
                .minimum = 0,
                .maximum = 51,
                .step = 1,
-               .default_value = 1,
+               .default_value = 51,
        },
        {
                .id = V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP,
index 368582b091bfb35ac65ef7bf81705156fe36ae82..58ec7bb26ebc715f11b145f72149b9a4535a9297 100644 (file)
@@ -1582,7 +1582,7 @@ static int s5p_mfc_get_int_reason_v5(struct s5p_mfc_dev *dev)
                break;
        default:
                reason = S5P_MFC_R2H_CMD_EMPTY;
-       };
+       }
        return reason;
 }
 
index b93a21f5aa131656cbc62649e164031ca3a08c86..74344c764daad5ebe4fa19011a83d70f5f8751e1 100644 (file)
@@ -226,7 +226,7 @@ static void mxr_graph_fix_geometry(struct mxr_layer *layer,
                        src->width + src->x_offset, 32767);
                src->full_height = clamp_val(src->full_height,
                        src->height + src->y_offset, 2047);
-       };
+       }
 }
 
 /* PUBLIC API */
index 3d13a636877be73ce50079a3d286014b6182b3c3..c9388c45ad757b48d42c7b45f7b603d03fdd0b12 100644 (file)
@@ -197,7 +197,7 @@ static void mxr_vp_fix_geometry(struct mxr_layer *layer,
                        ALIGN(src->width + src->x_offset, 8), 8192U);
                src->full_height = clamp(src->full_height,
                        src->height + src->y_offset, 8192U);
-       };
+       }
 }
 
 /* PUBLIC API */
index d02a7e0b773f4c9acec74459ce4f8fe184f3674e..6866bb4fbebc0d553fc27fdb3f72e8d2f6791f9c 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <linux/delay.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_data/camera-rcar.h>
 #define VIN_MAX_HEIGHT         2048
 
 enum chip_id {
+       RCAR_H2,
        RCAR_H1,
        RCAR_M1,
        RCAR_E1,
@@ -300,7 +302,8 @@ static int rcar_vin_setup(struct rcar_vin_priv *priv)
                dmr = 0;
                break;
        case V4L2_PIX_FMT_RGB32:
-               if (priv->chip == RCAR_H1 || priv->chip == RCAR_E1) {
+               if (priv->chip == RCAR_H2 || priv->chip == RCAR_H1 ||
+                   priv->chip == RCAR_E1) {
                        dmr = VNDMR_EXRGB;
                        break;
                }
@@ -1381,6 +1384,7 @@ static struct soc_camera_host_ops rcar_vin_host_ops = {
 };
 
 static struct platform_device_id rcar_vin_id_table[] = {
+       { "r8a7790-vin",  RCAR_H2 },
        { "r8a7779-vin",  RCAR_H1 },
        { "r8a7778-vin",  RCAR_M1 },
        { "uPD35004-vin", RCAR_E1 },
index 8df22f7791753c9492665c985a639c6c53dda8dd..150bd4df413c321ca5f48a5514213ed1c1c306a4 100644 (file)
@@ -1800,7 +1800,7 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
 
        /* request irq */
        err = devm_request_irq(&pdev->dev, pcdev->irq, sh_mobile_ceu_irq,
-                              IRQF_DISABLED, dev_name(&pdev->dev), pcdev);
+                              0, dev_name(&pdev->dev), pcdev);
        if (err) {
                dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
                goto exit_release_mem;
index 387a232d95a4b63d74a9e3d2ef8030d8cdfee08c..4b8c024fc487d3267bd905a0b42533b26e5975f3 100644 (file)
@@ -71,13 +71,23 @@ static int video_dev_create(struct soc_camera_device *icd);
 int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
                        struct v4l2_clk *clk)
 {
-       int ret = clk ? v4l2_clk_enable(clk) : 0;
-       if (ret < 0) {
-               dev_err(dev, "Cannot enable clock: %d\n", ret);
-               return ret;
+       int ret;
+       bool clock_toggle;
+
+       if (clk && (!ssdd->unbalanced_power ||
+                   !test_and_set_bit(0, &ssdd->clock_state))) {
+               ret = v4l2_clk_enable(clk);
+               if (ret < 0) {
+                       dev_err(dev, "Cannot enable clock: %d\n", ret);
+                       return ret;
+               }
+               clock_toggle = true;
+       } else {
+               clock_toggle = false;
        }
-       ret = regulator_bulk_enable(ssdd->num_regulators,
-                                       ssdd->regulators);
+
+       ret = regulator_bulk_enable(ssdd->sd_pdata.num_regulators,
+                                   ssdd->sd_pdata.regulators);
        if (ret < 0) {
                dev_err(dev, "Cannot enable regulators\n");
                goto eregenable;
@@ -95,10 +105,10 @@ int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
        return 0;
 
 epwron:
-       regulator_bulk_disable(ssdd->num_regulators,
-                              ssdd->regulators);
+       regulator_bulk_disable(ssdd->sd_pdata.num_regulators,
+                              ssdd->sd_pdata.regulators);
 eregenable:
-       if (clk)
+       if (clock_toggle)
                v4l2_clk_disable(clk);
 
        return ret;
@@ -120,14 +130,14 @@ int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd
                }
        }
 
-       err = regulator_bulk_disable(ssdd->num_regulators,
-                                    ssdd->regulators);
+       err = regulator_bulk_disable(ssdd->sd_pdata.num_regulators,
+                                    ssdd->sd_pdata.regulators);
        if (err < 0) {
                dev_err(dev, "Cannot disable regulators\n");
                ret = ret ? : err;
        }
 
-       if (clk)
+       if (clk && (!ssdd->unbalanced_power || test_and_clear_bit(0, &ssdd->clock_state)))
                v4l2_clk_disable(clk);
 
        return ret;
@@ -137,8 +147,8 @@ EXPORT_SYMBOL(soc_camera_power_off);
 int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd)
 {
        /* Should not have any effect in synchronous case */
-       return devm_regulator_bulk_get(dev, ssdd->num_regulators,
-                                      ssdd->regulators);
+       return devm_regulator_bulk_get(dev, ssdd->sd_pdata.num_regulators,
+                                      ssdd->sd_pdata.regulators);
 }
 EXPORT_SYMBOL(soc_camera_power_init);
 
@@ -1346,8 +1356,8 @@ static int soc_camera_i2c_init(struct soc_camera_device *icd,
         * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try
         * to allocate them again.
         */
-       ssdd->num_regulators = 0;
-       ssdd->regulators = NULL;
+       ssdd->sd_pdata.num_regulators = 0;
+       ssdd->sd_pdata.regulators = NULL;
        shd->board_info->platform_data = ssdd;
 
        snprintf(clk_name, sizeof(clk_name), "%d-%04x",
@@ -2020,8 +2030,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
         * that case regulators are attached to the I2C device and not to the
         * camera platform device.
         */
-       ret = devm_regulator_bulk_get(&pdev->dev, ssdd->num_regulators,
-                                     ssdd->regulators);
+       ret = devm_regulator_bulk_get(&pdev->dev, ssdd->sd_pdata.num_regulators,
+                                     ssdd->sd_pdata.regulators);
        if (ret < 0)
                return ret;
 
diff --git a/drivers/media/platform/ti-vpe/Makefile b/drivers/media/platform/ti-vpe/Makefile
new file mode 100644 (file)
index 0000000..cbf0a80
--- /dev/null
@@ -0,0 +1,5 @@
+obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
+
+ti-vpe-y := vpe.o vpdma.o
+
+ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
diff --git a/drivers/media/platform/ti-vpe/vpdma.c b/drivers/media/platform/ti-vpe/vpdma.c
new file mode 100644 (file)
index 0000000..af0a5ff
--- /dev/null
@@ -0,0 +1,846 @@
+/*
+ * VPDMA helper library
+ *
+ * Copyright (c) 2013 Texas Instruments Inc.
+ *
+ * David Griego, <dagriego@biglakesoftware.com>
+ * Dale Farnsworth, <dale@farnsworth.org>
+ * Archit Taneja, <archit@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/firmware.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/videodev2.h>
+
+#include "vpdma.h"
+#include "vpdma_priv.h"
+
+#define VPDMA_FIRMWARE "vpdma-1b8.bin"
+
+const struct vpdma_data_format vpdma_yuv_fmts[] = {
+       [VPDMA_DATA_FMT_Y444] = {
+               .data_type      = DATA_TYPE_Y444,
+               .depth          = 8,
+       },
+       [VPDMA_DATA_FMT_Y422] = {
+               .data_type      = DATA_TYPE_Y422,
+               .depth          = 8,
+       },
+       [VPDMA_DATA_FMT_Y420] = {
+               .data_type      = DATA_TYPE_Y420,
+               .depth          = 8,
+       },
+       [VPDMA_DATA_FMT_C444] = {
+               .data_type      = DATA_TYPE_C444,
+               .depth          = 8,
+       },
+       [VPDMA_DATA_FMT_C422] = {
+               .data_type      = DATA_TYPE_C422,
+               .depth          = 8,
+       },
+       [VPDMA_DATA_FMT_C420] = {
+               .data_type      = DATA_TYPE_C420,
+               .depth          = 4,
+       },
+       [VPDMA_DATA_FMT_YC422] = {
+               .data_type      = DATA_TYPE_YC422,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_YC444] = {
+               .data_type      = DATA_TYPE_YC444,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_CY422] = {
+               .data_type      = DATA_TYPE_CY422,
+               .depth          = 16,
+       },
+};
+
+const struct vpdma_data_format vpdma_rgb_fmts[] = {
+       [VPDMA_DATA_FMT_RGB565] = {
+               .data_type      = DATA_TYPE_RGB16_565,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_ARGB16_1555] = {
+               .data_type      = DATA_TYPE_ARGB_1555,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_ARGB16] = {
+               .data_type      = DATA_TYPE_ARGB_4444,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_RGBA16_5551] = {
+               .data_type      = DATA_TYPE_RGBA_5551,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_RGBA16] = {
+               .data_type      = DATA_TYPE_RGBA_4444,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_ARGB24] = {
+               .data_type      = DATA_TYPE_ARGB24_6666,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_RGB24] = {
+               .data_type      = DATA_TYPE_RGB24_888,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_ARGB32] = {
+               .data_type      = DATA_TYPE_ARGB32_8888,
+               .depth          = 32,
+       },
+       [VPDMA_DATA_FMT_RGBA24] = {
+               .data_type      = DATA_TYPE_RGBA24_6666,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_RGBA32] = {
+               .data_type      = DATA_TYPE_RGBA32_8888,
+               .depth          = 32,
+       },
+       [VPDMA_DATA_FMT_BGR565] = {
+               .data_type      = DATA_TYPE_BGR16_565,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_ABGR16_1555] = {
+               .data_type      = DATA_TYPE_ABGR_1555,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_ABGR16] = {
+               .data_type      = DATA_TYPE_ABGR_4444,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_BGRA16_5551] = {
+               .data_type      = DATA_TYPE_BGRA_5551,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_BGRA16] = {
+               .data_type      = DATA_TYPE_BGRA_4444,
+               .depth          = 16,
+       },
+       [VPDMA_DATA_FMT_ABGR24] = {
+               .data_type      = DATA_TYPE_ABGR24_6666,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_BGR24] = {
+               .data_type      = DATA_TYPE_BGR24_888,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_ABGR32] = {
+               .data_type      = DATA_TYPE_ABGR32_8888,
+               .depth          = 32,
+       },
+       [VPDMA_DATA_FMT_BGRA24] = {
+               .data_type      = DATA_TYPE_BGRA24_6666,
+               .depth          = 24,
+       },
+       [VPDMA_DATA_FMT_BGRA32] = {
+               .data_type      = DATA_TYPE_BGRA32_8888,
+               .depth          = 32,
+       },
+};
+
+const struct vpdma_data_format vpdma_misc_fmts[] = {
+       [VPDMA_DATA_FMT_MV] = {
+               .data_type      = DATA_TYPE_MV,
+               .depth          = 4,
+       },
+};
+
+struct vpdma_channel_info {
+       int num;                /* VPDMA channel number */
+       int cstat_offset;       /* client CSTAT register offset */
+};
+
+static const struct vpdma_channel_info chan_info[] = {
+       [VPE_CHAN_LUMA1_IN] = {
+               .num            = VPE_CHAN_NUM_LUMA1_IN,
+               .cstat_offset   = VPDMA_DEI_LUMA1_CSTAT,
+       },
+       [VPE_CHAN_CHROMA1_IN] = {
+               .num            = VPE_CHAN_NUM_CHROMA1_IN,
+               .cstat_offset   = VPDMA_DEI_CHROMA1_CSTAT,
+       },
+       [VPE_CHAN_LUMA2_IN] = {
+               .num            = VPE_CHAN_NUM_LUMA2_IN,
+               .cstat_offset   = VPDMA_DEI_LUMA2_CSTAT,
+       },
+       [VPE_CHAN_CHROMA2_IN] = {
+               .num            = VPE_CHAN_NUM_CHROMA2_IN,
+               .cstat_offset   = VPDMA_DEI_CHROMA2_CSTAT,
+       },
+       [VPE_CHAN_LUMA3_IN] = {
+               .num            = VPE_CHAN_NUM_LUMA3_IN,
+               .cstat_offset   = VPDMA_DEI_LUMA3_CSTAT,
+       },
+       [VPE_CHAN_CHROMA3_IN] = {
+               .num            = VPE_CHAN_NUM_CHROMA3_IN,
+               .cstat_offset   = VPDMA_DEI_CHROMA3_CSTAT,
+       },
+       [VPE_CHAN_MV_IN] = {
+               .num            = VPE_CHAN_NUM_MV_IN,
+               .cstat_offset   = VPDMA_DEI_MV_IN_CSTAT,
+       },
+       [VPE_CHAN_MV_OUT] = {
+               .num            = VPE_CHAN_NUM_MV_OUT,
+               .cstat_offset   = VPDMA_DEI_MV_OUT_CSTAT,
+       },
+       [VPE_CHAN_LUMA_OUT] = {
+               .num            = VPE_CHAN_NUM_LUMA_OUT,
+               .cstat_offset   = VPDMA_VIP_UP_Y_CSTAT,
+       },
+       [VPE_CHAN_CHROMA_OUT] = {
+               .num            = VPE_CHAN_NUM_CHROMA_OUT,
+               .cstat_offset   = VPDMA_VIP_UP_UV_CSTAT,
+       },
+       [VPE_CHAN_RGB_OUT] = {
+               .num            = VPE_CHAN_NUM_RGB_OUT,
+               .cstat_offset   = VPDMA_VIP_UP_Y_CSTAT,
+       },
+};
+
+static u32 read_reg(struct vpdma_data *vpdma, int offset)
+{
+       return ioread32(vpdma->base + offset);
+}
+
+static void write_reg(struct vpdma_data *vpdma, int offset, u32 value)
+{
+       iowrite32(value, vpdma->base + offset);
+}
+
+static int read_field_reg(struct vpdma_data *vpdma, int offset,
+               u32 mask, int shift)
+{
+       return (read_reg(vpdma, offset) & (mask << shift)) >> shift;
+}
+
+static void write_field_reg(struct vpdma_data *vpdma, int offset, u32 field,
+               u32 mask, int shift)
+{
+       u32 val = read_reg(vpdma, offset);
+
+       val &= ~(mask << shift);
+       val |= (field & mask) << shift;
+
+       write_reg(vpdma, offset, val);
+}
+
+void vpdma_dump_regs(struct vpdma_data *vpdma)
+{
+       struct device *dev = &vpdma->pdev->dev;
+
+#define DUMPREG(r) dev_dbg(dev, "%-35s %08x\n", #r, read_reg(vpdma, VPDMA_##r))
+
+       dev_dbg(dev, "VPDMA Registers:\n");
+
+       DUMPREG(PID);
+       DUMPREG(LIST_ADDR);
+       DUMPREG(LIST_ATTR);
+       DUMPREG(LIST_STAT_SYNC);
+       DUMPREG(BG_RGB);
+       DUMPREG(BG_YUV);
+       DUMPREG(SETUP);
+       DUMPREG(MAX_SIZE1);
+       DUMPREG(MAX_SIZE2);
+       DUMPREG(MAX_SIZE3);
+
+       /*
+        * dumping registers of only group0 and group3, because VPE channels
+        * lie within group0 and group3 registers
+        */
+       DUMPREG(INT_CHAN_STAT(0));
+       DUMPREG(INT_CHAN_MASK(0));
+       DUMPREG(INT_CHAN_STAT(3));
+       DUMPREG(INT_CHAN_MASK(3));
+       DUMPREG(INT_CLIENT0_STAT);
+       DUMPREG(INT_CLIENT0_MASK);
+       DUMPREG(INT_CLIENT1_STAT);
+       DUMPREG(INT_CLIENT1_MASK);
+       DUMPREG(INT_LIST0_STAT);
+       DUMPREG(INT_LIST0_MASK);
+
+       /*
+        * these are registers specific to VPE clients, we can make this
+        * function dump client registers specific to VPE or VIP based on
+        * who is using it
+        */
+       DUMPREG(DEI_CHROMA1_CSTAT);
+       DUMPREG(DEI_LUMA1_CSTAT);
+       DUMPREG(DEI_CHROMA2_CSTAT);
+       DUMPREG(DEI_LUMA2_CSTAT);
+       DUMPREG(DEI_CHROMA3_CSTAT);
+       DUMPREG(DEI_LUMA3_CSTAT);
+       DUMPREG(DEI_MV_IN_CSTAT);
+       DUMPREG(DEI_MV_OUT_CSTAT);
+       DUMPREG(VIP_UP_Y_CSTAT);
+       DUMPREG(VIP_UP_UV_CSTAT);
+       DUMPREG(VPI_CTL_CSTAT);
+}
+
+/*
+ * Allocate a DMA buffer
+ */
+int vpdma_alloc_desc_buf(struct vpdma_buf *buf, size_t size)
+{
+       buf->size = size;
+       buf->mapped = false;
+       buf->addr = kzalloc(size, GFP_KERNEL);
+       if (!buf->addr)
+               return -ENOMEM;
+
+       WARN_ON((u32) buf->addr & VPDMA_DESC_ALIGN);
+
+       return 0;
+}
+
+void vpdma_free_desc_buf(struct vpdma_buf *buf)
+{
+       WARN_ON(buf->mapped);
+       kfree(buf->addr);
+       buf->addr = NULL;
+       buf->size = 0;
+}
+
+/*
+ * map descriptor/payload DMA buffer, enabling DMA access
+ */
+int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf)
+{
+       struct device *dev = &vpdma->pdev->dev;
+
+       WARN_ON(buf->mapped);
+       buf->dma_addr = dma_map_single(dev, buf->addr, buf->size,
+                               DMA_TO_DEVICE);
+       if (dma_mapping_error(dev, buf->dma_addr)) {
+               dev_err(dev, "failed to map buffer\n");
+               return -EINVAL;
+       }
+
+       buf->mapped = true;
+
+       return 0;
+}
+
+/*
+ * unmap descriptor/payload DMA buffer, disabling DMA access and
+ * allowing the main processor to acces the data
+ */
+void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf)
+{
+       struct device *dev = &vpdma->pdev->dev;
+
+       if (buf->mapped)
+               dma_unmap_single(dev, buf->dma_addr, buf->size, DMA_TO_DEVICE);
+
+       buf->mapped = false;
+}
+
+/*
+ * create a descriptor list, the user of this list will append configuration,
+ * control and data descriptors to this list, this list will be submitted to
+ * VPDMA. VPDMA's list parser will go through each descriptor and perform the
+ * required DMA operations
+ */
+int vpdma_create_desc_list(struct vpdma_desc_list *list, size_t size, int type)
+{
+       int r;
+
+       r = vpdma_alloc_desc_buf(&list->buf, size);
+       if (r)
+               return r;
+
+       list->next = list->buf.addr;
+
+       list->type = type;
+
+       return 0;
+}
+
+/*
+ * once a descriptor list is parsed by VPDMA, we reset the list by emptying it,
+ * to allow new descriptors to be added to the list.
+ */
+void vpdma_reset_desc_list(struct vpdma_desc_list *list)
+{
+       list->next = list->buf.addr;
+}
+
+/*
+ * free the buffer allocated fot the VPDMA descriptor list, this should be
+ * called when the user doesn't want to use VPDMA any more.
+ */
+void vpdma_free_desc_list(struct vpdma_desc_list *list)
+{
+       vpdma_free_desc_buf(&list->buf);
+
+       list->next = NULL;
+}
+
+static bool vpdma_list_busy(struct vpdma_data *vpdma, int list_num)
+{
+       return read_reg(vpdma, VPDMA_LIST_STAT_SYNC) & BIT(list_num + 16);
+}
+
+/*
+ * submit a list of DMA descriptors to the VPE VPDMA, do not wait for completion
+ */
+int vpdma_submit_descs(struct vpdma_data *vpdma, struct vpdma_desc_list *list)
+{
+       /* we always use the first list */
+       int list_num = 0;
+       int list_size;
+
+       if (vpdma_list_busy(vpdma, list_num))
+               return -EBUSY;
+
+       /* 16-byte granularity */
+       list_size = (list->next - list->buf.addr) >> 4;
+
+       write_reg(vpdma, VPDMA_LIST_ADDR, (u32) list->buf.dma_addr);
+
+       write_reg(vpdma, VPDMA_LIST_ATTR,
+                       (list_num << VPDMA_LIST_NUM_SHFT) |
+                       (list->type << VPDMA_LIST_TYPE_SHFT) |
+                       list_size);
+
+       return 0;
+}
+
+static void dump_cfd(struct vpdma_cfd *cfd)
+{
+       int class;
+
+       class = cfd_get_class(cfd);
+
+       pr_debug("config descriptor of payload class: %s\n",
+               class == CFD_CLS_BLOCK ? "simple block" :
+               "address data block");
+
+       if (class == CFD_CLS_BLOCK)
+               pr_debug("word0: dst_addr_offset = 0x%08x\n",
+                       cfd->dest_addr_offset);
+
+       if (class == CFD_CLS_BLOCK)
+               pr_debug("word1: num_data_wrds = %d\n", cfd->block_len);
+
+       pr_debug("word2: payload_addr = 0x%08x\n", cfd->payload_addr);
+
+       pr_debug("word3: pkt_type = %d, direct = %d, class = %d, dest = %d, "
+               "payload_len = %d\n", cfd_get_pkt_type(cfd),
+               cfd_get_direct(cfd), class, cfd_get_dest(cfd),
+               cfd_get_payload_len(cfd));
+}
+
+/*
+ * append a configuration descriptor to the given descriptor list, where the
+ * payload is in the form of a simple data block specified in the descriptor
+ * header, this is used to upload scaler coefficients to the scaler module
+ */
+void vpdma_add_cfd_block(struct vpdma_desc_list *list, int client,
+               struct vpdma_buf *blk, u32 dest_offset)
+{
+       struct vpdma_cfd *cfd;
+       int len = blk->size;
+
+       WARN_ON(blk->dma_addr & VPDMA_DESC_ALIGN);
+
+       cfd = list->next;
+       WARN_ON((void *)(cfd + 1) > (list->buf.addr + list->buf.size));
+
+       cfd->dest_addr_offset = dest_offset;
+       cfd->block_len = len;
+       cfd->payload_addr = (u32) blk->dma_addr;
+       cfd->ctl_payload_len = cfd_pkt_payload_len(CFD_INDIRECT, CFD_CLS_BLOCK,
+                               client, len >> 4);
+
+       list->next = cfd + 1;
+
+       dump_cfd(cfd);
+}
+
+/*
+ * append a configuration descriptor to the given descriptor list, where the
+ * payload is in the address data block format, this is used to a configure a
+ * discontiguous set of MMRs
+ */
+void vpdma_add_cfd_adb(struct vpdma_desc_list *list, int client,
+               struct vpdma_buf *adb)
+{
+       struct vpdma_cfd *cfd;
+       unsigned int len = adb->size;
+
+       WARN_ON(len & VPDMA_ADB_SIZE_ALIGN);
+       WARN_ON(adb->dma_addr & VPDMA_DESC_ALIGN);
+
+       cfd = list->next;
+       BUG_ON((void *)(cfd + 1) > (list->buf.addr + list->buf.size));
+
+       cfd->w0 = 0;
+       cfd->w1 = 0;
+       cfd->payload_addr = (u32) adb->dma_addr;
+       cfd->ctl_payload_len = cfd_pkt_payload_len(CFD_INDIRECT, CFD_CLS_ADB,
+                               client, len >> 4);
+
+       list->next = cfd + 1;
+
+       dump_cfd(cfd);
+};
+
+/*
+ * control descriptor format change based on what type of control descriptor it
+ * is, we only use 'sync on channel' control descriptors for now, so assume it's
+ * that
+ */
+static void dump_ctd(struct vpdma_ctd *ctd)
+{
+       pr_debug("control descriptor\n");
+
+       pr_debug("word3: pkt_type = %d, source = %d, ctl_type = %d\n",
+               ctd_get_pkt_type(ctd), ctd_get_source(ctd), ctd_get_ctl(ctd));
+}
+
+/*
+ * append a 'sync on channel' type control descriptor to the given descriptor
+ * list, this descriptor stalls the VPDMA list till the time DMA is completed
+ * on the specified channel
+ */
+void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list *list,
+               enum vpdma_channel chan)
+{
+       struct vpdma_ctd *ctd;
+
+       ctd = list->next;
+       WARN_ON((void *)(ctd + 1) > (list->buf.addr + list->buf.size));
+
+       ctd->w0 = 0;
+       ctd->w1 = 0;
+       ctd->w2 = 0;
+       ctd->type_source_ctl = ctd_type_source_ctl(chan_info[chan].num,
+                               CTD_TYPE_SYNC_ON_CHANNEL);
+
+       list->next = ctd + 1;
+
+       dump_ctd(ctd);
+}
+
+static void dump_dtd(struct vpdma_dtd *dtd)
+{
+       int dir, chan;
+
+       dir = dtd_get_dir(dtd);
+       chan = dtd_get_chan(dtd);
+
+       pr_debug("%s data transfer descriptor for channel %d\n",
+               dir == DTD_DIR_OUT ? "outbound" : "inbound", chan);
+
+       pr_debug("word0: data_type = %d, notify = %d, field = %d, 1D = %d, "
+               "even_ln_skp = %d, odd_ln_skp = %d, line_stride = %d\n",
+               dtd_get_data_type(dtd), dtd_get_notify(dtd), dtd_get_field(dtd),
+               dtd_get_1d(dtd), dtd_get_even_line_skip(dtd),
+               dtd_get_odd_line_skip(dtd), dtd_get_line_stride(dtd));
+
+       if (dir == DTD_DIR_IN)
+               pr_debug("word1: line_length = %d, xfer_height = %d\n",
+                       dtd_get_line_length(dtd), dtd_get_xfer_height(dtd));
+
+       pr_debug("word2: start_addr = 0x%08x\n", dtd->start_addr);
+
+       pr_debug("word3: pkt_type = %d, mode = %d, dir = %d, chan = %d, "
+               "pri = %d, next_chan = %d\n", dtd_get_pkt_type(dtd),
+               dtd_get_mode(dtd), dir, chan, dtd_get_priority(dtd),
+               dtd_get_next_chan(dtd));
+
+       if (dir == DTD_DIR_IN)
+               pr_debug("word4: frame_width = %d, frame_height = %d\n",
+                       dtd_get_frame_width(dtd), dtd_get_frame_height(dtd));
+       else
+               pr_debug("word4: desc_write_addr = 0x%08x, write_desc = %d, "
+                       "drp_data = %d, use_desc_reg = %d\n",
+                       dtd_get_desc_write_addr(dtd), dtd_get_write_desc(dtd),
+                       dtd_get_drop_data(dtd), dtd_get_use_desc(dtd));
+
+       if (dir == DTD_DIR_IN)
+               pr_debug("word5: hor_start = %d, ver_start = %d\n",
+                       dtd_get_h_start(dtd), dtd_get_v_start(dtd));
+       else
+               pr_debug("word5: max_width %d, max_height %d\n",
+                       dtd_get_max_width(dtd), dtd_get_max_height(dtd));
+
+       pr_debug("word6: client specfic attr0 = 0x%08x\n", dtd->client_attr0);
+       pr_debug("word7: client specfic attr1 = 0x%08x\n", dtd->client_attr1);
+}
+
+/*
+ * append an outbound data transfer descriptor to the given descriptor list,
+ * this sets up a 'client to memory' VPDMA transfer for the given VPDMA channel
+ */
+void vpdma_add_out_dtd(struct vpdma_desc_list *list, struct v4l2_rect *c_rect,
+               const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
+               enum vpdma_channel chan, u32 flags)
+{
+       int priority = 0;
+       int field = 0;
+       int notify = 1;
+       int channel, next_chan;
+       int depth = fmt->depth;
+       int stride;
+       struct vpdma_dtd *dtd;
+
+       channel = next_chan = chan_info[chan].num;
+
+       if (fmt->data_type == DATA_TYPE_C420)
+               depth = 8;
+
+       stride = (depth * c_rect->width) >> 3;
+       dma_addr += (c_rect->left * depth) >> 3;
+
+       dtd = list->next;
+       WARN_ON((void *)(dtd + 1) > (list->buf.addr + list->buf.size));
+
+       dtd->type_ctl_stride = dtd_type_ctl_stride(fmt->data_type,
+                                       notify,
+                                       field,
+                                       !!(flags & VPDMA_DATA_FRAME_1D),
+                                       !!(flags & VPDMA_DATA_EVEN_LINE_SKIP),
+                                       !!(flags & VPDMA_DATA_ODD_LINE_SKIP),
+                                       stride);
+       dtd->w1 = 0;
+       dtd->start_addr = (u32) dma_addr;
+       dtd->pkt_ctl = dtd_pkt_ctl(!!(flags & VPDMA_DATA_MODE_TILED),
+                               DTD_DIR_OUT, channel, priority, next_chan);
+       dtd->desc_write_addr = dtd_desc_write_addr(0, 0, 0, 0);
+       dtd->max_width_height = dtd_max_width_height(MAX_OUT_WIDTH_1920,
+                                       MAX_OUT_HEIGHT_1080);
+       dtd->client_attr0 = 0;
+       dtd->client_attr1 = 0;
+
+       list->next = dtd + 1;
+
+       dump_dtd(dtd);
+}
+
+/*
+ * append an inbound data transfer descriptor to the given descriptor list,
+ * this sets up a 'memory to client' VPDMA transfer for the given VPDMA channel
+ */
+void vpdma_add_in_dtd(struct vpdma_desc_list *list, int frame_width,
+               int frame_height, struct v4l2_rect *c_rect,
+               const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
+               enum vpdma_channel chan, int field, u32 flags)
+{
+       int priority = 0;
+       int notify = 1;
+       int depth = fmt->depth;
+       int channel, next_chan;
+       int stride;
+       int height = c_rect->height;
+       struct vpdma_dtd *dtd;
+
+       channel = next_chan = chan_info[chan].num;
+
+       if (fmt->data_type == DATA_TYPE_C420) {
+               height >>= 1;
+               frame_height >>= 1;
+               depth = 8;
+       }
+
+       stride = (depth * c_rect->width) >> 3;
+       dma_addr += (c_rect->left * depth) >> 3;
+
+       dtd = list->next;
+       WARN_ON((void *)(dtd + 1) > (list->buf.addr + list->buf.size));
+
+       dtd->type_ctl_stride = dtd_type_ctl_stride(fmt->data_type,
+                                       notify,
+                                       field,
+                                       !!(flags & VPDMA_DATA_FRAME_1D),
+                                       !!(flags & VPDMA_DATA_EVEN_LINE_SKIP),
+                                       !!(flags & VPDMA_DATA_ODD_LINE_SKIP),
+                                       stride);
+
+       dtd->xfer_length_height = dtd_xfer_length_height(c_rect->width, height);
+       dtd->start_addr = (u32) dma_addr;
+       dtd->pkt_ctl = dtd_pkt_ctl(!!(flags & VPDMA_DATA_MODE_TILED),
+                               DTD_DIR_IN, channel, priority, next_chan);
+       dtd->frame_width_height = dtd_frame_width_height(frame_width,
+                                       frame_height);
+       dtd->start_h_v = dtd_start_h_v(c_rect->left, c_rect->top);
+       dtd->client_attr0 = 0;
+       dtd->client_attr1 = 0;
+
+       list->next = dtd + 1;
+
+       dump_dtd(dtd);
+}
+
+/* set or clear the mask for list complete interrupt */
+void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int list_num,
+               bool enable)
+{
+       u32 val;
+
+       val = read_reg(vpdma, VPDMA_INT_LIST0_MASK);
+       if (enable)
+               val |= (1 << (list_num * 2));
+       else
+               val &= ~(1 << (list_num * 2));
+       write_reg(vpdma, VPDMA_INT_LIST0_MASK, val);
+}
+
+/* clear previosuly occured list intterupts in the LIST_STAT register */
+void vpdma_clear_list_stat(struct vpdma_data *vpdma)
+{
+       write_reg(vpdma, VPDMA_INT_LIST0_STAT,
+               read_reg(vpdma, VPDMA_INT_LIST0_STAT));
+}
+
+/*
+ * configures the output mode of the line buffer for the given client, the
+ * line buffer content can either be mirrored(each line repeated twice) or
+ * passed to the client as is
+ */
+void vpdma_set_line_mode(struct vpdma_data *vpdma, int line_mode,
+               enum vpdma_channel chan)
+{
+       int client_cstat = chan_info[chan].cstat_offset;
+
+       write_field_reg(vpdma, client_cstat, line_mode,
+               VPDMA_CSTAT_LINE_MODE_MASK, VPDMA_CSTAT_LINE_MODE_SHIFT);
+}
+
+/*
+ * configures the event which should trigger VPDMA transfer for the given
+ * client
+ */
+void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
+               enum vpdma_frame_start_event fs_event,
+               enum vpdma_channel chan)
+{
+       int client_cstat = chan_info[chan].cstat_offset;
+
+       write_field_reg(vpdma, client_cstat, fs_event,
+               VPDMA_CSTAT_FRAME_START_MASK, VPDMA_CSTAT_FRAME_START_SHIFT);
+}
+
+static void vpdma_firmware_cb(const struct firmware *f, void *context)
+{
+       struct vpdma_data *vpdma = context;
+       struct vpdma_buf fw_dma_buf;
+       int i, r;
+
+       dev_dbg(&vpdma->pdev->dev, "firmware callback\n");
+
+       if (!f || !f->data) {
+               dev_err(&vpdma->pdev->dev, "couldn't get firmware\n");
+               return;
+       }
+
+       /* already initialized */
+       if (read_field_reg(vpdma, VPDMA_LIST_ATTR, VPDMA_LIST_RDY_MASK,
+                       VPDMA_LIST_RDY_SHFT)) {
+               vpdma->ready = true;
+               return;
+       }
+
+       r = vpdma_alloc_desc_buf(&fw_dma_buf, f->size);
+       if (r) {
+               dev_err(&vpdma->pdev->dev,
+                       "failed to allocate dma buffer for firmware\n");
+               goto rel_fw;
+       }
+
+       memcpy(fw_dma_buf.addr, f->data, f->size);
+
+       vpdma_map_desc_buf(vpdma, &fw_dma_buf);
+
+       write_reg(vpdma, VPDMA_LIST_ADDR, (u32) fw_dma_buf.dma_addr);
+
+       for (i = 0; i < 100; i++) {             /* max 1 second */
+               msleep_interruptible(10);
+
+               if (read_field_reg(vpdma, VPDMA_LIST_ATTR, VPDMA_LIST_RDY_MASK,
+                               VPDMA_LIST_RDY_SHFT))
+                       break;
+       }
+
+       if (i == 100) {
+               dev_err(&vpdma->pdev->dev, "firmware upload failed\n");
+               goto free_buf;
+       }
+
+       vpdma->ready = true;
+
+free_buf:
+       vpdma_unmap_desc_buf(vpdma, &fw_dma_buf);
+
+       vpdma_free_desc_buf(&fw_dma_buf);
+rel_fw:
+       release_firmware(f);
+}
+
+static int vpdma_load_firmware(struct vpdma_data *vpdma)
+{
+       int r;
+       struct device *dev = &vpdma->pdev->dev;
+
+       r = request_firmware_nowait(THIS_MODULE, 1,
+               (const char *) VPDMA_FIRMWARE, dev, GFP_KERNEL, vpdma,
+               vpdma_firmware_cb);
+       if (r) {
+               dev_err(dev, "firmware not available %s\n", VPDMA_FIRMWARE);
+               return r;
+       } else {
+               dev_info(dev, "loading firmware %s\n", VPDMA_FIRMWARE);
+       }
+
+       return 0;
+}
+
+struct vpdma_data *vpdma_create(struct platform_device *pdev)
+{
+       struct resource *res;
+       struct vpdma_data *vpdma;
+       int r;
+
+       dev_dbg(&pdev->dev, "vpdma_create\n");
+
+       vpdma = devm_kzalloc(&pdev->dev, sizeof(*vpdma), GFP_KERNEL);
+       if (!vpdma) {
+               dev_err(&pdev->dev, "couldn't alloc vpdma_dev\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       vpdma->pdev = pdev;
+
+       res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
+       if (res == NULL) {
+               dev_err(&pdev->dev, "missing platform resources data\n");
+               return ERR_PTR(-ENODEV);
+       }
+
+       vpdma->base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+       if (!vpdma->base) {
+               dev_err(&pdev->dev, "failed to ioremap\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       r = vpdma_load_firmware(vpdma);
+       if (r) {
+               pr_err("failed to load firmware %s\n", VPDMA_FIRMWARE);
+               return ERR_PTR(r);
+       }
+
+       return vpdma;
+}
+MODULE_FIRMWARE(VPDMA_FIRMWARE);
diff --git a/drivers/media/platform/ti-vpe/vpdma.h b/drivers/media/platform/ti-vpe/vpdma.h
new file mode 100644 (file)
index 0000000..eaa2a71
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2013 Texas Instruments Inc.
+ *
+ * David Griego, <dagriego@biglakesoftware.com>
+ * Dale Farnsworth, <dale@farnsworth.org>
+ * Archit Taneja, <archit@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef __TI_VPDMA_H_
+#define __TI_VPDMA_H_
+
+/*
+ * A vpdma_buf tracks the size, DMA address and mapping status of each
+ * driver DMA area.
+ */
+struct vpdma_buf {
+       void                    *addr;
+       dma_addr_t              dma_addr;
+       size_t                  size;
+       bool                    mapped;
+};
+
+struct vpdma_desc_list {
+       struct vpdma_buf buf;
+       void *next;
+       int type;
+};
+
+struct vpdma_data {
+       void __iomem            *base;
+
+       struct platform_device  *pdev;
+
+       /* tells whether vpdma firmware is loaded or not */
+       bool ready;
+};
+
+struct vpdma_data_format {
+       int data_type;
+       u8 depth;
+};
+
+#define VPDMA_DESC_ALIGN               16      /* 16-byte descriptor alignment */
+
+#define VPDMA_DTD_DESC_SIZE            32      /* 8 words */
+#define VPDMA_CFD_CTD_DESC_SIZE                16      /* 4 words */
+
+#define VPDMA_LIST_TYPE_NORMAL         0
+#define VPDMA_LIST_TYPE_SELF_MODIFYING 1
+#define VPDMA_LIST_TYPE_DOORBELL       2
+
+enum vpdma_yuv_formats {
+       VPDMA_DATA_FMT_Y444 = 0,
+       VPDMA_DATA_FMT_Y422,
+       VPDMA_DATA_FMT_Y420,
+       VPDMA_DATA_FMT_C444,
+       VPDMA_DATA_FMT_C422,
+       VPDMA_DATA_FMT_C420,
+       VPDMA_DATA_FMT_YC422,
+       VPDMA_DATA_FMT_YC444,
+       VPDMA_DATA_FMT_CY422,
+};
+
+enum vpdma_rgb_formats {
+       VPDMA_DATA_FMT_RGB565 = 0,
+       VPDMA_DATA_FMT_ARGB16_1555,
+       VPDMA_DATA_FMT_ARGB16,
+       VPDMA_DATA_FMT_RGBA16_5551,
+       VPDMA_DATA_FMT_RGBA16,
+       VPDMA_DATA_FMT_ARGB24,
+       VPDMA_DATA_FMT_RGB24,
+       VPDMA_DATA_FMT_ARGB32,
+       VPDMA_DATA_FMT_RGBA24,
+       VPDMA_DATA_FMT_RGBA32,
+       VPDMA_DATA_FMT_BGR565,
+       VPDMA_DATA_FMT_ABGR16_1555,
+       VPDMA_DATA_FMT_ABGR16,
+       VPDMA_DATA_FMT_BGRA16_5551,
+       VPDMA_DATA_FMT_BGRA16,
+       VPDMA_DATA_FMT_ABGR24,
+       VPDMA_DATA_FMT_BGR24,
+       VPDMA_DATA_FMT_ABGR32,
+       VPDMA_DATA_FMT_BGRA24,
+       VPDMA_DATA_FMT_BGRA32,
+};
+
+enum vpdma_misc_formats {
+       VPDMA_DATA_FMT_MV = 0,
+};
+
+extern const struct vpdma_data_format vpdma_yuv_fmts[];
+extern const struct vpdma_data_format vpdma_rgb_fmts[];
+extern const struct vpdma_data_format vpdma_misc_fmts[];
+
+enum vpdma_frame_start_event {
+       VPDMA_FSEVENT_HDMI_FID = 0,
+       VPDMA_FSEVENT_DVO2_FID,
+       VPDMA_FSEVENT_HDCOMP_FID,
+       VPDMA_FSEVENT_SD_FID,
+       VPDMA_FSEVENT_LM_FID0,
+       VPDMA_FSEVENT_LM_FID1,
+       VPDMA_FSEVENT_LM_FID2,
+       VPDMA_FSEVENT_CHANNEL_ACTIVE,
+};
+
+/*
+ * VPDMA channel numbers
+ */
+enum vpdma_channel {
+       VPE_CHAN_LUMA1_IN,
+       VPE_CHAN_CHROMA1_IN,
+       VPE_CHAN_LUMA2_IN,
+       VPE_CHAN_CHROMA2_IN,
+       VPE_CHAN_LUMA3_IN,
+       VPE_CHAN_CHROMA3_IN,
+       VPE_CHAN_MV_IN,
+       VPE_CHAN_MV_OUT,
+       VPE_CHAN_LUMA_OUT,
+       VPE_CHAN_CHROMA_OUT,
+       VPE_CHAN_RGB_OUT,
+};
+
+/* flags for VPDMA data descriptors */
+#define VPDMA_DATA_ODD_LINE_SKIP       (1 << 0)
+#define VPDMA_DATA_EVEN_LINE_SKIP      (1 << 1)
+#define VPDMA_DATA_FRAME_1D            (1 << 2)
+#define VPDMA_DATA_MODE_TILED          (1 << 3)
+
+/*
+ * client identifiers used for configuration descriptors
+ */
+#define CFD_MMR_CLIENT         0
+#define CFD_SC_CLIENT          4
+
+/* Address data block header format */
+struct vpdma_adb_hdr {
+       u32                     offset;
+       u32                     nwords;
+       u32                     reserved0;
+       u32                     reserved1;
+};
+
+/* helpers for creating ADB headers for config descriptors MMRs as client */
+#define ADB_ADDR(dma_buf, str, fld)    ((dma_buf)->addr + offsetof(str, fld))
+#define MMR_ADB_ADDR(buf, str, fld)    ADB_ADDR(&(buf), struct str, fld)
+
+#define VPDMA_SET_MMR_ADB_HDR(buf, str, hdr, regs, offset_a)   \
+       do {                                                    \
+               struct vpdma_adb_hdr *h;                        \
+               struct str *adb = NULL;                         \
+               h = MMR_ADB_ADDR(buf, str, hdr);                \
+               h->offset = (offset_a);                         \
+               h->nwords = sizeof(adb->regs) >> 2;             \
+       } while (0)
+
+/* vpdma descriptor buffer allocation and management */
+int vpdma_alloc_desc_buf(struct vpdma_buf *buf, size_t size);
+void vpdma_free_desc_buf(struct vpdma_buf *buf);
+int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf);
+void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf);
+
+/* vpdma descriptor list funcs */
+int vpdma_create_desc_list(struct vpdma_desc_list *list, size_t size, int type);
+void vpdma_reset_desc_list(struct vpdma_desc_list *list);
+void vpdma_free_desc_list(struct vpdma_desc_list *list);
+int vpdma_submit_descs(struct vpdma_data *vpdma, struct vpdma_desc_list *list);
+
+/* helpers for creating vpdma descriptors */
+void vpdma_add_cfd_block(struct vpdma_desc_list *list, int client,
+               struct vpdma_buf *blk, u32 dest_offset);
+void vpdma_add_cfd_adb(struct vpdma_desc_list *list, int client,
+               struct vpdma_buf *adb);
+void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list *list,
+               enum vpdma_channel chan);
+void vpdma_add_out_dtd(struct vpdma_desc_list *list, struct v4l2_rect *c_rect,
+               const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
+               enum vpdma_channel chan, u32 flags);
+void vpdma_add_in_dtd(struct vpdma_desc_list *list, int frame_width,
+               int frame_height, struct v4l2_rect *c_rect,
+               const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
+               enum vpdma_channel chan, int field, u32 flags);
+
+/* vpdma list interrupt management */
+void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int list_num,
+               bool enable);
+void vpdma_clear_list_stat(struct vpdma_data *vpdma);
+
+/* vpdma client configuration */
+void vpdma_set_line_mode(struct vpdma_data *vpdma, int line_mode,
+               enum vpdma_channel chan);
+void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
+               enum vpdma_frame_start_event fs_event, enum vpdma_channel chan);
+
+void vpdma_dump_regs(struct vpdma_data *vpdma);
+
+/* initialize vpdma, passed with VPE's platform device pointer */
+struct vpdma_data *vpdma_create(struct platform_device *pdev);
+
+#endif
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h b/drivers/media/platform/ti-vpe/vpdma_priv.h
new file mode 100644 (file)
index 0000000..f0e9a80
--- /dev/null
@@ -0,0 +1,641 @@
+/*
+ * Copyright (c) 2013 Texas Instruments Inc.
+ *
+ * David Griego, <dagriego@biglakesoftware.com>
+ * Dale Farnsworth, <dale@farnsworth.org>
+ * Archit Taneja, <archit@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef _TI_VPDMA_PRIV_H_
+#define _TI_VPDMA_PRIV_H_
+
+/*
+ * VPDMA Register offsets
+ */
+
+/* Top level */
+#define VPDMA_PID              0x00
+#define VPDMA_LIST_ADDR                0x04
+#define VPDMA_LIST_ATTR                0x08
+#define VPDMA_LIST_STAT_SYNC   0x0c
+#define VPDMA_BG_RGB           0x18
+#define VPDMA_BG_YUV           0x1c
+#define VPDMA_SETUP            0x30
+#define VPDMA_MAX_SIZE1                0x34
+#define VPDMA_MAX_SIZE2                0x38
+#define VPDMA_MAX_SIZE3                0x3c
+
+/* Interrupts */
+#define VPDMA_INT_CHAN_STAT(grp)       (0x40 + grp * 8)
+#define VPDMA_INT_CHAN_MASK(grp)       (VPDMA_INT_CHAN_STAT(grp) + 4)
+#define VPDMA_INT_CLIENT0_STAT         0x78
+#define VPDMA_INT_CLIENT0_MASK         0x7c
+#define VPDMA_INT_CLIENT1_STAT         0x80
+#define VPDMA_INT_CLIENT1_MASK         0x84
+#define VPDMA_INT_LIST0_STAT           0x88
+#define VPDMA_INT_LIST0_MASK           0x8c
+
+#define VPDMA_PERFMON(i)               (0x200 + i * 4)
+
+/* VPE specific client registers */
+#define VPDMA_DEI_CHROMA1_CSTAT                0x0300
+#define VPDMA_DEI_LUMA1_CSTAT          0x0304
+#define VPDMA_DEI_LUMA2_CSTAT          0x0308
+#define VPDMA_DEI_CHROMA2_CSTAT                0x030c
+#define VPDMA_DEI_LUMA3_CSTAT          0x0310
+#define VPDMA_DEI_CHROMA3_CSTAT                0x0314
+#define VPDMA_DEI_MV_IN_CSTAT          0x0330
+#define VPDMA_DEI_MV_OUT_CSTAT         0x033c
+#define VPDMA_VIP_UP_Y_CSTAT           0x0390
+#define VPDMA_VIP_UP_UV_CSTAT          0x0394
+#define VPDMA_VPI_CTL_CSTAT            0x03d0
+
+/* Reg field info for VPDMA_CLIENT_CSTAT registers */
+#define VPDMA_CSTAT_LINE_MODE_MASK     0x03
+#define VPDMA_CSTAT_LINE_MODE_SHIFT    8
+#define VPDMA_CSTAT_FRAME_START_MASK   0xf
+#define VPDMA_CSTAT_FRAME_START_SHIFT  10
+
+#define VPDMA_LIST_NUM_MASK            0x07
+#define VPDMA_LIST_NUM_SHFT            24
+#define VPDMA_LIST_STOP_SHFT           20
+#define VPDMA_LIST_RDY_MASK            0x01
+#define VPDMA_LIST_RDY_SHFT            19
+#define VPDMA_LIST_TYPE_MASK           0x03
+#define VPDMA_LIST_TYPE_SHFT           16
+#define VPDMA_LIST_SIZE_MASK           0xffff
+
+/* VPDMA data type values for data formats */
+#define DATA_TYPE_Y444                         0x0
+#define DATA_TYPE_Y422                         0x1
+#define DATA_TYPE_Y420                         0x2
+#define DATA_TYPE_C444                         0x4
+#define DATA_TYPE_C422                         0x5
+#define DATA_TYPE_C420                         0x6
+#define DATA_TYPE_YC422                                0x7
+#define DATA_TYPE_YC444                                0x8
+#define DATA_TYPE_CY422                                0x23
+
+#define DATA_TYPE_RGB16_565                    0x0
+#define DATA_TYPE_ARGB_1555                    0x1
+#define DATA_TYPE_ARGB_4444                    0x2
+#define DATA_TYPE_RGBA_5551                    0x3
+#define DATA_TYPE_RGBA_4444                    0x4
+#define DATA_TYPE_ARGB24_6666                  0x5
+#define DATA_TYPE_RGB24_888                    0x6
+#define DATA_TYPE_ARGB32_8888                  0x7
+#define DATA_TYPE_RGBA24_6666                  0x8
+#define DATA_TYPE_RGBA32_8888                  0x9
+#define DATA_TYPE_BGR16_565                    0x10
+#define DATA_TYPE_ABGR_1555                    0x11
+#define DATA_TYPE_ABGR_4444                    0x12
+#define DATA_TYPE_BGRA_5551                    0x13
+#define DATA_TYPE_BGRA_4444                    0x14
+#define DATA_TYPE_ABGR24_6666                  0x15
+#define DATA_TYPE_BGR24_888                    0x16
+#define DATA_TYPE_ABGR32_8888                  0x17
+#define DATA_TYPE_BGRA24_6666                  0x18
+#define DATA_TYPE_BGRA32_8888                  0x19
+
+#define DATA_TYPE_MV                           0x3
+
+/* VPDMA channel numbers(only VPE channels for now) */
+#define        VPE_CHAN_NUM_LUMA1_IN           0
+#define        VPE_CHAN_NUM_CHROMA1_IN         1
+#define        VPE_CHAN_NUM_LUMA2_IN           2
+#define        VPE_CHAN_NUM_CHROMA2_IN         3
+#define        VPE_CHAN_NUM_LUMA3_IN           4
+#define        VPE_CHAN_NUM_CHROMA3_IN         5
+#define        VPE_CHAN_NUM_MV_IN              12
+#define        VPE_CHAN_NUM_MV_OUT             15
+#define        VPE_CHAN_NUM_LUMA_OUT           102
+#define        VPE_CHAN_NUM_CHROMA_OUT         103
+#define        VPE_CHAN_NUM_RGB_OUT            106
+
+/*
+ * a VPDMA address data block payload for a configuration descriptor needs to
+ * have each sub block length as a multiple of 16 bytes. Therefore, the overall
+ * size of the payload also needs to be a multiple of 16 bytes. The sub block
+ * lengths should be ensured to be aligned by the VPDMA user.
+ */
+#define VPDMA_ADB_SIZE_ALIGN           0x0f
+
+/*
+ * data transfer descriptor
+ */
+struct vpdma_dtd {
+       u32                     type_ctl_stride;
+       union {
+               u32             xfer_length_height;
+               u32             w1;
+       };
+       dma_addr_t              start_addr;
+       u32                     pkt_ctl;
+       union {
+               u32             frame_width_height;     /* inbound */
+               dma_addr_t      desc_write_addr;        /* outbound */
+       };
+       union {
+               u32             start_h_v;              /* inbound */
+               u32             max_width_height;       /* outbound */
+       };
+       u32                     client_attr0;
+       u32                     client_attr1;
+};
+
+/* Data Transfer Descriptor specifics */
+#define DTD_NO_NOTIFY          0
+#define DTD_NOTIFY             1
+
+#define DTD_PKT_TYPE           0xa
+#define DTD_DIR_IN             0
+#define DTD_DIR_OUT            1
+
+/* type_ctl_stride */
+#define DTD_DATA_TYPE_MASK     0x3f
+#define DTD_DATA_TYPE_SHFT     26
+#define DTD_NOTIFY_MASK                0x01
+#define DTD_NOTIFY_SHFT                25
+#define DTD_FIELD_MASK         0x01
+#define DTD_FIELD_SHFT         24
+#define DTD_1D_MASK            0x01
+#define DTD_1D_SHFT            23
+#define DTD_EVEN_LINE_SKIP_MASK        0x01
+#define DTD_EVEN_LINE_SKIP_SHFT        20
+#define DTD_ODD_LINE_SKIP_MASK 0x01
+#define DTD_ODD_LINE_SKIP_SHFT 16
+#define DTD_LINE_STRIDE_MASK   0xffff
+#define DTD_LINE_STRIDE_SHFT   0
+
+/* xfer_length_height */
+#define DTD_LINE_LENGTH_MASK   0xffff
+#define DTD_LINE_LENGTH_SHFT   16
+#define DTD_XFER_HEIGHT_MASK   0xffff
+#define DTD_XFER_HEIGHT_SHFT   0
+
+/* pkt_ctl */
+#define DTD_PKT_TYPE_MASK      0x1f
+#define DTD_PKT_TYPE_SHFT      27
+#define DTD_MODE_MASK          0x01
+#define DTD_MODE_SHFT          26
+#define DTD_DIR_MASK           0x01
+#define DTD_DIR_SHFT           25
+#define DTD_CHAN_MASK          0x01ff
+#define DTD_CHAN_SHFT          16
+#define DTD_PRI_MASK           0x0f
+#define DTD_PRI_SHFT           9
+#define DTD_NEXT_CHAN_MASK     0x01ff
+#define DTD_NEXT_CHAN_SHFT     0
+
+/* frame_width_height */
+#define DTD_FRAME_WIDTH_MASK   0xffff
+#define DTD_FRAME_WIDTH_SHFT   16
+#define DTD_FRAME_HEIGHT_MASK  0xffff
+#define DTD_FRAME_HEIGHT_SHFT  0
+
+/* start_h_v */
+#define DTD_H_START_MASK       0xffff
+#define DTD_H_START_SHFT       16
+#define DTD_V_START_MASK       0xffff
+#define DTD_V_START_SHFT       0
+
+#define DTD_DESC_START_SHIFT   5
+#define DTD_WRITE_DESC_MASK    0x01
+#define DTD_WRITE_DESC_SHIFT   2
+#define DTD_DROP_DATA_MASK     0x01
+#define DTD_DROP_DATA_SHIFT    1
+#define DTD_USE_DESC_MASK      0x01
+#define DTD_USE_DESC_SHIFT     0
+
+/* max_width_height */
+#define DTD_MAX_WIDTH_MASK     0x07
+#define DTD_MAX_WIDTH_SHFT     4
+#define DTD_MAX_HEIGHT_MASK    0x07
+#define DTD_MAX_HEIGHT_SHFT    0
+
+/* max width configurations */
+ /* unlimited width */
+#define        MAX_OUT_WIDTH_UNLIMITED         0
+/* as specified in max_size1 reg */
+#define MAX_OUT_WIDTH_REG1             1
+/* as specified in max_size2 reg */
+#define MAX_OUT_WIDTH_REG2             2
+/* as specified in max_size3 reg */
+#define        MAX_OUT_WIDTH_REG3              3
+/* maximum of 352 pixels as width */
+#define MAX_OUT_WIDTH_352              4
+/* maximum of 768 pixels as width */
+#define        MAX_OUT_WIDTH_768               5
+/* maximum of 1280 pixels width */
+#define        MAX_OUT_WIDTH_1280              6
+/* maximum of 1920 pixels as width */
+#define        MAX_OUT_WIDTH_1920              7
+
+/* max height configurations */
+ /* unlimited height */
+#define        MAX_OUT_HEIGHT_UNLIMITED        0
+/* as specified in max_size1 reg */
+#define MAX_OUT_HEIGHT_REG1            1
+/* as specified in max_size2 reg */
+#define MAX_OUT_HEIGHT_REG2            2
+/* as specified in max_size3 reg */
+#define        MAX_OUT_HEIGHT_REG3             3
+/* maximum of 288 lines as height */
+#define MAX_OUT_HEIGHT_288             4
+/* maximum of 576 lines as height */
+#define        MAX_OUT_HEIGHT_576              5
+/* maximum of 720 lines as height */
+#define        MAX_OUT_HEIGHT_720              6
+/* maximum of 1080 lines as height */
+#define        MAX_OUT_HEIGHT_1080             7
+
+static inline u32 dtd_type_ctl_stride(int type, bool notify, int field,
+                       bool one_d, bool even_line_skip, bool odd_line_skip,
+                       int line_stride)
+{
+       return (type << DTD_DATA_TYPE_SHFT) | (notify << DTD_NOTIFY_SHFT) |
+               (field << DTD_FIELD_SHFT) | (one_d << DTD_1D_SHFT) |
+               (even_line_skip << DTD_EVEN_LINE_SKIP_SHFT) |
+               (odd_line_skip << DTD_ODD_LINE_SKIP_SHFT) |
+               line_stride;
+}
+
+static inline u32 dtd_xfer_length_height(int line_length, int xfer_height)
+{
+       return (line_length << DTD_LINE_LENGTH_SHFT) | xfer_height;
+}
+
+static inline u32 dtd_pkt_ctl(bool mode, bool dir, int chan, int pri,
+                       int next_chan)
+{
+       return (DTD_PKT_TYPE << DTD_PKT_TYPE_SHFT) | (mode << DTD_MODE_SHFT) |
+               (dir << DTD_DIR_SHFT) | (chan << DTD_CHAN_SHFT) |
+               (pri << DTD_PRI_SHFT) | next_chan;
+}
+
+static inline u32 dtd_frame_width_height(int width, int height)
+{
+       return (width << DTD_FRAME_WIDTH_SHFT) | height;
+}
+
+static inline u32 dtd_desc_write_addr(unsigned int addr, bool write_desc,
+                       bool drop_data, bool use_desc)
+{
+       return (addr << DTD_DESC_START_SHIFT) |
+               (write_desc << DTD_WRITE_DESC_SHIFT) |
+               (drop_data << DTD_DROP_DATA_SHIFT) |
+               use_desc;
+}
+
+static inline u32 dtd_start_h_v(int h_start, int v_start)
+{
+       return (h_start << DTD_H_START_SHFT) | v_start;
+}
+
+static inline u32 dtd_max_width_height(int max_width, int max_height)
+{
+       return (max_width << DTD_MAX_WIDTH_SHFT) | max_height;
+}
+
+static inline int dtd_get_data_type(struct vpdma_dtd *dtd)
+{
+       return dtd->type_ctl_stride >> DTD_DATA_TYPE_SHFT;
+}
+
+static inline bool dtd_get_notify(struct vpdma_dtd *dtd)
+{
+       return (dtd->type_ctl_stride >> DTD_NOTIFY_SHFT) & DTD_NOTIFY_MASK;
+}
+
+static inline int dtd_get_field(struct vpdma_dtd *dtd)
+{
+       return (dtd->type_ctl_stride >> DTD_FIELD_SHFT) & DTD_FIELD_MASK;
+}
+
+static inline bool dtd_get_1d(struct vpdma_dtd *dtd)
+{
+       return (dtd->type_ctl_stride >> DTD_1D_SHFT) & DTD_1D_MASK;
+}
+
+static inline bool dtd_get_even_line_skip(struct vpdma_dtd *dtd)
+{
+       return (dtd->type_ctl_stride >> DTD_EVEN_LINE_SKIP_SHFT)
+               & DTD_EVEN_LINE_SKIP_MASK;
+}
+
+static inline bool dtd_get_odd_line_skip(struct vpdma_dtd *dtd)
+{
+       return (dtd->type_ctl_stride >> DTD_ODD_LINE_SKIP_SHFT)
+               & DTD_ODD_LINE_SKIP_MASK;
+}
+
+static inline int dtd_get_line_stride(struct vpdma_dtd *dtd)
+{
+       return dtd->type_ctl_stride & DTD_LINE_STRIDE_MASK;
+}
+
+static inline int dtd_get_line_length(struct vpdma_dtd *dtd)
+{
+       return dtd->xfer_length_height >> DTD_LINE_LENGTH_SHFT;
+}
+
+static inline int dtd_get_xfer_height(struct vpdma_dtd *dtd)
+{
+       return dtd->xfer_length_height & DTD_XFER_HEIGHT_MASK;
+}
+
+static inline int dtd_get_pkt_type(struct vpdma_dtd *dtd)
+{
+       return dtd->pkt_ctl >> DTD_PKT_TYPE_SHFT;
+}
+
+static inline bool dtd_get_mode(struct vpdma_dtd *dtd)
+{
+       return (dtd->pkt_ctl >> DTD_MODE_SHFT) & DTD_MODE_MASK;
+}
+
+static inline bool dtd_get_dir(struct vpdma_dtd *dtd)
+{
+       return (dtd->pkt_ctl >> DTD_DIR_SHFT) & DTD_DIR_MASK;
+}
+
+static inline int dtd_get_chan(struct vpdma_dtd *dtd)
+{
+       return (dtd->pkt_ctl >> DTD_CHAN_SHFT) & DTD_CHAN_MASK;
+}
+
+static inline int dtd_get_priority(struct vpdma_dtd *dtd)
+{
+       return (dtd->pkt_ctl >> DTD_PRI_SHFT) & DTD_PRI_MASK;
+}
+
+static inline int dtd_get_next_chan(struct vpdma_dtd *dtd)
+{
+       return (dtd->pkt_ctl >> DTD_NEXT_CHAN_SHFT) & DTD_NEXT_CHAN_MASK;
+}
+
+static inline int dtd_get_frame_width(struct vpdma_dtd *dtd)
+{
+       return dtd->frame_width_height >> DTD_FRAME_WIDTH_SHFT;
+}
+
+static inline int dtd_get_frame_height(struct vpdma_dtd *dtd)
+{
+       return dtd->frame_width_height & DTD_FRAME_HEIGHT_MASK;
+}
+
+static inline int dtd_get_desc_write_addr(struct vpdma_dtd *dtd)
+{
+       return dtd->desc_write_addr >> DTD_DESC_START_SHIFT;
+}
+
+static inline bool dtd_get_write_desc(struct vpdma_dtd *dtd)
+{
+       return (dtd->desc_write_addr >> DTD_WRITE_DESC_SHIFT) &
+                                                       DTD_WRITE_DESC_MASK;
+}
+
+static inline bool dtd_get_drop_data(struct vpdma_dtd *dtd)
+{
+       return (dtd->desc_write_addr >> DTD_DROP_DATA_SHIFT) &
+                                                       DTD_DROP_DATA_MASK;
+}
+
+static inline bool dtd_get_use_desc(struct vpdma_dtd *dtd)
+{
+       return dtd->desc_write_addr & DTD_USE_DESC_MASK;
+}
+
+static inline int dtd_get_h_start(struct vpdma_dtd *dtd)
+{
+       return dtd->start_h_v >> DTD_H_START_SHFT;
+}
+
+static inline int dtd_get_v_start(struct vpdma_dtd *dtd)
+{
+       return dtd->start_h_v & DTD_V_START_MASK;
+}
+
+static inline int dtd_get_max_width(struct vpdma_dtd *dtd)
+{
+       return (dtd->max_width_height >> DTD_MAX_WIDTH_SHFT) &
+                                                       DTD_MAX_WIDTH_MASK;
+}
+
+static inline int dtd_get_max_height(struct vpdma_dtd *dtd)
+{
+       return (dtd->max_width_height >> DTD_MAX_HEIGHT_SHFT) &
+                                                       DTD_MAX_HEIGHT_MASK;
+}
+
+/*
+ * configuration descriptor
+ */
+struct vpdma_cfd {
+       union {
+               u32     dest_addr_offset;
+               u32     w0;
+       };
+       union {
+               u32     block_len;              /* in words */
+               u32     w1;
+       };
+       u32             payload_addr;
+       u32             ctl_payload_len;        /* in words */
+};
+
+/* Configuration descriptor specifics */
+
+#define CFD_PKT_TYPE           0xb
+
+#define CFD_DIRECT             1
+#define CFD_INDIRECT           0
+#define CFD_CLS_ADB            0
+#define CFD_CLS_BLOCK          1
+
+/* block_len */
+#define CFD__BLOCK_LEN_MASK    0xffff
+#define CFD__BLOCK_LEN_SHFT    0
+
+/* ctl_payload_len */
+#define CFD_PKT_TYPE_MASK      0x1f
+#define CFD_PKT_TYPE_SHFT      27
+#define CFD_DIRECT_MASK                0x01
+#define CFD_DIRECT_SHFT                26
+#define CFD_CLASS_MASK         0x03
+#define CFD_CLASS_SHFT         24
+#define CFD_DEST_MASK          0xff
+#define CFD_DEST_SHFT          16
+#define CFD_PAYLOAD_LEN_MASK   0xffff
+#define CFD_PAYLOAD_LEN_SHFT   0
+
+static inline u32 cfd_pkt_payload_len(bool direct, int cls, int dest,
+               int payload_len)
+{
+       return (CFD_PKT_TYPE << CFD_PKT_TYPE_SHFT) |
+               (direct << CFD_DIRECT_SHFT) |
+               (cls << CFD_CLASS_SHFT) |
+               (dest << CFD_DEST_SHFT) |
+               payload_len;
+}
+
+static inline int cfd_get_pkt_type(struct vpdma_cfd *cfd)
+{
+       return cfd->ctl_payload_len >> CFD_PKT_TYPE_SHFT;
+}
+
+static inline bool cfd_get_direct(struct vpdma_cfd *cfd)
+{
+       return (cfd->ctl_payload_len >> CFD_DIRECT_SHFT) & CFD_DIRECT_MASK;
+}
+
+static inline bool cfd_get_class(struct vpdma_cfd *cfd)
+{
+       return (cfd->ctl_payload_len >> CFD_CLASS_SHFT) & CFD_CLASS_MASK;
+}
+
+static inline int cfd_get_dest(struct vpdma_cfd *cfd)
+{
+       return (cfd->ctl_payload_len >> CFD_DEST_SHFT) & CFD_DEST_MASK;
+}
+
+static inline int cfd_get_payload_len(struct vpdma_cfd *cfd)
+{
+       return cfd->ctl_payload_len & CFD_PAYLOAD_LEN_MASK;
+}
+
+/*
+ * control descriptor
+ */
+struct vpdma_ctd {
+       union {
+               u32     timer_value;
+               u32     list_addr;
+               u32     w0;
+       };
+       union {
+               u32     pixel_line_count;
+               u32     list_size;
+               u32     w1;
+       };
+       union {
+               u32     event;
+               u32     fid_ctl;
+               u32     w2;
+       };
+       u32             type_source_ctl;
+};
+
+/* control descriptor types */
+#define CTD_TYPE_SYNC_ON_CLIENT                0
+#define CTD_TYPE_SYNC_ON_LIST          1
+#define CTD_TYPE_SYNC_ON_EXT           2
+#define CTD_TYPE_SYNC_ON_LM_TIMER      3
+#define CTD_TYPE_SYNC_ON_CHANNEL       4
+#define CTD_TYPE_CHNG_CLIENT_IRQ       5
+#define CTD_TYPE_SEND_IRQ              6
+#define CTD_TYPE_RELOAD_LIST           7
+#define CTD_TYPE_ABORT_CHANNEL         8
+
+#define CTD_PKT_TYPE           0xc
+
+/* timer_value */
+#define CTD_TIMER_VALUE_MASK   0xffff
+#define CTD_TIMER_VALUE_SHFT   0
+
+/* pixel_line_count */
+#define CTD_PIXEL_COUNT_MASK   0xffff
+#define CTD_PIXEL_COUNT_SHFT   16
+#define CTD_LINE_COUNT_MASK    0xffff
+#define CTD_LINE_COUNT_SHFT    0
+
+/* list_size */
+#define CTD_LIST_SIZE_MASK     0xffff
+#define CTD_LIST_SIZE_SHFT     0
+
+/* event */
+#define CTD_EVENT_MASK         0x0f
+#define CTD_EVENT_SHFT         0
+
+/* fid_ctl */
+#define CTD_FID2_MASK          0x03
+#define CTD_FID2_SHFT          4
+#define CTD_FID1_MASK          0x03
+#define CTD_FID1_SHFT          2
+#define CTD_FID0_MASK          0x03
+#define CTD_FID0_SHFT          0
+
+/* type_source_ctl */
+#define CTD_PKT_TYPE_MASK      0x1f
+#define CTD_PKT_TYPE_SHFT      27
+#define CTD_SOURCE_MASK                0xff
+#define CTD_SOURCE_SHFT                16
+#define CTD_CONTROL_MASK       0x0f
+#define CTD_CONTROL_SHFT       0
+
+static inline u32 ctd_pixel_line_count(int pixel_count, int line_count)
+{
+       return (pixel_count << CTD_PIXEL_COUNT_SHFT) | line_count;
+}
+
+static inline u32 ctd_set_fid_ctl(int fid0, int fid1, int fid2)
+{
+       return (fid2 << CTD_FID2_SHFT) | (fid1 << CTD_FID1_SHFT) | fid0;
+}
+
+static inline u32 ctd_type_source_ctl(int source, int control)
+{
+       return (CTD_PKT_TYPE << CTD_PKT_TYPE_SHFT) |
+               (source << CTD_SOURCE_SHFT) | control;
+}
+
+static inline u32 ctd_get_pixel_count(struct vpdma_ctd *ctd)
+{
+       return ctd->pixel_line_count >> CTD_PIXEL_COUNT_SHFT;
+}
+
+static inline int ctd_get_line_count(struct vpdma_ctd *ctd)
+{
+       return ctd->pixel_line_count & CTD_LINE_COUNT_MASK;
+}
+
+static inline int ctd_get_event(struct vpdma_ctd *ctd)
+{
+       return ctd->event & CTD_EVENT_MASK;
+}
+
+static inline int ctd_get_fid2_ctl(struct vpdma_ctd *ctd)
+{
+       return (ctd->fid_ctl >> CTD_FID2_SHFT) & CTD_FID2_MASK;
+}
+
+static inline int ctd_get_fid1_ctl(struct vpdma_ctd *ctd)
+{
+       return (ctd->fid_ctl >> CTD_FID1_SHFT) & CTD_FID1_MASK;
+}
+
+static inline int ctd_get_fid0_ctl(struct vpdma_ctd *ctd)
+{
+       return ctd->fid_ctl & CTD_FID2_MASK;
+}
+
+static inline int ctd_get_pkt_type(struct vpdma_ctd *ctd)
+{
+       return ctd->type_source_ctl >> CTD_PKT_TYPE_SHFT;
+}
+
+static inline int ctd_get_source(struct vpdma_ctd *ctd)
+{
+       return (ctd->type_source_ctl >> CTD_SOURCE_SHFT) & CTD_SOURCE_MASK;
+}
+
+static inline int ctd_get_ctl(struct vpdma_ctd *ctd)
+{
+       return ctd->type_source_ctl & CTD_CONTROL_MASK;
+}
+
+#endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
new file mode 100644 (file)
index 0000000..4e58069
--- /dev/null
@@ -0,0 +1,2099 @@
+/*
+ * TI VPE mem2mem driver, based on the virtual v4l2-mem2mem example driver
+ *
+ * Copyright (c) 2013 Texas Instruments Inc.
+ * David Griego, <dagriego@biglakesoftware.com>
+ * Dale Farnsworth, <dale@farnsworth.org>
+ * Archit Taneja, <archit@ti.com>
+ *
+ * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
+ * Pawel Osciak, <pawel@osciak.com>
+ * Marek Szyprowski, <m.szyprowski@samsung.com>
+ *
+ * Based on the virtual v4l2-mem2mem example device
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation
+ */
+
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/ioctl.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/videodev2.h>
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-mem2mem.h>
+#include <media/videobuf2-core.h>
+#include <media/videobuf2-dma-contig.h>
+
+#include "vpdma.h"
+#include "vpe_regs.h"
+
+#define VPE_MODULE_NAME "vpe"
+
+/* minimum and maximum frame sizes */
+#define MIN_W          128
+#define MIN_H          128
+#define MAX_W          1920
+#define MAX_H          1080
+
+/* required alignments */
+#define S_ALIGN                0       /* multiple of 1 */
+#define H_ALIGN                1       /* multiple of 2 */
+#define W_ALIGN                1       /* multiple of 2 */
+
+/* multiple of 128 bits, line stride, 16 bytes */
+#define L_ALIGN                4
+
+/* flags that indicate a format can be used for capture/output */
+#define VPE_FMT_TYPE_CAPTURE   (1 << 0)
+#define VPE_FMT_TYPE_OUTPUT    (1 << 1)
+
+/* used as plane indices */
+#define VPE_MAX_PLANES 2
+#define VPE_LUMA       0
+#define VPE_CHROMA     1
+
+/* per m2m context info */
+#define VPE_MAX_SRC_BUFS       3       /* need 3 src fields to de-interlace */
+
+#define VPE_DEF_BUFS_PER_JOB   1       /* default one buffer per batch job */
+
+/*
+ * each VPE context can need up to 3 config desciptors, 7 input descriptors,
+ * 3 output descriptors, and 10 control descriptors
+ */
+#define VPE_DESC_LIST_SIZE     (10 * VPDMA_DTD_DESC_SIZE +     \
+                                       13 * VPDMA_CFD_CTD_DESC_SIZE)
+
+#define vpe_dbg(vpedev, fmt, arg...)   \
+               dev_dbg((vpedev)->v4l2_dev.dev, fmt, ##arg)
+#define vpe_err(vpedev, fmt, arg...)   \
+               dev_err((vpedev)->v4l2_dev.dev, fmt, ##arg)
+
+struct vpe_us_coeffs {
+       unsigned short  anchor_fid0_c0;
+       unsigned short  anchor_fid0_c1;
+       unsigned short  anchor_fid0_c2;
+       unsigned short  anchor_fid0_c3;
+       unsigned short  interp_fid0_c0;
+       unsigned short  interp_fid0_c1;
+       unsigned short  interp_fid0_c2;
+       unsigned short  interp_fid0_c3;
+       unsigned short  anchor_fid1_c0;
+       unsigned short  anchor_fid1_c1;
+       unsigned short  anchor_fid1_c2;
+       unsigned short  anchor_fid1_c3;
+       unsigned short  interp_fid1_c0;
+       unsigned short  interp_fid1_c1;
+       unsigned short  interp_fid1_c2;
+       unsigned short  interp_fid1_c3;
+};
+
+/*
+ * Default upsampler coefficients
+ */
+static const struct vpe_us_coeffs us_coeffs[] = {
+       {
+               /* Coefficients for progressive input */
+               0x00C8, 0x0348, 0x0018, 0x3FD8, 0x3FB8, 0x0378, 0x00E8, 0x3FE8,
+               0x00C8, 0x0348, 0x0018, 0x3FD8, 0x3FB8, 0x0378, 0x00E8, 0x3FE8,
+       },
+       {
+               /* Coefficients for Top Field Interlaced input */
+               0x0051, 0x03D5, 0x3FE3, 0x3FF7, 0x3FB5, 0x02E9, 0x018F, 0x3FD3,
+               /* Coefficients for Bottom Field Interlaced input */
+               0x016B, 0x0247, 0x00B1, 0x3F9D, 0x3FCF, 0x03DB, 0x005D, 0x3FF9,
+       },
+};
+
+/*
+ * the following registers are for configuring some of the parameters of the
+ * motion and edge detection blocks inside DEI, these generally remain the same,
+ * these could be passed later via userspace if some one needs to tweak these.
+ */
+struct vpe_dei_regs {
+       unsigned long mdt_spacial_freq_thr_reg;         /* VPE_DEI_REG2 */
+       unsigned long edi_config_reg;                   /* VPE_DEI_REG3 */
+       unsigned long edi_lut_reg0;                     /* VPE_DEI_REG4 */
+       unsigned long edi_lut_reg1;                     /* VPE_DEI_REG5 */
+       unsigned long edi_lut_reg2;                     /* VPE_DEI_REG6 */
+       unsigned long edi_lut_reg3;                     /* VPE_DEI_REG7 */
+};
+
+/*
+ * default expert DEI register values, unlikely to be modified.
+ */
+static const struct vpe_dei_regs dei_regs = {
+       0x020C0804u,
+       0x0118100Fu,
+       0x08040200u,
+       0x1010100Cu,
+       0x10101010u,
+       0x10101010u,
+};
+
+/*
+ * The port_data structure contains per-port data.
+ */
+struct vpe_port_data {
+       enum vpdma_channel channel;     /* VPDMA channel */
+       u8      vb_index;               /* input frame f, f-1, f-2 index */
+       u8      vb_part;                /* plane index for co-panar formats */
+};
+
+/*
+ * Define indices into the port_data tables
+ */
+#define VPE_PORT_LUMA1_IN      0
+#define VPE_PORT_CHROMA1_IN    1
+#define VPE_PORT_LUMA2_IN      2
+#define VPE_PORT_CHROMA2_IN    3
+#define VPE_PORT_LUMA3_IN      4
+#define VPE_PORT_CHROMA3_IN    5
+#define VPE_PORT_MV_IN         6
+#define VPE_PORT_MV_OUT                7
+#define VPE_PORT_LUMA_OUT      8
+#define VPE_PORT_CHROMA_OUT    9
+#define VPE_PORT_RGB_OUT       10
+
+static const struct vpe_port_data port_data[11] = {
+       [VPE_PORT_LUMA1_IN] = {
+               .channel        = VPE_CHAN_LUMA1_IN,
+               .vb_index       = 0,
+               .vb_part        = VPE_LUMA,
+       },
+       [VPE_PORT_CHROMA1_IN] = {
+               .channel        = VPE_CHAN_CHROMA1_IN,
+               .vb_index       = 0,
+               .vb_part        = VPE_CHROMA,
+       },
+       [VPE_PORT_LUMA2_IN] = {
+               .channel        = VPE_CHAN_LUMA2_IN,
+               .vb_index       = 1,
+               .vb_part        = VPE_LUMA,
+       },
+       [VPE_PORT_CHROMA2_IN] = {
+               .channel        = VPE_CHAN_CHROMA2_IN,
+               .vb_index       = 1,
+               .vb_part        = VPE_CHROMA,
+       },
+       [VPE_PORT_LUMA3_IN] = {
+               .channel        = VPE_CHAN_LUMA3_IN,
+               .vb_index       = 2,
+               .vb_part        = VPE_LUMA,
+       },
+       [VPE_PORT_CHROMA3_IN] = {
+               .channel        = VPE_CHAN_CHROMA3_IN,
+               .vb_index       = 2,
+               .vb_part        = VPE_CHROMA,
+       },
+       [VPE_PORT_MV_IN] = {
+               .channel        = VPE_CHAN_MV_IN,
+       },
+       [VPE_PORT_MV_OUT] = {
+               .channel        = VPE_CHAN_MV_OUT,
+       },
+       [VPE_PORT_LUMA_OUT] = {
+               .channel        = VPE_CHAN_LUMA_OUT,
+               .vb_part        = VPE_LUMA,
+       },
+       [VPE_PORT_CHROMA_OUT] = {
+               .channel        = VPE_CHAN_CHROMA_OUT,
+               .vb_part        = VPE_CHROMA,
+       },
+       [VPE_PORT_RGB_OUT] = {
+               .channel        = VPE_CHAN_RGB_OUT,
+               .vb_part        = VPE_LUMA,
+       },
+};
+
+
+/* driver info for each of the supported video formats */
+struct vpe_fmt {
+       char    *name;                  /* human-readable name */
+       u32     fourcc;                 /* standard format identifier */
+       u8      types;                  /* CAPTURE and/or OUTPUT */
+       u8      coplanar;               /* set for unpacked Luma and Chroma */
+       /* vpdma format info for each plane */
+       struct vpdma_data_format const *vpdma_fmt[VPE_MAX_PLANES];
+};
+
+static struct vpe_fmt vpe_formats[] = {
+       {
+               .name           = "YUV 422 co-planar",
+               .fourcc         = V4L2_PIX_FMT_NV16,
+               .types          = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
+               .coplanar       = 1,
+               .vpdma_fmt      = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y444],
+                                   &vpdma_yuv_fmts[VPDMA_DATA_FMT_C444],
+                                 },
+       },
+       {
+               .name           = "YUV 420 co-planar",
+               .fourcc         = V4L2_PIX_FMT_NV12,
+               .types          = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
+               .coplanar       = 1,
+               .vpdma_fmt      = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y420],
+                                   &vpdma_yuv_fmts[VPDMA_DATA_FMT_C420],
+                                 },
+       },
+       {
+               .name           = "YUYV 422 packed",
+               .fourcc         = V4L2_PIX_FMT_YUYV,
+               .types          = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
+               .coplanar       = 0,
+               .vpdma_fmt      = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_YC422],
+                                 },
+       },
+       {
+               .name           = "UYVY 422 packed",
+               .fourcc         = V4L2_PIX_FMT_UYVY,
+               .types          = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
+               .coplanar       = 0,
+               .vpdma_fmt      = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_CY422],
+                                 },
+       },
+};
+
+/*
+ * per-queue, driver-specific private data.
+ * there is one source queue and one destination queue for each m2m context.
+ */
+struct vpe_q_data {
+       unsigned int            width;                          /* frame width */
+       unsigned int            height;                         /* frame height */
+       unsigned int            bytesperline[VPE_MAX_PLANES];   /* bytes per line in memory */
+       enum v4l2_colorspace    colorspace;
+       enum v4l2_field         field;                          /* supported field value */
+       unsigned int            flags;
+       unsigned int            sizeimage[VPE_MAX_PLANES];      /* image size in memory */
+       struct v4l2_rect        c_rect;                         /* crop/compose rectangle */
+       struct vpe_fmt          *fmt;                           /* format info */
+};
+
+/* vpe_q_data flag bits */
+#define        Q_DATA_FRAME_1D         (1 << 0)
+#define        Q_DATA_MODE_TILED       (1 << 1)
+#define        Q_DATA_INTERLACED       (1 << 2)
+
+enum {
+       Q_DATA_SRC = 0,
+       Q_DATA_DST = 1,
+};
+
+/* find our format description corresponding to the passed v4l2_format */
+static struct vpe_fmt *find_format(struct v4l2_format *f)
+{
+       struct vpe_fmt *fmt;
+       unsigned int k;
+
+       for (k = 0; k < ARRAY_SIZE(vpe_formats); k++) {
+               fmt = &vpe_formats[k];
+               if (fmt->fourcc == f->fmt.pix.pixelformat)
+                       return fmt;
+       }
+
+       return NULL;
+}
+
+/*
+ * there is one vpe_dev structure in the driver, it is shared by
+ * all instances.
+ */
+struct vpe_dev {
+       struct v4l2_device      v4l2_dev;
+       struct video_device     vfd;
+       struct v4l2_m2m_dev     *m2m_dev;
+
+       atomic_t                num_instances;  /* count of driver instances */
+       dma_addr_t              loaded_mmrs;    /* shadow mmrs in device */
+       struct mutex            dev_mutex;
+       spinlock_t              lock;
+
+       int                     irq;
+       void __iomem            *base;
+
+       struct vb2_alloc_ctx    *alloc_ctx;
+       struct vpdma_data       *vpdma;         /* vpdma data handle */
+};
+
+/*
+ * There is one vpe_ctx structure for each m2m context.
+ */
+struct vpe_ctx {
+       struct v4l2_fh          fh;
+       struct vpe_dev          *dev;
+       struct v4l2_m2m_ctx     *m2m_ctx;
+       struct v4l2_ctrl_handler hdl;
+
+       unsigned int            field;                  /* current field */
+       unsigned int            sequence;               /* current frame/field seq */
+       unsigned int            aborting;               /* abort after next irq */
+
+       unsigned int            bufs_per_job;           /* input buffers per batch */
+       unsigned int            bufs_completed;         /* bufs done in this batch */
+
+       struct vpe_q_data       q_data[2];              /* src & dst queue data */
+       struct vb2_buffer       *src_vbs[VPE_MAX_SRC_BUFS];
+       struct vb2_buffer       *dst_vb;
+
+       dma_addr_t              mv_buf_dma[2];          /* dma addrs of motion vector in/out bufs */
+       void                    *mv_buf[2];             /* virtual addrs of motion vector bufs */
+       size_t                  mv_buf_size;            /* current motion vector buffer size */
+       struct vpdma_buf        mmr_adb;                /* shadow reg addr/data block */
+       struct vpdma_desc_list  desc_list;              /* DMA descriptor list */
+
+       bool                    deinterlacing;          /* using de-interlacer */
+       bool                    load_mmrs;              /* have new shadow reg values */
+
+       unsigned int            src_mv_buf_selector;
+};
+
+
+/*
+ * M2M devices get 2 queues.
+ * Return the queue given the type.
+ */
+static struct vpe_q_data *get_q_data(struct vpe_ctx *ctx,
+                                    enum v4l2_buf_type type)
+{
+       switch (type) {
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+               return &ctx->q_data[Q_DATA_SRC];
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+               return &ctx->q_data[Q_DATA_DST];
+       default:
+               BUG();
+       }
+       return NULL;
+}
+
+static u32 read_reg(struct vpe_dev *dev, int offset)
+{
+       return ioread32(dev->base + offset);
+}
+
+static void write_reg(struct vpe_dev *dev, int offset, u32 value)
+{
+       iowrite32(value, dev->base + offset);
+}
+
+/* register field read/write helpers */
+static int get_field(u32 value, u32 mask, int shift)
+{
+       return (value & (mask << shift)) >> shift;
+}
+
+static int read_field_reg(struct vpe_dev *dev, int offset, u32 mask, int shift)
+{
+       return get_field(read_reg(dev, offset), mask, shift);
+}
+
+static void write_field(u32 *valp, u32 field, u32 mask, int shift)
+{
+       u32 val = *valp;
+
+       val &= ~(mask << shift);
+       val |= (field & mask) << shift;
+       *valp = val;
+}
+
+static void write_field_reg(struct vpe_dev *dev, int offset, u32 field,
+               u32 mask, int shift)
+{
+       u32 val = read_reg(dev, offset);
+
+       write_field(&val, field, mask, shift);
+
+       write_reg(dev, offset, val);
+}
+
+/*
+ * DMA address/data block for the shadow registers
+ */
+struct vpe_mmr_adb {
+       struct vpdma_adb_hdr    out_fmt_hdr;
+       u32                     out_fmt_reg[1];
+       u32                     out_fmt_pad[3];
+       struct vpdma_adb_hdr    us1_hdr;
+       u32                     us1_regs[8];
+       struct vpdma_adb_hdr    us2_hdr;
+       u32                     us2_regs[8];
+       struct vpdma_adb_hdr    us3_hdr;
+       u32                     us3_regs[8];
+       struct vpdma_adb_hdr    dei_hdr;
+       u32                     dei_regs[8];
+       struct vpdma_adb_hdr    sc_hdr;
+       u32                     sc_regs[1];
+       u32                     sc_pad[3];
+       struct vpdma_adb_hdr    csc_hdr;
+       u32                     csc_regs[6];
+       u32                     csc_pad[2];
+};
+
+#define VPE_SET_MMR_ADB_HDR(ctx, hdr, regs, offset_a)  \
+       VPDMA_SET_MMR_ADB_HDR(ctx->mmr_adb, vpe_mmr_adb, hdr, regs, offset_a)
+/*
+ * Set the headers for all of the address/data block structures.
+ */
+static void init_adb_hdrs(struct vpe_ctx *ctx)
+{
+       VPE_SET_MMR_ADB_HDR(ctx, out_fmt_hdr, out_fmt_reg, VPE_CLK_FORMAT_SELECT);
+       VPE_SET_MMR_ADB_HDR(ctx, us1_hdr, us1_regs, VPE_US1_R0);
+       VPE_SET_MMR_ADB_HDR(ctx, us2_hdr, us2_regs, VPE_US2_R0);
+       VPE_SET_MMR_ADB_HDR(ctx, us3_hdr, us3_regs, VPE_US3_R0);
+       VPE_SET_MMR_ADB_HDR(ctx, dei_hdr, dei_regs, VPE_DEI_FRAME_SIZE);
+       VPE_SET_MMR_ADB_HDR(ctx, sc_hdr, sc_regs, VPE_SC_MP_SC0);
+       VPE_SET_MMR_ADB_HDR(ctx, csc_hdr, csc_regs, VPE_CSC_CSC00);
+};
+
+/*
+ * Allocate or re-allocate the motion vector DMA buffers
+ * There are two buffers, one for input and one for output.
+ * However, the roles are reversed after each field is processed.
+ * In other words, after each field is processed, the previous
+ * output (dst) MV buffer becomes the new input (src) MV buffer.
+ */
+static int realloc_mv_buffers(struct vpe_ctx *ctx, size_t size)
+{
+       struct device *dev = ctx->dev->v4l2_dev.dev;
+
+       if (ctx->mv_buf_size == size)
+               return 0;
+
+       if (ctx->mv_buf[0])
+               dma_free_coherent(dev, ctx->mv_buf_size, ctx->mv_buf[0],
+                       ctx->mv_buf_dma[0]);
+
+       if (ctx->mv_buf[1])
+               dma_free_coherent(dev, ctx->mv_buf_size, ctx->mv_buf[1],
+                       ctx->mv_buf_dma[1]);
+
+       if (size == 0)
+               return 0;
+
+       ctx->mv_buf[0] = dma_alloc_coherent(dev, size, &ctx->mv_buf_dma[0],
+                               GFP_KERNEL);
+       if (!ctx->mv_buf[0]) {
+               vpe_err(ctx->dev, "failed to allocate motion vector buffer\n");
+               return -ENOMEM;
+       }
+
+       ctx->mv_buf[1] = dma_alloc_coherent(dev, size, &ctx->mv_buf_dma[1],
+                               GFP_KERNEL);
+       if (!ctx->mv_buf[1]) {
+               vpe_err(ctx->dev, "failed to allocate motion vector buffer\n");
+               dma_free_coherent(dev, size, ctx->mv_buf[0],
+                       ctx->mv_buf_dma[0]);
+
+               return -ENOMEM;
+       }
+
+       ctx->mv_buf_size = size;
+       ctx->src_mv_buf_selector = 0;
+
+       return 0;
+}
+
+static void free_mv_buffers(struct vpe_ctx *ctx)
+{
+       realloc_mv_buffers(ctx, 0);
+}
+
+/*
+ * While de-interlacing, we keep the two most recent input buffers
+ * around.  This function frees those two buffers when we have
+ * finished processing the current stream.
+ */
+static void free_vbs(struct vpe_ctx *ctx)
+{
+       struct vpe_dev *dev = ctx->dev;
+       unsigned long flags;
+
+       if (ctx->src_vbs[2] == NULL)
+               return;
+
+       spin_lock_irqsave(&dev->lock, flags);
+       if (ctx->src_vbs[2]) {
+               v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_DONE);
+               v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_DONE);
+       }
+       spin_unlock_irqrestore(&dev->lock, flags);
+}
+
+/*
+ * Enable or disable the VPE clocks
+ */
+static void vpe_set_clock_enable(struct vpe_dev *dev, bool on)
+{
+       u32 val = 0;
+
+       if (on)
+               val = VPE_DATA_PATH_CLK_ENABLE | VPE_VPEDMA_CLK_ENABLE;
+       write_reg(dev, VPE_CLK_ENABLE, val);
+}
+
+static void vpe_top_reset(struct vpe_dev *dev)
+{
+
+       write_field_reg(dev, VPE_CLK_RESET, 1, VPE_DATA_PATH_CLK_RESET_MASK,
+               VPE_DATA_PATH_CLK_RESET_SHIFT);
+
+       usleep_range(100, 150);
+
+       write_field_reg(dev, VPE_CLK_RESET, 0, VPE_DATA_PATH_CLK_RESET_MASK,
+               VPE_DATA_PATH_CLK_RESET_SHIFT);
+}
+
+static void vpe_top_vpdma_reset(struct vpe_dev *dev)
+{
+       write_field_reg(dev, VPE_CLK_RESET, 1, VPE_VPDMA_CLK_RESET_MASK,
+               VPE_VPDMA_CLK_RESET_SHIFT);
+
+       usleep_range(100, 150);
+
+       write_field_reg(dev, VPE_CLK_RESET, 0, VPE_VPDMA_CLK_RESET_MASK,
+               VPE_VPDMA_CLK_RESET_SHIFT);
+}
+
+/*
+ * Load the correct of upsampler coefficients into the shadow MMRs
+ */
+static void set_us_coefficients(struct vpe_ctx *ctx)
+{
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
+       u32 *us1_reg = &mmr_adb->us1_regs[0];
+       u32 *us2_reg = &mmr_adb->us2_regs[0];
+       u32 *us3_reg = &mmr_adb->us3_regs[0];
+       const unsigned short *cp, *end_cp;
+
+       cp = &us_coeffs[0].anchor_fid0_c0;
+
+       if (s_q_data->flags & Q_DATA_INTERLACED)        /* interlaced */
+               cp += sizeof(us_coeffs[0]) / sizeof(*cp);
+
+       end_cp = cp + sizeof(us_coeffs[0]) / sizeof(*cp);
+
+       while (cp < end_cp) {
+               write_field(us1_reg, *cp++, VPE_US_C0_MASK, VPE_US_C0_SHIFT);
+               write_field(us1_reg, *cp++, VPE_US_C1_MASK, VPE_US_C1_SHIFT);
+               *us2_reg++ = *us1_reg;
+               *us3_reg++ = *us1_reg++;
+       }
+       ctx->load_mmrs = true;
+}
+
+/*
+ * Set the upsampler config mode and the VPDMA line mode in the shadow MMRs.
+ */
+static void set_cfg_and_line_modes(struct vpe_ctx *ctx)
+{
+       struct vpe_fmt *fmt = ctx->q_data[Q_DATA_SRC].fmt;
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       u32 *us1_reg0 = &mmr_adb->us1_regs[0];
+       u32 *us2_reg0 = &mmr_adb->us2_regs[0];
+       u32 *us3_reg0 = &mmr_adb->us3_regs[0];
+       int line_mode = 1;
+       int cfg_mode = 1;
+
+       /*
+        * Cfg Mode 0: YUV420 source, enable upsampler, DEI is de-interlacing.
+        * Cfg Mode 1: YUV422 source, disable upsampler, DEI is de-interlacing.
+        */
+
+       if (fmt->fourcc == V4L2_PIX_FMT_NV12) {
+               cfg_mode = 0;
+               line_mode = 0;          /* double lines to line buffer */
+       }
+
+       write_field(us1_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
+       write_field(us2_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
+       write_field(us3_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
+
+       /* regs for now */
+       vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA1_IN);
+       vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA2_IN);
+       vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA3_IN);
+
+       /* frame start for input luma */
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_LUMA1_IN);
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_LUMA2_IN);
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_LUMA3_IN);
+
+       /* frame start for input chroma */
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_CHROMA1_IN);
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_CHROMA2_IN);
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_CHROMA3_IN);
+
+       /* frame start for MV in client */
+       vpdma_set_frame_start_event(ctx->dev->vpdma, VPDMA_FSEVENT_CHANNEL_ACTIVE,
+               VPE_CHAN_MV_IN);
+
+       ctx->load_mmrs = true;
+}
+
+/*
+ * Set the shadow registers that are modified when the source
+ * format changes.
+ */
+static void set_src_registers(struct vpe_ctx *ctx)
+{
+       set_us_coefficients(ctx);
+}
+
+/*
+ * Set the shadow registers that are modified when the destination
+ * format changes.
+ */
+static void set_dst_registers(struct vpe_ctx *ctx)
+{
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt;
+       u32 val = 0;
+
+       /* select RGB path when color space conversion is supported in future */
+       if (fmt->fourcc == V4L2_PIX_FMT_RGB24)
+               val |= VPE_RGB_OUT_SELECT | VPE_CSC_SRC_DEI_SCALER;
+       else if (fmt->fourcc == V4L2_PIX_FMT_NV16)
+               val |= VPE_COLOR_SEPARATE_422;
+
+       /* The source of CHR_DS is always the scaler, whether it's used or not */
+       val |= VPE_DS_SRC_DEI_SCALER;
+
+       if (fmt->fourcc != V4L2_PIX_FMT_NV12)
+               val |= VPE_DS_BYPASS;
+
+       mmr_adb->out_fmt_reg[0] = val;
+
+       ctx->load_mmrs = true;
+}
+
+/*
+ * Set the de-interlacer shadow register values
+ */
+static void set_dei_regs(struct vpe_ctx *ctx)
+{
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
+       unsigned int src_h = s_q_data->c_rect.height;
+       unsigned int src_w = s_q_data->c_rect.width;
+       u32 *dei_mmr0 = &mmr_adb->dei_regs[0];
+       bool deinterlace = true;
+       u32 val = 0;
+
+       /*
+        * according to TRM, we should set DEI in progressive bypass mode when
+        * the input content is progressive, however, DEI is bypassed correctly
+        * for both progressive and interlace content in interlace bypass mode.
+        * It has been recommended not to use progressive bypass mode.
+        */
+       if ((!ctx->deinterlacing && (s_q_data->flags & Q_DATA_INTERLACED)) ||
+                       !(s_q_data->flags & Q_DATA_INTERLACED)) {
+               deinterlace = false;
+               val = VPE_DEI_INTERLACE_BYPASS;
+       }
+
+       src_h = deinterlace ? src_h * 2 : src_h;
+
+       val |= (src_h << VPE_DEI_HEIGHT_SHIFT) |
+               (src_w << VPE_DEI_WIDTH_SHIFT) |
+               VPE_DEI_FIELD_FLUSH;
+
+       *dei_mmr0 = val;
+
+       ctx->load_mmrs = true;
+}
+
+static void set_dei_shadow_registers(struct vpe_ctx *ctx)
+{
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       u32 *dei_mmr = &mmr_adb->dei_regs[0];
+       const struct vpe_dei_regs *cur = &dei_regs;
+
+       dei_mmr[2]  = cur->mdt_spacial_freq_thr_reg;
+       dei_mmr[3]  = cur->edi_config_reg;
+       dei_mmr[4]  = cur->edi_lut_reg0;
+       dei_mmr[5]  = cur->edi_lut_reg1;
+       dei_mmr[6]  = cur->edi_lut_reg2;
+       dei_mmr[7]  = cur->edi_lut_reg3;
+
+       ctx->load_mmrs = true;
+}
+
+static void set_csc_coeff_bypass(struct vpe_ctx *ctx)
+{
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       u32 *shadow_csc_reg5 = &mmr_adb->csc_regs[5];
+
+       *shadow_csc_reg5 |= VPE_CSC_BYPASS;
+
+       ctx->load_mmrs = true;
+}
+
+static void set_sc_regs_bypass(struct vpe_ctx *ctx)
+{
+       struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+       u32 *sc_reg0 = &mmr_adb->sc_regs[0];
+       u32 val = 0;
+
+       val |= VPE_SC_BYPASS;
+       *sc_reg0 = val;
+
+       ctx->load_mmrs = true;
+}
+
+/*
+ * Set the shadow registers whose values are modified when either the
+ * source or destination format is changed.
+ */
+static int set_srcdst_params(struct vpe_ctx *ctx)
+{
+       struct vpe_q_data *s_q_data =  &ctx->q_data[Q_DATA_SRC];
+       struct vpe_q_data *d_q_data =  &ctx->q_data[Q_DATA_DST];
+       size_t mv_buf_size;
+       int ret;
+
+       ctx->sequence = 0;
+       ctx->field = V4L2_FIELD_TOP;
+
+       if ((s_q_data->flags & Q_DATA_INTERLACED) &&
+                       !(d_q_data->flags & Q_DATA_INTERLACED)) {
+               const struct vpdma_data_format *mv =
+                       &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
+
+               ctx->deinterlacing = 1;
+               mv_buf_size =
+                       (s_q_data->width * s_q_data->height * mv->depth) >> 3;
+       } else {
+               ctx->deinterlacing = 0;
+               mv_buf_size = 0;
+       }
+
+       free_vbs(ctx);
+
+       ret = realloc_mv_buffers(ctx, mv_buf_size);
+       if (ret)
+               return ret;
+
+       set_cfg_and_line_modes(ctx);
+       set_dei_regs(ctx);
+       set_csc_coeff_bypass(ctx);
+       set_sc_regs_bypass(ctx);
+
+       return 0;
+}
+
+/*
+ * Return the vpe_ctx structure for a given struct file
+ */
+static struct vpe_ctx *file2ctx(struct file *file)
+{
+       return container_of(file->private_data, struct vpe_ctx, fh);
+}
+
+/*
+ * mem2mem callbacks
+ */
+
+/**
+ * job_ready() - check whether an instance is ready to be scheduled to run
+ */
+static int job_ready(void *priv)
+{
+       struct vpe_ctx *ctx = priv;
+       int needed = ctx->bufs_per_job;
+
+       if (ctx->deinterlacing && ctx->src_vbs[2] == NULL)
+               needed += 2;    /* need additional two most recent fields */
+
+       if (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) < needed)
+               return 0;
+
+       return 1;
+}
+
+static void job_abort(void *priv)
+{
+       struct vpe_ctx *ctx = priv;
+
+       /* Will cancel the transaction in the next interrupt handler */
+       ctx->aborting = 1;
+}
+
+/*
+ * Lock access to the device
+ */
+static void vpe_lock(void *priv)
+{
+       struct vpe_ctx *ctx = priv;
+       struct vpe_dev *dev = ctx->dev;
+       mutex_lock(&dev->dev_mutex);
+}
+
+static void vpe_unlock(void *priv)
+{
+       struct vpe_ctx *ctx = priv;
+       struct vpe_dev *dev = ctx->dev;
+       mutex_unlock(&dev->dev_mutex);
+}
+
+static void vpe_dump_regs(struct vpe_dev *dev)
+{
+#define DUMPREG(r) vpe_dbg(dev, "%-35s %08x\n", #r, read_reg(dev, VPE_##r))
+
+       vpe_dbg(dev, "VPE Registers:\n");
+
+       DUMPREG(PID);
+       DUMPREG(SYSCONFIG);
+       DUMPREG(INT0_STATUS0_RAW);
+       DUMPREG(INT0_STATUS0);
+       DUMPREG(INT0_ENABLE0);
+       DUMPREG(INT0_STATUS1_RAW);
+       DUMPREG(INT0_STATUS1);
+       DUMPREG(INT0_ENABLE1);
+       DUMPREG(CLK_ENABLE);
+       DUMPREG(CLK_RESET);
+       DUMPREG(CLK_FORMAT_SELECT);
+       DUMPREG(CLK_RANGE_MAP);
+       DUMPREG(US1_R0);
+       DUMPREG(US1_R1);
+       DUMPREG(US1_R2);
+       DUMPREG(US1_R3);
+       DUMPREG(US1_R4);
+       DUMPREG(US1_R5);
+       DUMPREG(US1_R6);
+       DUMPREG(US1_R7);
+       DUMPREG(US2_R0);
+       DUMPREG(US2_R1);
+       DUMPREG(US2_R2);
+       DUMPREG(US2_R3);
+       DUMPREG(US2_R4);
+       DUMPREG(US2_R5);
+       DUMPREG(US2_R6);
+       DUMPREG(US2_R7);
+       DUMPREG(US3_R0);
+       DUMPREG(US3_R1);
+       DUMPREG(US3_R2);
+       DUMPREG(US3_R3);
+       DUMPREG(US3_R4);
+       DUMPREG(US3_R5);
+       DUMPREG(US3_R6);
+       DUMPREG(US3_R7);
+       DUMPREG(DEI_FRAME_SIZE);
+       DUMPREG(MDT_BYPASS);
+       DUMPREG(MDT_SF_THRESHOLD);
+       DUMPREG(EDI_CONFIG);
+       DUMPREG(DEI_EDI_LUT_R0);
+       DUMPREG(DEI_EDI_LUT_R1);
+       DUMPREG(DEI_EDI_LUT_R2);
+       DUMPREG(DEI_EDI_LUT_R3);
+       DUMPREG(DEI_FMD_WINDOW_R0);
+       DUMPREG(DEI_FMD_WINDOW_R1);
+       DUMPREG(DEI_FMD_CONTROL_R0);
+       DUMPREG(DEI_FMD_CONTROL_R1);
+       DUMPREG(DEI_FMD_STATUS_R0);
+       DUMPREG(DEI_FMD_STATUS_R1);
+       DUMPREG(DEI_FMD_STATUS_R2);
+       DUMPREG(SC_MP_SC0);
+       DUMPREG(SC_MP_SC1);
+       DUMPREG(SC_MP_SC2);
+       DUMPREG(SC_MP_SC3);
+       DUMPREG(SC_MP_SC4);
+       DUMPREG(SC_MP_SC5);
+       DUMPREG(SC_MP_SC6);
+       DUMPREG(SC_MP_SC8);
+       DUMPREG(SC_MP_SC9);
+       DUMPREG(SC_MP_SC10);
+       DUMPREG(SC_MP_SC11);
+       DUMPREG(SC_MP_SC12);
+       DUMPREG(SC_MP_SC13);
+       DUMPREG(SC_MP_SC17);
+       DUMPREG(SC_MP_SC18);
+       DUMPREG(SC_MP_SC19);
+       DUMPREG(SC_MP_SC20);
+       DUMPREG(SC_MP_SC21);
+       DUMPREG(SC_MP_SC22);
+       DUMPREG(SC_MP_SC23);
+       DUMPREG(SC_MP_SC24);
+       DUMPREG(SC_MP_SC25);
+       DUMPREG(CSC_CSC00);
+       DUMPREG(CSC_CSC01);
+       DUMPREG(CSC_CSC02);
+       DUMPREG(CSC_CSC03);
+       DUMPREG(CSC_CSC04);
+       DUMPREG(CSC_CSC05);
+#undef DUMPREG
+}
+
+static void add_out_dtd(struct vpe_ctx *ctx, int port)
+{
+       struct vpe_q_data *q_data = &ctx->q_data[Q_DATA_DST];
+       const struct vpe_port_data *p_data = &port_data[port];
+       struct vb2_buffer *vb = ctx->dst_vb;
+       struct v4l2_rect *c_rect = &q_data->c_rect;
+       struct vpe_fmt *fmt = q_data->fmt;
+       const struct vpdma_data_format *vpdma_fmt;
+       int mv_buf_selector = !ctx->src_mv_buf_selector;
+       dma_addr_t dma_addr;
+       u32 flags = 0;
+
+       if (port == VPE_PORT_MV_OUT) {
+               vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
+               dma_addr = ctx->mv_buf_dma[mv_buf_selector];
+       } else {
+               /* to incorporate interleaved formats */
+               int plane = fmt->coplanar ? p_data->vb_part : 0;
+
+               vpdma_fmt = fmt->vpdma_fmt[plane];
+               dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+               if (!dma_addr) {
+                       vpe_err(ctx->dev,
+                               "acquiring output buffer(%d) dma_addr failed\n",
+                               port);
+                       return;
+               }
+       }
+
+       if (q_data->flags & Q_DATA_FRAME_1D)
+               flags |= VPDMA_DATA_FRAME_1D;
+       if (q_data->flags & Q_DATA_MODE_TILED)
+               flags |= VPDMA_DATA_MODE_TILED;
+
+       vpdma_add_out_dtd(&ctx->desc_list, c_rect, vpdma_fmt, dma_addr,
+               p_data->channel, flags);
+}
+
+static void add_in_dtd(struct vpe_ctx *ctx, int port)
+{
+       struct vpe_q_data *q_data = &ctx->q_data[Q_DATA_SRC];
+       const struct vpe_port_data *p_data = &port_data[port];
+       struct vb2_buffer *vb = ctx->src_vbs[p_data->vb_index];
+       struct v4l2_rect *c_rect = &q_data->c_rect;
+       struct vpe_fmt *fmt = q_data->fmt;
+       const struct vpdma_data_format *vpdma_fmt;
+       int mv_buf_selector = ctx->src_mv_buf_selector;
+       int field = vb->v4l2_buf.field == V4L2_FIELD_BOTTOM;
+       dma_addr_t dma_addr;
+       u32 flags = 0;
+
+       if (port == VPE_PORT_MV_IN) {
+               vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
+               dma_addr = ctx->mv_buf_dma[mv_buf_selector];
+       } else {
+               /* to incorporate interleaved formats */
+               int plane = fmt->coplanar ? p_data->vb_part : 0;
+
+               vpdma_fmt = fmt->vpdma_fmt[plane];
+
+               dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+               if (!dma_addr) {
+                       vpe_err(ctx->dev,
+                               "acquiring input buffer(%d) dma_addr failed\n",
+                               port);
+                       return;
+               }
+       }
+
+       if (q_data->flags & Q_DATA_FRAME_1D)
+               flags |= VPDMA_DATA_FRAME_1D;
+       if (q_data->flags & Q_DATA_MODE_TILED)
+               flags |= VPDMA_DATA_MODE_TILED;
+
+       vpdma_add_in_dtd(&ctx->desc_list, q_data->width, q_data->height,
+               c_rect, vpdma_fmt, dma_addr, p_data->channel, field, flags);
+}
+
+/*
+ * Enable the expected IRQ sources
+ */
+static void enable_irqs(struct vpe_ctx *ctx)
+{
+       write_reg(ctx->dev, VPE_INT0_ENABLE0_SET, VPE_INT0_LIST0_COMPLETE);
+       write_reg(ctx->dev, VPE_INT0_ENABLE1_SET, VPE_DEI_ERROR_INT |
+                               VPE_DS1_UV_ERROR_INT);
+
+       vpdma_enable_list_complete_irq(ctx->dev->vpdma, 0, true);
+}
+
+static void disable_irqs(struct vpe_ctx *ctx)
+{
+       write_reg(ctx->dev, VPE_INT0_ENABLE0_CLR, 0xffffffff);
+       write_reg(ctx->dev, VPE_INT0_ENABLE1_CLR, 0xffffffff);
+
+       vpdma_enable_list_complete_irq(ctx->dev->vpdma, 0, false);
+}
+
+/* device_run() - prepares and starts the device
+ *
+ * This function is only called when both the source and destination
+ * buffers are in place.
+ */
+static void device_run(void *priv)
+{
+       struct vpe_ctx *ctx = priv;
+       struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST];
+
+       if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) {
+               ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+               WARN_ON(ctx->src_vbs[2] == NULL);
+               ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+               WARN_ON(ctx->src_vbs[1] == NULL);
+       }
+
+       ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
+       WARN_ON(ctx->src_vbs[0] == NULL);
+       ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
+       WARN_ON(ctx->dst_vb == NULL);
+
+       /* config descriptors */
+       if (ctx->dev->loaded_mmrs != ctx->mmr_adb.dma_addr || ctx->load_mmrs) {
+               vpdma_map_desc_buf(ctx->dev->vpdma, &ctx->mmr_adb);
+               vpdma_add_cfd_adb(&ctx->desc_list, CFD_MMR_CLIENT, &ctx->mmr_adb);
+               ctx->dev->loaded_mmrs = ctx->mmr_adb.dma_addr;
+               ctx->load_mmrs = false;
+       }
+
+       /* output data descriptors */
+       if (ctx->deinterlacing)
+               add_out_dtd(ctx, VPE_PORT_MV_OUT);
+
+       add_out_dtd(ctx, VPE_PORT_LUMA_OUT);
+       if (d_q_data->fmt->coplanar)
+               add_out_dtd(ctx, VPE_PORT_CHROMA_OUT);
+
+       /* input data descriptors */
+       if (ctx->deinterlacing) {
+               add_in_dtd(ctx, VPE_PORT_LUMA3_IN);
+               add_in_dtd(ctx, VPE_PORT_CHROMA3_IN);
+
+               add_in_dtd(ctx, VPE_PORT_LUMA2_IN);
+               add_in_dtd(ctx, VPE_PORT_CHROMA2_IN);
+       }
+
+       add_in_dtd(ctx, VPE_PORT_LUMA1_IN);
+       add_in_dtd(ctx, VPE_PORT_CHROMA1_IN);
+
+       if (ctx->deinterlacing)
+               add_in_dtd(ctx, VPE_PORT_MV_IN);
+
+       /* sync on channel control descriptors for input ports */
+       vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_LUMA1_IN);
+       vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_CHROMA1_IN);
+
+       if (ctx->deinterlacing) {
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
+                       VPE_CHAN_LUMA2_IN);
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
+                       VPE_CHAN_CHROMA2_IN);
+
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
+                       VPE_CHAN_LUMA3_IN);
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
+                       VPE_CHAN_CHROMA3_IN);
+
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_MV_IN);
+       }
+
+       /* sync on channel control descriptors for output ports */
+       vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_LUMA_OUT);
+       if (d_q_data->fmt->coplanar)
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_CHROMA_OUT);
+
+       if (ctx->deinterlacing)
+               vpdma_add_sync_on_channel_ctd(&ctx->desc_list, VPE_CHAN_MV_OUT);
+
+       enable_irqs(ctx);
+
+       vpdma_map_desc_buf(ctx->dev->vpdma, &ctx->desc_list.buf);
+       vpdma_submit_descs(ctx->dev->vpdma, &ctx->desc_list);
+}
+
+static void dei_error(struct vpe_ctx *ctx)
+{
+       dev_warn(ctx->dev->v4l2_dev.dev,
+               "received DEI error interrupt\n");
+}
+
+static void ds1_uv_error(struct vpe_ctx *ctx)
+{
+       dev_warn(ctx->dev->v4l2_dev.dev,
+               "received downsampler error interrupt\n");
+}
+
+static irqreturn_t vpe_irq(int irq_vpe, void *data)
+{
+       struct vpe_dev *dev = (struct vpe_dev *)data;
+       struct vpe_ctx *ctx;
+       struct vpe_q_data *d_q_data;
+       struct vb2_buffer *s_vb, *d_vb;
+       struct v4l2_buffer *s_buf, *d_buf;
+       unsigned long flags;
+       u32 irqst0, irqst1;
+
+       irqst0 = read_reg(dev, VPE_INT0_STATUS0);
+       if (irqst0) {
+               write_reg(dev, VPE_INT0_STATUS0_CLR, irqst0);
+               vpe_dbg(dev, "INT0_STATUS0 = 0x%08x\n", irqst0);
+       }
+
+       irqst1 = read_reg(dev, VPE_INT0_STATUS1);
+       if (irqst1) {
+               write_reg(dev, VPE_INT0_STATUS1_CLR, irqst1);
+               vpe_dbg(dev, "INT0_STATUS1 = 0x%08x\n", irqst1);
+       }
+
+       ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev);
+       if (!ctx) {
+               vpe_err(dev, "instance released before end of transaction\n");
+               goto handled;
+       }
+
+       if (irqst1) {
+               if (irqst1 & VPE_DEI_ERROR_INT) {
+                       irqst1 &= ~VPE_DEI_ERROR_INT;
+                       dei_error(ctx);
+               }
+               if (irqst1 & VPE_DS1_UV_ERROR_INT) {
+                       irqst1 &= ~VPE_DS1_UV_ERROR_INT;
+                       ds1_uv_error(ctx);
+               }
+       }
+
+       if (irqst0) {
+               if (irqst0 & VPE_INT0_LIST0_COMPLETE)
+                       vpdma_clear_list_stat(ctx->dev->vpdma);
+
+               irqst0 &= ~(VPE_INT0_LIST0_COMPLETE);
+       }
+
+       if (irqst0 | irqst1) {
+               dev_warn(dev->v4l2_dev.dev, "Unexpected interrupt: "
+                       "INT0_STATUS0 = 0x%08x, INT0_STATUS1 = 0x%08x\n",
+                       irqst0, irqst1);
+       }
+
+       disable_irqs(ctx);
+
+       vpdma_unmap_desc_buf(dev->vpdma, &ctx->desc_list.buf);
+       vpdma_unmap_desc_buf(dev->vpdma, &ctx->mmr_adb);
+
+       vpdma_reset_desc_list(&ctx->desc_list);
+
+        /* the previous dst mv buffer becomes the next src mv buffer */
+       ctx->src_mv_buf_selector = !ctx->src_mv_buf_selector;
+
+       if (ctx->aborting)
+               goto finished;
+
+       s_vb = ctx->src_vbs[0];
+       d_vb = ctx->dst_vb;
+       s_buf = &s_vb->v4l2_buf;
+       d_buf = &d_vb->v4l2_buf;
+
+       d_buf->timestamp = s_buf->timestamp;
+       if (s_buf->flags & V4L2_BUF_FLAG_TIMECODE) {
+               d_buf->flags |= V4L2_BUF_FLAG_TIMECODE;
+               d_buf->timecode = s_buf->timecode;
+       }
+       d_buf->sequence = ctx->sequence;
+       d_buf->field = ctx->field;
+
+       d_q_data = &ctx->q_data[Q_DATA_DST];
+       if (d_q_data->flags & Q_DATA_INTERLACED) {
+               if (ctx->field == V4L2_FIELD_BOTTOM) {
+                       ctx->sequence++;
+                       ctx->field = V4L2_FIELD_TOP;
+               } else {
+                       WARN_ON(ctx->field != V4L2_FIELD_TOP);
+                       ctx->field = V4L2_FIELD_BOTTOM;
+               }
+       } else {
+               ctx->sequence++;
+       }
+
+       if (ctx->deinterlacing)
+               s_vb = ctx->src_vbs[2];
+
+       spin_lock_irqsave(&dev->lock, flags);
+       v4l2_m2m_buf_done(s_vb, VB2_BUF_STATE_DONE);
+       v4l2_m2m_buf_done(d_vb, VB2_BUF_STATE_DONE);
+       spin_unlock_irqrestore(&dev->lock, flags);
+
+       if (ctx->deinterlacing) {
+               ctx->src_vbs[2] = ctx->src_vbs[1];
+               ctx->src_vbs[1] = ctx->src_vbs[0];
+       }
+
+       ctx->bufs_completed++;
+       if (ctx->bufs_completed < ctx->bufs_per_job) {
+               device_run(ctx);
+               goto handled;
+       }
+
+finished:
+       vpe_dbg(ctx->dev, "finishing transaction\n");
+       ctx->bufs_completed = 0;
+       v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx);
+handled:
+       return IRQ_HANDLED;
+}
+
+/*
+ * video ioctls
+ */
+static int vpe_querycap(struct file *file, void *priv,
+                       struct v4l2_capability *cap)
+{
+       strncpy(cap->driver, VPE_MODULE_NAME, sizeof(cap->driver) - 1);
+       strncpy(cap->card, VPE_MODULE_NAME, sizeof(cap->card) - 1);
+       strlcpy(cap->bus_info, VPE_MODULE_NAME, sizeof(cap->bus_info));
+       cap->device_caps  = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
+       cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
+       return 0;
+}
+
+static int __enum_fmt(struct v4l2_fmtdesc *f, u32 type)
+{
+       int i, index;
+       struct vpe_fmt *fmt = NULL;
+
+       index = 0;
+       for (i = 0; i < ARRAY_SIZE(vpe_formats); ++i) {
+               if (vpe_formats[i].types & type) {
+                       if (index == f->index) {
+                               fmt = &vpe_formats[i];
+                               break;
+                       }
+                       index++;
+               }
+       }
+
+       if (!fmt)
+               return -EINVAL;
+
+       strncpy(f->description, fmt->name, sizeof(f->description) - 1);
+       f->pixelformat = fmt->fourcc;
+       return 0;
+}
+
+static int vpe_enum_fmt(struct file *file, void *priv,
+                               struct v4l2_fmtdesc *f)
+{
+       if (V4L2_TYPE_IS_OUTPUT(f->type))
+               return __enum_fmt(f, VPE_FMT_TYPE_OUTPUT);
+
+       return __enum_fmt(f, VPE_FMT_TYPE_CAPTURE);
+}
+
+static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
+{
+       struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
+       struct vpe_ctx *ctx = file2ctx(file);
+       struct vb2_queue *vq;
+       struct vpe_q_data *q_data;
+       int i;
+
+       vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
+       if (!vq)
+               return -EINVAL;
+
+       q_data = get_q_data(ctx, f->type);
+
+       pix->width = q_data->width;
+       pix->height = q_data->height;
+       pix->pixelformat = q_data->fmt->fourcc;
+       pix->field = q_data->field;
+
+       if (V4L2_TYPE_IS_OUTPUT(f->type)) {
+               pix->colorspace = q_data->colorspace;
+       } else {
+               struct vpe_q_data *s_q_data;
+
+               /* get colorspace from the source queue */
+               s_q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
+
+               pix->colorspace = s_q_data->colorspace;
+       }
+
+       pix->num_planes = q_data->fmt->coplanar ? 2 : 1;
+
+       for (i = 0; i < pix->num_planes; i++) {
+               pix->plane_fmt[i].bytesperline = q_data->bytesperline[i];
+               pix->plane_fmt[i].sizeimage = q_data->sizeimage[i];
+       }
+
+       return 0;
+}
+
+static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
+                      struct vpe_fmt *fmt, int type)
+{
+       struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
+       struct v4l2_plane_pix_format *plane_fmt;
+       int i;
+
+       if (!fmt || !(fmt->types & type)) {
+               vpe_err(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
+                       pix->pixelformat);
+               return -EINVAL;
+       }
+
+       if (pix->field != V4L2_FIELD_NONE && pix->field != V4L2_FIELD_ALTERNATE)
+               pix->field = V4L2_FIELD_NONE;
+
+       v4l_bound_align_image(&pix->width, MIN_W, MAX_W, W_ALIGN,
+                             &pix->height, MIN_H, MAX_H, H_ALIGN,
+                             S_ALIGN);
+
+       pix->num_planes = fmt->coplanar ? 2 : 1;
+       pix->pixelformat = fmt->fourcc;
+
+       if (type == VPE_FMT_TYPE_CAPTURE) {
+               struct vpe_q_data *s_q_data;
+
+               /* get colorspace from the source queue */
+               s_q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
+
+               pix->colorspace = s_q_data->colorspace;
+       } else {
+               if (!pix->colorspace)
+                       pix->colorspace = V4L2_COLORSPACE_SMPTE240M;
+       }
+
+       for (i = 0; i < pix->num_planes; i++) {
+               int depth;
+
+               plane_fmt = &pix->plane_fmt[i];
+               depth = fmt->vpdma_fmt[i]->depth;
+
+               if (i == VPE_LUMA)
+                       plane_fmt->bytesperline =
+                                       round_up((pix->width * depth) >> 3,
+                                               1 << L_ALIGN);
+               else
+                       plane_fmt->bytesperline = pix->width;
+
+               plane_fmt->sizeimage =
+                               (pix->height * pix->width * depth) >> 3;
+       }
+
+       return 0;
+}
+
+static int vpe_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+       struct vpe_fmt *fmt = find_format(f);
+
+       if (V4L2_TYPE_IS_OUTPUT(f->type))
+               return __vpe_try_fmt(ctx, f, fmt, VPE_FMT_TYPE_OUTPUT);
+       else
+               return __vpe_try_fmt(ctx, f, fmt, VPE_FMT_TYPE_CAPTURE);
+}
+
+static int __vpe_s_fmt(struct vpe_ctx *ctx, struct v4l2_format *f)
+{
+       struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
+       struct v4l2_plane_pix_format *plane_fmt;
+       struct vpe_q_data *q_data;
+       struct vb2_queue *vq;
+       int i;
+
+       vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
+       if (!vq)
+               return -EINVAL;
+
+       if (vb2_is_busy(vq)) {
+               vpe_err(ctx->dev, "queue busy\n");
+               return -EBUSY;
+       }
+
+       q_data = get_q_data(ctx, f->type);
+       if (!q_data)
+               return -EINVAL;
+
+       q_data->fmt             = find_format(f);
+       q_data->width           = pix->width;
+       q_data->height          = pix->height;
+       q_data->colorspace      = pix->colorspace;
+       q_data->field           = pix->field;
+
+       for (i = 0; i < pix->num_planes; i++) {
+               plane_fmt = &pix->plane_fmt[i];
+
+               q_data->bytesperline[i] = plane_fmt->bytesperline;
+               q_data->sizeimage[i]    = plane_fmt->sizeimage;
+       }
+
+       q_data->c_rect.left     = 0;
+       q_data->c_rect.top      = 0;
+       q_data->c_rect.width    = q_data->width;
+       q_data->c_rect.height   = q_data->height;
+
+       if (q_data->field == V4L2_FIELD_ALTERNATE)
+               q_data->flags |= Q_DATA_INTERLACED;
+       else
+               q_data->flags &= ~Q_DATA_INTERLACED;
+
+       vpe_dbg(ctx->dev, "Setting format for type %d, wxh: %dx%d, fmt: %d bpl_y %d",
+               f->type, q_data->width, q_data->height, q_data->fmt->fourcc,
+               q_data->bytesperline[VPE_LUMA]);
+       if (q_data->fmt->coplanar)
+               vpe_dbg(ctx->dev, " bpl_uv %d\n",
+                       q_data->bytesperline[VPE_CHROMA]);
+
+       return 0;
+}
+
+static int vpe_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
+{
+       int ret;
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       ret = vpe_try_fmt(file, priv, f);
+       if (ret)
+               return ret;
+
+       ret = __vpe_s_fmt(ctx, f);
+       if (ret)
+               return ret;
+
+       if (V4L2_TYPE_IS_OUTPUT(f->type))
+               set_src_registers(ctx);
+       else
+               set_dst_registers(ctx);
+
+       return set_srcdst_params(ctx);
+}
+
+static int vpe_reqbufs(struct file *file, void *priv,
+                      struct v4l2_requestbuffers *reqbufs)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
+}
+
+static int vpe_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
+}
+
+static int vpe_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
+}
+
+static int vpe_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
+}
+
+static int vpe_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
+}
+
+static int vpe_streamoff(struct file *file, void *priv, enum v4l2_buf_type type)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       vpe_dump_regs(ctx->dev);
+       vpdma_dump_regs(ctx->dev->vpdma);
+
+       return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
+}
+
+/*
+ * defines number of buffers/frames a context can process with VPE before
+ * switching to a different context. default value is 1 buffer per context
+ */
+#define V4L2_CID_VPE_BUFS_PER_JOB              (V4L2_CID_USER_TI_VPE_BASE + 0)
+
+static int vpe_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+       struct vpe_ctx *ctx =
+               container_of(ctrl->handler, struct vpe_ctx, hdl);
+
+       switch (ctrl->id) {
+       case V4L2_CID_VPE_BUFS_PER_JOB:
+               ctx->bufs_per_job = ctrl->val;
+               break;
+
+       default:
+               vpe_err(ctx->dev, "Invalid control\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static const struct v4l2_ctrl_ops vpe_ctrl_ops = {
+       .s_ctrl = vpe_s_ctrl,
+};
+
+static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
+       .vidioc_querycap        = vpe_querycap,
+
+       .vidioc_enum_fmt_vid_cap_mplane = vpe_enum_fmt,
+       .vidioc_g_fmt_vid_cap_mplane    = vpe_g_fmt,
+       .vidioc_try_fmt_vid_cap_mplane  = vpe_try_fmt,
+       .vidioc_s_fmt_vid_cap_mplane    = vpe_s_fmt,
+
+       .vidioc_enum_fmt_vid_out_mplane = vpe_enum_fmt,
+       .vidioc_g_fmt_vid_out_mplane    = vpe_g_fmt,
+       .vidioc_try_fmt_vid_out_mplane  = vpe_try_fmt,
+       .vidioc_s_fmt_vid_out_mplane    = vpe_s_fmt,
+
+       .vidioc_reqbufs         = vpe_reqbufs,
+       .vidioc_querybuf        = vpe_querybuf,
+
+       .vidioc_qbuf            = vpe_qbuf,
+       .vidioc_dqbuf           = vpe_dqbuf,
+
+       .vidioc_streamon        = vpe_streamon,
+       .vidioc_streamoff       = vpe_streamoff,
+       .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+       .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+/*
+ * Queue operations
+ */
+static int vpe_queue_setup(struct vb2_queue *vq,
+                          const struct v4l2_format *fmt,
+                          unsigned int *nbuffers, unsigned int *nplanes,
+                          unsigned int sizes[], void *alloc_ctxs[])
+{
+       int i;
+       struct vpe_ctx *ctx = vb2_get_drv_priv(vq);
+       struct vpe_q_data *q_data;
+
+       q_data = get_q_data(ctx, vq->type);
+
+       *nplanes = q_data->fmt->coplanar ? 2 : 1;
+
+       for (i = 0; i < *nplanes; i++) {
+               sizes[i] = q_data->sizeimage[i];
+               alloc_ctxs[i] = ctx->dev->alloc_ctx;
+       }
+
+       vpe_dbg(ctx->dev, "get %d buffer(s) of size %d", *nbuffers,
+               sizes[VPE_LUMA]);
+       if (q_data->fmt->coplanar)
+               vpe_dbg(ctx->dev, " and %d\n", sizes[VPE_CHROMA]);
+
+       return 0;
+}
+
+static int vpe_buf_prepare(struct vb2_buffer *vb)
+{
+       struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+       struct vpe_q_data *q_data;
+       int i, num_planes;
+
+       vpe_dbg(ctx->dev, "type: %d\n", vb->vb2_queue->type);
+
+       q_data = get_q_data(ctx, vb->vb2_queue->type);
+       num_planes = q_data->fmt->coplanar ? 2 : 1;
+
+       for (i = 0; i < num_planes; i++) {
+               if (vb2_plane_size(vb, i) < q_data->sizeimage[i]) {
+                       vpe_err(ctx->dev,
+                               "data will not fit into plane (%lu < %lu)\n",
+                               vb2_plane_size(vb, i),
+                               (long) q_data->sizeimage[i]);
+                       return -EINVAL;
+               }
+       }
+
+       for (i = 0; i < num_planes; i++)
+               vb2_set_plane_payload(vb, i, q_data->sizeimage[i]);
+
+       return 0;
+}
+
+static void vpe_buf_queue(struct vb2_buffer *vb)
+{
+       struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+       v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
+}
+
+static void vpe_wait_prepare(struct vb2_queue *q)
+{
+       struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+       vpe_unlock(ctx);
+}
+
+static void vpe_wait_finish(struct vb2_queue *q)
+{
+       struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+       vpe_lock(ctx);
+}
+
+static struct vb2_ops vpe_qops = {
+       .queue_setup     = vpe_queue_setup,
+       .buf_prepare     = vpe_buf_prepare,
+       .buf_queue       = vpe_buf_queue,
+       .wait_prepare    = vpe_wait_prepare,
+       .wait_finish     = vpe_wait_finish,
+};
+
+static int queue_init(void *priv, struct vb2_queue *src_vq,
+                     struct vb2_queue *dst_vq)
+{
+       struct vpe_ctx *ctx = priv;
+       int ret;
+
+       memset(src_vq, 0, sizeof(*src_vq));
+       src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+       src_vq->io_modes = VB2_MMAP;
+       src_vq->drv_priv = ctx;
+       src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
+       src_vq->ops = &vpe_qops;
+       src_vq->mem_ops = &vb2_dma_contig_memops;
+       src_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+
+       ret = vb2_queue_init(src_vq);
+       if (ret)
+               return ret;
+
+       memset(dst_vq, 0, sizeof(*dst_vq));
+       dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+       dst_vq->io_modes = VB2_MMAP;
+       dst_vq->drv_priv = ctx;
+       dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
+       dst_vq->ops = &vpe_qops;
+       dst_vq->mem_ops = &vb2_dma_contig_memops;
+       dst_vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+
+       return vb2_queue_init(dst_vq);
+}
+
+static const struct v4l2_ctrl_config vpe_bufs_per_job = {
+       .ops = &vpe_ctrl_ops,
+       .id = V4L2_CID_VPE_BUFS_PER_JOB,
+       .name = "Buffers Per Transaction",
+       .type = V4L2_CTRL_TYPE_INTEGER,
+       .def = VPE_DEF_BUFS_PER_JOB,
+       .min = 1,
+       .max = VIDEO_MAX_FRAME,
+       .step = 1,
+};
+
+/*
+ * File operations
+ */
+static int vpe_open(struct file *file)
+{
+       struct vpe_dev *dev = video_drvdata(file);
+       struct vpe_ctx *ctx = NULL;
+       struct vpe_q_data *s_q_data;
+       struct v4l2_ctrl_handler *hdl;
+       int ret;
+
+       vpe_dbg(dev, "vpe_open\n");
+
+       if (!dev->vpdma->ready) {
+               vpe_err(dev, "vpdma firmware not loaded\n");
+               return -ENODEV;
+       }
+
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       ctx->dev = dev;
+
+       if (mutex_lock_interruptible(&dev->dev_mutex)) {
+               ret = -ERESTARTSYS;
+               goto free_ctx;
+       }
+
+       ret = vpdma_create_desc_list(&ctx->desc_list, VPE_DESC_LIST_SIZE,
+                       VPDMA_LIST_TYPE_NORMAL);
+       if (ret != 0)
+               goto unlock;
+
+       ret = vpdma_alloc_desc_buf(&ctx->mmr_adb, sizeof(struct vpe_mmr_adb));
+       if (ret != 0)
+               goto free_desc_list;
+
+       init_adb_hdrs(ctx);
+
+       v4l2_fh_init(&ctx->fh, video_devdata(file));
+       file->private_data = &ctx->fh;
+
+       hdl = &ctx->hdl;
+       v4l2_ctrl_handler_init(hdl, 1);
+       v4l2_ctrl_new_custom(hdl, &vpe_bufs_per_job, NULL);
+       if (hdl->error) {
+               ret = hdl->error;
+               goto exit_fh;
+       }
+       ctx->fh.ctrl_handler = hdl;
+       v4l2_ctrl_handler_setup(hdl);
+
+       s_q_data = &ctx->q_data[Q_DATA_SRC];
+       s_q_data->fmt = &vpe_formats[2];
+       s_q_data->width = 1920;
+       s_q_data->height = 1080;
+       s_q_data->sizeimage[VPE_LUMA] = (s_q_data->width * s_q_data->height *
+                       s_q_data->fmt->vpdma_fmt[VPE_LUMA]->depth) >> 3;
+       s_q_data->colorspace = V4L2_COLORSPACE_SMPTE240M;
+       s_q_data->field = V4L2_FIELD_NONE;
+       s_q_data->c_rect.left = 0;
+       s_q_data->c_rect.top = 0;
+       s_q_data->c_rect.width = s_q_data->width;
+       s_q_data->c_rect.height = s_q_data->height;
+       s_q_data->flags = 0;
+
+       ctx->q_data[Q_DATA_DST] = *s_q_data;
+
+       set_dei_shadow_registers(ctx);
+       set_src_registers(ctx);
+       set_dst_registers(ctx);
+       ret = set_srcdst_params(ctx);
+       if (ret)
+               goto exit_fh;
+
+       ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
+
+       if (IS_ERR(ctx->m2m_ctx)) {
+               ret = PTR_ERR(ctx->m2m_ctx);
+               goto exit_fh;
+       }
+
+       v4l2_fh_add(&ctx->fh);
+
+       /*
+        * for now, just report the creation of the first instance, we can later
+        * optimize the driver to enable or disable clocks when the first
+        * instance is created or the last instance released
+        */
+       if (atomic_inc_return(&dev->num_instances) == 1)
+               vpe_dbg(dev, "first instance created\n");
+
+       ctx->bufs_per_job = VPE_DEF_BUFS_PER_JOB;
+
+       ctx->load_mmrs = true;
+
+       vpe_dbg(dev, "created instance %p, m2m_ctx: %p\n",
+               ctx, ctx->m2m_ctx);
+
+       mutex_unlock(&dev->dev_mutex);
+
+       return 0;
+exit_fh:
+       v4l2_ctrl_handler_free(hdl);
+       v4l2_fh_exit(&ctx->fh);
+       vpdma_free_desc_buf(&ctx->mmr_adb);
+free_desc_list:
+       vpdma_free_desc_list(&ctx->desc_list);
+unlock:
+       mutex_unlock(&dev->dev_mutex);
+free_ctx:
+       kfree(ctx);
+       return ret;
+}
+
+static int vpe_release(struct file *file)
+{
+       struct vpe_dev *dev = video_drvdata(file);
+       struct vpe_ctx *ctx = file2ctx(file);
+
+       vpe_dbg(dev, "releasing instance %p\n", ctx);
+
+       mutex_lock(&dev->dev_mutex);
+       free_vbs(ctx);
+       free_mv_buffers(ctx);
+       vpdma_free_desc_list(&ctx->desc_list);
+       vpdma_free_desc_buf(&ctx->mmr_adb);
+
+       v4l2_fh_del(&ctx->fh);
+       v4l2_fh_exit(&ctx->fh);
+       v4l2_ctrl_handler_free(&ctx->hdl);
+       v4l2_m2m_ctx_release(ctx->m2m_ctx);
+
+       kfree(ctx);
+
+       /*
+        * for now, just report the release of the last instance, we can later
+        * optimize the driver to enable or disable clocks when the first
+        * instance is created or the last instance released
+        */
+       if (atomic_dec_return(&dev->num_instances) == 0)
+               vpe_dbg(dev, "last instance released\n");
+
+       mutex_unlock(&dev->dev_mutex);
+
+       return 0;
+}
+
+static unsigned int vpe_poll(struct file *file,
+                            struct poll_table_struct *wait)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+       struct vpe_dev *dev = ctx->dev;
+       int ret;
+
+       mutex_lock(&dev->dev_mutex);
+       ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
+       mutex_unlock(&dev->dev_mutex);
+       return ret;
+}
+
+static int vpe_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       struct vpe_ctx *ctx = file2ctx(file);
+       struct vpe_dev *dev = ctx->dev;
+       int ret;
+
+       if (mutex_lock_interruptible(&dev->dev_mutex))
+               return -ERESTARTSYS;
+       ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
+       mutex_unlock(&dev->dev_mutex);
+       return ret;
+}
+
+static const struct v4l2_file_operations vpe_fops = {
+       .owner          = THIS_MODULE,
+       .open           = vpe_open,
+       .release        = vpe_release,
+       .poll           = vpe_poll,
+       .unlocked_ioctl = video_ioctl2,
+       .mmap           = vpe_mmap,
+};
+
+static struct video_device vpe_videodev = {
+       .name           = VPE_MODULE_NAME,
+       .fops           = &vpe_fops,
+       .ioctl_ops      = &vpe_ioctl_ops,
+       .minor          = -1,
+       .release        = video_device_release,
+       .vfl_dir        = VFL_DIR_M2M,
+};
+
+static struct v4l2_m2m_ops m2m_ops = {
+       .device_run     = device_run,
+       .job_ready      = job_ready,
+       .job_abort      = job_abort,
+       .lock           = vpe_lock,
+       .unlock         = vpe_unlock,
+};
+
+static int vpe_runtime_get(struct platform_device *pdev)
+{
+       int r;
+
+       dev_dbg(&pdev->dev, "vpe_runtime_get\n");
+
+       r = pm_runtime_get_sync(&pdev->dev);
+       WARN_ON(r < 0);
+       return r < 0 ? r : 0;
+}
+
+static void vpe_runtime_put(struct platform_device *pdev)
+{
+
+       int r;
+
+       dev_dbg(&pdev->dev, "vpe_runtime_put\n");
+
+       r = pm_runtime_put_sync(&pdev->dev);
+       WARN_ON(r < 0 && r != -ENOSYS);
+}
+
+static int vpe_probe(struct platform_device *pdev)
+{
+       struct vpe_dev *dev;
+       struct video_device *vfd;
+       struct resource *res;
+       int ret, irq, func;
+
+       dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+       if (IS_ERR(dev))
+               return PTR_ERR(dev);
+
+       spin_lock_init(&dev->lock);
+
+       ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
+       if (ret)
+               return ret;
+
+       atomic_set(&dev->num_instances, 0);
+       mutex_init(&dev->dev_mutex);
+
+       res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpe_top");
+       /*
+        * HACK: we get resource info from device tree in the form of a list of
+        * VPE sub blocks, the driver currently uses only the base of vpe_top
+        * for register access, the driver should be changed later to access
+        * registers based on the sub block base addresses
+        */
+       dev->base = devm_ioremap(&pdev->dev, res->start, SZ_32K);
+       if (IS_ERR(dev->base)) {
+               ret = PTR_ERR(dev->base);
+               goto v4l2_dev_unreg;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       ret = devm_request_irq(&pdev->dev, irq, vpe_irq, 0, VPE_MODULE_NAME,
+                       dev);
+       if (ret)
+               goto v4l2_dev_unreg;
+
+       platform_set_drvdata(pdev, dev);
+
+       dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
+       if (IS_ERR(dev->alloc_ctx)) {
+               vpe_err(dev, "Failed to alloc vb2 context\n");
+               ret = PTR_ERR(dev->alloc_ctx);
+               goto v4l2_dev_unreg;
+       }
+
+       dev->m2m_dev = v4l2_m2m_init(&m2m_ops);
+       if (IS_ERR(dev->m2m_dev)) {
+               vpe_err(dev, "Failed to init mem2mem device\n");
+               ret = PTR_ERR(dev->m2m_dev);
+               goto rel_ctx;
+       }
+
+       pm_runtime_enable(&pdev->dev);
+
+       ret = vpe_runtime_get(pdev);
+       if (ret)
+               goto rel_m2m;
+
+       /* Perform clk enable followed by reset */
+       vpe_set_clock_enable(dev, 1);
+
+       vpe_top_reset(dev);
+
+       func = read_field_reg(dev, VPE_PID, VPE_PID_FUNC_MASK,
+               VPE_PID_FUNC_SHIFT);
+       vpe_dbg(dev, "VPE PID function %x\n", func);
+
+       vpe_top_vpdma_reset(dev);
+
+       dev->vpdma = vpdma_create(pdev);
+       if (IS_ERR(dev->vpdma))
+               goto runtime_put;
+
+       vfd = &dev->vfd;
+       *vfd = vpe_videodev;
+       vfd->lock = &dev->dev_mutex;
+       vfd->v4l2_dev = &dev->v4l2_dev;
+
+       ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
+       if (ret) {
+               vpe_err(dev, "Failed to register video device\n");
+               goto runtime_put;
+       }
+
+       video_set_drvdata(vfd, dev);
+       snprintf(vfd->name, sizeof(vfd->name), "%s", vpe_videodev.name);
+       dev_info(dev->v4l2_dev.dev, "Device registered as /dev/video%d\n",
+               vfd->num);
+
+       return 0;
+
+runtime_put:
+       vpe_runtime_put(pdev);
+rel_m2m:
+       pm_runtime_disable(&pdev->dev);
+       v4l2_m2m_release(dev->m2m_dev);
+rel_ctx:
+       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
+v4l2_dev_unreg:
+       v4l2_device_unregister(&dev->v4l2_dev);
+
+       return ret;
+}
+
+static int vpe_remove(struct platform_device *pdev)
+{
+       struct vpe_dev *dev =
+               (struct vpe_dev *) platform_get_drvdata(pdev);
+
+       v4l2_info(&dev->v4l2_dev, "Removing " VPE_MODULE_NAME);
+
+       v4l2_m2m_release(dev->m2m_dev);
+       video_unregister_device(&dev->vfd);
+       v4l2_device_unregister(&dev->v4l2_dev);
+       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
+
+       vpe_set_clock_enable(dev, 0);
+       vpe_runtime_put(pdev);
+       pm_runtime_disable(&pdev->dev);
+
+       return 0;
+}
+
+#if defined(CONFIG_OF)
+static const struct of_device_id vpe_of_match[] = {
+       {
+               .compatible = "ti,vpe",
+       },
+       {},
+};
+#else
+#define vpe_of_match NULL
+#endif
+
+static struct platform_driver vpe_pdrv = {
+       .probe          = vpe_probe,
+       .remove         = vpe_remove,
+       .driver         = {
+               .name   = VPE_MODULE_NAME,
+               .owner  = THIS_MODULE,
+               .of_match_table = vpe_of_match,
+       },
+};
+
+static void __exit vpe_exit(void)
+{
+       platform_driver_unregister(&vpe_pdrv);
+}
+
+static int __init vpe_init(void)
+{
+       return platform_driver_register(&vpe_pdrv);
+}
+
+module_init(vpe_init);
+module_exit(vpe_exit);
+
+MODULE_DESCRIPTION("TI VPE driver");
+MODULE_AUTHOR("Dale Farnsworth, <dale@farnsworth.org>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/platform/ti-vpe/vpe_regs.h b/drivers/media/platform/ti-vpe/vpe_regs.h
new file mode 100644 (file)
index 0000000..ed214e8
--- /dev/null
@@ -0,0 +1,496 @@
+/*
+ * Copyright (c) 2013 Texas Instruments Inc.
+ *
+ * David Griego, <dagriego@biglakesoftware.com>
+ * Dale Farnsworth, <dale@farnsworth.org>
+ * Archit Taneja, <archit@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef __TI_VPE_REGS_H
+#define __TI_VPE_REGS_H
+
+/* VPE register offsets and field selectors */
+
+/* VPE top level regs */
+#define VPE_PID                                0x0000
+#define VPE_PID_MINOR_MASK             0x3f
+#define VPE_PID_MINOR_SHIFT            0
+#define VPE_PID_CUSTOM_MASK            0x03
+#define VPE_PID_CUSTOM_SHIFT           6
+#define VPE_PID_MAJOR_MASK             0x07
+#define VPE_PID_MAJOR_SHIFT            8
+#define VPE_PID_RTL_MASK               0x1f
+#define VPE_PID_RTL_SHIFT              11
+#define VPE_PID_FUNC_MASK              0xfff
+#define VPE_PID_FUNC_SHIFT             16
+#define VPE_PID_SCHEME_MASK            0x03
+#define VPE_PID_SCHEME_SHIFT           30
+
+#define VPE_SYSCONFIG                  0x0010
+#define VPE_SYSCONFIG_IDLE_MASK                0x03
+#define VPE_SYSCONFIG_IDLE_SHIFT       2
+#define VPE_SYSCONFIG_STANDBY_MASK     0x03
+#define VPE_SYSCONFIG_STANDBY_SHIFT    4
+#define VPE_FORCE_IDLE_MODE            0
+#define VPE_NO_IDLE_MODE               1
+#define VPE_SMART_IDLE_MODE            2
+#define VPE_SMART_IDLE_WAKEUP_MODE     3
+#define VPE_FORCE_STANDBY_MODE         0
+#define VPE_NO_STANDBY_MODE            1
+#define VPE_SMART_STANDBY_MODE         2
+#define VPE_SMART_STANDBY_WAKEUP_MODE  3
+
+#define VPE_INT0_STATUS0_RAW_SET       0x0020
+#define VPE_INT0_STATUS0_RAW           VPE_INT0_STATUS0_RAW_SET
+#define VPE_INT0_STATUS0_CLR           0x0028
+#define VPE_INT0_STATUS0               VPE_INT0_STATUS0_CLR
+#define VPE_INT0_ENABLE0_SET           0x0030
+#define VPE_INT0_ENABLE0               VPE_INT0_ENABLE0_SET
+#define VPE_INT0_ENABLE0_CLR           0x0038
+#define VPE_INT0_LIST0_COMPLETE                (1 << 0)
+#define VPE_INT0_LIST0_NOTIFY          (1 << 1)
+#define VPE_INT0_LIST1_COMPLETE                (1 << 2)
+#define VPE_INT0_LIST1_NOTIFY          (1 << 3)
+#define VPE_INT0_LIST2_COMPLETE                (1 << 4)
+#define VPE_INT0_LIST2_NOTIFY          (1 << 5)
+#define VPE_INT0_LIST3_COMPLETE                (1 << 6)
+#define VPE_INT0_LIST3_NOTIFY          (1 << 7)
+#define VPE_INT0_LIST4_COMPLETE                (1 << 8)
+#define VPE_INT0_LIST4_NOTIFY          (1 << 9)
+#define VPE_INT0_LIST5_COMPLETE                (1 << 10)
+#define VPE_INT0_LIST5_NOTIFY          (1 << 11)
+#define VPE_INT0_LIST6_COMPLETE                (1 << 12)
+#define VPE_INT0_LIST6_NOTIFY          (1 << 13)
+#define VPE_INT0_LIST7_COMPLETE                (1 << 14)
+#define VPE_INT0_LIST7_NOTIFY          (1 << 15)
+#define VPE_INT0_DESCRIPTOR            (1 << 16)
+#define VPE_DEI_FMD_INT                        (1 << 18)
+
+#define VPE_INT0_STATUS1_RAW_SET       0x0024
+#define VPE_INT0_STATUS1_RAW           VPE_INT0_STATUS1_RAW_SET
+#define VPE_INT0_STATUS1_CLR           0x002c
+#define VPE_INT0_STATUS1               VPE_INT0_STATUS1_CLR
+#define VPE_INT0_ENABLE1_SET           0x0034
+#define VPE_INT0_ENABLE1               VPE_INT0_ENABLE1_SET
+#define VPE_INT0_ENABLE1_CLR           0x003c
+#define VPE_INT0_CHANNEL_GROUP0                (1 << 0)
+#define VPE_INT0_CHANNEL_GROUP1                (1 << 1)
+#define VPE_INT0_CHANNEL_GROUP2                (1 << 2)
+#define VPE_INT0_CHANNEL_GROUP3                (1 << 3)
+#define VPE_INT0_CHANNEL_GROUP4                (1 << 4)
+#define VPE_INT0_CHANNEL_GROUP5                (1 << 5)
+#define VPE_INT0_CLIENT                        (1 << 7)
+#define VPE_DEI_ERROR_INT              (1 << 16)
+#define VPE_DS1_UV_ERROR_INT           (1 << 22)
+
+#define VPE_INTC_EOI                   0x00a0
+
+#define VPE_CLK_ENABLE                 0x0100
+#define VPE_VPEDMA_CLK_ENABLE          (1 << 0)
+#define VPE_DATA_PATH_CLK_ENABLE       (1 << 1)
+
+#define VPE_CLK_RESET                  0x0104
+#define VPE_VPDMA_CLK_RESET_MASK       0x1
+#define VPE_VPDMA_CLK_RESET_SHIFT      0
+#define VPE_DATA_PATH_CLK_RESET_MASK   0x1
+#define VPE_DATA_PATH_CLK_RESET_SHIFT  1
+#define VPE_MAIN_RESET_MASK            0x1
+#define VPE_MAIN_RESET_SHIFT           31
+
+#define VPE_CLK_FORMAT_SELECT          0x010c
+#define VPE_CSC_SRC_SELECT_MASK                0x03
+#define VPE_CSC_SRC_SELECT_SHIFT       0
+#define VPE_RGB_OUT_SELECT             (1 << 8)
+#define VPE_DS_SRC_SELECT_MASK         0x07
+#define VPE_DS_SRC_SELECT_SHIFT                9
+#define VPE_DS_BYPASS                  (1 << 16)
+#define VPE_COLOR_SEPARATE_422         (1 << 18)
+
+#define VPE_DS_SRC_DEI_SCALER          (5 << VPE_DS_SRC_SELECT_SHIFT)
+#define VPE_CSC_SRC_DEI_SCALER         (3 << VPE_CSC_SRC_SELECT_SHIFT)
+
+#define VPE_CLK_RANGE_MAP              0x011c
+#define VPE_RANGE_RANGE_MAP_Y_MASK     0x07
+#define VPE_RANGE_RANGE_MAP_Y_SHIFT    0
+#define VPE_RANGE_RANGE_MAP_UV_MASK    0x07
+#define VPE_RANGE_RANGE_MAP_UV_SHIFT   3
+#define VPE_RANGE_MAP_ON               (1 << 6)
+#define VPE_RANGE_REDUCTION_ON         (1 << 28)
+
+/* VPE chrominance upsampler regs */
+#define VPE_US1_R0                     0x0304
+#define VPE_US2_R0                     0x0404
+#define VPE_US3_R0                     0x0504
+#define VPE_US_C1_MASK                 0x3fff
+#define VPE_US_C1_SHIFT                        2
+#define VPE_US_C0_MASK                 0x3fff
+#define VPE_US_C0_SHIFT                        18
+#define VPE_US_MODE_MASK               0x03
+#define VPE_US_MODE_SHIFT              16
+#define VPE_ANCHOR_FID0_C1_MASK                0x3fff
+#define VPE_ANCHOR_FID0_C1_SHIFT       2
+#define VPE_ANCHOR_FID0_C0_MASK                0x3fff
+#define VPE_ANCHOR_FID0_C0_SHIFT       18
+
+#define VPE_US1_R1                     0x0308
+#define VPE_US2_R1                     0x0408
+#define VPE_US3_R1                     0x0508
+#define VPE_ANCHOR_FID0_C3_MASK                0x3fff
+#define VPE_ANCHOR_FID0_C3_SHIFT       2
+#define VPE_ANCHOR_FID0_C2_MASK                0x3fff
+#define VPE_ANCHOR_FID0_C2_SHIFT       18
+
+#define VPE_US1_R2                     0x030c
+#define VPE_US2_R2                     0x040c
+#define VPE_US3_R2                     0x050c
+#define VPE_INTERP_FID0_C1_MASK                0x3fff
+#define VPE_INTERP_FID0_C1_SHIFT       2
+#define VPE_INTERP_FID0_C0_MASK                0x3fff
+#define VPE_INTERP_FID0_C0_SHIFT       18
+
+#define VPE_US1_R3                     0x0310
+#define VPE_US2_R3                     0x0410
+#define VPE_US3_R3                     0x0510
+#define VPE_INTERP_FID0_C3_MASK                0x3fff
+#define VPE_INTERP_FID0_C3_SHIFT       2
+#define VPE_INTERP_FID0_C2_MASK                0x3fff
+#define VPE_INTERP_FID0_C2_SHIFT       18
+
+#define VPE_US1_R4                     0x0314
+#define VPE_US2_R4                     0x0414
+#define VPE_US3_R4                     0x0514
+#define VPE_ANCHOR_FID1_C1_MASK                0x3fff
+#define VPE_ANCHOR_FID1_C1_SHIFT       2
+#define VPE_ANCHOR_FID1_C0_MASK                0x3fff
+#define VPE_ANCHOR_FID1_C0_SHIFT       18
+
+#define VPE_US1_R5                     0x0318
+#define VPE_US2_R5                     0x0418
+#define VPE_US3_R5                     0x0518
+#define VPE_ANCHOR_FID1_C3_MASK                0x3fff
+#define VPE_ANCHOR_FID1_C3_SHIFT       2
+#define VPE_ANCHOR_FID1_C2_MASK                0x3fff
+#define VPE_ANCHOR_FID1_C2_SHIFT       18
+
+#define VPE_US1_R6                     0x031c
+#define VPE_US2_R6                     0x041c
+#define VPE_US3_R6                     0x051c
+#define VPE_INTERP_FID1_C1_MASK                0x3fff
+#define VPE_INTERP_FID1_C1_SHIFT       2
+#define VPE_INTERP_FID1_C0_MASK                0x3fff
+#define VPE_INTERP_FID1_C0_SHIFT       18
+
+#define VPE_US1_R7                     0x0320
+#define VPE_US2_R7                     0x0420
+#define VPE_US3_R7                     0x0520
+#define VPE_INTERP_FID0_C3_MASK                0x3fff
+#define VPE_INTERP_FID0_C3_SHIFT       2
+#define VPE_INTERP_FID0_C2_MASK                0x3fff
+#define VPE_INTERP_FID0_C2_SHIFT       18
+
+/* VPE de-interlacer regs */
+#define VPE_DEI_FRAME_SIZE             0x0600
+#define VPE_DEI_WIDTH_MASK             0x07ff
+#define VPE_DEI_WIDTH_SHIFT            0
+#define VPE_DEI_HEIGHT_MASK            0x07ff
+#define VPE_DEI_HEIGHT_SHIFT           16
+#define VPE_DEI_INTERLACE_BYPASS       (1 << 29)
+#define VPE_DEI_FIELD_FLUSH            (1 << 30)
+#define VPE_DEI_PROGRESSIVE            (1 << 31)
+
+#define VPE_MDT_BYPASS                 0x0604
+#define VPE_MDT_TEMPMAX_BYPASS         (1 << 0)
+#define VPE_MDT_SPATMAX_BYPASS         (1 << 1)
+
+#define VPE_MDT_SF_THRESHOLD           0x0608
+#define VPE_MDT_SF_SC_THR1_MASK                0xff
+#define VPE_MDT_SF_SC_THR1_SHIFT       0
+#define VPE_MDT_SF_SC_THR2_MASK                0xff
+#define VPE_MDT_SF_SC_THR2_SHIFT       0
+#define VPE_MDT_SF_SC_THR3_MASK                0xff
+#define VPE_MDT_SF_SC_THR3_SHIFT       0
+
+#define VPE_EDI_CONFIG                 0x060c
+#define VPE_EDI_INP_MODE_MASK          0x03
+#define VPE_EDI_INP_MODE_SHIFT         0
+#define VPE_EDI_ENABLE_3D              (1 << 2)
+#define VPE_EDI_ENABLE_CHROMA_3D       (1 << 3)
+#define VPE_EDI_CHROMA3D_COR_THR_MASK  0xff
+#define VPE_EDI_CHROMA3D_COR_THR_SHIFT 8
+#define VPE_EDI_DIR_COR_LOWER_THR_MASK 0xff
+#define VPE_EDI_DIR_COR_LOWER_THR_SHIFT        16
+#define VPE_EDI_COR_SCALE_FACTOR_MASK  0xff
+#define VPE_EDI_COR_SCALE_FACTOR_SHIFT 23
+
+#define VPE_DEI_EDI_LUT_R0             0x0610
+#define VPE_EDI_LUT0_MASK              0x1f
+#define VPE_EDI_LUT0_SHIFT             0
+#define VPE_EDI_LUT1_MASK              0x1f
+#define VPE_EDI_LUT1_SHIFT             8
+#define VPE_EDI_LUT2_MASK              0x1f
+#define VPE_EDI_LUT2_SHIFT             16
+#define VPE_EDI_LUT3_MASK              0x1f
+#define VPE_EDI_LUT3_SHIFT             24
+
+#define VPE_DEI_EDI_LUT_R1             0x0614
+#define VPE_EDI_LUT0_MASK              0x1f
+#define VPE_EDI_LUT0_SHIFT             0
+#define VPE_EDI_LUT1_MASK              0x1f
+#define VPE_EDI_LUT1_SHIFT             8
+#define VPE_EDI_LUT2_MASK              0x1f
+#define VPE_EDI_LUT2_SHIFT             16
+#define VPE_EDI_LUT3_MASK              0x1f
+#define VPE_EDI_LUT3_SHIFT             24
+
+#define VPE_DEI_EDI_LUT_R2             0x0618
+#define VPE_EDI_LUT4_MASK              0x1f
+#define VPE_EDI_LUT4_SHIFT             0
+#define VPE_EDI_LUT5_MASK              0x1f
+#define VPE_EDI_LUT5_SHIFT             8
+#define VPE_EDI_LUT6_MASK              0x1f
+#define VPE_EDI_LUT6_SHIFT             16
+#define VPE_EDI_LUT7_MASK              0x1f
+#define VPE_EDI_LUT7_SHIFT             24
+
+#define VPE_DEI_EDI_LUT_R3             0x061c
+#define VPE_EDI_LUT8_MASK              0x1f
+#define VPE_EDI_LUT8_SHIFT             0
+#define VPE_EDI_LUT9_MASK              0x1f
+#define VPE_EDI_LUT9_SHIFT             8
+#define VPE_EDI_LUT10_MASK             0x1f
+#define VPE_EDI_LUT10_SHIFT            16
+#define VPE_EDI_LUT11_MASK             0x1f
+#define VPE_EDI_LUT11_SHIFT            24
+
+#define VPE_DEI_FMD_WINDOW_R0          0x0620
+#define VPE_FMD_WINDOW_MINX_MASK       0x07ff
+#define VPE_FMD_WINDOW_MINX_SHIFT      0
+#define VPE_FMD_WINDOW_MAXX_MASK       0x07ff
+#define VPE_FMD_WINDOW_MAXX_SHIFT      16
+#define VPE_FMD_WINDOW_ENABLE          (1 << 31)
+
+#define VPE_DEI_FMD_WINDOW_R1          0x0624
+#define VPE_FMD_WINDOW_MINY_MASK       0x07ff
+#define VPE_FMD_WINDOW_MINY_SHIFT      0
+#define VPE_FMD_WINDOW_MAXY_MASK       0x07ff
+#define VPE_FMD_WINDOW_MAXY_SHIFT      16
+
+#define VPE_DEI_FMD_CONTROL_R0         0x0628
+#define VPE_FMD_ENABLE                 (1 << 0)
+#define VPE_FMD_LOCK                   (1 << 1)
+#define VPE_FMD_JAM_DIR                        (1 << 2)
+#define VPE_FMD_BED_ENABLE             (1 << 3)
+#define VPE_FMD_CAF_FIELD_THR_MASK     0xff
+#define VPE_FMD_CAF_FIELD_THR_SHIFT    16
+#define VPE_FMD_CAF_LINE_THR_MASK      0xff
+#define VPE_FMD_CAF_LINE_THR_SHIFT     24
+
+#define VPE_DEI_FMD_CONTROL_R1         0x062c
+#define VPE_FMD_CAF_THR_MASK           0x000fffff
+#define VPE_FMD_CAF_THR_SHIFT          0
+
+#define VPE_DEI_FMD_STATUS_R0          0x0630
+#define VPE_FMD_CAF_MASK               0x000fffff
+#define VPE_FMD_CAF_SHIFT              0
+#define VPE_FMD_RESET                  (1 << 24)
+
+#define VPE_DEI_FMD_STATUS_R1          0x0634
+#define VPE_FMD_FIELD_DIFF_MASK                0x0fffffff
+#define VPE_FMD_FIELD_DIFF_SHIFT       0
+
+#define VPE_DEI_FMD_STATUS_R2          0x0638
+#define VPE_FMD_FRAME_DIFF_MASK                0x000fffff
+#define VPE_FMD_FRAME_DIFF_SHIFT       0
+
+/* VPE scaler regs */
+#define VPE_SC_MP_SC0                  0x0700
+#define VPE_INTERLACE_O                        (1 << 0)
+#define VPE_LINEAR                     (1 << 1)
+#define VPE_SC_BYPASS                  (1 << 2)
+#define VPE_INVT_FID                   (1 << 3)
+#define VPE_USE_RAV                    (1 << 4)
+#define VPE_ENABLE_EV                  (1 << 5)
+#define VPE_AUTO_HS                    (1 << 6)
+#define VPE_DCM_2X                     (1 << 7)
+#define VPE_DCM_4X                     (1 << 8)
+#define VPE_HP_BYPASS                  (1 << 9)
+#define VPE_INTERLACE_I                        (1 << 10)
+#define VPE_ENABLE_SIN2_VER_INTP       (1 << 11)
+#define VPE_Y_PK_EN                    (1 << 14)
+#define VPE_TRIM                       (1 << 15)
+#define VPE_SELFGEN_FID                        (1 << 16)
+
+#define VPE_SC_MP_SC1                  0x0704
+#define VPE_ROW_ACC_INC_MASK           0x07ffffff
+#define VPE_ROW_ACC_INC_SHIFT          0
+
+#define VPE_SC_MP_SC2                  0x0708
+#define VPE_ROW_ACC_OFFSET_MASK                0x0fffffff
+#define VPE_ROW_ACC_OFFSET_SHIFT       0
+
+#define VPE_SC_MP_SC3                  0x070c
+#define VPE_ROW_ACC_OFFSET_B_MASK      0x0fffffff
+#define VPE_ROW_ACC_OFFSET_B_SHIFT     0
+
+#define VPE_SC_MP_SC4                  0x0710
+#define VPE_TAR_H_MASK                 0x07ff
+#define VPE_TAR_H_SHIFT                        0
+#define VPE_TAR_W_MASK                 0x07ff
+#define VPE_TAR_W_SHIFT                        12
+#define VPE_LIN_ACC_INC_U_MASK         0x07
+#define VPE_LIN_ACC_INC_U_SHIFT                24
+#define VPE_NLIN_ACC_INIT_U_MASK       0x07
+#define VPE_NLIN_ACC_INIT_U_SHIFT      28
+
+#define VPE_SC_MP_SC5                  0x0714
+#define VPE_SRC_H_MASK                 0x07ff
+#define VPE_SRC_H_SHIFT                        0
+#define VPE_SRC_W_MASK                 0x07ff
+#define VPE_SRC_W_SHIFT                        12
+#define VPE_NLIN_ACC_INC_U_MASK                0x07
+#define VPE_NLIN_ACC_INC_U_SHIFT       24
+
+#define VPE_SC_MP_SC6                  0x0718
+#define VPE_ROW_ACC_INIT_RAV_MASK      0x03ff
+#define VPE_ROW_ACC_INIT_RAV_SHIFT     0
+#define VPE_ROW_ACC_INIT_RAV_B_MASK    0x03ff
+#define VPE_ROW_ACC_INIT_RAV_B_SHIFT   10
+
+#define VPE_SC_MP_SC8                  0x0720
+#define VPE_NLIN_LEFT_MASK             0x07ff
+#define VPE_NLIN_LEFT_SHIFT            0
+#define VPE_NLIN_RIGHT_MASK            0x07ff
+#define VPE_NLIN_RIGHT_SHIFT           12
+
+#define VPE_SC_MP_SC9                  0x0724
+#define VPE_LIN_ACC_INC                        VPE_SC_MP_SC9
+
+#define VPE_SC_MP_SC10                 0x0728
+#define VPE_NLIN_ACC_INIT              VPE_SC_MP_SC10
+
+#define VPE_SC_MP_SC11                 0x072c
+#define VPE_NLIN_ACC_INC               VPE_SC_MP_SC11
+
+#define VPE_SC_MP_SC12                 0x0730
+#define VPE_COL_ACC_OFFSET_MASK                0x01ffffff
+#define VPE_COL_ACC_OFFSET_SHIFT       0
+
+#define VPE_SC_MP_SC13                 0x0734
+#define VPE_SC_FACTOR_RAV_MASK         0x03ff
+#define VPE_SC_FACTOR_RAV_SHIFT                0
+#define VPE_CHROMA_INTP_THR_MASK       0x03ff
+#define VPE_CHROMA_INTP_THR_SHIFT      12
+#define VPE_DELTA_CHROMA_THR_MASK      0x0f
+#define VPE_DELTA_CHROMA_THR_SHIFT     24
+
+#define VPE_SC_MP_SC17                 0x0744
+#define VPE_EV_THR_MASK                        0x03ff
+#define VPE_EV_THR_SHIFT               12
+#define VPE_DELTA_LUMA_THR_MASK                0x0f
+#define VPE_DELTA_LUMA_THR_SHIFT       24
+#define VPE_DELTA_EV_THR_MASK          0x0f
+#define VPE_DELTA_EV_THR_SHIFT         28
+
+#define VPE_SC_MP_SC18                 0x0748
+#define VPE_HS_FACTOR_MASK             0x03ff
+#define VPE_HS_FACTOR_SHIFT            0
+#define VPE_CONF_DEFAULT_MASK          0x01ff
+#define VPE_CONF_DEFAULT_SHIFT         16
+
+#define VPE_SC_MP_SC19                 0x074c
+#define VPE_HPF_COEFF0_MASK            0xff
+#define VPE_HPF_COEFF0_SHIFT           0
+#define VPE_HPF_COEFF1_MASK            0xff
+#define VPE_HPF_COEFF1_SHIFT           8
+#define VPE_HPF_COEFF2_MASK            0xff
+#define VPE_HPF_COEFF2_SHIFT           16
+#define VPE_HPF_COEFF3_MASK            0xff
+#define VPE_HPF_COEFF3_SHIFT           23
+
+#define VPE_SC_MP_SC20                 0x0750
+#define VPE_HPF_COEFF4_MASK            0xff
+#define VPE_HPF_COEFF4_SHIFT           0
+#define VPE_HPF_COEFF5_MASK            0xff
+#define VPE_HPF_COEFF5_SHIFT           8
+#define VPE_HPF_NORM_SHIFT_MASK                0x07
+#define VPE_HPF_NORM_SHIFT_SHIFT       16
+#define VPE_NL_LIMIT_MASK              0x1ff
+#define VPE_NL_LIMIT_SHIFT             20
+
+#define VPE_SC_MP_SC21                 0x0754
+#define VPE_NL_LO_THR_MASK             0x01ff
+#define VPE_NL_LO_THR_SHIFT            0
+#define VPE_NL_LO_SLOPE_MASK           0xff
+#define VPE_NL_LO_SLOPE_SHIFT          16
+
+#define VPE_SC_MP_SC22                 0x0758
+#define VPE_NL_HI_THR_MASK             0x01ff
+#define VPE_NL_HI_THR_SHIFT            0
+#define VPE_NL_HI_SLOPE_SH_MASK                0x07
+#define VPE_NL_HI_SLOPE_SH_SHIFT       16
+
+#define VPE_SC_MP_SC23                 0x075c
+#define VPE_GRADIENT_THR_MASK          0x07ff
+#define VPE_GRADIENT_THR_SHIFT         0
+#define VPE_GRADIENT_THR_RANGE_MASK    0x0f
+#define VPE_GRADIENT_THR_RANGE_SHIFT   12
+#define VPE_MIN_GY_THR_MASK            0xff
+#define VPE_MIN_GY_THR_SHIFT           16
+#define VPE_MIN_GY_THR_RANGE_MASK      0x0f
+#define VPE_MIN_GY_THR_RANGE_SHIFT     28
+
+#define VPE_SC_MP_SC24                 0x0760
+#define VPE_ORG_H_MASK                 0x07ff
+#define VPE_ORG_H_SHIFT                        0
+#define VPE_ORG_W_MASK                 0x07ff
+#define VPE_ORG_W_SHIFT                        16
+
+#define VPE_SC_MP_SC25                 0x0764
+#define VPE_OFF_H_MASK                 0x07ff
+#define VPE_OFF_H_SHIFT                        0
+#define VPE_OFF_W_MASK                 0x07ff
+#define VPE_OFF_W_SHIFT                        16
+
+/* VPE color space converter regs */
+#define VPE_CSC_CSC00                  0x5700
+#define VPE_CSC_A0_MASK                        0x1fff
+#define VPE_CSC_A0_SHIFT               0
+#define VPE_CSC_B0_MASK                        0x1fff
+#define VPE_CSC_B0_SHIFT               16
+
+#define VPE_CSC_CSC01                  0x5704
+#define VPE_CSC_C0_MASK                        0x1fff
+#define VPE_CSC_C0_SHIFT               0
+#define VPE_CSC_A1_MASK                        0x1fff
+#define VPE_CSC_A1_SHIFT               16
+
+#define VPE_CSC_CSC02                  0x5708
+#define VPE_CSC_B1_MASK                        0x1fff
+#define VPE_CSC_B1_SHIFT               0
+#define VPE_CSC_C1_MASK                        0x1fff
+#define VPE_CSC_C1_SHIFT               16
+
+#define VPE_CSC_CSC03                  0x570c
+#define VPE_CSC_A2_MASK                        0x1fff
+#define VPE_CSC_A2_SHIFT               0
+#define VPE_CSC_B2_MASK                        0x1fff
+#define VPE_CSC_B2_SHIFT               16
+
+#define VPE_CSC_CSC04                  0x5710
+#define VPE_CSC_C2_MASK                        0x1fff
+#define VPE_CSC_C2_SHIFT               0
+#define VPE_CSC_D0_MASK                        0x0fff
+#define VPE_CSC_D0_SHIFT               16
+
+#define VPE_CSC_CSC05                  0x5714
+#define VPE_CSC_D1_MASK                        0x0fff
+#define VPE_CSC_D1_SHIFT               0
+#define VPE_CSC_D2_MASK                        0x0fff
+#define VPE_CSC_D2_SHIFT               16
+#define VPE_CSC_BYPASS                 (1 << 28)
+
+#endif
index b557caf5b1a4791846361ebf8ac382c429025f18..ccdadd623a3aae3ffabd49be553709d5a9511ec6 100644 (file)
@@ -403,7 +403,7 @@ static int timblogiw_s_input(struct file *file, void  *priv, unsigned int input)
        return 0;
 }
 
-static int timblogiw_streamon(struct file *file, void  *priv, unsigned int type)
+static int timblogiw_streamon(struct file *file, void  *priv, enum v4l2_buf_type type)
 {
        struct video_device *vdev = video_devdata(file);
        struct timblogiw_fh *fh = priv;
@@ -420,7 +420,7 @@ static int timblogiw_streamon(struct file *file, void  *priv, unsigned int type)
 }
 
 static int timblogiw_streamoff(struct file *file, void  *priv,
-       unsigned int type)
+       enum v4l2_buf_type type)
 {
        struct video_device *vdev = video_devdata(file);
        struct timblogiw_fh *fh = priv;
@@ -565,7 +565,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 
        desc = dmaengine_prep_slave_sg(fh->chan,
                buf->sg, sg_elems, DMA_DEV_TO_MEM,
-               DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP);
+               DMA_PREP_INTERRUPT);
        if (!desc) {
                spin_lock_irq(&fh->queue_lock);
                list_del_init(&vb->queue);
index 21db23b196bed15eb46af3d1214fe5774a74062e..fa3964022b96d939a3c222b90d81bd5bb2822255 100644 (file)
@@ -123,7 +123,7 @@ static int keene_cmd_set(struct keene_device *radio)
        /* If bit 0 is set, then transmit mono, otherwise stereo.
           If bit 2 is set, then enable 75 us preemphasis, otherwise
           it is 50 us. */
-       radio->buffer[3] = (!radio->stereo) | (radio->preemph_75_us ? 4 : 0);
+       radio->buffer[3] = (radio->stereo ? 0 : 1) | (radio->preemph_75_us ? 4 : 0);
        radio->buffer[4] = 0x00;
        radio->buffer[5] = 0x00;
        radio->buffer[6] = 0x00;
index f1e3714b5f16cdf017a4868ab5eb31ecb5899515..93d864eb830627898c82d3d33416466819ee5c76 100644 (file)
@@ -74,8 +74,8 @@ static u8 fmr2_tea575x_get_pins(struct snd_tea575x *tea)
        struct fmr2 *fmr2 = tea->private_data;
        u8 bits = inb(fmr2->io);
 
-       return  (bits & STR_DATA) ? TEA575X_DATA : 0 |
-               (bits & STR_MOST) ? TEA575X_MOST : 0;
+       return  ((bits & STR_DATA) ? TEA575X_DATA : 0) |
+               ((bits & STR_MOST) ? TEA575X_MOST : 0);
 }
 
 static void fmr2_tea575x_set_direction(struct snd_tea575x *tea, bool output)
@@ -295,7 +295,6 @@ static void fmr2_remove(struct fmr2 *fmr2)
 static int fmr2_isa_remove(struct device *pdev, unsigned int ndev)
 {
        fmr2_remove(dev_get_drvdata(pdev));
-       dev_set_drvdata(pdev, NULL);
 
        return 0;
 }
index b91477212413ac0f46e78165cbb7b5f60b64af8e..3db8a8cfe1a87f4eb80e9c22950bbcac93b7daed 100644 (file)
@@ -271,6 +271,7 @@ static void shark_unregister_leds(struct shark_device *shark)
        cancel_work_sync(&shark->led_work);
 }
 
+#ifdef CONFIG_PM
 static void shark_resume_leds(struct shark_device *shark)
 {
        if (test_bit(BLUE_IS_PULSE, &shark->brightness_new))
@@ -280,6 +281,7 @@ static void shark_resume_leds(struct shark_device *shark)
        set_bit(RED_LED, &shark->brightness_new);
        schedule_work(&shark->led_work);
 }
+#endif
 #else
 static int shark_register_leds(struct shark_device *shark, struct device *dev)
 {
index 9fb669721e66d8a3ee48850c1f77f8ad34074873..d86d90dab8bf880666a05ca0463aa83fc62f77de 100644 (file)
@@ -237,6 +237,7 @@ static void shark_unregister_leds(struct shark_device *shark)
        cancel_work_sync(&shark->led_work);
 }
 
+#ifdef CONFIG_PM
 static void shark_resume_leds(struct shark_device *shark)
 {
        int i;
@@ -246,6 +247,7 @@ static void shark_resume_leds(struct shark_device *shark)
 
        schedule_work(&shark->led_work);
 }
+#endif
 #else
 static int shark_register_leds(struct shark_device *shark, struct device *dev)
 {
index 0bd250068285baabbe701929395d61b0f8d3bcc3..0e750aef656a6f8a053aafbd965b4e9e1fe64f23 100644 (file)
@@ -254,7 +254,7 @@ static unsigned int si470x_get_step(struct si470x_device *radio)
        /* 2:  50 kHz */
        default:
                return 50 * 16;
-       };
+       }
 }
 
 
index e5fc9acd0c4f5debdc03cb4645ac2cd3f2a23c6b..2a497c80c77f2e1c2996403c356992a771c5df82 100644 (file)
@@ -463,7 +463,7 @@ static int si470x_i2c_remove(struct i2c_client *client)
 }
 
 
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 /*
  * si470x_i2c_suspend - suspend the device
  */
@@ -509,7 +509,7 @@ static struct i2c_driver si470x_i2c_driver = {
        .driver = {
                .name           = "si470x",
                .owner          = THIS_MODULE,
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
                .pm             = &si470x_i2c_pm,
 #endif
        },
index fe160882ee1061760edc95dd79a5c09455837bc3..9ec48ccbcf0b2acab93f4eddd6eb31ed4998de34 100644 (file)
@@ -1456,7 +1456,7 @@ static int si4713_probe(struct i2c_client *client,
 
        if (client->irq) {
                rval = request_irq(client->irq,
-                       si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED,
+                       si4713_handler, IRQF_TRIGGER_FALLING,
                        client->name, sdev);
                if (rval < 0) {
                        v4l2_err(&sdev->sd, "Could not request IRQ\n");
index 06ac69245ca1cde81ddeb5018fae23f84d84e397..69e3245a58a0cbfcc1d333d390a30aa45e4c70d8 100644 (file)
 #define WM_SUB_TEST            0xF
 
 /* Different modes of the MSA register */
-#define MODE_BUFFER            0x0
-#define MODE_PRESET            0x1
-#define MODE_SEARCH            0x2
-#define MODE_AF_UPDATE         0x3
-#define MODE_JUMP              0x4
-#define MODE_CHECK             0x5
-#define MODE_LOAD              0x6
-#define MODE_END               0x7
-#define MODE_SHIFT             5
+#define MSA_MODE_BUFFER                0x0
+#define MSA_MODE_PRESET                0x1
+#define MSA_MODE_SEARCH                0x2
+#define MSA_MODE_AF_UPDATE     0x3
+#define MSA_MODE_JUMP          0x4
+#define MSA_MODE_CHECK         0x5
+#define MSA_MODE_LOAD          0x6
+#define MSA_MODE_END           0x7
+#define MSA_MODE_SHIFT         5
 
 struct tef6862_state {
        struct v4l2_subdev sd;
@@ -114,7 +114,7 @@ static int tef6862_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequen
 
        clamp(freq, TEF6862_LO_FREQ, TEF6862_HI_FREQ);
        pll = 1964 + ((freq - TEF6862_LO_FREQ) * 20) / FREQ_MUL;
-       i2cmsg[0] = (MODE_PRESET << MODE_SHIFT) | WM_SUB_PLLM;
+       i2cmsg[0] = (MSA_MODE_PRESET << MSA_MODE_SHIFT) | WM_SUB_PLLM;
        i2cmsg[1] = (pll >> 8) & 0xff;
        i2cmsg[2] = pll & 0xff;
 
index 253f307f0b379bc5d57271e630343c0e0b35c8c5..4b2e9e8298e1f6e962a468eeb1fba4b91b5c68bd 100644 (file)
@@ -175,7 +175,7 @@ static int_handler_prototype int_handler_table[] = {
        fm_irq_handle_intmsk_cmd_resp
 };
 
-long (*g_st_write) (struct sk_buff *skb);
+static long (*g_st_write) (struct sk_buff *skb);
 static struct completion wait_for_fmdrv_reg_comp;
 
 static inline void fm_irq_call(struct fmdev *fmdev)
index 11e84bcc23a169be3db8f8a3168a458bee0a31d0..904f11367c2992fc502c4632c5d4a8617cbde839 100644 (file)
@@ -322,4 +322,14 @@ config IR_GPIO_CIR
           To compile this driver as a module, choose M here: the module will
           be called gpio-ir-recv.
 
+config RC_ST
+       tristate "ST remote control receiver"
+       depends on ARCH_STI && RC_CORE
+       help
+        Say Y here if you want support for ST remote control driver
+        which allows both IR and UHF RX.
+        The driver passes raw pulse and space information to the LIRC decoder.
+
+        If you're not sure, select N here.
+
 endif #RC_DEVICES
index 56bacf07b3618f37db4cbe5ea39735ec9d6065b6..f4eb32c0a455e04058bdf52fb2158d1dbe7ac479 100644 (file)
@@ -30,3 +30,4 @@ obj-$(CONFIG_RC_LOOPBACK) += rc-loopback.o
 obj-$(CONFIG_IR_GPIO_CIR) += gpio-ir-recv.o
 obj-$(CONFIG_IR_IGUANA) += iguanair.o
 obj-$(CONFIG_IR_TTUSBIR) += ttusbir.o
+obj-$(CONFIG_RC_ST) += st_rc.o
index 82516a1d39b0777d7e591ef89f850b1cce1f1310..b698f3d2ced938582a80aa9c8075add338921fb9 100644 (file)
@@ -76,8 +76,8 @@ struct fintek_dev {
        } tx;
 
        /* Config register index/data port pair */
-       u8 cr_ip;
-       u8 cr_dp;
+       u32 cr_ip;
+       u32 cr_dp;
 
        /* hardware I/O settings */
        unsigned long cir_addr;
index 07aacfa5903dca6430bda96cbedd733b23d5a300..80c611c2e8c28fabd83b0383d19670cf1cbe0faf 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/interrupt.h>
 #include <linux/gpio.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 #include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/irq.h>
index b53626ba6f4954bf1bbe4e7caf954f2f597247d6..fdae05c4f3775d7f54050c8776f0b882ac2fe630 100644 (file)
@@ -308,22 +308,12 @@ static int iguanair_set_tx_carrier(struct rc_dev *dev, uint32_t carrier)
                cycles = DIV_ROUND_CLOSEST(24000000, carrier * 2) -
                                                        ir->cycle_overhead;
 
-               /*  make up the the remainer of 4-cycle blocks */
-               switch (cycles & 3) {
-               case 0:
-                       sevens = 0;
-                       break;
-               case 1:
-                       sevens = 3;
-                       break;
-               case 2:
-                       sevens = 2;
-                       break;
-               case 3:
-                       sevens = 1;
-                       break;
-               }
-
+               /*
+                * Calculate minimum number of 7 cycles needed so
+                * we are left with a multiple of 4; so we want to have
+                * (sevens * 7) & 3 == cycles & 3
+                */
+               sevens = (4 - cycles) & 3;
                fours = (cycles - sevens * 7) / 4;
 
                /* magic happens here */
index 31b955bf7664497ff967ab08e55271d99ca70eba..b1e19a26208d88627ab95743717e1fd6a039dc54 100644 (file)
@@ -201,8 +201,7 @@ static int lirc_rx51_init_port(struct lirc_rx51 *lirc_rx51)
 
        lirc_rx51->irq_num = omap_dm_timer_get_irq(lirc_rx51->pulse_timer);
        retval = request_irq(lirc_rx51->irq_num, lirc_rx51_interrupt_handler,
-                            IRQF_DISABLED | IRQF_SHARED,
-                            "lirc_pulse_timer", lirc_rx51);
+                            IRQF_SHARED, "lirc_pulse_timer", lirc_rx51);
        if (retval) {
                dev_err(lirc_rx51->dev, ": Failed to request interrupt line\n");
                goto err2;
index 4d13a7f2e5c3bcb64f65dff524d233f85af0d506..492a05ade7e190b3d3c874f7b2942b3138a796cd 100644 (file)
@@ -5,7 +5,7 @@
  * TODO: This table is a real mess, as it merges RC codes from several
  * devices into a big table. It also has both RC-5 and NEC codes inside.
  * It should be broken into small tables, and the protocols should properly
- * be indentificated.
+ * be identificated.
  *
  * The table were imported from dib0700_devices.c.
  *
index ba81d9697cfcaa3b653ee6748df368ec5b6a094e..454ea596a7eef89fdabbcf1dccfef4dfbd0f9ce8 100644 (file)
@@ -5,7 +5,7 @@
  * TODO: This table is a real mess, as it merges RC codes from several
  * devices into a big table. It also has both RC-5 and NEC codes inside.
  * It should be broken into small tables, and the protocols should properly
- * be indentificated.
+ * be identificated.
  *
  * The table were imported from dib0700_devices.c.
  *
index 7c3674ff5ea2a06073820bb1b19d2b7ec0097ef9..07e83108df0f6834681887c1902c6742212324ed 100644 (file)
@@ -84,8 +84,8 @@ struct nvt_dev {
        } tx;
 
        /* EFER Config register index/data pair */
-       u8 cr_efir;
-       u8 cr_efdr;
+       u32 cr_efir;
+       u32 cr_efdr;
 
        /* hardware I/O settings */
        unsigned long cir_addr;
diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c
new file mode 100644 (file)
index 0000000..65120c2
--- /dev/null
@@ -0,0 +1,395 @@
+/*
+ * Copyright (C) 2013 STMicroelectronics Limited
+ * Author: Srinivas Kandagatla <srinivas.kandagatla@st.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <media/rc-core.h>
+#include <linux/pinctrl/consumer.h>
+
+struct st_rc_device {
+       struct device                   *dev;
+       int                             irq;
+       int                             irq_wake;
+       struct clk                      *sys_clock;
+       void                            *base;  /* Register base address */
+       void                            *rx_base;/* RX Register base address */
+       struct rc_dev                   *rdev;
+       bool                            overclocking;
+       int                             sample_mult;
+       int                             sample_div;
+       bool                            rxuhfmode;
+};
+
+/* Registers */
+#define IRB_SAMPLE_RATE_COMM   0x64    /* sample freq divisor*/
+#define IRB_CLOCK_SEL          0x70    /* clock select       */
+#define IRB_CLOCK_SEL_STATUS   0x74    /* clock status       */
+/* IRB IR/UHF receiver registers */
+#define IRB_RX_ON               0x40   /* pulse time capture */
+#define IRB_RX_SYS              0X44   /* sym period capture */
+#define IRB_RX_INT_EN           0x48   /* IRQ enable (R/W)   */
+#define IRB_RX_INT_STATUS       0x4c   /* IRQ status (R/W)   */
+#define IRB_RX_EN               0x50   /* Receive enable     */
+#define IRB_MAX_SYM_PERIOD      0x54   /* max sym value      */
+#define IRB_RX_INT_CLEAR        0x58   /* overrun status     */
+#define IRB_RX_STATUS           0x6c   /* receive status     */
+#define IRB_RX_NOISE_SUPPR      0x5c   /* noise suppression  */
+#define IRB_RX_POLARITY_INV     0x68   /* polarity inverter  */
+
+/**
+ * IRQ set: Enable full FIFO                 1  -> bit  3;
+ *          Enable overrun IRQ               1  -> bit  2;
+ *          Enable last symbol IRQ           1  -> bit  1:
+ *          Enable RX interrupt              1  -> bit  0;
+ */
+#define IRB_RX_INTS            0x0f
+#define IRB_RX_OVERRUN_INT     0x04
+ /* maximum symbol period (microsecs),timeout to detect end of symbol train */
+#define MAX_SYMB_TIME          0x5000
+#define IRB_SAMPLE_FREQ                10000000
+#define        IRB_FIFO_NOT_EMPTY      0xff00
+#define IRB_OVERFLOW           0x4
+#define IRB_TIMEOUT            0xffff
+#define IR_ST_NAME "st-rc"
+
+static void st_rc_send_lirc_timeout(struct rc_dev *rdev)
+{
+       DEFINE_IR_RAW_EVENT(ev);
+       ev.timeout = true;
+       ir_raw_event_store(rdev, &ev);
+}
+
+/**
+ * RX graphical example to better understand the difference between ST IR block
+ * output and standard definition used by LIRC (and most of the world!)
+ *
+ *           mark                                     mark
+ *      |-IRB_RX_ON-|                            |-IRB_RX_ON-|
+ *      ___  ___  ___                            ___  ___  ___             _
+ *      | |  | |  | |                            | |  | |  | |             |
+ *      | |  | |  | |         space 0            | |  | |  | |   space 1   |
+ * _____| |__| |__| |____________________________| |__| |__| |_____________|
+ *
+ *      |--------------- IRB_RX_SYS -------------|------ IRB_RX_SYS -------|
+ *
+ *      |------------- encoding bit 0 -----------|---- encoding bit 1 -----|
+ *
+ * ST hardware returns mark (IRB_RX_ON) and total symbol time (IRB_RX_SYS), so
+ * convert to standard mark/space we have to calculate space=(IRB_RX_SYS-mark)
+ * The mark time represents the amount of time the carrier (usually 36-40kHz)
+ * is detected.The above examples shows Pulse Width Modulation encoding where
+ * bit 0 is represented by space>mark.
+ */
+
+static irqreturn_t st_rc_rx_interrupt(int irq, void *data)
+{
+       unsigned int symbol, mark = 0;
+       struct st_rc_device *dev = data;
+       int last_symbol = 0;
+       u32 status;
+       DEFINE_IR_RAW_EVENT(ev);
+
+       if (dev->irq_wake)
+               pm_wakeup_event(dev->dev, 0);
+
+       status  = readl(dev->rx_base + IRB_RX_STATUS);
+
+       while (status & (IRB_FIFO_NOT_EMPTY | IRB_OVERFLOW)) {
+               u32 int_status = readl(dev->rx_base + IRB_RX_INT_STATUS);
+               if (unlikely(int_status & IRB_RX_OVERRUN_INT)) {
+                       /* discard the entire collection in case of errors!  */
+                       ir_raw_event_reset(dev->rdev);
+                       dev_info(dev->dev, "IR RX overrun\n");
+                       writel(IRB_RX_OVERRUN_INT,
+                                       dev->rx_base + IRB_RX_INT_CLEAR);
+                       continue;
+               }
+
+               symbol = readl(dev->rx_base + IRB_RX_SYS);
+               mark = readl(dev->rx_base + IRB_RX_ON);
+
+               if (symbol == IRB_TIMEOUT)
+                       last_symbol = 1;
+
+                /* Ignore any noise */
+               if ((mark > 2) && (symbol > 1)) {
+                       symbol -= mark;
+                       if (dev->overclocking) { /* adjustments to timings */
+                               symbol *= dev->sample_mult;
+                               symbol /= dev->sample_div;
+                               mark *= dev->sample_mult;
+                               mark /= dev->sample_div;
+                       }
+
+                       ev.duration = US_TO_NS(mark);
+                       ev.pulse = true;
+                       ir_raw_event_store(dev->rdev, &ev);
+
+                       if (!last_symbol) {
+                               ev.duration = US_TO_NS(symbol);
+                               ev.pulse = false;
+                               ir_raw_event_store(dev->rdev, &ev);
+                       } else  {
+                               st_rc_send_lirc_timeout(dev->rdev);
+                       }
+
+               }
+               last_symbol = 0;
+               status  = readl(dev->rx_base + IRB_RX_STATUS);
+       }
+
+       writel(IRB_RX_INTS, dev->rx_base + IRB_RX_INT_CLEAR);
+
+       /* Empty software fifo */
+       ir_raw_event_handle(dev->rdev);
+       return IRQ_HANDLED;
+}
+
+static void st_rc_hardware_init(struct st_rc_device *dev)
+{
+       int baseclock, freqdiff;
+       unsigned int rx_max_symbol_per = MAX_SYMB_TIME;
+       unsigned int rx_sampling_freq_div;
+
+       clk_prepare_enable(dev->sys_clock);
+       baseclock = clk_get_rate(dev->sys_clock);
+
+       /* IRB input pins are inverted internally from high to low. */
+       writel(1, dev->rx_base + IRB_RX_POLARITY_INV);
+
+       rx_sampling_freq_div = baseclock / IRB_SAMPLE_FREQ;
+       writel(rx_sampling_freq_div, dev->base + IRB_SAMPLE_RATE_COMM);
+
+       freqdiff = baseclock - (rx_sampling_freq_div * IRB_SAMPLE_FREQ);
+       if (freqdiff) { /* over clocking, workout the adjustment factors */
+               dev->overclocking = true;
+               dev->sample_mult = 1000;
+               dev->sample_div = baseclock / (10000 * rx_sampling_freq_div);
+               rx_max_symbol_per = (rx_max_symbol_per * 1000)/dev->sample_div;
+       }
+
+       writel(rx_max_symbol_per, dev->rx_base + IRB_MAX_SYM_PERIOD);
+}
+
+static int st_rc_remove(struct platform_device *pdev)
+{
+       struct st_rc_device *rc_dev = platform_get_drvdata(pdev);
+       clk_disable_unprepare(rc_dev->sys_clock);
+       rc_unregister_device(rc_dev->rdev);
+       return 0;
+}
+
+static int st_rc_open(struct rc_dev *rdev)
+{
+       struct st_rc_device *dev = rdev->priv;
+       unsigned long flags;
+       local_irq_save(flags);
+       /* enable interrupts and receiver */
+       writel(IRB_RX_INTS, dev->rx_base + IRB_RX_INT_EN);
+       writel(0x01, dev->rx_base + IRB_RX_EN);
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+static void st_rc_close(struct rc_dev *rdev)
+{
+       struct st_rc_device *dev = rdev->priv;
+       /* disable interrupts and receiver */
+       writel(0x00, dev->rx_base + IRB_RX_EN);
+       writel(0x00, dev->rx_base + IRB_RX_INT_EN);
+}
+
+static int st_rc_probe(struct platform_device *pdev)
+{
+       int ret = -EINVAL;
+       struct rc_dev *rdev;
+       struct device *dev = &pdev->dev;
+       struct resource *res;
+       struct st_rc_device *rc_dev;
+       struct device_node *np = pdev->dev.of_node;
+       const char *rx_mode;
+
+       rc_dev = devm_kzalloc(dev, sizeof(struct st_rc_device), GFP_KERNEL);
+
+       if (!rc_dev)
+               return -ENOMEM;
+
+       rdev = rc_allocate_device();
+
+       if (!rdev)
+               return -ENOMEM;
+
+       if (np && !of_property_read_string(np, "rx-mode", &rx_mode)) {
+
+               if (!strcmp(rx_mode, "uhf")) {
+                       rc_dev->rxuhfmode = true;
+               } else if (!strcmp(rx_mode, "infrared")) {
+                       rc_dev->rxuhfmode = false;
+               } else {
+                       dev_err(dev, "Unsupported rx mode [%s]\n", rx_mode);
+                       goto err;
+               }
+
+       } else {
+               goto err;
+       }
+
+       rc_dev->sys_clock = devm_clk_get(dev, NULL);
+       if (IS_ERR(rc_dev->sys_clock)) {
+               dev_err(dev, "System clock not found\n");
+               ret = PTR_ERR(rc_dev->sys_clock);
+               goto err;
+       }
+
+       rc_dev->irq = platform_get_irq(pdev, 0);
+       if (rc_dev->irq < 0) {
+               ret = rc_dev->irq;
+               goto err;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+       rc_dev->base = devm_ioremap_resource(dev, res);
+       if (IS_ERR(rc_dev->base)) {
+               ret = PTR_ERR(rc_dev->base);
+               goto err;
+       }
+
+       if (rc_dev->rxuhfmode)
+               rc_dev->rx_base = rc_dev->base + 0x40;
+       else
+               rc_dev->rx_base = rc_dev->base;
+
+       rc_dev->dev = dev;
+       platform_set_drvdata(pdev, rc_dev);
+       st_rc_hardware_init(rc_dev);
+
+       rdev->driver_type = RC_DRIVER_IR_RAW;
+       rdev->allowed_protos = RC_BIT_ALL;
+       /* rx sampling rate is 10Mhz */
+       rdev->rx_resolution = 100;
+       rdev->timeout = US_TO_NS(MAX_SYMB_TIME);
+       rdev->priv = rc_dev;
+       rdev->open = st_rc_open;
+       rdev->close = st_rc_close;
+       rdev->driver_name = IR_ST_NAME;
+       rdev->map_name = RC_MAP_LIRC;
+       rdev->input_name = "ST Remote Control Receiver";
+
+       /* enable wake via this device */
+       device_set_wakeup_capable(dev, true);
+       device_set_wakeup_enable(dev, true);
+
+       ret = rc_register_device(rdev);
+       if (ret < 0)
+               goto clkerr;
+
+       rc_dev->rdev = rdev;
+       if (devm_request_irq(dev, rc_dev->irq, st_rc_rx_interrupt,
+                       IRQF_NO_SUSPEND, IR_ST_NAME, rc_dev) < 0) {
+               dev_err(dev, "IRQ %d register failed\n", rc_dev->irq);
+               ret = -EINVAL;
+               goto rcerr;
+       }
+
+       /**
+        * for LIRC_MODE_MODE2 or LIRC_MODE_PULSE or LIRC_MODE_RAW
+        * lircd expects a long space first before a signal train to sync.
+        */
+       st_rc_send_lirc_timeout(rdev);
+
+       dev_info(dev, "setup in %s mode\n", rc_dev->rxuhfmode ? "UHF" : "IR");
+
+       return ret;
+rcerr:
+       rc_unregister_device(rdev);
+       rdev = NULL;
+clkerr:
+       clk_disable_unprepare(rc_dev->sys_clock);
+err:
+       rc_free_device(rdev);
+       dev_err(dev, "Unable to register device (%d)\n", ret);
+       return ret;
+}
+
+#ifdef CONFIG_PM
+static int st_rc_suspend(struct device *dev)
+{
+       struct st_rc_device *rc_dev = dev_get_drvdata(dev);
+
+       if (device_may_wakeup(dev)) {
+               if (!enable_irq_wake(rc_dev->irq))
+                       rc_dev->irq_wake = 1;
+               else
+                       return -EINVAL;
+       } else {
+               pinctrl_pm_select_sleep_state(dev);
+               writel(0x00, rc_dev->rx_base + IRB_RX_EN);
+               writel(0x00, rc_dev->rx_base + IRB_RX_INT_EN);
+               clk_disable_unprepare(rc_dev->sys_clock);
+       }
+
+       return 0;
+}
+
+static int st_rc_resume(struct device *dev)
+{
+       struct st_rc_device *rc_dev = dev_get_drvdata(dev);
+       struct rc_dev   *rdev = rc_dev->rdev;
+
+       if (rc_dev->irq_wake) {
+               disable_irq_wake(rc_dev->irq);
+               rc_dev->irq_wake = 0;
+       } else {
+               pinctrl_pm_select_default_state(dev);
+               st_rc_hardware_init(rc_dev);
+               if (rdev->users) {
+                       writel(IRB_RX_INTS, rc_dev->rx_base + IRB_RX_INT_EN);
+                       writel(0x01, rc_dev->rx_base + IRB_RX_EN);
+               }
+       }
+
+       return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(st_rc_pm_ops, st_rc_suspend, st_rc_resume);
+#endif
+
+#ifdef CONFIG_OF
+static struct of_device_id st_rc_match[] = {
+       { .compatible = "st,comms-irb", },
+       {},
+};
+
+MODULE_DEVICE_TABLE(of, st_rc_match);
+#endif
+
+static struct platform_driver st_rc_driver = {
+       .driver = {
+               .name = IR_ST_NAME,
+               .owner  = THIS_MODULE,
+               .of_match_table = of_match_ptr(st_rc_match),
+#ifdef CONFIG_PM
+               .pm     = &st_rc_pm_ops,
+#endif
+       },
+       .probe = st_rc_probe,
+       .remove = st_rc_remove,
+};
+
+module_platform_driver(st_rc_driver);
+
+MODULE_DESCRIPTION("RC Transceiver driver for STMicroelectronics platforms");
+MODULE_AUTHOR("STMicroelectronics (R&D) Ltd");
+MODULE_LICENSE("GPL");
index 98bd4960c75ec1729ce1930c90e8e20d2db44bef..904baf4eec28ac902731d90bb78ae6f73632c4cc 100644 (file)
@@ -1110,7 +1110,7 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
        }
 
        err = request_irq(data->irq, wbcir_irq_handler,
-                         IRQF_DISABLED, DRVNAME, device);
+                         0, DRVNAME, device);
        if (err) {
                dev_err(dev, "Failed to claim IRQ %u\n", data->irq);
                err = -EBUSY;
index 6c96e4898777f29f5c9ae4457d488e9424b32f2b..72971a8d3c37978ef1c42b6a2523bb4cb8e92f4a 100644 (file)
 #include "e4000_priv.h"
 #include <linux/math64.h>
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /* write multiple registers */
 static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
 {
        int ret;
-       u8 buf[1 + len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg->i2c_addr,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = 1 + len,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
@@ -54,7 +64,7 @@ static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
 static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
 {
        int ret;
-       u8 buf[len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[2] = {
                {
                        .addr = priv->cfg->i2c_addr,
@@ -64,11 +74,18 @@ static int e4000_rd_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
                }, {
                        .addr = priv->cfg->i2c_addr,
                        .flags = I2C_M_RD,
-                       .len = sizeof(buf),
+                       .len = len,
                        .buf = buf,
                }
        };
 
+       if (len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c rd reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        ret = i2c_transfer(priv->i2c, msg, 2);
        if (ret == 2) {
                memcpy(val, buf, len);
index f4d0e797a6cc456229a75e74edb99a9e814f1526..d74e920568104dad4070ad120f4ca1953939d83d 100644 (file)
@@ -139,7 +139,7 @@ static int fc0012_set_params(struct dvb_frontend *fe)
        unsigned char reg[7], am, pm, multi, tmp;
        unsigned long f_vco;
        unsigned short xtal_freq_khz_2, xin, xdiv;
-       int vco_select = false;
+       bool vco_select = false;
 
        if (fe->callback) {
                ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
index bd8f0f1e8f3b5432d7b98939993d3ac8e0a859a6..b4162315773d90d314e7476aeccfe2d3a396c140 100644 (file)
@@ -233,7 +233,7 @@ static int fc0013_set_params(struct dvb_frontend *fe)
        unsigned char reg[7], am, pm, multi, tmp;
        unsigned long f_vco;
        unsigned short xtal_freq_khz_2, xin, xdiv;
-       int vco_select = false;
+       bool vco_select = false;
 
        if (fe->callback) {
                ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER,
index 81f38aae9c66f6ba2893eb1ff5ea7f6c092be96d..3aecaf4650942429eba75ee89cc33180aac4ae07 100644 (file)
@@ -20,6 +20,9 @@
 
 #include "fc2580_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /*
  * TODO:
  * I2C write and read works only for one single register. Multiple registers
 static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
 {
        int ret;
-       u8 buf[1 + len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg->i2c_addr,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = 1 + len,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
@@ -69,7 +79,7 @@ static int fc2580_wr_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
 static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
 {
        int ret;
-       u8 buf[len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[2] = {
                {
                        .addr = priv->cfg->i2c_addr,
@@ -79,11 +89,18 @@ static int fc2580_rd_regs(struct fc2580_priv *priv, u8 reg, u8 *val, int len)
                }, {
                        .addr = priv->cfg->i2c_addr,
                        .flags = I2C_M_RD,
-                       .len = sizeof(buf),
+                       .len = len,
                        .buf = buf,
                }
        };
 
+       if (len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c rd reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        ret = i2c_transfer(priv->i2c, msg, 2);
        if (ret == 2) {
                memcpy(val, buf, len);
index 1c23666468cf69223542b5f89f024a1201c4733d..d9ee43fae62dee4f7f5cf474d4f74ed21e4c5a01 100644 (file)
@@ -612,10 +612,19 @@ static int r820t_set_pll(struct r820t_priv *priv, enum v4l2_tuner_type type,
 
        vco_fine_tune = (data[4] & 0x30) >> 4;
 
-       if (vco_fine_tune > VCO_POWER_REF)
-               div_num = div_num - 1;
-       else if (vco_fine_tune < VCO_POWER_REF)
-               div_num = div_num + 1;
+       tuner_dbg("mix_div=%d div_num=%d vco_fine_tune=%d\n",
+                       mix_div, div_num, vco_fine_tune);
+
+       /*
+        * XXX: R828D/16MHz seems to have always vco_fine_tune=1.
+        * Due to that, this calculation goes wrong.
+        */
+       if (priv->cfg->rafael_chip != CHIP_R828D) {
+               if (vco_fine_tune > VCO_POWER_REF)
+                       div_num = div_num - 1;
+               else if (vco_fine_tune < VCO_POWER_REF)
+                       div_num = div_num + 1;
+       }
 
        rc = r820t_write_reg_mask(priv, 0x10, div_num << 5, 0xe0);
        if (rc < 0)
@@ -637,11 +646,6 @@ static int r820t_set_pll(struct r820t_priv *priv, enum v4l2_tuner_type type,
                vco_fra = pll_ref * 129 / 128;
        }
 
-       if (nint > 63) {
-               tuner_info("No valid PLL values for %u kHz!\n", freq);
-               return -EINVAL;
-       }
-
        ni = (nint - 13) / 4;
        si = nint - 4 * ni - 13;
 
index e4a84ee231cf458a4e5b84292f2e83115e023caf..abe256e1f84324d36041fc67af9ca4587f113cb2 100644 (file)
@@ -20,6 +20,9 @@
 
 #include "tda18212.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 struct tda18212_priv {
        struct tda18212_config *cfg;
        struct i2c_adapter *i2c;
@@ -32,16 +35,23 @@ static int tda18212_wr_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
        int len)
 {
        int ret;
-       u8 buf[len+1];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg->i2c_address,
                        .flags = 0,
-                       .len = sizeof(buf),
+                       .len = 1 + len,
                        .buf = buf,
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        buf[0] = reg;
        memcpy(&buf[1], val, len);
 
@@ -61,7 +71,7 @@ static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
        int len)
 {
        int ret;
-       u8 buf[len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[2] = {
                {
                        .addr = priv->cfg->i2c_address,
@@ -71,11 +81,18 @@ static int tda18212_rd_regs(struct tda18212_priv *priv, u8 reg, u8 *val,
                }, {
                        .addr = priv->cfg->i2c_address,
                        .flags = I2C_M_RD,
-                       .len = sizeof(buf),
+                       .len = len,
                        .buf = buf,
                }
        };
 
+       if (len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c rd reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        ret = i2c_transfer(priv->i2c, msg, 2);
        if (ret == 2) {
                memcpy(val, buf, len);
index 2d31aeb6b088997fbed7678f631a47f175500d55..9300e9361e3bce840aa8f517b18a1c5cafd32628 100644 (file)
 
 #include "tda18218_priv.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /* write multiple registers */
 static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
 {
        int ret = 0, len2, remaining;
-       u8 buf[1 + len];
+       u8 buf[MAX_XFER_SIZE];
        struct i2c_msg msg[1] = {
                {
                        .addr = priv->cfg->i2c_address,
@@ -33,6 +36,13 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
                }
        };
 
+       if (1 + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        for (remaining = len; remaining > 0;
                        remaining -= (priv->cfg->i2c_wr_max - 1)) {
                len2 = remaining;
@@ -63,7 +73,7 @@ static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
 static int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
 {
        int ret;
-       u8 buf[reg+len]; /* we must start read always from reg 0x00 */
+       u8 buf[MAX_XFER_SIZE]; /* we must start read always from reg 0x00 */
        struct i2c_msg msg[2] = {
                {
                        .addr = priv->cfg->i2c_address,
@@ -73,11 +83,18 @@ static int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
                }, {
                        .addr = priv->cfg->i2c_address,
                        .flags = I2C_M_RD,
-                       .len = sizeof(buf),
+                       .len = reg + len,
                        .buf = buf,
                }
        };
 
+       if (reg + len > sizeof(buf)) {
+               dev_warn(&priv->i2c->dev,
+                        "%s: i2c wr reg=%04x: len=%d is too big!\n",
+                        KBUILD_MODNAME, reg, len);
+               return -EINVAL;
+       }
+
        ret = i2c_transfer(priv->i2c, msg, 2);
        if (ret == 2) {
                memcpy(val, &buf[reg], len);
index 300005c535ba076ba0e90bf0e7e58b1f25f223ab..9823248d743f8de71da853cca6c3dd215da7bb1e 100644 (file)
@@ -536,8 +536,8 @@ static int tda9887_status(struct dvb_frontend *fe)
        unsigned char buf[1];
        int rc;
 
-       memset(buf,0,sizeof(buf));
-       if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1)))
+       rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, 1);
+       if (rc != 1)
                tuner_info("i2c i/o error: rc == %d (should be 1)\n", rc);
        dump_read_message(fe, buf);
        return 0;
index 878d2c4d9e8ef545d7f76bbda04f5d96ecf7fdbd..4be5cf808a40584d949e89fa78e7a90c086a31f5 100644 (file)
@@ -24,6 +24,9 @@
 #include <linux/dvb/frontend.h>
 #include "dvb_frontend.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  80
+
 /* Registers (Write-only) */
 #define XREG_INIT         0x00
 #define XREG_RF_FREQ      0x02
@@ -547,7 +550,10 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
 {
        struct xc2028_data *priv = fe->tuner_priv;
        int                pos, rc;
-       unsigned char      *p, *endp, buf[priv->ctrl.max_len];
+       unsigned char      *p, *endp, buf[MAX_XFER_SIZE];
+
+       if (priv->ctrl.max_len > sizeof(buf))
+               priv->ctrl.max_len = sizeof(buf);
 
        tuner_dbg("%s called\n", __func__);
 
@@ -572,7 +578,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
                        return -EINVAL;
                }
 
-               size = le16_to_cpu(*(__u16 *) p);
+               size = le16_to_cpu(*(__le16 *) p);
                p += sizeof(size);
 
                if (size == 0xffff)
@@ -683,7 +689,7 @@ static int load_scode(struct dvb_frontend *fe, unsigned int type,
                /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
                 * has a 2-byte size header in the firmware format. */
                if (priv->firm[pos].size != 14 * 16 || scode >= 16 ||
-                   le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12)
+                   le16_to_cpu(*(__le16 *)(p + 14 * scode)) != 12)
                        return -EINVAL;
                p += 14 * scode + 2;
        }
index 8b6275f859088d703fcc2893412dfe5c4ccd58b8..0bd96906339227ec8b3df4e78640fc500be4fb87 100644 (file)
@@ -390,7 +390,7 @@ static void flexcop_usb_transfer_exit(struct flexcop_usb *fc_usb)
                }
 
        if (fc_usb->iso_buffer != NULL)
-               pci_free_consistent(NULL,
+               usb_free_coherent(fc_usb->udev,
                        fc_usb->buffer_size, fc_usb->iso_buffer,
                        fc_usb->dma_addr);
 }
@@ -407,8 +407,8 @@ static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb)
                        "each of %d bytes size = %d.\n", B2C2_USB_NUM_ISO_URB,
                        B2C2_USB_FRAMES_PER_ISO, frame_size, bufsize);
 
-       fc_usb->iso_buffer = pci_alloc_consistent(NULL,
-                       bufsize, &fc_usb->dma_addr);
+       fc_usb->iso_buffer = usb_alloc_coherent(fc_usb->udev,
+                       bufsize, GFP_KERNEL, &fc_usb->dma_addr);
        if (fc_usb->iso_buffer == NULL)
                return -ENOMEM;
 
index be17192836099c4e1759e2e7a9d41cf7e9cf3a33..351a78a84c3d618346167563c15d77a204fffeae 100644 (file)
@@ -209,7 +209,7 @@ static void cpia2_usb_complete(struct urb *urb)
 {
        int i;
        unsigned char *cdata;
-       static int frame_ready = false;
+       static bool frame_ready = false;
        struct camera_data *cam = (struct camera_data *) urb->context;
 
        if (urb->status!=0) {
index a384f80f595eb7805d0a112b547bd18b983c0bfd..e9d017bea377069da087751404e75f86b081c7cd 100644 (file)
@@ -978,7 +978,6 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
                            int minor)
 {
        int retval = -ENOMEM;
-       int errCode;
        unsigned int maxh, maxw;
 
        dev->udev = udev;
@@ -1014,8 +1013,8 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
        /* Cx231xx pre card setup */
        cx231xx_pre_card_setup(dev);
 
-       errCode = cx231xx_config(dev);
-       if (errCode) {
+       retval = cx231xx_config(dev);
+       if (retval) {
                cx231xx_errdev("error configuring device\n");
                return -ENOMEM;
        }
@@ -1024,12 +1023,11 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
        dev->norm = dev->board.norm;
 
        /* register i2c bus */
-       errCode = cx231xx_dev_init(dev);
-       if (errCode < 0) {
-               cx231xx_dev_uninit(dev);
+       retval = cx231xx_dev_init(dev);
+       if (retval) {
                cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n",
-                              __func__, errCode);
-               return errCode;
+                              __func__, retval);
+               goto err_dev_init;
        }
 
        /* Do board specific init */
@@ -1047,11 +1045,11 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
        dev->interlaced = 0;
        dev->video_input = 0;
 
-       errCode = cx231xx_config(dev);
-       if (errCode < 0) {
+       retval = cx231xx_config(dev);
+       if (retval) {
                cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n",
-                              __func__, errCode);
-               return errCode;
+                              __func__, retval);
+               goto err_dev_init;
        }
 
        /* init video dma queues */
@@ -1075,9 +1073,9 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
        }
 
        retval = cx231xx_register_analog_devices(dev);
-       if (retval < 0) {
-               cx231xx_release_resources(dev);
-               return retval;
+       if (retval) {
+               cx231xx_release_analog_resources(dev);
+               goto err_analog;
        }
 
        cx231xx_ir_init(dev);
@@ -1085,6 +1083,11 @@ static int cx231xx_init_dev(struct cx231xx *dev, struct usb_device *udev,
        cx231xx_init_extension(dev);
 
        return 0;
+err_analog:
+       cx231xx_remove_from_devlist(dev);
+err_dev_init:
+       cx231xx_dev_uninit(dev);
+       return retval;
 }
 
 #if defined(CONFIG_MODULES) && defined(MODULE)
@@ -1132,7 +1135,6 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        char *speed;
        struct usb_interface_assoc_descriptor *assoc_desc;
 
-       udev = usb_get_dev(interface_to_usbdev(interface));
        ifnum = interface->altsetting[0].desc.bInterfaceNumber;
 
        /*
@@ -1161,6 +1163,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                return -ENOMEM;
        }
 
+       udev = usb_get_dev(interface_to_usbdev(interface));
+
        snprintf(dev->name, 29, "cx231xx #%d", nr);
        dev->devno = nr;
        dev->model = id->driver_info;
@@ -1223,10 +1227,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        if (assoc_desc->bFirstInterface != ifnum) {
                cx231xx_err(DRIVER_NAME ": Not found "
                            "matching IAD interface\n");
-               clear_bit(dev->devno, &cx231xx_devused);
-               kfree(dev);
-               dev = NULL;
-               return -ENODEV;
+               retval = -ENODEV;
+               goto err_if;
        }
 
        cx231xx_info("registering interface %d\n", ifnum);
@@ -1242,22 +1244,13 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
        if (retval) {
                cx231xx_errdev("v4l2_device_register failed\n");
-               clear_bit(dev->devno, &cx231xx_devused);
-               kfree(dev);
-               dev = NULL;
-               return -EIO;
+               retval = -EIO;
+               goto err_v4l2;
        }
        /* allocate device struct */
        retval = cx231xx_init_dev(dev, udev, nr);
-       if (retval) {
-               clear_bit(dev->devno, &cx231xx_devused);
-               v4l2_device_unregister(&dev->v4l2_dev);
-               kfree(dev);
-               dev = NULL;
-               usb_set_intfdata(interface, NULL);
-
-               return retval;
-       }
+       if (retval)
+               goto err_init;
 
        /* compute alternate max packet sizes for video */
        uif = udev->actconfig->interface[dev->current_pcb_config.
@@ -1275,11 +1268,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 
        if (dev->video_mode.alt_max_pkt_size == NULL) {
                cx231xx_errdev("out of memory!\n");
-               clear_bit(dev->devno, &cx231xx_devused);
-               v4l2_device_unregister(&dev->v4l2_dev);
-               kfree(dev);
-               dev = NULL;
-               return -ENOMEM;
+               retval = -ENOMEM;
+               goto err_video_alt;
        }
 
        for (i = 0; i < dev->video_mode.num_alt; i++) {
@@ -1309,11 +1299,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 
        if (dev->vbi_mode.alt_max_pkt_size == NULL) {
                cx231xx_errdev("out of memory!\n");
-               clear_bit(dev->devno, &cx231xx_devused);
-               v4l2_device_unregister(&dev->v4l2_dev);
-               kfree(dev);
-               dev = NULL;
-               return -ENOMEM;
+               retval = -ENOMEM;
+               goto err_vbi_alt;
        }
 
        for (i = 0; i < dev->vbi_mode.num_alt; i++) {
@@ -1344,11 +1331,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 
        if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) {
                cx231xx_errdev("out of memory!\n");
-               clear_bit(dev->devno, &cx231xx_devused);
-               v4l2_device_unregister(&dev->v4l2_dev);
-               kfree(dev);
-               dev = NULL;
-               return -ENOMEM;
+               retval = -ENOMEM;
+               goto err_sliced_cc_alt;
        }
 
        for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
@@ -1380,11 +1364,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
 
                if (dev->ts1_mode.alt_max_pkt_size == NULL) {
                        cx231xx_errdev("out of memory!\n");
-                       clear_bit(dev->devno, &cx231xx_devused);
-                       v4l2_device_unregister(&dev->v4l2_dev);
-                       kfree(dev);
-                       dev = NULL;
-                       return -ENOMEM;
+                       retval = -ENOMEM;
+                       goto err_ts1_alt;
                }
 
                for (i = 0; i < dev->ts1_mode.num_alt; i++) {
@@ -1411,6 +1392,29 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        request_modules(dev);
 
        return 0;
+err_ts1_alt:
+       kfree(dev->sliced_cc_mode.alt_max_pkt_size);
+err_sliced_cc_alt:
+       kfree(dev->vbi_mode.alt_max_pkt_size);
+err_vbi_alt:
+       kfree(dev->video_mode.alt_max_pkt_size);
+err_video_alt:
+       /* cx231xx_uninit_dev: */
+       cx231xx_close_extension(dev);
+       cx231xx_ir_exit(dev);
+       cx231xx_release_analog_resources(dev);
+       cx231xx_417_unregister(dev);
+       cx231xx_remove_from_devlist(dev);
+       cx231xx_dev_uninit(dev);
+err_init:
+       v4l2_device_unregister(&dev->v4l2_dev);
+err_v4l2:
+       usb_set_intfdata(interface, NULL);
+err_if:
+       usb_put_dev(udev);
+       kfree(dev);
+       clear_bit(dev->devno, &cx231xx_devused);
+       return retval;
 }
 
 /*
index d7308ab7a90feba03c8164bb17c5bb56ba2f42bd..2a34ceee48020b886ba2d1ebd832dd2e3ee4ef6a 100644 (file)
@@ -28,7 +28,7 @@ MODULE_PARM_DESC(pcb_debug, "enable pcb config debug messages [video]");
 
 /******************************************************************************/
 
-struct pcb_config cx231xx_Scenario[] = {
+static struct pcb_config cx231xx_Scenario[] = {
        {
         INDEX_SELFPOWER_DIGITAL_ONLY,  /* index */
         USB_SELF_POWER,        /* power_type */
@@ -672,7 +672,7 @@ u32 initialize_cx231xx(struct cx231xx *dev)
        pcb config it is related to */
        cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT, data, 4);
 
-       config_info = le32_to_cpu(*((u32 *) data));
+       config_info = le32_to_cpu(*((__le32 *)data));
        usb_speed = (u8) (config_info & 0x1);
 
        /* Verify this device belongs to Bus power or Self power device */
index d556042cf312c280ede9bc1851efc1effda5c042..da47d2392f2a204f0832608821a743baa2627f19 100644 (file)
@@ -397,12 +397,13 @@ error:
        return ret;
 }
 
+#define AF9015_EEPROM_SIZE 256
+
 /* hash (and dump) eeprom */
 static int af9015_eeprom_hash(struct dvb_usb_device *d)
 {
        struct af9015_state *state = d_to_priv(d);
        int ret, i;
-       static const unsigned int AF9015_EEPROM_SIZE = 256;
        u8 buf[AF9015_EEPROM_SIZE];
        struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL};
 
index 1ea17dc2a76ed51b6560ae642c6f31301f4a57fe..c8fcd78425bd228ca4374daf94fdbf4ed1c0c17a 100644 (file)
@@ -21,6 +21,9 @@
 
 #include "af9035.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 static u16 af9035_checksum(const u8 *buf, size_t len)
@@ -126,10 +129,16 @@ exit:
 /* write multiple registers */
 static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len)
 {
-       u8 wbuf[6 + len];
+       u8 wbuf[MAX_XFER_SIZE];
        u8 mbox = (reg >> 16) & 0xff;
        struct usb_req req = { CMD_MEM_WR, mbox, sizeof(wbuf), wbuf, 0, NULL };
 
+       if (6 + len > sizeof(wbuf)) {
+               dev_warn(&d->udev->dev, "%s: i2c wr: len=%d is too big!\n",
+                        KBUILD_MODNAME, len);
+               return -EOPNOTSUPP;
+       }
+
        wbuf[0] = len;
        wbuf[1] = 2;
        wbuf[2] = 0;
@@ -228,9 +237,16 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
                                        msg[1].len);
                } else {
                        /* I2C */
-                       u8 buf[5 + msg[0].len];
+                       u8 buf[MAX_XFER_SIZE];
                        struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
                                        buf, msg[1].len, msg[1].buf };
+
+                       if (5 + msg[0].len > sizeof(buf)) {
+                               dev_warn(&d->udev->dev,
+                                        "%s: i2c xfer: len=%d is too big!\n",
+                                        KBUILD_MODNAME, msg[0].len);
+                               return -EOPNOTSUPP;
+                       }
                        req.mbox |= ((msg[0].addr & 0x80)  >>  3);
                        buf[0] = msg[1].len;
                        buf[1] = msg[0].addr << 1;
@@ -257,9 +273,16 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
                                        msg[0].len - 3);
                } else {
                        /* I2C */
-                       u8 buf[5 + msg[0].len];
+                       u8 buf[MAX_XFER_SIZE];
                        struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf,
                                        0, NULL };
+
+                       if (5 + msg[0].len > sizeof(buf)) {
+                               dev_warn(&d->udev->dev,
+                                        "%s: i2c xfer: len=%d is too big!\n",
+                                        KBUILD_MODNAME, msg[0].len);
+                               return -EOPNOTSUPP;
+                       }
                        req.mbox |= ((msg[0].addr & 0x80)  >>  3);
                        buf[0] = msg[0].len;
                        buf[1] = msg[0].addr << 1;
index e97964ef7f56a847081dc99efb278579090e6d2c..2627553f7de1f90c262f2d234d1d1faa9288f45f 100644 (file)
@@ -23,6 +23,9 @@
 #include "lgdt3305.h"
 #include "lg2160.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 int dvb_usb_mxl111sf_debug;
 module_param_named(debug, dvb_usb_mxl111sf_debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level "
@@ -57,7 +60,12 @@ int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
 {
        int wo = (rbuf == NULL || rlen == 0); /* write-only */
        int ret;
-       u8 sndbuf[1+wlen];
+       u8 sndbuf[MAX_XFER_SIZE];
+
+       if (1 + wlen > sizeof(sndbuf)) {
+               pr_warn("%s: len=%d is too big!\n", __func__, wlen);
+               return -EOPNOTSUPP;
+       }
 
        pr_debug("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
 
index c0cd0848631b22953bd09723aa722decedef8687..ecca03667f9870d865f212bd0a59932aa9d7f00d 100644 (file)
@@ -377,6 +377,7 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
        struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
        struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
        struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
+       struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
 
        dev_dbg(&d->udev->dev, "%s:\n", __func__);
 
@@ -489,6 +490,15 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
                goto found;
        }
 
+       /* check R828D ID register; reg=00 val=69 */
+       ret = rtl28xxu_ctrl_msg(d, &req_r828d);
+       if (ret == 0 && buf[0] == 0x69) {
+               priv->tuner = TUNER_RTL2832_R828D;
+               priv->tuner_name = "R828D";
+               goto found;
+       }
+
+
 found:
        dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
 
@@ -745,6 +755,7 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
                rtl2832_config = &rtl28xxu_rtl2832_e4000_config;
                break;
        case TUNER_RTL2832_R820T:
+       case TUNER_RTL2832_R828D:
                rtl2832_config = &rtl28xxu_rtl2832_r820t_config;
                break;
        default:
@@ -866,6 +877,13 @@ static const struct r820t_config rtl2832u_r820t_config = {
        .rafael_chip = CHIP_R820T,
 };
 
+static const struct r820t_config rtl2832u_r828d_config = {
+       .i2c_addr = 0x3a,
+       .xtal = 16000000,
+       .max_i2c_msg_len = 2,
+       .rafael_chip = CHIP_R828D,
+};
+
 static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
 {
        int ret;
@@ -919,6 +937,27 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
                fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap,
                                &rtl2832u_r820t_config);
 
+               /* Use tuner to get the signal strength */
+               adap->fe[0]->ops.read_signal_strength =
+                               adap->fe[0]->ops.tuner_ops.get_rf_strength;
+               break;
+       case TUNER_RTL2832_R828D:
+               /* power off mn88472 demod on GPIO0 */
+               ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x01);
+               if (ret)
+                       goto err;
+
+               ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
+               if (ret)
+                       goto err;
+
+               ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
+               if (ret)
+                       goto err;
+
+               fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap,
+                               &rtl2832u_r828d_config);
+
                /* Use tuner to get the signal strength */
                adap->fe[0]->ops.read_signal_strength =
                                adap->fe[0]->ops.tuner_ops.get_rf_strength;
@@ -1388,6 +1427,9 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
                &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
        { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
                &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) },
+
+       { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
+               &rtl2832u_props, "Astrometa DVB-T2", NULL) },
        { }
 };
 MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
index 729b3540c2f9b4fe28ffb97f59daccd910e3ea6d..2142bcb41b414b42a45774babef70529c3658d97 100644 (file)
@@ -83,6 +83,7 @@ enum rtl28xxu_tuner {
        TUNER_RTL2832_TDA18272,
        TUNER_RTL2832_FC0013,
        TUNER_RTL2832_R820T,
+       TUNER_RTL2832_R828D,
 };
 
 struct rtl28xxu_req {
index ea2d5ee86576565930d0336605a6e20f6e0528b8..c11138ebf6fb964ee800613d768ef6639e15663a 100644 (file)
@@ -254,7 +254,7 @@ static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = {
 
 
 
-struct stb0899_config az6027_stb0899_config = {
+static struct stb0899_config az6027_stb0899_config = {
        .init_dev               = az6027_stb0899_s1_init_1,
        .init_s2_demod          = stb0899_s2_init_2,
        .init_s1_demod          = az6027_stb0899_s1_init_3,
@@ -291,7 +291,7 @@ struct stb0899_config az6027_stb0899_config = {
        .tuner_set_rfsiggain    = NULL,
 };
 
-struct stb6100_config az6027_stb6100_config = {
+static struct stb6100_config az6027_stb6100_config = {
        .tuner_address  = 0xc0,
        .refclock       = 27000000,
 };
index 3940bb0f9ef62dd8b3121d3ee0a7739669581d90..20e345d9fe8f3aca89a913f79f3ccb813b7d5ab4 100644 (file)
@@ -43,6 +43,9 @@
 #include "lgs8gxx.h"
 #include "atbm8830.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 /* debug */
 static int dvb_usb_cxusb_debug;
 module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
@@ -57,7 +60,14 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
                          u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
 {
        int wo = (rbuf == NULL || rlen == 0); /* write-only */
-       u8 sndbuf[1+wlen];
+       u8 sndbuf[MAX_XFER_SIZE];
+
+       if (1 + wlen > sizeof(sndbuf)) {
+               warn("i2c wr: len=%d is too big!\n",
+                    wlen);
+               return -EOPNOTSUPP;
+       }
+
        memset(sndbuf, 0, 1+wlen);
 
        sndbuf[0] = cmd;
@@ -158,7 +168,13 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 
                if (msg[i].flags & I2C_M_RD) {
                        /* read only */
-                       u8 obuf[3], ibuf[1+msg[i].len];
+                       u8 obuf[3], ibuf[MAX_XFER_SIZE];
+
+                       if (1 + msg[i].len > sizeof(ibuf)) {
+                               warn("i2c rd: len=%d is too big!\n",
+                                    msg[i].len);
+                               return -EOPNOTSUPP;
+                       }
                        obuf[0] = 0;
                        obuf[1] = msg[i].len;
                        obuf[2] = msg[i].addr;
@@ -172,7 +188,18 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
                           msg[i].addr == msg[i+1].addr) {
                        /* write to then read from same address */
-                       u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
+                       u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
+
+                       if (3 + msg[i].len > sizeof(obuf)) {
+                               warn("i2c wr: len=%d is too big!\n",
+                                    msg[i].len);
+                               return -EOPNOTSUPP;
+                       }
+                       if (1 + msg[i + 1].len > sizeof(ibuf)) {
+                               warn("i2c rd: len=%d is too big!\n",
+                                    msg[i + 1].len);
+                               return -EOPNOTSUPP;
+                       }
                        obuf[0] = msg[i].len;
                        obuf[1] = msg[i+1].len;
                        obuf[2] = msg[i].addr;
@@ -191,7 +218,13 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                        i++;
                } else {
                        /* write only */
-                       u8 obuf[2+msg[i].len], ibuf;
+                       u8 obuf[MAX_XFER_SIZE], ibuf;
+
+                       if (2 + msg[i].len > sizeof(obuf)) {
+                               warn("i2c wr: len=%d is too big!\n",
+                                    msg[i].len);
+                               return -EOPNOTSUPP;
+                       }
                        obuf[0] = msg[i].addr;
                        obuf[1] = msg[i].len;
                        memcpy(&obuf[2], msg[i].buf, msg[i].len);
index c2dded92f1d3799a331f3576b0df617afac6d4db..6d68af0c49c83ecab8d542eb0a3942902e70e7e8 100644 (file)
@@ -12,6 +12,9 @@
 #include <linux/kconfig.h>
 #include "dibusb.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 static int debug;
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level (1=info (|-able))." DVB_USB_DEBUG_STATUS);
@@ -105,11 +108,16 @@ EXPORT_SYMBOL(dibusb2_0_power_ctrl);
 static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
                          u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
 {
-       u8 sndbuf[wlen+4]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */
+       u8 sndbuf[MAX_XFER_SIZE]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */
        /* write only ? */
        int wo = (rbuf == NULL || rlen == 0),
                len = 2 + wlen + (wo ? 0 : 2);
 
+       if (4 + wlen > sizeof(sndbuf)) {
+               warn("i2c wr: len=%d is too big!\n", wlen);
+               return -EOPNOTSUPP;
+       }
+
        sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
        sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
 
index 6e237b6dd0a8d8acb5bba115152e5b060775e680..c1a63b2a6baa53725342b4ef0b6bc93234207275 100644 (file)
@@ -30,6 +30,9 @@
 #include "stb6100_proc.h"
 #include "m88rs2000.h"
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 #ifndef USB_PID_DW2102
 #define USB_PID_DW2102 0x2102
 #endif
@@ -308,7 +311,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
        case 2: {
                /* read */
                /* first write first register number */
-               u8 ibuf[msg[1].len + 2], obuf[3];
+               u8 ibuf[MAX_XFER_SIZE], obuf[3];
+
+               if (2 + msg[1].len > sizeof(ibuf)) {
+                       warn("i2c rd: len=%d is too big!\n",
+                            msg[1].len);
+                       return -EOPNOTSUPP;
+               }
+
                obuf[0] = msg[0].addr << 1;
                obuf[1] = msg[0].len;
                obuf[2] = msg[0].buf[0];
@@ -325,7 +335,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
                switch (msg[0].addr) {
                case 0x68: {
                        /* write to register */
-                       u8 obuf[msg[0].len + 2];
+                       u8 obuf[MAX_XFER_SIZE];
+
+                       if (2 + msg[0].len > sizeof(obuf)) {
+                               warn("i2c wr: len=%d is too big!\n",
+                                    msg[1].len);
+                               return -EOPNOTSUPP;
+                       }
+
                        obuf[0] = msg[0].addr << 1;
                        obuf[1] = msg[0].len;
                        memcpy(obuf + 2, msg[0].buf, msg[0].len);
@@ -335,7 +352,14 @@ static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg ms
                }
                case 0x61: {
                        /* write to tuner */
-                       u8 obuf[msg[0].len + 2];
+                       u8 obuf[MAX_XFER_SIZE];
+
+                       if (2 + msg[0].len > sizeof(obuf)) {
+                               warn("i2c wr: len=%d is too big!\n",
+                                    msg[1].len);
+                               return -EOPNOTSUPP;
+                       }
+
                        obuf[0] = msg[0].addr << 1;
                        obuf[1] = msg[0].len;
                        memcpy(obuf + 2, msg[0].buf, msg[0].len);
@@ -401,7 +425,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
                default: {
                        if (msg[j].flags == I2C_M_RD) {
                                /* read registers */
-                               u8  ibuf[msg[j].len + 2];
+                               u8  ibuf[MAX_XFER_SIZE];
+
+                               if (2 + msg[j].len > sizeof(ibuf)) {
+                                       warn("i2c rd: len=%d is too big!\n",
+                                            msg[j].len);
+                                       return -EOPNOTSUPP;
+                               }
+
                                dw210x_op_rw(d->udev, 0xc3,
                                                (msg[j].addr << 1) + 1, 0,
                                                ibuf, msg[j].len + 2,
@@ -430,7 +461,14 @@ static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], i
                                } while (len > 0);
                        } else {
                                /* write registers */
-                               u8 obuf[msg[j].len + 2];
+                               u8 obuf[MAX_XFER_SIZE];
+
+                               if (2 + msg[j].len > sizeof(obuf)) {
+                                       warn("i2c wr: len=%d is too big!\n",
+                                            msg[j].len);
+                                       return -EOPNOTSUPP;
+                               }
+
                                obuf[0] = msg[j].addr << 1;
                                obuf[1] = msg[j].len;
                                memcpy(obuf + 2, msg[j].buf, msg[j].len);
@@ -463,7 +501,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
        case 2: {
                /* read */
                /* first write first register number */
-               u8 ibuf[msg[1].len + 2], obuf[3];
+               u8 ibuf[MAX_XFER_SIZE], obuf[3];
+
+               if (2 + msg[1].len > sizeof(ibuf)) {
+                       warn("i2c rd: len=%d is too big!\n",
+                            msg[1].len);
+                       return -EOPNOTSUPP;
+               }
                obuf[0] = msg[0].addr << 1;
                obuf[1] = msg[0].len;
                obuf[2] = msg[0].buf[0];
@@ -481,7 +525,13 @@ static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                case 0x60:
                case 0x0c: {
                        /* write to register */
-                       u8 obuf[msg[0].len + 2];
+                       u8 obuf[MAX_XFER_SIZE];
+
+                       if (2 + msg[0].len > sizeof(obuf)) {
+                               warn("i2c wr: len=%d is too big!\n",
+                                    msg[0].len);
+                               return -EOPNOTSUPP;
+                       }
                        obuf[0] = msg[0].addr << 1;
                        obuf[1] = msg[0].len;
                        memcpy(obuf + 2, msg[0].buf, msg[0].len);
@@ -563,7 +613,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                default: {
                        if (msg[j].flags == I2C_M_RD) {
                                /* read registers */
-                               u8 ibuf[msg[j].len];
+                               u8 ibuf[MAX_XFER_SIZE];
+
+                               if (msg[j].len > sizeof(ibuf)) {
+                                       warn("i2c rd: len=%d is too big!\n",
+                                            msg[j].len);
+                                       return -EOPNOTSUPP;
+                               }
+
                                dw210x_op_rw(d->udev, 0x91, 0, 0,
                                                ibuf, msg[j].len,
                                                DW210X_READ_MSG);
@@ -590,7 +647,14 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                                } while (len > 0);
                        } else if (j < (num - 1)) {
                                /* write register addr before read */
-                               u8 obuf[msg[j].len + 2];
+                               u8 obuf[MAX_XFER_SIZE];
+
+                               if (2 + msg[j].len > sizeof(obuf)) {
+                                       warn("i2c wr: len=%d is too big!\n",
+                                            msg[j].len);
+                                       return -EOPNOTSUPP;
+                               }
+
                                obuf[0] = msg[j + 1].len;
                                obuf[1] = (msg[j].addr << 1);
                                memcpy(obuf + 2, msg[j].buf, msg[j].len);
@@ -602,7 +666,13 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                                break;
                        } else {
                                /* write registers */
-                               u8 obuf[msg[j].len + 2];
+                               u8 obuf[MAX_XFER_SIZE];
+
+                               if (2 + msg[j].len > sizeof(obuf)) {
+                                       warn("i2c wr: len=%d is too big!\n",
+                                            msg[j].len);
+                                       return -EOPNOTSUPP;
+                               }
                                obuf[0] = msg[j].len + 1;
                                obuf[1] = (msg[j].addr << 1);
                                memcpy(obuf + 2, msg[j].buf, msg[j].len);
@@ -955,9 +1025,10 @@ static struct ds3000_config dw2104_ds3000_config = {
        .demod_address = 0x68,
 };
 
-static struct ts2020_config dw2104_ts2020_config  = {
+static struct ts2020_config dw2104_ts2020_config = {
        .tuner_address = 0x60,
        .clk_out_div = 1,
+       .frequency_div = 1060000,
 };
 
 static struct ds3000_config s660_ds3000_config = {
@@ -966,6 +1037,12 @@ static struct ds3000_config s660_ds3000_config = {
        .set_lock_led = dw210x_led_ctrl,
 };
 
+static struct ts2020_config s660_ts2020_config = {
+       .tuner_address = 0x60,
+       .clk_out_div = 1,
+       .frequency_div = 1146000,
+};
+
 static struct stv0900_config dw2104a_stv0900_config = {
        .demod_address = 0x6a,
        .demod_mode = 0,
@@ -1205,7 +1282,7 @@ static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
        if (d->fe_adap[0].fe == NULL)
                return -EIO;
 
-       dvb_attach(ts2020_attach, d->fe_adap[0].fe, &dw2104_ts2020_config,
+       dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
                &d->dev->i2c_adap);
 
        st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
@@ -1213,7 +1290,7 @@ static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
 
        dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
 
-       info("Attached ds3000+ds2020!\n");
+       info("Attached ds3000+ts2020!\n");
 
        return 0;
 }
index 73cc50afa5e168fd4e63664f68258ae115c95f10..d666741797d4e690fbd6a62aa2141cd50ec1e507 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/i2c.h>
 #include <media/soc_camera.h>
 #include <media/mt9v011.h>
+#include <media/v4l2-clk.h>
 #include <media/v4l2-common.h>
 
 #include "em28xx.h"
@@ -47,6 +48,7 @@ static struct soc_camera_link camlink = {
        .bus_id = 0,
        .flags = 0,
        .module_name = "em28xx",
+       .unbalanced_power = true,
 };
 
 
@@ -325,13 +327,24 @@ int em28xx_detect_sensor(struct em28xx *dev)
 
 int em28xx_init_camera(struct em28xx *dev)
 {
+       char clk_name[V4L2_SUBDEV_NAME_SIZE];
+       struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
+       struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus];
+       int ret = 0;
+
+       v4l2_clk_name_i2c(clk_name, sizeof(clk_name),
+                         i2c_adapter_id(adap), client->addr);
+       dev->clk = v4l2_clk_register_fixed(clk_name, "mclk", -EINVAL);
+       if (IS_ERR(dev->clk))
+               return PTR_ERR(dev->clk);
+
        switch (dev->em28xx_sensor) {
        case EM28XX_MT9V011:
        {
                struct mt9v011_platform_data pdata;
                struct i2c_board_info mt9v011_info = {
                        .type = "mt9v011",
-                       .addr = dev->i2c_client[dev->def_i2c_bus].addr,
+                       .addr = client->addr,
                        .platform_data = &pdata,
                };
 
@@ -352,10 +365,11 @@ int em28xx_init_camera(struct em28xx *dev)
                dev->sensor_xtal = 4300000;
                pdata.xtal = dev->sensor_xtal;
                if (NULL ==
-                   v4l2_i2c_new_subdev_board(&dev->v4l2_dev,
-                                             &dev->i2c_adap[dev->def_i2c_bus],
-                                             &mt9v011_info, NULL))
-                       return -ENODEV;
+                   v4l2_i2c_new_subdev_board(&dev->v4l2_dev, adap,
+                                             &mt9v011_info, NULL)) {
+                       ret = -ENODEV;
+                       break;
+               }
                /* probably means GRGB 16 bit bayer */
                dev->vinmode = 0x0d;
                dev->vinctl = 0x00;
@@ -391,7 +405,7 @@ int em28xx_init_camera(struct em28xx *dev)
                struct i2c_board_info ov2640_info = {
                        .type = "ov2640",
                        .flags = I2C_CLIENT_SCCB,
-                       .addr = dev->i2c_client[dev->def_i2c_bus].addr,
+                       .addr = client->addr,
                        .platform_data = &camlink,
                };
                struct v4l2_mbus_framefmt fmt;
@@ -408,9 +422,12 @@ int em28xx_init_camera(struct em28xx *dev)
                dev->sensor_yres = 480;
 
                subdev =
-                    v4l2_i2c_new_subdev_board(&dev->v4l2_dev,
-                                              &dev->i2c_adap[dev->def_i2c_bus],
+                    v4l2_i2c_new_subdev_board(&dev->v4l2_dev, adap,
                                               &ov2640_info, NULL);
+               if (NULL == subdev) {
+                       ret = -ENODEV;
+                       break;
+               }
 
                fmt.code = V4L2_MBUS_FMT_YUYV8_2X8;
                fmt.width = 640;
@@ -427,8 +444,13 @@ int em28xx_init_camera(struct em28xx *dev)
        }
        case EM28XX_NOSENSOR:
        default:
-               return -EINVAL;
+               ret = -EINVAL;
        }
 
-       return 0;
+       if (ret < 0) {
+               v4l2_clk_unregister_fixed(dev->clk);
+               dev->clk = NULL;
+       }
+
+       return ret;
 }
index dc65742c4bbcabfddf54f8fdd9797d6bdf162a6f..a5196697627f3be4098d849111731b352f989e0f 100644 (file)
@@ -36,6 +36,7 @@
 #include <media/tvaudio.h>
 #include <media/i2c-addr.h>
 #include <media/tveeprom.h>
+#include <media/v4l2-clk.h>
 #include <media/v4l2-common.h>
 
 #include "em28xx.h"
@@ -95,8 +96,8 @@ static struct em28xx_reg_seq default_digital[] = {
 /* Board Hauppauge WinTV HVR 900 analog */
 static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
        {EM2820_R08_GPIO_CTRL,  0x2d,   ~EM_GPIO_4,     10},
-       {0x05,                  0xff,   0x10,           10},
-       {  -1,                  -1,     -1,             -1},
+       {       0x05,           0xff,   0x10,           10},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Board Hauppauge WinTV HVR 900 digital */
@@ -104,20 +105,20 @@ static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
        {EM2820_R08_GPIO_CTRL,  0x2e,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x04,   0x0f,           10},
        {EM2880_R04_GPO,        0x0c,   0x0f,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Board Hauppauge WinTV HVR 900 (R2) digital */
 static struct em28xx_reg_seq hauppauge_wintv_hvr_900R2_digital[] = {
        {EM2820_R08_GPIO_CTRL,  0x2e,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x0c,   0x0f,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
 static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
-       {EM2820_R08_GPIO_CTRL,       0x69,   ~EM_GPIO_4,         10},
-       {       -1,             -1,     -1,              -1},
+       {EM2820_R08_GPIO_CTRL,  0x69,   ~EM_GPIO_4,     10},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
@@ -132,7 +133,7 @@ static struct em28xx_reg_seq em2882_kworld_315u_digital[] = {
        {EM2880_R04_GPO,        0x04,   0xff,           10},
        {EM2880_R04_GPO,        0x0c,   0xff,           10},
        {EM2820_R08_GPIO_CTRL,  0x7e,   0xff,           10},
-       {  -1,                  -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = {
@@ -140,19 +141,19 @@ static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = {
        {EM2880_R04_GPO,        0x0c,   0xff,           10},
        {EM2880_R04_GPO,        0x08,   0xff,           10},
        {EM2880_R04_GPO,        0x0c,   0xff,           10},
-       {  -1,                  -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 static struct em28xx_reg_seq kworld_330u_analog[] = {
        {EM2820_R08_GPIO_CTRL,  0x6d,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x00,   0xff,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 static struct em28xx_reg_seq kworld_330u_digital[] = {
        {EM2820_R08_GPIO_CTRL,  0x6e,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x08,   0xff,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Evga inDtube
@@ -170,11 +171,11 @@ static struct em28xx_reg_seq evga_indtube_digital[] = {
        {EM2820_R08_GPIO_CTRL,  0x7a,   0xff,            1},
        {EM2880_R04_GPO,        0x04,   0xff,           10},
        {EM2880_R04_GPO,        0x0c,   0xff,            1},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 /*
- * KWorld PlusTV 340U and UB435-Q (ATSC) GPIOs map:
+ * KWorld PlusTV 340U, UB435-Q and UB435-Q V2 (ATSC) GPIOs map:
  * EM_GPIO_0 - currently unknown
  * EM_GPIO_1 - LED disable/enable (1 = off, 0 = on)
  * EM_GPIO_2 - currently unknown
@@ -185,8 +186,8 @@ static struct em28xx_reg_seq evga_indtube_digital[] = {
  * EM_GPIO_7 - currently unknown
  */
 static struct em28xx_reg_seq kworld_a340_digital[] = {
-       {EM2820_R08_GPIO_CTRL,  0x6d,           ~EM_GPIO_4,     10},
-       { -1,                   -1,             -1,             -1},
+       {EM2820_R08_GPIO_CTRL,  0x6d,   ~EM_GPIO_4,     10},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Pinnacle Hybrid Pro eb1a:2881 */
@@ -205,13 +206,13 @@ static struct em28xx_reg_seq pinnacle_hybrid_pro_digital[] = {
 static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_analog[] = {
        {EM2820_R08_GPIO_CTRL,  0x6d,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x00,   0xff,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = {
        {EM2820_R08_GPIO_CTRL,  0x6e,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x08,   0xff,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* eb1a:2868 Reddo DVB-C USB TV Box
@@ -225,7 +226,7 @@ static struct em28xx_reg_seq reddo_dvb_c_usb_box[] = {
        {EM2820_R08_GPIO_CTRL,  0x7f,   0xff,           10},
        {EM2820_R08_GPIO_CTRL,  0x6f,   0xff,           10},
        {EM2820_R08_GPIO_CTRL,  0xff,   0xff,           10},
-       {-1,                    -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 /* Callback for the most boards */
@@ -233,23 +234,23 @@ static struct em28xx_reg_seq default_tuner_gpio[] = {
        {EM2820_R08_GPIO_CTRL,  EM_GPIO_4,      EM_GPIO_4,      10},
        {EM2820_R08_GPIO_CTRL,  0,              EM_GPIO_4,      10},
        {EM2820_R08_GPIO_CTRL,  EM_GPIO_4,      EM_GPIO_4,      10},
-       {  -1,                  -1,             -1,             -1},
+       {       -1,             -1,             -1,             -1},
 };
 
 /* Mute/unmute */
 static struct em28xx_reg_seq compro_unmute_tv_gpio[] = {
-       {EM2820_R08_GPIO_CTRL,  5,              7,              10},
-       {  -1,                  -1,             -1,             -1},
+       {EM2820_R08_GPIO_CTRL,  5,      7,      10},
+       {       -1,             -1,     -1,     -1},
 };
 
 static struct em28xx_reg_seq compro_unmute_svid_gpio[] = {
-       {EM2820_R08_GPIO_CTRL,  4,              7,              10},
-       {  -1,                  -1,             -1,             -1},
+       {EM2820_R08_GPIO_CTRL,  4,      7,      10},
+       {       -1,             -1,     -1,     -1},
 };
 
 static struct em28xx_reg_seq compro_mute_gpio[] = {
-       {EM2820_R08_GPIO_CTRL,  6,              7,              10},
-       {  -1,                  -1,             -1,             -1},
+       {EM2820_R08_GPIO_CTRL,  6,      7,      10},
+       {       -1,             -1,     -1,     -1},
 };
 
 /* Terratec AV350 */
@@ -279,21 +280,21 @@ static struct em28xx_reg_seq vc211a_enable[] = {
 static struct em28xx_reg_seq dikom_dk300_digital[] = {
        {EM2820_R08_GPIO_CTRL,  0x6e,   ~EM_GPIO_4,     10},
        {EM2880_R04_GPO,        0x08,   0xff,           10},
-       { -1,                   -1,     -1,             -1},
+       {       -1,             -1,     -1,             -1},
 };
 
 
 /* Reset for the most [digital] boards */
 static struct em28xx_reg_seq leadership_digital[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0x70,   0xff,   10},
-       {       -1,             -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 
 static struct em28xx_reg_seq leadership_reset[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0xf0,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0xb0,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0xf0,   0xff,   10},
-       {       -1,             -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 
 /* 2013:024f PCTV nanoStick T2 290e
@@ -304,7 +305,7 @@ static struct em28xx_reg_seq pctv_290e[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0x00,   0xff,   80},
        {EM2874_R80_GPIO_P0_CTRL,       0x40,   0xff,   80}, /* GPIO_6 = 1 */
        {EM2874_R80_GPIO_P0_CTRL,       0xc0,   0xff,   80}, /* GPIO_7 = 1 */
-       {-1,                    -1,     -1,             -1},
+       {       -1,                     -1,     -1,     -1},
 };
 
 #if 0
@@ -313,14 +314,14 @@ static struct em28xx_reg_seq terratec_h5_gpio[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   100},
        {EM2874_R80_GPIO_P0_CTRL,       0xf2,   0xff,   50},
        {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   50},
-       { -1,                   -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 
 static struct em28xx_reg_seq terratec_h5_digital[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0xe6,   0xff,   100},
        {EM2874_R80_GPIO_P0_CTRL,       0xa6,   0xff,   10},
-       { -1,                   -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 #endif
 
@@ -335,12 +336,12 @@ static struct em28xx_reg_seq terratec_h5_digital[] = {
  * GPIO_7 - LED (green LED)
  */
 static struct em28xx_reg_seq pctv_460e[] = {
-       {EM2874_R80_GPIO_P0_CTRL, 0x01, 0xff,  50},
-       {0x0d,            0xff, 0xff,  50},
-       {EM2874_R80_GPIO_P0_CTRL, 0x41, 0xff,  50}, /* GPIO_6=1 */
-       {0x0d,            0x42, 0xff,  50},
-       {EM2874_R80_GPIO_P0_CTRL, 0x61, 0xff,  50}, /* GPIO_5=1 */
-       {             -1,   -1,   -1,  -1},
+       {EM2874_R80_GPIO_P0_CTRL,       0x01,   0xff,   50},
+       {       0x0d,                   0xff,   0xff,   50},
+       {EM2874_R80_GPIO_P0_CTRL,       0x41,   0xff,   50}, /* GPIO_6=1 */
+       {       0x0d,                   0x42,   0xff,   50},
+       {EM2874_R80_GPIO_P0_CTRL,       0x61,   0xff,   50}, /* GPIO_5=1 */
+       {       -1,                     -1,     -1,     -1},
 };
 
 static struct em28xx_reg_seq c3tech_digital_duo_digital[] = {
@@ -352,7 +353,7 @@ static struct em28xx_reg_seq c3tech_digital_duo_digital[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0xfe,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0xbe,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0xfe,   0xff,   20},
-       { -1,                   -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 
 #if 0
@@ -361,14 +362,14 @@ static struct em28xx_reg_seq hauppauge_930c_gpio[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0x4f,   0xff,   10}, /* xc5000 reset */
        {EM2874_R80_GPIO_P0_CTRL,       0x6f,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0x4f,   0xff,   10},
-       { -1,                   -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 
 static struct em28xx_reg_seq hauppauge_930c_digital[] = {
        {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   10},
        {EM2874_R80_GPIO_P0_CTRL,       0xe6,   0xff,   100},
        {EM2874_R80_GPIO_P0_CTRL,       0xa6,   0xff,   10},
-       { -1,                   -1,     -1,     -1},
+       {       -1,                     -1,     -1,     -1},
 };
 #endif
 
@@ -378,10 +379,10 @@ static struct em28xx_reg_seq hauppauge_930c_digital[] = {
  * GPIO_7 - LED, 0=active
  */
 static struct em28xx_reg_seq maxmedia_ub425_tc[] = {
-       {EM2874_R80_GPIO_P0_CTRL,  0x83,  0xff,  100},
-       {EM2874_R80_GPIO_P0_CTRL,  0xc3,  0xff,  100}, /* GPIO_6 = 1 */
-       {EM2874_R80_GPIO_P0_CTRL,  0x43,  0xff,  000}, /* GPIO_7 = 0 */
-       {-1,                 -1,    -1,   -1},
+       {EM2874_R80_GPIO_P0_CTRL,       0x83,   0xff,   100},
+       {EM2874_R80_GPIO_P0_CTRL,       0xc3,   0xff,   100}, /* GPIO_6 = 1 */
+       {EM2874_R80_GPIO_P0_CTRL,       0x43,   0xff,   000}, /* GPIO_7 = 0 */
+       {       -1,                     -1,     -1,     -1},
 };
 
 /* 2304:0242 PCTV QuatroStick (510e)
@@ -391,10 +392,10 @@ static struct em28xx_reg_seq maxmedia_ub425_tc[] = {
  * GPIO_7: LED, 1=active
  */
 static struct em28xx_reg_seq pctv_510e[] = {
-       {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100},
-       {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */
-       {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */
-       {             -1,   -1,   -1,  -1},
+       {EM2874_R80_GPIO_P0_CTRL,       0x10,   0xff,   100},
+       {EM2874_R80_GPIO_P0_CTRL,       0x14,   0xff,   100}, /* GPIO_2 = 1 */
+       {EM2874_R80_GPIO_P0_CTRL,       0x54,   0xff,   050}, /* GPIO_6 = 1 */
+       {       -1,                     -1,     -1,     -1},
 };
 
 /* 2013:0251 PCTV QuatroStick nano (520e)
@@ -404,11 +405,11 @@ static struct em28xx_reg_seq pctv_510e[] = {
  * GPIO_7: LED, 1=active
  */
 static struct em28xx_reg_seq pctv_520e[] = {
-       {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100},
-       {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */
-       {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */
-       {EM2874_R80_GPIO_P0_CTRL, 0xd4, 0xff, 000}, /* GPIO_7 = 1 */
-       {             -1,   -1,   -1,  -1},
+       {EM2874_R80_GPIO_P0_CTRL,       0x10,   0xff,   100},
+       {EM2874_R80_GPIO_P0_CTRL,       0x14,   0xff,   100}, /* GPIO_2 = 1 */
+       {EM2874_R80_GPIO_P0_CTRL,       0x54,   0xff,   050}, /* GPIO_6 = 1 */
+       {EM2874_R80_GPIO_P0_CTRL,       0xd4,   0xff,   000}, /* GPIO_7 = 1 */
+       {       -1,                     -1,     -1,     -1},
 };
 
 /*
@@ -2030,6 +2031,18 @@ struct em28xx_board em28xx_boards[] = {
                .i2c_speed     = EM28XX_I2C_CLK_WAIT_ENABLE |
                                EM28XX_I2C_FREQ_400_KHZ,
        },
+       /*
+        * 1b80:e346 KWorld USB ATSC TV Stick UB435-Q V2
+        * Empia EM2874B + LG DT3305 + NXP TDA18271HDC2
+        */
+       [EM2874_BOARD_KWORLD_UB435Q_V2] = {
+               .name           = "KWorld USB ATSC TV Stick UB435-Q V2",
+               .tuner_type     = TUNER_ABSENT,
+               .has_dvb        = 1,
+               .dvb_gpio       = kworld_a340_digital,
+               .tuner_gpio     = default_tuner_gpio,
+               .def_i2c_bus    = 1,
+       },
 };
 const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
 
@@ -2173,6 +2186,8 @@ struct usb_device_id em28xx_id_table[] = {
                        .driver_info = EM2860_BOARD_GADMEI_UTV330 },
        { USB_DEVICE(0x1b80, 0xa340),
                        .driver_info = EM2870_BOARD_KWORLD_A340 },
+       { USB_DEVICE(0x1b80, 0xe346),
+                       .driver_info = EM2874_BOARD_KWORLD_UB435Q_V2 },
        { USB_DEVICE(0x2013, 0x024f),
                        .driver_info = EM28174_BOARD_PCTV_290E },
        { USB_DEVICE(0x2013, 0x024c),
@@ -2857,6 +2872,8 @@ void em28xx_release_resources(struct em28xx *dev)
        if (dev->def_i2c_bus)
                em28xx_i2c_unregister(dev, 1);
        em28xx_i2c_unregister(dev, 0);
+       if (dev->clk)
+               v4l2_clk_unregister_fixed(dev->clk);
 
        v4l2_ctrl_handler_free(&dev->ctrl_handler);
 
index bb1e8dca80cdfc88dff7919b70da410aa617d1c0..344042bb845cbee2326e47ca021085e0299447e4 100644 (file)
@@ -298,6 +298,18 @@ static struct lgdt3305_config em2870_lgdt3304_dev = {
        .qam_if_khz         = 4000,
 };
 
+static struct lgdt3305_config em2874_lgdt3305_dev = {
+       .i2c_addr           = 0x0e,
+       .demod_chip         = LGDT3305,
+       .spectral_inversion = 1,
+       .deny_i2c_rptr      = 0,
+       .mpeg_mode          = LGDT3305_MPEG_SERIAL,
+       .tpclk_edge         = LGDT3305_TPCLK_FALLING_EDGE,
+       .tpvalid_polarity   = LGDT3305_TP_VALID_HIGH,
+       .vsb_if_khz         = 3250,
+       .qam_if_khz         = 4000,
+};
+
 static struct s921_config sharp_isdbt = {
        .demod_address = 0x30 >> 1
 };
@@ -329,6 +341,11 @@ static struct tda18271_config kworld_a340_config = {
        .std_map           = &kworld_a340_std_map,
 };
 
+static struct tda18271_config kworld_ub435q_v2_config = {
+       .std_map        = &kworld_a340_std_map,
+       .gate           = TDA18271_GATE_DIGITAL,
+};
+
 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
        .demod_address = (0x1e >> 1),
        .no_tuner = 1,
@@ -384,7 +401,10 @@ static struct drxk_config maxmedia_ub425_tc_drxk = {
        .adr = 0x29,
        .single_master = 1,
        .no_i2c_bridge = 1,
+       .microcode_name = "dvb-demod-drxk-01.fw",
+       .chunk_size = 62,
        .load_firmware_sync = true,
+       .qam_demod_parameter_count = 2,
 };
 
 static struct drxk_config pctv_520e_drxk = {
@@ -424,7 +444,7 @@ static void hauppauge_hvr930c_init(struct em28xx *dev)
                {EM2874_R80_GPIO_P0_CTRL,       0xff,   0xff,   0x65},
                {EM2874_R80_GPIO_P0_CTRL,       0xfb,   0xff,   0x32},
                {EM2874_R80_GPIO_P0_CTRL,       0xff,   0xff,   0xb8},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
        struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
                {EM2874_R80_GPIO_P0_CTRL,       0xef,   0xff,   0x01},
@@ -439,7 +459,7 @@ static void hauppauge_hvr930c_init(struct em28xx *dev)
                {EM2874_R80_GPIO_P0_CTRL,       0xcf,   0xff,   0x0b},
                {EM2874_R80_GPIO_P0_CTRL,       0xef,   0xff,   0x65},
 
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
 
        struct {
@@ -491,13 +511,13 @@ static void terratec_h5_init(struct em28xx *dev)
                {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   100},
                {EM2874_R80_GPIO_P0_CTRL,       0xf2,   0xff,   50},
                {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   100},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
        struct em28xx_reg_seq terratec_h5_end[] = {
                {EM2874_R80_GPIO_P0_CTRL,       0xe6,   0xff,   100},
                {EM2874_R80_GPIO_P0_CTRL,       0xa6,   0xff,   50},
                {EM2874_R80_GPIO_P0_CTRL,       0xe6,   0xff,   100},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
        struct {
                unsigned char r[4];
@@ -547,12 +567,12 @@ static void terratec_htc_stick_init(struct em28xx *dev)
                {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   100},
                {EM2874_R80_GPIO_P0_CTRL,       0xe6,   0xff,   50},
                {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   100},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
        struct em28xx_reg_seq terratec_htc_stick_end[] = {
                {EM2874_R80_GPIO_P0_CTRL,       0xb6,   0xff,   100},
                {EM2874_R80_GPIO_P0_CTRL,       0xf6,   0xff,   50},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
 
        /*
@@ -594,13 +614,13 @@ static void terratec_htc_usb_xs_init(struct em28xx *dev)
                {EM2874_R80_GPIO_P0_CTRL,       0xb2,   0xff,   100},
                {EM2874_R80_GPIO_P0_CTRL,       0xb2,   0xff,   50},
                {EM2874_R80_GPIO_P0_CTRL,       0xb6,   0xff,   100},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
        struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
                {EM2874_R80_GPIO_P0_CTRL,       0xa6,   0xff,   100},
                {EM2874_R80_GPIO_P0_CTRL,       0xa6,   0xff,   50},
                {EM2874_R80_GPIO_P0_CTRL,       0xe6,   0xff,   100},
-               { -1,                   -1,     -1,     -1},
+               {       -1,                     -1,     -1,     -1},
        };
 
        /*
@@ -1227,18 +1247,14 @@ static int em28xx_dvb_init(struct em28xx *dev)
                        dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
 
                        /* attach tuner */
-                       if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
-                                       &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
+                       if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
+                                       &dev->i2c_adap[dev->def_i2c_bus],
+                                       &em28xx_cxd2820r_tda18271_config)) {
                                dvb_frontend_detach(dvb->fe[0]);
                                result = -EINVAL;
                                goto out_free;
                        }
                }
-
-               /* TODO: we need drx-3913k firmware in order to support DVB-T */
-               em28xx_info("MaxMedia UB425-TC/Delock 61959: only DVB-C " \
-                               "supported by that driver version\n");
-
                break;
        case EM2884_BOARD_PCTV_510E:
        case EM2884_BOARD_PCTV_520E:
@@ -1297,6 +1313,23 @@ static int em28xx_dvb_init(struct em28xx *dev)
                        goto out_free;
                }
                break;
+       case EM2874_BOARD_KWORLD_UB435Q_V2:
+               dvb->fe[0] = dvb_attach(lgdt3305_attach,
+                                       &em2874_lgdt3305_dev,
+                                       &dev->i2c_adap[dev->def_i2c_bus]);
+               if (!dvb->fe[0]) {
+                       result = -EINVAL;
+                       goto out_free;
+               }
+
+               /* Attach the demodulator. */
+               if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
+                               &dev->i2c_adap[dev->def_i2c_bus],
+                               &kworld_ub435q_v2_config)) {
+                       result = -EINVAL;
+                       goto out_free;
+               }
+               break;
        default:
                em28xx_errdev("/2: The frontend of your DVB/ATSC card"
                                " isn't supported yet\n");
index 9d103344f34ab5e4e3267ca8fa08f58db1f5a741..fc5d60efd4abe99f19acbafff7b83879da5ff3ac 100644 (file)
@@ -638,7 +638,7 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
        if (rc)
                return rc;
 
-       if (dev->streaming_users++ == 0) {
+       if (dev->streaming_users == 0) {
                /* First active streaming user, so allocate all the URBs */
 
                /* Allocate the USB bandwidth */
@@ -657,7 +657,7 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
                                          dev->packet_multiplier,
                                          em28xx_urb_data_copy);
                if (rc < 0)
-                       goto fail;
+                       return rc;
 
                /*
                 * djh: it's not clear whether this code is still needed.  I'm
@@ -675,7 +675,8 @@ int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
                v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
        }
 
-fail:
+       dev->streaming_users++;
+
        return rc;
 }
 
index 205e9038b1c0d406989a180d059b9f68e7b517c5..f8726ad5d0a8776063c6acbc482c9180ee10b08c 100644 (file)
 #define EM2884_BOARD_TERRATEC_HTC_USB_XS         87
 #define EM2884_BOARD_C3TECH_DIGITAL_DUO                  88
 #define EM2874_BOARD_DELOCK_61959                89
+#define EM2874_BOARD_KWORLD_UB435Q_V2            90
 
 /* Limits minimum and default number of buffers */
 #define EM28XX_MIN_BUF 4
@@ -492,6 +493,7 @@ struct em28xx {
 
        struct v4l2_device v4l2_dev;
        struct v4l2_ctrl_handler ctrl_handler;
+       struct v4l2_clk *clk;
        struct em28xx_board board;
 
        /* Webcam specific fields */
index 38714df31ac49878d13d64a9e626f26f1813041b..2e15c80d6e3d11b953d210b553cbc6878110427f 100644 (file)
@@ -783,7 +783,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, QUALITY);
 
index 064b53043b153359d70b2b6f3abdbc31a9131d6f..f23df4a9d8c56e460840082bfd5bb9ebcafce511 100644 (file)
@@ -1553,9 +1553,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
                sd->params.format.videoSize = VIDEOSIZE_CIF;
 
        sd->params.roi.colEnd = sd->params.roi.colStart +
-                               (gspca_dev->width >> 3);
+                               (gspca_dev->pixfmt.width >> 3);
        sd->params.roi.rowEnd = sd->params.roi.rowStart +
-                               (gspca_dev->height >> 2);
+                               (gspca_dev->pixfmt.height >> 2);
 
        /* And now set the camera to a known state */
        ret = do_command(gspca_dev, CPIA_COMMAND_SetGrabMode,
index 048507b27bb2388573ea8d76077e32a5eb1c708e..f3a7ace0fac9cc8bd4e2b2c8b82038dc85aa7068 100644 (file)
@@ -504,8 +504,7 @@ static int frame_alloc(struct gspca_dev *gspca_dev, struct file *file,
        unsigned int frsz;
        int i;
 
-       i = gspca_dev->curr_mode;
-       frsz = gspca_dev->cam.cam_mode[i].sizeimage;
+       frsz = gspca_dev->pixfmt.sizeimage;
        PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz);
        frsz = PAGE_ALIGN(frsz);
        if (count >= GSPCA_MAX_FRAMES)
@@ -627,16 +626,14 @@ static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt,
 static u32 which_bandwidth(struct gspca_dev *gspca_dev)
 {
        u32 bandwidth;
-       int i;
 
        /* get the (max) image size */
-       i = gspca_dev->curr_mode;
-       bandwidth = gspca_dev->cam.cam_mode[i].sizeimage;
+       bandwidth = gspca_dev->pixfmt.sizeimage;
 
        /* if the image is compressed, estimate its mean size */
        if (!gspca_dev->cam.needs_full_bandwidth &&
-           bandwidth < gspca_dev->cam.cam_mode[i].width *
-                               gspca_dev->cam.cam_mode[i].height)
+           bandwidth < gspca_dev->pixfmt.width *
+                               gspca_dev->pixfmt.height)
                bandwidth = bandwidth * 3 / 8;  /* 0.375 */
 
        /* estimate the frame rate */
@@ -650,7 +647,7 @@ static u32 which_bandwidth(struct gspca_dev *gspca_dev)
 
                /* don't hope more than 15 fps with USB 1.1 and
                 * image resolution >= 640x480 */
-               if (gspca_dev->width >= 640
+               if (gspca_dev->pixfmt.width >= 640
                 && gspca_dev->dev->speed == USB_SPEED_FULL)
                        bandwidth *= 15;                /* 15 fps */
                else
@@ -982,9 +979,7 @@ static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
 
        i = gspca_dev->cam.nmodes - 1;  /* take the highest mode */
        gspca_dev->curr_mode = i;
-       gspca_dev->width = gspca_dev->cam.cam_mode[i].width;
-       gspca_dev->height = gspca_dev->cam.cam_mode[i].height;
-       gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat;
+       gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i];
 
        /* does nothing if ctrl_handler == NULL */
        v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler);
@@ -1105,10 +1100,8 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
                            struct v4l2_format *fmt)
 {
        struct gspca_dev *gspca_dev = video_drvdata(file);
-       int mode;
 
-       mode = gspca_dev->curr_mode;
-       fmt->fmt.pix = gspca_dev->cam.cam_mode[mode];
+       fmt->fmt.pix = gspca_dev->pixfmt;
        /* some drivers use priv internally, zero it before giving it to
           userspace */
        fmt->fmt.pix.priv = 0;
@@ -1140,6 +1133,12 @@ static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
                        mode = mode2;
        }
        fmt->fmt.pix = gspca_dev->cam.cam_mode[mode];
+       if (gspca_dev->sd_desc->try_fmt) {
+               /* pass original resolution to subdriver try_fmt */
+               fmt->fmt.pix.width = w;
+               fmt->fmt.pix.height = h;
+               gspca_dev->sd_desc->try_fmt(gspca_dev, fmt);
+       }
        /* some drivers use priv internally, zero it before giving it to
           userspace */
        fmt->fmt.pix.priv = 0;
@@ -1178,19 +1177,16 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
                goto out;
        }
 
-       if (ret == gspca_dev->curr_mode) {
-               ret = 0;
-               goto out;                       /* same mode */
-       }
-
        if (gspca_dev->streaming) {
                ret = -EBUSY;
                goto out;
        }
-       gspca_dev->width = fmt->fmt.pix.width;
-       gspca_dev->height = fmt->fmt.pix.height;
-       gspca_dev->pixfmt = fmt->fmt.pix.pixelformat;
        gspca_dev->curr_mode = ret;
+       if (gspca_dev->sd_desc->try_fmt)
+               /* subdriver try_fmt can modify format parameters */
+               gspca_dev->pixfmt = fmt->fmt.pix;
+       else
+               gspca_dev->pixfmt = gspca_dev->cam.cam_mode[ret];
 
        ret = 0;
 out:
@@ -1205,6 +1201,9 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
        int i;
        __u32 index = 0;
 
+       if (gspca_dev->sd_desc->enum_framesizes)
+               return gspca_dev->sd_desc->enum_framesizes(gspca_dev, fsize);
+
        for (i = 0; i < gspca_dev->cam.nmodes; i++) {
                if (fsize->pixel_format !=
                                gspca_dev->cam.cam_mode[i].pixelformat)
@@ -1471,8 +1470,9 @@ static int vidioc_streamon(struct file *file, void *priv,
                if (ret < 0)
                        goto out;
        }
-       PDEBUG_MODE(gspca_dev, D_STREAM, "stream on OK", gspca_dev->pixfmt,
-                   gspca_dev->width, gspca_dev->height);
+       PDEBUG_MODE(gspca_dev, D_STREAM, "stream on OK",
+                   gspca_dev->pixfmt.pixelformat,
+                   gspca_dev->pixfmt.width, gspca_dev->pixfmt.height);
        ret = 0;
 out:
        mutex_unlock(&gspca_dev->queue_lock);
index ac0b11f46f5037d0cb29eaeb8896b445537fa76b..300642dc1a177207c1e4b9952f20404e19667c8e 100644 (file)
@@ -88,6 +88,10 @@ typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
 typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
                                u8 *data,
                                int len);
+typedef void (*cam_format_op) (struct gspca_dev *gspca_dev,
+                               struct v4l2_format *fmt);
+typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev,
+                               struct v4l2_frmsizeenum *fsize);
 
 /* subdriver description */
 struct sd_desc {
@@ -109,6 +113,8 @@ struct sd_desc {
        cam_set_jpg_op set_jcomp;
        cam_streamparm_op get_streamparm;
        cam_streamparm_op set_streamparm;
+       cam_format_op try_fmt;
+       cam_frmsize_op enum_framesizes;
 #ifdef CONFIG_VIDEO_ADV_DEBUG
        cam_set_reg_op set_register;
        cam_get_reg_op get_register;
@@ -183,9 +189,7 @@ struct gspca_dev {
        __u8 streaming;                 /* protected by both mutexes (*) */
 
        __u8 curr_mode;                 /* current camera mode */
-       __u32 pixfmt;                   /* current mode parameters */
-       __u16 width;
-       __u16 height;
+       struct v4l2_pix_format pixfmt;  /* current mode parameters */
        __u32 sequence;                 /* frame sequence number */
 
        wait_queue_head_t wq;           /* wait queue */
index 8da3dde383853d9c0faaad80a7f0c53eadaf449b..19736e237b37d6a14e50141c8d24104141783f16 100644 (file)
@@ -378,11 +378,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
        struct sd *dev = (struct sd *) gspca_dev;
 
        /* create the JPEG header */
-       jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(dev->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x21);          /* JPEG 422 */
        jpeg_set_qual(dev->jpeg_hdr, dev->quality);
        PDEBUG(D_STREAM, "Start streaming at %dx%d",
-               gspca_dev->height, gspca_dev->width);
+               gspca_dev->pixfmt.height, gspca_dev->pixfmt.width);
        jlj_start(gspca_dev);
        return gspca_dev->usb_err;
 }
index fdaeeb14453fbb42d82d9d31c0d64e088333bed2..5b481fa430992a7b37b9d14f9df108498f0c4d86 100644 (file)
@@ -455,7 +455,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
        sd->cap_mode = gspca_dev->cam.cam_mode;
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 640:
                PDEBUG(D_STREAM, "Start streaming at vga resolution");
                jl2005c_stream_start_vga_lg(gspca_dev);
index cfa4663f8934ebea47eb7d8d116a4405e875c17d..27fcef11aef42998b0132b26f3b3b4790ee06dd7 100644 (file)
@@ -266,7 +266,7 @@ static int mt9m111_set_hvflip(struct gspca_dev *gspca_dev)
                return err;
 
        data[0] = MT9M111_RMB_OVER_SIZED;
-       if (gspca_dev->width == 640) {
+       if (gspca_dev->pixfmt.width == 640) {
                data[1] = MT9M111_RMB_ROW_SKIP_2X |
                          MT9M111_RMB_COLUMN_SKIP_2X |
                          (hflip << 1) | vflip;
index ff2c5abf115ba635d59a363f190d04acb21ceb66..779a8785f421bbcb67c62840c8a67478ee0a44a2 100644 (file)
@@ -254,7 +254,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int i;
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x21);          /* JPEG 422 */
        jpeg_set_qual(sd->jpeg_hdr, QUALITY);
 
@@ -270,8 +271,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        data[0] = 0x00;         /* address */
        data[1] = 0x0c | 0x01;  /* reg 0 */
        data[2] = 0x01;         /* reg 1 */
-       data[3] = gspca_dev->width / 8;         /* h_size , reg 2 */
-       data[4] = gspca_dev->height / 8;        /* v_size , reg 3 */
+       data[3] = gspca_dev->pixfmt.width / 8;  /* h_size , reg 2 */
+       data[4] = gspca_dev->pixfmt.height / 8; /* v_size , reg 3 */
        data[5] = 0x30;         /* reg 4, MI, PAS5101 :
                                 *      0x30 for 24mhz , 0x28 for 12mhz */
        data[6] = 0x02;         /* reg 5, H start - was 0x04 */
index 68bb2f35966656e8005bb9ef6cb08707ef266bbb..f006e29ca0197b66ec62dfd821dcb520e24635bf 100644 (file)
@@ -521,7 +521,7 @@ static int start_cif_cam(struct gspca_dev *gspca_dev)
        if (sd->sensor_type)
                data[5] = 0xbb;
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160:
                data[9] |= 0x04;  /* reg 8, 2:1 scale down from 320 */
                /* fall thru */
@@ -618,7 +618,7 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
                data[10] = 0x18;
        }
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160:
                data[9] |= 0x0c;  /* reg 8, 4:1 scale down */
                /* fall thru */
@@ -847,7 +847,7 @@ static void setexposure(struct gspca_dev *gspca_dev, s32 expo, s32 min_clockdiv)
                u8 clockdiv = (60 * expo + 7999) / 8000;
 
                /* Limit framerate to not exceed usb bandwidth */
-               if (clockdiv < min_clockdiv && gspca_dev->width >= 320)
+               if (clockdiv < min_clockdiv && gspca_dev->pixfmt.width >= 320)
                        clockdiv = min_clockdiv;
                else if (clockdiv < 2)
                        clockdiv = 2;
index 44c9964b1b3e206085ac1ea3dea8e23048aaead2..599f755e75b86513c28228468bc19e15278a414a 100644 (file)
@@ -1708,7 +1708,7 @@ static void setautogain(struct gspca_dev *gspca_dev, s32 val)
 
        reg_r(gspca_dev, 0x1004, 1);
        if (gspca_dev->usb_buf[0] & 0x04) {     /* if AE_FULL_FRM */
-               sd->ae_res = gspca_dev->width * gspca_dev->height;
+               sd->ae_res = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
        } else {                                /* get the AE window size */
                reg_r(gspca_dev, 0x1011, 8);
                w = (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0]
@@ -1717,7 +1717,8 @@ static void setautogain(struct gspca_dev *gspca_dev, s32 val)
                  - (gspca_dev->usb_buf[7] << 8) - gspca_dev->usb_buf[6];
                sd->ae_res = h * w;
                if (sd->ae_res == 0)
-                       sd->ae_res = gspca_dev->width * gspca_dev->height;
+                       sd->ae_res = gspca_dev->pixfmt.width *
+                                       gspca_dev->pixfmt.height;
        }
 }
 
@@ -1856,21 +1857,21 @@ static int sd_start(struct gspca_dev *gspca_dev)
        reg_w_buf(gspca_dev, cmd);
        switch (sd->webcam) {
        case P35u:
-               if (gspca_dev->width == 320)
+               if (gspca_dev->pixfmt.width == 320)
                        reg_w_buf(gspca_dev, nw801_start_qvga);
                else
                        reg_w_buf(gspca_dev, nw801_start_vga);
                reg_w_buf(gspca_dev, nw801_start_2);
                break;
        case Kr651us:
-               if (gspca_dev->width == 320)
+               if (gspca_dev->pixfmt.width == 320)
                        reg_w_buf(gspca_dev, kr651_start_qvga);
                else
                        reg_w_buf(gspca_dev, kr651_start_vga);
                reg_w_buf(gspca_dev, kr651_start_2);
                break;
        case Proscope:
-               if (gspca_dev->width == 320)
+               if (gspca_dev->pixfmt.width == 320)
                        reg_w_buf(gspca_dev, proscope_start_qvga);
                else
                        reg_w_buf(gspca_dev, proscope_start_vga);
index 8937d79fd1762bcea5ebd863d2eecf6d0d69c0cc..c95f32a0c02b4283d0f4c66b253e0a7e402f392d 100644 (file)
@@ -3468,7 +3468,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
 
        switch (sd->bridge) {
        case BRIDGE_OVFX2:
-               if (gspca_dev->width != 800)
+               if (gspca_dev->pixfmt.width != 800)
                        gspca_dev->cam.bulk_size = OVFX2_BULK_SIZE;
                else
                        gspca_dev->cam.bulk_size = 7 * 4096;
@@ -3507,8 +3507,8 @@ static void ov511_mode_init_regs(struct sd *sd)
        /* Here I'm assuming that snapshot size == image size.
         * I hope that's always true. --claudio
         */
-       hsegs = (sd->gspca_dev.width >> 3) - 1;
-       vsegs = (sd->gspca_dev.height >> 3) - 1;
+       hsegs = (sd->gspca_dev.pixfmt.width >> 3) - 1;
+       vsegs = (sd->gspca_dev.pixfmt.height >> 3) - 1;
 
        reg_w(sd, R511_CAM_PXCNT, hsegs);
        reg_w(sd, R511_CAM_LNCNT, vsegs);
@@ -3541,7 +3541,7 @@ static void ov511_mode_init_regs(struct sd *sd)
        case SEN_OV7640:
        case SEN_OV7648:
        case SEN_OV76BE:
-               if (sd->gspca_dev.width == 320)
+               if (sd->gspca_dev.pixfmt.width == 320)
                        interlaced = 1;
                /* Fall through */
        case SEN_OV6630:
@@ -3551,7 +3551,7 @@ static void ov511_mode_init_regs(struct sd *sd)
                case 30:
                case 25:
                        /* Not enough bandwidth to do 640x480 @ 30 fps */
-                       if (sd->gspca_dev.width != 640) {
+                       if (sd->gspca_dev.pixfmt.width != 640) {
                                sd->clockdiv = 0;
                                break;
                        }
@@ -3584,7 +3584,8 @@ static void ov511_mode_init_regs(struct sd *sd)
 
        /* Check if we have enough bandwidth to disable compression */
        fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
-       needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
+       needed = fps * sd->gspca_dev.pixfmt.width *
+                       sd->gspca_dev.pixfmt.height * 3 / 2;
        /* 1000 isoc packets/sec */
        if (needed > 1000 * packet_size) {
                /* Enable Y and UV quantization and compression */
@@ -3646,8 +3647,8 @@ static void ov518_mode_init_regs(struct sd *sd)
                reg_w(sd, 0x38, 0x80);
        }
 
-       hsegs = sd->gspca_dev.width / 16;
-       vsegs = sd->gspca_dev.height / 4;
+       hsegs = sd->gspca_dev.pixfmt.width / 16;
+       vsegs = sd->gspca_dev.pixfmt.height / 4;
 
        reg_w(sd, 0x29, hsegs);
        reg_w(sd, 0x2a, vsegs);
@@ -3686,7 +3687,8 @@ static void ov518_mode_init_regs(struct sd *sd)
                         * happened to be with revision < 2 cams using an
                         * OV7620 and revision 2 cams using an OV7620AE.
                         */
-                       if (sd->revision > 0 && sd->gspca_dev.width == 640) {
+                       if (sd->revision > 0 &&
+                                       sd->gspca_dev.pixfmt.width == 640) {
                                reg_w(sd, 0x20, 0x60);
                                reg_w(sd, 0x21, 0x1f);
                        } else {
@@ -3812,8 +3814,8 @@ static void ov519_mode_init_regs(struct sd *sd)
                break;
        }
 
-       reg_w(sd, OV519_R10_H_SIZE,     sd->gspca_dev.width >> 4);
-       reg_w(sd, OV519_R11_V_SIZE,     sd->gspca_dev.height >> 3);
+       reg_w(sd, OV519_R10_H_SIZE,     sd->gspca_dev.pixfmt.width >> 4);
+       reg_w(sd, OV519_R11_V_SIZE,     sd->gspca_dev.pixfmt.height >> 3);
        if (sd->sensor == SEN_OV7670 &&
            sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
                reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
@@ -3947,14 +3949,16 @@ static void mode_init_ov_sensor_regs(struct sd *sd)
            }
        case SEN_OV3610:
                if (qvga) {
-                       xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
-                       ystart = (776 - gspca_dev->height) / 2;
+                       xstart = (1040 - gspca_dev->pixfmt.width) / 2 +
+                               (0x1f << 4);
+                       ystart = (776 - gspca_dev->pixfmt.height) / 2;
                } else {
-                       xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
-                       ystart = (1544 - gspca_dev->height) / 2;
+                       xstart = (2076 - gspca_dev->pixfmt.width) / 2 +
+                               (0x10 << 4);
+                       ystart = (1544 - gspca_dev->pixfmt.height) / 2;
                }
-               xend = xstart + gspca_dev->width;
-               yend = ystart + gspca_dev->height;
+               xend = xstart + gspca_dev->pixfmt.width;
+               yend = ystart + gspca_dev->pixfmt.height;
                /* Writing to the COMH register resets the other windowing regs
                   to their default values, so we must do this first. */
                i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
@@ -4229,8 +4233,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
 
        /* Default for most bridges, allow bridge_mode_init_regs to override */
-       sd->sensor_width = sd->gspca_dev.width;
-       sd->sensor_height = sd->gspca_dev.height;
+       sd->sensor_width = sd->gspca_dev.pixfmt.width;
+       sd->sensor_height = sd->gspca_dev.pixfmt.height;
 
        switch (sd->bridge) {
        case BRIDGE_OV511:
@@ -4345,12 +4349,13 @@ static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
                ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
                if (in[8] & 0x80) {
                        /* Frame end */
-                       if ((in[9] + 1) * 8 != gspca_dev->width ||
-                           (in[10] + 1) * 8 != gspca_dev->height) {
+                       if ((in[9] + 1) * 8 != gspca_dev->pixfmt.width ||
+                           (in[10] + 1) * 8 != gspca_dev->pixfmt.height) {
                                PERR("Invalid frame size, got: %dx%d,"
                                        " requested: %dx%d\n",
                                        (in[9] + 1) * 8, (in[10] + 1) * 8,
-                                       gspca_dev->width, gspca_dev->height);
+                                       gspca_dev->pixfmt.width,
+                                       gspca_dev->pixfmt.height);
                                gspca_dev->last_packet_type = DISCARD_PACKET;
                                return;
                        }
@@ -4470,7 +4475,8 @@ static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
                if (sd->first_frame) {
                        sd->first_frame--;
                        if (gspca_dev->image_len <
-                                 sd->gspca_dev.width * sd->gspca_dev.height)
+                                 sd->gspca_dev.pixfmt.width *
+                                       sd->gspca_dev.pixfmt.height)
                                gspca_dev->last_packet_type = DISCARD_PACKET;
                }
                gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
index 03a33c46ca2c0ede859867d00b0652f911566be9..90f0d637cd9d05f66450ef645859cf7f5f7fb381 100644 (file)
@@ -1440,9 +1440,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
                /* If this packet is marked as EOF, end the frame */
                } else if (data[1] & UVC_STREAM_EOF) {
                        sd->last_pts = 0;
-                       if (gspca_dev->pixfmt == V4L2_PIX_FMT_YUYV
+                       if (gspca_dev->pixfmt.pixelformat == V4L2_PIX_FMT_YUYV
                         && gspca_dev->image_len + len - 12 !=
-                                  gspca_dev->width * gspca_dev->height * 2) {
+                                  gspca_dev->pixfmt.width *
+                                       gspca_dev->pixfmt.height * 2) {
                                PDEBUG(D_PACK, "wrong sized frame");
                                goto discard;
                        }
index c4cd028fe0b4c8ea0c662ab82fbf98695f23a722..47085cf2d72365b5fdac410d5394bbdb8a7407b0 100644 (file)
@@ -59,6 +59,7 @@ enum sensors {
        SENSOR_OV965x,          /* ov9657 */
        SENSOR_OV971x,          /* ov9712 */
        SENSOR_OV562x,          /* ov5621 */
+       SENSOR_OV361x,          /* ov3610 */
        NSENSORS
 };
 
@@ -106,6 +107,274 @@ static const struct v4l2_pix_format ov562x_mode[] = {
        }
 };
 
+enum ov361x {
+       ov361x_2048 = 0,
+       ov361x_1600,
+       ov361x_1024,
+       ov361x_640,
+       ov361x_320,
+       ov361x_160,
+       ov361x_last
+};
+
+static const struct v4l2_pix_format ov361x_mode[] = {
+       {0x800, 0x600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 0x800,
+               .sizeimage = 0x800 * 0x600,
+               .colorspace = V4L2_COLORSPACE_SRGB},
+       {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 1600,
+               .sizeimage = 1600 * 1200,
+               .colorspace = V4L2_COLORSPACE_SRGB},
+       {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 768,
+               .sizeimage = 1024 * 768,
+               .colorspace = V4L2_COLORSPACE_SRGB},
+       {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 640,
+               .sizeimage = 640 * 480,
+               .colorspace = V4L2_COLORSPACE_SRGB},
+       {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 320,
+               .sizeimage = 320 * 240,
+               .colorspace = V4L2_COLORSPACE_SRGB},
+       {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
+               .bytesperline = 160,
+               .sizeimage = 160 * 120,
+               .colorspace = V4L2_COLORSPACE_SRGB}
+};
+
+static const u8 ov361x_start_2048[][2] = {
+       {0x12, 0x80},
+       {0x13, 0xcf},
+       {0x14, 0x40},
+       {0x15, 0x00},
+       {0x01, 0x80},
+       {0x02, 0x80},
+       {0x04, 0x70},
+       {0x0d, 0x40},
+       {0x0f, 0x47},
+       {0x11, 0x81},
+       {0x32, 0x36},
+       {0x33, 0x0c},
+       {0x34, 0x00},
+       {0x35, 0x90},
+       {0x12, 0x00},
+       {0x17, 0x10},
+       {0x18, 0x90},
+       {0x19, 0x00},
+       {0x1a, 0xc0},
+};
+static const u8 ov361x_bridge_start_2048[][2] = {
+       {0xf1, 0x60},
+       {0x88, 0x00},
+       {0x89, 0x08},
+       {0x8a, 0x00},
+       {0x8b, 0x06},
+       {0x8c, 0x01},
+       {0x8d, 0x10},
+       {0x1c, 0x00},
+       {0x1d, 0x48},
+       {0x1d, 0x00},
+       {0x1d, 0xff},
+       {0x1c, 0x0a},
+       {0x1d, 0x2e},
+       {0x1d, 0x1e},
+};
+
+static const u8 ov361x_start_1600[][2] = {
+       {0x12, 0x80},
+       {0x13, 0xcf},
+       {0x14, 0x40},
+       {0x15, 0x00},
+       {0x01, 0x80},
+       {0x02, 0x80},
+       {0x04, 0x70},
+       {0x0d, 0x40},
+       {0x0f, 0x47},
+       {0x11, 0x81},
+       {0x32, 0x36},
+       {0x33, 0x0C},
+       {0x34, 0x00},
+       {0x35, 0x90},
+       {0x12, 0x00},
+       {0x17, 0x10},
+       {0x18, 0x90},
+       {0x19, 0x00},
+       {0x1a, 0xc0},
+};
+static const u8 ov361x_bridge_start_1600[][2] = {
+       {0xf1, 0x60},  /* Hsize[7:0] */
+       {0x88, 0x00},  /* Hsize[15:8] Write Only, can't read */
+       {0x89, 0x08},  /* Vsize[7:0] */
+       {0x8a, 0x00},  /* Vsize[15:8] Write Only, can't read */
+       {0x8b, 0x06},  /* for Iso */
+       {0x8c, 0x01},  /* RAW input */
+       {0x8d, 0x10},
+       {0x1c, 0x00},  /* RAW output, Iso transfer */
+       {0x1d, 0x48},
+       {0x1d, 0x00},
+       {0x1d, 0xff},
+       {0x1c, 0x0a},  /* turn off JPEG, Iso mode */
+       {0x1d, 0x2e},  /* for Iso */
+       {0x1d, 0x1e},
+};
+
+static const u8 ov361x_start_1024[][2] = {
+       {0x12, 0x80},
+       {0x13, 0xcf},
+       {0x14, 0x40},
+       {0x15, 0x00},
+       {0x01, 0x80},
+       {0x02, 0x80},
+       {0x04, 0x70},
+       {0x0d, 0x40},
+       {0x0f, 0x47},
+       {0x11, 0x81},
+       {0x32, 0x36},
+       {0x33, 0x0C},
+       {0x34, 0x00},
+       {0x35, 0x90},
+       {0x12, 0x40},
+       {0x17, 0x1f},
+       {0x18, 0x5f},
+       {0x19, 0x00},
+       {0x1a, 0x68},
+};
+static const u8 ov361x_bridge_start_1024[][2] = {
+       {0xf1, 0x60},  /* Hsize[7:0] */
+       {0x88, 0x00},  /* Hsize[15:8] Write Only, can't read */
+       {0x89, 0x04},  /* Vsize[7:0] */
+       {0x8a, 0x00},  /* Vsize[15:8] Write Only, can't read */
+       {0x8b, 0x03},  /* for Iso */
+       {0x8c, 0x01},  /* RAW input  */
+       {0x8d, 0x10},
+       {0x1c, 0x00},  /* RAW output, Iso transfer */
+       {0x1d, 0x48},
+       {0x1d, 0x00},
+       {0x1d, 0xff},
+       {0x1c, 0x0a},  /* turn off JPEG, Iso mode */
+       {0x1d, 0x2e},  /* for Iso */
+       {0x1d, 0x1e},
+};
+
+static const u8 ov361x_start_640[][2] = {
+       {0x12, 0x80},
+       {0x13, 0xcf},
+       {0x14, 0x40},
+       {0x15, 0x00},
+       {0x01, 0x80},
+       {0x02, 0x80},
+       {0x04, 0x70},
+       {0x0d, 0x40},
+       {0x0f, 0x47},
+       {0x11, 0x81},
+       {0x32, 0x36},
+       {0x33, 0x0C},
+       {0x34, 0x00},
+       {0x35, 0x90},
+       {0x12, 0x40},
+       {0x17, 0x1f},
+       {0x18, 0x5f},
+       {0x19, 0x00},
+       {0x1a, 0x68},
+};
+
+static const u8 ov361x_bridge_start_640[][2] = {
+       {0xf1, 0x60},  /* Hsize[7:0]*/
+       {0x88, 0x00},  /* Hsize[15:8] Write Only, can't read */
+       {0x89, 0x04},  /* Vsize[7:0] */
+       {0x8a, 0x00},  /* Vsize[15:8] Write Only, can't read */
+       {0x8b, 0x03},  /* for Iso */
+       {0x8c, 0x01},  /* RAW input */
+       {0x8d, 0x10},
+       {0x1c, 0x00},  /* RAW output, Iso transfer */
+       {0x1d, 0x48},
+       {0x1d, 0x00},
+       {0x1d, 0xff},
+       {0x1c, 0x0a},  /* turn off JPEG, Iso mode */
+       {0x1d, 0x2e},  /* for Iso */
+       {0x1d, 0x1e},
+};
+
+static const u8 ov361x_start_320[][2] = {
+       {0x12, 0x80},
+       {0x13, 0xcf},
+       {0x14, 0x40},
+       {0x15, 0x00},
+       {0x01, 0x80},
+       {0x02, 0x80},
+       {0x04, 0x70},
+       {0x0d, 0x40},
+       {0x0f, 0x47},
+       {0x11, 0x81},
+       {0x32, 0x36},
+       {0x33, 0x0C},
+       {0x34, 0x00},
+       {0x35, 0x90},
+       {0x12, 0x40},
+       {0x17, 0x1f},
+       {0x18, 0x5f},
+       {0x19, 0x00},
+       {0x1a, 0x68},
+};
+
+static const u8 ov361x_bridge_start_320[][2] = {
+       {0xf1, 0x60},  /* Hsize[7:0] */
+       {0x88, 0x00},  /* Hsize[15:8] Write Only, can't read */
+       {0x89, 0x04},  /* Vsize[7:0] */
+       {0x8a, 0x00},  /* Vsize[15:8] Write Only, can't read */
+       {0x8b, 0x03},  /* for Iso */
+       {0x8c, 0x01},  /* RAW input */
+       {0x8d, 0x10},
+       {0x1c, 0x00},  /* RAW output, Iso transfer; */
+       {0x1d, 0x48},
+       {0x1d, 0x00},
+       {0x1d, 0xff},
+       {0x1c, 0x0a},  /* turn off JPEG, Iso mode */
+       {0x1d, 0x2e},  /* for Iso */
+       {0x1d, 0x1e},
+};
+
+static const u8 ov361x_start_160[][2] = {
+       {0x12, 0x80},
+       {0x13, 0xcf},
+       {0x14, 0x40},
+       {0x15, 0x00},
+       {0x01, 0x80},
+       {0x02, 0x80},
+       {0x04, 0x70},
+       {0x0d, 0x40},
+       {0x0f, 0x47},
+       {0x11, 0x81},
+       {0x32, 0x36},
+       {0x33, 0x0C},
+       {0x34, 0x00},
+       {0x35, 0x90},
+       {0x12, 0x40},
+       {0x17, 0x1f},
+       {0x18, 0x5f},
+       {0x19, 0x00},
+       {0x1a, 0x68},
+};
+
+static const u8 ov361x_bridge_start_160[][2] = {
+       {0xf1, 0x60},  /* Hsize[7:0] */
+       {0x88, 0x00},  /* Hsize[15:8] Write Only, can't read */
+       {0x89, 0x04},  /* Vsize[7:0] */
+       {0x8a, 0x00},  /* Vsize[15:8] Write Only, can't read */
+       {0x8b, 0x03},  /* for Iso */
+       {0x8c, 0x01},  /* RAW input */
+       {0x8d, 0x10},
+       {0x1c, 0x00},  /* RAW output, Iso transfer */
+       {0x1d, 0x48},
+       {0x1d, 0x00},
+       {0x1d, 0xff},
+       {0x1c, 0x0a},  /* turn off JPEG, Iso mode */
+       {0x1d, 0x2e},  /* for Iso */
+       {0x1d, 0x1e},
+};
+
 static const u8 bridge_init[][2] = {
        {0x88, 0xf8},
        {0x89, 0xff},
@@ -898,7 +1167,7 @@ static int sccb_check_status(struct gspca_dev *gspca_dev)
        int i;
 
        for (i = 0; i < 5; i++) {
-               msleep(10);
+               msleep(20);
                data = reg_r(gspca_dev, OV534_REG_STATUS);
 
                switch (data) {
@@ -1221,6 +1490,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
                sccb_w_array(gspca_dev, ov562x_init_2,
                                ARRAY_SIZE(ov562x_init_2));
                reg_w(gspca_dev, 0xe0, 0x00);
+       } else if ((sensor_id & 0xfff0) == 0x3610) {
+               sd->sensor = SENSOR_OV361x;
+               gspca_dev->cam.cam_mode = ov361x_mode;
+               gspca_dev->cam.nmodes = ARRAY_SIZE(ov361x_mode);
+               reg_w(gspca_dev, 0xe7, 0x3a);
+               reg_w(gspca_dev, 0xf1, 0x60);
+               sccb_write(gspca_dev, 0x12, 0x80);
        } else {
                pr_err("Unknown sensor %04x", sensor_id);
                return -EINVAL;
@@ -1229,6 +1505,53 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return gspca_dev->usb_err;
 }
 
+static int sd_start_ov361x(struct gspca_dev *gspca_dev)
+{
+       sccb_write(gspca_dev, 0x12, 0x80);
+       msleep(20);
+       switch (gspca_dev->curr_mode % (ov361x_last)) {
+       case ov361x_2048:
+               reg_w_array(gspca_dev, ov361x_bridge_start_2048,
+                           ARRAY_SIZE(ov361x_bridge_start_2048));
+               sccb_w_array(gspca_dev, ov361x_start_2048,
+                            ARRAY_SIZE(ov361x_start_2048));
+               break;
+       case ov361x_1600:
+               reg_w_array(gspca_dev, ov361x_bridge_start_1600,
+                           ARRAY_SIZE(ov361x_bridge_start_1600));
+               sccb_w_array(gspca_dev, ov361x_start_1600,
+                            ARRAY_SIZE(ov361x_start_1600));
+               break;
+       case ov361x_1024:
+               reg_w_array(gspca_dev, ov361x_bridge_start_1024,
+                           ARRAY_SIZE(ov361x_bridge_start_1024));
+               sccb_w_array(gspca_dev, ov361x_start_1024,
+                            ARRAY_SIZE(ov361x_start_1024));
+               break;
+       case ov361x_640:
+               reg_w_array(gspca_dev, ov361x_bridge_start_640,
+                           ARRAY_SIZE(ov361x_bridge_start_640));
+               sccb_w_array(gspca_dev, ov361x_start_640,
+                            ARRAY_SIZE(ov361x_start_640));
+               break;
+       case ov361x_320:
+               reg_w_array(gspca_dev, ov361x_bridge_start_320,
+                           ARRAY_SIZE(ov361x_bridge_start_320));
+               sccb_w_array(gspca_dev, ov361x_start_320,
+                            ARRAY_SIZE(ov361x_start_320));
+               break;
+       case ov361x_160:
+               reg_w_array(gspca_dev, ov361x_bridge_start_160,
+                           ARRAY_SIZE(ov361x_bridge_start_160));
+               sccb_w_array(gspca_dev, ov361x_start_160,
+                            ARRAY_SIZE(ov361x_start_160));
+               break;
+       }
+       reg_w(gspca_dev, 0xe0, 0x00); /* start transfer */
+
+       return gspca_dev->usb_err;
+}
+
 static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
@@ -1237,6 +1560,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
                return gspca_dev->usb_err;
        if (sd->sensor == SENSOR_OV562x)
                return gspca_dev->usb_err;
+       if (sd->sensor == SENSOR_OV361x)
+               return sd_start_ov361x(gspca_dev);
 
        switch (gspca_dev->curr_mode) {
        case QVGA_MODE:                 /* 320x240 */
@@ -1290,6 +1615,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
 {
+       if (((struct sd *)gspca_dev)->sensor == SENSOR_OV361x) {
+               reg_w(gspca_dev, 0xe0, 0x01); /* stop transfer */
+               /* reg_w(gspca_dev, 0x31, 0x09); */
+               return;
+       }
        reg_w(gspca_dev, 0xe0, 0x01);
        set_led(gspca_dev, 0);
        reg_w(gspca_dev, 0xe0, 0x00);
@@ -1425,6 +1755,8 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
 
        if (sd->sensor == SENSOR_OV971x)
                return 0;
+       if (sd->sensor == SENSOR_OV361x)
+               return 0;
        gspca_dev->vdev.ctrl_handler = hdl;
        v4l2_ctrl_handler_init(hdl, 7);
        if (sd->sensor == SENSOR_OV562x) {
index 83519be94e58c704b7b50c50b69cce558645cb1b..cd79c180f67b87e84689a8a162b4962bf5691cde 100644 (file)
@@ -299,7 +299,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8);
 
        /* Compression Balance */
-       if (gspca_dev->width == 176)
+       if (gspca_dev->pixfmt.width == 176)
                pac207_write_reg(gspca_dev, 0x4a, 0xff);
        else
                pac207_write_reg(gspca_dev, 0x4a, 0x30);
@@ -317,7 +317,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                mode = 0x00;
        else
                mode = 0x02;
-       if (gspca_dev->width == 176) {  /* 176x144 */
+       if (gspca_dev->pixfmt.width == 176) {   /* 176x144 */
                mode |= 0x01;
                PDEBUG(D_STREAM, "pac207_start mode 176x144");
        } else {                                /* 352x288 */
index 1a5bdc853a80dbc2fb9a3c15360f2243a7f77f91..25f86b1e74a80b9c9d6f4d856b8156a216d47102 100644 (file)
@@ -326,7 +326,7 @@ static void setexposure(struct gspca_dev *gspca_dev, s32 val)
         *  640x480 mode and page 4 reg 2 <= 3 then it must be 9
         */
        reg_w(gspca_dev, 0xff, 0x01);
-       if (gspca_dev->width != 640 && val <= 3)
+       if (gspca_dev->pixfmt.width != 640 && val <= 3)
                reg_w(gspca_dev, 0x08, 0x09);
        else
                reg_w(gspca_dev, 0x08, 0x08);
@@ -337,7 +337,7 @@ static void setexposure(struct gspca_dev *gspca_dev, s32 val)
         * camera to use higher compression or we may run out of
         * bandwidth.
         */
-       if (gspca_dev->width == 640 && val == 2)
+       if (gspca_dev->pixfmt.width == 640 && val == 2)
                reg_w(gspca_dev, 0x80, 0x01);
        else
                reg_w(gspca_dev, 0x80, 0x1c);
@@ -615,7 +615,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
 
                /* Start the new frame with the jpeg header */
                pac_start_frame(gspca_dev,
-                       gspca_dev->height, gspca_dev->width);
+                       gspca_dev->pixfmt.height, gspca_dev->pixfmt.width);
        }
        gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
 }
index 5f729b8aa2bd64bee74af9c02b1954a12c4bb304..5102cea504710c5c2aeeba1b0101159f35b0b459 100644 (file)
@@ -354,9 +354,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
 
        /* set size + mode */
        se401_write_req(gspca_dev, SE401_REQ_SET_WIDTH,
-                       gspca_dev->width * mult, 0);
+                       gspca_dev->pixfmt.width * mult, 0);
        se401_write_req(gspca_dev, SE401_REQ_SET_HEIGHT,
-                       gspca_dev->height * mult, 0);
+                       gspca_dev->pixfmt.height * mult, 0);
        /*
         * HDG: disabled this as it does not seem to do anything
         * se401_write_req(gspca_dev, SE401_REQ_SET_OUTPUT_MODE,
@@ -480,7 +480,7 @@ static void sd_complete_frame(struct gspca_dev *gspca_dev, u8 *data, int len)
 static void sd_pkt_scan_janggu(struct gspca_dev *gspca_dev, u8 *data, int len)
 {
        struct sd *sd = (struct sd *)gspca_dev;
-       int imagesize = gspca_dev->width * gspca_dev->height;
+       int imagesize = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
        int i, plen, bits, pixels, info, count;
 
        if (sd->restart_stream)
index f4453d52801b94140cc1201f437ba68fec694095..2a38621cf7188d1f8cdfe03e7d1fede7ffcad566 100644 (file)
@@ -1955,7 +1955,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
                        return 0;
                }
 
-               switch (gspca_dev->width) {
+               switch (gspca_dev->pixfmt.width) {
                case 160: /* 160x120 */
                        gspca_dev->alt = 2;
                        break;
@@ -1985,8 +1985,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
-       int width = gspca_dev->width;
-       int height = gspca_dev->height;
+       int width = gspca_dev->pixfmt.width;
+       int height = gspca_dev->pixfmt.height;
        u8 fmt, scale = 0;
 
        jpeg_define(sd->jpeg_hdr, height, width,
index d7ff3b9687c57cb22c504e7a3a9493e41fd924eb..7277dbd2afcdb8c88629aafc2c9013b38cd79390 100644 (file)
@@ -513,10 +513,7 @@ static void i2c_w(struct gspca_dev *gspca_dev, const u8 *buf)
                if (gspca_dev->usb_buf[0] & 0x04) {
                        if (gspca_dev->usb_buf[0] & 0x08) {
                                dev_err(gspca_dev->v4l2_dev.dev,
-                                       "i2c error writing %02x %02x %02x %02x"
-                                       " %02x %02x %02x %02x\n",
-                                       buf[0], buf[1], buf[2], buf[3],
-                                       buf[4], buf[5], buf[6], buf[7]);
+                                       "i2c error writing %8ph\n", buf);
                                gspca_dev->usb_err = -EIO;
                        }
                        return;
@@ -753,7 +750,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
                /* In 640x480, if the reg11 has less than 4, the image is
                   unstable (the bridge goes into a higher compression mode
                   which we have not reverse engineered yet). */
-               if (gspca_dev->width == 640 && reg11 < 4)
+               if (gspca_dev->pixfmt.width == 640 && reg11 < 4)
                        reg11 = 4;
 
                /* frame exposure time in ms = 1000 * reg11 / 30    ->
index 3b5ccb1c4cdf11e0597995f1acdd3e74d182cabe..c69b45d7cfbf3995281ce1ede849a6b761474d77 100644 (file)
@@ -2204,7 +2204,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
                                { 0x14, 0xe7, 0x1e, 0xdd };
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x21);          /* JPEG 422 */
 
        /* initialize the bridge */
index 688592b289eafad0055e4f10d747492a6b65d0b5..f38fd8949609fd917cee8568a4cba9bdb5e83cb4 100644 (file)
@@ -255,7 +255,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
 
        /* initialize the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x22);          /* JPEG 411 */
 
        /* the JPEG quality shall be 85% */
index 9f8bf51fd64b64cb1e4544a722f2b0d9da308c1e..f011a309dd65f4d0776e82cb55f4e6c3fb4ccf58 100644 (file)
@@ -608,7 +608,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        __u8 xmult, ymult;
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, QUALITY);
 
index acb19fb9a3df3a7d8914eb4f5efa927aa6a18fad..aa21edc9502d67466f7ed13959d85709b9e36889 100644 (file)
@@ -272,7 +272,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
 
        dev->cap_mode = gspca_dev->cam.cam_mode;
        /* "Open the shutter" and set size, to start capture */
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 640:
                PDEBUG(D_STREAM, "Start streaming at high resolution");
                dev->cap_mode++;
index b10d0821111cba7815be078d338c8e1f0917e5ef..e274cf19a3ea22a1448f340f7a779c5a1274d528 100644 (file)
@@ -906,7 +906,8 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
 
        gspca_dev->cam.bulk_nurbs = 1;  /* there must be one URB only */
        sd->do_ctrl = 0;
-       gspca_dev->cam.bulk_size = gspca_dev->width * gspca_dev->height + 8;
+       gspca_dev->cam.bulk_size = gspca_dev->pixfmt.width *
+                       gspca_dev->pixfmt.height + 8;
        return 0;
 }
 
index 8c0982607f25c0ca8b14518be8ebee8b40b50278..b0c70fea760ba68a8235372e9c0ddcc2970af941 100644 (file)
@@ -250,7 +250,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int ret, value;
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, QUALITY);
 
@@ -261,7 +262,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        set_par(gspca_dev, 0x00000000);
        set_par(gspca_dev, 0x8002e001);
        set_par(gspca_dev, 0x14000000);
-       if (gspca_dev->width > 320)
+       if (gspca_dev->pixfmt.width > 320)
                value = 0x8002e001;             /* 640x480 */
        else
                value = 0x4001f000;             /* 320x240 */
index 585868835aceab032418a13448cf2d00007947f8..1fc80af2a18907e57d54eac3f58481ada0f3cda7 100644 (file)
@@ -48,42 +48,11 @@ struct sd {
 };
 
 static const struct v4l2_pix_format stk1135_modes[] = {
-       {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 160,
-               .sizeimage = 160 * 120,
-               .colorspace = V4L2_COLORSPACE_SRGB},
-       {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 176,
-               .sizeimage = 176 * 144,
-               .colorspace = V4L2_COLORSPACE_SRGB},
-       {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 320,
-               .sizeimage = 320 * 240,
-               .colorspace = V4L2_COLORSPACE_SRGB},
-       {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 352,
-               .sizeimage = 352 * 288,
-               .colorspace = V4L2_COLORSPACE_SRGB},
+       /* default mode (this driver supports variable resolution) */
        {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
                .bytesperline = 640,
                .sizeimage = 640 * 480,
                .colorspace = V4L2_COLORSPACE_SRGB},
-       {720, 576, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 720,
-               .sizeimage = 720 * 576,
-               .colorspace = V4L2_COLORSPACE_SRGB},
-       {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 800,
-               .sizeimage = 800 * 600,
-               .colorspace = V4L2_COLORSPACE_SRGB},
-       {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 1024,
-               .sizeimage = 1024 * 768,
-               .colorspace = V4L2_COLORSPACE_SRGB},
-       {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
-               .bytesperline = 1280,
-               .sizeimage = 1280 * 1024,
-               .colorspace = V4L2_COLORSPACE_SRGB},
 };
 
 /* -- read a register -- */
@@ -347,16 +316,16 @@ static void stk1135_configure_mt9m112(struct gspca_dev *gspca_dev)
                sensor_write(gspca_dev, cfg[i].reg, cfg[i].val);
 
        /* set output size */
-       width = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].width;
-       height = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].height;
-       if (width <= 640) { /* use context A (half readout speed by default) */
+       width = gspca_dev->pixfmt.width;
+       height = gspca_dev->pixfmt.height;
+       if (width <= 640 && height <= 512) { /* context A (half readout speed)*/
                sensor_write(gspca_dev, 0x1a7, width);
                sensor_write(gspca_dev, 0x1aa, height);
                /* set read mode context A */
                sensor_write(gspca_dev, 0x0c8, 0x0000);
                /* set resize, read mode, vblank, hblank context A */
                sensor_write(gspca_dev, 0x2c8, 0x0000);
-       } else { /* use context B (full readout speed by default) */
+       } else { /* context B (full readout speed) */
                sensor_write(gspca_dev, 0x1a1, width);
                sensor_write(gspca_dev, 0x1a4, height);
                /* set read mode context B */
@@ -484,8 +453,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        reg_w(gspca_dev, STK1135_REG_CISPO + 3, 0x00);
 
        /* set capture end position */
-       width = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].width;
-       height = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].height;
+       width = gspca_dev->pixfmt.width;
+       height = gspca_dev->pixfmt.height;
        reg_w(gspca_dev, STK1135_REG_CIEPO + 0, width & 0xff);
        reg_w(gspca_dev, STK1135_REG_CIEPO + 1, width >> 8);
        reg_w(gspca_dev, STK1135_REG_CIEPO + 2, height & 0xff);
@@ -643,6 +612,35 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
        return 0;
 }
 
+static void stk1135_try_fmt(struct gspca_dev *gspca_dev, struct v4l2_format *fmt)
+{
+       fmt->fmt.pix.width = clamp(fmt->fmt.pix.width, 32U, 1280U);
+       fmt->fmt.pix.height = clamp(fmt->fmt.pix.height, 32U, 1024U);
+       /* round up to even numbers */
+       fmt->fmt.pix.width += (fmt->fmt.pix.width & 1);
+       fmt->fmt.pix.height += (fmt->fmt.pix.height & 1);
+
+       fmt->fmt.pix.bytesperline = fmt->fmt.pix.width;
+       fmt->fmt.pix.sizeimage = fmt->fmt.pix.width * fmt->fmt.pix.height;
+}
+
+static int stk1135_enum_framesizes(struct gspca_dev *gspca_dev,
+                       struct v4l2_frmsizeenum *fsize)
+{
+       if (fsize->index != 0 || fsize->pixel_format != V4L2_PIX_FMT_SBGGR8)
+               return -EINVAL;
+
+       fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+       fsize->stepwise.min_width = 32;
+       fsize->stepwise.min_height = 32;
+       fsize->stepwise.max_width = 1280;
+       fsize->stepwise.max_height = 1024;
+       fsize->stepwise.step_width = 2;
+       fsize->stepwise.step_height = 2;
+
+       return 0;
+}
+
 /* sub-driver description */
 static const struct sd_desc sd_desc = {
        .name = MODULE_NAME,
@@ -653,6 +651,8 @@ static const struct sd_desc sd_desc = {
        .stopN = sd_stopN,
        .pkt_scan = sd_pkt_scan,
        .dq_callback = stk1135_dq_callback,
+       .try_fmt = stk1135_try_fmt,
+       .enum_framesizes = stk1135_enum_framesizes,
 };
 
 /* -- module initialisation -- */
index 55ee7a61c67fb635fe8dbfb2527f178c554c0f6c..49d209bbf9ee08f54e2caa86283205b914a72afd 100644 (file)
@@ -452,7 +452,7 @@ frame_data:
                                        NULL, 0);
 
                        if (sd->bridge == BRIDGE_ST6422)
-                               sd->to_skip = gspca_dev->width * 4;
+                               sd->to_skip = gspca_dev->pixfmt.width * 4;
 
                        if (chunk_len)
                                PERR("Chunk length is "
index 8206b77433006690f3926767290a2802de816611..8d785edcccf2ef040906840f55ea3173e555ecbf 100644 (file)
@@ -421,7 +421,7 @@ static int pb0100_set_autogain_target(struct gspca_dev *gspca_dev, __s32 val)
 
        /* Number of pixels counted by the sensor when subsampling the pixels.
         * Slightly larger than the real value to avoid oscillation */
-       totalpixels = gspca_dev->width * gspca_dev->height;
+       totalpixels = gspca_dev->pixfmt.width * gspca_dev->pixfmt.height;
        totalpixels = totalpixels/(8*8) + totalpixels/(64*64);
 
        brightpixels = (totalpixels * val) >> 8;
index af8767a9bd4ccc1a9af62d7f23c69e68a6348f2a..a517d185febed4590bbb5f58306aa4e4a2c4f0f1 100644 (file)
@@ -715,7 +715,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int enable;
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, QUALITY);
 
index 4cb511ccc5f6ecbefadee9ef64de47f9fd75f3e2..640c2fe760b3c4e13c687eefbde34e156025d648 100644 (file)
@@ -3856,7 +3856,7 @@ static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
 
        if (sd->bridge == BRIDGE_TP6800) {
                val |= 0x08;            /* grid compensation enable */
-               if (gspca_dev->width == 640)
+               if (gspca_dev->pixfmt.width == 640)
                        reg_w(gspca_dev, TP6800_R78_FORMAT, 0x00); /* vga */
                else
                        val |= 0x04;            /* scaling down enable */
@@ -3880,7 +3880,7 @@ static void set_resolution(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
 
        reg_w(gspca_dev, TP6800_R21_ENDP_1_CTL, 0x00);
-       if (gspca_dev->width == 320) {
+       if (gspca_dev->pixfmt.width == 320) {
                reg_w(gspca_dev, TP6800_R3F_FRAME_RATE, 0x06);
                msleep(100);
                i2c_w(gspca_dev, CX0342_AUTO_ADC_CALIB, 0x01);
@@ -3924,7 +3924,7 @@ static int get_fr_idx(struct gspca_dev *gspca_dev)
 
                /* 640x480 * 30 fps does not work */
                if (i == 6                      /* if 30 fps */
-                && gspca_dev->width == 640)
+                && gspca_dev->pixfmt.width == 640)
                        i = 0x05;               /* 15 fps */
        } else {
                for (i = 0; i < ARRAY_SIZE(rates_6810) - 1; i++) {
@@ -3935,7 +3935,7 @@ static int get_fr_idx(struct gspca_dev *gspca_dev)
 
                /* 640x480 * 30 fps does not work */
                if (i == 7                      /* if 30 fps */
-                && gspca_dev->width == 640)
+                && gspca_dev->pixfmt.width == 640)
                        i = 6;                  /* 15 fps */
                i |= 0x80;                      /* clock * 1 */
        }
@@ -4554,7 +4554,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width);
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width);
        set_dqt(gspca_dev, sd->quality);
        if (sd->bridge == BRIDGE_TP6800) {
                if (sd->sensor == SENSOR_CX0342)
@@ -4737,7 +4738,7 @@ static void sd_dq_callback(struct gspca_dev *gspca_dev)
                        (gspca_dev->usb_buf[26] << 8) + gspca_dev->usb_buf[25] +
                        (gspca_dev->usb_buf[29] << 8) + gspca_dev->usb_buf[28])
                                / 8;
-               if (gspca_dev->width == 640)
+               if (gspca_dev->pixfmt.width == 640)
                        luma /= 4;
                reg_w(gspca_dev, 0x7d, 0x00);
 
index 8591324a53e15edc5582d73d9c90715969ffe0f4..d497ba38af0da06149ebb95ec91526c21e6a4604 100644 (file)
@@ -268,7 +268,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
        packet_type0 = packet_type1 = INTER_PACKET;
        if (gspca_dev->empty_packet) {
                gspca_dev->empty_packet = 0;
-               sd->packet = gspca_dev->height / 2;
+               sd->packet = gspca_dev->pixfmt.height / 2;
                packet_type0 = FIRST_PACKET;
        } else if (sd->packet == 0)
                return;                 /* 2 more lines in 352x288 ! */
@@ -284,9 +284,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
         * - 4 bytes
         */
        gspca_frame_add(gspca_dev, packet_type0,
-                       data + 2, gspca_dev->width);
+                       data + 2, gspca_dev->pixfmt.width);
        gspca_frame_add(gspca_dev, packet_type1,
-                       data + gspca_dev->width + 5, gspca_dev->width);
+                       data + gspca_dev->pixfmt.width + 5,
+                       gspca_dev->pixfmt.width);
 }
 
 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
index a2275cfe0b814625b1bfc9e14144084aed74ca6b..103f6c4236b0789d9eb621eb17efd77a5d46c63e 100644 (file)
@@ -121,13 +121,13 @@ static int vicam_read_frame(struct gspca_dev *gspca_dev, u8 *data, int size)
 
        memset(req_data, 0, 16);
        req_data[0] = gain;
-       if (gspca_dev->width == 256)
+       if (gspca_dev->pixfmt.width == 256)
                req_data[1] |= 0x01; /* low nibble x-scale */
-       if (gspca_dev->height <= 122) {
+       if (gspca_dev->pixfmt.height <= 122) {
                req_data[1] |= 0x10; /* high nibble y-scale */
-               unscaled_height = gspca_dev->height * 2;
+               unscaled_height = gspca_dev->pixfmt.height * 2;
        } else
-               unscaled_height = gspca_dev->height;
+               unscaled_height = gspca_dev->pixfmt.height;
        req_data[2] = 0x90; /* unknown, does not seem to do anything */
        if (unscaled_height <= 200)
                req_data[3] = 0x06; /* vend? */
index 2165da0c7ce1570828be04c572a0bcc816353677..fb9fe2ef3a6f60059b7f3fee4e89254b4869d52f 100644 (file)
@@ -430,11 +430,11 @@ static void w9968cf_set_crop_window(struct sd *sd)
        #define SC(x) ((x) << 10)
 
        /* Scaling factors */
-       fw = SC(sd->gspca_dev.width) / max_width;
-       fh = SC(sd->gspca_dev.height) / max_height;
+       fw = SC(sd->gspca_dev.pixfmt.width) / max_width;
+       fh = SC(sd->gspca_dev.pixfmt.height) / max_height;
 
-       cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.width) / fh;
-       ch = (fw >= fh) ? SC(sd->gspca_dev.height) / fw : max_height;
+       cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.pixfmt.width) / fh;
+       ch = (fw >= fh) ? SC(sd->gspca_dev.pixfmt.height) / fw : max_height;
 
        sd->sensor_width = max_width;
        sd->sensor_height = max_height;
@@ -454,34 +454,34 @@ static void w9968cf_mode_init_regs(struct sd *sd)
 
        w9968cf_set_crop_window(sd);
 
-       reg_w(sd, 0x14, sd->gspca_dev.width);
-       reg_w(sd, 0x15, sd->gspca_dev.height);
+       reg_w(sd, 0x14, sd->gspca_dev.pixfmt.width);
+       reg_w(sd, 0x15, sd->gspca_dev.pixfmt.height);
 
        /* JPEG width & height */
-       reg_w(sd, 0x30, sd->gspca_dev.width);
-       reg_w(sd, 0x31, sd->gspca_dev.height);
+       reg_w(sd, 0x30, sd->gspca_dev.pixfmt.width);
+       reg_w(sd, 0x31, sd->gspca_dev.pixfmt.height);
 
        /* Y & UV frame buffer strides (in WORD) */
        if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
            V4L2_PIX_FMT_JPEG) {
-               reg_w(sd, 0x2c, sd->gspca_dev.width / 2);
-               reg_w(sd, 0x2d, sd->gspca_dev.width / 4);
+               reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width / 2);
+               reg_w(sd, 0x2d, sd->gspca_dev.pixfmt.width / 4);
        } else
-               reg_w(sd, 0x2c, sd->gspca_dev.width);
+               reg_w(sd, 0x2c, sd->gspca_dev.pixfmt.width);
 
        reg_w(sd, 0x00, 0xbf17); /* reset everything */
        reg_w(sd, 0x00, 0xbf10); /* normal operation */
 
        /* Transfer size in WORDS (for UYVY format only) */
-       val = sd->gspca_dev.width * sd->gspca_dev.height;
+       val = sd->gspca_dev.pixfmt.width * sd->gspca_dev.pixfmt.height;
        reg_w(sd, 0x3d, val & 0xffff); /* low bits */
        reg_w(sd, 0x3e, val >> 16);    /* high bits */
 
        if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
            V4L2_PIX_FMT_JPEG) {
                /* We may get called multiple times (usb isoc bw negotiat.) */
-               jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height,
-                           sd->gspca_dev.width, 0x22); /* JPEG 420 */
+               jpeg_define(sd->jpeg_hdr, sd->gspca_dev.pixfmt.height,
+                           sd->gspca_dev.pixfmt.width, 0x22); /* JPEG 420 */
                jpeg_set_qual(sd->jpeg_hdr, v4l2_ctrl_g_ctrl(sd->jpegqual));
                w9968cf_upload_quantizationtables(sd);
                v4l2_ctrl_grab(sd->jpegqual, true);
index 7eaf64eb867cf5ebdef1e55c265cd6f7ca4a6685..a41aa7817c54349e196a4aeee80c60a8adb4a921 100644 (file)
@@ -1471,14 +1471,14 @@ static int cit_get_clock_div(struct gspca_dev *gspca_dev)
 
        while (clock_div > 3 &&
                        1000 * packet_size >
-                       gspca_dev->width * gspca_dev->height *
+                       gspca_dev->pixfmt.width * gspca_dev->pixfmt.height *
                        fps[clock_div - 1] * 3 / 2)
                clock_div--;
 
        PDEBUG(D_PROBE,
               "PacketSize: %d, res: %dx%d -> using clockdiv: %d (%d fps)",
-              packet_size, gspca_dev->width, gspca_dev->height, clock_div,
-              fps[clock_div]);
+              packet_size, gspca_dev->pixfmt.width, gspca_dev->pixfmt.height,
+              clock_div, fps[clock_div]);
 
        return clock_div;
 }
@@ -1502,7 +1502,7 @@ static int cit_start_model0(struct gspca_dev *gspca_dev)
        cit_write_reg(gspca_dev, 0x0002, 0x0426);
        cit_write_reg(gspca_dev, 0x0014, 0x0427);
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160: /* 160x120 */
                cit_write_reg(gspca_dev, 0x0004, 0x010b);
                cit_write_reg(gspca_dev, 0x0001, 0x010a);
@@ -1643,7 +1643,7 @@ static int cit_start_model1(struct gspca_dev *gspca_dev)
        cit_write_reg(gspca_dev, 0x00, 0x0101);
        cit_write_reg(gspca_dev, 0x00, 0x010a);
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 128: /* 128x96 */
                cit_write_reg(gspca_dev, 0x80, 0x0103);
                cit_write_reg(gspca_dev, 0x60, 0x0105);
@@ -1700,7 +1700,7 @@ static int cit_start_model1(struct gspca_dev *gspca_dev)
        }
 
        /* Assorted init */
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 128: /* 128x96 */
                cit_Packet_Format1(gspca_dev, 0x2b, 0x1e);
                cit_write_reg(gspca_dev, 0xc9, 0x0119); /* Same everywhere */
@@ -1753,7 +1753,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
        cit_write_reg(gspca_dev, 0x0000, 0x0108);
        cit_write_reg(gspca_dev, 0x0001, 0x0133);
        cit_write_reg(gspca_dev, 0x0001, 0x0102);
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 176: /* 176x144 */
                cit_write_reg(gspca_dev, 0x002c, 0x0103);       /* All except 320x240 */
                cit_write_reg(gspca_dev, 0x0000, 0x0104);       /* Same */
@@ -1792,7 +1792,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
 
        cit_write_reg(gspca_dev, 0x0000, 0x0100);       /* LED on */
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 176: /* 176x144 */
                cit_write_reg(gspca_dev, 0x0050, 0x0111);
                cit_write_reg(gspca_dev, 0x00d0, 0x0111);
@@ -1840,7 +1840,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
         * Magic control of CMOS sensor. Only lower values like
         * 0-3 work, and picture shifts left or right. Don't change.
         */
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 176: /* 176x144 */
                cit_model2_Packet1(gspca_dev, 0x0014, 0x0002);
                cit_model2_Packet1(gspca_dev, 0x0016, 0x0002); /* Horizontal shift */
@@ -1899,7 +1899,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
         * does not allow arbitrary values and apparently is a bit mask, to
         * be activated only at appropriate time. Don't change it randomly!
         */
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 176: /* 176x144 */
                cit_model2_Packet1(gspca_dev, 0x0026, 0x00c2);
                break;
@@ -2023,7 +2023,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
        cit_model3_Packet1(gspca_dev, 0x009e, 0x0096);
        cit_model3_Packet1(gspca_dev, 0x009f, 0x000a);
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160:
                cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */
                cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */
@@ -2134,7 +2134,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
           like with the IBM netcam pro). */
        cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160:
                cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */
                cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */
@@ -2211,7 +2211,7 @@ static int cit_start_model4(struct gspca_dev *gspca_dev)
        cit_write_reg(gspca_dev, 0xfffa, 0x0124);
        cit_model4_Packet1(gspca_dev, 0x0034, 0x0000);
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 128: /* 128x96 */
                cit_write_reg(gspca_dev, 0x0070, 0x0119);
                cit_write_reg(gspca_dev, 0x00d0, 0x0111);
@@ -2531,7 +2531,7 @@ static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
        cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */
        cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160: /* 160x120 */
                cit_write_reg(gspca_dev, 0x0024, 0x010b);
                cit_write_reg(gspca_dev, 0x0089, 0x0119);
@@ -2635,7 +2635,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
        struct usb_host_interface *alt;
        int max_packet_size;
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160:
                max_packet_size = 450;
                break;
@@ -2659,7 +2659,7 @@ static int sd_isoc_nego(struct gspca_dev *gspca_dev)
        int ret, packet_size, min_packet_size;
        struct usb_host_interface *alt;
 
-       switch (gspca_dev->width) {
+       switch (gspca_dev->pixfmt.width) {
        case 160:
                min_packet_size = 200;
                break;
@@ -2780,7 +2780,7 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
        case CIT_MODEL1:
        case CIT_MODEL3:
        case CIT_IBM_NETCAM_PRO:
-               switch (gspca_dev->width) {
+               switch (gspca_dev->pixfmt.width) {
                case 160: /* 160x120 */
                        byte3 = 0x02;
                        byte4 = 0x0a;
@@ -2864,20 +2864,16 @@ static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
                                if (data[i] == 0xff) {
                                        if (i >= 4)
                                                PDEBUG(D_FRAM,
-                                                      "header found at offset: %d: %02x %02x 00 %02x %02x %02x\n",
+                                                      "header found at offset: %d: %02x %02x 00 %3ph\n",
                                                       i - 1,
                                                       data[i - 4],
                                                       data[i - 3],
-                                                      data[i],
-                                                      data[i + 1],
-                                                      data[i + 2]);
+                                                      &data[i]);
                                        else
                                                PDEBUG(D_FRAM,
-                                                      "header found at offset: %d: 00 %02x %02x %02x\n",
+                                                      "header found at offset: %d: 00 %3ph\n",
                                                       i - 1,
-                                                      data[i],
-                                                      data[i + 1],
-                                                      data[i + 2]);
+                                                      &data[i]);
                                        return data + i + (sd->sof_len - 1);
                                }
                                break;
index cbfc2f921427cd250556210bdbcf37539c6d5e88..7b95d8e88a20240305a8817b72c3459d80a5adc6 100644 (file)
@@ -6700,7 +6700,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        };
 
        /* create the JPEG header */
-       jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
+       jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
+                       gspca_dev->pixfmt.width,
                        0x21);          /* JPEG 422 */
 
        mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
index 6e5070774dc2ca480fe3970c75bb79c0a893e47b..2f0c89cbac763bfdb5d8434bc19768df8b8f977b 100644 (file)
@@ -78,7 +78,8 @@ void hdpvr_delete(struct hdpvr_device *dev)
 
 static void challenge(u8 *bytes)
 {
-       u64 *i64P, tmp64;
+       __le64 *i64P;
+       u64 tmp64;
        uint i, idx;
 
        for (idx = 0; idx < 32; ++idx) {
@@ -106,10 +107,10 @@ static void challenge(u8 *bytes)
                        for (i = 0; i < 3; i++)
                                bytes[1] *= bytes[6] + 1;
                        for (i = 0; i < 3; i++) {
-                               i64P = (u64 *)bytes;
+                               i64P = (__le64 *)bytes;
                                tmp64 = le64_to_cpup(i64P);
-                               tmp64 <<= bytes[7] & 0x0f;
-                               *i64P += cpu_to_le64(tmp64);
+                               tmp64 = tmp64 + (tmp64 << (bytes[7] & 0x0f));
+                               *i64P = cpu_to_le64(tmp64);
                        }
                        break;
                }
@@ -301,8 +302,6 @@ static int hdpvr_probe(struct usb_interface *interface,
                goto error;
        }
 
-       dev->workqueue = 0;
-
        /* init video transfer queues first of all */
        /* to prevent oops in hdpvr_delete() on error paths */
        INIT_LIST_HEAD(&dev->free_buff_list);
index c4d51d78f837771eafd6fb170cfc4f4feb7a9734..ea05f678b5597ee801c249fd3a22694df6f34edc 100644 (file)
@@ -2868,7 +2868,7 @@ static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
                pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
        }
 
-v4l2_std_id pvr2_hdw_get_detected_std(struct pvr2_hdw *hdw)
+static v4l2_std_id pvr2_hdw_get_detected_std(struct pvr2_hdw *hdw)
 {
        v4l2_std_id std;
        std = (v4l2_std_id)hdw->std_mask_avail;
index 03761c6f472f89d920823384930e8b71a23d56be..05bd91a60c09fe91d535aad8323cf0a49b48fe16 100644 (file)
@@ -209,8 +209,10 @@ static int smsusb_sendrequest(void *context, void *buffer, size_t size)
        struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;
        int dummy;
 
-       if (dev->state != SMSUSB_ACTIVE)
+       if (dev->state != SMSUSB_ACTIVE) {
+               sms_debug("Device not active yet");
                return -ENOENT;
+       }
 
        sms_debug("sending %s(%d) size: %d",
                  smscore_translate_msg(phdr->msg_type), phdr->msg_type,
@@ -243,6 +245,9 @@ static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id)
        int rc, dummy;
        char *fw_filename;
 
+       if (id < 0)
+               id = sms_get_board(board_id)->default_mode;
+
        if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
                sms_err("invalid firmware id specified %d", id);
                return -EINVAL;
@@ -445,14 +450,15 @@ static int smsusb_probe(struct usb_interface *intf,
        char devpath[32];
        int i, rc;
 
-       sms_info("interface number %d",
+       sms_info("board id=%lu, interface number %d",
+                id->driver_info,
                 intf->cur_altsetting->desc.bInterfaceNumber);
 
        if (sms_get_board(id->driver_info)->intf_num !=
            intf->cur_altsetting->desc.bInterfaceNumber) {
-               sms_err("interface number is %d expecting %d",
-                       sms_get_board(id->driver_info)->intf_num,
-                       intf->cur_altsetting->desc.bInterfaceNumber);
+               sms_debug("interface %d won't be used. Expecting interface %d to popup",
+                       intf->cur_altsetting->desc.bInterfaceNumber,
+                       sms_get_board(id->driver_info)->intf_num);
                return -ENODEV;
        }
 
@@ -483,22 +489,32 @@ static int smsusb_probe(struct usb_interface *intf,
        }
        if ((udev->actconfig->desc.bNumInterfaces == 2) &&
            (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
-               sms_err("rom interface 0 is not used");
+               sms_debug("rom interface 0 is not used");
                return -ENODEV;
        }
 
        if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) {
-               sms_info("stellar device was found.");
+               /* Detected a Siano Stellar uninitialized */
+
                snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
                         udev->bus->busnum, udev->devpath);
-               sms_info("stellar device was found.");
-               return smsusb1_load_firmware(
+               sms_info("stellar device in cold state was found at %s.", devpath);
+               rc = smsusb1_load_firmware(
                                udev, smscore_registry_getmode(devpath),
                                id->driver_info);
+
+               /* This device will reset and gain another USB ID */
+               if (!rc)
+                       sms_info("stellar device now in warm state");
+               else
+                       sms_err("Failed to put stellar in warm state. Error: %d", rc);
+
+               return rc;
+       } else {
+               rc = smsusb_init_device(intf, id->driver_info);
        }
 
-       rc = smsusb_init_device(intf, id->driver_info);
-       sms_info("rc %d", rc);
+       sms_info("Device initialized with return code %d", rc);
        sms_board_load_modules(id->driver_info);
        return rc;
 }
@@ -550,10 +566,13 @@ static int smsusb_resume(struct usb_interface *intf)
 }
 
 static const struct usb_device_id smsusb_id_table[] = {
+       /* This device is only present before firmware load */
        { USB_DEVICE(0x187f, 0x0010),
-               .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
+               .driver_info = SMS1XXX_BOARD_SIANO_STELLAR_ROM },
+       /* This device pops up after firmware load */
        { USB_DEVICE(0x187f, 0x0100),
                .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
+
        { USB_DEVICE(0x187f, 0x0200),
                .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
        { USB_DEVICE(0x187f, 0x0201),
index 95f94e5aa66d2a14910bc0b81eec3bf595534f02..3316caa4733b6a48951f14f8e3e483188e325eba 100644 (file)
@@ -232,7 +232,7 @@ static int firmware_download(struct usb_device *udev)
                goto out;
        }
 
-       max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize;
+       max_packet_size = le16_to_cpu(udev->ep_out[0x1]->desc.wMaxPacketSize);
        log("\t\t download size : %d", (int)max_packet_size);
 
        for (offset = 0; offset < fwlength; offset += max_packet_size) {
index e52c3b97f304d9b2dfcb1e32bb9a24a3c08f45c6..29724af9b9ab11fbb36c1871bacada0fde62409c 100644 (file)
@@ -366,7 +366,7 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
                }
                return 0;
        } else {
-               return -1;
+               return -ENOENT;
        }
 }
 
@@ -1241,6 +1241,8 @@ static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
 
 static int ttusb_dec_init_usb(struct ttusb_dec *dec)
 {
+       int result;
+
        dprintk("%s\n", __func__);
 
        mutex_init(&dec->usb_mutex);
@@ -1258,7 +1260,7 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
                        return -ENOMEM;
                }
                dec->irq_buffer = usb_alloc_coherent(dec->udev,IRQ_PACKET_SIZE,
-                                       GFP_ATOMIC, &dec->irq_dma_handle);
+                                       GFP_KERNEL, &dec->irq_dma_handle);
                if(!dec->irq_buffer) {
                        usb_free_urb(dec->irq_urb);
                        return -ENOMEM;
@@ -1270,7 +1272,13 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
                dec->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
        }
 
-       return ttusb_dec_alloc_iso_urbs(dec);
+       result = ttusb_dec_alloc_iso_urbs(dec);
+       if (result) {
+               usb_free_urb(dec->irq_urb);
+               usb_free_coherent(dec->udev, IRQ_PACKET_SIZE,
+                                 dec->irq_buffer, dec->irq_dma_handle);
+       }
+       return result;
 }
 
 static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
@@ -1293,10 +1301,11 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
 
        dprintk("%s\n", __func__);
 
-       if (request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev)) {
+       result = request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev);
+       if (result) {
                printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
                       __func__, dec->firmware_name);
-               return 1;
+               return result;
        }
 
        firmware = fw_entry->data;
@@ -1306,7 +1315,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
                printk("%s: firmware size too small for DSP code (%zu < 60).\n",
                        __func__, firmware_size);
                release_firmware(fw_entry);
-               return -1;
+               return -ENOENT;
        }
 
        /* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
@@ -1320,7 +1329,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
                       "0x%08x != 0x%08x in file), file invalid.\n",
                        __func__, crc32_csum, crc32_check);
                release_firmware(fw_entry);
-               return -1;
+               return -ENOENT;
        }
        memcpy(idstring, &firmware[36], 20);
        idstring[20] = '\0';
@@ -1389,55 +1398,48 @@ static int ttusb_dec_init_stb(struct ttusb_dec *dec)
        dprintk("%s\n", __func__);
 
        result = ttusb_dec_get_stb_state(dec, &mode, &model, &version);
+       if (result)
+               return result;
 
-       if (!result) {
-               if (!mode) {
-                       if (version == 0xABCDEFAB)
-                               printk(KERN_INFO "ttusb_dec: no version "
-                                      "info in Firmware\n");
-                       else
-                               printk(KERN_INFO "ttusb_dec: Firmware "
-                                      "%x.%02x%c%c\n",
-                                      version >> 24, (version >> 16) & 0xff,
-                                      (version >> 8) & 0xff, version & 0xff);
-
-                       result = ttusb_dec_boot_dsp(dec);
-                       if (result)
-                               return result;
-                       else
-                               return 1;
-               } else {
-                       /* We can't trust the USB IDs that some firmwares
-                          give the box */
-                       switch (model) {
-                       case 0x00070001:
-                       case 0x00070008:
-                       case 0x0007000c:
-                               ttusb_dec_set_model(dec, TTUSB_DEC3000S);
-                               break;
-                       case 0x00070009:
-                       case 0x00070013:
-                               ttusb_dec_set_model(dec, TTUSB_DEC2000T);
-                               break;
-                       case 0x00070011:
-                               ttusb_dec_set_model(dec, TTUSB_DEC2540T);
-                               break;
-                       default:
-                               printk(KERN_ERR "%s: unknown model returned "
-                                      "by firmware (%08x) - please report\n",
-                                      __func__, model);
-                               return -1;
-                               break;
-                       }
+       if (!mode) {
+               if (version == 0xABCDEFAB)
+                       printk(KERN_INFO "ttusb_dec: no version "
+                              "info in Firmware\n");
+               else
+                       printk(KERN_INFO "ttusb_dec: Firmware "
+                              "%x.%02x%c%c\n",
+                              version >> 24, (version >> 16) & 0xff,
+                              (version >> 8) & 0xff, version & 0xff);
 
+               result = ttusb_dec_boot_dsp(dec);
+               if (result)
+                       return result;
+       } else {
+               /* We can't trust the USB IDs that some firmwares
+                  give the box */
+               switch (model) {
+               case 0x00070001:
+               case 0x00070008:
+               case 0x0007000c:
+                       ttusb_dec_set_model(dec, TTUSB_DEC3000S);
+                       break;
+               case 0x00070009:
+               case 0x00070013:
+                       ttusb_dec_set_model(dec, TTUSB_DEC2000T);
+                       break;
+               case 0x00070011:
+                       ttusb_dec_set_model(dec, TTUSB_DEC2540T);
+                       break;
+               default:
+                       printk(KERN_ERR "%s: unknown model returned "
+                              "by firmware (%08x) - please report\n",
+                              __func__, model);
+                       return -ENOENT;
+               }
                        if (version >= 0x01770000)
                                dec->can_playback = 1;
-
-                       return 0;
-               }
        }
-       else
-               return result;
+       return 0;
 }
 
 static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
@@ -1539,19 +1541,7 @@ static void ttusb_dec_exit_dvb(struct ttusb_dec *dec)
 
 static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
 {
-
        dprintk("%s\n", __func__);
-       /* we have to check whether the irq URB is already submitted.
-         * As the irq is submitted after the interface is changed,
-         * this is the best method i figured out.
-         * Any others?*/
-       if (dec->interface == TTUSB_DEC_INTERFACE_IN)
-               usb_kill_urb(dec->irq_urb);
-
-       usb_free_urb(dec->irq_urb);
-
-       usb_free_coherent(dec->udev,IRQ_PACKET_SIZE,
-                         dec->irq_buffer, dec->irq_dma_handle);
 
        if (dec->rc_input_dev) {
                input_unregister_device(dec->rc_input_dev);
@@ -1566,6 +1556,20 @@ static void ttusb_dec_exit_usb(struct ttusb_dec *dec)
 
        dprintk("%s\n", __func__);
 
+       if (enable_rc) {
+               /* we have to check whether the irq URB is already submitted.
+                * As the irq is submitted after the interface is changed,
+                * this is the best method i figured out.
+                * Any others?*/
+               if (dec->interface == TTUSB_DEC_INTERFACE_IN)
+                       usb_kill_urb(dec->irq_urb);
+
+               usb_free_urb(dec->irq_urb);
+
+               usb_free_coherent(dec->udev, IRQ_PACKET_SIZE,
+                                 dec->irq_buffer, dec->irq_dma_handle);
+       }
+
        dec->iso_stream_count = 0;
 
        for (i = 0; i < ISO_BUF_COUNT; i++)
@@ -1623,6 +1627,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
 {
        struct usb_device *udev;
        struct ttusb_dec *dec;
+       int result;
 
        dprintk("%s\n", __func__);
 
@@ -1651,13 +1656,15 @@ static int ttusb_dec_probe(struct usb_interface *intf,
 
        dec->udev = udev;
 
-       if (ttusb_dec_init_usb(dec))
-               return 0;
-       if (ttusb_dec_init_stb(dec)) {
-               ttusb_dec_exit_usb(dec);
-               return 0;
-       }
-       ttusb_dec_init_dvb(dec);
+       result = ttusb_dec_init_usb(dec);
+       if (result)
+               goto err_usb;
+       result = ttusb_dec_init_stb(dec);
+       if (result)
+               goto err_stb;
+       result = ttusb_dec_init_dvb(dec);
+       if (result)
+               goto err_stb;
 
        dec->adapter.priv = dec;
        switch (id->idProduct) {
@@ -1696,6 +1703,11 @@ static int ttusb_dec_probe(struct usb_interface *intf,
                ttusb_init_rc(dec);
 
        return 0;
+err_stb:
+       ttusb_dec_exit_usb(dec);
+err_usb:
+       kfree(dec);
+       return result;
 }
 
 static void ttusb_dec_disconnect(struct usb_interface *intf)
index a2f4501c23ca3502d57be595afb6f6e91b84c903..0eb82106d2ff4015bc8cee2e0159626b8ba4ad8e 100644 (file)
@@ -664,7 +664,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
                .size           = 32,
                .offset         = 0,
                .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
-               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
        },
        {
                .id             = V4L2_CID_TILT_ABSOLUTE,
@@ -674,7 +674,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
                .size           = 32,
                .offset         = 32,
                .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
-               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
        },
        {
                .id             = V4L2_CID_PRIVACY,
index 3394c34320117542ccab9adc4607a1caedb18f53..899cb6d1c4a4a74a68cae01dbea51de5befc821e 100644 (file)
@@ -680,7 +680,8 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
                  stream->dev->name,
                  sof >> 16, div_u64(((u64)sof & 0xffff) * 1000000LLU, 65536),
                  y, ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC,
-                 v4l2_buf->timestamp.tv_sec, v4l2_buf->timestamp.tv_usec,
+                 v4l2_buf->timestamp.tv_sec,
+                 (unsigned long)v4l2_buf->timestamp.tv_usec,
                  x1, first->host_sof, first->dev_sof,
                  x2, last->host_sof, last->dev_sof, y1, y2);
 
index ddc9379eb2769c308198cb17bc9afde4e4067fb3..20c09229a08ed7063cc05a02a30909c3c7fe7bd6 100644 (file)
@@ -43,7 +43,7 @@
 
 #define UNSET (-1U)
 
-#define PREFIX (t->i2c->driver->driver.name)
+#define PREFIX (t->i2c->dev.driver->name)
 
 /*
  * Driver modprobe parameters
@@ -247,7 +247,7 @@ static const struct analog_demod_ops tuner_analog_ops = {
 /**
  * set_type - Sets the tuner type for a given device
  *
- * @c:                 i2c_client descriptoy
+ * @c:                 i2c_client descriptor
  * @type:              type of the tuner (e. g. tuner number)
  * @new_mode_mask:     Indicates if tuner supports TV and/or Radio
  * @new_config:                an optional parameter used by a few tuners to adjust
@@ -452,7 +452,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
        }
 
        tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
-                 c->adapter->name, c->driver->driver.name, c->addr << 1, type,
+                 c->adapter->name, c->dev.driver->name, c->addr << 1, type,
                  t->mode_mask);
        return;
 
@@ -556,7 +556,7 @@ static void tuner_lookup(struct i2c_adapter *adap,
                int mode_mask;
 
                if (pos->i2c->adapter != adap ||
-                   strcmp(pos->i2c->driver->driver.name, "tuner"))
+                   strcmp(pos->i2c->dev.driver->name, "tuner"))
                        continue;
 
                mode_mask = pos->mode_mask;
index c85d69da35bdee1b2c0f82ac9deb395e8450b786..85a6a34128a8ecfcba63c372886bcc00cadf74d7 100644 (file)
@@ -189,30 +189,53 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
        struct v4l2_subdev *sd, *tmp;
        unsigned int notif_n_subdev = notifier->num_subdevs;
        unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS);
-       struct device *dev[n_subdev];
+       struct device **dev;
        int i = 0;
 
        if (!notifier->v4l2_dev)
                return;
 
+       dev = kmalloc(n_subdev * sizeof(*dev), GFP_KERNEL);
+       if (!dev) {
+               dev_err(notifier->v4l2_dev->dev,
+                       "Failed to allocate device cache!\n");
+       }
+
        mutex_lock(&list_lock);
 
        list_del(&notifier->list);
 
        list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
-               dev[i] = get_device(sd->dev);
+               struct device *d;
+
+               d = get_device(sd->dev);
 
                v4l2_async_cleanup(sd);
 
                /* If we handled USB devices, we'd have to lock the parent too */
-               device_release_driver(dev[i++]);
+               device_release_driver(d);
 
                if (notifier->unbind)
                        notifier->unbind(notifier, sd, sd->asd);
+
+               /*
+                * Store device at the device cache, in order to call
+                * put_device() on the final step
+                */
+               if (dev)
+                       dev[i++] = d;
+               else
+                       put_device(d);
        }
 
        mutex_unlock(&list_lock);
 
+       /*
+        * Call device_attach() to reprobe devices
+        *
+        * NOTE: If dev allocation fails, i is 0, and the whole loop won't be
+        * executed.
+        */
        while (i--) {
                struct device *d = dev[i];
 
@@ -228,6 +251,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
                }
                put_device(d);
        }
+       kfree(dev);
 
        notifier->v4l2_dev = NULL;
 
index b67de8642b5ab3a675ef8e7ed62f35a361045f89..e18cc0469cf8271fcaccae98a4cb676cfa12c200 100644 (file)
@@ -240,3 +240,42 @@ void v4l2_clk_unregister(struct v4l2_clk *clk)
        kfree(clk);
 }
 EXPORT_SYMBOL(v4l2_clk_unregister);
+
+struct v4l2_clk_fixed {
+       unsigned long rate;
+       struct v4l2_clk_ops ops;
+};
+
+static unsigned long fixed_get_rate(struct v4l2_clk *clk)
+{
+       struct v4l2_clk_fixed *priv = clk->priv;
+       return priv->rate;
+}
+
+struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
+               const char *id, unsigned long rate, struct module *owner)
+{
+       struct v4l2_clk *clk;
+       struct v4l2_clk_fixed *priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+
+       if (!priv)
+               return ERR_PTR(-ENOMEM);
+
+       priv->rate = rate;
+       priv->ops.get_rate = fixed_get_rate;
+       priv->ops.owner = owner;
+
+       clk = v4l2_clk_register(&priv->ops, dev_id, id, priv);
+       if (IS_ERR(clk))
+               kfree(priv);
+
+       return clk;
+}
+EXPORT_SYMBOL(__v4l2_clk_register_fixed);
+
+void v4l2_clk_unregister_fixed(struct v4l2_clk *clk)
+{
+       kfree(clk->priv);
+       v4l2_clk_unregister(clk);
+}
+EXPORT_SYMBOL(v4l2_clk_unregister_fixed);
index 037d7a55aa8c6c0595987d9142630a6ea2c7f5b7..433d6d77942eeeab78fa7282fdb77ccb3648a0e8 100644 (file)
@@ -236,14 +236,14 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
        v4l2_subdev_init(sd, ops);
        sd->flags |= V4L2_SUBDEV_FL_IS_I2C;
        /* the owner is the same as the i2c_client's driver owner */
-       sd->owner = client->driver->driver.owner;
+       sd->owner = client->dev.driver->owner;
        sd->dev = &client->dev;
        /* i2c_client and v4l2_subdev point to one another */
        v4l2_set_subdevdata(sd, client);
        i2c_set_clientdata(client, sd);
        /* initialize name */
        snprintf(sd->name, sizeof(sd->name), "%s %d-%04x",
-               client->driver->driver.name, i2c_adapter_id(client->adapter),
+               client->dev.driver->name, i2c_adapter_id(client->adapter),
                client->addr);
 }
 EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
@@ -274,11 +274,11 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
           loaded. This delay-load mechanism doesn't work if other drivers
           want to use the i2c device, so explicitly loading the module
           is the best alternative. */
-       if (client == NULL || client->driver == NULL)
+       if (client == NULL || client->dev.driver == NULL)
                goto error;
 
        /* Lock the module so we can safely get the v4l2_subdev pointer */
-       if (!try_module_get(client->driver->driver.owner))
+       if (!try_module_get(client->dev.driver->owner))
                goto error;
        sd = i2c_get_clientdata(client);
 
@@ -287,7 +287,7 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
        if (v4l2_device_register_subdev(v4l2_dev, sd))
                sd = NULL;
        /* Decrease the module use count to match the first try_module_get. */
-       module_put(client->driver->driver.owner);
+       module_put(client->dev.driver->owner);
 
 error:
        /* If we have a client but no subdev, then something went wrong and
index c3f0803886843d3b3c0ac8abd8474cf23dddd301..60dcc0f3b32e7b445352b455d377f5b2b794b4fb 100644 (file)
@@ -565,13 +565,13 @@ EXPORT_SYMBOL(v4l2_ctrl_get_menu);
  * Returns NULL or an s64 type array containing the menu for given
  * control ID. The total number of the menu items is returned in @len.
  */
-const s64 const *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
+const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
 {
-       static const s64 const qmenu_int_vpx_num_partitions[] = {
+       static const s64 qmenu_int_vpx_num_partitions[] = {
                1, 2, 4, 8,
        };
 
-       static const s64 const qmenu_int_vpx_num_ref_frames[] = {
+       static const s64 qmenu_int_vpx_num_ref_frames[] = {
                1, 2, 3,
        };
 
@@ -583,7 +583,7 @@ const s64 const *v4l2_ctrl_get_int_menu(u32 id, u32 *len)
        default:
                *len = 0;
                return NULL;
-       };
+       }
 }
 EXPORT_SYMBOL(v4l2_ctrl_get_int_menu);
 
index 7c43712882158787e951ba9a923fa86d1eb67f90..73035ee0f4def8c7425872dba6c1687419b1303f 100644 (file)
@@ -41,6 +41,8 @@ module_param(debug, bool, 0644);
 #define TRANS_QUEUED           (1 << 0)
 /* Instance is currently running in hardware */
 #define TRANS_RUNNING          (1 << 1)
+/* Instance is currently aborting */
+#define TRANS_ABORT            (1 << 2)
 
 
 /* Offset base for buffers on the destination queue - used to distinguish
@@ -221,6 +223,14 @@ static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
        }
 
        spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
+
+       /* If the context is aborted then don't schedule it */
+       if (m2m_ctx->job_flags & TRANS_ABORT) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+               dprintk("Aborted context\n");
+               return;
+       }
+
        if (m2m_ctx->job_flags & TRANS_QUEUED) {
                spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
                dprintk("On job queue already\n");
@@ -280,6 +290,8 @@ static void v4l2_m2m_cancel_job(struct v4l2_m2m_ctx *m2m_ctx)
 
        m2m_dev = m2m_ctx->m2m_dev;
        spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+
+       m2m_ctx->job_flags |= TRANS_ABORT;
        if (m2m_ctx->job_flags & TRANS_RUNNING) {
                spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
                m2m_dev->m2m_ops->job_abort(m2m_ctx->priv);
@@ -480,13 +492,15 @@ int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
        m2m_dev = m2m_ctx->m2m_dev;
        spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
        /* We should not be scheduled anymore, since we're dropping a queue. */
-       INIT_LIST_HEAD(&m2m_ctx->queue);
+       if (m2m_ctx->job_flags & TRANS_QUEUED)
+               list_del(&m2m_ctx->queue);
        m2m_ctx->job_flags = 0;
 
        spin_lock_irqsave(&q_ctx->rdy_spinlock, flags);
        /* Drop queue, since streamoff returns device to the same state as after
         * calling reqbufs. */
        INIT_LIST_HEAD(&q_ctx->rdy_queue);
+       q_ctx->num_rdy = 0;
        spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags);
 
        if (m2m_dev->curr_ctx == m2m_ctx) {
index de0e87f0b2c3a833f113121709b9a496d29ef1f3..b19b306c8f7f533d3112db441f692e57bd76638d 100644 (file)
@@ -241,7 +241,8 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
                q->bufs[q->num_buffers + buffer] = vb;
        }
 
-       __setup_offsets(q, buffer);
+       if (memory == V4L2_MEMORY_MMAP)
+               __setup_offsets(q, buffer);
 
        dprintk(1, "Allocated %d buffers, %d plane(s) each\n",
                        buffer, num_planes);
@@ -1015,6 +1016,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 
                /* Check if the provided plane buffer is large enough */
                if (planes[plane].length < q->plane_sizes[plane]) {
+                       dprintk(1, "qbuf: provided buffer size %u is less than "
+                                               "setup size %u for plane %d\n",
+                                               planes[plane].length,
+                                               q->plane_sizes[plane], plane);
                        ret = -EINVAL;
                        goto err;
                }
@@ -1205,8 +1210,11 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
        int ret;
 
        ret = __verify_length(vb, b);
-       if (ret < 0)
+       if (ret < 0) {
+               dprintk(1, "%s(): plane parameters verification failed: %d\n",
+                       __func__, ret);
                return ret;
+       }
 
        switch (q->memory) {
        case V4L2_MEMORY_MMAP:
@@ -2469,10 +2477,11 @@ size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
 }
 EXPORT_SYMBOL_GPL(vb2_read);
 
-size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count,
+size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
                loff_t *ppos, int nonblocking)
 {
-       return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 0);
+       return __vb2_perform_fileio(q, (char __user *) data, count,
+                                                       ppos, nonblocking, 0);
 }
 EXPORT_SYMBOL_GPL(vb2_write);
 
@@ -2633,7 +2642,7 @@ int vb2_fop_release(struct file *file)
 }
 EXPORT_SYMBOL_GPL(vb2_fop_release);
 
-ssize_t vb2_fop_write(struct file *file, char __user *buf,
+ssize_t vb2_fop_write(struct file *file, const char __user *buf,
                size_t count, loff_t *ppos)
 {
        struct video_device *vdev = video_devdata(file);
index 16ae3dcc7e294cdb4722d0991b31b9e6ac7cacf0..2f860543912cd1c3f5dd4f286705b2c8b208dc37 100644 (file)
@@ -35,17 +35,61 @@ struct vb2_dma_sg_buf {
        struct page                     **pages;
        int                             write;
        int                             offset;
-       struct vb2_dma_sg_desc          sg_desc;
+       struct sg_table                 sg_table;
+       size_t                          size;
+       unsigned int                    num_pages;
        atomic_t                        refcount;
        struct vb2_vmarea_handler       handler;
 };
 
 static void vb2_dma_sg_put(void *buf_priv);
 
+static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,
+               gfp_t gfp_flags)
+{
+       unsigned int last_page = 0;
+       int size = buf->size;
+
+       while (size > 0) {
+               struct page *pages;
+               int order;
+               int i;
+
+               order = get_order(size);
+               /* Dont over allocate*/
+               if ((PAGE_SIZE << order) > size)
+                       order--;
+
+               pages = NULL;
+               while (!pages) {
+                       pages = alloc_pages(GFP_KERNEL | __GFP_ZERO |
+                                       __GFP_NOWARN | gfp_flags, order);
+                       if (pages)
+                               break;
+
+                       if (order == 0) {
+                               while (last_page--)
+                                       __free_page(buf->pages[last_page]);
+                               return -ENOMEM;
+                       }
+                       order--;
+               }
+
+               split_page(pages, order);
+               for (i = 0; i < (1 << order); i++)
+                       buf->pages[last_page++] = &pages[i];
+
+               size -= PAGE_SIZE << order;
+       }
+
+       return 0;
+}
+
 static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags)
 {
        struct vb2_dma_sg_buf *buf;
-       int i;
+       int ret;
+       int num_pages;
 
        buf = kzalloc(sizeof *buf, GFP_KERNEL);
        if (!buf)
@@ -54,29 +98,23 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_fla
        buf->vaddr = NULL;
        buf->write = 0;
        buf->offset = 0;
-       buf->sg_desc.size = size;
+       buf->size = size;
        /* size is already page aligned */
-       buf->sg_desc.num_pages = size >> PAGE_SHIFT;
+       buf->num_pages = size >> PAGE_SHIFT;
 
-       buf->sg_desc.sglist = vzalloc(buf->sg_desc.num_pages *
-                                     sizeof(*buf->sg_desc.sglist));
-       if (!buf->sg_desc.sglist)
-               goto fail_sglist_alloc;
-       sg_init_table(buf->sg_desc.sglist, buf->sg_desc.num_pages);
-
-       buf->pages = kzalloc(buf->sg_desc.num_pages * sizeof(struct page *),
+       buf->pages = kzalloc(buf->num_pages * sizeof(struct page *),
                             GFP_KERNEL);
        if (!buf->pages)
                goto fail_pages_array_alloc;
 
-       for (i = 0; i < buf->sg_desc.num_pages; ++i) {
-               buf->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO |
-                                          __GFP_NOWARN | gfp_flags);
-               if (NULL == buf->pages[i])
-                       goto fail_pages_alloc;
-               sg_set_page(&buf->sg_desc.sglist[i],
-                           buf->pages[i], PAGE_SIZE, 0);
-       }
+       ret = vb2_dma_sg_alloc_compacted(buf, gfp_flags);
+       if (ret)
+               goto fail_pages_alloc;
+
+       ret = sg_alloc_table_from_pages(&buf->sg_table, buf->pages,
+                       buf->num_pages, 0, size, gfp_flags);
+       if (ret)
+               goto fail_table_alloc;
 
        buf->handler.refcount = &buf->refcount;
        buf->handler.put = vb2_dma_sg_put;
@@ -85,18 +123,16 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_fla
        atomic_inc(&buf->refcount);
 
        dprintk(1, "%s: Allocated buffer of %d pages\n",
-               __func__, buf->sg_desc.num_pages);
+               __func__, buf->num_pages);
        return buf;
 
+fail_table_alloc:
+       num_pages = buf->num_pages;
+       while (num_pages--)
+               __free_page(buf->pages[num_pages]);
 fail_pages_alloc:
-       while (--i >= 0)
-               __free_page(buf->pages[i]);
        kfree(buf->pages);
-
 fail_pages_array_alloc:
-       vfree(buf->sg_desc.sglist);
-
-fail_sglist_alloc:
        kfree(buf);
        return NULL;
 }
@@ -104,14 +140,14 @@ fail_sglist_alloc:
 static void vb2_dma_sg_put(void *buf_priv)
 {
        struct vb2_dma_sg_buf *buf = buf_priv;
-       int i = buf->sg_desc.num_pages;
+       int i = buf->num_pages;
 
        if (atomic_dec_and_test(&buf->refcount)) {
                dprintk(1, "%s: Freeing buffer of %d pages\n", __func__,
-                       buf->sg_desc.num_pages);
+                       buf->num_pages);
                if (buf->vaddr)
-                       vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages);
-               vfree(buf->sg_desc.sglist);
+                       vm_unmap_ram(buf->vaddr, buf->num_pages);
+               sg_free_table(&buf->sg_table);
                while (--i >= 0)
                        __free_page(buf->pages[i]);
                kfree(buf->pages);
@@ -124,7 +160,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
 {
        struct vb2_dma_sg_buf *buf;
        unsigned long first, last;
-       int num_pages_from_user, i;
+       int num_pages_from_user;
 
        buf = kzalloc(sizeof *buf, GFP_KERNEL);
        if (!buf)
@@ -133,56 +169,41 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
        buf->vaddr = NULL;
        buf->write = write;
        buf->offset = vaddr & ~PAGE_MASK;
-       buf->sg_desc.size = size;
+       buf->size = size;
 
        first = (vaddr           & PAGE_MASK) >> PAGE_SHIFT;
        last  = ((vaddr + size - 1) & PAGE_MASK) >> PAGE_SHIFT;
-       buf->sg_desc.num_pages = last - first + 1;
-
-       buf->sg_desc.sglist = vzalloc(
-               buf->sg_desc.num_pages * sizeof(*buf->sg_desc.sglist));
-       if (!buf->sg_desc.sglist)
-               goto userptr_fail_sglist_alloc;
-
-       sg_init_table(buf->sg_desc.sglist, buf->sg_desc.num_pages);
+       buf->num_pages = last - first + 1;
 
-       buf->pages = kzalloc(buf->sg_desc.num_pages * sizeof(struct page *),
+       buf->pages = kzalloc(buf->num_pages * sizeof(struct page *),
                             GFP_KERNEL);
        if (!buf->pages)
-               goto userptr_fail_pages_array_alloc;
+               return NULL;
 
        num_pages_from_user = get_user_pages(current, current->mm,
                                             vaddr & PAGE_MASK,
-                                            buf->sg_desc.num_pages,
+                                            buf->num_pages,
                                             write,
                                             1, /* force */
                                             buf->pages,
                                             NULL);
 
-       if (num_pages_from_user != buf->sg_desc.num_pages)
+       if (num_pages_from_user != buf->num_pages)
                goto userptr_fail_get_user_pages;
 
-       sg_set_page(&buf->sg_desc.sglist[0], buf->pages[0],
-                   PAGE_SIZE - buf->offset, buf->offset);
-       size -= PAGE_SIZE - buf->offset;
-       for (i = 1; i < buf->sg_desc.num_pages; ++i) {
-               sg_set_page(&buf->sg_desc.sglist[i], buf->pages[i],
-                           min_t(size_t, PAGE_SIZE, size), 0);
-               size -= min_t(size_t, PAGE_SIZE, size);
-       }
+       if (sg_alloc_table_from_pages(&buf->sg_table, buf->pages,
+                       buf->num_pages, buf->offset, size, 0))
+               goto userptr_fail_alloc_table_from_pages;
+
        return buf;
 
+userptr_fail_alloc_table_from_pages:
 userptr_fail_get_user_pages:
        dprintk(1, "get_user_pages requested/got: %d/%d]\n",
-              num_pages_from_user, buf->sg_desc.num_pages);
+              num_pages_from_user, buf->num_pages);
        while (--num_pages_from_user >= 0)
                put_page(buf->pages[num_pages_from_user]);
        kfree(buf->pages);
-
-userptr_fail_pages_array_alloc:
-       vfree(buf->sg_desc.sglist);
-
-userptr_fail_sglist_alloc:
        kfree(buf);
        return NULL;
 }
@@ -194,18 +215,18 @@ userptr_fail_sglist_alloc:
 static void vb2_dma_sg_put_userptr(void *buf_priv)
 {
        struct vb2_dma_sg_buf *buf = buf_priv;
-       int i = buf->sg_desc.num_pages;
+       int i = buf->num_pages;
 
        dprintk(1, "%s: Releasing userspace buffer of %d pages\n",
-              __func__, buf->sg_desc.num_pages);
+              __func__, buf->num_pages);
        if (buf->vaddr)
-               vm_unmap_ram(buf->vaddr, buf->sg_desc.num_pages);
+               vm_unmap_ram(buf->vaddr, buf->num_pages);
+       sg_free_table(&buf->sg_table);
        while (--i >= 0) {
                if (buf->write)
                        set_page_dirty_lock(buf->pages[i]);
                put_page(buf->pages[i]);
        }
-       vfree(buf->sg_desc.sglist);
        kfree(buf->pages);
        kfree(buf);
 }
@@ -218,7 +239,7 @@ static void *vb2_dma_sg_vaddr(void *buf_priv)
 
        if (!buf->vaddr)
                buf->vaddr = vm_map_ram(buf->pages,
-                                       buf->sg_desc.num_pages,
+                                       buf->num_pages,
                                        -1,
                                        PAGE_KERNEL);
 
@@ -274,7 +295,7 @@ static void *vb2_dma_sg_cookie(void *buf_priv)
 {
        struct vb2_dma_sg_buf *buf = buf_priv;
 
-       return &buf->sg_desc;
+       return &buf->sg_table;
 }
 
 const struct vb2_mem_ops vb2_dma_sg_memops = {
index 7ebe9ef1eba663006399ec1b52f327e3fd3d0e47..c9b1f6422941eeaf628a0f7a65fd4e65053a8a14 100644 (file)
@@ -1247,7 +1247,7 @@ static struct i2c_driver pm860x_driver = {
                .name   = "88PM860x",
                .owner  = THIS_MODULE,
                .pm     = &pm860x_pm_ops,
-               .of_match_table = of_match_ptr(pm860x_dt_ids),
+               .of_match_table = pm860x_dt_ids,
        },
        .probe          = pm860x_probe,
        .remove         = pm860x_remove,
index 914c3d142f789f0a517d32e59f53b457b61c2089..62a60caa5d1fe7eb583cb208fef9b96a5b0dd8f0 100644 (file)
@@ -27,6 +27,18 @@ config MFD_AS3711
        help
          Support for the AS3711 PMIC from AMS
 
+config MFD_AS3722
+       bool "ams AS3722 Power Management IC"
+       select MFD_CORE
+       select REGMAP_I2C
+       select REGMAP_IRQ
+       depends on I2C && OF
+       help
+         The ams AS3722 is a compact system PMU suitable for mobile phones,
+         tablets etc. It has 4 DC/DC step-down regulators, 3 DC/DC step-down
+         controllers, 11 LDOs, RTC, automatic battery, temperature and
+         over current monitoring, GPIOs, ADC and a watchdog.
+
 config PMIC_ADP5520
        bool "Analog Devices ADP5520/01 MFD PMIC Core Support"
        depends on I2C=y
@@ -664,14 +676,14 @@ menu "STMicroelectronics STMPE Interface Drivers"
 depends on MFD_STMPE
 
 config STMPE_I2C
-       bool "STMicroelectronics STMPE I2C Inteface"
+       bool "STMicroelectronics STMPE I2C Interface"
        depends on I2C=y
        default y
        help
          This is used to enable I2C interface of STMPE
 
 config STMPE_SPI
-       bool "STMicroelectronics STMPE SPI Inteface"
+       bool "STMicroelectronics STMPE SPI Interface"
        depends on SPI_MASTER
        help
          This is used to enable SPI interface of STMPE
@@ -1151,6 +1163,16 @@ config MFD_WM8994
          core support for the WM8994, in order to use the actual
          functionaltiy of the device other drivers must be enabled.
 
+config MFD_STW481X
+       bool "Support for ST Microelectronics STw481x"
+       depends on I2C && ARCH_NOMADIK
+       select REGMAP_I2C
+       select MFD_CORE
+       help
+         Select this option to enable the STw481x chip driver used
+         in various ST Microelectronics and ST-Ericsson embedded
+         Nomadik series.
+
 endmenu
 endif
 
index 15b905c6553c07e7953b7cc4b57c63fcd5ad06a1..8a28dc90fe785033452a1740973f34883abbe0de 100644 (file)
@@ -162,3 +162,5 @@ obj-$(CONFIG_MFD_LM3533)    += lm3533-core.o lm3533-ctrlbank.o
 obj-$(CONFIG_VEXPRESS_CONFIG)  += vexpress-config.o vexpress-sysreg.o
 obj-$(CONFIG_MFD_RETU)         += retu-mfd.o
 obj-$(CONFIG_MFD_AS3711)       += as3711.o
+obj-$(CONFIG_MFD_AS3722)       += as3722.o
+obj-$(CONFIG_MFD_STW481X)      += stw481x.o
index 6f68472e0ca633e9b0ec5f08db4f1389af93336e..14d9542a4eed8d1408c556c781795e0c24869a9c 100644 (file)
@@ -293,7 +293,7 @@ static ssize_t aat2870_reg_write_file(struct file *file,
        unsigned long addr, val;
        int ret;
 
-       buf_size = min(count, (sizeof(buf)-1));
+       buf_size = min(count, (size_t)(sizeof(buf)-1));
        if (copy_from_user(buf, user_buf, buf_size)) {
                dev_err(aat2870->dev, "Failed to copy from user\n");
                return -EFAULT;
index 022b1863d36cdf5af689be720a972baef3a54820..75e180ceecf3fac16f9a432ada482130624dfe01 100644 (file)
@@ -540,7 +540,7 @@ static int arizona_of_get_core_pdata(struct arizona *arizona)
                for (i = 0; i < ARRAY_SIZE(arizona->pdata.gpio_defaults); i++) {
                        if (arizona->pdata.gpio_defaults[i] > 0xffff)
                                arizona->pdata.gpio_defaults[i] = 0;
-                       if (arizona->pdata.gpio_defaults[i] == 0)
+                       else if (arizona->pdata.gpio_defaults[i] == 0)
                                arizona->pdata.gpio_defaults[i] = 0x10000;
                }
        } else {
@@ -633,11 +633,11 @@ int arizona_dev_init(struct arizona *arizona)
        dev_set_drvdata(arizona->dev, arizona);
        mutex_init(&arizona->clk_lock);
 
-       arizona_of_get_core_pdata(arizona);
-
        if (dev_get_platdata(arizona->dev))
                memcpy(&arizona->pdata, dev_get_platdata(arizona->dev),
                       sizeof(arizona->pdata));
+       else
+               arizona_of_get_core_pdata(arizona);
 
        regcache_cache_only(arizona->regmap, true);
 
index 51dbabf7c0217f185323869ae1259f75aa7925a4..beccb790c9bab93869015044142666dc786b9508 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #include <linux/mfd/arizona/core.h>
 
index 47be7b35b5c5b09c9e17c4ef0cb7dae32b0c2855..1ca554b18bef76c8dd92156a2c9bf7ed87127fc3 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
+#include <linux/of.h>
 
 #include <linux/mfd/arizona/core.h>
 
index abd3ab7c0908ab6232f0e7d82a35361ca33c46c7..ec684fcedb42c5cd5be4178151d0ee5c7249a6b9 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mfd/as3711.h>
 #include <linux/mfd/core.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
diff --git a/drivers/mfd/as3722.c b/drivers/mfd/as3722.c
new file mode 100644 (file)
index 0000000..f161f2e
--- /dev/null
@@ -0,0 +1,449 @@
+/*
+ * Core driver for ams AS3722 PMICs
+ *
+ * Copyright (C) 2013 AMS AG
+ * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
+ *
+ * Author: Florian Lobmaier <florian.lobmaier@ams.com>
+ * Author: Laxman Dewangan <ldewangan@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/as3722.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+
+#define AS3722_DEVICE_ID       0x0C
+
+static const struct resource as3722_rtc_resource[] = {
+       {
+               .name = "as3722-rtc-alarm",
+               .start = AS3722_IRQ_RTC_ALARM,
+               .end = AS3722_IRQ_RTC_ALARM,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static const struct resource as3722_adc_resource[] = {
+       {
+               .name = "as3722-adc",
+               .start = AS3722_IRQ_ADC,
+               .end = AS3722_IRQ_ADC,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct mfd_cell as3722_devs[] = {
+       {
+               .name = "as3722-pinctrl",
+       },
+       {
+               .name = "as3722-regulator",
+       },
+       {
+               .name = "as3722-rtc",
+               .num_resources = ARRAY_SIZE(as3722_rtc_resource),
+               .resources = as3722_rtc_resource,
+       },
+       {
+               .name = "as3722-adc",
+               .num_resources = ARRAY_SIZE(as3722_adc_resource),
+               .resources = as3722_adc_resource,
+       },
+       {
+               .name = "as3722-power-off",
+       },
+};
+
+static const struct regmap_irq as3722_irqs[] = {
+       /* INT1 IRQs */
+       [AS3722_IRQ_LID] = {
+               .mask = AS3722_INTERRUPT_MASK1_LID,
+       },
+       [AS3722_IRQ_ACOK] = {
+               .mask = AS3722_INTERRUPT_MASK1_ACOK,
+       },
+       [AS3722_IRQ_ENABLE1] = {
+               .mask = AS3722_INTERRUPT_MASK1_ENABLE1,
+       },
+       [AS3722_IRQ_OCCUR_ALARM_SD0] = {
+               .mask = AS3722_INTERRUPT_MASK1_OCURR_ALARM_SD0,
+       },
+       [AS3722_IRQ_ONKEY_LONG_PRESS] = {
+               .mask = AS3722_INTERRUPT_MASK1_ONKEY_LONG,
+       },
+       [AS3722_IRQ_ONKEY] = {
+               .mask = AS3722_INTERRUPT_MASK1_ONKEY,
+       },
+       [AS3722_IRQ_OVTMP] = {
+               .mask = AS3722_INTERRUPT_MASK1_OVTMP,
+       },
+       [AS3722_IRQ_LOWBAT] = {
+               .mask = AS3722_INTERRUPT_MASK1_LOWBAT,
+       },
+
+       /* INT2 IRQs */
+       [AS3722_IRQ_SD0_LV] = {
+               .mask = AS3722_INTERRUPT_MASK2_SD0_LV,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_SD1_LV] = {
+               .mask = AS3722_INTERRUPT_MASK2_SD1_LV,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_SD2_LV] = {
+               .mask = AS3722_INTERRUPT_MASK2_SD2345_LV,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_PWM1_OV_PROT] = {
+               .mask = AS3722_INTERRUPT_MASK2_PWM1_OV_PROT,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_PWM2_OV_PROT] = {
+               .mask = AS3722_INTERRUPT_MASK2_PWM2_OV_PROT,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_ENABLE2] = {
+               .mask = AS3722_INTERRUPT_MASK2_ENABLE2,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_SD6_LV] = {
+               .mask = AS3722_INTERRUPT_MASK2_SD6_LV,
+               .reg_offset = 1,
+       },
+       [AS3722_IRQ_RTC_REP] = {
+               .mask = AS3722_INTERRUPT_MASK2_RTC_REP,
+               .reg_offset = 1,
+       },
+
+       /* INT3 IRQs */
+       [AS3722_IRQ_RTC_ALARM] = {
+               .mask = AS3722_INTERRUPT_MASK3_RTC_ALARM,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_GPIO1] = {
+               .mask = AS3722_INTERRUPT_MASK3_GPIO1,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_GPIO2] = {
+               .mask = AS3722_INTERRUPT_MASK3_GPIO2,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_GPIO3] = {
+               .mask = AS3722_INTERRUPT_MASK3_GPIO3,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_GPIO4] = {
+               .mask = AS3722_INTERRUPT_MASK3_GPIO4,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_GPIO5] = {
+               .mask = AS3722_INTERRUPT_MASK3_GPIO5,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_WATCHDOG] = {
+               .mask = AS3722_INTERRUPT_MASK3_WATCHDOG,
+               .reg_offset = 2,
+       },
+       [AS3722_IRQ_ENABLE3] = {
+               .mask = AS3722_INTERRUPT_MASK3_ENABLE3,
+               .reg_offset = 2,
+       },
+
+       /* INT4 IRQs */
+       [AS3722_IRQ_TEMP_SD0_SHUTDOWN] = {
+               .mask = AS3722_INTERRUPT_MASK4_TEMP_SD0_SHUTDOWN,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_TEMP_SD1_SHUTDOWN] = {
+               .mask = AS3722_INTERRUPT_MASK4_TEMP_SD1_SHUTDOWN,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_TEMP_SD2_SHUTDOWN] = {
+               .mask = AS3722_INTERRUPT_MASK4_TEMP_SD6_SHUTDOWN,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_TEMP_SD0_ALARM] = {
+               .mask = AS3722_INTERRUPT_MASK4_TEMP_SD0_ALARM,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_TEMP_SD1_ALARM] = {
+               .mask = AS3722_INTERRUPT_MASK4_TEMP_SD1_ALARM,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_TEMP_SD6_ALARM] = {
+               .mask = AS3722_INTERRUPT_MASK4_TEMP_SD6_ALARM,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_OCCUR_ALARM_SD6] = {
+               .mask = AS3722_INTERRUPT_MASK4_OCCUR_ALARM_SD6,
+               .reg_offset = 3,
+       },
+       [AS3722_IRQ_ADC] = {
+               .mask = AS3722_INTERRUPT_MASK4_ADC,
+               .reg_offset = 3,
+       },
+};
+
+static const struct regmap_irq_chip as3722_irq_chip = {
+       .name = "as3722",
+       .irqs = as3722_irqs,
+       .num_irqs = ARRAY_SIZE(as3722_irqs),
+       .num_regs = 4,
+       .status_base = AS3722_INTERRUPT_STATUS1_REG,
+       .mask_base = AS3722_INTERRUPT_MASK1_REG,
+};
+
+static int as3722_check_device_id(struct as3722 *as3722)
+{
+       u32 val;
+       int ret;
+
+       /* Check that this is actually a AS3722 */
+       ret = as3722_read(as3722, AS3722_ASIC_ID1_REG, &val);
+       if (ret < 0) {
+               dev_err(as3722->dev, "ASIC_ID1 read failed: %d\n", ret);
+               return ret;
+       }
+
+       if (val != AS3722_DEVICE_ID) {
+               dev_err(as3722->dev, "Device is not AS3722, ID is 0x%x\n", val);
+               return -ENODEV;
+       }
+
+       ret = as3722_read(as3722, AS3722_ASIC_ID2_REG, &val);
+       if (ret < 0) {
+               dev_err(as3722->dev, "ASIC_ID2 read failed: %d\n", ret);
+               return ret;
+       }
+
+       dev_info(as3722->dev, "AS3722 with revision 0x%x found\n", val);
+       return 0;
+}
+
+static int as3722_configure_pullups(struct as3722 *as3722)
+{
+       int ret;
+       u32 val = 0;
+
+       if (as3722->en_intern_int_pullup)
+               val |= AS3722_INT_PULL_UP;
+       if (as3722->en_intern_i2c_pullup)
+               val |= AS3722_I2C_PULL_UP;
+
+       ret = as3722_update_bits(as3722, AS3722_IOVOLTAGE_REG,
+                       AS3722_INT_PULL_UP | AS3722_I2C_PULL_UP, val);
+       if (ret < 0)
+               dev_err(as3722->dev, "IOVOLTAGE_REG update failed: %d\n", ret);
+       return ret;
+}
+
+static const struct regmap_range as3722_readable_ranges[] = {
+       regmap_reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_SD6_VOLTAGE_REG),
+       regmap_reg_range(AS3722_GPIO0_CONTROL_REG, AS3722_LDO7_VOLTAGE_REG),
+       regmap_reg_range(AS3722_LDO9_VOLTAGE_REG, AS3722_REG_SEQU_MOD3_REG),
+       regmap_reg_range(AS3722_SD_PHSW_CTRL_REG, AS3722_PWM_CONTROL_H_REG),
+       regmap_reg_range(AS3722_WATCHDOG_TIMER_REG, AS3722_WATCHDOG_TIMER_REG),
+       regmap_reg_range(AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG,
+                                       AS3722_BATTERY_VOLTAGE_MONITOR2_REG),
+       regmap_reg_range(AS3722_SD_CONTROL_REG, AS3722_PWM_VCONTROL4_REG),
+       regmap_reg_range(AS3722_BB_CHARGER_REG, AS3722_SRAM_REG),
+       regmap_reg_range(AS3722_RTC_ACCESS_REG, AS3722_RTC_ACCESS_REG),
+       regmap_reg_range(AS3722_RTC_STATUS_REG, AS3722_TEMP_STATUS_REG),
+       regmap_reg_range(AS3722_ADC0_CONTROL_REG, AS3722_ADC_CONFIGURATION_REG),
+       regmap_reg_range(AS3722_ASIC_ID1_REG, AS3722_ASIC_ID2_REG),
+       regmap_reg_range(AS3722_LOCK_REG, AS3722_LOCK_REG),
+};
+
+static const struct regmap_access_table as3722_readable_table = {
+       .yes_ranges = as3722_readable_ranges,
+       .n_yes_ranges = ARRAY_SIZE(as3722_readable_ranges),
+};
+
+static const struct regmap_range as3722_writable_ranges[] = {
+       regmap_reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_SD6_VOLTAGE_REG),
+       regmap_reg_range(AS3722_GPIO0_CONTROL_REG, AS3722_LDO7_VOLTAGE_REG),
+       regmap_reg_range(AS3722_LDO9_VOLTAGE_REG, AS3722_GPIO_SIGNAL_OUT_REG),
+       regmap_reg_range(AS3722_REG_SEQU_MOD1_REG, AS3722_REG_SEQU_MOD3_REG),
+       regmap_reg_range(AS3722_SD_PHSW_CTRL_REG, AS3722_PWM_CONTROL_H_REG),
+       regmap_reg_range(AS3722_WATCHDOG_TIMER_REG, AS3722_WATCHDOG_TIMER_REG),
+       regmap_reg_range(AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG,
+                                       AS3722_BATTERY_VOLTAGE_MONITOR2_REG),
+       regmap_reg_range(AS3722_SD_CONTROL_REG, AS3722_PWM_VCONTROL4_REG),
+       regmap_reg_range(AS3722_BB_CHARGER_REG, AS3722_SRAM_REG),
+       regmap_reg_range(AS3722_INTERRUPT_MASK1_REG, AS3722_TEMP_STATUS_REG),
+       regmap_reg_range(AS3722_ADC0_CONTROL_REG, AS3722_ADC1_CONTROL_REG),
+       regmap_reg_range(AS3722_ADC1_THRESHOLD_HI_MSB_REG,
+                                       AS3722_ADC_CONFIGURATION_REG),
+       regmap_reg_range(AS3722_LOCK_REG, AS3722_LOCK_REG),
+};
+
+static const struct regmap_access_table as3722_writable_table = {
+       .yes_ranges = as3722_writable_ranges,
+       .n_yes_ranges = ARRAY_SIZE(as3722_writable_ranges),
+};
+
+static const struct regmap_range as3722_cacheable_ranges[] = {
+       regmap_reg_range(AS3722_SD0_VOLTAGE_REG, AS3722_LDO11_VOLTAGE_REG),
+       regmap_reg_range(AS3722_SD_CONTROL_REG, AS3722_LDOCONTROL1_REG),
+};
+
+static const struct regmap_access_table as3722_volatile_table = {
+       .no_ranges = as3722_cacheable_ranges,
+       .n_no_ranges = ARRAY_SIZE(as3722_cacheable_ranges),
+};
+
+static const struct regmap_config as3722_regmap_config = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = AS3722_MAX_REGISTER,
+       .cache_type = REGCACHE_RBTREE,
+       .rd_table = &as3722_readable_table,
+       .wr_table = &as3722_writable_table,
+       .volatile_table = &as3722_volatile_table,
+};
+
+static int as3722_i2c_of_probe(struct i2c_client *i2c,
+                       struct as3722 *as3722)
+{
+       struct device_node *np = i2c->dev.of_node;
+       struct irq_data *irq_data;
+
+       if (!np) {
+               dev_err(&i2c->dev, "Device Tree not found\n");
+               return -EINVAL;
+       }
+
+       irq_data = irq_get_irq_data(i2c->irq);
+       if (!irq_data) {
+               dev_err(&i2c->dev, "Invalid IRQ: %d\n", i2c->irq);
+               return -EINVAL;
+       }
+
+       as3722->en_intern_int_pullup = of_property_read_bool(np,
+                                       "ams,enable-internal-int-pullup");
+       as3722->en_intern_i2c_pullup = of_property_read_bool(np,
+                                       "ams,enable-internal-i2c-pullup");
+       as3722->irq_flags = irqd_get_trigger_type(irq_data);
+       dev_dbg(&i2c->dev, "IRQ flags are 0x%08lx\n", as3722->irq_flags);
+       return 0;
+}
+
+static int as3722_i2c_probe(struct i2c_client *i2c,
+                       const struct i2c_device_id *id)
+{
+       struct as3722 *as3722;
+       unsigned long irq_flags;
+       int ret;
+
+       as3722 = devm_kzalloc(&i2c->dev, sizeof(struct as3722), GFP_KERNEL);
+       if (!as3722)
+               return -ENOMEM;
+
+       as3722->dev = &i2c->dev;
+       as3722->chip_irq = i2c->irq;
+       i2c_set_clientdata(i2c, as3722);
+
+       ret = as3722_i2c_of_probe(i2c, as3722);
+       if (ret < 0)
+               return ret;
+
+       as3722->regmap = devm_regmap_init_i2c(i2c, &as3722_regmap_config);
+       if (IS_ERR(as3722->regmap)) {
+               ret = PTR_ERR(as3722->regmap);
+               dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
+               return ret;
+       }
+
+       ret = as3722_check_device_id(as3722);
+       if (ret < 0)
+               return ret;
+
+       irq_flags = as3722->irq_flags | IRQF_ONESHOT;
+       ret = regmap_add_irq_chip(as3722->regmap, as3722->chip_irq,
+                       irq_flags, -1, &as3722_irq_chip,
+                       &as3722->irq_data);
+       if (ret < 0) {
+               dev_err(as3722->dev, "Failed to add regmap irq: %d\n", ret);
+               return ret;
+       }
+
+       ret = as3722_configure_pullups(as3722);
+       if (ret < 0)
+               goto scrub;
+
+       ret = mfd_add_devices(&i2c->dev, -1, as3722_devs,
+                       ARRAY_SIZE(as3722_devs), NULL, 0,
+                       regmap_irq_get_domain(as3722->irq_data));
+       if (ret) {
+               dev_err(as3722->dev, "Failed to add MFD devices: %d\n", ret);
+               goto scrub;
+       }
+
+       dev_dbg(as3722->dev, "AS3722 core driver initialized successfully\n");
+       return 0;
+
+scrub:
+       regmap_del_irq_chip(as3722->chip_irq, as3722->irq_data);
+       return ret;
+}
+
+static int as3722_i2c_remove(struct i2c_client *i2c)
+{
+       struct as3722 *as3722 = i2c_get_clientdata(i2c);
+
+       mfd_remove_devices(as3722->dev);
+       regmap_del_irq_chip(as3722->chip_irq, as3722->irq_data);
+       return 0;
+}
+
+static const struct of_device_id as3722_of_match[] = {
+       { .compatible = "ams,as3722", },
+       {},
+};
+MODULE_DEVICE_TABLE(of, as3722_of_match);
+
+static const struct i2c_device_id as3722_i2c_id[] = {
+       { "as3722", 0 },
+       {},
+};
+MODULE_DEVICE_TABLE(i2c, as3722_i2c_id);
+
+static struct i2c_driver as3722_i2c_driver = {
+       .driver = {
+               .name = "as3722",
+               .owner = THIS_MODULE,
+               .of_match_table = as3722_of_match,
+       },
+       .probe = as3722_i2c_probe,
+       .remove = as3722_i2c_remove,
+       .id_table = as3722_i2c_id,
+};
+
+module_i2c_driver(as3722_i2c_driver);
+
+MODULE_DESCRIPTION("I2C support for AS3722 PMICs");
+MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
+MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
+MODULE_LICENSE("GPL");
index 6a9fec40d018308a39e1ea24b086bfc94dfb77f0..c319c4ef5d499c9f59140adf941987ac6d024bb2 100644 (file)
@@ -86,7 +86,11 @@ static int da9052_i2c_fix(struct da9052 *da9052, unsigned char reg)
        return 0;
 }
 
-static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
+/*
+ * According to errata item 24, multiwrite mode should be avoided
+ * in order to prevent register data corruption after power-down.
+ */
+static int da9052_i2c_disable_multiwrite(struct da9052 *da9052)
 {
        int reg_val, ret;
 
@@ -94,8 +98,8 @@ static int da9052_i2c_enable_multiwrite(struct da9052 *da9052)
        if (ret < 0)
                return ret;
 
-       if (reg_val & DA9052_CONTROL_B_WRITEMODE) {
-               reg_val &= ~DA9052_CONTROL_B_WRITEMODE;
+       if (!(reg_val & DA9052_CONTROL_B_WRITEMODE)) {
+               reg_val |= DA9052_CONTROL_B_WRITEMODE;
                ret = regmap_write(da9052->regmap, DA9052_CONTROL_B_REG,
                                   reg_val);
                if (ret < 0)
@@ -154,7 +158,7 @@ static int da9052_i2c_probe(struct i2c_client *client,
                return ret;
        }
 
-       ret = da9052_i2c_enable_multiwrite(da9052);
+       ret = da9052_i2c_disable_multiwrite(da9052);
        if (ret < 0)
                return ret;
 
index 7245b0c5b794be489d1c5d250c196c92e028a48f..2ed774e7d342c64211bf862fdcbdf0cac3e57170 100644 (file)
@@ -394,16 +394,12 @@ static int pcap_add_subdev(struct pcap_chip *pcap,
 static int ezx_pcap_remove(struct spi_device *spi)
 {
        struct pcap_chip *pcap = spi_get_drvdata(spi);
-       struct pcap_platform_data *pdata = dev_get_platdata(&spi->dev);
-       int i, adc_irq;
+       int i;
 
        /* remove all registered subdevs */
        device_for_each_child(&spi->dev, NULL, pcap_remove_subdev);
 
        /* cleanup ADC */
-       adc_irq = pcap_to_irq(pcap, (pdata->config & PCAP_SECOND_PORT) ?
-                               PCAP_IRQ_ADCDONE2 : PCAP_IRQ_ADCDONE);
-       devm_free_irq(&spi->dev, adc_irq, pcap);
        mutex_lock(&pcap->adc_mutex);
        for (i = 0; i < PCAP_ADC_MAXQ; i++)
                kfree(pcap->adc_queue[i]);
@@ -509,8 +505,6 @@ static int ezx_pcap_probe(struct spi_device *spi)
 
 remove_subdevs:
        device_for_each_child(&spi->dev, NULL, pcap_remove_subdev);
-/* free_adc: */
-       devm_free_irq(&spi->dev, adc_irq, pcap);
 free_irqchip:
        for (i = pcap->irq_base; i < (pcap->irq_base + PCAP_NIRQS); i++)
                irq_set_chip_and_handler(i, NULL, NULL);
index 9483bc8472a51acbbc45a3f08b6072104a81e027..da1c6566d93d2f755878d358a018835bd7cd1454 100644 (file)
@@ -53,6 +53,7 @@
  *     document number TBD : Wellsburg
  *     document number TBD : Avoton SoC
  *     document number TBD : Coleto Creek
+ *     document number TBD : Wildcat Point-LP
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -211,6 +212,7 @@ enum lpc_chipsets {
        LPC_WBG,        /* Wellsburg */
        LPC_AVN,        /* Avoton SoC */
        LPC_COLETO,     /* Coleto Creek */
+       LPC_WPT_LP,     /* Wildcat Point-LP */
 };
 
 static struct lpc_ich_info lpc_chipset_info[] = {
@@ -503,6 +505,10 @@ static struct lpc_ich_info lpc_chipset_info[] = {
                .name = "Coleto Creek",
                .iTCO_version = 2,
        },
+       [LPC_WPT_LP] = {
+               .name = "Lynx Point_LP",
+               .iTCO_version = 2,
+       },
 };
 
 /*
@@ -721,6 +727,13 @@ static DEFINE_PCI_DEVICE_TABLE(lpc_ich_ids) = {
        { PCI_VDEVICE(INTEL, 0x1f3a), LPC_AVN},
        { PCI_VDEVICE(INTEL, 0x1f3b), LPC_AVN},
        { PCI_VDEVICE(INTEL, 0x2390), LPC_COLETO},
+       { PCI_VDEVICE(INTEL, 0x9cc1), LPC_WPT_LP},
+       { PCI_VDEVICE(INTEL, 0x9cc2), LPC_WPT_LP},
+       { PCI_VDEVICE(INTEL, 0x9cc3), LPC_WPT_LP},
+       { PCI_VDEVICE(INTEL, 0x9cc5), LPC_WPT_LP},
+       { PCI_VDEVICE(INTEL, 0x9cc6), LPC_WPT_LP},
+       { PCI_VDEVICE(INTEL, 0x9cc7), LPC_WPT_LP},
+       { PCI_VDEVICE(INTEL, 0x9cc9), LPC_WPT_LP},
        { 0, },                 /* End of list */
 };
 MODULE_DEVICE_TABLE(pci, lpc_ich_ids);
@@ -969,7 +982,6 @@ static int lpc_ich_probe(struct pci_dev *dev,
        if (!cell_added) {
                dev_warn(&dev->dev, "No MFD cells added\n");
                lpc_ich_restore_config_space(dev);
-               pci_set_drvdata(dev, NULL);
                return -ENODEV;
        }
 
@@ -980,7 +992,6 @@ static void lpc_ich_remove(struct pci_dev *dev)
 {
        mfd_remove_devices(&dev->dev);
        lpc_ich_restore_config_space(dev);
-       pci_set_drvdata(dev, NULL);
 }
 
 static struct pci_driver lpc_ich_driver = {
index 8cc6aac27cb2d5ef77b0c7894dc9670afcfae4a8..fbfbf0b7f97ac1cfad5d8964a7436fa05122a89f 100644 (file)
@@ -59,18 +59,21 @@ static struct mfd_cell isch_smbus_cell = {
        .name = "isch_smbus",
        .num_resources = 1,
        .resources = &smbus_sch_resource,
+       .ignore_resource_conflicts = true,
 };
 
 static struct mfd_cell sch_gpio_cell = {
        .name = "sch_gpio",
        .num_resources = 1,
        .resources = &gpio_sch_resource,
+       .ignore_resource_conflicts = true,
 };
 
 static struct mfd_cell wdt_sch_cell = {
        .name = "ie6xx_wdt",
        .num_resources = 1,
        .resources = &wdt_sch_resource,
+       .ignore_resource_conflicts = true,
 };
 
 static DEFINE_PCI_DEVICE_TABLE(lpc_sch_ids) = {
index 522be67b2e682d743c36534005fb09737cfcf590..34520cbe8afbd6e9f0daca77f4bbde41b93697a6 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/mfd/max77686.h>
 #include <linux/mfd/max77686-private.h>
 #include <linux/err.h>
+#include <linux/of.h>
 
 #define I2C_ADDR_RTC   (0x0C >> 1)
 
index 1029d018c73921828f34740b4034c0cd7df5c3bd..66b58fe770944d714c69b57107924b17c8ff4fff 100644 (file)
@@ -128,7 +128,8 @@ static void max77693_irq_sync_unlock(struct irq_data *data)
 static const inline struct max77693_irq_data *
 irq_to_max77693_irq(struct max77693_dev *max77693, int irq)
 {
-       return &max77693_irqs[irq];
+       struct irq_data *data = irq_get_irq_data(irq);
+       return &max77693_irqs[data->hwirq];
 }
 
 static void max77693_irq_mask(struct irq_data *data)
index c04723efc70709d4dd81db288be1fa11fc6deccb..9f92463f4f7ecaca1b005a14e6cd59f7d38deb4a 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/i2c.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
+#include <linux/of.h>
 #include <linux/pm_runtime.h>
 #include <linux/mutex.h>
 #include <linux/mfd/core.h>
@@ -110,15 +111,9 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
                              const struct i2c_device_id *id)
 {
        struct max77693_dev *max77693;
-       struct max77693_platform_data *pdata = dev_get_platdata(&i2c->dev);
        u8 reg_data;
        int ret = 0;
 
-       if (!pdata) {
-               dev_err(&i2c->dev, "No platform data found.\n");
-               return -EINVAL;
-       }
-
        max77693 = devm_kzalloc(&i2c->dev,
                        sizeof(struct max77693_dev), GFP_KERNEL);
        if (max77693 == NULL)
@@ -138,8 +133,6 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
                return ret;
        }
 
-       max77693->wakeup = pdata->wakeup;
-
        ret = max77693_read_reg(max77693->regmap, MAX77693_PMIC_REG_PMIC_ID2,
                                &reg_data);
        if (ret < 0) {
@@ -179,8 +172,6 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
        if (ret < 0)
                goto err_mfd;
 
-       device_init_wakeup(max77693->dev, pdata->wakeup);
-
        return ret;
 
 err_mfd:
@@ -235,11 +226,19 @@ static const struct dev_pm_ops max77693_pm = {
        .resume = max77693_resume,
 };
 
+#ifdef CONFIG_OF
+static struct of_device_id max77693_dt_match[] = {
+       { .compatible = "maxim,max77693" },
+       {},
+};
+#endif
+
 static struct i2c_driver max77693_i2c_driver = {
        .driver = {
                   .name = "max77693",
                   .owner = THIS_MODULE,
                   .pm = &max77693_pm,
+                  .of_match_table = of_match_ptr(max77693_dt_match),
        },
        .probe = max77693_i2c_probe,
        .remove = max77693_i2c_remove,
index e9b1c93a3ade36ba41de62bff0bd588fd4148162..3bbfedc07f41c8e24d866120b64423374c629fa3 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/max8907.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
index de7fb80a60528e8f3bcbc2c45e934dcfa5a65181..176aa26fc787eae4ba7196edcfae535d22ae50be 100644 (file)
@@ -238,7 +238,7 @@ static struct i2c_driver max8925_driver = {
                .name   = "max8925",
                .owner  = THIS_MODULE,
                .pm     = &max8925_pm_ops,
-               .of_match_table = of_match_ptr(max8925_dt_ids),
+               .of_match_table = max8925_dt_ids,
        },
        .probe          = max8925_probe,
        .remove         = max8925_remove,
index cee098c0dae36ef4ef9baf9d3fb07ec11e24913f..791aea3e96ce27622032a0c0fd1bc52ecd69203e 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/interrupt.h>
 #include <linux/pm_runtime.h>
index f745e27ee874a469e734cebd2757542388a0d10d..898bd335cd8ee99d7d8a2c233ef455801941ff30 100644 (file)
@@ -78,7 +78,6 @@ static int mc13xxx_i2c_probe(struct i2c_client *client,
                ret = PTR_ERR(mc13xxx->regmap);
                dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",
                                ret);
-               dev_set_drvdata(&client->dev, NULL);
                return ret;
        }
 
index adc8ea36e7c483e5f9ee05e1587d3fd1b6029719..2676492447378e989b019d05e223b622afb2c79c 100644 (file)
@@ -64,7 +64,8 @@ int mfd_cell_disable(struct platform_device *pdev)
 EXPORT_SYMBOL(mfd_cell_disable);
 
 static int mfd_platform_add_cell(struct platform_device *pdev,
-                                const struct mfd_cell *cell)
+                                const struct mfd_cell *cell,
+                                atomic_t *usage_count)
 {
        if (!cell)
                return 0;
@@ -73,11 +74,12 @@ static int mfd_platform_add_cell(struct platform_device *pdev,
        if (!pdev->mfd_cell)
                return -ENOMEM;
 
+       pdev->mfd_cell->usage_count = usage_count;
        return 0;
 }
 
 static int mfd_add_device(struct device *parent, int id,
-                         const struct mfd_cell *cell,
+                         const struct mfd_cell *cell, atomic_t *usage_count,
                          struct resource *mem_base,
                          int irq_base, struct irq_domain *domain)
 {
@@ -123,7 +125,7 @@ static int mfd_add_device(struct device *parent, int id,
                        goto fail_alias;
        }
 
-       ret = mfd_platform_add_cell(pdev, cell);
+       ret = mfd_platform_add_cell(pdev, cell, usage_count);
        if (ret)
                goto fail_alias;
 
@@ -192,12 +194,12 @@ fail_alloc:
 }
 
 int mfd_add_devices(struct device *parent, int id,
-                   struct mfd_cell *cells, int n_devs,
+                   const struct mfd_cell *cells, int n_devs,
                    struct resource *mem_base,
                    int irq_base, struct irq_domain *domain)
 {
        int i;
-       int ret = 0;
+       int ret;
        atomic_t *cnts;
 
        /* initialize reference counting for all cells */
@@ -207,16 +209,19 @@ int mfd_add_devices(struct device *parent, int id,
 
        for (i = 0; i < n_devs; i++) {
                atomic_set(&cnts[i], 0);
-               cells[i].usage_count = &cnts[i];
-               ret = mfd_add_device(parent, id, cells + i, mem_base,
+               ret = mfd_add_device(parent, id, cells + i, cnts + i, mem_base,
                                     irq_base, domain);
                if (ret)
-                       break;
+                       goto fail;
        }
 
-       if (ret)
-               mfd_remove_devices(parent);
+       return 0;
 
+fail:
+       if (i)
+               mfd_remove_devices(parent);
+       else
+               kfree(cnts);
        return ret;
 }
 EXPORT_SYMBOL(mfd_add_devices);
@@ -271,8 +276,8 @@ int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones)
        for (i = 0; i < n_clones; i++) {
                cell_entry.name = clones[i];
                /* don't give up if a single call fails; just report error */
-               if (mfd_add_device(pdev->dev.parent, -1, &cell_entry, NULL, 0,
-                                  NULL))
+               if (mfd_add_device(pdev->dev.parent, -1, &cell_entry,
+                                  cell_entry.usage_count, NULL, 0, NULL))
                        dev_err(dev, "failed to create platform device '%s'\n",
                                        clones[i]);
        }
index 29ee54d68512e3ce38dad4b5d6897f192b8295f8..142650fdc0582e1d25f99480e4a2fb13e1e9bd23 100644 (file)
@@ -328,13 +328,13 @@ static int usbhs_runtime_resume(struct device *dev)
        omap_tll_enable(pdata);
 
        if (!IS_ERR(omap->ehci_logic_fck))
-               clk_enable(omap->ehci_logic_fck);
+               clk_prepare_enable(omap->ehci_logic_fck);
 
        for (i = 0; i < omap->nports; i++) {
                switch (pdata->port_mode[i]) {
                case OMAP_EHCI_PORT_MODE_HSIC:
                        if (!IS_ERR(omap->hsic60m_clk[i])) {
-                               r = clk_enable(omap->hsic60m_clk[i]);
+                               r = clk_prepare_enable(omap->hsic60m_clk[i]);
                                if (r) {
                                        dev_err(dev,
                                         "Can't enable port %d hsic60m clk:%d\n",
@@ -343,7 +343,7 @@ static int usbhs_runtime_resume(struct device *dev)
                        }
 
                        if (!IS_ERR(omap->hsic480m_clk[i])) {
-                               r = clk_enable(omap->hsic480m_clk[i]);
+                               r = clk_prepare_enable(omap->hsic480m_clk[i]);
                                if (r) {
                                        dev_err(dev,
                                         "Can't enable port %d hsic480m clk:%d\n",
@@ -354,7 +354,7 @@ static int usbhs_runtime_resume(struct device *dev)
 
                case OMAP_EHCI_PORT_MODE_TLL:
                        if (!IS_ERR(omap->utmi_clk[i])) {
-                               r = clk_enable(omap->utmi_clk[i]);
+                               r = clk_prepare_enable(omap->utmi_clk[i]);
                                if (r) {
                                        dev_err(dev,
                                         "Can't enable port %d clk : %d\n",
@@ -382,15 +382,15 @@ static int usbhs_runtime_suspend(struct device *dev)
                switch (pdata->port_mode[i]) {
                case OMAP_EHCI_PORT_MODE_HSIC:
                        if (!IS_ERR(omap->hsic60m_clk[i]))
-                               clk_disable(omap->hsic60m_clk[i]);
+                               clk_disable_unprepare(omap->hsic60m_clk[i]);
 
                        if (!IS_ERR(omap->hsic480m_clk[i]))
-                               clk_disable(omap->hsic480m_clk[i]);
+                               clk_disable_unprepare(omap->hsic480m_clk[i]);
                /* Fall through as utmi_clks were used in HSIC mode */
 
                case OMAP_EHCI_PORT_MODE_TLL:
                        if (!IS_ERR(omap->utmi_clk[i]))
-                               clk_disable(omap->utmi_clk[i]);
+                               clk_disable_unprepare(omap->utmi_clk[i]);
                        break;
                default:
                        break;
@@ -398,7 +398,7 @@ static int usbhs_runtime_suspend(struct device *dev)
        }
 
        if (!IS_ERR(omap->ehci_logic_fck))
-               clk_disable(omap->ehci_logic_fck);
+               clk_disable_unprepare(omap->ehci_logic_fck);
 
        omap_tll_disable(pdata);
 
@@ -893,7 +893,7 @@ static struct platform_driver usbhs_omap_driver = {
                .name           = (char *)usbhs_driver_name,
                .owner          = THIS_MODULE,
                .pm             = &usbhsomap_dev_pm_ops,
-               .of_match_table = of_match_ptr(usbhs_omap_dt_ids),
+               .of_match_table = usbhs_omap_dt_ids,
        },
        .remove         = usbhs_omap_remove,
 };
index e59ac4cbac96136c7cf34607030a408428c6b3a9..0d946ae14453380e4abca019a09519627309c5b6 100644 (file)
@@ -320,7 +320,7 @@ static struct platform_driver usbtll_omap_driver = {
        .driver = {
                .name           = (char *)usbtll_driver_name,
                .owner          = THIS_MODULE,
-               .of_match_table = of_match_ptr(usbtll_omap_dt_ids),
+               .of_match_table = usbtll_omap_dt_ids,
        },
        .probe          = usbtll_omap_probe,
        .remove         = usbtll_omap_remove,
@@ -429,7 +429,7 @@ int omap_tll_enable(struct usbhs_omap_platform_data *pdata)
                        if (IS_ERR(tll->ch_clk[i]))
                                continue;
 
-                       r = clk_enable(tll->ch_clk[i]);
+                       r = clk_prepare_enable(tll->ch_clk[i]);
                        if (r) {
                                dev_err(tll_dev,
                                 "Error enabling ch %d clock: %d\n", i, r);
@@ -460,7 +460,7 @@ int omap_tll_disable(struct usbhs_omap_platform_data *pdata)
        for (i = 0; i < tll->nch; i++) {
                if (omap_usb_mode_needs_tll(pdata->port_mode[i])) {
                        if (!IS_ERR(tll->ch_clk[i]))
-                               clk_disable(tll->ch_clk[i]);
+                               clk_disable_unprepare(tll->ch_clk[i]);
                }
        }
 
index 135afabe4ae2ae850a6897ddad06dc1969dba301..d280d789e55a5cc0a60896eee95ad8de3ee1dac8 100644 (file)
@@ -368,6 +368,7 @@ static const struct of_device_id of_palmas_match_tbl[] = {
        },
        { },
 };
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
 
 static int palmas_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
@@ -402,7 +403,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
        palmas->dev = &i2c->dev;
        palmas->irq = i2c->irq;
 
-       match = of_match_device(of_match_ptr(of_palmas_match_tbl), &i2c->dev);
+       match = of_match_device(of_palmas_match_tbl, &i2c->dev);
 
        if (!match)
                return -ENODATA;
@@ -421,7 +422,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
                                dev_err(palmas->dev,
                                        "can't attach client %d\n", i);
                                ret = -ENOMEM;
-                               goto err;
+                               goto err_i2c;
                        }
                        palmas->i2c_clients[i]->dev.of_node = of_node_get(node);
                }
@@ -432,7 +433,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
                        dev_err(palmas->dev,
                                "Failed to allocate regmap %d, err: %d\n",
                                i, ret);
-                       goto err;
+                       goto err_i2c;
                }
        }
 
@@ -451,7 +452,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
                        reg);
        if (ret < 0) {
                dev_err(palmas->dev, "POLARITY_CTRL updat failed: %d\n", ret);
-               goto err;
+               goto err_i2c;
        }
 
        /* Change IRQ into clear on read mode for efficiency */
@@ -465,7 +466,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
                        IRQF_ONESHOT | pdata->irq_flags, 0, &palmas_irq_chip,
                        &palmas->irq_data);
        if (ret < 0)
-               goto err;
+               goto err_i2c;
 
 no_irq:
        slave = PALMAS_BASE_TO_SLAVE(PALMAS_PU_PD_OD_BASE);
@@ -551,7 +552,6 @@ no_irq:
                } else if (pdata->pm_off && !pm_power_off) {
                        palmas_dev = palmas;
                        pm_power_off = palmas_power_off;
-                       return ret;
                }
        }
 
@@ -559,17 +559,31 @@ no_irq:
 
 err_irq:
        regmap_del_irq_chip(palmas->irq, palmas->irq_data);
-err:
+err_i2c:
+       for (i = 1; i < PALMAS_NUM_CLIENTS; i++) {
+               if (palmas->i2c_clients[i])
+                       i2c_unregister_device(palmas->i2c_clients[i]);
+       }
        return ret;
 }
 
 static int palmas_i2c_remove(struct i2c_client *i2c)
 {
        struct palmas *palmas = i2c_get_clientdata(i2c);
+       int i;
 
-       mfd_remove_devices(palmas->dev);
        regmap_del_irq_chip(palmas->irq, palmas->irq_data);
 
+       for (i = 1; i < PALMAS_NUM_CLIENTS; i++) {
+               if (palmas->i2c_clients[i])
+                       i2c_unregister_device(palmas->i2c_clients[i]);
+       }
+
+       if (palmas == palmas_dev) {
+               pm_power_off = NULL;
+               palmas_dev = NULL;
+       }
+
        return 0;
 }
 
index a6841f77aa5e709d472b120336e25e5572646cf8..484fe66e6c884e7f32c9c9caca6473bcfc5b81e2 100644 (file)
@@ -171,11 +171,12 @@ static int pm8921_remove(struct platform_device *pdev)
        drvdata = platform_get_drvdata(pdev);
        if (drvdata)
                pmic = drvdata->pm_chip_data;
-       if (pmic)
+       if (pmic) {
                mfd_remove_devices(pmic->dev);
-       if (pmic->irq_chip) {
-               pm8xxx_irq_exit(pmic->irq_chip);
-               pmic->irq_chip = NULL;
+               if (pmic->irq_chip) {
+                       pm8xxx_irq_exit(pmic->irq_chip);
+                       pmic->irq_chip = NULL;
+               }
        }
 
        return 0;
index 3b835f593e35294a4666c25872eb911e9726b131..573de7bfcced0be23098434759a16505291f0e75 100644 (file)
@@ -130,13 +130,57 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
 {
        int err;
 
-       err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV, 0xFE46);
+       err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV,
+                       PHY_REG_REV_RESV | PHY_REG_REV_RXIDLE_LATCHED |
+                       PHY_REG_REV_P1_EN | PHY_REG_REV_RXIDLE_EN |
+                       PHY_REG_REV_RX_PWST | PHY_REG_REV_CLKREQ_DLY_TIMER_1_0 |
+                       PHY_REG_REV_STOP_CLKRD | PHY_REG_REV_STOP_CLKWR);
        if (err < 0)
                return err;
 
        msleep(1);
 
-       return rtsx_pci_write_phy_register(pcr, PHY_BPCR, 0x05C0);
+       err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
+                       PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
+                       PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
+       if (err < 0)
+               return err;
+       err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
+                       PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
+                       PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
+                       PHY_PCR_RSSI_EN);
+       if (err < 0)
+               return err;
+       err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
+                       PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
+                       PHY_RCR2_CDR_CP_10 | PHY_RCR2_CDR_SR_2 |
+                       PHY_RCR2_FREQSEL_12 | PHY_RCR2_CPADJEN |
+                       PHY_RCR2_CDR_SC_8 | PHY_RCR2_CALIB_LATE);
+       if (err < 0)
+               return err;
+       err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
+                       PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
+                       PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
+                       PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
+                       PHY_FLD4_BER_CHK_EN);
+       if (err < 0)
+               return err;
+       err = rtsx_pci_write_phy_register(pcr, PHY_RDR, PHY_RDR_RXDSEL_1_9);
+       if (err < 0)
+               return err;
+       err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
+                       PHY_RCR1_ADP_TIME | PHY_RCR1_VCO_COARSE);
+       if (err < 0)
+               return err;
+       err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
+                       PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
+                       PHY_FLD3_RXDELINK);
+       if (err < 0)
+               return err;
+       return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
+                       PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
+                       PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
+                       PHY_TUNE_TUNED12);
 }
 
 static int rts5249_turn_on_led(struct rtsx_pcr *pcr)
index e6ae7720f9e15bd546362509bca185c7a64eb86f..11e20afbdcacb7d31e49798db6d2dfbf0504afd8 100644 (file)
@@ -1149,7 +1149,7 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
        pcr->remap_addr = ioremap_nocache(base, len);
        if (!pcr->remap_addr) {
                ret = -ENOMEM;
-               goto free_host;
+               goto free_handle;
        }
 
        pcr->rtsx_resv_buf = dma_alloc_coherent(&(pcidev->dev),
@@ -1209,8 +1209,6 @@ disable_msi:
                        pcr->rtsx_resv_buf, pcr->rtsx_resv_buf_addr);
 unmap:
        iounmap(pcr->remap_addr);
-free_host:
-       dev_set_drvdata(&pcidev->dev, NULL);
 free_handle:
        kfree(handle);
 free_pcr:
@@ -1242,7 +1240,6 @@ static void rtsx_pci_remove(struct pci_dev *pcidev)
                pci_disable_msi(pcr->pci);
        iounmap(pcr->remap_addr);
 
-       dev_set_drvdata(&pcidev->dev, NULL);
        pci_release_regions(pcidev);
        pci_disable_device(pcidev);
 
index f530e4b73f19abd63fe42ba7f18230dba79c088f..34c18fb8c0896b46f49de48b4d5631a5d780a811 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/interrupt.h>
 #include <linux/pm_runtime.h>
index 33f040c558d090aca5887356bdd1cd2bbb11f461..c2c8c91c6c7b3188180301e85c6a4ce5ffff0c77 100644 (file)
@@ -1232,7 +1232,7 @@ static ssize_t sm501_dbg_regs(struct device *dev,
 }
 
 
-static DEVICE_ATTR(dbg_regs, 0666, sm501_dbg_regs, NULL);
+static DEVICE_ATTR(dbg_regs, 0444, sm501_dbg_regs, NULL);
 
 /* sm501_init_reg
  *
@@ -1660,7 +1660,6 @@ static int sm501_pci_probe(struct pci_dev *dev,
  err3:
        pci_disable_device(dev);
  err2:
-       pci_set_drvdata(dev, NULL);
        kfree(sm);
  err1:
        return err;
@@ -1695,7 +1694,6 @@ static void sm501_pci_remove(struct pci_dev *dev)
        release_resource(sm->regs_claim);
        kfree(sm->regs_claim);
 
-       pci_set_drvdata(dev, NULL);
        pci_disable_device(dev);
 }
 
diff --git a/drivers/mfd/stw481x.c b/drivers/mfd/stw481x.c
new file mode 100644 (file)
index 0000000..1243d5c
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * Core driver for STw4810/STw4811
+ *
+ * Copyright (C) 2013 ST-Ericsson SA
+ * Written on behalf of Linaro for ST-Ericsson
+ *
+ * Author: Linus Walleij <linus.walleij@linaro.org>
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/stw481x.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+
+/*
+ * This driver can only access the non-USB portions of STw4811, the register
+ * range 0x00-0x10 dealing with USB is bound to the two special I2C pins used
+ * for USB control.
+ */
+
+/* Registers inside the power control address space */
+#define STW_PC_VCORE_SEL       0x05U
+#define STW_PC_VAUX_SEL                0x06U
+#define STW_PC_VPLL_SEL                0x07U
+
+/**
+ * stw481x_get_pctl_reg() - get a power control register
+ * @stw481x: handle to the stw481x chip
+ * @reg: power control register to fetch
+ *
+ * The power control registers is a set of one-time-programmable registers
+ * in its own register space, accessed by writing addess bits to these
+ * two registers: bits 7,6,5 of PCTL_REG_LO corresponds to the 3 LSBs of
+ * the address and bits 8,9 of PCTL_REG_HI corresponds to the 2 MSBs of
+ * the address, forming an address space of 5 bits, i.e. 32 registers
+ * 0x00 ... 0x1f can be obtained.
+ */
+static int stw481x_get_pctl_reg(struct stw481x *stw481x, u8 reg)
+{
+       u8 msb = (reg >> 3) & 0x03;
+       u8 lsb = (reg << 5) & 0xe0;
+       unsigned int val;
+       u8 vrfy;
+       int ret;
+
+       ret = regmap_write(stw481x->map, STW_PCTL_REG_HI, msb);
+       if (ret)
+               return ret;
+       ret = regmap_write(stw481x->map, STW_PCTL_REG_LO, lsb);
+       if (ret)
+               return ret;
+       ret = regmap_read(stw481x->map, STW_PCTL_REG_HI, &val);
+       if (ret)
+               return ret;
+       vrfy = (val & 0x03) << 3;
+       ret = regmap_read(stw481x->map, STW_PCTL_REG_LO, &val);
+       if (ret)
+               return ret;
+       vrfy |= ((val >> 5) & 0x07);
+       if (vrfy != reg)
+               return -EIO;
+       return (val >> 1) & 0x0f;
+}
+
+static int stw481x_startup(struct stw481x *stw481x)
+{
+       /* Voltages multiplied by 100 */
+       u8 vcore_val[] = { 100, 105, 110, 115, 120, 122, 124, 126, 128,
+                          130, 132, 134, 136, 138, 140, 145 };
+       u8 vpll_val[] = { 105, 120, 130, 180 };
+       u8 vaux_val[] = { 15, 18, 25, 28 };
+       u8 vcore;
+       u8 vcore_slp;
+       u8 vpll;
+       u8 vaux;
+       bool vaux_en;
+       bool it_warn;
+       int ret;
+       unsigned int val;
+
+       ret = regmap_read(stw481x->map, STW_CONF1, &val);
+       if (ret)
+               return ret;
+       vaux_en = !!(val & STW_CONF1_PDN_VAUX);
+       it_warn = !!(val & STW_CONF1_IT_WARN);
+
+       dev_info(&stw481x->client->dev, "voltages %s\n",
+               (val & STW_CONF1_V_MONITORING) ? "OK" : "LOW");
+       dev_info(&stw481x->client->dev, "MMC level shifter %s\n",
+               (val & STW_CONF1_MMC_LS_STATUS) ? "high impedance" : "ON");
+       dev_info(&stw481x->client->dev, "VMMC: %s\n",
+               (val & STW_CONF1_PDN_VMMC) ? "ON" : "disabled");
+
+       dev_info(&stw481x->client->dev, "STw481x power control registers:\n");
+
+       ret = stw481x_get_pctl_reg(stw481x, STW_PC_VCORE_SEL);
+       if (ret < 0)
+               return ret;
+       vcore = ret & 0x0f;
+
+       ret = stw481x_get_pctl_reg(stw481x, STW_PC_VAUX_SEL);
+       if (ret < 0)
+               return ret;
+       vaux = (ret >> 2) & 3;
+       vpll = (ret >> 4) & 1; /* Save bit 4 */
+
+       ret = stw481x_get_pctl_reg(stw481x, STW_PC_VPLL_SEL);
+       if (ret < 0)
+               return ret;
+       vpll |= (ret >> 1) & 2;
+
+       dev_info(&stw481x->client->dev, "VCORE: %u.%uV %s\n",
+               vcore_val[vcore] / 100, vcore_val[vcore] % 100,
+               (ret & 4) ? "ON" : "OFF");
+
+       dev_info(&stw481x->client->dev, "VPLL:  %u.%uV %s\n",
+               vpll_val[vpll] / 100, vpll_val[vpll] % 100,
+               (ret & 0x10) ? "ON" : "OFF");
+
+       dev_info(&stw481x->client->dev, "VAUX:  %u.%uV %s\n",
+               vaux_val[vaux] / 10, vaux_val[vaux] % 10,
+               vaux_en ? "ON" : "OFF");
+
+       ret = regmap_read(stw481x->map, STW_CONF2, &val);
+       if (ret)
+               return ret;
+
+       dev_info(&stw481x->client->dev, "TWARN: %s threshold, %s\n",
+               it_warn ? "below" : "above",
+               (val & STW_CONF2_MASK_TWARN) ?
+                "enabled" : "mask through VDDOK");
+       dev_info(&stw481x->client->dev, "VMMC: %s\n",
+               (val & STW_CONF2_VMMC_EXT) ? "internal" : "external");
+       dev_info(&stw481x->client->dev, "IT WAKE UP: %s\n",
+               (val & STW_CONF2_MASK_IT_WAKE_UP) ? "enabled" : "masked");
+       dev_info(&stw481x->client->dev, "GPO1: %s\n",
+               (val & STW_CONF2_GPO1) ? "low" : "high impedance");
+       dev_info(&stw481x->client->dev, "GPO2: %s\n",
+               (val & STW_CONF2_GPO2) ? "low" : "high impedance");
+
+       ret = regmap_read(stw481x->map, STW_VCORE_SLEEP, &val);
+       if (ret)
+               return ret;
+       vcore_slp = val & 0x0f;
+       dev_info(&stw481x->client->dev, "VCORE SLEEP: %u.%uV\n",
+               vcore_val[vcore_slp] / 100, vcore_val[vcore_slp] % 100);
+
+       return 0;
+}
+
+/*
+ * MFD cells - we have one cell which is selected operation
+ * mode, and we always have a GPIO cell.
+ */
+static struct mfd_cell stw481x_cells[] = {
+       {
+               .of_compatible = "st,stw481x-vmmc",
+               .name = "stw481x-vmmc-regulator",
+               .id = -1,
+       },
+};
+
+const struct regmap_config stw481x_regmap_config = {
+       .reg_bits = 8,
+       .val_bits = 8,
+};
+
+static int stw481x_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct stw481x                  *stw481x;
+       int ret;
+       int i;
+
+       stw481x = devm_kzalloc(&client->dev, sizeof(*stw481x), GFP_KERNEL);
+       if (!stw481x)
+               return -ENOMEM;
+
+       i2c_set_clientdata(client, stw481x);
+       stw481x->client = client;
+       stw481x->map = devm_regmap_init_i2c(client, &stw481x_regmap_config);
+
+       ret = stw481x_startup(stw481x);
+       if (ret) {
+               dev_err(&client->dev, "chip initialization failed\n");
+               return ret;
+       }
+
+       /* Set up and register the platform devices. */
+       for (i = 0; i < ARRAY_SIZE(stw481x_cells); i++) {
+               /* One state holder for all drivers, this is simple */
+               stw481x_cells[i].platform_data = stw481x;
+               stw481x_cells[i].pdata_size = sizeof(*stw481x);
+       }
+
+       ret = mfd_add_devices(&client->dev, 0, stw481x_cells,
+                       ARRAY_SIZE(stw481x_cells), NULL, 0, NULL);
+       if (ret)
+               return ret;
+
+       dev_info(&client->dev, "initialized STw481x device\n");
+
+       return ret;
+}
+
+static int stw481x_remove(struct i2c_client *client)
+{
+       mfd_remove_devices(&client->dev);
+       return 0;
+}
+
+/*
+ * This ID table is completely unused, as this is a pure
+ * device-tree probed driver, but it has to be here due to
+ * the structure of the I2C core.
+ */
+static const struct i2c_device_id stw481x_id[] = {
+       { "stw481x", 0 },
+       { },
+};
+
+static const struct of_device_id stw481x_match[] = {
+       { .compatible = "st,stw4810", },
+       { .compatible = "st,stw4811", },
+       { },
+};
+MODULE_DEVICE_TABLE(of, stw481x_match);
+
+static struct i2c_driver stw481x_driver = {
+       .driver = {
+               .name   = "stw481x",
+               .of_match_table = stw481x_match,
+       },
+       .probe          = stw481x_probe,
+       .remove         = stw481x_remove,
+       .id_table       = stw481x_id,
+};
+
+module_i2c_driver(stw481x_driver);
+
+MODULE_AUTHOR("Linus Walleij");
+MODULE_DESCRIPTION("STw481x PMIC driver");
+MODULE_LICENSE("GPL v2");
index 70f4909fee13b8d30a632029a9639b41b81cb051..87ea51dc6234a243021bce1682a213856c49128b 100644 (file)
 #include <linux/mfd/core.h>
 #include <linux/mfd/tc3589x.h>
 
+/**
+ * enum tc3589x_version - indicates the TC3589x version
+ */
+enum tc3589x_version {
+       TC3589X_TC35890,
+       TC3589X_TC35892,
+       TC3589X_TC35893,
+       TC3589X_TC35894,
+       TC3589X_TC35895,
+       TC3589X_TC35896,
+       TC3589X_UNKNOWN,
+};
+
 #define TC3589x_CLKMODE_MODCTL_SLEEP           0x0
 #define TC3589x_CLKMODE_MODCTL_OPERATION       (1 << 0)
 
@@ -361,7 +374,21 @@ static int tc3589x_probe(struct i2c_client *i2c,
        tc3589x->i2c = i2c;
        tc3589x->pdata = pdata;
        tc3589x->irq_base = pdata->irq_base;
-       tc3589x->num_gpio = id->driver_data;
+
+       switch (id->driver_data) {
+       case TC3589X_TC35893:
+       case TC3589X_TC35895:
+       case TC3589X_TC35896:
+               tc3589x->num_gpio = 20;
+               break;
+       case TC3589X_TC35890:
+       case TC3589X_TC35892:
+       case TC3589X_TC35894:
+       case TC3589X_UNKNOWN:
+       default:
+               tc3589x->num_gpio = 24;
+               break;
+       }
 
        i2c_set_clientdata(i2c, tc3589x);
 
@@ -432,7 +459,13 @@ static int tc3589x_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend, tc3589x_resume);
 
 static const struct i2c_device_id tc3589x_id[] = {
-       { "tc3589x", 24 },
+       { "tc35890", TC3589X_TC35890 },
+       { "tc35892", TC3589X_TC35892 },
+       { "tc35893", TC3589X_TC35893 },
+       { "tc35894", TC3589X_TC35894 },
+       { "tc35895", TC3589X_TC35895 },
+       { "tc35896", TC3589X_TC35896 },
+       { "tc3589x", TC3589X_UNKNOWN },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, tc3589x_id);
index 1c2b994e1f6c0b0ce1e4bd346a4ff6e1e1c77e3d..71e3e0c5bf730c7e8f3423619d9a2e2acc6fa27d 100644 (file)
@@ -445,7 +445,6 @@ static int ti_ssp_remove(struct platform_device *pdev)
        iounmap(ssp->regs);
        release_mem_region(ssp->res->start, resource_size(ssp->res));
        kfree(ssp);
-       dev_set_drvdata(dev, NULL);
        return 0;
 }
 
index baaf5a8123bb8eba1aadffda901238acce2a9a98..88718abfb9ba0169090201e8fc04037ea4f32854 100644 (file)
@@ -56,21 +56,25 @@ EXPORT_SYMBOL_GPL(am335x_tsc_se_update);
 
 void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val)
 {
-       spin_lock(&tsadc->reg_lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&tsadc->reg_lock, flags);
        tsadc->reg_se_cache = tscadc_readl(tsadc, REG_SE);
        tsadc->reg_se_cache |= val;
        am335x_tsc_se_update(tsadc);
-       spin_unlock(&tsadc->reg_lock);
+       spin_unlock_irqrestore(&tsadc->reg_lock, flags);
 }
 EXPORT_SYMBOL_GPL(am335x_tsc_se_set);
 
 void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
 {
-       spin_lock(&tsadc->reg_lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&tsadc->reg_lock, flags);
        tsadc->reg_se_cache = tscadc_readl(tsadc, REG_SE);
        tsadc->reg_se_cache &= ~val;
        am335x_tsc_se_update(tsadc);
-       spin_unlock(&tsadc->reg_lock);
+       spin_unlock_irqrestore(&tsadc->reg_lock, flags);
 }
 EXPORT_SYMBOL_GPL(am335x_tsc_se_clr);
 
@@ -95,7 +99,7 @@ static        int ti_tscadc_probe(struct platform_device *pdev)
        const __be32            *cur;
        u32                     val;
        int                     err, ctrl;
-       int                     clk_value, clock_rate;
+       int                     clock_rate;
        int                     tsc_wires = 0, adc_channels = 0, total_channels;
        int                     readouts = 0;
 
@@ -196,11 +200,11 @@ static    int ti_tscadc_probe(struct platform_device *pdev)
        }
        clock_rate = clk_get_rate(clk);
        clk_put(clk);
-       clk_value = clock_rate / ADC_CLK;
+       tscadc->clk_div = clock_rate / ADC_CLK;
 
        /* TSCADC_CLKDIV needs to be configured to the value minus 1 */
-       clk_value = clk_value - 1;
-       tscadc_writel(tscadc, REG_CLKDIV, clk_value);
+       tscadc->clk_div--;
+       tscadc_writel(tscadc, REG_CLKDIV, tscadc->clk_div);
 
        /* Set the control register bits */
        ctrl = CNTRLREG_STEPCONFIGWRT |
@@ -303,6 +307,8 @@ static int tscadc_resume(struct device *dev)
        tscadc_writel(tscadc_dev, REG_CTRL,
                        (restore | CNTRLREG_TSCSSENB));
 
+       tscadc_writel(tscadc_dev, REG_CLKDIV, tscadc_dev->clk_div);
+
        return 0;
 }
 
@@ -326,7 +332,7 @@ static struct platform_driver ti_tscadc_driver = {
                .name   = "ti_am3359-tscadc",
                .owner  = THIS_MODULE,
                .pm     = TSCADC_PM_OPS,
-               .of_match_table = of_match_ptr(ti_tscadc_dt_ids),
+               .of_match_table = ti_tscadc_dt_ids,
        },
        .probe  = ti_tscadc_probe,
        .remove = ti_tscadc_remove,
index a6755ec7bd6ac55a1a8675a2d0382330f6863f54..dbb34f94e5e3fce2e0df7f18097930558069af2f 100644 (file)
@@ -678,7 +678,7 @@ static int timb_probe(struct pci_dev *dev,
        priv->ctl_mapbase = mapbase + CHIPCTLOFFSET;
        if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) {
                dev_err(&dev->dev, "Failed to request ctl mem\n");
-               goto err_request;
+               goto err_start;
        }
 
        priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE);
@@ -828,13 +828,10 @@ err_config:
        iounmap(priv->ctl_membase);
 err_ioremap:
        release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
-err_request:
-       pci_set_drvdata(dev, NULL);
 err_start:
        pci_disable_device(dev);
 err_enable:
        kfree(priv);
-       pci_set_drvdata(dev, NULL);
        return -ENODEV;
 }
 
@@ -851,7 +848,6 @@ static void timb_remove(struct pci_dev *dev)
 
        pci_disable_msix(dev);
        pci_disable_device(dev);
-       pci_set_drvdata(dev, NULL);
        kfree(priv);
 }
 
index 5ad4b772b09797bec97c9759bb9c80e609102651..a081b925d10b2debf94e28ea2c5c500081262309 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
+#include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/tps6507x.h>
index b8f48647661e7db4a58612208bb51ed8957d3fab..b7be0b29557599ab94c30ba4f16534c88eff030b 100644 (file)
@@ -245,7 +245,7 @@ static struct i2c_driver tps65217_driver = {
        .driver         = {
                .name   = "tps65217",
                .owner  = THIS_MODULE,
-               .of_match_table = of_match_ptr(tps65217_of_match),
+               .of_match_table = tps65217_of_match,
        },
        .id_table       = tps65217_id_table,
        .probe          = tps65217_probe,
index f54fe4d4f77b34a7ecbcef449635dbdbccf036d8..ee61fd7c198da714c2dd56ba7be2bfe6da5a068d 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/of.h>
 
 #include <linux/mfd/core.h>
 #include <linux/mfd/tps6586x.h>
@@ -124,6 +125,7 @@ struct tps6586x {
        struct i2c_client       *client;
        struct regmap           *regmap;
 
+       int                     irq;
        struct irq_chip         irq_chip;
        struct mutex            irq_lock;
        int                     irq_base;
@@ -261,12 +263,23 @@ static void tps6586x_irq_sync_unlock(struct irq_data *data)
        mutex_unlock(&tps6586x->irq_lock);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int tps6586x_irq_set_wake(struct irq_data *irq_data, unsigned int on)
+{
+       struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data);
+       return irq_set_irq_wake(tps6586x->irq, on);
+}
+#else
+#define tps6586x_irq_set_wake NULL
+#endif
+
 static struct irq_chip tps6586x_irq_chip = {
        .name = "tps6586x",
        .irq_bus_lock = tps6586x_irq_lock,
        .irq_bus_sync_unlock = tps6586x_irq_sync_unlock,
        .irq_disable = tps6586x_irq_disable,
        .irq_enable = tps6586x_irq_enable,
+       .irq_set_wake = tps6586x_irq_set_wake,
 };
 
 static int tps6586x_irq_map(struct irq_domain *h, unsigned int virq,
@@ -331,6 +344,8 @@ static int tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
        int new_irq_base;
        int irq_num = ARRAY_SIZE(tps6586x_irqs);
 
+       tps6586x->irq = irq;
+
        mutex_init(&tps6586x->irq_lock);
        for (i = 0; i < 5; i++) {
                tps6586x->mask_reg[i] = 0xff;
@@ -360,10 +375,8 @@ static int tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
        ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
                                   "tps6586x", tps6586x);
 
-       if (!ret) {
+       if (!ret)
                device_init_wakeup(tps6586x->dev, 1);
-               enable_irq_wake(irq);
-       }
 
        return ret;
 }
index d792772048358dbc9857cd3090d693a951d48713..c0f608e3ca9e5fc1fc0706666b8fcc4f89778567 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/mfd/core.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/of.h>
 #include <linux/of_device.h>
 
 static struct resource rtc_resources[] = {
@@ -410,14 +411,10 @@ static struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
        ret = of_property_read_u32(np, "ti,vmbch-threshold", &prop);
        if (!ret)
                board_info->vmbch_threshold = prop;
-       else if (*chip_id == TPS65911)
-               dev_warn(&client->dev, "VMBCH-Threshold not specified");
 
        ret = of_property_read_u32(np, "ti,vmbch2-threshold", &prop);
        if (!ret)
                board_info->vmbch2_threshold = prop;
-       else if (*chip_id == TPS65911)
-               dev_warn(&client->dev, "VMBCH2-Threshold not specified");
 
        prop = of_property_read_bool(np, "ti,en-ck32k-xtal");
        board_info->en_ck32k_xtal = prop;
index daf66942071c9084779497f6b40ac7bc2c8c916d..0779d5ab9ab1538631981aff4994743a5b96b008 100644 (file)
@@ -565,13 +565,13 @@ static int twl6040_probe(struct i2c_client *client,
                                      twl6040->supplies);
        if (ret != 0) {
                dev_err(&client->dev, "Failed to get supplies: %d\n", ret);
-               goto regulator_get_err;
+               return ret;
        }
 
        ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
        if (ret != 0) {
                dev_err(&client->dev, "Failed to enable supplies: %d\n", ret);
-               goto regulator_get_err;
+               return ret;
        }
 
        twl6040->dev = &client->dev;
@@ -619,7 +619,7 @@ static int twl6040_probe(struct i2c_client *client,
                                        "twl6040_irq_th", twl6040);
        if (ret) {
                dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret);
-               goto thirq_err;
+               goto readyirq_err;
        }
 
        /* dual-access registers controlled by I2C only */
@@ -659,21 +659,14 @@ static int twl6040_probe(struct i2c_client *client,
        ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
                              NULL, 0, NULL);
        if (ret)
-               goto mfd_err;
+               goto readyirq_err;
 
        return 0;
 
-mfd_err:
-       devm_free_irq(&client->dev, twl6040->irq_th, twl6040);
-thirq_err:
-       devm_free_irq(&client->dev, twl6040->irq_ready, twl6040);
 readyirq_err:
        regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
 gpio_err:
        regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
-regulator_get_err:
-       i2c_set_clientdata(client, NULL);
-
        return ret;
 }
 
@@ -684,12 +677,9 @@ static int twl6040_remove(struct i2c_client *client)
        if (twl6040->power_count)
                twl6040_power(twl6040, 0);
 
-       devm_free_irq(&client->dev, twl6040->irq_ready, twl6040);
-       devm_free_irq(&client->dev, twl6040->irq_th, twl6040);
        regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
 
        mfd_remove_devices(&client->dev);
-       i2c_set_clientdata(client, NULL);
 
        regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
 
index d5966e6b5a7d8058a9ff37f15a86204ffe6ffe6c..0313f839e8fadc32228b9c892edb31a449b53ace 100644 (file)
@@ -553,6 +553,7 @@ static int ucb1x00_probe(struct mcp *mcp)
        if (ucb->irq_base < 0) {
                dev_err(&ucb->dev, "unable to allocate 16 irqs: %d\n",
                        ucb->irq_base);
+               ret = ucb->irq_base;
                goto err_irq_alloc;
        }
 
index 802dd3cb18cf06a2504941e0c21e5fd37ec9e7b4..1e9a4b2102f9d89c9549e3d226cf7ef0c91866ef 100644 (file)
@@ -903,7 +903,6 @@ static const struct reg_default wm5102_reg_default[] = {
        { 0x00000D1B, 0xFFFF },   /* R3355  - IRQ2 Status 4 Mask */ 
        { 0x00000D1C, 0xFFFF },   /* R3356  - IRQ2 Status 5 Mask */ 
        { 0x00000D1F, 0x0000 },   /* R3359  - IRQ2 Control */ 
-       { 0x00000D50, 0x0000 },   /* R3408  - AOD wkup and trig */
        { 0x00000D53, 0xFFFF },   /* R3411  - AOD IRQ Mask IRQ1 */ 
        { 0x00000D54, 0xFFFF },   /* R3412  - AOD IRQ Mask IRQ2 */ 
        { 0x00000D56, 0x0000 },   /* R3414  - Jack detect debounce */ 
index 3113e39b318e27a7aa2e74b7433e601edae2da72..bf8b3b5ad1fe65d03eb067881599c5cbc1418a32 100644 (file)
@@ -243,6 +243,12 @@ int wm5110_patch(struct arizona *arizona)
 EXPORT_SYMBOL_GPL(wm5110_patch);
 
 static const struct regmap_irq wm5110_aod_irqs[ARIZONA_NUM_IRQ] = {
+       [ARIZONA_IRQ_MICD_CLAMP_FALL] = {
+               .mask = ARIZONA_MICD_CLAMP_FALL_EINT1
+       },
+       [ARIZONA_IRQ_MICD_CLAMP_RISE] = {
+               .mask = ARIZONA_MICD_CLAMP_RISE_EINT1
+       },
        [ARIZONA_IRQ_GP5_FALL] = { .mask = ARIZONA_GP5_FALL_EINT1 },
        [ARIZONA_IRQ_GP5_RISE] = { .mask = ARIZONA_GP5_RISE_EINT1 },
        [ARIZONA_IRQ_JD_FALL] = { .mask = ARIZONA_JD1_FALL_EINT1 },
@@ -505,6 +511,7 @@ static const struct reg_default wm5110_reg_default[] = {
        { 0x00000293, 0x0000 },    /* R659   - Accessory Detect Mode 1 */
        { 0x0000029B, 0x0020 },    /* R667   - Headphone Detect 1 */
        { 0x0000029C, 0x0000 },    /* R668   - Headphone Detect 2 */
+       { 0x000002A2, 0x0000 },    /* R674   - Micd clamp control */
        { 0x000002A3, 0x1102 },    /* R675   - Mic Detect 1 */
        { 0x000002A4, 0x009F },    /* R676   - Mic Detect 2 */
        { 0x000002A5, 0x0000 },    /* R677   - Mic Detect 3 */
@@ -592,7 +599,7 @@ static const struct reg_default wm5110_reg_default[] = {
        { 0x0000043E, 0x0080 },    /* R1086  - DAC Volume Limit 6R */
        { 0x0000043F, 0x0800 },    /* R1087  - Noise Gate Select 6R */
        { 0x00000450, 0x0000 },    /* R1104  - DAC AEC Control 1 */
-       { 0x00000458, 0x0001 },    /* R1112  - Noise Gate Control */
+       { 0x00000458, 0x0000 },    /* R1112  - Noise Gate Control */
        { 0x00000480, 0x0040 },    /* R1152  - Class W ANC Threshold 1 */
        { 0x00000481, 0x0040 },    /* R1153  - Class W ANC Threshold 2 */
        { 0x00000490, 0x0069 },    /* R1168  - PDM SPK1 CTRL 1 */
@@ -1204,7 +1211,6 @@ static const struct reg_default wm5110_reg_default[] = {
        { 0x00000D1B, 0xFFFF },    /* R3355  - IRQ2 Status 4 Mask */
        { 0x00000D1C, 0xFFFF },    /* R3356  - IRQ2 Status 5 Mask */
        { 0x00000D1F, 0x0000 },    /* R3359  - IRQ2 Control */
-       { 0x00000D50, 0x0000 },    /* R3408  - AOD wkup and trig */
        { 0x00000D53, 0xFFFF },    /* R3411  - AOD IRQ Mask IRQ1 */
        { 0x00000D54, 0xFFFF },    /* R3412  - AOD IRQ Mask IRQ2 */
        { 0x00000D56, 0x0000 },    /* R3414  - Jack detect debounce */
@@ -1440,6 +1446,7 @@ static bool wm5110_readable_register(struct device *dev, unsigned int reg)
        case ARIZONA_ACCESSORY_DETECT_MODE_1:
        case ARIZONA_HEADPHONE_DETECT_1:
        case ARIZONA_HEADPHONE_DETECT_2:
+       case ARIZONA_MICD_CLAMP_CONTROL:
        case ARIZONA_MIC_DETECT_1:
        case ARIZONA_MIC_DETECT_2:
        case ARIZONA_MIC_DETECT_3:
@@ -2291,21 +2298,37 @@ static bool wm5110_readable_register(struct device *dev, unsigned int reg)
        case ARIZONA_DSP1_STATUS_1:
        case ARIZONA_DSP1_STATUS_2:
        case ARIZONA_DSP1_STATUS_3:
+       case ARIZONA_DSP1_SCRATCH_0:
+       case ARIZONA_DSP1_SCRATCH_1:
+       case ARIZONA_DSP1_SCRATCH_2:
+       case ARIZONA_DSP1_SCRATCH_3:
        case ARIZONA_DSP2_CONTROL_1:
        case ARIZONA_DSP2_CLOCKING_1:
        case ARIZONA_DSP2_STATUS_1:
        case ARIZONA_DSP2_STATUS_2:
        case ARIZONA_DSP2_STATUS_3:
+       case ARIZONA_DSP2_SCRATCH_0:
+       case ARIZONA_DSP2_SCRATCH_1:
+       case ARIZONA_DSP2_SCRATCH_2:
+       case ARIZONA_DSP2_SCRATCH_3:
        case ARIZONA_DSP3_CONTROL_1:
        case ARIZONA_DSP3_CLOCKING_1:
        case ARIZONA_DSP3_STATUS_1:
        case ARIZONA_DSP3_STATUS_2:
        case ARIZONA_DSP3_STATUS_3:
+       case ARIZONA_DSP3_SCRATCH_0:
+       case ARIZONA_DSP3_SCRATCH_1:
+       case ARIZONA_DSP3_SCRATCH_2:
+       case ARIZONA_DSP3_SCRATCH_3:
        case ARIZONA_DSP4_CONTROL_1:
        case ARIZONA_DSP4_CLOCKING_1:
        case ARIZONA_DSP4_STATUS_1:
        case ARIZONA_DSP4_STATUS_2:
        case ARIZONA_DSP4_STATUS_3:
+       case ARIZONA_DSP4_SCRATCH_0:
+       case ARIZONA_DSP4_SCRATCH_1:
+       case ARIZONA_DSP4_SCRATCH_2:
+       case ARIZONA_DSP4_SCRATCH_3:
                return true;
        default:
                return false;
@@ -2347,25 +2370,41 @@ static bool wm5110_volatile_register(struct device *dev, unsigned int reg)
        case ARIZONA_INTERRUPT_RAW_STATUS_7:
        case ARIZONA_INTERRUPT_RAW_STATUS_8:
        case ARIZONA_IRQ_PIN_STATUS:
+       case ARIZONA_AOD_WKUP_AND_TRIG:
        case ARIZONA_AOD_IRQ1:
        case ARIZONA_AOD_IRQ2:
+       case ARIZONA_AOD_IRQ_RAW_STATUS:
        case ARIZONA_FX_CTRL2:
        case ARIZONA_ASRC_STATUS:
        case ARIZONA_DSP_STATUS:
-       case ARIZONA_DSP1_CONTROL_1:
-       case ARIZONA_DSP1_CLOCKING_1:
        case ARIZONA_DSP1_STATUS_1:
        case ARIZONA_DSP1_STATUS_2:
        case ARIZONA_DSP1_STATUS_3:
+       case ARIZONA_DSP1_SCRATCH_0:
+       case ARIZONA_DSP1_SCRATCH_1:
+       case ARIZONA_DSP1_SCRATCH_2:
+       case ARIZONA_DSP1_SCRATCH_3:
        case ARIZONA_DSP2_STATUS_1:
        case ARIZONA_DSP2_STATUS_2:
        case ARIZONA_DSP2_STATUS_3:
+       case ARIZONA_DSP2_SCRATCH_0:
+       case ARIZONA_DSP2_SCRATCH_1:
+       case ARIZONA_DSP2_SCRATCH_2:
+       case ARIZONA_DSP2_SCRATCH_3:
        case ARIZONA_DSP3_STATUS_1:
        case ARIZONA_DSP3_STATUS_2:
        case ARIZONA_DSP3_STATUS_3:
+       case ARIZONA_DSP3_SCRATCH_0:
+       case ARIZONA_DSP3_SCRATCH_1:
+       case ARIZONA_DSP3_SCRATCH_2:
+       case ARIZONA_DSP3_SCRATCH_3:
        case ARIZONA_DSP4_STATUS_1:
        case ARIZONA_DSP4_STATUS_2:
        case ARIZONA_DSP4_STATUS_3:
+       case ARIZONA_DSP4_SCRATCH_0:
+       case ARIZONA_DSP4_SCRATCH_1:
+       case ARIZONA_DSP4_SCRATCH_2:
+       case ARIZONA_DSP4_SCRATCH_3:
                return true;
        default:
                return false;
index e1c283e6d4e54eca7e88e1404ed9d1ec72497cf9..0308275116672c2b15ab2d91b334c561dadbcf46 100644 (file)
 
 #include "wm8994.h"
 
-/**
- * wm8994_reg_read: Read a single WM8994 register.
- *
- * @wm8994: Device to read from.
- * @reg: Register to read.
- */
-int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
-{
-       unsigned int val;
-       int ret;
-
-       ret = regmap_read(wm8994->regmap, reg, &val);
-
-       if (ret < 0)
-               return ret;
-       else
-               return val;
-}
-EXPORT_SYMBOL_GPL(wm8994_reg_read);
-
-/**
- * wm8994_bulk_read: Read multiple WM8994 registers
- *
- * @wm8994: Device to read from
- * @reg: First register
- * @count: Number of registers
- * @buf: Buffer to fill.  The data will be returned big endian.
- */
-int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
-                    int count, u16 *buf)
-{
-       return regmap_bulk_read(wm8994->regmap, reg, buf, count);
-}
-
-/**
- * wm8994_reg_write: Write a single WM8994 register.
- *
- * @wm8994: Device to write to.
- * @reg: Register to write to.
- * @val: Value to write.
- */
-int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
-                    unsigned short val)
-{
-       return regmap_write(wm8994->regmap, reg, val);
-}
-EXPORT_SYMBOL_GPL(wm8994_reg_write);
-
-/**
- * wm8994_bulk_write: Write multiple WM8994 registers
- *
- * @wm8994: Device to write to
- * @reg: First register
- * @count: Number of registers
- * @buf: Buffer to write from.  Data must be big-endian formatted.
- */
-int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
-                     int count, const u16 *buf)
-{
-       return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
-}
-EXPORT_SYMBOL_GPL(wm8994_bulk_write);
-
-/**
- * wm8994_set_bits: Set the value of a bitfield in a WM8994 register
- *
- * @wm8994: Device to write to.
- * @reg: Register to write to.
- * @mask: Mask of bits to set.
- * @val: Value to set (unshifted)
- */
-int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
-                   unsigned short mask, unsigned short val)
-{
-       return regmap_update_bits(wm8994->regmap, reg, mask, val);
-}
-EXPORT_SYMBOL_GPL(wm8994_set_bits);
-
 static struct mfd_cell wm8994_regulator_devs[] = {
        {
                .name = "wm8994-ldo",
index e760715bd9cbd30c01c6c16da430c06931fb04c1..a3e291d0df9a19211c7b3d855fc31ad3463524ff 100644 (file)
@@ -381,19 +381,6 @@ config HMC6352
          This driver provides support for the Honeywell HMC6352 compass,
          providing configuration and heading data via sysfs.
 
-config EP93XX_PWM
-       tristate "EP93xx PWM support"
-       depends on ARCH_EP93XX
-       help
-         This option enables device driver support for the PWM channels
-         on the Cirrus EP93xx processors.  The EP9307 chip only has one
-         PWM channel all the others have two, the second channel is an
-         alternate function of the EGPIO14 pin.  A sysfs interface is
-         provided to control the PWM channels.
-
-         To compile this driver as a module, choose M here: the module will
-         be called ep93xx_pwm.
-
 config DS1682
        tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm"
        depends on I2C
index 0b7ea3ea8bb86cc3971c7af15258c285100bd8e1..f45473e68bf71d7ab65e40e06c9bf0a0484242e6 100644 (file)
@@ -33,7 +33,6 @@ obj-$(CONFIG_APDS9802ALS)     += apds9802als.o
 obj-$(CONFIG_ISL29003)         += isl29003.o
 obj-$(CONFIG_ISL29020)         += isl29020.o
 obj-$(CONFIG_SENSORS_TSL2550)  += tsl2550.o
-obj-$(CONFIG_EP93XX_PWM)       += ep93xx_pwm.o
 obj-$(CONFIG_DS1682)           += ds1682.o
 obj-$(CONFIG_TI_DAC7512)       += ti_dac7512.o
 obj-$(CONFIG_C2PORT)           += c2port/
index 08b18f3f5264aa8052cea030143d5bc5c4b76cd0..9e2b985293fc08cf30bef9a9455fcade1eb095cb 100644 (file)
@@ -633,8 +633,7 @@ static int data_submit_dma(struct fpga_device *priv, struct data_buf *buf)
        struct dma_async_tx_descriptor *tx;
        dma_cookie_t cookie;
        dma_addr_t dst, src;
-       unsigned long dma_flags = DMA_COMPL_SKIP_DEST_UNMAP |
-                                 DMA_COMPL_SKIP_SRC_UNMAP;
+       unsigned long dma_flags = 0;
 
        dst_sg = buf->vb.sglist;
        dst_nents = buf->vb.sglen;
index 94b8a33243192d4217c54442424bc91e1dbd936c..d87f77f790d67fb49019cf94c69e346f50c89b28 100644 (file)
@@ -22,7 +22,7 @@
 #include <linux/jiffies.h>
 #include <linux/of.h>
 #include <linux/i2c.h>
-#include <linux/i2c/at24.h>
+#include <linux/platform_data/at24.h>
 
 /*
  * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
diff --git a/drivers/misc/ep93xx_pwm.c b/drivers/misc/ep93xx_pwm.c
deleted file mode 100644 (file)
index cdb67a9..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- *  Simple PWM driver for EP93XX
- *
- *     (c) Copyright 2009  Matthieu Crapet <mcrapet@gmail.com>
- *     (c) Copyright 2009  H Hartley Sweeten <hsweeten@visionengravers.com>
- *
- *     This program is free software; you can redistribute it and/or
- *     modify it under the terms of the GNU General Public License
- *     as published by the Free Software Foundation; either version
- *     2 of the License, or (at your option) any later version.
- *
- *  EP9307 has only one channel:
- *    - PWMOUT
- *
- *  EP9301/02/12/15 have two channels:
- *    - PWMOUT
- *    - PWMOUT1 (alternate function for EGPIO14)
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/io.h>
-
-#include <mach/platform.h>
-
-#define EP93XX_PWMx_TERM_COUNT 0x00
-#define EP93XX_PWMx_DUTY_CYCLE 0x04
-#define EP93XX_PWMx_ENABLE     0x08
-#define EP93XX_PWMx_INVERT     0x0C
-
-#define EP93XX_PWM_MAX_COUNT   0xFFFF
-
-struct ep93xx_pwm {
-       void __iomem    *mmio_base;
-       struct clk      *clk;
-       u32             duty_percent;
-};
-
-/*
- * /sys/devices/platform/ep93xx-pwm.N
- *   /min_freq      read-only   minimum pwm output frequency
- *   /max_req       read-only   maximum pwm output frequency
- *   /freq          read-write  pwm output frequency (0 = disable output)
- *   /duty_percent  read-write  pwm duty cycle percent (1..99)
- *   /invert        read-write  invert pwm output
- */
-
-static ssize_t ep93xx_pwm_get_min_freq(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-       unsigned long rate = clk_get_rate(pwm->clk);
-
-       return sprintf(buf, "%ld\n", rate / (EP93XX_PWM_MAX_COUNT + 1));
-}
-
-static ssize_t ep93xx_pwm_get_max_freq(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-       unsigned long rate = clk_get_rate(pwm->clk);
-
-       return sprintf(buf, "%ld\n", rate / 2);
-}
-
-static ssize_t ep93xx_pwm_get_freq(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-
-       if (readl(pwm->mmio_base + EP93XX_PWMx_ENABLE) & 0x1) {
-               unsigned long rate = clk_get_rate(pwm->clk);
-               u16 term = readl(pwm->mmio_base + EP93XX_PWMx_TERM_COUNT);
-
-               return sprintf(buf, "%ld\n", rate / (term + 1));
-       } else {
-               return sprintf(buf, "disabled\n");
-       }
-}
-
-static ssize_t ep93xx_pwm_set_freq(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-       long val;
-       int err;
-
-       err = kstrtol(buf, 10, &val);
-       if (err)
-               return -EINVAL;
-
-       if (val == 0) {
-               writel(0x0, pwm->mmio_base + EP93XX_PWMx_ENABLE);
-       } else if (val <= (clk_get_rate(pwm->clk) / 2)) {
-               u32 term, duty;
-
-               val = (clk_get_rate(pwm->clk) / val) - 1;
-               if (val > EP93XX_PWM_MAX_COUNT)
-                       val = EP93XX_PWM_MAX_COUNT;
-               if (val < 1)
-                       val = 1;
-
-               term = readl(pwm->mmio_base + EP93XX_PWMx_TERM_COUNT);
-               duty = ((val + 1) * pwm->duty_percent / 100) - 1;
-
-               /* If pwm is running, order is important */
-               if (val > term) {
-                       writel(val, pwm->mmio_base + EP93XX_PWMx_TERM_COUNT);
-                       writel(duty, pwm->mmio_base + EP93XX_PWMx_DUTY_CYCLE);
-               } else {
-                       writel(duty, pwm->mmio_base + EP93XX_PWMx_DUTY_CYCLE);
-                       writel(val, pwm->mmio_base + EP93XX_PWMx_TERM_COUNT);
-               }
-
-               if (!readl(pwm->mmio_base + EP93XX_PWMx_ENABLE) & 0x1)
-                       writel(0x1, pwm->mmio_base + EP93XX_PWMx_ENABLE);
-       } else {
-               return -EINVAL;
-       }
-
-       return count;
-}
-
-static ssize_t ep93xx_pwm_get_duty_percent(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-
-       return sprintf(buf, "%d\n", pwm->duty_percent);
-}
-
-static ssize_t ep93xx_pwm_set_duty_percent(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-       long val;
-       int err;
-
-       err = kstrtol(buf, 10, &val);
-       if (err)
-               return -EINVAL;
-
-       if (val > 0 && val < 100) {
-               u32 term = readl(pwm->mmio_base + EP93XX_PWMx_TERM_COUNT);
-               u32 duty = ((term + 1) * val / 100) - 1;
-
-               writel(duty, pwm->mmio_base + EP93XX_PWMx_DUTY_CYCLE);
-               pwm->duty_percent = val;
-               return count;
-       }
-
-       return -EINVAL;
-}
-
-static ssize_t ep93xx_pwm_get_invert(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-       int inverted = readl(pwm->mmio_base + EP93XX_PWMx_INVERT) & 0x1;
-
-       return sprintf(buf, "%d\n", inverted);
-}
-
-static ssize_t ep93xx_pwm_set_invert(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-       long val;
-       int err;
-
-       err = kstrtol(buf, 10, &val);
-       if (err)
-               return -EINVAL;
-
-       if (val == 0)
-               writel(0x0, pwm->mmio_base + EP93XX_PWMx_INVERT);
-       else if (val == 1)
-               writel(0x1, pwm->mmio_base + EP93XX_PWMx_INVERT);
-       else
-               return -EINVAL;
-
-       return count;
-}
-
-static DEVICE_ATTR(min_freq, S_IRUGO, ep93xx_pwm_get_min_freq, NULL);
-static DEVICE_ATTR(max_freq, S_IRUGO, ep93xx_pwm_get_max_freq, NULL);
-static DEVICE_ATTR(freq, S_IWUSR | S_IRUGO,
-                  ep93xx_pwm_get_freq, ep93xx_pwm_set_freq);
-static DEVICE_ATTR(duty_percent, S_IWUSR | S_IRUGO,
-                  ep93xx_pwm_get_duty_percent, ep93xx_pwm_set_duty_percent);
-static DEVICE_ATTR(invert, S_IWUSR | S_IRUGO,
-                  ep93xx_pwm_get_invert, ep93xx_pwm_set_invert);
-
-static struct attribute *ep93xx_pwm_attrs[] = {
-       &dev_attr_min_freq.attr,
-       &dev_attr_max_freq.attr,
-       &dev_attr_freq.attr,
-       &dev_attr_duty_percent.attr,
-       &dev_attr_invert.attr,
-       NULL
-};
-
-static const struct attribute_group ep93xx_pwm_sysfs_files = {
-       .attrs  = ep93xx_pwm_attrs,
-};
-
-static int ep93xx_pwm_probe(struct platform_device *pdev)
-{
-       struct ep93xx_pwm *pwm;
-       struct resource *res;
-       int ret;
-
-       pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
-       if (!pwm)
-               return -ENOMEM;
-
-       pwm->clk = devm_clk_get(&pdev->dev, "pwm_clk");
-       if (IS_ERR(pwm->clk))
-               return PTR_ERR(pwm->clk);
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       pwm->mmio_base = devm_ioremap_resource(&pdev->dev, res);
-       if (IS_ERR(pwm->mmio_base))
-               return PTR_ERR(pwm->mmio_base);
-
-       ret = ep93xx_pwm_acquire_gpio(pdev);
-       if (ret)
-               return ret;
-
-       ret = sysfs_create_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
-       if (ret) {
-               ep93xx_pwm_release_gpio(pdev);
-               return ret;
-       }
-
-       pwm->duty_percent = 50;
-
-       /* disable pwm at startup. Avoids zero value. */
-       writel(0x0, pwm->mmio_base + EP93XX_PWMx_ENABLE);
-       writel(EP93XX_PWM_MAX_COUNT, pwm->mmio_base + EP93XX_PWMx_TERM_COUNT);
-       writel(EP93XX_PWM_MAX_COUNT/2, pwm->mmio_base + EP93XX_PWMx_DUTY_CYCLE);
-
-       clk_enable(pwm->clk);
-
-       platform_set_drvdata(pdev, pwm);
-       return 0;
-}
-
-static int ep93xx_pwm_remove(struct platform_device *pdev)
-{
-       struct ep93xx_pwm *pwm = platform_get_drvdata(pdev);
-
-       writel(0x0, pwm->mmio_base + EP93XX_PWMx_ENABLE);
-       clk_disable(pwm->clk);
-       sysfs_remove_group(&pdev->dev.kobj, &ep93xx_pwm_sysfs_files);
-       ep93xx_pwm_release_gpio(pdev);
-
-       return 0;
-}
-
-static struct platform_driver ep93xx_pwm_driver = {
-       .driver         = {
-               .name   = "ep93xx-pwm",
-               .owner  = THIS_MODULE,
-       },
-       .probe          = ep93xx_pwm_probe,
-       .remove         = ep93xx_pwm_remove,
-};
-module_platform_driver(ep93xx_pwm_driver);
-
-MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, "
-             "H Hartley Sweeten <hsweeten@visionengravers.com>");
-MODULE_DESCRIPTION("EP93xx PWM driver");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:ep93xx-pwm");
index 1a3163f1407e2093a43a6a1c61db5a9538f6a329..29d5d988a51cc6233ce71215a3d88bcc91167c94 100644 (file)
@@ -2448,7 +2448,6 @@ static int _mmc_blk_suspend(struct mmc_card *card)
        struct mmc_blk_data *md = mmc_get_drvdata(card);
 
        if (md) {
-               pm_runtime_get_sync(&card->dev);
                mmc_queue_suspend(&md->queue);
                list_for_each_entry(part_md, &md->part, part) {
                        mmc_queue_suspend(&part_md->queue);
@@ -2483,7 +2482,6 @@ static int mmc_blk_resume(struct mmc_card *card)
                list_for_each_entry(part_md, &md->part, part) {
                        mmc_queue_resume(&part_md->queue);
                }
-               pm_runtime_put(&card->dev);
        }
        return 0;
 }
index 3e227bd91e81935eaf3f4ffce830de99b3e1321d..64145a32b917b37ce862e392fe3600417c99c336 100644 (file)
@@ -342,7 +342,7 @@ int mmc_add_card(struct mmc_card *card)
                break;
        }
 
-       if (mmc_sd_card_uhs(card) &&
+       if (mmc_card_uhs(card) &&
                (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds)))
                uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed];
 
index bf18b6bfce487b2dd6a77917344c1514dc1aa7a8..57a2b403bf8e9107204c3cda03671a5a1c8bd87d 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/log2.h>
 #include <linux/regulator/consumer.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_wakeup.h>
 #include <linux/suspend.h>
 #include <linux/fault-inject.h>
 #include <linux/random.h>
@@ -301,7 +302,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
        }
 
        err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-                       EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal);
+                       EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal, true);
        if (err) {
                pr_warn("%s: Error %d starting bkops\n",
                        mmc_hostname(card->host), err);
@@ -917,31 +918,6 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 
 EXPORT_SYMBOL(__mmc_claim_host);
 
-/**
- *     mmc_try_claim_host - try exclusively to claim a host
- *     @host: mmc host to claim
- *
- *     Returns %1 if the host is claimed, %0 otherwise.
- */
-int mmc_try_claim_host(struct mmc_host *host)
-{
-       int claimed_host = 0;
-       unsigned long flags;
-
-       spin_lock_irqsave(&host->lock, flags);
-       if (!host->claimed || host->claimer == current) {
-               host->claimed = 1;
-               host->claimer = current;
-               host->claim_cnt += 1;
-               claimed_host = 1;
-       }
-       spin_unlock_irqrestore(&host->lock, flags);
-       if (host->ops->enable && claimed_host && host->claim_cnt == 1)
-               host->ops->enable(host);
-       return claimed_host;
-}
-EXPORT_SYMBOL(mmc_try_claim_host);
-
 /**
  *     mmc_release_host - release a host
  *     @host: mmc host to release
@@ -1382,22 +1358,31 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
 {
        int bit;
 
-       ocr &= host->ocr_avail;
+       /*
+        * Sanity check the voltages that the card claims to
+        * support.
+        */
+       if (ocr & 0x7F) {
+               dev_warn(mmc_dev(host),
+               "card claims to support voltages below defined range\n");
+               ocr &= ~0x7F;
+       }
 
-       bit = ffs(ocr);
-       if (bit) {
-               bit -= 1;
+       ocr &= host->ocr_avail;
+       if (!ocr) {
+               dev_warn(mmc_dev(host), "no support for card's volts\n");
+               return 0;
+       }
 
+       if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) {
+               bit = ffs(ocr) - 1;
                ocr &= 3 << bit;
-
-               mmc_host_clk_hold(host);
-               host->ios.vdd = bit;
-               mmc_set_ios(host);
-               mmc_host_clk_release(host);
+               mmc_power_cycle(host, ocr);
        } else {
-               pr_warning("%s: host doesn't support card's voltages\n",
-                               mmc_hostname(host));
-               ocr = 0;
+               bit = fls(ocr) - 1;
+               ocr &= 3 << bit;
+               if (bit != host->ios.vdd)
+                       dev_warn(mmc_dev(host), "exceeding card's volts\n");
        }
 
        return ocr;
@@ -1422,7 +1407,7 @@ int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
 
 }
 
-int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
+int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr)
 {
        struct mmc_command cmd = {0};
        int err = 0;
@@ -1504,7 +1489,7 @@ power_cycle:
        if (err) {
                pr_debug("%s: Signal voltage switch failed, "
                        "power cycling card\n", mmc_hostname(host));
-               mmc_power_cycle(host);
+               mmc_power_cycle(host, ocr);
        }
 
        mmc_host_clk_release(host);
@@ -1545,22 +1530,14 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type)
  * If a host does all the power sequencing itself, ignore the
  * initial MMC_POWER_UP stage.
  */
-void mmc_power_up(struct mmc_host *host)
+void mmc_power_up(struct mmc_host *host, u32 ocr)
 {
-       int bit;
-
        if (host->ios.power_mode == MMC_POWER_ON)
                return;
 
        mmc_host_clk_hold(host);
 
-       /* If ocr is set, we use it */
-       if (host->ocr)
-               bit = ffs(host->ocr) - 1;
-       else
-               bit = fls(host->ocr_avail) - 1;
-
-       host->ios.vdd = bit;
+       host->ios.vdd = fls(ocr) - 1;
        if (mmc_host_is_spi(host))
                host->ios.chip_select = MMC_CS_HIGH;
        else
@@ -1604,13 +1581,6 @@ void mmc_power_off(struct mmc_host *host)
        host->ios.clock = 0;
        host->ios.vdd = 0;
 
-
-       /*
-        * Reset ocr mask to be the highest possible voltage supported for
-        * this mmc host. This value will be used at next power up.
-        */
-       host->ocr = 1 << (fls(host->ocr_avail) - 1);
-
        if (!mmc_host_is_spi(host)) {
                host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
                host->ios.chip_select = MMC_CS_DONTCARE;
@@ -1630,12 +1600,12 @@ void mmc_power_off(struct mmc_host *host)
        mmc_host_clk_release(host);
 }
 
-void mmc_power_cycle(struct mmc_host *host)
+void mmc_power_cycle(struct mmc_host *host, u32 ocr)
 {
        mmc_power_off(host);
        /* Wait at least 1 ms according to SD spec */
        mmc_delay(1);
-       mmc_power_up(host);
+       mmc_power_up(host, ocr);
 }
 
 /*
@@ -1723,6 +1693,28 @@ void mmc_detach_bus(struct mmc_host *host)
        mmc_bus_put(host);
 }
 
+static void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
+                               bool cd_irq)
+{
+#ifdef CONFIG_MMC_DEBUG
+       unsigned long flags;
+       spin_lock_irqsave(&host->lock, flags);
+       WARN_ON(host->removed);
+       spin_unlock_irqrestore(&host->lock, flags);
+#endif
+
+       /*
+        * If the device is configured as wakeup, we prevent a new sleep for
+        * 5 s to give provision for user space to consume the event.
+        */
+       if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL) &&
+               device_can_wakeup(mmc_dev(host)))
+               pm_wakeup_event(mmc_dev(host), 5000);
+
+       host->detect_change = 1;
+       mmc_schedule_delayed_work(&host->detect, delay);
+}
+
 /**
  *     mmc_detect_change - process change of state on a MMC socket
  *     @host: host which changed state.
@@ -1735,16 +1727,8 @@ void mmc_detach_bus(struct mmc_host *host)
  */
 void mmc_detect_change(struct mmc_host *host, unsigned long delay)
 {
-#ifdef CONFIG_MMC_DEBUG
-       unsigned long flags;
-       spin_lock_irqsave(&host->lock, flags);
-       WARN_ON(host->removed);
-       spin_unlock_irqrestore(&host->lock, flags);
-#endif
-       host->detect_change = 1;
-       mmc_schedule_delayed_work(&host->detect, delay);
+       _mmc_detect_change(host, delay, true);
 }
-
 EXPORT_SYMBOL(mmc_detect_change);
 
 void mmc_init_erase(struct mmc_card *card)
@@ -2334,7 +2318,7 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
        pr_info("%s: %s: trying to init card at %u Hz\n",
                mmc_hostname(host), __func__, host->f_init);
 #endif
-       mmc_power_up(host);
+       mmc_power_up(host, host->ocr_avail);
 
        /*
         * Some eMMCs (with VCCQ always on) may not be reset after power up, so
@@ -2423,7 +2407,7 @@ int mmc_detect_card_removed(struct mmc_host *host)
                         * rescan handle the card removal.
                         */
                        cancel_delayed_work(&host->detect);
-                       mmc_detect_change(host, 0);
+                       _mmc_detect_change(host, 0, false);
                }
        }
 
@@ -2504,8 +2488,8 @@ void mmc_start_host(struct mmc_host *host)
        if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)
                mmc_power_off(host);
        else
-               mmc_power_up(host);
-       mmc_detect_change(host, 0);
+               mmc_power_up(host, host->ocr_avail);
+       _mmc_detect_change(host, 0, false);
 }
 
 void mmc_stop_host(struct mmc_host *host)
@@ -2583,7 +2567,7 @@ int mmc_power_restore_host(struct mmc_host *host)
                return -EINVAL;
        }
 
-       mmc_power_up(host);
+       mmc_power_up(host, host->card->ocr);
        ret = host->bus_ops->power_restore(host);
 
        mmc_bus_put(host);
@@ -2657,28 +2641,6 @@ EXPORT_SYMBOL(mmc_cache_ctrl);
 
 #ifdef CONFIG_PM
 
-/**
- *     mmc_suspend_host - suspend a host
- *     @host: mmc host
- */
-int mmc_suspend_host(struct mmc_host *host)
-{
-       /* This function is deprecated */
-       return 0;
-}
-EXPORT_SYMBOL(mmc_suspend_host);
-
-/**
- *     mmc_resume_host - resume a previously suspended host
- *     @host: mmc host
- */
-int mmc_resume_host(struct mmc_host *host)
-{
-       /* This function is deprecated */
-       return 0;
-}
-EXPORT_SYMBOL(mmc_resume_host);
-
 /* Do the card removal on suspend if card is assumed removeable
  * Do that in pm notifier while userspace isn't yet frozen, so we will be able
    to sync the card.
@@ -2724,7 +2686,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
                spin_lock_irqsave(&host->lock, flags);
                host->rescan_disable = 0;
                spin_unlock_irqrestore(&host->lock, flags);
-               mmc_detect_change(host, 0);
+               _mmc_detect_change(host, 0, false);
 
        }
 
index 5345d156493efcc00dcb11790aa145d0f4ea51a0..443a584660f0132de2b07ee232e068575a63faf4 100644 (file)
@@ -42,13 +42,13 @@ void mmc_set_ungated(struct mmc_host *host);
 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
 void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
-int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
+int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr);
 int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
 void mmc_set_timing(struct mmc_host *host, unsigned int timing);
 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
-void mmc_power_up(struct mmc_host *host);
+void mmc_power_up(struct mmc_host *host, u32 ocr);
 void mmc_power_off(struct mmc_host *host);
-void mmc_power_cycle(struct mmc_host *host);
+void mmc_power_cycle(struct mmc_host *host, u32 ocr);
 
 static inline void mmc_delay(unsigned int ms)
 {
index 6d02012a1d0bb72201baeb0b33c56c8ff3262938..f631f5a9bf7948b848754cc3ba475619c957a79b 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/stat.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -934,6 +935,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
                        goto err;
                }
 
+               card->ocr = ocr;
                card->type = MMC_TYPE_MMC;
                card->rca = 1;
                memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
@@ -1404,9 +1406,9 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
        if (notify_type == EXT_CSD_POWER_OFF_LONG)
                timeout = card->ext_csd.power_off_longtime;
 
-       err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-                        EXT_CSD_POWER_OFF_NOTIFICATION,
-                        notify_type, timeout);
+       err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+                       EXT_CSD_POWER_OFF_NOTIFICATION,
+                       notify_type, timeout, true, false);
        if (err)
                pr_err("%s: Power Off Notification timed out, %u\n",
                       mmc_hostname(card->host), timeout);
@@ -1477,6 +1479,9 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
 
        mmc_claim_host(host);
 
+       if (mmc_card_suspended(host->card))
+               goto out;
+
        if (mmc_card_doing_bkops(host->card)) {
                err = mmc_stop_bkops(host->card);
                if (err)
@@ -1496,51 +1501,93 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
                err = mmc_deselect_cards(host);
        host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
 
-       if (!err)
+       if (!err) {
                mmc_power_off(host);
+               mmc_card_set_suspended(host->card);
+       }
 out:
        mmc_release_host(host);
        return err;
 }
 
 /*
- * Suspend callback from host.
+ * Suspend callback
  */
 static int mmc_suspend(struct mmc_host *host)
 {
-       return _mmc_suspend(host, true);
-}
+       int err;
 
-/*
- * Shutdown callback
- */
-static int mmc_shutdown(struct mmc_host *host)
-{
-       return _mmc_suspend(host, false);
+       err = _mmc_suspend(host, true);
+       if (!err) {
+               pm_runtime_disable(&host->card->dev);
+               pm_runtime_set_suspended(&host->card->dev);
+       }
+
+       return err;
 }
 
 /*
- * Resume callback from host.
- *
  * This function tries to determine if the same card is still present
  * and, if so, restore all state to it.
  */
-static int mmc_resume(struct mmc_host *host)
+static int _mmc_resume(struct mmc_host *host)
 {
-       int err;
+       int err = 0;
 
        BUG_ON(!host);
        BUG_ON(!host->card);
 
        mmc_claim_host(host);
-       mmc_power_up(host);
-       mmc_select_voltage(host, host->ocr);
-       err = mmc_init_card(host, host->ocr, host->card);
+
+       if (!mmc_card_suspended(host->card))
+               goto out;
+
+       mmc_power_up(host, host->card->ocr);
+       err = mmc_init_card(host, host->card->ocr, host->card);
+       mmc_card_clr_suspended(host->card);
+
+out:
        mmc_release_host(host);
+       return err;
+}
+
+/*
+ * Shutdown callback
+ */
+static int mmc_shutdown(struct mmc_host *host)
+{
+       int err = 0;
+
+       /*
+        * In a specific case for poweroff notify, we need to resume the card
+        * before we can shutdown it properly.
+        */
+       if (mmc_can_poweroff_notify(host->card) &&
+               !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE))
+               err = _mmc_resume(host);
+
+       if (!err)
+               err = _mmc_suspend(host, false);
 
        return err;
 }
 
+/*
+ * Callback for resume.
+ */
+static int mmc_resume(struct mmc_host *host)
+{
+       int err = 0;
+
+       if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
+               err = _mmc_resume(host);
+               pm_runtime_set_active(&host->card->dev);
+               pm_runtime_mark_last_busy(&host->card->dev);
+       }
+       pm_runtime_enable(&host->card->dev);
+
+       return err;
+}
 
 /*
  * Callback for runtime_suspend.
@@ -1552,18 +1599,11 @@ static int mmc_runtime_suspend(struct mmc_host *host)
        if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
                return 0;
 
-       mmc_claim_host(host);
-
-       err = mmc_suspend(host);
-       if (err) {
+       err = _mmc_suspend(host, true);
+       if (err)
                pr_err("%s: error %d doing aggessive suspend\n",
                        mmc_hostname(host), err);
-               goto out;
-       }
-       mmc_power_off(host);
 
-out:
-       mmc_release_host(host);
        return err;
 }
 
@@ -1574,18 +1614,14 @@ static int mmc_runtime_resume(struct mmc_host *host)
 {
        int err;
 
-       if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
+       if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
                return 0;
 
-       mmc_claim_host(host);
-
-       mmc_power_up(host);
-       err = mmc_resume(host);
+       err = _mmc_resume(host);
        if (err)
                pr_err("%s: error %d doing aggessive resume\n",
                        mmc_hostname(host), err);
 
-       mmc_release_host(host);
        return 0;
 }
 
@@ -1595,7 +1631,7 @@ static int mmc_power_restore(struct mmc_host *host)
 
        host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
        mmc_claim_host(host);
-       ret = mmc_init_card(host, host->ocr, host->card);
+       ret = mmc_init_card(host, host->card->ocr, host->card);
        mmc_release_host(host);
 
        return ret;
@@ -1640,7 +1676,7 @@ static void mmc_attach_bus_ops(struct mmc_host *host)
 int mmc_attach_mmc(struct mmc_host *host)
 {
        int err;
-       u32 ocr;
+       u32 ocr, rocr;
 
        BUG_ON(!host);
        WARN_ON(!host->claimed);
@@ -1666,23 +1702,12 @@ int mmc_attach_mmc(struct mmc_host *host)
                        goto err;
        }
 
-       /*
-        * Sanity check the voltages that the card claims to
-        * support.
-        */
-       if (ocr & 0x7F) {
-               pr_warning("%s: card claims to support voltages "
-                      "below the defined range. These will be ignored.\n",
-                      mmc_hostname(host));
-               ocr &= ~0x7F;
-       }
-
-       host->ocr = mmc_select_voltage(host, ocr);
+       rocr = mmc_select_voltage(host, ocr);
 
        /*
         * Can we support the voltage of the card?
         */
-       if (!host->ocr) {
+       if (!rocr) {
                err = -EINVAL;
                goto err;
        }
@@ -1690,7 +1715,7 @@ int mmc_attach_mmc(struct mmc_host *host)
        /*
         * Detect and init the card.
         */
-       err = mmc_init_card(host, host->ocr, NULL);
+       err = mmc_init_card(host, rocr, NULL);
        if (err)
                goto err;
 
index ef183483d5b67934440cd8dc1a8d6910467e6a61..e5b5eeb548d17eb08e1f374a83024dc5e4a1170b 100644 (file)
 
 #define MMC_OPS_TIMEOUT_MS     (10 * 60 * 1000) /* 10 minute timeout */
 
+static inline int __mmc_send_status(struct mmc_card *card, u32 *status,
+                                   bool ignore_crc)
+{
+       int err;
+       struct mmc_command cmd = {0};
+
+       BUG_ON(!card);
+       BUG_ON(!card->host);
+
+       cmd.opcode = MMC_SEND_STATUS;
+       if (!mmc_host_is_spi(card->host))
+               cmd.arg = card->rca << 16;
+       cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
+       if (ignore_crc)
+               cmd.flags &= ~MMC_RSP_CRC;
+
+       err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
+       if (err)
+               return err;
+
+       /* NOTE: callers are required to understand the difference
+        * between "native" and SPI format status words!
+        */
+       if (status)
+               *status = cmd.resp[0];
+
+       return 0;
+}
+
+int mmc_send_status(struct mmc_card *card, u32 *status)
+{
+       return __mmc_send_status(card, status, false);
+}
+
 static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
 {
        int err;
@@ -370,16 +404,18 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
  *     @timeout_ms: timeout (ms) for operation performed by register write,
  *                   timeout of zero implies maximum possible timeout
  *     @use_busy_signal: use the busy signal as response type
+ *     @send_status: send status cmd to poll for busy
  *
  *     Modifies the EXT_CSD register for selected card.
  */
 int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
-              unsigned int timeout_ms, bool use_busy_signal)
+               unsigned int timeout_ms, bool use_busy_signal, bool send_status)
 {
        int err;
        struct mmc_command cmd = {0};
        unsigned long timeout;
-       u32 status;
+       u32 status = 0;
+       bool ignore_crc = false;
 
        BUG_ON(!card);
        BUG_ON(!card->host);
@@ -408,17 +444,37 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
        if (!use_busy_signal)
                return 0;
 
-       /* Must check status to be sure of no errors */
+       /*
+        * Must check status to be sure of no errors
+        * If CMD13 is to check the busy completion of the timing change,
+        * disable the check of CRC error.
+        */
+       if (index == EXT_CSD_HS_TIMING &&
+           !(card->host->caps & MMC_CAP_WAIT_WHILE_BUSY))
+               ignore_crc = true;
+
        timeout = jiffies + msecs_to_jiffies(MMC_OPS_TIMEOUT_MS);
        do {
-               err = mmc_send_status(card, &status);
-               if (err)
-                       return err;
+               if (send_status) {
+                       err = __mmc_send_status(card, &status, ignore_crc);
+                       if (err)
+                               return err;
+               }
                if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
                        break;
                if (mmc_host_is_spi(card->host))
                        break;
 
+               /*
+                * We are not allowed to issue a status command and the host
+                * does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only
+                * rely on waiting for the stated timeout to be sufficient.
+                */
+               if (!send_status) {
+                       mmc_delay(timeout_ms);
+                       return 0;
+               }
+
                /* Timeout if the device never leaves the program state. */
                if (time_after(jiffies, timeout)) {
                        pr_err("%s: Card stuck in programming state! %s\n",
@@ -445,36 +501,10 @@ EXPORT_SYMBOL_GPL(__mmc_switch);
 int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
                unsigned int timeout_ms)
 {
-       return __mmc_switch(card, set, index, value, timeout_ms, true);
+       return __mmc_switch(card, set, index, value, timeout_ms, true, true);
 }
 EXPORT_SYMBOL_GPL(mmc_switch);
 
-int mmc_send_status(struct mmc_card *card, u32 *status)
-{
-       int err;
-       struct mmc_command cmd = {0};
-
-       BUG_ON(!card);
-       BUG_ON(!card->host);
-
-       cmd.opcode = MMC_SEND_STATUS;
-       if (!mmc_host_is_spi(card->host))
-               cmd.arg = card->rca << 16;
-       cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
-
-       err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
-       if (err)
-               return err;
-
-       /* NOTE: callers are required to understand the difference
-        * between "native" and SPI format status words!
-        */
-       if (status)
-               *status = cmd.resp[0];
-
-       return 0;
-}
-
 static int
 mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
                  u8 len)
index 5e8823dc3ef613b70e24ff3d6e16c143da2976a2..6f42050b7ccc6d829d6b58ece04b1177e73cbe80 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/stat.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
@@ -721,6 +722,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
        int err;
        u32 max_current;
        int retries = 10;
+       u32 pocr = ocr;
 
 try_again:
        if (!retries) {
@@ -773,7 +775,8 @@ try_again:
         */
        if (!mmc_host_is_spi(host) && rocr &&
           ((*rocr & 0x41000000) == 0x41000000)) {
-               err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
+               err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
+                                       pocr);
                if (err == -EAGAIN) {
                        retries--;
                        goto try_again;
@@ -935,6 +938,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
                if (IS_ERR(card))
                        return PTR_ERR(card);
 
+               card->ocr = ocr;
                card->type = MMC_TYPE_SD;
                memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
        }
@@ -1064,10 +1068,7 @@ static void mmc_sd_detect(struct mmc_host *host)
        }
 }
 
-/*
- * Suspend callback from host.
- */
-static int mmc_sd_suspend(struct mmc_host *host)
+static int _mmc_sd_suspend(struct mmc_host *host)
 {
        int err = 0;
 
@@ -1075,34 +1076,77 @@ static int mmc_sd_suspend(struct mmc_host *host)
        BUG_ON(!host->card);
 
        mmc_claim_host(host);
+
+       if (mmc_card_suspended(host->card))
+               goto out;
+
        if (!mmc_host_is_spi(host))
                err = mmc_deselect_cards(host);
        host->card->state &= ~MMC_STATE_HIGHSPEED;
-       if (!err)
+       if (!err) {
                mmc_power_off(host);
+               mmc_card_set_suspended(host->card);
+       }
+
+out:
        mmc_release_host(host);
+       return err;
+}
+
+/*
+ * Callback for suspend
+ */
+static int mmc_sd_suspend(struct mmc_host *host)
+{
+       int err;
+
+       err = _mmc_sd_suspend(host);
+       if (!err) {
+               pm_runtime_disable(&host->card->dev);
+               pm_runtime_set_suspended(&host->card->dev);
+       }
 
        return err;
 }
 
 /*
- * Resume callback from host.
- *
  * This function tries to determine if the same card is still present
  * and, if so, restore all state to it.
  */
-static int mmc_sd_resume(struct mmc_host *host)
+static int _mmc_sd_resume(struct mmc_host *host)
 {
-       int err;
+       int err = 0;
 
        BUG_ON(!host);
        BUG_ON(!host->card);
 
        mmc_claim_host(host);
-       mmc_power_up(host);
-       mmc_select_voltage(host, host->ocr);
-       err = mmc_sd_init_card(host, host->ocr, host->card);
+
+       if (!mmc_card_suspended(host->card))
+               goto out;
+
+       mmc_power_up(host, host->card->ocr);
+       err = mmc_sd_init_card(host, host->card->ocr, host->card);
+       mmc_card_clr_suspended(host->card);
+
+out:
        mmc_release_host(host);
+       return err;
+}
+
+/*
+ * Callback for resume
+ */
+static int mmc_sd_resume(struct mmc_host *host)
+{
+       int err = 0;
+
+       if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
+               err = _mmc_sd_resume(host);
+               pm_runtime_set_active(&host->card->dev);
+               pm_runtime_mark_last_busy(&host->card->dev);
+       }
+       pm_runtime_enable(&host->card->dev);
 
        return err;
 }
@@ -1117,18 +1161,11 @@ static int mmc_sd_runtime_suspend(struct mmc_host *host)
        if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
                return 0;
 
-       mmc_claim_host(host);
-
-       err = mmc_sd_suspend(host);
-       if (err) {
+       err = _mmc_sd_suspend(host);
+       if (err)
                pr_err("%s: error %d doing aggessive suspend\n",
                        mmc_hostname(host), err);
-               goto out;
-       }
-       mmc_power_off(host);
 
-out:
-       mmc_release_host(host);
        return err;
 }
 
@@ -1139,18 +1176,14 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
 {
        int err;
 
-       if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
+       if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
                return 0;
 
-       mmc_claim_host(host);
-
-       mmc_power_up(host);
-       err = mmc_sd_resume(host);
+       err = _mmc_sd_resume(host);
        if (err)
                pr_err("%s: error %d doing aggessive resume\n",
                        mmc_hostname(host), err);
 
-       mmc_release_host(host);
        return 0;
 }
 
@@ -1160,7 +1193,7 @@ static int mmc_sd_power_restore(struct mmc_host *host)
 
        host->card->state &= ~MMC_STATE_HIGHSPEED;
        mmc_claim_host(host);
-       ret = mmc_sd_init_card(host, host->ocr, host->card);
+       ret = mmc_sd_init_card(host, host->card->ocr, host->card);
        mmc_release_host(host);
 
        return ret;
@@ -1205,7 +1238,7 @@ static void mmc_sd_attach_bus_ops(struct mmc_host *host)
 int mmc_attach_sd(struct mmc_host *host)
 {
        int err;
-       u32 ocr;
+       u32 ocr, rocr;
 
        BUG_ON(!host);
        WARN_ON(!host->claimed);
@@ -1229,31 +1262,12 @@ int mmc_attach_sd(struct mmc_host *host)
                        goto err;
        }
 
-       /*
-        * Sanity check the voltages that the card claims to
-        * support.
-        */
-       if (ocr & 0x7F) {
-               pr_warning("%s: card claims to support voltages "
-                      "below the defined range. These will be ignored.\n",
-                      mmc_hostname(host));
-               ocr &= ~0x7F;
-       }
-
-       if ((ocr & MMC_VDD_165_195) &&
-           !(host->ocr_avail_sd & MMC_VDD_165_195)) {
-               pr_warning("%s: SD card claims to support the "
-                      "incompletely defined 'low voltage range'. This "
-                      "will be ignored.\n", mmc_hostname(host));
-               ocr &= ~MMC_VDD_165_195;
-       }
-
-       host->ocr = mmc_select_voltage(host, ocr);
+       rocr = mmc_select_voltage(host, ocr);
 
        /*
         * Can we support the voltage(s) of the card(s)?
         */
-       if (!host->ocr) {
+       if (!rocr) {
                err = -EINVAL;
                goto err;
        }
@@ -1261,7 +1275,7 @@ int mmc_attach_sd(struct mmc_host *host)
        /*
         * Detect and init the card.
         */
-       err = mmc_sd_init_card(host, host->ocr, NULL);
+       err = mmc_sd_init_card(host, rocr, NULL);
        if (err)
                goto err;
 
index 80d89cff7306533071c8f7f71aac97205b942d31..4d721c6e2af01026ea967dbd54bdaf17c8648aee 100644 (file)
@@ -593,23 +593,28 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
        struct mmc_card *card;
        int err;
        int retries = 10;
+       u32 rocr = 0;
+       u32 ocr_card = ocr;
 
        BUG_ON(!host);
        WARN_ON(!host->claimed);
 
+       /* to query card if 1.8V signalling is supported */
+       if (mmc_host_uhs(host))
+               ocr |= R4_18V_PRESENT;
+
 try_again:
        if (!retries) {
                pr_warning("%s: Skipping voltage switch\n",
                                mmc_hostname(host));
                ocr &= ~R4_18V_PRESENT;
-               host->ocr &= ~R4_18V_PRESENT;
        }
 
        /*
         * Inform the card of the voltage
         */
        if (!powered_resume) {
-               err = mmc_send_io_op_cond(host, host->ocr, &ocr);
+               err = mmc_send_io_op_cond(host, ocr, &rocr);
                if (err)
                        goto err;
        }
@@ -632,8 +637,8 @@ try_again:
                goto err;
        }
 
-       if ((ocr & R4_MEMORY_PRESENT) &&
-           mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid, NULL) == 0) {
+       if ((rocr & R4_MEMORY_PRESENT) &&
+           mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) {
                card->type = MMC_TYPE_SD_COMBO;
 
                if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO ||
@@ -663,8 +668,9 @@ try_again:
         * systems that claim 1.8v signalling in fact do not support
         * it.
         */
-       if (!powered_resume && (ocr & R4_18V_PRESENT) && mmc_host_uhs(host)) {
-               err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
+       if (!powered_resume && (rocr & ocr & R4_18V_PRESENT)) {
+               err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
+                                       ocr);
                if (err == -EAGAIN) {
                        sdio_reset(host);
                        mmc_go_idle(host);
@@ -674,12 +680,10 @@ try_again:
                        goto try_again;
                } else if (err) {
                        ocr &= ~R4_18V_PRESENT;
-                       host->ocr &= ~R4_18V_PRESENT;
                }
                err = 0;
        } else {
                ocr &= ~R4_18V_PRESENT;
-               host->ocr &= ~R4_18V_PRESENT;
        }
 
        /*
@@ -759,6 +763,7 @@ try_again:
 
                card = oldcard;
        }
+       card->ocr = ocr_card;
        mmc_fixup_device(card, NULL);
 
        if (card->type == MMC_TYPE_SD_COMBO) {
@@ -981,8 +986,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
 
        /* Restore power if needed */
        if (!mmc_card_keep_power(host)) {
-               mmc_power_up(host);
-               mmc_select_voltage(host, host->ocr);
+               mmc_power_up(host, host->card->ocr);
                /*
                 * Tell runtime PM core we just powered up the card,
                 * since it still believes the card is powered off.
@@ -1000,7 +1004,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
        if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
                sdio_reset(host);
                mmc_go_idle(host);
-               err = mmc_sdio_init_card(host, host->ocr, host->card,
+               err = mmc_sdio_init_card(host, host->card->ocr, host->card,
                                        mmc_card_keep_power(host));
        } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
                /* We may have switched to 1-bit mode during suspend */
@@ -1040,7 +1044,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
 static int mmc_sdio_power_restore(struct mmc_host *host)
 {
        int ret;
-       u32 ocr;
 
        BUG_ON(!host);
        BUG_ON(!host->card);
@@ -1062,32 +1065,17 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
         * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
         * harmless in other situations.
         *
-        * With these steps taken, mmc_select_voltage() is also required to
-        * restore the correct voltage setting of the card.
         */
 
        sdio_reset(host);
        mmc_go_idle(host);
        mmc_send_if_cond(host, host->ocr_avail);
 
-       ret = mmc_send_io_op_cond(host, 0, &ocr);
+       ret = mmc_send_io_op_cond(host, 0, NULL);
        if (ret)
                goto out;
 
-       if (host->ocr_avail_sdio)
-               host->ocr_avail = host->ocr_avail_sdio;
-
-       host->ocr = mmc_select_voltage(host, ocr & ~0x7F);
-       if (!host->ocr) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (mmc_host_uhs(host))
-               /* to query card if 1.8V signalling is supported */
-               host->ocr |= R4_18V_PRESENT;
-
-       ret = mmc_sdio_init_card(host, host->ocr, host->card,
+       ret = mmc_sdio_init_card(host, host->card->ocr, host->card,
                                mmc_card_keep_power(host));
        if (!ret && host->sdio_irqs)
                mmc_signal_sdio_irq(host);
@@ -1108,7 +1096,7 @@ static int mmc_sdio_runtime_suspend(struct mmc_host *host)
 static int mmc_sdio_runtime_resume(struct mmc_host *host)
 {
        /* Restore power and re-initialize. */
-       mmc_power_up(host);
+       mmc_power_up(host, host->card->ocr);
        return mmc_sdio_power_restore(host);
 }
 
@@ -1131,7 +1119,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = {
 int mmc_attach_sdio(struct mmc_host *host)
 {
        int err, i, funcs;
-       u32 ocr;
+       u32 ocr, rocr;
        struct mmc_card *card;
 
        BUG_ON(!host);
@@ -1145,23 +1133,13 @@ int mmc_attach_sdio(struct mmc_host *host)
        if (host->ocr_avail_sdio)
                host->ocr_avail = host->ocr_avail_sdio;
 
-       /*
-        * Sanity check the voltages that the card claims to
-        * support.
-        */
-       if (ocr & 0x7F) {
-               pr_warning("%s: card claims to support voltages "
-                      "below the defined range. These will be ignored.\n",
-                      mmc_hostname(host));
-               ocr &= ~0x7F;
-       }
 
-       host->ocr = mmc_select_voltage(host, ocr);
+       rocr = mmc_select_voltage(host, ocr);
 
        /*
         * Can we support the voltage(s) of the card(s)?
         */
-       if (!host->ocr) {
+       if (!rocr) {
                err = -EINVAL;
                goto err;
        }
@@ -1169,22 +1147,10 @@ int mmc_attach_sdio(struct mmc_host *host)
        /*
         * Detect and init the card.
         */
-       if (mmc_host_uhs(host))
-               /* to query card if 1.8V signalling is supported */
-               host->ocr |= R4_18V_PRESENT;
+       err = mmc_sdio_init_card(host, rocr, NULL, 0);
+       if (err)
+               goto err;
 
-       err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
-       if (err) {
-               if (err == -EAGAIN) {
-                       /*
-                        * Retry initialization with S18R set to 0.
-                        */
-                       host->ocr &= ~R4_18V_PRESENT;
-                       err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
-               }
-               if (err)
-                       goto err;
-       }
        card = host->card;
 
        /*
index ef8956568c3a2978b90cab02a9dc0ed56c76254f..157b570ba343e4648b796e7330e7b75bc052d00a 100644 (file)
@@ -308,8 +308,7 @@ static void sdio_acpi_set_handle(struct sdio_func *func)
        struct mmc_host *host = func->card->host;
        u64 addr = (host->slotno << 16) | func->num;
 
-       ACPI_HANDLE_SET(&func->dev,
-                       acpi_get_child(ACPI_HANDLE(host->parent), addr));
+       acpi_preset_companion(&func->dev, ACPI_HANDLE(host->parent), addr);
 }
 #else
 static inline void sdio_acpi_set_handle(struct sdio_func *func) {}
index 69e438ee043e6f8a9c151d3447f6a9e418544231..2cbb4516d3530fd4167db6533c6da4740ed60a46 100644 (file)
@@ -255,7 +255,6 @@ struct atmel_mci_slot {
 #define ATMCI_CARD_PRESENT     0
 #define ATMCI_CARD_NEED_INIT   1
 #define ATMCI_SHUTDOWN         2
-#define ATMCI_SUSPENDED                3
 
        int                     detect_pin;
        int                     wp_pin;
@@ -589,6 +588,13 @@ static void atmci_timeout_timer(unsigned long data)
        if (host->mrq->cmd->data) {
                host->mrq->cmd->data->error = -ETIMEDOUT;
                host->data = NULL;
+               /*
+                * With some SDIO modules, sometimes DMA transfer hangs. If
+                * stop_transfer() is not called then the DMA request is not
+                * removed, following ones are queued and never computed.
+                */
+               if (host->state == STATE_DATA_XFER)
+                       host->stop_transfer(host);
        } else {
                host->mrq->cmd->error = -ETIMEDOUT;
                host->cmd = NULL;
@@ -1803,12 +1809,14 @@ static void atmci_tasklet_func(unsigned long priv)
                        if (unlikely(status)) {
                                host->stop_transfer(host);
                                host->data = NULL;
-                               if (status & ATMCI_DTOE) {
-                                       data->error = -ETIMEDOUT;
-                               } else if (status & ATMCI_DCRCE) {
-                                       data->error = -EILSEQ;
-                               } else {
-                                       data->error = -EIO;
+                               if (data) {
+                                       if (status & ATMCI_DTOE) {
+                                               data->error = -ETIMEDOUT;
+                                       } else if (status & ATMCI_DCRCE) {
+                                               data->error = -EILSEQ;
+                                       } else {
+                                               data->error = -EIO;
+                                       }
                                }
                        }
 
@@ -2520,70 +2528,10 @@ static int __exit atmci_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int atmci_suspend(struct device *dev)
-{
-       struct atmel_mci *host = dev_get_drvdata(dev);
-       int i;
-
-        for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
-               struct atmel_mci_slot *slot = host->slot[i];
-               int ret;
-
-               if (!slot)
-                       continue;
-               ret = mmc_suspend_host(slot->mmc);
-               if (ret < 0) {
-                       while (--i >= 0) {
-                               slot = host->slot[i];
-                               if (slot
-                               && test_bit(ATMCI_SUSPENDED, &slot->flags)) {
-                                       mmc_resume_host(host->slot[i]->mmc);
-                                       clear_bit(ATMCI_SUSPENDED, &slot->flags);
-                               }
-                       }
-                       return ret;
-               } else {
-                       set_bit(ATMCI_SUSPENDED, &slot->flags);
-               }
-       }
-
-       return 0;
-}
-
-static int atmci_resume(struct device *dev)
-{
-       struct atmel_mci *host = dev_get_drvdata(dev);
-       int i;
-       int ret = 0;
-
-       for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
-               struct atmel_mci_slot *slot = host->slot[i];
-               int err;
-
-               slot = host->slot[i];
-               if (!slot)
-                       continue;
-               if (!test_bit(ATMCI_SUSPENDED, &slot->flags))
-                       continue;
-               err = mmc_resume_host(slot->mmc);
-               if (err < 0)
-                       ret = err;
-               else
-                       clear_bit(ATMCI_SUSPENDED, &slot->flags);
-       }
-
-       return ret;
-}
-#endif
-
-static SIMPLE_DEV_PM_OPS(atmci_pm, atmci_suspend, atmci_resume);
-
 static struct platform_driver atmci_driver = {
        .remove         = __exit_p(atmci_remove),
        .driver         = {
                .name           = "atmel_mci",
-               .pm             = &atmci_pm,
                .of_match_table = of_match_ptr(atmci_dt_ids),
        },
 };
index df9becdd2e991739010fc62638757bf02387aeda..f5443a6c4915d2580ad8b05b38a111318e3b665e 100644 (file)
@@ -1157,11 +1157,6 @@ static int au1xmmc_remove(struct platform_device *pdev)
 static int au1xmmc_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct au1xmmc_host *host = platform_get_drvdata(pdev);
-       int ret;
-
-       ret = mmc_suspend_host(host->mmc);
-       if (ret)
-               return ret;
 
        au_writel(0, HOST_CONFIG2(host));
        au_writel(0, HOST_CONFIG(host));
@@ -1178,7 +1173,7 @@ static int au1xmmc_resume(struct platform_device *pdev)
 
        au1xmmc_reset_controller(host);
 
-       return mmc_resume_host(host->mmc);
+       return 0;
 }
 #else
 #define au1xmmc_suspend NULL
index 94fae2f1baaf4de39f9c0e929f35c973b8d4b0b5..2b7f37e82ca94edf7c875c8cd32614675d625a54 100644 (file)
@@ -391,6 +391,7 @@ static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                /* Disable 4 bit SDIO */
                cfg &= ~SD4E;
        }
+       bfin_write_SDH_CFG(cfg);
 
        host->power_mode = ios->power_mode;
 #ifndef RSI_BLKSZ
@@ -415,7 +416,6 @@ static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                cfg &= ~SD_CMD_OD;
 # endif
 
-
        if (ios->power_mode != MMC_POWER_OFF)
                cfg |= PWR_ON;
        else
@@ -433,7 +433,6 @@ static void sdh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                clk_ctl |= CLK_E;
                host->clk_div = clk_div;
                bfin_write_SDH_CLK_CTL(clk_ctl);
-
        } else
                sdh_stop_clock(host);
 
@@ -640,21 +639,15 @@ static int sdh_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM
 static int sdh_suspend(struct platform_device *dev, pm_message_t state)
 {
-       struct mmc_host *mmc = platform_get_drvdata(dev);
        struct bfin_sd_host *drv_data = get_sdh_data(dev);
-       int ret = 0;
-
-       if (mmc)
-               ret = mmc_suspend_host(mmc);
 
        peripheral_free_list(drv_data->pin_req);
 
-       return ret;
+       return 0;
 }
 
 static int sdh_resume(struct platform_device *dev)
 {
-       struct mmc_host *mmc = platform_get_drvdata(dev);
        struct bfin_sd_host *drv_data = get_sdh_data(dev);
        int ret = 0;
 
@@ -665,10 +658,6 @@ static int sdh_resume(struct platform_device *dev)
        }
 
        sdh_reset();
-
-       if (mmc)
-               ret = mmc_resume_host(mmc);
-
        return ret;
 }
 #else
index 9d6e2b844404d681bf5b5e61c22ccb026cf51181..1087b4c79cd661bbf8bfe57f73470e681324b668 100644 (file)
@@ -667,12 +667,6 @@ static const struct mmc_host_ops cb710_mmc_host = {
 static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
-       struct mmc_host *mmc = cb710_slot_to_mmc(slot);
-       int err;
-
-       err = mmc_suspend_host(mmc);
-       if (err)
-               return err;
 
        cb710_mmc_enable_irq(slot, 0, ~0);
        return 0;
@@ -681,11 +675,9 @@ static int cb710_mmc_suspend(struct platform_device *pdev, pm_message_t state)
 static int cb710_mmc_resume(struct platform_device *pdev)
 {
        struct cb710_slot *slot = cb710_pdev_to_slot(pdev);
-       struct mmc_host *mmc = cb710_slot_to_mmc(slot);
 
        cb710_mmc_enable_irq(slot, 0, ~0);
-
-       return mmc_resume_host(mmc);
+       return 0;
 }
 
 #endif /* CONFIG_PM */
index e9fa87df909c248d4fc6d9c30244360bf28327b7..d6153740b77fa174060679a4fe3d31d18e619eb9 100644 (file)
@@ -193,7 +193,6 @@ struct mmc_davinci_host {
 #define DAVINCI_MMC_DATADIR_READ       1
 #define DAVINCI_MMC_DATADIR_WRITE      2
        unsigned char data_dir;
-       unsigned char suspended;
 
        /* buffer is used during PIO of one scatterlist segment, and
         * is updated along with buffer_bytes_left.  bytes_left applies
@@ -1435,38 +1434,23 @@ static int davinci_mmcsd_suspend(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct mmc_davinci_host *host = platform_get_drvdata(pdev);
-       int ret;
 
-       ret = mmc_suspend_host(host->mmc);
-       if (!ret) {
-               writel(0, host->base + DAVINCI_MMCIM);
-               mmc_davinci_reset_ctrl(host, 1);
-               clk_disable(host->clk);
-               host->suspended = 1;
-       } else {
-               host->suspended = 0;
-       }
+       writel(0, host->base + DAVINCI_MMCIM);
+       mmc_davinci_reset_ctrl(host, 1);
+       clk_disable(host->clk);
 
-       return ret;
+       return 0;
 }
 
 static int davinci_mmcsd_resume(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct mmc_davinci_host *host = platform_get_drvdata(pdev);
-       int ret;
-
-       if (!host->suspended)
-               return 0;
 
        clk_enable(host->clk);
-
        mmc_davinci_reset_ctrl(host, 0);
-       ret = mmc_resume_host(host->mmc);
-       if (!ret)
-               host->suspended = 0;
 
-       return ret;
+       return 0;
 }
 
 static const struct dev_pm_ops davinci_mmcsd_pm = {
index 6a1fa2110a057b42d2a79cfb3407bb0f8fb8f3b8..3423c5ed50c7a0ec918af7c7adcba7b2e5d2baed 100644 (file)
 #include <linux/clk.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/dw_mmc.h>
+#include <linux/mmc/mmc.h>
 #include <linux/of.h>
 #include <linux/of_gpio.h>
+#include <linux/slab.h>
 
 #include "dw_mmc.h"
 #include "dw_mmc-pltfm.h"
 #define SDMMC_CLKSEL_TIMING(x, y, z)   (SDMMC_CLKSEL_CCLK_SAMPLE(x) |  \
                                        SDMMC_CLKSEL_CCLK_DRIVE(y) |    \
                                        SDMMC_CLKSEL_CCLK_DIVIDER(z))
+#define SDMMC_CLKSEL_WAKEUP_INT                BIT(11)
 
 #define EXYNOS4210_FIXED_CIU_CLK_DIV   2
 #define EXYNOS4412_FIXED_CIU_CLK_DIV   4
 
+/* Block number in eMMC */
+#define DWMCI_BLOCK_NUM                0xFFFFFFFF
+
+#define SDMMC_EMMCP_BASE       0x1000
+#define SDMMC_MPSECURITY       (SDMMC_EMMCP_BASE + 0x0010)
+#define SDMMC_MPSBEGIN0                (SDMMC_EMMCP_BASE + 0x0200)
+#define SDMMC_MPSEND0          (SDMMC_EMMCP_BASE + 0x0204)
+#define SDMMC_MPSCTRL0         (SDMMC_EMMCP_BASE + 0x020C)
+
+/* SMU control bits */
+#define DWMCI_MPSCTRL_SECURE_READ_BIT          BIT(7)
+#define DWMCI_MPSCTRL_SECURE_WRITE_BIT         BIT(6)
+#define DWMCI_MPSCTRL_NON_SECURE_READ_BIT      BIT(5)
+#define DWMCI_MPSCTRL_NON_SECURE_WRITE_BIT     BIT(4)
+#define DWMCI_MPSCTRL_USE_FUSE_KEY             BIT(3)
+#define DWMCI_MPSCTRL_ECB_MODE                 BIT(2)
+#define DWMCI_MPSCTRL_ENCRYPTION               BIT(1)
+#define DWMCI_MPSCTRL_VALID                    BIT(0)
+
+#define EXYNOS_CCLKIN_MIN      50000000        /* unit: HZ */
+
 /* Variations in Exynos specific dw-mshc controller */
 enum dw_mci_exynos_type {
        DW_MCI_TYPE_EXYNOS4210,
        DW_MCI_TYPE_EXYNOS4412,
        DW_MCI_TYPE_EXYNOS5250,
        DW_MCI_TYPE_EXYNOS5420,
+       DW_MCI_TYPE_EXYNOS5420_SMU,
 };
 
 /* Exynos implementation specific driver private data */
@@ -48,6 +73,7 @@ struct dw_mci_exynos_priv_data {
        u8                              ciu_div;
        u32                             sdr_timing;
        u32                             ddr_timing;
+       u32                             cur_speed;
 };
 
 static struct dw_mci_exynos_compatible {
@@ -66,44 +92,80 @@ static struct dw_mci_exynos_compatible {
        }, {
                .compatible     = "samsung,exynos5420-dw-mshc",
                .ctrl_type      = DW_MCI_TYPE_EXYNOS5420,
+       }, {
+               .compatible     = "samsung,exynos5420-dw-mshc-smu",
+               .ctrl_type      = DW_MCI_TYPE_EXYNOS5420_SMU,
        },
 };
 
 static int dw_mci_exynos_priv_init(struct dw_mci *host)
 {
-       struct dw_mci_exynos_priv_data *priv;
-       int idx;
-
-       priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv) {
-               dev_err(host->dev, "mem alloc failed for private data\n");
-               return -ENOMEM;
-       }
+       struct dw_mci_exynos_priv_data *priv = host->priv;
 
-       for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
-               if (of_device_is_compatible(host->dev->of_node,
-                                       exynos_compat[idx].compatible))
-                       priv->ctrl_type = exynos_compat[idx].ctrl_type;
+       if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU) {
+               mci_writel(host, MPSBEGIN0, 0);
+               mci_writel(host, MPSEND0, DWMCI_BLOCK_NUM);
+               mci_writel(host, MPSCTRL0, DWMCI_MPSCTRL_SECURE_WRITE_BIT |
+                          DWMCI_MPSCTRL_NON_SECURE_READ_BIT |
+                          DWMCI_MPSCTRL_VALID |
+                          DWMCI_MPSCTRL_NON_SECURE_WRITE_BIT);
        }
 
-       host->priv = priv;
        return 0;
 }
 
 static int dw_mci_exynos_setup_clock(struct dw_mci *host)
 {
        struct dw_mci_exynos_priv_data *priv = host->priv;
+       unsigned long rate = clk_get_rate(host->ciu_clk);
 
-       if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250 ||
-               priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420)
-               host->bus_hz /= (priv->ciu_div + 1);
-       else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
-               host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV;
-       else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
-               host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV;
+       host->bus_hz = rate / (priv->ciu_div + 1);
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int dw_mci_exynos_suspend(struct device *dev)
+{
+       struct dw_mci *host = dev_get_drvdata(dev);
+
+       return dw_mci_suspend(host);
+}
+
+static int dw_mci_exynos_resume(struct device *dev)
+{
+       struct dw_mci *host = dev_get_drvdata(dev);
+
+       dw_mci_exynos_priv_init(host);
+       return dw_mci_resume(host);
+}
+
+/**
+ * dw_mci_exynos_resume_noirq - Exynos-specific resume code
+ *
+ * On exynos5420 there is a silicon errata that will sometimes leave the
+ * WAKEUP_INT bit in the CLKSEL register asserted.  This bit is 1 to indicate
+ * that it fired and we can clear it by writing a 1 back.  Clear it to prevent
+ * interrupts from going off constantly.
+ *
+ * We run this code on all exynos variants because it doesn't hurt.
+ */
+
+static int dw_mci_exynos_resume_noirq(struct device *dev)
+{
+       struct dw_mci *host = dev_get_drvdata(dev);
+       u32 clksel;
+
+       clksel = mci_readl(host, CLKSEL);
+       if (clksel & SDMMC_CLKSEL_WAKEUP_INT)
+               mci_writel(host, CLKSEL, clksel);
 
        return 0;
 }
+#else
+#define dw_mci_exynos_suspend          NULL
+#define dw_mci_exynos_resume           NULL
+#define dw_mci_exynos_resume_noirq     NULL
+#endif /* CONFIG_PM_SLEEP */
 
 static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
 {
@@ -121,23 +183,68 @@ static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
 static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
 {
        struct dw_mci_exynos_priv_data *priv = host->priv;
+       unsigned int wanted = ios->clock;
+       unsigned long actual;
+       u8 div = priv->ciu_div + 1;
 
-       if (ios->timing == MMC_TIMING_UHS_DDR50)
+       if (ios->timing == MMC_TIMING_UHS_DDR50) {
                mci_writel(host, CLKSEL, priv->ddr_timing);
-       else
+               /* Should be double rate for DDR mode */
+               if (ios->bus_width == MMC_BUS_WIDTH_8)
+                       wanted <<= 1;
+       } else {
                mci_writel(host, CLKSEL, priv->sdr_timing);
+       }
+
+       /* Don't care if wanted clock is zero */
+       if (!wanted)
+               return;
+
+       /* Guaranteed minimum frequency for cclkin */
+       if (wanted < EXYNOS_CCLKIN_MIN)
+               wanted = EXYNOS_CCLKIN_MIN;
+
+       if (wanted != priv->cur_speed) {
+               int ret = clk_set_rate(host->ciu_clk, wanted * div);
+               if (ret)
+                       dev_warn(host->dev,
+                               "failed to set clk-rate %u error: %d\n",
+                                wanted * div, ret);
+               actual = clk_get_rate(host->ciu_clk);
+               host->bus_hz = actual / div;
+               priv->cur_speed = wanted;
+               host->current_speed = 0;
+       }
 }
 
 static int dw_mci_exynos_parse_dt(struct dw_mci *host)
 {
-       struct dw_mci_exynos_priv_data *priv = host->priv;
+       struct dw_mci_exynos_priv_data *priv;
        struct device_node *np = host->dev->of_node;
        u32 timing[2];
        u32 div = 0;
+       int idx;
        int ret;
 
-       of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
-       priv->ciu_div = div;
+       priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv) {
+               dev_err(host->dev, "mem alloc failed for private data\n");
+               return -ENOMEM;
+       }
+
+       for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
+               if (of_device_is_compatible(np, exynos_compat[idx].compatible))
+                       priv->ctrl_type = exynos_compat[idx].ctrl_type;
+       }
+
+       if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
+               priv->ciu_div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1;
+       else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
+               priv->ciu_div = EXYNOS4210_FIXED_CIU_CLK_DIV - 1;
+       else {
+               of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
+               priv->ciu_div = div;
+       }
 
        ret = of_property_read_u32_array(np,
                        "samsung,dw-mshc-sdr-timing", timing, 2);
@@ -152,9 +259,131 @@ static int dw_mci_exynos_parse_dt(struct dw_mci *host)
                return ret;
 
        priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
+       host->priv = priv;
        return 0;
 }
 
+static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host)
+{
+       return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL));
+}
+
+static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample)
+{
+       u32 clksel;
+       clksel = mci_readl(host, CLKSEL);
+       clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample);
+       mci_writel(host, CLKSEL, clksel);
+}
+
+static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
+{
+       u32 clksel;
+       u8 sample;
+
+       clksel = mci_readl(host, CLKSEL);
+       sample = (clksel + 1) & 0x7;
+       clksel = (clksel & ~0x7) | sample;
+       mci_writel(host, CLKSEL, clksel);
+       return sample;
+}
+
+static s8 dw_mci_exynos_get_best_clksmpl(u8 candiates)
+{
+       const u8 iter = 8;
+       u8 __c;
+       s8 i, loc = -1;
+
+       for (i = 0; i < iter; i++) {
+               __c = ror8(candiates, i);
+               if ((__c & 0xc7) == 0xc7) {
+                       loc = i;
+                       goto out;
+               }
+       }
+
+       for (i = 0; i < iter; i++) {
+               __c = ror8(candiates, i);
+               if ((__c & 0x83) == 0x83) {
+                       loc = i;
+                       goto out;
+               }
+       }
+
+out:
+       return loc;
+}
+
+static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode,
+                                       struct dw_mci_tuning_data *tuning_data)
+{
+       struct dw_mci *host = slot->host;
+       struct mmc_host *mmc = slot->mmc;
+       const u8 *blk_pattern = tuning_data->blk_pattern;
+       u8 *blk_test;
+       unsigned int blksz = tuning_data->blksz;
+       u8 start_smpl, smpl, candiates = 0;
+       s8 found = -1;
+       int ret = 0;
+
+       blk_test = kmalloc(blksz, GFP_KERNEL);
+       if (!blk_test)
+               return -ENOMEM;
+
+       start_smpl = dw_mci_exynos_get_clksmpl(host);
+
+       do {
+               struct mmc_request mrq = {NULL};
+               struct mmc_command cmd = {0};
+               struct mmc_command stop = {0};
+               struct mmc_data data = {0};
+               struct scatterlist sg;
+
+               cmd.opcode = opcode;
+               cmd.arg = 0;
+               cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
+
+               stop.opcode = MMC_STOP_TRANSMISSION;
+               stop.arg = 0;
+               stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
+
+               data.blksz = blksz;
+               data.blocks = 1;
+               data.flags = MMC_DATA_READ;
+               data.sg = &sg;
+               data.sg_len = 1;
+
+               sg_init_one(&sg, blk_test, blksz);
+               mrq.cmd = &cmd;
+               mrq.stop = &stop;
+               mrq.data = &data;
+               host->mrq = &mrq;
+
+               mci_writel(host, TMOUT, ~0);
+               smpl = dw_mci_exynos_move_next_clksmpl(host);
+
+               mmc_wait_for_req(mmc, &mrq);
+
+               if (!cmd.error && !data.error) {
+                       if (!memcmp(blk_pattern, blk_test, blksz))
+                               candiates |= (1 << smpl);
+               } else {
+                       dev_dbg(host->dev,
+                               "Tuning error: cmd.error:%d, data.error:%d\n",
+                               cmd.error, data.error);
+               }
+       } while (start_smpl != smpl);
+
+       found = dw_mci_exynos_get_best_clksmpl(candiates);
+       if (found >= 0)
+               dw_mci_exynos_set_clksmpl(host, found);
+       else
+               ret = -EIO;
+
+       kfree(blk_test);
+       return ret;
+}
+
 /* Common capabilities of Exynos4/Exynos5 SoC */
 static unsigned long exynos_dwmmc_caps[4] = {
        MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR |
@@ -171,6 +400,7 @@ static const struct dw_mci_drv_data exynos_drv_data = {
        .prepare_command        = dw_mci_exynos_prepare_command,
        .set_ios                = dw_mci_exynos_set_ios,
        .parse_dt               = dw_mci_exynos_parse_dt,
+       .execute_tuning         = dw_mci_exynos_execute_tuning,
 };
 
 static const struct of_device_id dw_mci_exynos_match[] = {
@@ -180,6 +410,8 @@ static const struct of_device_id dw_mci_exynos_match[] = {
                        .data = &exynos_drv_data, },
        { .compatible = "samsung,exynos5420-dw-mshc",
                        .data = &exynos_drv_data, },
+       { .compatible = "samsung,exynos5420-dw-mshc-smu",
+                       .data = &exynos_drv_data, },
        {},
 };
 MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
@@ -194,13 +426,20 @@ static int dw_mci_exynos_probe(struct platform_device *pdev)
        return dw_mci_pltfm_register(pdev, drv_data);
 }
 
+const struct dev_pm_ops dw_mci_exynos_pmops = {
+       SET_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend, dw_mci_exynos_resume)
+       .resume_noirq = dw_mci_exynos_resume_noirq,
+       .thaw_noirq = dw_mci_exynos_resume_noirq,
+       .restore_noirq = dw_mci_exynos_resume_noirq,
+};
+
 static struct platform_driver dw_mci_exynos_pltfm_driver = {
        .probe          = dw_mci_exynos_probe,
        .remove         = __exit_p(dw_mci_pltfm_remove),
        .driver         = {
                .name           = "dwmmc_exynos",
                .of_match_table = dw_mci_exynos_match,
-               .pm             = &dw_mci_pltfm_pmops,
+               .pm             = &dw_mci_exynos_pmops,
        },
 };
 
index 20897529ea5e10185a3d39864755ccdbeb8fea6b..5c496565529796f06ca4d26b280724376aa6348c 100644 (file)
@@ -39,7 +39,6 @@ int dw_mci_pltfm_register(struct platform_device *pdev,
 {
        struct dw_mci *host;
        struct resource *regs;
-       int ret;
 
        host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
        if (!host)
@@ -59,12 +58,6 @@ int dw_mci_pltfm_register(struct platform_device *pdev,
        if (IS_ERR(host->regs))
                return PTR_ERR(host->regs);
 
-       if (drv_data && drv_data->init) {
-               ret = drv_data->init(host);
-               if (ret)
-                       return ret;
-       }
-
        platform_set_drvdata(pdev, host);
        return dw_mci_probe(host);
 }
index 14b5961a851c43ed3a78e0df34d7be79e3cc0162..3e8e53ae3302b7231c64acaf7de991b6e6861b35 100644 (file)
@@ -38,21 +38,6 @@ struct dw_mci_socfpga_priv_data {
 
 static int dw_mci_socfpga_priv_init(struct dw_mci *host)
 {
-       struct dw_mci_socfpga_priv_data *priv;
-
-       priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
-       if (!priv) {
-               dev_err(host->dev, "mem alloc failed for private data\n");
-               return -ENOMEM;
-       }
-
-       priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
-       if (IS_ERR(priv->sysreg)) {
-               dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
-               return PTR_ERR(priv->sysreg);
-       }
-       host->priv = priv;
-
        return 0;
 }
 
@@ -79,12 +64,24 @@ static void dw_mci_socfpga_prepare_command(struct dw_mci *host, u32 *cmdr)
 
 static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
 {
-       struct dw_mci_socfpga_priv_data *priv = host->priv;
+       struct dw_mci_socfpga_priv_data *priv;
        struct device_node *np = host->dev->of_node;
        u32 timing[2];
        u32 div = 0;
        int ret;
 
+       priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv) {
+               dev_err(host->dev, "mem alloc failed for private data\n");
+               return -ENOMEM;
+       }
+
+       priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
+       if (IS_ERR(priv->sysreg)) {
+               dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
+               return PTR_ERR(priv->sysreg);
+       }
+
        ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div);
        if (ret)
                dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1");
@@ -96,6 +93,7 @@ static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
                return ret;
 
        priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]);
+       host->priv = priv;
        return 0;
 }
 
@@ -113,7 +111,7 @@ static const struct of_device_id dw_mci_socfpga_match[] = {
 };
 MODULE_DEVICE_TABLE(of, dw_mci_socfpga_match);
 
-int dw_mci_socfpga_probe(struct platform_device *pdev)
+static int dw_mci_socfpga_probe(struct platform_device *pdev)
 {
        const struct dw_mci_drv_data *drv_data;
        const struct of_device_id *match;
@@ -128,7 +126,7 @@ static struct platform_driver dw_mci_socfpga_pltfm_driver = {
        .remove         = __exit_p(dw_mci_pltfm_remove),
        .driver         = {
                .name           = "dwmmc_socfpga",
-               .of_match_table = of_match_ptr(dw_mci_socfpga_match),
+               .of_match_table = dw_mci_socfpga_match,
                .pm             = &dw_mci_pltfm_pmops,
        },
 };
index 018f365e5ae46c71a6e8a0f2327e9fb8775c900d..4bce0deec362c02ab8b5c99cf074ab0b7d669d6c 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/irq.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/mmc.h>
+#include <linux/mmc/sdio.h>
 #include <linux/mmc/dw_mmc.h>
 #include <linux/bitops.h>
 #include <linux/regulator/consumer.h>
@@ -50,6 +51,9 @@
 #define DW_MCI_RECV_STATUS     2
 #define DW_MCI_DMA_THRESHOLD   16
 
+#define DW_MCI_FREQ_MAX        200000000       /* unit: HZ */
+#define DW_MCI_FREQ_MIN        400000          /* unit: HZ */
+
 #ifdef CONFIG_MMC_DW_IDMAC
 #define IDMAC_INT_CLR          (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
                                 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
@@ -76,42 +80,39 @@ struct idmac_desc {
 };
 #endif /* CONFIG_MMC_DW_IDMAC */
 
-/**
- * struct dw_mci_slot - MMC slot state
- * @mmc: The mmc_host representing this slot.
- * @host: The MMC controller this slot is using.
- * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
- * @wp_gpio: If gpio_is_valid() we'll use this to read write protect.
- * @ctype: Card type for this slot.
- * @mrq: mmc_request currently being processed or waiting to be
- *     processed, or NULL when the slot is idle.
- * @queue_node: List node for placing this node in the @queue list of
- *     &struct dw_mci.
- * @clock: Clock rate configured by set_ios(). Protected by host->lock.
- * @flags: Random state bits associated with the slot.
- * @id: Number of this slot.
- * @last_detect_state: Most recently observed card detect state.
- */
-struct dw_mci_slot {
-       struct mmc_host         *mmc;
-       struct dw_mci           *host;
-
-       int                     quirks;
-       int                     wp_gpio;
-
-       u32                     ctype;
-
-       struct mmc_request      *mrq;
-       struct list_head        queue_node;
+static const u8 tuning_blk_pattern_4bit[] = {
+       0xff, 0x0f, 0xff, 0x00, 0xff, 0xcc, 0xc3, 0xcc,
+       0xc3, 0x3c, 0xcc, 0xff, 0xfe, 0xff, 0xfe, 0xef,
+       0xff, 0xdf, 0xff, 0xdd, 0xff, 0xfb, 0xff, 0xfb,
+       0xbf, 0xff, 0x7f, 0xff, 0x77, 0xf7, 0xbd, 0xef,
+       0xff, 0xf0, 0xff, 0xf0, 0x0f, 0xfc, 0xcc, 0x3c,
+       0xcc, 0x33, 0xcc, 0xcf, 0xff, 0xef, 0xff, 0xee,
+       0xff, 0xfd, 0xff, 0xfd, 0xdf, 0xff, 0xbf, 0xff,
+       0xbb, 0xff, 0xf7, 0xff, 0xf7, 0x7f, 0x7b, 0xde,
+};
 
-       unsigned int            clock;
-       unsigned long           flags;
-#define DW_MMC_CARD_PRESENT    0
-#define DW_MMC_CARD_NEED_INIT  1
-       int                     id;
-       int                     last_detect_state;
+static const u8 tuning_blk_pattern_8bit[] = {
+       0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
+       0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc,
+       0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, 0xff,
+       0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff,
+       0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, 0xdd,
+       0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb,
+       0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, 0xff,
+       0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff,
+       0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
+       0x00, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc,
+       0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff,
+       0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee,
+       0xff, 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd,
+       0xdd, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff,
+       0xbb, 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff,
+       0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
 };
 
+static inline bool dw_mci_fifo_reset(struct dw_mci *host);
+static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host);
+
 #if defined(CONFIG_DEBUG_FS)
 static int dw_mci_req_show(struct seq_file *s, void *v)
 {
@@ -249,10 +250,15 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
 
        cmdr = cmd->opcode;
 
-       if (cmdr == MMC_STOP_TRANSMISSION)
+       if (cmd->opcode == MMC_STOP_TRANSMISSION ||
+           cmd->opcode == MMC_GO_IDLE_STATE ||
+           cmd->opcode == MMC_GO_INACTIVE_STATE ||
+           (cmd->opcode == SD_IO_RW_DIRECT &&
+            ((cmd->arg >> 9) & 0x1FFFF) == SDIO_CCCR_ABORT))
                cmdr |= SDMMC_CMD_STOP;
        else
-               cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
+               if (cmd->opcode != MMC_SEND_STATUS && cmd->data)
+                       cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
 
        if (cmd->flags & MMC_RSP_PRESENT) {
                /* We expect a response, so set this bit */
@@ -279,6 +285,40 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
        return cmdr;
 }
 
+static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
+{
+       struct mmc_command *stop;
+       u32 cmdr;
+
+       if (!cmd->data)
+               return 0;
+
+       stop = &host->stop_abort;
+       cmdr = cmd->opcode;
+       memset(stop, 0, sizeof(struct mmc_command));
+
+       if (cmdr == MMC_READ_SINGLE_BLOCK ||
+           cmdr == MMC_READ_MULTIPLE_BLOCK ||
+           cmdr == MMC_WRITE_BLOCK ||
+           cmdr == MMC_WRITE_MULTIPLE_BLOCK) {
+               stop->opcode = MMC_STOP_TRANSMISSION;
+               stop->arg = 0;
+               stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
+       } else if (cmdr == SD_IO_RW_EXTENDED) {
+               stop->opcode = SD_IO_RW_DIRECT;
+               stop->arg |= (1 << 31) | (0 << 28) | (SDIO_CCCR_ABORT << 9) |
+                            ((cmd->arg >> 28) & 0x7);
+               stop->flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
+       } else {
+               return 0;
+       }
+
+       cmdr = stop->opcode | SDMMC_CMD_STOP |
+               SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
+
+       return cmdr;
+}
+
 static void dw_mci_start_command(struct dw_mci *host,
                                 struct mmc_command *cmd, u32 cmd_flags)
 {
@@ -293,9 +333,10 @@ static void dw_mci_start_command(struct dw_mci *host,
        mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
 }
 
-static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data)
+static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
 {
-       dw_mci_start_command(host, data->stop, host->stop_cmdr);
+       struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort;
+       dw_mci_start_command(host, stop, host->stop_cmdr);
 }
 
 /* DMA interface functions */
@@ -304,10 +345,10 @@ static void dw_mci_stop_dma(struct dw_mci *host)
        if (host->using_dma) {
                host->dma_ops->stop(host);
                host->dma_ops->cleanup(host);
-       } else {
-               /* Data transfer was stopped by the interrupt handler */
-               set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
        }
+
+       /* Data transfer was stopped by the interrupt handler */
+       set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
 }
 
 static int dw_mci_get_dma_dir(struct mmc_data *data)
@@ -331,6 +372,14 @@ static void dw_mci_dma_cleanup(struct dw_mci *host)
                                     dw_mci_get_dma_dir(data));
 }
 
+static void dw_mci_idmac_reset(struct dw_mci *host)
+{
+       u32 bmod = mci_readl(host, BMOD);
+       /* Software reset of DMA */
+       bmod |= SDMMC_IDMAC_SWRESET;
+       mci_writel(host, BMOD, bmod);
+}
+
 static void dw_mci_idmac_stop_dma(struct dw_mci *host)
 {
        u32 temp;
@@ -344,6 +393,7 @@ static void dw_mci_idmac_stop_dma(struct dw_mci *host)
        /* Stop the IDMAC running */
        temp = mci_readl(host, BMOD);
        temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
+       temp |= SDMMC_IDMAC_SWRESET;
        mci_writel(host, BMOD, temp);
 }
 
@@ -435,7 +485,7 @@ static int dw_mci_idmac_init(struct dw_mci *host)
        p->des3 = host->sg_dma;
        p->des0 = IDMAC_DES0_ER;
 
-       mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET);
+       dw_mci_idmac_reset(host);
 
        /* Mask out interrupts - get Tx & Rx complete only */
        mci_writel(host, IDSTS, IDMAC_INT_CLR);
@@ -532,6 +582,78 @@ static void dw_mci_post_req(struct mmc_host *mmc,
        data->host_cookie = 0;
 }
 
+static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
+{
+#ifdef CONFIG_MMC_DW_IDMAC
+       unsigned int blksz = data->blksz;
+       const u32 mszs[] = {1, 4, 8, 16, 32, 64, 128, 256};
+       u32 fifo_width = 1 << host->data_shift;
+       u32 blksz_depth = blksz / fifo_width, fifoth_val;
+       u32 msize = 0, rx_wmark = 1, tx_wmark, tx_wmark_invers;
+       int idx = (sizeof(mszs) / sizeof(mszs[0])) - 1;
+
+       tx_wmark = (host->fifo_depth) / 2;
+       tx_wmark_invers = host->fifo_depth - tx_wmark;
+
+       /*
+        * MSIZE is '1',
+        * if blksz is not a multiple of the FIFO width
+        */
+       if (blksz % fifo_width) {
+               msize = 0;
+               rx_wmark = 1;
+               goto done;
+       }
+
+       do {
+               if (!((blksz_depth % mszs[idx]) ||
+                    (tx_wmark_invers % mszs[idx]))) {
+                       msize = idx;
+                       rx_wmark = mszs[idx] - 1;
+                       break;
+               }
+       } while (--idx > 0);
+       /*
+        * If idx is '0', it won't be tried
+        * Thus, initial values are uesed
+        */
+done:
+       fifoth_val = SDMMC_SET_FIFOTH(msize, rx_wmark, tx_wmark);
+       mci_writel(host, FIFOTH, fifoth_val);
+#endif
+}
+
+static void dw_mci_ctrl_rd_thld(struct dw_mci *host, struct mmc_data *data)
+{
+       unsigned int blksz = data->blksz;
+       u32 blksz_depth, fifo_depth;
+       u16 thld_size;
+
+       WARN_ON(!(data->flags & MMC_DATA_READ));
+
+       if (host->timing != MMC_TIMING_MMC_HS200 &&
+           host->timing != MMC_TIMING_UHS_SDR104)
+               goto disable;
+
+       blksz_depth = blksz / (1 << host->data_shift);
+       fifo_depth = host->fifo_depth;
+
+       if (blksz_depth > fifo_depth)
+               goto disable;
+
+       /*
+        * If (blksz_depth) >= (fifo_depth >> 1), should be 'thld_size <= blksz'
+        * If (blksz_depth) <  (fifo_depth >> 1), should be thld_size = blksz
+        * Currently just choose blksz.
+        */
+       thld_size = blksz;
+       mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(thld_size, 1));
+       return;
+
+disable:
+       mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(0, 0));
+}
+
 static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
 {
        int sg_len;
@@ -556,6 +678,14 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
                 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
                 sg_len);
 
+       /*
+        * Decide the MSIZE and RX/TX Watermark.
+        * If current block size is same with previous size,
+        * no need to update fifoth.
+        */
+       if (host->prev_blksz != data->blksz)
+               dw_mci_adjust_fifoth(host, data);
+
        /* Enable the DMA interface */
        temp = mci_readl(host, CTRL);
        temp |= SDMMC_CTRL_DMA_ENABLE;
@@ -581,10 +711,12 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
        host->sg = NULL;
        host->data = data;
 
-       if (data->flags & MMC_DATA_READ)
+       if (data->flags & MMC_DATA_READ) {
                host->dir_status = DW_MCI_RECV_STATUS;
-       else
+               dw_mci_ctrl_rd_thld(host, data);
+       } else {
                host->dir_status = DW_MCI_SEND_STATUS;
+       }
 
        if (dw_mci_submit_data_dma(host, data)) {
                int flags = SG_MITER_ATOMIC;
@@ -606,6 +738,21 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
                temp = mci_readl(host, CTRL);
                temp &= ~SDMMC_CTRL_DMA_ENABLE;
                mci_writel(host, CTRL, temp);
+
+               /*
+                * Use the initial fifoth_val for PIO mode.
+                * If next issued data may be transfered by DMA mode,
+                * prev_blksz should be invalidated.
+                */
+               mci_writel(host, FIFOTH, host->fifoth_val);
+               host->prev_blksz = 0;
+       } else {
+               /*
+                * Keep the current block size.
+                * It will be used to decide whether to update
+                * fifoth register next time.
+                */
+               host->prev_blksz = data->blksz;
        }
 }
 
@@ -632,24 +779,31 @@ static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
 static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
 {
        struct dw_mci *host = slot->host;
+       unsigned int clock = slot->clock;
        u32 div;
        u32 clk_en_a;
 
-       if (slot->clock != host->current_speed || force_clkinit) {
-               div = host->bus_hz / slot->clock;
-               if (host->bus_hz % slot->clock && host->bus_hz > slot->clock)
+       if (!clock) {
+               mci_writel(host, CLKENA, 0);
+               mci_send_cmd(slot,
+                            SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
+       } else if (clock != host->current_speed || force_clkinit) {
+               div = host->bus_hz / clock;
+               if (host->bus_hz % clock && host->bus_hz > clock)
                        /*
                         * move the + 1 after the divide to prevent
                         * over-clocking the card.
                         */
                        div += 1;
 
-               div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0;
+               div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
 
-               dev_info(&slot->mmc->class_dev,
-                        "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ"
-                        " div = %d)\n", slot->id, host->bus_hz, slot->clock,
-                        div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div);
+               if ((clock << div) != slot->__clk_old || force_clkinit)
+                       dev_info(&slot->mmc->class_dev,
+                                "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
+                                slot->id, host->bus_hz, clock,
+                                div ? ((host->bus_hz / div) >> 1) :
+                                host->bus_hz, div);
 
                /* disable clock */
                mci_writel(host, CLKENA, 0);
@@ -676,9 +830,12 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
                mci_send_cmd(slot,
                             SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
 
-               host->current_speed = slot->clock;
+               /* keep the clock with reflecting clock dividor */
+               slot->__clk_old = clock << div;
        }
 
+       host->current_speed = clock;
+
        /* Set the current slot bus width */
        mci_writel(host, CTYPE, (slot->ctype << slot->id));
 }
@@ -700,7 +857,9 @@ static void __dw_mci_start_request(struct dw_mci *host,
 
        host->pending_events = 0;
        host->completed_events = 0;
+       host->cmd_status = 0;
        host->data_status = 0;
+       host->dir_status = 0;
 
        data = cmd->data;
        if (data) {
@@ -724,6 +883,8 @@ static void __dw_mci_start_request(struct dw_mci *host,
 
        if (mrq->stop)
                host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
+       else
+               host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
 }
 
 static void dw_mci_start_request(struct dw_mci *host,
@@ -806,14 +967,13 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                regs &= ~((0x1 << slot->id) << 16);
 
        mci_writel(slot->host, UHS_REG, regs);
+       slot->host->timing = ios->timing;
 
-       if (ios->clock) {
-               /*
-                * Use mirror of ios->clock to prevent race with mmc
-                * core ios update when finding the minimum.
-                */
-               slot->clock = ios->clock;
-       }
+       /*
+        * Use mirror of ios->clock to prevent race with mmc
+        * core ios update when finding the minimum.
+        */
+       slot->clock = ios->clock;
 
        if (drv_data && drv_data->set_ios)
                drv_data->set_ios(slot->host, ios);
@@ -939,6 +1099,38 @@ static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
        }
 }
 
+static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)
+{
+       struct dw_mci_slot *slot = mmc_priv(mmc);
+       struct dw_mci *host = slot->host;
+       const struct dw_mci_drv_data *drv_data = host->drv_data;
+       struct dw_mci_tuning_data tuning_data;
+       int err = -ENOSYS;
+
+       if (opcode == MMC_SEND_TUNING_BLOCK_HS200) {
+               if (mmc->ios.bus_width == MMC_BUS_WIDTH_8) {
+                       tuning_data.blk_pattern = tuning_blk_pattern_8bit;
+                       tuning_data.blksz = sizeof(tuning_blk_pattern_8bit);
+               } else if (mmc->ios.bus_width == MMC_BUS_WIDTH_4) {
+                       tuning_data.blk_pattern = tuning_blk_pattern_4bit;
+                       tuning_data.blksz = sizeof(tuning_blk_pattern_4bit);
+               } else {
+                       return -EINVAL;
+               }
+       } else if (opcode == MMC_SEND_TUNING_BLOCK) {
+               tuning_data.blk_pattern = tuning_blk_pattern_4bit;
+               tuning_data.blksz = sizeof(tuning_blk_pattern_4bit);
+       } else {
+               dev_err(host->dev,
+                       "Undefined command(%d) for tuning\n", opcode);
+               return -EINVAL;
+       }
+
+       if (drv_data && drv_data->execute_tuning)
+               err = drv_data->execute_tuning(slot, opcode, &tuning_data);
+       return err;
+}
+
 static const struct mmc_host_ops dw_mci_ops = {
        .request                = dw_mci_request,
        .pre_req                = dw_mci_pre_req,
@@ -947,6 +1139,7 @@ static const struct mmc_host_ops dw_mci_ops = {
        .get_ro                 = dw_mci_get_ro,
        .get_cd                 = dw_mci_get_cd,
        .enable_sdio_irq        = dw_mci_enable_sdio_irq,
+       .execute_tuning         = dw_mci_execute_tuning,
 };
 
 static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
@@ -978,7 +1171,7 @@ static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
        spin_lock(&host->lock);
 }
 
-static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
+static int dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
 {
        u32 status = host->cmd_status;
 
@@ -1012,12 +1205,52 @@ static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd
                /* newer ip versions need a delay between retries */
                if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
                        mdelay(20);
+       }
 
-               if (cmd->data) {
-                       dw_mci_stop_dma(host);
-                       host->data = NULL;
+       return cmd->error;
+}
+
+static int dw_mci_data_complete(struct dw_mci *host, struct mmc_data *data)
+{
+       u32 status = host->data_status;
+
+       if (status & DW_MCI_DATA_ERROR_FLAGS) {
+               if (status & SDMMC_INT_DRTO) {
+                       data->error = -ETIMEDOUT;
+               } else if (status & SDMMC_INT_DCRC) {
+                       data->error = -EILSEQ;
+               } else if (status & SDMMC_INT_EBE) {
+                       if (host->dir_status ==
+                               DW_MCI_SEND_STATUS) {
+                               /*
+                                * No data CRC status was returned.
+                                * The number of bytes transferred
+                                * will be exaggerated in PIO mode.
+                                */
+                               data->bytes_xfered = 0;
+                               data->error = -ETIMEDOUT;
+                       } else if (host->dir_status ==
+                                       DW_MCI_RECV_STATUS) {
+                               data->error = -EIO;
+                       }
+               } else {
+                       /* SDMMC_INT_SBE is included */
+                       data->error = -EIO;
                }
+
+               dev_err(host->dev, "data error, status 0x%08x\n", status);
+
+               /*
+                * After an error, there may be data lingering
+                * in the FIFO
+                */
+               dw_mci_fifo_reset(host);
+       } else {
+               data->bytes_xfered = data->blocks * data->blksz;
+               data->error = 0;
        }
+
+       return data->error;
 }
 
 static void dw_mci_tasklet_func(unsigned long priv)
@@ -1025,14 +1258,16 @@ static void dw_mci_tasklet_func(unsigned long priv)
        struct dw_mci *host = (struct dw_mci *)priv;
        struct mmc_data *data;
        struct mmc_command *cmd;
+       struct mmc_request *mrq;
        enum dw_mci_state state;
        enum dw_mci_state prev_state;
-       u32 status, ctrl;
+       unsigned int err;
 
        spin_lock(&host->lock);
 
        state = host->state;
        data = host->data;
+       mrq = host->mrq;
 
        do {
                prev_state = state;
@@ -1049,16 +1284,23 @@ static void dw_mci_tasklet_func(unsigned long priv)
                        cmd = host->cmd;
                        host->cmd = NULL;
                        set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
-                       dw_mci_command_complete(host, cmd);
-                       if (cmd == host->mrq->sbc && !cmd->error) {
+                       err = dw_mci_command_complete(host, cmd);
+                       if (cmd == mrq->sbc && !err) {
                                prev_state = state = STATE_SENDING_CMD;
                                __dw_mci_start_request(host, host->cur_slot,
-                                                      host->mrq->cmd);
+                                                      mrq->cmd);
                                goto unlock;
                        }
 
-                       if (!host->mrq->data || cmd->error) {
-                               dw_mci_request_end(host, host->mrq);
+                       if (cmd->data && err) {
+                               dw_mci_stop_dma(host);
+                               send_stop_abort(host, data);
+                               state = STATE_SENDING_STOP;
+                               break;
+                       }
+
+                       if (!cmd->data || err) {
+                               dw_mci_request_end(host, mrq);
                                goto unlock;
                        }
 
@@ -1069,8 +1311,7 @@ static void dw_mci_tasklet_func(unsigned long priv)
                        if (test_and_clear_bit(EVENT_DATA_ERROR,
                                               &host->pending_events)) {
                                dw_mci_stop_dma(host);
-                               if (data->stop)
-                                       send_stop_cmd(host, data);
+                               send_stop_abort(host, data);
                                state = STATE_DATA_ERROR;
                                break;
                        }
@@ -1090,60 +1331,27 @@ static void dw_mci_tasklet_func(unsigned long priv)
 
                        host->data = NULL;
                        set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
-                       status = host->data_status;
-
-                       if (status & DW_MCI_DATA_ERROR_FLAGS) {
-                               if (status & SDMMC_INT_DRTO) {
-                                       data->error = -ETIMEDOUT;
-                               } else if (status & SDMMC_INT_DCRC) {
-                                       data->error = -EILSEQ;
-                               } else if (status & SDMMC_INT_EBE &&
-                                          host->dir_status ==
-                                                       DW_MCI_SEND_STATUS) {
-                                       /*
-                                        * No data CRC status was returned.
-                                        * The number of bytes transferred will
-                                        * be exaggerated in PIO mode.
-                                        */
-                                       data->bytes_xfered = 0;
-                                       data->error = -ETIMEDOUT;
-                               } else {
-                                       dev_err(host->dev,
-                                               "data FIFO error "
-                                               "(status=%08x)\n",
-                                               status);
-                                       data->error = -EIO;
-                               }
-                               /*
-                                * After an error, there may be data lingering
-                                * in the FIFO, so reset it - doing so
-                                * generates a block interrupt, hence setting
-                                * the scatter-gather pointer to NULL.
-                                */
-                               sg_miter_stop(&host->sg_miter);
-                               host->sg = NULL;
-                               ctrl = mci_readl(host, CTRL);
-                               ctrl |= SDMMC_CTRL_FIFO_RESET;
-                               mci_writel(host, CTRL, ctrl);
-                       } else {
-                               data->bytes_xfered = data->blocks * data->blksz;
-                               data->error = 0;
-                       }
+                       err = dw_mci_data_complete(host, data);
 
-                       if (!data->stop) {
-                               dw_mci_request_end(host, host->mrq);
-                               goto unlock;
-                       }
+                       if (!err) {
+                               if (!data->stop || mrq->sbc) {
+                                       if (mrq->sbc)
+                                               data->stop->error = 0;
+                                       dw_mci_request_end(host, mrq);
+                                       goto unlock;
+                               }
 
-                       if (host->mrq->sbc && !data->error) {
-                               data->stop->error = 0;
-                               dw_mci_request_end(host, host->mrq);
-                               goto unlock;
+                               /* stop command for open-ended transfer*/
+                               if (data->stop)
+                                       send_stop_abort(host, data);
                        }
 
+                       /*
+                        * If err has non-zero,
+                        * stop-abort command has been already issued.
+                        */
                        prev_state = state = STATE_SENDING_STOP;
-                       if (!data->error)
-                               send_stop_cmd(host, data);
+
                        /* fall through */
 
                case STATE_SENDING_STOP:
@@ -1151,9 +1359,19 @@ static void dw_mci_tasklet_func(unsigned long priv)
                                                &host->pending_events))
                                break;
 
+                       /* CMD error in data command */
+                       if (mrq->cmd->error && mrq->data)
+                               dw_mci_fifo_reset(host);
+
                        host->cmd = NULL;
-                       dw_mci_command_complete(host, host->mrq->stop);
-                       dw_mci_request_end(host, host->mrq);
+                       host->data = NULL;
+
+                       if (mrq->stop)
+                               dw_mci_command_complete(host, mrq->stop);
+                       else
+                               host->cmd_status = 0;
+
+                       dw_mci_request_end(host, mrq);
                        goto unlock;
 
                case STATE_DATA_ERROR:
@@ -1697,7 +1915,6 @@ static void dw_mci_work_routine_card(struct work_struct *work)
                struct mmc_host *mmc = slot->mmc;
                struct mmc_request *mrq;
                int present;
-               u32 ctrl;
 
                present = dw_mci_get_cd(mmc);
                while (present != slot->last_detect_state) {
@@ -1736,11 +1953,10 @@ static void dw_mci_work_routine_card(struct work_struct *work)
                                        case STATE_DATA_ERROR:
                                                if (mrq->data->error == -EINPROGRESS)
                                                        mrq->data->error = -ENOMEDIUM;
-                                               if (!mrq->stop)
-                                                       break;
                                                /* fall through */
                                        case STATE_SENDING_STOP:
-                                               mrq->stop->error = -ENOMEDIUM;
+                                               if (mrq->stop)
+                                                       mrq->stop->error = -ENOMEDIUM;
                                                break;
                                        }
 
@@ -1763,23 +1979,10 @@ static void dw_mci_work_routine_card(struct work_struct *work)
                        if (present == 0) {
                                clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
 
-                               /*
-                                * Clear down the FIFO - doing so generates a
-                                * block interrupt, hence setting the
-                                * scatter-gather pointer to NULL.
-                                */
-                               sg_miter_stop(&host->sg_miter);
-                               host->sg = NULL;
-
-                               ctrl = mci_readl(host, CTRL);
-                               ctrl |= SDMMC_CTRL_FIFO_RESET;
-                               mci_writel(host, CTRL, ctrl);
-
+                               /* Clear down the FIFO */
+                               dw_mci_fifo_reset(host);
 #ifdef CONFIG_MMC_DW_IDMAC
-                               ctrl = mci_readl(host, BMOD);
-                               /* Software reset of DMA */
-                               ctrl |= SDMMC_IDMAC_SWRESET;
-                               mci_writel(host, BMOD, ctrl);
+                               dw_mci_idmac_reset(host);
 #endif
 
                        }
@@ -1901,6 +2104,7 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
        struct dw_mci_slot *slot;
        const struct dw_mci_drv_data *drv_data = host->drv_data;
        int ctrl_id, ret;
+       u32 freq[2];
        u8 bus_width;
 
        mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
@@ -1916,8 +2120,14 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
        slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id);
 
        mmc->ops = &dw_mci_ops;
-       mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510);
-       mmc->f_max = host->bus_hz;
+       if (of_property_read_u32_array(host->dev->of_node,
+                                      "clock-freq-min-max", freq, 2)) {
+               mmc->f_min = DW_MCI_FREQ_MIN;
+               mmc->f_max = DW_MCI_FREQ_MAX;
+       } else {
+               mmc->f_min = freq[0];
+               mmc->f_max = freq[1];
+       }
 
        if (host->pdata->get_ocr)
                mmc->ocr_avail = host->pdata->get_ocr(id);
@@ -1964,9 +2174,6 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
                mmc->caps |= MMC_CAP_4_BIT_DATA;
        }
 
-       if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED)
-               mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
-
        if (host->pdata->blk_settings) {
                mmc->max_segs = host->pdata->blk_settings->max_segs;
                mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
@@ -2008,12 +2215,6 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
        /* Card initially undetected */
        slot->last_detect_state = 0;
 
-       /*
-        * Card may have been plugged in prior to boot so we
-        * need to run the detect tasklet
-        */
-       queue_work(host->card_workqueue, &host->card_work);
-
        return 0;
 
 err_setup_bus:
@@ -2074,36 +2275,57 @@ no_dma:
        return;
 }
 
-static bool mci_wait_reset(struct device *dev, struct dw_mci *host)
+static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
 {
        unsigned long timeout = jiffies + msecs_to_jiffies(500);
-       unsigned int ctrl;
+       u32 ctrl;
 
-       mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
-                               SDMMC_CTRL_DMA_RESET));
+       ctrl = mci_readl(host, CTRL);
+       ctrl |= reset;
+       mci_writel(host, CTRL, ctrl);
 
        /* wait till resets clear */
        do {
                ctrl = mci_readl(host, CTRL);
-               if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
-                             SDMMC_CTRL_DMA_RESET)))
+               if (!(ctrl & reset))
                        return true;
        } while (time_before(jiffies, timeout));
 
-       dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl);
+       dev_err(host->dev,
+               "Timeout resetting block (ctrl reset %#x)\n",
+               ctrl & reset);
 
        return false;
 }
 
+static inline bool dw_mci_fifo_reset(struct dw_mci *host)
+{
+       /*
+        * Reseting generates a block interrupt, hence setting
+        * the scatter-gather pointer to NULL.
+        */
+       if (host->sg) {
+               sg_miter_stop(&host->sg_miter);
+               host->sg = NULL;
+       }
+
+       return dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET);
+}
+
+static inline bool dw_mci_ctrl_all_reset(struct dw_mci *host)
+{
+       return dw_mci_ctrl_reset(host,
+                                SDMMC_CTRL_FIFO_RESET |
+                                SDMMC_CTRL_RESET |
+                                SDMMC_CTRL_DMA_RESET);
+}
+
 #ifdef CONFIG_OF
 static struct dw_mci_of_quirks {
        char *quirk;
        int id;
 } of_quirks[] = {
        {
-               .quirk  = "supports-highspeed",
-               .id     = DW_MCI_QUIRK_HIGHSPEED,
-       }, {
                .quirk  = "broken-cd",
                .id     = DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
        },
@@ -2158,6 +2380,15 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
        if (of_find_property(np, "enable-sdio-wakeup", NULL))
                pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
 
+       if (of_find_property(np, "supports-highspeed", NULL))
+               pdata->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
+
+       if (of_find_property(np, "caps2-mmc-hs200-1_8v", NULL))
+               pdata->caps2 |= MMC_CAP2_HS200_1_8V_SDR;
+
+       if (of_find_property(np, "caps2-mmc-hs200-1_2v", NULL))
+               pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR;
+
        return pdata;
 }
 
@@ -2221,6 +2452,15 @@ int dw_mci_probe(struct dw_mci *host)
                host->bus_hz = clk_get_rate(host->ciu_clk);
        }
 
+       if (drv_data && drv_data->init) {
+               ret = drv_data->init(host);
+               if (ret) {
+                       dev_err(host->dev,
+                               "implementation specific init failed\n");
+                       goto err_clk_ciu;
+               }
+       }
+
        if (drv_data && drv_data->setup_clock) {
                ret = drv_data->setup_clock(host);
                if (ret) {
@@ -2287,7 +2527,7 @@ int dw_mci_probe(struct dw_mci *host)
        }
 
        /* Reset all blocks */
-       if (!mci_wait_reset(host->dev, host))
+       if (!dw_mci_ctrl_all_reset(host))
                return -ENODEV;
 
        host->dma_ops = host->pdata->dma_ops;
@@ -2317,8 +2557,8 @@ int dw_mci_probe(struct dw_mci *host)
                fifo_size = host->pdata->fifo_depth;
        }
        host->fifo_depth = fifo_size;
-       host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) |
-                       ((fifo_size/2) << 0));
+       host->fifoth_val =
+               SDMMC_SET_FIFOTH(0x2, fifo_size / 2 - 1, fifo_size / 2);
        mci_writel(host, FIFOTH, host->fifoth_val);
 
        /* disable clock to CIU */
@@ -2456,23 +2696,6 @@ EXPORT_SYMBOL(dw_mci_remove);
  */
 int dw_mci_suspend(struct dw_mci *host)
 {
-       int i, ret = 0;
-
-       for (i = 0; i < host->num_slots; i++) {
-               struct dw_mci_slot *slot = host->slot[i];
-               if (!slot)
-                       continue;
-               ret = mmc_suspend_host(slot->mmc);
-               if (ret < 0) {
-                       while (--i >= 0) {
-                               slot = host->slot[i];
-                               if (slot)
-                                       mmc_resume_host(host->slot[i]->mmc);
-                       }
-                       return ret;
-               }
-       }
-
        if (host->vmmc)
                regulator_disable(host->vmmc);
 
@@ -2493,7 +2716,7 @@ int dw_mci_resume(struct dw_mci *host)
                }
        }
 
-       if (!mci_wait_reset(host->dev, host)) {
+       if (!dw_mci_ctrl_all_reset(host)) {
                ret = -ENODEV;
                return ret;
        }
@@ -2501,8 +2724,15 @@ int dw_mci_resume(struct dw_mci *host)
        if (host->use_dma && host->dma_ops->init)
                host->dma_ops->init(host);
 
-       /* Restore the old value at FIFOTH register */
+       /*
+        * Restore the initial value at FIFOTH register
+        * And Invalidate the prev_blksz with zero
+        */
        mci_writel(host, FIFOTH, host->fifoth_val);
+       host->prev_blksz = 0;
+
+       /* Put in max timeout */
+       mci_writel(host, TMOUT, 0xFFFFFFFF);
 
        mci_writel(host, RINTSTS, 0xFFFFFFFF);
        mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
@@ -2518,10 +2748,6 @@ int dw_mci_resume(struct dw_mci *host)
                        dw_mci_set_ios(slot->mmc, &slot->mmc->ios);
                        dw_mci_setup_bus(slot, true);
                }
-
-               ret = mmc_resume_host(host->slot[i]->mmc);
-               if (ret < 0)
-                       return ret;
        }
        return 0;
 }
index 81b29941c5b9b1ddaff3f313cab7bab9c57c6e46..6bf24ab917e6453a22d09689befd58e40fa96efd 100644 (file)
@@ -53,6 +53,7 @@
 #define SDMMC_IDINTEN          0x090
 #define SDMMC_DSCADDR          0x094
 #define SDMMC_BUFADDR          0x098
+#define SDMMC_CDTHRCTL         0x100
 #define SDMMC_DATA(x)          (x)
 
 /*
 #define SDMMC_CMD_INDX(n)              ((n) & 0x1F)
 /* Status register defines */
 #define SDMMC_GET_FCNT(x)              (((x)>>17) & 0x1FFF)
+/* FIFOTH register defines */
+#define SDMMC_SET_FIFOTH(m, r, t)      (((m) & 0x7) << 28 | \
+                                        ((r) & 0xFFF) << 16 | \
+                                        ((t) & 0xFFF))
 /* Internal DMAC interrupt defines */
 #define SDMMC_IDMAC_INT_AI             BIT(9)
 #define SDMMC_IDMAC_INT_NI             BIT(8)
 #define SDMMC_IDMAC_SWRESET            BIT(0)
 /* Version ID register define */
 #define SDMMC_GET_VERID(x)             ((x) & 0xFFFF)
+/* Card read threshold */
+#define SDMMC_SET_RD_THLD(v, x)                (((v) & 0x1FFF) << 16 | (x))
 
 /* Register access macros */
 #define mci_readl(dev, reg)                    \
@@ -183,6 +190,52 @@ extern int dw_mci_suspend(struct dw_mci *host);
 extern int dw_mci_resume(struct dw_mci *host);
 #endif
 
+/**
+ * struct dw_mci_slot - MMC slot state
+ * @mmc: The mmc_host representing this slot.
+ * @host: The MMC controller this slot is using.
+ * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
+ * @wp_gpio: If gpio_is_valid() we'll use this to read write protect.
+ * @ctype: Card type for this slot.
+ * @mrq: mmc_request currently being processed or waiting to be
+ *     processed, or NULL when the slot is idle.
+ * @queue_node: List node for placing this node in the @queue list of
+ *     &struct dw_mci.
+ * @clock: Clock rate configured by set_ios(). Protected by host->lock.
+ * @__clk_old: The last updated clock with reflecting clock divider.
+ *     Keeping track of this helps us to avoid spamming the console
+ *     with CONFIG_MMC_CLKGATE.
+ * @flags: Random state bits associated with the slot.
+ * @id: Number of this slot.
+ * @last_detect_state: Most recently observed card detect state.
+ */
+struct dw_mci_slot {
+       struct mmc_host         *mmc;
+       struct dw_mci           *host;
+
+       int                     quirks;
+       int                     wp_gpio;
+
+       u32                     ctype;
+
+       struct mmc_request      *mrq;
+       struct list_head        queue_node;
+
+       unsigned int            clock;
+       unsigned int            __clk_old;
+
+       unsigned long           flags;
+#define DW_MMC_CARD_PRESENT    0
+#define DW_MMC_CARD_NEED_INIT  1
+       int                     id;
+       int                     last_detect_state;
+};
+
+struct dw_mci_tuning_data {
+       const u8 *blk_pattern;
+       unsigned int blksz;
+};
+
 /**
  * dw_mci driver data - dw-mshc implementation specific driver data.
  * @caps: mmc subsystem specified capabilities of the controller(s).
@@ -203,5 +256,7 @@ struct dw_mci_drv_data {
        void            (*prepare_command)(struct dw_mci *host, u32 *cmdr);
        void            (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
        int             (*parse_dt)(struct dw_mci *host);
+       int             (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
+                                       struct dw_mci_tuning_data *tuning_data);
 };
 #endif /* _DW_MMC_H_ */
index 66516339e3a0fe474533f62fae475283180d701b..de2139cf344477bbe8922448a963c9e1094dd882 100644 (file)
@@ -880,8 +880,6 @@ static int jz4740_mmc_suspend(struct device *dev)
 {
        struct jz4740_mmc_host *host = dev_get_drvdata(dev);
 
-       mmc_suspend_host(host->mmc);
-
        jz_gpio_bulk_suspend(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
 
        return 0;
@@ -893,8 +891,6 @@ static int jz4740_mmc_resume(struct device *dev)
 
        jz_gpio_bulk_resume(jz4740_mmc_pins, jz4740_mmc_num_pins(host));
 
-       mmc_resume_host(host->mmc);
-
        return 0;
 }
 
index d135c76c4855b825175370e215979bd528e4b2d4..f32057972dd77fe9a7487f74aa2ab727c2126db6 100644 (file)
@@ -1730,37 +1730,28 @@ static int mmci_suspend(struct device *dev)
 {
        struct amba_device *adev = to_amba_device(dev);
        struct mmc_host *mmc = amba_get_drvdata(adev);
-       int ret = 0;
 
        if (mmc) {
                struct mmci_host *host = mmc_priv(mmc);
-
-               ret = mmc_suspend_host(mmc);
-               if (ret == 0) {
-                       pm_runtime_get_sync(dev);
-                       writel(0, host->base + MMCIMASK0);
-               }
+               pm_runtime_get_sync(dev);
+               writel(0, host->base + MMCIMASK0);
        }
 
-       return ret;
+       return 0;
 }
 
 static int mmci_resume(struct device *dev)
 {
        struct amba_device *adev = to_amba_device(dev);
        struct mmc_host *mmc = amba_get_drvdata(adev);
-       int ret = 0;
 
        if (mmc) {
                struct mmci_host *host = mmc_priv(mmc);
-
                writel(MCI_IRQENABLE, host->base + MMCIMASK0);
                pm_runtime_put(dev);
-
-               ret = mmc_resume_host(mmc);
        }
 
-       return ret;
+       return 0;
 }
 #endif
 
index b900de4e7e942c38c6bd5c78c521325619b83aca..9405ecdaf6cf952f4a5d2cbd0c75f0d745915ae4 100644 (file)
@@ -1416,28 +1416,10 @@ ioremap_free:
 }
 
 #ifdef CONFIG_PM
-#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
-static void
-do_resume_work(struct work_struct *work)
-{
-       struct msmsdcc_host *host =
-               container_of(work, struct msmsdcc_host, resume_task);
-       struct mmc_host *mmc = host->mmc;
-
-       if (mmc) {
-               mmc_resume_host(mmc);
-               if (host->stat_irq)
-                       enable_irq(host->stat_irq);
-       }
-}
-#endif
-
-
 static int
 msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
 {
        struct mmc_host *mmc = mmc_get_drvdata(dev);
-       int rc = 0;
 
        if (mmc) {
                struct msmsdcc_host *host = mmc_priv(mmc);
@@ -1445,14 +1427,11 @@ msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
                if (host->stat_irq)
                        disable_irq(host->stat_irq);
 
-               if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
-                       rc = mmc_suspend_host(mmc);
-               if (!rc)
-                       msmsdcc_writel(host, 0, MMCIMASK0);
+               msmsdcc_writel(host, 0, MMCIMASK0);
                if (host->clks_on)
                        msmsdcc_disable_clocks(host, 0);
        }
-       return rc;
+       return 0;
 }
 
 static int
@@ -1467,8 +1446,6 @@ msmsdcc_resume(struct platform_device *dev)
 
                msmsdcc_writel(host, host->saved_irq0mask, MMCIMASK0);
 
-               if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
-                       mmc_resume_host(mmc);
                if (host->stat_irq)
                        enable_irq(host->stat_irq);
 #if BUSCLK_PWRSAVE
index deecee08c2881d0ee6ad34a9d049368e5d05ceec..45aa2206741db8da3bebac2f6b94385add678ced 100644 (file)
@@ -775,9 +775,9 @@ static int mvsd_probe(struct platform_device *pdev)
 
        spin_lock_init(&host->lock);
 
-       host->base = devm_request_and_ioremap(&pdev->dev, r);
-       if (!host->base) {
-               ret = -ENOMEM;
+       host->base = devm_ioremap_resource(&pdev->dev, r);
+       if (IS_ERR(host->base)) {
+               ret = PTR_ERR(host->base);
                goto out;
        }
 
@@ -838,33 +838,6 @@ static int mvsd_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int mvsd_suspend(struct platform_device *dev, pm_message_t state)
-{
-       struct mmc_host *mmc = platform_get_drvdata(dev);
-       int ret = 0;
-
-       if (mmc)
-               ret = mmc_suspend_host(mmc);
-
-       return ret;
-}
-
-static int mvsd_resume(struct platform_device *dev)
-{
-       struct mmc_host *mmc = platform_get_drvdata(dev);
-       int ret = 0;
-
-       if (mmc)
-               ret = mmc_resume_host(mmc);
-
-       return ret;
-}
-#else
-#define mvsd_suspend   NULL
-#define mvsd_resume    NULL
-#endif
-
 static const struct of_device_id mvsdio_dt_ids[] = {
        { .compatible = "marvell,orion-sdio" },
        { /* sentinel */ }
@@ -874,8 +847,6 @@ MODULE_DEVICE_TABLE(of, mvsdio_dt_ids);
 static struct platform_driver mvsd_driver = {
        .probe          = mvsd_probe,
        .remove         = mvsd_remove,
-       .suspend        = mvsd_suspend,
-       .resume         = mvsd_resume,
        .driver         = {
                .name   = DRIVER_NAME,
                .of_match_table = mvsdio_dt_ids,
index c174c6a0d224f86bcc2d91dc524940a5e90d616e..f7199c83f5cf8e85c49ed54b575502d0187fc8c3 100644 (file)
@@ -1250,28 +1250,20 @@ static int mxcmci_suspend(struct device *dev)
 {
        struct mmc_host *mmc = dev_get_drvdata(dev);
        struct mxcmci_host *host = mmc_priv(mmc);
-       int ret = 0;
 
-       if (mmc)
-               ret = mmc_suspend_host(mmc);
        clk_disable_unprepare(host->clk_per);
        clk_disable_unprepare(host->clk_ipg);
-
-       return ret;
+       return 0;
 }
 
 static int mxcmci_resume(struct device *dev)
 {
        struct mmc_host *mmc = dev_get_drvdata(dev);
        struct mxcmci_host *host = mmc_priv(mmc);
-       int ret = 0;
 
        clk_prepare_enable(host->clk_per);
        clk_prepare_enable(host->clk_ipg);
-       if (mmc)
-               ret = mmc_resume_host(mmc);
-
-       return ret;
+       return 0;
 }
 
 static const struct dev_pm_ops mxcmci_pm_ops = {
index e1fa3ef735e097e1c3c8e533fedec63d30786f43..50fc9df791b2934deb5acb25532440dd32347551 100644 (file)
@@ -724,13 +724,9 @@ static int mxs_mmc_suspend(struct device *dev)
        struct mmc_host *mmc = dev_get_drvdata(dev);
        struct mxs_mmc_host *host = mmc_priv(mmc);
        struct mxs_ssp *ssp = &host->ssp;
-       int ret = 0;
-
-       ret = mmc_suspend_host(mmc);
 
        clk_disable_unprepare(ssp->clk);
-
-       return ret;
+       return 0;
 }
 
 static int mxs_mmc_resume(struct device *dev)
@@ -738,13 +734,9 @@ static int mxs_mmc_resume(struct device *dev)
        struct mmc_host *mmc = dev_get_drvdata(dev);
        struct mxs_mmc_host *host = mmc_priv(mmc);
        struct mxs_ssp *ssp = &host->ssp;
-       int ret = 0;
 
        clk_prepare_enable(ssp->clk);
-
-       ret = mmc_resume_host(mmc);
-
-       return ret;
+       return 0;
 }
 
 static const struct dev_pm_ops mxs_mmc_pm_ops = {
index b94f38ec2a838acff3f67861a8059eb22d41c2ff..0b10a9030f4e2a85029ea4bab3afcdb8102899be 100644 (file)
@@ -128,7 +128,6 @@ struct mmc_omap_slot {
 
 struct mmc_omap_host {
        int                     initialized;
-       int                     suspended;
        struct mmc_request *    mrq;
        struct mmc_command *    cmd;
        struct mmc_data *       data;
@@ -1513,61 +1512,9 @@ static int mmc_omap_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int mmc_omap_suspend(struct platform_device *pdev, pm_message_t mesg)
-{
-       int i, ret = 0;
-       struct mmc_omap_host *host = platform_get_drvdata(pdev);
-
-       if (host == NULL || host->suspended)
-               return 0;
-
-       for (i = 0; i < host->nr_slots; i++) {
-               struct mmc_omap_slot *slot;
-
-               slot = host->slots[i];
-               ret = mmc_suspend_host(slot->mmc);
-               if (ret < 0) {
-                       while (--i >= 0) {
-                               slot = host->slots[i];
-                               mmc_resume_host(slot->mmc);
-                       }
-                       return ret;
-               }
-       }
-       host->suspended = 1;
-       return 0;
-}
-
-static int mmc_omap_resume(struct platform_device *pdev)
-{
-       int i, ret = 0;
-       struct mmc_omap_host *host = platform_get_drvdata(pdev);
-
-       if (host == NULL || !host->suspended)
-               return 0;
-
-       for (i = 0; i < host->nr_slots; i++) {
-               struct mmc_omap_slot *slot;
-               slot = host->slots[i];
-               ret = mmc_resume_host(slot->mmc);
-               if (ret < 0)
-                       return ret;
-
-               host->suspended = 0;
-       }
-       return 0;
-}
-#else
-#define mmc_omap_suspend       NULL
-#define mmc_omap_resume                NULL
-#endif
-
 static struct platform_driver mmc_omap_driver = {
        .probe          = mmc_omap_probe,
        .remove         = mmc_omap_remove,
-       .suspend        = mmc_omap_suspend,
-       .resume         = mmc_omap_resume,
        .driver         = {
                .name   = DRIVER_NAME,
                .owner  = THIS_MODULE,
index 6ac63df645c405b0bd6586c7f8d993d940f8c1af..dbd32ad3b749337a196c98915694b0c013685186 100644 (file)
@@ -75,6 +75,7 @@
 #define ICE                    0x1
 #define ICS                    0x2
 #define CEN                    (1 << 2)
+#define CLKD_MAX               0x3FF           /* max clock divisor: 1023 */
 #define CLKD_MASK              0x0000FFC0
 #define CLKD_SHIFT             6
 #define DTO_MASK               0x000F0000
                BRR_EN | BWR_EN | TC_EN | CC_EN)
 
 #define MMC_AUTOSUSPEND_DELAY  100
-#define MMC_TIMEOUT_MS         20
+#define MMC_TIMEOUT_MS         20              /* 20 mSec */
+#define MMC_TIMEOUT_US         20000           /* 20000 micro Sec */
 #define OMAP_MMC_MIN_CLOCK     400000
 #define OMAP_MMC_MAX_CLOCK     52000000
 #define DRIVER_NAME            "omap_hsmmc"
@@ -171,6 +173,10 @@ struct omap_hsmmc_host {
        unsigned char           bus_mode;
        unsigned char           power_mode;
        int                     suspended;
+       u32                     con;
+       u32                     hctl;
+       u32                     sysctl;
+       u32                     capa;
        int                     irq;
        int                     use_dma, dma_ch;
        struct dma_chan         *tx_chan;
@@ -183,7 +189,6 @@ struct omap_hsmmc_host {
        int                     use_reg;
        int                     req_in_progress;
        struct omap_hsmmc_next  next_data;
-
        struct  omap_mmc_platform_data  *pdata;
 };
 
@@ -493,8 +498,8 @@ static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios)
 
        if (ios->clock) {
                dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock);
-               if (dsor > 250)
-                       dsor = 250;
+               if (dsor > CLKD_MAX)
+                       dsor = CLKD_MAX;
        }
 
        return dsor;
@@ -597,25 +602,20 @@ static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host)
 static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
 {
        struct mmc_ios *ios = &host->mmc->ios;
-       struct omap_mmc_platform_data *pdata = host->pdata;
-       int context_loss = 0;
        u32 hctl, capa;
        unsigned long timeout;
 
-       if (pdata->get_context_loss_count) {
-               context_loss = pdata->get_context_loss_count(host->dev);
-               if (context_loss < 0)
-                       return 1;
-       }
-
-       dev_dbg(mmc_dev(host->mmc), "context was %slost\n",
-               context_loss == host->context_loss ? "not " : "");
-       if (host->context_loss == context_loss)
-               return 1;
-
        if (!OMAP_HSMMC_READ(host->base, SYSSTATUS) & RESETDONE)
                return 1;
 
+       if (host->con == OMAP_HSMMC_READ(host->base, CON) &&
+           host->hctl == OMAP_HSMMC_READ(host->base, HCTL) &&
+           host->sysctl == OMAP_HSMMC_READ(host->base, SYSCTL) &&
+           host->capa == OMAP_HSMMC_READ(host->base, CAPA))
+               return 0;
+
+       host->context_loss++;
+
        if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) {
                if (host->power_mode != MMC_POWER_OFF &&
                    (1 << ios->vdd) <= MMC_VDD_23_24)
@@ -655,9 +655,8 @@ static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host)
        omap_hsmmc_set_bus_mode(host);
 
 out:
-       host->context_loss = context_loss;
-
-       dev_dbg(mmc_dev(host->mmc), "context is restored\n");
+       dev_dbg(mmc_dev(host->mmc), "context is restored: restore count %d\n",
+               host->context_loss);
        return 0;
 }
 
@@ -666,15 +665,10 @@ out:
  */
 static void omap_hsmmc_context_save(struct omap_hsmmc_host *host)
 {
-       struct omap_mmc_platform_data *pdata = host->pdata;
-       int context_loss;
-
-       if (pdata->get_context_loss_count) {
-               context_loss = pdata->get_context_loss_count(host->dev);
-               if (context_loss < 0)
-                       return;
-               host->context_loss = context_loss;
-       }
+       host->con =  OMAP_HSMMC_READ(host->base, CON);
+       host->hctl = OMAP_HSMMC_READ(host->base, HCTL);
+       host->sysctl =  OMAP_HSMMC_READ(host->base, SYSCTL);
+       host->capa = OMAP_HSMMC_READ(host->base, CAPA);
 }
 
 #else
@@ -975,8 +969,7 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
                                                   unsigned long bit)
 {
        unsigned long i = 0;
-       unsigned long limit = (loops_per_jiffy *
-                               msecs_to_jiffies(MMC_TIMEOUT_MS));
+       unsigned long limit = MMC_TIMEOUT_US;
 
        OMAP_HSMMC_WRITE(host->base, SYSCTL,
                         OMAP_HSMMC_READ(host->base, SYSCTL) | bit);
@@ -988,13 +981,13 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
        if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) {
                while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
                                        && (i++ < limit))
-                       cpu_relax();
+                       udelay(1);
        }
        i = 0;
 
        while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) &&
                (i++ < limit))
-               cpu_relax();
+               udelay(1);
 
        if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit)
                dev_err(mmc_dev(host->mmc),
@@ -1178,9 +1171,6 @@ static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)
        struct omap_mmc_slot_data *slot = &mmc_slot(host);
        int carddetect;
 
-       if (host->suspended)
-               return IRQ_HANDLED;
-
        sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
 
        if (slot->card_detect)
@@ -1635,18 +1625,9 @@ static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
 {
        struct mmc_host *mmc = s->private;
        struct omap_hsmmc_host *host = mmc_priv(mmc);
-       int context_loss = 0;
-
-       if (host->pdata->get_context_loss_count)
-               context_loss = host->pdata->get_context_loss_count(host->dev);
 
-       seq_printf(s, "mmc%d:\n ctx_loss:\t%d:%d\n\nregs:\n",
-                       mmc->index, host->context_loss, context_loss);
-
-       if (host->suspended) {
-               seq_printf(s, "host suspended, can't read registers\n");
-               return 0;
-       }
+       seq_printf(s, "mmc%d:\n ctx_loss:\t%d\n\nregs:\n",
+                       mmc->index, host->context_loss);
 
        pm_runtime_get_sync(host->dev);
 
@@ -1838,13 +1819,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
 
        mmc->ops        = &omap_hsmmc_ops;
 
-       /*
-        * If regulator_disable can only put vcc_aux to sleep then there is
-        * no off state.
-        */
-       if (mmc_slot(host).vcc_aux_disable_is_sleep)
-               mmc_slot(host).no_off = 1;
-
        mmc->f_min = OMAP_MMC_MIN_CLOCK;
 
        if (pdata->max_freq > 0)
@@ -1874,7 +1848,7 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
        omap_hsmmc_context_save(host);
 
        /* This can be removed once we support PBIAS with DT */
-       if (host->dev->of_node && host->mapbase == 0x4809c000)
+       if (host->dev->of_node && res->start == 0x4809c000)
                host->pbias_disable = 1;
 
        host->dbclk = clk_get(&pdev->dev, "mmchsdb_fck");
@@ -2119,23 +2093,12 @@ static void omap_hsmmc_complete(struct device *dev)
 
 static int omap_hsmmc_suspend(struct device *dev)
 {
-       int ret = 0;
        struct omap_hsmmc_host *host = dev_get_drvdata(dev);
 
        if (!host)
                return 0;
 
-       if (host && host->suspended)
-               return 0;
-
        pm_runtime_get_sync(host->dev);
-       host->suspended = 1;
-       ret = mmc_suspend_host(host->mmc);
-
-       if (ret) {
-               host->suspended = 0;
-               goto err;
-       }
 
        if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) {
                omap_hsmmc_disable_irq(host);
@@ -2145,23 +2108,19 @@ static int omap_hsmmc_suspend(struct device *dev)
 
        if (host->dbclk)
                clk_disable_unprepare(host->dbclk);
-err:
+
        pm_runtime_put_sync(host->dev);
-       return ret;
+       return 0;
 }
 
 /* Routine to resume the MMC device */
 static int omap_hsmmc_resume(struct device *dev)
 {
-       int ret = 0;
        struct omap_hsmmc_host *host = dev_get_drvdata(dev);
 
        if (!host)
                return 0;
 
-       if (host && !host->suspended)
-               return 0;
-
        pm_runtime_get_sync(host->dev);
 
        if (host->dbclk)
@@ -2172,16 +2131,9 @@ static int omap_hsmmc_resume(struct device *dev)
 
        omap_hsmmc_protect_card(host);
 
-       /* Notify the core to resume the host */
-       ret = mmc_resume_host(host->mmc);
-       if (ret == 0)
-               host->suspended = 0;
-
        pm_runtime_mark_last_busy(host->dev);
        pm_runtime_put_autosuspend(host->dev);
-
-       return ret;
-
+       return 0;
 }
 
 #else
index 1956a3df7cf3f0e2f03dd36775f478b454272fb6..32fe11323f39e10bee30cac93daa0ba94e771939 100644 (file)
@@ -880,35 +880,6 @@ static int pxamci_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int pxamci_suspend(struct device *dev)
-{
-       struct mmc_host *mmc = dev_get_drvdata(dev);
-       int ret = 0;
-
-       if (mmc)
-               ret = mmc_suspend_host(mmc);
-
-       return ret;
-}
-
-static int pxamci_resume(struct device *dev)
-{
-       struct mmc_host *mmc = dev_get_drvdata(dev);
-       int ret = 0;
-
-       if (mmc)
-               ret = mmc_resume_host(mmc);
-
-       return ret;
-}
-
-static const struct dev_pm_ops pxamci_pm_ops = {
-       .suspend        = pxamci_suspend,
-       .resume         = pxamci_resume,
-};
-#endif
-
 static struct platform_driver pxamci_driver = {
        .probe          = pxamci_probe,
        .remove         = pxamci_remove,
@@ -916,9 +887,6 @@ static struct platform_driver pxamci_driver = {
                .name   = DRIVER_NAME,
                .owner  = THIS_MODULE,
                .of_match_table = of_match_ptr(pxa_mmc_dt_ids),
-#ifdef CONFIG_PM
-               .pm     = &pxamci_pm_ops,
-#endif
        },
 };
 
index 375a880e0c5fb899efa5a2de9b77543fcf66d12d..c46feda07d56883b1b6e50cbb46338d73c82bcca 100644 (file)
@@ -364,7 +364,7 @@ static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
        struct mmc_host *mmc = host->mmc;
        struct mmc_card *card = mmc->card;
        struct mmc_data *data = mrq->data;
-       int uhs = mmc_sd_card_uhs(card);
+       int uhs = mmc_card_uhs(card);
        int read = (data->flags & MMC_DATA_READ) ? 1 : 0;
        u8 cfg2, trans_mode;
        int err;
@@ -1197,37 +1197,6 @@ static const struct mmc_host_ops realtek_pci_sdmmc_ops = {
        .execute_tuning = sdmmc_execute_tuning,
 };
 
-#ifdef CONFIG_PM
-static int rtsx_pci_sdmmc_suspend(struct platform_device *pdev,
-               pm_message_t state)
-{
-       struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
-       struct mmc_host *mmc = host->mmc;
-       int err;
-
-       dev_dbg(sdmmc_dev(host), "--> %s\n", __func__);
-
-       err = mmc_suspend_host(mmc);
-       if (err)
-               return err;
-
-       return 0;
-}
-
-static int rtsx_pci_sdmmc_resume(struct platform_device *pdev)
-{
-       struct realtek_pci_sdmmc *host = platform_get_drvdata(pdev);
-       struct mmc_host *mmc = host->mmc;
-
-       dev_dbg(sdmmc_dev(host), "--> %s\n", __func__);
-
-       return mmc_resume_host(mmc);
-}
-#else /* CONFIG_PM */
-#define rtsx_pci_sdmmc_suspend NULL
-#define rtsx_pci_sdmmc_resume NULL
-#endif /* CONFIG_PM */
-
 static void init_extra_caps(struct realtek_pci_sdmmc *host)
 {
        struct mmc_host *mmc = host->mmc;
@@ -1367,8 +1336,6 @@ static struct platform_driver rtsx_pci_sdmmc_driver = {
        .probe          = rtsx_pci_sdmmc_drv_probe,
        .remove         = rtsx_pci_sdmmc_drv_remove,
        .id_table       = rtsx_pci_sdmmc_ids,
-       .suspend        = rtsx_pci_sdmmc_suspend,
-       .resume         = rtsx_pci_sdmmc_resume,
        .driver         = {
                .owner  = THIS_MODULE,
                .name   = DRV_NAME_RTSX_PCI_SDMMC,
index 8d6794cdf899cd812e394b862c111a6c65b53dc4..2fce5ea5eb39cfe7f72152f75a0a852325640059 100644 (file)
@@ -1949,39 +1949,10 @@ static struct platform_device_id s3cmci_driver_ids[] = {
 
 MODULE_DEVICE_TABLE(platform, s3cmci_driver_ids);
 
-
-#ifdef CONFIG_PM
-
-static int s3cmci_suspend(struct device *dev)
-{
-       struct mmc_host *mmc = platform_get_drvdata(to_platform_device(dev));
-
-       return mmc_suspend_host(mmc);
-}
-
-static int s3cmci_resume(struct device *dev)
-{
-       struct mmc_host *mmc = platform_get_drvdata(to_platform_device(dev));
-
-       return mmc_resume_host(mmc);
-}
-
-static const struct dev_pm_ops s3cmci_pm = {
-       .suspend        = s3cmci_suspend,
-       .resume         = s3cmci_resume,
-};
-
-#define s3cmci_pm_ops &s3cmci_pm
-#else /* CONFIG_PM */
-#define s3cmci_pm_ops NULL
-#endif /* CONFIG_PM */
-
-
 static struct platform_driver s3cmci_driver = {
        .driver = {
                .name   = "s3c-sdi",
                .owner  = THIS_MODULE,
-               .pm     = s3cmci_pm_ops,
        },
        .id_table       = s3cmci_driver_ids,
        .probe          = s3cmci_probe,
index 85472d3fd37f76b7a4b24b4a6f42033ff9dec472..7a190fe4dff1b799958bfedf7bb01dd5d405a0f8 100644 (file)
@@ -316,19 +316,7 @@ err_pltfm_free:
 
 static int __exit sdhci_bcm_kona_remove(struct platform_device *pdev)
 {
-       struct sdhci_host *host = platform_get_drvdata(pdev);
-       int dead;
-       u32 scratch;
-
-       dead = 0;
-       scratch = readl(host->ioaddr + SDHCI_INT_STATUS);
-       if (scratch == (u32)-1)
-               dead = 1;
-       sdhci_remove_host(host, dead);
-
-       sdhci_free_host(host);
-
-       return 0;
+       return sdhci_pltfm_unregister(pdev);
 }
 
 static struct platform_driver sdhci_bcm_kona_driver = {
index 36fa2df0466007f7b618aa9986ca9aa098199b32..f6d8d67c545f882678ea40bca4f2525a77bf28bf 100644 (file)
@@ -178,13 +178,7 @@ err:
 
 static int bcm2835_sdhci_remove(struct platform_device *pdev)
 {
-       struct sdhci_host *host = platform_get_drvdata(pdev);
-       int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
-
-       sdhci_remove_host(host, dead);
-       sdhci_pltfm_free(pdev);
-
-       return 0;
+       return sdhci_pltfm_unregister(pdev);
 }
 
 static const struct of_device_id bcm2835_sdhci_of_match[] = {
index abc8cf01e6e3317ecc3e95d32aa66236def768e9..461a4c3f4ef725924319058e531aaa457bffd7d5 100644 (file)
 /* VENDOR SPEC register */
 #define ESDHC_VENDOR_SPEC              0xc0
 #define  ESDHC_VENDOR_SPEC_SDIO_QUIRK  (1 << 1)
+#define  ESDHC_VENDOR_SPEC_VSELECT     (1 << 1)
+#define  ESDHC_VENDOR_SPEC_FRC_SDCLK_ON        (1 << 8)
 #define ESDHC_WTMK_LVL                 0x44
 #define ESDHC_MIX_CTRL                 0x48
+#define  ESDHC_MIX_CTRL_DDREN          (1 << 3)
 #define  ESDHC_MIX_CTRL_AC23EN         (1 << 7)
+#define  ESDHC_MIX_CTRL_EXE_TUNE       (1 << 22)
+#define  ESDHC_MIX_CTRL_SMPCLK_SEL     (1 << 23)
+#define  ESDHC_MIX_CTRL_FBCLK_SEL      (1 << 25)
 /* Bits 3 and 6 are not SDHCI standard definitions */
 #define  ESDHC_MIX_CTRL_SDHCI_MASK     0xb7
 
+/* dll control register */
+#define ESDHC_DLL_CTRL                 0x60
+#define ESDHC_DLL_OVERRIDE_VAL_SHIFT   9
+#define ESDHC_DLL_OVERRIDE_EN_SHIFT    8
+
+/* tune control register */
+#define ESDHC_TUNE_CTRL_STATUS         0x68
+#define  ESDHC_TUNE_CTRL_STEP          1
+#define  ESDHC_TUNE_CTRL_MIN           0
+#define  ESDHC_TUNE_CTRL_MAX           ((1 << 7) - 1)
+
+#define ESDHC_TUNING_CTRL              0xcc
+#define ESDHC_STD_TUNING_EN            (1 << 24)
+/* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
+#define ESDHC_TUNING_START_TAP         0x1
+
+#define ESDHC_TUNING_BLOCK_PATTERN_LEN 64
+
+/* pinctrl state */
+#define ESDHC_PINCTRL_STATE_100MHZ     "state_100mhz"
+#define ESDHC_PINCTRL_STATE_200MHZ     "state_200mhz"
+
 /*
  * Our interpretation of the SDHCI_HOST_CONTROL register
  */
  * As a result, the TC flag is not asserted and SW  received timeout
  * exeception. Bit1 of Vendor Spec registor is used to fix it.
  */
-#define ESDHC_FLAG_MULTIBLK_NO_INT     (1 << 1)
-
-enum imx_esdhc_type {
-       IMX25_ESDHC,
-       IMX35_ESDHC,
-       IMX51_ESDHC,
-       IMX53_ESDHC,
-       IMX6Q_USDHC,
+#define ESDHC_FLAG_MULTIBLK_NO_INT     BIT(1)
+/*
+ * The flag enables the workaround for ESDHC errata ENGcm07207 which
+ * affects i.MX25 and i.MX35.
+ */
+#define ESDHC_FLAG_ENGCM07207          BIT(2)
+/*
+ * The flag tells that the ESDHC controller is an USDHC block that is
+ * integrated on the i.MX6 series.
+ */
+#define ESDHC_FLAG_USDHC               BIT(3)
+/* The IP supports manual tuning process */
+#define ESDHC_FLAG_MAN_TUNING          BIT(4)
+/* The IP supports standard tuning process */
+#define ESDHC_FLAG_STD_TUNING          BIT(5)
+/* The IP has SDHCI_CAPABILITIES_1 register */
+#define ESDHC_FLAG_HAVE_CAP1           BIT(6)
+
+struct esdhc_soc_data {
+       u32 flags;
+};
+
+static struct esdhc_soc_data esdhc_imx25_data = {
+       .flags = ESDHC_FLAG_ENGCM07207,
+};
+
+static struct esdhc_soc_data esdhc_imx35_data = {
+       .flags = ESDHC_FLAG_ENGCM07207,
+};
+
+static struct esdhc_soc_data esdhc_imx51_data = {
+       .flags = 0,
+};
+
+static struct esdhc_soc_data esdhc_imx53_data = {
+       .flags = ESDHC_FLAG_MULTIBLK_NO_INT,
+};
+
+static struct esdhc_soc_data usdhc_imx6q_data = {
+       .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_MAN_TUNING,
+};
+
+static struct esdhc_soc_data usdhc_imx6sl_data = {
+       .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
+                       | ESDHC_FLAG_HAVE_CAP1,
 };
 
 struct pltfm_imx_data {
-       int flags;
        u32 scratchpad;
-       enum imx_esdhc_type devtype;
        struct pinctrl *pinctrl;
+       struct pinctrl_state *pins_default;
+       struct pinctrl_state *pins_100mhz;
+       struct pinctrl_state *pins_200mhz;
+       const struct esdhc_soc_data *socdata;
        struct esdhc_platform_data boarddata;
        struct clk *clk_ipg;
        struct clk *clk_ahb;
@@ -90,25 +157,20 @@ struct pltfm_imx_data {
                MULTIBLK_IN_PROCESS, /* exact multiblock cmd in process */
                WAIT_FOR_INT,        /* sent CMD12, waiting for response INT */
        } multiblock_status;
-
+       u32 uhs_mode;
+       u32 is_ddr;
 };
 
 static struct platform_device_id imx_esdhc_devtype[] = {
        {
                .name = "sdhci-esdhc-imx25",
-               .driver_data = IMX25_ESDHC,
+               .driver_data = (kernel_ulong_t) &esdhc_imx25_data,
        }, {
                .name = "sdhci-esdhc-imx35",
-               .driver_data = IMX35_ESDHC,
+               .driver_data = (kernel_ulong_t) &esdhc_imx35_data,
        }, {
                .name = "sdhci-esdhc-imx51",
-               .driver_data = IMX51_ESDHC,
-       }, {
-               .name = "sdhci-esdhc-imx53",
-               .driver_data = IMX53_ESDHC,
-       }, {
-               .name = "sdhci-usdhc-imx6q",
-               .driver_data = IMX6Q_USDHC,
+               .driver_data = (kernel_ulong_t) &esdhc_imx51_data,
        }, {
                /* sentinel */
        }
@@ -116,38 +178,34 @@ static struct platform_device_id imx_esdhc_devtype[] = {
 MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype);
 
 static const struct of_device_id imx_esdhc_dt_ids[] = {
-       { .compatible = "fsl,imx25-esdhc", .data = &imx_esdhc_devtype[IMX25_ESDHC], },
-       { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], },
-       { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], },
-       { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], },
-       { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], },
+       { .compatible = "fsl,imx25-esdhc", .data = &esdhc_imx25_data, },
+       { .compatible = "fsl,imx35-esdhc", .data = &esdhc_imx35_data, },
+       { .compatible = "fsl,imx51-esdhc", .data = &esdhc_imx51_data, },
+       { .compatible = "fsl,imx53-esdhc", .data = &esdhc_imx53_data, },
+       { .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
+       { .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
 
 static inline int is_imx25_esdhc(struct pltfm_imx_data *data)
 {
-       return data->devtype == IMX25_ESDHC;
-}
-
-static inline int is_imx35_esdhc(struct pltfm_imx_data *data)
-{
-       return data->devtype == IMX35_ESDHC;
+       return data->socdata == &esdhc_imx25_data;
 }
 
-static inline int is_imx51_esdhc(struct pltfm_imx_data *data)
+static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
 {
-       return data->devtype == IMX51_ESDHC;
+       return data->socdata == &esdhc_imx53_data;
 }
 
-static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
+static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
 {
-       return data->devtype == IMX53_ESDHC;
+       return data->socdata == &usdhc_imx6q_data;
 }
 
-static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
+static inline int esdhc_is_usdhc(struct pltfm_imx_data *data)
 {
-       return data->devtype == IMX6Q_USDHC;
+       return !!(data->socdata->flags & ESDHC_FLAG_USDHC);
 }
 
 static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
@@ -164,7 +222,21 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
        struct pltfm_imx_data *imx_data = pltfm_host->priv;
        u32 val = readl(host->ioaddr + reg);
 
+       if (unlikely(reg == SDHCI_PRESENT_STATE)) {
+               u32 fsl_prss = val;
+               /* save the least 20 bits */
+               val = fsl_prss & 0x000FFFFF;
+               /* move dat[0-3] bits */
+               val |= (fsl_prss & 0x0F000000) >> 4;
+               /* move cmd line bit */
+               val |= (fsl_prss & 0x00800000) << 1;
+       }
+
        if (unlikely(reg == SDHCI_CAPABILITIES)) {
+               /* ignore bit[0-15] as it stores cap_1 register val for mx6sl */
+               if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1)
+                       val &= 0xffff0000;
+
                /* In FSL esdhc IC module, only bit20 is used to indicate the
                 * ADMA2 capability of esdhc, but this bit is messed up on
                 * some SOCs (e.g. on MX25, MX35 this bit is set, but they
@@ -178,6 +250,25 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
                }
        }
 
+       if (unlikely(reg == SDHCI_CAPABILITIES_1)) {
+               if (esdhc_is_usdhc(imx_data)) {
+                       if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1)
+                               val = readl(host->ioaddr + SDHCI_CAPABILITIES) & 0xFFFF;
+                       else
+                               /* imx6q/dl does not have cap_1 register, fake one */
+                               val = SDHCI_SUPPORT_DDR50 | SDHCI_SUPPORT_SDR104
+                                       | SDHCI_SUPPORT_SDR50
+                                       | SDHCI_USE_SDR50_TUNING;
+               }
+       }
+
+       if (unlikely(reg == SDHCI_MAX_CURRENT) && esdhc_is_usdhc(imx_data)) {
+               val = 0;
+               val |= 0xFF << SDHCI_MAX_CURRENT_330_SHIFT;
+               val |= 0xFF << SDHCI_MAX_CURRENT_300_SHIFT;
+               val |= 0xFF << SDHCI_MAX_CURRENT_180_SHIFT;
+       }
+
        if (unlikely(reg == SDHCI_INT_STATUS)) {
                if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) {
                        val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR;
@@ -224,7 +315,7 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
                }
        }
 
-       if (unlikely((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
+       if (unlikely((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
                                && (reg == SDHCI_INT_STATUS)
                                && (val & SDHCI_INT_DATA_END))) {
                        u32 v;
@@ -256,10 +347,12 @@ static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
        struct pltfm_imx_data *imx_data = pltfm_host->priv;
+       u16 ret = 0;
+       u32 val;
 
        if (unlikely(reg == SDHCI_HOST_VERSION)) {
                reg ^= 2;
-               if (is_imx6q_usdhc(imx_data)) {
+               if (esdhc_is_usdhc(imx_data)) {
                        /*
                         * The usdhc register returns a wrong host version.
                         * Correct it here.
@@ -268,6 +361,30 @@ static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
                }
        }
 
+       if (unlikely(reg == SDHCI_HOST_CONTROL2)) {
+               val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
+               if (val & ESDHC_VENDOR_SPEC_VSELECT)
+                       ret |= SDHCI_CTRL_VDD_180;
+
+               if (esdhc_is_usdhc(imx_data)) {
+                       if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
+                               val = readl(host->ioaddr + ESDHC_MIX_CTRL);
+                       else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
+                               /* the std tuning bits is in ACMD12_ERR for imx6sl */
+                               val = readl(host->ioaddr + SDHCI_ACMD12_ERR);
+               }
+
+               if (val & ESDHC_MIX_CTRL_EXE_TUNE)
+                       ret |= SDHCI_CTRL_EXEC_TUNING;
+               if (val & ESDHC_MIX_CTRL_SMPCLK_SEL)
+                       ret |= SDHCI_CTRL_TUNED_CLK;
+
+               ret |= (imx_data->uhs_mode & SDHCI_CTRL_UHS_MASK);
+               ret &= ~SDHCI_CTRL_PRESET_VAL_ENABLE;
+
+               return ret;
+       }
+
        return readw(host->ioaddr + reg);
 }
 
@@ -275,10 +392,59 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
        struct pltfm_imx_data *imx_data = pltfm_host->priv;
+       u32 new_val = 0;
 
        switch (reg) {
+       case SDHCI_CLOCK_CONTROL:
+               new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
+               if (val & SDHCI_CLOCK_CARD_EN)
+                       new_val |= ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
+               else
+                       new_val &= ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON;
+                       writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
+               return;
+       case SDHCI_HOST_CONTROL2:
+               new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
+               if (val & SDHCI_CTRL_VDD_180)
+                       new_val |= ESDHC_VENDOR_SPEC_VSELECT;
+               else
+                       new_val &= ~ESDHC_VENDOR_SPEC_VSELECT;
+               writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC);
+               imx_data->uhs_mode = val & SDHCI_CTRL_UHS_MASK;
+               if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
+                       new_val = readl(host->ioaddr + ESDHC_MIX_CTRL);
+                       if (val & SDHCI_CTRL_TUNED_CLK)
+                               new_val |= ESDHC_MIX_CTRL_SMPCLK_SEL;
+                       else
+                               new_val &= ~ESDHC_MIX_CTRL_SMPCLK_SEL;
+                       writel(new_val , host->ioaddr + ESDHC_MIX_CTRL);
+               } else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) {
+                       u32 v = readl(host->ioaddr + SDHCI_ACMD12_ERR);
+                       u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
+                       new_val = readl(host->ioaddr + ESDHC_TUNING_CTRL);
+                       if (val & SDHCI_CTRL_EXEC_TUNING) {
+                               new_val |= ESDHC_STD_TUNING_EN |
+                                               ESDHC_TUNING_START_TAP;
+                               v |= ESDHC_MIX_CTRL_EXE_TUNE;
+                               m |= ESDHC_MIX_CTRL_FBCLK_SEL;
+                       } else {
+                               new_val &= ~ESDHC_STD_TUNING_EN;
+                               v &= ~ESDHC_MIX_CTRL_EXE_TUNE;
+                               m &= ~ESDHC_MIX_CTRL_FBCLK_SEL;
+                       }
+
+                       if (val & SDHCI_CTRL_TUNED_CLK)
+                               v |= ESDHC_MIX_CTRL_SMPCLK_SEL;
+                       else
+                               v &= ~ESDHC_MIX_CTRL_SMPCLK_SEL;
+
+                       writel(new_val, host->ioaddr + ESDHC_TUNING_CTRL);
+                       writel(v, host->ioaddr + SDHCI_ACMD12_ERR);
+                       writel(m, host->ioaddr + ESDHC_MIX_CTRL);
+               }
+               return;
        case SDHCI_TRANSFER_MODE:
-               if ((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
+               if ((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)
                                && (host->cmd->opcode == SD_IO_RW_EXTENDED)
                                && (host->cmd->data->blocks > 1)
                                && (host->cmd->data->flags & MMC_DATA_READ)) {
@@ -288,7 +454,7 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
                        writel(v, host->ioaddr + ESDHC_VENDOR_SPEC);
                }
 
-               if (is_imx6q_usdhc(imx_data)) {
+               if (esdhc_is_usdhc(imx_data)) {
                        u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL);
                        /* Swap AC23 bit */
                        if (val & SDHCI_TRNS_AUTO_CMD23) {
@@ -310,10 +476,10 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
                        val |= SDHCI_CMD_ABORTCMD;
 
                if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) &&
-                   (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
+                   (imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
                        imx_data->multiblock_status = MULTIBLK_IN_PROCESS;
 
-               if (is_imx6q_usdhc(imx_data))
+               if (esdhc_is_usdhc(imx_data))
                        writel(val << 16,
                               host->ioaddr + SDHCI_TRANSFER_MODE);
                else
@@ -379,8 +545,10 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
                 * The reset on usdhc fails to clear MIX_CTRL register.
                 * Do it manually here.
                 */
-               if (is_imx6q_usdhc(imx_data))
+               if (esdhc_is_usdhc(imx_data)) {
                        writel(0, host->ioaddr + ESDHC_MIX_CTRL);
+                       imx_data->is_ddr = 0;
+               }
        }
 }
 
@@ -409,8 +577,60 @@ static inline void esdhc_pltfm_set_clock(struct sdhci_host *host,
                                         unsigned int clock)
 {
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data = pltfm_host->priv;
+       unsigned int host_clock = clk_get_rate(pltfm_host->clk);
+       int pre_div = 2;
+       int div = 1;
+       u32 temp, val;
+
+       if (clock == 0) {
+               if (esdhc_is_usdhc(imx_data)) {
+                       val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
+                       writel(val & ~ESDHC_VENDOR_SPEC_FRC_SDCLK_ON,
+                                       host->ioaddr + ESDHC_VENDOR_SPEC);
+               }
+               goto out;
+       }
+
+       if (esdhc_is_usdhc(imx_data) && !imx_data->is_ddr)
+               pre_div = 1;
+
+       temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
+       temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
+               | ESDHC_CLOCK_MASK);
+       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
+
+       while (host_clock / pre_div / 16 > clock && pre_div < 256)
+               pre_div *= 2;
+
+       while (host_clock / pre_div / div > clock && div < 16)
+               div++;
 
-       esdhc_set_clock(host, clock, clk_get_rate(pltfm_host->clk));
+       host->mmc->actual_clock = host_clock / pre_div / div;
+       dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
+               clock, host->mmc->actual_clock);
+
+       if (imx_data->is_ddr)
+               pre_div >>= 2;
+       else
+               pre_div >>= 1;
+       div--;
+
+       temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
+       temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
+               | (div << ESDHC_DIVIDER_SHIFT)
+               | (pre_div << ESDHC_PREDIV_SHIFT));
+       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
+
+       if (esdhc_is_usdhc(imx_data)) {
+               val = readl(host->ioaddr + ESDHC_VENDOR_SPEC);
+               writel(val | ESDHC_VENDOR_SPEC_FRC_SDCLK_ON,
+               host->ioaddr + ESDHC_VENDOR_SPEC);
+       }
+
+       mdelay(1);
+out:
+       host->clock = clock;
 }
 
 static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host)
@@ -454,7 +674,192 @@ static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width)
        return 0;
 }
 
-static const struct sdhci_ops sdhci_esdhc_ops = {
+static void esdhc_prepare_tuning(struct sdhci_host *host, u32 val)
+{
+       u32 reg;
+
+       /* FIXME: delay a bit for card to be ready for next tuning due to errors */
+       mdelay(1);
+
+       reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
+       reg |= ESDHC_MIX_CTRL_EXE_TUNE | ESDHC_MIX_CTRL_SMPCLK_SEL |
+                       ESDHC_MIX_CTRL_FBCLK_SEL;
+       writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
+       writel(val << 8, host->ioaddr + ESDHC_TUNE_CTRL_STATUS);
+       dev_dbg(mmc_dev(host->mmc),
+               "tunning with delay 0x%x ESDHC_TUNE_CTRL_STATUS 0x%x\n",
+                       val, readl(host->ioaddr + ESDHC_TUNE_CTRL_STATUS));
+}
+
+static void esdhc_request_done(struct mmc_request *mrq)
+{
+       complete(&mrq->completion);
+}
+
+static int esdhc_send_tuning_cmd(struct sdhci_host *host, u32 opcode)
+{
+       struct mmc_command cmd = {0};
+       struct mmc_request mrq = {0};
+       struct mmc_data data = {0};
+       struct scatterlist sg;
+       char tuning_pattern[ESDHC_TUNING_BLOCK_PATTERN_LEN];
+
+       cmd.opcode = opcode;
+       cmd.arg = 0;
+       cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
+
+       data.blksz = ESDHC_TUNING_BLOCK_PATTERN_LEN;
+       data.blocks = 1;
+       data.flags = MMC_DATA_READ;
+       data.sg = &sg;
+       data.sg_len = 1;
+
+       sg_init_one(&sg, tuning_pattern, sizeof(tuning_pattern));
+
+       mrq.cmd = &cmd;
+       mrq.cmd->mrq = &mrq;
+       mrq.data = &data;
+       mrq.data->mrq = &mrq;
+       mrq.cmd->data = mrq.data;
+
+       mrq.done = esdhc_request_done;
+       init_completion(&(mrq.completion));
+
+       disable_irq(host->irq);
+       spin_lock(&host->lock);
+       host->mrq = &mrq;
+
+       sdhci_send_command(host, mrq.cmd);
+
+       spin_unlock(&host->lock);
+       enable_irq(host->irq);
+
+       wait_for_completion(&mrq.completion);
+
+       if (cmd.error)
+               return cmd.error;
+       if (data.error)
+               return data.error;
+
+       return 0;
+}
+
+static void esdhc_post_tuning(struct sdhci_host *host)
+{
+       u32 reg;
+
+       reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
+       reg &= ~ESDHC_MIX_CTRL_EXE_TUNE;
+       writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
+}
+
+static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
+{
+       int min, max, avg, ret;
+
+       /* find the mininum delay first which can pass tuning */
+       min = ESDHC_TUNE_CTRL_MIN;
+       while (min < ESDHC_TUNE_CTRL_MAX) {
+               esdhc_prepare_tuning(host, min);
+               if (!esdhc_send_tuning_cmd(host, opcode))
+                       break;
+               min += ESDHC_TUNE_CTRL_STEP;
+       }
+
+       /* find the maxinum delay which can not pass tuning */
+       max = min + ESDHC_TUNE_CTRL_STEP;
+       while (max < ESDHC_TUNE_CTRL_MAX) {
+               esdhc_prepare_tuning(host, max);
+               if (esdhc_send_tuning_cmd(host, opcode)) {
+                       max -= ESDHC_TUNE_CTRL_STEP;
+                       break;
+               }
+               max += ESDHC_TUNE_CTRL_STEP;
+       }
+
+       /* use average delay to get the best timing */
+       avg = (min + max) / 2;
+       esdhc_prepare_tuning(host, avg);
+       ret = esdhc_send_tuning_cmd(host, opcode);
+       esdhc_post_tuning(host);
+
+       dev_dbg(mmc_dev(host->mmc), "tunning %s at 0x%x ret %d\n",
+               ret ? "failed" : "passed", avg, ret);
+
+       return ret;
+}
+
+static int esdhc_change_pinstate(struct sdhci_host *host,
+                                               unsigned int uhs)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data = pltfm_host->priv;
+       struct pinctrl_state *pinctrl;
+
+       dev_dbg(mmc_dev(host->mmc), "change pinctrl state for uhs %d\n", uhs);
+
+       if (IS_ERR(imx_data->pinctrl) ||
+               IS_ERR(imx_data->pins_default) ||
+               IS_ERR(imx_data->pins_100mhz) ||
+               IS_ERR(imx_data->pins_200mhz))
+               return -EINVAL;
+
+       switch (uhs) {
+       case MMC_TIMING_UHS_SDR50:
+               pinctrl = imx_data->pins_100mhz;
+               break;
+       case MMC_TIMING_UHS_SDR104:
+               pinctrl = imx_data->pins_200mhz;
+               break;
+       default:
+               /* back to default state for other legacy timing */
+               pinctrl = imx_data->pins_default;
+       }
+
+       return pinctrl_select_state(imx_data->pinctrl, pinctrl);
+}
+
+static int esdhc_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs)
+{
+       struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+       struct pltfm_imx_data *imx_data = pltfm_host->priv;
+       struct esdhc_platform_data *boarddata = &imx_data->boarddata;
+
+       switch (uhs) {
+       case MMC_TIMING_UHS_SDR12:
+               imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR12;
+               break;
+       case MMC_TIMING_UHS_SDR25:
+               imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR25;
+               break;
+       case MMC_TIMING_UHS_SDR50:
+               imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR50;
+               break;
+       case MMC_TIMING_UHS_SDR104:
+               imx_data->uhs_mode = SDHCI_CTRL_UHS_SDR104;
+               break;
+       case MMC_TIMING_UHS_DDR50:
+               imx_data->uhs_mode = SDHCI_CTRL_UHS_DDR50;
+               writel(readl(host->ioaddr + ESDHC_MIX_CTRL) |
+                               ESDHC_MIX_CTRL_DDREN,
+                               host->ioaddr + ESDHC_MIX_CTRL);
+               imx_data->is_ddr = 1;
+               if (boarddata->delay_line) {
+                       u32 v;
+                       v = boarddata->delay_line <<
+                               ESDHC_DLL_OVERRIDE_VAL_SHIFT |
+                               (1 << ESDHC_DLL_OVERRIDE_EN_SHIFT);
+                       if (is_imx53_esdhc(imx_data))
+                               v <<= 1;
+                       writel(v, host->ioaddr + ESDHC_DLL_CTRL);
+               }
+               break;
+       }
+
+       return esdhc_change_pinstate(host, uhs);
+}
+
+static struct sdhci_ops sdhci_esdhc_ops = {
        .read_l = esdhc_readl_le,
        .read_w = esdhc_readw_le,
        .write_l = esdhc_writel_le,
@@ -465,6 +870,7 @@ static const struct sdhci_ops sdhci_esdhc_ops = {
        .get_min_clock = esdhc_pltfm_get_min_clock,
        .get_ro = esdhc_pltfm_get_ro,
        .platform_bus_width = esdhc_pltfm_bus_width,
+       .set_uhs_signaling = esdhc_set_uhs_signaling,
 };
 
 static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
@@ -506,6 +912,14 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev,
 
        of_property_read_u32(np, "max-frequency", &boarddata->f_max);
 
+       if (of_find_property(np, "no-1-8-v", NULL))
+               boarddata->support_vsel = false;
+       else
+               boarddata->support_vsel = true;
+
+       if (of_property_read_u32(np, "fsl,delay-line", &boarddata->delay_line))
+               boarddata->delay_line = 0;
+
        return 0;
 }
 #else
@@ -539,9 +953,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
                goto free_sdhci;
        }
 
-       if (of_id)
-               pdev->id_entry = of_id->data;
-       imx_data->devtype = pdev->id_entry->driver_data;
+       imx_data->socdata = of_id ? of_id->data : (struct esdhc_soc_data *)
+                                                 pdev->id_entry->driver_data;
        pltfm_host->priv = imx_data;
 
        imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
@@ -568,29 +981,39 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
        clk_prepare_enable(imx_data->clk_ipg);
        clk_prepare_enable(imx_data->clk_ahb);
 
-       imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+       imx_data->pinctrl = devm_pinctrl_get(&pdev->dev);
        if (IS_ERR(imx_data->pinctrl)) {
                err = PTR_ERR(imx_data->pinctrl);
                goto disable_clk;
        }
 
+       imx_data->pins_default = pinctrl_lookup_state(imx_data->pinctrl,
+                                               PINCTRL_STATE_DEFAULT);
+       if (IS_ERR(imx_data->pins_default)) {
+               err = PTR_ERR(imx_data->pins_default);
+               dev_err(mmc_dev(host->mmc), "could not get default state\n");
+               goto disable_clk;
+       }
+
        host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
 
-       if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data))
+       if (imx_data->socdata->flags & ESDHC_FLAG_ENGCM07207)
                /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
                host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
                        | SDHCI_QUIRK_BROKEN_ADMA;
 
-       if (is_imx53_esdhc(imx_data))
-               imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
-
        /*
         * The imx6q ROM code will change the default watermark level setting
         * to something insane.  Change it back here.
         */
-       if (is_imx6q_usdhc(imx_data))
+       if (esdhc_is_usdhc(imx_data)) {
                writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL);
+               host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
+       }
 
+       if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
+               sdhci_esdhc_ops.platform_execute_tuning =
+                                       esdhc_executing_tuning;
        boarddata = &imx_data->boarddata;
        if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
                if (!host->mmc->parent->platform_data) {
@@ -650,6 +1073,23 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
                break;
        }
 
+       /* sdr50 and sdr104 needs work on 1.8v signal voltage */
+       if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data)) {
+               imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl,
+                                               ESDHC_PINCTRL_STATE_100MHZ);
+               imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl,
+                                               ESDHC_PINCTRL_STATE_200MHZ);
+               if (IS_ERR(imx_data->pins_100mhz) ||
+                               IS_ERR(imx_data->pins_200mhz)) {
+                       dev_warn(mmc_dev(host->mmc),
+                               "could not get ultra high speed state, work on normal mode\n");
+                       /* fall back to not support uhs by specify no 1.8v quirk */
+                       host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
+               }
+       } else {
+               host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V;
+       }
+
        err = sdhci_add_host(host);
        if (err)
                goto disable_clk;
index a2a06420e4635b3904c0cd73f662b21623994de7..a7d9f95a7b03dd81af540212ef8016157a595c5e 100644 (file)
 
 #define ESDHC_HOST_CONTROL_RES 0x05
 
-static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock,
-                                  unsigned int host_clock)
-{
-       int pre_div = 2;
-       int div = 1;
-       u32 temp;
-
-       if (clock == 0)
-               goto out;
-
-       temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-       temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-               | ESDHC_CLOCK_MASK);
-       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-
-       while (host_clock / pre_div / 16 > clock && pre_div < 256)
-               pre_div *= 2;
-
-       while (host_clock / pre_div / div > clock && div < 16)
-               div++;
-
-       dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
-               clock, host_clock / pre_div / div);
-
-       pre_div >>= 1;
-       div--;
-
-       temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
-       temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
-               | (div << ESDHC_DIVIDER_SHIFT)
-               | (pre_div << ESDHC_PREDIV_SHIFT));
-       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
-       mdelay(1);
-out:
-       host->clock = clock;
-}
-
 #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
index e328252ebf2a7f684d0756dbfe1c1b20935d05ab..0b249970b1197fcc92af6e63184c72cf7c406286 100644 (file)
@@ -199,6 +199,14 @@ static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
 
 static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
 {
+
+       int pre_div = 2;
+       int div = 1;
+       u32 temp;
+
+       if (clock == 0)
+               goto out;
+
        /* Workaround to reduce the clock frequency for p1010 esdhc */
        if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) {
                if (clock > 20000000)
@@ -207,8 +215,31 @@ static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
                        clock -= 5000000;
        }
 
-       /* Set the clock */
-       esdhc_set_clock(host, clock, host->max_clk);
+       temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
+       temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
+               | ESDHC_CLOCK_MASK);
+       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
+
+       while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
+               pre_div *= 2;
+
+       while (host->max_clk / pre_div / div > clock && div < 16)
+               div++;
+
+       dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
+               clock, host->max_clk / pre_div / div);
+
+       pre_div >>= 1;
+       div--;
+
+       temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
+       temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
+               | (div << ESDHC_DIVIDER_SHIFT)
+               | (pre_div << ESDHC_PREDIV_SHIFT));
+       sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
+       mdelay(1);
+out:
+       host->clock = clock;
 }
 
 #ifdef CONFIG_PM
index d7d6bc8968d2422d8b2e9fb44a695b35b17927d4..8f753811fc7a6ccec6ca8bf5090cc98287013f45 100644 (file)
 #define PCI_DEVICE_ID_INTEL_BYT_SDIO   0x0f15
 #define PCI_DEVICE_ID_INTEL_BYT_SD     0x0f16
 #define PCI_DEVICE_ID_INTEL_BYT_EMMC2  0x0f50
+#define PCI_DEVICE_ID_INTEL_MRFL_MMC   0x1190
+#define PCI_DEVICE_ID_INTEL_CLV_SDIO0  0x08f9
+#define PCI_DEVICE_ID_INTEL_CLV_SDIO1  0x08fa
+#define PCI_DEVICE_ID_INTEL_CLV_SDIO2  0x08fb
+#define PCI_DEVICE_ID_INTEL_CLV_EMMC0  0x08e5
+#define PCI_DEVICE_ID_INTEL_CLV_EMMC1  0x08e6
 
 /*
  * PCI registers
@@ -356,6 +362,28 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
        .allow_runtime_pm = true,
 };
 
+/* Define Host controllers for Intel Merrifield platform */
+#define INTEL_MRFL_EMMC_0      0
+#define INTEL_MRFL_EMMC_1      1
+
+static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
+{
+       if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
+           (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
+               /* SD support is not ready yet */
+               return -ENODEV;
+
+       slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
+                                MMC_CAP_1_8V_DDR;
+
+       return 0;
+}
+
+static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
+       .quirks         = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
+       .probe_slot     = intel_mrfl_mmc_probe_slot,
+};
+
 /* O2Micro extra registers */
 #define O2_SD_LOCK_WP          0xD3
 #define O2_SD_MULTI_VCC3V      0xEE
@@ -939,6 +967,54 @@ static const struct pci_device_id pci_ids[] = {
                .driver_data    = (kernel_ulong_t)&sdhci_intel_byt_emmc,
        },
 
+
+       {
+               .vendor         = PCI_VENDOR_ID_INTEL,
+               .device         = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = (kernel_ulong_t)&sdhci_intel_mfd_sd,
+       },
+
+       {
+               .vendor         = PCI_VENDOR_ID_INTEL,
+               .device         = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
+       },
+
+       {
+               .vendor         = PCI_VENDOR_ID_INTEL,
+               .device         = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
+       },
+
+       {
+               .vendor         = PCI_VENDOR_ID_INTEL,
+               .device         = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
+       },
+
+       {
+               .vendor         = PCI_VENDOR_ID_INTEL,
+               .device         = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
+       },
+
+       {
+               .vendor         = PCI_VENDOR_ID_INTEL,
+               .device         = PCI_DEVICE_ID_INTEL_MRFL_MMC,
+               .subvendor      = PCI_ANY_ID,
+               .subdevice      = PCI_ANY_ID,
+               .driver_data    = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
+       },
        {
                .vendor         = PCI_VENDOR_ID_O2,
                .device         = PCI_DEVICE_ID_O2_8120,
index 7a7fb4f0d5a43a4829fa1e258afbf112f4dd9b82..bd8a0982aec33ec99b95b97fbcbdd65dee642770 100644 (file)
@@ -49,7 +49,6 @@ static unsigned int debug_quirks2;
 
 static void sdhci_finish_data(struct sdhci_host *);
 
-static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
 static void sdhci_finish_command(struct sdhci_host *);
 static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
 static void sdhci_tuning_timer(unsigned long data);
@@ -981,7 +980,7 @@ static void sdhci_finish_data(struct sdhci_host *host)
                tasklet_schedule(&host->finish_tasklet);
 }
 
-static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
+void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 {
        int flags;
        u32 mask;
@@ -1053,6 +1052,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 
        sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
 }
+EXPORT_SYMBOL_GPL(sdhci_send_command);
 
 static void sdhci_finish_command(struct sdhci_host *host)
 {
@@ -1435,7 +1435,8 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
        }
 
        if (host->version >= SDHCI_SPEC_300 &&
-               (ios->power_mode == MMC_POWER_UP))
+               (ios->power_mode == MMC_POWER_UP) &&
+               !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN))
                sdhci_enable_preset_value(host, false);
 
        sdhci_set_clock(host, ios->clock);
@@ -1875,6 +1876,14 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
                return 0;
        }
 
+       if (host->ops->platform_execute_tuning) {
+               spin_unlock(&host->lock);
+               enable_irq(host->irq);
+               err = host->ops->platform_execute_tuning(host, opcode);
+               sdhci_runtime_pm_put(host);
+               return err;
+       }
+
        sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
 
        /*
@@ -1981,6 +1990,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
        if (!tuning_loop_counter || !timeout) {
                ctrl &= ~SDHCI_CTRL_TUNED_CLK;
                sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
+               err = -EIO;
        } else {
                if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
                        pr_info(DRIVER_NAME ": Tuning procedure"
@@ -2491,6 +2501,14 @@ again:
        result = IRQ_HANDLED;
 
        intmask = sdhci_readl(host, SDHCI_INT_STATUS);
+
+       /*
+        * If we know we'll call the driver to signal SDIO IRQ, disregard
+        * further indications of Card Interrupt in the status to avoid a
+        * needless loop.
+        */
+       if (cardint)
+               intmask &= ~SDHCI_INT_CARD_INT;
        if (intmask && --max_loops)
                goto again;
 out:
@@ -2546,8 +2564,6 @@ EXPORT_SYMBOL_GPL(sdhci_disable_irq_wakeups);
 
 int sdhci_suspend_host(struct sdhci_host *host)
 {
-       int ret;
-
        if (host->ops->platform_suspend)
                host->ops->platform_suspend(host);
 
@@ -2559,19 +2575,6 @@ int sdhci_suspend_host(struct sdhci_host *host)
                host->flags &= ~SDHCI_NEEDS_RETUNING;
        }
 
-       ret = mmc_suspend_host(host->mmc);
-       if (ret) {
-               if (host->flags & SDHCI_USING_RETUNING_TIMER) {
-                       host->flags |= SDHCI_NEEDS_RETUNING;
-                       mod_timer(&host->tuning_timer, jiffies +
-                                       host->tuning_count * HZ);
-               }
-
-               sdhci_enable_card_detection(host);
-
-               return ret;
-       }
-
        if (!device_may_wakeup(mmc_dev(host->mmc))) {
                sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
                free_irq(host->irq, host);
@@ -2579,14 +2582,14 @@ int sdhci_suspend_host(struct sdhci_host *host)
                sdhci_enable_irq_wakeups(host);
                enable_irq_wake(host->irq);
        }
-       return ret;
+       return 0;
 }
 
 EXPORT_SYMBOL_GPL(sdhci_suspend_host);
 
 int sdhci_resume_host(struct sdhci_host *host)
 {
-       int ret;
+       int ret = 0;
 
        if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
                if (host->ops->enable_dma)
@@ -2615,7 +2618,6 @@ int sdhci_resume_host(struct sdhci_host *host)
                mmiowb();
        }
 
-       ret = mmc_resume_host(host->mmc);
        sdhci_enable_card_detection(host);
 
        if (host->ops->platform_resume)
index b037f188fe44b26c357b77ebe985f8406aa4c1ac..0a3ed01887db824da03a66f103ef4b4948fc074f 100644 (file)
@@ -288,6 +288,7 @@ struct sdhci_ops {
        unsigned int    (*get_ro)(struct sdhci_host *host);
        void    (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
        void    (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
+       int     (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
        int     (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
        void    (*hw_reset)(struct sdhci_host *host);
        void    (*platform_suspend)(struct sdhci_host *host);
@@ -393,6 +394,8 @@ static inline void *sdhci_priv(struct sdhci_host *host)
 extern void sdhci_card_detect(struct sdhci_host *host);
 extern int sdhci_add_host(struct sdhci_host *host);
 extern void sdhci_remove_host(struct sdhci_host *host, int dead);
+extern void sdhci_send_command(struct sdhci_host *host,
+                               struct mmc_command *cmd);
 
 #ifdef CONFIG_PM
 extern int sdhci_suspend_host(struct sdhci_host *host);
index 50adbd155f355bc00676fcc8d986b889f3c28040..b7e305775314fa75ccc58dd67752420bda8494ce 100644 (file)
@@ -516,9 +516,7 @@ static void sdricoh_pcmcia_detach(struct pcmcia_device *link)
 #ifdef CONFIG_PM
 static int sdricoh_pcmcia_suspend(struct pcmcia_device *link)
 {
-       struct mmc_host *mmc = link->priv;
        dev_dbg(&link->dev, "suspend\n");
-       mmc_suspend_host(mmc);
        return 0;
 }
 
@@ -527,7 +525,6 @@ static int sdricoh_pcmcia_resume(struct pcmcia_device *link)
        struct mmc_host *mmc = link->priv;
        dev_dbg(&link->dev, "resume\n");
        sdricoh_reset(mmc_priv(mmc));
-       mmc_resume_host(mmc);
        return 0;
 }
 #else
index 36629a024aa1350e6278237f42a6d92e97b33807..d032b080ac4de66311e390458629204332a6ca57 100644 (file)
@@ -964,7 +964,7 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
 static int sh_mmcif_clk_update(struct sh_mmcif_host *host)
 {
-       int ret = clk_enable(host->hclk);
+       int ret = clk_prepare_enable(host->hclk);
 
        if (!ret) {
                host->clk = clk_get_rate(host->hclk);
@@ -1018,7 +1018,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                }
                if (host->power) {
                        pm_runtime_put_sync(&host->pd->dev);
-                       clk_disable(host->hclk);
+                       clk_disable_unprepare(host->hclk);
                        host->power = false;
                        if (ios->power_mode == MMC_POWER_OFF)
                                sh_mmcif_set_power(host, ios);
@@ -1466,7 +1466,7 @@ static int sh_mmcif_probe(struct platform_device *pdev)
 
        mutex_init(&host->thread_lock);
 
-       clk_disable(host->hclk);
+       clk_disable_unprepare(host->hclk);
        ret = mmc_add_host(mmc);
        if (ret < 0)
                goto emmcaddh;
@@ -1487,7 +1487,7 @@ ereqirq1:
 ereqirq0:
        pm_runtime_suspend(&pdev->dev);
 eresume:
-       clk_disable(host->hclk);
+       clk_disable_unprepare(host->hclk);
 eclkupdate:
        clk_put(host->hclk);
 eclkget:
@@ -1505,7 +1505,7 @@ static int sh_mmcif_remove(struct platform_device *pdev)
        int irq[2];
 
        host->dying = true;
-       clk_enable(host->hclk);
+       clk_prepare_enable(host->hclk);
        pm_runtime_get_sync(&pdev->dev);
 
        dev_pm_qos_hide_latency_limit(&pdev->dev);
@@ -1530,7 +1530,7 @@ static int sh_mmcif_remove(struct platform_device *pdev)
        if (irq[1] >= 0)
                free_irq(irq[1], host);
 
-       clk_disable(host->hclk);
+       clk_disable_unprepare(host->hclk);
        mmc_free_host(host->mmc);
        pm_runtime_put_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
@@ -1538,28 +1538,21 @@ static int sh_mmcif_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 static int sh_mmcif_suspend(struct device *dev)
 {
        struct sh_mmcif_host *host = dev_get_drvdata(dev);
-       int ret = mmc_suspend_host(host->mmc);
 
-       if (!ret)
-               sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
+       sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
 
-       return ret;
+       return 0;
 }
 
 static int sh_mmcif_resume(struct device *dev)
 {
-       struct sh_mmcif_host *host = dev_get_drvdata(dev);
-
-       return mmc_resume_host(host->mmc);
+       return 0;
 }
-#else
-#define sh_mmcif_suspend       NULL
-#define sh_mmcif_resume                NULL
-#endif /* CONFIG_PM */
+#endif
 
 static const struct of_device_id mmcif_of_match[] = {
        { .compatible = "renesas,sh-mmcif" },
@@ -1568,8 +1561,7 @@ static const struct of_device_id mmcif_of_match[] = {
 MODULE_DEVICE_TABLE(of, mmcif_of_match);
 
 static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
-       .suspend = sh_mmcif_suspend,
-       .resume = sh_mmcif_resume,
+       SET_SYSTEM_SLEEP_PM_OPS(sh_mmcif_suspend, sh_mmcif_resume)
 };
 
 static struct platform_driver sh_mmcif_driver = {
index 43d962829f8ec60326a0c63f3b3274871f2904fd..d1760ebcac0359e6e25273ac849f4c89f60f6b2b 100644 (file)
@@ -1030,7 +1030,7 @@ static void tifm_sd_remove(struct tifm_dev *sock)
 
 static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state)
 {
-       return mmc_suspend_host(tifm_get_drvdata(sock));
+       return 0;
 }
 
 static int tifm_sd_resume(struct tifm_dev *sock)
@@ -1044,8 +1044,6 @@ static int tifm_sd_resume(struct tifm_dev *sock)
 
        if (rc)
                host->eject = 1;
-       else
-               rc = mmc_resume_host(mmc);
 
        return rc;
 }
index b3802256f954b24d7da9f2b3dae35eed4091cae1..f3b2d8ca1eca5cc831d2269e4617938bf3d90bfb 100644 (file)
@@ -1145,12 +1145,9 @@ int tmio_mmc_host_suspend(struct device *dev)
 {
        struct mmc_host *mmc = dev_get_drvdata(dev);
        struct tmio_mmc_host *host = mmc_priv(mmc);
-       int ret = mmc_suspend_host(mmc);
 
-       if (!ret)
-               tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL);
-
-       return ret;
+       tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_ALL);
+       return 0;
 }
 EXPORT_SYMBOL(tmio_mmc_host_suspend);
 
@@ -1163,7 +1160,7 @@ int tmio_mmc_host_resume(struct device *dev)
 
        /* The MMC core will perform the complete set up */
        host->resuming = true;
-       return mmc_resume_host(mmc);
+       return 0;
 }
 EXPORT_SYMBOL(tmio_mmc_host_resume);
 
index 4f84586c6e9eeed9cafd5f89cc83c530b46fff87..63fac78b3d46aaa0a76861cc8c359c441b367a76 100644 (file)
@@ -1269,21 +1269,18 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
 static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
 {
        struct via_crdr_mmc_host *host;
-       int ret = 0;
 
        host = pci_get_drvdata(pcidev);
 
        via_save_pcictrlreg(host);
        via_save_sdcreg(host);
 
-       ret = mmc_suspend_host(host->mmc);
-
        pci_save_state(pcidev);
        pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0);
        pci_disable_device(pcidev);
        pci_set_power_state(pcidev, pci_choose_state(pcidev, state));
 
-       return ret;
+       return 0;
 }
 
 static int via_sd_resume(struct pci_dev *pcidev)
@@ -1316,8 +1313,6 @@ static int via_sd_resume(struct pci_dev *pcidev)
        via_restore_pcictrlreg(sdhost);
        via_init_sdc_pm(sdhost);
 
-       ret = mmc_resume_host(sdhost->mmc);
-
        return ret;
 }
 
index e9028ad05ffbe3fe070e91ff9f7dda4a6a71bdd3..4262296c12faa7bb210068d3b62be7216040fc5a 100644 (file)
@@ -2392,26 +2392,12 @@ static void vub300_disconnect(struct usb_interface *interface)
 #ifdef CONFIG_PM
 static int vub300_suspend(struct usb_interface *intf, pm_message_t message)
 {
-       struct vub300_mmc_host *vub300 = usb_get_intfdata(intf);
-       if (!vub300 || !vub300->mmc) {
-               return 0;
-       } else {
-               struct mmc_host *mmc = vub300->mmc;
-               mmc_suspend_host(mmc);
-               return 0;
-       }
+       return 0;
 }
 
 static int vub300_resume(struct usb_interface *intf)
 {
-       struct vub300_mmc_host *vub300 = usb_get_intfdata(intf);
-       if (!vub300 || !vub300->mmc) {
-               return 0;
-       } else {
-               struct mmc_host *mmc = vub300->mmc;
-               mmc_resume_host(mmc);
-               return 0;
-       }
+       return 0;
 }
 #else
 #define vub300_suspend NULL
index e954b77588769ce6950ff73f9c8e3c5c3320c531..1defd5ed323668780846c6fe85041dec6205c20a 100644 (file)
@@ -1814,28 +1814,11 @@ static void wbsd_pnp_remove(struct pnp_dev *dev)
 
 #ifdef CONFIG_PM
 
-static int wbsd_suspend(struct wbsd_host *host, pm_message_t state)
-{
-       BUG_ON(host == NULL);
-
-       return mmc_suspend_host(host->mmc);
-}
-
-static int wbsd_resume(struct wbsd_host *host)
-{
-       BUG_ON(host == NULL);
-
-       wbsd_init_device(host);
-
-       return mmc_resume_host(host->mmc);
-}
-
 static int wbsd_platform_suspend(struct platform_device *dev,
                                 pm_message_t state)
 {
        struct mmc_host *mmc = platform_get_drvdata(dev);
        struct wbsd_host *host;
-       int ret;
 
        if (mmc == NULL)
                return 0;
@@ -1844,12 +1827,7 @@ static int wbsd_platform_suspend(struct platform_device *dev,
 
        host = mmc_priv(mmc);
 
-       ret = wbsd_suspend(host, state);
-       if (ret)
-               return ret;
-
        wbsd_chip_poweroff(host);
-
        return 0;
 }
 
@@ -1872,7 +1850,8 @@ static int wbsd_platform_resume(struct platform_device *dev)
         */
        mdelay(5);
 
-       return wbsd_resume(host);
+       wbsd_init_device(host);
+       return 0;
 }
 
 #ifdef CONFIG_PNP
@@ -1880,16 +1859,12 @@ static int wbsd_platform_resume(struct platform_device *dev)
 static int wbsd_pnp_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
 {
        struct mmc_host *mmc = dev_get_drvdata(&pnp_dev->dev);
-       struct wbsd_host *host;
 
        if (mmc == NULL)
                return 0;
 
        DBGF("Suspending...\n");
-
-       host = mmc_priv(mmc);
-
-       return wbsd_suspend(host, state);
+       return 0;
 }
 
 static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
@@ -1922,7 +1897,8 @@ static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
         */
        mdelay(5);
 
-       return wbsd_resume(host);
+       wbsd_init_device(host);
+       return 0;
 }
 
 #endif /* CONFIG_PNP */
index 34231d5168fcf12dfe804d2a26b3cda2c6647976..e902ed7846b0544012a289368b187d541ced1969 100644 (file)
@@ -212,28 +212,14 @@ struct wmt_mci_priv {
 
 static void wmt_set_sd_power(struct wmt_mci_priv *priv, int enable)
 {
-       u32 reg_tmp;
-       if (enable) {
-               if (priv->power_inverted) {
-                       reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
-                       writeb(reg_tmp | BM_SD_OFF,
-                              priv->sdmmc_base + SDMMC_BUSMODE);
-               } else {
-                       reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
-                       writeb(reg_tmp & (~BM_SD_OFF),
-                              priv->sdmmc_base + SDMMC_BUSMODE);
-               }
-       } else {
-               if (priv->power_inverted) {
-                       reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
-                       writeb(reg_tmp & (~BM_SD_OFF),
-                              priv->sdmmc_base + SDMMC_BUSMODE);
-               } else {
-                       reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
-                       writeb(reg_tmp | BM_SD_OFF,
-                              priv->sdmmc_base + SDMMC_BUSMODE);
-               }
-       }
+       u32 reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
+
+       if (enable ^ priv->power_inverted)
+               reg_tmp &= ~BM_SD_OFF;
+       else
+               reg_tmp |= BM_SD_OFF;
+
+       writeb(reg_tmp, priv->sdmmc_base + SDMMC_BUSMODE);
 }
 
 static void wmt_mci_read_response(struct mmc_host *mmc)
@@ -939,28 +925,23 @@ static int wmt_mci_suspend(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct mmc_host *mmc = platform_get_drvdata(pdev);
        struct wmt_mci_priv *priv;
-       int ret;
 
        if (!mmc)
                return 0;
 
        priv = mmc_priv(mmc);
-       ret = mmc_suspend_host(mmc);
-
-       if (!ret) {
-               reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
-               writeb(reg_tmp | BM_SOFT_RESET, priv->sdmmc_base +
-                      SDMMC_BUSMODE);
+       reg_tmp = readb(priv->sdmmc_base + SDMMC_BUSMODE);
+       writeb(reg_tmp | BM_SOFT_RESET, priv->sdmmc_base +
+              SDMMC_BUSMODE);
 
-               reg_tmp = readw(priv->sdmmc_base + SDMMC_BLKLEN);
-               writew(reg_tmp & 0x5FFF, priv->sdmmc_base + SDMMC_BLKLEN);
+       reg_tmp = readw(priv->sdmmc_base + SDMMC_BLKLEN);
+       writew(reg_tmp & 0x5FFF, priv->sdmmc_base + SDMMC_BLKLEN);
 
-               writeb(0xFF, priv->sdmmc_base + SDMMC_STS0);
-               writeb(0xFF, priv->sdmmc_base + SDMMC_STS1);
+       writeb(0xFF, priv->sdmmc_base + SDMMC_STS0);
+       writeb(0xFF, priv->sdmmc_base + SDMMC_STS1);
 
-               clk_disable(priv->clk_sdmmc);
-       }
-       return ret;
+       clk_disable(priv->clk_sdmmc);
+       return 0;
 }
 
 static int wmt_mci_resume(struct device *dev)
@@ -969,7 +950,6 @@ static int wmt_mci_resume(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct mmc_host *mmc = platform_get_drvdata(pdev);
        struct wmt_mci_priv *priv;
-       int ret = 0;
 
        if (mmc) {
                priv = mmc_priv(mmc);
@@ -987,10 +967,9 @@ static int wmt_mci_resume(struct device *dev)
                writeb(reg_tmp | INT0_DI_INT_EN, priv->sdmmc_base +
                       SDMMC_INTMASK0);
 
-               ret = mmc_resume_host(mmc);
        }
 
-       return ret;
+       return 0;
 }
 
 static const struct dev_pm_ops wmt_mci_pm = {
index d78a97d4153a98234998080b40c4cb94f50a0876..59f08c44abdbc9be920ea62974d19bcdc7884889 100644 (file)
@@ -375,8 +375,7 @@ static int atmel_nand_dma_op(struct mtd_info *mtd, void *buf, int len,
 
        dma_dev = host->dma_chan->device;
 
-       flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP |
-               DMA_COMPL_SKIP_DEST_UNMAP;
+       flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT;
 
        phys_addr = dma_map_single(dma_dev->dev, p, len, dir);
        if (dma_mapping_error(dma_dev->dev, phys_addr)) {
index bd1cb672034fe770d2db2b986caa1821c1f63f58..1b0265e85a066b2b8903d84645d1df918e4a9ee5 100644 (file)
@@ -491,7 +491,7 @@ static uint8_t docg4_read_byte(struct mtd_info *mtd)
                return status;
        }
 
-       dev_warn(doc->dev, "unexpectd call to read_byte()\n");
+       dev_warn(doc->dev, "unexpected call to read_byte()\n");
 
        return 0;
 }
index 3dc1a7564d8725d62085b16cb7c0544e138858b2..8b2752263db9a5549742bb36c3dcee48999b8b62 100644 (file)
@@ -573,8 +573,6 @@ static int dma_xfer(struct fsmc_nand_data *host, void *buffer, int len,
        dma_dev = chan->device;
        dma_addr = dma_map_single(dma_dev->dev, buffer, len, direction);
 
-       flags |= DMA_COMPL_SKIP_SRC_UNMAP | DMA_COMPL_SKIP_DEST_UNMAP;
-
        if (direction == DMA_TO_DEVICE) {
                dma_src = dma_addr;
                dma_dst = host->data_pa;
index bc8fd362a5aa7624fc01a6c79722f4b57e824aef..0ec2a7e8c8a9588170c97715856e7b5f34cf7c60 100644 (file)
@@ -524,8 +524,9 @@ static ssize_t bonding_store_arp_interval(struct device *d,
                goto out;
        }
        if (bond->params.mode == BOND_MODE_ALB ||
-           bond->params.mode == BOND_MODE_TLB) {
-               pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n",
+           bond->params.mode == BOND_MODE_TLB ||
+           bond->params.mode == BOND_MODE_8023AD) {
+               pr_info("%s: ARP monitoring cannot be used with ALB/TLB/802.3ad. Only MII monitoring is supported on %s.\n",
                        bond->dev->name, bond->dev->name);
                ret = -EINVAL;
                goto out;
@@ -603,15 +604,14 @@ static ssize_t bonding_store_arp_targets(struct device *d,
                return restart_syscall();
 
        targets = bond->params.arp_targets;
-       newtarget = in_aton(buf + 1);
+       if (!in4_pton(buf + 1, -1, (u8 *)&newtarget, -1, NULL) ||
+           IS_IP_TARGET_UNUSABLE_ADDRESS(newtarget)) {
+               pr_err("%s: invalid ARP target %pI4 specified for addition\n",
+                      bond->dev->name, &newtarget);
+               goto out;
+       }
        /* look for adds */
        if (buf[0] == '+') {
-               if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
-                       pr_err("%s: invalid ARP target %pI4 specified for addition\n",
-                              bond->dev->name, &newtarget);
-                       goto out;
-               }
-
                if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */
                        pr_err("%s: ARP target %pI4 is already present\n",
                               bond->dev->name, &newtarget);
@@ -634,12 +634,6 @@ static ssize_t bonding_store_arp_targets(struct device *d,
                targets[ind] = newtarget;
                write_unlock_bh(&bond->lock);
        } else if (buf[0] == '-')       {
-               if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
-                       pr_err("%s: invalid ARP target %pI4 specified for removal\n",
-                              bond->dev->name, &newtarget);
-                       goto out;
-               }
-
                ind = bond_get_targets_ip(targets, newtarget);
                if (ind == -1) {
                        pr_err("%s: unable to remove nonexistent ARP target %pI4.\n",
@@ -701,6 +695,8 @@ static ssize_t bonding_store_downdelay(struct device *d,
        int new_value, ret = count;
        struct bonding *bond = to_bond(d);
 
+       if (!rtnl_trylock())
+               return restart_syscall();
        if (!(bond->params.miimon)) {
                pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
                       bond->dev->name);
@@ -734,6 +730,7 @@ static ssize_t bonding_store_downdelay(struct device *d,
        }
 
 out:
+       rtnl_unlock();
        return ret;
 }
 static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
@@ -756,6 +753,8 @@ static ssize_t bonding_store_updelay(struct device *d,
        int new_value, ret = count;
        struct bonding *bond = to_bond(d);
 
+       if (!rtnl_trylock())
+               return restart_syscall();
        if (!(bond->params.miimon)) {
                pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
                       bond->dev->name);
@@ -789,6 +788,7 @@ static ssize_t bonding_store_updelay(struct device *d,
        }
 
 out:
+       rtnl_unlock();
        return ret;
 }
 static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
index 77a07a12e77fea8e44376e40fd4c0d12caba53af..ca31286aa028158341a5847382b75afb74a6ea2f 100644 (file)
@@ -63,6 +63,9 @@
                (((mode) == BOND_MODE_TLB) ||   \
                 ((mode) == BOND_MODE_ALB))
 
+#define IS_IP_TARGET_UNUSABLE_ADDRESS(a)       \
+       ((htonl(INADDR_BROADCAST) == a) ||      \
+        ipv4_is_zeronet(a))
 /*
  * Less bad way to call ioctl from within the kernel; this needs to be
  * done some other way to get the call out of interrupt context.
index 5aa5e8146496ba807ece60fe5b287d70a79a8ad4..c3c4c266b8465981b658676617fa79202aa4396d 100644 (file)
@@ -1388,6 +1388,9 @@ static int alx_resume(struct device *dev)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct alx_priv *alx = pci_get_drvdata(pdev);
+       struct alx_hw *hw = &alx->hw;
+
+       alx_reset_phy(hw);
 
        if (!netif_running(alx->dev))
                return 0;
index 4e01c57d8c8de349da61e80cb0e4cb0f4aece3fd..a1f66e2c9a8694c9d83471dd63f6659d431840eb 100644 (file)
@@ -1376,7 +1376,6 @@ enum {
        BNX2X_SP_RTNL_RX_MODE,
        BNX2X_SP_RTNL_HYPERVISOR_VLAN,
        BNX2X_SP_RTNL_TX_STOP,
-       BNX2X_SP_RTNL_TX_RESUME,
 };
 
 struct bnx2x_prev_path_list {
index dcafbda3e5be1035034d61c486f4eefceb6887f6..ec96130533cc54630c3f26f6253e58b5a0f5a7cf 100644 (file)
@@ -2959,6 +2959,10 @@ int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode, bool keep_link)
 
        bp->port.pmf = 0;
 
+       /* clear pending work in rtnl task */
+       bp->sp_rtnl_state = 0;
+       smp_mb();
+
        /* Free SKBs, SGEs, TPA pool and driver internals */
        bnx2x_free_skbs(bp);
        if (CNIC_LOADED(bp))
index fcf2761d8828804d3edf7ca8e2ad245576d23685..fdace204b0549aa2599edd67c1c3112e0c4bf9de 100644 (file)
@@ -778,11 +778,6 @@ void bnx2x_dcbx_set_params(struct bnx2x *bp, u32 state)
 
                /* ets may affect cmng configuration: reinit it in hw */
                bnx2x_set_local_cmng(bp);
-
-               set_bit(BNX2X_SP_RTNL_TX_RESUME, &bp->sp_rtnl_state);
-
-               schedule_delayed_work(&bp->sp_rtnl_task, 0);
-
                return;
        case BNX2X_DCBX_STATE_TX_RELEASED:
                DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_TX_RELEASED\n");
index e622cc1f96ffe58336ee8c24f12c54e1679e11b7..814d0eca9b334ea86c862bc617a46f137f04d475 100644 (file)
@@ -577,7 +577,9 @@ void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
        rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
        if (rc) {
                BNX2X_ERR("DMAE returned failure %d\n", rc);
+#ifdef BNX2X_STOP_ON_ERROR
                bnx2x_panic();
+#endif
        }
 }
 
@@ -614,7 +616,9 @@ void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
        rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
        if (rc) {
                BNX2X_ERR("DMAE returned failure %d\n", rc);
+#ifdef BNX2X_STOP_ON_ERROR
                bnx2x_panic();
+#endif
        }
 }
 
@@ -5231,18 +5235,18 @@ static void bnx2x_eq_int(struct bnx2x *bp)
 
                case EVENT_RING_OPCODE_STOP_TRAFFIC:
                        DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
+                       bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
                        if (f_obj->complete_cmd(bp, f_obj,
                                                BNX2X_F_CMD_TX_STOP))
                                break;
-                       bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
                        goto next_spqe;
 
                case EVENT_RING_OPCODE_START_TRAFFIC:
                        DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
+                       bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
                        if (f_obj->complete_cmd(bp, f_obj,
                                                BNX2X_F_CMD_TX_START))
                                break;
-                       bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
                        goto next_spqe;
 
                case EVENT_RING_OPCODE_FUNCTION_UPDATE:
@@ -9352,6 +9356,10 @@ static int bnx2x_process_kill(struct bnx2x *bp, bool global)
        bnx2x_process_kill_chip_reset(bp, global);
        barrier();
 
+       /* clear errors in PGB */
+       if (!CHIP_IS_E1x(bp))
+               REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
+
        /* Recover after reset: */
        /* MCP */
        if (global && bnx2x_reset_mcp_comp(bp, val))
@@ -9706,11 +9714,10 @@ sp_rtnl_not_reset:
                               &bp->sp_rtnl_state))
                bnx2x_pf_set_vfs_vlan(bp);
 
-       if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state))
+       if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
                bnx2x_dcbx_stop_hw_tx(bp);
-
-       if (test_and_clear_bit(BNX2X_SP_RTNL_TX_RESUME, &bp->sp_rtnl_state))
                bnx2x_dcbx_resume_hw_tx(bp);
+       }
 
        /* work which needs rtnl lock not-taken (as it takes the lock itself and
         * can be called from other contexts as well)
index 5ecf267dc4cc8da779112356057cb8253d27e7cb..3efbb35267c853d576cc3a4d3104ec4ba1a18d1d 100644 (file)
 #define PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ            0x9430
 #define PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_WRITE           0x9434
 #define PGLUE_B_REG_INTERNAL_VFID_ENABLE                        0x9438
+/* [W 7] Writing 1 to each bit in this register clears a corresponding error
+ * details register and enables logging new error details. Bit 0 - clears
+ * INCORRECT_RCV_DETAILS; Bit 1 - clears RX_ERR_DETAILS; Bit 2 - clears
+ * TX_ERR_WR_ADD_31_0 TX_ERR_WR_ADD_63_32 TX_ERR_WR_DETAILS
+ * TX_ERR_WR_DETAILS2 TX_ERR_RD_ADD_31_0 TX_ERR_RD_ADD_63_32
+ * TX_ERR_RD_DETAILS TX_ERR_RD_DETAILS2 TX_ERR_WR_DETAILS_ICPL; Bit 3 -
+ * clears VF_LENGTH_VIOLATION_DETAILS. Bit 4 - clears
+ * VF_GRC_SPACE_VIOLATION_DETAILS. Bit 5 - clears RX_TCPL_ERR_DETAILS. Bit 6
+ * - clears TCPL_IN_TWO_RCBS_DETAILS. */
+#define PGLUE_B_REG_LATCHED_ERRORS_CLR                          0x943c
+
 /* [R 9] Interrupt register #0 read */
 #define PGLUE_B_REG_PGLUE_B_INT_STS                             0x9298
 /* [RC 9] Interrupt register #0 read clear */
index 9199adf32d33c1639dfa2354e609ef92b638ef91..efa8a151d78907d4b17d5f5dd07eaed9b1f2c02c 100644 (file)
@@ -152,7 +152,7 @@ static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
        if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
                DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
                *done = PFVF_STATUS_SUCCESS;
-               return 0;
+               return -EINVAL;
        }
 
        /* Write message address */
index 00c5be8c55b8ff7186a670645cb654dc46779399..a9e068423ba0651414cc0c5b23f0eda6937a6c23 100644 (file)
@@ -13618,16 +13618,9 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev,
        if (stmpconf.flags)
                return -EINVAL;
 
-       switch (stmpconf.tx_type) {
-       case HWTSTAMP_TX_ON:
-               tg3_flag_set(tp, TX_TSTAMP_EN);
-               break;
-       case HWTSTAMP_TX_OFF:
-               tg3_flag_clear(tp, TX_TSTAMP_EN);
-               break;
-       default:
+       if (stmpconf.tx_type != HWTSTAMP_TX_ON &&
+           stmpconf.tx_type != HWTSTAMP_TX_OFF)
                return -ERANGE;
-       }
 
        switch (stmpconf.rx_filter) {
        case HWTSTAMP_FILTER_NONE:
@@ -13689,6 +13682,11 @@ static int tg3_hwtstamp_ioctl(struct net_device *dev,
                tw32(TG3_RX_PTP_CTL,
                     tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK);
 
+       if (stmpconf.tx_type == HWTSTAMP_TX_ON)
+               tg3_flag_set(tp, TX_TSTAMP_EN);
+       else
+               tg3_flag_clear(tp, TX_TSTAMP_EN);
+
        return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ?
                -EFAULT : 0;
 }
index 7fb0edfe3d2482514f32f48afef1a5a1c46e9805..dbcd5262c0167c1ae0dacf7dd578b5c3a2a43ce5 100644 (file)
@@ -1758,7 +1758,7 @@ err:
 
 /* Uses sycnhronous mcc */
 int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
-                       u32 num, bool untagged, bool promiscuous)
+                      u32 num, bool promiscuous)
 {
        struct be_mcc_wrb *wrb;
        struct be_cmd_req_vlan_config *req;
@@ -1778,7 +1778,7 @@ int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
 
        req->interface_id = if_id;
        req->promiscuous = promiscuous;
-       req->untagged = untagged;
+       req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0;
        req->num_vlan = num;
        if (!promiscuous) {
                memcpy(req->normal_vlan, vtag_array,
@@ -1847,7 +1847,19 @@ int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
                        memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
        }
 
+       if ((req->if_flags_mask & cpu_to_le32(be_if_cap_flags(adapter))) !=
+            req->if_flags_mask) {
+               dev_warn(&adapter->pdev->dev,
+                        "Cannot set rx filter flags 0x%x\n",
+                        req->if_flags_mask);
+               dev_warn(&adapter->pdev->dev,
+                        "Interface is capable of 0x%x flags only\n",
+                        be_if_cap_flags(adapter));
+       }
+       req->if_flags_mask &= cpu_to_le32(be_if_cap_flags(adapter));
+
        status = be_mcc_notify_wait(adapter);
+
 err:
        spin_unlock_bh(&adapter->mcc_lock);
        return status;
index edf3e8a0ff839c069bc05154f85c1e68e89544f2..0075686276aa7f703a6fa63856065a971b5d8388 100644 (file)
@@ -1984,7 +1984,7 @@ int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
                      char *fw_on_flash);
 int be_cmd_modify_eqd(struct be_adapter *adapter, struct be_set_eqd *, int num);
 int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
-                      u32 num, bool untagged, bool promiscuous);
+                      u32 num, bool promiscuous);
 int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 status);
 int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc);
 int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc);
index eaecaadfa8c56436994c2afbe9a70223467ceec2..abde97471636918a6b7e2381634cdc743678d24c 100644 (file)
@@ -1079,7 +1079,7 @@ static int be_vid_config(struct be_adapter *adapter)
                        vids[num++] = cpu_to_le16(i);
 
        status = be_cmd_vlan_config(adapter, adapter->if_handle,
-                                   vids, num, 1, 0);
+                                   vids, num, 0);
 
        if (status) {
                /* Set to VLAN promisc mode as setting VLAN filter failed */
@@ -2676,6 +2676,11 @@ static int be_close(struct net_device *netdev)
 
        be_rx_qs_destroy(adapter);
 
+       for (i = 1; i < (adapter->uc_macs + 1); i++)
+               be_cmd_pmac_del(adapter, adapter->if_handle,
+                               adapter->pmac_id[i], 0);
+       adapter->uc_macs = 0;
+
        for_all_evt_queues(adapter, eqo, i) {
                if (msix_enabled(adapter))
                        synchronize_irq(be_msix_vec_get(adapter, eqo));
index b2793b91cc553e41e80170ac791d10b83f0e776d..4cbebf3d80eb1492d847f1ad8a9888e2a6c17b97 100644 (file)
@@ -386,7 +386,14 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
         */
        bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, bufaddr,
                        FEC_ENET_TX_FRSIZE, DMA_TO_DEVICE);
-
+       if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) {
+               bdp->cbd_bufaddr = 0;
+               fep->tx_skbuff[index] = NULL;
+               dev_kfree_skb_any(skb);
+               if (net_ratelimit())
+                       netdev_err(ndev, "Tx DMA memory map failed\n");
+               return NETDEV_TX_OK;
+       }
        /* Send it on its way.  Tell FEC it's ready, interrupt when done,
         * it's the last BD of the frame, and to put the CRC on the end.
         */
@@ -861,6 +868,7 @@ fec_enet_rx(struct net_device *ndev, int budget)
        struct  bufdesc_ex *ebdp = NULL;
        bool    vlan_packet_rcvd = false;
        u16     vlan_tag;
+       int     index = 0;
 
 #ifdef CONFIG_M532x
        flush_cache_all();
@@ -916,10 +924,15 @@ fec_enet_rx(struct net_device *ndev, int budget)
                ndev->stats.rx_packets++;
                pkt_len = bdp->cbd_datlen;
                ndev->stats.rx_bytes += pkt_len;
-               data = (__u8*)__va(bdp->cbd_bufaddr);
 
-               dma_unmap_single(&fep->pdev->dev, bdp->cbd_bufaddr,
-                               FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
+               if (fep->bufdesc_ex)
+                       index = (struct bufdesc_ex *)bdp -
+                               (struct bufdesc_ex *)fep->rx_bd_base;
+               else
+                       index = bdp - fep->rx_bd_base;
+               data = fep->rx_skbuff[index]->data;
+               dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr,
+                                       FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
 
                if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME)
                        swap_buffer(data, pkt_len);
@@ -999,8 +1012,8 @@ fec_enet_rx(struct net_device *ndev, int budget)
                        napi_gro_receive(&fep->napi, skb);
                }
 
-               bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
-                               FEC_ENET_TX_FRSIZE, DMA_FROM_DEVICE);
+               dma_sync_single_for_device(&fep->pdev->dev, bdp->cbd_bufaddr,
+                                       FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
 rx_processing_done:
                /* Clear the status flags for this buffer */
                status &= ~BD_ENET_RX_STATS;
@@ -1719,6 +1732,12 @@ static int fec_enet_alloc_buffers(struct net_device *ndev)
 
                bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, skb->data,
                                FEC_ENET_RX_FRSIZE, DMA_FROM_DEVICE);
+               if (dma_mapping_error(&fep->pdev->dev, bdp->cbd_bufaddr)) {
+                       fec_enet_free_buffers(ndev);
+                       if (net_ratelimit())
+                               netdev_err(ndev, "Rx DMA memory map failed\n");
+                       return -ENOMEM;
+               }
                bdp->cbd_sc = BD_ENET_RX_EMPTY;
 
                if (fep->bufdesc_ex) {
index aedd5736a87d53862fa2be4176e9762fcd8df18a..8d3945ab7334840684db42ea6eefa9bafc52c061 100644 (file)
@@ -3482,10 +3482,10 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
  * specified. Matching the kind of event packet is not supported, with the
  * exception of "all V2 events regardless of level 2 or 4".
  **/
-static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
+static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
+                                 struct hwtstamp_config *config)
 {
        struct e1000_hw *hw = &adapter->hw;
-       struct hwtstamp_config *config = &adapter->hwtstamp_config;
        u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
        u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
        u32 rxmtrl = 0;
@@ -3586,6 +3586,8 @@ static int e1000e_config_hwtstamp(struct e1000_adapter *adapter)
                return -ERANGE;
        }
 
+       adapter->hwtstamp_config = *config;
+
        /* enable/disable Tx h/w time stamping */
        regval = er32(TSYNCTXCTL);
        regval &= ~E1000_TSYNCTXCTL_ENABLED;
@@ -3874,7 +3876,7 @@ void e1000e_reset(struct e1000_adapter *adapter)
        e1000e_reset_adaptive(hw);
 
        /* initialize systim and reset the ns time counter */
-       e1000e_config_hwtstamp(adapter);
+       e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
 
        /* Set EEE advertisement as appropriate */
        if (adapter->flags2 & FLAG2_HAS_EEE) {
@@ -5797,14 +5799,10 @@ static int e1000e_hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
        if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
                return -EFAULT;
 
-       adapter->hwtstamp_config = config;
-
-       ret_val = e1000e_config_hwtstamp(adapter);
+       ret_val = e1000e_config_hwtstamp(adapter, &config);
        if (ret_val)
                return ret_val;
 
-       config = adapter->hwtstamp_config;
-
        switch (config.rx_filter) {
        case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
        case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
index 00cd36e0860105aaa577d089e8a169e7d7b1fd97..61088a6a94245144f46fa42e92fdce9eb07f1599 100644 (file)
@@ -2890,7 +2890,8 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
                                         PHY_INTERFACE_MODE_GMII);
                if (!mp->phy)
                        err = -ENODEV;
-               phy_addr_set(mp, mp->phy->addr);
+               else
+                       phy_addr_set(mp, mp->phy->addr);
        } else if (pd->phy_addr != MV643XX_ETH_PHY_NONE) {
                mp->phy = phy_scan(mp, pd->phy_addr);
 
index fda26679f7d5c8cac8780c55a470357a2f16ec01..194928214606e160932fcb335f604421431b6eb2 100644 (file)
@@ -1774,7 +1774,7 @@ void mlx4_opreq_action(struct work_struct *work)
                                   MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A,
                                   MLX4_CMD_NATIVE);
                if (err) {
-                       mlx4_err(dev, "Failed to retreive required operation: %d\n",
+                       mlx4_err(dev, "Failed to retrieve required operation: %d\n",
                                 err);
                        return;
                }
index 6ca30739625f7ac568d693b5d4b9d3d9e47b46de..8675d26a678ba39cce44359453681f65e654022c 100644 (file)
@@ -98,6 +98,7 @@ enum {
 static struct mlx5_cmd_work_ent *alloc_cmd(struct mlx5_cmd *cmd,
                                           struct mlx5_cmd_msg *in,
                                           struct mlx5_cmd_msg *out,
+                                          void *uout, int uout_size,
                                           mlx5_cmd_cbk_t cbk,
                                           void *context, int page_queue)
 {
@@ -110,6 +111,8 @@ static struct mlx5_cmd_work_ent *alloc_cmd(struct mlx5_cmd *cmd,
 
        ent->in         = in;
        ent->out        = out;
+       ent->uout       = uout;
+       ent->uout_size  = uout_size;
        ent->callback   = cbk;
        ent->context    = context;
        ent->cmd        = cmd;
@@ -534,6 +537,7 @@ static void cmd_work_handler(struct work_struct *work)
        ent->lay = lay;
        memset(lay, 0, sizeof(*lay));
        memcpy(lay->in, ent->in->first.data, sizeof(lay->in));
+       ent->op = be32_to_cpu(lay->in[0]) >> 16;
        if (ent->in->next)
                lay->in_ptr = cpu_to_be64(ent->in->next->dma);
        lay->inlen = cpu_to_be32(ent->in->len);
@@ -628,7 +632,8 @@ static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent)
  *    2. page queue commands do not support asynchrous completion
  */
 static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
-                          struct mlx5_cmd_msg *out, mlx5_cmd_cbk_t callback,
+                          struct mlx5_cmd_msg *out, void *uout, int uout_size,
+                          mlx5_cmd_cbk_t callback,
                           void *context, int page_queue, u8 *status)
 {
        struct mlx5_cmd *cmd = &dev->cmd;
@@ -642,7 +647,8 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
        if (callback && page_queue)
                return -EINVAL;
 
-       ent = alloc_cmd(cmd, in, out, callback, context, page_queue);
+       ent = alloc_cmd(cmd, in, out, uout, uout_size, callback, context,
+                       page_queue);
        if (IS_ERR(ent))
                return PTR_ERR(ent);
 
@@ -670,10 +676,10 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
                op = be16_to_cpu(((struct mlx5_inbox_hdr *)in->first.data)->opcode);
                if (op < ARRAY_SIZE(cmd->stats)) {
                        stats = &cmd->stats[op];
-                       spin_lock(&stats->lock);
+                       spin_lock_irq(&stats->lock);
                        stats->sum += ds;
                        ++stats->n;
-                       spin_unlock(&stats->lock);
+                       spin_unlock_irq(&stats->lock);
                }
                mlx5_core_dbg_mask(dev, 1 << MLX5_CMD_TIME,
                                   "fw exec time for %s is %lld nsec\n",
@@ -826,7 +832,7 @@ static struct mlx5_cmd_msg *mlx5_alloc_cmd_msg(struct mlx5_core_dev *dev,
        int n;
        int i;
 
-       msg = kzalloc(sizeof(*msg), GFP_KERNEL);
+       msg = kzalloc(sizeof(*msg), flags);
        if (!msg)
                return ERR_PTR(-ENOMEM);
 
@@ -1109,6 +1115,19 @@ void mlx5_cmd_use_polling(struct mlx5_core_dev *dev)
                up(&cmd->sem);
 }
 
+static void free_msg(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *msg)
+{
+       unsigned long flags;
+
+       if (msg->cache) {
+               spin_lock_irqsave(&msg->cache->lock, flags);
+               list_add_tail(&msg->list, &msg->cache->head);
+               spin_unlock_irqrestore(&msg->cache->lock, flags);
+       } else {
+               mlx5_free_cmd_msg(dev, msg);
+       }
+}
+
 void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
 {
        struct mlx5_cmd *cmd = &dev->cmd;
@@ -1117,6 +1136,10 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
        void *context;
        int err;
        int i;
+       ktime_t t1, t2, delta;
+       s64 ds;
+       struct mlx5_cmd_stats *stats;
+       unsigned long flags;
 
        for (i = 0; i < (1 << cmd->log_sz); i++) {
                if (test_bit(i, &vector)) {
@@ -1141,9 +1164,29 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector)
                        }
                        free_ent(cmd, ent->idx);
                        if (ent->callback) {
+                               t1 = timespec_to_ktime(ent->ts1);
+                               t2 = timespec_to_ktime(ent->ts2);
+                               delta = ktime_sub(t2, t1);
+                               ds = ktime_to_ns(delta);
+                               if (ent->op < ARRAY_SIZE(cmd->stats)) {
+                                       stats = &cmd->stats[ent->op];
+                                       spin_lock_irqsave(&stats->lock, flags);
+                                       stats->sum += ds;
+                                       ++stats->n;
+                                       spin_unlock_irqrestore(&stats->lock, flags);
+                               }
+
                                callback = ent->callback;
                                context = ent->context;
                                err = ent->ret;
+                               if (!err)
+                                       err = mlx5_copy_from_msg(ent->uout,
+                                                                ent->out,
+                                                                ent->uout_size);
+
+                               mlx5_free_cmd_msg(dev, ent->out);
+                               free_msg(dev, ent->in);
+
                                free_cmd(ent);
                                callback(err, context);
                        } else {
@@ -1160,7 +1203,8 @@ static int status_to_err(u8 status)
        return status ? -1 : 0; /* TBD more meaningful codes */
 }
 
-static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size)
+static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size,
+                                     gfp_t gfp)
 {
        struct mlx5_cmd_msg *msg = ERR_PTR(-ENOMEM);
        struct mlx5_cmd *cmd = &dev->cmd;
@@ -1172,7 +1216,7 @@ static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size)
                ent = &cmd->cache.med;
 
        if (ent) {
-               spin_lock(&ent->lock);
+               spin_lock_irq(&ent->lock);
                if (!list_empty(&ent->head)) {
                        msg = list_entry(ent->head.next, typeof(*msg), list);
                        /* For cached lists, we must explicitly state what is
@@ -1181,43 +1225,34 @@ static struct mlx5_cmd_msg *alloc_msg(struct mlx5_core_dev *dev, int in_size)
                        msg->len = in_size;
                        list_del(&msg->list);
                }
-               spin_unlock(&ent->lock);
+               spin_unlock_irq(&ent->lock);
        }
 
        if (IS_ERR(msg))
-               msg = mlx5_alloc_cmd_msg(dev, GFP_KERNEL, in_size);
+               msg = mlx5_alloc_cmd_msg(dev, gfp, in_size);
 
        return msg;
 }
 
-static void free_msg(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *msg)
-{
-       if (msg->cache) {
-               spin_lock(&msg->cache->lock);
-               list_add_tail(&msg->list, &msg->cache->head);
-               spin_unlock(&msg->cache->lock);
-       } else {
-               mlx5_free_cmd_msg(dev, msg);
-       }
-}
-
 static int is_manage_pages(struct mlx5_inbox_hdr *in)
 {
        return be16_to_cpu(in->opcode) == MLX5_CMD_OP_MANAGE_PAGES;
 }
 
-int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
-                 int out_size)
+static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
+                   int out_size, mlx5_cmd_cbk_t callback, void *context)
 {
        struct mlx5_cmd_msg *inb;
        struct mlx5_cmd_msg *outb;
        int pages_queue;
+       gfp_t gfp;
        int err;
        u8 status = 0;
 
        pages_queue = is_manage_pages(in);
+       gfp = callback ? GFP_ATOMIC : GFP_KERNEL;
 
-       inb = alloc_msg(dev, in_size);
+       inb = alloc_msg(dev, in_size, gfp);
        if (IS_ERR(inb)) {
                err = PTR_ERR(inb);
                return err;
@@ -1229,13 +1264,14 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
                goto out_in;
        }
 
-       outb = mlx5_alloc_cmd_msg(dev, GFP_KERNEL, out_size);
+       outb = mlx5_alloc_cmd_msg(dev, gfp, out_size);
        if (IS_ERR(outb)) {
                err = PTR_ERR(outb);
                goto out_in;
        }
 
-       err = mlx5_cmd_invoke(dev, inb, outb, NULL, NULL, pages_queue, &status);
+       err = mlx5_cmd_invoke(dev, inb, outb, out, out_size, callback, context,
+                             pages_queue, &status);
        if (err)
                goto out_out;
 
@@ -1248,14 +1284,30 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
        err = mlx5_copy_from_msg(out, outb, out_size);
 
 out_out:
-       mlx5_free_cmd_msg(dev, outb);
+       if (!callback)
+               mlx5_free_cmd_msg(dev, outb);
 
 out_in:
-       free_msg(dev, inb);
+       if (!callback)
+               free_msg(dev, inb);
        return err;
 }
+
+int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
+                 int out_size)
+{
+       return cmd_exec(dev, in, in_size, out, out_size, NULL, NULL);
+}
 EXPORT_SYMBOL(mlx5_cmd_exec);
 
+int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
+                    void *out, int out_size, mlx5_cmd_cbk_t callback,
+                    void *context)
+{
+       return cmd_exec(dev, in, in_size, out, out_size, callback, context);
+}
+EXPORT_SYMBOL(mlx5_cmd_exec_cb);
+
 static void destroy_msg_cache(struct mlx5_core_dev *dev)
 {
        struct mlx5_cmd *cmd = &dev->cmd;
index 9c7194b26ee2dbf3aa3dd1b1f19b3de290d13f57..80f6d127257adbbcd590eadbdcafeab95c42f38f 100644 (file)
@@ -154,10 +154,10 @@ static ssize_t average_read(struct file *filp, char __user *buf, size_t count,
                return 0;
 
        stats = filp->private_data;
-       spin_lock(&stats->lock);
+       spin_lock_irq(&stats->lock);
        if (stats->n)
                field = div64_u64(stats->sum, stats->n);
-       spin_unlock(&stats->lock);
+       spin_unlock_irq(&stats->lock);
        ret = snprintf(tbuf, sizeof(tbuf), "%llu\n", field);
        if (ret > 0) {
                if (copy_to_user(buf, tbuf, ret))
@@ -175,10 +175,10 @@ static ssize_t average_write(struct file *filp, const char __user *buf,
        struct mlx5_cmd_stats *stats;
 
        stats = filp->private_data;
-       spin_lock(&stats->lock);
+       spin_lock_irq(&stats->lock);
        stats->sum = 0;
        stats->n = 0;
-       spin_unlock(&stats->lock);
+       spin_unlock_irq(&stats->lock);
 
        *pos += count;
 
index 2231d93cc7ad116e55c77e0269fa27878f6c6a4d..64a61b286b2c959fbb67c72dcc098199d74ff68d 100644 (file)
@@ -354,7 +354,7 @@ int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
        in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_CREATE_EQ);
        in->ctx.log_sz_usr_page = cpu_to_be32(ilog2(eq->nent) << 24 | uar->index);
        in->ctx.intr = vecidx;
-       in->ctx.log_page_size = PAGE_SHIFT - 12;
+       in->ctx.log_page_size = eq->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT;
        in->events_mask = cpu_to_be64(mask);
 
        err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out));
index bc0f5fb66e249dc2e652b4126f9b907707b87c6c..40a9f5ed814dd16defab7915d4368266cd5fa1e4 100644 (file)
@@ -159,6 +159,36 @@ struct mlx5_reg_host_endianess {
        u8      rsvd[15];
 };
 
+
+#define CAP_MASK(pos, size) ((u64)((1 << (size)) - 1) << (pos))
+
+enum {
+       MLX5_CAP_BITS_RW_MASK   = CAP_MASK(MLX5_CAP_OFF_CMDIF_CSUM, 2) |
+                                 CAP_MASK(MLX5_CAP_OFF_DCT, 1),
+};
+
+/* selectively copy writable fields clearing any reserved area
+ */
+static void copy_rw_fields(struct mlx5_hca_cap *to, struct mlx5_hca_cap *from)
+{
+       u64 v64;
+
+       to->log_max_qp = from->log_max_qp & 0x1f;
+       to->log_max_ra_req_dc = from->log_max_ra_req_dc & 0x3f;
+       to->log_max_ra_res_dc = from->log_max_ra_res_dc & 0x3f;
+       to->log_max_ra_req_qp = from->log_max_ra_req_qp & 0x3f;
+       to->log_max_ra_res_qp = from->log_max_ra_res_qp & 0x3f;
+       to->log_max_atomic_size_qp = from->log_max_atomic_size_qp;
+       to->log_max_atomic_size_dc = from->log_max_atomic_size_dc;
+       v64 = be64_to_cpu(from->flags) & MLX5_CAP_BITS_RW_MASK;
+       to->flags = cpu_to_be64(v64);
+}
+
+enum {
+       HCA_CAP_OPMOD_GET_MAX   = 0,
+       HCA_CAP_OPMOD_GET_CUR   = 1,
+};
+
 static int handle_hca_cap(struct mlx5_core_dev *dev)
 {
        struct mlx5_cmd_query_hca_cap_mbox_out *query_out = NULL;
@@ -180,7 +210,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
        }
 
        query_ctx.hdr.opcode = cpu_to_be16(MLX5_CMD_OP_QUERY_HCA_CAP);
-       query_ctx.hdr.opmod  = cpu_to_be16(0x1);
+       query_ctx.hdr.opmod  = cpu_to_be16(HCA_CAP_OPMOD_GET_CUR);
        err = mlx5_cmd_exec(dev, &query_ctx, sizeof(query_ctx),
                                 query_out, sizeof(*query_out));
        if (err)
@@ -192,8 +222,7 @@ static int handle_hca_cap(struct mlx5_core_dev *dev)
                goto query_ex;
        }
 
-       memcpy(&set_ctx->hca_cap, &query_out->hca_cap,
-              sizeof(set_ctx->hca_cap));
+       copy_rw_fields(&set_ctx->hca_cap, &query_out->hca_cap);
 
        if (dev->profile->mask & MLX5_PROF_MASK_QP_SIZE)
                set_ctx->hca_cap.log_max_qp = dev->profile->log_max_qp;
index 5b44e2e46dafbec0855fe682a1e06c6e91ad7def..35e514dc7b7d7148cbed9198b0d3348e6db88a62 100644 (file)
 #include "mlx5_core.h"
 
 int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
-                         struct mlx5_create_mkey_mbox_in *in, int inlen)
+                         struct mlx5_create_mkey_mbox_in *in, int inlen,
+                         mlx5_cmd_cbk_t callback, void *context,
+                         struct mlx5_create_mkey_mbox_out *out)
 {
-       struct mlx5_create_mkey_mbox_out out;
+       struct mlx5_create_mkey_mbox_out lout;
        int err;
        u8 key;
 
-       memset(&out, 0, sizeof(out));
-       spin_lock(&dev->priv.mkey_lock);
+       memset(&lout, 0, sizeof(lout));
+       spin_lock_irq(&dev->priv.mkey_lock);
        key = dev->priv.mkey_key++;
-       spin_unlock(&dev->priv.mkey_lock);
+       spin_unlock_irq(&dev->priv.mkey_lock);
        in->seg.qpn_mkey7_0 |= cpu_to_be32(key);
        in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_CREATE_MKEY);
-       err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out));
+       if (callback) {
+               err = mlx5_cmd_exec_cb(dev, in, inlen, out, sizeof(*out),
+                                      callback, context);
+               return err;
+       } else {
+               err = mlx5_cmd_exec(dev, in, inlen, &lout, sizeof(lout));
+       }
+
        if (err) {
                mlx5_core_dbg(dev, "cmd exec faile %d\n", err);
                return err;
        }
 
-       if (out.hdr.status) {
-               mlx5_core_dbg(dev, "status %d\n", out.hdr.status);
-               return mlx5_cmd_status_to_err(&out.hdr);
+       if (lout.hdr.status) {
+               mlx5_core_dbg(dev, "status %d\n", lout.hdr.status);
+               return mlx5_cmd_status_to_err(&lout.hdr);
        }
 
-       mr->key = mlx5_idx_to_mkey(be32_to_cpu(out.mkey) & 0xffffff) | key;
-       mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n", be32_to_cpu(out.mkey), key, mr->key);
+       mr->key = mlx5_idx_to_mkey(be32_to_cpu(lout.mkey) & 0xffffff) | key;
+       mlx5_core_dbg(dev, "out 0x%x, key 0x%x, mkey 0x%x\n",
+                     be32_to_cpu(lout.mkey), key, mr->key);
 
        return err;
 }
index 7b12acf210f81cd408a4b0e8a965fd4441165c9f..37b6ad1f9a1bf6697fb813d5e5c1ebd0bea48d15 100644 (file)
@@ -57,10 +57,13 @@ struct mlx5_pages_req {
 };
 
 struct fw_page {
-       struct rb_node  rb_node;
-       u64             addr;
-       struct page     *page;
-       u16             func_id;
+       struct rb_node          rb_node;
+       u64                     addr;
+       struct page            *page;
+       u16                     func_id;
+       unsigned long           bitmask;
+       struct list_head        list;
+       unsigned                free_count;
 };
 
 struct mlx5_query_pages_inbox {
@@ -94,6 +97,11 @@ enum {
        MAX_RECLAIM_TIME_MSECS  = 5000,
 };
 
+enum {
+       MLX5_MAX_RECLAIM_TIME_MILI      = 5000,
+       MLX5_NUM_4K_IN_PAGE             = PAGE_SIZE / 4096,
+};
+
 static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u16 func_id)
 {
        struct rb_root *root = &dev->priv.page_root;
@@ -101,6 +109,7 @@ static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u
        struct rb_node *parent = NULL;
        struct fw_page *nfp;
        struct fw_page *tfp;
+       int i;
 
        while (*new) {
                parent = *new;
@@ -113,25 +122,29 @@ static int insert_page(struct mlx5_core_dev *dev, u64 addr, struct page *page, u
                        return -EEXIST;
        }
 
-       nfp = kmalloc(sizeof(*nfp), GFP_KERNEL);
+       nfp = kzalloc(sizeof(*nfp), GFP_KERNEL);
        if (!nfp)
                return -ENOMEM;
 
        nfp->addr = addr;
        nfp->page = page;
        nfp->func_id = func_id;
+       nfp->free_count = MLX5_NUM_4K_IN_PAGE;
+       for (i = 0; i < MLX5_NUM_4K_IN_PAGE; i++)
+               set_bit(i, &nfp->bitmask);
 
        rb_link_node(&nfp->rb_node, parent, new);
        rb_insert_color(&nfp->rb_node, root);
+       list_add(&nfp->list, &dev->priv.free_list);
 
        return 0;
 }
 
-static struct page *remove_page(struct mlx5_core_dev *dev, u64 addr)
+static struct fw_page *find_fw_page(struct mlx5_core_dev *dev, u64 addr)
 {
        struct rb_root *root = &dev->priv.page_root;
        struct rb_node *tmp = root->rb_node;
-       struct page *result = NULL;
+       struct fw_page *result = NULL;
        struct fw_page *tfp;
 
        while (tmp) {
@@ -141,9 +154,7 @@ static struct page *remove_page(struct mlx5_core_dev *dev, u64 addr)
                } else if (tfp->addr > addr) {
                        tmp = tmp->rb_right;
                } else {
-                       rb_erase(&tfp->rb_node, root);
-                       result = tfp->page;
-                       kfree(tfp);
+                       result = tfp;
                        break;
                }
        }
@@ -176,12 +187,98 @@ static int mlx5_cmd_query_pages(struct mlx5_core_dev *dev, u16 *func_id,
        return err;
 }
 
+static int alloc_4k(struct mlx5_core_dev *dev, u64 *addr)
+{
+       struct fw_page *fp;
+       unsigned n;
+
+       if (list_empty(&dev->priv.free_list)) {
+               return -ENOMEM;
+               mlx5_core_warn(dev, "\n");
+       }
+
+       fp = list_entry(dev->priv.free_list.next, struct fw_page, list);
+       n = find_first_bit(&fp->bitmask, 8 * sizeof(fp->bitmask));
+       if (n >= MLX5_NUM_4K_IN_PAGE) {
+               mlx5_core_warn(dev, "alloc 4k bug\n");
+               return -ENOENT;
+       }
+       clear_bit(n, &fp->bitmask);
+       fp->free_count--;
+       if (!fp->free_count)
+               list_del(&fp->list);
+
+       *addr = fp->addr + n * 4096;
+
+       return 0;
+}
+
+static void free_4k(struct mlx5_core_dev *dev, u64 addr)
+{
+       struct fw_page *fwp;
+       int n;
+
+       fwp = find_fw_page(dev, addr & PAGE_MASK);
+       if (!fwp) {
+               mlx5_core_warn(dev, "page not found\n");
+               return;
+       }
+
+       n = (addr & ~PAGE_MASK) % 4096;
+       fwp->free_count++;
+       set_bit(n, &fwp->bitmask);
+       if (fwp->free_count == MLX5_NUM_4K_IN_PAGE) {
+               rb_erase(&fwp->rb_node, &dev->priv.page_root);
+               if (fwp->free_count != 1)
+                       list_del(&fwp->list);
+               dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
+               __free_page(fwp->page);
+               kfree(fwp);
+       } else if (fwp->free_count == 1) {
+               list_add(&fwp->list, &dev->priv.free_list);
+       }
+}
+
+static int alloc_system_page(struct mlx5_core_dev *dev, u16 func_id)
+{
+       struct page *page;
+       u64 addr;
+       int err;
+
+       page = alloc_page(GFP_HIGHUSER);
+       if (!page) {
+               mlx5_core_warn(dev, "failed to allocate page\n");
+               return -ENOMEM;
+       }
+       addr = dma_map_page(&dev->pdev->dev, page, 0,
+                           PAGE_SIZE, DMA_BIDIRECTIONAL);
+       if (dma_mapping_error(&dev->pdev->dev, addr)) {
+               mlx5_core_warn(dev, "failed dma mapping page\n");
+               err = -ENOMEM;
+               goto out_alloc;
+       }
+       err = insert_page(dev, addr, page, func_id);
+       if (err) {
+               mlx5_core_err(dev, "failed to track allocated page\n");
+               goto out_mapping;
+       }
+
+       return 0;
+
+out_mapping:
+       dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
+
+out_alloc:
+       __free_page(page);
+
+       return err;
+}
 static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
                      int notify_fail)
 {
        struct mlx5_manage_pages_inbox *in;
        struct mlx5_manage_pages_outbox out;
-       struct page *page;
+       struct mlx5_manage_pages_inbox *nin;
        int inlen;
        u64 addr;
        int err;
@@ -196,27 +293,15 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
        memset(&out, 0, sizeof(out));
 
        for (i = 0; i < npages; i++) {
-               page = alloc_page(GFP_HIGHUSER);
-               if (!page) {
-                       err = -ENOMEM;
-                       mlx5_core_warn(dev, "failed to allocate page\n");
-                       goto out_alloc;
-               }
-               addr = dma_map_page(&dev->pdev->dev, page, 0,
-                                   PAGE_SIZE, DMA_BIDIRECTIONAL);
-               if (dma_mapping_error(&dev->pdev->dev, addr)) {
-                       mlx5_core_warn(dev, "failed dma mapping page\n");
-                       __free_page(page);
-                       err = -ENOMEM;
-                       goto out_alloc;
-               }
-               err = insert_page(dev, addr, page, func_id);
+retry:
+               err = alloc_4k(dev, &addr);
                if (err) {
-                       mlx5_core_err(dev, "failed to track allocated page\n");
-                       dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
-                       __free_page(page);
-                       err = -ENOMEM;
-                       goto out_alloc;
+                       if (err == -ENOMEM)
+                               err = alloc_system_page(dev, func_id);
+                       if (err)
+                               goto out_4k;
+
+                       goto retry;
                }
                in->pas[i] = cpu_to_be64(addr);
        }
@@ -226,7 +311,6 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
        in->func_id = cpu_to_be16(func_id);
        in->num_entries = cpu_to_be32(npages);
        err = mlx5_cmd_exec(dev, in, inlen, &out, sizeof(out));
-       mlx5_core_dbg(dev, "err %d\n", err);
        if (err) {
                mlx5_core_warn(dev, "func_id 0x%x, npages %d, err %d\n", func_id, npages, err);
                goto out_alloc;
@@ -247,25 +331,22 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
 
 out_alloc:
        if (notify_fail) {
-               memset(in, 0, inlen);
-               memset(&out, 0, sizeof(out));
-               in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_MANAGE_PAGES);
-               in->hdr.opmod = cpu_to_be16(MLX5_PAGES_CANT_GIVE);
-               if (mlx5_cmd_exec(dev, in, sizeof(*in), &out, sizeof(out)))
-                       mlx5_core_warn(dev, "\n");
-       }
-       for (i--; i >= 0; i--) {
-               addr = be64_to_cpu(in->pas[i]);
-               page = remove_page(dev, addr);
-               if (!page) {
-                       mlx5_core_err(dev, "BUG: can't remove page at addr 0x%llx\n",
-                                     addr);
-                       continue;
+               nin = kzalloc(sizeof(*nin), GFP_KERNEL);
+               if (!nin) {
+                       mlx5_core_warn(dev, "allocation failed\n");
+                       goto out_4k;
                }
-               dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
-               __free_page(page);
+               memset(&out, 0, sizeof(out));
+               nin->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_MANAGE_PAGES);
+               nin->hdr.opmod = cpu_to_be16(MLX5_PAGES_CANT_GIVE);
+               if (mlx5_cmd_exec(dev, nin, sizeof(*nin), &out, sizeof(out)))
+                       mlx5_core_warn(dev, "page notify failed\n");
+               kfree(nin);
        }
 
+out_4k:
+       for (i--; i >= 0; i--)
+               free_4k(dev, be64_to_cpu(in->pas[i]));
 out_free:
        mlx5_vfree(in);
        return err;
@@ -276,7 +357,6 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u32 func_id, int npages,
 {
        struct mlx5_manage_pages_inbox   in;
        struct mlx5_manage_pages_outbox *out;
-       struct page *page;
        int num_claimed;
        int outlen;
        u64 addr;
@@ -315,13 +395,7 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u32 func_id, int npages,
 
        for (i = 0; i < num_claimed; i++) {
                addr = be64_to_cpu(out->pas[i]);
-               page = remove_page(dev, addr);
-               if (!page) {
-                       mlx5_core_warn(dev, "FW reported unknown DMA address 0x%llx\n", addr);
-               } else {
-                       dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
-                       __free_page(page);
-               }
+               free_4k(dev, addr);
        }
 
 out_free:
@@ -381,14 +455,19 @@ int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot)
        return give_pages(dev, func_id, npages, 0);
 }
 
+enum {
+       MLX5_BLKS_FOR_RECLAIM_PAGES = 12
+};
+
 static int optimal_reclaimed_pages(void)
 {
        struct mlx5_cmd_prot_block *block;
        struct mlx5_cmd_layout *lay;
        int ret;
 
-       ret = (sizeof(lay->in) + sizeof(block->data) -
-              sizeof(struct mlx5_manage_pages_outbox)) / 8;
+       ret = (sizeof(lay->out) + MLX5_BLKS_FOR_RECLAIM_PAGES * sizeof(block->data) -
+              sizeof(struct mlx5_manage_pages_outbox)) /
+              FIELD_SIZEOF(struct mlx5_manage_pages_outbox, pas[0]);
 
        return ret;
 }
@@ -427,6 +506,7 @@ int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev)
 void mlx5_pagealloc_init(struct mlx5_core_dev *dev)
 {
        dev->priv.page_root = RB_ROOT;
+       INIT_LIST_HEAD(&dev->priv.free_list);
 }
 
 void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev)
index 0951f7aca1eff6671f187d03b203952926a1ecea..822616e3c3754118ab2e09eada44d59a24c3954c 100644 (file)
@@ -459,8 +459,7 @@ static int ks8842_tx_frame_dma(struct sk_buff *skb, struct net_device *netdev)
                sg_dma_len(&ctl->sg) += 4 - sg_dma_len(&ctl->sg) % 4;
 
        ctl->adesc = dmaengine_prep_slave_sg(ctl->chan,
-               &ctl->sg, 1, DMA_MEM_TO_DEV,
-               DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP);
+               &ctl->sg, 1, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
        if (!ctl->adesc)
                return NETDEV_TX_BUSY;
 
@@ -571,8 +570,7 @@ static int __ks8842_start_new_rx_dma(struct net_device *netdev)
                sg_dma_len(sg) = DMA_BUFFER_SIZE;
 
                ctl->adesc = dmaengine_prep_slave_sg(ctl->chan,
-                       sg, 1, DMA_DEV_TO_MEM,
-                       DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP);
+                       sg, 1, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
 
                if (!ctl->adesc)
                        goto out;
index 5a0f04c2c813661991047174c7a2643e74d694bd..27ffe0ebf0a686793c30f25f033895bf70ddfe51 100644 (file)
@@ -245,16 +245,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
        /* Get ieee1588's dev information */
        pdev = adapter->ptp_pdev;
 
-       switch (cfg.tx_type) {
-       case HWTSTAMP_TX_OFF:
-               adapter->hwts_tx_en = 0;
-               break;
-       case HWTSTAMP_TX_ON:
-               adapter->hwts_tx_en = 1;
-               break;
-       default:
+       if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
                return -ERANGE;
-       }
 
        switch (cfg.rx_filter) {
        case HWTSTAMP_FILTER_NONE:
@@ -284,6 +276,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
                return -ERANGE;
        }
 
+       adapter->hwts_tx_en = cfg.tx_type == HWTSTAMP_TX_ON;
+
        /* Clear out any old time stamps. */
        pch_ch_event_write(pdev, TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED);
 
index a01a6a74ee3ab9fb07a2ec0ae64bdcdd96def117..b1cb0ffb15c70d1970f3cbebab28ff7f8e8530ce 100644 (file)
@@ -1730,7 +1730,7 @@ static void qlcnic_extend_lb_idc_cmpltn_wait(struct qlcnic_adapter *adapter,
        struct qlcnic_hardware_context *ahw = adapter->ahw;
        int temp;
 
-       netdev_info(adapter->netdev, "Recieved loopback IDC time extend event for 0x%x seconds\n",
+       netdev_info(adapter->netdev, "Received loopback IDC time extend event for 0x%x seconds\n",
                    ahw->extend_lb_time);
        temp = ahw->extend_lb_time * 1000;
        *max_wait_count += temp / QLC_83XX_LB_MSLEEP_COUNT;
index 8d4ccd35a01692d911f50d91bfe9bee0d89d883f..8a7a23a84ac5c3b6a7b7d4979e8c5866097895a5 100644 (file)
@@ -435,16 +435,9 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
        if (config.flags)
                return -EINVAL;
 
-       switch (config.tx_type) {
-       case HWTSTAMP_TX_OFF:
-               priv->hwts_tx_en = 0;
-               break;
-       case HWTSTAMP_TX_ON:
-               priv->hwts_tx_en = 1;
-               break;
-       default:
+       if (config.tx_type != HWTSTAMP_TX_OFF &&
+           config.tx_type != HWTSTAMP_TX_ON)
                return -ERANGE;
-       }
 
        if (priv->adv_ts) {
                switch (config.rx_filter) {
@@ -576,6 +569,7 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
                }
        }
        priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
+       priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
 
        if (!priv->hwts_tx_en && !priv->hwts_rx_en)
                priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0);
index 90d41d26ec6d8c37f04682aa05b8731a4d4c3002..7536a4c01293a9b3e97bf1171941b6724213ad6c 100644 (file)
@@ -967,14 +967,19 @@ static inline void cpsw_add_dual_emac_def_ale_entries(
                priv->host_port, ALE_VLAN, slave->port_vlan);
 }
 
-static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
+static void soft_reset_slave(struct cpsw_slave *slave)
 {
        char name[32];
-       u32 slave_port;
-
-       sprintf(name, "slave-%d", slave->slave_num);
 
+       snprintf(name, sizeof(name), "slave-%d", slave->slave_num);
        soft_reset(name, &slave->sliver->soft_reset);
+}
+
+static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
+{
+       u32 slave_port;
+
+       soft_reset_slave(slave);
 
        /* setup priority mapping */
        __raw_writel(RX_PRIORITY_MAPPING, &slave->sliver->rx_pri_map);
@@ -1323,6 +1328,10 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
        struct cpts *cpts = priv->cpts;
        struct hwtstamp_config cfg;
 
+       if (priv->version != CPSW_VERSION_1 &&
+           priv->version != CPSW_VERSION_2)
+               return -EOPNOTSUPP;
+
        if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
                return -EFAULT;
 
@@ -1330,16 +1339,8 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
        if (cfg.flags)
                return -EINVAL;
 
-       switch (cfg.tx_type) {
-       case HWTSTAMP_TX_OFF:
-               cpts->tx_enable = 0;
-               break;
-       case HWTSTAMP_TX_ON:
-               cpts->tx_enable = 1;
-               break;
-       default:
+       if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
                return -ERANGE;
-       }
 
        switch (cfg.rx_filter) {
        case HWTSTAMP_FILTER_NONE:
@@ -1366,6 +1367,8 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
                return -ERANGE;
        }
 
+       cpts->tx_enable = cfg.tx_type == HWTSTAMP_TX_ON;
+
        switch (priv->version) {
        case CPSW_VERSION_1:
                cpsw_hwtstamp_v1(priv);
@@ -1374,7 +1377,7 @@ static int cpsw_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
                cpsw_hwtstamp_v2(priv);
                break;
        default:
-               return -ENOTSUPP;
+               WARN_ON(1);
        }
 
        return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
@@ -2173,8 +2176,9 @@ static int cpsw_suspend(struct device *dev)
 
        if (netif_running(ndev))
                cpsw_ndo_stop(ndev);
-       soft_reset("sliver 0", &priv->slaves[0].sliver->soft_reset);
-       soft_reset("sliver 1", &priv->slaves[1].sliver->soft_reset);
+
+       for_each_slave(priv, soft_reset_slave);
+
        pm_runtime_put_sync(&pdev->dev);
 
        /* Select sleep pin state */
index e78802e75ea6cb358d6e3bec8d3a25efcffc66d4..bcc224a83734cdb49c25993066babe904a42d32f 100644 (file)
@@ -389,16 +389,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
        ch = PORT2CHANNEL(port);
        regs = (struct ixp46x_ts_regs __iomem *) IXP4XX_TIMESYNC_BASE_VIRT;
 
-       switch (cfg.tx_type) {
-       case HWTSTAMP_TX_OFF:
-               port->hwts_tx_en = 0;
-               break;
-       case HWTSTAMP_TX_ON:
-               port->hwts_tx_en = 1;
-               break;
-       default:
+       if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON)
                return -ERANGE;
-       }
 
        switch (cfg.rx_filter) {
        case HWTSTAMP_FILTER_NONE:
@@ -416,6 +408,8 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
                return -ERANGE;
        }
 
+       port->hwts_tx_en = cfg.tx_type == HWTSTAMP_TX_ON;
+
        /* Clear out any old time stamps. */
        __raw_writel(TX_SNAPSHOT_LOCKED | RX_SNAPSHOT_LOCKED,
                     &regs->channel[ch].ch_event);
index 7bbd318bc93e0bb062ed378b4aa6e3bd3b2f2a44..befa45f809c32976470d2a9f072a5580a578f791 100644 (file)
@@ -627,7 +627,7 @@ static int ali_ircc_setup(chipio_t *info)
 /*
  * Function ali_ircc_read_dongle_id (int index, info)
  *
- * Try to read dongle indentification. This procedure needs to be executed
+ * Try to read dongle identification. This procedure needs to be executed
  * once after power-on/reset. It also needs to be used whenever you suspect
  * that the user may have plugged/unplugged the IrDA Dongle.
  */
index ceeb53737f86ba195b13b69933234313e8dcb506..66bc03bdb138c36cd8f717b76fe7bc9cd57cbbb3 100644 (file)
@@ -1035,7 +1035,7 @@ static int nsc_ircc_setup(chipio_t *info)
 /*
  * Function nsc_ircc_read_dongle_id (void)
  *
- * Try to read dongle indentification. This procedure needs to be executed
+ * Try to read dongle identification. This procedure needs to be executed
  * once after power-on/reset. It also needs to be used whenever you suspect
  * that the user may have plugged/unplugged the IrDA Dongle.
  */
index 9dccb1edfd2aba2070023f4ae874bac0cc432293..dc76670c2f2a16c244d0ec58a779a8742d0e6c3e 100644 (file)
@@ -628,6 +628,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
                                const struct iovec *iv, unsigned long total_len,
                                size_t count, int noblock)
 {
+       int good_linear = SKB_MAX_HEAD(NET_IP_ALIGN);
        struct sk_buff *skb;
        struct macvlan_dev *vlan;
        unsigned long len = total_len;
@@ -670,6 +671,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 
        if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
                copylen = vnet_hdr.hdr_len ? vnet_hdr.hdr_len : GOODCOPY_LEN;
+               if (copylen > good_linear)
+                       copylen = good_linear;
                linear = copylen;
                if (iov_pages(iv, vnet_hdr_len + copylen, count)
                    <= MAX_SKB_FRAGS)
@@ -678,7 +681,10 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
 
        if (!zerocopy) {
                copylen = len;
-               linear = vnet_hdr.hdr_len;
+               if (vnet_hdr.hdr_len > good_linear)
+                       linear = good_linear;
+               else
+                       linear = vnet_hdr.hdr_len;
        }
 
        skb = macvtap_alloc_skb(&q->sk, NET_IP_ALIGN, copylen,
index 6574eb8766f90997c38d0ea56d67ad542ecf99b3..34b0de09d88190a04e30d867e31ad001f35f0e34 100644 (file)
@@ -2650,7 +2650,7 @@ static int team_nl_cmd_port_list_get(struct sk_buff *skb,
        return err;
 }
 
-static struct genl_ops team_nl_ops[] = {
+static const struct genl_ops team_nl_ops[] = {
        {
                .cmd = TEAM_CMD_NOOP,
                .doit = team_nl_cmd_noop,
@@ -2676,15 +2676,15 @@ static struct genl_ops team_nl_ops[] = {
        },
 };
 
-static struct genl_multicast_group team_change_event_mcgrp = {
-       .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME,
+static const struct genl_multicast_group team_nl_mcgrps[] = {
+       { .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
 };
 
 static int team_nl_send_multicast(struct sk_buff *skb,
                                  struct team *team, u32 portid)
 {
-       return genlmsg_multicast_netns(dev_net(team->dev), skb, 0,
-                                      team_change_event_mcgrp.id, GFP_KERNEL);
+       return genlmsg_multicast_netns(&team_nl_family, dev_net(team->dev),
+                                      skb, 0, 0, GFP_KERNEL);
 }
 
 static int team_nl_send_event_options_get(struct team *team,
@@ -2703,23 +2703,8 @@ static int team_nl_send_event_port_get(struct team *team,
 
 static int team_nl_init(void)
 {
-       int err;
-
-       err = genl_register_family_with_ops(&team_nl_family, team_nl_ops,
-                                           ARRAY_SIZE(team_nl_ops));
-       if (err)
-               return err;
-
-       err = genl_register_mc_group(&team_nl_family, &team_change_event_mcgrp);
-       if (err)
-               goto err_change_event_grp_reg;
-
-       return 0;
-
-err_change_event_grp_reg:
-       genl_unregister_family(&team_nl_family);
-
-       return err;
+       return genl_register_family_with_ops_groups(&team_nl_family, team_nl_ops,
+                                                   team_nl_mcgrps);
 }
 
 static void team_nl_fini(void)
index 7cb105c103fe9408eb7c02b96dac4f4bfb702456..782e38bfc1eeea38215492aee5aaa587cc534525 100644 (file)
@@ -981,6 +981,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
        struct sk_buff *skb;
        size_t len = total_len, align = NET_SKB_PAD, linear;
        struct virtio_net_hdr gso = { 0 };
+       int good_linear;
        int offset = 0;
        int copylen;
        bool zerocopy = false;
@@ -1021,12 +1022,16 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
                        return -EINVAL;
        }
 
+       good_linear = SKB_MAX_HEAD(align);
+
        if (msg_control) {
                /* There are 256 bytes to be copied in skb, so there is
                 * enough room for skb expand head in case it is used.
                 * The rest of the buffer is mapped from userspace.
                 */
                copylen = gso.hdr_len ? gso.hdr_len : GOODCOPY_LEN;
+               if (copylen > good_linear)
+                       copylen = good_linear;
                linear = copylen;
                if (iov_pages(iv, offset + copylen, count) <= MAX_SKB_FRAGS)
                        zerocopy = true;
@@ -1034,7 +1039,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 
        if (!zerocopy) {
                copylen = len;
-               linear = gso.hdr_len;
+               if (gso.hdr_len > good_linear)
+                       linear = good_linear;
+               else
+                       linear = gso.hdr_len;
        }
 
        skb = tun_alloc_skb(tfile, align, copylen, linear, noblock);
index f74786aa37be3cca7a4020cc82b08f0777aec4f5..e15ec2b12035aa06b4662c284a7bb3abda148eff 100644 (file)
@@ -66,7 +66,7 @@ static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
 static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
 static struct usb_driver cdc_ncm_driver;
 
-static u8 cdc_ncm_setup(struct usbnet *dev)
+static int cdc_ncm_setup(struct usbnet *dev)
 {
        struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
        struct usb_cdc_ncm_ntb_parameters ncm_parm;
index 90a429b7ebad8497d317639389c041d534366255..8494bb53ebdc9f33abee1d8e5a27f7d0dea3cc17 100644 (file)
@@ -204,9 +204,6 @@ static void intr_complete (struct urb *urb)
                break;
        }
 
-       if (!netif_running (dev->net))
-               return;
-
        status = usb_submit_urb (urb, GFP_ATOMIC);
        if (status != 0)
                netif_err(dev, timer, dev->net,
index cdc7c90a6a9e3053d3a2e26eb78100a0f518b646..7bab4de658a91d9fb1231f5e45461a268efc8487 100644 (file)
@@ -36,7 +36,10 @@ module_param(csum, bool, 0444);
 module_param(gso, bool, 0444);
 
 /* FIXME: MTU in config. */
-#define MAX_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
+#define GOOD_PACKET_LEN (ETH_HLEN + VLAN_HLEN + ETH_DATA_LEN)
+#define MERGE_BUFFER_LEN (ALIGN(GOOD_PACKET_LEN + \
+                                sizeof(struct virtio_net_hdr_mrg_rxbuf), \
+                                L1_CACHE_BYTES))
 #define GOOD_COPY_LEN  128
 
 #define VIRTNET_DRIVER_VERSION "1.0.0"
@@ -314,10 +317,10 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb)
                        head_skb->dev->stats.rx_length_errors++;
                        return -EINVAL;
                }
-               if (unlikely(len > MAX_PACKET_LEN)) {
+               if (unlikely(len > MERGE_BUFFER_LEN)) {
                        pr_debug("%s: rx error: merge buffer too long\n",
                                 head_skb->dev->name);
-                       len = MAX_PACKET_LEN;
+                       len = MERGE_BUFFER_LEN;
                }
                if (unlikely(num_skb_frags == MAX_SKB_FRAGS)) {
                        struct sk_buff *nskb = alloc_skb(0, GFP_ATOMIC);
@@ -336,18 +339,17 @@ static int receive_mergeable(struct receive_queue *rq, struct sk_buff *head_skb)
                if (curr_skb != head_skb) {
                        head_skb->data_len += len;
                        head_skb->len += len;
-                       head_skb->truesize += MAX_PACKET_LEN;
+                       head_skb->truesize += MERGE_BUFFER_LEN;
                }
                page = virt_to_head_page(buf);
                offset = buf - (char *)page_address(page);
                if (skb_can_coalesce(curr_skb, num_skb_frags, page, offset)) {
                        put_page(page);
                        skb_coalesce_rx_frag(curr_skb, num_skb_frags - 1,
-                                            len, MAX_PACKET_LEN);
+                                            len, MERGE_BUFFER_LEN);
                } else {
                        skb_add_rx_frag(curr_skb, num_skb_frags, page,
-                                       offset, len,
-                                       MAX_PACKET_LEN);
+                                       offset, len, MERGE_BUFFER_LEN);
                }
                --rq->num;
        }
@@ -383,7 +385,7 @@ static void receive_buf(struct receive_queue *rq, void *buf, unsigned int len)
                struct page *page = virt_to_head_page(buf);
                skb = page_to_skb(rq, page,
                                  (char *)buf - (char *)page_address(page),
-                                 len, MAX_PACKET_LEN);
+                                 len, MERGE_BUFFER_LEN);
                if (unlikely(!skb)) {
                        dev->stats.rx_dropped++;
                        put_page(page);
@@ -471,11 +473,11 @@ static int add_recvbuf_small(struct receive_queue *rq, gfp_t gfp)
        struct skb_vnet_hdr *hdr;
        int err;
 
-       skb = __netdev_alloc_skb_ip_align(vi->dev, MAX_PACKET_LEN, gfp);
+       skb = __netdev_alloc_skb_ip_align(vi->dev, GOOD_PACKET_LEN, gfp);
        if (unlikely(!skb))
                return -ENOMEM;
 
-       skb_put(skb, MAX_PACKET_LEN);
+       skb_put(skb, GOOD_PACKET_LEN);
 
        hdr = skb_vnet_hdr(skb);
        sg_set_buf(rq->sg, &hdr->hdr, sizeof hdr->hdr);
@@ -542,20 +544,20 @@ static int add_recvbuf_mergeable(struct receive_queue *rq, gfp_t gfp)
        int err;
 
        if (gfp & __GFP_WAIT) {
-               if (skb_page_frag_refill(MAX_PACKET_LEN, &vi->alloc_frag,
+               if (skb_page_frag_refill(MERGE_BUFFER_LEN, &vi->alloc_frag,
                                         gfp)) {
                        buf = (char *)page_address(vi->alloc_frag.page) +
                              vi->alloc_frag.offset;
                        get_page(vi->alloc_frag.page);
-                       vi->alloc_frag.offset += MAX_PACKET_LEN;
+                       vi->alloc_frag.offset += MERGE_BUFFER_LEN;
                }
        } else {
-               buf = netdev_alloc_frag(MAX_PACKET_LEN);
+               buf = netdev_alloc_frag(MERGE_BUFFER_LEN);
        }
        if (!buf)
                return -ENOMEM;
 
-       sg_init_one(rq->sg, buf, MAX_PACKET_LEN);
+       sg_init_one(rq->sg, buf, MERGE_BUFFER_LEN);
        err = virtqueue_add_inbuf(rq->vq, rq->sg, 1, buf, gfp);
        if (err < 0)
                put_page(virt_to_head_page(buf));
@@ -1619,8 +1621,8 @@ static int virtnet_probe(struct virtio_device *vdev)
        if (err)
                goto free_stats;
 
-       netif_set_real_num_tx_queues(dev, 1);
-       netif_set_real_num_rx_queues(dev, 1);
+       netif_set_real_num_tx_queues(dev, vi->curr_queue_pairs);
+       netif_set_real_num_rx_queues(dev, vi->curr_queue_pairs);
 
        err = register_netdev(dev);
        if (err) {
index f8d59c7b90821a69b3401a7ec143bd6d8e0fc367..9e86a811086f6bf2e8316afdecdd29a4ec5195c9 100644 (file)
@@ -2363,7 +2363,7 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
                break;
        default:
                ret = -ENODEV;
-               ath10k_err("Unkown device ID: %d\n", pci_dev->device);
+               ath10k_err("Unknown device ID: %d\n", pci_dev->device);
                goto err_ar_pci;
        }
 
index ce86f158423bdc3861dc4547242eb37fc8210930..ba200b24be64cd307483fad13fef4a9283a93784 100644 (file)
@@ -661,7 +661,7 @@ ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
                        ah->ah_txq_isr_txok_all |= AR5K_REG_MS(sisr1,
                                                AR5K_SISR1_QCU_TXEOL);
 
-               /* Currently this is not much usefull since we treat
+               /* Currently this is not much useful since we treat
                 * all queues the same way if we get a TXURN (update
                 * tx trigger level) but we might need it later on*/
                if (pisr & AR5K_ISR_TXURN)
index b07f164d65cf582a63c2ddfbfccaced509a6ceca..20e49095db2ae2ba0c2d7d83071aa2a14a81252d 100644 (file)
@@ -187,17 +187,17 @@ static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
                INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
                               ar9485_1_1_baseband_core_txfir_coeff_japan_2484);
 
-               /* Load PCIE SERDES settings from INI */
-
-               /* Awake Setting */
-
-               INIT_INI_ARRAY(&ah->iniPcieSerdes,
-                               ar9485_1_1_pcie_phy_clkreq_disable_L1);
-
-               /* Sleep Setting */
-
-               INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
-                               ar9485_1_1_pcie_phy_clkreq_disable_L1);
+               if (ah->config.no_pll_pwrsave) {
+                       INIT_INI_ARRAY(&ah->iniPcieSerdes,
+                                      ar9485_1_1_pcie_phy_clkreq_disable_L1);
+                       INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
+                                      ar9485_1_1_pcie_phy_clkreq_disable_L1);
+               } else {
+                       INIT_INI_ARRAY(&ah->iniPcieSerdes,
+                                      ar9485_1_1_pll_on_cdr_on_clkreq_disable_L1);
+                       INIT_INI_ARRAY(&ah->iniPcieSerdesLowPower,
+                                      ar9485_1_1_pll_on_cdr_on_clkreq_disable_L1);
+               }
        } else if (AR_SREV_9462_21(ah)) {
                INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
                               ar9462_2p1_mac_core);
index 6f899c6926474ba2f60cd642399e10d61814ec3d..7c1845221e1cc08a0904b35a491e64b1cd70b953 100644 (file)
@@ -32,13 +32,6 @@ static const u32 ar9485_1_1_mac_postamble[][5] = {
        {0x00008318, 0x00003e80, 0x00007d00, 0x00006880, 0x00003440},
 };
 
-static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_disable_L1[][2] = {
-       /* Addr      allmodes  */
-       {0x00018c00, 0x18012e5e},
-       {0x00018c04, 0x000801d8},
-       {0x00018c08, 0x0000080c},
-};
-
 static const u32 ar9485Common_wo_xlna_rx_gain_1_1[][2] = {
        /* Addr      allmodes  */
        {0x00009e00, 0x037216a0},
@@ -1101,20 +1094,6 @@ static const u32 ar9485_common_rx_gain_1_1[][2] = {
        {0x0000a1fc, 0x00000296},
 };
 
-static const u32 ar9485_1_1_pcie_phy_pll_on_clkreq_enable_L1[][2] = {
-       /* Addr      allmodes  */
-       {0x00018c00, 0x18052e5e},
-       {0x00018c04, 0x000801d8},
-       {0x00018c08, 0x0000080c},
-};
-
-static const u32 ar9485_1_1_pcie_phy_clkreq_enable_L1[][2] = {
-       /* Addr      allmodes  */
-       {0x00018c00, 0x18053e5e},
-       {0x00018c04, 0x000801d8},
-       {0x00018c08, 0x0000080c},
-};
-
 static const u32 ar9485_1_1_soc_preamble[][2] = {
        /* Addr      allmodes  */
        {0x00004014, 0xba280400},
@@ -1173,13 +1152,6 @@ static const u32 ar9485_1_1_baseband_postamble[][5] = {
        {0x0000be18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
 };
 
-static const u32 ar9485_1_1_pcie_phy_clkreq_disable_L1[][2] = {
-       /* Addr      allmodes  */
-       {0x00018c00, 0x18013e5e},
-       {0x00018c04, 0x000801d8},
-       {0x00018c08, 0x0000080c},
-};
-
 static const u32 ar9485_1_1_radio_postamble[][2] = {
        /* Addr      allmodes  */
        {0x0001609c, 0x0b283f31},
@@ -1358,4 +1330,18 @@ static const u32 ar9485_1_1_baseband_core_txfir_coeff_japan_2484[][2] = {
        {0x0000a3a0, 0xca9228ee},
 };
 
+static const u32 ar9485_1_1_pcie_phy_clkreq_disable_L1[][2] = {
+       /* Addr      allmodes  */
+       {0x00018c00, 0x18013e5e},
+       {0x00018c04, 0x000801d8},
+       {0x00018c08, 0x0000080c},
+};
+
+static const u32 ar9485_1_1_pll_on_cdr_on_clkreq_disable_L1[][2] = {
+       /* Addr      allmodes  */
+       {0x00018c00, 0x1801265e},
+       {0x00018c04, 0x000801d8},
+       {0x00018c08, 0x0000080c},
+};
+
 #endif /* INITVALS_9485_H */
index e7a38d844a6a4e7a2e9ba738e56606d946fea47a..60a5da53668f54f9987692ccf7389794d13ea851 100644 (file)
@@ -632,15 +632,16 @@ void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
 /* Main driver core */
 /********************/
 
-#define ATH9K_PCI_CUS198      0x0001
-#define ATH9K_PCI_CUS230      0x0002
-#define ATH9K_PCI_CUS217      0x0004
-#define ATH9K_PCI_CUS252      0x0008
-#define ATH9K_PCI_WOW         0x0010
-#define ATH9K_PCI_BT_ANT_DIV  0x0020
-#define ATH9K_PCI_D3_L1_WAR   0x0040
-#define ATH9K_PCI_AR9565_1ANT 0x0080
-#define ATH9K_PCI_AR9565_2ANT 0x0100
+#define ATH9K_PCI_CUS198          0x0001
+#define ATH9K_PCI_CUS230          0x0002
+#define ATH9K_PCI_CUS217          0x0004
+#define ATH9K_PCI_CUS252          0x0008
+#define ATH9K_PCI_WOW             0x0010
+#define ATH9K_PCI_BT_ANT_DIV      0x0020
+#define ATH9K_PCI_D3_L1_WAR       0x0040
+#define ATH9K_PCI_AR9565_1ANT     0x0080
+#define ATH9K_PCI_AR9565_2ANT     0x0100
+#define ATH9K_PCI_NO_PLL_PWRSAVE  0x0200
 
 /*
  * Default cache line size, in bytes.
index 90b8342d1ed4bd2e95389541f299d49d59261e6a..8824610c21fb3a3476a281f6b3435213ebef12cd 100644 (file)
@@ -44,14 +44,20 @@ static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
        if (buf == NULL)
                return -ENOMEM;
 
-       if (sc->dfs_detector)
-               dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
-
        len += scnprintf(buf + len, size - len, "DFS support for "
                         "macVersion = 0x%x, macRev = 0x%x: %s\n",
                         hw_ver->macVersion, hw_ver->macRev,
                         (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_DFS) ?
                                        "enabled" : "disabled");
+
+       if (!sc->dfs_detector) {
+               len += scnprintf(buf + len, size - len,
+                                "DFS detector not enabled\n");
+               goto exit;
+       }
+
+       dfs_pool_stats = sc->dfs_detector->get_stats(sc->dfs_detector);
+
        len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
        ATH9K_DFS_STAT("pulse events reported   ", pulses_total);
        ATH9K_DFS_STAT("invalid pulse events    ", pulses_no_dfs);
@@ -76,6 +82,7 @@ static ssize_t read_file_dfs(struct file *file, char __user *user_buf,
        ATH9K_DFS_POOL_STAT("Seqs. alloc error       ", pseq_alloc_error);
        ATH9K_DFS_POOL_STAT("Seqs. in use            ", pseq_used);
 
+exit:
        if (len > size)
                len = size;
 
index 9ea24f1cba73f812de0b3352806e89434c0d59f9..a2c9a5dbac6b0317fba5131ee212d3ef9292c77a 100644 (file)
@@ -316,6 +316,7 @@ struct ath9k_ops_config {
        u32 ant_ctrl_comm2g_switch_enable;
        bool xatten_margin_cfg;
        bool alt_mingainidx;
+       bool no_pll_pwrsave;
 };
 
 enum ath9k_int {
index d8643ebabd3001b6a00544157a65a9bc9f3265c5..710192ed27ed3118656f1a3b08bc41ec92c649a1 100644 (file)
@@ -609,6 +609,11 @@ static void ath9k_init_platform(struct ath_softc *sc)
                ah->config.pcie_waen = 0x0040473b;
                ath_info(common, "Enable WAR for ASPM D3/L1\n");
        }
+
+       if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
+               ah->config.no_pll_pwrsave = true;
+               ath_info(common, "Disable PLL PowerSave\n");
+       }
 }
 
 static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
@@ -863,8 +868,8 @@ static const struct ieee80211_iface_combination if_comb[] = {
                .max_interfaces = 1,
                .num_different_channels = 1,
                .beacon_int_infra_match = true,
-               .radar_detect_widths =  BIT(NL80211_CHAN_NO_HT) |
-                                       BIT(NL80211_CHAN_HT20),
+               .radar_detect_widths =  BIT(NL80211_CHAN_WIDTH_20_NOHT) |
+                                       BIT(NL80211_CHAN_WIDTH_20),
        }
 };
 
index 7e4c2524b63052006650ff76b92b3b839d6c9cd6..b5656fce4ff5f042b9053258e31c9b503802d217 100644 (file)
@@ -195,6 +195,93 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_id_table) = {
                         0x3219),
          .driver_data = ATH9K_PCI_BT_ANT_DIV },
 
+       /* AR9485 cards with PLL power-save disabled by default. */
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_AZWAVE,
+                        0x2C97),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_AZWAVE,
+                        0x2100),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x1C56, /* ASKEY */
+                        0x4001),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x11AD, /* LITEON */
+                        0x6627),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x11AD, /* LITEON */
+                        0x6628),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_FOXCONN,
+                        0xE04E),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_FOXCONN,
+                        0xE04F),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x144F, /* ASKEY */
+                        0x7197),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x1B9A, /* XAVI */
+                        0x2000),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x1B9A, /* XAVI */
+                        0x2001),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_AZWAVE,
+                        0x1186),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_AZWAVE,
+                        0x1F86),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_AZWAVE,
+                        0x1195),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_AZWAVE,
+                        0x1F95),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x1B9A, /* XAVI */
+                        0x1C00),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        0x1B9A, /* XAVI */
+                        0x1C01),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+       { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
+                        0x0032,
+                        PCI_VENDOR_ID_ASUSTEK,
+                        0x850D),
+         .driver_data = ATH9K_PCI_NO_PLL_PWRSAVE },
+
        { PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E  AR9485 */
        { PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E  AR9580 */
 
index 5b84f7ae0b1e3820cdee9737f9e4bacd8ed7b8d3..ef44a2da644d47be1613041703093cf7567f8979 100644 (file)
@@ -126,7 +126,7 @@ static ssize_t write_file_dump(struct file *file,
                if (begin == NULL)
                        break;
 
-               if (kstrtoul(begin, 0, (unsigned long *)(arg + i)) != 0)
+               if (kstrtou32(begin, 0, &arg[i]) != 0)
                        break;
        }
 
index f8c3a10510c22b01eb06d9b51310562cb0c8b7dd..de9eb2cfbf4b5784c36a97da2748acd357250c37 100644 (file)
@@ -1286,7 +1286,8 @@ int wcn36xx_smd_send_beacon(struct wcn36xx *wcn, struct ieee80211_vif *vif,
        } else {
                wcn36xx_err("Beacon is to big: beacon size=%d\n",
                              msg_body.beacon_length);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
        memcpy(msg_body.bssid, vif->addr, ETH_ALEN);
 
@@ -1327,7 +1328,8 @@ int wcn36xx_smd_update_proberesp_tmpl(struct wcn36xx *wcn,
        if (skb->len > BEACON_TEMPLATE_SIZE) {
                wcn36xx_warn("probe response template is too big: %d\n",
                             skb->len);
-               return -E2BIG;
+               ret = -E2BIG;
+               goto out;
        }
 
        msg.probe_resp_template_len = skb->len;
@@ -1606,7 +1608,8 @@ int wcn36xx_smd_keep_alive_req(struct wcn36xx *wcn,
                /* TODO: it also support ARP response type */
        } else {
                wcn36xx_warn("unknow keep alive packet type %d\n", packet_type);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto out;
        }
 
        PREPARE_HAL_BUF(wcn->hal_buf, msg_body);
index 668dd27616a0c83f9a4a39b94de2ad22b8e98a2b..cc6a0a586f0b748c054c4c0e8631ea0d706501cb 100644 (file)
@@ -913,7 +913,10 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
        char *p2;
        struct debug_data *d = f->private_data;
 
-       pdata = kmalloc(cnt, GFP_KERNEL);
+       if (cnt == 0)
+               return 0;
+
+       pdata = kmalloc(cnt + 1, GFP_KERNEL);
        if (pdata == NULL)
                return 0;
 
@@ -922,6 +925,7 @@ static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
                kfree(pdata);
                return 0;
        }
+       pdata[cnt] = '\0';
 
        p0 = pdata;
        for (i = 0; i < num_of_items; i++) {
index ef8c98e21098479d231df5844fb2abab8ddab04f..f499efc6abcf8bed36c46c7aaa342c8b8be3c878 100644 (file)
@@ -902,6 +902,7 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
        if (card->model == MODEL_UNKNOWN) {
                pr_err("unsupported manf_id 0x%04x / card_id 0x%04x\n",
                       p_dev->manf_id, p_dev->card_id);
+               ret = -ENODEV;
                goto out2;
        }
 
index de0df86704e714778891b7fb1af6b2cfc1340bef..9df7bc91a26f54c9812718e481c538895aa5b4f8 100644 (file)
@@ -2097,7 +2097,7 @@ out:
 }
 
 /* Generic Netlink operations array */
-static struct genl_ops hwsim_ops[] = {
+static const struct genl_ops hwsim_ops[] = {
        {
                .cmd = HWSIM_CMD_REGISTER,
                .policy = hwsim_genl_policy,
@@ -2148,8 +2148,7 @@ static int hwsim_init_netlink(void)
 
        printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");
 
-       rc = genl_register_family_with_ops(&hwsim_genl_family,
-               hwsim_ops, ARRAY_SIZE(hwsim_ops));
+       rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops);
        if (rc)
                goto failure;
 
index f80f30b6160e7f4be38811198e76c245f26e08ca..c8385ec77a86af678b36cf28a5d7c2fa8448de84 100644 (file)
@@ -1020,8 +1020,8 @@ struct mwifiex_power_group {
 } __packed;
 
 struct mwifiex_types_power_group {
-       u16 type;
-       u16 length;
+       __le16 type;
+       __le16 length;
 } __packed;
 
 struct host_cmd_ds_txpwr_cfg {
index 220af4fe0fc65b18b575c81025c436d303f01bbd..81ac001ee74187d325f7a7d166666f9ec3c497fa 100644 (file)
@@ -82,7 +82,7 @@ mwifiex_update_autoindex_ies(struct mwifiex_private *priv,
                             struct mwifiex_ie_list *ie_list)
 {
        u16 travel_len, index, mask;
-       s16 input_len;
+       s16 input_len, tlv_len;
        struct mwifiex_ie *ie;
        u8 *tmp;
 
@@ -91,11 +91,13 @@ mwifiex_update_autoindex_ies(struct mwifiex_private *priv,
 
        ie_list->len = 0;
 
-       while (input_len > 0) {
+       while (input_len >= sizeof(struct mwifiex_ie_types_header)) {
                ie = (struct mwifiex_ie *)(((u8 *)ie_list) + travel_len);
-               input_len -= le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
-               travel_len += le16_to_cpu(ie->ie_length) + MWIFIEX_IE_HDR_SIZE;
+               tlv_len = le16_to_cpu(ie->ie_length);
+               travel_len += tlv_len + MWIFIEX_IE_HDR_SIZE;
 
+               if (input_len < tlv_len + MWIFIEX_IE_HDR_SIZE)
+                       return -1;
                index = le16_to_cpu(ie->ie_index);
                mask = le16_to_cpu(ie->mgmt_subtype_mask);
 
@@ -132,6 +134,7 @@ mwifiex_update_autoindex_ies(struct mwifiex_private *priv,
                le16_add_cpu(&ie_list->len,
                             le16_to_cpu(priv->mgmt_ie[index].ie_length) +
                             MWIFIEX_IE_HDR_SIZE);
+               input_len -= tlv_len + MWIFIEX_IE_HDR_SIZE;
        }
 
        if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)
index 1576104e3d9531ada721dc41ec5740f021345b83..9bf8898743ab3d8a31aaad7641ecad09204e0265 100644 (file)
@@ -1029,7 +1029,10 @@ static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
                                    struct sk_buff *skb, u32 upld_typ)
 {
        u8 *cmd_buf;
+       __le16 *curr_ptr = (__le16 *)skb->data;
+       u16 pkt_len = le16_to_cpu(*curr_ptr);
 
+       skb_trim(skb, pkt_len);
        skb_pull(skb, INTF_HEADER_LEN);
 
        switch (upld_typ) {
index 7d66018a2e33060d1bdc1a96b970fd61f6480e4a..2181ee283d823e19dafaa5b1b8a09fcb1b4f2b1a 100644 (file)
@@ -239,14 +239,14 @@ static int mwifiex_cmd_tx_power_cfg(struct host_cmd_ds_command *cmd,
                        memmove(cmd_txp_cfg, txp,
                                sizeof(struct host_cmd_ds_txpwr_cfg) +
                                sizeof(struct mwifiex_types_power_group) +
-                               pg_tlv->length);
+                               le16_to_cpu(pg_tlv->length));
 
                        pg_tlv = (struct mwifiex_types_power_group *) ((u8 *)
                                  cmd_txp_cfg +
                                  sizeof(struct host_cmd_ds_txpwr_cfg));
                        cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) +
                                  sizeof(struct mwifiex_types_power_group) +
-                                 pg_tlv->length);
+                                 le16_to_cpu(pg_tlv->length));
                } else {
                        memmove(cmd_txp_cfg, txp, sizeof(*txp));
                }
index 58a6013712d2d2c7e063282e056fa31e2dd7a955..2675ca7f8d146ca579a7a4bb4c1397f641a95ee0 100644 (file)
@@ -274,17 +274,20 @@ static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
        struct host_cmd_ds_tx_rate_cfg *rate_cfg = &resp->params.tx_rate_cfg;
        struct mwifiex_rate_scope *rate_scope;
        struct mwifiex_ie_types_header *head;
-       u16 tlv, tlv_buf_len;
+       u16 tlv, tlv_buf_len, tlv_buf_left;
        u8 *tlv_buf;
        u32 i;
 
-       tlv_buf = ((u8 *)rate_cfg) +
-                       sizeof(struct host_cmd_ds_tx_rate_cfg);
-       tlv_buf_len = le16_to_cpu(*(__le16 *) (tlv_buf + sizeof(u16)));
+       tlv_buf = ((u8 *)rate_cfg) + sizeof(struct host_cmd_ds_tx_rate_cfg);
+       tlv_buf_left = le16_to_cpu(resp->size) - S_DS_GEN - sizeof(*rate_cfg);
 
-       while (tlv_buf && tlv_buf_len > 0) {
-               tlv = (*tlv_buf);
-               tlv = tlv | (*(tlv_buf + 1) << 8);
+       while (tlv_buf_left >= sizeof(*head)) {
+               head = (struct mwifiex_ie_types_header *)tlv_buf;
+               tlv = le16_to_cpu(head->type);
+               tlv_buf_len = le16_to_cpu(head->len);
+
+               if (tlv_buf_left < (sizeof(*head) + tlv_buf_len))
+                       break;
 
                switch (tlv) {
                case TLV_TYPE_RATE_SCOPE:
@@ -304,9 +307,8 @@ static int mwifiex_ret_tx_rate_cfg(struct mwifiex_private *priv,
                        /* Add RATE_DROP tlv here */
                }
 
-               head = (struct mwifiex_ie_types_header *) tlv_buf;
-               tlv_buf += le16_to_cpu(head->len) + sizeof(*head);
-               tlv_buf_len -= le16_to_cpu(head->len);
+               tlv_buf += (sizeof(*head) + tlv_buf_len);
+               tlv_buf_left -= (sizeof(*head) + tlv_buf_len);
        }
 
        priv->is_data_rate_auto = mwifiex_is_rate_auto(priv);
@@ -340,13 +342,17 @@ static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
                ((u8 *) data_buf + sizeof(struct host_cmd_ds_txpwr_cfg));
        pg = (struct mwifiex_power_group *)
                ((u8 *) pg_tlv_hdr + sizeof(struct mwifiex_types_power_group));
-       length = pg_tlv_hdr->length;
-       if (length > 0) {
-               max_power = pg->power_max;
-               min_power = pg->power_min;
-               length -= sizeof(struct mwifiex_power_group);
-       }
-       while (length) {
+       length = le16_to_cpu(pg_tlv_hdr->length);
+
+       /* At least one structure required to update power */
+       if (length < sizeof(struct mwifiex_power_group))
+               return 0;
+
+       max_power = pg->power_max;
+       min_power = pg->power_min;
+       length -= sizeof(struct mwifiex_power_group);
+
+       while (length >= sizeof(struct mwifiex_power_group)) {
                pg++;
                if (max_power < pg->power_max)
                        max_power = pg->power_max;
@@ -356,10 +362,8 @@ static int mwifiex_get_power_level(struct mwifiex_private *priv, void *data_buf)
 
                length -= sizeof(struct mwifiex_power_group);
        }
-       if (pg_tlv_hdr->length > 0) {
-               priv->min_tx_power_level = (u8) min_power;
-               priv->max_tx_power_level = (u8) max_power;
-       }
+       priv->min_tx_power_level = (u8) min_power;
+       priv->max_tx_power_level = (u8) max_power;
 
        return 0;
 }
index f084412eee0b7cdeced4f2b21b4140b01d1b141e..c8e029df770e38cac9a52dccb660666bd8cc9f74 100644 (file)
@@ -638,8 +638,9 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
                txp_cfg->mode = cpu_to_le32(1);
                pg_tlv = (struct mwifiex_types_power_group *)
                         (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
-               pg_tlv->type = TLV_TYPE_POWER_GROUP;
-               pg_tlv->length = 4 * sizeof(struct mwifiex_power_group);
+               pg_tlv->type = cpu_to_le16(TLV_TYPE_POWER_GROUP);
+               pg_tlv->length =
+                       cpu_to_le16(4 * sizeof(struct mwifiex_power_group));
                pg = (struct mwifiex_power_group *)
                     (buf + sizeof(struct host_cmd_ds_txpwr_cfg)
                      + sizeof(struct mwifiex_types_power_group));
index 1cfe5a738c479e53e3dd5ba21f460096d2a16e53..92f76d655e6cc1206e46c4fc0e60b147b62280e0 100644 (file)
@@ -97,6 +97,7 @@ static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv,
        struct mwifiex_txinfo *tx_info;
        int hdr_chop;
        struct timeval tv;
+       struct ethhdr *p_ethhdr;
        u8 rfc1042_eth_hdr[ETH_ALEN] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
 
        uap_rx_pd = (struct uap_rxpd *)(skb->data);
@@ -112,14 +113,36 @@ static void mwifiex_uap_queue_bridged_pkt(struct mwifiex_private *priv,
        }
 
        if (!memcmp(&rx_pkt_hdr->rfc1042_hdr,
-                   rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr)))
+                   rfc1042_eth_hdr, sizeof(rfc1042_eth_hdr))) {
+               /* Replace the 803 header and rfc1042 header (llc/snap) with
+                * an Ethernet II header, keep the src/dst and snap_type
+                * (ethertype).
+                *
+                * The firmware only passes up SNAP frames converting all RX
+                * data from 802.11 to 802.2/LLC/SNAP frames.
+                *
+                * To create the Ethernet II, just move the src, dst address
+                * right before the snap_type.
+                */
+               p_ethhdr = (struct ethhdr *)
+                       ((u8 *)(&rx_pkt_hdr->eth803_hdr)
+                        + sizeof(rx_pkt_hdr->eth803_hdr)
+                        + sizeof(rx_pkt_hdr->rfc1042_hdr)
+                        - sizeof(rx_pkt_hdr->eth803_hdr.h_dest)
+                        - sizeof(rx_pkt_hdr->eth803_hdr.h_source)
+                        - sizeof(rx_pkt_hdr->rfc1042_hdr.snap_type));
+               memcpy(p_ethhdr->h_source, rx_pkt_hdr->eth803_hdr.h_source,
+                      sizeof(p_ethhdr->h_source));
+               memcpy(p_ethhdr->h_dest, rx_pkt_hdr->eth803_hdr.h_dest,
+                      sizeof(p_ethhdr->h_dest));
                /* Chop off the rxpd + the excess memory from
                 * 802.2/llc/snap header that was removed.
                 */
-               hdr_chop = (u8 *)eth_hdr - (u8 *)uap_rx_pd;
-       else
+               hdr_chop = (u8 *)p_ethhdr - (u8 *)uap_rx_pd;
+       } else {
                /* Chop off the rxpd */
                hdr_chop = (u8 *)&rx_pkt_hdr->eth803_hdr - (u8 *)uap_rx_pd;
+       }
 
        /* Chop off the leading header bytes so the it points
         * to the start of either the reconstructed EthII frame
index 5dd0ccc70b863ea15fad25d739adebd39ce09dbd..13eaeed03898288d43abf107090346d513132820 100644 (file)
@@ -722,6 +722,9 @@ int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv,
                tlv_hdr = (struct mwifiex_ie_types_data *) curr;
                tlv_len = le16_to_cpu(tlv_hdr->header.len);
 
+               if (resp_len < tlv_len + sizeof(tlv_hdr->header))
+                       break;
+
                switch (le16_to_cpu(tlv_hdr->header.type)) {
                case TLV_TYPE_WMMQSTATUS:
                        tlv_wmm_qstatus =
index 41a16d30c79c5be46f89229d3185a033d8131f0f..e05d9b4c8317c44df17b9ca0c2dea0577741b1a6 100644 (file)
@@ -811,6 +811,10 @@ static const struct net_device_ops islpci_netdev_ops = {
        .ndo_validate_addr      = eth_validate_addr,
 };
 
+static struct device_type wlan_type = {
+       .name   = "wlan",
+};
+
 struct net_device *
 islpci_setup(struct pci_dev *pdev)
 {
@@ -821,9 +825,8 @@ islpci_setup(struct pci_dev *pdev)
                return ndev;
 
        pci_set_drvdata(pdev, ndev);
-#if defined(SET_NETDEV_DEV)
        SET_NETDEV_DEV(ndev, &pdev->dev);
-#endif
+       SET_NETDEV_DEVTYPE(ndev, &wlan_type);
 
        /* setup the structure members */
        ndev->base_addr = pci_resource_start(pdev, 0);
index c5738f14c4ba21b7a60453ab282309089134bdc2..776aff3678ff23bddda925dfbb48bde925cb7b82 100644 (file)
@@ -2640,7 +2640,7 @@ static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
 
        if (rt2x00_rt(rt2x00dev, RT5392)) {
                rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
-               if (info->default_power1 > POWER_BOUND)
+               if (info->default_power2 > POWER_BOUND)
                        rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND);
                else
                        rt2x00_set_field8(&rfcsr, RFCSR50_TX,
index a0935987fa3a3ca22dfa0298d7bef054408830e6..7f40ab8e1bd809d017d6dff41b68b815c7ade240 100644 (file)
@@ -146,7 +146,7 @@ void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length);
  * @local: frame is not from mac80211
  */
 int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
-                              bool local);
+                              struct ieee80211_sta *sta, bool local);
 
 /**
  * rt2x00queue_update_beacon - Send new beacon from mac80211
index 7c157857f5cee925e796a49396a5843a758a01cd..2183e79783995eea92cb8d8498d0a8582c43c820 100644 (file)
@@ -90,7 +90,7 @@ static int rt2x00mac_tx_rts_cts(struct rt2x00_dev *rt2x00dev,
                                  frag_skb->data, data_length, tx_info,
                                  (struct ieee80211_rts *)(skb->data));
 
-       retval = rt2x00queue_write_tx_frame(queue, skb, true);
+       retval = rt2x00queue_write_tx_frame(queue, skb, NULL, true);
        if (retval) {
                dev_kfree_skb_any(skb);
                rt2x00_warn(rt2x00dev, "Failed to send RTS/CTS frame\n");
@@ -151,7 +151,7 @@ void rt2x00mac_tx(struct ieee80211_hw *hw,
                        goto exit_fail;
        }
 
-       if (unlikely(rt2x00queue_write_tx_frame(queue, skb, false)))
+       if (unlikely(rt2x00queue_write_tx_frame(queue, skb, control->sta, false)))
                goto exit_fail;
 
        /*
index 50590b1420a516863845249c96f689b28e766964..a5d38e8ad9e4925cabd9f90744befd6b9a35d522 100644 (file)
@@ -635,7 +635,7 @@ static void rt2x00queue_bar_check(struct queue_entry *entry)
 }
 
 int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
-                              bool local)
+                              struct ieee80211_sta *sta, bool local)
 {
        struct ieee80211_tx_info *tx_info;
        struct queue_entry *entry;
@@ -649,7 +649,7 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
         * after that we are free to use the skb->cb array
         * for our information.
         */
-       rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, NULL);
+       rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, sta);
 
        /*
         * All information is retrieved from the skb->cb array,
index 9a78e3daf74264fa13f446a4779d342ab6341488..ff784072fb4233a29a46a55bf21d75e094bb8d5c 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <linux/ip.h>
 #include <linux/module.h>
+#include <linux/udp.h>
 
 /*
  *NOTICE!!!: This file will be very big, we should
@@ -1074,64 +1075,52 @@ u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
        if (!ieee80211_is_data(fc))
                return false;
 
+       ip = (const struct iphdr *)(skb->data + mac_hdr_len +
+                                   SNAP_SIZE + PROTOC_TYPE_SIZE);
+       ether_type = be16_to_cpup((__be16 *)
+                                 (skb->data + mac_hdr_len + SNAP_SIZE));
 
-       ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
-                             SNAP_SIZE + PROTOC_TYPE_SIZE);
-       ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
-       /*      ether_type = ntohs(ether_type); */
-
-       if (ETH_P_IP == ether_type) {
-               if (IPPROTO_UDP == ip->protocol) {
-                       struct udphdr *udp = (struct udphdr *)((u8 *) ip +
-                                                              (ip->ihl << 2));
-                       if (((((u8 *) udp)[1] == 68) &&
-                            (((u8 *) udp)[3] == 67)) ||
-                           ((((u8 *) udp)[1] == 67) &&
-                            (((u8 *) udp)[3] == 68))) {
-                               /*
-                                * 68 : UDP BOOTP client
-                                * 67 : UDP BOOTP server
-                                */
-                               RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
-                                        DBG_DMESG, "dhcp %s !!\n",
-                                        is_tx ? "Tx" : "Rx");
-
-                               if (is_tx) {
-                                       rtlpriv->enter_ps = false;
-                                       schedule_work(&rtlpriv->
-                                                     works.lps_change_work);
-                                       ppsc->last_delaylps_stamp_jiffies =
-                                           jiffies;
-                               }
+       switch (ether_type) {
+       case ETH_P_IP: {
+               struct udphdr *udp;
+               u16 src;
+               u16 dst;
 
-                               return true;
-                       }
-               }
-       } else if (ETH_P_ARP == ether_type) {
-               if (is_tx) {
-                       rtlpriv->enter_ps = false;
-                       schedule_work(&rtlpriv->works.lps_change_work);
-                       ppsc->last_delaylps_stamp_jiffies = jiffies;
-               }
+               if (ip->protocol != IPPROTO_UDP)
+                       return false;
+               udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
+               src = be16_to_cpu(udp->source);
+               dst = be16_to_cpu(udp->dest);
 
-               return true;
-       } else if (ETH_P_PAE == ether_type) {
+               /* If this case involves port 68 (UDP BOOTP client) connecting
+                * with port 67 (UDP BOOTP server), then return true so that
+                * the lowest speed is used.
+                */
+               if (!((src == 68 && dst == 67) || (src == 67 && dst == 68)))
+                       return false;
+
+               RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
+                        "dhcp %s !!\n", is_tx ? "Tx" : "Rx");
+               break;
+       }
+       case ETH_P_ARP:
+               break;
+       case ETH_P_PAE:
                RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
                         "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx");
-
-               if (is_tx) {
-                       rtlpriv->enter_ps = false;
-                       schedule_work(&rtlpriv->works.lps_change_work);
-                       ppsc->last_delaylps_stamp_jiffies = jiffies;
-               }
-
-               return true;
-       } else if (ETH_P_IPV6 == ether_type) {
-               /* IPv6 */
-               return true;
+               break;
+       case ETH_P_IPV6:
+               /* TODO: Is this right? */
+               return false;
+       default:
+               return false;
        }
-
-       return false;
+       if (is_tx) {
+               rtlpriv->enter_ps = false;
+               schedule_work(&rtlpriv->works.lps_change_work);
+               ppsc->last_delaylps_stamp_jiffies = jiffies;
+       }
+       return true;
 }
 EXPORT_SYMBOL_GPL(rtl_is_special_data);
 
index ae13fb94b2e8d7b82a259cdc830643cb2e144901..2ffc7298f686ec6002ee54dd210ebc7e8b13b757 100644 (file)
@@ -262,9 +262,9 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
                            sizeof(u8), GFP_ATOMIC);
        if (!efuse_tbl)
                return;
-       efuse_word = kmalloc(EFUSE_MAX_WORD_UNIT * sizeof(u16 *), GFP_ATOMIC);
+       efuse_word = kzalloc(EFUSE_MAX_WORD_UNIT * sizeof(u16 *), GFP_ATOMIC);
        if (!efuse_word)
-               goto done;
+               goto out;
        for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
                efuse_word[i] = kmalloc(efuse_max_section * sizeof(u16),
                                        GFP_ATOMIC);
@@ -378,6 +378,7 @@ done:
        for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++)
                kfree(efuse_word[i]);
        kfree(efuse_word);
+out:
        kfree(efuse_tbl);
 }
 
index 25e50ffc44ec8b42fd35b4ab0b60a08ee09edd7d..b0c346a9e4b8ca8adf9df562ac444d478a3ece57 100644 (file)
@@ -349,7 +349,7 @@ bool rtl92cu_rx_query_desc(struct ieee80211_hw *hw,
                                                 p_drvinfo);
        }
        /*rx_status->qual = stats->signal; */
-       rx_status->signal = stats->rssi + 10;
+       rx_status->signal = stats->recvsignalpower + 10;
        return true;
 }
 
index 945ddecf90c9a3b6c6bcd916c3c1d293ac51dc15..0eb0f4ae592054f7ebf1ee9182169fc57adbc11c 100644 (file)
@@ -525,7 +525,7 @@ bool rtl92de_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
                                                   p_drvinfo);
        }
        /*rx_status->qual = stats->signal; */
-       rx_status->signal = stats->rssi + 10;
+       rx_status->signal = stats->recvsignalpower + 10;
        return true;
 }
 
index 5061f1db3f021072b32a0617385ccb75db427d07..92d38ab3c60e87861f992411e3774aeceed30f56 100644 (file)
@@ -265,7 +265,7 @@ static void _rtl92s_get_txpower_writeval_byregulatory(struct ieee80211_hw *hw,
                                    rtlefuse->pwrgroup_ht40
                                    [RF90_PATH_A][chnl - 1]) {
                                        pwrdiff_limit[i] =
-                                         rtlefuse->pwrgroup_ht20
+                                         rtlefuse->pwrgroup_ht40
                                          [RF90_PATH_A][chnl - 1];
                                }
                        } else {
index 222d2e792ca6d259885fa6da3a8ad792bbb338ad..27efbcdac6a979875976a7a74d1c15e07c1afa49 100644 (file)
@@ -329,7 +329,7 @@ bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
        }
 
        /*rx_status->qual = stats->signal; */
-       rx_status->signal = stats->rssi + 10;
+       rx_status->signal = stats->recvsignalpower + 10;
 
        return true;
 }
index d224dc3bb092b0ef04545cc57891a7bdb4de4b2f..0c65386fa30d5cecda61d9d4ca290b6577df2f59 100644 (file)
 #define RTL_SLOT_TIME_9                                9
 #define RTL_SLOT_TIME_20                       20
 
-/*related with tcp/ip. */
-/*if_ehther.h*/
-#define ETH_P_PAE              0x888E  /*Port Access Entity (IEEE 802.1X) */
-#define ETH_P_IP               0x0800  /*Internet Protocol packet */
-#define ETH_P_ARP              0x0806  /*Address Resolution packet */
+/*related to tcp/ip. */
 #define SNAP_SIZE              6
 #define PROTOC_TYPE_SIZE       2
 
index d85e66979711cbe62a168d9012f1a40ed2d5c405..e59acb1daa2355efd56e4398ab82d0c0f8647ab4 100644 (file)
@@ -277,12 +277,13 @@ static void xennet_alloc_rx_buffers(struct net_device *dev)
                if (!page) {
                        kfree_skb(skb);
 no_skb:
-                       /* Any skbuffs queued for refill? Force them out. */
-                       if (i != 0)
-                               goto refill;
                        /* Could not allocate any skbuffs. Try again later. */
                        mod_timer(&np->rx_refill_timer,
                                  jiffies + (HZ/10));
+
+                       /* Any skbuffs queued for refill? Force them out. */
+                       if (i != 0)
+                               goto refill;
                        break;
                }
 
index 12a9e83c008b402f0f7acde4e80c742c7795348e..d0222f13d154808f3cfa4ed3cab26cd1a7b899ee 100644 (file)
@@ -1034,10 +1034,9 @@ static void ntb_async_rx(struct ntb_queue_entry *entry, void *offset,
        struct dma_chan *chan = qp->dma_chan;
        struct dma_device *device;
        size_t pay_off, buff_off;
-       dma_addr_t src, dest;
+       struct dmaengine_unmap_data *unmap;
        dma_cookie_t cookie;
        void *buf = entry->buf;
-       unsigned long flags;
 
        entry->len = len;
 
@@ -1045,35 +1044,49 @@ static void ntb_async_rx(struct ntb_queue_entry *entry, void *offset,
                goto err;
 
        if (len < copy_bytes) 
-               goto err1;
+               goto err_wait;
 
        device = chan->device;
        pay_off = (size_t) offset & ~PAGE_MASK;
        buff_off = (size_t) buf & ~PAGE_MASK;
 
        if (!is_dma_copy_aligned(device, pay_off, buff_off, len))
-               goto err1;
+               goto err_wait;
 
-       dest = dma_map_single(device->dev, buf, len, DMA_FROM_DEVICE);
-       if (dma_mapping_error(device->dev, dest))
-               goto err1;
+       unmap = dmaengine_get_unmap_data(device->dev, 2, GFP_NOWAIT);
+       if (!unmap)
+               goto err_wait;
 
-       src = dma_map_single(device->dev, offset, len, DMA_TO_DEVICE);
-       if (dma_mapping_error(device->dev, src))
-               goto err2;
+       unmap->len = len;
+       unmap->addr[0] = dma_map_page(device->dev, virt_to_page(offset),
+                                     pay_off, len, DMA_TO_DEVICE);
+       if (dma_mapping_error(device->dev, unmap->addr[0]))
+               goto err_get_unmap;
+
+       unmap->to_cnt = 1;
 
-       flags = DMA_COMPL_DEST_UNMAP_SINGLE | DMA_COMPL_SRC_UNMAP_SINGLE |
-               DMA_PREP_INTERRUPT;
-       txd = device->device_prep_dma_memcpy(chan, dest, src, len, flags);
+       unmap->addr[1] = dma_map_page(device->dev, virt_to_page(buf),
+                                     buff_off, len, DMA_FROM_DEVICE);
+       if (dma_mapping_error(device->dev, unmap->addr[1]))
+               goto err_get_unmap;
+
+       unmap->from_cnt = 1;
+
+       txd = device->device_prep_dma_memcpy(chan, unmap->addr[1],
+                                            unmap->addr[0], len,
+                                            DMA_PREP_INTERRUPT);
        if (!txd)
-               goto err3;
+               goto err_get_unmap;
 
        txd->callback = ntb_rx_copy_callback;
        txd->callback_param = entry;
+       dma_set_unmap(txd, unmap);
 
        cookie = dmaengine_submit(txd);
        if (dma_submit_error(cookie))
-               goto err3;
+               goto err_set_unmap;
+
+       dmaengine_unmap_put(unmap);
 
        qp->last_cookie = cookie;
 
@@ -1081,11 +1094,11 @@ static void ntb_async_rx(struct ntb_queue_entry *entry, void *offset,
 
        return;
 
-err3:
-       dma_unmap_single(device->dev, src, len, DMA_TO_DEVICE);
-err2:
-       dma_unmap_single(device->dev, dest, len, DMA_FROM_DEVICE);
-err1:
+err_set_unmap:
+       dmaengine_unmap_put(unmap);
+err_get_unmap:
+       dmaengine_unmap_put(unmap);
+err_wait:
        /* If the callbacks come out of order, the writing of the index to the
         * last completed will be out of order.  This may result in the
         * receive stalling forever.
@@ -1245,12 +1258,12 @@ static void ntb_async_tx(struct ntb_transport_qp *qp,
        struct dma_chan *chan = qp->dma_chan;
        struct dma_device *device;
        size_t dest_off, buff_off;
-       dma_addr_t src, dest;
+       struct dmaengine_unmap_data *unmap;
+       dma_addr_t dest;
        dma_cookie_t cookie;
        void __iomem *offset;
        size_t len = entry->len;
        void *buf = entry->buf;
-       unsigned long flags;
 
        offset = qp->tx_mw + qp->tx_max_frame * qp->tx_index;
        hdr = offset + qp->tx_max_frame - sizeof(struct ntb_payload_header);
@@ -1273,28 +1286,41 @@ static void ntb_async_tx(struct ntb_transport_qp *qp,
        if (!is_dma_copy_aligned(device, buff_off, dest_off, len))
                goto err;
 
-       src = dma_map_single(device->dev, buf, len, DMA_TO_DEVICE);
-       if (dma_mapping_error(device->dev, src))
+       unmap = dmaengine_get_unmap_data(device->dev, 1, GFP_NOWAIT);
+       if (!unmap)
                goto err;
 
-       flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_PREP_INTERRUPT;
-       txd = device->device_prep_dma_memcpy(chan, dest, src, len, flags);
+       unmap->len = len;
+       unmap->addr[0] = dma_map_page(device->dev, virt_to_page(buf),
+                                     buff_off, len, DMA_TO_DEVICE);
+       if (dma_mapping_error(device->dev, unmap->addr[0]))
+               goto err_get_unmap;
+
+       unmap->to_cnt = 1;
+
+       txd = device->device_prep_dma_memcpy(chan, dest, unmap->addr[0], len,
+                                            DMA_PREP_INTERRUPT);
        if (!txd)
-               goto err1;
+               goto err_get_unmap;
 
        txd->callback = ntb_tx_copy_callback;
        txd->callback_param = entry;
+       dma_set_unmap(txd, unmap);
 
        cookie = dmaengine_submit(txd);
        if (dma_submit_error(cookie))
-               goto err1;
+               goto err_set_unmap;
+
+       dmaengine_unmap_put(unmap);
 
        dma_async_issue_pending(chan);
        qp->tx_async++;
 
        return;
-err1:
-       dma_unmap_single(device->dev, src, len, DMA_TO_DEVICE);
+err_set_unmap:
+       dmaengine_unmap_put(unmap);
+err_get_unmap:
+       dmaengine_unmap_put(unmap);
 err:
        ntb_memcpy_tx(entry, offset);
        qp->tx_memcpy++;
index dc82ef096f3ba61267484057b083caed92748d5b..2872ece81f358df7ff139c143e86d58031485b14 100644 (file)
@@ -31,15 +31,18 @@ menuconfig PARPORT
 
          If unsure, say Y.
 
+config ARCH_MIGHT_HAVE_PC_PARPORT
+       bool
+       help
+         Select this config option from the architecture Kconfig if
+         the architecture might have PC parallel port hardware.
+
 if PARPORT
 
 config PARPORT_PC
        tristate "PC-style hardware"
-       depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV && !S390 && \
-               (!M68K || ISA) && !MN10300 && !AVR32 && !BLACKFIN && \
-               !XTENSA && !CRIS
-
-       ---help---
+       depends on ARCH_MIGHT_HAVE_PC_PARPORT
+       help
          You should say Y here if you have a PC-style parallel port. All
          IBM PC compatible computers and some Alphas have PC-style
          parallel ports.  PA-RISC owners should only say Y here if they
index 1ce8ee054f1aa89ba83fb1001761e9200262a666..a94d850ae228c377387d036fd0f3af7e656130c6 100644 (file)
@@ -367,7 +367,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *pdev, u32 flags)
                string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL };
        }
 
-       handle = DEVICE_ACPI_HANDLE(&pdev->dev);
+       handle = ACPI_HANDLE(&pdev->dev);
        if (!handle) {
                /*
                 * This hotplug controller was not listed in the ACPI name
index 26100f510b1087f45bbe39b79dcf9649acf38e9d..1592dbe4f90461dbfa82be205f334eb0e8ecc6f6 100644 (file)
@@ -176,7 +176,6 @@ u8 acpiphp_get_latch_status(struct acpiphp_slot *slot);
 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot);
 
 /* variables */
-extern bool acpiphp_debug;
 extern bool acpiphp_disabled;
 
 #endif /* _ACPIPHP_H */
index ead7c534095e885572c85c6963d57742dcab7bec..cff7cadfc2e4b27344d79ed479f419a7a012f5e0 100644 (file)
@@ -54,7 +54,7 @@ int pciehp_acpi_slot_detection_check(struct pci_dev *dev)
 {
        if (slot_detection_mode != PCIEHP_DETECT_ACPI)
                return 0;
-       if (acpi_pci_detect_ejectable(DEVICE_ACPI_HANDLE(&dev->dev)))
+       if (acpi_pci_detect_ejectable(ACPI_HANDLE(&dev->dev)))
                return 0;
        return -ENODEV;
 }
@@ -96,7 +96,7 @@ static int __init dummy_probe(struct pcie_device *dev)
                        dup_slot_id++;
        }
        list_add_tail(&slot->list, &dummy_slots);
-       handle = DEVICE_ACPI_HANDLE(&pdev->dev);
+       handle = ACPI_HANDLE(&pdev->dev);
        if (!acpi_slot_detected && acpi_pci_detect_ejectable(handle))
                acpi_slot_detected = 1;
        return -ENODEV;         /* dummy driver always returns error */
index b2781dfe60e9e3cbc79095de46b96f8421958275..5b05a68cca6c73aaf50c7f66ccec5923e4f3d431 100644 (file)
@@ -9,6 +9,7 @@
  * Work to add BIOS PROM support was completed by Mike Habeck.
  */
 
+#include <linux/acpi.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -29,7 +30,6 @@
 #include <asm/sn/sn_feature_sets.h>
 #include <asm/sn/sn_sal.h>
 #include <asm/sn/types.h>
-#include <linux/acpi.h>
 #include <asm/sn/acpi.h>
 
 #include "../pci.h"
@@ -414,7 +414,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
                acpi_handle rethandle;
                acpi_status ret;
 
-               phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
+               phandle = acpi_device_handle(PCI_CONTROLLER(slot->pci_bus)->companion);
 
                if (acpi_bus_get_device(phandle, &pdevice)) {
                        dev_dbg(&slot->pci_bus->self->dev,
@@ -495,7 +495,7 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
 
        /* free the ACPI resources for the slot */
        if (SN_ACPI_BASE_SUPPORT() &&
-            PCI_CONTROLLER(slot->pci_bus)->acpi_handle) {
+            PCI_CONTROLLER(slot->pci_bus)->companion) {
                unsigned long long adr;
                struct acpi_device *device;
                acpi_handle phandle;
@@ -504,7 +504,7 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
                acpi_status ret;
 
                /* Get the rootbus node pointer */
-               phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
+               phandle = acpi_device_handle(PCI_CONTROLLER(slot->pci_bus)->companion);
 
                acpi_scan_lock_acquire();
                /*
index 1b90579b233ae8c2d7db5efe00cc022c42fbb73a..50ce6809829836c38d4aedfa58aeb642b126d9df 100644 (file)
@@ -37,7 +37,7 @@ static int ioapic_probe(struct pci_dev *dev, const struct pci_device_id *ent)
        char *type;
        struct resource *res;
 
-       handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       handle = ACPI_HANDLE(&dev->dev);
        if (!handle)
                return -EINVAL;
 
index dfd1f59de729c6293416d789fb6f665dc09bf701..f166126e28d17ad4b43846beb361d0a5c10fa78e 100644 (file)
@@ -173,14 +173,14 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
 
 static bool acpi_pci_power_manageable(struct pci_dev *dev)
 {
-       acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       acpi_handle handle = ACPI_HANDLE(&dev->dev);
 
        return handle ? acpi_bus_power_manageable(handle) : false;
 }
 
 static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
-       acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       acpi_handle handle = ACPI_HANDLE(&dev->dev);
        static const u8 state_conv[] = {
                [PCI_D0] = ACPI_STATE_D0,
                [PCI_D1] = ACPI_STATE_D1,
@@ -217,7 +217,7 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 
 static bool acpi_pci_can_wakeup(struct pci_dev *dev)
 {
-       acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       acpi_handle handle = ACPI_HANDLE(&dev->dev);
 
        return handle ? acpi_bus_can_wakeup(handle) : false;
 }
index edaed6f4da6cebfbe1c0e2b1b40ac94a039af9dc..d51f45aa669e5ff9184daab1df72776e8165aa84 100644 (file)
@@ -263,7 +263,7 @@ device_has_dsm(struct device *dev)
        acpi_handle handle;
        struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
 
-       handle = DEVICE_ACPI_HANDLE(dev);
+       handle = ACPI_HANDLE(dev);
 
        if (!handle)
                return FALSE;
@@ -295,7 +295,7 @@ acpilabel_show(struct device *dev, struct device_attribute *attr, char *buf)
        acpi_handle handle;
        int length;
 
-       handle = DEVICE_ACPI_HANDLE(dev);
+       handle = ACPI_HANDLE(dev);
 
        if (!handle)
                return -1;
@@ -316,7 +316,7 @@ acpiindex_show(struct device *dev, struct device_attribute *attr, char *buf)
        acpi_handle handle;
        int length;
 
-       handle = DEVICE_ACPI_HANDLE(dev);
+       handle = ACPI_HANDLE(dev);
 
        if (!handle)
                return -1;
index 0846922b2316d0774e4f154aee45256c6019a41a..829b98c5c66fc99da137857847c7048c4e4d1d47 100644 (file)
@@ -1604,6 +1604,9 @@ static inline void pcs_irq_set(struct pcs_soc_data *pcs_soc,
                pcs->write(mask, pcswi->reg);
                raw_spin_unlock(&pcs->lock);
        }
+
+       if (pcs_soc->rearm)
+               pcs_soc->rearm();
 }
 
 /**
@@ -1626,8 +1629,6 @@ static void pcs_irq_unmask(struct irq_data *d)
        struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d);
 
        pcs_irq_set(pcs_soc, d->irq, true);
-       if (pcs_soc->rearm)
-               pcs_soc->rearm();
 }
 
 /**
@@ -1678,11 +1679,6 @@ static int pcs_irq_handle(struct pcs_soc_data *pcs_soc)
                }
        }
 
-       /*
-        * For debugging on omaps, you may want to call pcs_soc->rearm()
-        * here to see wake-up interrupts during runtime also.
-        */
-
        return count;
 }
 
index 605a9be5512907238e520d080c55e4637afcbea0..b9429fbf1cd82a403c65bddd09acc6e11078b66a 100644 (file)
@@ -519,7 +519,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 
        gmux_data->power_state = VGA_SWITCHEROO_ON;
 
-       gmux_data->dhandle = DEVICE_ACPI_HANDLE(&pnp->dev);
+       gmux_data->dhandle = ACPI_HANDLE(&pnp->dev);
        if (!gmux_data->dhandle) {
                pr_err("Cannot find acpi handle for pnp device %s\n",
                       dev_name(&pnp->dev));
index 747826d99059955f8941d592ef2f7734cd38fd08..14655a0f0431b35bd9a0988b669c510a162155e3 100644 (file)
@@ -89,7 +89,7 @@ static int pnpacpi_set_resources(struct pnp_dev *dev)
 
        pnp_dbg(&dev->dev, "set resources\n");
 
-       handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       handle = ACPI_HANDLE(&dev->dev);
        if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
                dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
                return -ENODEV;
@@ -122,7 +122,7 @@ static int pnpacpi_disable_resources(struct pnp_dev *dev)
 
        dev_dbg(&dev->dev, "disable resources\n");
 
-       handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       handle = ACPI_HANDLE(&dev->dev);
        if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
                dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
                return 0;
@@ -144,7 +144,7 @@ static bool pnpacpi_can_wakeup(struct pnp_dev *dev)
        struct acpi_device *acpi_dev;
        acpi_handle handle;
 
-       handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       handle = ACPI_HANDLE(&dev->dev);
        if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
                dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
                return false;
@@ -159,7 +159,7 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
        acpi_handle handle;
        int error = 0;
 
-       handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       handle = ACPI_HANDLE(&dev->dev);
        if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
                dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__);
                return 0;
@@ -194,7 +194,7 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state)
 static int pnpacpi_resume(struct pnp_dev *dev)
 {
        struct acpi_device *acpi_dev;
-       acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
+       acpi_handle handle = ACPI_HANDLE(&dev->dev);
        int error = 0;
 
        if (!handle || acpi_bus_get_device(handle, &acpi_dev)) {
index e6f92b450913e47c490b3481c4c33c537c2526bb..5e2054afe840e9d6412a28c5250f34d1017aa7b2 100644 (file)
@@ -346,6 +346,12 @@ config CHARGER_BQ24190
        help
          Say Y to enable support for the TI BQ24190 battery charger.
 
+config CHARGER_BQ24735
+       tristate "TI BQ24735 battery charger support"
+       depends on I2C && GPIOLIB
+       help
+         Say Y to enable support for the TI BQ24735 battery charger.
+
 config CHARGER_SMB347
        tristate "Summit Microelectronics SMB347 Battery Charger"
        depends on I2C
index a4b74177706f24397f327ee4361c7408bf6b0d90..372b4e8ab59863a89b8de900d5e2de492823dee8 100644 (file)
@@ -52,6 +52,7 @@ obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
 obj-$(CONFIG_CHARGER_MAX8998)  += max8998_charger.o
 obj-$(CONFIG_CHARGER_BQ2415X)  += bq2415x_charger.o
 obj-$(CONFIG_CHARGER_BQ24190)  += bq24190_charger.o
+obj-$(CONFIG_CHARGER_BQ24735)  += bq24735-charger.o
 obj-$(CONFIG_POWER_AVS)                += avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
index a4c4a10b3a41cd2e2e05d67773097cbfed686f8f..19110aa613a13110ba08d8c7cc783ba834f990b7 100644 (file)
@@ -766,7 +766,6 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
                        ret = -ENXIO;
                        break;
                }
-               break;
        case USB_STAT_CARKIT_1:
        case USB_STAT_CARKIT_2:
        case USB_STAT_ACA_DOCK_CHARGER:
@@ -1387,8 +1386,12 @@ static int ab8500_charger_ac_en(struct ux500_charger *charger,
                 * the GPADC module independant of the AB8500 chargers
                 */
                if (!di->vddadc_en_ac) {
-                       regulator_enable(di->regu);
-                       di->vddadc_en_ac = true;
+                       ret = regulator_enable(di->regu);
+                       if (ret)
+                               dev_warn(di->dev,
+                                       "Failed to enable regulator\n");
+                       else
+                               di->vddadc_en_ac = true;
                }
 
                /* Check if the requested voltage or current is valid */
@@ -1556,8 +1559,12 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
                 * the GPADC module independant of the AB8500 chargers
                 */
                if (!di->vddadc_en_usb) {
-                       regulator_enable(di->regu);
-                       di->vddadc_en_usb = true;
+                       ret = regulator_enable(di->regu);
+                       if (ret)
+                               dev_warn(di->dev,
+                                       "Failed to enable regulator\n");
+                       else
+                               di->vddadc_en_usb = true;
                }
 
                /* Enable USB charging */
index 0727f9256138589cf0184756b46adc5f216df4bd..df893dd1447d1534695ace9405e4783ec49fd79d 100644 (file)
@@ -605,9 +605,13 @@ static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq,
 {
        int val = (mV/10 - 350) / 2;
 
+       /*
+        * According to datasheet, maximum battery regulation voltage is
+        * 4440mV which is b101111 = 47.
+        */
        if (val < 0)
                val = 0;
-       else if (val > 94) /* FIXME: Max is 94 or 122 ? Set max value ? */
+       else if (val > 47)
                return -EINVAL;
 
        return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val,
diff --git a/drivers/power/bq24735-charger.c b/drivers/power/bq24735-charger.c
new file mode 100644 (file)
index 0000000..d022b82
--- /dev/null
@@ -0,0 +1,419 @@
+/*
+ * Battery charger driver for TI BQ24735
+ *
+ * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/power_supply.h>
+#include <linux/slab.h>
+
+#include <linux/power/bq24735-charger.h>
+
+#define BQ24735_CHG_OPT                        0x12
+#define BQ24735_CHG_OPT_CHARGE_DISABLE (1 << 0)
+#define BQ24735_CHG_OPT_AC_PRESENT     (1 << 4)
+#define BQ24735_CHARGE_CURRENT         0x14
+#define BQ24735_CHARGE_CURRENT_MASK    0x1fc0
+#define BQ24735_CHARGE_VOLTAGE         0x15
+#define BQ24735_CHARGE_VOLTAGE_MASK    0x7ff0
+#define BQ24735_INPUT_CURRENT          0x3f
+#define BQ24735_INPUT_CURRENT_MASK     0x1f80
+#define BQ24735_MANUFACTURER_ID                0xfe
+#define BQ24735_DEVICE_ID              0xff
+
+struct bq24735 {
+       struct power_supply     charger;
+       struct i2c_client       *client;
+       struct bq24735_platform *pdata;
+};
+
+static inline struct bq24735 *to_bq24735(struct power_supply *psy)
+{
+       return container_of(psy, struct bq24735, charger);
+}
+
+static enum power_supply_property bq24735_charger_properties[] = {
+       POWER_SUPPLY_PROP_ONLINE,
+};
+
+static inline int bq24735_write_word(struct i2c_client *client, u8 reg,
+                                    u16 value)
+{
+       return i2c_smbus_write_word_data(client, reg, le16_to_cpu(value));
+}
+
+static inline int bq24735_read_word(struct i2c_client *client, u8 reg)
+{
+       s32 ret = i2c_smbus_read_word_data(client, reg);
+
+       return ret < 0 ? ret : le16_to_cpu(ret);
+}
+
+static int bq24735_update_word(struct i2c_client *client, u8 reg,
+                              u16 mask, u16 value)
+{
+       unsigned int tmp;
+       int ret;
+
+       ret = bq24735_read_word(client, reg);
+       if (ret < 0)
+               return ret;
+
+       tmp = ret & ~mask;
+       tmp |= value & mask;
+
+       return bq24735_write_word(client, reg, tmp);
+}
+
+static inline int bq24735_enable_charging(struct bq24735 *charger)
+{
+       return bq24735_update_word(charger->client, BQ24735_CHG_OPT,
+                                  BQ24735_CHG_OPT_CHARGE_DISABLE,
+                                  ~BQ24735_CHG_OPT_CHARGE_DISABLE);
+}
+
+static inline int bq24735_disable_charging(struct bq24735 *charger)
+{
+       return bq24735_update_word(charger->client, BQ24735_CHG_OPT,
+                                  BQ24735_CHG_OPT_CHARGE_DISABLE,
+                                  BQ24735_CHG_OPT_CHARGE_DISABLE);
+}
+
+static int bq24735_config_charger(struct bq24735 *charger)
+{
+       struct bq24735_platform *pdata = charger->pdata;
+       int ret;
+       u16 value;
+
+       if (pdata->charge_current) {
+               value = pdata->charge_current & BQ24735_CHARGE_CURRENT_MASK;
+
+               ret = bq24735_write_word(charger->client,
+                                        BQ24735_CHARGE_CURRENT, value);
+               if (ret < 0) {
+                       dev_err(&charger->client->dev,
+                               "Failed to write charger current : %d\n",
+                               ret);
+                       return ret;
+               }
+       }
+
+       if (pdata->charge_voltage) {
+               value = pdata->charge_voltage & BQ24735_CHARGE_VOLTAGE_MASK;
+
+               ret = bq24735_write_word(charger->client,
+                                        BQ24735_CHARGE_VOLTAGE, value);
+               if (ret < 0) {
+                       dev_err(&charger->client->dev,
+                               "Failed to write charger voltage : %d\n",
+                               ret);
+                       return ret;
+               }
+       }
+
+       if (pdata->input_current) {
+               value = pdata->input_current & BQ24735_INPUT_CURRENT_MASK;
+
+               ret = bq24735_write_word(charger->client,
+                                        BQ24735_INPUT_CURRENT, value);
+               if (ret < 0) {
+                       dev_err(&charger->client->dev,
+                               "Failed to write input current : %d\n",
+                               ret);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+static bool bq24735_charger_is_present(struct bq24735 *charger)
+{
+       struct bq24735_platform *pdata = charger->pdata;
+       int ret;
+
+       if (pdata->status_gpio_valid) {
+               ret = gpio_get_value_cansleep(pdata->status_gpio);
+               return ret ^= pdata->status_gpio_active_low == 0;
+       } else {
+               int ac = 0;
+
+               ac = bq24735_read_word(charger->client, BQ24735_CHG_OPT);
+               if (ac < 0) {
+                       dev_err(&charger->client->dev,
+                               "Failed to read charger options : %d\n",
+                               ac);
+                       return false;
+               }
+               return (ac & BQ24735_CHG_OPT_AC_PRESENT) ? true : false;
+       }
+
+       return false;
+}
+
+static irqreturn_t bq24735_charger_isr(int irq, void *devid)
+{
+       struct power_supply *psy = devid;
+       struct bq24735 *charger = to_bq24735(psy);
+
+       if (bq24735_charger_is_present(charger))
+               bq24735_enable_charging(charger);
+       else
+               bq24735_disable_charging(charger);
+
+       power_supply_changed(psy);
+
+       return IRQ_HANDLED;
+}
+
+static int bq24735_charger_get_property(struct power_supply *psy,
+                                       enum power_supply_property psp,
+                                       union power_supply_propval *val)
+{
+       struct bq24735 *charger;
+
+       charger = container_of(psy, struct bq24735, charger);
+
+       switch (psp) {
+       case POWER_SUPPLY_PROP_ONLINE:
+               val->intval = bq24735_charger_is_present(charger) ? 1 : 0;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct bq24735_platform *bq24735_parse_dt_data(struct i2c_client *client)
+{
+       struct bq24735_platform *pdata;
+       struct device_node *np = client->dev.of_node;
+       u32 val;
+       int ret;
+       enum of_gpio_flags flags;
+
+       pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata) {
+               dev_err(&client->dev,
+                       "Memory alloc for bq24735 pdata failed\n");
+               return NULL;
+       }
+
+       pdata->status_gpio = of_get_named_gpio_flags(np, "ti,ac-detect-gpios",
+                                                    0, &flags);
+
+       if (flags & OF_GPIO_ACTIVE_LOW)
+               pdata->status_gpio_active_low = 1;
+
+       ret = of_property_read_u32(np, "ti,charge-current", &val);
+       if (!ret)
+               pdata->charge_current = val;
+
+       ret = of_property_read_u32(np, "ti,charge-voltage", &val);
+       if (!ret)
+               pdata->charge_voltage = val;
+
+       ret = of_property_read_u32(np, "ti,input-current", &val);
+       if (!ret)
+               pdata->input_current = val;
+
+       return pdata;
+}
+
+static int bq24735_charger_probe(struct i2c_client *client,
+                                const struct i2c_device_id *id)
+{
+       int ret;
+       struct bq24735 *charger;
+       struct power_supply *supply;
+       char *name;
+
+       charger = devm_kzalloc(&client->dev, sizeof(*charger), GFP_KERNEL);
+       if (!charger)
+               return -ENOMEM;
+
+       charger->pdata = client->dev.platform_data;
+
+       if (IS_ENABLED(CONFIG_OF) && !charger->pdata && client->dev.of_node)
+               charger->pdata = bq24735_parse_dt_data(client);
+
+       if (!charger->pdata) {
+               dev_err(&client->dev, "no platform data provided\n");
+               return -EINVAL;
+       }
+
+       name = (char *)charger->pdata->name;
+       if (!name) {
+               name = kasprintf(GFP_KERNEL, "bq24735@%s",
+                                dev_name(&client->dev));
+               if (!name) {
+                       dev_err(&client->dev, "Failed to alloc device name\n");
+                       return -ENOMEM;
+               }
+       }
+
+       charger->client = client;
+
+       supply = &charger->charger;
+
+       supply->name = name;
+       supply->type = POWER_SUPPLY_TYPE_MAINS;
+       supply->properties = bq24735_charger_properties;
+       supply->num_properties = ARRAY_SIZE(bq24735_charger_properties);
+       supply->get_property = bq24735_charger_get_property;
+       supply->supplied_to = charger->pdata->supplied_to;
+       supply->num_supplicants = charger->pdata->num_supplicants;
+       supply->of_node = client->dev.of_node;
+
+       i2c_set_clientdata(client, charger);
+
+       ret = bq24735_read_word(client, BQ24735_MANUFACTURER_ID);
+       if (ret < 0) {
+               dev_err(&client->dev, "Failed to read manufacturer id : %d\n",
+                       ret);
+               goto err_free_name;
+       } else if (ret != 0x0040) {
+               dev_err(&client->dev,
+                       "manufacturer id mismatch. 0x0040 != 0x%04x\n", ret);
+               ret = -ENODEV;
+               goto err_free_name;
+       }
+
+       ret = bq24735_read_word(client, BQ24735_DEVICE_ID);
+       if (ret < 0) {
+               dev_err(&client->dev, "Failed to read device id : %d\n", ret);
+               goto err_free_name;
+       } else if (ret != 0x000B) {
+               dev_err(&client->dev,
+                       "device id mismatch. 0x000b != 0x%04x\n", ret);
+               ret = -ENODEV;
+               goto err_free_name;
+       }
+
+       if (gpio_is_valid(charger->pdata->status_gpio)) {
+               ret = devm_gpio_request(&client->dev,
+                                       charger->pdata->status_gpio,
+                                       name);
+               if (ret) {
+                       dev_err(&client->dev,
+                               "Failed GPIO request for GPIO %d: %d\n",
+                               charger->pdata->status_gpio, ret);
+               }
+
+               charger->pdata->status_gpio_valid = !ret;
+       }
+
+       ret = bq24735_config_charger(charger);
+       if (ret < 0) {
+               dev_err(&client->dev, "failed in configuring charger");
+               goto err_free_name;
+       }
+
+       /* check for AC adapter presence */
+       if (bq24735_charger_is_present(charger)) {
+               ret = bq24735_enable_charging(charger);
+               if (ret < 0) {
+                       dev_err(&client->dev, "Failed to enable charging\n");
+                       goto err_free_name;
+               }
+       }
+
+       ret = power_supply_register(&client->dev, supply);
+       if (ret < 0) {
+               dev_err(&client->dev, "Failed to register power supply: %d\n",
+                       ret);
+               goto err_free_name;
+       }
+
+       if (client->irq) {
+               ret = devm_request_threaded_irq(&client->dev, client->irq,
+                                               NULL, bq24735_charger_isr,
+                                               IRQF_TRIGGER_RISING |
+                                               IRQF_TRIGGER_FALLING |
+                                               IRQF_ONESHOT,
+                                               supply->name, supply);
+               if (ret) {
+                       dev_err(&client->dev,
+                               "Unable to register IRQ %d err %d\n",
+                               client->irq, ret);
+                       goto err_unregister_supply;
+               }
+       }
+
+       return 0;
+err_unregister_supply:
+       power_supply_unregister(supply);
+err_free_name:
+       if (name != charger->pdata->name)
+               kfree(name);
+
+       return ret;
+}
+
+static int bq24735_charger_remove(struct i2c_client *client)
+{
+       struct bq24735 *charger = i2c_get_clientdata(client);
+
+       if (charger->client->irq)
+               devm_free_irq(&charger->client->dev, charger->client->irq,
+                             &charger->charger);
+
+       power_supply_unregister(&charger->charger);
+
+       if (charger->charger.name != charger->pdata->name)
+               kfree(charger->charger.name);
+
+       return 0;
+}
+
+static const struct i2c_device_id bq24735_charger_id[] = {
+       { "bq24735-charger", 0 },
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, bq24735_charger_id);
+
+static const struct of_device_id bq24735_match_ids[] = {
+       { .compatible = "ti,bq24735", },
+       { /* end */ }
+};
+MODULE_DEVICE_TABLE(of, bq24735_match_ids);
+
+static struct i2c_driver bq24735_charger_driver = {
+       .driver = {
+               .name = "bq24735-charger",
+               .owner = THIS_MODULE,
+               .of_match_table = bq24735_match_ids,
+       },
+       .probe = bq24735_charger_probe,
+       .remove = bq24735_charger_remove,
+       .id_table = bq24735_charger_id,
+};
+
+module_i2c_driver(bq24735_charger_driver);
+
+MODULE_DESCRIPTION("bq24735 battery charging driver");
+MODULE_AUTHOR("Darbha Sriharsha <dsriharsha@nvidia.com>");
+MODULE_LICENSE("GPL v2");
index e30e847600bb69c71519b7e1325286830e504c53..7287c0efd6bfc5e2a877d322c82cf4dae0e68b7a 100644 (file)
@@ -1378,7 +1378,8 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
                charger = &desc->charger_regulators[i];
 
                snprintf(buf, 10, "charger.%d", i);
-               str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
+               str = devm_kzalloc(cm->dev,
+                               sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
                if (!str) {
                        ret = -ENOMEM;
                        goto err;
@@ -1452,30 +1453,23 @@ static int charger_manager_probe(struct platform_device *pdev)
                        rtc_dev = NULL;
                        dev_err(&pdev->dev, "Cannot get RTC %s\n",
                                g_desc->rtc_name);
-                       ret = -ENODEV;
-                       goto err_alloc;
+                       return -ENODEV;
                }
        }
 
        if (!desc) {
                dev_err(&pdev->dev, "No platform data (desc) found\n");
-               ret = -ENODEV;
-               goto err_alloc;
+               return -ENODEV;
        }
 
-       cm = kzalloc(sizeof(struct charger_manager), GFP_KERNEL);
-       if (!cm) {
-               ret = -ENOMEM;
-               goto err_alloc;
-       }
+       cm = devm_kzalloc(&pdev->dev,
+                       sizeof(struct charger_manager), GFP_KERNEL);
+       if (!cm)
+               return -ENOMEM;
 
        /* Basic Values. Unspecified are Null or 0 */
        cm->dev = &pdev->dev;
-       cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL);
-       if (!cm->desc) {
-               ret = -ENOMEM;
-               goto err_alloc_desc;
-       }
+       cm->desc = desc;
        cm->last_temp_mC = INT_MIN; /* denotes "unmeasured, yet" */
 
        /*
@@ -1498,27 +1492,23 @@ static int charger_manager_probe(struct platform_device *pdev)
        }
 
        if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
-               ret = -EINVAL;
                dev_err(&pdev->dev, "charger_regulators undefined\n");
-               goto err_no_charger;
+               return -EINVAL;
        }
 
        if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) {
                dev_err(&pdev->dev, "No power supply defined\n");
-               ret = -EINVAL;
-               goto err_no_charger_stat;
+               return -EINVAL;
        }
 
        /* Counting index only */
        while (desc->psy_charger_stat[i])
                i++;
 
-       cm->charger_stat = kzalloc(sizeof(struct power_supply *) * (i + 1),
-                                  GFP_KERNEL);
-       if (!cm->charger_stat) {
-               ret = -ENOMEM;
-               goto err_no_charger_stat;
-       }
+       cm->charger_stat = devm_kzalloc(&pdev->dev,
+                               sizeof(struct power_supply *) * i, GFP_KERNEL);
+       if (!cm->charger_stat)
+               return -ENOMEM;
 
        for (i = 0; desc->psy_charger_stat[i]; i++) {
                cm->charger_stat[i] = power_supply_get_by_name(
@@ -1526,8 +1516,7 @@ static int charger_manager_probe(struct platform_device *pdev)
                if (!cm->charger_stat[i]) {
                        dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
                                desc->psy_charger_stat[i]);
-                       ret = -ENODEV;
-                       goto err_chg_stat;
+                       return -ENODEV;
                }
        }
 
@@ -1535,21 +1524,18 @@ static int charger_manager_probe(struct platform_device *pdev)
        if (!cm->fuel_gauge) {
                dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
                        desc->psy_fuel_gauge);
-               ret = -ENODEV;
-               goto err_chg_stat;
+               return -ENODEV;
        }
 
        if (desc->polling_interval_ms == 0 ||
            msecs_to_jiffies(desc->polling_interval_ms) <= CM_JIFFIES_SMALL) {
                dev_err(&pdev->dev, "polling_interval_ms is too small\n");
-               ret = -EINVAL;
-               goto err_chg_stat;
+               return -EINVAL;
        }
 
        if (!desc->temperature_out_of_range) {
                dev_err(&pdev->dev, "there is no temperature_out_of_range\n");
-               ret = -EINVAL;
-               goto err_chg_stat;
+               return -EINVAL;
        }
 
        if (!desc->charging_max_duration_ms ||
@@ -1570,14 +1556,13 @@ static int charger_manager_probe(struct platform_device *pdev)
        cm->charger_psy.name = cm->psy_name_buf;
 
        /* Allocate for psy properties because they may vary */
-       cm->charger_psy.properties = kzalloc(sizeof(enum power_supply_property)
+       cm->charger_psy.properties = devm_kzalloc(&pdev->dev,
+                               sizeof(enum power_supply_property)
                                * (ARRAY_SIZE(default_charger_props) +
-                               NUM_CHARGER_PSY_OPTIONAL),
-                               GFP_KERNEL);
-       if (!cm->charger_psy.properties) {
-               ret = -ENOMEM;
-               goto err_chg_stat;
-       }
+                               NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
+       if (!cm->charger_psy.properties)
+               return -ENOMEM;
+
        memcpy(cm->charger_psy.properties, default_charger_props,
                sizeof(enum power_supply_property) *
                ARRAY_SIZE(default_charger_props));
@@ -1614,7 +1599,7 @@ static int charger_manager_probe(struct platform_device *pdev)
        if (ret) {
                dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
                        cm->charger_psy.name);
-               goto err_register;
+               return ret;
        }
 
        /* Register extcon device for charger cable */
@@ -1655,8 +1640,6 @@ err_reg_sysfs:
                charger = &desc->charger_regulators[i];
                sysfs_remove_group(&cm->charger_psy.dev->kobj,
                                &charger->attr_g);
-
-               kfree(charger->attr_g.name);
        }
 err_reg_extcon:
        for (i = 0; i < desc->num_charger_regulators; i++) {
@@ -1674,16 +1657,7 @@ err_reg_extcon:
        }
 
        power_supply_unregister(&cm->charger_psy);
-err_register:
-       kfree(cm->charger_psy.properties);
-err_chg_stat:
-       kfree(cm->charger_stat);
-err_no_charger_stat:
-err_no_charger:
-       kfree(cm->desc);
-err_alloc_desc:
-       kfree(cm);
-err_alloc:
+
        return ret;
 }
 
@@ -1718,11 +1692,6 @@ static int charger_manager_remove(struct platform_device *pdev)
 
        try_charger_enable(cm, false);
 
-       kfree(cm->charger_psy.properties);
-       kfree(cm->charger_stat);
-       kfree(cm->desc);
-       kfree(cm);
-
        return 0;
 }
 
index fc04d191579bd987ba0ad94ddd6b298c329c2b18..1bb3a91b1acc2eb376d6460006218a7b1f4e1e76 100644 (file)
@@ -2,6 +2,7 @@
  * ISP1704 USB Charger Detection driver
  *
  * Copyright (C) 2010 Nokia Corporation
+ * Copyright (C) 2012 - 2013 Pali Rohár <pali.rohar@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -65,10 +66,6 @@ struct isp1704_charger {
        unsigned                present:1;
        unsigned                online:1;
        unsigned                current_max;
-
-       /* temp storage variables */
-       unsigned long           event;
-       unsigned                max_power;
 };
 
 static inline int isp1704_read(struct isp1704_charger *isp, u32 reg)
@@ -231,56 +228,59 @@ static inline int isp1704_charger_detect(struct isp1704_charger *isp)
        return ret;
 }
 
+static inline int isp1704_charger_detect_dcp(struct isp1704_charger *isp)
+{
+       if (isp1704_charger_detect(isp) &&
+                       isp1704_charger_type(isp) == POWER_SUPPLY_TYPE_USB_DCP)
+               return true;
+       else
+               return false;
+}
+
 static void isp1704_charger_work(struct work_struct *data)
 {
-       int                     detect;
-       unsigned long           event;
-       unsigned                power;
        struct isp1704_charger  *isp =
                container_of(data, struct isp1704_charger, work);
        static DEFINE_MUTEX(lock);
 
-       event = isp->event;
-       power = isp->max_power;
-
        mutex_lock(&lock);
 
-       if (event != USB_EVENT_NONE)
-               isp1704_charger_set_power(isp, 1);
-
-       switch (event) {
+       switch (isp->phy->last_event) {
        case USB_EVENT_VBUS:
-               isp->online = true;
+               /* do not call wall charger detection more times */
+               if (!isp->present) {
+                       isp->online = true;
+                       isp->present = 1;
+                       isp1704_charger_set_power(isp, 1);
+
+                       /* detect wall charger */
+                       if (isp1704_charger_detect_dcp(isp)) {
+                               isp->psy.type = POWER_SUPPLY_TYPE_USB_DCP;
+                               isp->current_max = 1800;
+                       } else {
+                               isp->psy.type = POWER_SUPPLY_TYPE_USB;
+                               isp->current_max = 500;
+                       }
 
-               /* detect charger */
-               detect = isp1704_charger_detect(isp);
-
-               if (detect) {
-                       isp->present = detect;
-                       isp->psy.type = isp1704_charger_type(isp);
+                       /* enable data pullups */
+                       if (isp->phy->otg->gadget)
+                               usb_gadget_connect(isp->phy->otg->gadget);
                }
 
-               switch (isp->psy.type) {
-               case POWER_SUPPLY_TYPE_USB_DCP:
-                       isp->current_max = 1800;
-                       break;
-               case POWER_SUPPLY_TYPE_USB_CDP:
+               if (isp->psy.type != POWER_SUPPLY_TYPE_USB_DCP) {
                        /*
                         * Only 500mA here or high speed chirp
                         * handshaking may break
                         */
-                       isp->current_max = 500;
-                       /* FALLTHROUGH */
-               case POWER_SUPPLY_TYPE_USB:
-               default:
-                       /* enable data pullups */
-                       if (isp->phy->otg->gadget)
-                               usb_gadget_connect(isp->phy->otg->gadget);
+                       if (isp->current_max > 500)
+                               isp->current_max = 500;
+
+                       if (isp->current_max > 100)
+                               isp->psy.type = POWER_SUPPLY_TYPE_USB_CDP;
                }
                break;
        case USB_EVENT_NONE:
                isp->online = false;
-               isp->current_max = 0;
                isp->present = 0;
                isp->current_max = 0;
                isp->psy.type = POWER_SUPPLY_TYPE_USB;
@@ -298,12 +298,6 @@ static void isp1704_charger_work(struct work_struct *data)
 
                isp1704_charger_set_power(isp, 0);
                break;
-       case USB_EVENT_ENUMERATED:
-               if (isp->present)
-                       isp->current_max = 1800;
-               else
-                       isp->current_max = power;
-               break;
        default:
                goto out;
        }
@@ -314,16 +308,11 @@ out:
 }
 
 static int isp1704_notifier_call(struct notifier_block *nb,
-               unsigned long event, void *power)
+               unsigned long val, void *v)
 {
        struct isp1704_charger *isp =
                container_of(nb, struct isp1704_charger, nb);
 
-       isp->event = event;
-
-       if (power)
-               isp->max_power = *((unsigned *)power);
-
        schedule_work(&isp->work);
 
        return NOTIFY_OK;
@@ -462,13 +451,13 @@ static int isp1704_charger_probe(struct platform_device *pdev)
        if (isp->phy->otg->gadget)
                usb_gadget_disconnect(isp->phy->otg->gadget);
 
+       if (isp->phy->last_event == USB_EVENT_NONE)
+               isp1704_charger_set_power(isp, 0);
+
        /* Detect charger if VBUS is valid (the cable was already plugged). */
-       ret = isp1704_read(isp, ULPI_USB_INT_STS);
-       isp1704_charger_set_power(isp, 0);
-       if ((ret & ULPI_INT_VBUS_VALID) && !isp->phy->otg->default_a) {
-               isp->event = USB_EVENT_VBUS;
+       if (isp->phy->last_event == USB_EVENT_VBUS &&
+                       !isp->phy->otg->default_a)
                schedule_work(&isp->work);
-       }
 
        return 0;
 fail2:
index d664ef58afa7d0ffd34d03e89444cd015f31ab7d..e0b22f9b6fdd643edd124d3940025636924d0dc3 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/power_supply.h>
 #include <linux/power/max17042_battery.h>
 #include <linux/of.h>
+#include <linux/regmap.h>
 
 /* Status register bits */
 #define STATUS_POR_BIT         (1 << 1)
@@ -67,6 +68,7 @@
 
 struct max17042_chip {
        struct i2c_client *client;
+       struct regmap *regmap;
        struct power_supply battery;
        enum max170xx_chip_type chip_type;
        struct max17042_platform_data *pdata;
@@ -74,35 +76,6 @@ struct max17042_chip {
        int    init_complete;
 };
 
-static int max17042_write_reg(struct i2c_client *client, u8 reg, u16 value)
-{
-       int ret = i2c_smbus_write_word_data(client, reg, value);
-
-       if (ret < 0)
-               dev_err(&client->dev, "%s: err %d\n", __func__, ret);
-
-       return ret;
-}
-
-static int max17042_read_reg(struct i2c_client *client, u8 reg)
-{
-       int ret = i2c_smbus_read_word_data(client, reg);
-
-       if (ret < 0)
-               dev_err(&client->dev, "%s: err %d\n", __func__, ret);
-
-       return ret;
-}
-
-static void max17042_set_reg(struct i2c_client *client,
-                            struct max17042_reg_data *data, int size)
-{
-       int i;
-
-       for (i = 0; i < size; i++)
-               max17042_write_reg(client, data[i].addr, data[i].data);
-}
-
 static enum power_supply_property max17042_battery_props[] = {
        POWER_SUPPLY_PROP_PRESENT,
        POWER_SUPPLY_PROP_CYCLE_COUNT,
@@ -125,96 +98,98 @@ static int max17042_get_property(struct power_supply *psy,
 {
        struct max17042_chip *chip = container_of(psy,
                                struct max17042_chip, battery);
+       struct regmap *map = chip->regmap;
        int ret;
+       u32 data;
 
        if (!chip->init_complete)
                return -EAGAIN;
 
        switch (psp) {
        case POWER_SUPPLY_PROP_PRESENT:
-               ret = max17042_read_reg(chip->client, MAX17042_STATUS);
+               ret = regmap_read(map, MAX17042_STATUS, &data);
                if (ret < 0)
                        return ret;
 
-               if (ret & MAX17042_STATUS_BattAbsent)
+               if (data & MAX17042_STATUS_BattAbsent)
                        val->intval = 0;
                else
                        val->intval = 1;
                break;
        case POWER_SUPPLY_PROP_CYCLE_COUNT:
-               ret = max17042_read_reg(chip->client, MAX17042_Cycles);
+               ret = regmap_read(map, MAX17042_Cycles, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret;
+               val->intval = data;
                break;
        case POWER_SUPPLY_PROP_VOLTAGE_MAX:
-               ret = max17042_read_reg(chip->client, MAX17042_MinMaxVolt);
+               ret = regmap_read(map, MAX17042_MinMaxVolt, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret >> 8;
+               val->intval = data >> 8;
                val->intval *= 20000; /* Units of LSB = 20mV */
                break;
        case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
                if (chip->chip_type == MAX17042)
-                       ret = max17042_read_reg(chip->client, MAX17042_V_empty);
+                       ret = regmap_read(map, MAX17042_V_empty, &data);
                else
-                       ret = max17042_read_reg(chip->client, MAX17047_V_empty);
+                       ret = regmap_read(map, MAX17047_V_empty, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret >> 7;
+               val->intval = data >> 7;
                val->intval *= 10000; /* Units of LSB = 10mV */
                break;
        case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-               ret = max17042_read_reg(chip->client, MAX17042_VCELL);
+               ret = regmap_read(map, MAX17042_VCELL, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret * 625 / 8;
+               val->intval = data * 625 / 8;
                break;
        case POWER_SUPPLY_PROP_VOLTAGE_AVG:
-               ret = max17042_read_reg(chip->client, MAX17042_AvgVCELL);
+               ret = regmap_read(map, MAX17042_AvgVCELL, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret * 625 / 8;
+               val->intval = data * 625 / 8;
                break;
        case POWER_SUPPLY_PROP_VOLTAGE_OCV:
-               ret = max17042_read_reg(chip->client, MAX17042_OCVInternal);
+               ret = regmap_read(map, MAX17042_OCVInternal, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret * 625 / 8;
+               val->intval = data * 625 / 8;
                break;
        case POWER_SUPPLY_PROP_CAPACITY:
-               ret = max17042_read_reg(chip->client, MAX17042_RepSOC);
+               ret = regmap_read(map, MAX17042_RepSOC, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret >> 8;
+               val->intval = data >> 8;
                break;
        case POWER_SUPPLY_PROP_CHARGE_FULL:
-               ret = max17042_read_reg(chip->client, MAX17042_FullCAP);
+               ret = regmap_read(map, MAX17042_FullCAP, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret * 1000 / 2;
+               val->intval = data * 1000 / 2;
                break;
        case POWER_SUPPLY_PROP_CHARGE_COUNTER:
-               ret = max17042_read_reg(chip->client, MAX17042_QH);
+               ret = regmap_read(map, MAX17042_QH, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret * 1000 / 2;
+               val->intval = data * 1000 / 2;
                break;
        case POWER_SUPPLY_PROP_TEMP:
-               ret = max17042_read_reg(chip->client, MAX17042_TEMP);
+               ret = regmap_read(map, MAX17042_TEMP, &data);
                if (ret < 0)
                        return ret;
 
-               val->intval = ret;
+               val->intval = data;
                /* The value is signed. */
                if (val->intval & 0x8000) {
                        val->intval = (0x7fff & ~val->intval) + 1;
@@ -226,11 +201,11 @@ static int max17042_get_property(struct power_supply *psy,
                break;
        case POWER_SUPPLY_PROP_CURRENT_NOW:
                if (chip->pdata->enable_current_sense) {
-                       ret = max17042_read_reg(chip->client, MAX17042_Current);
+                       ret = regmap_read(map, MAX17042_Current, &data);
                        if (ret < 0)
                                return ret;
 
-                       val->intval = ret;
+                       val->intval = data;
                        if (val->intval & 0x8000) {
                                /* Negative */
                                val->intval = ~val->intval & 0x7fff;
@@ -244,12 +219,11 @@ static int max17042_get_property(struct power_supply *psy,
                break;
        case POWER_SUPPLY_PROP_CURRENT_AVG:
                if (chip->pdata->enable_current_sense) {
-                       ret = max17042_read_reg(chip->client,
-                                               MAX17042_AvgCurrent);
+                       ret = regmap_read(map, MAX17042_AvgCurrent, &data);
                        if (ret < 0)
                                return ret;
 
-                       val->intval = ret;
+                       val->intval = data;
                        if (val->intval & 0x8000) {
                                /* Negative */
                                val->intval = ~val->intval & 0x7fff;
@@ -267,16 +241,15 @@ static int max17042_get_property(struct power_supply *psy,
        return 0;
 }
 
-static int max17042_write_verify_reg(struct i2c_client *client,
-                               u8 reg, u16 value)
+static int max17042_write_verify_reg(struct regmap *map, u8 reg, u32 value)
 {
        int retries = 8;
        int ret;
-       u16 read_value;
+       u32 read_value;
 
        do {
-               ret = i2c_smbus_write_word_data(client, reg, value);
-               read_value =  max17042_read_reg(client, reg);
+               ret = regmap_write(map, reg, value);
+               regmap_read(map, reg, &read_value);
                if (read_value != value) {
                        ret = -EIO;
                        retries--;
@@ -284,50 +257,51 @@ static int max17042_write_verify_reg(struct i2c_client *client,
        } while (retries && read_value != value);
 
        if (ret < 0)
-               dev_err(&client->dev, "%s: err %d\n", __func__, ret);
+               pr_err("%s: err %d\n", __func__, ret);
 
        return ret;
 }
 
-static inline void max17042_override_por(
-       struct i2c_client *client, u8 reg, u16 value)
+static inline void max17042_override_por(struct regmap *map,
+                                        u8 reg, u16 value)
 {
        if (value)
-               max17042_write_reg(client, reg, value);
+               regmap_write(map, reg, value);
 }
 
 static inline void max10742_unlock_model(struct max17042_chip *chip)
 {
-       struct i2c_client *client = chip->client;
-       max17042_write_reg(client, MAX17042_MLOCKReg1, MODEL_UNLOCK1);
-       max17042_write_reg(client, MAX17042_MLOCKReg2, MODEL_UNLOCK2);
+       struct regmap *map = chip->regmap;
+       regmap_write(map, MAX17042_MLOCKReg1, MODEL_UNLOCK1);
+       regmap_write(map, MAX17042_MLOCKReg2, MODEL_UNLOCK2);
 }
 
 static inline void max10742_lock_model(struct max17042_chip *chip)
 {
-       struct i2c_client *client = chip->client;
-       max17042_write_reg(client, MAX17042_MLOCKReg1, MODEL_LOCK1);
-       max17042_write_reg(client, MAX17042_MLOCKReg2, MODEL_LOCK2);
+       struct regmap *map = chip->regmap;
+
+       regmap_write(map, MAX17042_MLOCKReg1, MODEL_LOCK1);
+       regmap_write(map, MAX17042_MLOCKReg2, MODEL_LOCK2);
 }
 
 static inline void max17042_write_model_data(struct max17042_chip *chip,
                                        u8 addr, int size)
 {
-       struct i2c_client *client = chip->client;
+       struct regmap *map = chip->regmap;
        int i;
        for (i = 0; i < size; i++)
-               max17042_write_reg(client, addr + i,
-                               chip->pdata->config_data->cell_char_tbl[i]);
+               regmap_write(map, addr + i,
+                       chip->pdata->config_data->cell_char_tbl[i]);
 }
 
 static inline void max17042_read_model_data(struct max17042_chip *chip,
-                                       u8 addr, u16 *data, int size)
+                                       u8 addr, u32 *data, int size)
 {
-       struct i2c_client *client = chip->client;
+       struct regmap *map = chip->regmap;
        int i;
 
        for (i = 0; i < size; i++)
-               data[i] = max17042_read_reg(client, addr + i);
+               regmap_read(map, addr + i, &data[i]);
 }
 
 static inline int max17042_model_data_compare(struct max17042_chip *chip,
@@ -350,7 +324,7 @@ static int max17042_init_model(struct max17042_chip *chip)
 {
        int ret;
        int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
-       u16 *temp_data;
+       u32 *temp_data;
 
        temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
        if (!temp_data)
@@ -365,7 +339,7 @@ static int max17042_init_model(struct max17042_chip *chip)
        ret = max17042_model_data_compare(
                chip,
                chip->pdata->config_data->cell_char_tbl,
-               temp_data,
+               (u16 *)temp_data,
                table_size);
 
        max10742_lock_model(chip);
@@ -378,7 +352,7 @@ static int max17042_verify_model_lock(struct max17042_chip *chip)
 {
        int i;
        int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
-       u16 *temp_data;
+       u32 *temp_data;
        int ret = 0;
 
        temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
@@ -398,40 +372,38 @@ static int max17042_verify_model_lock(struct max17042_chip *chip)
 static void max17042_write_config_regs(struct max17042_chip *chip)
 {
        struct max17042_config_data *config = chip->pdata->config_data;
+       struct regmap *map = chip->regmap;
 
-       max17042_write_reg(chip->client, MAX17042_CONFIG, config->config);
-       max17042_write_reg(chip->client, MAX17042_LearnCFG, config->learn_cfg);
-       max17042_write_reg(chip->client, MAX17042_FilterCFG,
+       regmap_write(map, MAX17042_CONFIG, config->config);
+       regmap_write(map, MAX17042_LearnCFG, config->learn_cfg);
+       regmap_write(map, MAX17042_FilterCFG,
                        config->filter_cfg);
-       max17042_write_reg(chip->client, MAX17042_RelaxCFG, config->relax_cfg);
+       regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg);
        if (chip->chip_type == MAX17047)
-               max17042_write_reg(chip->client, MAX17047_FullSOCThr,
+               regmap_write(map, MAX17047_FullSOCThr,
                                                config->full_soc_thresh);
 }
 
 static void  max17042_write_custom_regs(struct max17042_chip *chip)
 {
        struct max17042_config_data *config = chip->pdata->config_data;
+       struct regmap *map = chip->regmap;
 
-       max17042_write_verify_reg(chip->client, MAX17042_RCOMP0,
-                               config->rcomp0);
-       max17042_write_verify_reg(chip->client, MAX17042_TempCo,
-                               config->tcompc0);
-       max17042_write_verify_reg(chip->client, MAX17042_ICHGTerm,
-                               config->ichgt_term);
+       max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0);
+       max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0);
+       max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term);
        if (chip->chip_type == MAX17042) {
-               max17042_write_reg(chip->client, MAX17042_EmptyTempCo,
-                                       config->empty_tempco);
-               max17042_write_verify_reg(chip->client, MAX17042_K_empty0,
+               regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco);
+               max17042_write_verify_reg(map, MAX17042_K_empty0,
                                        config->kempty0);
        } else {
-               max17042_write_verify_reg(chip->client, MAX17047_QRTbl00,
+               max17042_write_verify_reg(map, MAX17047_QRTbl00,
                                                config->qrtbl00);
-               max17042_write_verify_reg(chip->client, MAX17047_QRTbl10,
+               max17042_write_verify_reg(map, MAX17047_QRTbl10,
                                                config->qrtbl10);
-               max17042_write_verify_reg(chip->client, MAX17047_QRTbl20,
+               max17042_write_verify_reg(map, MAX17047_QRTbl20,
                                                config->qrtbl20);
-               max17042_write_verify_reg(chip->client, MAX17047_QRTbl30,
+               max17042_write_verify_reg(map, MAX17047_QRTbl30,
                                                config->qrtbl30);
        }
 }
@@ -439,58 +411,60 @@ static void  max17042_write_custom_regs(struct max17042_chip *chip)
 static void max17042_update_capacity_regs(struct max17042_chip *chip)
 {
        struct max17042_config_data *config = chip->pdata->config_data;
+       struct regmap *map = chip->regmap;
 
-       max17042_write_verify_reg(chip->client, MAX17042_FullCAP,
+       max17042_write_verify_reg(map, MAX17042_FullCAP,
                                config->fullcap);
-       max17042_write_reg(chip->client, MAX17042_DesignCap,
-                       config->design_cap);
-       max17042_write_verify_reg(chip->client, MAX17042_FullCAPNom,
+       regmap_write(map, MAX17042_DesignCap, config->design_cap);
+       max17042_write_verify_reg(map, MAX17042_FullCAPNom,
                                config->fullcapnom);
 }
 
 static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip)
 {
-       u16 vfSoc;
+       unsigned int vfSoc;
+       struct regmap *map = chip->regmap;
 
-       vfSoc = max17042_read_reg(chip->client, MAX17042_VFSOC);
-       max17042_write_reg(chip->client, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK);
-       max17042_write_verify_reg(chip->client, MAX17042_VFSOC0, vfSoc);
-       max17042_write_reg(chip->client, MAX17042_VFSOC0Enable, VFSOC0_LOCK);
+       regmap_read(map, MAX17042_VFSOC, &vfSoc);
+       regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK);
+       max17042_write_verify_reg(map, MAX17042_VFSOC0, vfSoc);
+       regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_LOCK);
 }
 
 static void max17042_load_new_capacity_params(struct max17042_chip *chip)
 {
-       u16 full_cap0, rep_cap, dq_acc, vfSoc;
+       u32 full_cap0, rep_cap, dq_acc, vfSoc;
        u32 rem_cap;
 
        struct max17042_config_data *config = chip->pdata->config_data;
+       struct regmap *map = chip->regmap;
 
-       full_cap0 = max17042_read_reg(chip->client, MAX17042_FullCAP0);
-       vfSoc = max17042_read_reg(chip->client, MAX17042_VFSOC);
+       regmap_read(map, MAX17042_FullCAP0, &full_cap0);
+       regmap_read(map, MAX17042_VFSOC, &vfSoc);
 
        /* fg_vfSoc needs to shifted by 8 bits to get the
         * perc in 1% accuracy, to get the right rem_cap multiply
         * full_cap0, fg_vfSoc and devide by 100
         */
        rem_cap = ((vfSoc >> 8) * full_cap0) / 100;
-       max17042_write_verify_reg(chip->client, MAX17042_RemCap, (u16)rem_cap);
+       max17042_write_verify_reg(map, MAX17042_RemCap, rem_cap);
 
-       rep_cap = (u16)rem_cap;
-       max17042_write_verify_reg(chip->client, MAX17042_RepCap, rep_cap);
+       rep_cap = rem_cap;
+       max17042_write_verify_reg(map, MAX17042_RepCap, rep_cap);
 
        /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */
        dq_acc = config->fullcap / dQ_ACC_DIV;
-       max17042_write_verify_reg(chip->client, MAX17042_dQacc, dq_acc);
-       max17042_write_verify_reg(chip->client, MAX17042_dPacc, dP_ACC_200);
+       max17042_write_verify_reg(map, MAX17042_dQacc, dq_acc);
+       max17042_write_verify_reg(map, MAX17042_dPacc, dP_ACC_200);
 
-       max17042_write_verify_reg(chip->client, MAX17042_FullCAP,
+       max17042_write_verify_reg(map, MAX17042_FullCAP,
                        config->fullcap);
-       max17042_write_reg(chip->client, MAX17042_DesignCap,
+       regmap_write(map, MAX17042_DesignCap,
                        config->design_cap);
-       max17042_write_verify_reg(chip->client, MAX17042_FullCAPNom,
+       max17042_write_verify_reg(map, MAX17042_FullCAPNom,
                        config->fullcapnom);
        /* Update SOC register with new SOC */
-       max17042_write_reg(chip->client, MAX17042_RepSOC, vfSoc);
+       regmap_write(map, MAX17042_RepSOC, vfSoc);
 }
 
 /*
@@ -500,59 +474,60 @@ static void max17042_load_new_capacity_params(struct max17042_chip *chip)
  */
 static inline void max17042_override_por_values(struct max17042_chip *chip)
 {
-       struct i2c_client *client = chip->client;
+       struct regmap *map = chip->regmap;
        struct max17042_config_data *config = chip->pdata->config_data;
 
-       max17042_override_por(client, MAX17042_TGAIN, config->tgain);
-       max17042_override_por(client, MAx17042_TOFF, config->toff);
-       max17042_override_por(client, MAX17042_CGAIN, config->cgain);
-       max17042_override_por(client, MAX17042_COFF, config->coff);
-
-       max17042_override_por(client, MAX17042_VALRT_Th, config->valrt_thresh);
-       max17042_override_por(client, MAX17042_TALRT_Th, config->talrt_thresh);
-       max17042_override_por(client, MAX17042_SALRT_Th,
-                       config->soc_alrt_thresh);
-       max17042_override_por(client, MAX17042_CONFIG, config->config);
-       max17042_override_por(client, MAX17042_SHDNTIMER, config->shdntimer);
-
-       max17042_override_por(client, MAX17042_DesignCap, config->design_cap);
-       max17042_override_por(client, MAX17042_ICHGTerm, config->ichgt_term);
-
-       max17042_override_por(client, MAX17042_AtRate, config->at_rate);
-       max17042_override_por(client, MAX17042_LearnCFG, config->learn_cfg);
-       max17042_override_por(client, MAX17042_FilterCFG, config->filter_cfg);
-       max17042_override_por(client, MAX17042_RelaxCFG, config->relax_cfg);
-       max17042_override_por(client, MAX17042_MiscCFG, config->misc_cfg);
-       max17042_override_por(client, MAX17042_MaskSOC, config->masksoc);
-
-       max17042_override_por(client, MAX17042_FullCAP, config->fullcap);
-       max17042_override_por(client, MAX17042_FullCAPNom, config->fullcapnom);
+       max17042_override_por(map, MAX17042_TGAIN, config->tgain);
+       max17042_override_por(map, MAx17042_TOFF, config->toff);
+       max17042_override_por(map, MAX17042_CGAIN, config->cgain);
+       max17042_override_por(map, MAX17042_COFF, config->coff);
+
+       max17042_override_por(map, MAX17042_VALRT_Th, config->valrt_thresh);
+       max17042_override_por(map, MAX17042_TALRT_Th, config->talrt_thresh);
+       max17042_override_por(map, MAX17042_SALRT_Th,
+                                               config->soc_alrt_thresh);
+       max17042_override_por(map, MAX17042_CONFIG, config->config);
+       max17042_override_por(map, MAX17042_SHDNTIMER, config->shdntimer);
+
+       max17042_override_por(map, MAX17042_DesignCap, config->design_cap);
+       max17042_override_por(map, MAX17042_ICHGTerm, config->ichgt_term);
+
+       max17042_override_por(map, MAX17042_AtRate, config->at_rate);
+       max17042_override_por(map, MAX17042_LearnCFG, config->learn_cfg);
+       max17042_override_por(map, MAX17042_FilterCFG, config->filter_cfg);
+       max17042_override_por(map, MAX17042_RelaxCFG, config->relax_cfg);
+       max17042_override_por(map, MAX17042_MiscCFG, config->misc_cfg);
+       max17042_override_por(map, MAX17042_MaskSOC, config->masksoc);
+
+       max17042_override_por(map, MAX17042_FullCAP, config->fullcap);
+       max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom);
        if (chip->chip_type == MAX17042)
-               max17042_override_por(client, MAX17042_SOC_empty,
+               max17042_override_por(map, MAX17042_SOC_empty,
                                                config->socempty);
-       max17042_override_por(client, MAX17042_LAvg_empty, config->lavg_empty);
-       max17042_override_por(client, MAX17042_dQacc, config->dqacc);
-       max17042_override_por(client, MAX17042_dPacc, config->dpacc);
+       max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty);
+       max17042_override_por(map, MAX17042_dQacc, config->dqacc);
+       max17042_override_por(map, MAX17042_dPacc, config->dpacc);
 
        if (chip->chip_type == MAX17042)
-               max17042_override_por(client, MAX17042_V_empty, config->vempty);
+               max17042_override_por(map, MAX17042_V_empty, config->vempty);
        else
-               max17042_override_por(client, MAX17047_V_empty, config->vempty);
-       max17042_override_por(client, MAX17042_TempNom, config->temp_nom);
-       max17042_override_por(client, MAX17042_TempLim, config->temp_lim);
-       max17042_override_por(client, MAX17042_FCTC, config->fctc);
-       max17042_override_por(client, MAX17042_RCOMP0, config->rcomp0);
-       max17042_override_por(client, MAX17042_TempCo, config->tcompc0);
+               max17042_override_por(map, MAX17047_V_empty, config->vempty);
+       max17042_override_por(map, MAX17042_TempNom, config->temp_nom);
+       max17042_override_por(map, MAX17042_TempLim, config->temp_lim);
+       max17042_override_por(map, MAX17042_FCTC, config->fctc);
+       max17042_override_por(map, MAX17042_RCOMP0, config->rcomp0);
+       max17042_override_por(map, MAX17042_TempCo, config->tcompc0);
        if (chip->chip_type) {
-               max17042_override_por(client, MAX17042_EmptyTempCo,
-                                       config->empty_tempco);
-               max17042_override_por(client, MAX17042_K_empty0,
-                                       config->kempty0);
+               max17042_override_por(map, MAX17042_EmptyTempCo,
+                                               config->empty_tempco);
+               max17042_override_por(map, MAX17042_K_empty0,
+                                               config->kempty0);
        }
 }
 
 static int max17042_init_chip(struct max17042_chip *chip)
 {
+       struct regmap *map = chip->regmap;
        int ret;
        int val;
 
@@ -597,31 +572,32 @@ static int max17042_init_chip(struct max17042_chip *chip)
        max17042_load_new_capacity_params(chip);
 
        /* Init complete, Clear the POR bit */
-       val = max17042_read_reg(chip->client, MAX17042_STATUS);
-       max17042_write_reg(chip->client, MAX17042_STATUS,
-                       val & (~STATUS_POR_BIT));
+       regmap_read(map, MAX17042_STATUS, &val);
+       regmap_write(map, MAX17042_STATUS, val & (~STATUS_POR_BIT));
        return 0;
 }
 
 static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)
 {
-       u16 soc, soc_tr;
+       struct regmap *map = chip->regmap;
+       u32 soc, soc_tr;
 
        /* program interrupt thesholds such that we should
         * get interrupt for every 'off' perc change in the soc
         */
-       soc = max17042_read_reg(chip->client, MAX17042_RepSOC) >> 8;
+       regmap_read(map, MAX17042_RepSOC, &soc);
+       soc >>= 8;
        soc_tr = (soc + off) << 8;
        soc_tr |= (soc - off);
-       max17042_write_reg(chip->client, MAX17042_SALRT_Th, soc_tr);
+       regmap_write(map, MAX17042_SALRT_Th, soc_tr);
 }
 
 static irqreturn_t max17042_thread_handler(int id, void *dev)
 {
        struct max17042_chip *chip = dev;
-       u16 val;
+       u32 val;
 
-       val = max17042_read_reg(chip->client, MAX17042_STATUS);
+       regmap_read(chip->regmap, MAX17042_STATUS, &val);
        if ((val & STATUS_INTR_SOCMIN_BIT) ||
                (val & STATUS_INTR_SOCMAX_BIT)) {
                dev_info(&chip->client->dev, "SOC threshold INTR\n");
@@ -682,13 +658,20 @@ max17042_get_pdata(struct device *dev)
 }
 #endif
 
+static struct regmap_config max17042_regmap_config = {
+       .reg_bits = 8,
+       .val_bits = 16,
+       .val_format_endian = REGMAP_ENDIAN_NATIVE,
+};
+
 static int max17042_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
        struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
        struct max17042_chip *chip;
        int ret;
-       int reg;
+       int i;
+       u32 val;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
                return -EIO;
@@ -698,6 +681,12 @@ static int max17042_probe(struct i2c_client *client,
                return -ENOMEM;
 
        chip->client = client;
+       chip->regmap = devm_regmap_init_i2c(client, &max17042_regmap_config);
+       if (IS_ERR(chip->regmap)) {
+               dev_err(&client->dev, "Failed to initialize regmap\n");
+               return -EINVAL;
+       }
+
        chip->pdata = max17042_get_pdata(&client->dev);
        if (!chip->pdata) {
                dev_err(&client->dev, "no platform data provided\n");
@@ -706,15 +695,15 @@ static int max17042_probe(struct i2c_client *client,
 
        i2c_set_clientdata(client, chip);
 
-       ret = max17042_read_reg(chip->client, MAX17042_DevName);
-       if (ret == MAX17042_IC_VERSION) {
+       regmap_read(chip->regmap, MAX17042_DevName, &val);
+       if (val == MAX17042_IC_VERSION) {
                dev_dbg(&client->dev, "chip type max17042 detected\n");
                chip->chip_type = MAX17042;
-       } else if (ret == MAX17047_IC_VERSION) {
+       } else if (val == MAX17047_IC_VERSION) {
                dev_dbg(&client->dev, "chip type max17047/50 detected\n");
                chip->chip_type = MAX17047;
        } else {
-               dev_err(&client->dev, "device version mismatch: %x\n", ret);
+               dev_err(&client->dev, "device version mismatch: %x\n", val);
                return -EIO;
        }
 
@@ -733,13 +722,15 @@ static int max17042_probe(struct i2c_client *client,
                chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR;
 
        if (chip->pdata->init_data)
-               max17042_set_reg(client, chip->pdata->init_data,
-                               chip->pdata->num_init_data);
+               for (i = 0; i < chip->pdata->num_init_data; i++)
+                       regmap_write(chip->regmap,
+                                       chip->pdata->init_data[i].addr,
+                                       chip->pdata->init_data[i].data);
 
        if (!chip->pdata->enable_current_sense) {
-               max17042_write_reg(client, MAX17042_CGAIN, 0x0000);
-               max17042_write_reg(client, MAX17042_MiscCFG, 0x0003);
-               max17042_write_reg(client, MAX17042_LearnCFG, 0x0007);
+               regmap_write(chip->regmap, MAX17042_CGAIN, 0x0000);
+               regmap_write(chip->regmap, MAX17042_MiscCFG, 0x0003);
+               regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007);
        }
 
        ret = power_supply_register(&client->dev, &chip->battery);
@@ -754,9 +745,9 @@ static int max17042_probe(struct i2c_client *client,
                                                IRQF_TRIGGER_FALLING,
                                                chip->battery.name, chip);
                if (!ret) {
-                       reg =  max17042_read_reg(client, MAX17042_CONFIG);
-                       reg |= CONFIG_ALRT_BIT_ENBL;
-                       max17042_write_reg(client, MAX17042_CONFIG, reg);
+                       regmap_read(chip->regmap, MAX17042_CONFIG, &val);
+                       val |= CONFIG_ALRT_BIT_ENBL;
+                       regmap_write(chip->regmap, MAX17042_CONFIG, val);
                        max17042_set_soc_threshold(chip, 1);
                } else {
                        client->irq = 0;
@@ -765,8 +756,8 @@ static int max17042_probe(struct i2c_client *client,
                }
        }
 
-       reg = max17042_read_reg(chip->client, MAX17042_STATUS);
-       if (reg & STATUS_POR_BIT) {
+       regmap_read(chip->regmap, MAX17042_STATUS, &val);
+       if (val & STATUS_POR_BIT) {
                INIT_WORK(&chip->work, max17042_init_worker);
                schedule_work(&chip->work);
        } else {
@@ -786,7 +777,7 @@ static int max17042_remove(struct i2c_client *client)
        return 0;
 }
 
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 static int max17042_suspend(struct device *dev)
 {
        struct max17042_chip *chip = dev_get_drvdata(dev);
@@ -816,17 +807,11 @@ static int max17042_resume(struct device *dev)
 
        return 0;
 }
-
-static const struct dev_pm_ops max17042_pm_ops = {
-       .suspend        = max17042_suspend,
-       .resume         = max17042_resume,
-};
-
-#define MAX17042_PM_OPS (&max17042_pm_ops)
-#else
-#define MAX17042_PM_OPS NULL
 #endif
 
+static SIMPLE_DEV_PM_OPS(max17042_pm_ops, max17042_suspend,
+                       max17042_resume);
+
 #ifdef CONFIG_OF
 static const struct of_device_id max17042_dt_match[] = {
        { .compatible = "maxim,max17042" },
@@ -849,7 +834,7 @@ static struct i2c_driver max17042_i2c_driver = {
        .driver = {
                .name   = "max17042",
                .of_match_table = of_match_ptr(max17042_dt_match),
-               .pm     = MAX17042_PM_OPS,
+               .pm     = &max17042_pm_ops,
        },
        .probe          = max17042_probe,
        .remove         = max17042_remove,
index ffa10ed83eb1559481c0f1252f37644013c0b9b1..62c15af58c9af37420ab81e889b6f3d61021086d 100644 (file)
@@ -205,7 +205,7 @@ static int pm2xxx_charger_batt_therm_mngt(struct pm2xxx_charger *pm2, int val)
 }
 
 
-int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val)
+static int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val)
 {
        queue_work(pm2->charger_wq, &pm2->check_main_thermal_prot_work);
 
@@ -722,8 +722,12 @@ static int pm2xxx_charger_ac_en(struct ux500_charger *charger,
 
                dev_dbg(pm2->dev, "Enable AC: %dmV %dmA\n", vset, iset);
                if (!pm2->vddadc_en_ac) {
-                       regulator_enable(pm2->regu);
-                       pm2->vddadc_en_ac = true;
+                       ret = regulator_enable(pm2->regu);
+                       if (ret)
+                               dev_warn(pm2->dev,
+                                       "Failed to enable vddadc regulator\n");
+                       else
+                               pm2->vddadc_en_ac = true;
                }
 
                ret = pm2xxx_charging_init(pm2);
@@ -953,37 +957,24 @@ static int  pm2xxx_runtime_suspend(struct device *dev)
 {
        struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev);
        struct pm2xxx_charger *pm2;
-       int ret = 0;
 
        pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client);
-       if (!pm2) {
-               dev_err(pm2->dev, "no pm2xxx_charger data supplied\n");
-               ret = -EINVAL;
-               return ret;
-       }
-
        clear_lpn_pin(pm2);
 
-       return ret;
+       return 0;
 }
 
 static int  pm2xxx_runtime_resume(struct device *dev)
 {
        struct i2c_client *pm2xxx_i2c_client = to_i2c_client(dev);
        struct pm2xxx_charger *pm2;
-       int ret = 0;
 
        pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(pm2xxx_i2c_client);
-       if (!pm2) {
-               dev_err(pm2->dev, "no pm2xxx_charger data supplied\n");
-               ret = -EINVAL;
-               return ret;
-       }
 
        if (gpio_is_valid(pm2->lpn_pin) && gpio_get_value(pm2->lpn_pin) == 0)
                set_lpn_pin(pm2);
 
-       return ret;
+       return 0;
 }
 
 #endif
index bdd7b9b2546a500bc7366cfea79f5b1970cc0fae..8fc9d6df87f682610187a7ca665c393ef30c6e1d 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
+#include <linux/slab.h>
+
 #include <linux/mfd/tps65090.h>
 
 #define TPS65090_REG_INTR_STS  0x00
@@ -185,10 +187,6 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-#if defined(CONFIG_OF)
-
-#include <linux/of_device.h>
-
 static struct tps65090_platform_data *
                tps65090_parse_dt_charger_data(struct platform_device *pdev)
 {
@@ -210,13 +208,6 @@ static struct tps65090_platform_data *
        return pdata;
 
 }
-#else
-static struct tps65090_platform_data *
-               tps65090_parse_dt_charger_data(struct platform_device *pdev)
-{
-       return NULL;
-}
-#endif
 
 static int tps65090_charger_probe(struct platform_device *pdev)
 {
@@ -228,7 +219,7 @@ static int tps65090_charger_probe(struct platform_device *pdev)
 
        pdata = dev_get_platdata(pdev->dev.parent);
 
-       if (!pdata && pdev->dev.of_node)
+       if (IS_ENABLED(CONFIG_OF) && !pdata && pdev->dev.of_node)
                pdata = tps65090_parse_dt_charger_data(pdev);
 
        if (!pdata) {
@@ -277,13 +268,13 @@ static int tps65090_charger_probe(struct platform_device *pdev)
        if (ret) {
                dev_err(cdata->dev, "Unable to register irq %d err %d\n", irq,
                        ret);
-               goto fail_free_irq;
+               goto fail_unregister_supply;
        }
 
        ret = tps65090_config_charger(cdata);
        if (ret < 0) {
                dev_err(&pdev->dev, "charger config failed, err %d\n", ret);
-               goto fail_free_irq;
+               goto fail_unregister_supply;
        }
 
        /* Check for charger presence */
@@ -292,14 +283,14 @@ static int tps65090_charger_probe(struct platform_device *pdev)
        if (ret < 0) {
                dev_err(cdata->dev, "%s(): Error in reading reg 0x%x", __func__,
                        TPS65090_REG_CG_STATUS1);
-               goto fail_free_irq;
+               goto fail_unregister_supply;
        }
 
        if (status1 != 0) {
                ret = tps65090_enable_charging(cdata);
                if (ret < 0) {
                        dev_err(cdata->dev, "error enabling charger\n");
-                       goto fail_free_irq;
+                       goto fail_unregister_supply;
                }
                cdata->ac_online = 1;
                power_supply_changed(&cdata->ac);
@@ -307,8 +298,6 @@ static int tps65090_charger_probe(struct platform_device *pdev)
 
        return 0;
 
-fail_free_irq:
-       devm_free_irq(cdata->dev, irq, cdata);
 fail_unregister_supply:
        power_supply_unregister(&cdata->ac);
 
@@ -319,7 +308,6 @@ static int tps65090_charger_remove(struct platform_device *pdev)
 {
        struct tps65090_charger *cdata = platform_get_drvdata(pdev);
 
-       devm_free_irq(cdata->dev, cdata->irq, cdata);
        power_supply_unregister(&cdata->ac);
 
        return 0;
index d98abe911e376cc69f187c53caae17a979d812d8..f14108844e1a100b8ae61d6bbd9f7124653218f0 100644 (file)
@@ -495,10 +495,38 @@ static enum power_supply_property twl4030_charger_props[] = {
        POWER_SUPPLY_PROP_CURRENT_NOW,
 };
 
+#ifdef CONFIG_OF
+static const struct twl4030_bci_platform_data *
+twl4030_bci_parse_dt(struct device *dev)
+{
+       struct device_node *np = dev->of_node;
+       struct twl4030_bci_platform_data *pdata;
+       u32 num;
+
+       if (!np)
+               return NULL;
+       pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return pdata;
+
+       if (of_property_read_u32(np, "ti,bb-uvolt", &num) == 0)
+               pdata->bb_uvolt = num;
+       if (of_property_read_u32(np, "ti,bb-uamp", &num) == 0)
+               pdata->bb_uamp = num;
+       return pdata;
+}
+#else
+static inline const struct twl4030_bci_platform_data *
+twl4030_bci_parse_dt(struct device *dev)
+{
+       return NULL;
+}
+#endif
+
 static int __init twl4030_bci_probe(struct platform_device *pdev)
 {
        struct twl4030_bci *bci;
-       struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
+       const struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data;
        int ret;
        u32 reg;
 
@@ -506,6 +534,9 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
        if (bci == NULL)
                return -ENOMEM;
 
+       if (!pdata)
+               pdata = twl4030_bci_parse_dt(&pdev->dev);
+
        bci->dev = &pdev->dev;
        bci->irq_chg = platform_get_irq(pdev, 0);
        bci->irq_bci = platform_get_irq(pdev, 1);
@@ -581,8 +612,11 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
 
        twl4030_charger_enable_ac(true);
        twl4030_charger_enable_usb(bci, true);
-       twl4030_charger_enable_backup(pdata->bb_uvolt,
-                                     pdata->bb_uamp);
+       if (pdata)
+               twl4030_charger_enable_backup(pdata->bb_uvolt,
+                                             pdata->bb_uamp);
+       else
+               twl4030_charger_enable_backup(0, 0);
 
        return 0;
 
@@ -631,10 +665,17 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
        return 0;
 }
 
+static const struct of_device_id twl_bci_of_match[] = {
+       {.compatible = "ti,twl4030-bci", },
+       { }
+};
+MODULE_DEVICE_TABLE(of, twl_bci_of_match);
+
 static struct platform_driver twl4030_bci_driver = {
        .driver = {
                .name   = "twl4030_bci",
                .owner  = THIS_MODULE,
+               .of_match_table = of_match_ptr(twl_bci_of_match),
        },
        .remove = __exit_p(twl4030_bci_remove),
 };
index 75840b5cea6dfd978d83c5b4c741af0b5af99122..eece329d78729049c4dd7b2e49668217309a5668 100644 (file)
@@ -62,6 +62,15 @@ config PWM_BFIN
          To compile this driver as a module, choose M here: the module
          will be called pwm-bfin.
 
+config PWM_EP93XX
+       tristate "Cirrus Logic EP93xx PWM support"
+       depends on ARCH_EP93XX
+       help
+         Generic PWM framework driver for Cirrus Logic EP93xx.
+
+         To compile this driver as a module, choose M here: the module
+         will be called pwm-ep93xx.
+
 config PWM_IMX
        tristate "i.MX PWM support"
        depends on ARCH_MXC
index 77a8c185c5b2b46c6a4afe0e0a45bc8d5dd772d0..8b754e4dba4aae03cc36562d5e0c079e6327c4d2 100644 (file)
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS)         += sysfs.o
 obj-$(CONFIG_PWM_AB8500)       += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL_TCB)    += pwm-atmel-tcb.o
 obj-$(CONFIG_PWM_BFIN)         += pwm-bfin.o
+obj-$(CONFIG_PWM_EP93XX)       += pwm-ep93xx.o
 obj-$(CONFIG_PWM_IMX)          += pwm-imx.o
 obj-$(CONFIG_PWM_JZ4740)       += pwm-jz4740.o
 obj-$(CONFIG_PWM_LPC32XX)      += pwm-lpc32xx.o
index ba6ce01035e4feae2c1f40dcf8b24e0ad4923ffa..f3dcd02390f1b5da7d9cf43d3b053d3e6840bc0f 100644 (file)
@@ -249,6 +249,8 @@ static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
                }
        }
 
+       cmr |= (tcbpwm->div & ATMEL_TC_TCCLKS);
+
        __raw_writel(cmr, regs + ATMEL_TC_REG(group, CMR));
 
        if (index == 0)
@@ -305,7 +307,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
                i = slowclk;
                rate = 32768;
                min = div_u64(NSEC_PER_SEC, rate);
-               max = min << 16;
+               max = min << tc->tcb_config->counter_width;
 
                /* If period is too big return ERANGE error */
                if (max < period_ns)
diff --git a/drivers/pwm/pwm-ep93xx.c b/drivers/pwm/pwm-ep93xx.c
new file mode 100644 (file)
index 0000000..33aa446
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ * PWM framework driver for Cirrus Logic EP93xx
+ *
+ * Copyright (c) 2009        Matthieu Crapet <mcrapet@gmail.com>
+ * Copyright (c) 2009, 2013  H Hartley Sweeten <hsweeten@visionengravers.com>
+ *
+ * EP9301/02 have only one channel:
+ *   platform device ep93xx-pwm.1 - PWMOUT1 (EGPIO14)
+ *
+ * EP9307 has only one channel:
+ *   platform device ep93xx-pwm.0 - PWMOUT
+ *
+ * EP9312/15 have two channels:
+ *   platform device ep93xx-pwm.0 - PWMOUT
+ *   platform device ep93xx-pwm.1 - PWMOUT1 (EGPIO14)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/pwm.h>
+
+#include <asm/div64.h>
+
+#include <mach/platform.h>     /* for ep93xx_pwm_{acquire,release}_gpio() */
+
+#define EP93XX_PWMx_TERM_COUNT 0x00
+#define EP93XX_PWMx_DUTY_CYCLE 0x04
+#define EP93XX_PWMx_ENABLE     0x08
+#define EP93XX_PWMx_INVERT     0x0c
+
+struct ep93xx_pwm {
+       void __iomem *base;
+       struct clk *clk;
+       struct pwm_chip chip;
+};
+
+static inline struct ep93xx_pwm *to_ep93xx_pwm(struct pwm_chip *chip)
+{
+       return container_of(chip, struct ep93xx_pwm, chip);
+}
+
+static int ep93xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct platform_device *pdev = to_platform_device(chip->dev);
+
+       return ep93xx_pwm_acquire_gpio(pdev);
+}
+
+static void ep93xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct platform_device *pdev = to_platform_device(chip->dev);
+
+       ep93xx_pwm_release_gpio(pdev);
+}
+
+static int ep93xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
+                            int duty_ns, int period_ns)
+{
+       struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
+       void __iomem *base = ep93xx_pwm->base;
+       unsigned long long c;
+       unsigned long period_cycles;
+       unsigned long duty_cycles;
+       unsigned long term;
+       int ret = 0;
+
+       /*
+        * The clock needs to be enabled to access the PWM registers.
+        * Configuration can be changed at any time.
+        */
+       if (!test_bit(PWMF_ENABLED, &pwm->flags)) {
+               ret = clk_enable(ep93xx_pwm->clk);
+               if (ret)
+                       return ret;
+       }
+
+       c = clk_get_rate(ep93xx_pwm->clk);
+       c *= period_ns;
+       do_div(c, 1000000000);
+       period_cycles = c;
+
+       c = period_cycles;
+       c *= duty_ns;
+       do_div(c, period_ns);
+       duty_cycles = c;
+
+       if (period_cycles < 0x10000 && duty_cycles < 0x10000) {
+               term = readw(base + EP93XX_PWMx_TERM_COUNT);
+
+               /* Order is important if PWM is running */
+               if (period_cycles > term) {
+                       writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
+                       writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
+               } else {
+                       writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
+                       writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
+               }
+       } else {
+               ret = -EINVAL;
+       }
+
+       if (!test_bit(PWMF_ENABLED, &pwm->flags))
+               clk_disable(ep93xx_pwm->clk);
+
+       return ret;
+}
+
+static int ep93xx_pwm_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
+                              enum pwm_polarity polarity)
+{
+       struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
+       int ret;
+
+       /*
+        * The clock needs to be enabled to access the PWM registers.
+        * Polarity can only be changed when the PWM is disabled.
+        */
+       ret = clk_enable(ep93xx_pwm->clk);
+       if (ret)
+               return ret;
+
+       if (polarity == PWM_POLARITY_INVERSED)
+               writew(0x1, ep93xx_pwm->base + EP93XX_PWMx_INVERT);
+       else
+               writew(0x0, ep93xx_pwm->base + EP93XX_PWMx_INVERT);
+
+       clk_disable(ep93xx_pwm->clk);
+
+       return 0;
+}
+
+static int ep93xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
+       int ret;
+
+       ret = clk_enable(ep93xx_pwm->clk);
+       if (ret)
+               return ret;
+
+       writew(0x1, ep93xx_pwm->base + EP93XX_PWMx_ENABLE);
+
+       return 0;
+}
+
+static void ep93xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
+
+       writew(0x0, ep93xx_pwm->base + EP93XX_PWMx_ENABLE);
+       clk_disable(ep93xx_pwm->clk);
+}
+
+static const struct pwm_ops ep93xx_pwm_ops = {
+       .request = ep93xx_pwm_request,
+       .free = ep93xx_pwm_free,
+       .config = ep93xx_pwm_config,
+       .set_polarity = ep93xx_pwm_polarity,
+       .enable = ep93xx_pwm_enable,
+       .disable = ep93xx_pwm_disable,
+       .owner = THIS_MODULE,
+};
+
+static int ep93xx_pwm_probe(struct platform_device *pdev)
+{
+       struct ep93xx_pwm *ep93xx_pwm;
+       struct resource *res;
+       int ret;
+
+       ep93xx_pwm = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_pwm), GFP_KERNEL);
+       if (!ep93xx_pwm)
+               return -ENOMEM;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       ep93xx_pwm->base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(ep93xx_pwm->base))
+               return PTR_ERR(ep93xx_pwm->base);
+
+       ep93xx_pwm->clk = devm_clk_get(&pdev->dev, "pwm_clk");
+       if (IS_ERR(ep93xx_pwm->clk))
+               return PTR_ERR(ep93xx_pwm->clk);
+
+       ep93xx_pwm->chip.dev = &pdev->dev;
+       ep93xx_pwm->chip.ops = &ep93xx_pwm_ops;
+       ep93xx_pwm->chip.base = -1;
+       ep93xx_pwm->chip.npwm = 1;
+
+       ret = pwmchip_add(&ep93xx_pwm->chip);
+       if (ret < 0)
+               return ret;
+
+       platform_set_drvdata(pdev, ep93xx_pwm);
+       return 0;
+}
+
+static int ep93xx_pwm_remove(struct platform_device *pdev)
+{
+       struct ep93xx_pwm *ep93xx_pwm = platform_get_drvdata(pdev);
+
+       return pwmchip_remove(&ep93xx_pwm->chip);
+}
+
+static struct platform_driver ep93xx_pwm_driver = {
+       .driver = {
+               .name = "ep93xx-pwm",
+       },
+       .probe = ep93xx_pwm_probe,
+       .remove = ep93xx_pwm_remove,
+};
+module_platform_driver(ep93xx_pwm_driver);
+
+MODULE_DESCRIPTION("Cirrus Logic EP93xx PWM driver");
+MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, "
+             "H Hartley Sweeten <hsweeten@visionengravers.com>");
+MODULE_ALIAS("platform:ep93xx-pwm");
+MODULE_LICENSE("GPL");
index 2b7c4f88b461b788c1d683a141d6a402d958af12..cc477334487494fe014ba8993feb8c674fadad3f 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/pwm.h>
+#include <linux/of.h>
 #include <linux/of_device.h>
 
 /* i.MX1 and i.MX21 share the same PWM function block: */
@@ -296,7 +297,7 @@ static struct platform_driver imx_pwm_driver = {
        .driver         = {
                .name   = "imx-pwm",
                .owner = THIS_MODULE,
-               .of_match_table = of_match_ptr(imx_pwm_dt_ids),
+               .of_match_table = imx_pwm_dt_ids,
        },
        .probe          = imx_pwm_probe,
        .remove         = imx_pwm_remove,
index efac99e03d57191c2d8667264cff0a5e8a603dbe..9dc0f9d42bfa3a44807c8f2b3917ad27c3f8f437 100644 (file)
@@ -169,7 +169,7 @@ static struct platform_driver lpc32xx_pwm_driver = {
        .driver = {
                .name = "lpc32xx-pwm",
                .owner = THIS_MODULE,
-               .of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids),
+               .of_match_table = lpc32xx_pwm_dt_ids,
        },
        .probe = lpc32xx_pwm_probe,
        .remove = lpc32xx_pwm_remove,
index c2c5a4fd1b96bb4eede5bdd553911e3da66dee5e..9475bc7a6f97ded7ec293881151747073c198ff3 100644 (file)
@@ -189,7 +189,7 @@ static struct platform_driver mxs_pwm_driver = {
        .driver = {
                .name = "mxs-pwm",
                .owner = THIS_MODULE,
-               .of_match_table = of_match_ptr(mxs_pwm_dt_ids),
+               .of_match_table = mxs_pwm_dt_ids,
        },
        .probe = mxs_pwm_probe,
        .remove = mxs_pwm_remove,
index fcc8b9adde9fe89b2e35ae3ae01312aaff90605c..b59639e0c02978388126a1d7d56d8f3b62c32b6c 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pwm.h>
 #include <linux/slab.h>
@@ -224,8 +225,8 @@ static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm)
 
 static void pwm_samsung_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
-       pwm_set_chip_data(pwm, NULL);
        devm_kfree(chip->dev, pwm_get_chip_data(pwm));
+       pwm_set_chip_data(pwm, NULL);
 }
 
 static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm)
index c2e2e5852362afbd62a8c097fb195ea92433cf15..4e5c3d13d4f8d31a0faa65ccd7146c0a28436e3c 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/pm_runtime.h>
 #include <linux/pwm.h>
 #include <linux/of_device.h>
-#include <linux/pinctrl/consumer.h>
 
 #include "pwm-tipwmss.h"
 
@@ -208,11 +207,6 @@ static int ecap_pwm_probe(struct platform_device *pdev)
        struct clk *clk;
        struct ecap_pwm_chip *pc;
        u16 status;
-       struct pinctrl *pinctrl;
-
-       pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
-       if (IS_ERR(pinctrl))
-               dev_warn(&pdev->dev, "unable to select pin group\n");
 
        pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
        if (!pc) {
index 084f552465322654f9f3b7e0a765926ff8bd49fd..a4d8f519d965660d1a33e0cdfc7bda02224fbd7d 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/clk.h>
 #include <linux/pm_runtime.h>
 #include <linux/of_device.h>
-#include <linux/pinctrl/consumer.h>
 
 #include "pwm-tipwmss.h"
 
@@ -439,11 +438,6 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev)
        struct clk *clk;
        struct ehrpwm_pwm_chip *pc;
        u16 status;
-       struct pinctrl *pinctrl;
-
-       pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
-       if (IS_ERR(pinctrl))
-               dev_warn(&pdev->dev, "unable to select pin group\n");
 
        pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
        if (!pc) {
index 29d1bba4804ec95fa7c249ebbe6ad3ea057fe08a..b964470025c5e288a6009817ddb683c679868eb6 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pwm.h>
 #include <linux/i2c/twl.h>
index eef910580eaef3c355bb0384759b16155924e9d8..b99a50e626a64f82ca98783cc373bd2bc4c82e01 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pwm.h>
 #include <linux/i2c/twl.h>
index 23f8d1ce877d4e133fc690b7055b4342841e4112..a00132e31ec7ab245f2017f13e110c6730c906fd 100644 (file)
@@ -906,7 +906,7 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
                }
                ret = tps65910_reg_write(pmic->mfd, sr_reg_add, 0);
                if (ret < 0) {
-                       dev_err(mfd->dev, "Error in settting sr register\n");
+                       dev_err(mfd->dev, "Error in setting sr register\n");
                        return ret;
                }
        }
index 548209a9c43c58ae687809d5da605f7b8e97184b..d0ab5019d885cea6113f677a4f58990fa4a3ca55 100644 (file)
@@ -118,22 +118,6 @@ static void scm_request_done(struct scm_request *scmrq)
        spin_unlock_irqrestore(&list_lock, flags);
 }
 
-static int scm_open(struct block_device *blkdev, fmode_t mode)
-{
-       return scm_get_ref();
-}
-
-static void scm_release(struct gendisk *gendisk, fmode_t mode)
-{
-       scm_put_ref();
-}
-
-static const struct block_device_operations scm_blk_devops = {
-       .owner = THIS_MODULE,
-       .open = scm_open,
-       .release = scm_release,
-};
-
 static bool scm_permit_request(struct scm_blk_dev *bdev, struct request *req)
 {
        return rq_data_dir(req) != WRITE || bdev->state != SCM_WR_PROHIBIT;
@@ -256,7 +240,7 @@ static void scm_blk_request(struct request_queue *rq)
                atomic_inc(&bdev->queued_reqs);
                blk_start_request(req);
 
-               ret = scm_start_aob(scmrq->aob);
+               ret = eadm_start_aob(scmrq->aob);
                if (ret) {
                        SCM_LOG(5, "no subchannel");
                        scm_request_requeue(scmrq);
@@ -320,7 +304,7 @@ static void scm_blk_handle_error(struct scm_request *scmrq)
        }
 
 restart:
-       if (!scm_start_aob(scmrq->aob))
+       if (!eadm_start_aob(scmrq->aob))
                return;
 
 requeue:
@@ -363,6 +347,10 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev)
        blk_run_queue(bdev->rq);
 }
 
+static const struct block_device_operations scm_blk_devops = {
+       .owner = THIS_MODULE,
+};
+
 int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
 {
        struct request_queue *rq;
index c0d102e3a48bf569d0c9744abb466317e942342b..27f930cd657fcdd3a223412cb68c393ebd565556 100644 (file)
@@ -187,7 +187,7 @@ bool scm_need_cluster_request(struct scm_request *scmrq)
 void scm_initiate_cluster_request(struct scm_request *scmrq)
 {
        scm_prepare_cluster_request(scmrq);
-       if (scm_start_aob(scmrq->aob))
+       if (eadm_start_aob(scmrq->aob))
                scm_request_requeue(scmrq);
 }
 
index 17821a026c9ca9b4ae6878bb57c04a56692850e4..b69ab17f13fabef4afc6c44a62534d549505db12 100644 (file)
@@ -3,7 +3,8 @@
 #
 
 obj-y += ctrlchar.o keyboard.o defkeymap.o sclp.o sclp_rw.o sclp_quiesce.o \
-        sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o
+        sclp_cmd.o sclp_config.o sclp_cpi_sys.o sclp_ocf.o sclp_ctl.o \
+        sclp_early.o
 
 obj-$(CONFIG_TN3270) += raw3270.o
 obj-$(CONFIG_TN3270_CONSOLE) += con3270.o
index f93cc32eb81871b468c3439ecb03de5c19783710..71e9747380149d627a92883b2d17bd269c9f7817 100644 (file)
@@ -564,6 +564,7 @@ static void __exit
 fs3270_exit(void)
 {
        raw3270_unregister_notifier(&fs3270_notifier);
+       device_destroy(class3270, MKDEV(IBM_FS3270_MAJOR, 0));
        __unregister_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270");
 }
 
index 40d1406289ed2533f6bd4bdffda0b0e19a80a79e..6fbe09686d18fc1024fb3f1151914fc69abaa394 100644 (file)
@@ -99,6 +99,7 @@ struct init_sccb {
 } __attribute__((packed));
 
 extern u64 sclp_facilities;
+
 #define SCLP_HAS_CHP_INFO      (sclp_facilities & 0x8000000000000000ULL)
 #define SCLP_HAS_CHP_RECONFIG  (sclp_facilities & 0x2000000000000000ULL)
 #define SCLP_HAS_CPU_INFO      (sclp_facilities & 0x0800000000000000ULL)
@@ -179,6 +180,10 @@ void sclp_sdias_exit(void);
 extern int sclp_console_pages;
 extern int sclp_console_drop;
 extern unsigned long sclp_console_full;
+extern u8 sclp_fac84;
+extern unsigned long long sclp_rzm;
+extern unsigned long long sclp_rnmax;
+extern __initdata int sclp_early_read_info_sccb_valid;
 
 /* useful inlines */
 
index 77df9cb00688feeda6cad1fbfd4623fc5a26134e..eaa21d542c5cb102c19753eeec8abd2fff719cf0 100644 (file)
 
 #include "sclp.h"
 
-#define SCLP_CMDW_READ_SCP_INFO                0x00020001
-#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
-
-struct read_info_sccb {
-       struct  sccb_header header;     /* 0-7 */
-       u16     rnmax;                  /* 8-9 */
-       u8      rnsize;                 /* 10 */
-       u8      _reserved0[24 - 11];    /* 11-15 */
-       u8      loadparm[8];            /* 24-31 */
-       u8      _reserved1[48 - 32];    /* 32-47 */
-       u64     facilities;             /* 48-55 */
-       u8      _reserved2[84 - 56];    /* 56-83 */
-       u8      fac84;                  /* 84 */
-       u8      fac85;                  /* 85 */
-       u8      _reserved3[91 - 86];    /* 86-90 */
-       u8      flags;                  /* 91 */
-       u8      _reserved4[100 - 92];   /* 92-99 */
-       u32     rnsize2;                /* 100-103 */
-       u64     rnmax2;                 /* 104-111 */
-       u8      _reserved5[4096 - 112]; /* 112-4095 */
-} __attribute__((packed, aligned(PAGE_SIZE)));
-
-static struct init_sccb __initdata early_event_mask_sccb __aligned(PAGE_SIZE);
-static struct read_info_sccb __initdata early_read_info_sccb;
-static int __initdata early_read_info_sccb_valid;
-
-u64 sclp_facilities;
-static u8 sclp_fac84;
-static unsigned long long rzm;
-static unsigned long long rnmax;
-
-static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
-{
-       int rc;
-
-       __ctl_set_bit(0, 9);
-       rc = sclp_service_call(cmd, sccb);
-       if (rc)
-               goto out;
-       __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
-                       PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
-       local_irq_disable();
-out:
-       /* Contents of the sccb might have changed. */
-       barrier();
-       __ctl_clear_bit(0, 9);
-       return rc;
-}
-
-static void __init sclp_read_info_early(void)
-{
-       int rc;
-       int i;
-       struct read_info_sccb *sccb;
-       sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
-                                 SCLP_CMDW_READ_SCP_INFO};
-
-       sccb = &early_read_info_sccb;
-       for (i = 0; i < ARRAY_SIZE(commands); i++) {
-               do {
-                       memset(sccb, 0, sizeof(*sccb));
-                       sccb->header.length = sizeof(*sccb);
-                       sccb->header.function_code = 0x80;
-                       sccb->header.control_mask[2] = 0x80;
-                       rc = sclp_cmd_sync_early(commands[i], sccb);
-               } while (rc == -EBUSY);
-
-               if (rc)
-                       break;
-               if (sccb->header.response_code == 0x10) {
-                       early_read_info_sccb_valid = 1;
-                       break;
-               }
-               if (sccb->header.response_code != 0x1f0)
-                       break;
-       }
-}
-
-static void __init sclp_event_mask_early(void)
-{
-       struct init_sccb *sccb = &early_event_mask_sccb;
-       int rc;
-
-       do {
-               memset(sccb, 0, sizeof(*sccb));
-               sccb->header.length = sizeof(*sccb);
-               sccb->mask_length = sizeof(sccb_mask_t);
-               rc = sclp_cmd_sync_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
-       } while (rc == -EBUSY);
-}
-
-void __init sclp_facilities_detect(void)
-{
-       struct read_info_sccb *sccb;
-
-       sclp_read_info_early();
-       if (!early_read_info_sccb_valid)
-               return;
-
-       sccb = &early_read_info_sccb;
-       sclp_facilities = sccb->facilities;
-       sclp_fac84 = sccb->fac84;
-       if (sccb->fac85 & 0x02)
-               S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
-       rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
-       rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
-       rzm <<= 20;
-
-       sclp_event_mask_early();
-}
-
-bool __init sclp_has_linemode(void)
-{
-       struct init_sccb *sccb = &early_event_mask_sccb;
-
-       if (sccb->header.response_code != 0x20)
-               return 0;
-       if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
-               return 0;
-       if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
-               return 0;
-       return 1;
-}
-
-bool __init sclp_has_vt220(void)
-{
-       struct init_sccb *sccb = &early_event_mask_sccb;
-
-       if (sccb->header.response_code != 0x20)
-               return 0;
-       if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
-               return 1;
-       return 0;
-}
-
-unsigned long long sclp_get_rnmax(void)
-{
-       return rnmax;
-}
-
-unsigned long long sclp_get_rzm(void)
-{
-       return rzm;
-}
-
-/*
- * This function will be called after sclp_facilities_detect(), which gets
- * called from early.c code. Therefore the sccb should have valid contents.
- */
-void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
-{
-       struct read_info_sccb *sccb;
-
-       if (!early_read_info_sccb_valid)
-               return;
-       sccb = &early_read_info_sccb;
-       info->is_valid = 1;
-       if (sccb->flags & 0x2)
-               info->has_dump = 1;
-       memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
-}
-
 static void sclp_sync_callback(struct sclp_req *req, void *data)
 {
        struct completion *completion = data;
@@ -356,14 +194,14 @@ struct assign_storage_sccb {
 
 int arch_get_memory_phys_device(unsigned long start_pfn)
 {
-       if (!rzm)
+       if (!sclp_rzm)
                return 0;
-       return PFN_PHYS(start_pfn) >> ilog2(rzm);
+       return PFN_PHYS(start_pfn) >> ilog2(sclp_rzm);
 }
 
 static unsigned long long rn2addr(u16 rn)
 {
-       return (unsigned long long) (rn - 1) * rzm;
+       return (unsigned long long) (rn - 1) * sclp_rzm;
 }
 
 static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
@@ -404,7 +242,7 @@ static int sclp_assign_storage(u16 rn)
        if (rc)
                return rc;
        start = rn2addr(rn);
-       storage_key_init_range(start, start + rzm);
+       storage_key_init_range(start, start + sclp_rzm);
        return 0;
 }
 
@@ -462,7 +300,7 @@ static int sclp_mem_change_state(unsigned long start, unsigned long size,
                istart = rn2addr(incr->rn);
                if (start + size - 1 < istart)
                        break;
-               if (start > istart + rzm - 1)
+               if (start > istart + sclp_rzm - 1)
                        continue;
                if (online)
                        rc |= sclp_assign_storage(incr->rn);
@@ -526,7 +364,7 @@ static void __init add_memory_merged(u16 rn)
        if (!first_rn)
                goto skip_add;
        start = rn2addr(first_rn);
-       size = (unsigned long long ) num * rzm;
+       size = (unsigned long long) num * sclp_rzm;
        if (start >= VMEM_MAX_PHYS)
                goto skip_add;
        if (start + size > VMEM_MAX_PHYS)
@@ -574,7 +412,7 @@ static void __init insert_increment(u16 rn, int standby, int assigned)
        }
        if (!assigned)
                new_incr->rn = last_rn + 1;
-       if (new_incr->rn > rnmax) {
+       if (new_incr->rn > sclp_rnmax) {
                kfree(new_incr);
                return;
        }
@@ -617,7 +455,7 @@ static int __init sclp_detect_standby_memory(void)
 
        if (OLDMEM_BASE) /* No standby memory in kdump mode */
                return 0;
-       if (!early_read_info_sccb_valid)
+       if (!sclp_early_read_info_sccb_valid)
                return 0;
        if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
                return 0;
@@ -661,7 +499,7 @@ static int __init sclp_detect_standby_memory(void)
        }
        if (rc || list_empty(&sclp_mem_list))
                goto out;
-       for (i = 1; i <= rnmax - assigned; i++)
+       for (i = 1; i <= sclp_rnmax - assigned; i++)
                insert_increment(0, 1, 0);
        rc = register_memory_notifier(&sclp_mem_nb);
        if (rc)
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
new file mode 100644 (file)
index 0000000..f7aa080
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+ * SCLP early driver
+ *
+ * Copyright IBM Corp. 2013
+ */
+
+#define KMSG_COMPONENT "sclp_early"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
+#include <asm/ctl_reg.h>
+#include <asm/sclp.h>
+#include <asm/ipl.h>
+#include "sclp_sdias.h"
+#include "sclp.h"
+
+#define SCLP_CMDW_READ_SCP_INFO                0x00020001
+#define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
+
+struct read_info_sccb {
+       struct  sccb_header header;     /* 0-7 */
+       u16     rnmax;                  /* 8-9 */
+       u8      rnsize;                 /* 10 */
+       u8      _reserved0[24 - 11];    /* 11-15 */
+       u8      loadparm[8];            /* 24-31 */
+       u8      _reserved1[48 - 32];    /* 32-47 */
+       u64     facilities;             /* 48-55 */
+       u8      _reserved2[84 - 56];    /* 56-83 */
+       u8      fac84;                  /* 84 */
+       u8      fac85;                  /* 85 */
+       u8      _reserved3[91 - 86];    /* 86-90 */
+       u8      flags;                  /* 91 */
+       u8      _reserved4[100 - 92];   /* 92-99 */
+       u32     rnsize2;                /* 100-103 */
+       u64     rnmax2;                 /* 104-111 */
+       u8      _reserved5[4096 - 112]; /* 112-4095 */
+} __packed __aligned(PAGE_SIZE);
+
+static __initdata struct init_sccb early_event_mask_sccb __aligned(PAGE_SIZE);
+static __initdata struct read_info_sccb early_read_info_sccb;
+static __initdata char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE);
+static unsigned long sclp_hsa_size;
+
+__initdata int sclp_early_read_info_sccb_valid;
+u64 sclp_facilities;
+u8 sclp_fac84;
+unsigned long long sclp_rzm;
+unsigned long long sclp_rnmax;
+
+static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
+{
+       int rc;
+
+       __ctl_set_bit(0, 9);
+       rc = sclp_service_call(cmd, sccb);
+       if (rc)
+               goto out;
+       __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
+                       PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
+       local_irq_disable();
+out:
+       /* Contents of the sccb might have changed. */
+       barrier();
+       __ctl_clear_bit(0, 9);
+       return rc;
+}
+
+static void __init sclp_read_info_early(void)
+{
+       int rc;
+       int i;
+       struct read_info_sccb *sccb;
+       sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
+                                 SCLP_CMDW_READ_SCP_INFO};
+
+       sccb = &early_read_info_sccb;
+       for (i = 0; i < ARRAY_SIZE(commands); i++) {
+               do {
+                       memset(sccb, 0, sizeof(*sccb));
+                       sccb->header.length = sizeof(*sccb);
+                       sccb->header.function_code = 0x80;
+                       sccb->header.control_mask[2] = 0x80;
+                       rc = sclp_cmd_sync_early(commands[i], sccb);
+               } while (rc == -EBUSY);
+
+               if (rc)
+                       break;
+               if (sccb->header.response_code == 0x10) {
+                       sclp_early_read_info_sccb_valid = 1;
+                       break;
+               }
+               if (sccb->header.response_code != 0x1f0)
+                       break;
+       }
+}
+
+static void __init sclp_facilities_detect(void)
+{
+       struct read_info_sccb *sccb;
+
+       sclp_read_info_early();
+       if (!sclp_early_read_info_sccb_valid)
+               return;
+
+       sccb = &early_read_info_sccb;
+       sclp_facilities = sccb->facilities;
+       sclp_fac84 = sccb->fac84;
+       if (sccb->fac85 & 0x02)
+               S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
+       sclp_rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
+       sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
+       sclp_rzm <<= 20;
+}
+
+bool __init sclp_has_linemode(void)
+{
+       struct init_sccb *sccb = &early_event_mask_sccb;
+
+       if (sccb->header.response_code != 0x20)
+               return 0;
+       if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
+               return 0;
+       if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
+               return 0;
+       return 1;
+}
+
+bool __init sclp_has_vt220(void)
+{
+       struct init_sccb *sccb = &early_event_mask_sccb;
+
+       if (sccb->header.response_code != 0x20)
+               return 0;
+       if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
+               return 1;
+       return 0;
+}
+
+unsigned long long sclp_get_rnmax(void)
+{
+       return sclp_rnmax;
+}
+
+unsigned long long sclp_get_rzm(void)
+{
+       return sclp_rzm;
+}
+
+/*
+ * This function will be called after sclp_facilities_detect(), which gets
+ * called from early.c code. Therefore the sccb should have valid contents.
+ */
+void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
+{
+       struct read_info_sccb *sccb;
+
+       if (!sclp_early_read_info_sccb_valid)
+               return;
+       sccb = &early_read_info_sccb;
+       info->is_valid = 1;
+       if (sccb->flags & 0x2)
+               info->has_dump = 1;
+       memcpy(&info->loadparm, &sccb->loadparm, LOADPARM_LEN);
+}
+
+static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
+{
+       int rc;
+
+       do {
+               rc = sclp_cmd_sync_early(cmd, sccb);
+       } while (rc == -EBUSY);
+
+       if (rc)
+               return -EIO;
+       if (((struct sccb_header *) sccb)->response_code != 0x0020)
+               return -EIO;
+       return 0;
+}
+
+static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
+{
+       memset(sccb, 0, sizeof(*sccb));
+
+       sccb->hdr.length = sizeof(*sccb);
+       sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
+       sccb->evbuf.hdr.type = EVTYP_SDIAS;
+       sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
+       sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
+       sccb->evbuf.event_id = 4712;
+       sccb->evbuf.dbs = 1;
+}
+
+static int __init sclp_set_event_mask(unsigned long receive_mask,
+                                     unsigned long send_mask)
+{
+       struct init_sccb *sccb = (void *) &sccb_early;
+
+       memset(sccb, 0, sizeof(*sccb));
+       sccb->header.length = sizeof(*sccb);
+       sccb->mask_length = sizeof(sccb_mask_t);
+       sccb->receive_mask = receive_mask;
+       sccb->send_mask = send_mask;
+       return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
+}
+
+static long __init sclp_hsa_size_init(void)
+{
+       struct sdias_sccb *sccb = (void *) &sccb_early;
+
+       sccb_init_eq_size(sccb);
+       if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
+               return -EIO;
+       if (sccb->evbuf.blk_cnt != 0)
+               return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
+       return 0;
+}
+
+static long __init sclp_hsa_copy_wait(void)
+{
+       struct sccb_header *sccb = (void *) &sccb_early;
+
+       memset(sccb, 0, PAGE_SIZE);
+       sccb->length = PAGE_SIZE;
+       if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
+               return -EIO;
+       return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
+}
+
+unsigned long sclp_get_hsa_size(void)
+{
+       return sclp_hsa_size;
+}
+
+static void __init sclp_hsa_size_detect(void)
+{
+       long size;
+
+       /* First try synchronous interface (LPAR) */
+       if (sclp_set_event_mask(0, 0x40000010))
+               return;
+       size = sclp_hsa_size_init();
+       if (size < 0)
+               return;
+       if (size != 0)
+               goto out;
+       /* Then try asynchronous interface (z/VM) */
+       if (sclp_set_event_mask(0x00000010, 0x40000010))
+               return;
+       size = sclp_hsa_size_init();
+       if (size < 0)
+               return;
+       size = sclp_hsa_copy_wait();
+       if (size < 0)
+               return;
+out:
+       sclp_hsa_size = size;
+}
+
+void __init sclp_early_detect(void)
+{
+       sclp_facilities_detect();
+       sclp_hsa_size_detect();
+       sclp_set_event_mask(0, 0);
+}
index b1032931a1c41237766eaf6c38d7e5032e71e33d..561a0414b35282f97174d0cfb0e68ce87fab9c50 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Sclp "store data in absolut storage"
+ * SCLP "store data in absolute storage"
  *
- * Copyright IBM Corp. 2003, 2007
+ * Copyright IBM Corp. 2003, 2013
  * Author(s): Michael Holzheu
  */
 
@@ -14,6 +14,7 @@
 #include <asm/debug.h>
 #include <asm/ipl.h>
 
+#include "sclp_sdias.h"
 #include "sclp.h"
 #include "sclp_rw.h"
 
 #define SDIAS_RETRIES 300
 #define SDIAS_SLEEP_TICKS 50
 
-#define EQ_STORE_DATA  0x0
-#define EQ_SIZE                0x1
-#define DI_FCP_DUMP    0x0
-#define ASA_SIZE_32    0x0
-#define ASA_SIZE_64    0x1
-#define EVSTATE_ALL_STORED     0x0
-#define EVSTATE_NO_DATA                0x3
-#define EVSTATE_PART_STORED    0x10
-
 static struct debug_info *sdias_dbf;
 
 static struct sclp_register sclp_sdias_register = {
        .send_mask = EVTYP_SDIAS_MASK,
 };
 
-struct sdias_evbuf {
-       struct  evbuf_header hdr;
-       u8      event_qual;
-       u8      data_id;
-       u64     reserved2;
-       u32     event_id;
-       u16     reserved3;
-       u8      asa_size;
-       u8      event_status;
-       u32     reserved4;
-       u32     blk_cnt;
-       u64     asa;
-       u32     reserved5;
-       u32     fbn;
-       u32     reserved6;
-       u32     lbn;
-       u16     reserved7;
-       u16     dbs;
-} __attribute__((packed));
-
-struct sdias_sccb {
-       struct sccb_header  hdr;
-       struct sdias_evbuf  evbuf;
-} __attribute__((packed));
-
 static struct sdias_sccb sccb __attribute__((aligned(4096)));
 static struct sdias_evbuf sdias_evbuf;
 
@@ -148,8 +115,8 @@ int sclp_sdias_blk_count(void)
        sccb.hdr.length = sizeof(sccb);
        sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
        sccb.evbuf.hdr.type = EVTYP_SDIAS;
-       sccb.evbuf.event_qual = EQ_SIZE;
-       sccb.evbuf.data_id = DI_FCP_DUMP;
+       sccb.evbuf.event_qual = SDIAS_EQ_SIZE;
+       sccb.evbuf.data_id = SDIAS_DI_FCP_DUMP;
        sccb.evbuf.event_id = 4712;
        sccb.evbuf.dbs = 1;
 
@@ -208,13 +175,13 @@ int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
        sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
        sccb.evbuf.hdr.type = EVTYP_SDIAS;
        sccb.evbuf.hdr.flags = 0;
-       sccb.evbuf.event_qual = EQ_STORE_DATA;
-       sccb.evbuf.data_id = DI_FCP_DUMP;
+       sccb.evbuf.event_qual = SDIAS_EQ_STORE_DATA;
+       sccb.evbuf.data_id = SDIAS_DI_FCP_DUMP;
        sccb.evbuf.event_id = 4712;
 #ifdef CONFIG_64BIT
-       sccb.evbuf.asa_size = ASA_SIZE_64;
+       sccb.evbuf.asa_size = SDIAS_ASA_SIZE_64;
 #else
-       sccb.evbuf.asa_size = ASA_SIZE_32;
+       sccb.evbuf.asa_size = SDIAS_ASA_SIZE_32;
 #endif
        sccb.evbuf.event_status = 0;
        sccb.evbuf.blk_cnt = nr_blks;
@@ -240,20 +207,19 @@ int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
        }
 
        switch (sdias_evbuf.event_status) {
-               case EVSTATE_ALL_STORED:
-                       TRACE("all stored\n");
-                       break;
-               case EVSTATE_PART_STORED:
-                       TRACE("part stored: %i\n", sdias_evbuf.blk_cnt);
-                       break;
-               case EVSTATE_NO_DATA:
-                       TRACE("no data\n");
-                       /* fall through */
-               default:
-                       pr_err("Error from SCLP while copying hsa. "
-                              "Event status = %x\n",
-                              sdias_evbuf.event_status);
-                       rc = -EIO;
+       case SDIAS_EVSTATE_ALL_STORED:
+               TRACE("all stored\n");
+               break;
+       case SDIAS_EVSTATE_PART_STORED:
+               TRACE("part stored: %i\n", sdias_evbuf.blk_cnt);
+               break;
+       case SDIAS_EVSTATE_NO_DATA:
+               TRACE("no data\n");
+               /* fall through */
+       default:
+               pr_err("Error from SCLP while copying hsa. Event status = %x\n",
+                      sdias_evbuf.event_status);
+               rc = -EIO;
        }
 out:
        mutex_unlock(&sdias_mutex);
diff --git a/drivers/s390/char/sclp_sdias.h b/drivers/s390/char/sclp_sdias.h
new file mode 100644 (file)
index 0000000..f2431c4
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SCLP "store data in absolute storage"
+ *
+ * Copyright IBM Corp. 2003, 2013
+ */
+
+#ifndef SCLP_SDIAS_H
+#define SCLP_SDIAS_H
+
+#include "sclp.h"
+
+#define SDIAS_EQ_STORE_DATA            0x0
+#define SDIAS_EQ_SIZE                  0x1
+#define SDIAS_DI_FCP_DUMP              0x0
+#define SDIAS_ASA_SIZE_32              0x0
+#define SDIAS_ASA_SIZE_64              0x1
+#define SDIAS_EVSTATE_ALL_STORED       0x0
+#define SDIAS_EVSTATE_NO_DATA          0x3
+#define SDIAS_EVSTATE_PART_STORED      0x10
+
+struct sdias_evbuf {
+       struct  evbuf_header hdr;
+       u8      event_qual;
+       u8      data_id;
+       u64     reserved2;
+       u32     event_id;
+       u16     reserved3;
+       u8      asa_size;
+       u8      event_status;
+       u32     reserved4;
+       u32     blk_cnt;
+       u64     asa;
+       u32     reserved5;
+       u32     fbn;
+       u32     reserved6;
+       u32     lbn;
+       u16     reserved7;
+       u16     dbs;
+} __packed;
+
+struct sdias_sccb {
+       struct sccb_header      hdr;
+       struct sdias_evbuf      evbuf;
+} __packed;
+
+#endif /* SCLP_SDIAS_H */
index ffb1fcf0bf5bed9928f53e1205f8b6b01635f6b6..3d8e4d63f51418c876f9918e0be77be628d2afb3 100644 (file)
@@ -328,9 +328,9 @@ static ssize_t zcore_read(struct file *file, char __user *buf, size_t count,
        mem_offs = 0;
 
        /* Copy from HSA data */
-       if (*ppos < (ZFCPDUMP_HSA_SIZE + HEADER_SIZE)) {
-               size = min((count - hdr_count), (size_t) (ZFCPDUMP_HSA_SIZE
-                          - mem_start));
+       if (*ppos < sclp_get_hsa_size() + HEADER_SIZE) {
+               size = min((count - hdr_count),
+                          (size_t) (sclp_get_hsa_size() - mem_start));
                rc = memcpy_hsa_user(buf + hdr_count, mem_start, size);
                if (rc)
                        goto fail;
@@ -490,7 +490,7 @@ static ssize_t zcore_hsa_read(struct file *filp, char __user *buf,
        static char str[18];
 
        if (hsa_available)
-               snprintf(str, sizeof(str), "%lx\n", ZFCPDUMP_HSA_SIZE);
+               snprintf(str, sizeof(str), "%lx\n", sclp_get_hsa_size());
        else
                snprintf(str, sizeof(str), "0\n");
        return simple_read_from_buffer(buf, count, ppos, str, strlen(str));
@@ -584,17 +584,9 @@ static int __init sys_info_init(enum arch_id arch, unsigned long mem_end)
 
 static int __init check_sdias(void)
 {
-       int rc, act_hsa_size;
-
-       rc = sclp_sdias_blk_count();
-       if (rc < 0) {
+       if (!sclp_get_hsa_size()) {
                TRACE("Could not determine HSA size\n");
-               return rc;
-       }
-       act_hsa_size = (rc - 1) * PAGE_SIZE;
-       if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
-               TRACE("HSA size too small: %i\n", act_hsa_size);
-               return -EINVAL;
+               return -ENODEV;
        }
        return 0;
 }
@@ -662,7 +654,7 @@ static int __init zcore_reipl_init(void)
        ipl_block = (void *) __get_free_page(GFP_KERNEL);
        if (!ipl_block)
                return -ENOMEM;
-       if (ipib_info.ipib < ZFCPDUMP_HSA_SIZE)
+       if (ipib_info.ipib < sclp_get_hsa_size())
                rc = memcpy_hsa_kernel(ipl_block, ipib_info.ipib, PAGE_SIZE);
        else
                rc = memcpy_real(ipl_block, (void *) ipib_info.ipib, PAGE_SIZE);
index aca7bfc113aaeb4067043cd10bdc0662dd8ec286..3a2ee4a740b4465da4bd80948bd5daa57e703cae 100644 (file)
@@ -190,7 +190,7 @@ static struct subchannel *eadm_get_idle_sch(void)
        return NULL;
 }
 
-static int eadm_start_aob(struct aob *aob)
+int eadm_start_aob(struct aob *aob)
 {
        struct eadm_private *private;
        struct subchannel *sch;
@@ -218,6 +218,7 @@ out_unlock:
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(eadm_start_aob);
 
 static int eadm_subchannel_probe(struct subchannel *sch)
 {
@@ -380,11 +381,6 @@ static struct css_driver eadm_subchannel_driver = {
        .restore = eadm_subchannel_restore,
 };
 
-static struct eadm_ops eadm_ops = {
-       .eadm_start = eadm_start_aob,
-       .owner = THIS_MODULE,
-};
-
 static int __init eadm_sch_init(void)
 {
        int ret;
@@ -404,7 +400,6 @@ static int __init eadm_sch_init(void)
        if (ret)
                goto cleanup;
 
-       register_eadm_ops(&eadm_ops);
        return ret;
 
 cleanup:
@@ -415,7 +410,6 @@ cleanup:
 
 static void __exit eadm_sch_exit(void)
 {
-       unregister_eadm_ops(&eadm_ops);
        css_driver_unregister(&eadm_subchannel_driver);
        isc_unregister(EADM_SCH_ISC);
        debug_unregister(eadm_debug);
index 46ec25632e8bd4ef8e0be26a3f515697abd7f760..15268edc54aea979c581e9135bb3c325b0d31dde 100644 (file)
@@ -15,8 +15,6 @@
 #include "chsc.h"
 
 static struct device *scm_root;
-static struct eadm_ops *eadm_ops;
-static DEFINE_MUTEX(eadm_ops_mutex);
 
 #define to_scm_dev(n) container_of(n, struct scm_device, dev)
 #define        to_scm_drv(d) container_of(d, struct scm_driver, drv)
@@ -73,49 +71,6 @@ void scm_driver_unregister(struct scm_driver *scmdrv)
 }
 EXPORT_SYMBOL_GPL(scm_driver_unregister);
 
-int scm_get_ref(void)
-{
-       int ret = 0;
-
-       mutex_lock(&eadm_ops_mutex);
-       if (!eadm_ops || !try_module_get(eadm_ops->owner))
-               ret = -ENOENT;
-       mutex_unlock(&eadm_ops_mutex);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(scm_get_ref);
-
-void scm_put_ref(void)
-{
-       mutex_lock(&eadm_ops_mutex);
-       module_put(eadm_ops->owner);
-       mutex_unlock(&eadm_ops_mutex);
-}
-EXPORT_SYMBOL_GPL(scm_put_ref);
-
-void register_eadm_ops(struct eadm_ops *ops)
-{
-       mutex_lock(&eadm_ops_mutex);
-       eadm_ops = ops;
-       mutex_unlock(&eadm_ops_mutex);
-}
-EXPORT_SYMBOL_GPL(register_eadm_ops);
-
-void unregister_eadm_ops(struct eadm_ops *ops)
-{
-       mutex_lock(&eadm_ops_mutex);
-       eadm_ops = NULL;
-       mutex_unlock(&eadm_ops_mutex);
-}
-EXPORT_SYMBOL_GPL(unregister_eadm_ops);
-
-int scm_start_aob(struct aob *aob)
-{
-       return eadm_ops->eadm_start(aob);
-}
-EXPORT_SYMBOL_GPL(scm_start_aob);
-
 void scm_irq_handler(struct aob *aob, int error)
 {
        struct aob_rq_header *aobrq = (void *) aob->request.data;
index 132a905b6bdb76e5012399eda5df32e04bbefa81..0ca64484cfa3328bd33d5e5b0cb028e7d4991424 100644 (file)
@@ -344,7 +344,7 @@ void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
 
 /**
  * zfcp_dbf_san_req - trace event for issued SAN request
- * @tag: indentifier for event
+ * @tag: identifier for event
  * @fsf_req: request containing issued CT data
  * d_id: destination ID
  */
@@ -361,7 +361,7 @@ void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
 
 /**
  * zfcp_dbf_san_res - trace event for received SAN request
- * @tag: indentifier for event
+ * @tag: identifier for event
  * @fsf_req: request containing issued CT data
  */
 void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
@@ -377,7 +377,7 @@ void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
 
 /**
  * zfcp_dbf_san_in_els - trace event for incoming ELS
- * @tag: indentifier for event
+ * @tag: identifier for event
  * @fsf_req: request containing issued CT data
  */
 void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
index d85ac1a9d2c0698b85c606ab6b2ff917cb0959ed..fbcd48d0bfc3397f2a5b202b093d06bbaa2420a6 100644 (file)
@@ -511,7 +511,8 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
                goto cleanup;
        }
 
-       if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr))) {
+       if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) ||
+           (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) {
                rcode = -EINVAL;
                goto cleanup;
        }
index 33c52bc2c7b461033b8845e7e538f072f9ab671f..97fd450aff09315194233e7a8ea1f06b566248ef 100644 (file)
@@ -1035,7 +1035,6 @@ static void arcmsr_remove(struct pci_dev *pdev)
        pci_release_regions(pdev);
        scsi_host_put(host);
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
 }
 
 static void arcmsr_shutdown(struct pci_dev *pdev)
index 15a629d8ed081efe1e5b9e13160703c3d2f8fe6e..a795d81ef8750881aa55cf47c5558a5cdb7da175 100644 (file)
@@ -3144,8 +3144,6 @@ static void atp870u_remove (struct pci_dev *pdev)
        atp870u_free_tables(pshost);
        printk(KERN_INFO "scsi_host_put : %p\n",pshost);
        scsi_host_put(pshost);
-       printk(KERN_INFO "pci_set_drvdata : %p\n",pdev);
-       pci_set_drvdata(pdev, NULL);    
 }
 MODULE_LICENSE("GPL");
 
index 7591fa4e28bb2be8ed6e6a64e972568429457f20..fc80a325a1e6577c8fb5225d9f8a7ea614311540 100644 (file)
@@ -804,7 +804,6 @@ bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
        /* Disable PCIE Advanced Error Recovery (AER) */
        pci_disable_pcie_error_reporting(pdev);
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
 }
 
 bfa_status_t
index 5be718c241c4f329edb1c23e684daa7b4681a0f1..e4cf23df4b4f094d64a40332c81facd39da4097c 100644 (file)
@@ -126,7 +126,7 @@ static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
 
 /**
  * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  * @action:    action, ARM or DISARM. For now only ARM_CQE is used
  *
  * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
@@ -756,7 +756,7 @@ void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
 /**
  * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
  * @hba:       adapter structure pointer
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
  *     iscsi connection context clean-up process
@@ -791,7 +791,7 @@ int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
 /**
  * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
  * @hba:               adapter structure pointer
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  */
@@ -851,7 +851,7 @@ static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
 /**
  * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
  * @hba:               adapter structure pointer
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  */
@@ -920,7 +920,7 @@ static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
  * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
  *
  * @hba:               adapter structure pointer
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
  */
@@ -939,7 +939,7 @@ int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
 
 /**
  * setup_qp_page_tables - iscsi QP page table setup function
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
  *     64-bit address in big endian format. Whereas 10G/sec (57710) requires
@@ -1046,7 +1046,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
 /**
  * bnx2i_alloc_qp_resc - allocates required resources for QP.
  * @hba:       adapter structure pointer
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
  *     memory for SQ/RQ/CQ and page tables. EP structure elements such
@@ -1191,7 +1191,7 @@ mem_alloc_err:
 /**
  * bnx2i_free_qp_resc - free memory resources held by QP
  * @hba:       adapter structure pointer
- * @ep:        endpoint (transport indentifier) structure
+ * @ep:        endpoint (transport identifier) structure
  *
  * Free QP resources - SQ/RQ/CQ memory and page tables.
  */
index fabeb88602acb65c8b5b7e493314f30822d0227e..854dad7d5b03318d10077d2e367eeb6ca8242dc6 100644 (file)
@@ -596,7 +596,7 @@ void bnx2i_drop_session(struct iscsi_cls_session *cls_session)
 /**
  * bnx2i_ep_destroy_list_add - add an entry to EP destroy list
  * @hba:       pointer to adapter instance
- * @ep:                pointer to endpoint (transport indentifier) structure
+ * @ep:                pointer to endpoint (transport identifier) structure
  *
  * EP destroy queue manager
  */
@@ -613,7 +613,7 @@ static int bnx2i_ep_destroy_list_add(struct bnx2i_hba *hba,
  * bnx2i_ep_destroy_list_del - add an entry to EP destroy list
  *
  * @hba:               pointer to adapter instance
- * @ep:                pointer to endpoint (transport indentifier) structure
+ * @ep:                pointer to endpoint (transport identifier) structure
  *
  * EP destroy queue manager
  */
@@ -630,7 +630,7 @@ static int bnx2i_ep_destroy_list_del(struct bnx2i_hba *hba,
 /**
  * bnx2i_ep_ofld_list_add - add an entry to ep offload pending list
  * @hba:       pointer to adapter instance
- * @ep:                pointer to endpoint (transport indentifier) structure
+ * @ep:                pointer to endpoint (transport identifier) structure
  *
  * pending conn offload completion queue manager
  */
@@ -646,7 +646,7 @@ static int bnx2i_ep_ofld_list_add(struct bnx2i_hba *hba,
 /**
  * bnx2i_ep_ofld_list_del - add an entry to ep offload pending list
  * @hba:               pointer to adapter instance
- * @ep:                pointer to endpoint (transport indentifier) structure
+ * @ep:                pointer to endpoint (transport identifier) structure
  *
  * pending conn offload completion queue manager
  */
@@ -721,7 +721,7 @@ bnx2i_find_ep_in_destroy_list(struct bnx2i_hba *hba, u32 iscsi_cid)
 /**
  * bnx2i_ep_active_list_add - add an entry to ep active list
  * @hba:       pointer to adapter instance
- * @ep:                pointer to endpoint (transport indentifier) structure
+ * @ep:                pointer to endpoint (transport identifier) structure
  *
  * current active conn queue manager
  */
@@ -737,7 +737,7 @@ static void bnx2i_ep_active_list_add(struct bnx2i_hba *hba,
 /**
  * bnx2i_ep_active_list_del - deletes an entry to ep active list
  * @hba:       pointer to adapter instance
- * @ep:                pointer to endpoint (transport indentifier) structure
+ * @ep:                pointer to endpoint (transport identifier) structure
  *
  * current active conn queue manager
  */
@@ -1695,7 +1695,7 @@ no_nx2_route:
 /**
  * bnx2i_tear_down_conn - tear down iscsi/tcp connection and free resources
  * @hba:       pointer to adapter instance
- * @ep:                endpoint (transport indentifier) structure
+ * @ep:                endpoint (transport identifier) structure
  *
  * destroys cm_sock structure and on chip iscsi context
  */
index 00346fe939d554b5d089980718cd2fac1492ba41..1aafc331ee63a1a2d9380ffd53710da3466bbf96 100644 (file)
@@ -1010,7 +1010,6 @@ err_lnode_exit:
        csio_hw_stop(hw);
        spin_unlock_irq(&hw->lock);
        csio_lnodes_unblock_request(hw);
-       pci_set_drvdata(hw->pdev, NULL);
        csio_lnodes_exit(hw, 0);
        csio_hw_free(hw);
 err_pci_exit:
@@ -1044,7 +1043,6 @@ static void csio_remove_one(struct pci_dev *pdev)
 
        csio_lnodes_exit(hw, 0);
        csio_hw_free(hw);
-       pci_set_drvdata(pdev, NULL);
        csio_pci_exit(pdev, &bars);
 }
 
index 42e8624a9b9a1137fe77088e1efa3f3b0186fa7f..83d9bf6fa6ca9989717e0fd9f4ae20b9b8d7e724 100644 (file)
@@ -4861,7 +4861,6 @@ static void dc395x_remove_one(struct pci_dev *dev)
        adapter_uninit(acb);
        pci_disable_device(dev);
        scsi_host_put(scsi_host);
-       pci_set_drvdata(dev, NULL);
 }
 
 
index be09b101b4a148534caafb39071ee7827904e648..33e4ec2bfe734eefda1cd049bfde7f1112cf0ea2 100644 (file)
@@ -1005,7 +1005,6 @@ static void fnic_remove(struct pci_dev *pdev)
        fnic_iounmap(fnic);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
        scsi_host_put(lp->host);
 }
 
index 6d55b4e7e7923121d58535ab1a7ff83c50298c8c..ee4fa40a50b131597a3e1b6960bffc17191f2d03 100644 (file)
@@ -594,8 +594,6 @@ static void gdth_pci_remove_one(struct pci_dev *pdev)
 {
        gdth_ha_str *ha = pci_get_drvdata(pdev);
 
-       pci_set_drvdata(pdev, NULL);
-
        list_del(&ha->list);
        gdth_remove_one(ha);
 
index fb5a8981515057b8bbffe5423a41afbe9bc7e71d..22f6432eb4755a20af732e8c4d4060e9fbb9e909 100644 (file)
@@ -5017,7 +5017,6 @@ static void hpsa_remove_one(struct pci_dev *pdev)
        kfree(h->hba_inquiry_data);
        pci_disable_device(pdev);
        pci_release_regions(pdev);
-       pci_set_drvdata(pdev, NULL);
        kfree(h);
 }
 
index ca6bf2af7ce8b7b0fb8a657f1f511f33f44f5028..68c94cc85c35da9dd6e4ebab0052867f5c07c01f 100644 (file)
@@ -4581,8 +4581,6 @@ lpfc_disable_pci_dev(struct lpfc_hba *phba)
        /* Release PCI resource and disable PCI device */
        pci_release_selected_regions(pdev, bars);
        pci_disable_device(pdev);
-       /* Null out PCI private reference to driver */
-       pci_set_drvdata(pdev, NULL);
 
        return;
 }
@@ -9429,7 +9427,6 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
        /* Disable interrupt */
        lpfc_sli_disable_intr(phba);
 
-       pci_set_drvdata(pdev, NULL);
        scsi_host_put(shost);
 
        /*
index 515c9629e9fedf0679257a762b553045858070c1..d1a4b82836ea6936f55504e33bcaabb5db9adbee 100644 (file)
@@ -534,7 +534,6 @@ megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        return 0;
 
 out_cmm_unreg:
-       pci_set_drvdata(pdev, NULL);
        megaraid_cmm_unregister(adapter);
 out_fini_mbox:
        megaraid_fini_mbox(adapter);
@@ -594,11 +593,6 @@ megaraid_detach_one(struct pci_dev *pdev)
        // detach from the IO sub-system
        megaraid_io_detach(adapter);
 
-       // reset the device state in the PCI structure. We check this
-       // condition when we enter here. If the device state is NULL,
-       // that would mean the device has already been removed
-       pci_set_drvdata(pdev, NULL);
-
        // Unregister from common management module
        //
        // FIXME: this must return success or failure for conditions if there
index 2cf9470dd11b55a0840f8d31f9a10c257c1c56d5..0a743a5d16477a5e168f02a77a99e90f201caac3 100644 (file)
@@ -4451,7 +4451,6 @@ retry_irq_register:
        megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL;
        megasas_mgmt_info.max_index--;
 
-       pci_set_drvdata(pdev, NULL);
        instance->instancet->disable_intr(instance);
        if (instance->msix_vectors)
                for (i = 0 ; i < instance->msix_vectors; i++)
@@ -4807,8 +4806,6 @@ static void megasas_detach_one(struct pci_dev *pdev)
                }
        }
 
-       pci_set_drvdata(instance->pdev, NULL);
-
        instance->instancet->disable_intr(instance);
 
        if (instance->msix_vectors)
@@ -4850,8 +4847,6 @@ static void megasas_detach_one(struct pci_dev *pdev)
                                instance->evt_detail, instance->evt_detail_h);
        scsi_host_put(host);
 
-       pci_set_drvdata(pdev, NULL);
-
        pci_disable_device(pdev);
 
        return;
index 7b7381d7671fdc9cfeecdf3c256984b0261d3116..5ff978be249d22b37df66601787cceca92933047 100644 (file)
@@ -657,7 +657,6 @@ static void mvs_pci_remove(struct pci_dev *pdev)
        tasklet_kill(&((struct mvs_prv_info *)sha->lldd_ha)->mv_tasklet);
 #endif
 
-       pci_set_drvdata(pdev, NULL);
        sas_unregister_ha(sha);
        sas_remove_host(mvi->shost);
        scsi_remove_host(mvi->shost);
index 6b1b4e91e53f655128edf0235589bd02081963fb..6c1f223a8e1d335fa7c86a374e470e666e848906 100644 (file)
@@ -1411,7 +1411,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
 
                if (res) {
                        del_timer(&task->slow_task->timer);
-                       mv_printk("executing internel task failed:%d\n", res);
+                       mv_printk("executing internal task failed:%d\n", res);
                        goto ex_err;
                }
 
index c3601b57a80c796cd32aebeb3c00f3d94e89b06f..edbee8dc62c9ab546b5340ca06cbef62ba4cecf3 100644 (file)
@@ -2583,7 +2583,6 @@ static int mvumi_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        return 0;
 
 fail_io_attach:
-       pci_set_drvdata(pdev, NULL);
        mhba->instancet->disable_intr(mhba);
        free_irq(mhba->pdev->irq, mhba);
 fail_init_irq:
@@ -2618,7 +2617,6 @@ static void mvumi_detach_one(struct pci_dev *pdev)
        free_irq(mhba->pdev->irq, mhba);
        mvumi_release_fw(mhba);
        scsi_host_put(host);
-       pci_set_drvdata(pdev, NULL);
        pci_disable_device(pdev);
        dev_dbg(&pdev->dev, "driver is removed!\n");
 }
index 5982a587babc875a56aaba6ed9983860c8b593a9..7d014b11df62fc086be5d8deff46ad4facaa4499 100644 (file)
@@ -1615,7 +1615,7 @@ struct ncb {
        spinlock_t      smp_lock;       /* Lock for SMP threading       */
 
        /*----------------------------------------------------------------
-       **      Chip and controller indentification.
+       **      Chip and controller identification.
        **----------------------------------------------------------------
        */
        int             unit;           /* Unit number                  */
index 662bf13c42f012720f114cdf6d4355a0446c5280..34f5f5ffef056ec2e86e44726dd99c13ae204877 100644 (file)
@@ -909,7 +909,6 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
        struct pm8001_hba_info *pm8001_ha;
        int i;
        pm8001_ha = sha->lldd_ha;
-       pci_set_drvdata(pdev, NULL);
        sas_unregister_ha(sha);
        sas_remove_host(pm8001_ha->shost);
        list_del(&pm8001_ha->list);
index 1eb7b0280a45447fc1855ce0a653488cf1591002..bd6f743d87a78af19c698d38d70291723fd28dfb 100644 (file)
@@ -1512,7 +1512,8 @@ static int pmcraid_notify_aen(
        }
 
        result =
-               genlmsg_multicast(skb, 0, pmcraid_event_family.id, GFP_ATOMIC);
+               genlmsg_multicast(&pmcraid_event_family, skb, 0,
+                                 pmcraid_event_family.id, GFP_ATOMIC);
 
        /* If there are no listeners, genlmsg_multicast may return non-zero
         * value.
@@ -6049,7 +6050,6 @@ out_release_regions:
 
 out_disable_device:
        atomic_dec(&pmcraid_adapter_count);
-       pci_set_drvdata(pdev, NULL);
        pci_disable_device(pdev);
        return -ENODEV;
 }
index bcd57f699ebbcc7dad7d597044c7bc54da22cf52..52be35e0300c901ac18faff6ded2aaf65e43b675 100644 (file)
@@ -3179,7 +3179,6 @@ qla2x00_remove_one(struct pci_dev *pdev)
        pci_disable_pcie_error_reporting(pdev);
 
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
 }
 
 static void
index 6dc3e99b7f9cd22e23aa0df57e223a3ed6a0227f..a28d5e624aabcdd729e4c64c4c904549e21d6e17 100644 (file)
@@ -7827,7 +7827,6 @@ static void qla4xxx_remove_adapter(struct pci_dev *pdev)
 
        pci_disable_pcie_error_reporting(pdev);
        pci_disable_device(pdev);
-       pci_set_drvdata(pdev, NULL);
 }
 
 /**
index f379c7f3034cd55392355189e081b45547323008..2700a5a09bd45a103b857b2f6a81da42834e4d28 100644 (file)
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/delay.h>
 
 #include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_transport.h>
 #include <scsi/scsi_transport_srp.h>
+#include "scsi_priv.h"
 #include "scsi_transport_srp_internal.h"
 
 struct srp_host_attrs {
@@ -38,7 +41,7 @@ struct srp_host_attrs {
 #define to_srp_host_attrs(host)        ((struct srp_host_attrs *)(host)->shost_data)
 
 #define SRP_HOST_ATTRS 0
-#define SRP_RPORT_ATTRS 3
+#define SRP_RPORT_ATTRS 8
 
 struct srp_internal {
        struct scsi_transport_template t;
@@ -54,6 +57,36 @@ struct srp_internal {
 
 #define        dev_to_rport(d) container_of(d, struct srp_rport, dev)
 #define transport_class_to_srp_rport(dev) dev_to_rport((dev)->parent)
+static inline struct Scsi_Host *rport_to_shost(struct srp_rport *r)
+{
+       return dev_to_shost(r->dev.parent);
+}
+
+/**
+ * srp_tmo_valid() - check timeout combination validity
+ *
+ * The combination of the timeout parameters must be such that SCSI commands
+ * are finished in a reasonable time. Hence do not allow the fast I/O fail
+ * timeout to exceed SCSI_DEVICE_BLOCK_MAX_TIMEOUT. Furthermore, these
+ * parameters must be such that multipath can detect failed paths timely.
+ * Hence do not allow all three parameters to be disabled simultaneously.
+ */
+int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)
+{
+       if (reconnect_delay < 0 && fast_io_fail_tmo < 0 && dev_loss_tmo < 0)
+               return -EINVAL;
+       if (reconnect_delay == 0)
+               return -EINVAL;
+       if (fast_io_fail_tmo > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
+               return -EINVAL;
+       if (dev_loss_tmo >= LONG_MAX / HZ)
+               return -EINVAL;
+       if (fast_io_fail_tmo >= 0 && dev_loss_tmo >= 0 &&
+           fast_io_fail_tmo >= dev_loss_tmo)
+               return -EINVAL;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(srp_tmo_valid);
 
 static int srp_host_setup(struct transport_container *tc, struct device *dev,
                          struct device *cdev)
@@ -134,10 +167,465 @@ static ssize_t store_srp_rport_delete(struct device *dev,
 
 static DEVICE_ATTR(delete, S_IWUSR, NULL, store_srp_rport_delete);
 
+static ssize_t show_srp_rport_state(struct device *dev,
+                                   struct device_attribute *attr,
+                                   char *buf)
+{
+       static const char *const state_name[] = {
+               [SRP_RPORT_RUNNING]     = "running",
+               [SRP_RPORT_BLOCKED]     = "blocked",
+               [SRP_RPORT_FAIL_FAST]   = "fail-fast",
+               [SRP_RPORT_LOST]        = "lost",
+       };
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+       enum srp_rport_state state = rport->state;
+
+       return sprintf(buf, "%s\n",
+                      (unsigned)state < ARRAY_SIZE(state_name) ?
+                      state_name[state] : "???");
+}
+
+static DEVICE_ATTR(state, S_IRUGO, show_srp_rport_state, NULL);
+
+static ssize_t srp_show_tmo(char *buf, int tmo)
+{
+       return tmo >= 0 ? sprintf(buf, "%d\n", tmo) : sprintf(buf, "off\n");
+}
+
+static int srp_parse_tmo(int *tmo, const char *buf)
+{
+       int res = 0;
+
+       if (strncmp(buf, "off", 3) != 0)
+               res = kstrtoint(buf, 0, tmo);
+       else
+               *tmo = -1;
+
+       return res;
+}
+
+static ssize_t show_reconnect_delay(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+
+       return srp_show_tmo(buf, rport->reconnect_delay);
+}
+
+static ssize_t store_reconnect_delay(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, const size_t count)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+       int res, delay;
+
+       res = srp_parse_tmo(&delay, buf);
+       if (res)
+               goto out;
+       res = srp_tmo_valid(delay, rport->fast_io_fail_tmo,
+                           rport->dev_loss_tmo);
+       if (res)
+               goto out;
+
+       if (rport->reconnect_delay <= 0 && delay > 0 &&
+           rport->state != SRP_RPORT_RUNNING) {
+               queue_delayed_work(system_long_wq, &rport->reconnect_work,
+                                  delay * HZ);
+       } else if (delay <= 0) {
+               cancel_delayed_work(&rport->reconnect_work);
+       }
+       rport->reconnect_delay = delay;
+       res = count;
+
+out:
+       return res;
+}
+
+static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR, show_reconnect_delay,
+                  store_reconnect_delay);
+
+static ssize_t show_failed_reconnects(struct device *dev,
+                                     struct device_attribute *attr, char *buf)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+
+       return sprintf(buf, "%d\n", rport->failed_reconnects);
+}
+
+static DEVICE_ATTR(failed_reconnects, S_IRUGO, show_failed_reconnects, NULL);
+
+static ssize_t show_srp_rport_fast_io_fail_tmo(struct device *dev,
+                                              struct device_attribute *attr,
+                                              char *buf)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+
+       return srp_show_tmo(buf, rport->fast_io_fail_tmo);
+}
+
+static ssize_t store_srp_rport_fast_io_fail_tmo(struct device *dev,
+                                               struct device_attribute *attr,
+                                               const char *buf, size_t count)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+       int res;
+       int fast_io_fail_tmo;
+
+       res = srp_parse_tmo(&fast_io_fail_tmo, buf);
+       if (res)
+               goto out;
+       res = srp_tmo_valid(rport->reconnect_delay, fast_io_fail_tmo,
+                           rport->dev_loss_tmo);
+       if (res)
+               goto out;
+       rport->fast_io_fail_tmo = fast_io_fail_tmo;
+       res = count;
+
+out:
+       return res;
+}
+
+static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
+                  show_srp_rport_fast_io_fail_tmo,
+                  store_srp_rport_fast_io_fail_tmo);
+
+static ssize_t show_srp_rport_dev_loss_tmo(struct device *dev,
+                                          struct device_attribute *attr,
+                                          char *buf)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+
+       return srp_show_tmo(buf, rport->dev_loss_tmo);
+}
+
+static ssize_t store_srp_rport_dev_loss_tmo(struct device *dev,
+                                           struct device_attribute *attr,
+                                           const char *buf, size_t count)
+{
+       struct srp_rport *rport = transport_class_to_srp_rport(dev);
+       int res;
+       int dev_loss_tmo;
+
+       res = srp_parse_tmo(&dev_loss_tmo, buf);
+       if (res)
+               goto out;
+       res = srp_tmo_valid(rport->reconnect_delay, rport->fast_io_fail_tmo,
+                           dev_loss_tmo);
+       if (res)
+               goto out;
+       rport->dev_loss_tmo = dev_loss_tmo;
+       res = count;
+
+out:
+       return res;
+}
+
+static DEVICE_ATTR(dev_loss_tmo, S_IRUGO | S_IWUSR,
+                  show_srp_rport_dev_loss_tmo,
+                  store_srp_rport_dev_loss_tmo);
+
+static int srp_rport_set_state(struct srp_rport *rport,
+                              enum srp_rport_state new_state)
+{
+       enum srp_rport_state old_state = rport->state;
+
+       lockdep_assert_held(&rport->mutex);
+
+       switch (new_state) {
+       case SRP_RPORT_RUNNING:
+               switch (old_state) {
+               case SRP_RPORT_LOST:
+                       goto invalid;
+               default:
+                       break;
+               }
+               break;
+       case SRP_RPORT_BLOCKED:
+               switch (old_state) {
+               case SRP_RPORT_RUNNING:
+                       break;
+               default:
+                       goto invalid;
+               }
+               break;
+       case SRP_RPORT_FAIL_FAST:
+               switch (old_state) {
+               case SRP_RPORT_LOST:
+                       goto invalid;
+               default:
+                       break;
+               }
+               break;
+       case SRP_RPORT_LOST:
+               break;
+       }
+       rport->state = new_state;
+       return 0;
+
+invalid:
+       return -EINVAL;
+}
+
+/**
+ * srp_reconnect_work() - reconnect and schedule a new attempt if necessary
+ */
+static void srp_reconnect_work(struct work_struct *work)
+{
+       struct srp_rport *rport = container_of(to_delayed_work(work),
+                                       struct srp_rport, reconnect_work);
+       struct Scsi_Host *shost = rport_to_shost(rport);
+       int delay, res;
+
+       res = srp_reconnect_rport(rport);
+       if (res != 0) {
+               shost_printk(KERN_ERR, shost,
+                            "reconnect attempt %d failed (%d)\n",
+                            ++rport->failed_reconnects, res);
+               delay = rport->reconnect_delay *
+                       min(100, max(1, rport->failed_reconnects - 10));
+               if (delay > 0)
+                       queue_delayed_work(system_long_wq,
+                                          &rport->reconnect_work, delay * HZ);
+       }
+}
+
+static void __rport_fail_io_fast(struct srp_rport *rport)
+{
+       struct Scsi_Host *shost = rport_to_shost(rport);
+       struct srp_internal *i;
+
+       lockdep_assert_held(&rport->mutex);
+
+       if (srp_rport_set_state(rport, SRP_RPORT_FAIL_FAST))
+               return;
+       scsi_target_unblock(rport->dev.parent, SDEV_TRANSPORT_OFFLINE);
+
+       /* Involve the LLD if possible to terminate all I/O on the rport. */
+       i = to_srp_internal(shost->transportt);
+       if (i->f->terminate_rport_io)
+               i->f->terminate_rport_io(rport);
+}
+
+/**
+ * rport_fast_io_fail_timedout() - fast I/O failure timeout handler
+ */
+static void rport_fast_io_fail_timedout(struct work_struct *work)
+{
+       struct srp_rport *rport = container_of(to_delayed_work(work),
+                                       struct srp_rport, fast_io_fail_work);
+       struct Scsi_Host *shost = rport_to_shost(rport);
+
+       pr_info("fast_io_fail_tmo expired for SRP %s / %s.\n",
+               dev_name(&rport->dev), dev_name(&shost->shost_gendev));
+
+       mutex_lock(&rport->mutex);
+       if (rport->state == SRP_RPORT_BLOCKED)
+               __rport_fail_io_fast(rport);
+       mutex_unlock(&rport->mutex);
+}
+
+/**
+ * rport_dev_loss_timedout() - device loss timeout handler
+ */
+static void rport_dev_loss_timedout(struct work_struct *work)
+{
+       struct srp_rport *rport = container_of(to_delayed_work(work),
+                                       struct srp_rport, dev_loss_work);
+       struct Scsi_Host *shost = rport_to_shost(rport);
+       struct srp_internal *i = to_srp_internal(shost->transportt);
+
+       pr_info("dev_loss_tmo expired for SRP %s / %s.\n",
+               dev_name(&rport->dev), dev_name(&shost->shost_gendev));
+
+       mutex_lock(&rport->mutex);
+       WARN_ON(srp_rport_set_state(rport, SRP_RPORT_LOST) != 0);
+       scsi_target_unblock(rport->dev.parent, SDEV_TRANSPORT_OFFLINE);
+       mutex_unlock(&rport->mutex);
+
+       i->f->rport_delete(rport);
+}
+
+static void __srp_start_tl_fail_timers(struct srp_rport *rport)
+{
+       struct Scsi_Host *shost = rport_to_shost(rport);
+       int delay, fast_io_fail_tmo, dev_loss_tmo;
+
+       lockdep_assert_held(&rport->mutex);
+
+       if (!rport->deleted) {
+               delay = rport->reconnect_delay;
+               fast_io_fail_tmo = rport->fast_io_fail_tmo;
+               dev_loss_tmo = rport->dev_loss_tmo;
+               pr_debug("%s current state: %d\n",
+                        dev_name(&shost->shost_gendev), rport->state);
+
+               if (delay > 0)
+                       queue_delayed_work(system_long_wq,
+                                          &rport->reconnect_work,
+                                          1UL * delay * HZ);
+               if (fast_io_fail_tmo >= 0 &&
+                   srp_rport_set_state(rport, SRP_RPORT_BLOCKED) == 0) {
+                       pr_debug("%s new state: %d\n",
+                                dev_name(&shost->shost_gendev),
+                                rport->state);
+                       scsi_target_block(&shost->shost_gendev);
+                       queue_delayed_work(system_long_wq,
+                                          &rport->fast_io_fail_work,
+                                          1UL * fast_io_fail_tmo * HZ);
+               }
+               if (dev_loss_tmo >= 0)
+                       queue_delayed_work(system_long_wq,
+                                          &rport->dev_loss_work,
+                                          1UL * dev_loss_tmo * HZ);
+       } else {
+               pr_debug("%s has already been deleted\n",
+                        dev_name(&shost->shost_gendev));
+               srp_rport_set_state(rport, SRP_RPORT_FAIL_FAST);
+               scsi_target_unblock(&shost->shost_gendev,
+                                   SDEV_TRANSPORT_OFFLINE);
+       }
+}
+
+/**
+ * srp_start_tl_fail_timers() - start the transport layer failure timers
+ *
+ * Start the transport layer fast I/O failure and device loss timers. Do not
+ * modify a timer that was already started.
+ */
+void srp_start_tl_fail_timers(struct srp_rport *rport)
+{
+       mutex_lock(&rport->mutex);
+       __srp_start_tl_fail_timers(rport);
+       mutex_unlock(&rport->mutex);
+}
+EXPORT_SYMBOL(srp_start_tl_fail_timers);
+
+/**
+ * scsi_request_fn_active() - number of kernel threads inside scsi_request_fn()
+ */
+static int scsi_request_fn_active(struct Scsi_Host *shost)
+{
+       struct scsi_device *sdev;
+       struct request_queue *q;
+       int request_fn_active = 0;
+
+       shost_for_each_device(sdev, shost) {
+               q = sdev->request_queue;
+
+               spin_lock_irq(q->queue_lock);
+               request_fn_active += q->request_fn_active;
+               spin_unlock_irq(q->queue_lock);
+       }
+
+       return request_fn_active;
+}
+
+/**
+ * srp_reconnect_rport() - reconnect to an SRP target port
+ *
+ * Blocks SCSI command queueing before invoking reconnect() such that
+ * queuecommand() won't be invoked concurrently with reconnect() from outside
+ * the SCSI EH. This is important since a reconnect() implementation may
+ * reallocate resources needed by queuecommand().
+ *
+ * Notes:
+ * - This function neither waits until outstanding requests have finished nor
+ *   tries to abort these. It is the responsibility of the reconnect()
+ *   function to finish outstanding commands before reconnecting to the target
+ *   port.
+ * - It is the responsibility of the caller to ensure that the resources
+ *   reallocated by the reconnect() function won't be used while this function
+ *   is in progress. One possible strategy is to invoke this function from
+ *   the context of the SCSI EH thread only. Another possible strategy is to
+ *   lock the rport mutex inside each SCSI LLD callback that can be invoked by
+ *   the SCSI EH (the scsi_host_template.eh_*() functions and also the
+ *   scsi_host_template.queuecommand() function).
+ */
+int srp_reconnect_rport(struct srp_rport *rport)
+{
+       struct Scsi_Host *shost = rport_to_shost(rport);
+       struct srp_internal *i = to_srp_internal(shost->transportt);
+       struct scsi_device *sdev;
+       int res;
+
+       pr_debug("SCSI host %s\n", dev_name(&shost->shost_gendev));
+
+       res = mutex_lock_interruptible(&rport->mutex);
+       if (res)
+               goto out;
+       scsi_target_block(&shost->shost_gendev);
+       while (scsi_request_fn_active(shost))
+               msleep(20);
+       res = i->f->reconnect(rport);
+       pr_debug("%s (state %d): transport.reconnect() returned %d\n",
+                dev_name(&shost->shost_gendev), rport->state, res);
+       if (res == 0) {
+               cancel_delayed_work(&rport->fast_io_fail_work);
+               cancel_delayed_work(&rport->dev_loss_work);
+
+               rport->failed_reconnects = 0;
+               srp_rport_set_state(rport, SRP_RPORT_RUNNING);
+               scsi_target_unblock(&shost->shost_gendev, SDEV_RUNNING);
+               /*
+                * If the SCSI error handler has offlined one or more devices,
+                * invoking scsi_target_unblock() won't change the state of
+                * these devices into running so do that explicitly.
+                */
+               spin_lock_irq(shost->host_lock);
+               __shost_for_each_device(sdev, shost)
+                       if (sdev->sdev_state == SDEV_OFFLINE)
+                               sdev->sdev_state = SDEV_RUNNING;
+               spin_unlock_irq(shost->host_lock);
+       } else if (rport->state == SRP_RPORT_RUNNING) {
+               /*
+                * srp_reconnect_rport() was invoked with fast_io_fail
+                * off. Mark the port as failed and start the TL failure
+                * timers if these had not yet been started.
+                */
+               __rport_fail_io_fast(rport);
+               scsi_target_unblock(&shost->shost_gendev,
+                                   SDEV_TRANSPORT_OFFLINE);
+               __srp_start_tl_fail_timers(rport);
+       } else if (rport->state != SRP_RPORT_BLOCKED) {
+               scsi_target_unblock(&shost->shost_gendev,
+                                   SDEV_TRANSPORT_OFFLINE);
+       }
+       mutex_unlock(&rport->mutex);
+
+out:
+       return res;
+}
+EXPORT_SYMBOL(srp_reconnect_rport);
+
+/**
+ * srp_timed_out() - SRP transport intercept of the SCSI timeout EH
+ *
+ * If a timeout occurs while an rport is in the blocked state, ask the SCSI
+ * EH to continue waiting (BLK_EH_RESET_TIMER). Otherwise let the SCSI core
+ * handle the timeout (BLK_EH_NOT_HANDLED).
+ *
+ * Note: This function is called from soft-IRQ context and with the request
+ * queue lock held.
+ */
+static enum blk_eh_timer_return srp_timed_out(struct scsi_cmnd *scmd)
+{
+       struct scsi_device *sdev = scmd->device;
+       struct Scsi_Host *shost = sdev->host;
+       struct srp_internal *i = to_srp_internal(shost->transportt);
+
+       pr_debug("timeout for sdev %s\n", dev_name(&sdev->sdev_gendev));
+       return i->f->reset_timer_if_blocked && scsi_device_blocked(sdev) ?
+               BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
+}
+
 static void srp_rport_release(struct device *dev)
 {
        struct srp_rport *rport = dev_to_rport(dev);
 
+       cancel_delayed_work_sync(&rport->reconnect_work);
+       cancel_delayed_work_sync(&rport->fast_io_fail_work);
+       cancel_delayed_work_sync(&rport->dev_loss_work);
+
        put_device(dev->parent);
        kfree(rport);
 }
@@ -184,6 +672,24 @@ static int srp_host_match(struct attribute_container *cont, struct device *dev)
        return &i->t.host_attrs.ac == cont;
 }
 
+/**
+ * srp_rport_get() - increment rport reference count
+ */
+void srp_rport_get(struct srp_rport *rport)
+{
+       get_device(&rport->dev);
+}
+EXPORT_SYMBOL(srp_rport_get);
+
+/**
+ * srp_rport_put() - decrement rport reference count
+ */
+void srp_rport_put(struct srp_rport *rport)
+{
+       put_device(&rport->dev);
+}
+EXPORT_SYMBOL(srp_rport_put);
+
 /**
  * srp_rport_add - add a SRP remote port to the device hierarchy
  * @shost:     scsi host the remote port is connected to.
@@ -196,12 +702,15 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
 {
        struct srp_rport *rport;
        struct device *parent = &shost->shost_gendev;
+       struct srp_internal *i = to_srp_internal(shost->transportt);
        int id, ret;
 
        rport = kzalloc(sizeof(*rport), GFP_KERNEL);
        if (!rport)
                return ERR_PTR(-ENOMEM);
 
+       mutex_init(&rport->mutex);
+
        device_initialize(&rport->dev);
 
        rport->dev.parent = get_device(parent);
@@ -210,6 +719,17 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
        memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
        rport->roles = ids->roles;
 
+       if (i->f->reconnect)
+               rport->reconnect_delay = i->f->reconnect_delay ?
+                       *i->f->reconnect_delay : 10;
+       INIT_DELAYED_WORK(&rport->reconnect_work, srp_reconnect_work);
+       rport->fast_io_fail_tmo = i->f->fast_io_fail_tmo ?
+               *i->f->fast_io_fail_tmo : 15;
+       rport->dev_loss_tmo = i->f->dev_loss_tmo ? *i->f->dev_loss_tmo : 60;
+       INIT_DELAYED_WORK(&rport->fast_io_fail_work,
+                         rport_fast_io_fail_timedout);
+       INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
+
        id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
        dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
 
@@ -259,6 +779,13 @@ void srp_rport_del(struct srp_rport *rport)
        transport_remove_device(dev);
        device_del(dev);
        transport_destroy_device(dev);
+
+       mutex_lock(&rport->mutex);
+       if (rport->state == SRP_RPORT_BLOCKED)
+               __rport_fail_io_fast(rport);
+       rport->deleted = true;
+       mutex_unlock(&rport->mutex);
+
        put_device(dev);
 }
 EXPORT_SYMBOL_GPL(srp_rport_del);
@@ -310,6 +837,8 @@ srp_attach_transport(struct srp_function_template *ft)
        if (!i)
                return NULL;
 
+       i->t.eh_timed_out = srp_timed_out;
+
        i->t.tsk_mgmt_response = srp_tsk_mgmt_response;
        i->t.it_nexus_response = srp_it_nexus_response;
 
@@ -327,6 +856,15 @@ srp_attach_transport(struct srp_function_template *ft)
        count = 0;
        i->rport_attrs[count++] = &dev_attr_port_id;
        i->rport_attrs[count++] = &dev_attr_roles;
+       if (ft->has_rport_state) {
+               i->rport_attrs[count++] = &dev_attr_state;
+               i->rport_attrs[count++] = &dev_attr_fast_io_fail_tmo;
+               i->rport_attrs[count++] = &dev_attr_dev_loss_tmo;
+       }
+       if (ft->reconnect) {
+               i->rport_attrs[count++] = &dev_attr_reconnect_delay;
+               i->rport_attrs[count++] = &dev_attr_failed_reconnects;
+       }
        if (ft->rport_delete)
                i->rport_attrs[count++] = &dev_attr_delete;
        i->rport_attrs[count++] = NULL;
index 325c31caa6e0dd98dbce0724b968a7ee5efcba69..1aa4befcfbd0120b11df14a4b0f918b00f5be72d 100644 (file)
@@ -1790,8 +1790,6 @@ static void stex_remove(struct pci_dev *pdev)
 
        scsi_remove_host(hba->host);
 
-       pci_set_drvdata(pdev, NULL);
-
        stex_hba_stop(hba);
 
        stex_hba_free(hba);
index b80bf709f104ade623662ea8c646dea308a67818..805369521df8eeb22de129d70432444b45269029 100644 (file)
@@ -174,7 +174,7 @@ struct sym_slcb {
  */
 struct sym_shcb {
        /*
-        *  Chip and controller indentification.
+        *  Chip and controller identification.
         */
        int             unit;
        char            inst_name[16];
index 11423615c2eaa8b8ea84a097e632204ca6d2503b..b006cf789ba1186ac3bac5a69c9ca71a17da8837 100644 (file)
@@ -2553,7 +2553,6 @@ static void dc390_remove_one(struct pci_dev *dev)
 
        pci_disable_device(dev);
        scsi_host_put(scsi_host);
-       pci_set_drvdata(dev, NULL);
 }
 
 static struct pci_device_id tmscsim_pci_tbl[] = {
index a823cf44e9494bdc506a2e4b86d7edb190ea76dc..8b9531204c2bb7ee570fb3d504a59803765a4ba6 100644 (file)
@@ -132,7 +132,6 @@ static void ufshcd_pci_remove(struct pci_dev *pdev)
        pm_runtime_forbid(&pdev->dev);
        pm_runtime_get_noresume(&pdev->dev);
        ufshcd_remove(hba);
-       pci_set_drvdata(pdev, NULL);
 }
 
 /**
index 3bfaa66fa0d16d31610ee33ef41c9cce10031f1a..b9755ec0e8123cdd7a3479659fb2111924dc3056 100644 (file)
@@ -1405,7 +1405,6 @@ out_release_resources:
 out_free_host:
        scsi_host_put(host);
 out_disable_device:
-       pci_set_drvdata(pdev, NULL);
        pci_disable_device(pdev);
 
        return error;
@@ -1445,7 +1444,6 @@ static void pvscsi_remove(struct pci_dev *pdev)
 
        scsi_host_put(host);
 
-       pci_set_drvdata(pdev, NULL);
        pci_disable_device(pdev);
 }
 
index b9f0192758d6d929aab86d087c443adc46154e66..6d207afec8cbdb578c9e5428d6018dff1d93690b 100644 (file)
@@ -150,7 +150,7 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
                                &dws->tx_sgl,
                                1,
                                DMA_MEM_TO_DEV,
-                               DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_DEST_UNMAP);
+                               DMA_PREP_INTERRUPT);
        txdesc->callback = dw_spi_dma_done;
        txdesc->callback_param = dws;
 
@@ -173,7 +173,7 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
                                &dws->rx_sgl,
                                1,
                                DMA_DEV_TO_MEM,
-                               DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_DEST_UNMAP);
+                               DMA_PREP_INTERRUPT);
        rxdesc->callback = dw_spi_dma_done;
        rxdesc->callback_param = dws;
 
index 8d85ddc4601173c14fd24ae6a5f7defe60b94102..18cc625d887f796aed4b082eb2366262aec8aaa8 100644 (file)
@@ -357,6 +357,19 @@ struct spi_device *spi_alloc_device(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_alloc_device);
 
+static void spi_dev_set_name(struct spi_device *spi)
+{
+       struct acpi_device *adev = ACPI_COMPANION(&spi->dev);
+
+       if (adev) {
+               dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));
+               return;
+       }
+
+       dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
+                    spi->chip_select);
+}
+
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -383,9 +396,7 @@ int spi_add_device(struct spi_device *spi)
        }
 
        /* Set the bus ID string */
-       dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
-                       spi->chip_select);
-
+       spi_dev_set_name(spi);
 
        /* We need to make sure there's no other device with this
         * chipselect **BEFORE** we call setup(), else we'll trash
@@ -1144,7 +1155,7 @@ static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level,
                return AE_NO_MEMORY;
        }
 
-       ACPI_HANDLE_SET(&spi->dev, handle);
+       ACPI_COMPANION_SET(&spi->dev, adev);
        spi->irq = -1;
 
        INIT_LIST_HEAD(&resource_list);
index 9221a74efd18a00cf31c24c79b3e271a7a181d85..93c7299e83539c2e38edb4d3b10e44867c2333dc 100644 (file)
@@ -42,7 +42,7 @@ struct ad7606_platform_data {
 
 /**
  * struct ad7606_chip_info - chip specifc information
- * @name:              indentification string for chip
+ * @name:              identification string for chip
  * @int_vref_mv:       the internal reference voltage
  * @channels:          channel specification
  * @num_channels:      number of channels
index b6cb593f55c6727046903828886dfe453530a00c..cbea5d84fed387bb00183d4cf217f2fbebc09739 100644 (file)
@@ -2,6 +2,11 @@
   (see drivers/media/IR/mceusb.c vs. lirc_mceusb.c in lirc cvs for an
   example of a previously completed port).
 
+- lirc_bt829 uses registers on a Mach64 VT, which has a separate kernel
+  framebuffer driver (atyfb) and userland X driver (mach64).  It can't
+  simply be converted to a normal PCI driver, but ideally it should be
+  coordinated with the other drivers.
+
 Please send patches to:
 Jarod Wilson <jarod@wilsonet.com>
 Greg Kroah-Hartman <greg@kroah.com>
index fbbdce4c119f71cab122bde5c203bb03b9ee43de..30edc740ac2546fcaea7b0dfcc82ec67c1eb7f06 100644 (file)
@@ -63,7 +63,7 @@ static bool debug;
        } while (0)
 
 static int atir_minor;
-static unsigned long pci_addr_phys;
+static phys_addr_t pci_addr_phys;
 static unsigned char *pci_addr_lin;
 
 static struct lirc_driver atir_driver;
@@ -78,11 +78,11 @@ static struct pci_dev *do_pci_probe(void)
                pci_addr_phys = 0;
                if (my_dev->resource[0].flags & IORESOURCE_MEM) {
                        pci_addr_phys = my_dev->resource[0].start;
-                       pr_info("memory at 0x%08X\n",
-                              (unsigned int)pci_addr_phys);
+                       pr_info("memory at %pa\n", &pci_addr_phys);
                }
                if (pci_addr_phys == 0) {
                        pr_err("no memory resource ?\n");
+                       pci_dev_put(my_dev);
                        return NULL;
                }
        } else {
@@ -120,13 +120,20 @@ static void atir_set_use_dec(void *data)
 int init_module(void)
 {
        struct pci_dev *pdev;
+       int rc;
 
        pdev = do_pci_probe();
        if (pdev == NULL)
                return -ENODEV;
 
-       if (!atir_init_start())
-               return -ENODEV;
+       rc = pci_enable_device(pdev);
+       if (rc)
+               goto err_put_dev;
+
+       if (!atir_init_start()) {
+               rc = -ENODEV;
+               goto err_disable;
+       }
 
        strcpy(atir_driver.name, "ATIR");
        atir_driver.minor       = -1;
@@ -142,17 +149,31 @@ int init_module(void)
        atir_minor = lirc_register_driver(&atir_driver);
        if (atir_minor < 0) {
                pr_err("failed to register driver!\n");
-               return atir_minor;
+               rc = atir_minor;
+               goto err_unmap;
        }
        dprintk("driver is registered on minor %d\n", atir_minor);
 
        return 0;
+
+err_unmap:
+       iounmap(pci_addr_lin);
+err_disable:
+       pci_disable_device(pdev);
+err_put_dev:
+       pci_dev_put(pdev);
+       return rc;
 }
 
 
 void cleanup_module(void)
 {
+       struct pci_dev *pdev = to_pci_dev(atir_driver.dev);
+
        lirc_unregister_driver(atir_minor);
+       iounmap(pci_addr_lin);
+       pci_disable_device(pdev);
+       pci_dev_put(pdev);
 }
 
 
index f6bc4c91ab35f4737338e945a70b7a7fedf84f4c..2e3a98575d47f9fbdddebecdd2a17d9741ffd09e 100644 (file)
@@ -707,7 +707,8 @@ static irqreturn_t irq_handler(int i, void *blah)
                                pr_warn("ignoring spike: %d %d %lx %lx %lx %lx\n",
                                        dcd, sense,
                                        tv.tv_sec, lasttv.tv_sec,
-                                       tv.tv_usec, lasttv.tv_usec);
+                                       (unsigned long)tv.tv_usec,
+                                       (unsigned long)lasttv.tv_usec);
                                continue;
                        }
 
@@ -719,7 +720,8 @@ static irqreturn_t irq_handler(int i, void *blah)
                                pr_warn("%d %d %lx %lx %lx %lx\n",
                                        dcd, sense,
                                        tv.tv_sec, lasttv.tv_sec,
-                                       tv.tv_usec, lasttv.tv_usec);
+                                       (unsigned long)tv.tv_usec,
+                                       (unsigned long)lasttv.tv_usec);
                                data = PULSE_MASK;
                        } else if (deltv > 15) {
                                data = PULSE_MASK; /* really long time */
@@ -728,7 +730,8 @@ static irqreturn_t irq_handler(int i, void *blah)
                                        pr_warn("AIEEEE: %d %d %lx %lx %lx %lx\n",
                                                dcd, sense,
                                                tv.tv_sec, lasttv.tv_sec,
-                                               tv.tv_usec, lasttv.tv_usec);
+                                               (unsigned long)tv.tv_usec,
+                                               (unsigned long)lasttv.tv_usec);
                                        /*
                                         * detecting pulse while this
                                         * MUST be a space!
index 11d5338b4f2ffaa458ddc6729a5ea48298e17227..0feeaadf29dc12c47eee290c7616cfaf915e6ace 100644 (file)
@@ -61,6 +61,9 @@
 #include <media/lirc_dev.h>
 #include <media/lirc.h>
 
+/* Max transfer size done by I2C transfer functions */
+#define MAX_XFER_SIZE  64
+
 struct IR;
 
 struct IR_rx {
@@ -941,7 +944,14 @@ static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
                        schedule();
                        set_current_state(TASK_INTERRUPTIBLE);
                } else {
-                       unsigned char buf[rbuf->chunk_size];
+                       unsigned char buf[MAX_XFER_SIZE];
+
+                       if (rbuf->chunk_size > sizeof(buf)) {
+                               zilog_error("chunk_size is too big (%d)!\n",
+                                           rbuf->chunk_size);
+                               ret = -EINVAL;
+                               break;
+                       }
                        m = lirc_buffer_read(rbuf, buf);
                        if (m == rbuf->chunk_size) {
                                ret = copy_to_user((void *)outbuf+written, buf,
index 76d5bbd4d93c38f3e25274f8d7b337eb808f1b7d..0c349c8595e44d542c4625de893cc709ca1acfe7 100644 (file)
@@ -1,4 +1,5 @@
 config USB_MSI3101
        tristate "Mirics MSi3101 SDR Dongle"
        depends on USB && VIDEO_DEV && VIDEO_V4L2
-        select VIDEOBUF2_VMALLOC
+       select VIDEOBUF2_CORE
+       select VIDEOBUF2_VMALLOC
index 32d9953bc36eb00ad0ec31bf2c8c5fbe77ad354b..145295a5db72baa1942217c4d5dc19023a278132 100644 (file)
@@ -176,18 +176,27 @@ static void solo_vout_config(struct solo_dev *solo_dev)
 static int solo_dma_vin_region(struct solo_dev *solo_dev, u32 off,
                               u16 val, int reg_size)
 {
-       u16 buf[64];
-       int i;
-       int ret = 0;
+       u16 *buf;
+       const int n = 64, size = n * sizeof(*buf);
+       int i, ret = 0;
+
+       buf = kmalloc(size, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
 
-       for (i = 0; i < sizeof(buf) >> 1; i++)
+       for (i = 0; i < n; i++)
                buf[i] = cpu_to_le16(val);
 
-       for (i = 0; i < reg_size; i += sizeof(buf))
-               ret |= solo_p2m_dma(solo_dev, 1, buf,
-                                   SOLO_MOTION_EXT_ADDR(solo_dev) + off + i,
-                                   sizeof(buf), 0, 0);
+       for (i = 0; i < reg_size; i += size) {
+               ret = solo_p2m_dma(solo_dev, 1, buf,
+                                  SOLO_MOTION_EXT_ADDR(solo_dev) + off + i,
+                                  size, 0, 0);
+
+               if (ret)
+                       break;
+       }
 
+       kfree(buf);
        return ret;
 }
 
index a4c589604b028d7d74e1a7f895b6ab3aecbeac75..d582c5b84c14cc2c8821d9a982ba47746187cf76 100644 (file)
@@ -95,38 +95,11 @@ static unsigned char vop_6110_pal_cif[] = {
        0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
 };
 
-struct vop_header {
-       /* VE_STATUS0 */
-       u32 mpeg_size:20, sad_motion_flag:1, video_motion_flag:1, vop_type:2,
-               channel:5, source_fl:1, interlace:1, progressive:1;
-
-       /* VE_STATUS1 */
-       u32 vsize:8, hsize:8, last_queue:4, nop0:8, scale:4;
-
-       /* VE_STATUS2 */
-       u32 mpeg_off;
-
-       /* VE_STATUS3 */
-       u32 jpeg_off;
-
-       /* VE_STATUS4 */
-       u32 jpeg_size:20, interval:10, nop1:2;
-
-       /* VE_STATUS5/6 */
-       u32 sec, usec;
-
-       /* VE_STATUS7/8/9 */
-       u32 nop2[3];
-
-       /* VE_STATUS10 */
-       u32 mpeg_size_alt:20, nop3:12;
-
-       u32 end_nops[5];
-} __packed;
+typedef __le32 vop_header[16];
 
 struct solo_enc_buf {
        enum solo_enc_types     type;
-       struct vop_header       *vh;
+       const vop_header        *vh;
        int                     motion;
 };
 
@@ -346,7 +319,7 @@ static int enc_get_mpeg_dma(struct solo_dev *solo_dev, dma_addr_t dma,
 /* Build a descriptor queue out of an SG list and send it to the P2M for
  * processing. */
 static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
-                         struct vb2_dma_sg_desc *vbuf, int off, int size,
+                         struct sg_table *vbuf, int off, int size,
                          unsigned int base, unsigned int base_size)
 {
        struct solo_dev *solo_dev = solo_enc->solo_dev;
@@ -359,7 +332,7 @@ static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
 
        solo_enc->desc_count = 1;
 
-       for_each_sg(vbuf->sglist, sg, vbuf->num_pages, i) {
+       for_each_sg(vbuf->sgl, sg, vbuf->nents, i) {
                struct solo_p2m_desc *desc;
                dma_addr_t dma;
                int len;
@@ -430,84 +403,145 @@ static int solo_send_desc(struct solo_enc_dev *solo_enc, int skip,
                                 solo_enc->desc_count - 1);
 }
 
+/* Extract values from VOP header - VE_STATUSxx */
+static inline int vop_interlaced(const vop_header *vh)
+{
+       return (__le32_to_cpu((*vh)[0]) >> 30) & 1;
+}
+
+static inline u8 vop_channel(const vop_header *vh)
+{
+       return (__le32_to_cpu((*vh)[0]) >> 24) & 0x1F;
+}
+
+static inline u8 vop_type(const vop_header *vh)
+{
+       return (__le32_to_cpu((*vh)[0]) >> 22) & 3;
+}
+
+static inline u32 vop_mpeg_size(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[0]) & 0xFFFFF;
+}
+
+static inline u8 vop_hsize(const vop_header *vh)
+{
+       return (__le32_to_cpu((*vh)[1]) >> 8) & 0xFF;
+}
+
+static inline u8 vop_vsize(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[1]) & 0xFF;
+}
+
+static inline u32 vop_mpeg_offset(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[2]);
+}
+
+static inline u32 vop_jpeg_offset(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[3]);
+}
+
+static inline u32 vop_jpeg_size(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[4]) & 0xFFFFF;
+}
+
+static inline u32 vop_sec(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[5]);
+}
+
+static inline u32 vop_usec(const vop_header *vh)
+{
+       return __le32_to_cpu((*vh)[6]);
+}
+
 static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
-               struct vb2_buffer *vb, struct vop_header *vh)
+                         struct vb2_buffer *vb, const vop_header *vh)
 {
        struct solo_dev *solo_dev = solo_enc->solo_dev;
-       struct vb2_dma_sg_desc *vbuf = vb2_dma_sg_plane_desc(vb, 0);
+       struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
        int frame_size;
        int ret;
 
        vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
 
-       if (vb2_plane_size(vb, 0) < vh->jpeg_size + solo_enc->jpeg_len)
+       if (vb2_plane_size(vb, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
                return -EIO;
 
-       sg_copy_from_buffer(vbuf->sglist, vbuf->num_pages,
-                       solo_enc->jpeg_header,
-                       solo_enc->jpeg_len);
-
-       frame_size = (vh->jpeg_size + solo_enc->jpeg_len + (DMA_ALIGN - 1))
+       frame_size = (vop_jpeg_size(vh) + solo_enc->jpeg_len + (DMA_ALIGN - 1))
                & ~(DMA_ALIGN - 1);
-       vb2_set_plane_payload(vb, 0, vh->jpeg_size + solo_enc->jpeg_len);
+       vb2_set_plane_payload(vb, 0, vop_jpeg_size(vh) + solo_enc->jpeg_len);
 
-       dma_map_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
+       /* may discard all previous data in vbuf->sgl */
+       dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
                        DMA_FROM_DEVICE);
-       ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf, vh->jpeg_off,
-                       frame_size, SOLO_JPEG_EXT_ADDR(solo_dev),
-                       SOLO_JPEG_EXT_SIZE(solo_dev));
-       dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
+       ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf,
+                            vop_jpeg_offset(vh) - SOLO_JPEG_EXT_ADDR(solo_dev),
+                            frame_size, SOLO_JPEG_EXT_ADDR(solo_dev),
+                            SOLO_JPEG_EXT_SIZE(solo_dev));
+       dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
                        DMA_FROM_DEVICE);
+
+       /* add the header only after dma_unmap_sg() */
+       sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
+                           solo_enc->jpeg_header, solo_enc->jpeg_len);
+
        return ret;
 }
 
 static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
-               struct vb2_buffer *vb, struct vop_header *vh)
+               struct vb2_buffer *vb, const vop_header *vh)
 {
        struct solo_dev *solo_dev = solo_enc->solo_dev;
-       struct vb2_dma_sg_desc *vbuf = vb2_dma_sg_plane_desc(vb, 0);
+       struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
        int frame_off, frame_size;
        int skip = 0;
        int ret;
 
-       if (vb2_plane_size(vb, 0) < vh->mpeg_size)
+       if (vb2_plane_size(vb, 0) < vop_mpeg_size(vh))
                return -EIO;
 
        /* If this is a key frame, add extra header */
-       if (!vh->vop_type) {
-               sg_copy_from_buffer(vbuf->sglist, vbuf->num_pages,
-                               solo_enc->vop,
-                               solo_enc->vop_len);
-
+       vb->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME);
+       if (!vop_type(vh)) {
                skip = solo_enc->vop_len;
-
                vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
-               vb2_set_plane_payload(vb, 0, vh->mpeg_size + solo_enc->vop_len);
+               vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh) + solo_enc->vop_len);
        } else {
                vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
-               vb2_set_plane_payload(vb, 0, vh->mpeg_size);
+               vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh));
        }
 
        /* Now get the actual mpeg payload */
-       frame_off = (vh->mpeg_off + sizeof(*vh))
+       frame_off = (vop_mpeg_offset(vh) - SOLO_MP4E_EXT_ADDR(solo_dev) + sizeof(*vh))
                % SOLO_MP4E_EXT_SIZE(solo_dev);
-       frame_size = (vh->mpeg_size + skip + (DMA_ALIGN - 1))
+       frame_size = (vop_mpeg_size(vh) + skip + (DMA_ALIGN - 1))
                & ~(DMA_ALIGN - 1);
 
-       dma_map_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
+       /* may discard all previous data in vbuf->sgl */
+       dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
                        DMA_FROM_DEVICE);
        ret = solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size,
                        SOLO_MP4E_EXT_ADDR(solo_dev),
                        SOLO_MP4E_EXT_SIZE(solo_dev));
-       dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sglist, vbuf->num_pages,
+       dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents,
                        DMA_FROM_DEVICE);
+
+       /* add the header only after dma_unmap_sg() */
+       if (!vop_type(vh))
+               sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
+                                   solo_enc->vop, solo_enc->vop_len);
        return ret;
 }
 
 static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
                            struct vb2_buffer *vb, struct solo_enc_buf *enc_buf)
 {
-       struct vop_header *vh = enc_buf->vh;
+       const vop_header *vh = enc_buf->vh;
        int ret;
 
        /* Check for motion flags */
@@ -531,8 +565,8 @@ static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
 
        if (!ret) {
                vb->v4l2_buf.sequence = solo_enc->sequence++;
-               vb->v4l2_buf.timestamp.tv_sec = vh->sec;
-               vb->v4l2_buf.timestamp.tv_usec = vh->usec;
+               vb->v4l2_buf.timestamp.tv_sec = vop_sec(vh);
+               vb->v4l2_buf.timestamp.tv_usec = vop_usec(vh);
        }
 
        vb2_buffer_done(vb, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
@@ -605,15 +639,13 @@ static void solo_handle_ring(struct solo_dev *solo_dev)
 
                /* FAIL... */
                if (enc_get_mpeg_dma(solo_dev, solo_dev->vh_dma, off,
-                                    sizeof(struct vop_header)))
+                                    sizeof(vop_header)))
                        continue;
 
-               enc_buf.vh = (struct vop_header *)solo_dev->vh_buf;
-               enc_buf.vh->mpeg_off -= SOLO_MP4E_EXT_ADDR(solo_dev);
-               enc_buf.vh->jpeg_off -= SOLO_JPEG_EXT_ADDR(solo_dev);
+               enc_buf.vh = solo_dev->vh_buf;
 
                /* Sanity check */
-               if (enc_buf.vh->mpeg_off != off)
+               if (vop_mpeg_offset(enc_buf.vh) != SOLO_MP4E_EXT_ADDR(solo_dev) + off)
                        continue;
 
                if (solo_motion_detected(solo_enc))
@@ -1329,7 +1361,7 @@ int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
 
        init_waitqueue_head(&solo_dev->ring_thread_wait);
 
-       solo_dev->vh_size = sizeof(struct vop_header);
+       solo_dev->vh_size = sizeof(vop_header);
        solo_dev->vh_buf = pci_alloc_consistent(solo_dev->pdev,
                                                solo_dev->vh_size,
                                                &solo_dev->vh_dma);
index 6f91d2e34b2a7bd971e8e3d3060b8e98b4f4f566..f1bbb8cb74e69db4fcc2d327c745d7e261f685f6 100644 (file)
@@ -94,7 +94,6 @@
 #define SOLO_ENC_MODE_HD1              1
 #define SOLO_ENC_MODE_D1               9
 
-#define SOLO_DEFAULT_GOP               30
 #define SOLO_DEFAULT_QP                        3
 
 #ifndef V4L2_BUF_FLAG_MOTION_ON
index 03a567199bbe313cd36dd0a4d62e3d9f7cab957d..f1d511a9475b4dc29ec28864cb3b948e8ba13183 100644 (file)
@@ -1608,15 +1608,17 @@ exit:
 EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
 
 #ifdef CONFIG_NET
+static const struct genl_multicast_group thermal_event_mcgrps[] = {
+       { .name = THERMAL_GENL_MCAST_GROUP_NAME, },
+};
+
 static struct genl_family thermal_event_genl_family = {
        .id = GENL_ID_GENERATE,
        .name = THERMAL_GENL_FAMILY_NAME,
        .version = THERMAL_GENL_VERSION,
        .maxattr = THERMAL_GENL_ATTR_MAX,
-};
-
-static struct genl_multicast_group thermal_event_mcgrp = {
-       .name = THERMAL_GENL_MCAST_GROUP_NAME,
+       .mcgrps = thermal_event_mcgrps,
+       .n_mcgrps = ARRAY_SIZE(thermal_event_mcgrps),
 };
 
 int thermal_generate_netlink_event(struct thermal_zone_device *tz,
@@ -1677,7 +1679,8 @@ int thermal_generate_netlink_event(struct thermal_zone_device *tz,
                return result;
        }
 
-       result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
+       result = genlmsg_multicast(&thermal_event_genl_family, skb, 0,
+                                  0, GFP_ATOMIC);
        if (result)
                dev_err(&tz->device, "Failed to send netlink event:%d", result);
 
@@ -1687,17 +1690,7 @@ EXPORT_SYMBOL_GPL(thermal_generate_netlink_event);
 
 static int genetlink_init(void)
 {
-       int result;
-
-       result = genl_register_family(&thermal_event_genl_family);
-       if (result)
-               return result;
-
-       result = genl_register_mc_group(&thermal_event_genl_family,
-                                       &thermal_event_mcgrp);
-       if (result)
-               genl_unregister_family(&thermal_event_genl_family);
-       return result;
+       return genl_register_family(&thermal_event_genl_family);
 }
 
 static void genetlink_exit(void)
index 537750261aaa2fe5a5e2de8fdb3e6ee0adf8fe4d..7d8103cd3e2ec56eacbb5a5d3f3f332597e190ff 100644 (file)
@@ -1433,7 +1433,7 @@ static void work_fn_rx(struct work_struct *work)
        desc = s->desc_rx[new];
 
        if (dma_async_is_tx_complete(s->chan_rx, s->active_rx, NULL, NULL) !=
-           DMA_SUCCESS) {
+           DMA_COMPLETE) {
                /* Handle incomplete DMA receive */
                struct dma_chan *chan = s->chan_rx;
                struct shdma_desc *sh_desc = container_of(desc,
index db535b0aa172c85b3787a476b8fe3adeefbe3e6f..fed7f68d025d1174e9e6882c3cba59a94de8220d 100644 (file)
@@ -28,7 +28,7 @@ config USB_DEFAULT_PERSIST
        bool "Enable USB persist by default"
        default y
        help
-         Say N here if you don't want USB power session persistance
+         Say N here if you don't want USB power session persistence
          enabled by default.  If you say N it will make suspended USB
          devices that lose power get reenumerated as if they had been
          unplugged, causing any mounted filesystems to be lost.  The
index 06cec635e703adc3f9859ae8ca53dbb124820cd4..a7c04e24ca484deb233db5dcfd995b73427c4cc0 100644 (file)
@@ -5501,6 +5501,6 @@ acpi_handle usb_get_hub_port_acpi_handle(struct usb_device *hdev,
        if (!hub)
                return NULL;
 
-       return DEVICE_ACPI_HANDLE(&hub->ports[port1 - 1]->dev);
+       return ACPI_HANDLE(&hub->ports[port1 - 1]->dev);
 }
 #endif
index 255c14464bf2ea7a30dffab6fa1770c7b030c0aa..4e243c37f17f50ab197582a3ee5d4662e933d368 100644 (file)
@@ -173,7 +173,7 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
                }
 
                /* root hub's parent is the usb hcd. */
-               parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
+               parent_handle = ACPI_HANDLE(dev->parent);
                *handle = acpi_get_child(parent_handle, udev->portnum);
                if (!*handle)
                        return -ENODEV;
@@ -194,7 +194,7 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
 
                        raw_port_num = usb_hcd_find_raw_port_number(hcd,
                                port_num);
-                       *handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev),
+                       *handle = acpi_get_child(ACPI_HANDLE(&udev->dev),
                                raw_port_num);
                        if (!*handle)
                                return -ENODEV;
index 36db5d98dd2f5e900d9dafe3bd6e0e10b30e082e..fb80d68f4d3366e5672498da5bd05f3140e7a753 100644 (file)
@@ -10,6 +10,8 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -19,6 +21,7 @@
 #include <linux/err.h>
 #include <linux/pwm.h>
 #include <linux/pwm_backlight.h>
+#include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 
 struct pwm_bl_data {
@@ -27,6 +30,11 @@ struct pwm_bl_data {
        unsigned int            period;
        unsigned int            lth_brightness;
        unsigned int            *levels;
+       bool                    enabled;
+       struct regulator        *power_supply;
+       int                     enable_gpio;
+       unsigned long           enable_gpio_flags;
+       unsigned int            scale;
        int                     (*notify)(struct device *,
                                          int brightness);
        void                    (*notify_after)(struct device *,
@@ -35,11 +43,65 @@ struct pwm_bl_data {
        void                    (*exit)(struct device *);
 };
 
+static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
+{
+       int err;
+
+       if (pb->enabled)
+               return;
+
+       err = regulator_enable(pb->power_supply);
+       if (err < 0)
+               dev_err(pb->dev, "failed to enable power supply\n");
+
+       if (gpio_is_valid(pb->enable_gpio)) {
+               if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW)
+                       gpio_set_value(pb->enable_gpio, 0);
+               else
+                       gpio_set_value(pb->enable_gpio, 1);
+       }
+
+       pwm_enable(pb->pwm);
+       pb->enabled = true;
+}
+
+static void pwm_backlight_power_off(struct pwm_bl_data *pb)
+{
+       if (!pb->enabled)
+               return;
+
+       pwm_config(pb->pwm, 0, pb->period);
+       pwm_disable(pb->pwm);
+
+       if (gpio_is_valid(pb->enable_gpio)) {
+               if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW)
+                       gpio_set_value(pb->enable_gpio, 1);
+               else
+                       gpio_set_value(pb->enable_gpio, 0);
+       }
+
+       regulator_disable(pb->power_supply);
+       pb->enabled = false;
+}
+
+static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
+{
+       unsigned int lth = pb->lth_brightness;
+       int duty_cycle;
+
+       if (pb->levels)
+               duty_cycle = pb->levels[brightness];
+       else
+               duty_cycle = brightness;
+
+       return (duty_cycle * (pb->period - lth) / pb->scale) + lth;
+}
+
 static int pwm_backlight_update_status(struct backlight_device *bl)
 {
        struct pwm_bl_data *pb = bl_get_data(bl);
        int brightness = bl->props.brightness;
-       int max = bl->props.max_brightness;
+       int duty_cycle;
 
        if (bl->props.power != FB_BLANK_UNBLANK ||
            bl->props.fb_blank != FB_BLANK_UNBLANK ||
@@ -49,24 +111,12 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
        if (pb->notify)
                brightness = pb->notify(pb->dev, brightness);
 
-       if (brightness == 0) {
-               pwm_config(pb->pwm, 0, pb->period);
-               pwm_disable(pb->pwm);
-       } else {
-               int duty_cycle;
-
-               if (pb->levels) {
-                       duty_cycle = pb->levels[brightness];
-                       max = pb->levels[max];
-               } else {
-                       duty_cycle = brightness;
-               }
-
-               duty_cycle = pb->lth_brightness +
-                    (duty_cycle * (pb->period - pb->lth_brightness) / max);
+       if (brightness > 0) {
+               duty_cycle = compute_duty_cycle(pb, brightness);
                pwm_config(pb->pwm, duty_cycle, pb->period);
-               pwm_enable(pb->pwm);
-       }
+               pwm_backlight_power_on(pb, brightness);
+       } else
+               pwm_backlight_power_off(pb);
 
        if (pb->notify_after)
                pb->notify_after(pb->dev, brightness);
@@ -98,6 +148,7 @@ static int pwm_backlight_parse_dt(struct device *dev,
                                  struct platform_pwm_backlight_data *data)
 {
        struct device_node *node = dev->of_node;
+       enum of_gpio_flags flags;
        struct property *prop;
        int length;
        u32 value;
@@ -138,11 +189,13 @@ static int pwm_backlight_parse_dt(struct device *dev,
                data->max_brightness--;
        }
 
-       /*
-        * TODO: Most users of this driver use a number of GPIOs to control
-        *       backlight power. Support for specifying these needs to be
-        *       added.
-        */
+       data->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0,
+                                                   &flags);
+       if (data->enable_gpio == -EPROBE_DEFER)
+               return -EPROBE_DEFER;
+
+       if (gpio_is_valid(data->enable_gpio) && (flags & OF_GPIO_ACTIVE_LOW))
+               data->enable_gpio_flags |= PWM_BACKLIGHT_GPIO_ACTIVE_LOW;
 
        return 0;
 }
@@ -168,7 +221,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        struct backlight_properties props;
        struct backlight_device *bl;
        struct pwm_bl_data *pb;
-       unsigned int max;
        int ret;
 
        if (!data) {
@@ -195,16 +247,46 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        }
 
        if (data->levels) {
-               max = data->levels[data->max_brightness];
+               unsigned int i;
+
+               for (i = 0; i <= data->max_brightness; i++)
+                       if (data->levels[i] > pb->scale)
+                               pb->scale = data->levels[i];
+
                pb->levels = data->levels;
        } else
-               max = data->max_brightness;
+               pb->scale = data->max_brightness;
 
+       pb->enable_gpio = data->enable_gpio;
+       pb->enable_gpio_flags = data->enable_gpio_flags;
        pb->notify = data->notify;
        pb->notify_after = data->notify_after;
        pb->check_fb = data->check_fb;
        pb->exit = data->exit;
        pb->dev = &pdev->dev;
+       pb->enabled = false;
+
+       if (gpio_is_valid(pb->enable_gpio)) {
+               unsigned long flags;
+
+               if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW)
+                       flags = GPIOF_OUT_INIT_HIGH;
+               else
+                       flags = GPIOF_OUT_INIT_LOW;
+
+               ret = gpio_request_one(pb->enable_gpio, flags, "enable");
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n",
+                               pb->enable_gpio, ret);
+                       goto err_alloc;
+               }
+       }
+
+       pb->power_supply = devm_regulator_get(&pdev->dev, "power");
+       if (IS_ERR(pb->power_supply)) {
+               ret = PTR_ERR(pb->power_supply);
+               goto err_gpio;
+       }
 
        pb->pwm = devm_pwm_get(&pdev->dev, NULL);
        if (IS_ERR(pb->pwm)) {
@@ -214,7 +296,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                if (IS_ERR(pb->pwm)) {
                        dev_err(&pdev->dev, "unable to request legacy PWM\n");
                        ret = PTR_ERR(pb->pwm);
-                       goto err_alloc;
+                       goto err_gpio;
                }
        }
 
@@ -229,7 +311,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                pwm_set_period(pb->pwm, data->pwm_period_ns);
 
        pb->period = pwm_get_period(pb->pwm);
-       pb->lth_brightness = data->lth_brightness * (pb->period / max);
+       pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale);
 
        memset(&props, 0, sizeof(struct backlight_properties));
        props.type = BACKLIGHT_RAW;
@@ -239,7 +321,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        if (IS_ERR(bl)) {
                dev_err(&pdev->dev, "failed to register backlight\n");
                ret = PTR_ERR(bl);
-               goto err_alloc;
+               goto err_gpio;
        }
 
        if (data->dft_brightness > data->max_brightness) {
@@ -255,6 +337,9 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, bl);
        return 0;
 
+err_gpio:
+       if (gpio_is_valid(pb->enable_gpio))
+               gpio_free(pb->enable_gpio);
 err_alloc:
        if (data->exit)
                data->exit(&pdev->dev);
@@ -267,10 +352,11 @@ static int pwm_backlight_remove(struct platform_device *pdev)
        struct pwm_bl_data *pb = bl_get_data(bl);
 
        backlight_device_unregister(bl);
-       pwm_config(pb->pwm, 0, pb->period);
-       pwm_disable(pb->pwm);
+       pwm_backlight_power_off(pb);
+
        if (pb->exit)
                pb->exit(&pdev->dev);
+
        return 0;
 }
 
@@ -282,10 +368,12 @@ static int pwm_backlight_suspend(struct device *dev)
 
        if (pb->notify)
                pb->notify(pb->dev, 0);
-       pwm_config(pb->pwm, 0, pb->period);
-       pwm_disable(pb->pwm);
+
+       pwm_backlight_power_off(pb);
+
        if (pb->notify_after)
                pb->notify_after(pb->dev, 0);
+
        return 0;
 }
 
@@ -294,12 +382,19 @@ static int pwm_backlight_resume(struct device *dev)
        struct backlight_device *bl = dev_get_drvdata(dev);
 
        backlight_update_status(bl);
+
        return 0;
 }
 #endif
 
-static SIMPLE_DEV_PM_OPS(pwm_backlight_pm_ops, pwm_backlight_suspend,
-                        pwm_backlight_resume);
+static const struct dev_pm_ops pwm_backlight_pm_ops = {
+#ifdef CONFIG_PM_SLEEP
+       .suspend = pwm_backlight_suspend,
+       .resume = pwm_backlight_resume,
+       .poweroff = pwm_backlight_suspend,
+       .restore = pwm_backlight_resume,
+#endif
+};
 
 static struct platform_driver pwm_backlight_driver = {
        .driver         = {
@@ -317,4 +412,3 @@ module_platform_driver(pwm_backlight_driver);
 MODULE_DESCRIPTION("PWM based Backlight Driver");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:pwm-backlight");
-
index 00b3a52c1d68766d42cab3c65a1a9405d4a04617..cee9602f9a7b4ed0ca8071e1723137da7bf12d7e 100644 (file)
@@ -141,7 +141,6 @@ static int exynos_mipi_dsi_early_blank_mode(struct mipi_dsim_device *dsim,
 
 static int exynos_mipi_dsi_blank_mode(struct mipi_dsim_device *dsim, int power)
 {
-       struct platform_device *pdev = to_platform_device(dsim->dev);
        struct mipi_dsim_lcd_driver *client_drv = dsim->dsim_lcd_drv;
        struct mipi_dsim_lcd_device *client_dev = dsim->dsim_lcd_dev;
 
index 6df632e0bb555d1841bae04c4a8ee5862a50896d..5be6e919f7850d7d101542b55120163cec935162 100644 (file)
@@ -392,6 +392,25 @@ config RETU_WATCHDOG
          To compile this driver as a module, choose M here: the
          module will be called retu_wdt.
 
+config MOXART_WDT
+       tristate "MOXART watchdog"
+       depends on ARCH_MOXART
+       help
+         Say Y here to include Watchdog timer support for the watchdog
+         existing on the MOXA ART SoC series platforms.
+
+         To compile this driver as a module, choose M here: the
+         module will be called moxart_wdt.
+
+config SIRFSOC_WATCHDOG
+       tristate "SiRFSOC watchdog"
+       depends on ARCH_SIRF
+       select WATCHDOG_CORE
+       default y
+       help
+         Support for CSR SiRFprimaII and SiRFatlasVI watchdog. When
+         the watchdog triggers the system will be reset.
+
 # AVR32 Architecture
 
 config AT32AP700X_WDT
@@ -866,6 +885,7 @@ config VIA_WDT
 config W83627HF_WDT
        tristate "W83627HF/W83627DHG Watchdog Timer"
        depends on X86
+       select WATCHDOG_CORE
        ---help---
          This is the driver for the hardware watchdog on the W83627HF chipset
          as used in Advantech PC-9578 and Tyan S2721-533 motherboards
@@ -1125,6 +1145,13 @@ config LANTIQ_WDT
        help
          Hardware driver for the Lantiq SoC Watchdog Timer.
 
+config RALINK_WDT
+       tristate "Ralink SoC watchdog"
+       select WATCHDOG_CORE
+       depends on RALINK
+       help
+         Hardware driver for the Ralink SoC Watchdog Timer.
+
 # PARISC Architecture
 
 # POWERPC Architecture
index 8c7b8bcbbdc5b83d6f22584a144de9a3dbc3837e..91bd95a64baf7bfe083e6f67ff803f2edc0ce2f9 100644 (file)
@@ -55,6 +55,8 @@ obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
 obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
 obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
 obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
+obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
+obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
@@ -134,6 +136,7 @@ obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
 obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
 octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
 obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
+obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
 
 # PARISC Architecture
 
index 24a517777fa0a83533daa9c8b585278776ca1518..5cf1621def9c690a2e5947e1e712c1d846769379 100644 (file)
@@ -60,8 +60,7 @@
 #include <linux/types.h>               /* For standard types (like size_t) */
 #include <linux/errno.h>               /* For the -ENODEV/... values */
 #include <linux/kernel.h>              /* For printk/panic/... */
-#include <linux/miscdevice.h>          /* For MODULE_ALIAS_MISCDEV
-                                                       (WATCHDOG_MINOR) */
+#include <linux/miscdevice.h>          /* For struct miscdevice */
 #include <linux/watchdog.h>            /* For the watchdog specific items */
 #include <linux/fs.h>                  /* For file operations */
 #include <linux/ioport.h>              /* For io-port access */
@@ -337,4 +336,3 @@ module_exit(acq_exit);
 MODULE_AUTHOR("David Woodhouse");
 MODULE_DESCRIPTION("Acquire Inc. Single Board Computer Watchdog Timer driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index cc6702fc52685f54f28588108b49d293cbac04da..a8961addc59cf110df2a0ff3d5cbdff67b4fbd4a 100644 (file)
@@ -345,4 +345,3 @@ module_exit(advwdt_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Marek Michalkiewicz <marekm@linux.org.pl>");
 MODULE_DESCRIPTION("Advantech Single Board Computer WDT driver");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 41b84936a521f62b81bec020646a7014e23e51bc..fbb7b94cabfd5816e7532fe0093b579b831b63a8 100644 (file)
@@ -452,4 +452,3 @@ module_exit(watchdog_exit);
 MODULE_AUTHOR("Alan Cox");
 MODULE_DESCRIPTION("ALi M1535 PMU Watchdog Timer driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 5eee55012e3375915b769e2bbcf05da9adbeff60..12f0b762b528948b15e30fab605860a34c01ba57 100644 (file)
@@ -425,4 +425,3 @@ MODULE_DEVICE_TABLE(pci, alim7101_pci_tbl);
 MODULE_AUTHOR("Steve Hill");
 MODULE_DESCRIPTION("ALi M7101 PMU Computer Watchdog Timer driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index b3709f9cf5beab1d5e6d8f51136ae90e3bf23726..3a996576343a3b8abb20b8cab7bf65c7b503a803 100644 (file)
@@ -46,7 +46,6 @@
 MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
 MODULE_DESCRIPTION(LONGNAME);
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 static int margin = 60;
 module_param(margin, int, 0);
index b178e717ef09e025b6984b00b68184e05934f8e8..afe7d17e677634f1fd447a147deeb133ac366f36 100644 (file)
@@ -434,4 +434,3 @@ module_platform_driver_probe(at32_wdt_driver, at32_wdt_probe);
 MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
 MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 1c75260b987c13dcd58ef1137c08ac5386709b0a..dee6cc21d27021d3280b0cd7da999e562147aa40 100644 (file)
@@ -269,7 +269,7 @@ static struct platform_driver at91wdt_driver = {
        .driver         = {
                .name   = "at91_wdt",
                .owner  = THIS_MODULE,
-               .of_match_table = of_match_ptr(at91_wdt_dt_ids),
+               .of_match_table = at91_wdt_dt_ids,
        },
 };
 
@@ -297,5 +297,4 @@ module_exit(at91_wdt_exit);
 MODULE_AUTHOR("Andrew Victor");
 MODULE_DESCRIPTION("Watchdog driver for Atmel AT91RM9200");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:at91_wdt");
index 37cb09b27b6328e85581955400cb94bf18b66f0e..9fa1f69dac1328d73c45fccd9034032fcb4412d8 100644 (file)
@@ -329,4 +329,3 @@ MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
 MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
 MODULE_LICENSE("GPL v2");
 MODULE_ALIAS("platform:" DRIVER_NAME);
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 61566fc47f8441b9249054415acee30301e68b78..a6a2cebb25879242b8408b1537838a67d932b2b3 100644 (file)
@@ -186,4 +186,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
 MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
 MODULE_DESCRIPTION("Driver for Broadcom BCM2835 watchdog timer");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index a14a58d9d1107bdbc31a0ff28f0fcad8fdc71906..4eb188b87f8eb881784488e78d3447400499388e 100644 (file)
@@ -317,5 +317,4 @@ MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
 MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
 MODULE_DESCRIPTION("Driver for the Broadcom BCM63xx SoC watchdog");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:bcm63xx-wdt");
index 5d36d6fb496919d6007a51114d8eee98759d445d..a3b6a5b30f9fe53e885e205ea6f870352f2aa09f 100644 (file)
@@ -465,7 +465,6 @@ module_exit(bfin_wdt_exit);
 MODULE_AUTHOR("Michele d'Amico, Mike Frysinger <vapier@gentoo.org>");
 MODULE_DESCRIPTION("Blackfin Watchdog Device Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 module_param(timeout, uint, 0);
 MODULE_PARM_DESC(timeout,
index f270bb7bc4564126638200c270882da039219c88..f7ae49edb5186d13080fe369aa5cc50f38ef791f 100644 (file)
@@ -289,7 +289,6 @@ MODULE_AUTHOR("Heiko Ronsdorf <hero@ihg.uni-duisburg.de>");
 MODULE_DESCRIPTION("sma cpu5 watchdog driver");
 MODULE_SUPPORTED_DEVICE("sma cpu5 watchdog");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 module_param(port, int, 0);
 MODULE_PARM_DESC(port, "base address of watchdog card, default is 0x91");
index bead7740c86a44da31d3b8dc876b20b51a62cd78..dd625cca1ae5669d4e513a8611736c1b82d33a62 100644 (file)
@@ -267,5 +267,4 @@ MODULE_PARM_DESC(heartbeat,
                 __MODULE_STRING(DEFAULT_HEARTBEAT));
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:watchdog");
index e621098bf6630e17ff6eb7a578028bc3f3f4a476..a46f5c7ee7ff4e6c11eceb36a59ca7438949e5b5 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/of.h>
 #include <linux/pm.h>
 #include <linux/platform_device.h>
 #include <linux/spinlock.h>
@@ -203,12 +204,12 @@ static long dw_wdt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
        switch (cmd) {
        case WDIOC_GETSUPPORT:
-               return copy_to_user((struct watchdog_info *)arg, &dw_wdt_ident,
+               return copy_to_user((void __user *)arg, &dw_wdt_ident,
                                    sizeof(dw_wdt_ident)) ? -EFAULT : 0;
 
        case WDIOC_GETSTATUS:
        case WDIOC_GETBOOTSTATUS:
-               return put_user(0, (int *)arg);
+               return put_user(0, (int __user *)arg);
 
        case WDIOC_KEEPALIVE:
                dw_wdt_set_next_heartbeat();
@@ -252,17 +253,17 @@ static int dw_wdt_release(struct inode *inode, struct file *filp)
        return 0;
 }
 
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 static int dw_wdt_suspend(struct device *dev)
 {
-       clk_disable(dw_wdt.clk);
+       clk_disable_unprepare(dw_wdt.clk);
 
        return 0;
 }
 
 static int dw_wdt_resume(struct device *dev)
 {
-       int err = clk_enable(dw_wdt.clk);
+       int err = clk_prepare_enable(dw_wdt.clk);
 
        if (err)
                return err;
@@ -271,12 +272,9 @@ static int dw_wdt_resume(struct device *dev)
 
        return 0;
 }
+#endif /* CONFIG_PM_SLEEP */
 
-static const struct dev_pm_ops dw_wdt_pm_ops = {
-       .suspend        = dw_wdt_suspend,
-       .resume         = dw_wdt_resume,
-};
-#endif /* CONFIG_PM */
+static SIMPLE_DEV_PM_OPS(dw_wdt_pm_ops, dw_wdt_suspend, dw_wdt_resume);
 
 static const struct file_operations wdt_fops = {
        .owner          = THIS_MODULE,
@@ -309,7 +307,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
        if (IS_ERR(dw_wdt.clk))
                return PTR_ERR(dw_wdt.clk);
 
-       ret = clk_enable(dw_wdt.clk);
+       ret = clk_prepare_enable(dw_wdt.clk);
        if (ret)
                return ret;
 
@@ -326,7 +324,7 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
        return 0;
 
 out_disable_clk:
-       clk_disable(dw_wdt.clk);
+       clk_disable_unprepare(dw_wdt.clk);
 
        return ret;
 }
@@ -335,20 +333,27 @@ static int dw_wdt_drv_remove(struct platform_device *pdev)
 {
        misc_deregister(&dw_wdt_miscdev);
 
-       clk_disable(dw_wdt.clk);
+       clk_disable_unprepare(dw_wdt.clk);
 
        return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id dw_wdt_of_match[] = {
+       { .compatible = "snps,dw-wdt", },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, dw_wdt_of_match);
+#endif
+
 static struct platform_driver dw_wdt_driver = {
        .probe          = dw_wdt_drv_probe,
        .remove         = dw_wdt_drv_remove,
        .driver         = {
                .name   = "dw_wdt",
                .owner  = THIS_MODULE,
-#ifdef CONFIG_PM
+               .of_match_table = of_match_ptr(dw_wdt_of_match),
                .pm     = &dw_wdt_pm_ops,
-#endif /* CONFIG_PM */
        },
 };
 
@@ -357,4 +362,3 @@ module_platform_driver(dw_wdt_driver);
 MODULE_AUTHOR("Jamie Iles");
 MODULE_DESCRIPTION("Synopsys DesignWare Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index e0574844c3132c01f86b2c66ed72fc67e69a85d3..833e813118489216a8a27901f749f0765bd03e8f 100644 (file)
@@ -179,4 +179,3 @@ MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>,"
 MODULE_DESCRIPTION("EP93xx Watchdog");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(WDT_VERSION);
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index cd31b8a2a729f1a720a61a15a4a7ae3c2ad366ba..23ee53240c4c1858f7d8aa0f7530d43dcc44f650 100644 (file)
@@ -477,4 +477,3 @@ module_exit(eurwdt_exit);
 MODULE_AUTHOR("Rodolfo Giometti");
 MODULE_DESCRIPTION("Driver for Eurotech CPU-1220/1410 on board watchdog");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 3755833430dc3d8146a3f515e68b0a897a400c60..25beb30878d72644e407cf83a4211b656aca9c42 100644 (file)
@@ -331,5 +331,4 @@ module_exit(gef_wdt_exit);
 MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>");
 MODULE_DESCRIPTION("GE watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:gef_wdt");
index fcd599d4e22542a085fffa4619c9f163d4adb114..4a6ae84b42bcc5b2e829a8bec9a51b017d2a63d5 100644 (file)
@@ -297,4 +297,3 @@ module_exit(geodewdt_exit);
 MODULE_AUTHOR("Advanced Micro Devices, Inc");
 MODULE_DESCRIPTION("Geode GX/LX Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 19f3c3fc65f4c9af0ffa4a25cf8410e308a5fda8..45b979d9dd13acf223ac4ede12262c51fe6e1e9d 100644 (file)
@@ -881,7 +881,6 @@ MODULE_AUTHOR("Tom Mingarelli");
 MODULE_DESCRIPTION("hp watchdog driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(HPWDT_VERSION);
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 module_param(soft_margin, int, 0);
 MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
index 2b2ea13d03ea714a28b2d48e2794e9a8d2361636..a72fe9361ddf028ef717959183cc5bdfc3ea0478 100644 (file)
@@ -497,4 +497,3 @@ module_pci_driver(esb_driver);
 MODULE_AUTHOR("Ross Biro and David Härdeman");
 MODULE_DESCRIPTION("Watchdog driver for Intel 6300ESB chipsets");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 6130321da3871dc80b020acc232fca4fc0b8cffc..04f8af65acfd568b486c68460ff5227a841cf9a2 100644 (file)
@@ -56,8 +56,6 @@
 #include <linux/types.h>               /* For standard types (like size_t) */
 #include <linux/errno.h>               /* For the -ENODEV/... values */
 #include <linux/kernel.h>              /* For printk/panic/... */
-#include <linux/miscdevice.h>          /* For MODULE_ALIAS_MISCDEV
-                                                       (WATCHDOG_MINOR) */
 #include <linux/watchdog.h>            /* For the watchdog specific items */
 #include <linux/init.h>                        /* For __init/__exit/... */
 #include <linux/fs.h>                  /* For file operations */
@@ -394,7 +392,7 @@ static int iTCO_wdt_probe(struct platform_device *dev)
 {
        int ret = -ENODEV;
        unsigned long val32;
-       struct lpc_ich_info *ich_info = dev->dev.platform_data;
+       struct lpc_ich_info *ich_info = dev_get_platdata(&dev->dev);
 
        if (!ich_info)
                goto out;
@@ -582,5 +580,4 @@ MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
 MODULE_DESCRIPTION("Intel TCO WatchDog Timer Driver");
 MODULE_VERSION(DRV_VERSION);
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:" DRV_NAME);
index eb6b5cc98ec68cc48bbfc906f159a368c98ba739..7ae36690c44916305508408d61fdb117af3d7945 100644 (file)
@@ -382,6 +382,5 @@ module_exit(ibwdt_exit);
 MODULE_AUTHOR("Charles Howes <chowes@vsol.net>");
 MODULE_DESCRIPTION("IB700 SBC watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 /* end of ib700wdt.c */
index bc3fb8fe89abd94312dc0a07e8e19f5e66475c6d..db0a34460e57a796a3891cb407d52d2985d20102 100644 (file)
@@ -419,4 +419,3 @@ MODULE_PARM_DESC(nowayout,
 MODULE_DESCRIPTION("IBM Automatic Server Restart driver");
 MODULE_AUTHOR("Andrey Panin");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index e24ef6a6e06461aa01731a3e4910d3cc23924b5e..70a240297c6d22f2a7d170a731f70320512f478a 100644 (file)
@@ -344,5 +344,4 @@ module_exit(ie6xx_wdt_exit);
 MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>");
 MODULE_DESCRIPTION("Intel Atom E6xx Watchdog Device Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:" DRIVER_NAME);
index 693ac3f4de5aaba92d2a2a7f7004be468b1b0b77..b4786bccc42c3c062153ef06ce2419900d84a76d 100644 (file)
@@ -322,6 +322,7 @@ static const struct of_device_id imx2_wdt_dt_ids[] = {
        { .compatible = "fsl,imx21-wdt", },
        { /* sentinel */ }
 };
+MODULE_DEVICE_TABLE(of, imx2_wdt_dt_ids);
 
 static struct platform_driver imx2_wdt_driver = {
        .remove         = __exit_p(imx2_wdt_remove),
@@ -338,5 +339,4 @@ module_platform_driver_probe(imx2_wdt_driver, imx2_wdt_probe);
 MODULE_AUTHOR("Wolfram Sang");
 MODULE_DESCRIPTION("Watchdog driver for IMX2 and later");
 MODULE_LICENSE("GPL v2");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:" DRIVER_NAME);
index 6d90f7a2ce2218e36e72282749dd5ab6c1dcbabe..1b5c25a47b876194561490aba581d84ac5cd27cc 100644 (file)
@@ -214,4 +214,3 @@ module_exit(watchdog_exit);
 MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
 MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 8ced2561395640cdeb16fcc679442011a230c97f..e13e65e996aa7b996f18232243642f7298f8532b 100644 (file)
@@ -564,5 +564,4 @@ module_exit(intel_scu_watchdog_exit);
 MODULE_AUTHOR("Intel Corporation");
 MODULE_DESCRIPTION("Intel SCU Watchdog Device Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_VERSION(WDT_VER);
index d964faf1a2505291b15a5e946e4642ef1d292b08..b16013ffacc27c2e091233b4c8dfb353465a8586 100644 (file)
@@ -259,4 +259,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
 MODULE_AUTHOR("Curt E Bruns <curt.e.bruns@intel.com>");
 MODULE_DESCRIPTION("iop watchdog timer driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index f4cce6d66a5573b42afb4517a26752fe15b2a5be..41b3979a9d87068c3cbf3ad5ce9cb430d122ae5a 100644 (file)
@@ -41,7 +41,6 @@
 MODULE_AUTHOR("Jorge Boncompte - DTI2 <jorge@dti2.net>");
 MODULE_DESCRIPTION("IT8712F Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 static int max_units = 255;
 static int margin = 60;                /* in seconds */
index d3dcc6988b5f107dd65395aa8459a8a04af4d012..e2bba68ae71e0108707a24dfa9d14feb6c3c974d 100644 (file)
@@ -772,4 +772,3 @@ module_exit(it87_wdt_exit);
 MODULE_AUTHOR("Oliver Schuster");
 MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 5580b4fff7fe0dc7fd85376e3313678356cc650f..f20cc53ff71976cdfb48bb956fb83e8fd88b1e91 100644 (file)
@@ -208,5 +208,3 @@ module_param(nowayout, bool, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
index d1afdf684c18c55a5899238dc0843fee40a08cee..2de486a7eea18a058808cbb33a0ec0fa5f3a650b 100644 (file)
@@ -222,5 +222,4 @@ module_platform_driver(jz4740_wdt_driver);
 MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>");
 MODULE_DESCRIPTION("jz4740 Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:jz4740-wdt");
index 5c3d4df63e6835f534cb57a3eca724ce08c3ba47..a1a3638c579c857c382ec9c253e5f69424e1dbbb 100644 (file)
@@ -67,7 +67,7 @@ enum {
        PRESCALER_12,
 };
 
-const u32 kempld_prescaler[] = {
+static const u32 kempld_prescaler[] = {
        [PRESCALER_21] = (1 << 21) - 1,
        [PRESCALER_17] = (1 << 17) - 1,
        [PRESCALER_12] = (1 << 12) - 1,
@@ -361,7 +361,7 @@ static long kempld_wdt_ioctl(struct watchdog_device *wdd, unsigned int cmd,
                ret = kempld_wdt_keepalive(wdd);
                break;
        case WDIOC_GETPRETIMEOUT:
-               ret = put_user(wdt_data->pretimeout, (int *)arg);
+               ret = put_user(wdt_data->pretimeout, (int __user *)arg);
                break;
        }
 
@@ -578,4 +578,3 @@ module_platform_driver(kempld_wdt_driver);
 MODULE_DESCRIPTION("KEM PLD Watchdog Driver");
 MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index dce9ecffd44a95b4fb627003f3f18e7fcf26ac49..40ca5594a336fa36ed38e0dc953c429ce144c547 100644 (file)
@@ -323,5 +323,4 @@ module_exit(ks8695_wdt_exit);
 MODULE_AUTHOR("Andrew Victor");
 MODULE_DESCRIPTION("Watchdog driver for KS8695");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:ks8695_wdt");
index 088fd0c9d88811e81dfab7217d612ec950654d69..3b3148c764a3853c9076d9e14a804f92fdea8347 100644 (file)
@@ -249,4 +249,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
 MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
 MODULE_DESCRIPTION("Lantiq SoC Watchdog");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 173494a681e6faab613bcfda9a8c72a9fafda325..da6fa2b68074b2523d8ba4a9a819d927c4191b8c 100644 (file)
@@ -223,4 +223,3 @@ module_param(nowayout, bool, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index bf84f788e59261f985ce85dce2a6fade949807e9..9826b59ef73471c1e450e564176c2e49c4fcb283 100644 (file)
@@ -92,7 +92,6 @@ static unsigned short zf_readw(unsigned char port)
 MODULE_AUTHOR("Fernando Fuganti <fuganti@conectiva.com.br>");
 MODULE_DESCRIPTION("MachZ ZF-Logic Watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 static bool nowayout = WATCHDOG_NOWAYOUT;
 module_param(nowayout, bool, 0);
index cc9d328086eda5bc343b9d72b8cfd4b4304381ef..6d4f3998e1f6c08e7158fdf1068b3a94c3bad448 100644 (file)
@@ -258,4 +258,3 @@ MODULE_PARM_DESC(nodelay,
                 "(max6373/74 only, default=0)");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 97d62ee503418822a1e649fa1b8e7059117aaf13..be86ea359eee1c1ffefd1cbae6f6e12f0059f273 100644 (file)
@@ -315,4 +315,3 @@ MODULE_AUTHOR("Gergely Madarasz <gorgo@itc.hu>");
 MODULE_DESCRIPTION("MixCom Watchdog driver");
 MODULE_VERSION(VERSION);
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/moxart_wdt.c b/drivers/watchdog/moxart_wdt.c
new file mode 100644 (file)
index 0000000..4166e4d
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * MOXA ART SoCs watchdog driver.
+ *
+ * Copyright (C) 2013 Jonas Jensen
+ *
+ * Jonas Jensen <jonas.jensen@gmail.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+#include <linux/moduleparam.h>
+
+#define REG_COUNT                      0x4
+#define REG_MODE                       0x8
+#define REG_ENABLE                     0xC
+
+struct moxart_wdt_dev {
+       struct watchdog_device dev;
+       void __iomem *base;
+       unsigned int clock_frequency;
+};
+
+static int heartbeat;
+
+static int moxart_wdt_stop(struct watchdog_device *wdt_dev)
+{
+       struct moxart_wdt_dev *moxart_wdt = watchdog_get_drvdata(wdt_dev);
+
+       writel(0, moxart_wdt->base + REG_ENABLE);
+
+       return 0;
+}
+
+static int moxart_wdt_start(struct watchdog_device *wdt_dev)
+{
+       struct moxart_wdt_dev *moxart_wdt = watchdog_get_drvdata(wdt_dev);
+
+       writel(moxart_wdt->clock_frequency * wdt_dev->timeout,
+              moxart_wdt->base + REG_COUNT);
+       writel(0x5ab9, moxart_wdt->base + REG_MODE);
+       writel(0x03, moxart_wdt->base + REG_ENABLE);
+
+       return 0;
+}
+
+static int moxart_wdt_set_timeout(struct watchdog_device *wdt_dev,
+                                 unsigned int timeout)
+{
+       wdt_dev->timeout = timeout;
+
+       return 0;
+}
+
+static const struct watchdog_info moxart_wdt_info = {
+       .identity       = "moxart-wdt",
+       .options        = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
+                         WDIOF_MAGICCLOSE,
+};
+
+static const struct watchdog_ops moxart_wdt_ops = {
+       .owner          = THIS_MODULE,
+       .start          = moxart_wdt_start,
+       .stop           = moxart_wdt_stop,
+       .set_timeout    = moxart_wdt_set_timeout,
+};
+
+static int moxart_wdt_probe(struct platform_device *pdev)
+{
+       struct moxart_wdt_dev *moxart_wdt;
+       struct device *dev = &pdev->dev;
+       struct device_node *node = dev->of_node;
+       struct resource *res;
+       struct clk *clk;
+       int err;
+       unsigned int max_timeout;
+       bool nowayout = WATCHDOG_NOWAYOUT;
+
+       moxart_wdt = devm_kzalloc(dev, sizeof(*moxart_wdt), GFP_KERNEL);
+       if (!moxart_wdt)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, moxart_wdt);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       moxart_wdt->base = devm_ioremap_resource(dev, res);
+       if (IS_ERR(moxart_wdt->base))
+               return PTR_ERR(moxart_wdt->base);
+
+       clk = of_clk_get(node, 0);
+       if (IS_ERR(clk)) {
+               pr_err("%s: of_clk_get failed\n", __func__);
+               return PTR_ERR(clk);
+       }
+
+       moxart_wdt->clock_frequency = clk_get_rate(clk);
+       if (moxart_wdt->clock_frequency == 0) {
+               pr_err("%s: incorrect clock frequency\n", __func__);
+               return -EINVAL;
+       }
+
+       max_timeout = UINT_MAX / moxart_wdt->clock_frequency;
+
+       moxart_wdt->dev.info = &moxart_wdt_info;
+       moxart_wdt->dev.ops = &moxart_wdt_ops;
+       moxart_wdt->dev.timeout = max_timeout;
+       moxart_wdt->dev.min_timeout = 1;
+       moxart_wdt->dev.max_timeout = max_timeout;
+       moxart_wdt->dev.parent = dev;
+
+       watchdog_init_timeout(&moxart_wdt->dev, heartbeat, dev);
+       watchdog_set_nowayout(&moxart_wdt->dev, nowayout);
+
+       watchdog_set_drvdata(&moxart_wdt->dev, moxart_wdt);
+
+       err = watchdog_register_device(&moxart_wdt->dev);
+       if (err)
+               return err;
+
+       dev_dbg(dev, "Watchdog enabled (heartbeat=%d sec, nowayout=%d)\n",
+               moxart_wdt->dev.timeout, nowayout);
+
+       return 0;
+}
+
+static int moxart_wdt_remove(struct platform_device *pdev)
+{
+       struct moxart_wdt_dev *moxart_wdt = platform_get_drvdata(pdev);
+
+       moxart_wdt_stop(&moxart_wdt->dev);
+       watchdog_unregister_device(&moxart_wdt->dev);
+
+       return 0;
+}
+
+static const struct of_device_id moxart_watchdog_match[] = {
+       { .compatible = "moxa,moxart-watchdog" },
+       { },
+};
+
+static struct platform_driver moxart_wdt_driver = {
+       .probe      = moxart_wdt_probe,
+       .remove     = moxart_wdt_remove,
+       .driver     = {
+               .name           = "moxart-watchdog",
+               .owner          = THIS_MODULE,
+               .of_match_table = moxart_watchdog_match,
+       },
+};
+module_platform_driver(moxart_wdt_driver);
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds");
+
+MODULE_DESCRIPTION("MOXART watchdog driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");
index d0ebebae607c847766b3e9cc7204dad7afad7cac..d82152077fd9fb1c512145c92a8700cb0ccaf385 100644 (file)
@@ -330,4 +330,3 @@ MODULE_AUTHOR("Dave Updegraff, Kumar Gala");
 MODULE_DESCRIPTION("Driver for watchdog timer in MPC8xx/MPC83xx/MPC86xx "
                   "uProcessors");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index b4341110ad4f43eef5038a9e3d82a7b2644b2ab8..edb31ffd79270c7e8edf86d255215efa2aeaaf28 100644 (file)
@@ -257,5 +257,4 @@ module_platform_driver(mtx1_wdt_driver);
 MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
 MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:mtx1-wdt");
index e4cf980192658fa1d02959ba55e69ec03dc24ea0..f9fa5840939617a45a576ceb5edc1bb271780325 100644 (file)
@@ -255,7 +255,7 @@ static struct miscdevice mv64x60_wdt_miscdev = {
 
 static int mv64x60_wdt_probe(struct platform_device *dev)
 {
-       struct mv64x60_wdt_pdata *pdata = dev->dev.platform_data;
+       struct mv64x60_wdt_pdata *pdata = dev_get_platdata(&dev->dev);
        struct resource *r;
        int timeout = 10;
 
@@ -323,5 +323,4 @@ module_exit(mv64x60_wdt_exit);
 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
 MODULE_DESCRIPTION("MV64x60 watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:" MV64x60_WDT_NAME);
index b15b6efd91a146f08d8bac2cc6664172c79b194c..a0d893b0930e3309969963a8c5422d31e57d3032 100644 (file)
@@ -307,5 +307,4 @@ module_platform_driver(nuc900wdt_driver);
 MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
 MODULE_DESCRIPTION("Watchdog driver for NUC900");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:nuc900-wdt");
index 59cf19eeea07668e76501fa1734e933947f8d79f..231e5b9d5c8e079ec424b9331aca90912f42efae 100644 (file)
@@ -513,4 +513,3 @@ module_exit(nv_tco_cleanup_module);
 MODULE_AUTHOR("Mike Waychison");
 MODULE_DESCRIPTION("TCO timer driver for NV chipsets");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 4dd281f2c33f29b275eaa64cfa80a62d0c62c109..fb57103c8ebcc2e6dcee213d12527cdc81a83aed 100644 (file)
@@ -405,4 +405,3 @@ module_platform_driver(xwdt_driver);
 MODULE_AUTHOR("Alejandro Cabrera <aldaya@gmail.com>");
 MODULE_DESCRIPTION("Xilinx Watchdog driver");
 MODULE_LICENSE("GPL v2");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index af88ffd1068f57ebd50354c7a6dd06fdf54af1f4..09cf0135e8acd3078d2480870109984ece309301 100644 (file)
@@ -68,14 +68,14 @@ static void omap_wdt_reload(struct omap_wdt_dev *wdev)
        void __iomem    *base = wdev->base;
 
        /* wait for posted write to complete */
-       while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
+       while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
                cpu_relax();
 
        wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
-       __raw_writel(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
+       writel_relaxed(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
 
        /* wait for posted write to complete */
-       while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
+       while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
                cpu_relax();
        /* reloaded WCRR from WLDR */
 }
@@ -85,12 +85,12 @@ static void omap_wdt_enable(struct omap_wdt_dev *wdev)
        void __iomem *base = wdev->base;
 
        /* Sequence to enable the watchdog */
-       __raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR);
-       while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
+       writel_relaxed(0xBBBB, base + OMAP_WATCHDOG_SPR);
+       while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
                cpu_relax();
 
-       __raw_writel(0x4444, base + OMAP_WATCHDOG_SPR);
-       while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
+       writel_relaxed(0x4444, base + OMAP_WATCHDOG_SPR);
+       while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
                cpu_relax();
 }
 
@@ -99,12 +99,12 @@ static void omap_wdt_disable(struct omap_wdt_dev *wdev)
        void __iomem *base = wdev->base;
 
        /* sequence required to disable watchdog */
-       __raw_writel(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
-       while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
+       writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR);       /* TIMER_MODE */
+       while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
                cpu_relax();
 
-       __raw_writel(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
-       while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
+       writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR);       /* TIMER_MODE */
+       while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
                cpu_relax();
 }
 
@@ -115,11 +115,11 @@ static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
        void __iomem *base = wdev->base;
 
        /* just count up at 32 KHz */
-       while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
+       while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
                cpu_relax();
 
-       __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
-       while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
+       writel_relaxed(pre_margin, base + OMAP_WATCHDOG_LDR);
+       while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
                cpu_relax();
 }
 
@@ -135,11 +135,11 @@ static int omap_wdt_start(struct watchdog_device *wdog)
        pm_runtime_get_sync(wdev->dev);
 
        /* initialize prescaler */
-       while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
+       while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
                cpu_relax();
 
-       __raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
-       while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
+       writel_relaxed((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
+       while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
                cpu_relax();
 
        omap_wdt_set_timer(wdev, wdog->timeout);
@@ -205,7 +205,7 @@ static const struct watchdog_ops omap_wdt_ops = {
 
 static int omap_wdt_probe(struct platform_device *pdev)
 {
-       struct omap_wd_timer_platform_data *pdata = pdev->dev.platform_data;
+       struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
        struct watchdog_device *omap_wdt;
        struct resource *res, *mem;
        struct omap_wdt_dev *wdev;
@@ -275,7 +275,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
        }
 
        pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
-               __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
+               readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
                omap_wdt->timeout);
 
        pm_runtime_put_sync(wdev->dev);
index 4ea5fcccac02d1ee6f933cc1e5b8b8e0260da3a4..44edca66d564195a8e20b54f20c8b4cc389eca2c 100644 (file)
@@ -207,7 +207,7 @@ static struct platform_driver orion_wdt_driver = {
        .driver         = {
                .owner  = THIS_MODULE,
                .name   = "orion_wdt",
-               .of_match_table = of_match_ptr(orion_wdt_of_match_table),
+               .of_match_table = orion_wdt_of_match_table,
        },
 };
 
@@ -225,4 +225,3 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
 
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:orion_wdt");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 5afb89b48650a4326298933cf01ec69f3fe84fb7..5211d56b368183ca1b1dc7de2bfe97adcde90efd 100644 (file)
@@ -580,8 +580,6 @@ MODULE_AUTHOR("Sven Anders <anders@anduras.de>, "
 MODULE_DESCRIPTION("PC87413 WDT driver");
 MODULE_LICENSE("GPL");
 
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
 module_param(io, int, 0);
 MODULE_PARM_DESC(io, MODNAME " I/O port (default: "
                                        __MODULE_STRING(IO_DEFAULT) ").");
index 33e49a7f889fcb33c553b126a9495383a414164a..e936f15dc7c7d3b2590478170a648cb2194b8d43 100644 (file)
@@ -61,7 +61,7 @@
 #include <linux/delay.h>       /* For mdelay function */
 #include <linux/timer.h>       /* For timer related operations */
 #include <linux/jiffies.h>     /* For jiffies stuff */
-#include <linux/miscdevice.h>  /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
+#include <linux/miscdevice.h>  /* For struct miscdevice */
 #include <linux/watchdog.h>    /* For the watchdog specific items */
 #include <linux/reboot.h>      /* For kernel_power_off() */
 #include <linux/init.h>                /* For __init/__exit/... */
@@ -1011,5 +1011,3 @@ MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, "
 MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
 MODULE_VERSION(WATCHDOG_VERSION);
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-MODULE_ALIAS_MISCDEV(TEMP_MINOR);
index 7890f84edf760743094ac32c27b712c08fc823a4..b4864f254b48940b7fd9b7febb368b6608af4716 100644 (file)
@@ -40,7 +40,7 @@
 #include <linux/errno.h>       /* For the -ENODEV/... values */
 #include <linux/kernel.h>      /* For printk/panic/... */
 #include <linux/delay.h>       /* For mdelay function */
-#include <linux/miscdevice.h>  /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
+#include <linux/miscdevice.h>  /* For struct miscdevice */
 #include <linux/watchdog.h>    /* For the watchdog specific items */
 #include <linux/notifier.h>    /* For notifier support */
 #include <linux/reboot.h>      /* For reboot_notifier stuff */
@@ -820,5 +820,3 @@ module_pci_driver(pcipcwd_driver);
 MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
 MODULE_DESCRIPTION("Berkshire PCI-PC Watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-MODULE_ALIAS_MISCDEV(TEMP_MINOR);
index 7b14d184792705d3b60ea6fba20041be351a186d..b731b5d129bedee728ca195bc032bb24918f5ef0 100644 (file)
@@ -32,7 +32,7 @@
 #include <linux/errno.h>       /* For the -ENODEV/... values */
 #include <linux/kernel.h>      /* For printk/panic/... */
 #include <linux/delay.h>       /* For mdelay function */
-#include <linux/miscdevice.h>  /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
+#include <linux/miscdevice.h>  /* For struct miscdevice */
 #include <linux/watchdog.h>    /* For the watchdog specific items */
 #include <linux/notifier.h>    /* For notifier support */
 #include <linux/reboot.h>      /* For reboot_notifier stuff */
@@ -72,8 +72,6 @@ do {                                                  \
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE(DRIVER_LICENSE);
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-MODULE_ALIAS_MISCDEV(TEMP_MINOR);
 
 /* Module Parameters */
 module_param(debug, int, 0);
@@ -235,13 +233,17 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
                unsigned char cmd, unsigned char *msb, unsigned char *lsb)
 {
        int got_response, count;
-       unsigned char buf[6];
+       unsigned char *buf;
 
        /* We will not send any commands if the USB PCWD device does
         * not exist */
        if ((!usb_pcwd) || (!usb_pcwd->exists))
                return -1;
 
+       buf = kmalloc(6, GFP_KERNEL);
+       if (buf == NULL)
+               return 0;
+
        /* The USB PC Watchdog uses a 6 byte report format.
         * The board currently uses only 3 of the six bytes of the report. */
        buf[0] = cmd;                   /* Byte 0 = CMD */
@@ -256,8 +258,8 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
 
        if (usb_control_msg(usb_pcwd->udev, usb_sndctrlpipe(usb_pcwd->udev, 0),
                        HID_REQ_SET_REPORT, HID_DT_REPORT,
-                       0x0200, usb_pcwd->interface_number, buf, sizeof(buf),
-                       USB_COMMAND_TIMEOUT) != sizeof(buf)) {
+                       0x0200, usb_pcwd->interface_number, buf, 6,
+                       USB_COMMAND_TIMEOUT) != 6) {
                dbg("usb_pcwd_send_command: error in usb_control_msg for "
                                "cmd 0x%x 0x%x 0x%x\n", cmd, *msb, *lsb);
        }
@@ -277,6 +279,8 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd,
                *lsb = usb_pcwd->cmd_data_lsb;
        }
 
+       kfree(buf);
+
        return got_response;
 }
 
index 329bc60ad7a23537b42f6871128f62e37e4e8916..0cdfee266690b70fccc93eee4573f0b0cb65766a 100644 (file)
@@ -299,5 +299,3 @@ module_exit(pikawdt_exit);
 MODULE_AUTHOR("Sean MacLennan <smaclennan@pikatech.com>");
 MODULE_DESCRIPTION("PIKA FPGA based Watchdog Timer");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
index b30bd430f59120b812dac8feb1732d2edb2f3f22..1bdcc313e1d9f713dc24c8b4cf7e2f7e9c312574 100644 (file)
@@ -233,5 +233,4 @@ MODULE_PARM_DESC(nowayout,
                 "Set to 1 to keep watchdog running after device release");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:pnx4008-watchdog");
index 1b62a7dfcc95c743b97c085202ef233b46c34f82..882fdcb46ad1f5d9610b545eacc665aa01b460cc 100644 (file)
@@ -278,4 +278,3 @@ module_exit(watchdog_exit);
 MODULE_AUTHOR("Daniel Laird/Andre McCurdy");
 MODULE_DESCRIPTION("Hardware Watchdog Device for PNX833x");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 9cf6bc7a234f8d7bad6df0cd2733fead4cf11301..71e78ef4b736a1b035e69f5cef063b3a528aaebc 100644 (file)
@@ -25,8 +25,7 @@
 #include <linux/errno.h>               /* For the -ENODEV/... values */
 #include <linux/kernel.h>              /* For printk/panic/... */
 #include <linux/fs.h>                  /* For file operations */
-#include <linux/miscdevice.h>          /* For MODULE_ALIAS_MISCDEV
-                                                       (WATCHDOG_MINOR) */
+#include <linux/miscdevice.h>          /* For struct miscdevice */
 #include <linux/watchdog.h>            /* For the watchdog specific items */
 #include <linux/init.h>                        /* For __init/__exit/... */
 #include <linux/platform_device.h>     /* For platform_driver framework */
@@ -329,4 +328,3 @@ MODULE_AUTHOR("Ondrej Zajicek <santiago@crfreenet.org>,"
                "Florian Fainelli <florian@openwrt.org>");
 MODULE_DESCRIPTION("Driver for the IDT RC32434 SoC watchdog");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index b0f116c2fd533b9d3a63361696d793e3a38d6a23..082d062629592970f741967fe4a458ce7bd1df2f 100644 (file)
@@ -231,7 +231,7 @@ static int rdc321x_wdt_probe(struct platform_device *pdev)
        struct resource *r;
        struct rdc321x_wdt_pdata *pdata;
 
-       pdata = pdev->dev.platform_data;
+       pdata = dev_get_platdata(&pdev->dev);
        if (!pdata) {
                dev_err(&pdev->dev, "no platform data supplied\n");
                return -ENODEV;
@@ -298,4 +298,3 @@ module_platform_driver(rdc321x_wdt_driver);
 MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
 MODULE_DESCRIPTION("RDC321x watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/rt2880_wdt.c b/drivers/watchdog/rt2880_wdt.c
new file mode 100644 (file)
index 0000000..53d37fe
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Ralink RT288x/RT3xxx/MT76xx built-in hardware watchdog timer
+ *
+ * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
+ *
+ * This driver was based on: drivers/watchdog/softdog.c
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include <linux/clk.h>
+#include <linux/reset.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/watchdog.h>
+#include <linux/miscdevice.h>
+#include <linux/moduleparam.h>
+#include <linux/platform_device.h>
+
+#include <asm/mach-ralink/ralink_regs.h>
+
+#define SYSC_RSTSTAT                   0x38
+#define WDT_RST_CAUSE                  BIT(1)
+
+#define RALINK_WDT_TIMEOUT             30
+#define RALINK_WDT_PRESCALE            65536
+
+#define TIMER_REG_TMR1LOAD             0x00
+#define TIMER_REG_TMR1CTL              0x08
+
+#define TMRSTAT_TMR1RST                        BIT(5)
+
+#define TMR1CTL_ENABLE                 BIT(7)
+#define TMR1CTL_MODE_SHIFT             4
+#define TMR1CTL_MODE_MASK              0x3
+#define TMR1CTL_MODE_FREE_RUNNING      0x0
+#define TMR1CTL_MODE_PERIODIC          0x1
+#define TMR1CTL_MODE_TIMEOUT           0x2
+#define TMR1CTL_MODE_WDT               0x3
+#define TMR1CTL_PRESCALE_MASK          0xf
+#define TMR1CTL_PRESCALE_65536         0xf
+
+static struct clk *rt288x_wdt_clk;
+static unsigned long rt288x_wdt_freq;
+static void __iomem *rt288x_wdt_base;
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout,
+               "Watchdog cannot be stopped once started (default="
+               __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static inline void rt_wdt_w32(unsigned reg, u32 val)
+{
+       iowrite32(val, rt288x_wdt_base + reg);
+}
+
+static inline u32 rt_wdt_r32(unsigned reg)
+{
+       return ioread32(rt288x_wdt_base + reg);
+}
+
+static int rt288x_wdt_ping(struct watchdog_device *w)
+{
+       rt_wdt_w32(TIMER_REG_TMR1LOAD, w->timeout * rt288x_wdt_freq);
+
+       return 0;
+}
+
+static int rt288x_wdt_start(struct watchdog_device *w)
+{
+       u32 t;
+
+       t = rt_wdt_r32(TIMER_REG_TMR1CTL);
+       t &= ~(TMR1CTL_MODE_MASK << TMR1CTL_MODE_SHIFT |
+               TMR1CTL_PRESCALE_MASK);
+       t |= (TMR1CTL_MODE_WDT << TMR1CTL_MODE_SHIFT |
+               TMR1CTL_PRESCALE_65536);
+       rt_wdt_w32(TIMER_REG_TMR1CTL, t);
+
+       rt288x_wdt_ping(w);
+
+       t = rt_wdt_r32(TIMER_REG_TMR1CTL);
+       t |= TMR1CTL_ENABLE;
+       rt_wdt_w32(TIMER_REG_TMR1CTL, t);
+
+       return 0;
+}
+
+static int rt288x_wdt_stop(struct watchdog_device *w)
+{
+       u32 t;
+
+       rt288x_wdt_ping(w);
+
+       t = rt_wdt_r32(TIMER_REG_TMR1CTL);
+       t &= ~TMR1CTL_ENABLE;
+       rt_wdt_w32(TIMER_REG_TMR1CTL, t);
+
+       return 0;
+}
+
+static int rt288x_wdt_set_timeout(struct watchdog_device *w, unsigned int t)
+{
+       w->timeout = t;
+       rt288x_wdt_ping(w);
+
+       return 0;
+}
+
+static int rt288x_wdt_bootcause(void)
+{
+       if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
+               return WDIOF_CARDRESET;
+
+       return 0;
+}
+
+static struct watchdog_info rt288x_wdt_info = {
+       .identity = "Ralink Watchdog",
+       .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+};
+
+static struct watchdog_ops rt288x_wdt_ops = {
+       .owner = THIS_MODULE,
+       .start = rt288x_wdt_start,
+       .stop = rt288x_wdt_stop,
+       .ping = rt288x_wdt_ping,
+       .set_timeout = rt288x_wdt_set_timeout,
+};
+
+static struct watchdog_device rt288x_wdt_dev = {
+       .info = &rt288x_wdt_info,
+       .ops = &rt288x_wdt_ops,
+       .min_timeout = 1,
+};
+
+static int rt288x_wdt_probe(struct platform_device *pdev)
+{
+       struct resource *res;
+       int ret;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       rt288x_wdt_base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(rt288x_wdt_base))
+               return PTR_ERR(rt288x_wdt_base);
+
+       rt288x_wdt_clk = devm_clk_get(&pdev->dev, NULL);
+       if (IS_ERR(rt288x_wdt_clk))
+               return PTR_ERR(rt288x_wdt_clk);
+
+       device_reset(&pdev->dev);
+
+       rt288x_wdt_freq = clk_get_rate(rt288x_wdt_clk) / RALINK_WDT_PRESCALE;
+
+       rt288x_wdt_dev.dev = &pdev->dev;
+       rt288x_wdt_dev.bootstatus = rt288x_wdt_bootcause();
+
+       rt288x_wdt_dev.max_timeout = (0xfffful / rt288x_wdt_freq);
+       rt288x_wdt_dev.timeout = rt288x_wdt_dev.max_timeout;
+
+       watchdog_set_nowayout(&rt288x_wdt_dev, nowayout);
+
+       ret = watchdog_register_device(&rt288x_wdt_dev);
+       if (!ret)
+               dev_info(&pdev->dev, "Initialized\n");
+
+       return 0;
+}
+
+static int rt288x_wdt_remove(struct platform_device *pdev)
+{
+       watchdog_unregister_device(&rt288x_wdt_dev);
+
+       return 0;
+}
+
+static void rt288x_wdt_shutdown(struct platform_device *pdev)
+{
+       rt288x_wdt_stop(&rt288x_wdt_dev);
+}
+
+static const struct of_device_id rt288x_wdt_match[] = {
+       { .compatible = "ralink,rt2880-wdt" },
+       {},
+};
+MODULE_DEVICE_TABLE(of, rt288x_wdt_match);
+
+static struct platform_driver rt288x_wdt_driver = {
+       .probe          = rt288x_wdt_probe,
+       .remove         = rt288x_wdt_remove,
+       .shutdown       = rt288x_wdt_shutdown,
+       .driver         = {
+               .name           = KBUILD_MODNAME,
+               .owner          = THIS_MODULE,
+               .of_match_table = rt288x_wdt_match,
+       },
+};
+
+module_platform_driver(rt288x_wdt_driver);
+
+MODULE_DESCRIPTION("MediaTek/Ralink RT288x/RT3xxx hardware watchdog driver");
+MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
+MODULE_LICENSE("GPL v2");
index 23aad7c6bf5d67dac3c4f43064186dc689fe292a..7d8fd041ee250d3759fc2b86519012a09ded76e2 100644 (file)
@@ -29,7 +29,6 @@
 #include <linux/moduleparam.h>
 #include <linux/types.h>
 #include <linux/timer.h>
-#include <linux/miscdevice.h> /* for MODULE_ALIAS_MISCDEV */
 #include <linux/watchdog.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
@@ -539,5 +538,4 @@ MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, "
              "Dimitry Andric <dimitry.andric@tomtom.com>");
 MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:s3c2410-wdt");
index ccd6b29e21bfef2aad0ea86ff58c22ac1acc76c1..e1d39a1e9628dd4ce177b197032bb716083b7506 100644 (file)
@@ -193,4 +193,3 @@ module_param(margin, int, 0);
 MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index ea5d84a1fdad71ad517eba174d5ef1a0fb8cffb0..3abae50773b88d29281c57dd5aba3451fd4ef861 100644 (file)
@@ -341,7 +341,6 @@ MODULE_PARM_DESC(timeout,
       "Watchdog timeout in microseconds (max/default 8388607 or 8.3ish secs)");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 /*
  * example code that can be put in a platform code area to utilize the
index 63632ec87c7e7f7064485521a9fa3109b61c7740..2eef58a0cf059837c5055d386bede89e21247c7f 100644 (file)
@@ -387,4 +387,3 @@ module_exit(sbc60xxwdt_unload);
 MODULE_AUTHOR("Jakob Oestergaard <jakob@unthought.net>");
 MODULE_DESCRIPTION("60xx Single Board Computer Watchdog Timer driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 719edc8fdeb39c083d797fa72010b79bb50e728b..5f268add17ceffdd9b4aa4466b73804cc5310e31 100644 (file)
@@ -309,5 +309,3 @@ MODULE_AUTHOR("Gilles Gigan");
 MODULE_DESCRIPTION("Watchdog device driver for single board"
                   " computers EPIC Nano 7240 from iEi");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
index d4781e05f0171bbe577f95d524445362db59624a..da60560ca446e7a1023c1707a0615c15e4f3af3c 100644 (file)
@@ -404,6 +404,5 @@ MODULE_AUTHOR("Ian E. Morgan <imorgan@webcon.ca>");
 MODULE_DESCRIPTION("SBC8360 watchdog driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION("1.01");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 /* end of sbc8360.c */
index 0c3e9f66ef7713bc88e37c48353fb646197f9ff8..a1c502e0d8ece4e58dc6cbfed36df21c53e81e45 100644 (file)
@@ -220,4 +220,3 @@ MODULE_DESCRIPTION("Hardware Watchdog Device for Winsystems EPX-C3 SBC.  "
        "so only use it if you are *sure* you are running on this specific "
        "SBC system from Winsystems!  It writes to IO ports 0x1ee and 0x1ef!");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 90d5527ca8863663cbd951ae2a656423eff3fb1e..a517d8bae7578d707585753e81c44fe2353f19c3 100644 (file)
@@ -263,5 +263,3 @@ module_param(nowayout, bool, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
 
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
index 3fb83b0c28c23a58862b55f482ed2e8c3c0003c9..3b9fff9dcf654ba6abfb09f970a7d288147d7083 100644 (file)
@@ -476,4 +476,3 @@ MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>");
 MODULE_DESCRIPTION(
        "Driver for National Semiconductor PC87307/PC97307 watchdog component");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 707e027e50025f4fbff1c73215ede8a3ee4491df..f353e18b1a82fc65221a0dcf9efa7bf696eedbe3 100644 (file)
@@ -433,4 +433,3 @@ MODULE_AUTHOR("Scott and Bill Jennings");
 MODULE_DESCRIPTION(
        "Driver for watchdog timer in AMD \"Elan\" SC520 uProcessor");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index af7b136b1874912b735786471421e64208101057..b96127ea3de16322927da5c1351aecbacbd2843d 100644 (file)
@@ -26,8 +26,7 @@
 #include <linux/types.h>               /* For standard types (like size_t) */
 #include <linux/errno.h>               /* For the -ENODEV/... values */
 #include <linux/kernel.h>              /* For printk/... */
-#include <linux/miscdevice.h>          /* For MODULE_ALIAS_MISCDEV
-                                                       (WATCHDOG_MINOR) */
+#include <linux/miscdevice.h>          /* For struct miscdevice */
 #include <linux/watchdog.h>            /* For the watchdog specific items */
 #include <linux/init.h>                        /* For __init/__exit/... */
 #include <linux/fs.h>                  /* For file operations */
@@ -545,5 +544,3 @@ module_exit(sch311x_wdt_exit);
 MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
 MODULE_DESCRIPTION("SMSC SCH311x WatchDog Timer Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
index 8ae7c282d465ade3be2c3f08efe91968bf2bb503..836377cf92710a03af1a158cd69edfa94a67794b 100644 (file)
@@ -37,7 +37,6 @@
 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
 MODULE_DESCRIPTION("NatSemi SCx200 Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 static int margin = 60;                /* in seconds */
 module_param(margin, int, 0);
index 5bca794577687046f4b978c58066f7e7ade7f516..f9b8e06f355808e763ca7a1f7f2e4511fe33c88f 100644 (file)
@@ -343,7 +343,6 @@ MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
 MODULE_DESCRIPTION("SuperH watchdog driver");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:" DRV_NAME);
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 module_param(clock_division_ratio, int, 0);
 MODULE_PARM_DESC(clock_division_ratio,
diff --git a/drivers/watchdog/sirfsoc_wdt.c b/drivers/watchdog/sirfsoc_wdt.c
new file mode 100644 (file)
index 0000000..ced3edc
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ * Watchdog driver for CSR SiRFprimaII and SiRFatlasVI
+ *
+ * Copyright (c) 2013 Cambridge Silicon Radio Limited, a CSR plc group company.
+ *
+ * Licensed under GPLv2 or later.
+ */
+
+#include <linux/module.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/moduleparam.h>
+#include <linux/of.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
+
+#define CLOCK_FREQ     1000000
+
+#define SIRFSOC_TIMER_COUNTER_LO       0x0000
+#define SIRFSOC_TIMER_MATCH_0          0x0008
+#define SIRFSOC_TIMER_INT_EN           0x0024
+#define SIRFSOC_TIMER_WATCHDOG_EN      0x0028
+#define SIRFSOC_TIMER_LATCH            0x0030
+#define SIRFSOC_TIMER_LATCHED_LO       0x0034
+
+#define SIRFSOC_TIMER_WDT_INDEX                5
+
+#define SIRFSOC_WDT_MIN_TIMEOUT                30              /* 30 secs */
+#define SIRFSOC_WDT_MAX_TIMEOUT                (10 * 60)       /* 10 mins */
+#define SIRFSOC_WDT_DEFAULT_TIMEOUT    30              /* 30 secs */
+
+static unsigned int timeout = SIRFSOC_WDT_DEFAULT_TIMEOUT;
+static bool nowayout = WATCHDOG_NOWAYOUT;
+
+module_param(timeout, uint, 0);
+module_param(nowayout, bool, 0);
+
+MODULE_PARM_DESC(timeout, "Default watchdog timeout (in seconds)");
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+                       __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static unsigned int sirfsoc_wdt_gettimeleft(struct watchdog_device *wdd)
+{
+       u32 counter, match;
+       void __iomem *wdt_base;
+       int time_left;
+
+       wdt_base = watchdog_get_drvdata(wdd);
+       counter = readl(wdt_base + SIRFSOC_TIMER_COUNTER_LO);
+       match = readl(wdt_base +
+               SIRFSOC_TIMER_MATCH_0 + (SIRFSOC_TIMER_WDT_INDEX << 2));
+
+       time_left = match - counter;
+
+       return time_left / CLOCK_FREQ;
+}
+
+static int sirfsoc_wdt_updatetimeout(struct watchdog_device *wdd)
+{
+       u32 counter, timeout_ticks;
+       void __iomem *wdt_base;
+
+       timeout_ticks = wdd->timeout * CLOCK_FREQ;
+       wdt_base = watchdog_get_drvdata(wdd);
+
+       /* Enable the latch before reading the LATCH_LO register */
+       writel(1, wdt_base + SIRFSOC_TIMER_LATCH);
+
+       /* Set the TO value */
+       counter = readl(wdt_base + SIRFSOC_TIMER_LATCHED_LO);
+
+       counter += timeout_ticks;
+
+       writel(counter, wdt_base +
+               SIRFSOC_TIMER_MATCH_0 + (SIRFSOC_TIMER_WDT_INDEX << 2));
+
+       return 0;
+}
+
+static int sirfsoc_wdt_enable(struct watchdog_device *wdd)
+{
+       void __iomem *wdt_base = watchdog_get_drvdata(wdd);
+       sirfsoc_wdt_updatetimeout(wdd);
+
+       /*
+        * NOTE: If interrupt is not enabled
+        * then WD-Reset doesn't get generated at all.
+        */
+       writel(readl(wdt_base + SIRFSOC_TIMER_INT_EN)
+               | (1 << SIRFSOC_TIMER_WDT_INDEX),
+               wdt_base + SIRFSOC_TIMER_INT_EN);
+       writel(1, wdt_base + SIRFSOC_TIMER_WATCHDOG_EN);
+
+       return 0;
+}
+
+static int sirfsoc_wdt_disable(struct watchdog_device *wdd)
+{
+       void __iomem *wdt_base = watchdog_get_drvdata(wdd);
+
+       writel(0, wdt_base + SIRFSOC_TIMER_WATCHDOG_EN);
+       writel(readl(wdt_base + SIRFSOC_TIMER_INT_EN)
+               & (~(1 << SIRFSOC_TIMER_WDT_INDEX)),
+               wdt_base + SIRFSOC_TIMER_INT_EN);
+
+       return 0;
+}
+
+static int sirfsoc_wdt_settimeout(struct watchdog_device *wdd, unsigned int to)
+{
+       wdd->timeout = to;
+       sirfsoc_wdt_updatetimeout(wdd);
+
+       return 0;
+}
+
+#define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
+
+static const struct watchdog_info sirfsoc_wdt_ident = {
+       .options          =     OPTIONS,
+       .firmware_version =     0,
+       .identity         =     "SiRFSOC Watchdog",
+};
+
+static struct watchdog_ops sirfsoc_wdt_ops = {
+       .owner = THIS_MODULE,
+       .start = sirfsoc_wdt_enable,
+       .stop = sirfsoc_wdt_disable,
+       .get_timeleft = sirfsoc_wdt_gettimeleft,
+       .ping = sirfsoc_wdt_updatetimeout,
+       .set_timeout = sirfsoc_wdt_settimeout,
+};
+
+static struct watchdog_device sirfsoc_wdd = {
+       .info = &sirfsoc_wdt_ident,
+       .ops = &sirfsoc_wdt_ops,
+       .timeout = SIRFSOC_WDT_DEFAULT_TIMEOUT,
+       .min_timeout = SIRFSOC_WDT_MIN_TIMEOUT,
+       .max_timeout = SIRFSOC_WDT_MAX_TIMEOUT,
+};
+
+static int sirfsoc_wdt_probe(struct platform_device *pdev)
+{
+       struct resource *res;
+       int ret;
+       void __iomem *base;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(base))
+               return PTR_ERR(base);
+
+       watchdog_set_drvdata(&sirfsoc_wdd, base);
+
+       watchdog_init_timeout(&sirfsoc_wdd, timeout, &pdev->dev);
+       watchdog_set_nowayout(&sirfsoc_wdd, nowayout);
+
+       ret = watchdog_register_device(&sirfsoc_wdd);
+       if (ret)
+               return ret;
+
+       platform_set_drvdata(pdev, &sirfsoc_wdd);
+
+       return 0;
+}
+
+static void sirfsoc_wdt_shutdown(struct platform_device *pdev)
+{
+       struct watchdog_device *wdd = platform_get_drvdata(pdev);
+
+       sirfsoc_wdt_disable(wdd);
+}
+
+static int sirfsoc_wdt_remove(struct platform_device *pdev)
+{
+       sirfsoc_wdt_shutdown(pdev);
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int sirfsoc_wdt_suspend(struct device *dev)
+{
+       return 0;
+}
+
+static int sirfsoc_wdt_resume(struct device *dev)
+{
+       struct watchdog_device *wdd = dev_get_drvdata(dev);
+
+       /*
+        * NOTE: Since timer controller registers settings are saved
+        * and restored back by the timer-prima2.c, so we need not
+        * update WD settings except refreshing timeout.
+        */
+       sirfsoc_wdt_updatetimeout(wdd);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(sirfsoc_wdt_pm_ops,
+               sirfsoc_wdt_suspend, sirfsoc_wdt_resume);
+
+static const struct of_device_id sirfsoc_wdt_of_match[] = {
+       { .compatible = "sirf,prima2-tick"},
+       {},
+};
+MODULE_DEVICE_TABLE(of, sirfsoc_wdt_of_match);
+
+static struct platform_driver sirfsoc_wdt_driver = {
+       .driver = {
+               .name = "sirfsoc-wdt",
+               .owner = THIS_MODULE,
+               .pm = &sirfsoc_wdt_pm_ops,
+               .of_match_table = of_match_ptr(sirfsoc_wdt_of_match),
+       },
+       .probe = sirfsoc_wdt_probe,
+       .remove = sirfsoc_wdt_remove,
+       .shutdown = sirfsoc_wdt_shutdown,
+};
+module_platform_driver(sirfsoc_wdt_driver);
+
+MODULE_DESCRIPTION("SiRF SoC watchdog driver");
+MODULE_AUTHOR("Xianglong Du <Xianglong.Du@csr.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:sirfsoc-wdt");
index 6d665f9c1d586393224594df0d2ae57bd9412b29..445ea1ad1fa9abc7fcef53b63e5d0025032f9f07 100644 (file)
@@ -603,8 +603,6 @@ MODULE_DESCRIPTION("Driver for SMsC 37B787 watchdog component (Version "
                                                                VERSION ")");
 MODULE_LICENSE("GPL");
 
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-
 #ifdef SMSC_SUPPORT_MINUTES
 module_param(unit, int, 0);
 MODULE_PARM_DESC(unit,
index b68b1e519d53d02d77b8a89e73a1779adda2138c..ef2638fee4a8f7037c1f7c342ec1be1347ee3957 100644 (file)
@@ -207,4 +207,3 @@ module_exit(watchdog_exit);
 MODULE_AUTHOR("Alan Cox");
 MODULE_DESCRIPTION("Software Watchdog Device Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 0e9d8c479c3551e2bb5a51cb9bfcd055f2bcb3e7..ce63a1bbf395fa94ea5833aa0eb98d84aaa5dc75 100644 (file)
@@ -580,4 +580,3 @@ module_exit(sp5100_tco_cleanup_module);
 MODULE_AUTHOR("Priyanka Gupta");
 MODULE_DESCRIPTION("TCO timer driver for SP5100/SB800 chipset");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 58df98aec1228d794e6b42030192cd6e54012234..3f786ce0a6f2ae93fbb788f7b5dbfc1a06efeac5 100644 (file)
@@ -268,7 +268,6 @@ static int sp805_wdt_remove(struct amba_device *adev)
        struct sp805_wdt *wdt = amba_get_drvdata(adev);
 
        watchdog_unregister_device(&wdt->wdd);
-       amba_set_drvdata(adev, NULL);
        watchdog_set_drvdata(&wdt->wdd, NULL);
 
        return 0;
index c97e98dcde62f9eb47e87c65676324aaaaae5209..d667f6b51d35f93aba02547f82653f3dbb189aa4 100644 (file)
@@ -30,7 +30,7 @@ MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat period in seconds from 1 to "
 static int wdt_start(struct watchdog_device *wdd)
 {
        struct device *dev = watchdog_get_drvdata(wdd);
-       struct stmp3xxx_wdt_pdata *pdata = dev->platform_data;
+       struct stmp3xxx_wdt_pdata *pdata = dev_get_platdata(dev);
 
        pdata->wdt_set_timeout(dev->parent, wdd->timeout * WDOG_TICK_RATE);
        return 0;
@@ -39,7 +39,7 @@ static int wdt_start(struct watchdog_device *wdd)
 static int wdt_stop(struct watchdog_device *wdd)
 {
        struct device *dev = watchdog_get_drvdata(wdd);
-       struct stmp3xxx_wdt_pdata *pdata = dev->platform_data;
+       struct stmp3xxx_wdt_pdata *pdata = dev_get_platdata(dev);
 
        pdata->wdt_set_timeout(dev->parent, 0);
        return 0;
@@ -108,4 +108,3 @@ module_platform_driver(stmp3xxx_wdt_driver);
 MODULE_DESCRIPTION("STMP3XXX RTC Watchdog Driver");
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index f6caa77151c74a4fc827d933715c92c57da5e0b7..76332d893e122a3293ec3d2b6e7230ad354b04a2 100644 (file)
@@ -217,7 +217,7 @@ static struct platform_driver sunxi_wdt_driver = {
        .driver         = {
                .owner          = THIS_MODULE,
                .name           = DRV_NAME,
-               .of_match_table = of_match_ptr(sunxi_wdt_dt_ids)
+               .of_match_table = sunxi_wdt_dt_ids,
        },
 };
 
index c9b0c627fe7e6d8513dd4d43ba18cb65cfbba132..09d4831aa61f8328b6291f97849c9adf06b62b0a 100644 (file)
@@ -192,7 +192,7 @@ static int ts72xx_wdt_open(struct inode *inode, struct file *file)
                dev_err(&wdt->pdev->dev,
                        "failed to convert timeout (%d) to register value\n",
                        timeout);
-               return -EINVAL;
+               return regval;
        }
 
        if (mutex_lock_interruptible(&wdt->lock))
@@ -305,7 +305,8 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
 
        switch (cmd) {
        case WDIOC_GETSUPPORT:
-               error = copy_to_user(argp, &winfo, sizeof(winfo));
+               if (copy_to_user(argp, &winfo, sizeof(winfo)))
+                       error = -EFAULT;
                break;
 
        case WDIOC_GETSTATUS:
@@ -320,10 +321,9 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
        case WDIOC_SETOPTIONS: {
                int options;
 
-               if (get_user(options, p)) {
-                       error = -EFAULT;
+               error = get_user(options, p);
+               if (error)
                        break;
-               }
 
                error = -EINVAL;
 
@@ -341,30 +341,26 @@ static long ts72xx_wdt_ioctl(struct file *file, unsigned int cmd,
 
        case WDIOC_SETTIMEOUT: {
                int new_timeout;
+               int regval;
 
-               if (get_user(new_timeout, p)) {
-                       error = -EFAULT;
-               } else {
-                       int regval;
-
-                       regval = timeout_to_regval(new_timeout);
-                       if (regval < 0) {
-                               error = -EINVAL;
-                       } else {
-                               ts72xx_wdt_stop(wdt);
-                               wdt->regval = regval;
-                               ts72xx_wdt_start(wdt);
-                       }
-               }
+               error = get_user(new_timeout, p);
                if (error)
                        break;
 
+               regval = timeout_to_regval(new_timeout);
+               if (regval < 0) {
+                       error = regval;
+                       break;
+               }
+               ts72xx_wdt_stop(wdt);
+               wdt->regval = regval;
+               ts72xx_wdt_start(wdt);
+
                /*FALLTHROUGH*/
        }
 
        case WDIOC_GETTIMEOUT:
-               if (put_user(regval_to_timeout(wdt->regval), p))
-                       error = -EFAULT;
+               error = put_user(regval_to_timeout(wdt->regval), p);
                break;
 
        default:
index 88f23c5cfddba5cf646d6adb4de5c4bccd1b9bb4..0fd0e8ae62a833b462b29bd09f8f5e7666e437bf 100644 (file)
@@ -176,5 +176,4 @@ module_platform_driver_probe(txx9wdt_driver, txx9wdt_probe);
 
 MODULE_DESCRIPTION("TXx9 Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:txx9wdt");
index a614d84121c317c8707447803eaaeb1802be7554..e029b5768f2c1379279f034dc24c892b52fc0ec3 100644 (file)
@@ -88,7 +88,7 @@ static struct watchdog_device ux500_wdt = {
 static int ux500_wdt_probe(struct platform_device *pdev)
 {
        int ret;
-       struct ux500_wdt_data *pdata = pdev->dev.platform_data;
+       struct ux500_wdt_data *pdata = dev_get_platdata(&pdev->dev);
 
        if (pdata) {
                if (pdata->timeout > 0)
@@ -167,5 +167,4 @@ module_platform_driver(ux500_wdt_driver);
 MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
 MODULE_DESCRIPTION("Ux500 Watchdog Driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 MODULE_ALIAS("platform:ux500_wdt");
index 92f1326f0cfc30dd24b0d829a02548ac42e0d33b..e24b2108287483803c82709d0feec1dae8b29907 100644 (file)
@@ -1,6 +1,9 @@
 /*
  *     w83627hf/thf WDT driver
  *
+ *     (c) Copyright 2013 Guenter Roeck
+ *             converted to watchdog infrastructure
+ *
  *     (c) Copyright 2007 Vlad Drukker <vlad@storewiz.com>
  *             added support for W83627THF.
  *
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/types.h>
-#include <linux/miscdevice.h>
 #include <linux/watchdog.h>
-#include <linux/fs.h>
 #include <linux/ioport.h>
 #include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/init.h>
-#include <linux/spinlock.h>
 #include <linux/io.h>
-#include <linux/uaccess.h>
-
 
 #define WATCHDOG_NAME "w83627hf/thf/hg/dhg WDT"
 #define WATCHDOG_TIMEOUT 60            /* 60 sec default timeout */
 
-static unsigned long wdt_is_open;
-static char expect_close;
-static DEFINE_SPINLOCK(io_lock);
-
 /* You must set this - there is no sane way to probe for this board. */
 static int wdt_io = 0x2E;
 module_param(wdt_io, int, 0);
 MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)");
 
-static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
+static int timeout;                    /* in seconds */
 module_param(timeout, int, 0);
 MODULE_PARM_DESC(timeout,
                "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
@@ -76,236 +70,147 @@ MODULE_PARM_DESC(nowayout,
                                                        (same as EFER) */
 #define WDT_EFDR (WDT_EFIR+1) /* Extended Function Data Register */
 
-static void w83627hf_select_wd_register(void)
+#define W83627HF_LD_WDT                0x08
+
+static void superio_outb(int reg, int val)
 {
-       unsigned char c;
+       outb(reg, WDT_EFER);
+       outb(val, WDT_EFDR);
+}
+
+static inline int superio_inb(int reg)
+{
+       outb(reg, WDT_EFER);
+       return inb(WDT_EFDR);
+}
+
+static int superio_enter(void)
+{
+       if (!request_muxed_region(wdt_io, 2, WATCHDOG_NAME))
+               return -EBUSY;
+
        outb_p(0x87, WDT_EFER); /* Enter extended function mode */
        outb_p(0x87, WDT_EFER); /* Again according to manual */
 
-       outb(0x20, WDT_EFER);   /* check chip version   */
-       c = inb(WDT_EFDR);
-       if (c == 0x82) {        /* W83627THF            */
-               outb_p(0x2b, WDT_EFER); /* select GPIO3 */
-               c = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */
-               outb_p(0x2b, WDT_EFER);
-               outb_p(c, WDT_EFDR);    /* set GPIO3 to WDT0 */
-       } else if (c == 0x88 || c == 0xa0) {    /* W83627EHF / W83627DHG */
-               outb_p(0x2d, WDT_EFER); /* select GPIO5 */
-               c = inb_p(WDT_EFDR) & ~0x01; /* PIN77 -> WDT0# */
-               outb_p(0x2d, WDT_EFER);
-               outb_p(c, WDT_EFDR); /* set GPIO5 to WDT0 */
-       }
+       return 0;
+}
 
-       outb_p(0x07, WDT_EFER); /* point to logical device number reg */
-       outb_p(0x08, WDT_EFDR); /* select logical device 8 (GPIO2) */
-       outb_p(0x30, WDT_EFER); /* select CR30 */
-       outb_p(0x01, WDT_EFDR); /* set bit 0 to activate GPIO2 */
+static void superio_select(int ld)
+{
+       superio_outb(0x07, ld);
 }
 
-static void w83627hf_unselect_wd_register(void)
+static void superio_exit(void)
 {
        outb_p(0xAA, WDT_EFER); /* Leave extended function mode */
+       release_region(wdt_io, 2);
 }
 
 /* tyan motherboards seem to set F5 to 0x4C ?
  * So explicitly init to appropriate value. */
 
-static void w83627hf_init(void)
+static int w83627hf_init(struct watchdog_device *wdog)
 {
+       int ret;
        unsigned char t;
 
-       w83627hf_select_wd_register();
+       ret = superio_enter();
+       if (ret)
+               return ret;
+
+       superio_select(W83627HF_LD_WDT);
+       t = superio_inb(0x20);  /* check chip version   */
+       if (t == 0x82) {        /* W83627THF            */
+               t = (superio_inb(0x2b) & 0xf7);
+               superio_outb(0x2b, t | 0x04); /* set GPIO3 to WDT0 */
+       } else if (t == 0x88 || t == 0xa0) {    /* W83627EHF / W83627DHG */
+               t = superio_inb(0x2d);
+               superio_outb(0x2d, t & ~0x01);  /* set GPIO5 to WDT0 */
+       }
+
+       /* set CR30 bit 0 to activate GPIO2 */
+       t = superio_inb(0x30);
+       if (!(t & 0x01))
+               superio_outb(0x30, t | 0x01);
 
-       outb_p(0xF6, WDT_EFER); /* Select CRF6 */
-       t = inb_p(WDT_EFDR);      /* read CRF6 */
+       t = superio_inb(0xF6);
        if (t != 0) {
                pr_info("Watchdog already running. Resetting timeout to %d sec\n",
-                       timeout);
-               outb_p(timeout, WDT_EFDR);    /* Write back to CRF6 */
+                       wdog->timeout);
+               superio_outb(0xF6, wdog->timeout);
        }
 
-       outb_p(0xF5, WDT_EFER); /* Select CRF5 */
-       t = inb_p(WDT_EFDR);      /* read CRF5 */
-       t &= ~0x0C;               /* set second mode & disable keyboard
-                                   turning off watchdog */
-       t |= 0x02;                /* enable the WDTO# output low pulse
-                                   to the KBRST# pin (PIN60) */
-       outb_p(t, WDT_EFDR);    /* Write back to CRF5 */
-
-       outb_p(0xF7, WDT_EFER); /* Select CRF7 */
-       t = inb_p(WDT_EFDR);      /* read CRF7 */
-       t &= ~0xC0;               /* disable keyboard & mouse turning off
-                                   watchdog */
-       outb_p(t, WDT_EFDR);    /* Write back to CRF7 */
-
-       w83627hf_unselect_wd_register();
-}
-
-static void wdt_set_time(int timeout)
-{
-       spin_lock(&io_lock);
-
-       w83627hf_select_wd_register();
+       /* set second mode & disable keyboard turning off watchdog */
+       t = superio_inb(0xF5) & ~0x0C;
+       /* enable the WDTO# output low pulse to the KBRST# pin */
+       t |= 0x02;
+       superio_outb(0xF5, t);
 
-       outb_p(0xF6, WDT_EFER);    /* Select CRF6 */
-       outb_p(timeout, WDT_EFDR); /* Write Timeout counter to CRF6 */
+       /* disable keyboard & mouse turning off watchdog */
+       t = superio_inb(0xF7) & ~0xC0;
+       superio_outb(0xF7, t);
 
-       w83627hf_unselect_wd_register();
+       superio_exit();
 
-       spin_unlock(&io_lock);
-}
-
-static int wdt_ping(void)
-{
-       wdt_set_time(timeout);
        return 0;
 }
 
-static int wdt_disable(void)
+static int wdt_set_time(unsigned int timeout)
 {
-       wdt_set_time(0);
-       return 0;
-}
+       int ret;
+
+       ret = superio_enter();
+       if (ret)
+               return ret;
+
+       superio_select(W83627HF_LD_WDT);
+       superio_outb(0xF6, timeout);
+       superio_exit();
 
-static int wdt_set_heartbeat(int t)
-{
-       if (t < 1 || t > 255)
-               return -EINVAL;
-       timeout = t;
        return 0;
 }
 
-static int wdt_get_time(void)
+static int wdt_start(struct watchdog_device *wdog)
 {
-       int timeleft;
-
-       spin_lock(&io_lock);
-
-       w83627hf_select_wd_register();
-
-       outb_p(0xF6, WDT_EFER);    /* Select CRF6 */
-       timeleft = inb_p(WDT_EFDR); /* Read Timeout counter to CRF6 */
-
-       w83627hf_unselect_wd_register();
-
-       spin_unlock(&io_lock);
-
-       return timeleft;
+       return wdt_set_time(wdog->timeout);
 }
 
-static ssize_t wdt_write(struct file *file, const char __user *buf,
-                                               size_t count, loff_t *ppos)
+static int wdt_stop(struct watchdog_device *wdog)
 {
-       if (count) {
-               if (!nowayout) {
-                       size_t i;
-
-                       expect_close = 0;
-
-                       for (i = 0; i != count; i++) {
-                               char c;
-                               if (get_user(c, buf + i))
-                                       return -EFAULT;
-                               if (c == 'V')
-                                       expect_close = 42;
-                       }
-               }
-               wdt_ping();
-       }
-       return count;
+       return wdt_set_time(0);
 }
 
-static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+static int wdt_set_timeout(struct watchdog_device *wdog, unsigned int timeout)
 {
-       void __user *argp = (void __user *)arg;
-       int __user *p = argp;
-       int timeval;
-       static const struct watchdog_info ident = {
-               .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
-                                                       WDIOF_MAGICCLOSE,
-               .firmware_version = 1,
-               .identity = "W83627HF WDT",
-       };
-
-       switch (cmd) {
-       case WDIOC_GETSUPPORT:
-               if (copy_to_user(argp, &ident, sizeof(ident)))
-                       return -EFAULT;
-               break;
-       case WDIOC_GETSTATUS:
-       case WDIOC_GETBOOTSTATUS:
-               return put_user(0, p);
-       case WDIOC_SETOPTIONS:
-       {
-               int options, retval = -EINVAL;
-
-               if (get_user(options, p))
-                       return -EFAULT;
-               if (options & WDIOS_DISABLECARD) {
-                       wdt_disable();
-                       retval = 0;
-               }
-               if (options & WDIOS_ENABLECARD) {
-                       wdt_ping();
-                       retval = 0;
-               }
-               return retval;
-       }
-       case WDIOC_KEEPALIVE:
-               wdt_ping();
-               break;
-       case WDIOC_SETTIMEOUT:
-               if (get_user(timeval, p))
-                       return -EFAULT;
-               if (wdt_set_heartbeat(timeval))
-                       return -EINVAL;
-               wdt_ping();
-               /* Fall */
-       case WDIOC_GETTIMEOUT:
-               return put_user(timeout, p);
-       case WDIOC_GETTIMELEFT:
-               timeval = wdt_get_time();
-               return put_user(timeval, p);
-       default:
-               return -ENOTTY;
-       }
+       wdog->timeout = timeout;
+
        return 0;
 }
 
-static int wdt_open(struct inode *inode, struct file *file)
+static unsigned int wdt_get_time(struct watchdog_device *wdog)
 {
-       if (test_and_set_bit(0, &wdt_is_open))
-               return -EBUSY;
-       /*
-        *      Activate
-        */
+       unsigned int timeleft;
+       int ret;
 
-       wdt_ping();
-       return nonseekable_open(inode, file);
-}
+       ret = superio_enter();
+       if (ret)
+               return 0;
 
-static int wdt_close(struct inode *inode, struct file *file)
-{
-       if (expect_close == 42)
-               wdt_disable();
-       else {
-               pr_crit("Unexpected close, not stopping watchdog!\n");
-               wdt_ping();
-       }
-       expect_close = 0;
-       clear_bit(0, &wdt_is_open);
-       return 0;
+       superio_select(W83627HF_LD_WDT);
+       timeleft = superio_inb(0xF6);
+       superio_exit();
+
+       return timeleft;
 }
 
 /*
  *     Notifier for system down
  */
-
 static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
        void *unused)
 {
        if (code == SYS_DOWN || code == SYS_HALT)
-               wdt_disable();  /* Turn the WDT off */
+               wdt_set_time(0);        /* Turn the WDT off */
 
        return NOTIFY_DONE;
 }
@@ -314,19 +219,25 @@ static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
  *     Kernel Interfaces
  */
 
-static const struct file_operations wdt_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .write          = wdt_write,
-       .unlocked_ioctl = wdt_ioctl,
-       .open           = wdt_open,
-       .release        = wdt_close,
+static struct watchdog_info wdt_info = {
+       .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+       .identity = "W83627HF Watchdog",
 };
 
-static struct miscdevice wdt_miscdev = {
-       .minor = WATCHDOG_MINOR,
-       .name = "watchdog",
-       .fops = &wdt_fops,
+static struct watchdog_ops wdt_ops = {
+       .owner = THIS_MODULE,
+       .start = wdt_start,
+       .stop = wdt_stop,
+       .set_timeout = wdt_set_timeout,
+       .get_timeleft = wdt_get_time,
+};
+
+static struct watchdog_device wdt_dev = {
+       .info = &wdt_info,
+       .ops = &wdt_ops,
+       .timeout = WATCHDOG_TIMEOUT,
+       .min_timeout = 1,
+       .max_timeout = 255,
 };
 
 /*
@@ -344,50 +255,39 @@ static int __init wdt_init(void)
 
        pr_info("WDT driver for the Winbond(TM) W83627HF/THF/HG/DHG Super I/O chip initialising\n");
 
-       if (wdt_set_heartbeat(timeout)) {
-               wdt_set_heartbeat(WATCHDOG_TIMEOUT);
-               pr_info("timeout value must be 1 <= timeout <= 255, using %d\n",
-                       WATCHDOG_TIMEOUT);
-       }
+       watchdog_init_timeout(&wdt_dev, timeout, NULL);
+       watchdog_set_nowayout(&wdt_dev, nowayout);
 
-       if (!request_region(wdt_io, 1, WATCHDOG_NAME)) {
-               pr_err("I/O address 0x%04x already in use\n", wdt_io);
-               ret = -EIO;
-               goto out;
+       ret = w83627hf_init(&wdt_dev);
+       if (ret) {
+               pr_err("failed to initialize watchdog (err=%d)\n", ret);
+               return ret;
        }
 
-       w83627hf_init();
-
        ret = register_reboot_notifier(&wdt_notifier);
        if (ret != 0) {
                pr_err("cannot register reboot notifier (err=%d)\n", ret);
-               goto unreg_regions;
+               return ret;
        }
 
-       ret = misc_register(&wdt_miscdev);
-       if (ret != 0) {
-               pr_err("cannot register miscdev on minor=%d (err=%d)\n",
-                      WATCHDOG_MINOR, ret);
+       ret = watchdog_register_device(&wdt_dev);
+       if (ret)
                goto unreg_reboot;
-       }
 
        pr_info("initialized. timeout=%d sec (nowayout=%d)\n",
-               timeout, nowayout);
+               wdt_dev.timeout, nowayout);
 
-out:
        return ret;
+
 unreg_reboot:
        unregister_reboot_notifier(&wdt_notifier);
-unreg_regions:
-       release_region(wdt_io, 1);
-       goto out;
+       return ret;
 }
 
 static void __exit wdt_exit(void)
 {
-       misc_deregister(&wdt_miscdev);
+       watchdog_unregister_device(&wdt_dev);
        unregister_reboot_notifier(&wdt_notifier);
-       release_region(wdt_io, 1);
 }
 
 module_init(wdt_init);
@@ -396,4 +296,3 @@ module_exit(wdt_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Pádraig  Brady <P@draigBrady.com>");
 MODULE_DESCRIPTION("w83627hf/thf WDT driver");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index cd9f3c1e1af44bc14cdd5b116176b9262a783a96..aaf2995d37f4b595d010efa500e89bb1ae5aef5b 100644 (file)
@@ -458,4 +458,3 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Marcus Junker <junker@anduras.de>, "
                "Samuel Tardieu <sam@rfc1149.net>");
 MODULE_DESCRIPTION("w83697hf/hg WDT driver");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 274be0bfaf244878438411fb025063352cb51f91..ff58cb74671f55ec8220a7d4cf6bbffca6ed2c25 100644 (file)
@@ -395,4 +395,3 @@ module_exit(wdt_exit);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Flemming Frandsen <ff@nrvissing.net>");
 MODULE_DESCRIPTION("w83697ug/uf WDT driver");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 7874ae06232b3648757c1529c8df5aaa10729d16..f0483c75ed324b63cf3d63f33a2367325b1c7869 100644 (file)
@@ -406,4 +406,3 @@ module_exit(w83877f_wdt_unload);
 MODULE_AUTHOR("Scott and Bill Jennings");
 MODULE_DESCRIPTION("Driver for watchdog timer in w83877f chip");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 5d2c902825c2ec558f0044b3cc07b4c0a4620894..91bf55a2002497eca6de68258515484ba9f13efa 100644 (file)
@@ -527,4 +527,3 @@ module_exit(w83977f_wdt_exit);
 MODULE_AUTHOR("Jose Goncalves <jose.goncalves@inov.pt>");
 MODULE_DESCRIPTION("Driver for watchdog timer in W83977F I/O chip");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 25aba6e00a23ffc49f344709d4149d3991958bfd..db0da7ea4fd8d8c12514f1f8552b1f425c84d9bc 100644 (file)
@@ -322,6 +322,5 @@ module_exit(wafwdt_exit);
 MODULE_AUTHOR("Justin Cormack");
 MODULE_DESCRIPTION("ICP Wafer 5823 Single Board Computer WDT driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 /* end of wafer5823wdt.c */
index 05d18b4c661b2c15904982e6385944b1ca5515d1..461336c4519faf3acee6dad759030a6f0778876d 100644 (file)
@@ -77,7 +77,7 @@ int watchdog_init_timeout(struct watchdog_device *wdd,
 
        watchdog_check_min_max_timeout(wdd);
 
-       /* try to get the tiemout module parameter first */
+       /* try to get the timeout module parameter first */
        if (!watchdog_timeout_invalid(wdd, timeout_parm)) {
                wdd->timeout = timeout_parm;
                return ret;
index 3045debd5411e26d818309fc3a24c349af0ade4f..0240c60d14e3c04461f376de24f2ed9f9b358344 100644 (file)
@@ -48,8 +48,6 @@
 MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>");
 MODULE_DESCRIPTION("RTAS watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-MODULE_ALIAS_MISCDEV(TEMP_MINOR);
 
 static bool wdrtas_nowayout = WATCHDOG_NOWAYOUT;
 static atomic_t wdrtas_miscdev_open = ATOMIC_INIT(0);
index ee4333c01109335088dbbd1a5cd4124f4e2f922b..e0206b5b7d8955526f9598a6cc012fcdfd090873 100644 (file)
@@ -664,6 +664,4 @@ module_exit(wdt_exit);
 
 MODULE_AUTHOR("Alan Cox");
 MODULE_DESCRIPTION("Driver for ISA ICS watchdog cards (WDT500/501)");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-MODULE_ALIAS_MISCDEV(TEMP_MINOR);
 MODULE_LICENSE("GPL");
index 5eec740538824b4e529c725f8e82606b54364240..7355ddd0b2073be68c78e3ced5932942c690876c 100644 (file)
@@ -224,7 +224,6 @@ static void __exit footbridge_watchdog_exit(void)
 MODULE_AUTHOR("Phil Blundell <pb@nexus.co.uk>");
 MODULE_DESCRIPTION("Footbridge watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 
 module_param(soft_margin, int, 0);
 MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
index 65a402344933952176170de888311d72fe0bd157..a8e6f87f60c918fb21cb76aae708085fb1a57d44 100644 (file)
@@ -507,4 +507,3 @@ module_exit(wd977_exit);
 MODULE_AUTHOR("Woody Suwalski <woodys@xandros.com>");
 MODULE_DESCRIPTION("W83977AF Watchdog driver");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index 36a54c0e32dd0bded2a4c64393101ba7cde2151d..ee89ba4dea63c932ecad137b49712191b9a9b799 100644 (file)
@@ -744,5 +744,3 @@ module_pci_driver(wdtpci_driver);
 MODULE_AUTHOR("JP Nollmann, Alan Cox");
 MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards");
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-MODULE_ALIAS_MISCDEV(TEMP_MINOR);
index d4e47eda41828ea4591a019bde479173e8a4c49a..e243bd01c774274813e48c7dbfdcb56e53af3197 100644 (file)
@@ -184,7 +184,7 @@ static const struct watchdog_ops wm831x_wdt_ops = {
 static int wm831x_wdt_probe(struct platform_device *pdev)
 {
        struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
-       struct wm831x_pdata *chip_pdata;
+       struct wm831x_pdata *chip_pdata = dev_get_platdata(pdev->dev.parent);
        struct wm831x_watchdog_pdata *pdata;
        struct wm831x_wdt_drvdata *driver_data;
        struct watchdog_device *wm831x_wdt;
@@ -231,12 +231,10 @@ static int wm831x_wdt_probe(struct platform_device *pdev)
                wm831x_wdt->timeout = wm831x_wdt_cfgs[i].time;
 
        /* Apply any configuration */
-       if (pdev->dev.parent->platform_data) {
-               chip_pdata = pdev->dev.parent->platform_data;
+       if (chip_pdata)
                pdata = chip_pdata->watchdog;
-       } else {
+       else
                pdata = NULL;
-       }
 
        if (pdata) {
                reg &= ~(WM831X_WDOG_SECACT_MASK | WM831X_WDOG_PRIMACT_MASK |
index 92ad33d0cb71c2c897f6f6ff29e695bc62eb35ee..7a42dffd39e59d51ba8748acf8d21d8ff4dfa29d 100644 (file)
@@ -362,4 +362,3 @@ MODULE_AUTHOR("Jan Beulich <jbeulich@novell.com>");
 MODULE_DESCRIPTION("Xen WatchDog Timer Driver");
 MODULE_VERSION(DRV_VERSION);
 MODULE_LICENSE("GPL");
-MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
index d15f6e80479f5388f52af9eba6effb9e6e769a11..188825122aae8a037bccc8255dbd43211ca6a941 100644 (file)
@@ -59,12 +59,12 @@ static int xen_add_device(struct device *dev)
                        add.flags = XEN_PCI_DEV_EXTFN;
 
 #ifdef CONFIG_ACPI
-               handle = DEVICE_ACPI_HANDLE(&pci_dev->dev);
+               handle = ACPI_HANDLE(&pci_dev->dev);
                if (!handle && pci_dev->bus->bridge)
-                       handle = DEVICE_ACPI_HANDLE(pci_dev->bus->bridge);
+                       handle = ACPI_HANDLE(pci_dev->bus->bridge);
 #ifdef CONFIG_PCI_IOV
                if (!handle && pci_dev->is_virtfn)
-                       handle = DEVICE_ACPI_HANDLE(physfn->bus->bridge);
+                       handle = ACPI_HANDLE(physfn->bus->bridge);
 #endif
                if (handle) {
                        acpi_status status;
index 2bdb4e25ee77db6c2a5c135b3c726eae734153b9..33d79a4eb92d6e623aa90e2291af39b2b2689d83 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -601,7 +601,7 @@ EXPORT_SYMBOL(bio_get_nr_vecs);
 
 static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
                          *page, unsigned int len, unsigned int offset,
-                         unsigned short max_sectors)
+                         unsigned int max_sectors)
 {
        int retried_segments = 0;
        struct bio_vec *bvec;
index 398cbd517be218bbfc155f06e1bec5e5fe71717c..f9d5094e102943db81708451a43312f6ac2e9525 100644 (file)
@@ -59,7 +59,8 @@ config BTRFS_FS_RUN_SANITY_TESTS
        help
          This will run some basic sanity tests on the free space cache
          code to make sure it is acting as it should.  These are mostly
-         regression tests and are only really interesting to btrfs devlopers.
+         regression tests and are only really interesting to btrfs
+         developers.
 
          If unsure, say N.
 
index aea4433081dcadf4a5db4e834134d8fdad64358e..f9aeb2759a646e7d3c258ce4ea3498e7c786e1ad 100644 (file)
@@ -3111,11 +3111,6 @@ static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
        ((unsigned long)(btrfs_leaf_data(leaf) + \
        btrfs_item_offset_nr(leaf, slot)))
 
-static inline struct dentry *fdentry(struct file *file)
-{
-       return file->f_path.dentry;
-}
-
 static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
 {
        return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) &&
index 1d04b5559e6187ef9c44cbbce406dc0798e1ae1d..a111622598b0b23f82c84352e6b782361e079526 100644 (file)
@@ -320,7 +320,7 @@ static int btrfs_ioctl_getversion(struct file *file, int __user *arg)
 
 static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
 {
-       struct btrfs_fs_info *fs_info = btrfs_sb(fdentry(file)->d_sb);
+       struct btrfs_fs_info *fs_info = btrfs_sb(file_inode(file)->i_sb);
        struct btrfs_device *device;
        struct request_queue *q;
        struct fstrim_range range;
@@ -368,8 +368,13 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
 
 int btrfs_is_empty_uuid(u8 *uuid)
 {
-       BUILD_BUG_ON(BTRFS_UUID_SIZE > PAGE_SIZE);
-       return !memcmp(uuid, empty_zero_page, BTRFS_UUID_SIZE);
+       int i;
+
+       for (i = 0; i < BTRFS_UUID_SIZE; i++) {
+               if (uuid[i])
+                       return 0;
+       }
+       return 1;
 }
 
 static noinline int create_subvol(struct inode *dir,
@@ -2084,7 +2089,7 @@ static noinline int btrfs_ioctl_ino_lookup(struct file *file,
 static noinline int btrfs_ioctl_snap_destroy(struct file *file,
                                             void __user *arg)
 {
-       struct dentry *parent = fdentry(file);
+       struct dentry *parent = file->f_path.dentry;
        struct dentry *dentry;
        struct inode *dir = parent->d_inode;
        struct inode *inode;
@@ -3100,7 +3105,7 @@ out:
 static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
                                       u64 off, u64 olen, u64 destoff)
 {
-       struct inode *inode = fdentry(file)->d_inode;
+       struct inode *inode = file_inode(file);
        struct btrfs_root *root = BTRFS_I(inode)->root;
        struct fd src_file;
        struct inode *src;
@@ -4299,7 +4304,7 @@ static long btrfs_ioctl_quota_rescan_status(struct file *file, void __user *arg)
 
 static long btrfs_ioctl_quota_rescan_wait(struct file *file, void __user *arg)
 {
-       struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
+       struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
index fc6f4f3a1a9d6c4c2f8b0c7afa1eb20d8029febf..4934347321d379b61aa170d0f93dd4468c383000 100644 (file)
@@ -548,7 +548,13 @@ static int
 CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
 {
        int rc;
-       unsigned int offset = CIFS_SESS_KEY_SIZE + 8;
+       struct ntlmv2_resp *ntlmv2 = (struct ntlmv2_resp *)
+           (ses->auth_key.response + CIFS_SESS_KEY_SIZE);
+       unsigned int hash_len;
+
+       /* The MD5 hash starts at challenge_key.key */
+       hash_len = ses->auth_key.len - (CIFS_SESS_KEY_SIZE +
+               offsetof(struct ntlmv2_resp, challenge.key[0]));
 
        if (!ses->server->secmech.sdeschmacmd5) {
                cifs_dbg(VFS, "%s: can't generate ntlmv2 hash\n", __func__);
@@ -556,7 +562,7 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
        }
 
        rc = crypto_shash_setkey(ses->server->secmech.hmacmd5,
-                               ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
+                                ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
        if (rc) {
                cifs_dbg(VFS, "%s: Could not set NTLMV2 Hash as a key\n",
                         __func__);
@@ -570,20 +576,21 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
        }
 
        if (ses->server->negflavor == CIFS_NEGFLAVOR_EXTENDED)
-               memcpy(ses->auth_key.response + offset,
-                       ses->ntlmssp->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
+               memcpy(ntlmv2->challenge.key,
+                      ses->ntlmssp->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
        else
-               memcpy(ses->auth_key.response + offset,
-                       ses->server->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
+               memcpy(ntlmv2->challenge.key,
+                      ses->server->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
        rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
-               ses->auth_key.response + offset, ses->auth_key.len - offset);
+                                ntlmv2->challenge.key, hash_len);
        if (rc) {
                cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
                return rc;
        }
 
+       /* Note that the MD5 digest over writes anon.challenge_key.key */
        rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
-               ses->auth_key.response + CIFS_SESS_KEY_SIZE);
+                               ntlmv2->ntlmv2_hash);
        if (rc)
                cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
 
@@ -627,7 +634,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
        int rc;
        int baselen;
        unsigned int tilen;
-       struct ntlmv2_resp *buf;
+       struct ntlmv2_resp *ntlmv2;
        char ntlmv2_hash[16];
        unsigned char *tiblob = NULL; /* target info blob */
 
@@ -660,13 +667,14 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
        }
        ses->auth_key.len += baselen;
 
-       buf = (struct ntlmv2_resp *)
+       ntlmv2 = (struct ntlmv2_resp *)
                        (ses->auth_key.response + CIFS_SESS_KEY_SIZE);
-       buf->blob_signature = cpu_to_le32(0x00000101);
-       buf->reserved = 0;
-       buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
-       get_random_bytes(&buf->client_chal, sizeof(buf->client_chal));
-       buf->reserved2 = 0;
+       ntlmv2->blob_signature = cpu_to_le32(0x00000101);
+       ntlmv2->reserved = 0;
+       /* Must be within 5 minutes of the server */
+       ntlmv2->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
+       get_random_bytes(&ntlmv2->client_chal, sizeof(ntlmv2->client_chal));
+       ntlmv2->reserved2 = 0;
 
        memcpy(ses->auth_key.response + baselen, tiblob, tilen);
 
@@ -706,7 +714,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
        }
 
        rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
-               ses->auth_key.response + CIFS_SESS_KEY_SIZE,
+               ntlmv2->ntlmv2_hash,
                CIFS_HMAC_MD5_HASH_SIZE);
        if (rc) {
                cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
index 26b1c1dc93f6ef20c8c3d23fc57db320478cc923..d9ea7ada1378f95e48b08e286e38e2d080893993 100644 (file)
@@ -261,7 +261,7 @@ struct smb_version_operations {
        /* query path data from the server */
        int (*query_path_info)(const unsigned int, struct cifs_tcon *,
                               struct cifs_sb_info *, const char *,
-                              FILE_ALL_INFO *, bool *);
+                              FILE_ALL_INFO *, bool *, bool *);
        /* query file data from the server */
        int (*query_file_info)(const unsigned int, struct cifs_tcon *,
                               struct cifs_fid *, FILE_ALL_INFO *);
@@ -381,6 +381,9 @@ struct smb_version_operations {
        char * (*create_lease_buf)(u8 *, u8);
        /* parse lease context buffer and return oplock/epoch info */
        __u8 (*parse_lease_buf)(void *, unsigned int *);
+       int (*clone_range)(const unsigned int, struct cifsFileInfo *src_file,
+                       struct cifsFileInfo *target_file, u64 src_off, u64 len,
+                       u64 dest_off);
 };
 
 struct smb_version_values {
@@ -855,6 +858,9 @@ struct cifs_tcon {
        __le64 vol_create_time;
        __u32 ss_flags;         /* sector size flags */
        __u32 perf_sector_size; /* best sector size for perf */
+       __u32 max_chunks;
+       __u32 max_bytes_chunk;
+       __u32 max_bytes_copy;
 #endif /* CONFIG_CIFS_SMB2 */
 #ifdef CONFIG_CIFS_FSCACHE
        u64 resource_id;                /* server resource id */
index 9e5ee34de98633b0d894ddadfdf86cd5bd963159..33df36ef9d52037e69857f1dc7b1c9591acb8251 100644 (file)
@@ -697,7 +697,13 @@ struct ntlmssp2_name {
 } __attribute__((packed));
 
 struct ntlmv2_resp {
-       char ntlmv2_hash[CIFS_ENCPWD_SIZE];
+       union {
+           char ntlmv2_hash[CIFS_ENCPWD_SIZE];
+           struct {
+               __u8 reserved[8];
+               __u8 key[CIFS_SERVER_CHALLENGE_SIZE];
+           } __attribute__((packed)) challenge;
+       } __attribute__((packed));
        __le32 blob_signature;
        __u32  reserved;
        __le64  time;
index 93b29474714a0cdba1356c85c049e874dbc195dd..124aa0230c1b8738edb8d04ca5d764f0a6cc5b12 100644 (file)
@@ -3369,11 +3369,13 @@ static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL,
                return 0;
        }
        cifs_acl->version = cpu_to_le16(1);
-       if (acl_type == ACL_TYPE_ACCESS)
+       if (acl_type == ACL_TYPE_ACCESS) {
                cifs_acl->access_entry_count = cpu_to_le16(count);
-       else if (acl_type == ACL_TYPE_DEFAULT)
+               cifs_acl->default_entry_count = __constant_cpu_to_le16(0xFFFF);
+       } else if (acl_type == ACL_TYPE_DEFAULT) {
                cifs_acl->default_entry_count = cpu_to_le16(count);
-       else {
+               cifs_acl->access_entry_count = __constant_cpu_to_le16(0xFFFF);
+       } else {
                cifs_dbg(FYI, "unknown ACL type %d\n", acl_type);
                return 0;
        }
index 5384c2a640ca6fc06962a01261ca4f8ce890b246..11ff5f116b20e663bf5e0428a940b437d9b232aa 100644 (file)
@@ -756,7 +756,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
        /*      if it was once a directory (but how can we tell?) we could do
                shrink_dcache_parent(direntry); */
        } else if (rc != -EACCES) {
-               cifs_dbg(VFS, "Unexpected lookup error %d\n", rc);
+               cifs_dbg(FYI, "Unexpected lookup error %d\n", rc);
                /* We special case check for Access Denied - since that
                is a common return code */
        }
index 7ddddf2e25046af5fceb6fcbe097e2b14750710c..5a5a87240fe2cfa971a17f7b673d06f9b2326e5f 100644 (file)
@@ -3663,6 +3663,27 @@ void cifs_oplock_break(struct work_struct *work)
        }
 }
 
+/*
+ * The presence of cifs_direct_io() in the address space ops vector
+ * allowes open() O_DIRECT flags which would have failed otherwise.
+ *
+ * In the non-cached mode (mount with cache=none), we shunt off direct read and write requests
+ * so this method should never be called.
+ *
+ * Direct IO is not yet supported in the cached mode. 
+ */
+static ssize_t
+cifs_direct_io(int rw, struct kiocb *iocb, const struct iovec *iov,
+               loff_t pos, unsigned long nr_segs)
+{
+        /*
+         * FIXME
+         * Eventually need to support direct IO for non forcedirectio mounts
+         */
+        return -EINVAL;
+}
+
+
 const struct address_space_operations cifs_addr_ops = {
        .readpage = cifs_readpage,
        .readpages = cifs_readpages,
@@ -3672,6 +3693,7 @@ const struct address_space_operations cifs_addr_ops = {
        .write_end = cifs_write_end,
        .set_page_dirty = __set_page_dirty_nobuffers,
        .releasepage = cifs_release_page,
+       .direct_IO = cifs_direct_io,
        .invalidatepage = cifs_invalidate_page,
        .launder_page = cifs_launder_page,
 };
index 867b7cdc794a221a6eb21257d20bdc3f9e516248..36f9ebb93ceba676c363cdf7b973f3936a9dde8f 100644 (file)
@@ -542,7 +542,8 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
 /* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
 static void
 cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
-                      struct cifs_sb_info *cifs_sb, bool adjust_tz)
+                      struct cifs_sb_info *cifs_sb, bool adjust_tz,
+                      bool symlink)
 {
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 
@@ -569,7 +570,11 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
        fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 
        fattr->cf_nlink = le32_to_cpu(info->NumberOfLinks);
-       if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
+
+       if (symlink) {
+               fattr->cf_mode = S_IFLNK;
+               fattr->cf_dtype = DT_LNK;
+       } else if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
                fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
                fattr->cf_dtype = DT_DIR;
                /*
@@ -578,10 +583,6 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
                 */
                if (!tcon->unix_ext)
                        fattr->cf_flags |= CIFS_FATTR_UNKNOWN_NLINK;
-       } else if (fattr->cf_cifsattrs & ATTR_REPARSE) {
-               fattr->cf_mode = S_IFLNK;
-               fattr->cf_dtype = DT_LNK;
-               fattr->cf_nlink = le32_to_cpu(info->NumberOfLinks);
        } else {
                fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
                fattr->cf_dtype = DT_REG;
@@ -626,7 +627,8 @@ cifs_get_file_info(struct file *filp)
        rc = server->ops->query_file_info(xid, tcon, &cfile->fid, &find_data);
        switch (rc) {
        case 0:
-               cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false);
+               cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false,
+                                      false);
                break;
        case -EREMOTE:
                cifs_create_dfs_fattr(&fattr, inode->i_sb);
@@ -673,6 +675,7 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
        bool adjust_tz = false;
        struct cifs_fattr fattr;
        struct cifs_search_info *srchinf = NULL;
+       bool symlink = false;
 
        tlink = cifs_sb_tlink(cifs_sb);
        if (IS_ERR(tlink))
@@ -702,12 +705,12 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
                }
                data = (FILE_ALL_INFO *)buf;
                rc = server->ops->query_path_info(xid, tcon, cifs_sb, full_path,
-                                                 data, &adjust_tz);
+                                                 data, &adjust_tz, &symlink);
        }
 
        if (!rc) {
-               cifs_all_info_to_fattr(&fattr, (FILE_ALL_INFO *)data, cifs_sb,
-                                      adjust_tz);
+               cifs_all_info_to_fattr(&fattr, data, cifs_sb, adjust_tz,
+                                      symlink);
        } else if (rc == -EREMOTE) {
                cifs_create_dfs_fattr(&fattr, sb);
                rc = 0;
index ba54bf6ab1165d6db4b587a898554dd8dc388d2d..409b45eefe7086899ae4da636b96cd8c07794dd5 100644 (file)
  */
 
 #include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/mount.h>
+#include <linux/mm.h>
+#include <linux/pagemap.h>
+#include <linux/btrfs.h>
 #include "cifspdu.h"
 #include "cifsglob.h"
 #include "cifsproto.h"
 #include "cifs_debug.h"
 #include "cifsfs.h"
 
+static long cifs_ioctl_clone(unsigned int xid, struct file *dst_file,
+                       unsigned long srcfd, u64 off, u64 len, u64 destoff)
+{
+       int rc;
+       struct cifsFileInfo *smb_file_target = dst_file->private_data;
+       struct inode *target_inode = file_inode(dst_file);
+       struct cifs_tcon *target_tcon;
+       struct fd src_file;
+       struct cifsFileInfo *smb_file_src;
+       struct inode *src_inode;
+       struct cifs_tcon *src_tcon;
+
+       cifs_dbg(FYI, "ioctl clone range\n");
+       /* the destination must be opened for writing */
+       if (!(dst_file->f_mode & FMODE_WRITE)) {
+               cifs_dbg(FYI, "file target not open for write\n");
+               return -EINVAL;
+       }
+
+       /* check if target volume is readonly and take reference */
+       rc = mnt_want_write_file(dst_file);
+       if (rc) {
+               cifs_dbg(FYI, "mnt_want_write failed with rc %d\n", rc);
+               return rc;
+       }
+
+       src_file = fdget(srcfd);
+       if (!src_file.file) {
+               rc = -EBADF;
+               goto out_drop_write;
+       }
+
+       if ((!src_file.file->private_data) || (!dst_file->private_data)) {
+               rc = -EBADF;
+               cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
+               goto out_fput;
+       }
+
+       rc = -EXDEV;
+       smb_file_target = dst_file->private_data;
+       smb_file_src = src_file.file->private_data;
+       src_tcon = tlink_tcon(smb_file_src->tlink);
+       target_tcon = tlink_tcon(smb_file_target->tlink);
+
+       /* check if source and target are on same tree connection */
+       if (src_tcon != target_tcon) {
+               cifs_dbg(VFS, "file copy src and target on different volume\n");
+               goto out_fput;
+       }
+
+       src_inode = src_file.file->f_dentry->d_inode;
+
+       /*
+        * Note: cifs case is easier than btrfs since server responsible for
+        * checks for proper open modes and file type and if it wants
+        * server could even support copy of range where source = target
+        */
+
+       /* so we do not deadlock racing two ioctls on same files */
+       if (target_inode < src_inode) {
+               mutex_lock_nested(&target_inode->i_mutex, I_MUTEX_PARENT);
+               mutex_lock_nested(&src_inode->i_mutex, I_MUTEX_CHILD);
+       } else {
+               mutex_lock_nested(&src_inode->i_mutex, I_MUTEX_PARENT);
+               mutex_lock_nested(&target_inode->i_mutex, I_MUTEX_CHILD);
+       }
+
+       /* determine range to clone */
+       rc = -EINVAL;
+       if (off + len > src_inode->i_size || off + len < off)
+               goto out_unlock;
+       if (len == 0)
+               len = src_inode->i_size - off;
+
+       cifs_dbg(FYI, "about to flush pages\n");
+       /* should we flush first and last page first */
+       truncate_inode_pages_range(&target_inode->i_data, destoff,
+                                  PAGE_CACHE_ALIGN(destoff + len)-1);
+
+       if (target_tcon->ses->server->ops->clone_range)
+               rc = target_tcon->ses->server->ops->clone_range(xid,
+                       smb_file_src, smb_file_target, off, len, destoff);
+
+       /* force revalidate of size and timestamps of target file now
+          that target is updated on the server */
+       CIFS_I(target_inode)->time = 0;
+out_unlock:
+       /* although unlocking in the reverse order from locking is not
+          strictly necessary here it is a little cleaner to be consistent */
+       if (target_inode < src_inode) {
+               mutex_unlock(&src_inode->i_mutex);
+               mutex_unlock(&target_inode->i_mutex);
+       } else {
+               mutex_unlock(&target_inode->i_mutex);
+               mutex_unlock(&src_inode->i_mutex);
+       }
+out_fput:
+       fdput(src_file);
+out_drop_write:
+       mnt_drop_write_file(dst_file);
+       return rc;
+}
+
 long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
 {
        struct inode *inode = file_inode(filep);
@@ -105,6 +213,9 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
                                cifs_dbg(FYI, "set compress flag rc %d\n", rc);
                        }
                        break;
+               case BTRFS_IOC_CLONE:
+                       rc = cifs_ioctl_clone(xid, filep, arg, 0, 0, 0);
+                       break;
                default:
                        cifs_dbg(FYI, "unsupported ioctl\n");
                        break;
index 651a5279607b968a255a528e5411e4f4b39ca438..049884552e76385091513111576bdf11703945aa 100644 (file)
@@ -51,7 +51,7 @@ static const struct smb_to_posix_error mapping_table_ERRDOS[] = {
        {ERRnoaccess, -EACCES},
        {ERRbadfid, -EBADF},
        {ERRbadmcb, -EIO},
-       {ERRnomem, -ENOMEM},
+       {ERRnomem, -EREMOTEIO},
        {ERRbadmem, -EFAULT},
        {ERRbadenv, -EFAULT},
        {ERRbadformat, -EINVAL},
index 53a75f3d0179231d395611f61f2897c9a52f33de..5940ecabbe6a4f538f7dc91c334ed3017235e4dd 100644 (file)
@@ -134,22 +134,6 @@ out:
        dput(dentry);
 }
 
-/*
- * Is it possible that this directory might turn out to be a DFS referral
- * once we go to try and use it?
- */
-static bool
-cifs_dfs_is_possible(struct cifs_sb_info *cifs_sb)
-{
-#ifdef CONFIG_CIFS_DFS_UPCALL
-       struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-
-       if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
-               return true;
-#endif
-       return false;
-}
-
 static void
 cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)
 {
@@ -159,27 +143,19 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)
        if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
                fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
                fattr->cf_dtype = DT_DIR;
-               /*
-                * Windows CIFS servers generally make DFS referrals look
-                * like directories in FIND_* responses with the reparse
-                * attribute flag also set (since DFS junctions are
-                * reparse points). We must revalidate at least these
-                * directory inodes before trying to use them (if
-                * they are DFS we will get PATH_NOT_COVERED back
-                * when queried directly and can then try to connect
-                * to the DFS target)
-                */
-               if (cifs_dfs_is_possible(cifs_sb) &&
-                   (fattr->cf_cifsattrs & ATTR_REPARSE))
-                       fattr->cf_flags |= CIFS_FATTR_NEED_REVAL;
-       } else if (fattr->cf_cifsattrs & ATTR_REPARSE) {
-               fattr->cf_mode = S_IFLNK;
-               fattr->cf_dtype = DT_LNK;
        } else {
                fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
                fattr->cf_dtype = DT_REG;
        }
 
+       /*
+        * We need to revalidate it further to make a decision about whether it
+        * is a symbolic link, DFS referral or a reparse point with a direct
+        * access like junctions, deduplicated files, NFS symlinks.
+        */
+       if (fattr->cf_cifsattrs & ATTR_REPARSE)
+               fattr->cf_flags |= CIFS_FATTR_NEED_REVAL;
+
        /* non-unix readdir doesn't provide nlink */
        fattr->cf_flags |= CIFS_FATTR_UNKNOWN_NLINK;
 
index 384cffe42850cdbdb4365e0ff6d6e8eb1a1fbb87..5f5ba0dc2ee1b9c7b3d26ede9590a185ac6925e0 100644 (file)
@@ -534,10 +534,12 @@ cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
 static int
 cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
                     struct cifs_sb_info *cifs_sb, const char *full_path,
-                    FILE_ALL_INFO *data, bool *adjustTZ)
+                    FILE_ALL_INFO *data, bool *adjustTZ, bool *symlink)
 {
        int rc;
 
+       *symlink = false;
+
        /* could do find first instead but this returns more info */
        rc = CIFSSMBQPathInfo(xid, tcon, full_path, data, 0 /* not legacy */,
                              cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
@@ -554,6 +556,23 @@ cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
                *adjustTZ = true;
        }
+
+       if (!rc && (le32_to_cpu(data->Attributes) & ATTR_REPARSE)) {
+               int tmprc;
+               int oplock = 0;
+               __u16 netfid;
+
+               /* Need to check if this is a symbolic link or not */
+               tmprc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN,
+                                   FILE_READ_ATTRIBUTES, 0, &netfid, &oplock,
+                                   NULL, cifs_sb->local_nls,
+                       cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
+               if (tmprc == -EOPNOTSUPP)
+                       *symlink = true;
+               else
+                       CIFSSMBClose(xid, tcon, netfid);
+       }
+
        return rc;
 }
 
index 78ff88c467b99b9a17c706032a9ed655f92c58b0..84c012a6aba01fc9a7fcd82ab3548047da63d55b 100644 (file)
@@ -123,12 +123,13 @@ move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src)
 int
 smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
                     struct cifs_sb_info *cifs_sb, const char *full_path,
-                    FILE_ALL_INFO *data, bool *adjust_tz)
+                    FILE_ALL_INFO *data, bool *adjust_tz, bool *symlink)
 {
        int rc;
        struct smb2_file_all_info *smb2_data;
 
        *adjust_tz = false;
+       *symlink = false;
 
        smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
                            GFP_KERNEL);
@@ -136,9 +137,16 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
                return -ENOMEM;
 
        rc = smb2_open_op_close(xid, tcon, cifs_sb, full_path,
-                               FILE_READ_ATTRIBUTES, FILE_OPEN,
-                               OPEN_REPARSE_POINT, smb2_data,
-                               SMB2_OP_QUERY_INFO);
+                               FILE_READ_ATTRIBUTES, FILE_OPEN, 0,
+                               smb2_data, SMB2_OP_QUERY_INFO);
+       if (rc == -EOPNOTSUPP) {
+               *symlink = true;
+               /* Failed on a symbolic link - query a reparse point info */
+               rc = smb2_open_op_close(xid, tcon, cifs_sb, full_path,
+                                       FILE_READ_ATTRIBUTES, FILE_OPEN,
+                                       OPEN_REPARSE_POINT, smb2_data,
+                                       SMB2_OP_QUERY_INFO);
+       }
        if (rc)
                goto out;
 
index 7c2f45c06fc219357fa15d5b46f8aa8ac5449aba..94bd4fbb13d3d28283ec4d705086d784d0f70eaf 100644 (file)
@@ -306,7 +306,7 @@ static const struct status_to_posix_error smb2_error_map_table[] = {
        {STATUS_NONEXISTENT_SECTOR, -EIO, "STATUS_NONEXISTENT_SECTOR"},
        {STATUS_MORE_PROCESSING_REQUIRED, -EIO,
        "STATUS_MORE_PROCESSING_REQUIRED"},
-       {STATUS_NO_MEMORY, -ENOMEM, "STATUS_NO_MEMORY"},
+       {STATUS_NO_MEMORY, -EREMOTEIO, "STATUS_NO_MEMORY"},
        {STATUS_CONFLICTING_ADDRESSES, -EADDRINUSE,
        "STATUS_CONFLICTING_ADDRESSES"},
        {STATUS_NOT_MAPPED_VIEW, -EIO, "STATUS_NOT_MAPPED_VIEW"},
index c571be8cb76ef418ffcca63634fde5e3d39294f5..11dde4b24f8aa1dce05354cef65fa93feb82735f 100644 (file)
@@ -493,6 +493,85 @@ smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
        SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
 }
 
+static int
+SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
+                    u64 persistent_fid, u64 volatile_fid,
+                    struct copychunk_ioctl *pcchunk)
+{
+       int rc;
+       unsigned int ret_data_len;
+       struct resume_key_req *res_key;
+
+       rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
+                       FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
+                       NULL, 0 /* no input */,
+                       (char **)&res_key, &ret_data_len);
+
+       if (rc) {
+               cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
+               goto req_res_key_exit;
+       }
+       if (ret_data_len < sizeof(struct resume_key_req)) {
+               cifs_dbg(VFS, "Invalid refcopy resume key length\n");
+               rc = -EINVAL;
+               goto req_res_key_exit;
+       }
+       memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
+
+req_res_key_exit:
+       kfree(res_key);
+       return rc;
+}
+
+static int
+smb2_clone_range(const unsigned int xid,
+                       struct cifsFileInfo *srcfile,
+                       struct cifsFileInfo *trgtfile, u64 src_off,
+                       u64 len, u64 dest_off)
+{
+       int rc;
+       unsigned int ret_data_len;
+       struct copychunk_ioctl *pcchunk;
+       char *retbuf = NULL;
+
+       pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
+
+       if (pcchunk == NULL)
+               return -ENOMEM;
+
+       cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
+       /* Request a key from the server to identify the source of the copy */
+       rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
+                               srcfile->fid.persistent_fid,
+                               srcfile->fid.volatile_fid, pcchunk);
+
+       /* Note: request_res_key sets res_key null only if rc !=0 */
+       if (rc)
+               return rc;
+
+       /* For now array only one chunk long, will make more flexible later */
+       pcchunk->ChunkCount = __constant_cpu_to_le32(1);
+       pcchunk->Reserved = 0;
+       pcchunk->SourceOffset = cpu_to_le64(src_off);
+       pcchunk->TargetOffset = cpu_to_le64(dest_off);
+       pcchunk->Length = cpu_to_le32(len);
+       pcchunk->Reserved2 = 0;
+
+       /* Request that server copy to target from src file identified by key */
+       rc = SMB2_ioctl(xid, tlink_tcon(trgtfile->tlink),
+                       trgtfile->fid.persistent_fid,
+                       trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
+                       true /* is_fsctl */, (char *)pcchunk,
+                       sizeof(struct copychunk_ioctl), &retbuf, &ret_data_len);
+
+       /* BB need to special case rc = EINVAL to alter chunk size */
+
+       cifs_dbg(FYI, "rc %d data length out %d\n", rc, ret_data_len);
+
+       kfree(pcchunk);
+       return rc;
+}
+
 static int
 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
                struct cifs_fid *fid)
@@ -1017,6 +1096,7 @@ struct smb_version_operations smb20_operations = {
        .set_oplock_level = smb2_set_oplock_level,
        .create_lease_buf = smb2_create_lease_buf,
        .parse_lease_buf = smb2_parse_lease_buf,
+       .clone_range = smb2_clone_range,
 };
 
 struct smb_version_operations smb21_operations = {
@@ -1090,6 +1170,7 @@ struct smb_version_operations smb21_operations = {
        .set_oplock_level = smb21_set_oplock_level,
        .create_lease_buf = smb2_create_lease_buf,
        .parse_lease_buf = smb2_parse_lease_buf,
+       .clone_range = smb2_clone_range,
 };
 
 struct smb_version_operations smb30_operations = {
@@ -1165,6 +1246,7 @@ struct smb_version_operations smb30_operations = {
        .set_oplock_level = smb3_set_oplock_level,
        .create_lease_buf = smb3_create_lease_buf,
        .parse_lease_buf = smb3_parse_lease_buf,
+       .clone_range = smb2_clone_range,
 };
 
 struct smb_version_values smb20_values = {
index 8ab05b0d6778f99343d5740ff037ccbfad7bbef8..d65270c290a1b488157e14b316b7de59fe9bac54 100644 (file)
@@ -630,6 +630,8 @@ ssetup_ntlmssp_authenticate:
                goto ssetup_exit;
 
        ses->session_flags = le16_to_cpu(rsp->SessionFlags);
+       if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
+               cifs_dbg(VFS, "SMB3 encryption not supported yet\n");
 ssetup_exit:
        free_rsp_buf(resp_buftype, rsp);
 
@@ -717,6 +719,14 @@ static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code)
 
 #define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */)
 
+/* These are similar values to what Windows uses */
+static inline void init_copy_chunk_defaults(struct cifs_tcon *tcon)
+{
+       tcon->max_chunks = 256;
+       tcon->max_bytes_chunk = 1048576;
+       tcon->max_bytes_copy = 16777216;
+}
+
 int
 SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
          struct cifs_tcon *tcon, const struct nls_table *cp)
@@ -818,7 +828,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
        if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
            ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
                cifs_dbg(VFS, "DFS capability contradicts DFS flag\n");
-
+       init_copy_chunk_defaults(tcon);
 tcon_exit:
        free_rsp_buf(resp_buftype, rsp);
        kfree(unc_path);
index 6183b1b7550f068a7f0628e7dab6e701e9ad0d2f..f88320bbb47772923fe81f89b1a2352d783b89c0 100644 (file)
@@ -122,6 +122,23 @@ struct smb2_pdu {
        __le16 StructureSize2; /* size of wct area (varies, request specific) */
 } __packed;
 
+struct smb2_transform_hdr {
+       __be32 smb2_buf_length; /* big endian on wire */
+                               /* length is only two or three bytes - with
+                                one or two byte type preceding it that MBZ */
+       __u8   ProtocolId[4];   /* 0xFD 'S' 'M' 'B' */
+       __u8   Signature[16];
+       __u8   Nonce[11];
+       __u8   Reserved[5];
+       __le32 OriginalMessageSize;
+       __u16  Reserved1;
+       __le16 EncryptionAlgorithm;
+       __u64  SessionId;
+} __packed;
+
+/* Encryption Algorithms */
+#define SMB2_ENCRYPTION_AES128_CCM     __constant_cpu_to_le16(0x0001)
+
 /*
  *     SMB2 flag definitions
  */
@@ -237,6 +254,7 @@ struct smb2_sess_setup_req {
 /* Currently defined SessionFlags */
 #define SMB2_SESSION_FLAG_IS_GUEST     0x0001
 #define SMB2_SESSION_FLAG_IS_NULL      0x0002
+#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
 struct smb2_sess_setup_rsp {
        struct smb2_hdr hdr;
        __le16 StructureSize; /* Must be 9 */
@@ -534,9 +552,16 @@ struct create_durable {
        } Data;
 } __packed;
 
+#define COPY_CHUNK_RES_KEY_SIZE        24
+struct resume_key_req {
+       char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
+       __le32  ContextLength;  /* MBZ */
+       char    Context[0];     /* ignored, Windows sets to 4 bytes of zero */
+} __packed;
+
 /* this goes in the ioctl buffer when doing a copychunk request */
 struct copychunk_ioctl {
-       char SourceKey[24];
+       char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
        __le32 ChunkCount; /* we are only sending 1 */
        __le32 Reserved;
        /* array will only be one chunk long for us */
@@ -546,6 +571,12 @@ struct copychunk_ioctl {
        __u32 Reserved2;
 } __packed;
 
+struct copychunk_ioctl_rsp {
+       __le32 ChunksWritten;
+       __le32 ChunkBytesWritten;
+       __le32 TotalBytesWritten;
+} __packed;
+
 /* Response and Request are the same format */
 struct validate_negotiate_info {
        __le32 Capabilities;
index 313813e4c19b300357bfc5f6db225a3be85d1121..b4eea105b08cf96b22444d19181ee500a437787f 100644 (file)
@@ -61,7 +61,7 @@ extern void move_smb2_info_to_cifs(FILE_ALL_INFO *dst,
 extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
                                struct cifs_sb_info *cifs_sb,
                                const char *full_path, FILE_ALL_INFO *data,
-                               bool *adjust_tz);
+                               bool *adjust_tz, bool *symlink);
 extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
                              const char *full_path, __u64 size,
                              struct cifs_sb_info *cifs_sb, bool set_alloc);
index 60a327863b1122e246b79bf91ecdf23136eccac9..e7cfbaf8d0e2ed66b404c259dcd64c2d4ccd5f54 100644 (file)
@@ -74,14 +74,16 @@ static int user_cmd(struct sk_buff *skb, struct genl_info *info)
        return 0;
 }
 
-static struct genl_ops dlm_nl_ops = {
-       .cmd            = DLM_CMD_HELLO,
-       .doit           = user_cmd,
+static struct genl_ops dlm_nl_ops[] = {
+       {
+               .cmd    = DLM_CMD_HELLO,
+               .doit   = user_cmd,
+       },
 };
 
 int __init dlm_netlink_init(void)
 {
-       return genl_register_family_with_ops(&family, &dlm_nl_ops, 1);
+       return genl_register_family_with_ops(&family, dlm_nl_ops);
 }
 
 void dlm_netlink_exit(void)
index 38c1768b4142e6508a6805aaa1ff1067f8770381..3dece03f2fc8a4031db1bca96b9a8365bafd0312 100644 (file)
@@ -116,17 +116,17 @@ config NFS_V4_2
 config PNFS_FILE_LAYOUT
        tristate
        depends on NFS_V4_1
-       default m
+       default NFS_V4
 
 config PNFS_BLOCK
        tristate
        depends on NFS_V4_1 && BLK_DEV_DM
-       default m
+       default NFS_V4
 
 config PNFS_OBJLAYOUT
        tristate
        depends on NFS_V4_1 && SCSI_OSD_ULD
-       default m
+       default NFS_V4
 
 config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
        string "NFSv4.1 Implementation ID Domain"
index 74a7e12e10df472ee1752af9726220ee12ca4ac9..059c01b67a7164a6d782139fb7b66b0d3976ad21 100644 (file)
@@ -2093,10 +2093,15 @@ again:
                        nfs4_root_machine_cred(clp);
                        goto again;
                }
-               if (i > 2)
+               if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX)
                        break;
        case -NFS4ERR_CLID_INUSE:
        case -NFS4ERR_WRONGSEC:
+               /* No point in retrying if we already used RPC_AUTH_UNIX */
+               if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX) {
+                       status = -EPERM;
+                       break;
+               }
                clnt = rpc_clone_client_set_auth(clnt, RPC_AUTH_UNIX);
                if (IS_ERR(clnt)) {
                        status = PTR_ERR(clnt);
index 317d6fc2160ebe787714e0f0ac6cb5288b0527b7..910ed906eb82f0465eb9317f8c8d4c7640bc7e17 100644 (file)
@@ -1614,7 +1614,7 @@ static int nfs_parse_mount_options(char *raw,
                goto out_minorversion_mismatch;
 
        if (mnt->options & NFS_OPTION_MIGRATION &&
-           mnt->version != 4 && mnt->minorversion != 0)
+           (mnt->version != 4 || mnt->minorversion != 0))
                goto out_migration_misuse;
 
        /*
index dc8f1ef665ce6830db7cbf43b327a5fe198fbe37..f994e750e0d1db9ebe53e7f51883bfa5c039afc4 100644 (file)
@@ -95,7 +95,7 @@ config NFSD_V4_SECURITY_LABEL
        Smack policies on NFSv4 files, say N.
 
        WARNING: there is still a chance of backwards-incompatible protocol changes.
-       For now we recommend "Y" only for developers and testers."
+       For now we recommend "Y" only for developers and testers.
 
 config NFSD_FAULT_INJECTION
        bool "NFS server manual fault injection"
index 5f38ea36e266751f700b806bd4b4dfb7c6ed0dcd..8513c598fabfbb7cc83e32357d4ff0f6ba8e087d 100644 (file)
@@ -536,16 +536,12 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
                if (err)
                        goto out3;
                exp.ex_anon_uid= make_kuid(&init_user_ns, an_int);
-               if (!uid_valid(exp.ex_anon_uid))
-                       goto out3;
 
                /* anon gid */
                err = get_int(&mesg, &an_int);
                if (err)
                        goto out3;
                exp.ex_anon_gid= make_kgid(&init_user_ns, an_int);
-               if (!gid_valid(exp.ex_anon_gid))
-                       goto out3;
 
                /* fsid */
                err = get_int(&mesg, &an_int);
@@ -583,6 +579,26 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
                                   exp.ex_uuid);
                if (err)
                        goto out4;
+               /*
+                * No point caching this if it would immediately expire.
+                * Also, this protects exportfs's dummy export from the
+                * anon_uid/anon_gid checks:
+                */
+               if (exp.h.expiry_time < seconds_since_boot())
+                       goto out4;
+               /*
+                * For some reason exportfs has been passing down an
+                * invalid (-1) uid & gid on the "dummy" export which it
+                * uses to test export support.  To make sure exportfs
+                * sees errors from check_export we therefore need to
+                * delay these checks till after check_export:
+                */
+               err = -EINVAL;
+               if (!uid_valid(exp.ex_anon_uid))
+                       goto out4;
+               if (!gid_valid(exp.ex_anon_gid))
+                       goto out4;
+               err = 0;
        }
 
        expp = svc_export_lookup(&exp);
index f36a30a9f2d15c5d3500002e87b4afa3e80d951a..105d6fa7c5149ab496cf614763a4c3145f52c74e 100644 (file)
@@ -402,11 +402,16 @@ static void remove_stid(struct nfs4_stid *s)
        idr_remove(stateids, s->sc_stateid.si_opaque.so_id);
 }
 
+static void nfs4_free_stid(struct kmem_cache *slab, struct nfs4_stid *s)
+{
+       kmem_cache_free(slab, s);
+}
+
 void
 nfs4_put_delegation(struct nfs4_delegation *dp)
 {
        if (atomic_dec_and_test(&dp->dl_count)) {
-               kmem_cache_free(deleg_slab, dp);
+               nfs4_free_stid(deleg_slab, &dp->dl_stid);
                num_delegations--;
        }
 }
@@ -610,7 +615,7 @@ static void close_generic_stateid(struct nfs4_ol_stateid *stp)
 static void free_generic_stateid(struct nfs4_ol_stateid *stp)
 {
        remove_stid(&stp->st_stid);
-       kmem_cache_free(stateid_slab, stp);
+       nfs4_free_stid(stateid_slab, &stp->st_stid);
 }
 
 static void release_lock_stateid(struct nfs4_ol_stateid *stp)
@@ -668,7 +673,6 @@ static void unhash_open_stateid(struct nfs4_ol_stateid *stp)
 static void release_open_stateid(struct nfs4_ol_stateid *stp)
 {
        unhash_open_stateid(stp);
-       unhash_stid(&stp->st_stid);
        free_generic_stateid(stp);
 }
 
@@ -690,7 +694,6 @@ static void release_last_closed_stateid(struct nfs4_openowner *oo)
        struct nfs4_ol_stateid *s = oo->oo_last_closed_stid;
 
        if (s) {
-               unhash_stid(&s->st_stid);
                free_generic_stateid(s);
                oo->oo_last_closed_stid = NULL;
        }
@@ -1127,6 +1130,11 @@ destroy_client(struct nfs4_client *clp)
                dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru);
                destroy_delegation(dp);
        }
+       list_splice_init(&clp->cl_revoked, &reaplist);
+       while (!list_empty(&reaplist)) {
+               dp = list_entry(reaplist.next, struct nfs4_delegation, dl_recall_lru);
+               destroy_revoked_delegation(dp);
+       }
        while (!list_empty(&clp->cl_openowners)) {
                oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient);
                release_openowner(oo);
@@ -3154,7 +3162,7 @@ nfs4_open_delegation(struct net *net, struct svc_fh *fh,
        open->op_delegate_type = NFS4_OPEN_DELEGATE_READ;
        return;
 out_free:
-       unhash_stid(&dp->dl_stid);
+       remove_stid(&dp->dl_stid);
        nfs4_put_delegation(dp);
 out_no_deleg:
        open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE;
@@ -3995,10 +4003,9 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        nfsd4_close_open_stateid(stp);
 
-       if (cstate->minorversion) {
-               unhash_stid(&stp->st_stid);
+       if (cstate->minorversion)
                free_generic_stateid(stp);
-       else
+       else
                oo->oo_last_closed_stid = stp;
 
        if (list_empty(&oo->oo_owner.so_stateids)) {
@@ -5119,7 +5126,6 @@ out_recovery:
        return ret;
 }
 
-/* should be called with the state lock held */
 void
 nfs4_state_shutdown_net(struct net *net)
 {
@@ -5130,6 +5136,7 @@ nfs4_state_shutdown_net(struct net *net)
        cancel_delayed_work_sync(&nn->laundromat_work);
        locks_end_grace(&nn->nfsd4_manager);
 
+       nfs4_lock_state();
        INIT_LIST_HEAD(&reaplist);
        spin_lock(&recall_lock);
        list_for_each_safe(pos, next, &nn->del_recall_lru) {
@@ -5144,6 +5151,7 @@ nfs4_state_shutdown_net(struct net *net)
 
        nfsd4_client_tracking_exit(net);
        nfs4_state_destroy_net(net);
+       nfs4_unlock_state();
 }
 
 void
index d9454fe5653f70af2175432d22e36cebcbaef5be..088de1355e930c05fd9dd9c03bb3710b7531fed7 100644 (file)
@@ -411,6 +411,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
                label->data = kzalloc(dummy32 + 1, GFP_KERNEL);
                if (!label->data)
                        return nfserr_jukebox;
+               label->len = dummy32;
                defer_free(argp, kfree, label->data);
                memcpy(label->data, buf, dummy32);
        }
@@ -945,13 +946,16 @@ static __be32
 nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
 {
        DECODE_HEAD;
-                   
+
+       if (argp->minorversion >= 1)
+               return nfserr_notsupp;
+
        status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
        if (status)
                return status;
        READ_BUF(4);
        READ32(open_conf->oc_seqid);
-                                                       
+
        DECODE_TAIL;
 }
 
@@ -990,6 +994,14 @@ nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
        DECODE_TAIL;
 }
 
+static __be32
+nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p)
+{
+       if (argp->minorversion == 0)
+               return nfs_ok;
+       return nfserr_notsupp;
+}
+
 static __be32
 nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
 {
@@ -1061,6 +1073,9 @@ nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
 {
        DECODE_HEAD;
 
+       if (argp->minorversion >= 1)
+               return nfserr_notsupp;
+
        READ_BUF(sizeof(clientid_t));
        COPYMEM(clientid, sizeof(clientid_t));
 
@@ -1111,6 +1126,9 @@ nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclient
 {
        DECODE_HEAD;
 
+       if (argp->minorversion >= 1)
+               return nfserr_notsupp;
+
        READ_BUF(NFS4_VERIFIER_SIZE);
        COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE);
 
@@ -1137,6 +1155,9 @@ nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_s
 {
        DECODE_HEAD;
 
+       if (argp->minorversion >= 1)
+               return nfserr_notsupp;
+
        READ_BUF(8 + NFS4_VERIFIER_SIZE);
        COPYMEM(&scd_c->sc_clientid, 8);
        COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE);
@@ -1220,6 +1241,9 @@ nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_rel
 {
        DECODE_HEAD;
 
+       if (argp->minorversion >= 1)
+               return nfserr_notsupp;
+
        READ_BUF(12);
        COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
        READ32(rlockowner->rl_owner.len);
@@ -1519,7 +1543,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
        [OP_OPEN_CONFIRM]       = (nfsd4_dec)nfsd4_decode_open_confirm,
        [OP_OPEN_DOWNGRADE]     = (nfsd4_dec)nfsd4_decode_open_downgrade,
        [OP_PUTFH]              = (nfsd4_dec)nfsd4_decode_putfh,
-       [OP_PUTPUBFH]           = (nfsd4_dec)nfsd4_decode_noop,
+       [OP_PUTPUBFH]           = (nfsd4_dec)nfsd4_decode_putpubfh,
        [OP_PUTROOTFH]          = (nfsd4_dec)nfsd4_decode_noop,
        [OP_READ]               = (nfsd4_dec)nfsd4_decode_read,
        [OP_READDIR]            = (nfsd4_dec)nfsd4_decode_readdir,
@@ -1536,46 +1560,6 @@ static nfsd4_dec nfsd4_dec_ops[] = {
        [OP_VERIFY]             = (nfsd4_dec)nfsd4_decode_verify,
        [OP_WRITE]              = (nfsd4_dec)nfsd4_decode_write,
        [OP_RELEASE_LOCKOWNER]  = (nfsd4_dec)nfsd4_decode_release_lockowner,
-};
-
-static nfsd4_dec nfsd41_dec_ops[] = {
-       [OP_ACCESS]             = (nfsd4_dec)nfsd4_decode_access,
-       [OP_CLOSE]              = (nfsd4_dec)nfsd4_decode_close,
-       [OP_COMMIT]             = (nfsd4_dec)nfsd4_decode_commit,
-       [OP_CREATE]             = (nfsd4_dec)nfsd4_decode_create,
-       [OP_DELEGPURGE]         = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_DELEGRETURN]        = (nfsd4_dec)nfsd4_decode_delegreturn,
-       [OP_GETATTR]            = (nfsd4_dec)nfsd4_decode_getattr,
-       [OP_GETFH]              = (nfsd4_dec)nfsd4_decode_noop,
-       [OP_LINK]               = (nfsd4_dec)nfsd4_decode_link,
-       [OP_LOCK]               = (nfsd4_dec)nfsd4_decode_lock,
-       [OP_LOCKT]              = (nfsd4_dec)nfsd4_decode_lockt,
-       [OP_LOCKU]              = (nfsd4_dec)nfsd4_decode_locku,
-       [OP_LOOKUP]             = (nfsd4_dec)nfsd4_decode_lookup,
-       [OP_LOOKUPP]            = (nfsd4_dec)nfsd4_decode_noop,
-       [OP_NVERIFY]            = (nfsd4_dec)nfsd4_decode_verify,
-       [OP_OPEN]               = (nfsd4_dec)nfsd4_decode_open,
-       [OP_OPENATTR]           = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_OPEN_CONFIRM]       = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_OPEN_DOWNGRADE]     = (nfsd4_dec)nfsd4_decode_open_downgrade,
-       [OP_PUTFH]              = (nfsd4_dec)nfsd4_decode_putfh,
-       [OP_PUTPUBFH]           = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_PUTROOTFH]          = (nfsd4_dec)nfsd4_decode_noop,
-       [OP_READ]               = (nfsd4_dec)nfsd4_decode_read,
-       [OP_READDIR]            = (nfsd4_dec)nfsd4_decode_readdir,
-       [OP_READLINK]           = (nfsd4_dec)nfsd4_decode_noop,
-       [OP_REMOVE]             = (nfsd4_dec)nfsd4_decode_remove,
-       [OP_RENAME]             = (nfsd4_dec)nfsd4_decode_rename,
-       [OP_RENEW]              = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_RESTOREFH]          = (nfsd4_dec)nfsd4_decode_noop,
-       [OP_SAVEFH]             = (nfsd4_dec)nfsd4_decode_noop,
-       [OP_SECINFO]            = (nfsd4_dec)nfsd4_decode_secinfo,
-       [OP_SETATTR]            = (nfsd4_dec)nfsd4_decode_setattr,
-       [OP_SETCLIENTID]        = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_SETCLIENTID_CONFIRM]= (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_VERIFY]             = (nfsd4_dec)nfsd4_decode_verify,
-       [OP_WRITE]              = (nfsd4_dec)nfsd4_decode_write,
-       [OP_RELEASE_LOCKOWNER]  = (nfsd4_dec)nfsd4_decode_notsupp,
 
        /* new operations for NFSv4.1 */
        [OP_BACKCHANNEL_CTL]    = (nfsd4_dec)nfsd4_decode_backchannel_ctl,
@@ -1599,24 +1583,53 @@ static nfsd4_dec nfsd41_dec_ops[] = {
        [OP_RECLAIM_COMPLETE]   = (nfsd4_dec)nfsd4_decode_reclaim_complete,
 };
 
-struct nfsd4_minorversion_ops {
-       nfsd4_dec *decoders;
-       int nops;
-};
+static inline bool
+nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op)
+{
+       if (op->opnum < FIRST_NFS4_OP)
+               return false;
+       else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP)
+               return false;
+       else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP)
+               return false;
+       else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP)
+               return false;
+       return true;
+}
 
-static struct nfsd4_minorversion_ops nfsd4_minorversion[] = {
-       [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) },
-       [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
-       [2] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
-};
+/*
+ * Return a rough estimate of the maximum possible reply size.  Note the
+ * estimate includes rpc headers so is meant to be passed to
+ * svc_reserve, not svc_reserve_auth.
+ *
+ * Also note the current compound encoding permits only one operation to
+ * use pages beyond the first one, so the maximum possible length is the
+ * maximum over these values, not the sum.
+ */
+static int nfsd4_max_reply(u32 opnum)
+{
+       switch (opnum) {
+       case OP_READLINK:
+       case OP_READDIR:
+               /*
+                * Both of these ops take a single page for data and put
+                * the head and tail in another page:
+                */
+               return 2 * PAGE_SIZE;
+       case OP_READ:
+               return INT_MAX;
+       default:
+               return PAGE_SIZE;
+       }
+}
 
 static __be32
 nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
 {
        DECODE_HEAD;
        struct nfsd4_op *op;
-       struct nfsd4_minorversion_ops *ops;
        bool cachethis = false;
+       int max_reply = PAGE_SIZE;
        int i;
 
        READ_BUF(4);
@@ -1640,10 +1653,9 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
                }
        }
 
-       if (argp->minorversion >= ARRAY_SIZE(nfsd4_minorversion))
+       if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION)
                argp->opcnt = 0;
 
-       ops = &nfsd4_minorversion[argp->minorversion];
        for (i = 0; i < argp->opcnt; i++) {
                op = &argp->ops[i];
                op->replay = NULL;
@@ -1651,8 +1663,8 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
                READ_BUF(4);
                READ32(op->opnum);
 
-               if (op->opnum >= FIRST_NFS4_OP && op->opnum <= LAST_NFS4_OP)
-                       op->status = ops->decoders[op->opnum](argp, &op->u);
+               if (nfsd4_opnum_in_range(argp, op))
+                       op->status = nfsd4_dec_ops[op->opnum](argp, &op->u);
                else {
                        op->opnum = OP_ILLEGAL;
                        op->status = nfserr_op_illegal;
@@ -1667,10 +1679,14 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
                 * op in the compound wants to be cached:
                 */
                cachethis |= nfsd4_cache_this_op(op);
+
+               max_reply = max(max_reply, nfsd4_max_reply(op->opnum));
        }
        /* Sessions make the DRC unnecessary: */
        if (argp->minorversion)
                cachethis = false;
+       if (max_reply != INT_MAX)
+               svc_reserve(argp->rqstp, max_reply);
        argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
 
        DECODE_TAIL;
@@ -2375,7 +2391,7 @@ out_acl:
        if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
                if ((buflen -= 8) < 0)
                        goto out_resource;
-               WRITE64(~(u64)0);
+               WRITE64(exp->ex_path.mnt->mnt_sb->s_maxbytes);
        }
        if (bmval0 & FATTR4_WORD0_MAXLINK) {
                if ((buflen -= 4) < 0)
index 3d0e15ae6f726311ef82b337e66bea91a26792e4..3c37b160dcad22c6db5dc469f52ff0b2b2f68f00 100644 (file)
@@ -598,22 +598,20 @@ fh_update(struct svc_fh *fhp)
                _fh_update_old(dentry, fhp->fh_export, &fhp->fh_handle);
        } else {
                if (fhp->fh_handle.fh_fileid_type != FILEID_ROOT)
-                       goto out;
+                       return 0;
 
                _fh_update(fhp, fhp->fh_export, dentry);
                if (fhp->fh_handle.fh_fileid_type == FILEID_INVALID)
                        return nfserr_opnotsupp;
        }
-out:
        return 0;
-
 out_bad:
        printk(KERN_ERR "fh_update: fh not verified!\n");
-       goto out;
+       return nfserr_serverfault;
 out_negative:
        printk(KERN_ERR "fh_update: %pd2 still negative!\n",
                dentry);
-       goto out;
+       return nfserr_serverfault;
 }
 
 /*
index 16e8abb7709ba04fb1bcc1520573acf568e68eb9..72d29177998ebbf22e9888c9cd4cf43b3cc37e91 100644 (file)
@@ -9,13 +9,25 @@
 #include <net/netlink.h>
 #include <net/genetlink.h>
 
+static const struct genl_multicast_group quota_mcgrps[] = {
+       { .name = "events", },
+};
+
 /* Netlink family structure for quota */
 static struct genl_family quota_genl_family = {
-       .id = GENL_ID_GENERATE,
+       /*
+        * Needed due to multicast group ID abuse - old code assumed
+        * the family ID was also a valid multicast group ID (which
+        * isn't true) and userspace might thus rely on it. Assign a
+        * static ID for this group to make dealing with that easier.
+        */
+       .id = GENL_ID_VFS_DQUOT,
        .hdrsize = 0,
        .name = "VFS_DQUOT",
        .version = 1,
        .maxattr = QUOTA_NL_A_MAX,
+       .mcgrps = quota_mcgrps,
+       .n_mcgrps = ARRAY_SIZE(quota_mcgrps),
 };
 
 /**
@@ -78,7 +90,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
                goto attr_err_out;
        genlmsg_end(skb, msg_head);
 
-       genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
+       genlmsg_multicast(&quota_genl_family, skb, 0, 0, GFP_NOFS);
        return;
 attr_err_out:
        printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
index 1cd2388ca5bd7c11cd504b3a65ba67969cd936b5..1d641bb108d239f2476d862f0ce9e366c299762c 100644 (file)
@@ -136,6 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
 Eoverflow:
        m->op->stop(m, p);
        kfree(m->buf);
+       m->count = 0;
        m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
        return !m->buf ? -ENOMEM : -EAGAIN;
 }
@@ -232,10 +233,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
                        goto Fill;
                m->op->stop(m, p);
                kfree(m->buf);
+               m->count = 0;
                m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
                if (!m->buf)
                        goto Enomem;
-               m->count = 0;
                m->version = 0;
                pos = m->index;
                p = m->op->start(m, &pos);
index 89c60b0f640819c7ed93b40774d5b9c3f3cbadfb..7b2de026a4f3db11c730d9d3abfa8b903ba5713f 100644 (file)
@@ -431,9 +431,9 @@ static inline acpi_handle acpi_get_child(acpi_handle handle, u64 addr)
 {
        return acpi_find_child(handle, addr, false);
 }
+void acpi_preset_companion(struct device *dev, acpi_handle parent, u64 addr);
 int acpi_is_root_bridge(acpi_handle);
 struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle);
-#define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)ACPI_HANDLE(dev))
 
 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int state);
 int acpi_disable_wakeup_device_power(struct acpi_device *dev);
index aea9e45efce63572eee4daafc2ecfffcdd104b6e..14909b0b9cae71d879df88963a688d37a0e98a8a 100644 (file)
@@ -53,7 +53,7 @@
 
 #elif defined(CONFIG_SPARSEMEM)
 /*
- * Note: section's mem_map is encorded to reflect its start_pfn.
+ * Note: section's mem_map is encoded to reflect its start_pfn.
  * section[i].section_mem_map == mem_map's address - start_pfn;
  */
 #define __page_to_pfn(pg)                                      \
diff --git a/include/dt-bindings/mfd/as3722.h b/include/dt-bindings/mfd/as3722.h
new file mode 100644 (file)
index 0000000..0e69256
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * This header provides macros for ams AS3722 device bindings.
+ *
+ * Copyright (c) 2013, NVIDIA Corporation.
+ *
+ * Author: Laxman Dewangan <ldewangan@nvidia.com>
+ *
+ */
+
+#ifndef __DT_BINDINGS_AS3722_H__
+#define __DT_BINDINGS_AS3722_H__
+
+/* External control pins */
+#define AS3722_EXT_CONTROL_PIN_ENABLE1 1
+#define AS3722_EXT_CONTROL_PIN_ENABLE2 2
+#define AS3722_EXT_CONTROL_PIN_ENABLE2 3
+
+/* Interrupt numbers for AS3722 */
+#define AS3722_IRQ_LID                 0
+#define AS3722_IRQ_ACOK                        1
+#define AS3722_IRQ_ENABLE1             2
+#define AS3722_IRQ_OCCUR_ALARM_SD0     3
+#define AS3722_IRQ_ONKEY_LONG_PRESS    4
+#define AS3722_IRQ_ONKEY               5
+#define AS3722_IRQ_OVTMP               6
+#define AS3722_IRQ_LOWBAT              7
+#define AS3722_IRQ_SD0_LV              8
+#define AS3722_IRQ_SD1_LV              9
+#define AS3722_IRQ_SD2_LV              10
+#define AS3722_IRQ_PWM1_OV_PROT                11
+#define AS3722_IRQ_PWM2_OV_PROT                12
+#define AS3722_IRQ_ENABLE2             13
+#define AS3722_IRQ_SD6_LV              14
+#define AS3722_IRQ_RTC_REP             15
+#define AS3722_IRQ_RTC_ALARM           16
+#define AS3722_IRQ_GPIO1               17
+#define AS3722_IRQ_GPIO2               18
+#define AS3722_IRQ_GPIO3               19
+#define AS3722_IRQ_GPIO4               20
+#define AS3722_IRQ_GPIO5               21
+#define AS3722_IRQ_WATCHDOG            22
+#define AS3722_IRQ_ENABLE3             23
+#define AS3722_IRQ_TEMP_SD0_SHUTDOWN   24
+#define AS3722_IRQ_TEMP_SD1_SHUTDOWN   25
+#define AS3722_IRQ_TEMP_SD2_SHUTDOWN   26
+#define AS3722_IRQ_TEMP_SD0_ALARM      27
+#define AS3722_IRQ_TEMP_SD1_ALARM      28
+#define AS3722_IRQ_TEMP_SD6_ALARM      29
+#define AS3722_IRQ_OCCUR_ALARM_SD6     30
+#define AS3722_IRQ_ADC                 31
+
+#endif /* __DT_BINDINGS_AS3722_H__ */
index b0972c4ce81c3cc7e8ad1bbb03c5dc9054f2f32a..d9099b15b4726404343308a39e5e55d39a16aa05 100644 (file)
 #include <acpi/acpi_numa.h>
 #include <asm/acpi.h>
 
+static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
+{
+       return adev ? adev->handle : NULL;
+}
+
+#define ACPI_COMPANION(dev)            ((dev)->acpi_node.companion)
+#define ACPI_COMPANION_SET(dev, adev)  ACPI_COMPANION(dev) = (adev)
+#define ACPI_HANDLE(dev)               acpi_device_handle(ACPI_COMPANION(dev))
+
+static inline const char *acpi_dev_name(struct acpi_device *adev)
+{
+       return dev_name(&adev->dev);
+}
+
 enum acpi_irq_model_id {
        ACPI_IRQ_MODEL_PIC = 0,
        ACPI_IRQ_MODEL_IOAPIC,
@@ -401,6 +415,15 @@ static inline bool acpi_driver_match_device(struct device *dev,
 
 #define acpi_disabled 1
 
+#define ACPI_COMPANION(dev)            (NULL)
+#define ACPI_COMPANION_SET(dev, adev)  do { } while (0)
+#define ACPI_HANDLE(dev)               (NULL)
+
+static inline const char *acpi_dev_name(struct acpi_device *adev)
+{
+       return NULL;
+}
+
 static inline void acpi_early_init(void) { }
 
 static inline int early_acpi_boot_init(void)
index 62d9303c283789baacfdc3e745d11bb2110431fe..0ddb5c02ad8b6c279047c4c8c9c90e5516327ca7 100644 (file)
@@ -40,7 +40,7 @@
 #define UART010_LCRL           0x10    /* Line control register, low byte. */
 #define UART010_CR             0x14    /* Control register. */
 #define UART01x_FR             0x18    /* Flag register (Read only). */
-#define UART010_IIR            0x1C    /* Interrupt indentification register (Read). */
+#define UART010_IIR            0x1C    /* Interrupt identification register (Read). */
 #define UART010_ICR            0x1C    /* Interrupt clear register (Write). */
 #define ST_UART011_LCRH_RX     0x1C    /* Rx line control register. */
 #define UART01x_ILPR           0x20    /* IrDA low power counter register. */
index f26ec20f635476a88c8879baad16a5a908433fa7..1b135d49b27985d3243cdbf92d6002ce5eea8597 100644 (file)
@@ -505,6 +505,9 @@ struct request_queue {
                                 (1 << QUEUE_FLAG_SAME_COMP)    |       \
                                 (1 << QUEUE_FLAG_ADD_RANDOM))
 
+#define QUEUE_FLAG_MQ_DEFAULT  ((1 << QUEUE_FLAG_IO_STAT) |            \
+                                (1 << QUEUE_FLAG_SAME_COMP))
+
 static inline void queue_lockdep_assert_held(struct request_queue *q)
 {
        if (q->queue_lock)
index 7a7cc74d7f27e9901e59d2a61b850c0ec6acbe9e..d48dc00232a436cbf67b577b54a8bd27336a161c 100644 (file)
@@ -168,7 +168,7 @@ struct devfreq {
        unsigned long max_freq;
        bool stop_polling;
 
-       /* information for device freqeuncy transition */
+       /* information for device frequency transition */
        unsigned int total_trans;
        unsigned int *trans_table;
        unsigned long *time_in_state;
index b025925df7f75a5b86fa894de93e2e83d0bdf571..952b01033c32dedcf83349a988b920c1c5ed8aa8 100644 (file)
@@ -644,9 +644,11 @@ struct device_dma_parameters {
        unsigned long segment_boundary_mask;
 };
 
+struct acpi_device;
+
 struct acpi_dev_node {
 #ifdef CONFIG_ACPI
-       void    *handle;
+       struct acpi_device *companion;
 #endif
 };
 
@@ -790,14 +792,6 @@ static inline struct device *kobj_to_dev(struct kobject *kobj)
        return container_of(kobj, struct device, kobj);
 }
 
-#ifdef CONFIG_ACPI
-#define ACPI_HANDLE(dev)       ((dev)->acpi_node.handle)
-#define ACPI_HANDLE_SET(dev, _handle_) (dev)->acpi_node.handle = (_handle_)
-#else
-#define ACPI_HANDLE(dev)       (NULL)
-#define ACPI_HANDLE_SET(dev, _handle_) do { } while (0)
-#endif
-
 /* Get the wakeup routines, which depend on struct device */
 #include <linux/pm_wakeup.h>
 
index 0bc727534108d5a2d5d527e75eaa8020a3ccd239..41cf0c399288e022edf32f7e65c6f151004829d9 100644 (file)
@@ -45,13 +45,13 @@ static inline int dma_submit_error(dma_cookie_t cookie)
 
 /**
  * enum dma_status - DMA transaction status
- * @DMA_SUCCESS: transaction completed successfully
+ * @DMA_COMPLETE: transaction completed
  * @DMA_IN_PROGRESS: transaction not yet processed
  * @DMA_PAUSED: transaction is paused
  * @DMA_ERROR: transaction failed
  */
 enum dma_status {
-       DMA_SUCCESS,
+       DMA_COMPLETE,
        DMA_IN_PROGRESS,
        DMA_PAUSED,
        DMA_ERROR,
@@ -171,12 +171,6 @@ struct dma_interleaved_template {
  * @DMA_CTRL_ACK - if clear, the descriptor cannot be reused until the client
  *  acknowledges receipt, i.e. has has a chance to establish any dependency
  *  chains
- * @DMA_COMPL_SKIP_SRC_UNMAP - set to disable dma-unmapping the source buffer(s)
- * @DMA_COMPL_SKIP_DEST_UNMAP - set to disable dma-unmapping the destination(s)
- * @DMA_COMPL_SRC_UNMAP_SINGLE - set to do the source dma-unmapping as single
- *     (if not set, do the source dma-unmapping as page)
- * @DMA_COMPL_DEST_UNMAP_SINGLE - set to do the destination dma-unmapping as single
- *     (if not set, do the destination dma-unmapping as page)
  * @DMA_PREP_PQ_DISABLE_P - prevent generation of P while generating Q
  * @DMA_PREP_PQ_DISABLE_Q - prevent generation of Q while generating P
  * @DMA_PREP_CONTINUE - indicate to a driver that it is reusing buffers as
@@ -188,14 +182,10 @@ struct dma_interleaved_template {
 enum dma_ctrl_flags {
        DMA_PREP_INTERRUPT = (1 << 0),
        DMA_CTRL_ACK = (1 << 1),
-       DMA_COMPL_SKIP_SRC_UNMAP = (1 << 2),
-       DMA_COMPL_SKIP_DEST_UNMAP = (1 << 3),
-       DMA_COMPL_SRC_UNMAP_SINGLE = (1 << 4),
-       DMA_COMPL_DEST_UNMAP_SINGLE = (1 << 5),
-       DMA_PREP_PQ_DISABLE_P = (1 << 6),
-       DMA_PREP_PQ_DISABLE_Q = (1 << 7),
-       DMA_PREP_CONTINUE = (1 << 8),
-       DMA_PREP_FENCE = (1 << 9),
+       DMA_PREP_PQ_DISABLE_P = (1 << 2),
+       DMA_PREP_PQ_DISABLE_Q = (1 << 3),
+       DMA_PREP_CONTINUE = (1 << 4),
+       DMA_PREP_FENCE = (1 << 5),
 };
 
 /**
@@ -413,6 +403,17 @@ void dma_chan_cleanup(struct kref *kref);
 typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
 
 typedef void (*dma_async_tx_callback)(void *dma_async_param);
+
+struct dmaengine_unmap_data {
+       u8 to_cnt;
+       u8 from_cnt;
+       u8 bidi_cnt;
+       struct device *dev;
+       struct kref kref;
+       size_t len;
+       dma_addr_t addr[0];
+};
+
 /**
  * struct dma_async_tx_descriptor - async transaction descriptor
  * ---dma generic offload fields---
@@ -438,6 +439,7 @@ struct dma_async_tx_descriptor {
        dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
        dma_async_tx_callback callback;
        void *callback_param;
+       struct dmaengine_unmap_data *unmap;
 #ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
        struct dma_async_tx_descriptor *next;
        struct dma_async_tx_descriptor *parent;
@@ -445,6 +447,40 @@ struct dma_async_tx_descriptor {
 #endif
 };
 
+#ifdef CONFIG_DMA_ENGINE
+static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
+                                struct dmaengine_unmap_data *unmap)
+{
+       kref_get(&unmap->kref);
+       tx->unmap = unmap;
+}
+
+struct dmaengine_unmap_data *
+dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags);
+void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap);
+#else
+static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
+                                struct dmaengine_unmap_data *unmap)
+{
+}
+static inline struct dmaengine_unmap_data *
+dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags)
+{
+       return NULL;
+}
+static inline void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap)
+{
+}
+#endif
+
+static inline void dma_descriptor_unmap(struct dma_async_tx_descriptor *tx)
+{
+       if (tx->unmap) {
+               dmaengine_unmap_put(tx->unmap);
+               tx->unmap = NULL;
+       }
+}
+
 #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
 static inline void txd_lock(struct dma_async_tx_descriptor *txd)
 {
@@ -979,10 +1015,10 @@ static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
 {
        if (last_complete <= last_used) {
                if ((cookie <= last_complete) || (cookie > last_used))
-                       return DMA_SUCCESS;
+                       return DMA_COMPLETE;
        } else {
                if ((cookie <= last_complete) && (cookie > last_used))
-                       return DMA_SUCCESS;
+                       return DMA_COMPLETE;
        }
        return DMA_IN_PROGRESS;
 }
@@ -1013,11 +1049,11 @@ static inline struct dma_chan *dma_find_channel(enum dma_transaction_type tx_typ
 }
 static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
 {
-       return DMA_SUCCESS;
+       return DMA_COMPLETE;
 }
 static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
 {
-       return DMA_SUCCESS;
+       return DMA_COMPLETE;
 }
 static inline void dma_issue_pending_all(void)
 {
index 9f15c0064c50586ed08ee740698bcc6f2450c959..31ea4b428360c7e22929325ce90a76aee00a046b 100644 (file)
@@ -533,11 +533,11 @@ static inline int ftrace_force_update(void) { return 0; }
 static inline void ftrace_disable_daemon(void) { }
 static inline void ftrace_enable_daemon(void) { }
 static inline void ftrace_release_mod(struct module *mod) {}
-static inline int register_ftrace_command(struct ftrace_func_command *cmd)
+static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
 {
        return -EINVAL;
 }
-static inline int unregister_ftrace_command(char *cmd_name)
+static inline __init int unregister_ftrace_command(char *cmd_name)
 {
        return -EINVAL;
 }
@@ -721,6 +721,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
 extern char __irqentry_text_start[];
 extern char __irqentry_text_end[];
 
+#define FTRACE_NOTRACE_DEPTH 65536
 #define FTRACE_RETFUNC_DEPTH 50
 #define FTRACE_RETSTACK_ALLOC_SIZE 32
 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
index 5eaa746735ff7f4ce73f0ac5f0ed11ba78a24d50..9abbe630c456775b19cc999f36887efa94bbdd41 100644 (file)
@@ -202,6 +202,7 @@ enum {
        TRACE_EVENT_FL_NO_SET_FILTER_BIT,
        TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
        TRACE_EVENT_FL_WAS_ENABLED_BIT,
+       TRACE_EVENT_FL_USE_CALL_FILTER_BIT,
 };
 
 /*
@@ -213,6 +214,7 @@ enum {
  *  WAS_ENABLED   - Set and stays set when an event was ever enabled
  *                    (used for module unloading, if a module event is enabled,
  *                     it is best to clear the buffers that used it).
+ *  USE_CALL_FILTER - For ftrace internal events, don't use file filter
  */
 enum {
        TRACE_EVENT_FL_FILTERED         = (1 << TRACE_EVENT_FL_FILTERED_BIT),
@@ -220,6 +222,7 @@ enum {
        TRACE_EVENT_FL_NO_SET_FILTER    = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
        TRACE_EVENT_FL_IGNORE_ENABLE    = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
        TRACE_EVENT_FL_WAS_ENABLED      = (1 << TRACE_EVENT_FL_WAS_ENABLED_BIT),
+       TRACE_EVENT_FL_USE_CALL_FILTER  = (1 << TRACE_EVENT_FL_USE_CALL_FILTER_BIT),
 };
 
 struct ftrace_event_call {
@@ -238,6 +241,7 @@ struct ftrace_event_call {
         *   bit 2:             failed to apply filter
         *   bit 3:             ftrace internal event (do not enable)
         *   bit 4:             Event was enabled by module
+        *   bit 5:             use call filter rather than file filter
         */
        int                     flags; /* static flags of different events */
 
@@ -253,6 +257,8 @@ struct ftrace_subsystem_dir;
 enum {
        FTRACE_EVENT_FL_ENABLED_BIT,
        FTRACE_EVENT_FL_RECORDED_CMD_BIT,
+       FTRACE_EVENT_FL_FILTERED_BIT,
+       FTRACE_EVENT_FL_NO_SET_FILTER_BIT,
        FTRACE_EVENT_FL_SOFT_MODE_BIT,
        FTRACE_EVENT_FL_SOFT_DISABLED_BIT,
 };
@@ -261,6 +267,8 @@ enum {
  * Ftrace event file flags:
  *  ENABLED      - The event is enabled
  *  RECORDED_CMD  - The comms should be recorded at sched_switch
+ *  FILTERED     - The event has a filter attached
+ *  NO_SET_FILTER - Set when filter has error and is to be ignored
  *  SOFT_MODE     - The event is enabled/disabled by SOFT_DISABLED
  *  SOFT_DISABLED - When set, do not trace the event (even though its
  *                   tracepoint may be enabled)
@@ -268,6 +276,8 @@ enum {
 enum {
        FTRACE_EVENT_FL_ENABLED         = (1 << FTRACE_EVENT_FL_ENABLED_BIT),
        FTRACE_EVENT_FL_RECORDED_CMD    = (1 << FTRACE_EVENT_FL_RECORDED_CMD_BIT),
+       FTRACE_EVENT_FL_FILTERED        = (1 << FTRACE_EVENT_FL_FILTERED_BIT),
+       FTRACE_EVENT_FL_NO_SET_FILTER   = (1 << FTRACE_EVENT_FL_NO_SET_FILTER_BIT),
        FTRACE_EVENT_FL_SOFT_MODE       = (1 << FTRACE_EVENT_FL_SOFT_MODE_BIT),
        FTRACE_EVENT_FL_SOFT_DISABLED   = (1 << FTRACE_EVENT_FL_SOFT_DISABLED_BIT),
 };
@@ -275,6 +285,7 @@ enum {
 struct ftrace_event_file {
        struct list_head                list;
        struct ftrace_event_call        *event_call;
+       struct event_filter             *filter;
        struct dentry                   *dir;
        struct trace_array              *tr;
        struct ftrace_subsystem_dir     *system;
@@ -310,12 +321,16 @@ struct ftrace_event_file {
 
 #define MAX_FILTER_STR_VAL     256     /* Should handle KSYM_SYMBOL_LEN */
 
-extern void destroy_preds(struct ftrace_event_call *call);
+extern void destroy_preds(struct ftrace_event_file *file);
+extern void destroy_call_preds(struct ftrace_event_call *call);
 extern int filter_match_preds(struct event_filter *filter, void *rec);
-extern int filter_current_check_discard(struct ring_buffer *buffer,
-                                       struct ftrace_event_call *call,
-                                       void *rec,
-                                       struct ring_buffer_event *event);
+
+extern int filter_check_discard(struct ftrace_event_file *file, void *rec,
+                               struct ring_buffer *buffer,
+                               struct ring_buffer_event *event);
+extern int call_filter_check_discard(struct ftrace_event_call *call, void *rec,
+                                    struct ring_buffer *buffer,
+                                    struct ring_buffer_event *event);
 
 enum {
        FILTER_OTHER = 0,
index 023bc346b877f08bd75be65edaba526af7314558..c0894dd8827b27378d31bb88f591bc2fd1e43a9c 100644 (file)
@@ -273,49 +273,40 @@ static struct genl_family ZZZ_genl_family __read_mostly = {
  * Magic: define multicast groups
  * Magic: define multicast group registration helper
  */
+#define ZZZ_genl_mcgrps                CONCAT_(GENL_MAGIC_FAMILY, _genl_mcgrps)
+static const struct genl_multicast_group ZZZ_genl_mcgrps[] = {
+#undef GENL_mc_group
+#define GENL_mc_group(group) { .name = #group, },
+#include GENL_MAGIC_INCLUDE_FILE
+};
+
+enum CONCAT_(GENL_MAGIC_FAMILY, group_ids) {
+#undef GENL_mc_group
+#define GENL_mc_group(group) CONCAT_(GENL_MAGIC_FAMILY, _group_ ## group),
+#include GENL_MAGIC_INCLUDE_FILE
+};
+
 #undef GENL_mc_group
 #define GENL_mc_group(group)                                           \
-static struct genl_multicast_group                                     \
-CONCAT_(GENL_MAGIC_FAMILY, _mcg_ ## group) __read_mostly = {           \
-       .name = #group,                                                 \
-};                                                                     \
 static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)(      \
        struct sk_buff *skb, gfp_t flags)                               \
 {                                                                      \
        unsigned int group_id =                                         \
-               CONCAT_(GENL_MAGIC_FAMILY, _mcg_ ## group).id;  \
-       if (!group_id)                                                  \
-               return -EINVAL;                                         \
-       return genlmsg_multicast(skb, 0, group_id, flags);              \
+               CONCAT_(GENL_MAGIC_FAMILY, _group_ ## group);           \
+       return genlmsg_multicast(&ZZZ_genl_family, skb, 0,              \
+                                group_id, flags);                      \
 }
 
 #include GENL_MAGIC_INCLUDE_FILE
 
-int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
-{
-       int err = genl_register_family_with_ops(&ZZZ_genl_family,
-               ZZZ_genl_ops, ARRAY_SIZE(ZZZ_genl_ops));
-       if (err)
-               return err;
-#undef GENL_mc_group
-#define GENL_mc_group(group)                                           \
-       err = genl_register_mc_group(&ZZZ_genl_family,                  \
-               &CONCAT_(GENL_MAGIC_FAMILY, _mcg_ ## group));           \
-       if (err)                                                        \
-               goto fail;                                              \
-       else                                                            \
-               pr_info("%s: mcg %s: %u\n", #group,                     \
-                       __stringify(GENL_MAGIC_FAMILY),                 \
-                       CONCAT_(GENL_MAGIC_FAMILY, _mcg_ ## group).id);
-
-#include GENL_MAGIC_INCLUDE_FILE
-
 #undef GENL_mc_group
 #define GENL_mc_group(group)
-       return 0;
-fail:
-       genl_unregister_family(&ZZZ_genl_family);
-       return err;
+
+int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
+{
+       return genl_register_family_with_ops_groups(&ZZZ_genl_family,   \
+                                                   ZZZ_genl_ops,       \
+                                                   ZZZ_genl_mcgrps);
 }
 
 void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void)
index 2ab11dc38077c89f7c60d767ed1096b909ab6039..eff50e062be850189ed9e78a9b6058a5eea49b74 100644 (file)
@@ -205,7 +205,6 @@ struct i2c_driver {
  * @name: Indicates the type of the device, usually a chip name that's
  *     generic enough to hide second-sourcing and compatible revisions.
  * @adapter: manages the bus segment hosting this I2C device
- * @driver: device's driver, hence pointer to access routines
  * @dev: Driver model device node for the slave.
  * @irq: indicates the IRQ generated by this device (if any)
  * @detected: member of an i2c_driver.clients list or i2c-core's
@@ -222,7 +221,6 @@ struct i2c_client {
                                        /* _LOWER_ 7 bits               */
        char name[I2C_NAME_SIZE];
        struct i2c_adapter *adapter;    /* the adapter we sit on        */
-       struct i2c_driver *driver;      /* and our access routines      */
        struct device dev;              /* the device structure         */
        int irq;                        /* irq issued by device         */
        struct list_head detected;
diff --git a/include/linux/i2c/at24.h b/include/linux/i2c/at24.h
deleted file mode 100644 (file)
index 285025a..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * at24.h - platform_data for the at24 (generic eeprom) driver
- * (C) Copyright 2008 by Pengutronix
- * (C) Copyright 2012 by Wolfram Sang
- * same license as the driver
- */
-
-#ifndef _LINUX_AT24_H
-#define _LINUX_AT24_H
-
-#include <linux/types.h>
-#include <linux/memory.h>
-
-/**
- * struct at24_platform_data - data to set up at24 (generic eeprom) driver
- * @byte_len: size of eeprom in byte
- * @page_size: number of byte which can be written in one go
- * @flags: tunable options, check AT24_FLAG_* defines
- * @setup: an optional callback invoked after eeprom is probed; enables kernel
-       code to access eeprom via memory_accessor, see example
- * @context: optional parameter passed to setup()
- *
- * If you set up a custom eeprom type, please double-check the parameters.
- * Especially page_size needs extra care, as you risk data loss if your value
- * is bigger than what the chip actually supports!
- *
- * An example in pseudo code for a setup() callback:
- *
- * void get_mac_addr(struct memory_accessor *mem_acc, void *context)
- * {
- *     u8 *mac_addr = ethernet_pdata->mac_addr;
- *     off_t offset = context;
- *
- *     // Read MAC addr from EEPROM
- *     if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN)
- *             pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
- * }
- *
- * This function pointer and context can now be set up in at24_platform_data.
- */
-
-struct at24_platform_data {
-       u32             byte_len;               /* size (sum of all addr) */
-       u16             page_size;              /* for writes */
-       u8              flags;
-#define AT24_FLAG_ADDR16       0x80    /* address pointer is 16 bit */
-#define AT24_FLAG_READONLY     0x40    /* sysfs-entry will be read-only */
-#define AT24_FLAG_IRUGO                0x20    /* sysfs-entry will be world-readable */
-#define AT24_FLAG_TAKE8ADDR    0x10    /* take always 8 addresses (24c00) */
-
-       void            (*setup)(struct memory_accessor *, void *context);
-       void            *context;
-};
-
-#endif /* _LINUX_AT24_H */
index c2702856295ebaaa06db6dddb7106a53d2e71315..84ba5ac39e039f80da563305155800cd1332782c 100644 (file)
@@ -119,4 +119,21 @@ extern int macvlan_link_register(struct rtnl_link_ops *ops);
 extern netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
                                      struct net_device *dev);
 
+#if IS_ENABLED(CONFIG_MACVLAN)
+static inline struct net_device *
+macvlan_dev_real_dev(const struct net_device *dev)
+{
+       struct macvlan_dev *macvlan = netdev_priv(dev);
+
+       return macvlan->lowerdev;
+}
+#else
+static inline struct net_device *
+macvlan_dev_real_dev(const struct net_device *dev)
+{
+       BUG();
+       return NULL;
+}
+#endif
+
 #endif /* _LINUX_IF_MACVLAN_H */
index 56bb0dc8b7d44cbab1a5a3cefb9efc04a7440995..7dc10036eff552229cdd964e88669a7759a8152f 100644 (file)
@@ -70,6 +70,9 @@ typedef       void (*irq_preflow_handler_t)(struct irq_data *data);
  * IRQ_MOVE_PCNTXT             - Interrupt can be migrated from process context
  * IRQ_NESTED_TRHEAD           - Interrupt nests into another thread
  * IRQ_PER_CPU_DEVID           - Dev_id is a per-cpu variable
+ * IRQ_IS_POLLED               - Always polled by another interrupt. Exclude
+ *                               it from the spurious interrupt detection
+ *                               mechanism and from core side polling.
  */
 enum {
        IRQ_TYPE_NONE           = 0x00000000,
@@ -94,12 +97,14 @@ enum {
        IRQ_NESTED_THREAD       = (1 << 15),
        IRQ_NOTHREAD            = (1 << 16),
        IRQ_PER_CPU_DEVID       = (1 << 17),
+       IRQ_IS_POLLED           = (1 << 18),
 };
 
 #define IRQF_MODIFY_MASK       \
        (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
         IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
-        IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID)
+        IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
+        IRQ_IS_POLLED)
 
 #define IRQ_NO_BALANCING_MASK  (IRQ_PER_CPU | IRQ_NO_BALANCING)
 
index 672ddc4de4af0511b20a4d269bcae1c517c3d5c4..d4e98d13eff4bda01b08313986b63135cc80ee2b 100644 (file)
@@ -501,7 +501,6 @@ void tracing_snapshot_alloc(void);
 
 extern void tracing_start(void);
 extern void tracing_stop(void);
-extern void ftrace_off_permanent(void);
 
 static inline __printf(1, 2)
 void ____trace_printk_check_format(const char *fmt, ...)
@@ -639,7 +638,6 @@ extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
 #else
 static inline void tracing_start(void) { }
 static inline void tracing_stop(void) { }
-static inline void ftrace_off_permanent(void) { }
 static inline void trace_dump_stack(int skip) { }
 
 static inline void tracing_on(void) { }
index 4706d3d46e56f1e4bd630bc0dcbb50e8111d4af8..cb49417f8ba9261ba436fef11851274f9df977d0 100644 (file)
 #define ARIZONA_FLL2_SYNC_GAIN_MASK              0x003c  /* FLL2_SYNC_GAIN */
 #define ARIZONA_FLL2_SYNC_GAIN_SHIFT                  2  /* FLL2_SYNC_GAIN */
 #define ARIZONA_FLL2_SYNC_GAIN_WIDTH                  4  /* FLL2_SYNC_GAIN */
-#define ARIZONA_FLL2_SYNC_BW_MASK                0x0001  /* FLL2_SYNC_BW */
+#define ARIZONA_FLL2_SYNC_BW                     0x0001  /* FLL2_SYNC_BW */
 #define ARIZONA_FLL2_SYNC_BW_MASK                0x0001  /* FLL2_SYNC_BW */
 #define ARIZONA_FLL2_SYNC_BW_SHIFT                    0  /* FLL2_SYNC_BW */
 #define ARIZONA_FLL2_SYNC_BW_WIDTH                    1  /* FLL2_SYNC_BW */
diff --git a/include/linux/mfd/as3722.h b/include/linux/mfd/as3722.h
new file mode 100644 (file)
index 0000000..16bf8a0
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * as3722 definitions
+ *
+ * Copyright (C) 2013 ams
+ * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
+ *
+ * Author: Florian Lobmaier <florian.lobmaier@ams.com>
+ * Author: Laxman Dewangan <ldewangan@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#ifndef __LINUX_MFD_AS3722_H__
+#define __LINUX_MFD_AS3722_H__
+
+#include <linux/regmap.h>
+
+/* AS3722 registers */
+#define AS3722_SD0_VOLTAGE_REG                         0x00
+#define AS3722_SD1_VOLTAGE_REG                         0x01
+#define AS3722_SD2_VOLTAGE_REG                         0x02
+#define AS3722_SD3_VOLTAGE_REG                         0x03
+#define AS3722_SD4_VOLTAGE_REG                         0x04
+#define AS3722_SD5_VOLTAGE_REG                         0x05
+#define AS3722_SD6_VOLTAGE_REG                         0x06
+#define AS3722_GPIO0_CONTROL_REG                       0x08
+#define AS3722_GPIO1_CONTROL_REG                       0x09
+#define AS3722_GPIO2_CONTROL_REG                       0x0A
+#define AS3722_GPIO3_CONTROL_REG                       0x0B
+#define AS3722_GPIO4_CONTROL_REG                       0x0C
+#define AS3722_GPIO5_CONTROL_REG                       0x0D
+#define AS3722_GPIO6_CONTROL_REG                       0x0E
+#define AS3722_GPIO7_CONTROL_REG                       0x0F
+#define AS3722_LDO0_VOLTAGE_REG                                0x10
+#define AS3722_LDO1_VOLTAGE_REG                                0x11
+#define AS3722_LDO2_VOLTAGE_REG                                0x12
+#define AS3722_LDO3_VOLTAGE_REG                                0x13
+#define AS3722_LDO4_VOLTAGE_REG                                0x14
+#define AS3722_LDO5_VOLTAGE_REG                                0x15
+#define AS3722_LDO6_VOLTAGE_REG                                0x16
+#define AS3722_LDO7_VOLTAGE_REG                                0x17
+#define AS3722_LDO9_VOLTAGE_REG                                0x19
+#define AS3722_LDO10_VOLTAGE_REG                       0x1A
+#define AS3722_LDO11_VOLTAGE_REG                       0x1B
+#define AS3722_GPIO_DEB1_REG                           0x1E
+#define AS3722_GPIO_DEB2_REG                           0x1F
+#define AS3722_GPIO_SIGNAL_OUT_REG                     0x20
+#define AS3722_GPIO_SIGNAL_IN_REG                      0x21
+#define AS3722_REG_SEQU_MOD1_REG                       0x22
+#define AS3722_REG_SEQU_MOD2_REG                       0x23
+#define AS3722_REG_SEQU_MOD3_REG                       0x24
+#define AS3722_SD_PHSW_CTRL_REG                                0x27
+#define AS3722_SD_PHSW_STATUS                          0x28
+#define AS3722_SD0_CONTROL_REG                         0x29
+#define AS3722_SD1_CONTROL_REG                         0x2A
+#define AS3722_SDmph_CONTROL_REG                       0x2B
+#define AS3722_SD23_CONTROL_REG                                0x2C
+#define AS3722_SD4_CONTROL_REG                         0x2D
+#define AS3722_SD5_CONTROL_REG                         0x2E
+#define AS3722_SD6_CONTROL_REG                         0x2F
+#define AS3722_SD_DVM_REG                              0x30
+#define AS3722_RESET_REASON_REG                                0x31
+#define AS3722_BATTERY_VOLTAGE_MONITOR_REG             0x32
+#define AS3722_STARTUP_CONTROL_REG                     0x33
+#define AS3722_RESET_TIMER_REG                         0x34
+#define AS3722_REFERENCE_CONTROL_REG                   0x35
+#define AS3722_RESET_CONTROL_REG                       0x36
+#define AS3722_OVER_TEMP_CONTROL_REG                   0x37
+#define AS3722_WATCHDOG_CONTROL_REG                    0x38
+#define AS3722_REG_STANDBY_MOD1_REG                    0x39
+#define AS3722_REG_STANDBY_MOD2_REG                    0x3A
+#define AS3722_REG_STANDBY_MOD3_REG                    0x3B
+#define AS3722_ENABLE_CTRL1_REG                                0x3C
+#define AS3722_ENABLE_CTRL2_REG                                0x3D
+#define AS3722_ENABLE_CTRL3_REG                                0x3E
+#define AS3722_ENABLE_CTRL4_REG                                0x3F
+#define AS3722_ENABLE_CTRL5_REG                                0x40
+#define AS3722_PWM_CONTROL_L_REG                       0x41
+#define AS3722_PWM_CONTROL_H_REG                       0x42
+#define AS3722_WATCHDOG_TIMER_REG                      0x46
+#define AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG            0x48
+#define AS3722_IOVOLTAGE_REG                           0x49
+#define AS3722_BATTERY_VOLTAGE_MONITOR2_REG            0x4A
+#define AS3722_SD_CONTROL_REG                          0x4D
+#define AS3722_LDOCONTROL0_REG                         0x4E
+#define AS3722_LDOCONTROL1_REG                         0x4F
+#define AS3722_SD0_PROTECT_REG                         0x50
+#define AS3722_SD6_PROTECT_REG                         0x51
+#define AS3722_PWM_VCONTROL1_REG                       0x52
+#define AS3722_PWM_VCONTROL2_REG                       0x53
+#define AS3722_PWM_VCONTROL3_REG                       0x54
+#define AS3722_PWM_VCONTROL4_REG                       0x55
+#define AS3722_BB_CHARGER_REG                          0x57
+#define AS3722_CTRL_SEQU1_REG                          0x58
+#define AS3722_CTRL_SEQU2_REG                          0x59
+#define AS3722_OVCURRENT_REG                           0x5A
+#define AS3722_OVCURRENT_DEB_REG                       0x5B
+#define AS3722_SDLV_DEB_REG                            0x5C
+#define AS3722_OC_PG_CTRL_REG                          0x5D
+#define AS3722_OC_PG_CTRL2_REG                         0x5E
+#define AS3722_CTRL_STATUS                             0x5F
+#define AS3722_RTC_CONTROL_REG                         0x60
+#define AS3722_RTC_SECOND_REG                          0x61
+#define AS3722_RTC_MINUTE_REG                          0x62
+#define AS3722_RTC_HOUR_REG                            0x63
+#define AS3722_RTC_DAY_REG                             0x64
+#define AS3722_RTC_MONTH_REG                           0x65
+#define AS3722_RTC_YEAR_REG                            0x66
+#define AS3722_RTC_ALARM_SECOND_REG                    0x67
+#define AS3722_RTC_ALARM_MINUTE_REG                    0x68
+#define AS3722_RTC_ALARM_HOUR_REG                      0x69
+#define AS3722_RTC_ALARM_DAY_REG                       0x6A
+#define AS3722_RTC_ALARM_MONTH_REG                     0x6B
+#define AS3722_RTC_ALARM_YEAR_REG                      0x6C
+#define AS3722_SRAM_REG                                        0x6D
+#define AS3722_RTC_ACCESS_REG                          0x6F
+#define AS3722_RTC_STATUS_REG                          0x73
+#define AS3722_INTERRUPT_MASK1_REG                     0x74
+#define AS3722_INTERRUPT_MASK2_REG                     0x75
+#define AS3722_INTERRUPT_MASK3_REG                     0x76
+#define AS3722_INTERRUPT_MASK4_REG                     0x77
+#define AS3722_INTERRUPT_STATUS1_REG                   0x78
+#define AS3722_INTERRUPT_STATUS2_REG                   0x79
+#define AS3722_INTERRUPT_STATUS3_REG                   0x7A
+#define AS3722_INTERRUPT_STATUS4_REG                   0x7B
+#define AS3722_TEMP_STATUS_REG                         0x7D
+#define AS3722_ADC0_CONTROL_REG                                0x80
+#define AS3722_ADC1_CONTROL_REG                                0x81
+#define AS3722_ADC0_MSB_RESULT_REG                     0x82
+#define AS3722_ADC0_LSB_RESULT_REG                     0x83
+#define AS3722_ADC1_MSB_RESULT_REG                     0x84
+#define AS3722_ADC1_LSB_RESULT_REG                     0x85
+#define AS3722_ADC1_THRESHOLD_HI_MSB_REG               0x86
+#define AS3722_ADC1_THRESHOLD_HI_LSB_REG               0x87
+#define AS3722_ADC1_THRESHOLD_LO_MSB_REG               0x88
+#define AS3722_ADC1_THRESHOLD_LO_LSB_REG               0x89
+#define AS3722_ADC_CONFIGURATION_REG                   0x8A
+#define AS3722_ASIC_ID1_REG                            0x90
+#define AS3722_ASIC_ID2_REG                            0x91
+#define AS3722_LOCK_REG                                        0x9E
+#define AS3722_MAX_REGISTER                            0xF4
+
+#define AS3722_SD0_EXT_ENABLE_MASK                     0x03
+#define AS3722_SD1_EXT_ENABLE_MASK                     0x0C
+#define AS3722_SD2_EXT_ENABLE_MASK                     0x30
+#define AS3722_SD3_EXT_ENABLE_MASK                     0xC0
+#define AS3722_SD4_EXT_ENABLE_MASK                     0x03
+#define AS3722_SD5_EXT_ENABLE_MASK                     0x0C
+#define AS3722_SD6_EXT_ENABLE_MASK                     0x30
+#define AS3722_LDO0_EXT_ENABLE_MASK                    0x03
+#define AS3722_LDO1_EXT_ENABLE_MASK                    0x0C
+#define AS3722_LDO2_EXT_ENABLE_MASK                    0x30
+#define AS3722_LDO3_EXT_ENABLE_MASK                    0xC0
+#define AS3722_LDO4_EXT_ENABLE_MASK                    0x03
+#define AS3722_LDO5_EXT_ENABLE_MASK                    0x0C
+#define AS3722_LDO6_EXT_ENABLE_MASK                    0x30
+#define AS3722_LDO7_EXT_ENABLE_MASK                    0xC0
+#define AS3722_LDO9_EXT_ENABLE_MASK                    0x0C
+#define AS3722_LDO10_EXT_ENABLE_MASK                   0x30
+#define AS3722_LDO11_EXT_ENABLE_MASK                   0xC0
+
+#define AS3722_OVCURRENT_SD0_ALARM_MASK                        0x07
+#define AS3722_OVCURRENT_SD0_ALARM_SHIFT               0x01
+#define AS3722_OVCURRENT_SD0_TRIP_MASK                 0x18
+#define AS3722_OVCURRENT_SD0_TRIP_SHIFT                        0x03
+#define AS3722_OVCURRENT_SD1_TRIP_MASK                 0x60
+#define AS3722_OVCURRENT_SD1_TRIP_SHIFT                        0x05
+
+#define AS3722_OVCURRENT_SD6_ALARM_MASK                        0x07
+#define AS3722_OVCURRENT_SD6_ALARM_SHIFT               0x01
+#define AS3722_OVCURRENT_SD6_TRIP_MASK                 0x18
+#define AS3722_OVCURRENT_SD6_TRIP_SHIFT                        0x03
+
+/* AS3722 register bits and bit masks */
+#define AS3722_LDO_ILIMIT_MASK                         BIT(7)
+#define AS3722_LDO_ILIMIT_BIT                          BIT(7)
+#define AS3722_LDO0_VSEL_MASK                          0x1F
+#define AS3722_LDO0_VSEL_MIN                           0x01
+#define AS3722_LDO0_VSEL_MAX                           0x12
+#define AS3722_LDO0_NUM_VOLT                           0x12
+#define AS3722_LDO3_VSEL_MASK                          0x3F
+#define AS3722_LDO3_VSEL_MIN                           0x01
+#define AS3722_LDO3_VSEL_MAX                           0x2D
+#define AS3722_LDO3_NUM_VOLT                           0x2D
+#define AS3722_LDO_VSEL_MASK                           0x7F
+#define AS3722_LDO_VSEL_MIN                            0x01
+#define AS3722_LDO_VSEL_MAX                            0x7F
+#define AS3722_LDO_VSEL_DNU_MIN                                0x25
+#define AS3722_LDO_VSEL_DNU_MAX                                0x3F
+#define AS3722_LDO_NUM_VOLT                            0x80
+
+#define AS3722_LDO0_CTRL                               BIT(0)
+#define AS3722_LDO1_CTRL                               BIT(1)
+#define AS3722_LDO2_CTRL                               BIT(2)
+#define AS3722_LDO3_CTRL                               BIT(3)
+#define AS3722_LDO4_CTRL                               BIT(4)
+#define AS3722_LDO5_CTRL                               BIT(5)
+#define AS3722_LDO6_CTRL                               BIT(6)
+#define AS3722_LDO7_CTRL                               BIT(7)
+#define AS3722_LDO9_CTRL                               BIT(1)
+#define AS3722_LDO10_CTRL                              BIT(2)
+#define AS3722_LDO11_CTRL                              BIT(3)
+
+#define AS3722_LDO3_MODE_MASK                          (3 << 6)
+#define AS3722_LDO3_MODE_VAL(n)                                (((n) & 0x3) << 6)
+#define AS3722_LDO3_MODE_PMOS                          AS3722_LDO3_MODE_VAL(0)
+#define AS3722_LDO3_MODE_PMOS_TRACKING                 AS3722_LDO3_MODE_VAL(1)
+#define AS3722_LDO3_MODE_NMOS                          AS3722_LDO3_MODE_VAL(2)
+#define AS3722_LDO3_MODE_SWITCH                                AS3722_LDO3_MODE_VAL(3)
+
+#define AS3722_SD_VSEL_MASK                            0x7F
+#define AS3722_SD0_VSEL_MIN                            0x01
+#define AS3722_SD0_VSEL_MAX                            0x5A
+#define AS3722_SD2_VSEL_MIN                            0x01
+#define AS3722_SD2_VSEL_MAX                            0x7F
+
+#define AS3722_SDn_CTRL(n)                             BIT(n)
+
+#define AS3722_SD0_MODE_FAST                           BIT(4)
+#define AS3722_SD1_MODE_FAST                           BIT(4)
+#define AS3722_SD2_MODE_FAST                           BIT(2)
+#define AS3722_SD3_MODE_FAST                           BIT(6)
+#define AS3722_SD4_MODE_FAST                           BIT(2)
+#define AS3722_SD5_MODE_FAST                           BIT(2)
+#define AS3722_SD6_MODE_FAST                           BIT(4)
+
+#define AS3722_POWER_OFF                               BIT(1)
+
+#define AS3722_INTERRUPT_MASK1_LID                     BIT(0)
+#define AS3722_INTERRUPT_MASK1_ACOK                    BIT(1)
+#define AS3722_INTERRUPT_MASK1_ENABLE1                 BIT(2)
+#define AS3722_INTERRUPT_MASK1_OCURR_ALARM_SD0         BIT(3)
+#define AS3722_INTERRUPT_MASK1_ONKEY_LONG              BIT(4)
+#define AS3722_INTERRUPT_MASK1_ONKEY                   BIT(5)
+#define AS3722_INTERRUPT_MASK1_OVTMP                   BIT(6)
+#define AS3722_INTERRUPT_MASK1_LOWBAT                  BIT(7)
+
+#define AS3722_INTERRUPT_MASK2_SD0_LV                  BIT(0)
+#define AS3722_INTERRUPT_MASK2_SD1_LV                  BIT(1)
+#define AS3722_INTERRUPT_MASK2_SD2345_LV               BIT(2)
+#define AS3722_INTERRUPT_MASK2_PWM1_OV_PROT            BIT(3)
+#define AS3722_INTERRUPT_MASK2_PWM2_OV_PROT            BIT(4)
+#define AS3722_INTERRUPT_MASK2_ENABLE2                 BIT(5)
+#define AS3722_INTERRUPT_MASK2_SD6_LV                  BIT(6)
+#define AS3722_INTERRUPT_MASK2_RTC_REP                 BIT(7)
+
+#define AS3722_INTERRUPT_MASK3_RTC_ALARM               BIT(0)
+#define AS3722_INTERRUPT_MASK3_GPIO1                   BIT(1)
+#define AS3722_INTERRUPT_MASK3_GPIO2                   BIT(2)
+#define AS3722_INTERRUPT_MASK3_GPIO3                   BIT(3)
+#define AS3722_INTERRUPT_MASK3_GPIO4                   BIT(4)
+#define AS3722_INTERRUPT_MASK3_GPIO5                   BIT(5)
+#define AS3722_INTERRUPT_MASK3_WATCHDOG                        BIT(6)
+#define AS3722_INTERRUPT_MASK3_ENABLE3                 BIT(7)
+
+#define AS3722_INTERRUPT_MASK4_TEMP_SD0_SHUTDOWN       BIT(0)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD1_SHUTDOWN       BIT(1)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD6_SHUTDOWN       BIT(2)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD0_ALARM          BIT(3)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD1_ALARM          BIT(4)
+#define AS3722_INTERRUPT_MASK4_TEMP_SD6_ALARM          BIT(5)
+#define AS3722_INTERRUPT_MASK4_OCCUR_ALARM_SD6         BIT(6)
+#define AS3722_INTERRUPT_MASK4_ADC                     BIT(7)
+
+#define AS3722_ADC1_INTERVAL_TIME                      BIT(0)
+#define AS3722_ADC1_INT_MODE_ON                                BIT(1)
+#define AS3722_ADC_BUF_ON                              BIT(2)
+#define AS3722_ADC1_LOW_VOLTAGE_RANGE                  BIT(5)
+#define AS3722_ADC1_INTEVAL_SCAN                       BIT(6)
+#define AS3722_ADC1_INT_MASK                           BIT(7)
+
+#define AS3722_ADC_MSB_VAL_MASK                                0x7F
+#define AS3722_ADC_LSB_VAL_MASK                                0x07
+
+#define AS3722_ADC0_CONV_START                         BIT(7)
+#define AS3722_ADC0_CONV_NOTREADY                      BIT(7)
+#define AS3722_ADC0_SOURCE_SELECT_MASK                 0x1F
+
+#define AS3722_ADC1_CONV_START                         BIT(7)
+#define AS3722_ADC1_CONV_NOTREADY                      BIT(7)
+#define AS3722_ADC1_SOURCE_SELECT_MASK                 0x1F
+
+/* GPIO modes */
+#define AS3722_GPIO_MODE_MASK                          0x07
+#define AS3722_GPIO_MODE_INPUT                         0x00
+#define AS3722_GPIO_MODE_OUTPUT_VDDH                   0x01
+#define AS3722_GPIO_MODE_IO_OPEN_DRAIN                 0x02
+#define AS3722_GPIO_MODE_ADC_IN                                0x03
+#define AS3722_GPIO_MODE_INPUT_PULL_UP                 0x04
+#define AS3722_GPIO_MODE_INPUT_PULL_DOWN               0x05
+#define AS3722_GPIO_MODE_IO_OPEN_DRAIN_PULL_UP         0x06
+#define AS3722_GPIO_MODE_OUTPUT_VDDL                   0x07
+#define AS3722_GPIO_MODE_VAL(n)                        ((n) & AS3722_GPIO_MODE_MASK)
+
+#define AS3722_GPIO_INV                                        BIT(7)
+#define AS3722_GPIO_IOSF_MASK                          0x78
+#define AS3722_GPIO_IOSF_VAL(n)                                (((n) & 0xF) << 3)
+#define AS3722_GPIO_IOSF_NORMAL                                AS3722_GPIO_IOSF_VAL(0)
+#define AS3722_GPIO_IOSF_INTERRUPT_OUT                 AS3722_GPIO_IOSF_VAL(1)
+#define AS3722_GPIO_IOSF_VSUP_LOW_OUT                  AS3722_GPIO_IOSF_VAL(2)
+#define AS3722_GPIO_IOSF_GPIO_INTERRUPT_IN             AS3722_GPIO_IOSF_VAL(3)
+#define AS3722_GPIO_IOSF_ISINK_PWM_IN                  AS3722_GPIO_IOSF_VAL(4)
+#define AS3722_GPIO_IOSF_VOLTAGE_STBY                  AS3722_GPIO_IOSF_VAL(5)
+#define AS3722_GPIO_IOSF_PWR_GOOD_OUT                  AS3722_GPIO_IOSF_VAL(7)
+#define AS3722_GPIO_IOSF_Q32K_OUT                      AS3722_GPIO_IOSF_VAL(8)
+#define AS3722_GPIO_IOSF_WATCHDOG_IN                   AS3722_GPIO_IOSF_VAL(9)
+#define AS3722_GPIO_IOSF_SOFT_RESET_IN                 AS3722_GPIO_IOSF_VAL(11)
+#define AS3722_GPIO_IOSF_PWM_OUT                       AS3722_GPIO_IOSF_VAL(12)
+#define AS3722_GPIO_IOSF_VSUP_LOW_DEB_OUT              AS3722_GPIO_IOSF_VAL(13)
+#define AS3722_GPIO_IOSF_SD6_LOW_VOLT_LOW              AS3722_GPIO_IOSF_VAL(14)
+
+#define AS3722_GPIOn_SIGNAL(n)                         BIT(n)
+#define AS3722_GPIOn_CONTROL_REG(n)            (AS3722_GPIO0_CONTROL_REG + n)
+#define AS3722_I2C_PULL_UP                             BIT(4)
+#define AS3722_INT_PULL_UP                             BIT(5)
+
+#define AS3722_RTC_REP_WAKEUP_EN                       BIT(0)
+#define AS3722_RTC_ALARM_WAKEUP_EN                     BIT(1)
+#define AS3722_RTC_ON                                  BIT(2)
+#define AS3722_RTC_IRQMODE                             BIT(3)
+#define AS3722_RTC_CLK32K_OUT_EN                       BIT(5)
+
+#define AS3722_WATCHDOG_TIMER_MAX                      0x7F
+#define AS3722_WATCHDOG_ON                             BIT(0)
+#define AS3722_WATCHDOG_SW_SIG                         BIT(0)
+
+#define AS3722_EXT_CONTROL_ENABLE1                     0x1
+#define AS3722_EXT_CONTROL_ENABLE2                     0x2
+#define AS3722_EXT_CONTROL_ENABLE3                     0x3
+
+/* Interrupt IDs */
+enum as3722_irq {
+       AS3722_IRQ_LID,
+       AS3722_IRQ_ACOK,
+       AS3722_IRQ_ENABLE1,
+       AS3722_IRQ_OCCUR_ALARM_SD0,
+       AS3722_IRQ_ONKEY_LONG_PRESS,
+       AS3722_IRQ_ONKEY,
+       AS3722_IRQ_OVTMP,
+       AS3722_IRQ_LOWBAT,
+       AS3722_IRQ_SD0_LV,
+       AS3722_IRQ_SD1_LV,
+       AS3722_IRQ_SD2_LV,
+       AS3722_IRQ_PWM1_OV_PROT,
+       AS3722_IRQ_PWM2_OV_PROT,
+       AS3722_IRQ_ENABLE2,
+       AS3722_IRQ_SD6_LV,
+       AS3722_IRQ_RTC_REP,
+       AS3722_IRQ_RTC_ALARM,
+       AS3722_IRQ_GPIO1,
+       AS3722_IRQ_GPIO2,
+       AS3722_IRQ_GPIO3,
+       AS3722_IRQ_GPIO4,
+       AS3722_IRQ_GPIO5,
+       AS3722_IRQ_WATCHDOG,
+       AS3722_IRQ_ENABLE3,
+       AS3722_IRQ_TEMP_SD0_SHUTDOWN,
+       AS3722_IRQ_TEMP_SD1_SHUTDOWN,
+       AS3722_IRQ_TEMP_SD2_SHUTDOWN,
+       AS3722_IRQ_TEMP_SD0_ALARM,
+       AS3722_IRQ_TEMP_SD1_ALARM,
+       AS3722_IRQ_TEMP_SD6_ALARM,
+       AS3722_IRQ_OCCUR_ALARM_SD6,
+       AS3722_IRQ_ADC,
+       AS3722_IRQ_MAX,
+};
+
+struct as3722 {
+       struct device *dev;
+       struct regmap *regmap;
+       int chip_irq;
+       unsigned long irq_flags;
+       bool en_intern_int_pullup;
+       bool en_intern_i2c_pullup;
+       struct regmap_irq_chip_data *irq_data;
+};
+
+static inline int as3722_read(struct as3722 *as3722, u32 reg, u32 *dest)
+{
+       return regmap_read(as3722->regmap, reg, dest);
+}
+
+static inline int as3722_write(struct as3722 *as3722, u32 reg, u32 value)
+{
+       return regmap_write(as3722->regmap, reg, value);
+}
+
+static inline int as3722_block_read(struct as3722 *as3722, u32 reg,
+               int count, u8 *buf)
+{
+       return regmap_bulk_read(as3722->regmap, reg, buf, count);
+}
+
+static inline int as3722_block_write(struct as3722 *as3722, u32 reg,
+               int count, u8 *data)
+{
+       return regmap_bulk_write(as3722->regmap, reg, data, count);
+}
+
+static inline int as3722_update_bits(struct as3722 *as3722, u32 reg,
+               u32 mask, u8 val)
+{
+       return regmap_update_bits(as3722->regmap, reg, mask, val);
+}
+
+static inline int as3722_irq_get_virq(struct as3722 *as3722, int irq)
+{
+       return regmap_irq_get_virq(as3722->irq_data, irq);
+}
+#endif /* __LINUX_MFD_AS3722_H__ */
index 7314fc4e6d2503b0e5e885c7ceccf0a873207ec0..bdba8c61207bb7b892e63eff49d81cfdf2f3538a 100644 (file)
@@ -104,7 +104,7 @@ static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
 }
 
 extern int mfd_add_devices(struct device *parent, int id,
-                          struct mfd_cell *cells, int n_devs,
+                          const struct mfd_cell *cells, int n_devs,
                           struct resource *mem_base,
                           int irq_base, struct irq_domain *irq_domain);
 
index 786d02eb79d2210ef8c3dfe145e3c8d0e0123ef1..21e21b81cc7551db7203b7d027b688feebd3577c 100644 (file)
@@ -148,10 +148,15 @@ static inline int da9052_group_read(struct da9052 *da9052, unsigned char reg,
                                     unsigned reg_cnt, unsigned char *val)
 {
        int ret;
+       unsigned int tmp;
+       int i;
 
-       ret = regmap_bulk_read(da9052->regmap, reg, val, reg_cnt);
-       if (ret < 0)
-               return ret;
+       for (i = 0; i < reg_cnt; i++) {
+               ret = regmap_read(da9052->regmap, reg + i, &tmp);
+               val[i] = (unsigned char)tmp;
+               if (ret < 0)
+                       return ret;
+       }
 
        if (da9052->fix_io) {
                ret = da9052->fix_io(da9052, reg);
@@ -166,10 +171,13 @@ static inline int da9052_group_write(struct da9052 *da9052, unsigned char reg,
                                      unsigned reg_cnt, unsigned char *val)
 {
        int ret;
+       int i;
 
-       ret = regmap_raw_write(da9052->regmap, reg, val, reg_cnt);
-       if (ret < 0)
-               return ret;
+       for (i = 0; i < reg_cnt; i++) {
+               ret = regmap_write(da9052->regmap, reg + i, val[i]);
+               if (ret < 0)
+                       return ret;
+       }
 
        if (da9052->fix_io) {
                ret = da9052->fix_io(da9052, reg);
index 244fb0d51589ffc9d92ed440bed1cb8f56084ae0..3e050b933dd0e28117a772e68e093a90ca6feddb 100644 (file)
@@ -323,7 +323,6 @@ struct max77693_dev {
 
        int irq;
        int irq_gpio;
-       bool wakeup;
        struct mutex irqlock;
        int irq_masks_cur[MAX77693_IRQ_GROUP_NR];
        int irq_masks_cache[MAX77693_IRQ_GROUP_NR];
index 676f0f388992410fe0b7ac918a08bfe992d1ca91..3f3dc45f93ee8058bab7048c3476fa508a9bb27f 100644 (file)
@@ -64,8 +64,6 @@ struct max77693_muic_platform_data {
 };
 
 struct max77693_platform_data {
-       int wakeup;
-
        /* regulator data */
        struct max77693_regulator_data *regulators;
        int num_regulators;
index d1382dfbeff022b5f91dfcf6789ece80874eea5b..0ce7721055081b3a75e16ea9b485c01b7e83a1f8 100644 (file)
 #define PCR_SETTING_REG2               0x814
 #define PCR_SETTING_REG3               0x747
 
+/* Phy bits */
+#define PHY_PCR_FORCE_CODE                     0xB000
+#define PHY_PCR_OOBS_CALI_50                   0x0800
+#define PHY_PCR_OOBS_VCM_08                    0x0200
+#define PHY_PCR_OOBS_SEN_90                    0x0040
+#define PHY_PCR_RSSI_EN                                0x0002
+
+#define PHY_RCR1_ADP_TIME                      0x0100
+#define PHY_RCR1_VCO_COARSE                    0x001F
+
+#define PHY_RCR2_EMPHASE_EN                    0x8000
+#define PHY_RCR2_NADJR                         0x4000
+#define PHY_RCR2_CDR_CP_10                     0x0400
+#define PHY_RCR2_CDR_SR_2                      0x0100
+#define PHY_RCR2_FREQSEL_12                    0x0040
+#define PHY_RCR2_CPADJEN                       0x0020
+#define PHY_RCR2_CDR_SC_8                      0x0008
+#define PHY_RCR2_CALIB_LATE                    0x0002
+
+#define PHY_RDR_RXDSEL_1_9                     0x4000
+
+#define PHY_TUNE_TUNEREF_1_0                   0x4000
+#define PHY_TUNE_VBGSEL_1252                   0x0C00
+#define PHY_TUNE_SDBUS_33                      0x0200
+#define PHY_TUNE_TUNED18                       0x01C0
+#define PHY_TUNE_TUNED12                       0X0020
+
+#define PHY_BPCR_IBRXSEL                       0x0400
+#define PHY_BPCR_IBTXSEL                       0x0100
+#define PHY_BPCR_IB_FILTER                     0x0080
+#define PHY_BPCR_CMIRROR_EN                    0x0040
+
+#define PHY_REG_REV_RESV                       0xE000
+#define PHY_REG_REV_RXIDLE_LATCHED             0x1000
+#define PHY_REG_REV_P1_EN                      0x0800
+#define PHY_REG_REV_RXIDLE_EN                  0x0400
+#define PHY_REG_REV_CLKREQ_DLY_TIMER_1_0       0x0040
+#define PHY_REG_REV_STOP_CLKRD                 0x0020
+#define PHY_REG_REV_RX_PWST                    0x0008
+#define PHY_REG_REV_STOP_CLKWR                 0x0004
+
+#define PHY_FLD3_TIMER_4                       0x7800
+#define PHY_FLD3_TIMER_6                       0x00E0
+#define PHY_FLD3_RXDELINK                      0x0004
+
+#define PHY_FLD4_FLDEN_SEL                     0x4000
+#define PHY_FLD4_REQ_REF                       0x2000
+#define PHY_FLD4_RXAMP_OFF                     0x1000
+#define PHY_FLD4_REQ_ADDA                      0x0800
+#define PHY_FLD4_BER_COUNT                     0x00E0
+#define PHY_FLD4_BER_TIMER                     0x000A
+#define PHY_FLD4_BER_CHK_EN                    0x0001
+
 #define rtsx_pci_init_cmd(pcr)         ((pcr)->ci = 0)
 
 struct rtsx_pcr;
index ba89b94e4a567ee5499ccd8964eb3526928654bf..674b45d5a757bc66fff49abb26aebed88929c9b0 100644 (file)
@@ -316,7 +316,7 @@ enum si476x_smoothmetrics {
  * response to 'FM_RD_STATUS' command
  * @rdstpptyint: Traffic program flag(TP) and/or program type(PTY)
  * code has changed.
- * @rdspiint: Program indentifiaction(PI) code has changed.
+ * @rdspiint: Program identification(PI) code has changed.
  * @rdssyncint: RDS synchronization has changed.
  * @rdsfifoint: RDS was received and the RDS FIFO has at least
  * 'FM_RDS_INTERRUPT_FIFO_COUNT' elements in it.
diff --git a/include/linux/mfd/stw481x.h b/include/linux/mfd/stw481x.h
new file mode 100644 (file)
index 0000000..eda1215
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011 ST-Ericsson SA
+ * Written on behalf of Linaro for ST-Ericsson
+ *
+ * Author: Linus Walleij <linus.walleij@linaro.org>
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+#ifndef MFD_STW481X_H
+#define MFD_STW481X_H
+
+#include <linux/i2c.h>
+#include <linux/regulator/machine.h>
+#include <linux/regmap.h>
+#include <linux/bitops.h>
+
+/* These registers are accessed from more than one driver */
+#define STW_CONF1                      0x11U
+#define STW_CONF1_PDN_VMMC             0x01U
+#define STW_CONF1_VMMC_MASK            0x0eU
+#define STW_CONF1_VMMC_1_8V            0x02U
+#define STW_CONF1_VMMC_2_85V           0x04U
+#define STW_CONF1_VMMC_3V              0x06U
+#define STW_CONF1_VMMC_1_85V           0x08U
+#define STW_CONF1_VMMC_2_6V            0x0aU
+#define STW_CONF1_VMMC_2_7V            0x0cU
+#define STW_CONF1_VMMC_3_3V            0x0eU
+#define STW_CONF1_MMC_LS_STATUS                0x10U
+#define STW_PCTL_REG_LO                        0x1eU
+#define STW_PCTL_REG_HI                        0x1fU
+#define STW_CONF1_V_MONITORING         0x20U
+#define STW_CONF1_IT_WARN              0x40U
+#define STW_CONF1_PDN_VAUX             0x80U
+#define STW_CONF2                      0x20U
+#define STW_CONF2_MASK_TWARN           0x01U
+#define STW_CONF2_VMMC_EXT             0x02U
+#define STW_CONF2_MASK_IT_WAKE_UP      0x04U
+#define STW_CONF2_GPO1                 0x08U
+#define STW_CONF2_GPO2                 0x10U
+#define STW_VCORE_SLEEP                        0x21U
+
+/**
+ * struct stw481x - state holder for the Stw481x drivers
+ * @mutex: mutex to serialize I2C accesses
+ * @i2c_client: corresponding I2C client
+ * @regulator: regulator device for regulator children
+ * @map: regmap handle to access device registers
+ */
+struct stw481x {
+       struct mutex            lock;
+       struct i2c_client       *client;
+       struct regulator_dev    *vmmc_regulator;
+       struct regmap           *map;
+};
+
+#endif
index b473577f36db5fad660396618ed5fd870e008407..8789fa3c7fd9d75dbc7fef3a0217ed3700112a35 100644 (file)
 
 struct device_node;
 
+#ifdef CONFIG_MFD_SYSCON
 extern struct regmap *syscon_node_to_regmap(struct device_node *np);
 extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s);
 extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s);
 extern struct regmap *syscon_regmap_lookup_by_phandle(
                                        struct device_node *np,
                                        const char *property);
+#else
+static inline struct regmap *syscon_node_to_regmap(struct device_node *np)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
+static inline struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
+static inline struct regmap *syscon_regmap_lookup_by_pdevname(const char *s)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
+static inline struct regmap *syscon_regmap_lookup_by_phandle(
+                                       struct device_node *np,
+                                       const char *property)
+{
+       return ERR_PTR(-ENOSYS);
+}
+#endif
+
 #endif /* __LINUX_MFD_SYSCON_H__ */
index 08cce7f96ab9365359c30a4726d910022f571be5..d498d98f0c2cbfd3c9076aa439433a23caa80899 100644 (file)
 #define FIFO1_THRESHOLD                19
 
 /*
-* ADC runs at 3MHz, and it takes
-* 15 cycles to latch one data output.
-* Hence the idle time for ADC to
-* process one sample data would be
-* around 5 micro seconds.
-*/
-#define IDLE_TIMEOUT 5 /* microsec */
+ * time in us for processing a single channel, calculated as follows:
+ *
+ * num cycles = open delay + (sample delay + conv time) * averaging
+ *
+ * num cycles: 152 + (1 + 13) * 16 = 376
+ *
+ * clock frequency: 26MHz / 8 = 3.25MHz
+ * clock period: 1 / 3.25MHz = 308ns
+ *
+ * processing time: 376 * 308ns = 116us
+ */
+#define IDLE_TIMEOUT 116 /* microsec */
 
 #define TSCADC_CELLS           2
 
@@ -155,6 +160,7 @@ struct ti_tscadc_dev {
        struct mfd_cell cells[TSCADC_CELLS];
        u32 reg_se_cache;
        spinlock_t reg_lock;
+       unsigned int clk_div;
 
        /* tsc device */
        struct titsc *tsc;
index 40854ac0ba3d0cc6fdfd3116275db97d15ec3811..eefafa62d3044d8f1a828a8a5f44d454251193ba 100644 (file)
@@ -56,8 +56,6 @@ struct irq_domain;
 #define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
 
 struct wm8994 {
-       struct mutex irq_lock;
-
        struct wm8994_pdata pdata;
 
        enum wm8994_type type;
@@ -85,16 +83,43 @@ struct wm8994 {
 };
 
 /* Device I/O API */
-int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg);
-int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
-                unsigned short val);
-int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
-                   unsigned short mask, unsigned short val);
-int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
-                    int count, u16 *buf);
-int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
-                    int count, const u16 *buf);
 
+static inline int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg)
+{
+       unsigned int val;
+       int ret;
+
+       ret = regmap_read(wm8994->regmap, reg, &val);
+
+       if (ret < 0)
+               return ret;
+       else
+               return val;
+}
+
+static inline int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg,
+                                  unsigned short val)
+{
+       return regmap_write(wm8994->regmap, reg, val);
+}
+
+static inline int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
+                                  int count, u16 *buf)
+{
+       return regmap_bulk_read(wm8994->regmap, reg, buf, count);
+}
+
+static inline int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg,
+                                   int count, const u16 *buf)
+{
+       return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16));
+}
+
+static inline int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
+                   unsigned short mask, unsigned short val)
+{
+       return regmap_update_bits(wm8994->regmap, reg, mask, val);
+}
 
 /* Helper to save on boilerplate */
 static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
index 5eb4e31af22b8e05356dfef793c1b96497af8cb3..da78875807fc33bb7c77dff5d374e474ba815f31 100644 (file)
@@ -230,6 +230,15 @@ enum {
        MLX5_MAX_PAGE_SHIFT             = 31
 };
 
+enum {
+       MLX5_ADAPTER_PAGE_SHIFT         = 12
+};
+
+enum {
+       MLX5_CAP_OFF_DCT                = 41,
+       MLX5_CAP_OFF_CMDIF_CSUM         = 46,
+};
+
 struct mlx5_inbox_hdr {
        __be16          opcode;
        u8              rsvd[4];
@@ -319,9 +328,9 @@ struct mlx5_hca_cap {
        u8      rsvd25[42];
        __be16  log_uar_page_sz;
        u8      rsvd26[28];
-       u8      log_msx_atomic_size_qp;
+       u8      log_max_atomic_size_qp;
        u8      rsvd27[2];
-       u8      log_msx_atomic_size_dc;
+       u8      log_max_atomic_size_dc;
        u8      rsvd28[76];
 };
 
index 6b8c496572c841d8ec8be70740557f1caf50b79a..554548cd3dd4683145ce5ef0a4b1e66fb829365d 100644 (file)
@@ -483,6 +483,7 @@ struct mlx5_priv {
        struct rb_root          page_root;
        int                     fw_pages;
        int                     reg_pages;
+       struct list_head        free_list;
 
        struct mlx5_core_health health;
 
@@ -557,9 +558,11 @@ typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
 struct mlx5_cmd_work_ent {
        struct mlx5_cmd_msg    *in;
        struct mlx5_cmd_msg    *out;
+       void                   *uout;
+       int                     uout_size;
        mlx5_cmd_cbk_t          callback;
        void                   *context;
-       int idx;
+       int                     idx;
        struct completion       done;
        struct mlx5_cmd        *cmd;
        struct work_struct      work;
@@ -570,6 +573,7 @@ struct mlx5_cmd_work_ent {
        u8                      token;
        struct timespec         ts1;
        struct timespec         ts2;
+       u16                     op;
 };
 
 struct mlx5_pas {
@@ -653,6 +657,9 @@ void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
 int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr);
 int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
                  int out_size);
+int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
+                    void *out, int out_size, mlx5_cmd_cbk_t callback,
+                    void *context);
 int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
 int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
 int mlx5_alloc_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari);
@@ -676,7 +683,9 @@ int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
 int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
                      u16 lwm, int is_srq);
 int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
-                         struct mlx5_create_mkey_mbox_in *in, int inlen);
+                         struct mlx5_create_mkey_mbox_in *in, int inlen,
+                         mlx5_cmd_cbk_t callback, void *context,
+                         struct mlx5_create_mkey_mbox_out *out);
 int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr);
 int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
                         struct mlx5_query_mkey_mbox_out *out, int outlen);
@@ -745,6 +754,11 @@ static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
        return mkey_idx << 8;
 }
 
+static inline u8 mlx5_mkey_variant(u32 mkey)
+{
+       return mkey & 0xff;
+}
+
 enum {
        MLX5_PROF_MASK_QP_SIZE          = (u64)1 << 0,
        MLX5_PROF_MASK_MR_CACHE         = (u64)1 << 1,
index 842de3e21e70c4125f3d1574ebb0391a8d2b4cd5..176fdf824b14733bf5a37ca48a3f7993f7544048 100644 (file)
@@ -240,6 +240,7 @@ struct mmc_part {
 struct mmc_card {
        struct mmc_host         *host;          /* the host this device belongs to */
        struct device           dev;            /* the device */
+       u32                     ocr;            /* the current OCR setting */
        unsigned int            rca;            /* relative card address of device */
        unsigned int            type;           /* card type */
 #define MMC_TYPE_MMC           0               /* MMC card */
@@ -257,6 +258,7 @@ struct mmc_card {
 #define MMC_CARD_REMOVED       (1<<7)          /* card has been removed */
 #define MMC_STATE_HIGHSPEED_200        (1<<8)          /* card is in HS200 mode */
 #define MMC_STATE_DOING_BKOPS  (1<<10)         /* card is doing BKOPS */
+#define MMC_STATE_SUSPENDED    (1<<11)         /* card is suspended */
        unsigned int            quirks;         /* card quirks */
 #define MMC_QUIRK_LENIENT_FN0  (1<<0)          /* allow SDIO FN0 writes outside of the VS CCCR range */
 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)   /* use func->cur_blksize */
@@ -420,10 +422,10 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_card_blockaddr(c)  ((c)->state & MMC_STATE_BLOCKADDR)
 #define mmc_card_ddr_mode(c)   ((c)->state & MMC_STATE_HIGHSPEED_DDR)
 #define mmc_card_uhs(c)                ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
-#define mmc_sd_card_uhs(c)     ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
 #define mmc_card_removed(c)    ((c) && ((c)->state & MMC_CARD_REMOVED))
 #define mmc_card_doing_bkops(c)        ((c)->state & MMC_STATE_DOING_BKOPS)
+#define mmc_card_suspended(c)  ((c)->state & MMC_STATE_SUSPENDED)
 
 #define mmc_card_set_present(c)        ((c)->state |= MMC_STATE_PRESENT)
 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
@@ -432,11 +434,12 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
 #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
 #define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
-#define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
 #define mmc_card_set_doing_bkops(c)    ((c)->state |= MMC_STATE_DOING_BKOPS)
 #define mmc_card_clr_doing_bkops(c)    ((c)->state &= ~MMC_STATE_DOING_BKOPS)
+#define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
+#define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
 
 /*
  * Quirk add/remove for MMC products.
index da51bec578c33043c156d6661668e8957f5cb86f..87079fc38011ccaca33f4ef6ad7d5d055ed3087e 100644 (file)
@@ -151,7 +151,8 @@ extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);
 extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
        struct mmc_command *, int);
 extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
-extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool);
+extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool,
+                       bool);
 extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
 extern int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
 
@@ -188,7 +189,6 @@ extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
 
 extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
 extern void mmc_release_host(struct mmc_host *host);
-extern int mmc_try_claim_host(struct mmc_host *host);
 
 extern void mmc_get_card(struct mmc_card *card);
 extern void mmc_put_card(struct mmc_card *card);
index 198f0fa44e9fd5c8f2b351c38f7679f165f89f7b..6ce7d2cd3c7ad7dd5eea530192de207b3d1aef22 100644 (file)
@@ -15,6 +15,7 @@
 #define LINUX_MMC_DW_MMC_H
 
 #include <linux/scatterlist.h>
+#include <linux/mmc/core.h>
 
 #define MAX_MCI_SLOTS  2
 
@@ -129,6 +130,9 @@ struct dw_mci {
        struct mmc_request      *mrq;
        struct mmc_command      *cmd;
        struct mmc_data         *data;
+       struct mmc_command      stop_abort;
+       unsigned int            prev_blksz;
+       unsigned char           timing;
        struct workqueue_struct *card_workqueue;
 
        /* DMA interface members*/
index 3b0c33ae13e1d7b32b051a2cb9a673d641914876..99f5709ac343df3d6c5b7bbda636eeeb42c4e14c 100644 (file)
@@ -254,6 +254,7 @@ struct mmc_host {
 #define MMC_CAP_UHS_SDR50      (1 << 17)       /* Host supports UHS SDR50 mode */
 #define MMC_CAP_UHS_SDR104     (1 << 18)       /* Host supports UHS SDR104 mode */
 #define MMC_CAP_UHS_DDR50      (1 << 19)       /* Host supports UHS DDR50 mode */
+#define MMC_CAP_RUNTIME_RESUME (1 << 20)       /* Resume at runtime_resume. */
 #define MMC_CAP_DRIVER_TYPE_A  (1 << 23)       /* Host supports Driver Type A */
 #define MMC_CAP_DRIVER_TYPE_C  (1 << 24)       /* Host supports Driver Type C */
 #define MMC_CAP_DRIVER_TYPE_D  (1 << 25)       /* Host supports Driver Type D */
@@ -309,7 +310,6 @@ struct mmc_host {
        spinlock_t              lock;           /* lock for claim and bus ops */
 
        struct mmc_ios          ios;            /* current io bus settings */
-       u32                     ocr;            /* the current OCR setting */
 
        /* group bitfields together to minimize padding */
        unsigned int            use_spi_crc:1;
@@ -382,9 +382,6 @@ static inline void *mmc_priv(struct mmc_host *host)
 #define mmc_classdev(x)        (&(x)->class_dev)
 #define mmc_hostname(x)        (dev_name(&(x)->class_dev))
 
-int mmc_suspend_host(struct mmc_host *);
-int mmc_resume_host(struct mmc_host *);
-
 int mmc_power_save_host(struct mmc_host *host);
 int mmc_power_restore_host(struct mmc_host *host);
 
index 8b3de7cc2ffc24f12ade53f8680d2851d7bf031b..7f0ed423a3606f1cc13e09a00d332dc4a45f924b 100644 (file)
@@ -1587,7 +1587,7 @@ static inline void *netdev_priv(const struct net_device *dev)
 #define SET_NETDEV_DEV(net, pdev)      ((net)->dev.parent = (pdev))
 
 /* Set the sysfs device type for the network logical device to allow
- * fin grained indentification of different network device types. For
+ * fine-grained identification of different network device types. For
  * example Ethernet, Wirelss LAN, Bluetooth, WiMAX etc.
  */
 #define SET_NETDEV_DEVTYPE(net, devtype)       ((net)->dev.type = (devtype))
index c6f41b616965b7b872879d873e49473e0fe81a6e..c1637062c1ce138129a87dd571a5ea7cd2b53abd 100644 (file)
@@ -118,6 +118,9 @@ Needs to be updated if more operations are defined in future.*/
 
 #define FIRST_NFS4_OP  OP_ACCESS
 #define LAST_NFS4_OP   OP_RECLAIM_COMPLETE
+#define LAST_NFS40_OP  OP_RELEASE_LOCKOWNER
+#define LAST_NFS41_OP  OP_RECLAIM_COMPLETE
+#define LAST_NFS42_OP  OP_RECLAIM_COMPLETE
 
 enum nfsstat4 {
        NFS4_OK = 0,
index d006f0ca60f46e92705fb8b3fd315ebacc5242b2..5a462c4e5009d68960525d2167728d59ee75e33b 100644 (file)
@@ -27,7 +27,7 @@ static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
        while (!pci_is_root_bus(pbus))
                pbus = pbus->parent;
 
-       return DEVICE_ACPI_HANDLE(pbus->bridge);
+       return ACPI_HANDLE(pbus->bridge);
 }
 
 static inline acpi_handle acpi_pci_get_bridge_handle(struct pci_bus *pbus)
@@ -39,7 +39,7 @@ static inline acpi_handle acpi_pci_get_bridge_handle(struct pci_bus *pbus)
        else
                dev = &pbus->self->dev;
 
-       return DEVICE_ACPI_HANDLE(dev);
+       return ACPI_HANDLE(dev);
 }
 
 void acpi_pci_add_bus(struct pci_bus *bus);
diff --git a/include/linux/platform_data/at24.h b/include/linux/platform_data/at24.h
new file mode 100644 (file)
index 0000000..c42aa89
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * at24.h - platform_data for the at24 (generic eeprom) driver
+ * (C) Copyright 2008 by Pengutronix
+ * (C) Copyright 2012 by Wolfram Sang
+ * same license as the driver
+ */
+
+#ifndef _LINUX_AT24_H
+#define _LINUX_AT24_H
+
+#include <linux/types.h>
+#include <linux/memory.h>
+
+/**
+ * struct at24_platform_data - data to set up at24 (generic eeprom) driver
+ * @byte_len: size of eeprom in byte
+ * @page_size: number of byte which can be written in one go
+ * @flags: tunable options, check AT24_FLAG_* defines
+ * @setup: an optional callback invoked after eeprom is probed; enables kernel
+       code to access eeprom via memory_accessor, see example
+ * @context: optional parameter passed to setup()
+ *
+ * If you set up a custom eeprom type, please double-check the parameters.
+ * Especially page_size needs extra care, as you risk data loss if your value
+ * is bigger than what the chip actually supports!
+ *
+ * An example in pseudo code for a setup() callback:
+ *
+ * void get_mac_addr(struct memory_accessor *mem_acc, void *context)
+ * {
+ *     u8 *mac_addr = ethernet_pdata->mac_addr;
+ *     off_t offset = context;
+ *
+ *     // Read MAC addr from EEPROM
+ *     if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN)
+ *             pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
+ * }
+ *
+ * This function pointer and context can now be set up in at24_platform_data.
+ */
+
+struct at24_platform_data {
+       u32             byte_len;               /* size (sum of all addr) */
+       u16             page_size;              /* for writes */
+       u8              flags;
+#define AT24_FLAG_ADDR16       0x80    /* address pointer is 16 bit */
+#define AT24_FLAG_READONLY     0x40    /* sysfs-entry will be read-only */
+#define AT24_FLAG_IRUGO                0x20    /* sysfs-entry will be world-readable */
+#define AT24_FLAG_TAKE8ADDR    0x10    /* take always 8 addresses (24c00) */
+
+       void            (*setup)(struct memory_accessor *, void *context);
+       void            *context;
+};
+
+#endif /* _LINUX_AT24_H */
index 179fb91bb5f2eaef7354e37411628f90a6c02335..f50821cb64be8c11165659b0f0719398bfa004cf 100644 (file)
@@ -67,10 +67,10 @@ struct edmacc_param {
 #define ITCCHEN                BIT(23)
 
 /*ch_status paramater of callback function possible values*/
-#define DMA_COMPLETE 1
-#define DMA_CC_ERROR 2
-#define DMA_TC1_ERROR 3
-#define DMA_TC2_ERROR 4
+#define EDMA_DMA_COMPLETE 1
+#define EDMA_DMA_CC_ERROR 2
+#define EDMA_DMA_TC1_ERROR 3
+#define EDMA_DMA_TC2_ERROR 4
 
 enum address_mode {
        INCR = 0,
index d44912d81578d072b8dab544254d58682ce39ab7..75f70f6ac13778f448a03de3136d32a0ef638b65 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef __ASM_ARCH_IMX_ESDHC_H
 #define __ASM_ARCH_IMX_ESDHC_H
 
+#include <linux/types.h>
+
 enum wp_types {
        ESDHC_WP_NONE,          /* no WP, neither controller nor gpio */
        ESDHC_WP_CONTROLLER,    /* mmc controller internal WP */
@@ -32,6 +34,7 @@ enum cd_types {
  * @cd_gpio:   gpio for card_detect interrupt
  * @wp_type:   type of write_protect method (see wp_types enum above)
  * @cd_type:   type of card_detect method (see cd_types enum above)
+ * @support_vsel:  indicate it supports 1.8v switching
  */
 
 struct esdhc_platform_data {
@@ -41,5 +44,7 @@ struct esdhc_platform_data {
        enum cd_types cd_type;
        int max_bus_width;
        unsigned int f_max;
+       bool support_vsel;
+       unsigned int delay_line;
 };
 #endif /* __ASM_ARCH_IMX_ESDHC_H */
diff --git a/include/linux/platform_data/zforce_ts.h b/include/linux/platform_data/zforce_ts.h
new file mode 100644 (file)
index 0000000..0472ab2
--- /dev/null
@@ -0,0 +1,26 @@
+/* drivers/input/touchscreen/zforce.c
+ *
+ * Copyright (C) 2012-2013 MundoReader S.L.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _LINUX_INPUT_ZFORCE_TS_H
+#define _LINUX_INPUT_ZFORCE_TS_H
+
+struct zforce_ts_platdata {
+       int gpio_int;
+       int gpio_rst;
+
+       unsigned int x_max;
+       unsigned int y_max;
+};
+
+#endif /* _LINUX_INPUT_ZFORCE_TS_H */
diff --git a/include/linux/power/bq24735-charger.h b/include/linux/power/bq24735-charger.h
new file mode 100644 (file)
index 0000000..f536164
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __CHARGER_BQ24735_H_
+#define __CHARGER_BQ24735_H_
+
+#include <linux/types.h>
+#include <linux/power_supply.h>
+
+struct bq24735_platform {
+       uint32_t charge_current;
+       uint32_t charge_voltage;
+       uint32_t input_current;
+
+       const char *name;
+
+       int status_gpio;
+       int status_gpio_active_low;
+       bool status_gpio_valid;
+
+       char **supplied_to;
+       size_t num_supplicants;
+};
+
+#endif /* __CHARGER_BQ24735_H_ */
index 931bc616219f626562364ba289d55a84f2ef2ba0..d169820203dd825e54bd35479954e162509e78d8 100644 (file)
  * - bits 0-7 are the preemption count (max preemption depth: 256)
  * - bits 8-15 are the softirq count (max # of softirqs: 256)
  *
- * The hardirq count can in theory reach the same as NR_IRQS.
- * In reality, the number of nested IRQS is limited to the stack
- * size as well. For archs with over 1000 IRQS it is not practical
- * to expect that they will all nest. We give a max of 10 bits for
- * hardirq nesting. An arch may choose to give less than 10 bits.
- * m68k expects it to be 8.
+ * The hardirq count could in theory be the same as the number of
+ * interrupts in the system, but we run all interrupt handlers with
+ * interrupts disabled, so we cannot have nesting interrupts. Though
+ * there are a few palaeontologic drivers which reenable interrupts in
+ * the handler, so we need more than one bit here.
  *
- * - bits 16-25 are the hardirq count (max # of nested hardirqs: 1024)
- * - bit 26 is the NMI_MASK
- * - bit 27 is the PREEMPT_ACTIVE flag
- *
- * PREEMPT_MASK: 0x000000ff
- * SOFTIRQ_MASK: 0x0000ff00
- * HARDIRQ_MASK: 0x03ff0000
- *     NMI_MASK: 0x04000000
+ * PREEMPT_MASK:       0x000000ff
+ * SOFTIRQ_MASK:       0x0000ff00
+ * HARDIRQ_MASK:       0x000f0000
+ *     NMI_MASK:       0x00100000
+ * PREEMPT_ACTIVE:     0x00200000
  */
 #define PREEMPT_BITS   8
 #define SOFTIRQ_BITS   8
+#define HARDIRQ_BITS   4
 #define NMI_BITS       1
 
-#define MAX_HARDIRQ_BITS 10
-
-#ifndef HARDIRQ_BITS
-# define HARDIRQ_BITS  MAX_HARDIRQ_BITS
-#endif
-
-#if HARDIRQ_BITS > MAX_HARDIRQ_BITS
-#error HARDIRQ_BITS too high!
-#endif
-
 #define PREEMPT_SHIFT  0
 #define SOFTIRQ_SHIFT  (PREEMPT_SHIFT + PREEMPT_BITS)
 #define HARDIRQ_SHIFT  (SOFTIRQ_SHIFT + SOFTIRQ_BITS)
 
 #define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
 
-#ifndef PREEMPT_ACTIVE
 #define PREEMPT_ACTIVE_BITS    1
 #define PREEMPT_ACTIVE_SHIFT   (NMI_SHIFT + NMI_BITS)
 #define PREEMPT_ACTIVE (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT)
-#endif
-
-#if PREEMPT_ACTIVE < (1 << (NMI_SHIFT + NMI_BITS))
-#error PREEMPT_ACTIVE is too low!
-#endif
 
 #define hardirq_count()        (preempt_count() & HARDIRQ_MASK)
 #define softirq_count()        (preempt_count() & SOFTIRQ_MASK)
index 56f4a866539ad7b66476fc3d1c09d15ab8ad2be1..2de2e275b2cbd1390ec6693d8f436b05352da16a 100644 (file)
@@ -6,6 +6,9 @@
 
 #include <linux/backlight.h>
 
+/* TODO: convert to gpiod_*() API once it has been merged */
+#define PWM_BACKLIGHT_GPIO_ACTIVE_LOW  (1 << 0)
+
 struct platform_pwm_backlight_data {
        int pwm_id;
        unsigned int max_brightness;
@@ -13,6 +16,8 @@ struct platform_pwm_backlight_data {
        unsigned int lth_brightness;
        unsigned int pwm_period_ns;
        unsigned int *levels;
+       int enable_gpio;
+       unsigned long enable_gpio_flags;
        int (*init)(struct device *dev);
        int (*notify)(struct device *dev, int brightness);
        void (*notify_after)(struct device *dev, int brightness);
index 6f7ffa460089796b324682e2a1c1fc5047f97da3..7e35d4b9e14a45cba37fd8a7f234e5a3a50ec4b5 100644 (file)
@@ -22,7 +22,7 @@ struct sched_param {
 #include <linux/errno.h>
 #include <linux/nodemask.h>
 #include <linux/mm_types.h>
-#include <linux/preempt.h>
+#include <linux/preempt_mask.h>
 
 #include <asm/page.h>
 #include <asm/ptrace.h>
index 215b5ea1cb302c43f0e8b9532fbe3ce59ff0f612..bec1cc7d5e3c41efbc4939ab742eeb955b64b7f0 100644 (file)
@@ -2263,24 +2263,6 @@ static inline void skb_postpull_rcsum(struct sk_buff *skb,
 
 unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);
 
-/**
- *     pskb_trim_rcsum - trim received skb and update checksum
- *     @skb: buffer to trim
- *     @len: new length
- *
- *     This is exactly the same as pskb_trim except that it ensures the
- *     checksum of received packets are still valid after the operation.
- */
-
-static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
-{
-       if (likely(len >= skb->len))
-               return 0;
-       if (skb->ip_summed == CHECKSUM_COMPLETE)
-               skb->ip_summed = CHECKSUM_NONE;
-       return __pskb_trim(skb, len);
-}
-
 #define skb_queue_walk(queue, skb) \
                for (skb = (queue)->next;                                       \
                     skb != (struct sk_buff *)(queue);                          \
@@ -2378,6 +2360,27 @@ __wsum __skb_checksum(const struct sk_buff *skb, int offset, int len,
 __wsum skb_checksum(const struct sk_buff *skb, int offset, int len,
                    __wsum csum);
 
+/**
+ *     pskb_trim_rcsum - trim received skb and update checksum
+ *     @skb: buffer to trim
+ *     @len: new length
+ *
+ *     This is exactly the same as pskb_trim except that it ensures the
+ *     checksum of received packets are still valid after the operation.
+ */
+
+static inline int pskb_trim_rcsum(struct sk_buff *skb, unsigned int len)
+{
+       if (likely(len >= skb->len))
+               return 0;
+       if (skb->ip_summed == CHECKSUM_COMPLETE) {
+               __wsum adj = skb_checksum(skb, len, skb->len - len, 0);
+
+               skb->csum = csum_sub(skb->csum, adj);
+       }
+       return __pskb_trim(skb, len);
+}
+
 static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
                                       int len, void *buffer)
 {
index c27f846f6b71ae10cc5a98de630f55e898b2c8e5..94273bbe605007462f6e0daacf01715f2a7aca6a 100644 (file)
@@ -120,7 +120,7 @@ extern struct trace_event_functions exit_syscall_print_funcs;
                .class                  = &event_class_syscall_enter,   \
                .event.funcs            = &enter_syscall_print_funcs,   \
                .data                   = (void *)&__syscall_meta_##sname,\
-               .flags                  = TRACE_EVENT_FL_CAP_ANY,       \
+               .flags                  = TRACE_EVENT_FL_CAP_ANY,       \
        };                                                              \
        static struct ftrace_event_call __used                          \
          __attribute__((section("_ftrace_events")))                    \
@@ -134,7 +134,7 @@ extern struct trace_event_functions exit_syscall_print_funcs;
                .class                  = &event_class_syscall_exit,    \
                .event.funcs            = &exit_syscall_print_funcs,    \
                .data                   = (void *)&__syscall_meta_##sname,\
-               .flags                  = TRACE_EVENT_FL_CAP_ANY,       \
+               .flags                  = TRACE_EVENT_FL_CAP_ANY,       \
        };                                                              \
        static struct ftrace_event_call __used                          \
          __attribute__((section("_ftrace_events")))                    \
index 61939ba30aa0abdbe7e36e608343338c80fada6b..eaa00b10abaaa53cf441170841c3faec588e9de0 100644 (file)
@@ -278,6 +278,31 @@ do {                                                                       \
        __ret;                                                          \
 })
 
+#define __wait_event_cmd(wq, condition, cmd1, cmd2)                    \
+       (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0,  \
+                           cmd1; schedule(); cmd2)
+
+/**
+ * wait_event_cmd - sleep until a condition gets true
+ * @wq: the waitqueue to wait on
+ * @condition: a C expression for the event to wait for
+ * cmd1: the command will be executed before sleep
+ * cmd2: the command will be executed after sleep
+ *
+ * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
+ * @condition evaluates to true. The @condition is checked each time
+ * the waitqueue @wq is woken up.
+ *
+ * wake_up() has to be called after changing any variable that could
+ * change the result of the wait condition.
+ */
+#define wait_event_cmd(wq, condition, cmd1, cmd2)                      \
+do {                                                                   \
+       if (condition)                                                  \
+               break;                                                  \
+       __wait_event_cmd(wq, condition, cmd1, cmd2);                    \
+} while (0)
+
 #define __wait_event_interruptible(wq, condition)                      \
        ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,          \
                      schedule())
diff --git a/include/media/lm3560.h b/include/media/lm3560.h
new file mode 100644 (file)
index 0000000..4667070
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * include/media/lm3560.h
+ *
+ * Copyright (C) 2013 Texas Instruments
+ *
+ * Contact: Daniel Jeong <gshark.jeong@gmail.com>
+ *                     Ldd-Mlp <ldd-mlp@list.ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __LM3560_H__
+#define __LM3560_H__
+
+#include <media/v4l2-subdev.h>
+
+#define LM3560_NAME    "lm3560"
+#define LM3560_I2C_ADDR        (0x53)
+
+/*  FLASH Brightness
+ *     min 62500uA, step 62500uA, max 1000000uA
+ */
+#define LM3560_FLASH_BRT_MIN 62500
+#define LM3560_FLASH_BRT_STEP 62500
+#define LM3560_FLASH_BRT_MAX 1000000
+#define LM3560_FLASH_BRT_uA_TO_REG(a)  \
+       ((a) < LM3560_FLASH_BRT_MIN ? 0 :       \
+        (((a) - LM3560_FLASH_BRT_MIN) / LM3560_FLASH_BRT_STEP))
+#define LM3560_FLASH_BRT_REG_TO_uA(a)          \
+       ((a) * LM3560_FLASH_BRT_STEP + LM3560_FLASH_BRT_MIN)
+
+/*  FLASH TIMEOUT DURATION
+ *     min 32ms, step 32ms, max 1024ms
+ */
+#define LM3560_FLASH_TOUT_MIN 32
+#define LM3560_FLASH_TOUT_STEP 32
+#define LM3560_FLASH_TOUT_MAX 1024
+#define LM3560_FLASH_TOUT_ms_TO_REG(a) \
+       ((a) < LM3560_FLASH_TOUT_MIN ? 0 :      \
+        (((a) - LM3560_FLASH_TOUT_MIN) / LM3560_FLASH_TOUT_STEP))
+#define LM3560_FLASH_TOUT_REG_TO_ms(a)         \
+       ((a) * LM3560_FLASH_TOUT_STEP + LM3560_FLASH_TOUT_MIN)
+
+/*  TORCH BRT
+ *     min 31250uA, step 31250uA, max 250000uA
+ */
+#define LM3560_TORCH_BRT_MIN 31250
+#define LM3560_TORCH_BRT_STEP 31250
+#define LM3560_TORCH_BRT_MAX 250000
+#define LM3560_TORCH_BRT_uA_TO_REG(a)  \
+       ((a) < LM3560_TORCH_BRT_MIN ? 0 :       \
+        (((a) - LM3560_TORCH_BRT_MIN) / LM3560_TORCH_BRT_STEP))
+#define LM3560_TORCH_BRT_REG_TO_uA(a)          \
+       ((a) * LM3560_TORCH_BRT_STEP + LM3560_TORCH_BRT_MIN)
+
+enum lm3560_led_id {
+       LM3560_LED0 = 0,
+       LM3560_LED1,
+       LM3560_LED_MAX
+};
+
+enum lm3560_peak_current {
+       LM3560_PEAK_1600mA = 0x00,
+       LM3560_PEAK_2300mA = 0x20,
+       LM3560_PEAK_3000mA = 0x40,
+       LM3560_PEAK_3600mA = 0x60
+};
+
+/* struct lm3560_platform_data
+ *
+ * @peak :  peak current
+ * @max_flash_timeout: flash timeout
+ * @max_flash_brt: flash mode led brightness
+ * @max_torch_brt: torch mode led brightness
+ */
+struct lm3560_platform_data {
+       enum lm3560_peak_current peak;
+
+       u32 max_flash_timeout;
+       u32 max_flash_brt[LM3560_LED_MAX];
+       u32 max_torch_brt[LM3560_LED_MAX];
+};
+
+#endif /* __LM3560_H__ */
index 34d2414f2b8c0a6207fb3d4dfe2c34d644f7d6aa..865246b001279ec611b5c7c8b3d23b194217d6f1 100644 (file)
@@ -146,9 +146,14 @@ struct soc_camera_subdev_desc {
        /* sensor driver private platform data */
        void *drv_priv;
 
-       /* Optional regulators that have to be managed on power on/off events */
-       struct regulator_bulk_data *regulators;
-       int num_regulators;
+       /*
+        * Set unbalanced_power to true to deal with legacy drivers, failing to
+        * balance their calls to subdevice's .s_power() method. clock_state is
+        * then used internally by helper functions, it shouldn't be touched by
+        * drivers or the platform code.
+        */
+       bool unbalanced_power;
+       unsigned long clock_state;
 
        /* Optional callbacks to power on or off and reset the sensor */
        int (*power)(struct device *, int);
@@ -162,6 +167,9 @@ struct soc_camera_subdev_desc {
        int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
        unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
        void (*free_bus)(struct soc_camera_subdev_desc *);
+
+       /* Optional regulators that have to be managed on power on/off events */
+       struct v4l2_subdev_platform_data sd_pdata;
 };
 
 struct soc_camera_host_desc {
@@ -202,9 +210,10 @@ struct soc_camera_link {
 
        void *priv;
 
-       /* Optional regulators that have to be managed on power on/off events */
-       struct regulator_bulk_data *regulators;
-       int num_regulators;
+       /* Set by platforms to handle misbehaving drivers */
+       bool unbalanced_power;
+       /* Used by soc-camera helper functions */
+       unsigned long clock_state;
 
        /* Optional callbacks to power on or off and reset the sensor */
        int (*power)(struct device *, int);
@@ -218,6 +227,12 @@ struct soc_camera_link {
        unsigned long (*query_bus_param)(struct soc_camera_link *);
        void (*free_bus)(struct soc_camera_link *);
 
+       /* Optional regulators that have to be managed on power on/off events */
+       struct regulator_bulk_data *regulators;
+       int num_regulators;
+
+       void *host_priv;
+
        /*
         * Host part - keep at bottom and compatible to
         * struct soc_camera_host_desc
index 0503a90b48bb2fdab6bfbf4395647cdc599027df..0b36cc138304706e98e5993fc0014b4af9afda43 100644 (file)
@@ -15,6 +15,7 @@
 #define MEDIA_V4L2_CLK_H
 
 #include <linux/atomic.h>
+#include <linux/export.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
 
@@ -51,4 +52,20 @@ void v4l2_clk_disable(struct v4l2_clk *clk);
 unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
 int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
 
+struct module;
+
+struct v4l2_clk *__v4l2_clk_register_fixed(const char *dev_id,
+               const char *id, unsigned long rate, struct module *owner);
+void v4l2_clk_unregister_fixed(struct v4l2_clk *clk);
+
+static inline struct v4l2_clk *v4l2_clk_register_fixed(const char *dev_id,
+                                                       const char *id,
+                                                       unsigned long rate)
+{
+       return __v4l2_clk_register_fixed(dev_id, id, rate, THIS_MODULE);
+}
+
+#define v4l2_clk_name_i2c(name, size, adap, client) snprintf(name, size, \
+                         "%d-%04x", adap, client)
+
 #endif
index 16550c4390081a03a8f2d4c8d3fdc51de54cc006..48f974866f13fe2fd2362ed0c87ccd8c29d59811 100644 (file)
@@ -35,7 +35,7 @@
        printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
 
 #define v4l_client_printk(level, client, fmt, arg...)                      \
-       v4l_printk(level, (client)->driver->driver.name, (client)->adapter, \
+       v4l_printk(level, (client)->dev.driver->name, (client)->adapter, \
                   (client)->addr, fmt , ## arg)
 
 #define v4l_err(client, fmt, arg...) \
@@ -86,7 +86,7 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
                const char * const *menu_items);
 const char *v4l2_ctrl_get_name(u32 id);
 const char * const *v4l2_ctrl_get_menu(u32 id);
-const s64 const *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
+const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
                struct v4l2_queryctrl *qctrl, const char * const *menu_items);
index 47ada23345a195973c3942681566244d50c7f34d..16f7f2606516982d8cf60ef18c3c953e15ac0526 100644 (file)
@@ -571,7 +571,7 @@ static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
        mutex_lock(ctrl->handler->lock);
 }
 
-/** v4l2_ctrl_lock() - Helper function to unlock the handler
+/** v4l2_ctrl_unlock() - Helper function to unlock the handler
   * associated with the control.
   * @ctrl:     The control to unlock.
   */
index a62ee18cb7b799c3982decdb63dc57f520e9b93a..528cdaf622e192aa572ade990b60acf949e74109 100644 (file)
@@ -26,7 +26,9 @@
 #ifndef V4L2_FH_H
 #define V4L2_FH_H
 
+#include <linux/fs.h>
 #include <linux/list.h>
+#include <linux/videodev2.h>
 
 struct video_device;
 struct v4l2_ctrl_handler;
index bfda0fe9aeb05fc494a167cc246d9b500a508be2..d67210a37ef376192dcd70e5004c4b526ea753e8 100644 (file)
@@ -559,6 +559,17 @@ struct v4l2_subdev_internal_ops {
 /* Set this flag if this subdev generates events. */
 #define V4L2_SUBDEV_FL_HAS_EVENTS              (1U << 3)
 
+struct regulator_bulk_data;
+
+struct v4l2_subdev_platform_data {
+       /* Optional regulators uset to power on/off the subdevice */
+       struct regulator_bulk_data *regulators;
+       int num_regulators;
+
+       /* Per-subdevice data, specific for a certain video host device */
+       void *host_priv;
+};
+
 /* Each instance of a subdev driver should create this struct, either
    stand-alone or embedded in a larger struct.
  */
@@ -592,6 +603,8 @@ struct v4l2_subdev {
        struct v4l2_async_subdev *asd;
        /* Pointer to the managing notifier. */
        struct v4l2_async_notifier *notifier;
+       /* common part of subdevice platform data */
+       struct v4l2_subdev_platform_data *pdata;
 };
 
 #define media_entity_to_v4l2_subdev(ent) \
@@ -622,13 +635,13 @@ struct v4l2_subdev_fh {
        v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh,       \
                                       unsigned int pad)                \
        {                                                               \
-               BUG_ON(unlikely(pad >= vdev_to_v4l2_subdev(             \
-                                       fh->vfh.vdev)->entity.num_pads)); \
+               BUG_ON(pad >= vdev_to_v4l2_subdev(                      \
+                                       fh->vfh.vdev)->entity.num_pads); \
                return &fh->pad[pad].field_name;                        \
        }
 
 __V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
-__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
+__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_crop)
 __V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
 #endif
 
index 6781258d0b677f4a7092b4d29d0c1c7094e8a8a0..bd8218b15009a810af8abd5df5a4bcad31dfdb20 100644 (file)
@@ -391,7 +391,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
 unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
 size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
                loff_t *ppos, int nonblock);
-size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count,
+size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
                loff_t *ppos, int nonblock);
 
 /**
@@ -491,7 +491,7 @@ int vb2_ioctl_expbuf(struct file *file, void *priv,
 
 int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
 int vb2_fop_release(struct file *file);
-ssize_t vb2_fop_write(struct file *file, char __user *buf,
+ssize_t vb2_fop_write(struct file *file, const char __user *buf,
                size_t count, loff_t *ppos);
 ssize_t vb2_fop_read(struct file *file, char __user *buf,
                size_t count, loff_t *ppos);
index 0038526b8ef7c0495bf12784a6c3c7a855c0b144..7b89852779af77b0f156f635f7b8e5287d9a9be1 100644 (file)
 
 #include <media/videobuf2-core.h>
 
-struct vb2_dma_sg_desc {
-       unsigned long           size;
-       unsigned int            num_pages;
-       struct scatterlist      *sglist;
-};
-
-static inline struct vb2_dma_sg_desc *vb2_dma_sg_plane_desc(
+static inline struct sg_table *vb2_dma_sg_plane_desc(
                struct vb2_buffer *vb, unsigned int plane_no)
 {
-       return (struct vb2_dma_sg_desc *)vb2_plane_cookie(vb, plane_no);
+       return (struct sg_table *)vb2_plane_cookie(vb, plane_no);
 }
 
 extern const struct vb2_mem_ops vb2_dma_sg_memops;
index 51329905bfaafda1c290a26103914d5879144a01..c853b16de4efde38a501440ce58ca260a379e5da 100644 (file)
@@ -240,7 +240,7 @@ struct l2cap_conn_rsp {
 #define L2CAP_PSM_RFCOMM       0x0003
 #define L2CAP_PSM_3DSP         0x0021
 
-/* channel indentifier */
+/* channel identifier */
 #define L2CAP_CID_SIGNALING    0x0001
 #define L2CAP_CID_CONN_LESS    0x0002
 #define L2CAP_CID_A2MP         0x0003
index 9b787b62cf16066e6f2335301865849fa674f7a1..ace4abf118d7d4b0501fa3c6829001da905e728b 100644 (file)
 /**
  * struct genl_multicast_group - generic netlink multicast group
  * @name: name of the multicast group, names are per-family
- * @id: multicast group ID, assigned by the core, to use with
- *      genlmsg_multicast().
- * @list: list entry for linking
- * @family: pointer to family, need not be set before registering
  */
 struct genl_multicast_group {
-       struct genl_family      *family;        /* private */
-       struct list_head        list;           /* private */
        char                    name[GENL_NAMSIZ];
-       u32                     id;
 };
 
 struct genl_ops;
@@ -39,9 +32,12 @@ struct genl_info;
  * @post_doit: called after an operation's doit callback, it may
  *     undo operations done by pre_doit, for example release locks
  * @attrbuf: buffer to store parsed attributes
- * @ops_list: list of all assigned operations
  * @family_list: family list
- * @mcast_groups: multicast groups list
+ * @mcgrps: multicast groups used by this family (private)
+ * @n_mcgrps: number of multicast groups (private)
+ * @mcgrp_offset: starting number of multicast group IDs in this family
+ * @ops: the operations supported by this family (private)
+ * @n_ops: number of operations supported by this family (private)
  */
 struct genl_family {
        unsigned int            id;
@@ -51,16 +47,19 @@ struct genl_family {
        unsigned int            maxattr;
        bool                    netnsok;
        bool                    parallel_ops;
-       int                     (*pre_doit)(struct genl_ops *ops,
+       int                     (*pre_doit)(const struct genl_ops *ops,
                                            struct sk_buff *skb,
                                            struct genl_info *info);
-       void                    (*post_doit)(struct genl_ops *ops,
+       void                    (*post_doit)(const struct genl_ops *ops,
                                             struct sk_buff *skb,
                                             struct genl_info *info);
        struct nlattr **        attrbuf;        /* private */
-       struct list_head        ops_list;       /* private */
+       const struct genl_ops * ops;            /* private */
+       const struct genl_multicast_group *mcgrps; /* private */
+       unsigned int            n_ops;          /* private */
+       unsigned int            n_mcgrps;       /* private */
+       unsigned int            mcgrp_offset;   /* private */
        struct list_head        family_list;    /* private */
-       struct list_head        mcast_groups;   /* private */
        struct module           *module;
 };
 
@@ -110,16 +109,15 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
  * @ops_list: operations list
  */
 struct genl_ops {
-       u8                      cmd;
-       u8                      internal_flags;
-       unsigned int            flags;
        const struct nla_policy *policy;
        int                    (*doit)(struct sk_buff *skb,
                                       struct genl_info *info);
        int                    (*dumpit)(struct sk_buff *skb,
                                         struct netlink_callback *cb);
        int                    (*done)(struct netlink_callback *cb);
-       struct list_head        ops_list;
+       u8                      cmd;
+       u8                      internal_flags;
+       u8                      flags;
 };
 
 int __genl_register_family(struct genl_family *family);
@@ -130,24 +128,53 @@ static inline int genl_register_family(struct genl_family *family)
        return __genl_register_family(family);
 }
 
-int __genl_register_family_with_ops(struct genl_family *family,
-                                   struct genl_ops *ops, size_t n_ops);
-
-static inline int genl_register_family_with_ops(struct genl_family *family,
-       struct genl_ops *ops, size_t n_ops)
+/**
+ * genl_register_family_with_ops - register a generic netlink family with ops
+ * @family: generic netlink family
+ * @ops: operations to be registered
+ * @n_ops: number of elements to register
+ *
+ * Registers the specified family and operations from the specified table.
+ * Only one family may be registered with the same family name or identifier.
+ *
+ * The family id may equal GENL_ID_GENERATE causing an unique id to
+ * be automatically generated and assigned.
+ *
+ * Either a doit or dumpit callback must be specified for every registered
+ * operation or the function will fail. Only one operation structure per
+ * command identifier may be registered.
+ *
+ * See include/net/genetlink.h for more documenation on the operations
+ * structure.
+ *
+ * Return 0 on success or a negative error code.
+ */
+static inline int
+_genl_register_family_with_ops_grps(struct genl_family *family,
+                                   const struct genl_ops *ops, size_t n_ops,
+                                   const struct genl_multicast_group *mcgrps,
+                                   size_t n_mcgrps)
 {
        family->module = THIS_MODULE;
-       return __genl_register_family_with_ops(family, ops, n_ops);
+       family->ops = ops;
+       family->n_ops = n_ops;
+       family->mcgrps = mcgrps;
+       family->n_mcgrps = n_mcgrps;
+       return __genl_register_family(family);
 }
 
+#define genl_register_family_with_ops(family, ops)                     \
+       _genl_register_family_with_ops_grps((family),                   \
+                                           (ops), ARRAY_SIZE(ops),     \
+                                           NULL, 0)
+#define genl_register_family_with_ops_groups(family, ops, grps)        \
+       _genl_register_family_with_ops_grps((family),                   \
+                                           (ops), ARRAY_SIZE(ops),     \
+                                           (grps), ARRAY_SIZE(grps))
+
 int genl_unregister_family(struct genl_family *family);
-int genl_register_ops(struct genl_family *, struct genl_ops *ops);
-int genl_unregister_ops(struct genl_family *, struct genl_ops *ops);
-int genl_register_mc_group(struct genl_family *family,
-                          struct genl_multicast_group *grp);
-void genl_unregister_mc_group(struct genl_family *family,
-                             struct genl_multicast_group *grp);
-void genl_notify(struct sk_buff *skb, struct net *net, u32 portid,
+void genl_notify(struct genl_family *family,
+                struct sk_buff *skb, struct net *net, u32 portid,
                 u32 group, struct nlmsghdr *nlh, gfp_t flags);
 
 void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
@@ -227,41 +254,54 @@ static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr)
 
 /**
  * genlmsg_multicast_netns - multicast a netlink message to a specific netns
+ * @family: the generic netlink family
  * @net: the net namespace
  * @skb: netlink message as socket buffer
  * @portid: own netlink portid to avoid sending to yourself
- * @group: multicast group id
+ * @group: offset of multicast group in groups array
  * @flags: allocation flags
  */
-static inline int genlmsg_multicast_netns(struct net *net, struct sk_buff *skb,
+static inline int genlmsg_multicast_netns(struct genl_family *family,
+                                         struct net *net, struct sk_buff *skb,
                                          u32 portid, unsigned int group, gfp_t flags)
 {
+       if (group >= family->n_mcgrps)
+               return -EINVAL;
+       group = family->mcgrp_offset + group;
        return nlmsg_multicast(net->genl_sock, skb, portid, group, flags);
 }
 
 /**
  * genlmsg_multicast - multicast a netlink message to the default netns
+ * @family: the generic netlink family
  * @skb: netlink message as socket buffer
  * @portid: own netlink portid to avoid sending to yourself
- * @group: multicast group id
+ * @group: offset of multicast group in groups array
  * @flags: allocation flags
  */
-static inline int genlmsg_multicast(struct sk_buff *skb, u32 portid,
+static inline int genlmsg_multicast(struct genl_family *family,
+                                   struct sk_buff *skb, u32 portid,
                                    unsigned int group, gfp_t flags)
 {
-       return genlmsg_multicast_netns(&init_net, skb, portid, group, flags);
+       if (group >= family->n_mcgrps)
+               return -EINVAL;
+       group = family->mcgrp_offset + group;
+       return genlmsg_multicast_netns(family, &init_net, skb,
+                                      portid, group, flags);
 }
 
 /**
  * genlmsg_multicast_allns - multicast a netlink message to all net namespaces
+ * @family: the generic netlink family
  * @skb: netlink message as socket buffer
  * @portid: own netlink portid to avoid sending to yourself
- * @group: multicast group id
+ * @group: offset of multicast group in groups array
  * @flags: allocation flags
  *
  * This function must hold the RTNL or rcu_read_lock().
  */
-int genlmsg_multicast_allns(struct sk_buff *skb, u32 portid,
+int genlmsg_multicast_allns(struct genl_family *family,
+                           struct sk_buff *skb, u32 portid,
                            unsigned int group, gfp_t flags);
 
 /**
@@ -332,5 +372,22 @@ static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
        return nlmsg_new(genlmsg_total_size(payload), flags);
 }
 
+/**
+ * genl_set_err - report error to genetlink broadcast listeners
+ * @family: the generic netlink family
+ * @net: the network namespace to report the error to
+ * @portid: the PORTID of a process that we want to skip (if any)
+ * @group: the broadcast group that will notice the error
+ *     (this is the offset of the multicast group in the groups array)
+ * @code: error code, must be negative (as usual in kernelspace)
+ *
+ * This function returns the number of broadcast listeners that have set the
+ * NETLINK_RECV_NO_ENOBUFS socket option.
+ */
+static inline int genl_set_err(struct genl_family *family, struct net *net,
+                              u32 portid, u32 group, int code)
+{
+       return netlink_set_err(net->genl_sock, portid, group, code);
+}
 
 #endif /* __NET_GENERIC_NETLINK_H */
index e393171e2facd2ad6317783560ceae6f89f80763..979874c627ee7f450c7aabff5c948cb2c87f84c3 100644 (file)
@@ -67,12 +67,14 @@ enum rdma_node_type {
        RDMA_NODE_IB_CA         = 1,
        RDMA_NODE_IB_SWITCH,
        RDMA_NODE_IB_ROUTER,
-       RDMA_NODE_RNIC
+       RDMA_NODE_RNIC,
+       RDMA_NODE_USNIC,
 };
 
 enum rdma_transport_type {
        RDMA_TRANSPORT_IB,
-       RDMA_TRANSPORT_IWARP
+       RDMA_TRANSPORT_IWARP,
+       RDMA_TRANSPORT_USNIC
 };
 
 enum rdma_transport_type
@@ -1436,6 +1438,7 @@ struct ib_device {
 
        int                          uverbs_abi_ver;
        u64                          uverbs_cmd_mask;
+       u64                          uverbs_ex_cmd_mask;
 
        char                         node_desc[64];
        __be64                       node_guid;
@@ -2384,4 +2387,17 @@ struct ib_flow *ib_create_flow(struct ib_qp *qp,
                               struct ib_flow_attr *flow_attr, int domain);
 int ib_destroy_flow(struct ib_flow *flow_id);
 
+static inline int ib_check_mr_access(int flags)
+{
+       /*
+        * Local write permission is required if remote write or
+        * remote atomic permission is also requested.
+        */
+       if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
+           !(flags & IB_ACCESS_LOCAL_WRITE))
+               return -EINVAL;
+
+       return 0;
+}
+
 #endif /* IB_VERBS_H */
index ff0f04ac91aad7c2311f9b889aa09c0accb90cc6..4ebf6913b7b2e4b5f85ffca6c2963331e2f433a0 100644 (file)
@@ -13,6 +13,27 @@ struct srp_rport_identifiers {
        u8 roles;
 };
 
+/**
+ * enum srp_rport_state - SRP transport layer state
+ * @SRP_RPORT_RUNNING:   Transport layer operational.
+ * @SRP_RPORT_BLOCKED:   Transport layer not operational; fast I/O fail timer
+ *                       is running and I/O has been blocked.
+ * @SRP_RPORT_FAIL_FAST: Fast I/O fail timer has expired; fail I/O fast.
+ * @SRP_RPORT_LOST:      Device loss timer has expired; port is being removed.
+ */
+enum srp_rport_state {
+       SRP_RPORT_RUNNING,
+       SRP_RPORT_BLOCKED,
+       SRP_RPORT_FAIL_FAST,
+       SRP_RPORT_LOST,
+};
+
+/**
+ * struct srp_rport
+ * @lld_data: LLD private data.
+ * @mutex:    Protects against concurrent rport reconnect / fast_io_fail /
+ *   dev_loss_tmo activity.
+ */
 struct srp_rport {
        /* for initiator and target drivers */
 
@@ -23,11 +44,43 @@ struct srp_rport {
 
        /* for initiator drivers */
 
-       void *lld_data; /* LLD private data */
+       void                    *lld_data;
+
+       struct mutex            mutex;
+       enum srp_rport_state    state;
+       bool                    deleted;
+       int                     reconnect_delay;
+       int                     failed_reconnects;
+       struct delayed_work     reconnect_work;
+       int                     fast_io_fail_tmo;
+       int                     dev_loss_tmo;
+       struct delayed_work     fast_io_fail_work;
+       struct delayed_work     dev_loss_work;
 };
 
+/**
+ * struct srp_function_template
+ * @has_rport_state: Whether or not to create the state, fast_io_fail_tmo and
+ *     dev_loss_tmo sysfs attribute for an rport.
+ * @reset_timer_if_blocked: Whether or srp_timed_out() should reset the command
+ *     timer if the device on which it has been queued is blocked.
+ * @reconnect_delay: If not NULL, points to the default reconnect_delay value.
+ * @fast_io_fail_tmo: If not NULL, points to the default fast_io_fail_tmo value.
+ * @dev_loss_tmo: If not NULL, points to the default dev_loss_tmo value.
+ * @reconnect: Callback function for reconnecting to the target. See also
+ *     srp_reconnect_rport().
+ * @terminate_rport_io: Callback function for terminating all outstanding I/O
+ *     requests for an rport.
+ */
 struct srp_function_template {
        /* for initiator drivers */
+       bool has_rport_state;
+       bool reset_timer_if_blocked;
+       int *reconnect_delay;
+       int *fast_io_fail_tmo;
+       int *dev_loss_tmo;
+       int (*reconnect)(struct srp_rport *rport);
+       void (*terminate_rport_io)(struct srp_rport *rport);
        void (*rport_delete)(struct srp_rport *rport);
        /* for target drivers */
        int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
@@ -38,10 +91,36 @@ extern struct scsi_transport_template *
 srp_attach_transport(struct srp_function_template *);
 extern void srp_release_transport(struct scsi_transport_template *);
 
+extern void srp_rport_get(struct srp_rport *rport);
+extern void srp_rport_put(struct srp_rport *rport);
 extern struct srp_rport *srp_rport_add(struct Scsi_Host *,
                                       struct srp_rport_identifiers *);
 extern void srp_rport_del(struct srp_rport *);
-
+extern int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo,
+                        int dev_loss_tmo);
+extern int srp_reconnect_rport(struct srp_rport *rport);
+extern void srp_start_tl_fail_timers(struct srp_rport *rport);
 extern void srp_remove_host(struct Scsi_Host *);
 
+/**
+ * srp_chkready() - evaluate the transport layer state before I/O
+ *
+ * Returns a SCSI result code that can be returned by the LLD queuecommand()
+ * implementation. The role of this function is similar to that of
+ * fc_remote_port_chkready().
+ */
+static inline int srp_chkready(struct srp_rport *rport)
+{
+       switch (rport->state) {
+       case SRP_RPORT_RUNNING:
+       case SRP_RPORT_BLOCKED:
+       default:
+               return 0;
+       case SRP_RPORT_FAIL_FAST:
+               return DID_TRANSPORT_FAILFAST << 16;
+       case SRP_RPORT_LOST:
+               return DID_NO_CONNECT << 16;
+       }
+}
+
 #endif
index 5ebda976ea93bd52c6ca80194d723e49e94c1558..e2b9576d00e24772580a601a268e42bdc46e349e 100644 (file)
@@ -6,11 +6,9 @@
 
 #include <linux/tracepoint.h>
 
-struct search;
-
 DECLARE_EVENT_CLASS(bcache_request,
-       TP_PROTO(struct search *s, struct bio *bio),
-       TP_ARGS(s, bio),
+       TP_PROTO(struct bcache_device *d, struct bio *bio),
+       TP_ARGS(d, bio),
 
        TP_STRUCT__entry(
                __field(dev_t,          dev                     )
@@ -24,8 +22,8 @@ DECLARE_EVENT_CLASS(bcache_request,
 
        TP_fast_assign(
                __entry->dev            = bio->bi_bdev->bd_dev;
-               __entry->orig_major     = s->d->disk->major;
-               __entry->orig_minor     = s->d->disk->first_minor;
+               __entry->orig_major     = d->disk->major;
+               __entry->orig_minor     = d->disk->first_minor;
                __entry->sector         = bio->bi_sector;
                __entry->orig_sector    = bio->bi_sector - 16;
                __entry->nr_sector      = bio->bi_size >> 9;
@@ -79,13 +77,13 @@ DECLARE_EVENT_CLASS(btree_node,
 /* request.c */
 
 DEFINE_EVENT(bcache_request, bcache_request_start,
-       TP_PROTO(struct search *s, struct bio *bio),
-       TP_ARGS(s, bio)
+       TP_PROTO(struct bcache_device *d, struct bio *bio),
+       TP_ARGS(d, bio)
 );
 
 DEFINE_EVENT(bcache_request, bcache_request_end,
-       TP_PROTO(struct search *s, struct bio *bio),
-       TP_ARGS(s, bio)
+       TP_PROTO(struct bcache_device *d, struct bio *bio),
+       TP_ARGS(d, bio)
 );
 
 DECLARE_EVENT_CLASS(bcache_bio,
@@ -370,6 +368,35 @@ DEFINE_EVENT(btree_node, bcache_btree_set_root,
        TP_ARGS(b)
 );
 
+TRACE_EVENT(bcache_keyscan,
+       TP_PROTO(unsigned nr_found,
+                unsigned start_inode, uint64_t start_offset,
+                unsigned end_inode, uint64_t end_offset),
+       TP_ARGS(nr_found,
+               start_inode, start_offset,
+               end_inode, end_offset),
+
+       TP_STRUCT__entry(
+               __field(__u32,  nr_found                        )
+               __field(__u32,  start_inode                     )
+               __field(__u64,  start_offset                    )
+               __field(__u32,  end_inode                       )
+               __field(__u64,  end_offset                      )
+       ),
+
+       TP_fast_assign(
+               __entry->nr_found       = nr_found;
+               __entry->start_inode    = start_inode;
+               __entry->start_offset   = start_offset;
+               __entry->end_inode      = end_inode;
+               __entry->end_offset     = end_offset;
+       ),
+
+       TP_printk("found %u keys from %u:%llu to %u:%llu", __entry->nr_found,
+                 __entry->start_inode, __entry->start_offset,
+                 __entry->end_inode, __entry->end_offset)
+);
+
 /* Allocator */
 
 TRACE_EVENT(bcache_alloc_invalidate,
index 422df19de732b687da6fbce4a54f90e48a6aae44..805af6db41cc6091a877d8ddf58742cb2e3fce55 100644 (file)
@@ -7,6 +7,25 @@
 #include <linux/writeback.h>
 #include <linux/tracepoint.h>
 
+TRACE_EVENT(add_device_randomness,
+       TP_PROTO(int bytes, unsigned long IP),
+
+       TP_ARGS(bytes, IP),
+
+       TP_STRUCT__entry(
+               __field(          int,  bytes                   )
+               __field(unsigned long,  IP                      )
+       ),
+
+       TP_fast_assign(
+               __entry->bytes          = bytes;
+               __entry->IP             = IP;
+       ),
+
+       TP_printk("bytes %d caller %pF",
+               __entry->bytes, (void *)__entry->IP)
+);
+
 DECLARE_EVENT_CLASS(random__mix_pool_bytes,
        TP_PROTO(const char *pool_name, int bytes, unsigned long IP),
 
@@ -68,7 +87,112 @@ TRACE_EVENT(credit_entropy_bits,
                  (void *)__entry->IP)
 );
 
-TRACE_EVENT(get_random_bytes,
+TRACE_EVENT(push_to_pool,
+       TP_PROTO(const char *pool_name, int pool_bits, int input_bits),
+
+       TP_ARGS(pool_name, pool_bits, input_bits),
+
+       TP_STRUCT__entry(
+               __field( const char *,  pool_name               )
+               __field(          int,  pool_bits               )
+               __field(          int,  input_bits              )
+       ),
+
+       TP_fast_assign(
+               __entry->pool_name      = pool_name;
+               __entry->pool_bits      = pool_bits;
+               __entry->input_bits     = input_bits;
+       ),
+
+       TP_printk("%s: pool_bits %d input_pool_bits %d",
+                 __entry->pool_name, __entry->pool_bits,
+                 __entry->input_bits)
+);
+
+TRACE_EVENT(debit_entropy,
+       TP_PROTO(const char *pool_name, int debit_bits),
+
+       TP_ARGS(pool_name, debit_bits),
+
+       TP_STRUCT__entry(
+               __field( const char *,  pool_name               )
+               __field(          int,  debit_bits              )
+       ),
+
+       TP_fast_assign(
+               __entry->pool_name      = pool_name;
+               __entry->debit_bits     = debit_bits;
+       ),
+
+       TP_printk("%s: debit_bits %d", __entry->pool_name,
+                 __entry->debit_bits)
+);
+
+TRACE_EVENT(add_input_randomness,
+       TP_PROTO(int input_bits),
+
+       TP_ARGS(input_bits),
+
+       TP_STRUCT__entry(
+               __field(          int,  input_bits              )
+       ),
+
+       TP_fast_assign(
+               __entry->input_bits     = input_bits;
+       ),
+
+       TP_printk("input_pool_bits %d", __entry->input_bits)
+);
+
+TRACE_EVENT(add_disk_randomness,
+       TP_PROTO(dev_t dev, int input_bits),
+
+       TP_ARGS(dev, input_bits),
+
+       TP_STRUCT__entry(
+               __field(        dev_t,  dev                     )
+               __field(          int,  input_bits              )
+       ),
+
+       TP_fast_assign(
+               __entry->dev            = dev;
+               __entry->input_bits     = input_bits;
+       ),
+
+       TP_printk("dev %d,%d input_pool_bits %d", MAJOR(__entry->dev),
+                 MINOR(__entry->dev), __entry->input_bits)
+);
+
+TRACE_EVENT(xfer_secondary_pool,
+       TP_PROTO(const char *pool_name, int xfer_bits, int request_bits,
+                int pool_entropy, int input_entropy),
+
+       TP_ARGS(pool_name, xfer_bits, request_bits, pool_entropy,
+               input_entropy),
+
+       TP_STRUCT__entry(
+               __field( const char *,  pool_name               )
+               __field(          int,  xfer_bits               )
+               __field(          int,  request_bits            )
+               __field(          int,  pool_entropy            )
+               __field(          int,  input_entropy           )
+       ),
+
+       TP_fast_assign(
+               __entry->pool_name      = pool_name;
+               __entry->xfer_bits      = xfer_bits;
+               __entry->request_bits   = request_bits;
+               __entry->pool_entropy   = pool_entropy;
+               __entry->input_entropy  = input_entropy;
+       ),
+
+       TP_printk("pool %s xfer_bits %d request_bits %d pool_entropy %d "
+                 "input_entropy %d", __entry->pool_name, __entry->xfer_bits,
+                 __entry->request_bits, __entry->pool_entropy,
+                 __entry->input_entropy)
+);
+
+DECLARE_EVENT_CLASS(random__get_random_bytes,
        TP_PROTO(int nbytes, unsigned long IP),
 
        TP_ARGS(nbytes, IP),
@@ -86,6 +210,18 @@ TRACE_EVENT(get_random_bytes,
        TP_printk("nbytes %d caller %pF", __entry->nbytes, (void *)__entry->IP)
 );
 
+DEFINE_EVENT(random__get_random_bytes, get_random_bytes,
+       TP_PROTO(int nbytes, unsigned long IP),
+
+       TP_ARGS(nbytes, IP)
+);
+
+DEFINE_EVENT(random__get_random_bytes, get_random_bytes_arch,
+       TP_PROTO(int nbytes, unsigned long IP),
+
+       TP_ARGS(nbytes, IP)
+);
+
 DECLARE_EVENT_CLASS(random__extract_entropy,
        TP_PROTO(const char *pool_name, int nbytes, int entropy_count,
                 unsigned long IP),
@@ -126,7 +262,52 @@ DEFINE_EVENT(random__extract_entropy, extract_entropy_user,
        TP_ARGS(pool_name, nbytes, entropy_count, IP)
 );
 
+TRACE_EVENT(random_read,
+       TP_PROTO(int got_bits, int need_bits, int pool_left, int input_left),
+
+       TP_ARGS(got_bits, need_bits, pool_left, input_left),
+
+       TP_STRUCT__entry(
+               __field(          int,  got_bits                )
+               __field(          int,  need_bits               )
+               __field(          int,  pool_left               )
+               __field(          int,  input_left              )
+       ),
+
+       TP_fast_assign(
+               __entry->got_bits       = got_bits;
+               __entry->need_bits      = need_bits;
+               __entry->pool_left      = pool_left;
+               __entry->input_left     = input_left;
+       ),
+
+       TP_printk("got_bits %d still_needed_bits %d "
+                 "blocking_pool_entropy_left %d input_entropy_left %d",
+                 __entry->got_bits, __entry->got_bits, __entry->pool_left,
+                 __entry->input_left)
+);
+
+TRACE_EVENT(urandom_read,
+       TP_PROTO(int got_bits, int pool_left, int input_left),
+
+       TP_ARGS(got_bits, pool_left, input_left),
+
+       TP_STRUCT__entry(
+               __field(          int,  got_bits                )
+               __field(          int,  pool_left               )
+               __field(          int,  input_left              )
+       ),
+
+       TP_fast_assign(
+               __entry->got_bits       = got_bits;
+               __entry->pool_left      = pool_left;
+               __entry->input_left     = input_left;
+       ),
 
+       TP_printk("got_bits %d nonblocking_pool_entropy_left %d "
+                 "input_entropy_left %d", __entry->got_bits,
+                 __entry->pool_left, __entry->input_left)
+);
 
 #endif /* _TRACE_RANDOM_H */
 
index 5c7ab17cbb0225eb3147d108a38d2564f5f23db8..52594b20179e0d8459a0810c7fbcc75fceda84ff 100644 (file)
@@ -437,9 +437,8 @@ static inline notrace int ftrace_get_offsets_##call(                        \
  *     { <assign>; }  <-- Here we assign the entries by the __field and
  *                        __array macros.
  *
- *     if (!filter_current_check_discard(buffer, event_call, entry, event))
- *             trace_nowake_buffer_unlock_commit(buffer,
- *                                                event, irq_flags, pc);
+ *     if (!filter_check_discard(ftrace_file, entry, buffer, event))
+ *             trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
  * }
  *
  * static struct trace_event ftrace_event_type_<call> = {
@@ -553,7 +552,7 @@ ftrace_raw_event_##call(void *__data, proto)                                \
                                                                        \
        { assign; }                                                     \
                                                                        \
-       if (!filter_current_check_discard(buffer, event_call, entry, event)) \
+       if (!filter_check_discard(ftrace_file, entry, buffer, event))   \
                trace_buffer_unlock_commit(buffer, event, irq_flags, pc); \
 }
 /*
diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
new file mode 100644 (file)
index 0000000..164a7e2
--- /dev/null
@@ -0,0 +1,373 @@
+#ifndef _LINUX_BCACHE_H
+#define _LINUX_BCACHE_H
+
+/*
+ * Bcache on disk data structures
+ */
+
+#include <asm/types.h>
+
+#define BITMASK(name, type, field, offset, size)               \
+static inline __u64 name(const type *k)                                \
+{ return (k->field >> offset) & ~(~0ULL << size); }            \
+                                                               \
+static inline void SET_##name(type *k, __u64 v)                        \
+{                                                              \
+       k->field &= ~(~(~0ULL << size) << offset);              \
+       k->field |= (v & ~(~0ULL << size)) << offset;           \
+}
+
+/* Btree keys - all units are in sectors */
+
+struct bkey {
+       __u64   high;
+       __u64   low;
+       __u64   ptr[];
+};
+
+#define KEY_FIELD(name, field, offset, size)                           \
+       BITMASK(name, struct bkey, field, offset, size)
+
+#define PTR_FIELD(name, offset, size)                                  \
+static inline __u64 name(const struct bkey *k, unsigned i)             \
+{ return (k->ptr[i] >> offset) & ~(~0ULL << size); }                   \
+                                                                       \
+static inline void SET_##name(struct bkey *k, unsigned i, __u64 v)     \
+{                                                                      \
+       k->ptr[i] &= ~(~(~0ULL << size) << offset);                     \
+       k->ptr[i] |= (v & ~(~0ULL << size)) << offset;                  \
+}
+
+#define KEY_SIZE_BITS          16
+
+KEY_FIELD(KEY_PTRS,    high, 60, 3)
+KEY_FIELD(HEADER_SIZE, high, 58, 2)
+KEY_FIELD(KEY_CSUM,    high, 56, 2)
+KEY_FIELD(KEY_PINNED,  high, 55, 1)
+KEY_FIELD(KEY_DIRTY,   high, 36, 1)
+
+KEY_FIELD(KEY_SIZE,    high, 20, KEY_SIZE_BITS)
+KEY_FIELD(KEY_INODE,   high, 0,  20)
+
+/* Next time I change the on disk format, KEY_OFFSET() won't be 64 bits */
+
+static inline __u64 KEY_OFFSET(const struct bkey *k)
+{
+       return k->low;
+}
+
+static inline void SET_KEY_OFFSET(struct bkey *k, __u64 v)
+{
+       k->low = v;
+}
+
+/*
+ * The high bit being set is a relic from when we used it to do binary
+ * searches - it told you where a key started. It's not used anymore,
+ * and can probably be safely dropped.
+ */
+#define KEY(inode, offset, size)                                       \
+((struct bkey) {                                                       \
+       .high = (1ULL << 63) | ((__u64) (size) << 20) | (inode),        \
+       .low = (offset)                                                 \
+})
+
+#define ZERO_KEY                       KEY(0, 0, 0)
+
+#define MAX_KEY_INODE                  (~(~0 << 20))
+#define MAX_KEY_OFFSET                 (~0ULL >> 1)
+#define MAX_KEY                                KEY(MAX_KEY_INODE, MAX_KEY_OFFSET, 0)
+
+#define KEY_START(k)                   (KEY_OFFSET(k) - KEY_SIZE(k))
+#define START_KEY(k)                   KEY(KEY_INODE(k), KEY_START(k), 0)
+
+#define PTR_DEV_BITS                   12
+
+PTR_FIELD(PTR_DEV,                     51, PTR_DEV_BITS)
+PTR_FIELD(PTR_OFFSET,                  8,  43)
+PTR_FIELD(PTR_GEN,                     0,  8)
+
+#define PTR_CHECK_DEV                  ((1 << PTR_DEV_BITS) - 1)
+
+#define PTR(gen, offset, dev)                                          \
+       ((((__u64) dev) << 51) | ((__u64) offset) << 8 | gen)
+
+/* Bkey utility code */
+
+static inline unsigned long bkey_u64s(const struct bkey *k)
+{
+       return (sizeof(struct bkey) / sizeof(__u64)) + KEY_PTRS(k);
+}
+
+static inline unsigned long bkey_bytes(const struct bkey *k)
+{
+       return bkey_u64s(k) * sizeof(__u64);
+}
+
+#define bkey_copy(_dest, _src) memcpy(_dest, _src, bkey_bytes(_src))
+
+static inline void bkey_copy_key(struct bkey *dest, const struct bkey *src)
+{
+       SET_KEY_INODE(dest, KEY_INODE(src));
+       SET_KEY_OFFSET(dest, KEY_OFFSET(src));
+}
+
+static inline struct bkey *bkey_next(const struct bkey *k)
+{
+       __u64 *d = (void *) k;
+       return (struct bkey *) (d + bkey_u64s(k));
+}
+
+static inline struct bkey *bkey_last(const struct bkey *k, unsigned nr_keys)
+{
+       __u64 *d = (void *) k;
+       return (struct bkey *) (d + nr_keys);
+}
+/* Enough for a key with 6 pointers */
+#define BKEY_PAD               8
+
+#define BKEY_PADDED(key)                                       \
+       union { struct bkey key; __u64 key ## _pad[BKEY_PAD]; }
+
+/* Superblock */
+
+/* Version 0: Cache device
+ * Version 1: Backing device
+ * Version 2: Seed pointer into btree node checksum
+ * Version 3: Cache device with new UUID format
+ * Version 4: Backing device with data offset
+ */
+#define BCACHE_SB_VERSION_CDEV         0
+#define BCACHE_SB_VERSION_BDEV         1
+#define BCACHE_SB_VERSION_CDEV_WITH_UUID 3
+#define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4
+#define BCACHE_SB_MAX_VERSION          4
+
+#define SB_SECTOR                      8
+#define SB_SIZE                                4096
+#define SB_LABEL_SIZE                  32
+#define SB_JOURNAL_BUCKETS             256U
+/* SB_JOURNAL_BUCKETS must be divisible by BITS_PER_LONG */
+#define MAX_CACHES_PER_SET             8
+
+#define BDEV_DATA_START_DEFAULT                16      /* sectors */
+
+struct cache_sb {
+       __u64                   csum;
+       __u64                   offset; /* sector where this sb was written */
+       __u64                   version;
+
+       __u8                    magic[16];
+
+       __u8                    uuid[16];
+       union {
+               __u8            set_uuid[16];
+               __u64           set_magic;
+       };
+       __u8                    label[SB_LABEL_SIZE];
+
+       __u64                   flags;
+       __u64                   seq;
+       __u64                   pad[8];
+
+       union {
+       struct {
+               /* Cache devices */
+               __u64           nbuckets;       /* device size */
+
+               __u16           block_size;     /* sectors */
+               __u16           bucket_size;    /* sectors */
+
+               __u16           nr_in_set;
+               __u16           nr_this_dev;
+       };
+       struct {
+               /* Backing devices */
+               __u64           data_offset;
+
+               /*
+                * block_size from the cache device section is still used by
+                * backing devices, so don't add anything here until we fix
+                * things to not need it for backing devices anymore
+                */
+       };
+       };
+
+       __u32                   last_mount;     /* time_t */
+
+       __u16                   first_bucket;
+       union {
+               __u16           njournal_buckets;
+               __u16           keys;
+       };
+       __u64                   d[SB_JOURNAL_BUCKETS];  /* journal buckets */
+};
+
+static inline _Bool SB_IS_BDEV(const struct cache_sb *sb)
+{
+       return sb->version == BCACHE_SB_VERSION_BDEV
+               || sb->version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
+}
+
+BITMASK(CACHE_SYNC,                    struct cache_sb, flags, 0, 1);
+BITMASK(CACHE_DISCARD,                 struct cache_sb, flags, 1, 1);
+BITMASK(CACHE_REPLACEMENT,             struct cache_sb, flags, 2, 3);
+#define CACHE_REPLACEMENT_LRU          0U
+#define CACHE_REPLACEMENT_FIFO         1U
+#define CACHE_REPLACEMENT_RANDOM       2U
+
+BITMASK(BDEV_CACHE_MODE,               struct cache_sb, flags, 0, 4);
+#define CACHE_MODE_WRITETHROUGH                0U
+#define CACHE_MODE_WRITEBACK           1U
+#define CACHE_MODE_WRITEAROUND         2U
+#define CACHE_MODE_NONE                        3U
+BITMASK(BDEV_STATE,                    struct cache_sb, flags, 61, 2);
+#define BDEV_STATE_NONE                        0U
+#define BDEV_STATE_CLEAN               1U
+#define BDEV_STATE_DIRTY               2U
+#define BDEV_STATE_STALE               3U
+
+/*
+ * Magic numbers
+ *
+ * The various other data structures have their own magic numbers, which are
+ * xored with the first part of the cache set's UUID
+ */
+
+#define JSET_MAGIC                     0x245235c1a3625032ULL
+#define PSET_MAGIC                     0x6750e15f87337f91ULL
+#define BSET_MAGIC                     0x90135c78b99e07f5ULL
+
+static inline __u64 jset_magic(struct cache_sb *sb)
+{
+       return sb->set_magic ^ JSET_MAGIC;
+}
+
+static inline __u64 pset_magic(struct cache_sb *sb)
+{
+       return sb->set_magic ^ PSET_MAGIC;
+}
+
+static inline __u64 bset_magic(struct cache_sb *sb)
+{
+       return sb->set_magic ^ BSET_MAGIC;
+}
+
+/*
+ * Journal
+ *
+ * On disk format for a journal entry:
+ * seq is monotonically increasing; every journal entry has its own unique
+ * sequence number.
+ *
+ * last_seq is the oldest journal entry that still has keys the btree hasn't
+ * flushed to disk yet.
+ *
+ * version is for on disk format changes.
+ */
+
+#define BCACHE_JSET_VERSION_UUIDv1     1
+#define BCACHE_JSET_VERSION_UUID       1       /* Always latest UUID format */
+#define BCACHE_JSET_VERSION            1
+
+struct jset {
+       __u64                   csum;
+       __u64                   magic;
+       __u64                   seq;
+       __u32                   version;
+       __u32                   keys;
+
+       __u64                   last_seq;
+
+       BKEY_PADDED(uuid_bucket);
+       BKEY_PADDED(btree_root);
+       __u16                   btree_level;
+       __u16                   pad[3];
+
+       __u64                   prio_bucket[MAX_CACHES_PER_SET];
+
+       union {
+               struct bkey     start[0];
+               __u64           d[0];
+       };
+};
+
+/* Bucket prios/gens */
+
+struct prio_set {
+       __u64                   csum;
+       __u64                   magic;
+       __u64                   seq;
+       __u32                   version;
+       __u32                   pad;
+
+       __u64                   next_bucket;
+
+       struct bucket_disk {
+               __u16           prio;
+               __u8            gen;
+       } __attribute((packed)) data[];
+};
+
+/* UUIDS - per backing device/flash only volume metadata */
+
+struct uuid_entry {
+       union {
+               struct {
+                       __u8    uuid[16];
+                       __u8    label[32];
+                       __u32   first_reg;
+                       __u32   last_reg;
+                       __u32   invalidated;
+
+                       __u32   flags;
+                       /* Size of flash only volumes */
+                       __u64   sectors;
+               };
+
+               __u8            pad[128];
+       };
+};
+
+BITMASK(UUID_FLASH_ONLY,       struct uuid_entry, flags, 0, 1);
+
+/* Btree nodes */
+
+/* Version 1: Seed pointer into btree node checksum
+ */
+#define BCACHE_BSET_CSUM               1
+#define BCACHE_BSET_VERSION            1
+
+/*
+ * Btree nodes
+ *
+ * On disk a btree node is a list/log of these; within each set the keys are
+ * sorted
+ */
+struct bset {
+       __u64                   csum;
+       __u64                   magic;
+       __u64                   seq;
+       __u32                   version;
+       __u32                   keys;
+
+       union {
+               struct bkey     start[0];
+               __u64           d[0];
+       };
+};
+
+/* OBSOLETE */
+
+/* UUIDS - per backing device/flash only volume metadata */
+
+struct uuid_entry_v0 {
+       __u8            uuid[16];
+       __u8            label[32];
+       __u32           first_reg;
+       __u32           last_reg;
+       __u32           invalidated;
+       __u32           pad;
+};
+
+#endif /* _LINUX_BCACHE_H */
index c880a417d8a93693874b76a3e364a203ed4d0a9c..1af72d8228e04db8c1d6de05cacfa1bfd4a577b7 100644 (file)
@@ -27,6 +27,7 @@ struct genlmsghdr {
  */
 #define GENL_ID_GENERATE       0
 #define GENL_ID_CTRL           NLMSG_MIN_TYPE
+#define GENL_ID_VFS_DQUOT      (NLMSG_MIN_TYPE + 1)
 
 /**************************************************************************
  * Controller
index 307f293477e83684970fc5c6dc05225d750d0882..a806687ad98fc1258ae0b36c75164ecf5d59eec4 100644 (file)
@@ -763,13 +763,14 @@ enum {
 
        TCA_FQ_RATE_ENABLE,     /* enable/disable rate limiting */
 
-       TCA_FQ_FLOW_DEFAULT_RATE,/* for sockets with unspecified sk_rate,
-                                 * use the following rate
-                                 */
+       TCA_FQ_FLOW_DEFAULT_RATE,/* obsolete, do not use */
 
        TCA_FQ_FLOW_MAX_RATE,   /* per flow max rate */
 
        TCA_FQ_BUCKETS_LOG,     /* log2(number of buckets) */
+
+       TCA_FQ_FLOW_REFILL_DELAY,       /* flow credit refill delay in usec */
+
        __TCA_FQ_MAX
 };
 
index fe1a5406d4d93cdf6012d11ab7315f014b552ede..f7cf7f351144873efd0bde3bdfe4e8f1676eb41d 100644 (file)
@@ -16,6 +16,7 @@
 #define _MD_P_H
 
 #include <linux/types.h>
+#include <asm/byteorder.h>
 
 /*
  * RAID superblock.
index 083bb5a5aae22f23e4e7c42c73714ee6df855c8b..1666aabbbb868ae9a215794e36726bd37a6fe2bd 100644 (file)
@@ -160,6 +160,10 @@ enum v4l2_colorfx {
  * of controls. Total of 16 controls is reserved for this driver */
 #define V4L2_CID_USER_SI476X_BASE              (V4L2_CID_USER_BASE + 0x1040)
 
+/* The base for the TI VPE driver controls. Total of 16 controls is reserved for
+ * this driver */
+#define V4L2_CID_USER_TI_VPE_BASE              (V4L2_CID_USER_BASE + 0x1050)
+
 /* MPEG-class control IDs */
 /* The MPEG controls are applicable to all codec controls
  * and the 'MPEG' part of the define is historical */
index e3ddd86c90a68610a20625729a99cf8effea8f31..cbfdd4ca951021854ff70843143ec8e1fabda358 100644 (file)
@@ -87,10 +87,11 @@ enum {
        IB_USER_VERBS_CMD_CLOSE_XRCD,
        IB_USER_VERBS_CMD_CREATE_XSRQ,
        IB_USER_VERBS_CMD_OPEN_QP,
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-       IB_USER_VERBS_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD,
-       IB_USER_VERBS_CMD_DESTROY_FLOW
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
+};
+
+enum {
+       IB_USER_VERBS_EX_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD,
+       IB_USER_VERBS_EX_CMD_DESTROY_FLOW
 };
 
 /*
@@ -122,22 +123,24 @@ struct ib_uverbs_comp_event_desc {
  * the rest of the command struct based on these value.
  */
 
+#define IB_USER_VERBS_CMD_COMMAND_MASK 0xff
+#define IB_USER_VERBS_CMD_FLAGS_MASK 0xff000000u
+#define IB_USER_VERBS_CMD_FLAGS_SHIFT 24
+
+#define IB_USER_VERBS_CMD_FLAG_EXTENDED 0x80
+
 struct ib_uverbs_cmd_hdr {
        __u32 command;
        __u16 in_words;
        __u16 out_words;
 };
 
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-struct ib_uverbs_cmd_hdr_ex {
-       __u32 command;
-       __u16 in_words;
-       __u16 out_words;
+struct ib_uverbs_ex_cmd_hdr {
+       __u64 response;
        __u16 provider_in_words;
        __u16 provider_out_words;
        __u32 cmd_hdr_reserved;
 };
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
 
 struct ib_uverbs_get_context {
        __u64 response;
@@ -700,62 +703,71 @@ struct ib_uverbs_detach_mcast {
        __u64 driver_data[0];
 };
 
-#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
-struct ib_kern_eth_filter {
+struct ib_uverbs_flow_spec_hdr {
+       __u32 type;
+       __u16 size;
+       __u16 reserved;
+       /* followed by flow_spec */
+       __u64 flow_spec_data[0];
+};
+
+struct ib_uverbs_flow_eth_filter {
        __u8  dst_mac[6];
        __u8  src_mac[6];
        __be16 ether_type;
        __be16 vlan_tag;
 };
 
-struct ib_kern_spec_eth {
-       __u32  type;
-       __u16  size;
-       __u16  reserved;
-       struct ib_kern_eth_filter val;
-       struct ib_kern_eth_filter mask;
+struct ib_uverbs_flow_spec_eth {
+       union {
+               struct ib_uverbs_flow_spec_hdr hdr;
+               struct {
+                       __u32 type;
+                       __u16 size;
+                       __u16 reserved;
+               };
+       };
+       struct ib_uverbs_flow_eth_filter val;
+       struct ib_uverbs_flow_eth_filter mask;
 };
 
-struct ib_kern_ipv4_filter {
+struct ib_uverbs_flow_ipv4_filter {
        __be32 src_ip;
        __be32 dst_ip;
 };
 
-struct ib_kern_spec_ipv4 {
-       __u32  type;
-       __u16  size;
-       __u16  reserved;
-       struct ib_kern_ipv4_filter val;
-       struct ib_kern_ipv4_filter mask;
+struct ib_uverbs_flow_spec_ipv4 {
+       union {
+               struct ib_uverbs_flow_spec_hdr hdr;
+               struct {
+                       __u32 type;
+                       __u16 size;
+                       __u16 reserved;
+               };
+       };
+       struct ib_uverbs_flow_ipv4_filter val;
+       struct ib_uverbs_flow_ipv4_filter mask;
 };
 
-struct ib_kern_tcp_udp_filter {
+struct ib_uverbs_flow_tcp_udp_filter {
        __be16 dst_port;
        __be16 src_port;
 };
 
-struct ib_kern_spec_tcp_udp {
-       __u32  type;
-       __u16  size;
-       __u16  reserved;
-       struct ib_kern_tcp_udp_filter val;
-       struct ib_kern_tcp_udp_filter mask;
-};
-
-struct ib_kern_spec {
+struct ib_uverbs_flow_spec_tcp_udp {
        union {
+               struct ib_uverbs_flow_spec_hdr hdr;
                struct {
                        __u32 type;
                        __u16 size;
                        __u16 reserved;
                };
-               struct ib_kern_spec_eth     eth;
-               struct ib_kern_spec_ipv4    ipv4;
-               struct ib_kern_spec_tcp_udp tcp_udp;
        };
+       struct ib_uverbs_flow_tcp_udp_filter val;
+       struct ib_uverbs_flow_tcp_udp_filter mask;
 };
 
-struct ib_kern_flow_attr {
+struct ib_uverbs_flow_attr {
        __u32 type;
        __u16 size;
        __u16 priority;
@@ -767,13 +779,13 @@ struct ib_kern_flow_attr {
         * struct ib_flow_spec_xxx
         * struct ib_flow_spec_yyy
         */
+       struct ib_uverbs_flow_spec_hdr flow_specs[0];
 };
 
 struct ib_uverbs_create_flow  {
        __u32 comp_mask;
-       __u64 response;
        __u32 qp_handle;
-       struct ib_kern_flow_attr flow_attr;
+       struct ib_uverbs_flow_attr flow_attr;
 };
 
 struct ib_uverbs_create_flow_resp {
@@ -785,7 +797,6 @@ struct ib_uverbs_destroy_flow  {
        __u32 comp_mask;
        __u32 flow_handle;
 };
-#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
 
 struct ib_uverbs_create_srq {
        __u64 response;
index 5496f307988ee44603ead02db2b2c5caa48511bd..3fc8a2f2fac4462eb7b1d1c5c1c1b7c4c3cabdf7 100644 (file)
@@ -118,6 +118,7 @@ config HAVE_KERNEL_LZ4
 choice
        prompt "Kernel compression mode"
        default KERNEL_GZIP
+       depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
        help
          The linux kernel is a kind of self-extracting executable.
          Several compression algorithms are available, which differ
@@ -136,13 +137,6 @@ choice
 
          If in doubt, select 'gzip'
 
-config KERNEL_UNCOMPRESSED
-       bool "No compression"
-       help
-         No compression at all. The kernel is huge but the compression and
-         decompression times are zero.
-         This is usually not what you want.
-
 config KERNEL_GZIP
        bool "Gzip"
        depends on HAVE_KERNEL_GZIP
@@ -851,7 +845,7 @@ config NUMA_BALANCING_DEFAULT_ENABLED
        default y
        depends on NUMA_BALANCING
        help
-         If set, autonumic NUMA balancing will be enabled if running on a NUMA
+         If set, automatic NUMA balancing will be enabled if running on a NUMA
          machine.
 
 config NUMA_BALANCING
@@ -862,7 +856,7 @@ config NUMA_BALANCING
        help
          This option adds support for automatic NUMA aware memory/task placement.
          The mechanism is quite primitive and is based on migrating memory when
-         it is references to the node the task is running on.
+         it has references to the node the task is running on.
 
          This system will be inactive on UMA systems.
 
index 578782ef6ae19c636e282af5e1592aaf0540126c..5253204afdcace55e89cda669aaf2896eba23aaa 100644 (file)
@@ -11,7 +11,7 @@
 #include <linux/kbuild.h>
 #include <linux/page_cgroup.h>
 #include <linux/log2.h>
-#include <linux/spinlock.h>
+#include <linux/spinlock_types.h>
 
 void foo(void)
 {
index a3bb14fbe5c61fec344a166f8b542571dab4704c..dc04c166c54d7bc8e86ab87bec4075a3cc492e12 100644 (file)
@@ -214,7 +214,7 @@ void irq_enable(struct irq_desc *desc)
 }
 
 /**
- * irq_disable - Mark interupt disabled
+ * irq_disable - Mark interrupt disabled
  * @desc:      irq descriptor which should be disabled
  *
  * If the chip does not implement the irq_disable callback, we
index 3e59f951d42f9663bfe39f7a8fc25bdc98b8b149..481a13c43b1708d3501a7f686760573c4eab6a34 100644 (file)
@@ -786,7 +786,7 @@ irq_forced_thread_fn(struct irq_desc *desc, struct irqaction *action)
 }
 
 /*
- * Interrupts explicitely requested as threaded interupts want to be
+ * Interrupts explicitly requested as threaded interrupts want to be
  * preemtible - many of them need to sleep and wait for slow busses to
  * complete.
  */
index 1162f1030f18f9326c23522417a3de87feb18ef4..3320b84cc60f79ac09501d6f4d55acc01b0cebe6 100644 (file)
@@ -14,6 +14,7 @@ enum {
        _IRQ_NO_BALANCING       = IRQ_NO_BALANCING,
        _IRQ_NESTED_THREAD      = IRQ_NESTED_THREAD,
        _IRQ_PER_CPU_DEVID      = IRQ_PER_CPU_DEVID,
+       _IRQ_IS_POLLED          = IRQ_IS_POLLED,
        _IRQF_MODIFY_MASK       = IRQF_MODIFY_MASK,
 };
 
@@ -26,6 +27,7 @@ enum {
 #define IRQ_NOAUTOEN           GOT_YOU_MORON
 #define IRQ_NESTED_THREAD      GOT_YOU_MORON
 #define IRQ_PER_CPU_DEVID      GOT_YOU_MORON
+#define IRQ_IS_POLLED          GOT_YOU_MORON
 #undef IRQF_MODIFY_MASK
 #define IRQF_MODIFY_MASK       GOT_YOU_MORON
 
@@ -147,3 +149,8 @@ static inline bool irq_settings_is_nested_thread(struct irq_desc *desc)
 {
        return desc->status_use_accessors & _IRQ_NESTED_THREAD;
 }
+
+static inline bool irq_settings_is_polled(struct irq_desc *desc)
+{
+       return desc->status_use_accessors & _IRQ_IS_POLLED;
+}
index 7b5f012bde9d73ff246652fe48d49e5b1aebc12c..a1d8cc63b56e55ddbb83741b1d20db58e5ab3b7c 100644 (file)
@@ -67,8 +67,13 @@ static int try_one_irq(int irq, struct irq_desc *desc, bool force)
 
        raw_spin_lock(&desc->lock);
 
-       /* PER_CPU and nested thread interrupts are never polled */
-       if (irq_settings_is_per_cpu(desc) || irq_settings_is_nested_thread(desc))
+       /*
+        * PER_CPU, nested thread interrupts and interrupts explicitely
+        * marked polled are excluded from polling.
+        */
+       if (irq_settings_is_per_cpu(desc) ||
+           irq_settings_is_nested_thread(desc) ||
+           irq_settings_is_polled(desc))
                goto out;
 
        /*
@@ -268,7 +273,8 @@ try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
 void note_interrupt(unsigned int irq, struct irq_desc *desc,
                    irqreturn_t action_ret)
 {
-       if (desc->istate & IRQS_POLL_INPROGRESS)
+       if (desc->istate & IRQS_POLL_INPROGRESS ||
+           irq_settings_is_polled(desc))
                return;
 
        /* we get here again via the threaded handler */
index 2a74f307c5ec57b050ceeb8a21341f8a394841ef..490afc03627e52e34e51d69e0a15693b7716b17a 100644 (file)
@@ -921,7 +921,7 @@ static int kimage_load_segment(struct kimage *image,
  *   reinitialize them.
  *
  * - A machine specific part that includes the syscall number
- *   and the copies the image to it's final destination.  And
+ *   and then copies the image to it's final destination.  And
  *   jumps into the image at entry.
  *
  * kexec does not sync, or unmount filesystems so if you need
index 10c22cae83a035e43eb54a79272fd1e6ae2fc757..b38109e204aff8e83afb0e15484cdfec8e450575 100644 (file)
@@ -792,7 +792,8 @@ void free_basic_memory_bitmaps(void)
 {
        struct memory_bitmap *bm1, *bm2;
 
-       BUG_ON(!(forbidden_pages_map && free_pages_map));
+       if (WARN_ON(!(forbidden_pages_map && free_pages_map)))
+               return;
 
        bm1 = forbidden_pages_map;
        bm2 = free_pages_map;
index 24850270c8024948d60c0f827457b18d2de2d9a7..98d357584cd6bad7bdc87cbc63e5c296a8393b60 100644 (file)
@@ -70,6 +70,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
                data->swap = swsusp_resume_device ?
                        swap_type_of(swsusp_resume_device, 0, NULL) : -1;
                data->mode = O_RDONLY;
+               data->free_bitmaps = false;
                error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
                if (error)
                        pm_notifier_call_chain(PM_POST_HIBERNATION);
index 0c9a934cfec19d0859b57c2ca9eca86830401ab2..1254f312d02483f524319ee5ab9d2e1a13f48678 100644 (file)
@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(rcu_irq_enter);
 /*
  * Test whether RCU thinks that the current CPU is idle.
  */
-bool __rcu_is_watching(void)
+bool notrace __rcu_is_watching(void)
 {
        return rcu_dynticks_nesting;
 }
index 4c06ddfea7cd2beffbf428a952e1efada1d1fa57..dd081987a8ec62349ad7721476cb97606077f28a 100644 (file)
@@ -664,7 +664,7 @@ void rcu_nmi_exit(void)
  * rcu_is_watching(), the caller of __rcu_is_watching() must have at
  * least disabled preemption.
  */
-bool __rcu_is_watching(void)
+bool notrace __rcu_is_watching(void)
 {
        return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
 }
@@ -675,7 +675,7 @@ bool __rcu_is_watching(void)
  * If the current CPU is in its idle loop and is neither in an interrupt
  * or NMI handler, return true.
  */
-bool rcu_is_watching(void)
+bool notrace rcu_is_watching(void)
 {
        int ret;
 
index 9f4618eb51c8528fe808d91f6dfdc6237af3ab65..13d2f7cd65dbfd851eaa61cf08645994c9fd0037 100644 (file)
@@ -673,17 +673,18 @@ err:
        nlmsg_free(rep_skb);
 }
 
-static struct genl_ops taskstats_ops = {
-       .cmd            = TASKSTATS_CMD_GET,
-       .doit           = taskstats_user_cmd,
-       .policy         = taskstats_cmd_get_policy,
-       .flags          = GENL_ADMIN_PERM,
-};
-
-static struct genl_ops cgroupstats_ops = {
-       .cmd            = CGROUPSTATS_CMD_GET,
-       .doit           = cgroupstats_user_cmd,
-       .policy         = cgroupstats_cmd_get_policy,
+static const struct genl_ops taskstats_ops[] = {
+       {
+               .cmd            = TASKSTATS_CMD_GET,
+               .doit           = taskstats_user_cmd,
+               .policy         = taskstats_cmd_get_policy,
+               .flags          = GENL_ADMIN_PERM,
+       },
+       {
+               .cmd            = CGROUPSTATS_CMD_GET,
+               .doit           = cgroupstats_user_cmd,
+               .policy         = cgroupstats_cmd_get_policy,
+       },
 };
 
 /* Needed early in initialization */
@@ -702,26 +703,13 @@ static int __init taskstats_init(void)
 {
        int rc;
 
-       rc = genl_register_family(&family);
+       rc = genl_register_family_with_ops(&family, taskstats_ops);
        if (rc)
                return rc;
 
-       rc = genl_register_ops(&family, &taskstats_ops);
-       if (rc < 0)
-               goto err;
-
-       rc = genl_register_ops(&family, &cgroupstats_ops);
-       if (rc < 0)
-               goto err_cgroup_ops;
-
        family_registered = 1;
        pr_info("registered taskstats version %d\n", TASKSTATS_GENL_VERSION);
        return 0;
-err_cgroup_ops:
-       genl_unregister_ops(&family, &taskstats_ops);
-err:
-       genl_unregister_family(&family);
-       return rc;
 }
 
 /*
index 03cf44ac54d3666b434a26a30bc6f7a1e34cbf56..22fa556967609465a0dbd98e238ee1d14b52e328 100644 (file)
@@ -3307,7 +3307,11 @@ void unregister_ftrace_function_probe_all(char *glob)
 static LIST_HEAD(ftrace_commands);
 static DEFINE_MUTEX(ftrace_cmd_mutex);
 
-int register_ftrace_command(struct ftrace_func_command *cmd)
+/*
+ * Currently we only register ftrace commands from __init, so mark this
+ * __init too.
+ */
+__init int register_ftrace_command(struct ftrace_func_command *cmd)
 {
        struct ftrace_func_command *p;
        int ret = 0;
@@ -3326,7 +3330,11 @@ int register_ftrace_command(struct ftrace_func_command *cmd)
        return ret;
 }
 
-int unregister_ftrace_command(struct ftrace_func_command *cmd)
+/*
+ * Currently we only unregister ftrace commands from __init, so mark
+ * this __init too.
+ */
+__init int unregister_ftrace_command(struct ftrace_func_command *cmd)
 {
        struct ftrace_func_command *p, *n;
        int ret = -ENODEV;
@@ -3641,7 +3649,7 @@ __setup("ftrace_filter=", set_ftrace_filter);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static char ftrace_graph_buf[FTRACE_FILTER_SIZE] __initdata;
-static int ftrace_set_func(unsigned long *array, int *idx, char *buffer);
+static int ftrace_set_func(unsigned long *array, int *idx, int size, char *buffer);
 
 static int __init set_graph_function(char *str)
 {
@@ -3659,7 +3667,7 @@ static void __init set_ftrace_early_graph(char *buf)
                func = strsep(&buf, ",");
                /* we allow only one expression at a time */
                ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count,
-                                     func);
+                                     FTRACE_GRAPH_MAX_FUNCS, func);
                if (ret)
                        printk(KERN_DEBUG "ftrace: function %s not "
                                          "traceable\n", func);
@@ -3776,15 +3784,25 @@ static const struct file_operations ftrace_notrace_fops = {
 static DEFINE_MUTEX(graph_lock);
 
 int ftrace_graph_count;
-int ftrace_graph_filter_enabled;
+int ftrace_graph_notrace_count;
 unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly;
+unsigned long ftrace_graph_notrace_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly;
+
+struct ftrace_graph_data {
+       unsigned long *table;
+       size_t size;
+       int *count;
+       const struct seq_operations *seq_ops;
+};
 
 static void *
 __g_next(struct seq_file *m, loff_t *pos)
 {
-       if (*pos >= ftrace_graph_count)
+       struct ftrace_graph_data *fgd = m->private;
+
+       if (*pos >= *fgd->count)
                return NULL;
-       return &ftrace_graph_funcs[*pos];
+       return &fgd->table[*pos];
 }
 
 static void *
@@ -3796,10 +3814,12 @@ g_next(struct seq_file *m, void *v, loff_t *pos)
 
 static void *g_start(struct seq_file *m, loff_t *pos)
 {
+       struct ftrace_graph_data *fgd = m->private;
+
        mutex_lock(&graph_lock);
 
        /* Nothing, tell g_show to print all functions are enabled */
-       if (!ftrace_graph_filter_enabled && !*pos)
+       if (!*fgd->count && !*pos)
                return (void *)1;
 
        return __g_next(m, pos);
@@ -3835,38 +3855,88 @@ static const struct seq_operations ftrace_graph_seq_ops = {
 };
 
 static int
-ftrace_graph_open(struct inode *inode, struct file *file)
+__ftrace_graph_open(struct inode *inode, struct file *file,
+                   struct ftrace_graph_data *fgd)
 {
        int ret = 0;
 
-       if (unlikely(ftrace_disabled))
-               return -ENODEV;
-
        mutex_lock(&graph_lock);
        if ((file->f_mode & FMODE_WRITE) &&
            (file->f_flags & O_TRUNC)) {
-               ftrace_graph_filter_enabled = 0;
-               ftrace_graph_count = 0;
-               memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs));
+               *fgd->count = 0;
+               memset(fgd->table, 0, fgd->size * sizeof(*fgd->table));
        }
        mutex_unlock(&graph_lock);
 
-       if (file->f_mode & FMODE_READ)
-               ret = seq_open(file, &ftrace_graph_seq_ops);
+       if (file->f_mode & FMODE_READ) {
+               ret = seq_open(file, fgd->seq_ops);
+               if (!ret) {
+                       struct seq_file *m = file->private_data;
+                       m->private = fgd;
+               }
+       } else
+               file->private_data = fgd;
 
        return ret;
 }
 
+static int
+ftrace_graph_open(struct inode *inode, struct file *file)
+{
+       struct ftrace_graph_data *fgd;
+
+       if (unlikely(ftrace_disabled))
+               return -ENODEV;
+
+       fgd = kmalloc(sizeof(*fgd), GFP_KERNEL);
+       if (fgd == NULL)
+               return -ENOMEM;
+
+       fgd->table = ftrace_graph_funcs;
+       fgd->size = FTRACE_GRAPH_MAX_FUNCS;
+       fgd->count = &ftrace_graph_count;
+       fgd->seq_ops = &ftrace_graph_seq_ops;
+
+       return __ftrace_graph_open(inode, file, fgd);
+}
+
+static int
+ftrace_graph_notrace_open(struct inode *inode, struct file *file)
+{
+       struct ftrace_graph_data *fgd;
+
+       if (unlikely(ftrace_disabled))
+               return -ENODEV;
+
+       fgd = kmalloc(sizeof(*fgd), GFP_KERNEL);
+       if (fgd == NULL)
+               return -ENOMEM;
+
+       fgd->table = ftrace_graph_notrace_funcs;
+       fgd->size = FTRACE_GRAPH_MAX_FUNCS;
+       fgd->count = &ftrace_graph_notrace_count;
+       fgd->seq_ops = &ftrace_graph_seq_ops;
+
+       return __ftrace_graph_open(inode, file, fgd);
+}
+
 static int
 ftrace_graph_release(struct inode *inode, struct file *file)
 {
-       if (file->f_mode & FMODE_READ)
+       if (file->f_mode & FMODE_READ) {
+               struct seq_file *m = file->private_data;
+
+               kfree(m->private);
                seq_release(inode, file);
+       } else {
+               kfree(file->private_data);
+       }
+
        return 0;
 }
 
 static int
-ftrace_set_func(unsigned long *array, int *idx, char *buffer)
+ftrace_set_func(unsigned long *array, int *idx, int size, char *buffer)
 {
        struct dyn_ftrace *rec;
        struct ftrace_page *pg;
@@ -3879,7 +3949,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
 
        /* decode regex */
        type = filter_parse_regex(buffer, strlen(buffer), &search, &not);
-       if (!not && *idx >= FTRACE_GRAPH_MAX_FUNCS)
+       if (!not && *idx >= size)
                return -EBUSY;
 
        search_len = strlen(search);
@@ -3907,7 +3977,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
                                fail = 0;
                                if (!exists) {
                                        array[(*idx)++] = rec->ip;
-                                       if (*idx >= FTRACE_GRAPH_MAX_FUNCS)
+                                       if (*idx >= size)
                                                goto out;
                                }
                        } else {
@@ -3925,8 +3995,6 @@ out:
        if (fail)
                return -EINVAL;
 
-       ftrace_graph_filter_enabled = !!(*idx);
-
        return 0;
 }
 
@@ -3935,36 +4003,33 @@ ftrace_graph_write(struct file *file, const char __user *ubuf,
                   size_t cnt, loff_t *ppos)
 {
        struct trace_parser parser;
-       ssize_t read, ret;
+       ssize_t read, ret = 0;
+       struct ftrace_graph_data *fgd = file->private_data;
 
        if (!cnt)
                return 0;
 
-       mutex_lock(&graph_lock);
-
-       if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX)) {
-               ret = -ENOMEM;
-               goto out_unlock;
-       }
+       if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX))
+               return -ENOMEM;
 
        read = trace_get_user(&parser, ubuf, cnt, ppos);
 
        if (read >= 0 && trace_parser_loaded((&parser))) {
                parser.buffer[parser.idx] = 0;
 
+               mutex_lock(&graph_lock);
+
                /* we allow only one expression at a time */
-               ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count,
-                                       parser.buffer);
-               if (ret)
-                       goto out_free;
+               ret = ftrace_set_func(fgd->table, fgd->count, fgd->size,
+                                     parser.buffer);
+
+               mutex_unlock(&graph_lock);
        }
 
-       ret = read;
+       if (!ret)
+               ret = read;
 
-out_free:
        trace_parser_put(&parser);
-out_unlock:
-       mutex_unlock(&graph_lock);
 
        return ret;
 }
@@ -3976,6 +4041,14 @@ static const struct file_operations ftrace_graph_fops = {
        .llseek         = ftrace_filter_lseek,
        .release        = ftrace_graph_release,
 };
+
+static const struct file_operations ftrace_graph_notrace_fops = {
+       .open           = ftrace_graph_notrace_open,
+       .read           = seq_read,
+       .write          = ftrace_graph_write,
+       .llseek         = ftrace_filter_lseek,
+       .release        = ftrace_graph_release,
+};
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
 
 static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
@@ -3997,6 +4070,9 @@ static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
        trace_create_file("set_graph_function", 0444, d_tracer,
                                    NULL,
                                    &ftrace_graph_fops);
+       trace_create_file("set_graph_notrace", 0444, d_tracer,
+                                   NULL,
+                                   &ftrace_graph_notrace_fops);
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
 
        return 0;
@@ -4320,12 +4396,21 @@ ftrace_ops_control_func(unsigned long ip, unsigned long parent_ip,
         */
        preempt_disable_notrace();
        trace_recursion_set(TRACE_CONTROL_BIT);
+
+       /*
+        * Control funcs (perf) uses RCU. Only trace if
+        * RCU is currently active.
+        */
+       if (!rcu_is_watching())
+               goto out;
+
        do_for_each_ftrace_op(op, ftrace_control_list) {
                if (!(op->flags & FTRACE_OPS_FL_STUB) &&
                    !ftrace_function_local_disabled(op) &&
                    ftrace_ops_test(op, ip, regs))
                        op->func(ip, parent_ip, op, regs);
        } while_for_each_ftrace_op(op);
+ out:
        trace_recursion_clear(TRACE_CONTROL_BIT);
        preempt_enable_notrace();
 }
index d9fea7dfd5d3bbb0570ac1e11537d3c1ce05d330..9d20cd9743efc0bf02cff0cf0f5536c19d0252cc 100644 (file)
@@ -235,13 +235,33 @@ void trace_array_put(struct trace_array *this_tr)
        mutex_unlock(&trace_types_lock);
 }
 
-int filter_current_check_discard(struct ring_buffer *buffer,
-                                struct ftrace_event_call *call, void *rec,
-                                struct ring_buffer_event *event)
+int filter_check_discard(struct ftrace_event_file *file, void *rec,
+                        struct ring_buffer *buffer,
+                        struct ring_buffer_event *event)
 {
-       return filter_check_discard(call, rec, buffer, event);
+       if (unlikely(file->flags & FTRACE_EVENT_FL_FILTERED) &&
+           !filter_match_preds(file->filter, rec)) {
+               ring_buffer_discard_commit(buffer, event);
+               return 1;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(filter_check_discard);
+
+int call_filter_check_discard(struct ftrace_event_call *call, void *rec,
+                             struct ring_buffer *buffer,
+                             struct ring_buffer_event *event)
+{
+       if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
+           !filter_match_preds(call->filter, rec)) {
+               ring_buffer_discard_commit(buffer, event);
+               return 1;
+       }
+
+       return 0;
 }
-EXPORT_SYMBOL_GPL(filter_current_check_discard);
+EXPORT_SYMBOL_GPL(call_filter_check_discard);
 
 cycle_t buffer_ftrace_now(struct trace_buffer *buf, int cpu)
 {
@@ -843,9 +863,12 @@ int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
        if (isspace(ch)) {
                parser->buffer[parser->idx] = 0;
                parser->cont = false;
-       } else {
+       } else if (parser->idx < parser->size - 1) {
                parser->cont = true;
                parser->buffer[parser->idx++] = ch;
+       } else {
+               ret = -EINVAL;
+               goto out;
        }
 
        *ppos += read;
@@ -1260,21 +1283,6 @@ int is_tracing_stopped(void)
        return global_trace.stop_count;
 }
 
-/**
- * ftrace_off_permanent - disable all ftrace code permanently
- *
- * This should only be called when a serious anomally has
- * been detected.  This will turn off the function tracing,
- * ring buffers, and other tracing utilites. It takes no
- * locks and can be called from any context.
- */
-void ftrace_off_permanent(void)
-{
-       tracing_disabled = 1;
-       ftrace_stop();
-       tracing_off_permanent();
-}
-
 /**
  * tracing_start - quick start of the tracer
  *
@@ -1631,7 +1639,7 @@ trace_function(struct trace_array *tr,
        entry->ip                       = ip;
        entry->parent_ip                = parent_ip;
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
 }
 
@@ -1715,7 +1723,7 @@ static void __ftrace_trace_stack(struct ring_buffer *buffer,
 
        entry->size = trace.nr_entries;
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
 
  out:
@@ -1817,7 +1825,7 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
        trace.entries           = entry->caller;
 
        save_stack_trace_user(&trace);
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
 
  out_drop_count:
@@ -2009,7 +2017,7 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
        entry->fmt                      = fmt;
 
        memcpy(entry->buf, tbuffer, sizeof(u32) * len);
-       if (!filter_check_discard(call, entry, buffer, event)) {
+       if (!call_filter_check_discard(call, entry, buffer, event)) {
                __buffer_unlock_commit(buffer, event);
                ftrace_trace_stack(buffer, flags, 6, pc);
        }
@@ -2064,7 +2072,7 @@ __trace_array_vprintk(struct ring_buffer *buffer,
 
        memcpy(&entry->buf, tbuffer, len);
        entry->buf[len] = '\0';
-       if (!filter_check_discard(call, entry, buffer, event)) {
+       if (!call_filter_check_discard(call, entry, buffer, event)) {
                __buffer_unlock_commit(buffer, event);
                ftrace_trace_stack(buffer, flags, 6, pc);
        }
@@ -2761,7 +2769,7 @@ static void show_snapshot_main_help(struct seq_file *m)
        seq_printf(m, "# echo 0 > snapshot : Clears and frees snapshot buffer\n");
        seq_printf(m, "# echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.\n");
        seq_printf(m, "#                      Takes a snapshot of the main buffer.\n");
-       seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate)\n");
+       seq_printf(m, "# echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)\n");
        seq_printf(m, "#                      (Doesn't have to be '2' works with any number that\n");
        seq_printf(m, "#                       is not a '0' or '1')\n");
 }
@@ -2965,6 +2973,11 @@ int tracing_open_generic(struct inode *inode, struct file *filp)
        return 0;
 }
 
+bool tracing_is_disabled(void)
+{
+       return (tracing_disabled) ? true: false;
+}
+
 /*
  * Open and update trace_array ref count.
  * Must have the current trace_array passed to it.
@@ -5455,12 +5468,12 @@ static struct ftrace_func_command ftrace_snapshot_cmd = {
        .func                   = ftrace_trace_snapshot_callback,
 };
 
-static int register_snapshot_cmd(void)
+static __init int register_snapshot_cmd(void)
 {
        return register_ftrace_command(&ftrace_snapshot_cmd);
 }
 #else
-static inline int register_snapshot_cmd(void) { return 0; }
+static inline __init int register_snapshot_cmd(void) { return 0; }
 #endif /* defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE) */
 
 struct dentry *tracing_init_dentry_tr(struct trace_array *tr)
@@ -6254,6 +6267,17 @@ void trace_init_global_iter(struct trace_iterator *iter)
        iter->trace = iter->tr->current_trace;
        iter->cpu_file = RING_BUFFER_ALL_CPUS;
        iter->trace_buffer = &global_trace.trace_buffer;
+
+       if (iter->trace && iter->trace->open)
+               iter->trace->open(iter);
+
+       /* Annotate start of buffers if we had overruns */
+       if (ring_buffer_overruns(iter->trace_buffer->buffer))
+               iter->iter_flags |= TRACE_FILE_ANNOTATE;
+
+       /* Output in nanoseconds only if we are using a clock in nanoseconds. */
+       if (trace_clocks[iter->tr->clock_id].in_ns)
+               iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
 }
 
 void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
index 73d08aa25b557a379a63c4602818c8cd33367547..ea189e027b80c3928a1c4390091b1eaa8f3699db 100644 (file)
@@ -193,8 +193,8 @@ struct trace_array {
 #ifdef CONFIG_FTRACE_SYSCALLS
        int                     sys_refcount_enter;
        int                     sys_refcount_exit;
-       DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls);
-       DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls);
+       struct ftrace_event_file __rcu *enter_syscall_files[NR_syscalls];
+       struct ftrace_event_file __rcu *exit_syscall_files[NR_syscalls];
 #endif
        int                     stop_count;
        int                     clock_id;
@@ -515,6 +515,7 @@ void tracing_reset_online_cpus(struct trace_buffer *buf);
 void tracing_reset_current(int cpu);
 void tracing_reset_all_online_cpus(void);
 int tracing_open_generic(struct inode *inode, struct file *filp);
+bool tracing_is_disabled(void);
 struct dentry *trace_create_file(const char *name,
                                 umode_t mode,
                                 struct dentry *parent,
@@ -712,6 +713,8 @@ extern unsigned long trace_flags;
 #define TRACE_GRAPH_PRINT_PROC          0x8
 #define TRACE_GRAPH_PRINT_DURATION      0x10
 #define TRACE_GRAPH_PRINT_ABS_TIME      0x20
+#define TRACE_GRAPH_PRINT_FILL_SHIFT   28
+#define TRACE_GRAPH_PRINT_FILL_MASK    (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
 
 extern enum print_line_t
 print_graph_function_flags(struct trace_iterator *iter, u32 flags);
@@ -731,15 +734,16 @@ extern void __trace_graph_return(struct trace_array *tr,
 #ifdef CONFIG_DYNAMIC_FTRACE
 /* TODO: make this variable */
 #define FTRACE_GRAPH_MAX_FUNCS         32
-extern int ftrace_graph_filter_enabled;
 extern int ftrace_graph_count;
 extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
+extern int ftrace_graph_notrace_count;
+extern unsigned long ftrace_graph_notrace_funcs[FTRACE_GRAPH_MAX_FUNCS];
 
 static inline int ftrace_graph_addr(unsigned long addr)
 {
        int i;
 
-       if (!ftrace_graph_filter_enabled)
+       if (!ftrace_graph_count)
                return 1;
 
        for (i = 0; i < ftrace_graph_count; i++) {
@@ -759,11 +763,31 @@ static inline int ftrace_graph_addr(unsigned long addr)
 
        return 0;
 }
+
+static inline int ftrace_graph_notrace_addr(unsigned long addr)
+{
+       int i;
+
+       if (!ftrace_graph_notrace_count)
+               return 0;
+
+       for (i = 0; i < ftrace_graph_notrace_count; i++) {
+               if (addr == ftrace_graph_notrace_funcs[i])
+                       return 1;
+       }
+
+       return 0;
+}
 #else
 static inline int ftrace_graph_addr(unsigned long addr)
 {
        return 1;
 }
+
+static inline int ftrace_graph_notrace_addr(unsigned long addr)
+{
+       return 0;
+}
 #endif /* CONFIG_DYNAMIC_FTRACE */
 #else /* CONFIG_FUNCTION_GRAPH_TRACER */
 static inline enum print_line_t
@@ -987,9 +1011,9 @@ struct filter_pred {
 
 extern enum regex_type
 filter_parse_regex(char *buff, int len, char **search, int *not);
-extern void print_event_filter(struct ftrace_event_call *call,
+extern void print_event_filter(struct ftrace_event_file *file,
                               struct trace_seq *s);
-extern int apply_event_filter(struct ftrace_event_call *call,
+extern int apply_event_filter(struct ftrace_event_file *file,
                              char *filter_string);
 extern int apply_subsystem_event_filter(struct ftrace_subsystem_dir *dir,
                                        char *filter_string);
@@ -1000,20 +1024,6 @@ extern int filter_assign_type(const char *type);
 struct ftrace_event_field *
 trace_find_event_field(struct ftrace_event_call *call, char *name);
 
-static inline int
-filter_check_discard(struct ftrace_event_call *call, void *rec,
-                    struct ring_buffer *buffer,
-                    struct ring_buffer_event *event)
-{
-       if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
-           !filter_match_preds(call->filter, rec)) {
-               ring_buffer_discard_commit(buffer, event);
-               return 1;
-       }
-
-       return 0;
-}
-
 extern void trace_event_enable_cmd_record(bool enable);
 extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
 extern int event_trace_del_tracer(struct trace_array *tr);
index d594da0dc03ce53db530e238df1d410c4b89e29a..697fb9bac8f0d69d8e5a5023d5e5d10fdd3ed09c 100644 (file)
@@ -78,7 +78,7 @@ probe_likely_condition(struct ftrace_branch_data *f, int val, int expect)
        entry->line = f->line;
        entry->correct = val == expect;
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
 
  out:
index 368a4d50cc308cbe9564d4b01925b7937b0c4aba..f919a2e21bf30e68ad6a99ee627d63f5bb6cb44c 100644 (file)
@@ -989,7 +989,7 @@ static ssize_t
 event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
                  loff_t *ppos)
 {
-       struct ftrace_event_call *call;
+       struct ftrace_event_file *file;
        struct trace_seq *s;
        int r = -ENODEV;
 
@@ -1004,12 +1004,12 @@ event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
        trace_seq_init(s);
 
        mutex_lock(&event_mutex);
-       call = event_file_data(filp);
-       if (call)
-               print_event_filter(call, s);
+       file = event_file_data(filp);
+       if (file)
+               print_event_filter(file, s);
        mutex_unlock(&event_mutex);
 
-       if (call)
+       if (file)
                r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
 
        kfree(s);
@@ -1021,7 +1021,7 @@ static ssize_t
 event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
                   loff_t *ppos)
 {
-       struct ftrace_event_call *call;
+       struct ftrace_event_file *file;
        char *buf;
        int err = -ENODEV;
 
@@ -1039,9 +1039,9 @@ event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
        buf[cnt] = '\0';
 
        mutex_lock(&event_mutex);
-       call = event_file_data(filp);
-       if (call)
-               err = apply_event_filter(call, buf);
+       file = event_file_data(filp);
+       if (file)
+               err = apply_event_filter(file, buf);
        mutex_unlock(&event_mutex);
 
        free_page((unsigned long) buf);
@@ -1062,6 +1062,9 @@ static int subsystem_open(struct inode *inode, struct file *filp)
        struct trace_array *tr;
        int ret;
 
+       if (tracing_is_disabled())
+               return -ENODEV;
+
        /* Make sure the system still exists */
        mutex_lock(&trace_types_lock);
        mutex_lock(&event_mutex);
@@ -1108,6 +1111,9 @@ static int system_tr_open(struct inode *inode, struct file *filp)
        struct trace_array *tr = inode->i_private;
        int ret;
 
+       if (tracing_is_disabled())
+               return -ENODEV;
+
        if (trace_array_get(tr) < 0)
                return -ENODEV;
 
@@ -1124,11 +1130,12 @@ static int system_tr_open(struct inode *inode, struct file *filp)
        if (ret < 0) {
                trace_array_put(tr);
                kfree(dir);
+               return ret;
        }
 
        filp->private_data = dir;
 
-       return ret;
+       return 0;
 }
 
 static int subsystem_release(struct inode *inode, struct file *file)
@@ -1539,7 +1546,7 @@ event_create_dir(struct dentry *parent, struct ftrace_event_file *file)
                        return -1;
                }
        }
-       trace_create_file("filter", 0644, file->dir, call,
+       trace_create_file("filter", 0644, file->dir, file,
                          &ftrace_event_filter_fops);
 
        trace_create_file("format", 0444, file->dir, call,
@@ -1577,6 +1584,7 @@ static void event_remove(struct ftrace_event_call *call)
                if (file->event_call != call)
                        continue;
                ftrace_event_enable_disable(file, 0);
+               destroy_preds(file);
                /*
                 * The do_for_each_event_file() is
                 * a double loop. After finding the call for this
@@ -1700,7 +1708,7 @@ static void __trace_remove_event_call(struct ftrace_event_call *call)
 {
        event_remove(call);
        trace_destroy_fields(call);
-       destroy_preds(call);
+       destroy_call_preds(call);
 }
 
 static int probe_remove_event_call(struct ftrace_event_call *call)
index 97daa8cf958df8e73c9fa8090f89cbaf4e63893e..2468f56dc5db2d1403df5692f1d9e0da912d6a1c 100644 (file)
@@ -637,10 +637,18 @@ static void append_filter_err(struct filter_parse_state *ps,
        free_page((unsigned long) buf);
 }
 
+static inline struct event_filter *event_filter(struct ftrace_event_file *file)
+{
+       if (file->event_call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               return file->event_call->filter;
+       else
+               return file->filter;
+}
+
 /* caller must hold event_mutex */
-void print_event_filter(struct ftrace_event_call *call, struct trace_seq *s)
+void print_event_filter(struct ftrace_event_file *file, struct trace_seq *s)
 {
-       struct event_filter *filter = call->filter;
+       struct event_filter *filter = event_filter(file);
 
        if (filter && filter->filter_string)
                trace_seq_printf(s, "%s\n", filter->filter_string);
@@ -766,11 +774,21 @@ static void __free_preds(struct event_filter *filter)
        filter->n_preds = 0;
 }
 
-static void filter_disable(struct ftrace_event_call *call)
+static void call_filter_disable(struct ftrace_event_call *call)
 {
        call->flags &= ~TRACE_EVENT_FL_FILTERED;
 }
 
+static void filter_disable(struct ftrace_event_file *file)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               call_filter_disable(call);
+       else
+               file->flags &= ~FTRACE_EVENT_FL_FILTERED;
+}
+
 static void __free_filter(struct event_filter *filter)
 {
        if (!filter)
@@ -781,16 +799,30 @@ static void __free_filter(struct event_filter *filter)
        kfree(filter);
 }
 
+void destroy_call_preds(struct ftrace_event_call *call)
+{
+       __free_filter(call->filter);
+       call->filter = NULL;
+}
+
+static void destroy_file_preds(struct ftrace_event_file *file)
+{
+       __free_filter(file->filter);
+       file->filter = NULL;
+}
+
 /*
- * Called when destroying the ftrace_event_call.
- * The call is being freed, so we do not need to worry about
- * the call being currently used. This is for module code removing
+ * Called when destroying the ftrace_event_file.
+ * The file is being freed, so we do not need to worry about
+ * the file being currently used. This is for module code removing
  * the tracepoints from within it.
  */
-void destroy_preds(struct ftrace_event_call *call)
+void destroy_preds(struct ftrace_event_file *file)
 {
-       __free_filter(call->filter);
-       call->filter = NULL;
+       if (file->event_call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               destroy_call_preds(file->event_call);
+       else
+               destroy_file_preds(file);
 }
 
 static struct event_filter *__alloc_filter(void)
@@ -825,28 +857,56 @@ static int __alloc_preds(struct event_filter *filter, int n_preds)
        return 0;
 }
 
-static void filter_free_subsystem_preds(struct event_subsystem *system)
+static inline void __remove_filter(struct ftrace_event_file *file)
 {
+       struct ftrace_event_call *call = file->event_call;
+
+       filter_disable(file);
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               remove_filter_string(call->filter);
+       else
+               remove_filter_string(file->filter);
+}
+
+static void filter_free_subsystem_preds(struct event_subsystem *system,
+                                       struct trace_array *tr)
+{
+       struct ftrace_event_file *file;
        struct ftrace_event_call *call;
 
-       list_for_each_entry(call, &ftrace_events, list) {
+       list_for_each_entry(file, &tr->events, list) {
+               call = file->event_call;
                if (strcmp(call->class->system, system->name) != 0)
                        continue;
 
-               filter_disable(call);
-               remove_filter_string(call->filter);
+               __remove_filter(file);
        }
 }
 
-static void filter_free_subsystem_filters(struct event_subsystem *system)
+static inline void __free_subsystem_filter(struct ftrace_event_file *file)
 {
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER) {
+               __free_filter(call->filter);
+               call->filter = NULL;
+       } else {
+               __free_filter(file->filter);
+               file->filter = NULL;
+       }
+}
+
+static void filter_free_subsystem_filters(struct event_subsystem *system,
+                                         struct trace_array *tr)
+{
+       struct ftrace_event_file *file;
        struct ftrace_event_call *call;
 
-       list_for_each_entry(call, &ftrace_events, list) {
+       list_for_each_entry(file, &tr->events, list) {
+               call = file->event_call;
                if (strcmp(call->class->system, system->name) != 0)
                        continue;
-               __free_filter(call->filter);
-               call->filter = NULL;
+               __free_subsystem_filter(file);
        }
 }
 
@@ -1617,15 +1677,85 @@ fail:
        return err;
 }
 
+static inline void event_set_filtered_flag(struct ftrace_event_file *file)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               call->flags |= TRACE_EVENT_FL_FILTERED;
+       else
+               file->flags |= FTRACE_EVENT_FL_FILTERED;
+}
+
+static inline void event_set_filter(struct ftrace_event_file *file,
+                                   struct event_filter *filter)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               rcu_assign_pointer(call->filter, filter);
+       else
+               rcu_assign_pointer(file->filter, filter);
+}
+
+static inline void event_clear_filter(struct ftrace_event_file *file)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               RCU_INIT_POINTER(call->filter, NULL);
+       else
+               RCU_INIT_POINTER(file->filter, NULL);
+}
+
+static inline void
+event_set_no_set_filter_flag(struct ftrace_event_file *file)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               call->flags |= TRACE_EVENT_FL_NO_SET_FILTER;
+       else
+               file->flags |= FTRACE_EVENT_FL_NO_SET_FILTER;
+}
+
+static inline void
+event_clear_no_set_filter_flag(struct ftrace_event_file *file)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (call->flags & TRACE_EVENT_FL_USE_CALL_FILTER)
+               call->flags &= ~TRACE_EVENT_FL_NO_SET_FILTER;
+       else
+               file->flags &= ~FTRACE_EVENT_FL_NO_SET_FILTER;
+}
+
+static inline bool
+event_no_set_filter_flag(struct ftrace_event_file *file)
+{
+       struct ftrace_event_call *call = file->event_call;
+
+       if (file->flags & FTRACE_EVENT_FL_NO_SET_FILTER)
+               return true;
+
+       if ((call->flags & TRACE_EVENT_FL_USE_CALL_FILTER) &&
+           (call->flags & TRACE_EVENT_FL_NO_SET_FILTER))
+               return true;
+
+       return false;
+}
+
 struct filter_list {
        struct list_head        list;
        struct event_filter     *filter;
 };
 
 static int replace_system_preds(struct event_subsystem *system,
+                               struct trace_array *tr,
                                struct filter_parse_state *ps,
                                char *filter_string)
 {
+       struct ftrace_event_file *file;
        struct ftrace_event_call *call;
        struct filter_list *filter_item;
        struct filter_list *tmp;
@@ -1633,8 +1763,8 @@ static int replace_system_preds(struct event_subsystem *system,
        bool fail = true;
        int err;
 
-       list_for_each_entry(call, &ftrace_events, list) {
-
+       list_for_each_entry(file, &tr->events, list) {
+               call = file->event_call;
                if (strcmp(call->class->system, system->name) != 0)
                        continue;
 
@@ -1644,18 +1774,20 @@ static int replace_system_preds(struct event_subsystem *system,
                 */
                err = replace_preds(call, NULL, ps, filter_string, true);
                if (err)
-                       call->flags |= TRACE_EVENT_FL_NO_SET_FILTER;
+                       event_set_no_set_filter_flag(file);
                else
-                       call->flags &= ~TRACE_EVENT_FL_NO_SET_FILTER;
+                       event_clear_no_set_filter_flag(file);
        }
 
-       list_for_each_entry(call, &ftrace_events, list) {
+       list_for_each_entry(file, &tr->events, list) {
                struct event_filter *filter;
 
+               call = file->event_call;
+
                if (strcmp(call->class->system, system->name) != 0)
                        continue;
 
-               if (call->flags & TRACE_EVENT_FL_NO_SET_FILTER)
+               if (event_no_set_filter_flag(file))
                        continue;
 
                filter_item = kzalloc(sizeof(*filter_item), GFP_KERNEL);
@@ -1676,17 +1808,17 @@ static int replace_system_preds(struct event_subsystem *system,
 
                err = replace_preds(call, filter, ps, filter_string, false);
                if (err) {
-                       filter_disable(call);
+                       filter_disable(file);
                        parse_error(ps, FILT_ERR_BAD_SUBSYS_FILTER, 0);
                        append_filter_err(ps, filter);
                } else
-                       call->flags |= TRACE_EVENT_FL_FILTERED;
+                       event_set_filtered_flag(file);
                /*
                 * Regardless of if this returned an error, we still
                 * replace the filter for the call.
                 */
-               filter = call->filter;
-               rcu_assign_pointer(call->filter, filter_item->filter);
+               filter = event_filter(file);
+               event_set_filter(file, filter_item->filter);
                filter_item->filter = filter;
 
                fail = false;
@@ -1816,6 +1948,7 @@ static int create_filter(struct ftrace_event_call *call,
  * and always remembers @filter_str.
  */
 static int create_system_filter(struct event_subsystem *system,
+                               struct trace_array *tr,
                                char *filter_str, struct event_filter **filterp)
 {
        struct event_filter *filter = NULL;
@@ -1824,7 +1957,7 @@ static int create_system_filter(struct event_subsystem *system,
 
        err = create_filter_start(filter_str, true, &ps, &filter);
        if (!err) {
-               err = replace_system_preds(system, ps, filter_str);
+               err = replace_system_preds(system, tr, ps, filter_str);
                if (!err) {
                        /* System filters just show a default message */
                        kfree(filter->filter_string);
@@ -1840,20 +1973,25 @@ static int create_system_filter(struct event_subsystem *system,
 }
 
 /* caller must hold event_mutex */
-int apply_event_filter(struct ftrace_event_call *call, char *filter_string)
+int apply_event_filter(struct ftrace_event_file *file, char *filter_string)
 {
+       struct ftrace_event_call *call = file->event_call;
        struct event_filter *filter;
        int err;
 
        if (!strcmp(strstrip(filter_string), "0")) {
-               filter_disable(call);
-               filter = call->filter;
+               filter_disable(file);
+               filter = event_filter(file);
+
                if (!filter)
                        return 0;
-               RCU_INIT_POINTER(call->filter, NULL);
+
+               event_clear_filter(file);
+
                /* Make sure the filter is not being used */
                synchronize_sched();
                __free_filter(filter);
+
                return 0;
        }
 
@@ -1866,14 +2004,15 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string)
         * string
         */
        if (filter) {
-               struct event_filter *tmp = call->filter;
+               struct event_filter *tmp;
 
+               tmp = event_filter(file);
                if (!err)
-                       call->flags |= TRACE_EVENT_FL_FILTERED;
+                       event_set_filtered_flag(file);
                else
-                       filter_disable(call);
+                       filter_disable(file);
 
-               rcu_assign_pointer(call->filter, filter);
+               event_set_filter(file, filter);
 
                if (tmp) {
                        /* Make sure the call is done with the filter */
@@ -1889,6 +2028,7 @@ int apply_subsystem_event_filter(struct ftrace_subsystem_dir *dir,
                                 char *filter_string)
 {
        struct event_subsystem *system = dir->subsystem;
+       struct trace_array *tr = dir->tr;
        struct event_filter *filter;
        int err = 0;
 
@@ -1901,18 +2041,18 @@ int apply_subsystem_event_filter(struct ftrace_subsystem_dir *dir,
        }
 
        if (!strcmp(strstrip(filter_string), "0")) {
-               filter_free_subsystem_preds(system);
+               filter_free_subsystem_preds(system, tr);
                remove_filter_string(system->filter);
                filter = system->filter;
                system->filter = NULL;
                /* Ensure all filters are no longer used */
                synchronize_sched();
-               filter_free_subsystem_filters(system);
+               filter_free_subsystem_filters(system, tr);
                __free_filter(filter);
                goto out_unlock;
        }
 
-       err = create_system_filter(system, filter_string, &filter);
+       err = create_system_filter(system, tr, filter_string, &filter);
        if (filter) {
                /*
                 * No event actually uses the system filter
index d21a74670088345fd97a81724e894ba9a0baff79..7c3e3e72e2b6bd2f0a6bd929ff67526497281b4a 100644 (file)
@@ -180,7 +180,7 @@ struct ftrace_event_call __used event_##call = {                    \
        .event.type             = etype,                                \
        .class                  = &event_class_ftrace_##call,           \
        .print_fmt              = print,                                \
-       .flags                  = TRACE_EVENT_FL_IGNORE_ENABLE,         \
+       .flags                  = TRACE_EVENT_FL_IGNORE_ENABLE | TRACE_EVENT_FL_USE_CALL_FILTER, \
 };                                                                     \
 struct ftrace_event_call __used                                                \
 __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
index b5c09242683d8cd1c989d2706702d4d42e182d73..0b99120d395cc166583e400e80108b7d07540935 100644 (file)
@@ -82,9 +82,9 @@ static struct trace_array *graph_array;
  * to fill in space into DURATION column.
  */
 enum {
-       DURATION_FILL_FULL  = -1,
-       DURATION_FILL_START = -2,
-       DURATION_FILL_END   = -3,
+       FLAGS_FILL_FULL  = 1 << TRACE_GRAPH_PRINT_FILL_SHIFT,
+       FLAGS_FILL_START = 2 << TRACE_GRAPH_PRINT_FILL_SHIFT,
+       FLAGS_FILL_END   = 3 << TRACE_GRAPH_PRINT_FILL_SHIFT,
 };
 
 static enum print_line_t
@@ -114,16 +114,37 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
                return -EBUSY;
        }
 
+       /*
+        * The curr_ret_stack is an index to ftrace return stack of
+        * current task.  Its value should be in [0, FTRACE_RETFUNC_
+        * DEPTH) when the function graph tracer is used.  To support
+        * filtering out specific functions, it makes the index
+        * negative by subtracting huge value (FTRACE_NOTRACE_DEPTH)
+        * so when it sees a negative index the ftrace will ignore
+        * the record.  And the index gets recovered when returning
+        * from the filtered function by adding the FTRACE_NOTRACE_
+        * DEPTH and then it'll continue to record functions normally.
+        *
+        * The curr_ret_stack is initialized to -1 and get increased
+        * in this function.  So it can be less than -1 only if it was
+        * filtered out via ftrace_graph_notrace_addr() which can be
+        * set from set_graph_notrace file in debugfs by user.
+        */
+       if (current->curr_ret_stack < -1)
+               return -EBUSY;
+
        calltime = trace_clock_local();
 
        index = ++current->curr_ret_stack;
+       if (ftrace_graph_notrace_addr(func))
+               current->curr_ret_stack -= FTRACE_NOTRACE_DEPTH;
        barrier();
        current->ret_stack[index].ret = ret;
        current->ret_stack[index].func = func;
        current->ret_stack[index].calltime = calltime;
        current->ret_stack[index].subtime = 0;
        current->ret_stack[index].fp = frame_pointer;
-       *depth = index;
+       *depth = current->curr_ret_stack;
 
        return 0;
 }
@@ -137,7 +158,17 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
 
        index = current->curr_ret_stack;
 
-       if (unlikely(index < 0)) {
+       /*
+        * A negative index here means that it's just returned from a
+        * notrace'd function.  Recover index to get an original
+        * return address.  See ftrace_push_return_trace().
+        *
+        * TODO: Need to check whether the stack gets corrupted.
+        */
+       if (index < 0)
+               index += FTRACE_NOTRACE_DEPTH;
+
+       if (unlikely(index < 0 || index >= FTRACE_RETFUNC_DEPTH)) {
                ftrace_graph_stop();
                WARN_ON(1);
                /* Might as well panic, otherwise we have no where to go */
@@ -193,6 +224,15 @@ unsigned long ftrace_return_to_handler(unsigned long frame_pointer)
        trace.rettime = trace_clock_local();
        barrier();
        current->curr_ret_stack--;
+       /*
+        * The curr_ret_stack can be less than -1 only if it was
+        * filtered out and it's about to return from the function.
+        * Recover the index and continue to trace normal functions.
+        */
+       if (current->curr_ret_stack < -1) {
+               current->curr_ret_stack += FTRACE_NOTRACE_DEPTH;
+               return ret;
+       }
 
        /*
         * The trace should run after decrementing the ret counter
@@ -230,7 +270,7 @@ int __trace_graph_entry(struct trace_array *tr,
                return 0;
        entry   = ring_buffer_event_data(event);
        entry->graph_ent                        = *trace;
-       if (!filter_current_check_discard(buffer, call, entry, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
 
        return 1;
@@ -259,10 +299,20 @@ int trace_graph_entry(struct ftrace_graph_ent *trace)
 
        /* trace it when it is-nested-in or is a function enabled. */
        if ((!(trace->depth || ftrace_graph_addr(trace->func)) ||
-            ftrace_graph_ignore_irqs()) ||
+            ftrace_graph_ignore_irqs()) || (trace->depth < 0) ||
            (max_depth && trace->depth >= max_depth))
                return 0;
 
+       /*
+        * Do not trace a function if it's filtered by set_graph_notrace.
+        * Make the index of ret stack negative to indicate that it should
+        * ignore further functions.  But it needs its own ret stack entry
+        * to recover the original index in order to continue tracing after
+        * returning from the function.
+        */
+       if (ftrace_graph_notrace_addr(trace->func))
+               return 1;
+
        local_irq_save(flags);
        cpu = raw_smp_processor_id();
        data = per_cpu_ptr(tr->trace_buffer.data, cpu);
@@ -335,7 +385,7 @@ void __trace_graph_return(struct trace_array *tr,
                return;
        entry   = ring_buffer_event_data(event);
        entry->ret                              = *trace;
-       if (!filter_current_check_discard(buffer, call, entry, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                __buffer_unlock_commit(buffer, event);
 }
 
@@ -652,7 +702,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
        }
 
        /* No overhead */
-       ret = print_graph_duration(DURATION_FILL_START, s, flags);
+       ret = print_graph_duration(0, s, flags | FLAGS_FILL_START);
        if (ret != TRACE_TYPE_HANDLED)
                return ret;
 
@@ -664,7 +714,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
        if (!ret)
                return TRACE_TYPE_PARTIAL_LINE;
 
-       ret = print_graph_duration(DURATION_FILL_END, s, flags);
+       ret = print_graph_duration(0, s, flags | FLAGS_FILL_END);
        if (ret != TRACE_TYPE_HANDLED)
                return ret;
 
@@ -729,14 +779,14 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s,
                        return TRACE_TYPE_HANDLED;
 
        /* No real adata, just filling the column with spaces */
-       switch (duration) {
-       case DURATION_FILL_FULL:
+       switch (flags & TRACE_GRAPH_PRINT_FILL_MASK) {
+       case FLAGS_FILL_FULL:
                ret = trace_seq_puts(s, "              |  ");
                return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
-       case DURATION_FILL_START:
+       case FLAGS_FILL_START:
                ret = trace_seq_puts(s, "  ");
                return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
-       case DURATION_FILL_END:
+       case FLAGS_FILL_END:
                ret = trace_seq_puts(s, " |");
                return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
        }
@@ -852,7 +902,7 @@ print_graph_entry_nested(struct trace_iterator *iter,
        }
 
        /* No time */
-       ret = print_graph_duration(DURATION_FILL_FULL, s, flags);
+       ret = print_graph_duration(0, s, flags | FLAGS_FILL_FULL);
        if (ret != TRACE_TYPE_HANDLED)
                return ret;
 
@@ -1172,7 +1222,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* No time */
-       ret = print_graph_duration(DURATION_FILL_FULL, s, flags);
+       ret = print_graph_duration(0, s, flags | FLAGS_FILL_FULL);
        if (ret != TRACE_TYPE_HANDLED)
                return ret;
 
index 243f6834d02675c9c1101e1eabe18e56eb7d3244..dae9541ada9ea9f46723878979f951834e8e84f1 100644 (file)
@@ -835,7 +835,7 @@ __kprobe_trace_func(struct trace_probe *tp, struct pt_regs *regs,
        entry->ip = (unsigned long)tp->rp.kp.addr;
        store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize);
 
-       if (!filter_current_check_discard(buffer, call, entry, event))
+       if (!filter_check_discard(ftrace_file, entry, buffer, event))
                trace_buffer_unlock_commit_regs(buffer, event,
                                                irq_flags, pc, regs);
 }
@@ -884,7 +884,7 @@ __kretprobe_trace_func(struct trace_probe *tp, struct kretprobe_instance *ri,
        entry->ret_ip = (unsigned long)ri->ret_addr;
        store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize);
 
-       if (!filter_current_check_discard(buffer, call, entry, event))
+       if (!filter_check_discard(ftrace_file, entry, buffer, event))
                trace_buffer_unlock_commit_regs(buffer, event,
                                                irq_flags, pc, regs);
 }
index b3dcfb2f0fef4e1bc9e9815021adc3e8dfe7d32a..0abd9b8634747e3001354f96b90dad379d6d2fd6 100644 (file)
@@ -323,7 +323,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
        entry   = ring_buffer_event_data(event);
        entry->rw                       = *rw;
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                trace_buffer_unlock_commit(buffer, event, 0, pc);
 }
 
@@ -353,7 +353,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
        entry   = ring_buffer_event_data(event);
        entry->map                      = *map;
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                trace_buffer_unlock_commit(buffer, event, 0, pc);
 }
 
index 4e98e3b257a3a74d3716a0fc4ab35c2a1530fc43..3f34dc9b40f350bac7ae8869b17e4f5216b05d1a 100644 (file)
@@ -45,7 +45,7 @@ tracing_sched_switch_trace(struct trace_array *tr,
        entry->next_state               = next->state;
        entry->next_cpu = task_cpu(next);
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                trace_buffer_unlock_commit(buffer, event, flags, pc);
 }
 
@@ -101,7 +101,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr,
        entry->next_state               = wakee->state;
        entry->next_cpu                 = task_cpu(wakee);
 
-       if (!filter_check_discard(call, entry, buffer, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                trace_buffer_unlock_commit(buffer, event, flags, pc);
 }
 
index 847f88a6194b4e4183e0ed08dd03828f6e5ff1bd..7af67360b3307413865e2ed0719ea63894f01016 100644 (file)
@@ -43,46 +43,15 @@ static DEFINE_MUTEX(all_stat_sessions_mutex);
 /* The root directory for all stat files */
 static struct dentry           *stat_dir;
 
-/*
- * Iterate through the rbtree using a post order traversal path
- * to release the next node.
- * It won't necessary release one at each iteration
- * but it will at least advance closer to the next one
- * to be released.
- */
-static struct rb_node *release_next(struct tracer_stat *ts,
-                                   struct rb_node *node)
+static void __reset_stat_session(struct stat_session *session)
 {
-       struct stat_node *snode;
-       struct rb_node *parent = rb_parent(node);
-
-       if (node->rb_left)
-               return node->rb_left;
-       else if (node->rb_right)
-               return node->rb_right;
-       else {
-               if (!parent)
-                       ;
-               else if (parent->rb_left == node)
-                       parent->rb_left = NULL;
-               else
-                       parent->rb_right = NULL;
+       struct stat_node *snode, *n;
 
-               snode = container_of(node, struct stat_node, node);
-               if (ts->stat_release)
-                       ts->stat_release(snode->stat);
+       rbtree_postorder_for_each_entry_safe(snode, n, &session->stat_root, node) {
+               if (session->ts->stat_release)
+                       session->ts->stat_release(snode->stat);
                kfree(snode);
-
-               return parent;
        }
-}
-
-static void __reset_stat_session(struct stat_session *session)
-{
-       struct rb_node *node = session->stat_root.rb_node;
-
-       while (node)
-               node = release_next(session->ts, node);
 
        session->stat_root = RB_ROOT;
 }
index 559329d9bd2fa4d9dd22f2ce31b4dcba6b5f1119..e4b6d11bdf78f35a2a6d8e831cd3ec21d97d9c00 100644 (file)
@@ -302,6 +302,7 @@ static int __init syscall_exit_define_fields(struct ftrace_event_call *call)
 static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
 {
        struct trace_array *tr = data;
+       struct ftrace_event_file *ftrace_file;
        struct syscall_trace_enter *entry;
        struct syscall_metadata *sys_data;
        struct ring_buffer_event *event;
@@ -314,7 +315,13 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
        syscall_nr = trace_get_syscall_nr(current, regs);
        if (syscall_nr < 0)
                return;
-       if (!test_bit(syscall_nr, tr->enabled_enter_syscalls))
+
+       /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE) */
+       ftrace_file = rcu_dereference_sched(tr->enter_syscall_files[syscall_nr]);
+       if (!ftrace_file)
+               return;
+
+       if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &ftrace_file->flags))
                return;
 
        sys_data = syscall_nr_to_meta(syscall_nr);
@@ -336,8 +343,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
        entry->nr = syscall_nr;
        syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args);
 
-       if (!filter_current_check_discard(buffer, sys_data->enter_event,
-                                         entry, event))
+       if (!filter_check_discard(ftrace_file, entry, buffer, event))
                trace_current_buffer_unlock_commit(buffer, event,
                                                   irq_flags, pc);
 }
@@ -345,6 +351,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
 static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
 {
        struct trace_array *tr = data;
+       struct ftrace_event_file *ftrace_file;
        struct syscall_trace_exit *entry;
        struct syscall_metadata *sys_data;
        struct ring_buffer_event *event;
@@ -356,7 +363,13 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
        syscall_nr = trace_get_syscall_nr(current, regs);
        if (syscall_nr < 0)
                return;
-       if (!test_bit(syscall_nr, tr->enabled_exit_syscalls))
+
+       /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE()) */
+       ftrace_file = rcu_dereference_sched(tr->exit_syscall_files[syscall_nr]);
+       if (!ftrace_file)
+               return;
+
+       if (test_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &ftrace_file->flags))
                return;
 
        sys_data = syscall_nr_to_meta(syscall_nr);
@@ -377,8 +390,7 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
        entry->nr = syscall_nr;
        entry->ret = syscall_get_return_value(current, regs);
 
-       if (!filter_current_check_discard(buffer, sys_data->exit_event,
-                                         entry, event))
+       if (!filter_check_discard(ftrace_file, entry, buffer, event))
                trace_current_buffer_unlock_commit(buffer, event,
                                                   irq_flags, pc);
 }
@@ -397,7 +409,7 @@ static int reg_event_syscall_enter(struct ftrace_event_file *file,
        if (!tr->sys_refcount_enter)
                ret = register_trace_sys_enter(ftrace_syscall_enter, tr);
        if (!ret) {
-               set_bit(num, tr->enabled_enter_syscalls);
+               rcu_assign_pointer(tr->enter_syscall_files[num], file);
                tr->sys_refcount_enter++;
        }
        mutex_unlock(&syscall_trace_lock);
@@ -415,10 +427,15 @@ static void unreg_event_syscall_enter(struct ftrace_event_file *file,
                return;
        mutex_lock(&syscall_trace_lock);
        tr->sys_refcount_enter--;
-       clear_bit(num, tr->enabled_enter_syscalls);
+       rcu_assign_pointer(tr->enter_syscall_files[num], NULL);
        if (!tr->sys_refcount_enter)
                unregister_trace_sys_enter(ftrace_syscall_enter, tr);
        mutex_unlock(&syscall_trace_lock);
+       /*
+        * Callers expect the event to be completely disabled on
+        * return, so wait for current handlers to finish.
+        */
+       synchronize_sched();
 }
 
 static int reg_event_syscall_exit(struct ftrace_event_file *file,
@@ -435,7 +452,7 @@ static int reg_event_syscall_exit(struct ftrace_event_file *file,
        if (!tr->sys_refcount_exit)
                ret = register_trace_sys_exit(ftrace_syscall_exit, tr);
        if (!ret) {
-               set_bit(num, tr->enabled_exit_syscalls);
+               rcu_assign_pointer(tr->exit_syscall_files[num], file);
                tr->sys_refcount_exit++;
        }
        mutex_unlock(&syscall_trace_lock);
@@ -453,10 +470,15 @@ static void unreg_event_syscall_exit(struct ftrace_event_file *file,
                return;
        mutex_lock(&syscall_trace_lock);
        tr->sys_refcount_exit--;
-       clear_bit(num, tr->enabled_exit_syscalls);
+       rcu_assign_pointer(tr->exit_syscall_files[num], NULL);
        if (!tr->sys_refcount_exit)
                unregister_trace_sys_exit(ftrace_syscall_exit, tr);
        mutex_unlock(&syscall_trace_lock);
+       /*
+        * Callers expect the event to be completely disabled on
+        * return, so wait for current handlers to finish.
+        */
+       synchronize_sched();
 }
 
 static int __init init_syscall_trace(struct ftrace_event_call *call)
index 272261b5f94ff84e3291be05aaa3b1a8c1ca00ca..b6dcc42ef7f5043e6115c53a5a47aa631bd04c57 100644 (file)
@@ -128,6 +128,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
        if (is_ret)
                tu->consumer.ret_handler = uretprobe_dispatcher;
        init_trace_uprobe_filter(&tu->filter);
+       tu->call.flags |= TRACE_EVENT_FL_USE_CALL_FILTER;
        return tu;
 
 error:
@@ -561,7 +562,7 @@ static void uprobe_trace_print(struct trace_uprobe *tu,
        for (i = 0; i < tu->nr_args; i++)
                call_fetch(&tu->args[i].fetch, regs, data + tu->args[i].offset);
 
-       if (!filter_current_check_discard(buffer, call, entry, event))
+       if (!call_filter_check_discard(call, entry, buffer, event))
                trace_buffer_unlock_commit(buffer, event, 0, 0);
 }
 
index 82da4f4c3489eb0fa2a814adf477be16c14cbed4..1e5b2df442916de82ef497f844c068724f8cd555 100644 (file)
@@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
 static void __prandom_timer(unsigned long dontcare)
 {
        u32 entropy;
+       unsigned long expires;
 
        get_random_bytes(&entropy, sizeof(entropy));
        prandom_seed(entropy);
+
        /* reseed every ~60 seconds, in [40 .. 80) interval with slack */
-       seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
+       expires = 40 + (prandom_u32() % 40);
+       seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
+
        add_timer(&seed_timer);
 }
 
-static void prandom_start_seed_timer(void)
+static void __init __prandom_start_seed_timer(void)
 {
        set_timer_slack(&seed_timer, HZ);
-       seed_timer.expires = jiffies + 40 * HZ;
+       seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
        add_timer(&seed_timer);
 }
 
@@ -270,7 +274,7 @@ void prandom_reseed_late(void)
 static int __init prandom_reseed(void)
 {
        __prandom_reseed(false);
-       prandom_start_seed_timer();
+       __prandom_start_seed_timer();
        return 0;
 }
 late_initcall(prandom_reseed);
index de31af25620713e5e689c026abf8195e59e94653..eb69f352401de910552fb7f28959b38f4746a878 100644 (file)
@@ -20,7 +20,7 @@ config FLATMEM_MANUAL
 
          Some users of more advanced features like NUMA and
          memory hotplug may have different options here.
-         DISCONTIGMEM is an more mature, better tested system,
+         DISCONTIGMEM is a more mature, better tested system,
          but is incompatible with memory hotplug and may suffer
          decreased performance over SPARSEMEM.  If unsure between
          "Sparse Memory" and "Discontiguous Memory", choose
index 92737a0b787b57b0e5d8467879b50b4915a43f9e..7e8bd8d828bc0e5c7e96919c6e24186d8d5382df 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -955,7 +955,7 @@ static inline void slab_free_hook(struct kmem_cache *s, void *x)
        kmemleak_free_recursive(x, s->flags);
 
        /*
-        * Trouble is that we may no longer disable interupts in the fast path
+        * Trouble is that we may no longer disable interrupts in the fast path
         * So in order to make the debug calls that expect irqs to be
         * disabled we need to disable interrupts temporarily.
         */
index c41d5fbb91d0c3e07bf0eff148d57e6cd74ef8d0..6e6194fcd88e1c3427c24a9c914956cc1bd1e66d 100644 (file)
@@ -172,6 +172,7 @@ void br_dev_delete(struct net_device *dev, struct list_head *head)
                del_nbp(p);
        }
 
+       br_vlan_flush(br);
        del_timer_sync(&br->gc_timer);
 
        br_sysfs_delbr(br->dev);
index 53f0990eab58e08a3da9160a27ee0834bd0f0272..af5ebd18d7059f2d0cc289e226c544f210309dc2 100644 (file)
@@ -34,7 +34,6 @@ static void __vlan_add_flags(struct net_port_vlans *v, u16 vid, u16 flags)
 
 static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
 {
-       const struct net_device_ops *ops;
        struct net_bridge_port *p = NULL;
        struct net_bridge *br;
        struct net_device *dev;
@@ -53,17 +52,15 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
                br = v->parent.br;
                dev = br->dev;
        }
-       ops = dev->netdev_ops;
 
-       if (p && (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) {
+       if (p) {
                /* Add VLAN to the device filter if it is supported.
                 * Stricly speaking, this is not necessary now, since
                 * devices are made promiscuous by the bridge, but if
                 * that ever changes this code will allow tagged
                 * traffic to enter the bridge.
                 */
-               err = ops->ndo_vlan_rx_add_vid(dev, htons(ETH_P_8021Q),
-                                              vid);
+               err = vlan_vid_add(dev, htons(ETH_P_8021Q), vid);
                if (err)
                        return err;
        }
@@ -82,8 +79,8 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
        return 0;
 
 out_filt:
-       if (p && (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
-               ops->ndo_vlan_rx_kill_vid(dev, htons(ETH_P_8021Q), vid);
+       if (p)
+               vlan_vid_del(dev, htons(ETH_P_8021Q), vid);
        return err;
 }
 
@@ -95,13 +92,8 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid)
        __vlan_delete_pvid(v, vid);
        clear_bit(vid, v->untagged_bitmap);
 
-       if (v->port_idx) {
-               struct net_device *dev = v->parent.port->dev;
-               const struct net_device_ops *ops = dev->netdev_ops;
-
-               if (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
-                       ops->ndo_vlan_rx_kill_vid(dev, htons(ETH_P_8021Q), vid);
-       }
+       if (v->port_idx)
+               vlan_vid_del(v->parent.port->dev, htons(ETH_P_8021Q), vid);
 
        clear_bit(vid, v->vlan_bitmap);
        v->num_vlans--;
@@ -398,6 +390,7 @@ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
 void nbp_vlan_flush(struct net_bridge_port *port)
 {
        struct net_port_vlans *pv;
+       u16 vid;
 
        ASSERT_RTNL();
 
@@ -405,6 +398,9 @@ void nbp_vlan_flush(struct net_bridge_port *port)
        if (!pv)
                return;
 
+       for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID)
+               vlan_vid_del(port->dev, htons(ETH_P_8021Q), vid);
+
        __vlan_flush(pv);
 }
 
index 3ab8dd2e12828fea31d97b59dbeb3fe7521e953b..d249874a366d363edfc94adc47df54dde6bdba0e 100644 (file)
@@ -420,7 +420,7 @@ static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
  * @mask: CAN mask (see description)
  * @func: callback function on filter match
  * @data: returned parameter for callback function
- * @ident: string for calling module indentification
+ * @ident: string for calling module identification
  *
  * Description:
  *  Invokes the callback function with the received sk_buff and the given
index 8ffc52e01ece35db173fee05a3fdc160d733b684..7e00a7342ee6aa4e9d7ab408423694fecb2966db 100644 (file)
 #include <linux/static_key.h>
 #include <linux/hashtable.h>
 #include <linux/vmalloc.h>
+#include <linux/if_macvlan.h>
 
 #include "net-sysfs.h"
 
@@ -1424,6 +1425,10 @@ void dev_disable_lro(struct net_device *dev)
        if (is_vlan_dev(dev))
                dev = vlan_dev_real_dev(dev);
 
+       /* the same for macvlan devices */
+       if (netif_is_macvlan(dev))
+               dev = macvlan_dev_real_dev(dev);
+
        dev->wanted_features &= ~NETIF_F_LRO;
        netdev_update_features(dev);
 
@@ -1690,13 +1695,9 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
                kfree_skb(skb);
                return NET_RX_DROP;
        }
-       skb->protocol = eth_type_trans(skb, dev);
 
-       /* eth_type_trans() can set pkt_type.
-        * call skb_scrub_packet() after it to clear pkt_type _after_ calling
-        * eth_type_trans().
-        */
        skb_scrub_packet(skb, true);
+       skb->protocol = eth_type_trans(skb, dev);
 
        return netif_rx(skb);
 }
index 5e78d44333b9bc39fdb56fdd489d0ac4f7f5d4e8..95897183226e18882bdbe16d8e9ba3a111ffae71 100644 (file)
@@ -106,6 +106,10 @@ static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
        return skb;
 }
 
+static struct genl_multicast_group dropmon_mcgrps[] = {
+       { .name = "events", },
+};
+
 static void send_dm_alert(struct work_struct *work)
 {
        struct sk_buff *skb;
@@ -116,7 +120,8 @@ static void send_dm_alert(struct work_struct *work)
        skb = reset_per_cpu_data(data);
 
        if (skb)
-               genlmsg_multicast(skb, 0, NET_DM_GRP_ALERT, GFP_KERNEL);
+               genlmsg_multicast(&net_drop_monitor_family, skb, 0,
+                                 0, GFP_KERNEL);
 }
 
 /*
@@ -333,7 +338,7 @@ out:
        return NOTIFY_DONE;
 }
 
-static struct genl_ops dropmon_ops[] = {
+static const struct genl_ops dropmon_ops[] = {
        {
                .cmd = NET_DM_CMD_CONFIG,
                .doit = net_dm_cmd_config,
@@ -364,13 +369,13 @@ static int __init init_net_drop_monitor(void)
                return -ENOSPC;
        }
 
-       rc = genl_register_family_with_ops(&net_drop_monitor_family,
-                                          dropmon_ops,
-                                          ARRAY_SIZE(dropmon_ops));
+       rc = genl_register_family_with_ops_groups(&net_drop_monitor_family,
+                                                 dropmon_ops, dropmon_mcgrps);
        if (rc) {
                pr_err("Could not create drop monitor netlink family\n");
                return rc;
        }
+       WARN_ON(net_drop_monitor_family.mcgrp_offset != NET_DM_GRP_ALERT);
 
        rc = register_netdevice_notifier(&dropmon_net_notifier);
        if (rc < 0) {
index 4e66bf61f585e58c2f975799833d540b5e5c9813..5325af85eea670f5c865367fc991eaf9b907cd98 100644 (file)
@@ -90,8 +90,8 @@ static struct genl_family hsr_genl_family = {
        .maxattr = HSR_A_MAX,
 };
 
-static struct genl_multicast_group hsr_network_genl_mcgrp = {
-       .name = "hsr-network",
+static const struct genl_multicast_group hsr_mcgrps[] = {
+       { .name = "hsr-network", },
 };
 
 
@@ -129,7 +129,7 @@ void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN],
                goto nla_put_failure;
 
        genlmsg_end(skb, msg_head);
-       genlmsg_multicast(skb, 0, hsr_network_genl_mcgrp.id, GFP_ATOMIC);
+       genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
 
        return;
 
@@ -163,7 +163,7 @@ void hsr_nl_nodedown(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN])
                goto nla_put_failure;
 
        genlmsg_end(skb, msg_head);
-       genlmsg_multicast(skb, 0, hsr_network_genl_mcgrp.id, GFP_ATOMIC);
+       genlmsg_multicast(&hsr_genl_family, skb, 0, 0, GFP_ATOMIC);
 
        return;
 
@@ -249,7 +249,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
                        &hsr_node_if2_age,
                        &hsr_node_if2_seq);
        if (res < 0)
-               goto fail;
+               goto nla_put_failure;
 
        res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN,
                                        nla_data(info->attrs[HSR_A_NODE_ADDR]));
@@ -306,15 +306,6 @@ fail:
        return res;
 }
 
-static struct genl_ops hsr_ops_get_node_status = {
-       .cmd = HSR_C_GET_NODE_STATUS,
-       .flags = 0,
-       .policy = hsr_genl_policy,
-       .doit = hsr_get_node_status,
-       .dumpit = NULL,
-};
-
-
 /* Get a list of MacAddressA of all nodes known to this node (other than self).
  */
 static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
@@ -398,12 +389,21 @@ fail:
 }
 
 
-static struct genl_ops hsr_ops_get_node_list = {
-       .cmd = HSR_C_GET_NODE_LIST,
-       .flags = 0,
-       .policy = hsr_genl_policy,
-       .doit = hsr_get_node_list,
-       .dumpit = NULL,
+static const struct genl_ops hsr_ops[] = {
+       {
+               .cmd = HSR_C_GET_NODE_STATUS,
+               .flags = 0,
+               .policy = hsr_genl_policy,
+               .doit = hsr_get_node_status,
+               .dumpit = NULL,
+       },
+       {
+               .cmd = HSR_C_GET_NODE_LIST,
+               .flags = 0,
+               .policy = hsr_genl_policy,
+               .doit = hsr_get_node_list,
+               .dumpit = NULL,
+       },
 };
 
 int __init hsr_netlink_init(void)
@@ -414,30 +414,13 @@ int __init hsr_netlink_init(void)
        if (rc)
                goto fail_rtnl_link_register;
 
-       rc = genl_register_family(&hsr_genl_family);
+       rc = genl_register_family_with_ops_groups(&hsr_genl_family, hsr_ops,
+                                                 hsr_mcgrps);
        if (rc)
                goto fail_genl_register_family;
 
-       rc = genl_register_ops(&hsr_genl_family, &hsr_ops_get_node_status);
-       if (rc)
-               goto fail_genl_register_ops;
-
-       rc = genl_register_ops(&hsr_genl_family, &hsr_ops_get_node_list);
-       if (rc)
-               goto fail_genl_register_ops_node_list;
-
-       rc = genl_register_mc_group(&hsr_genl_family, &hsr_network_genl_mcgrp);
-       if (rc)
-               goto fail_genl_register_mc_group;
-
        return 0;
 
-fail_genl_register_mc_group:
-       genl_unregister_ops(&hsr_genl_family, &hsr_ops_get_node_list);
-fail_genl_register_ops_node_list:
-       genl_unregister_ops(&hsr_genl_family, &hsr_ops_get_node_status);
-fail_genl_register_ops:
-       genl_unregister_family(&hsr_genl_family);
 fail_genl_register_family:
        rtnl_link_unregister(&hsr_link_ops);
 fail_rtnl_link_register:
@@ -447,10 +430,7 @@ fail_rtnl_link_register:
 
 void __exit hsr_netlink_exit(void)
 {
-       genl_unregister_mc_group(&hsr_genl_family, &hsr_network_genl_mcgrp);
-       genl_unregister_ops(&hsr_genl_family, &hsr_ops_get_node_status);
        genl_unregister_family(&hsr_genl_family);
-
        rtnl_link_unregister(&hsr_link_ops);
 }
 
index 426b5df1c98f1cc195158c9829a536cfbd0fefd6..459e200c08a40e4e737798582524cd973064b143 100644 (file)
@@ -956,7 +956,7 @@ lowpan_process_data(struct sk_buff *skb)
         * Traffic class carried in-line
         * ECN + DSCP (1 byte), Flow Label is elided
         */
-       case 1: /* 10b */
+       case 2: /* 10b */
                if (lowpan_fetch_skb_u8(skb, &tmp))
                        goto drop;
 
@@ -967,7 +967,7 @@ lowpan_process_data(struct sk_buff *skb)
         * Flow Label carried in-line
         * ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided
         */
-       case 2: /* 01b */
+       case 1: /* 01b */
                if (lowpan_fetch_skb_u8(skb, &tmp))
                        goto drop;
 
index 581a59504bd5f49d9a54584f3441c4e323b7bcd5..1865fdf5a5a5116be8bf28b25f9c340f8b8fd50b 100644 (file)
@@ -315,9 +315,8 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
        if (saddr) {
                saddr->family = AF_IEEE802154;
                saddr->addr = mac_cb(skb)->sa;
-       }
-       if (addr_len)
                *addr_len = sizeof(*saddr);
+       }
 
        if (flags & MSG_TRUNC)
                copied = skb->len;
index aadec428e6ec206deb3c41c75a69f2c527bbab1d..cee4425b995689702375435f0be7dd85eca3ed73 100644 (file)
@@ -47,7 +47,24 @@ struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
 int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info);
 
 extern struct genl_family nl802154_family;
-int nl802154_mac_register(void);
-int nl802154_phy_register(void);
+
+/* genetlink ops/groups */
+int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb);
+int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info);
+
+enum ieee802154_mcgrp_ids {
+       IEEE802154_COORD_MCGRP,
+       IEEE802154_BEACON_MCGRP,
+};
+
+int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info);
+int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb);
 
 #endif
index 7e49bbcc6967ebfaac72ee9e6b3e3b9032f1f88a..43f1b2bf469f40938a431582b305c45587049a04 100644 (file)
@@ -70,7 +70,7 @@ int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group)
        if (genlmsg_end(msg, hdr) < 0)
                goto out;
 
-       return genlmsg_multicast(msg, 0, group, GFP_ATOMIC);
+       return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC);
 out:
        nlmsg_free(msg);
        return -ENOBUFS;
@@ -109,31 +109,36 @@ out:
        return -ENOBUFS;
 }
 
-int __init ieee802154_nl_init(void)
-{
-       int rc;
-
-       rc = genl_register_family(&nl802154_family);
-       if (rc)
-               goto fail;
-
-       rc = nl802154_mac_register();
-       if (rc)
-               goto fail;
+static const struct genl_ops ieee8021154_ops[] = {
+       /* see nl-phy.c */
+       IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
+                       ieee802154_dump_phy),
+       IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
+       IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
+       /* see nl-mac.c */
+       IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
+       IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
+       IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
+       IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
+       IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
+       IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
+                       ieee802154_dump_iface),
+};
 
-       rc = nl802154_phy_register();
-       if (rc)
-               goto fail;
+static const struct genl_multicast_group ieee802154_mcgrps[] = {
+       [IEEE802154_COORD_MCGRP] = { .name = IEEE802154_MCAST_COORD_NAME, },
+       [IEEE802154_BEACON_MCGRP] = { .name = IEEE802154_MCAST_BEACON_NAME, },
+};
 
-       return 0;
 
-fail:
-       genl_unregister_family(&nl802154_family);
-       return rc;
+int __init ieee802154_nl_init(void)
+{
+       return genl_register_family_with_ops_groups(&nl802154_family,
+                                                   ieee8021154_ops,
+                                                   ieee802154_mcgrps);
 }
 
 void __exit ieee802154_nl_exit(void)
 {
        genl_unregister_family(&nl802154_family);
 }
-
index b0bdd8c51e9c83a0ef968fc678588f3807559b13..ba5c1e002f37b2630c53a0284736f5d177bded76 100644 (file)
 
 #include "ieee802154.h"
 
-static struct genl_multicast_group ieee802154_coord_mcgrp = {
-       .name           = IEEE802154_MCAST_COORD_NAME,
-};
-
-static struct genl_multicast_group ieee802154_beacon_mcgrp = {
-       .name           = IEEE802154_MCAST_BEACON_NAME,
-};
-
 int ieee802154_nl_assoc_indic(struct net_device *dev,
                struct ieee802154_addr *addr, u8 cap)
 {
@@ -72,7 +64,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev,
            nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap))
                goto nla_put_failure;
 
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -98,7 +90,7 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr,
            nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
            nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
                goto nla_put_failure;
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -133,7 +125,7 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev,
        }
        if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
                goto nla_put_failure;
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -157,7 +149,7 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
                    dev->dev_addr) ||
            nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
                goto nla_put_failure;
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -183,7 +175,7 @@ int ieee802154_nl_beacon_indic(struct net_device *dev,
            nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) ||
            nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
                goto nla_put_failure;
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -214,7 +206,7 @@ int ieee802154_nl_scan_confirm(struct net_device *dev,
            (edl &&
             nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl)))
                goto nla_put_failure;
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -238,7 +230,7 @@ int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
                    dev->dev_addr) ||
            nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
                goto nla_put_failure;
-       return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id);
+       return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
 
 nla_put_failure:
        nlmsg_free(msg);
@@ -309,8 +301,7 @@ static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
        return dev;
 }
 
-static int ieee802154_associate_req(struct sk_buff *skb,
-               struct genl_info *info)
+int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_device *dev;
        struct ieee802154_addr addr;
@@ -357,8 +348,7 @@ out:
        return ret;
 }
 
-static int ieee802154_associate_resp(struct sk_buff *skb,
-               struct genl_info *info)
+int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_device *dev;
        struct ieee802154_addr addr;
@@ -390,8 +380,7 @@ out:
        return ret;
 }
 
-static int ieee802154_disassociate_req(struct sk_buff *skb,
-               struct genl_info *info)
+int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_device *dev;
        struct ieee802154_addr addr;
@@ -433,7 +422,7 @@ out:
  * PAN_coordinator, battery_life_extension = 0,
  * coord_realignment = 0, security_enable = 0
 */
-static int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
+int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_device *dev;
        struct ieee802154_addr addr;
@@ -492,7 +481,7 @@ out:
        return ret;
 }
 
-static int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
+int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
 {
        struct net_device *dev;
        int ret = -EOPNOTSUPP;
@@ -530,8 +519,7 @@ out:
        return ret;
 }
 
-static int ieee802154_list_iface(struct sk_buff *skb,
-       struct genl_info *info)
+int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
 {
        /* Request for interface name, index, type, IEEE address,
           PAN Id, short address */
@@ -565,8 +553,7 @@ out_dev:
 
 }
 
-static int ieee802154_dump_iface(struct sk_buff *skb,
-       struct netlink_callback *cb)
+int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct net *net = sock_net(skb->sk);
        struct net_device *dev;
@@ -590,41 +577,3 @@ cont:
 
        return skb->len;
 }
-
-static struct genl_ops ieee802154_coordinator_ops[] = {
-       IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req),
-       IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp),
-       IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req),
-       IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req),
-       IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req),
-       IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface,
-                                                       ieee802154_dump_iface),
-};
-
-/*
- * No need to unregister as family unregistration will do it.
- */
-int nl802154_mac_register(void)
-{
-       int i;
-       int rc;
-
-       rc = genl_register_mc_group(&nl802154_family,
-                       &ieee802154_coord_mcgrp);
-       if (rc)
-               return rc;
-
-       rc = genl_register_mc_group(&nl802154_family,
-                       &ieee802154_beacon_mcgrp);
-       if (rc)
-               return rc;
-
-       for (i = 0; i < ARRAY_SIZE(ieee802154_coordinator_ops); i++) {
-               rc = genl_register_ops(&nl802154_family,
-                               &ieee802154_coordinator_ops[i]);
-               if (rc)
-                       return rc;
-       }
-
-       return 0;
-}
index 22b1a7058fd3f841d94ee27655840c1ae325f011..d08c7a43dcd1c72f1512b01e8a00dd2b9e6b1869 100644 (file)
@@ -77,8 +77,7 @@ out:
        return -EMSGSIZE;
 }
 
-static int ieee802154_list_phy(struct sk_buff *skb,
-       struct genl_info *info)
+int ieee802154_list_phy(struct sk_buff *skb, struct genl_info *info)
 {
        /* Request for interface name, index, type, IEEE address,
           PAN Id, short address */
@@ -151,8 +150,7 @@ static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data)
        return 0;
 }
 
-static int ieee802154_dump_phy(struct sk_buff *skb,
-       struct netlink_callback *cb)
+int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct dump_phy_data data = {
                .cb = cb,
@@ -170,8 +168,7 @@ static int ieee802154_dump_phy(struct sk_buff *skb,
        return skb->len;
 }
 
-static int ieee802154_add_iface(struct sk_buff *skb,
-               struct genl_info *info)
+int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info)
 {
        struct sk_buff *msg;
        struct wpan_phy *phy;
@@ -273,8 +270,7 @@ out_dev:
        return rc;
 }
 
-static int ieee802154_del_iface(struct sk_buff *skb,
-               struct genl_info *info)
+int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info)
 {
        struct sk_buff *msg;
        struct wpan_phy *phy;
@@ -356,28 +352,3 @@ out_dev:
 
        return rc;
 }
-
-static struct genl_ops ieee802154_phy_ops[] = {
-       IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
-                                                       ieee802154_dump_phy),
-       IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface),
-       IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface),
-};
-
-/*
- * No need to unregister as family unregistration will do it.
- */
-int nl802154_phy_register(void)
-{
-       int i;
-       int rc;
-
-       for (i = 0; i < ARRAY_SIZE(ieee802154_phy_ops); i++) {
-               rc = genl_register_ops(&nl802154_family,
-                               &ieee802154_phy_ops[i]);
-               if (rc)
-                       return rc;
-       }
-
-       return 0;
-}
index b28e863fe0a7143b199bee51cfdf242c125f31cf..19e36376d2a083b5c8b307208ebd17ade086dcaa 100644 (file)
@@ -57,7 +57,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
        if (IS_ERR(rt)) {
                err = PTR_ERR(rt);
                if (err == -ENETUNREACH)
-                       IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
+                       IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
                goto out;
        }
 
index caf01176a5e49774555b9c4dea5809e4f57cce19..90ff9570d7d4def935f3224514312fc217812d9c 100644 (file)
@@ -454,6 +454,8 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
        tstats->rx_bytes += skb->len;
        u64_stats_update_end(&tstats->syncp);
 
+       skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
+
        if (tunnel->dev->type == ARPHRD_ETHER) {
                skb->protocol = eth_type_trans(skb, tunnel->dev);
                skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
@@ -461,8 +463,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
                skb->dev = tunnel->dev;
        }
 
-       skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
-
        gro_cells_receive(&tunnel->gro_cells, skb);
        return 0;
 
index 5d9c845d288a3d8cce3eb96aeb65384e4a56edbc..52b802a0cd8cbda18579dd1811bce3405ecbdfdc 100644 (file)
@@ -126,6 +126,7 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
        if (!rt->dst.xfrm ||
            rt->dst.xfrm->props.mode != XFRM_MODE_TUNNEL) {
                dev->stats.tx_carrier_errors++;
+               ip_rt_put(rt);
                goto tx_error_icmp;
        }
        tdev = rt->dst.dev;
index cbc85f660d54a683f5e989bc729e1f5f0b52e4f0..876c6ca2d8f9e77a28f1e629aa6523df1ee8f42f 100644 (file)
@@ -830,8 +830,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 {
        struct inet_sock *isk = inet_sk(sk);
        int family = sk->sk_family;
-       struct sockaddr_in *sin;
-       struct sockaddr_in6 *sin6;
        struct sk_buff *skb;
        int copied, err;
 
@@ -841,13 +839,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        if (flags & MSG_OOB)
                goto out;
 
-       if (addr_len) {
-               if (family == AF_INET)
-                       *addr_len = sizeof(*sin);
-               else if (family == AF_INET6 && addr_len)
-                       *addr_len = sizeof(*sin6);
-       }
-
        if (flags & MSG_ERRQUEUE) {
                if (family == AF_INET) {
                        return ip_recv_error(sk, msg, len);
@@ -877,11 +868,15 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 
        /* Copy the address and add cmsg data. */
        if (family == AF_INET) {
-               sin = (struct sockaddr_in *) msg->msg_name;
-               sin->sin_family = AF_INET;
-               sin->sin_port = 0 /* skb->h.uh->source */;
-               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
-               memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
+               struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
+
+               if (sin) {
+                       sin->sin_family = AF_INET;
+                       sin->sin_port = 0 /* skb->h.uh->source */;
+                       sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
+                       memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
+                       *addr_len = sizeof(*sin);
+               }
 
                if (isk->cmsg_flags)
                        ip_cmsg_recv(msg, skb);
@@ -890,17 +885,21 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        } else if (family == AF_INET6) {
                struct ipv6_pinfo *np = inet6_sk(sk);
                struct ipv6hdr *ip6 = ipv6_hdr(skb);
-               sin6 = (struct sockaddr_in6 *) msg->msg_name;
-               sin6->sin6_family = AF_INET6;
-               sin6->sin6_port = 0;
-               sin6->sin6_addr = ip6->saddr;
-
-               sin6->sin6_flowinfo = 0;
-               if (np->sndflow)
-                       sin6->sin6_flowinfo = ip6_flowinfo(ip6);
-
-               sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
-                                                         IP6CB(skb)->iif);
+               struct sockaddr_in6 *sin6 =
+                       (struct sockaddr_in6 *)msg->msg_name;
+
+               if (sin6) {
+                       sin6->sin6_family = AF_INET6;
+                       sin6->sin6_port = 0;
+                       sin6->sin6_addr = ip6->saddr;
+                       sin6->sin6_flowinfo = 0;
+                       if (np->sndflow)
+                               sin6->sin6_flowinfo = ip6_flowinfo(ip6);
+                       sin6->sin6_scope_id =
+                               ipv6_iface_scope_id(&sin6->sin6_addr,
+                                                   IP6CB(skb)->iif);
+                       *addr_len = sizeof(*sin6);
+               }
 
                if (inet6_sk(sk)->rxopt.all)
                        pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
index 41e1d2845c8f6690b5588888134bd80e49fc5dcf..5cb8ddb505ee8911461ec92a5c74feef0b441e00 100644 (file)
@@ -696,9 +696,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        if (flags & MSG_OOB)
                goto out;
 
-       if (addr_len)
-               *addr_len = sizeof(*sin);
-
        if (flags & MSG_ERRQUEUE) {
                err = ip_recv_error(sk, msg, len);
                goto out;
@@ -726,6 +723,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
                sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
                sin->sin_port = 0;
                memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
+               *addr_len = sizeof(*sin);
        }
        if (inet->cmsg_flags)
                ip_cmsg_recv(msg, skb);
index 8e8529d3c8c92a4473a3ed9fd8db876ca83533bd..c4638e6f023843bedbceb91f1bef3c424ad3b666 100644 (file)
@@ -808,12 +808,6 @@ static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now,
                xmit_size_goal = min_t(u32, gso_size,
                                       sk->sk_gso_max_size - 1 - hlen);
 
-               /* TSQ : try to have at least two segments in flight
-                * (one in NIC TX ring, another in Qdisc)
-                */
-               xmit_size_goal = min_t(u32, xmit_size_goal,
-                                      sysctl_tcp_limit_output_bytes >> 1);
-
                xmit_size_goal = tcp_bound_to_half_wnd(tp, xmit_size_goal);
 
                /* We try hard to avoid divides here */
@@ -1431,7 +1425,7 @@ static void tcp_service_net_dma(struct sock *sk, bool wait)
        do {
                if (dma_async_is_tx_complete(tp->ucopy.dma_chan,
                                              last_issued, &done,
-                                             &used) == DMA_SUCCESS) {
+                                             &used) == DMA_COMPLETE) {
                        /* Safe to free early-copied skbs now */
                        __skb_queue_purge(&sk->sk_async_wait_queue);
                        break;
@@ -1439,7 +1433,7 @@ static void tcp_service_net_dma(struct sock *sk, bool wait)
                        struct sk_buff *skb;
                        while ((skb = skb_peek(&sk->sk_async_wait_queue)) &&
                               (dma_async_is_complete(skb->dma_cookie, done,
-                                                     used) == DMA_SUCCESS)) {
+                                                     used) == DMA_COMPLETE)) {
                                __skb_dequeue(&sk->sk_async_wait_queue);
                                kfree_skb(skb);
                        }
index 2ab09cbae74d29155d08f7dd701851136d205e0f..06493736fbc826842876180a24510d9e348cb7f3 100644 (file)
@@ -663,10 +663,13 @@ void tcp_fastopen_cache_get(struct sock *sk, u16 *mss,
 void tcp_fastopen_cache_set(struct sock *sk, u16 mss,
                            struct tcp_fastopen_cookie *cookie, bool syn_lost)
 {
+       struct dst_entry *dst = __sk_dst_get(sk);
        struct tcp_metrics_block *tm;
 
+       if (!dst)
+               return;
        rcu_read_lock();
-       tm = tcp_get_metrics(sk, __sk_dst_get(sk), true);
+       tm = tcp_get_metrics(sk, dst, true);
        if (tm) {
                struct tcp_fastopen_metrics *tfom = &tm->tcpm_fastopen;
 
@@ -988,7 +991,7 @@ static int tcp_metrics_nl_cmd_del(struct sk_buff *skb, struct genl_info *info)
        return 0;
 }
 
-static struct genl_ops tcp_metrics_nl_ops[] = {
+static const struct genl_ops tcp_metrics_nl_ops[] = {
        {
                .cmd = TCP_METRICS_CMD_GET,
                .doit = tcp_metrics_nl_cmd_get,
@@ -1079,8 +1082,7 @@ void __init tcp_metrics_init(void)
        if (ret < 0)
                goto cleanup;
        ret = genl_register_family_with_ops(&tcp_metrics_nl_family,
-                                           tcp_metrics_nl_ops,
-                                           ARRAY_SIZE(tcp_metrics_nl_ops));
+                                           tcp_metrics_nl_ops);
        if (ret < 0)
                goto cleanup_subsys;
        return;
index 672854664ff5c1d36783ac1bfb72fea481648ca1..7820f3a7dd704bd6375c5cdc858e71b7be4261ed 100644 (file)
@@ -1875,8 +1875,12 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
                 *  - better RTT estimation and ACK scheduling
                 *  - faster recovery
                 *  - high rates
+                * Alas, some drivers / subsystems require a fair amount
+                * of queued bytes to ensure line rate.
+                * One example is wifi aggregation (802.11 AMPDU)
                 */
-               limit = max(skb->truesize, sk->sk_pacing_rate >> 10);
+               limit = max_t(unsigned int, sysctl_tcp_limit_output_bytes,
+                             sk->sk_pacing_rate >> 10);
 
                if (atomic_read(&sk->sk_wmem_alloc) > limit) {
                        set_bit(TSQ_THROTTLED, &tp->tsq_flags);
@@ -3093,7 +3097,6 @@ void tcp_send_window_probe(struct sock *sk)
 {
        if (sk->sk_state == TCP_ESTABLISHED) {
                tcp_sk(sk)->snd_wl1 = tcp_sk(sk)->rcv_nxt - 1;
-               tcp_sk(sk)->snd_nxt = tcp_sk(sk)->write_seq;
                tcp_xmit_probe_skb(sk, 0);
        }
 }
index de86e5bc44629eaeaf1f8fc935dfd4abe5625703..5944d7d668dd91da21e945eac748bbbbbb11d67a 100644 (file)
@@ -1235,12 +1235,6 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        int is_udplite = IS_UDPLITE(sk);
        bool slow;
 
-       /*
-        *      Check any passed addresses
-        */
-       if (addr_len)
-               *addr_len = sizeof(*sin);
-
        if (flags & MSG_ERRQUEUE)
                return ip_recv_error(sk, msg, len);
 
@@ -1302,6 +1296,7 @@ try_again:
                sin->sin_port = udp_hdr(skb)->source;
                sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
                memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
+               *addr_len = sizeof(*sin);
        }
        if (inet->cmsg_flags)
                ip_cmsg_recv(msg, skb);
index 5658d9d51637beaa07790b49e4d405cc290afe16..12c97d8aa6bbb31ff1519459b89b7b9fb33817f5 100644 (file)
@@ -1996,23 +1996,6 @@ static void addrconf_add_mroute(struct net_device *dev)
        ip6_route_add(&cfg);
 }
 
-#if IS_ENABLED(CONFIG_IPV6_SIT)
-static void sit_route_add(struct net_device *dev)
-{
-       struct fib6_config cfg = {
-               .fc_table = RT6_TABLE_MAIN,
-               .fc_metric = IP6_RT_PRIO_ADDRCONF,
-               .fc_ifindex = dev->ifindex,
-               .fc_dst_len = 96,
-               .fc_flags = RTF_UP | RTF_NONEXTHOP,
-               .fc_nlinfo.nl_net = dev_net(dev),
-       };
-
-       /* prefix length - 96 bits "::d.d.d.d" */
-       ip6_route_add(&cfg);
-}
-#endif
-
 static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
 {
        struct inet6_dev *idev;
@@ -2542,7 +2525,8 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
        struct in6_addr addr;
        struct net_device *dev;
        struct net *net = dev_net(idev->dev);
-       int scope;
+       int scope, plen;
+       u32 pflags = 0;
 
        ASSERT_RTNL();
 
@@ -2552,12 +2536,16 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
        if (idev->dev->flags&IFF_POINTOPOINT) {
                addr.s6_addr32[0] = htonl(0xfe800000);
                scope = IFA_LINK;
+               plen = 64;
        } else {
                scope = IPV6_ADDR_COMPATv4;
+               plen = 96;
+               pflags |= RTF_NONEXTHOP;
        }
 
        if (addr.s6_addr32[3]) {
-               add_addr(idev, &addr, 128, scope);
+               add_addr(idev, &addr, plen, scope);
+               addrconf_prefix_route(&addr, plen, idev->dev, 0, pflags);
                return;
        }
 
@@ -2569,7 +2557,6 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
                        int flag = scope;
 
                        for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
-                               int plen;
 
                                addr.s6_addr32[3] = ifa->ifa_local;
 
@@ -2580,12 +2567,10 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
                                                continue;
                                        flag |= IFA_HOST;
                                }
-                               if (idev->dev->flags&IFF_POINTOPOINT)
-                                       plen = 64;
-                               else
-                                       plen = 96;
 
                                add_addr(idev, &addr, plen, flag);
+                               addrconf_prefix_route(&addr, plen, idev->dev, 0,
+                                                     pflags);
                        }
                }
        }
@@ -2711,7 +2696,6 @@ static void addrconf_sit_config(struct net_device *dev)
                struct in6_addr addr;
 
                ipv6_addr_set(&addr,  htonl(0xFE800000), 0, 0, 0);
-               addrconf_prefix_route(&addr, 64, dev, 0, 0);
                if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
                        addrconf_add_linklocal(idev, &addr);
                return;
@@ -2721,8 +2705,6 @@ static void addrconf_sit_config(struct net_device *dev)
 
        if (dev->flags&IFF_POINTOPOINT)
                addrconf_add_mroute(dev);
-       else
-               sit_route_add(dev);
 }
 #endif
 
@@ -2740,8 +2722,6 @@ static void addrconf_gre_config(struct net_device *dev)
        }
 
        ipv6_addr_set(&addr,  htonl(0xFE800000), 0, 0, 0);
-       addrconf_prefix_route(&addr, 64, dev, 0, 0);
-
        if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
                addrconf_add_linklocal(idev, &addr);
 }
index ff75313f27a848db69dc0af6cf1a367205e13d2d..4fbdb7046d286cf64f60c61e3ae87ba657f042a0 100644 (file)
@@ -972,10 +972,10 @@ out:
 
 #ifdef CONFIG_SYSCTL
 sysctl_fail:
-       ipv6_packet_cleanup();
+       pingv6_exit();
 #endif
 pingv6_fail:
-       pingv6_exit();
+       ipv6_packet_cleanup();
 ipv6_packet_fail:
        tcpv6_exit();
 tcpv6_fail:
index df1fa58528c6fdeae476193f3bf7ae53d2e38a7e..d6062325db08411207fd63b435ec1e5e4e0f2001 100644 (file)
@@ -1642,6 +1642,15 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
        return ip6_tnl_update(t, &p);
 }
 
+static void ip6_tnl_dellink(struct net_device *dev, struct list_head *head)
+{
+       struct net *net = dev_net(dev);
+       struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
+
+       if (dev != ip6n->fb_tnl_dev)
+               unregister_netdevice_queue(dev, head);
+}
+
 static size_t ip6_tnl_get_size(const struct net_device *dev)
 {
        return
@@ -1706,6 +1715,7 @@ static struct rtnl_link_ops ip6_link_ops __read_mostly = {
        .validate       = ip6_tnl_validate,
        .newlink        = ip6_tnl_newlink,
        .changelink     = ip6_tnl_changelink,
+       .dellink        = ip6_tnl_dellink,
        .get_size       = ip6_tnl_get_size,
        .fill_info      = ip6_tnl_fill_info,
 };
@@ -1722,9 +1732,9 @@ static struct xfrm6_tunnel ip6ip6_handler __read_mostly = {
        .priority       =       1,
 };
 
-static void __net_exit ip6_tnl_destroy_tunnels(struct ip6_tnl_net *ip6n)
+static void __net_exit ip6_tnl_destroy_tunnels(struct net *net)
 {
-       struct net *net = dev_net(ip6n->fb_tnl_dev);
+       struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
        struct net_device *dev, *aux;
        int h;
        struct ip6_tnl *t;
@@ -1792,10 +1802,8 @@ err_alloc_dev:
 
 static void __net_exit ip6_tnl_exit_net(struct net *net)
 {
-       struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
-
        rtnl_lock();
-       ip6_tnl_destroy_tunnels(ip6n);
+       ip6_tnl_destroy_tunnels(net);
        rtnl_unlock();
 }
 
index f8a55ff1971b36db95ae7c22dd8c65062fbdcb61..3512177deb4d0e7d12c6d145781802074f490615 100644 (file)
@@ -1726,8 +1726,8 @@ int __init ndisc_init(void)
                                    &ndisc_ifinfo_sysctl_change);
        if (err)
                goto out_unregister_pernet;
-#endif
 out:
+#endif
        return err;
 
 #ifdef CONFIG_SYSCTL
index 3c00842b0079240f1788c83bfab346d5879336d8..e24ff1df0401288e4e810cf79ec3ea20d86a06c0 100644 (file)
@@ -465,9 +465,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
        if (flags & MSG_OOB)
                return -EOPNOTSUPP;
 
-       if (addr_len)
-               *addr_len=sizeof(*sin6);
-
        if (flags & MSG_ERRQUEUE)
                return ipv6_recv_error(sk, msg, len);
 
@@ -506,6 +503,7 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
                sin6->sin6_flowinfo = 0;
                sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
                                                          IP6CB(skb)->iif);
+               *addr_len = sizeof(*sin6);
        }
 
        sock_recv_ts_and_drops(msg, sk, skb);
index bfc6fcea38410e3a5817ad7ba254a98151bb0749..1b4a4a95367552c8cc22d19850b0779eee87cdc6 100644 (file)
@@ -1619,6 +1619,15 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
 #endif
 };
 
+static void ipip6_dellink(struct net_device *dev, struct list_head *head)
+{
+       struct net *net = dev_net(dev);
+       struct sit_net *sitn = net_generic(net, sit_net_id);
+
+       if (dev != sitn->fb_tunnel_dev)
+               unregister_netdevice_queue(dev, head);
+}
+
 static struct rtnl_link_ops sit_link_ops __read_mostly = {
        .kind           = "sit",
        .maxtype        = IFLA_IPTUN_MAX,
@@ -1630,6 +1639,7 @@ static struct rtnl_link_ops sit_link_ops __read_mostly = {
        .changelink     = ipip6_changelink,
        .get_size       = ipip6_get_size,
        .fill_info      = ipip6_fill_info,
+       .dellink        = ipip6_dellink,
 };
 
 static struct xfrm_tunnel sit_handler __read_mostly = {
@@ -1644,9 +1654,10 @@ static struct xfrm_tunnel ipip_handler __read_mostly = {
        .priority       =       2,
 };
 
-static void __net_exit sit_destroy_tunnels(struct sit_net *sitn, struct list_head *head)
+static void __net_exit sit_destroy_tunnels(struct net *net,
+                                          struct list_head *head)
 {
-       struct net *net = dev_net(sitn->fb_tunnel_dev);
+       struct sit_net *sitn = net_generic(net, sit_net_id);
        struct net_device *dev, *aux;
        int prio;
 
@@ -1721,11 +1732,10 @@ err_alloc_dev:
 
 static void __net_exit sit_exit_net(struct net *net)
 {
-       struct sit_net *sitn = net_generic(net, sit_net_id);
        LIST_HEAD(list);
 
        rtnl_lock();
-       sit_destroy_tunnels(sitn, &list);
+       sit_destroy_tunnels(net, &list);
        unregister_netdevice_many(&list);
        rtnl_unlock();
 }
index f3893e897f721aa4345c82f0ea2b899c44fa0ae4..81eb8cf8389b6a5af55f7b2994d7dbefe3d732bf 100644 (file)
@@ -392,9 +392,6 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
        int is_udp4;
        bool slow;
 
-       if (addr_len)
-               *addr_len = sizeof(struct sockaddr_in6);
-
        if (flags & MSG_ERRQUEUE)
                return ipv6_recv_error(sk, msg, len);
 
@@ -480,7 +477,7 @@ try_again:
                                ipv6_iface_scope_id(&sin6->sin6_addr,
                                                    IP6CB(skb)->iif);
                }
-
+               *addr_len = sizeof(*sin6);
        }
        if (is_udp4) {
                if (inet->cmsg_flags)
index c32971269280116543c0bf560e1bbc3248df034d..a37b81fe04798e0c8cb0196f72b2cf97e4b610b7 100644 (file)
@@ -131,7 +131,7 @@ static const struct nla_policy irda_nl_policy[IRDA_NL_ATTR_MAX + 1] = {
        [IRDA_NL_ATTR_MODE] = { .type = NLA_U32 },
 };
 
-static struct genl_ops irda_nl_ops[] = {
+static const struct genl_ops irda_nl_ops[] = {
        {
                .cmd = IRDA_NL_CMD_SET_MODE,
                .doit = irda_nl_set_mode,
@@ -149,8 +149,7 @@ static struct genl_ops irda_nl_ops[] = {
 
 int irda_nl_register(void)
 {
-       return genl_register_family_with_ops(&irda_nl_family,
-               irda_nl_ops, ARRAY_SIZE(irda_nl_ops));
+       return genl_register_family_with_ops(&irda_nl_family, irda_nl_ops);
 }
 
 void irda_nl_unregister(void)
index 571db8dd2292a7c5b1f2e940073edce370b13699..da1a1cee1a088e39816d565e99975bbc69a392d3 100644 (file)
@@ -518,9 +518,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
        if (flags & MSG_OOB)
                goto out;
 
-       if (addr_len)
-               *addr_len = sizeof(*sin);
-
        skb = skb_recv_datagram(sk, flags, noblock, &err);
        if (!skb)
                goto out;
@@ -543,6 +540,7 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
                sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
                sin->sin_port = 0;
                memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
+               *addr_len = sizeof(*sin);
        }
        if (inet->cmsg_flags)
                ip_cmsg_recv(msg, skb);
index be446d517bc96641d413dc0bba09d9150398a81e..4cfd722e91536c1de137ec64f1e33bbc7fc5e1ea 100644 (file)
@@ -793,7 +793,7 @@ static struct nla_policy l2tp_nl_policy[L2TP_ATTR_MAX + 1] = {
        },
 };
 
-static struct genl_ops l2tp_nl_ops[] = {
+static const struct genl_ops l2tp_nl_ops[] = {
        {
                .cmd = L2TP_CMD_NOOP,
                .doit = l2tp_nl_cmd_noop,
@@ -887,13 +887,8 @@ EXPORT_SYMBOL_GPL(l2tp_nl_unregister_ops);
 
 static int l2tp_nl_init(void)
 {
-       int err;
-
        pr_info("L2TP netlink interface\n");
-       err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops,
-                                           ARRAY_SIZE(l2tp_nl_ops));
-
-       return err;
+       return genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops);
 }
 
 static void l2tp_nl_cleanup(void)
index 1ded5c6d268c662af2e4743fedfb8226b5715cc3..35be035ee0cec79b5b797efb46c287661b8dbc93 100644 (file)
@@ -3580,7 +3580,7 @@ out:
 }
 
 
-static struct genl_ops ip_vs_genl_ops[] __read_mostly = {
+static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
        {
                .cmd    = IPVS_CMD_NEW_SERVICE,
                .flags  = GENL_ADMIN_PERM,
@@ -3679,7 +3679,7 @@ static struct genl_ops ip_vs_genl_ops[] __read_mostly = {
 static int __init ip_vs_genl_register(void)
 {
        return genl_register_family_with_ops(&ip_vs_genl_family,
-               ip_vs_genl_ops, ARRAY_SIZE(ip_vs_genl_ops));
+                                            ip_vs_genl_ops);
 }
 
 static void ip_vs_genl_unregister(void)
index e7c4e0e01ff5de40fb32cdeddd70cb204b84ea32..80c2e2d603e00c718ad1744804ef29f926b9d404 100644 (file)
@@ -84,7 +84,7 @@ set_match_v0_checkentry(const struct xt_mtchk_param *par)
        index = ip_set_nfnl_get_byindex(par->net, info->match_set.index);
 
        if (index == IPSET_INVALID_ID) {
-               pr_warning("Cannot find set indentified by id %u to match\n",
+               pr_warning("Cannot find set identified by id %u to match\n",
                           info->match_set.index);
                return -ENOENT;
        }
@@ -134,7 +134,7 @@ set_match_v1_checkentry(const struct xt_mtchk_param *par)
        index = ip_set_nfnl_get_byindex(par->net, info->match_set.index);
 
        if (index == IPSET_INVALID_ID) {
-               pr_warning("Cannot find set indentified by id %u to match\n",
+               pr_warning("Cannot find set identified by id %u to match\n",
                           info->match_set.index);
                return -ENOENT;
        }
index a1100640495d3d3b106e850e9af6a9cc4e1ed547..69345cebe3a3e397beffbe56536bf971fb81ddf9 100644 (file)
@@ -737,7 +737,7 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info)
  * NetLabel Generic NETLINK Command Definitions
  */
 
-static struct genl_ops netlbl_cipsov4_ops[] = {
+static const struct genl_ops netlbl_cipsov4_ops[] = {
        {
        .cmd = NLBL_CIPSOV4_C_ADD,
        .flags = GENL_ADMIN_PERM,
@@ -783,5 +783,5 @@ static struct genl_ops netlbl_cipsov4_ops[] = {
 int __init netlbl_cipsov4_genl_init(void)
 {
        return genl_register_family_with_ops(&netlbl_cipsov4_gnl_family,
-               netlbl_cipsov4_ops, ARRAY_SIZE(netlbl_cipsov4_ops));
+                                            netlbl_cipsov4_ops);
 }
index dd1c37d7acbcfa6d126a8056360b8d6a56985035..8ef83ee97c6ad0fa934bbbe3d4988003e9ee287b 100644 (file)
@@ -705,7 +705,7 @@ version_failure:
  * NetLabel Generic NETLINK Command Definitions
  */
 
-static struct genl_ops netlbl_mgmt_genl_ops[] = {
+static const struct genl_ops netlbl_mgmt_genl_ops[] = {
        {
        .cmd = NLBL_MGMT_C_ADD,
        .flags = GENL_ADMIN_PERM,
@@ -779,5 +779,5 @@ static struct genl_ops netlbl_mgmt_genl_ops[] = {
 int __init netlbl_mgmt_genl_init(void)
 {
        return genl_register_family_with_ops(&netlbl_mgmt_gnl_family,
-               netlbl_mgmt_genl_ops, ARRAY_SIZE(netlbl_mgmt_genl_ops));
+                                            netlbl_mgmt_genl_ops);
 }
index 8f0897407a2cf950240082cfde9ab07969f96404..43817d73ccf997b69ec15da814e274404e08a2c7 100644 (file)
@@ -1323,7 +1323,7 @@ unlabel_staticlistdef_return:
  * NetLabel Generic NETLINK Command Definitions
  */
 
-static struct genl_ops netlbl_unlabel_genl_ops[] = {
+static const struct genl_ops netlbl_unlabel_genl_ops[] = {
        {
        .cmd = NLBL_UNLABEL_C_STATICADD,
        .flags = GENL_ADMIN_PERM,
@@ -1397,7 +1397,7 @@ static struct genl_ops netlbl_unlabel_genl_ops[] = {
 int __init netlbl_unlabel_genl_init(void)
 {
        return genl_register_family_with_ops(&netlbl_unlabel_gnl_family,
-               netlbl_unlabel_genl_ops, ARRAY_SIZE(netlbl_unlabel_genl_ops));
+                                            netlbl_unlabel_genl_ops);
 }
 
 /*
index 8df7f64c6db35a0f538bef1fa0206f7826fd1a14..f0176e1a5a81a01e59cfdbb59c51d54decf2c0e6 100644 (file)
@@ -2017,7 +2017,7 @@ out:
  * netlink_set_err - report error to broadcast listeners
  * @ssk: the kernel netlink socket, as returned by netlink_kernel_create()
  * @portid: the PORTID of a process that we want to skip (if any)
- * @groups: the broadcast group that will notice the error
+ * @group: the broadcast group that will notice the error
  * @code: error code, must be negative (as usual in kernelspace)
  *
  * This function returns the number of broadcast listeners that have set the
index 0c741cec4d0d294d808ddc26fdaacecc3e6a0b94..7dbc4f732c75a1ae7b18a59f07acbab5743c9e7f 100644 (file)
@@ -65,12 +65,24 @@ static struct list_head family_ht[GENL_FAM_TAB_SIZE];
  * To avoid an allocation at boot of just one unsigned long,
  * declare it global instead.
  * Bit 0 is marked as already used since group 0 is invalid.
+ * Bit 1 is marked as already used since the drop-monitor code
+ * abuses the API and thinks it can statically use group 1.
+ * That group will typically conflict with other groups that
+ * any proper users use.
+ * Bit 16 is marked as used since it's used for generic netlink
+ * and the code no longer marks pre-reserved IDs as used.
+ * Bit 17 is marked as already used since the VFS quota code
+ * also abused this API and relied on family == group ID, we
+ * cater to that by giving it a static family and group ID.
  */
-static unsigned long mc_group_start = 0x1;
+static unsigned long mc_group_start = 0x3 | BIT(GENL_ID_CTRL) |
+                                     BIT(GENL_ID_VFS_DQUOT);
 static unsigned long *mc_groups = &mc_group_start;
 static unsigned long mc_groups_longs = 1;
 
-static int genl_ctrl_event(int event, void *data);
+static int genl_ctrl_event(int event, struct genl_family *family,
+                          const struct genl_multicast_group *grp,
+                          int grp_id);
 
 static inline unsigned int genl_family_hash(unsigned int id)
 {
@@ -106,13 +118,13 @@ static struct genl_family *genl_family_find_byname(char *name)
        return NULL;
 }
 
-static struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family)
+static const struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family)
 {
-       struct genl_ops *ops;
+       int i;
 
-       list_for_each_entry(ops, &family->ops_list, ops_list)
-               if (ops->cmd == cmd)
-                       return ops;
+       for (i = 0; i < family->n_ops; i++)
+               if (family->ops[i].cmd == cmd)
+                       return &family->ops[i];
 
        return NULL;
 }
@@ -126,7 +138,8 @@ static u16 genl_generate_id(void)
        int i;
 
        for (i = 0; i <= GENL_MAX_ID - GENL_MIN_ID; i++) {
-               if (!genl_family_find_byid(id_gen_idx))
+               if (id_gen_idx != GENL_ID_VFS_DQUOT &&
+                   !genl_family_find_byid(id_gen_idx))
                        return id_gen_idx;
                if (++id_gen_idx > GENL_MAX_ID)
                        id_gen_idx = GENL_MIN_ID;
@@ -135,62 +148,110 @@ static u16 genl_generate_id(void)
        return 0;
 }
 
-static struct genl_multicast_group notify_grp;
-
-/**
- * genl_register_mc_group - register a multicast group
- *
- * Registers the specified multicast group and notifies userspace
- * about the new group.
- *
- * Returns 0 on success or a negative error code.
- *
- * @family: The generic netlink family the group shall be registered for.
- * @grp: The group to register, must have a name.
- */
-int genl_register_mc_group(struct genl_family *family,
-                          struct genl_multicast_group *grp)
+static int genl_allocate_reserve_groups(int n_groups, int *first_id)
 {
-       int id;
        unsigned long *new_groups;
-       int err = 0;
+       int start = 0;
+       int i;
+       int id;
+       bool fits;
+
+       do {
+               if (start == 0)
+                       id = find_first_zero_bit(mc_groups,
+                                                mc_groups_longs *
+                                                BITS_PER_LONG);
+               else
+                       id = find_next_zero_bit(mc_groups,
+                                               mc_groups_longs * BITS_PER_LONG,
+                                               start);
+
+               fits = true;
+               for (i = id;
+                    i < min_t(int, id + n_groups,
+                              mc_groups_longs * BITS_PER_LONG);
+                    i++) {
+                       if (test_bit(i, mc_groups)) {
+                               start = i;
+                               fits = false;
+                               break;
+                       }
+               }
 
-       BUG_ON(grp->name[0] == '\0');
-       BUG_ON(memchr(grp->name, '\0', GENL_NAMSIZ) == NULL);
+               if (id >= mc_groups_longs * BITS_PER_LONG) {
+                       unsigned long new_longs = mc_groups_longs +
+                                                 BITS_TO_LONGS(n_groups);
+                       size_t nlen = new_longs * sizeof(unsigned long);
+
+                       if (mc_groups == &mc_group_start) {
+                               new_groups = kzalloc(nlen, GFP_KERNEL);
+                               if (!new_groups)
+                                       return -ENOMEM;
+                               mc_groups = new_groups;
+                               *mc_groups = mc_group_start;
+                       } else {
+                               new_groups = krealloc(mc_groups, nlen,
+                                                     GFP_KERNEL);
+                               if (!new_groups)
+                                       return -ENOMEM;
+                               mc_groups = new_groups;
+                               for (i = 0; i < BITS_TO_LONGS(n_groups); i++)
+                                       mc_groups[mc_groups_longs + i] = 0;
+                       }
+                       mc_groups_longs = new_longs;
+               }
+       } while (!fits);
 
-       genl_lock_all();
+       for (i = id; i < id + n_groups; i++)
+               set_bit(i, mc_groups);
+       *first_id = id;
+       return 0;
+}
 
-       /* special-case our own group */
-       if (grp == &notify_grp)
-               id = GENL_ID_CTRL;
-       else
-               id = find_first_zero_bit(mc_groups,
-                                        mc_groups_longs * BITS_PER_LONG);
+static struct genl_family genl_ctrl;
 
+static int genl_validate_assign_mc_groups(struct genl_family *family)
+{
+       int first_id;
+       int n_groups = family->n_mcgrps;
+       int err, i;
+       bool groups_allocated = false;
 
-       if (id >= mc_groups_longs * BITS_PER_LONG) {
-               size_t nlen = (mc_groups_longs + 1) * sizeof(unsigned long);
+       if (!n_groups)
+               return 0;
 
-               if (mc_groups == &mc_group_start) {
-                       new_groups = kzalloc(nlen, GFP_KERNEL);
-                       if (!new_groups) {
-                               err = -ENOMEM;
-                               goto out;
-                       }
-                       mc_groups = new_groups;
-                       *mc_groups = mc_group_start;
-               } else {
-                       new_groups = krealloc(mc_groups, nlen, GFP_KERNEL);
-                       if (!new_groups) {
-                               err = -ENOMEM;
-                               goto out;
-                       }
-                       mc_groups = new_groups;
-                       mc_groups[mc_groups_longs] = 0;
-               }
-               mc_groups_longs++;
+       for (i = 0; i < n_groups; i++) {
+               const struct genl_multicast_group *grp = &family->mcgrps[i];
+
+               if (WARN_ON(grp->name[0] == '\0'))
+                       return -EINVAL;
+               if (WARN_ON(memchr(grp->name, '\0', GENL_NAMSIZ) == NULL))
+                       return -EINVAL;
+       }
+
+       /* special-case our own group and hacks */
+       if (family == &genl_ctrl) {
+               first_id = GENL_ID_CTRL;
+               BUG_ON(n_groups != 1);
+       } else if (strcmp(family->name, "NET_DM") == 0) {
+               first_id = 1;
+               BUG_ON(n_groups != 1);
+       } else if (strcmp(family->name, "VFS_DQUOT") == 0) {
+               first_id = GENL_ID_VFS_DQUOT;
+               BUG_ON(n_groups != 1);
+       } else {
+               groups_allocated = true;
+               err = genl_allocate_reserve_groups(n_groups, &first_id);
+               if (err)
+                       return err;
        }
 
+       family->mcgrp_offset = first_id;
+
+       /* if still initializing, can't and don't need to to realloc bitmaps */
+       if (!init_net.genl_sock)
+               return 0;
+
        if (family->netnsok) {
                struct net *net;
 
@@ -206,9 +267,7 @@ int genl_register_mc_group(struct genl_family *family,
                                 * number of _possible_ groups has been
                                 * increased on some sockets which is ok.
                                 */
-                               rcu_read_unlock();
-                               netlink_table_ungrab();
-                               goto out;
+                               break;
                        }
                }
                rcu_read_unlock();
@@ -216,152 +275,67 @@ int genl_register_mc_group(struct genl_family *family,
        } else {
                err = netlink_change_ngroups(init_net.genl_sock,
                                             mc_groups_longs * BITS_PER_LONG);
-               if (err)
-                       goto out;
        }
 
-       grp->id = id;
-       set_bit(id, mc_groups);
-       list_add_tail(&grp->list, &family->mcast_groups);
-       grp->family = family;
+       if (groups_allocated && err) {
+               for (i = 0; i < family->n_mcgrps; i++)
+                       clear_bit(family->mcgrp_offset + i, mc_groups);
+       }
 
-       genl_ctrl_event(CTRL_CMD_NEWMCAST_GRP, grp);
- out:
-       genl_unlock_all();
        return err;
 }
-EXPORT_SYMBOL(genl_register_mc_group);
 
-static void __genl_unregister_mc_group(struct genl_family *family,
-                                      struct genl_multicast_group *grp)
+static void genl_unregister_mc_groups(struct genl_family *family)
 {
        struct net *net;
-       BUG_ON(grp->family != family);
+       int i;
 
        netlink_table_grab();
        rcu_read_lock();
-       for_each_net_rcu(net)
-               __netlink_clear_multicast_users(net->genl_sock, grp->id);
+       for_each_net_rcu(net) {
+               for (i = 0; i < family->n_mcgrps; i++)
+                       __netlink_clear_multicast_users(
+                               net->genl_sock, family->mcgrp_offset + i);
+       }
        rcu_read_unlock();
        netlink_table_ungrab();
 
-       clear_bit(grp->id, mc_groups);
-       list_del(&grp->list);
-       genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, grp);
-       grp->id = 0;
-       grp->family = NULL;
-}
+       for (i = 0; i < family->n_mcgrps; i++) {
+               int grp_id = family->mcgrp_offset + i;
 
-/**
- * genl_unregister_mc_group - unregister a multicast group
- *
- * Unregisters the specified multicast group and notifies userspace
- * about it. All current listeners on the group are removed.
- *
- * Note: It is not necessary to unregister all multicast groups before
- *       unregistering the family, unregistering the family will cause
- *       all assigned multicast groups to be unregistered automatically.
- *
- * @family: Generic netlink family the group belongs to.
- * @grp: The group to unregister, must have been registered successfully
- *      previously.
- */
-void genl_unregister_mc_group(struct genl_family *family,
-                             struct genl_multicast_group *grp)
-{
-       genl_lock_all();
-       __genl_unregister_mc_group(family, grp);
-       genl_unlock_all();
+               if (grp_id != 1)
+                       clear_bit(grp_id, mc_groups);
+               genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, family,
+                               &family->mcgrps[i], grp_id);
+       }
 }
-EXPORT_SYMBOL(genl_unregister_mc_group);
 
-static void genl_unregister_mc_groups(struct genl_family *family)
+static int genl_validate_ops(struct genl_family *family)
 {
-       struct genl_multicast_group *grp, *tmp;
+       const struct genl_ops *ops = family->ops;
+       unsigned int n_ops = family->n_ops;
+       int i, j;
 
-       list_for_each_entry_safe(grp, tmp, &family->mcast_groups, list)
-               __genl_unregister_mc_group(family, grp);
-}
-
-/**
- * genl_register_ops - register generic netlink operations
- * @family: generic netlink family
- * @ops: operations to be registered
- *
- * Registers the specified operations and assigns them to the specified
- * family. Either a doit or dumpit callback must be specified or the
- * operation will fail. Only one operation structure per command
- * identifier may be registered.
- *
- * See include/net/genetlink.h for more documenation on the operations
- * structure.
- *
- * Returns 0 on success or a negative error code.
- */
-int genl_register_ops(struct genl_family *family, struct genl_ops *ops)
-{
-       int err = -EINVAL;
+       if (WARN_ON(n_ops && !ops))
+               return -EINVAL;
 
-       if (ops->dumpit == NULL && ops->doit == NULL)
-               goto errout;
+       if (!n_ops)
+               return 0;
 
-       if (genl_get_cmd(ops->cmd, family)) {
-               err = -EEXIST;
-               goto errout;
+       for (i = 0; i < n_ops; i++) {
+               if (ops[i].dumpit == NULL && ops[i].doit == NULL)
+                       return -EINVAL;
+               for (j = i + 1; j < n_ops; j++)
+                       if (ops[i].cmd == ops[j].cmd)
+                               return -EINVAL;
        }
 
-       if (ops->dumpit)
-               ops->flags |= GENL_CMD_CAP_DUMP;
-       if (ops->doit)
-               ops->flags |= GENL_CMD_CAP_DO;
-       if (ops->policy)
-               ops->flags |= GENL_CMD_CAP_HASPOL;
+       /* family is not registered yet, so no locking needed */
+       family->ops = ops;
+       family->n_ops = n_ops;
 
-       genl_lock_all();
-       list_add_tail(&ops->ops_list, &family->ops_list);
-       genl_unlock_all();
-
-       genl_ctrl_event(CTRL_CMD_NEWOPS, ops);
-       err = 0;
-errout:
-       return err;
-}
-EXPORT_SYMBOL(genl_register_ops);
-
-/**
- * genl_unregister_ops - unregister generic netlink operations
- * @family: generic netlink family
- * @ops: operations to be unregistered
- *
- * Unregisters the specified operations and unassigns them from the
- * specified family. The operation blocks until the current message
- * processing has finished and doesn't start again until the
- * unregister process has finished.
- *
- * Note: It is not necessary to unregister all operations before
- *       unregistering the family, unregistering the family will cause
- *       all assigned operations to be unregistered automatically.
- *
- * Returns 0 on success or a negative error code.
- */
-int genl_unregister_ops(struct genl_family *family, struct genl_ops *ops)
-{
-       struct genl_ops *rc;
-
-       genl_lock_all();
-       list_for_each_entry(rc, &family->ops_list, ops_list) {
-               if (rc == ops) {
-                       list_del(&ops->ops_list);
-                       genl_unlock_all();
-                       genl_ctrl_event(CTRL_CMD_DELOPS, ops);
-                       return 0;
-               }
-       }
-       genl_unlock_all();
-
-       return -ENOENT;
+       return 0;
 }
-EXPORT_SYMBOL(genl_unregister_ops);
 
 /**
  * __genl_register_family - register a generic netlink family
@@ -372,11 +346,14 @@ EXPORT_SYMBOL(genl_unregister_ops);
  * The family id may equal GENL_ID_GENERATE causing an unique id to
  * be automatically generated and assigned.
  *
+ * The family's ops array must already be assigned, you can use the
+ * genl_register_family_with_ops() helper function.
+ *
  * Return 0 on success or a negative error code.
  */
 int __genl_register_family(struct genl_family *family)
 {
-       int err = -EINVAL;
+       int err = -EINVAL, i;
 
        if (family->id && family->id < GENL_MIN_ID)
                goto errout;
@@ -384,8 +361,9 @@ int __genl_register_family(struct genl_family *family)
        if (family->id > GENL_MAX_ID)
                goto errout;
 
-       INIT_LIST_HEAD(&family->ops_list);
-       INIT_LIST_HEAD(&family->mcast_groups);
+       err = genl_validate_ops(family);
+       if (err)
+               return err;
 
        genl_lock_all();
 
@@ -418,10 +396,18 @@ int __genl_register_family(struct genl_family *family)
        } else
                family->attrbuf = NULL;
 
+       err = genl_validate_assign_mc_groups(family);
+       if (err)
+               goto errout_locked;
+
        list_add_tail(&family->family_list, genl_family_chain(family->id));
        genl_unlock_all();
 
-       genl_ctrl_event(CTRL_CMD_NEWFAMILY, family);
+       /* send all events */
+       genl_ctrl_event(CTRL_CMD_NEWFAMILY, family, NULL, 0);
+       for (i = 0; i < family->n_mcgrps; i++)
+               genl_ctrl_event(CTRL_CMD_NEWMCAST_GRP, family,
+                               &family->mcgrps[i], family->mcgrp_offset + i);
 
        return 0;
 
@@ -432,52 +418,6 @@ errout:
 }
 EXPORT_SYMBOL(__genl_register_family);
 
-/**
- * __genl_register_family_with_ops - register a generic netlink family
- * @family: generic netlink family
- * @ops: operations to be registered
- * @n_ops: number of elements to register
- *
- * Registers the specified family and operations from the specified table.
- * Only one family may be registered with the same family name or identifier.
- *
- * The family id may equal GENL_ID_GENERATE causing an unique id to
- * be automatically generated and assigned.
- *
- * Either a doit or dumpit callback must be specified for every registered
- * operation or the function will fail. Only one operation structure per
- * command identifier may be registered.
- *
- * See include/net/genetlink.h for more documenation on the operations
- * structure.
- *
- * This is equivalent to calling genl_register_family() followed by
- * genl_register_ops() for every operation entry in the table taking
- * care to unregister the family on error path.
- *
- * Return 0 on success or a negative error code.
- */
-int __genl_register_family_with_ops(struct genl_family *family,
-       struct genl_ops *ops, size_t n_ops)
-{
-       int err, i;
-
-       err = __genl_register_family(family);
-       if (err)
-               return err;
-
-       for (i = 0; i < n_ops; ++i, ++ops) {
-               err = genl_register_ops(family, ops);
-               if (err)
-                       goto err_out;
-       }
-       return 0;
-err_out:
-       genl_unregister_family(family);
-       return err;
-}
-EXPORT_SYMBOL(__genl_register_family_with_ops);
-
 /**
  * genl_unregister_family - unregister generic netlink family
  * @family: generic netlink family
@@ -499,11 +439,11 @@ int genl_unregister_family(struct genl_family *family)
                        continue;
 
                list_del(&rc->family_list);
-               INIT_LIST_HEAD(&family->ops_list);
+               family->n_ops = 0;
                genl_unlock_all();
 
                kfree(family->attrbuf);
-               genl_ctrl_event(CTRL_CMD_DELFAMILY, family);
+               genl_ctrl_event(CTRL_CMD_DELFAMILY, family, NULL, 0);
                return 0;
        }
 
@@ -546,7 +486,8 @@ EXPORT_SYMBOL(genlmsg_put);
 
 static int genl_lock_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 {
-       struct genl_ops *ops = cb->data;
+       /* our ops are always const - netlink API doesn't propagate that */
+       const struct genl_ops *ops = cb->data;
        int rc;
 
        genl_lock();
@@ -557,7 +498,8 @@ static int genl_lock_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 
 static int genl_lock_done(struct netlink_callback *cb)
 {
-       struct genl_ops *ops = cb->data;
+       /* our ops are always const - netlink API doesn't propagate that */
+       const struct genl_ops *ops = cb->data;
        int rc = 0;
 
        if (ops->done) {
@@ -572,7 +514,7 @@ static int genl_family_rcv_msg(struct genl_family *family,
                               struct sk_buff *skb,
                               struct nlmsghdr *nlh)
 {
-       struct genl_ops *ops;
+       const struct genl_ops *ops;
        struct net *net = sock_net(skb->sk);
        struct genl_info info;
        struct genlmsghdr *hdr = nlmsg_data(nlh);
@@ -604,7 +546,8 @@ static int genl_family_rcv_msg(struct genl_family *family,
                if (!family->parallel_ops) {
                        struct netlink_dump_control c = {
                                .module = family->module,
-                               .data = ops,
+                               /* we have const, but the netlink API doesn't */
+                               .data = (void *)ops,
                                .dump = genl_lock_dumpit,
                                .done = genl_lock_done,
                        };
@@ -726,24 +669,32 @@ static int ctrl_fill_info(struct genl_family *family, u32 portid, u32 seq,
            nla_put_u32(skb, CTRL_ATTR_MAXATTR, family->maxattr))
                goto nla_put_failure;
 
-       if (!list_empty(&family->ops_list)) {
+       if (family->n_ops) {
                struct nlattr *nla_ops;
-               struct genl_ops *ops;
-               int idx = 1;
+               int i;
 
                nla_ops = nla_nest_start(skb, CTRL_ATTR_OPS);
                if (nla_ops == NULL)
                        goto nla_put_failure;
 
-               list_for_each_entry(ops, &family->ops_list, ops_list) {
+               for (i = 0; i < family->n_ops; i++) {
                        struct nlattr *nest;
+                       const struct genl_ops *ops = &family->ops[i];
+                       u32 op_flags = ops->flags;
 
-                       nest = nla_nest_start(skb, idx++);
+                       if (ops->dumpit)
+                               op_flags |= GENL_CMD_CAP_DUMP;
+                       if (ops->doit)
+                               op_flags |= GENL_CMD_CAP_DO;
+                       if (ops->policy)
+                               op_flags |= GENL_CMD_CAP_HASPOL;
+
+                       nest = nla_nest_start(skb, i + 1);
                        if (nest == NULL)
                                goto nla_put_failure;
 
                        if (nla_put_u32(skb, CTRL_ATTR_OP_ID, ops->cmd) ||
-                           nla_put_u32(skb, CTRL_ATTR_OP_FLAGS, ops->flags))
+                           nla_put_u32(skb, CTRL_ATTR_OP_FLAGS, op_flags))
                                goto nla_put_failure;
 
                        nla_nest_end(skb, nest);
@@ -752,23 +703,26 @@ static int ctrl_fill_info(struct genl_family *family, u32 portid, u32 seq,
                nla_nest_end(skb, nla_ops);
        }
 
-       if (!list_empty(&family->mcast_groups)) {
-               struct genl_multicast_group *grp;
+       if (family->n_mcgrps) {
                struct nlattr *nla_grps;
-               int idx = 1;
+               int i;
 
                nla_grps = nla_nest_start(skb, CTRL_ATTR_MCAST_GROUPS);
                if (nla_grps == NULL)
                        goto nla_put_failure;
 
-               list_for_each_entry(grp, &family->mcast_groups, list) {
+               for (i = 0; i < family->n_mcgrps; i++) {
                        struct nlattr *nest;
+                       const struct genl_multicast_group *grp;
+
+                       grp = &family->mcgrps[i];
 
-                       nest = nla_nest_start(skb, idx++);
+                       nest = nla_nest_start(skb, i + 1);
                        if (nest == NULL)
                                goto nla_put_failure;
 
-                       if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID, grp->id) ||
+                       if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID,
+                                       family->mcgrp_offset + i) ||
                            nla_put_string(skb, CTRL_ATTR_MCAST_GRP_NAME,
                                           grp->name))
                                goto nla_put_failure;
@@ -785,9 +739,10 @@ nla_put_failure:
        return -EMSGSIZE;
 }
 
-static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 portid,
-                               u32 seq, u32 flags, struct sk_buff *skb,
-                               u8 cmd)
+static int ctrl_fill_mcgrp_info(struct genl_family *family,
+                               const struct genl_multicast_group *grp,
+                               int grp_id, u32 portid, u32 seq, u32 flags,
+                               struct sk_buff *skb, u8 cmd)
 {
        void *hdr;
        struct nlattr *nla_grps;
@@ -797,8 +752,8 @@ static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 portid,
        if (hdr == NULL)
                return -1;
 
-       if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, grp->family->name) ||
-           nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, grp->family->id))
+       if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) ||
+           nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id))
                goto nla_put_failure;
 
        nla_grps = nla_nest_start(skb, CTRL_ATTR_MCAST_GROUPS);
@@ -809,7 +764,7 @@ static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 portid,
        if (nest == NULL)
                goto nla_put_failure;
 
-       if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID, grp->id) ||
+       if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID, grp_id) ||
            nla_put_string(skb, CTRL_ATTR_MCAST_GRP_NAME,
                           grp->name))
                goto nla_put_failure;
@@ -875,8 +830,10 @@ static struct sk_buff *ctrl_build_family_msg(struct genl_family *family,
        return skb;
 }
 
-static struct sk_buff *ctrl_build_mcgrp_msg(struct genl_multicast_group *grp,
-                                           u32 portid, int seq, u8 cmd)
+static struct sk_buff *
+ctrl_build_mcgrp_msg(struct genl_family *family,
+                    const struct genl_multicast_group *grp,
+                    int grp_id, u32 portid, int seq, u8 cmd)
 {
        struct sk_buff *skb;
        int err;
@@ -885,7 +842,8 @@ static struct sk_buff *ctrl_build_mcgrp_msg(struct genl_multicast_group *grp,
        if (skb == NULL)
                return ERR_PTR(-ENOBUFS);
 
-       err = ctrl_fill_mcgrp_info(grp, portid, seq, 0, skb, cmd);
+       err = ctrl_fill_mcgrp_info(family, grp, grp_id, portid,
+                                  seq, 0, skb, cmd);
        if (err < 0) {
                nlmsg_free(skb);
                return ERR_PTR(err);
@@ -947,11 +905,11 @@ static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info)
        return genlmsg_reply(msg, info);
 }
 
-static int genl_ctrl_event(int event, void *data)
+static int genl_ctrl_event(int event, struct genl_family *family,
+                          const struct genl_multicast_group *grp,
+                          int grp_id)
 {
        struct sk_buff *msg;
-       struct genl_family *family;
-       struct genl_multicast_group *grp;
 
        /* genl is still initialising */
        if (!init_net.genl_sock)
@@ -960,14 +918,13 @@ static int genl_ctrl_event(int event, void *data)
        switch (event) {
        case CTRL_CMD_NEWFAMILY:
        case CTRL_CMD_DELFAMILY:
-               family = data;
+               WARN_ON(grp);
                msg = ctrl_build_family_msg(family, 0, 0, event);
                break;
        case CTRL_CMD_NEWMCAST_GRP:
        case CTRL_CMD_DELMCAST_GRP:
-               grp = data;
-               family = grp->family;
-               msg = ctrl_build_mcgrp_msg(data, 0, 0, event);
+               BUG_ON(!grp);
+               msg = ctrl_build_mcgrp_msg(family, grp, grp_id, 0, 0, event);
                break;
        default:
                return -EINVAL;
@@ -977,26 +934,29 @@ static int genl_ctrl_event(int event, void *data)
                return PTR_ERR(msg);
 
        if (!family->netnsok) {
-               genlmsg_multicast_netns(&init_net, msg, 0,
-                                       GENL_ID_CTRL, GFP_KERNEL);
+               genlmsg_multicast_netns(&genl_ctrl, &init_net, msg, 0,
+                                       0, GFP_KERNEL);
        } else {
                rcu_read_lock();
-               genlmsg_multicast_allns(msg, 0, GENL_ID_CTRL, GFP_ATOMIC);
+               genlmsg_multicast_allns(&genl_ctrl, msg, 0,
+                                       0, GFP_ATOMIC);
                rcu_read_unlock();
        }
 
        return 0;
 }
 
-static struct genl_ops genl_ctrl_ops = {
-       .cmd            = CTRL_CMD_GETFAMILY,
-       .doit           = ctrl_getfamily,
-       .dumpit         = ctrl_dumpfamily,
-       .policy         = ctrl_policy,
+static struct genl_ops genl_ctrl_ops[] = {
+       {
+               .cmd            = CTRL_CMD_GETFAMILY,
+               .doit           = ctrl_getfamily,
+               .dumpit         = ctrl_dumpfamily,
+               .policy         = ctrl_policy,
+       },
 };
 
-static struct genl_multicast_group notify_grp = {
-       .name           = "notify",
+static struct genl_multicast_group genl_ctrl_groups[] = {
+       { .name = "notify", },
 };
 
 static int __net_init genl_pernet_init(struct net *net)
@@ -1036,7 +996,8 @@ static int __init genl_init(void)
        for (i = 0; i < GENL_FAM_TAB_SIZE; i++)
                INIT_LIST_HEAD(&family_ht[i]);
 
-       err = genl_register_family_with_ops(&genl_ctrl, &genl_ctrl_ops, 1);
+       err = genl_register_family_with_ops_groups(&genl_ctrl, genl_ctrl_ops,
+                                                  genl_ctrl_groups);
        if (err < 0)
                goto problem;
 
@@ -1044,10 +1005,6 @@ static int __init genl_init(void)
        if (err)
                goto problem;
 
-       err = genl_register_mc_group(&genl_ctrl, &notify_grp);
-       if (err < 0)
-               goto problem;
-
        return 0;
 
 problem:
@@ -1085,14 +1042,18 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group,
        return err;
 }
 
-int genlmsg_multicast_allns(struct sk_buff *skb, u32 portid, unsigned int group,
-                           gfp_t flags)
+int genlmsg_multicast_allns(struct genl_family *family, struct sk_buff *skb,
+                           u32 portid, unsigned int group, gfp_t flags)
 {
+       if (group >= family->n_mcgrps)
+               return -EINVAL;
+       group = family->mcgrp_offset + group;
        return genlmsg_mcast(skb, portid, group, flags);
 }
 EXPORT_SYMBOL(genlmsg_multicast_allns);
 
-void genl_notify(struct sk_buff *skb, struct net *net, u32 portid, u32 group,
+void genl_notify(struct genl_family *family,
+                struct sk_buff *skb, struct net *net, u32 portid, u32 group,
                 struct nlmsghdr *nlh, gfp_t flags)
 {
        struct sock *sk = net->genl_sock;
@@ -1101,6 +1062,9 @@ void genl_notify(struct sk_buff *skb, struct net *net, u32 portid, u32 group,
        if (nlh)
                report = nlmsg_report(nlh);
 
+       if (group >= family->n_mcgrps)
+               return;
+       group = family->mcgrp_offset + group;
        nlmsg_notify(sk, skb, portid, group, report, flags);
 }
 EXPORT_SYMBOL(genl_notify);
index 84b7e3ea7b7ad7ce09e9256916589e4724d55969..a9b2342d5253295b607f3a3a1aa760e47c4d5ebe 100644 (file)
@@ -30,8 +30,8 @@
 #include "nfc.h"
 #include "llcp.h"
 
-static struct genl_multicast_group nfc_genl_event_mcgrp = {
-       .name = NFC_GENL_MCAST_EVENT_NAME,
+static const struct genl_multicast_group nfc_genl_mcgrps[] = {
+       { .name = NFC_GENL_MCAST_EVENT_NAME, },
 };
 
 static struct genl_family nfc_genl_family = {
@@ -194,7 +194,7 @@ int nfc_genl_targets_found(struct nfc_dev *dev)
 
        genlmsg_end(msg, hdr);
 
-       return genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+       return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
 
 nla_put_failure:
        genlmsg_cancel(msg, hdr);
@@ -223,7 +223,7 @@ int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -255,7 +255,7 @@ int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -285,7 +285,7 @@ int nfc_genl_tm_deactivated(struct nfc_dev *dev)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -318,7 +318,7 @@ int nfc_genl_device_added(struct nfc_dev *dev)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -348,7 +348,7 @@ int nfc_genl_device_removed(struct nfc_dev *dev)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -414,7 +414,7 @@ int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
 
        genlmsg_end(msg, hdr);
 
-       return genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+       return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
 
 nla_put_failure:
        genlmsg_cancel(msg, hdr);
@@ -448,7 +448,7 @@ int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -479,7 +479,7 @@ int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -600,7 +600,7 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
 
        dev->dep_link_up = true;
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
 
        return 0;
 
@@ -632,7 +632,7 @@ int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
 
        return 0;
 
@@ -1137,7 +1137,7 @@ int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        return 0;
 
@@ -1308,7 +1308,7 @@ static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
 
        kfree(ctx);
 
@@ -1364,7 +1364,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)
        return dev->ops->se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
 }
 
-static struct genl_ops nfc_genl_ops[] = {
+static const struct genl_ops nfc_genl_ops[] = {
        {
                .cmd = NFC_CMD_GET_DEVICE,
                .doit = nfc_genl_get_device,
@@ -1536,16 +1536,15 @@ int __init nfc_genl_init(void)
 {
        int rc;
 
-       rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops,
-                                          ARRAY_SIZE(nfc_genl_ops));
+       rc = genl_register_family_with_ops_groups(&nfc_genl_family,
+                                                 nfc_genl_ops,
+                                                 nfc_genl_mcgrps);
        if (rc)
                return rc;
 
-       rc = genl_register_mc_group(&nfc_genl_family, &nfc_genl_event_mcgrp);
-
        netlink_register_notifier(&nl_notifier);
 
-       return rc;
+       return 0;
 }
 
 /**
index 449e0776a2c0887bea75fbc963224a37d20ccb33..6f5e1dd3be2dbdcfdb591d64323c3558d0636e6d 100644 (file)
 
 int ovs_net_id __read_mostly;
 
-static void ovs_notify(struct sk_buff *skb, struct genl_info *info,
-                      struct genl_multicast_group *grp)
+static void ovs_notify(struct genl_family *family,
+                      struct sk_buff *skb, struct genl_info *info)
 {
-       genl_notify(skb, genl_info_net(info), info->snd_portid,
-                   grp->id, info->nlhdr, GFP_KERNEL);
+       genl_notify(family, skb, genl_info_net(info), info->snd_portid,
+                   0, info->nlhdr, GFP_KERNEL);
 }
 
 /**
@@ -557,7 +557,7 @@ static const struct nla_policy packet_policy[OVS_PACKET_ATTR_MAX + 1] = {
        [OVS_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED },
 };
 
-static struct genl_ops dp_packet_genl_ops[] = {
+static const struct genl_ops dp_packet_genl_ops[] = {
        { .cmd = OVS_PACKET_CMD_EXECUTE,
          .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
          .policy = packet_policy,
@@ -877,10 +877,10 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
        ovs_unlock();
 
        if (!IS_ERR(reply))
-               ovs_notify(reply, info, &ovs_dp_flow_multicast_group);
+               ovs_notify(&dp_flow_genl_family, reply, info);
        else
-               netlink_set_err(sock_net(skb->sk)->genl_sock, 0,
-                               ovs_dp_flow_multicast_group.id, PTR_ERR(reply));
+               genl_set_err(&dp_flow_genl_family, sock_net(skb->sk), 0,
+                            0, PTR_ERR(reply));
        return 0;
 
 err_flow_free:
@@ -990,7 +990,7 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
        ovs_flow_free(flow, true);
        ovs_unlock();
 
-       ovs_notify(reply, info, &ovs_dp_flow_multicast_group);
+       ovs_notify(&dp_flow_genl_family, reply, info);
        return 0;
 unlock:
        ovs_unlock();
@@ -1034,7 +1034,7 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
        return skb->len;
 }
 
-static struct genl_ops dp_flow_genl_ops[] = {
+static const struct genl_ops dp_flow_genl_ops[] = {
        { .cmd = OVS_FLOW_CMD_NEW,
          .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
          .policy = flow_policy,
@@ -1243,7 +1243,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 
        ovs_unlock();
 
-       ovs_notify(reply, info, &ovs_dp_datapath_multicast_group);
+       ovs_notify(&dp_datapath_genl_family, reply, info);
        return 0;
 
 err_destroy_local_port:
@@ -1308,7 +1308,7 @@ static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info)
        __dp_destroy(dp);
        ovs_unlock();
 
-       ovs_notify(reply, info, &ovs_dp_datapath_multicast_group);
+       ovs_notify(&dp_datapath_genl_family, reply, info);
 
        return 0;
 unlock:
@@ -1332,14 +1332,14 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info)
                                      info->snd_seq, OVS_DP_CMD_NEW);
        if (IS_ERR(reply)) {
                err = PTR_ERR(reply);
-               netlink_set_err(sock_net(skb->sk)->genl_sock, 0,
-                               ovs_dp_datapath_multicast_group.id, err);
+               genl_set_err(&dp_datapath_genl_family, sock_net(skb->sk), 0,
+                            0, err);
                err = 0;
                goto unlock;
        }
 
        ovs_unlock();
-       ovs_notify(reply, info, &ovs_dp_datapath_multicast_group);
+       ovs_notify(&dp_datapath_genl_family, reply, info);
 
        return 0;
 unlock:
@@ -1398,7 +1398,7 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
        return skb->len;
 }
 
-static struct genl_ops dp_datapath_genl_ops[] = {
+static const struct genl_ops dp_datapath_genl_ops[] = {
        { .cmd = OVS_DP_CMD_NEW,
          .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
          .policy = datapath_policy,
@@ -1431,7 +1431,7 @@ static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = {
        [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED },
 };
 
-static struct genl_family dp_vport_genl_family = {
+struct genl_family dp_vport_genl_family = {
        .id = GENL_ID_GENERATE,
        .hdrsize = sizeof(struct ovs_header),
        .name = OVS_VPORT_FAMILY,
@@ -1601,7 +1601,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
                goto exit_unlock;
        }
 
-       ovs_notify(reply, info, &ovs_dp_vport_multicast_group);
+       ovs_notify(&dp_vport_genl_family, reply, info);
 
 exit_unlock:
        ovs_unlock();
@@ -1648,7 +1648,7 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
        BUG_ON(err < 0);
 
        ovs_unlock();
-       ovs_notify(reply, info, &ovs_dp_vport_multicast_group);
+       ovs_notify(&dp_vport_genl_family, reply, info);
        return 0;
 
 exit_free:
@@ -1685,7 +1685,7 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info)
        err = 0;
        ovs_dp_detach_port(vport);
 
-       ovs_notify(reply, info, &ovs_dp_vport_multicast_group);
+       ovs_notify(&dp_vport_genl_family, reply, info);
 
 exit_unlock:
        ovs_unlock();
@@ -1759,7 +1759,7 @@ out:
        return skb->len;
 }
 
-static struct genl_ops dp_vport_genl_ops[] = {
+static const struct genl_ops dp_vport_genl_ops[] = {
        { .cmd = OVS_VPORT_CMD_NEW,
          .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
          .policy = vport_policy,
@@ -1785,9 +1785,9 @@ static struct genl_ops dp_vport_genl_ops[] = {
 
 struct genl_family_and_ops {
        struct genl_family *family;
-       struct genl_ops *ops;
+       const struct genl_ops *ops;
        int n_ops;
-       struct genl_multicast_group *group;
+       const struct genl_multicast_group *group;
 };
 
 static const struct genl_family_and_ops dp_genl_families[] = {
@@ -1823,17 +1823,14 @@ static int dp_register_genl(void)
        for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) {
                const struct genl_family_and_ops *f = &dp_genl_families[i];
 
-               err = genl_register_family_with_ops(f->family, f->ops,
-                                                   f->n_ops);
+               f->family->ops = f->ops;
+               f->family->n_ops = f->n_ops;
+               f->family->mcgrps = f->group;
+               f->family->n_mcgrps = f->group ? 1 : 0;
+               err = genl_register_family(f->family);
                if (err)
                        goto error;
                n_registered++;
-
-               if (f->group) {
-                       err = genl_register_mc_group(f->family, f->group);
-                       if (err)
-                               goto error;
-               }
        }
 
        return 0;
index d3d14a58aa91413bb18dae53bbb8aa1babd42c73..4067ea41be28d725c1312f2bb995df4e2c2209ab 100644 (file)
@@ -177,6 +177,7 @@ static inline struct vport *ovs_vport_ovsl(const struct datapath *dp, int port_n
 }
 
 extern struct notifier_block ovs_dp_device_notifier;
+extern struct genl_family dp_vport_genl_family;
 extern struct genl_multicast_group ovs_dp_vport_multicast_group;
 
 void ovs_dp_process_received_packet(struct vport *, struct sk_buff *);
index 5c2dab27610962caed49d6017a6cda5b5ac855fc..2c631fe76be191c1a7dd1bc33c1901c8507621b4 100644 (file)
@@ -34,15 +34,14 @@ static void dp_detach_port_notify(struct vport *vport)
                                          OVS_VPORT_CMD_DEL);
        ovs_dp_detach_port(vport);
        if (IS_ERR(notify)) {
-               netlink_set_err(ovs_dp_get_net(dp)->genl_sock, 0,
-                               ovs_dp_vport_multicast_group.id,
-                               PTR_ERR(notify));
+               genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
+                            0, PTR_ERR(notify));
                return;
        }
 
-       genlmsg_multicast_netns(ovs_dp_get_net(dp), notify, 0,
-                               ovs_dp_vport_multicast_group.id,
-                               GFP_KERNEL);
+       genlmsg_multicast_netns(&dp_vport_genl_family,
+                               ovs_dp_get_net(dp), notify, 0,
+                               0, GFP_KERNEL);
 }
 
 void ovs_dp_notify_wq(struct work_struct *work)
index 12c30f3e643e00e3fa495cfc7d471e0078b00114..38946b26e471c9754c922d3451e8ec2682f5ae3d 100644 (file)
@@ -139,9 +139,6 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
                        MSG_CMSG_COMPAT))
                goto out_nofree;
 
-       if (addr_len)
-               *addr_len = sizeof(sa);
-
        skb = skb_recv_datagram(sk, flags, noblock, &rval);
        if (skb == NULL)
                goto out_nofree;
@@ -162,8 +159,10 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
 
        rval = (flags & MSG_TRUNC) ? skb->len : copylen;
 
-       if (msg->msg_name != NULL)
-               memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
+       if (msg->msg_name != NULL) {
+               memcpy(msg->msg_name, &sa, sizeof(sa));
+               *addr_len = sizeof(sa);
+       }
 
 out:
        skb_free_datagram(sk, skb);
index fdc041c5785360731154521fb3492dba825776ff..95d843961907bf4b852743ea81015e7954db342b 100644 (file)
@@ -88,7 +88,7 @@ struct fq_sched_data {
        struct fq_flow  internal;       /* for non classified or high prio packets */
        u32             quantum;
        u32             initial_quantum;
-       u32             flow_default_rate;/* rate per flow : bytes per second */
+       u32             flow_refill_delay;
        u32             flow_max_rate;  /* optional max rate per flow */
        u32             flow_plimit;    /* max packets per flow */
        struct rb_root  *fq_root;
@@ -115,6 +115,7 @@ static struct fq_flow detached, throttled;
 static void fq_flow_set_detached(struct fq_flow *f)
 {
        f->next = &detached;
+       f->age = jiffies;
 }
 
 static bool fq_flow_is_detached(const struct fq_flow *f)
@@ -209,21 +210,15 @@ static void fq_gc(struct fq_sched_data *q,
        }
 }
 
-static const u8 prio2band[TC_PRIO_MAX + 1] = {
-       1, 2, 2, 2, 1, 2, 0, 0 , 1, 1, 1, 1, 1, 1, 1, 1
-};
-
 static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
 {
        struct rb_node **p, *parent;
        struct sock *sk = skb->sk;
        struct rb_root *root;
        struct fq_flow *f;
-       int band;
 
        /* warning: no starvation prevention... */
-       band = prio2band[skb->priority & TC_PRIO_MAX];
-       if (unlikely(band == 0))
+       if (unlikely((skb->priority & TC_PRIO_MAX) == TC_PRIO_CONTROL))
                return &q->internal;
 
        if (unlikely(!sk)) {
@@ -373,17 +368,20 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch)
        }
 
        f->qlen++;
-       flow_queue_add(f, skb);
        if (skb_is_retransmit(skb))
                q->stat_tcp_retrans++;
        sch->qstats.backlog += qdisc_pkt_len(skb);
        if (fq_flow_is_detached(f)) {
                fq_flow_add_tail(&q->new_flows, f);
-               if (q->quantum > f->credit)
-                       f->credit = q->quantum;
+               if (time_after(jiffies, f->age + q->flow_refill_delay))
+                       f->credit = max_t(u32, f->credit, q->quantum);
                q->inactive_flows--;
                qdisc_unthrottled(sch);
        }
+
+       /* Note: this overwrites f->age */
+       flow_queue_add(f, skb);
+
        if (unlikely(f == &q->internal)) {
                q->stat_internal_packets++;
                qdisc_unthrottled(sch);
@@ -461,7 +459,6 @@ begin:
                        fq_flow_add_tail(&q->old_flows, f);
                } else {
                        fq_flow_set_detached(f);
-                       f->age = jiffies;
                        q->inactive_flows++;
                }
                goto begin;
@@ -615,6 +612,7 @@ static const struct nla_policy fq_policy[TCA_FQ_MAX + 1] = {
        [TCA_FQ_FLOW_DEFAULT_RATE]      = { .type = NLA_U32 },
        [TCA_FQ_FLOW_MAX_RATE]          = { .type = NLA_U32 },
        [TCA_FQ_BUCKETS_LOG]            = { .type = NLA_U32 },
+       [TCA_FQ_FLOW_REFILL_DELAY]      = { .type = NLA_U32 },
 };
 
 static int fq_change(struct Qdisc *sch, struct nlattr *opt)
@@ -656,7 +654,8 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
                q->initial_quantum = nla_get_u32(tb[TCA_FQ_INITIAL_QUANTUM]);
 
        if (tb[TCA_FQ_FLOW_DEFAULT_RATE])
-               q->flow_default_rate = nla_get_u32(tb[TCA_FQ_FLOW_DEFAULT_RATE]);
+               pr_warn_ratelimited("sch_fq: defrate %u ignored.\n",
+                                   nla_get_u32(tb[TCA_FQ_FLOW_DEFAULT_RATE]));
 
        if (tb[TCA_FQ_FLOW_MAX_RATE])
                q->flow_max_rate = nla_get_u32(tb[TCA_FQ_FLOW_MAX_RATE]);
@@ -670,6 +669,12 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
                        err = -EINVAL;
        }
 
+       if (tb[TCA_FQ_FLOW_REFILL_DELAY]) {
+               u32 usecs_delay = nla_get_u32(tb[TCA_FQ_FLOW_REFILL_DELAY]) ;
+
+               q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
+       }
+
        if (!err)
                err = fq_resize(q, fq_log);
 
@@ -705,7 +710,7 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt)
        q->flow_plimit          = 100;
        q->quantum              = 2 * psched_mtu(qdisc_dev(sch));
        q->initial_quantum      = 10 * psched_mtu(qdisc_dev(sch));
-       q->flow_default_rate    = 0;
+       q->flow_refill_delay    = msecs_to_jiffies(40);
        q->flow_max_rate        = ~0U;
        q->rate_enable          = 1;
        q->new_flows.first      = NULL;
@@ -732,15 +737,16 @@ static int fq_dump(struct Qdisc *sch, struct sk_buff *skb)
        if (opts == NULL)
                goto nla_put_failure;
 
-       /* TCA_FQ_FLOW_DEFAULT_RATE is not used anymore,
-        * do not bother giving its value
-        */
+       /* TCA_FQ_FLOW_DEFAULT_RATE is not used anymore */
+
        if (nla_put_u32(skb, TCA_FQ_PLIMIT, sch->limit) ||
            nla_put_u32(skb, TCA_FQ_FLOW_PLIMIT, q->flow_plimit) ||
            nla_put_u32(skb, TCA_FQ_QUANTUM, q->quantum) ||
            nla_put_u32(skb, TCA_FQ_INITIAL_QUANTUM, q->initial_quantum) ||
            nla_put_u32(skb, TCA_FQ_RATE_ENABLE, q->rate_enable) ||
            nla_put_u32(skb, TCA_FQ_FLOW_MAX_RATE, q->flow_max_rate) ||
+           nla_put_u32(skb, TCA_FQ_FLOW_REFILL_DELAY,
+                       jiffies_to_usecs(q->flow_refill_delay)) ||
            nla_put_u32(skb, TCA_FQ_BUCKETS_LOG, q->fq_trees_log))
                goto nla_put_failure;
 
index c9b91cb1cb0dfdd4561ef3632d7443416a66b19d..68a27f9796d2ece54bcb53b98a47e8f98645077b 100644 (file)
@@ -907,8 +907,8 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
                if (!first || t->last_time_heard > first->last_time_heard) {
                        second = first;
                        first = t;
-               }
-               if (!second || t->last_time_heard > second->last_time_heard)
+               } else if (!second ||
+                          t->last_time_heard > second->last_time_heard)
                        second = t;
        }
 
@@ -929,6 +929,8 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
                first = asoc->peer.primary_path;
        }
 
+       if (!second)
+               second = first;
        /* If we failed to find a usable transport, just camp on the
         * primary, even if it is inactive.
         */
index 6cd930f3678fb21384fc91e8927d0e49901af108..6c981ddc19f89a35115c823a1acf743eca61844d 100644 (file)
@@ -150,7 +150,6 @@ gss_verify_mic_v2(struct krb5_ctx *ctx,
        struct xdr_netobj cksumobj = {.len = sizeof(cksumdata),
                                      .data = cksumdata};
        s32 now;
-       u64 seqnum;
        u8 *ptr = read_token->data;
        u8 *cksumkey;
        u8 flags;
@@ -197,9 +196,10 @@ gss_verify_mic_v2(struct krb5_ctx *ctx,
        if (now > ctx->endtime)
                return GSS_S_CONTEXT_EXPIRED;
 
-       /* do sequencing checks */
-
-       seqnum = be64_to_cpup((__be64 *)ptr + 8);
+       /*
+        * NOTE: the sequence number at ptr + 8 is skipped, rpcsec_gss
+        * doesn't want it checked; see page 6 of rfc 2203.
+        */
 
        return GSS_S_COMPLETE;
 }
index 1da52d1406fc87f0e625b0476bee3bedf682c6a1..42560e55d9789e946f5c02e73a0ed4b6c179409d 100644 (file)
@@ -489,7 +489,6 @@ static u32
 gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
 {
        s32             now;
-       u64             seqnum;
        u8              *ptr;
        u8              flags = 0x00;
        u16             ec, rrc;
@@ -525,7 +524,10 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
        ec = be16_to_cpup((__be16 *)(ptr + 4));
        rrc = be16_to_cpup((__be16 *)(ptr + 6));
 
-       seqnum = be64_to_cpup((__be64 *)(ptr + 8));
+       /*
+        * NOTE: the sequence number at ptr + 8 is skipped, rpcsec_gss
+        * doesn't want it checked; see page 6 of rfc 2203.
+        */
 
        if (rrc != 0)
                rotate_left(offset + 16, buf, rrc);
@@ -574,8 +576,8 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
        buf->head[0].iov_len -= GSS_KRB5_TOK_HDR_LEN + headskip;
        buf->len -= GSS_KRB5_TOK_HDR_LEN + headskip;
 
-       /* Trim off the checksum blob */
-       xdr_buf_trim(buf, GSS_KRB5_TOK_HDR_LEN + tailskip);
+       /* Trim off the trailing "extra count" and checksum blob */
+       xdr_buf_trim(buf, ec + GSS_KRB5_TOK_HDR_LEN + tailskip);
        return GSS_S_COMPLETE;
 }
 
index f1eb0d16666c2750b0001d923fabbd572f2cbe7d..458f85e9b0ba088575a72ef6dd6ff8d21484d290 100644 (file)
@@ -298,7 +298,8 @@ int gssp_accept_sec_context_upcall(struct net *net,
        if (res.context_handle) {
                data->out_handle = rctxh.exported_context_token;
                data->mech_oid.len = rctxh.mech.len;
-               memcpy(data->mech_oid.data, rctxh.mech.data,
+               if (rctxh.mech.data)
+                       memcpy(data->mech_oid.data, rctxh.mech.data,
                                                data->mech_oid.len);
                client_name = rctxh.src_name.display_name;
        }
index f0f78c5f1c7d9690bc017db01ddf697d3022a81a..1ec19f6f0c2b9fe71ee9a7110873873274b9ab62 100644 (file)
@@ -559,6 +559,8 @@ static int gssx_enc_cred(struct xdr_stream *xdr,
 
        /* cred->elements */
        err = dummy_enc_credel_array(xdr, &cred->elements);
+       if (err)
+               return err;
 
        /* cred->cred_handle_reference */
        err = gssx_enc_buffer(xdr, &cred->cred_handle_reference);
@@ -740,22 +742,20 @@ void gssx_enc_accept_sec_context(struct rpc_rqst *req,
                goto done;
 
        /* arg->context_handle */
-       if (arg->context_handle) {
+       if (arg->context_handle)
                err = gssx_enc_ctx(xdr, arg->context_handle);
-               if (err)
-                       goto done;
-       } else {
+       else
                err = gssx_enc_bool(xdr, 0);
-       }
+       if (err)
+               goto done;
 
        /* arg->cred_handle */
-       if (arg->cred_handle) {
+       if (arg->cred_handle)
                err = gssx_enc_cred(xdr, arg->cred_handle);
-               if (err)
-                       goto done;
-       } else {
+       else
                err = gssx_enc_bool(xdr, 0);
-       }
+       if (err)
+               goto done;
 
        /* arg->input_token */
        err = gssx_enc_in_token(xdr, &arg->input_token);
@@ -763,13 +763,12 @@ void gssx_enc_accept_sec_context(struct rpc_rqst *req,
                goto done;
 
        /* arg->input_cb */
-       if (arg->input_cb) {
+       if (arg->input_cb)
                err = gssx_enc_cb(xdr, arg->input_cb);
-               if (err)
-                       goto done;
-       } else {
+       else
                err = gssx_enc_bool(xdr, 0);
-       }
+       if (err)
+               goto done;
 
        err = gssx_enc_bool(xdr, arg->ret_deleg_cred);
        if (err)
index 09fb638bcaa42ea88ff1bc7a6d34b6605f34a0c7..008cdade5aae387db601607c463aa20291777513 100644 (file)
@@ -1167,8 +1167,8 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
        if (!ud->found_creds) {
                /* userspace seem buggy, we should always get at least a
                 * mapping to nobody */
-               dprintk("RPC:       No creds found, marking Negative!\n");
-               set_bit(CACHE_NEGATIVE, &rsci.h.flags);
+               dprintk("RPC:       No creds found!\n");
+               goto out;
        } else {
 
                /* steal creds */
index dab09dac8fc7ba08ed6ec1312eb840ef5d7bc5c0..f09b7db2c492f5a3f20a954e07e23b1a2f054c5e 100644 (file)
@@ -750,14 +750,16 @@ EXPORT_SYMBOL_GPL(rpc_shutdown_client);
 /*
  * Free an RPC client
  */
-static void
+static struct rpc_clnt *
 rpc_free_client(struct rpc_clnt *clnt)
 {
+       struct rpc_clnt *parent = NULL;
+
        dprintk_rcu("RPC:       destroying %s client for %s\n",
                        clnt->cl_program->name,
                        rcu_dereference(clnt->cl_xprt)->servername);
        if (clnt->cl_parent != clnt)
-               rpc_release_client(clnt->cl_parent);
+               parent = clnt->cl_parent;
        rpc_clnt_remove_pipedir(clnt);
        rpc_unregister_client(clnt);
        rpc_free_iostats(clnt->cl_metrics);
@@ -766,18 +768,17 @@ rpc_free_client(struct rpc_clnt *clnt)
        rpciod_down();
        rpc_free_clid(clnt);
        kfree(clnt);
+       return parent;
 }
 
 /*
  * Free an RPC client
  */
-static void
+static struct rpc_clnt * 
 rpc_free_auth(struct rpc_clnt *clnt)
 {
-       if (clnt->cl_auth == NULL) {
-               rpc_free_client(clnt);
-               return;
-       }
+       if (clnt->cl_auth == NULL)
+               return rpc_free_client(clnt);
 
        /*
         * Note: RPCSEC_GSS may need to send NULL RPC calls in order to
@@ -788,7 +789,8 @@ rpc_free_auth(struct rpc_clnt *clnt)
        rpcauth_release(clnt->cl_auth);
        clnt->cl_auth = NULL;
        if (atomic_dec_and_test(&clnt->cl_count))
-               rpc_free_client(clnt);
+               return rpc_free_client(clnt);
+       return NULL;
 }
 
 /*
@@ -799,10 +801,13 @@ rpc_release_client(struct rpc_clnt *clnt)
 {
        dprintk("RPC:       rpc_release_client(%p)\n", clnt);
 
-       if (list_empty(&clnt->cl_tasks))
-               wake_up(&destroy_wait);
-       if (atomic_dec_and_test(&clnt->cl_count))
-               rpc_free_auth(clnt);
+       do {
+               if (list_empty(&clnt->cl_tasks))
+                       wake_up(&destroy_wait);
+               if (!atomic_dec_and_test(&clnt->cl_count))
+                       break;
+               clnt = rpc_free_auth(clnt);
+       } while (clnt != NULL);
 }
 EXPORT_SYMBOL_GPL(rpc_release_client);
 
index b974571126fe90fce45ff6edc522366c463d5d8d..e7fbe368b4a38f665c538ae98b3c8db1ce2a5b81 100644 (file)
@@ -1104,8 +1104,6 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
        rqstp->rq_vers = vers = svc_getnl(argv);        /* version number */
        rqstp->rq_proc = proc = svc_getnl(argv);        /* procedure number */
 
-       progp = serv->sv_program;
-
        for (progp = serv->sv_program; progp; progp = progp->pg_next)
                if (prog == progp->pg_prog)
                        break;
index 17c88928b7db0abe001697867ead944bf6621712..dd9d295813cff2a8738946a3309fc31dcf57ebf0 100644 (file)
@@ -393,8 +393,10 @@ static int xs_send_kvec(struct socket *sock, struct sockaddr *addr, int addrlen,
        return kernel_sendmsg(sock, &msg, NULL, 0, 0);
 }
 
-static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned int base, int more)
+static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned int base, int more, bool zerocopy)
 {
+       ssize_t (*do_sendpage)(struct socket *sock, struct page *page,
+                       int offset, size_t size, int flags);
        struct page **ppage;
        unsigned int remainder;
        int err, sent = 0;
@@ -403,6 +405,9 @@ static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned i
        base += xdr->page_base;
        ppage = xdr->pages + (base >> PAGE_SHIFT);
        base &= ~PAGE_MASK;
+       do_sendpage = sock->ops->sendpage;
+       if (!zerocopy)
+               do_sendpage = sock_no_sendpage;
        for(;;) {
                unsigned int len = min_t(unsigned int, PAGE_SIZE - base, remainder);
                int flags = XS_SENDMSG_FLAGS;
@@ -410,7 +415,7 @@ static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned i
                remainder -= len;
                if (remainder != 0 || more)
                        flags |= MSG_MORE;
-               err = sock->ops->sendpage(sock, *ppage, base, len, flags);
+               err = do_sendpage(sock, *ppage, base, len, flags);
                if (remainder == 0 || err != len)
                        break;
                sent += err;
@@ -431,9 +436,10 @@ static int xs_send_pagedata(struct socket *sock, struct xdr_buf *xdr, unsigned i
  * @addrlen: UDP only -- length of destination address
  * @xdr: buffer containing this request
  * @base: starting position in the buffer
+ * @zerocopy: true if it is safe to use sendpage()
  *
  */
-static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base)
+static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen, struct xdr_buf *xdr, unsigned int base, bool zerocopy)
 {
        unsigned int remainder = xdr->len - base;
        int err, sent = 0;
@@ -461,7 +467,7 @@ static int xs_sendpages(struct socket *sock, struct sockaddr *addr, int addrlen,
        if (base < xdr->page_len) {
                unsigned int len = xdr->page_len - base;
                remainder -= len;
-               err = xs_send_pagedata(sock, xdr, base, remainder != 0);
+               err = xs_send_pagedata(sock, xdr, base, remainder != 0, zerocopy);
                if (remainder == 0 || err != len)
                        goto out;
                sent += err;
@@ -564,7 +570,7 @@ static int xs_local_send_request(struct rpc_task *task)
                        req->rq_svec->iov_base, req->rq_svec->iov_len);
 
        status = xs_sendpages(transport->sock, NULL, 0,
-                                               xdr, req->rq_bytes_sent);
+                                               xdr, req->rq_bytes_sent, true);
        dprintk("RPC:       %s(%u) = %d\n",
                        __func__, xdr->len - req->rq_bytes_sent, status);
        if (likely(status >= 0)) {
@@ -620,7 +626,7 @@ static int xs_udp_send_request(struct rpc_task *task)
        status = xs_sendpages(transport->sock,
                              xs_addr(xprt),
                              xprt->addrlen, xdr,
-                             req->rq_bytes_sent);
+                             req->rq_bytes_sent, true);
 
        dprintk("RPC:       xs_udp_send_request(%u) = %d\n",
                        xdr->len - req->rq_bytes_sent, status);
@@ -693,6 +699,7 @@ static int xs_tcp_send_request(struct rpc_task *task)
        struct rpc_xprt *xprt = req->rq_xprt;
        struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
        struct xdr_buf *xdr = &req->rq_snd_buf;
+       bool zerocopy = true;
        int status;
 
        xs_encode_stream_record_marker(&req->rq_snd_buf);
@@ -700,13 +707,20 @@ static int xs_tcp_send_request(struct rpc_task *task)
        xs_pktdump("packet data:",
                                req->rq_svec->iov_base,
                                req->rq_svec->iov_len);
+       /* Don't use zero copy if this is a resend. If the RPC call
+        * completes while the socket holds a reference to the pages,
+        * then we may end up resending corrupted data.
+        */
+       if (task->tk_flags & RPC_TASK_SENT)
+               zerocopy = false;
 
        /* Continue transmitting the packet/record. We must be careful
         * to cope with writespace callbacks arriving _after_ we have
         * called sendmsg(). */
        while (1) {
                status = xs_sendpages(transport->sock,
-                                       NULL, 0, xdr, req->rq_bytes_sent);
+                                       NULL, 0, xdr, req->rq_bytes_sent,
+                                       zerocopy);
 
                dprintk("RPC:       xs_tcp_send_request(%u) = %d\n",
                                xdr->len - req->rq_bytes_sent, status);
index cf465d66ccdec9506bab01cb7390fcd169b50dfc..69cd9bf3f561d64d377ddb65091b98e1017e15cf 100644 (file)
@@ -2358,7 +2358,8 @@ int tipc_link_recv_fragment(struct sk_buff **head, struct sk_buff **tail,
                *head = frag;
                skb_frag_list_init(*head);
                return 0;
-       } else if (skb_try_coalesce(*head, frag, &headstolen, &delta)) {
+       } else if (*head &&
+                  skb_try_coalesce(*head, frag, &headstolen, &delta)) {
                kfree_skb_partial(frag, headstolen);
        } else {
                if (!*head)
index 8bcd4985d0fb341f795346f06c55d1f059c4c643..9f72a6376362e613cb87185acbb3581174c45592 100644 (file)
@@ -76,9 +76,11 @@ static struct genl_family tipc_genl_family = {
        .maxattr        = 0,
 };
 
-static struct genl_ops tipc_genl_ops = {
-       .cmd            = TIPC_GENL_CMD,
-       .doit           = handle_cmd,
+static struct genl_ops tipc_genl_ops[] = {
+       {
+               .cmd            = TIPC_GENL_CMD,
+               .doit           = handle_cmd,
+       },
 };
 
 static int tipc_genl_family_registered;
@@ -87,8 +89,7 @@ int tipc_netlink_start(void)
 {
        int res;
 
-       res = genl_register_family_with_ops(&tipc_genl_family,
-               &tipc_genl_ops, 1);
+       res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops);
        if (res) {
                pr_err("Failed to register netlink interface\n");
                return res;
index b5fa7e40cdcbce54fb0c1cb8cce5502e17b0f3c1..14810abedc2ec455adbde24094a5c468477e03d8 100644 (file)
@@ -6,7 +6,7 @@ config VSOCKETS
        tristate "Virtual Socket protocol"
        help
          Virtual Socket Protocol is a socket protocol similar to TCP/IP
-         allowing comunication between Virtual Machines and hypervisor
+         allowing communication between Virtual Machines and hypervisor
          or host.
 
          You should also select one or more hypervisor-specific transports
index 0694d62e4dbc1b03f2b075269e23957c28ce85a2..c278b3356f75fe2de50b99b9e7e71609eb25a8df 100644 (file)
@@ -279,7 +279,7 @@ int wimax_msg_send(struct wimax_dev *wimax_dev, struct sk_buff *skb)
 
        d_printf(1, dev, "CTX: wimax msg, %zu bytes\n", size);
        d_dump(2, dev, msg, size);
-       genlmsg_multicast(skb, 0, wimax_gnl_mcg.id, GFP_KERNEL);
+       genlmsg_multicast(&wimax_gnl_family, skb, 0, 0, GFP_KERNEL);
        d_printf(1, dev, "CTX: genl multicast done\n");
        return 0;
 }
@@ -321,17 +321,6 @@ int wimax_msg(struct wimax_dev *wimax_dev, const char *pipe_name,
 }
 EXPORT_SYMBOL_GPL(wimax_msg);
 
-
-static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
-       [WIMAX_GNL_MSG_IFIDX] = {
-               .type = NLA_U32,
-       },
-       [WIMAX_GNL_MSG_DATA] = {
-               .type = NLA_UNSPEC,     /* libnl doesn't grok BINARY yet */
-       },
-};
-
-
 /*
  * Relays a message from user space to the driver
  *
@@ -340,7 +329,6 @@ static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
  *
  * This call will block while handling/relaying the message.
  */
-static
 int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
 {
        int result, ifindex;
@@ -418,16 +406,3 @@ error_no_wimax_dev:
        return result;
 }
 
-
-/*
- * Generic Netlink glue
- */
-
-struct genl_ops wimax_gnl_msg_from_user = {
-       .cmd = WIMAX_GNL_OP_MSG_FROM_USER,
-       .flags = GENL_ADMIN_PERM,
-       .policy = wimax_gnl_msg_policy,
-       .doit = wimax_gnl_doit_msg_from_user,
-       .dumpit = NULL,
-};
-
index 7ceffe39d70e4bb69b046b2de1e604834412abb5..eb4580784d9dc5abdcaf5be27b24578ed6b0ca0e 100644 (file)
@@ -92,13 +92,6 @@ int wimax_reset(struct wimax_dev *wimax_dev)
 EXPORT_SYMBOL(wimax_reset);
 
 
-static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] = {
-       [WIMAX_GNL_RESET_IFIDX] = {
-               .type = NLA_U32,
-       },
-};
-
-
 /*
  * Exporting to user space over generic netlink
  *
@@ -106,7 +99,6 @@ static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] =
  *
  * No attributes.
  */
-static
 int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
 {
        int result, ifindex;
@@ -130,12 +122,3 @@ error_no_wimax_dev:
        d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
        return result;
 }
-
-
-struct genl_ops wimax_gnl_reset = {
-       .cmd = WIMAX_GNL_OP_RESET,
-       .flags = GENL_ADMIN_PERM,
-       .policy = wimax_gnl_reset_policy,
-       .doit = wimax_gnl_doit_reset,
-       .dumpit = NULL,
-};
index 7ab60babdd22a32bd44bd28afc80972e4311084c..403078d670a909cb20b4660e1a33965fd996bb52 100644 (file)
@@ -411,17 +411,6 @@ void wimax_rfkill_rm(struct wimax_dev *wimax_dev)
  * just query).
  */
 
-static const struct nla_policy wimax_gnl_rfkill_policy[WIMAX_GNL_ATTR_MAX + 1] = {
-       [WIMAX_GNL_RFKILL_IFIDX] = {
-               .type = NLA_U32,
-       },
-       [WIMAX_GNL_RFKILL_STATE] = {
-               .type = NLA_U32         /* enum wimax_rf_state */
-       },
-};
-
-
-static
 int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
 {
        int result, ifindex;
@@ -457,13 +446,3 @@ error_no_wimax_dev:
        d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
        return result;
 }
-
-
-struct genl_ops wimax_gnl_rfkill = {
-       .cmd = WIMAX_GNL_OP_RFKILL,
-       .flags = GENL_ADMIN_PERM,
-       .policy = wimax_gnl_rfkill_policy,
-       .doit = wimax_gnl_doit_rfkill,
-       .dumpit = NULL,
-};
-
index aff8776e2d41a5d4020bdd5f8c937830e6e214a6..995c08c827b512bf4a9e6650f77ac834015e60fe 100644 (file)
 #include "debug-levels.h"
 
 
-static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1] = {
-       [WIMAX_GNL_STGET_IFIDX] = {
-               .type = NLA_U32,
-       },
-};
-
-
 /*
  * Exporting to user space over generic netlink
  *
@@ -48,7 +41,6 @@ static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1
  *
  * No attributes.
  */
-static
 int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
 {
        int result, ifindex;
@@ -72,12 +64,3 @@ error_no_wimax_dev:
        d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
        return result;
 }
-
-
-struct genl_ops wimax_gnl_state_get = {
-       .cmd = WIMAX_GNL_OP_STATE_GET,
-       .flags = GENL_ADMIN_PERM,
-       .policy = wimax_gnl_state_get_policy,
-       .doit = wimax_gnl_doit_state_get,
-       .dumpit = NULL,
-};
index a6470ac39498e807a5d760e96b95bbc6b748129d..ef2191b969a7aa6967f2a3f7855e5b20cfef5cfc 100644 (file)
@@ -116,8 +116,9 @@ struct sk_buff *wimax_gnl_re_state_change_alloc(
                dev_err(dev, "RE_STCH: can't create message\n");
                goto error_new;
        }
-       data = genlmsg_put(report_skb, 0, wimax_gnl_mcg.id, &wimax_gnl_family,
-                          0, WIMAX_GNL_RE_STATE_CHANGE);
+       /* FIXME: sending a group ID as the seq is wrong */
+       data = genlmsg_put(report_skb, 0, wimax_gnl_family.mcgrp_offset,
+                          &wimax_gnl_family, 0, WIMAX_GNL_RE_STATE_CHANGE);
        if (data == NULL) {
                dev_err(dev, "RE_STCH: can't put data into message\n");
                goto error_put;
@@ -177,7 +178,7 @@ int wimax_gnl_re_state_change_send(
                goto out;
        }
        genlmsg_end(report_skb, header);
-       genlmsg_multicast(report_skb, 0, wimax_gnl_mcg.id, GFP_KERNEL);
+       genlmsg_multicast(&wimax_gnl_family, report_skb, 0, 0, GFP_KERNEL);
 out:
        d_fnend(3, dev, "(wimax_dev %p report_skb %p) = %d\n",
                wimax_dev, report_skb, result);
@@ -402,22 +403,44 @@ void wimax_dev_init(struct wimax_dev *wimax_dev)
 }
 EXPORT_SYMBOL_GPL(wimax_dev_init);
 
-/*
- * This extern is declared here because it's easier to keep track --
- * both declarations are a list of the same
- */
-extern struct genl_ops
-       wimax_gnl_msg_from_user,
-       wimax_gnl_reset,
-       wimax_gnl_rfkill,
-       wimax_gnl_state_get;
+static const struct nla_policy wimax_gnl_policy[WIMAX_GNL_ATTR_MAX + 1] = {
+       [WIMAX_GNL_RESET_IFIDX] = { .type = NLA_U32, },
+       [WIMAX_GNL_RFKILL_IFIDX] = { .type = NLA_U32, },
+       [WIMAX_GNL_RFKILL_STATE] = {
+               .type = NLA_U32         /* enum wimax_rf_state */
+       },
+       [WIMAX_GNL_STGET_IFIDX] = { .type = NLA_U32, },
+       [WIMAX_GNL_MSG_IFIDX] = { .type = NLA_U32, },
+       [WIMAX_GNL_MSG_DATA] = {
+               .type = NLA_UNSPEC,     /* libnl doesn't grok BINARY yet */
+       },
+};
 
-static
-struct genl_ops *wimax_gnl_ops[] = {
-       &wimax_gnl_msg_from_user,
-       &wimax_gnl_reset,
-       &wimax_gnl_rfkill,
-       &wimax_gnl_state_get,
+static const struct genl_ops wimax_gnl_ops[] = {
+       {
+               .cmd = WIMAX_GNL_OP_MSG_FROM_USER,
+               .flags = GENL_ADMIN_PERM,
+               .policy = wimax_gnl_policy,
+               .doit = wimax_gnl_doit_msg_from_user,
+       },
+       {
+               .cmd = WIMAX_GNL_OP_RESET,
+               .flags = GENL_ADMIN_PERM,
+               .policy = wimax_gnl_policy,
+               .doit = wimax_gnl_doit_reset,
+       },
+       {
+               .cmd = WIMAX_GNL_OP_RFKILL,
+               .flags = GENL_ADMIN_PERM,
+               .policy = wimax_gnl_policy,
+               .doit = wimax_gnl_doit_rfkill,
+       },
+       {
+               .cmd = WIMAX_GNL_OP_STATE_GET,
+               .flags = GENL_ADMIN_PERM,
+               .policy = wimax_gnl_policy,
+               .doit = wimax_gnl_doit_state_get,
+       },
 };
 
 
@@ -557,8 +580,8 @@ struct genl_family wimax_gnl_family = {
        .maxattr = WIMAX_GNL_ATTR_MAX,
 };
 
-struct genl_multicast_group wimax_gnl_mcg = {
-       .name = "msg",
+static const struct genl_multicast_group wimax_gnl_mcgrps[] = {
+       { .name = "msg", },
 };
 
 
@@ -567,7 +590,7 @@ struct genl_multicast_group wimax_gnl_mcg = {
 static
 int __init wimax_subsys_init(void)
 {
-       int result, cnt;
+       int result;
 
        d_fnstart(4, NULL, "()\n");
        d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params,
@@ -575,37 +598,18 @@ int __init wimax_subsys_init(void)
 
        snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
                 "WiMAX");
-       result = genl_register_family(&wimax_gnl_family);
+       result = genl_register_family_with_ops_groups(&wimax_gnl_family,
+                                                     wimax_gnl_ops,
+                                                     wimax_gnl_mcgrps);
        if (unlikely(result < 0)) {
                printk(KERN_ERR "cannot register generic netlink family: %d\n",
                       result);
                goto error_register_family;
        }
 
-       for (cnt = 0; cnt < ARRAY_SIZE(wimax_gnl_ops); cnt++) {
-               result = genl_register_ops(&wimax_gnl_family,
-                                          wimax_gnl_ops[cnt]);
-               d_printf(4, NULL, "registering generic netlink op code "
-                        "%u: %d\n", wimax_gnl_ops[cnt]->cmd, result);
-               if (unlikely(result < 0)) {
-                       printk(KERN_ERR "cannot register generic netlink op "
-                              "code %u: %d\n",
-                              wimax_gnl_ops[cnt]->cmd, result);
-                       goto error_register_ops;
-               }
-       }
-
-       result = genl_register_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
-       if (result < 0)
-               goto error_mc_group;
        d_fnend(4, NULL, "() = 0\n");
        return 0;
 
-error_mc_group:
-error_register_ops:
-       for (cnt--; cnt >= 0; cnt--)
-               genl_unregister_ops(&wimax_gnl_family,
-                                   wimax_gnl_ops[cnt]);
        genl_unregister_family(&wimax_gnl_family);
 error_register_family:
        d_fnend(4, NULL, "() = %d\n", result);
@@ -619,12 +623,7 @@ module_init(wimax_subsys_init);
 static
 void __exit wimax_subsys_exit(void)
 {
-       int cnt;
        wimax_id_table_release();
-       genl_unregister_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
-       for (cnt = ARRAY_SIZE(wimax_gnl_ops) - 1; cnt >= 0; cnt--)
-               genl_unregister_ops(&wimax_gnl_family,
-                                   wimax_gnl_ops[cnt]);
        genl_unregister_family(&wimax_gnl_family);
 }
 module_exit(wimax_subsys_exit);
index 5dcd9c067bf0ac72a3c6e1067818053e31f7b748..b445b82020a83143aee4e9e89815dc921fdb4759 100644 (file)
@@ -84,8 +84,14 @@ void wimax_id_table_release(void);
 int wimax_rfkill_add(struct wimax_dev *);
 void wimax_rfkill_rm(struct wimax_dev *);
 
+/* generic netlink */
 extern struct genl_family wimax_gnl_family;
-extern struct genl_multicast_group wimax_gnl_mcg;
+
+/* ops */
+int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info);
+int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info);
+int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info);
+int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info);
 
 #endif /* #ifdef __KERNEL__ */
 #endif /* #ifndef __WIMAX_INTERNAL_H__ */
index a7f4e7902104907adf86c9fffcfc0ab956d36095..a1eb21073176115a587f9eb1edf5d36dba582484 100644 (file)
@@ -30,9 +30,9 @@ static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
                                   struct cfg80211_crypto_settings *settings,
                                   int cipher_limit);
 
-static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
+static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
                            struct genl_info *info);
-static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
+static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
                              struct genl_info *info);
 
 /* the netlink family */
@@ -47,6 +47,25 @@ static struct genl_family nl80211_fam = {
        .post_doit = nl80211_post_doit,
 };
 
+/* multicast groups */
+enum nl80211_multicast_groups {
+       NL80211_MCGRP_CONFIG,
+       NL80211_MCGRP_SCAN,
+       NL80211_MCGRP_REGULATORY,
+       NL80211_MCGRP_MLME,
+       NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
+};
+
+static const struct genl_multicast_group nl80211_mcgrps[] = {
+       [NL80211_MCGRP_CONFIG] = { .name = "config", },
+       [NL80211_MCGRP_SCAN] = { .name = "scan", },
+       [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
+       [NL80211_MCGRP_MLME] = { .name = "mlme", },
+#ifdef CONFIG_NL80211_TESTMODE
+       [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
+#endif
+};
+
 /* returns ERR_PTR values */
 static struct wireless_dev *
 __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
@@ -6656,10 +6675,6 @@ static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
 
 
 #ifdef CONFIG_NL80211_TESTMODE
-static struct genl_multicast_group nl80211_testmode_mcgrp = {
-       .name = "testmode",
-};
-
 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev = info->user_ptr[0];
@@ -6868,8 +6883,8 @@ void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
 
        nla_nest_end(skb, data);
        genlmsg_end(skb, hdr);
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
-                               nl80211_testmode_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
+                               NL80211_MCGRP_TESTMODE, gfp);
 }
 EXPORT_SYMBOL(cfg80211_testmode_event);
 #endif
@@ -8851,7 +8866,7 @@ static int nl80211_crit_protocol_stop(struct sk_buff *skb,
 #define NL80211_FLAG_NEED_WDEV_UP      (NL80211_FLAG_NEED_WDEV |\
                                         NL80211_FLAG_CHECK_NETDEV_UP)
 
-static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
+static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
                            struct genl_info *info)
 {
        struct cfg80211_registered_device *rdev;
@@ -8920,7 +8935,7 @@ static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
        return 0;
 }
 
-static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
+static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
                              struct genl_info *info)
 {
        if (info->user_ptr[1]) {
@@ -8937,7 +8952,7 @@ static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
                rtnl_unlock();
 }
 
-static struct genl_ops nl80211_ops[] = {
+static const struct genl_ops nl80211_ops[] = {
        {
                .cmd = NL80211_CMD_GET_WIPHY,
                .doit = nl80211_get_wiphy,
@@ -9566,21 +9581,6 @@ static struct genl_ops nl80211_ops[] = {
        },
 };
 
-static struct genl_multicast_group nl80211_mlme_mcgrp = {
-       .name = "mlme",
-};
-
-/* multicast groups */
-static struct genl_multicast_group nl80211_config_mcgrp = {
-       .name = "config",
-};
-static struct genl_multicast_group nl80211_scan_mcgrp = {
-       .name = "scan",
-};
-static struct genl_multicast_group nl80211_regulatory_mcgrp = {
-       .name = "regulatory",
-};
-
 /* notification functions */
 
 void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
@@ -9597,8 +9597,8 @@ void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_config_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_CONFIG, GFP_KERNEL);
 }
 
 static int nl80211_add_scan_req(struct sk_buff *msg,
@@ -9707,8 +9707,8 @@ void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_scan_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_SCAN, GFP_KERNEL);
 }
 
 void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
@@ -9726,8 +9726,8 @@ void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_scan_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_SCAN, GFP_KERNEL);
 }
 
 void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
@@ -9745,8 +9745,8 @@ void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_scan_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_SCAN, GFP_KERNEL);
 }
 
 void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
@@ -9764,8 +9764,8 @@ void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_scan_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_SCAN, GFP_KERNEL);
 }
 
 void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
@@ -9782,8 +9782,8 @@ void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_scan_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_SCAN, GFP_KERNEL);
 }
 
 /*
@@ -9837,8 +9837,8 @@ void nl80211_send_reg_change_event(struct regulatory_request *request)
        genlmsg_end(msg, hdr);
 
        rcu_read_lock();
-       genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
-                               GFP_ATOMIC);
+       genlmsg_multicast_allns(&nl80211_fam, msg, 0,
+                               NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
        rcu_read_unlock();
 
        return;
@@ -9873,8 +9873,8 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -9961,8 +9961,8 @@ static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10017,8 +10017,8 @@ void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10056,8 +10056,8 @@ void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10094,8 +10094,8 @@ void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, GFP_KERNEL);
        return;
 
  nla_put_failure:
@@ -10128,8 +10128,8 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10169,8 +10169,8 @@ void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10208,8 +10208,8 @@ void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10261,8 +10261,8 @@ void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
        genlmsg_end(msg, hdr);
 
        rcu_read_lock();
-       genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
-                               GFP_ATOMIC);
+       genlmsg_multicast_allns(&nl80211_fam, msg, 0,
+                               NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
        rcu_read_unlock();
 
        return;
@@ -10307,8 +10307,8 @@ static void nl80211_send_remain_on_chan_event(
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10362,8 +10362,8 @@ void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
                return;
        }
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
 }
 EXPORT_SYMBOL(cfg80211_new_sta);
 
@@ -10392,8 +10392,8 @@ void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10428,8 +10428,8 @@ void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10590,8 +10590,8 @@ void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10639,8 +10639,8 @@ void cfg80211_cqm_rssi_notify(struct net_device *dev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10684,8 +10684,8 @@ static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10742,8 +10742,8 @@ nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10789,8 +10789,8 @@ static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10866,8 +10866,8 @@ void cfg80211_cqm_txe_notify(struct net_device *dev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10915,8 +10915,8 @@ nl80211_radar_notify(struct cfg80211_registered_device *rdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -10962,8 +10962,8 @@ void cfg80211_cqm_pktloss_notify(struct net_device *dev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -11002,8 +11002,8 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -11154,8 +11154,8 @@ void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  free_msg:
@@ -11196,8 +11196,8 @@ void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, gfp);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, gfp);
        return;
 
  nla_put_failure:
@@ -11279,8 +11279,8 @@ void cfg80211_ft_event(struct net_device *netdev,
 
        genlmsg_end(msg, hdr);
 
-       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
-                               nl80211_mlme_mcgrp.id, GFP_KERNEL);
+       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
+                               NL80211_MCGRP_MLME, GFP_KERNEL);
 }
 EXPORT_SYMBOL(cfg80211_ft_event);
 
@@ -11329,33 +11329,11 @@ int nl80211_init(void)
 {
        int err;
 
-       err = genl_register_family_with_ops(&nl80211_fam,
-               nl80211_ops, ARRAY_SIZE(nl80211_ops));
+       err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
+                                                  nl80211_mcgrps);
        if (err)
                return err;
 
-       err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
-       if (err)
-               goto err_out;
-
-       err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
-       if (err)
-               goto err_out;
-
-       err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
-       if (err)
-               goto err_out;
-
-       err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
-       if (err)
-               goto err_out;
-
-#ifdef CONFIG_NL80211_TESTMODE
-       err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
-       if (err)
-               goto err_out;
-#endif
-
        err = netlink_register_notifier(&nl80211_netlink_notifier);
        if (err)
                goto err_out;
index 6129020c41a94570ff49f5e42b5963a23105ba8e..549d0ab8c66204ec8db65de3d48ce619f7dee925 100755 (executable)
@@ -19,9 +19,10 @@ def getsizes(file):
         size, type, name = l[:-1].split()
         if type in "tTdDbBrR":
             # strip generated symbols
-            if name[:6] == "__mod_": continue
-            # function names begin with '.' on 64-bit powerpc
-            if "." in name[1:]: name = "static." + name.split(".")[0]
+            if name.startswith("__mod_"): continue
+            if name == "linux_banner": continue
+            # statics and some other optimizations adds random .NUMBER
+            name = re.sub(r'\.[0-9]+', '', name)
             sym[name] = sym.get(name, 0) + int(size, 16)
     return sym
 
diff --git a/scripts/coccinelle/api/devm_request_and_ioremap.cocci b/scripts/coccinelle/api/devm_request_and_ioremap.cocci
deleted file mode 100644 (file)
index 562ec88..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/// Reimplement a call to devm_request_mem_region followed by a call to ioremap
-/// or ioremap_nocache by a call to devm_request_and_ioremap.
-/// Devm_request_and_ioremap was introduced in
-/// 72f8c0bfa0de64c68ee59f40eb9b2683bffffbb0.  It makes the code much more
-/// concise.
-///
-///
-// Confidence: High
-// Copyright: (C) 2011 Julia Lawall, INRIA/LIP6.  GPLv2.
-// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6.  GPLv2.
-// URL: http://coccinelle.lip6.fr/
-// Comments:
-// Options: --no-includes --include-headers
-
-virtual patch
-virtual org
-virtual report
-virtual context
-
-@nm@
-expression myname;
-identifier i;
-@@
-
-struct platform_driver i = { .driver = { .name = myname } };
-
-@depends on patch@
-expression dev,res,size;
-@@
-
--if (!devm_request_mem_region(dev, res->start, size,
--                              \(res->name\|dev_name(dev)\))) {
--   ...
--   return ...;
--}
-... when != res->start
-(
--devm_ioremap(dev,res->start,size)
-+devm_request_and_ioremap(dev,res)
-|
--devm_ioremap_nocache(dev,res->start,size)
-+devm_request_and_ioremap(dev,res)
-)
-... when any
-    when != res->start
-
-// this rule is separate from the previous one, because a single file can
-// have multiple values of myname
-@depends on patch@
-expression dev,res,size;
-expression nm.myname;
-@@
-
--if (!devm_request_mem_region(dev, res->start, size,myname)) {
--   ...
--   return ...;
--}
-... when != res->start
-(
--devm_ioremap(dev,res->start,size)
-+devm_request_and_ioremap(dev,res)
-|
--devm_ioremap_nocache(dev,res->start,size)
-+devm_request_and_ioremap(dev,res)
-)
-... when any
-    when != res->start
-
-
-@pb depends on org || report || context@
-expression dev,res,size;
-expression nm.myname;
-position p1,p2;
-@@
-
-*if
-  (!devm_request_mem_region@p1(dev, res->start, size,
-                              \(res->name\|dev_name(dev)\|myname\))) {
-   ...
-   return ...;
-}
-... when != res->start
-(
-*devm_ioremap@p2(dev,res->start,size)
-|
-*devm_ioremap_nocache@p2(dev,res->start,size)
-)
-... when any
-    when != res->start
-
-@script:python depends on org@
-p1 << pb.p1;
-p2 << pb.p2;
-@@
-
-cocci.print_main("INFO: replace by devm_request_and_ioremap",p1)
-cocci.print_secs("",p2)
-
-@script:python depends on report@
-p1 << pb.p1;
-p2 << pb.p2;
-@@
-
-msg = "INFO: devm_request_mem_region followed by ioremap on line %s can be replaced by devm_request_and_ioremap" % (p2[0].line)
-coccilib.report.print_report(p1[0],msg)
index 9a11f9f799f499f2d34d1dea3dec48feb36db00f..10085de886fef49b78a12746a2e0a593545d56e0 100644 (file)
@@ -115,6 +115,12 @@ static int read_symbol(FILE *in, struct sym_entry *s)
                        fprintf(stderr, "Read error or end of file.\n");
                return -1;
        }
+       if (strlen(str) > KSYM_NAME_LEN) {
+               fprintf(stderr, "Symbol %s too long for kallsyms (%zu vs %d).\n"
+                                "Please increase KSYM_NAME_LEN both in kernel and kallsyms.c\n",
+                       str, strlen(str), KSYM_NAME_LEN);
+               return -1;
+       }
 
        sym = str;
        /* skip prefix char */
index df198a5f482217781e7d4a605962bf443881ce7b..ba663e1dc7e35b7bf732c4863c1202e3249ac636 100644 (file)
@@ -93,7 +93,7 @@ struct symbol {
 #define SYMBOL_CHOICEVAL  0x0020  /* used as a value in a choice block */
 #define SYMBOL_VALID      0x0080  /* set when symbol.curr is calculated */
 #define SYMBOL_OPTIONAL   0x0100  /* choice is optional - values can be 'n' */
-#define SYMBOL_WRITE      0x0200  /* ? */
+#define SYMBOL_WRITE      0x0200  /* write symbol to file (KCONFIG_CONFIG) */
 #define SYMBOL_CHANGED    0x0400  /* ? */
 #define SYMBOL_AUTO       0x1000  /* value from environment variable */
 #define SYMBOL_CHECKED    0x2000  /* used during dependency checking */
index 2c3963165a0d83f45b2d180361e12e4542588302..59184bb41ef81054384bcd641097f95e9e5426a2 100644 (file)
@@ -25,7 +25,7 @@
 static const char mconf_readme[] = N_(
 "Overview\n"
 "--------\n"
-"This interface let you select features and parameters for the build.\n"
+"This interface lets you select features and parameters for the build.\n"
 "Features can either be built-in, modularized, or ignored. Parameters\n"
 "must be entered in as decimal or hexadecimal numbers or text.\n"
 "\n"
@@ -39,15 +39,15 @@ static const char mconf_readme[] = N_(
 "\n"
 "To change any of these features, highlight it with the cursor\n"
 "keys and press <Y> to build it in, <M> to make it a module or\n"
-"<N> to removed it.  You may also press the <Space Bar> to cycle\n"
-"through the available options (ie. Y->N->M->Y).\n"
+"<N> to remove it.  You may also press the <Space Bar> to cycle\n"
+"through the available options (i.e. Y->N->M->Y).\n"
 "\n"
 "Some additional keyboard hints:\n"
 "\n"
 "Menus\n"
 "----------\n"
-"o  Use the Up/Down arrow keys (cursor keys) to highlight the item\n"
-"   you wish to change or submenu wish to select and press <Enter>.\n"
+"o  Use the Up/Down arrow keys (cursor keys) to highlight the item you\n"
+"   wish to change or the submenu you wish to select and press <Enter>.\n"
 "   Submenus are designated by \"--->\", empty ones by \"----\".\n"
 "\n"
 "   Shortcut: Press the option's highlighted letter (hotkey).\n"
@@ -65,7 +65,7 @@ static const char mconf_readme[] = N_(
 "             there is a delayed response which you may find annoying.\n"
 "\n"
 "   Also, the <TAB> and cursor keys will cycle between <Select>,\n"
-"   <Exit> and <Help>.\n"
+"   <Exit>, <Help>, <Save>, and <Load>.\n"
 "\n"
 "o  To get help with an item, use the cursor keys to highlight <Help>\n"
 "   and press <ENTER>.\n"
@@ -105,7 +105,7 @@ static const char mconf_readme[] = N_(
 "Text Box    (Help Window)\n"
 "--------\n"
 "o  Use the cursor keys to scroll up/down/left/right.  The VI editor\n"
-"   keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for \n"
+"   keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for\n"
 "   those who are familiar with less and lynx.\n"
 "\n"
 "o  Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.\n"
@@ -117,23 +117,21 @@ static const char mconf_readme[] = N_(
 "those who, for various reasons, find it necessary to switch\n"
 "between different configurations.\n"
 "\n"
-"At the end of the main menu you will find two options.  One is\n"
-"for saving the current configuration to a file of your choosing.\n"
-"The other option is for loading a previously saved alternate\n"
-"configuration.\n"
+"The <Save> button will let you save the current configuration to\n"
+"a file of your choosing.  Use the <Load> button to load a previously\n"
+"saved alternate configuration.\n"
 "\n"
-"Even if you don't use alternate configuration files, but you\n"
-"find during a Menuconfig session that you have completely messed\n"
-"up your settings, you may use the \"Load Alternate...\" option to\n"
-"restore your previously saved settings from \".config\" without\n"
-"restarting Menuconfig.\n"
+"Even if you don't use alternate configuration files, but you find\n"
+"during a Menuconfig session that you have completely messed up your\n"
+"settings, you may use the <Load> button to restore your previously\n"
+"saved settings from \".config\" without restarting Menuconfig.\n"
 "\n"
 "Other information\n"
 "-----------------\n"
-"If you use Menuconfig in an XTERM window make sure you have your\n"
-"$TERM variable set to point to a xterm definition which supports color.\n"
-"Otherwise, Menuconfig will look rather bad.  Menuconfig will not\n"
-"display correctly in a RXVT window because rxvt displays only one\n"
+"If you use Menuconfig in an XTERM window, make sure you have your\n"
+"$TERM variable set to point to an xterm definition which supports\n"
+"color.  Otherwise, Menuconfig will look rather bad.  Menuconfig will\n"
+"not display correctly in an RXVT window because rxvt displays only one\n"
 "intensity of color, bright.\n"
 "\n"
 "Menuconfig will display larger menus on screens or xterms which are\n"
@@ -148,8 +146,8 @@ static const char mconf_readme[] = N_(
 "\n"
 "Optional personality available\n"
 "------------------------------\n"
-"If you prefer to have all of the options listed in a single menu, rather\n"
-"than the default multimenu hierarchy, run the menuconfig with\n"
+"If you prefer to have all of the options listed in a single menu,\n"
+"rather than the default multimenu hierarchy, run the menuconfig with\n"
 "MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
 "\n"
 "make MENUCONFIG_MODE=single_menu menuconfig\n"
@@ -172,7 +170,7 @@ static const char mconf_readme[] = N_(
 " mono       => selects colors suitable for monochrome displays\n"
 " blackbg    => selects a color scheme with black background\n"
 " classic    => theme with blue background. The classic look\n"
-" bluetitle  => a LCD friendly version of classic. (default)\n"
+" bluetitle  => an LCD friendly version of classic. (default)\n"
 "\n"),
 menu_instructions[] = N_(
        "Arrow keys navigate the menu.  "
@@ -238,24 +236,24 @@ search_help[] = N_(
        "Symbol: FOO [=m]\n"
        "Type  : tristate\n"
        "Prompt: Foo bus is used to drive the bar HW\n"
-       "  Defined at drivers/pci/Kconfig:47\n"
-       "  Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
        "  Location:\n"
        "    -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
        "      -> PCI support (PCI [=y])\n"
        "(1)     -> PCI access mode (<choice> [=y])\n"
+       "  Defined at drivers/pci/Kconfig:47\n"
+       "  Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
        "  Selects: LIBCRC32\n"
-       "  Selected by: BAR\n"
+       "  Selected by: BAR [=n]\n"
        "-----------------------------------------------------------------\n"
        "o The line 'Type:' shows the type of the configuration option for\n"
        "  this symbol (boolean, tristate, string, ...)\n"
        "o The line 'Prompt:' shows the text used in the menu structure for\n"
        "  this symbol\n"
-       "o The 'Defined at' line tell at what file / line number the symbol\n"
+       "o The 'Defined at' line tells at what file / line number the symbol\n"
        "  is defined\n"
-       "o The 'Depends on:' line tell what symbols needs to be defined for\n"
+       "o The 'Depends on:' line tells what symbols need to be defined for\n"
        "  this symbol to be visible in the menu (selectable)\n"
-       "o The 'Location:' lines tell where in the menu structure this symbol\n"
+       "o The 'Location:' lines tells where in the menu structure this symbol\n"
        "  is located\n"
        "    A location followed by a [=y] indicates that this is a\n"
        "    selectable menu item - and the current value is displayed inside\n"
@@ -263,9 +261,9 @@ search_help[] = N_(
        "    Press the key in the (#) prefix to jump directly to that\n"
        "    location. You will be returned to the current search results\n"
        "    after exiting this new menu.\n"
-       "o The 'Selects:' line tell what symbol will be automatically\n"
+       "o The 'Selects:' line tells what symbols will be automatically\n"
        "  selected if this symbol is selected (y or m)\n"
-       "o The 'Selected by' line tell what symbol has selected this symbol\n"
+       "o The 'Selected by' line tells what symbol has selected this symbol\n"
        "\n"
        "Only relevant lines are shown.\n"
        "\n\n"
index c1d53200c306dc6202cbcc13555a05333c34411a..db1512ae30cc48d6f2ea87bc26a082a084551811 100644 (file)
@@ -119,9 +119,10 @@ void menu_set_type(int type)
                sym->type = type;
                return;
        }
-       menu_warn(current_entry, "type of '%s' redefined from '%s' to '%s'",
-           sym->name ? sym->name : "<choice>",
-           sym_type_name(sym->type), sym_type_name(type));
+       menu_warn(current_entry,
+               "ignoring type redefinition of '%s' from '%s' to '%s'",
+               sym->name ? sym->name : "<choice>",
+               sym_type_name(sym->type), sym_type_name(type));
 }
 
 struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep)
@@ -583,7 +584,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
                for (j = 4; --i >= 0; j += 2) {
                        menu = submenu[i];
                        if (head && location && menu == location)
-                               jump->offset = r->len - 1;
+                               jump->offset = strlen(r->s);
                        str_printf(r, "%*c-> %s", j, ' ',
                                   _(menu_get_prompt(menu)));
                        if (menu->sym) {
@@ -597,7 +598,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
 }
 
 /*
- * get peoperty of type P_SYMBOL
+ * get property of type P_SYMBOL
  */
 static struct property *get_symbol_prop(struct symbol *sym)
 {
index 1500c38f0ccabf5908f7704f683759b0e754ebce..9d3b04b0769cbef51bfdcfcc75ac60cc2e1b67d1 100644 (file)
@@ -69,6 +69,11 @@ static inline QString qgettext(const QString& str)
        return QString::fromLocal8Bit(gettext(str.latin1()));
 }
 
+ConfigSettings::ConfigSettings()
+       : QSettings("kernel.org", "qconf")
+{
+}
+
 /**
  * Reads a list of integer values from the application settings.
  */
index 3715b3e7212c9adccdc25483e632487a64360b54..bde0c6b6f9e87dbeff3004413123f6d2cef0d42f 100644 (file)
@@ -32,6 +32,7 @@ class ConfigMainWindow;
 
 class ConfigSettings : public QSettings {
 public:
+       ConfigSettings();
        Q3ValueList<int> readSizes(const QString& key, bool *ok);
        bool writeSizes(const QString& key, const Q3ValueList<int>& value);
 };
index c9a6775565bfa13252138f81ef8a0312b11cfea8..7caabdb51c647e12e35b500bdebd262ba1545eb0 100644 (file)
@@ -1047,7 +1047,7 @@ sym_re_search_free:
  * When we check for recursive dependencies we use a stack to save
  * current state so we can print out relevant info to user.
  * The entries are located on the call stack so no need to free memory.
- * Note inser() remove() must always match to properly clear the stack.
+ * Note insert() remove() must always match to properly clear the stack.
  */
 static struct dep_stack {
        struct dep_stack *prev, *next;
index 6555a475453b882d2970c7ae4b16b5c4eb3286cf..1a9f53e535ca8ba87adc9b1af2bc761f128e56a0 100644 (file)
@@ -68,7 +68,6 @@ static void alloc_string(const char *str, int size)
 }
 %}
 
-ws     [ \n\t]
 n      [A-Za-z0-9_]
 
 %%
index dbd3e1ebbdada403bb5074669494428791ea2ba3..da058da413e7ec815dd3fdf891b26a75e3f7a8dd 100755 (executable)
@@ -2128,8 +2128,7 @@ sub dump_function($$) {
 
        create_parameterlist($args, ',', $file);
     } else {
-       print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
-       ++$errors;
+       print STDERR "Warning(${file}:$.): cannot understand function prototype: '$prototype'\n";
        return;
     }
 
index 9dfcd6d988dacaacebef7b91cd51a024618bfb00..deb2994b04c4952d48300e8c4c38a43cf462828b 100644 (file)
@@ -416,7 +416,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
                basename = strrchr(modname, '/') + 1;
        else
                basename = modname;
-       sprintf(filelist, "%s/%.*s.mod", modverdir,
+       snprintf(filelist, sizeof(filelist), "%s/%.*s.mod", modverdir,
                (int) strlen(basename) - 2, basename);
 
        file = grab_file(filelist, &len);
index a674fd5507c19db162af66787dcea6c65c19082d..d0da66396f6201b5dbce7e8b9aa2ae421aefd40a 100755 (executable)
@@ -214,13 +214,13 @@ $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)";
 $weak_regex = "^[0-9a-fA-F]+\\s+([wW])\\s+(\\S+)";
 $section_regex = "Disassembly of section\\s+(\\S+):";
 $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
-$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$";
+$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s(mcount|__fentry__)\$";
 $section_type = '@progbits';
 $mcount_adjust = 0;
 $type = ".long";
 
 if ($arch eq "x86_64") {
-    $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount([+-]0x[0-9a-zA-Z]+)?\$";
+    $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s(mcount|__fentry__)([+-]0x[0-9a-zA-Z]+)?\$";
     $type = ".quad";
     $alignment = 8;
     $mcount_adjust = -1;
index 17df3051747a93ee68a75255764408c813f1a14e..e25732b5d701127d904da3b608b825a520fce3ca 100755 (executable)
@@ -13,7 +13,7 @@ import sys
 import string
 
 def usage():
-       print """usage: show_delta [<options>] <filename>
+       print ("""usage: show_delta [<options>] <filename>
 
 This program parses the output from a set of printk message lines which
 have time data prefixed because the CONFIG_PRINTK_TIME option is set, or
@@ -35,7 +35,7 @@ ex: $ dmesg >timefile
 
 will show times relative to the line in the kernel output
 starting with "NET4".
-"""
+""")
        sys.exit(1)
 
 # returns a tuple containing the seconds and text for each message line
@@ -94,11 +94,11 @@ def main():
        try:
                lines = open(filein,"r").readlines()
        except:
-               print "Problem opening file: %s" % filein
+               print ("Problem opening file: %s" % filein)
                sys.exit(1)
 
        if base_str:
-               print 'base= "%s"' % base_str
+               print ('base= "%s"' % base_str)
                # assume a numeric base.  If that fails, try searching
                # for a matching line.
                try:
@@ -117,13 +117,13 @@ def main():
                                        # stop at first match
                                        break
                        if not found:
-                               print 'Couldn\'t find line matching base pattern "%s"' % base_str
+                               print ('Couldn\'t find line matching base pattern "%s"' % base_str)
                                sys.exit(1)
        else:
                base_time = 0.0
 
        for line in lines:
-               print convert_line(line, base_time),
+               print (convert_line(line, base_time),)
 
 main()
 
index 74f02e4dddd29eca8894fe409984ae525d1e2e96..58c4559290915594e1bd18a67770d0d4bafdc6e3 100755 (executable)
@@ -149,15 +149,16 @@ dogtags()
 exuberant()
 {
        all_target_sources | xargs $1 -a                        \
-       -I __initdata,__exitdata,__initconst,__devinitdata      \
-       -I __devinitconst,__cpuinitdata,__initdata_memblock     \
-       -I __refdata,__attribute                                \
+       -I __initdata,__exitdata,__initconst,                   \
+       -I __cpuinitdata,__initdata_memblock                    \
+       -I __refdata,__attribute,__maybe_unused,__always_unused \
        -I __acquires,__releases,__deprecated                   \
        -I __read_mostly,__aligned,____cacheline_aligned        \
        -I ____cacheline_aligned_in_smp                         \
+       -I __cacheline_aligned,__cacheline_aligned_in_smp       \
        -I ____cacheline_internodealigned_in_smp                \
        -I __used,__packed,__packed2__,__must_check,__must_hold \
-       -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL                      \
+       -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL,ACPI_EXPORT_SYMBOL   \
        -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
        -I static,const                                         \
        --extra=+f --c-kinds=+px                                \
index 61ab640e195f3cbf6ee30d574116c797eead5a99..9dc5806d23dd51134b90fb0f8c0966a0588ccd6c 100644 (file)
@@ -644,7 +644,7 @@ static int n##_control_put(struct snd_kcontrol *kcontrol,           \
                           struct snd_ctl_elem_value *ucontrol)         \
 {                                                                      \
        struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol);        \
-       if (gpio->methods && gpio->methods->get_##n)                    \
+       if (gpio->methods && gpio->methods->set_##n)                    \
                gpio->methods->set_##n(gpio,                            \
                        !!ucontrol->value.integer.value[0]);            \
        return 1;                                                       \
@@ -1135,7 +1135,7 @@ static int aoa_fabric_layout_resume(struct soundbus_dev *sdev)
 {
        struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
 
-       if (ldev->gpio.methods && ldev->gpio.methods->all_amps_off)
+       if (ldev->gpio.methods && ldev->gpio.methods->all_amps_restore)
                ldev->gpio.methods->all_amps_restore(&ldev->gpio);
 
        return 0;
index d9af6387f37c63acc631f670117b274c97e63824..9d518ac73eea064a6b4d918d3dba072cb50102f5 100644 (file)
@@ -384,8 +384,7 @@ static unsigned int snd_compr_poll(struct file *f, poll_table *wait)
                return -EFAULT;
 
        mutex_lock(&stream->device->lock);
-       if (stream->runtime->state == SNDRV_PCM_STATE_PAUSED ||
-                       stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
+       if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
                retval = -EBADFD;
                goto out;
        }
index b35fe7345c203c557d2baa5d0cbb778afac2dfb9..8658578eb584997ec867a864a4e31a124519f828 100644 (file)
@@ -34,12 +34,12 @@ static int jack_switch_types[SND_JACK_SWITCH_TYPES] = {
        SW_LINEIN_INSERT,
 };
 
-static int snd_jack_dev_free(struct snd_device *device)
+static int snd_jack_dev_disconnect(struct snd_device *device)
 {
        struct snd_jack *jack = device->device_data;
 
-       if (jack->private_free)
-               jack->private_free(jack);
+       if (!jack->input_dev)
+               return 0;
 
        /* If the input device is registered with the input subsystem
         * then we need to use a different deallocator. */
@@ -47,6 +47,18 @@ static int snd_jack_dev_free(struct snd_device *device)
                input_unregister_device(jack->input_dev);
        else
                input_free_device(jack->input_dev);
+       jack->input_dev = NULL;
+       return 0;
+}
+
+static int snd_jack_dev_free(struct snd_device *device)
+{
+       struct snd_jack *jack = device->device_data;
+
+       if (jack->private_free)
+               jack->private_free(jack);
+
+       snd_jack_dev_disconnect(device);
 
        kfree(jack->id);
        kfree(jack);
@@ -110,6 +122,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
        static struct snd_device_ops ops = {
                .dev_free = snd_jack_dev_free,
                .dev_register = snd_jack_dev_register,
+               .dev_disconnect = snd_jack_dev_disconnect,
        };
 
        jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
index f664bae3b9b057f1a0b04776c1d4329a6650ed4c..328bd29264ce555e048da881af2dcc7e60e289d6 100644 (file)
@@ -188,8 +188,8 @@ static int pcsp_probe(struct platform_device *dev)
 static int pcsp_remove(struct platform_device *dev)
 {
        struct snd_pcsp *chip = platform_get_drvdata(dev);
-       alsa_card_pcsp_exit(chip);
        pcspkr_input_remove(chip->input_dev);
+       alsa_card_pcsp_exit(chip);
        return 0;
 }
 
index 81aeb934261a26d2f2fca18060f21517b4650b32..0a90bd6ae2325d296f12f8d01a730e6d98fb0606 100644 (file)
 #ifdef MSND_CLASSIC
 #  include "msnd_classic.h"
 #  define LOGNAME                      "msnd_classic"
+#  define DEV_NAME                     "msnd-classic"
 #else
 #  include "msnd_pinnacle.h"
 #  define LOGNAME                      "snd_msnd_pinnacle"
+#  define DEV_NAME                     "msnd-pinnacle"
 #endif
 
 static void set_default_audio_parameters(struct snd_msnd *chip)
@@ -1067,8 +1069,6 @@ static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
        return 0;
 }
 
-#define DEV_NAME "msnd-pinnacle"
-
 static struct isa_driver snd_msnd_driver = {
        .match          = snd_msnd_isa_match,
        .probe          = snd_msnd_isa_probe,
index a2f87f9488ee163e336350c3c1b7cdebb48dca24..e5db001363eee9376d23e79f8a94483f62cd42d1 100644 (file)
@@ -1196,7 +1196,7 @@ wavefront_send_multisample (snd_wavefront_t *dev, wavefront_patch_info *header)
        int num_samples;
        unsigned char *msample_hdr;
 
-       msample_hdr = kmalloc(sizeof(WF_MSAMPLE_BYTES), GFP_KERNEL);
+       msample_hdr = kmalloc(WF_MSAMPLE_BYTES, GFP_KERNEL);
        if (! msample_hdr)
                return -ENOMEM;
 
index dd5403d40830bfa2d97e6012b767fff52d64fddf..afb90f48867f0bd4220ea9816820e750ca2722d1 100644 (file)
@@ -2579,9 +2579,6 @@ int snd_hda_codec_reset(struct hda_codec *codec)
        cancel_delayed_work_sync(&codec->jackpoll_work);
 #ifdef CONFIG_PM
        cancel_delayed_work_sync(&codec->power_work);
-       codec->power_on = 0;
-       codec->power_transition = 0;
-       codec->power_jiffies = jiffies;
        flush_workqueue(bus->workq);
 #endif
        snd_hda_ctls_clear(codec);
index 32d3e3855a6eb99f298a97c3168e604a74ceae77..79ca80f6c77ada6d182a86b9880f3ce9125726f5 100644 (file)
@@ -680,7 +680,7 @@ int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
 
        spkalloc = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SPEAKER_ALLOCATION, 0);
 
-       if (!spkalloc) {
+       if (spkalloc <= 0) {
                snd_printd(KERN_INFO "HDMI ATI/AMD: no speaker allocation for ELD\n");
                return -EINVAL;
        }
@@ -742,6 +742,9 @@ int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
                snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_AUDIO_DESCRIPTOR, i << 3);
                ati_sad = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_DESCRIPTOR, 0);
 
+               if (ati_sad <= 0)
+                       continue;
+
                if (ati_sad & ATI_AUDIODESC_RATES) {
                        /* format is supported, copy SAD as-is */
                        buf[pos++] = (ati_sad & 0x0000ff) >> 0;
@@ -765,21 +768,39 @@ int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
                return -EINVAL;
        }
 
+       /*
+        * HDMI VSDB latency format:
+        * separately for both audio and video:
+        *  0          field not valid or unknown latency
+        *  [1..251]   msecs = (x-1)*2  (max 500ms with x = 251 = 0xfb)
+        *  255        audio/video not supported
+        *
+        * HDA latency format:
+        * single value indicating video latency relative to audio:
+        *  0          unknown or 0ms
+        *  [1..250]   msecs = x*2  (max 500ms with x = 250 = 0xfa)
+        *  [251..255] reserved
+        */
        aud_synch = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_VIDEO_DELAY, 0);
        if ((aud_synch & ATI_DELAY_VIDEO_LATENCY) && (aud_synch & ATI_DELAY_AUDIO_LATENCY)) {
-               int video_latency = (aud_synch & ATI_DELAY_VIDEO_LATENCY) - 1;
-               int audio_latency = ((aud_synch & ATI_DELAY_AUDIO_LATENCY) >> 8) - 1;
+               int video_latency_hdmi = (aud_synch & ATI_DELAY_VIDEO_LATENCY);
+               int audio_latency_hdmi = (aud_synch & ATI_DELAY_AUDIO_LATENCY) >> 8;
 
-               if (video_latency > audio_latency)
-                       buf[6] = min(video_latency - audio_latency, 0xfa);
+               if (video_latency_hdmi <= 0xfb && audio_latency_hdmi <= 0xfb &&
+                   video_latency_hdmi > audio_latency_hdmi)
+                       buf[6] = video_latency_hdmi - audio_latency_hdmi;
+               /* else unknown/invalid or 0ms or video ahead of audio, so use zero */
        }
 
-       /* Baseline length */
-       buf[2] = pos - 4;
-
        /* SAD count */
        buf[5] |= ((pos - ELD_FIXED_BYTES - sink_desc_len) / 3) << 4;
 
+       /* Baseline ELD block length is 4-byte aligned */
+       pos = round_up(pos, 4);
+
+       /* Baseline ELD length (4-byte header is not counted in) */
+       buf[2] = (pos - 4) / 4;
+
        *eld_size = pos;
 
        return 0;
index 276f6e759bacee18dbbe1d5c969575906e34dacf..3067ed4fe3b2f7fdb7edfca13e2b14575b9707a1 100644 (file)
@@ -796,10 +796,10 @@ static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable)
        if (spec->own_eapd_ctl ||
            !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD))
                return;
-       if (codec->inv_eapd)
-               enable = !enable;
        if (spec->keep_eapd_on && !enable)
                return;
+       if (codec->inv_eapd)
+               enable = !enable;
        snd_hda_codec_update_cache(codec, pin, 0,
                                   AC_VERB_SET_EAPD_BTLENABLE,
                                   enable ? 0x02 : 0x00);
index 87d2e0335ae4c3288fb239562a68fec79bbaa5b9..1a83559f4cbd27e455a941adaddc6d0513d9dd81 100644 (file)
@@ -139,6 +139,18 @@ static int ad198x_suspend(struct hda_codec *codec)
 }
 #endif
 
+/* follow EAPD via vmaster hook */
+static void ad_vmaster_eapd_hook(void *private_data, int enabled)
+{
+       struct hda_codec *codec = private_data;
+       struct ad198x_spec *spec = codec->spec;
+
+       if (!spec->eapd_nid)
+               return;
+       snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
+                                  AC_VERB_SET_EAPD_BTLENABLE,
+                                  enabled ? 0x02 : 0x00);
+}
 
 /*
  * Automatic parse of I/O pins from the BIOS configuration
@@ -219,8 +231,14 @@ static int alloc_ad_spec(struct hda_codec *codec)
 static void ad_fixup_inv_jack_detect(struct hda_codec *codec,
                                     const struct hda_fixup *fix, int action)
 {
-       if (action == HDA_FIXUP_ACT_PRE_PROBE)
+       struct ad198x_spec *spec = codec->spec;
+
+       if (action == HDA_FIXUP_ACT_PRE_PROBE) {
                codec->inv_jack_detect = 1;
+               spec->gen.keep_eapd_on = 1;
+               spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook;
+               spec->eapd_nid = 0x1b;
+       }
 }
 
 enum {
@@ -465,19 +483,6 @@ static int patch_ad1983(struct hda_codec *codec)
  * AD1981 HD specific
  */
 
-/* follow EAPD via vmaster hook */
-static void ad_vmaster_eapd_hook(void *private_data, int enabled)
-{
-       struct hda_codec *codec = private_data;
-       struct ad198x_spec *spec = codec->spec;
-
-       if (!spec->eapd_nid)
-               return;
-       snd_hda_codec_update_cache(codec, spec->eapd_nid, 0,
-                                  AC_VERB_SET_EAPD_BTLENABLE,
-                                  enabled ? 0x02 : 0x00);
-}
-
 static void ad1981_fixup_hp_eapd(struct hda_codec *codec,
                                 const struct hda_fixup *fix, int action)
 {
index 072755c8289c0ee440c5366bf04d5e074fcd2538..fc492ac24caa917c9d3670a37f83cb1d3e0bca95 100644 (file)
@@ -47,6 +47,10 @@ struct cs_spec {
        unsigned int spdif_present:1;
        unsigned int sense_b:1;
        hda_nid_t vendor_nid;
+
+       /* for MBP SPDIF control */
+       int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
+                           struct snd_ctl_elem_value *ucontrol);
 };
 
 /* available models with CS420x */
@@ -331,10 +335,21 @@ static int cs_init(struct hda_codec *codec)
        return 0;
 }
 
+static int cs_build_controls(struct hda_codec *codec)
+{
+       int err;
+
+       err = snd_hda_gen_build_controls(codec);
+       if (err < 0)
+               return err;
+       snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
+       return 0;
+}
+
 #define cs_free                snd_hda_gen_free
 
 static const struct hda_codec_ops cs_patch_ops = {
-       .build_controls = snd_hda_gen_build_controls,
+       .build_controls = cs_build_controls,
        .build_pcms = snd_hda_gen_build_pcms,
        .init = cs_init,
        .free = cs_free,
@@ -599,12 +614,14 @@ static int patch_cs420x(struct hda_codec *codec)
 enum {
        CS4208_MAC_AUTO,
        CS4208_MBA6,
+       CS4208_MBP11,
        CS4208_GPIO0,
 };
 
 static const struct hda_model_fixup cs4208_models[] = {
        { .id = CS4208_GPIO0, .name = "gpio0" },
        { .id = CS4208_MBA6, .name = "mba6" },
+       { .id = CS4208_MBP11, .name = "mbp11" },
        {}
 };
 
@@ -615,6 +632,7 @@ static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
 
 /* codec SSID matching */
 static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
+       SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
        SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
        SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
        {} /* terminator */
@@ -646,6 +664,36 @@ static void cs4208_fixup_mac(struct hda_codec *codec,
        snd_hda_apply_fixup(codec, action);
 }
 
+static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct cs_spec *spec = codec->spec;
+       hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
+       int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
+
+       snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
+       return spec->spdif_sw_put(kcontrol, ucontrol);
+}
+
+/* hook the SPDIF switch */
+static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
+                                     const struct hda_fixup *fix, int action)
+{
+       if (action == HDA_FIXUP_ACT_BUILD) {
+               struct cs_spec *spec = codec->spec;
+               struct snd_kcontrol *kctl;
+
+               if (!spec->gen.autocfg.dig_out_pins[0])
+                       return;
+               kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
+               if (!kctl)
+                       return;
+               spec->spdif_sw_put = kctl->put;
+               kctl->put = cs4208_spdif_sw_put;
+       }
+}
+
 static const struct hda_fixup cs4208_fixups[] = {
        [CS4208_MBA6] = {
                .type = HDA_FIXUP_PINS,
@@ -653,6 +701,12 @@ static const struct hda_fixup cs4208_fixups[] = {
                .chained = true,
                .chain_id = CS4208_GPIO0,
        },
+       [CS4208_MBP11] = {
+               .type = HDA_FIXUP_FUNC,
+               .v.func = cs4208_fixup_spdif_switch,
+               .chained = true,
+               .chain_id = CS4208_GPIO0,
+       },
        [CS4208_GPIO0] = {
                .type = HDA_FIXUP_FUNC,
                .v.func = cs4208_fixup_gpio0,
index e68792311bb22850eb44ae0be6659ede770a1d06..08407bed093e5a64d4b659f90bf236dead9ec002 100644 (file)
@@ -763,12 +763,12 @@ static struct channel_map_table map_tables[] = {
        { SNDRV_CHMAP_RC,       RC },
        { SNDRV_CHMAP_FLC,      FLC },
        { SNDRV_CHMAP_FRC,      FRC },
-       { SNDRV_CHMAP_FLH,      FLH },
-       { SNDRV_CHMAP_FRH,      FRH },
+       { SNDRV_CHMAP_TFL,      FLH },
+       { SNDRV_CHMAP_TFR,      FRH },
        { SNDRV_CHMAP_FLW,      FLW },
        { SNDRV_CHMAP_FRW,      FRW },
        { SNDRV_CHMAP_TC,       TC },
-       { SNDRV_CHMAP_FCH,      FCH },
+       { SNDRV_CHMAP_TFC,      FCH },
        {} /* terminator */
 };
 
@@ -1247,6 +1247,9 @@ static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
                pinctl = snd_hda_codec_read(codec, pin_nid, 0,
                                            AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
 
+               if (pinctl < 0)
+                       return hbr ? -EINVAL : 0;
+
                new_pinctl = pinctl & ~AC_PINCTL_EPT;
                if (hbr)
                        new_pinctl |= AC_PINCTL_EPT_HBR;
@@ -3091,7 +3094,7 @@ static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
        int hbr_ctl, hbr_ctl_new;
 
        hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
-       if (hbr_ctl & ATI_HBR_CAPABLE) {
+       if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
                if (hbr)
                        hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
                else
index 24d924d563aa9753b20816db5dddab0f8441528e..04d1e6be600e509b94b6592442b1003465d8542f 100644 (file)
@@ -3344,8 +3344,10 @@ static void alc_update_headset_mode(struct hda_codec *codec)
        else
                new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;
 
-       if (new_headset_mode == spec->current_headset_mode)
+       if (new_headset_mode == spec->current_headset_mode) {
+               snd_hda_gen_update_outputs(codec);
                return;
+       }
 
        switch (new_headset_mode) {
        case ALC_HEADSET_MODE_UNPLUGGED:
index 69a549a8234507e9b4ee14576717d779d05ff6c1..d2cc0041d9d3f92803002addf12f2ca8c98900ec 100644 (file)
@@ -100,6 +100,7 @@ enum {
        STAC_92HD83XXX_HEADSET_JACK,
        STAC_92HD83XXX_HP,
        STAC_HP_ENVY_BASS,
+       STAC_HP_BNB13_EQ,
        STAC_92HD83XXX_MODELS
 };
 
@@ -2106,6 +2107,434 @@ static void stac92hd83xxx_fixup_headset_jack(struct hda_codec *codec,
                spec->headset_jack = 1;
 }
 
+static const struct hda_verb hp_bnb13_eq_verbs[] = {
+       /* 44.1KHz base */
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0x68 },
+       { 0x22, 0x7A8, 0x17 },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0x68 },
+       { 0x22, 0x7AB, 0x17 },
+       { 0x22, 0x7AC, 0x00 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x83 },
+       { 0x22, 0x7A7, 0x2F },
+       { 0x22, 0x7A8, 0xD1 },
+       { 0x22, 0x7A9, 0x83 },
+       { 0x22, 0x7AA, 0x2F },
+       { 0x22, 0x7AB, 0xD1 },
+       { 0x22, 0x7AC, 0x01 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0x68 },
+       { 0x22, 0x7A8, 0x17 },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0x68 },
+       { 0x22, 0x7AB, 0x17 },
+       { 0x22, 0x7AC, 0x02 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x7C },
+       { 0x22, 0x7A7, 0xC6 },
+       { 0x22, 0x7A8, 0x0C },
+       { 0x22, 0x7A9, 0x7C },
+       { 0x22, 0x7AA, 0xC6 },
+       { 0x22, 0x7AB, 0x0C },
+       { 0x22, 0x7AC, 0x03 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xC3 },
+       { 0x22, 0x7A7, 0x25 },
+       { 0x22, 0x7A8, 0xAF },
+       { 0x22, 0x7A9, 0xC3 },
+       { 0x22, 0x7AA, 0x25 },
+       { 0x22, 0x7AB, 0xAF },
+       { 0x22, 0x7AC, 0x04 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0x85 },
+       { 0x22, 0x7A8, 0x73 },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0x85 },
+       { 0x22, 0x7AB, 0x73 },
+       { 0x22, 0x7AC, 0x05 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x85 },
+       { 0x22, 0x7A7, 0x39 },
+       { 0x22, 0x7A8, 0xC7 },
+       { 0x22, 0x7A9, 0x85 },
+       { 0x22, 0x7AA, 0x39 },
+       { 0x22, 0x7AB, 0xC7 },
+       { 0x22, 0x7AC, 0x06 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3C },
+       { 0x22, 0x7A7, 0x90 },
+       { 0x22, 0x7A8, 0xB0 },
+       { 0x22, 0x7A9, 0x3C },
+       { 0x22, 0x7AA, 0x90 },
+       { 0x22, 0x7AB, 0xB0 },
+       { 0x22, 0x7AC, 0x07 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x7A },
+       { 0x22, 0x7A7, 0xC6 },
+       { 0x22, 0x7A8, 0x39 },
+       { 0x22, 0x7A9, 0x7A },
+       { 0x22, 0x7AA, 0xC6 },
+       { 0x22, 0x7AB, 0x39 },
+       { 0x22, 0x7AC, 0x08 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xC4 },
+       { 0x22, 0x7A7, 0xE9 },
+       { 0x22, 0x7A8, 0xDC },
+       { 0x22, 0x7A9, 0xC4 },
+       { 0x22, 0x7AA, 0xE9 },
+       { 0x22, 0x7AB, 0xDC },
+       { 0x22, 0x7AC, 0x09 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3D },
+       { 0x22, 0x7A7, 0xE1 },
+       { 0x22, 0x7A8, 0x0D },
+       { 0x22, 0x7A9, 0x3D },
+       { 0x22, 0x7AA, 0xE1 },
+       { 0x22, 0x7AB, 0x0D },
+       { 0x22, 0x7AC, 0x0A },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x89 },
+       { 0x22, 0x7A7, 0xB6 },
+       { 0x22, 0x7A8, 0xEB },
+       { 0x22, 0x7A9, 0x89 },
+       { 0x22, 0x7AA, 0xB6 },
+       { 0x22, 0x7AB, 0xEB },
+       { 0x22, 0x7AC, 0x0B },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x39 },
+       { 0x22, 0x7A7, 0x9D },
+       { 0x22, 0x7A8, 0xFE },
+       { 0x22, 0x7A9, 0x39 },
+       { 0x22, 0x7AA, 0x9D },
+       { 0x22, 0x7AB, 0xFE },
+       { 0x22, 0x7AC, 0x0C },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x76 },
+       { 0x22, 0x7A7, 0x49 },
+       { 0x22, 0x7A8, 0x15 },
+       { 0x22, 0x7A9, 0x76 },
+       { 0x22, 0x7AA, 0x49 },
+       { 0x22, 0x7AB, 0x15 },
+       { 0x22, 0x7AC, 0x0D },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xC8 },
+       { 0x22, 0x7A7, 0x80 },
+       { 0x22, 0x7A8, 0xF5 },
+       { 0x22, 0x7A9, 0xC8 },
+       { 0x22, 0x7AA, 0x80 },
+       { 0x22, 0x7AB, 0xF5 },
+       { 0x22, 0x7AC, 0x0E },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x40 },
+       { 0x22, 0x7A7, 0x00 },
+       { 0x22, 0x7A8, 0x00 },
+       { 0x22, 0x7A9, 0x40 },
+       { 0x22, 0x7AA, 0x00 },
+       { 0x22, 0x7AB, 0x00 },
+       { 0x22, 0x7AC, 0x0F },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x90 },
+       { 0x22, 0x7A7, 0x68 },
+       { 0x22, 0x7A8, 0xF1 },
+       { 0x22, 0x7A9, 0x90 },
+       { 0x22, 0x7AA, 0x68 },
+       { 0x22, 0x7AB, 0xF1 },
+       { 0x22, 0x7AC, 0x10 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x34 },
+       { 0x22, 0x7A7, 0x47 },
+       { 0x22, 0x7A8, 0x6C },
+       { 0x22, 0x7A9, 0x34 },
+       { 0x22, 0x7AA, 0x47 },
+       { 0x22, 0x7AB, 0x6C },
+       { 0x22, 0x7AC, 0x11 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x6F },
+       { 0x22, 0x7A7, 0x97 },
+       { 0x22, 0x7A8, 0x0F },
+       { 0x22, 0x7A9, 0x6F },
+       { 0x22, 0x7AA, 0x97 },
+       { 0x22, 0x7AB, 0x0F },
+       { 0x22, 0x7AC, 0x12 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xCB },
+       { 0x22, 0x7A7, 0xB8 },
+       { 0x22, 0x7A8, 0x94 },
+       { 0x22, 0x7A9, 0xCB },
+       { 0x22, 0x7AA, 0xB8 },
+       { 0x22, 0x7AB, 0x94 },
+       { 0x22, 0x7AC, 0x13 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x40 },
+       { 0x22, 0x7A7, 0x00 },
+       { 0x22, 0x7A8, 0x00 },
+       { 0x22, 0x7A9, 0x40 },
+       { 0x22, 0x7AA, 0x00 },
+       { 0x22, 0x7AB, 0x00 },
+       { 0x22, 0x7AC, 0x14 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x95 },
+       { 0x22, 0x7A7, 0x76 },
+       { 0x22, 0x7A8, 0x5B },
+       { 0x22, 0x7A9, 0x95 },
+       { 0x22, 0x7AA, 0x76 },
+       { 0x22, 0x7AB, 0x5B },
+       { 0x22, 0x7AC, 0x15 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x31 },
+       { 0x22, 0x7A7, 0xAC },
+       { 0x22, 0x7A8, 0x31 },
+       { 0x22, 0x7A9, 0x31 },
+       { 0x22, 0x7AA, 0xAC },
+       { 0x22, 0x7AB, 0x31 },
+       { 0x22, 0x7AC, 0x16 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x6A },
+       { 0x22, 0x7A7, 0x89 },
+       { 0x22, 0x7A8, 0xA5 },
+       { 0x22, 0x7A9, 0x6A },
+       { 0x22, 0x7AA, 0x89 },
+       { 0x22, 0x7AB, 0xA5 },
+       { 0x22, 0x7AC, 0x17 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xCE },
+       { 0x22, 0x7A7, 0x53 },
+       { 0x22, 0x7A8, 0xCF },
+       { 0x22, 0x7A9, 0xCE },
+       { 0x22, 0x7AA, 0x53 },
+       { 0x22, 0x7AB, 0xCF },
+       { 0x22, 0x7AC, 0x18 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x40 },
+       { 0x22, 0x7A7, 0x00 },
+       { 0x22, 0x7A8, 0x00 },
+       { 0x22, 0x7A9, 0x40 },
+       { 0x22, 0x7AA, 0x00 },
+       { 0x22, 0x7AB, 0x00 },
+       { 0x22, 0x7AC, 0x19 },
+       { 0x22, 0x7AD, 0x80 },
+       /* 48KHz base */
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0x88 },
+       { 0x22, 0x7A8, 0xDC },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0x88 },
+       { 0x22, 0x7AB, 0xDC },
+       { 0x22, 0x7AC, 0x1A },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x82 },
+       { 0x22, 0x7A7, 0xEE },
+       { 0x22, 0x7A8, 0x46 },
+       { 0x22, 0x7A9, 0x82 },
+       { 0x22, 0x7AA, 0xEE },
+       { 0x22, 0x7AB, 0x46 },
+       { 0x22, 0x7AC, 0x1B },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0x88 },
+       { 0x22, 0x7A8, 0xDC },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0x88 },
+       { 0x22, 0x7AB, 0xDC },
+       { 0x22, 0x7AC, 0x1C },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x7D },
+       { 0x22, 0x7A7, 0x09 },
+       { 0x22, 0x7A8, 0x28 },
+       { 0x22, 0x7A9, 0x7D },
+       { 0x22, 0x7AA, 0x09 },
+       { 0x22, 0x7AB, 0x28 },
+       { 0x22, 0x7AC, 0x1D },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xC2 },
+       { 0x22, 0x7A7, 0xE5 },
+       { 0x22, 0x7A8, 0xB4 },
+       { 0x22, 0x7A9, 0xC2 },
+       { 0x22, 0x7AA, 0xE5 },
+       { 0x22, 0x7AB, 0xB4 },
+       { 0x22, 0x7AC, 0x1E },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0xA3 },
+       { 0x22, 0x7A8, 0x1F },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0xA3 },
+       { 0x22, 0x7AB, 0x1F },
+       { 0x22, 0x7AC, 0x1F },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x84 },
+       { 0x22, 0x7A7, 0xCA },
+       { 0x22, 0x7A8, 0xF1 },
+       { 0x22, 0x7A9, 0x84 },
+       { 0x22, 0x7AA, 0xCA },
+       { 0x22, 0x7AB, 0xF1 },
+       { 0x22, 0x7AC, 0x20 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3C },
+       { 0x22, 0x7A7, 0xD5 },
+       { 0x22, 0x7A8, 0x9C },
+       { 0x22, 0x7A9, 0x3C },
+       { 0x22, 0x7AA, 0xD5 },
+       { 0x22, 0x7AB, 0x9C },
+       { 0x22, 0x7AC, 0x21 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x7B },
+       { 0x22, 0x7A7, 0x35 },
+       { 0x22, 0x7A8, 0x0F },
+       { 0x22, 0x7A9, 0x7B },
+       { 0x22, 0x7AA, 0x35 },
+       { 0x22, 0x7AB, 0x0F },
+       { 0x22, 0x7AC, 0x22 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xC4 },
+       { 0x22, 0x7A7, 0x87 },
+       { 0x22, 0x7A8, 0x45 },
+       { 0x22, 0x7A9, 0xC4 },
+       { 0x22, 0x7AA, 0x87 },
+       { 0x22, 0x7AB, 0x45 },
+       { 0x22, 0x7AC, 0x23 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3E },
+       { 0x22, 0x7A7, 0x0A },
+       { 0x22, 0x7A8, 0x78 },
+       { 0x22, 0x7A9, 0x3E },
+       { 0x22, 0x7AA, 0x0A },
+       { 0x22, 0x7AB, 0x78 },
+       { 0x22, 0x7AC, 0x24 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x88 },
+       { 0x22, 0x7A7, 0xE2 },
+       { 0x22, 0x7A8, 0x05 },
+       { 0x22, 0x7A9, 0x88 },
+       { 0x22, 0x7AA, 0xE2 },
+       { 0x22, 0x7AB, 0x05 },
+       { 0x22, 0x7AC, 0x25 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x3A },
+       { 0x22, 0x7A7, 0x1A },
+       { 0x22, 0x7A8, 0xA3 },
+       { 0x22, 0x7A9, 0x3A },
+       { 0x22, 0x7AA, 0x1A },
+       { 0x22, 0x7AB, 0xA3 },
+       { 0x22, 0x7AC, 0x26 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x77 },
+       { 0x22, 0x7A7, 0x1D },
+       { 0x22, 0x7A8, 0xFB },
+       { 0x22, 0x7A9, 0x77 },
+       { 0x22, 0x7AA, 0x1D },
+       { 0x22, 0x7AB, 0xFB },
+       { 0x22, 0x7AC, 0x27 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xC7 },
+       { 0x22, 0x7A7, 0xDA },
+       { 0x22, 0x7A8, 0xE5 },
+       { 0x22, 0x7A9, 0xC7 },
+       { 0x22, 0x7AA, 0xDA },
+       { 0x22, 0x7AB, 0xE5 },
+       { 0x22, 0x7AC, 0x28 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x40 },
+       { 0x22, 0x7A7, 0x00 },
+       { 0x22, 0x7A8, 0x00 },
+       { 0x22, 0x7A9, 0x40 },
+       { 0x22, 0x7AA, 0x00 },
+       { 0x22, 0x7AB, 0x00 },
+       { 0x22, 0x7AC, 0x29 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x8E },
+       { 0x22, 0x7A7, 0xD7 },
+       { 0x22, 0x7A8, 0x22 },
+       { 0x22, 0x7A9, 0x8E },
+       { 0x22, 0x7AA, 0xD7 },
+       { 0x22, 0x7AB, 0x22 },
+       { 0x22, 0x7AC, 0x2A },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x35 },
+       { 0x22, 0x7A7, 0x26 },
+       { 0x22, 0x7A8, 0xC6 },
+       { 0x22, 0x7A9, 0x35 },
+       { 0x22, 0x7AA, 0x26 },
+       { 0x22, 0x7AB, 0xC6 },
+       { 0x22, 0x7AC, 0x2B },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x71 },
+       { 0x22, 0x7A7, 0x28 },
+       { 0x22, 0x7A8, 0xDE },
+       { 0x22, 0x7A9, 0x71 },
+       { 0x22, 0x7AA, 0x28 },
+       { 0x22, 0x7AB, 0xDE },
+       { 0x22, 0x7AC, 0x2C },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xCA },
+       { 0x22, 0x7A7, 0xD9 },
+       { 0x22, 0x7A8, 0x3A },
+       { 0x22, 0x7A9, 0xCA },
+       { 0x22, 0x7AA, 0xD9 },
+       { 0x22, 0x7AB, 0x3A },
+       { 0x22, 0x7AC, 0x2D },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x40 },
+       { 0x22, 0x7A7, 0x00 },
+       { 0x22, 0x7A8, 0x00 },
+       { 0x22, 0x7A9, 0x40 },
+       { 0x22, 0x7AA, 0x00 },
+       { 0x22, 0x7AB, 0x00 },
+       { 0x22, 0x7AC, 0x2E },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x93 },
+       { 0x22, 0x7A7, 0x5E },
+       { 0x22, 0x7A8, 0xD8 },
+       { 0x22, 0x7A9, 0x93 },
+       { 0x22, 0x7AA, 0x5E },
+       { 0x22, 0x7AB, 0xD8 },
+       { 0x22, 0x7AC, 0x2F },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x32 },
+       { 0x22, 0x7A7, 0xB7 },
+       { 0x22, 0x7A8, 0xB1 },
+       { 0x22, 0x7A9, 0x32 },
+       { 0x22, 0x7AA, 0xB7 },
+       { 0x22, 0x7AB, 0xB1 },
+       { 0x22, 0x7AC, 0x30 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x6C },
+       { 0x22, 0x7A7, 0xA1 },
+       { 0x22, 0x7A8, 0x28 },
+       { 0x22, 0x7A9, 0x6C },
+       { 0x22, 0x7AA, 0xA1 },
+       { 0x22, 0x7AB, 0x28 },
+       { 0x22, 0x7AC, 0x31 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0xCD },
+       { 0x22, 0x7A7, 0x48 },
+       { 0x22, 0x7A8, 0x4F },
+       { 0x22, 0x7A9, 0xCD },
+       { 0x22, 0x7AA, 0x48 },
+       { 0x22, 0x7AB, 0x4F },
+       { 0x22, 0x7AC, 0x32 },
+       { 0x22, 0x7AD, 0x80 },
+       { 0x22, 0x7A6, 0x40 },
+       { 0x22, 0x7A7, 0x00 },
+       { 0x22, 0x7A8, 0x00 },
+       { 0x22, 0x7A9, 0x40 },
+       { 0x22, 0x7AA, 0x00 },
+       { 0x22, 0x7AB, 0x00 },
+       { 0x22, 0x7AC, 0x33 },
+       { 0x22, 0x7AD, 0x80 },
+       /* common */
+       { 0x22, 0x782, 0xC1 },
+       { 0x22, 0x771, 0x2C },
+       { 0x22, 0x772, 0x2C },
+       { 0x22, 0x788, 0x04 },
+       { 0x01, 0x7B0, 0x08 },
+       {}
+};
+
 static const struct hda_fixup stac92hd83xxx_fixups[] = {
        [STAC_92HD83XXX_REF] = {
                .type = HDA_FIXUP_PINS,
@@ -2174,6 +2603,12 @@ static const struct hda_fixup stac92hd83xxx_fixups[] = {
                        {}
                },
        },
+       [STAC_HP_BNB13_EQ] = {
+               .type = HDA_FIXUP_VERBS,
+               .v.verbs = hp_bnb13_eq_verbs,
+               .chained = true,
+               .chain_id = STAC_92HD83XXX_HP_MIC_LED,
+       },
 };
 
 static const struct hda_model_fixup stac92hd83xxx_models[] = {
@@ -2189,6 +2624,7 @@ static const struct hda_model_fixup stac92hd83xxx_models[] = {
        { .id = STAC_92HD83XXX_HP_MIC_LED, .name = "hp-mic-led" },
        { .id = STAC_92HD83XXX_HEADSET_JACK, .name = "headset-jack" },
        { .id = STAC_HP_ENVY_BASS, .name = "hp-envy-bass" },
+       { .id = STAC_HP_BNB13_EQ, .name = "hp-bnb13-eq" },
        {}
 };
 
@@ -2235,7 +2671,101 @@ static const struct snd_pci_quirk stac92hd83xxx_fixup_tbl[] = {
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1888,
                          "HP Envy Spectre", STAC_HP_ENVY_BASS),
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
-                         "HP Folio", STAC_92HD83XXX_HP_MIC_LED),
+                         "HP Folio", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18F8,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1909,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x190A,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1940,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1941,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1942,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1943,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1944,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1945,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1946,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1948,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1949,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194A,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194B,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194C,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194E,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x194F,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1950,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1951,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x195A,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x195B,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x195C,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1991,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2103,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2104,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2105,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2106,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2107,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2108,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2109,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x210A,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x210B,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211C,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211D,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211E,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x211F,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2120,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2121,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2122,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2123,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x213E,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x213F,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x2140,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B2,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B3,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B5,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x21B6,
+                         "HP bNB13", STAC_HP_BNB13_EQ),
        SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x1900,
                          "HP", STAC_92HD83XXX_HP_MIC_LED),
        SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x2000,
index 01aecc2b50738353ad8a96f618c01be631981240..0d1c27e911b8dde2cf1b69827e8743a31a67316f 100644 (file)
@@ -65,7 +65,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
         * already bound. If not it means binding failed, and then there
         * is no point in keeping the device instantiated.
         */
-       if (!keywest_ctx->client->driver) {
+       if (!keywest_ctx->client->dev.driver) {
                i2c_unregister_device(keywest_ctx->client);
                keywest_ctx->client = NULL;
                return -ENODEV;
@@ -76,7 +76,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
         * This is safe because i2c-core holds the core_lock mutex for us.
         */
        list_add_tail(&keywest_ctx->client->detected,
-                     &keywest_ctx->client->driver->clients);
+                     &to_i2c_driver(keywest_ctx->client->dev.driver)->clients);
        return 0;
 }
 
index 9a174fc47d39b38b0bf3ddfbd18f8367136744c4..39d774839b3ec064758604fbac83d5bfed2755bc 100644 (file)
@@ -121,6 +121,7 @@ static int bf5xx_i2s_hw_params(struct snd_pcm_substream *substream,
                bf5xx_i2s->tcr2 |= 7;
                bf5xx_i2s->rcr2 |= 7;
                sport_handle->wdsize = 1;
+               break;
        case SNDRV_PCM_FORMAT_S16_LE:
                bf5xx_i2s->tcr2 |= 15;
                bf5xx_i2s->rcr2 |= 15;
index f2e62e45f91288916a252486a4ac130c5d7dd022..19e9f222d09c0934cb184843b40ff0ad52b4a1ec 100644 (file)
@@ -614,7 +614,7 @@ struct _pll_div {
 };
 
 /* Note : pll code from original alc5632 driver. Not sure of how good it is */
-/* usefull only for master mode */
+/* useful only for master mode */
 static const struct _pll_div codec_master_pll_div[] = {
 
        {  2048000,  8192000,   0x0ea0},
index 1a9412d86d172a81f058294f331bbaa549dcf654..6fb8f00f4191a7ad890f387c40dc4711dbbfddab 100644 (file)
 #define CS42L52_MICB_CTL                       0x11
 #define        CS42L52_MIC_CTL_MIC_SEL_MASK            0xBF
 #define        CS42L52_MIC_CTL_MIC_SEL_SHIFT           6
-#define CS42L52_MIC_CTL_TYPE_MASK              0xDF
+#define CS42L52_MIC_CTL_TYPE_MASK              0x20
 #define CS42L52_MIC_CTL_TYPE_SHIFT             5
 
 
index 8bbddc151aa842eed14cae97cdabdcbbd9d8e469..a08e8bf6d07cb7db76cf8075d2e61d2ec2464b18 100644 (file)
@@ -685,13 +685,13 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
 ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
 ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
 
-SND_SOC_BYTES_MASK("EQ1 Coefficeints", ARIZONA_EQ1_1, 21,
+SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21,
                   ARIZONA_EQ1_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ2 Coefficeints", ARIZONA_EQ2_1, 21,
+SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
                   ARIZONA_EQ2_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ3 Coefficeints", ARIZONA_EQ3_1, 21,
+SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
                   ARIZONA_EQ3_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ4 Coefficeints", ARIZONA_EQ4_1, 21,
+SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
                   ARIZONA_EQ4_ENA_MASK),
 
 SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
index 8c91be5d67e3c51d87166c03c6b2855c4e22ad16..f2d1094424b9f6f3dcce1b5eab3a7f4492ec657e 100644 (file)
@@ -101,13 +101,13 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
 ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
 ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
 
-SND_SOC_BYTES_MASK("EQ1 Coefficeints", ARIZONA_EQ1_1, 21,
+SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21,
                   ARIZONA_EQ1_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ2 Coefficeints", ARIZONA_EQ2_1, 21,
+SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
                   ARIZONA_EQ2_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ3 Coefficeints", ARIZONA_EQ3_1, 21,
+SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
                   ARIZONA_EQ3_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ4 Coefficeints", ARIZONA_EQ4_1, 21,
+SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
                   ARIZONA_EQ4_ENA_MASK),
 
 SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
index ac1ff9947a90dbcc8353e8f146a82cd571c5dba3..543c5c2631b61827bcebca8af1926ea02b5655e9 100644 (file)
@@ -3728,6 +3728,8 @@ static int wm8962_i2c_probe(struct i2c_client *i2c,
        if (ret < 0)
                goto err_enable;
 
+       regcache_cache_only(wm8962->regmap, true);
+
        /* The drivers should power up as needed */
        regulator_bulk_disable(ARRAY_SIZE(wm8962->supplies), wm8962->supplies);
 
index 6ec3de3efa4fa2f75ab0cc73230ae7353d7e3e7b..1392bb3c92540366c9a28817891567bfcfd45601 100644 (file)
@@ -170,13 +170,13 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
 ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
 ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
 
-SND_SOC_BYTES_MASK("EQ1 Coefficeints", ARIZONA_EQ1_1, 21,
+SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21,
                   ARIZONA_EQ1_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ2 Coefficeints", ARIZONA_EQ2_1, 21,
+SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
                   ARIZONA_EQ2_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ3 Coefficeints", ARIZONA_EQ3_1, 21,
+SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
                   ARIZONA_EQ3_ENA_MASK),
-SND_SOC_BYTES_MASK("EQ4 Coefficeints", ARIZONA_EQ4_1, 21,
+SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
                   ARIZONA_EQ4_ENA_MASK),
 
 SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
@@ -887,7 +887,7 @@ static const struct snd_soc_dapm_route wm8997_dapm_routes[] = {
        ARIZONA_MIXER_ROUTES("Mic Mute Mixer", "Mic"),
 
        ARIZONA_MUX_ROUTES("ISRC1INT1", "ISRC1INT1"),
-       ARIZONA_MUX_ROUTES("ISRC1INT2", "ISRC2INT2"),
+       ARIZONA_MUX_ROUTES("ISRC1INT2", "ISRC1INT2"),
 
        ARIZONA_MUX_ROUTES("ISRC1DEC1", "ISRC1DEC1"),
        ARIZONA_MUX_ROUTES("ISRC1DEC2", "ISRC1DEC2"),
index fa64cd85204fff5a9615f9cabbb5ac519a164d9d..fb5d107f56034eebec7003878eceded711a51769 100644 (file)
@@ -238,7 +238,7 @@ static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
        print_buf_info(prtd->ram_channel, "i ram_channel");
        pr_debug("davinci_pcm: link=%d, status=0x%x\n", link, ch_status);
 
-       if (unlikely(ch_status != DMA_COMPLETE))
+       if (unlikely(ch_status != EDMA_DMA_COMPLETE))
                return;
 
        if (snd_pcm_running(substream)) {
index 41740e4888202263e72bb3900d04cd418513dd0c..c75d43bb2e92de772a97865e98227176473135a4 100644 (file)
@@ -42,7 +42,8 @@ struct imx_pcm_runtime_data {
        struct hrtimer hrt;
        int poll_time_ns;
        struct snd_pcm_substream *substream;
-       atomic_t running;
+       atomic_t playing;
+       atomic_t capturing;
 };
 
 static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
@@ -52,7 +53,7 @@ static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
        struct snd_pcm_substream *substream = iprtd->substream;
        struct pt_regs regs;
 
-       if (!atomic_read(&iprtd->running))
+       if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing))
                return HRTIMER_NORESTART;
 
        get_fiq_regs(&regs);
@@ -106,7 +107,6 @@ static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static int fiq_enable;
 static int imx_pcm_fiq;
 
 static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
@@ -118,23 +118,27 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        case SNDRV_PCM_TRIGGER_START:
        case SNDRV_PCM_TRIGGER_RESUME:
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               atomic_set(&iprtd->running, 1);
+               if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       atomic_set(&iprtd->playing, 1);
+               else
+                       atomic_set(&iprtd->capturing, 1);
                hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns),
                      HRTIMER_MODE_REL);
-               if (++fiq_enable == 1)
-                       enable_fiq(imx_pcm_fiq);
-
+               enable_fiq(imx_pcm_fiq);
                break;
 
        case SNDRV_PCM_TRIGGER_STOP:
        case SNDRV_PCM_TRIGGER_SUSPEND:
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               atomic_set(&iprtd->running, 0);
-
-               if (--fiq_enable == 0)
+               if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       atomic_set(&iprtd->playing, 0);
+               else
+                       atomic_set(&iprtd->capturing, 0);
+               if (!atomic_read(&iprtd->playing) &&
+                               !atomic_read(&iprtd->capturing))
                        disable_fiq(imx_pcm_fiq);
-
                break;
+
        default:
                return -EINVAL;
        }
@@ -182,7 +186,8 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
 
        iprtd->substream = substream;
 
-       atomic_set(&iprtd->running, 0);
+       atomic_set(&iprtd->playing, 0);
+       atomic_set(&iprtd->capturing, 0);
        hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        iprtd->hrt.function = snd_hrtimer_callback;
 
index 361f94f09b11565239b3edba824053b9bbd94e70..61e48852b9e8bd21b26eec98cca4fc9ba0eea145 100644 (file)
@@ -215,7 +215,7 @@ static int imx_wm8962_probe(struct platform_device *pdev)
                goto fail;
        }
        codec_dev = of_find_i2c_device_by_node(codec_np);
-       if (!codec_dev || !codec_dev->driver) {
+       if (!codec_dev || !codec_dev->dev.driver) {
                dev_err(&pdev->dev, "failed to find codec platform device\n");
                ret = -EINVAL;
                goto fail;
index b47f6fe6277fd72aadfeadda3eddb623a3215291..dbb1b625eb2f59b5fd536fc33c0679b054095652 100644 (file)
@@ -907,19 +907,24 @@ static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream)
        struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned long flags;
+       int ret = 0;
 
        spin_lock_irqsave(&chip->lock, flags);
 
        chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE |
                                            CS4231_PLAYBACK_PIO);
 
-       if (WARN_ON(runtime->period_size > 0xffff + 1))
-               return -EINVAL;
+       if (WARN_ON(runtime->period_size > 0xffff + 1)) {
+               ret = -EINVAL;
+               goto out;
+       }
 
        chip->p_periods_sent = 0;
+
+out:
        spin_unlock_irqrestore(&chip->lock, flags);
 
-       return 0;
+       return ret;
 }
 
 static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream,
index d42a584cf8292d99d349a309f55e2d1724e45898..3454262358b398913779954846ab12c11e7c5973 100644 (file)
@@ -433,6 +433,89 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
        }
 }
 
+/* EMU0204 */
+static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_info *uinfo)
+{
+       static const char *texts[2] = {"1/2",
+                                      "3/4"
+       };
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = 2;
+       if (uinfo->value.enumerated.item > 1)
+               uinfo->value.enumerated.item = 1;
+       strcpy(uinfo->value.enumerated.name,
+               texts[uinfo->value.enumerated.item]);
+
+       return 0;
+}
+
+static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
+                                    struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.enumerated.item[0] = kcontrol->private_value;
+       return 0;
+}
+
+static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol,
+                                    struct snd_ctl_elem_value *ucontrol)
+{
+       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+       unsigned int value = ucontrol->value.enumerated.item[0];
+       int err, changed;
+       unsigned char buf[2];
+
+       if (value > 1)
+               return -EINVAL;
+
+       buf[0] = 0x01;
+       buf[1] = value ? 0x02 : 0x01;
+
+       changed = value != kcontrol->private_value;
+       down_read(&mixer->chip->shutdown_rwsem);
+       if (mixer->chip->shutdown) {
+               err = -ENODEV;
+               goto out;
+       }
+       err = snd_usb_ctl_msg(mixer->chip->dev,
+                     usb_sndctrlpipe(mixer->chip->dev, 0), UAC_SET_CUR,
+                     USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
+                     0x0400, 0x0e00, buf, 2);
+ out:
+       up_read(&mixer->chip->shutdown_rwsem);
+       if (err < 0)
+               return err;
+       kcontrol->private_value = value;
+       return changed;
+}
+
+
+static struct snd_kcontrol_new snd_emu0204_controls[] = {
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Front Jack Channels",
+               .info = snd_emu0204_ch_switch_info,
+               .get = snd_emu0204_ch_switch_get,
+               .put = snd_emu0204_ch_switch_put,
+               .private_value = 0,
+       },
+};
+
+static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer)
+{
+       int i, err;
+
+       for (i = 0; i < ARRAY_SIZE(snd_emu0204_controls); ++i) {
+               err = snd_ctl_add(mixer->chip->card,
+                       snd_ctl_new1(&snd_emu0204_controls[i], mixer));
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
 /* ASUS Xonar U1 / U3 controls */
 
 static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
@@ -1545,6 +1628,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
                                              snd_audigy2nx_proc_read);
                break;
 
+       /* EMU0204 */
+       case USB_ID(0x041e, 0x3f19):
+               err = snd_emu0204_controls_create(mixer);
+               if (err < 0)
+                       break;
+               break;
+
        case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
        case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */
                err = snd_c400_create_mixer(mixer);
index d737d0e6e5580efdec49852b93ed610429c88e31..2fb71be5e100b0973c0993dbb8ed4da3f35c5cf2 100644 (file)
@@ -273,8 +273,8 @@ static struct snd_pcm_chmap_elem *convert_chmap(int channels, unsigned int bits,
                SNDRV_CHMAP_TSL,        /* top side left */
                SNDRV_CHMAP_TSR,        /* top side right */
                SNDRV_CHMAP_BC,         /* bottom center */
-               SNDRV_CHMAP_BLC,        /* bottom left center */
-               SNDRV_CHMAP_BRC,        /* bottom right center */
+               SNDRV_CHMAP_RLC,        /* back left of center */
+               SNDRV_CHMAP_RRC,        /* back right of center */
                0 /* terminator */
        };
        struct snd_pcm_chmap_elem *chmap;
index 052f7c4dc00c25a47dbe6355f0f762744ad5a79a..43b42c4f4a915ad96be76c737b63feee12925de2 100644 (file)
@@ -201,6 +201,12 @@ abort events and some memory events in precise mode on modern Intel CPUs.
 --transaction::
 Record transaction flags for transaction related events.
 
+--force-per-cpu::
+Force the use of per-cpu mmaps.  By default, when tasks are specified (i.e. -p,
+-t or -u options) per-thread mmaps are created.  This option overrides that and
+forces per-cpu mmaps.  A side-effect of that is that inheritance is
+automatically enabled.  Add the -i option also to disable inheritance.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
index 89acc17cf2a02e4c7d8760a7b89e1300007cc5a3..6ea9e85bdc00ca02a50735abf0ac304107dd1727 100644 (file)
@@ -325,6 +325,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
                     opt_set_filter),
        OPT_CALLBACK('x', "exec", NULL, "executable|path",
                        "target executable name or path", opt_set_target),
+       OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
+                   "Disable symbol demangling"),
        OPT_END()
        };
        int ret;
index 4d644fe2d5b78315f6d00f0d66560ae5836e7b02..7c8020a32784abcd6d44223dc3a5586f7ba7f3f0 100644 (file)
@@ -888,6 +888,8 @@ const struct option record_options[] = {
                    "sample by weight (on special events only)"),
        OPT_BOOLEAN(0, "transaction", &record.opts.sample_transaction,
                    "sample transaction flags (special events only)"),
+       OPT_BOOLEAN(0, "force-per-cpu", &record.opts.target.force_per_cpu,
+                   "force the use of per-cpu mmaps"),
        OPT_END()
 };
 
index b8f8e29db332df707887284d539b6ad6f3d5840f..71e6402729a8616bf9b9fe8e2141ea08ac0bbca2 100644 (file)
@@ -1172,7 +1172,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
        status = target__validate(target);
        if (status) {
                target__strerror(target, status, errbuf, BUFSIZ);
-               ui__warning("%s", errbuf);
+               ui__warning("%s\n", errbuf);
        }
 
        status = target__parse_uid(target);
@@ -1180,7 +1180,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
                int saved_errno = errno;
 
                target__strerror(target, status, errbuf, BUFSIZ);
-               ui__error("%s", errbuf);
+               ui__error("%s\n", errbuf);
 
                status = -saved_errno;
                goto out_delete_evlist;
index 6b230af940e2ab0c136098ef49b21522b6c165b6..8be17fc462baff466a6aa25682f804c4b5fdd1dc 100644 (file)
@@ -2112,9 +2112,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 
        printed += fprintf(fp, "\n");
 
-       printed += fprintf(fp, "                                                    msec/call\n");
-       printed += fprintf(fp, "   syscall            calls      min      avg      max stddev\n");
-       printed += fprintf(fp, "   --------------- -------- -------- -------- -------- ------\n");
+       printed += fprintf(fp, "   syscall            calls      min       avg       max      stddev\n");
+       printed += fprintf(fp, "                               (msec)    (msec)    (msec)        (%%)\n");
+       printed += fprintf(fp, "   --------------- -------- --------- --------- ---------     ------\n");
 
        /* each int_node is a syscall */
        while (inode) {
@@ -2131,9 +2131,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 
                        sc = &trace->syscalls.table[inode->i];
                        printed += fprintf(fp, "   %-15s", sc->name);
-                       printed += fprintf(fp, " %8" PRIu64 " %8.3f %8.3f",
+                       printed += fprintf(fp, " %8" PRIu64 " %9.3f %9.3f",
                                           n, min, avg);
-                       printed += fprintf(fp, " %8.3f %6.2f\n", max, pct);
+                       printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct);
                }
 
                inode = intlist__next(inode);
index f5905f2b197d81d7cb2c8e0ee5a3f2cc257d5f20..f7d11a811c743e6e2836270f4579124007140d32 100644 (file)
@@ -142,7 +142,8 @@ CORE_FEATURE_TESTS =                        \
        libunwind                       \
        on-exit                         \
        stackprotector                  \
-       stackprotector-all
+       stackprotector-all              \
+       timerfd
 
 #
 # So here we detect whether test-all was rebuilt, to be able
@@ -328,8 +329,14 @@ ifndef NO_LIBUNWIND
     msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1);
     NO_LIBUNWIND := 1
   else
-    ifneq ($(feature-libunwind-debug-frame), 1)
-      msg := $(warning No debug_frame support found in libunwind);
+    ifeq ($(ARCH),arm)
+      $(call feature_check,libunwind-debug-frame)
+      ifneq ($(feature-libunwind-debug-frame), 1)
+        msg := $(warning No debug_frame support found in libunwind);
+        CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
+      endif
+    else
+      # non-ARM has no dwarf_find_debug_frame() function:
       CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
     endif
   endif
@@ -405,7 +412,6 @@ else
   endif
 endif
 
-$(call feature_check,timerfd)
 ifeq ($(feature-timerfd), 1)
   CFLAGS += -DHAVE_TIMERFD_SUPPORT
 else
index e8e195f49a4ee7695a80b2a4d535fb35a5aac504..87e790017c6988b856e3b4e8b47f572a9d8beea9 100644 (file)
@@ -76,6 +76,9 @@ test-libnuma:
 test-libunwind:
        $(BUILD) $(LIBUNWIND_LIBS) -lelf
 
+test-libunwind-debug-frame:
+       $(BUILD) $(LIBUNWIND_LIBS) -lelf
+
 test-libaudit:
        $(BUILD) -laudit
 
index 799865b607721e247b847711cf656ef375ada341..59e7a705e146d4eb8ea029ebf74878411f8e3898 100644 (file)
 # include "test-libunwind.c"
 #undef main
 
-#define main main_test_libunwind_debug_frame
-# include "test-libunwind-debug-frame.c"
-#undef main
-
 #define main main_test_libaudit
 # include "test-libaudit.c"
 #undef main
index ef671cd41bb3ef554478db74cecc61c6df28afca..3cbd104960871705778f37450f0e33d117430f07 100644 (file)
@@ -441,9 +441,8 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)
 
 static int test__checkevent_pmu_events(struct perf_evlist *evlist)
 {
-       struct perf_evsel *evsel;
+       struct perf_evsel *evsel = perf_evlist__first(evlist);
 
-       evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
        TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
        TEST_ASSERT_VAL("wrong exclude_user",
index bbc782e364b0831f04b12ce417b22ae6b5948b16..cbaa7af45513660d0fda1d1b6cbea8fa0a39b2ec 100644 (file)
@@ -569,7 +569,7 @@ void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence)
                browser->top = browser->top + browser->top_idx + offset;
                break;
        case SEEK_END:
-               browser->top = browser->top + browser->nr_entries + offset;
+               browser->top = browser->top + browser->nr_entries - 1 + offset;
                break;
        default:
                return;
@@ -680,7 +680,7 @@ static void __ui_browser__line_arrow_down(struct ui_browser *browser,
        if (end >= browser->top_idx + browser->height)
                end_row = browser->height - 1;
        else
-               end_row = end - browser->top_idx;;
+               end_row = end - browser->top_idx;
 
        ui_browser__gotorc(browser, row, column);
        SLsmg_draw_vline(end_row - row + 1);
index 16848bb4c41842355be8c7a36d2df574a9c90214..a440e03cd8c235402b626526b41676b3ad95488b 100644 (file)
@@ -1847,15 +1847,15 @@ browse_hists:
                        switch (key) {
                        case K_TAB:
                                if (pos->node.next == &evlist->entries)
-                                       pos = list_entry(evlist->entries.next, struct perf_evsel, node);
+                                       pos = perf_evlist__first(evlist);
                                else
-                                       pos = list_entry(pos->node.next, struct perf_evsel, node);
+                                       pos = perf_evsel__next(pos);
                                goto browse_hists;
                        case K_UNTAB:
                                if (pos->node.prev == &evlist->entries)
-                                       pos = list_entry(evlist->entries.prev, struct perf_evsel, node);
+                                       pos = perf_evlist__last(evlist);
                                else
-                                       pos = list_entry(pos->node.prev, struct perf_evsel, node);
+                                       pos = perf_evsel__prev(pos);
                                goto browse_hists;
                        case K_ESC:
                                if (!ui_browser__dialog_yesno(&menu->b,
@@ -1943,8 +1943,7 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
 
 single_entry:
        if (nr_entries == 1) {
-               struct perf_evsel *first = list_entry(evlist->entries.next,
-                                                     struct perf_evsel, node);
+               struct perf_evsel *first = perf_evlist__first(evlist);
                const char *ev_name = perf_evsel__name(first);
 
                return perf_evsel__hists_browse(first, nr_entries, help,
index 6e3a846aed0ea99ac2958886a64a512359394cea..bb788c109fe6efa4ecb2ae5784efa49cf33bca73 100644 (file)
@@ -209,8 +209,10 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
                       &event->mmap.start, &event->mmap.len, prot,
                       &event->mmap.pgoff,
                       execname);
-
-               if (n != 5)
+               /*
+                * Anon maps don't have the execname.
+                */
+               if (n < 4)
                        continue;
                /*
                 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
index dc6fa3fbb180c69bf7a271450f11c52b45203880..bbc746aa571663d92e989bb5f3f2703c31c9a193 100644 (file)
@@ -819,7 +819,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
        if (evlist->threads == NULL)
                return -1;
 
-       if (target__has_task(target))
+       if (target->force_per_cpu)
+               evlist->cpus = cpu_map__new(target->cpu_list);
+       else if (target__has_task(target))
                evlist->cpus = cpu_map__dummy_new();
        else if (!target__has_cpu(target) && !target->uses_mmap)
                evlist->cpus = cpu_map__dummy_new();
@@ -1148,7 +1150,7 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp)
                                   perf_evsel__name(evsel));
        }
 
-       return printed + fprintf(fp, "\n");;
+       return printed + fprintf(fp, "\n");
 }
 
 int perf_evlist__strerror_tp(struct perf_evlist *evlist __maybe_unused,
index 18f7c188ff632816376c26b9f5a3594df4571fac..46dd4c2a41ce7e0a844e0b691c134e3ce23f55e6 100644 (file)
@@ -645,7 +645,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
                }
        }
 
-       if (target__has_cpu(&opts->target))
+       if (target__has_cpu(&opts->target) || opts->target.force_per_cpu)
                perf_evsel__set_sample_bit(evsel, CPU);
 
        if (opts->period)
@@ -653,7 +653,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 
        if (!perf_missing_features.sample_id_all &&
            (opts->sample_time || !opts->no_inherit ||
-            target__has_cpu(&opts->target)))
+            target__has_cpu(&opts->target) || opts->target.force_per_cpu))
                perf_evsel__set_sample_bit(evsel, TIME);
 
        if (opts->raw_samples) {
index f5029653dcd74f590aa2692c247cc3cefbd9e977..1ea7c92e6e3365aebbedbed37ae728e9473dbab5 100644 (file)
@@ -279,6 +279,11 @@ static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
        return list_entry(evsel->node.next, struct perf_evsel, node);
 }
 
+static inline struct perf_evsel *perf_evsel__prev(struct perf_evsel *evsel)
+{
+       return list_entry(evsel->node.prev, struct perf_evsel, node);
+}
+
 /**
  * perf_evsel__is_group_leader - Return whether given evsel is a leader event
  *
index 0393912d80336d641f055148a3c593a494597be4..84cdb072ac83975670c477fa180980ae61425bda 100644 (file)
@@ -1368,7 +1368,7 @@ int machine__resolve_callchain(struct machine *machine,
 
        return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
                                   thread, evsel->attr.sample_regs_user,
-                                  sample);
+                                  sample, max_stack);
 
 }
 
index 89bab7129de4a3c92b74ca037787431c155f251f..2d0c506908926f6fce822adc45a39e76911edd10 100644 (file)
@@ -12,6 +12,7 @@ struct target {
        uid_t        uid;
        bool         system_wide;
        bool         uses_mmap;
+       bool         force_per_cpu;
 };
 
 enum target_errno {
index 5390d0b8862a680e147cf52dd8bed22cfbba333f..0efd5393de85ea33775198f25045cfa00a612247 100644 (file)
@@ -559,7 +559,7 @@ static unw_accessors_t accessors = {
 };
 
 static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
-                      void *arg)
+                      void *arg, int max_stack)
 {
        unw_addr_space_t addr_space;
        unw_cursor_t c;
@@ -575,7 +575,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
        if (ret)
                display_error(ret);
 
-       while (!ret && (unw_step(&c) > 0)) {
+       while (!ret && (unw_step(&c) > 0) && max_stack--) {
                unw_word_t ip;
 
                unw_get_reg(&c, UNW_REG_IP, &ip);
@@ -588,7 +588,8 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
 
 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
                        struct machine *machine, struct thread *thread,
-                       u64 sample_uregs, struct perf_sample *data)
+                       u64 sample_uregs, struct perf_sample *data,
+                       int max_stack)
 {
        unw_word_t ip;
        struct unwind_info ui = {
@@ -610,5 +611,5 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
        if (ret)
                return -ENOMEM;
 
-       return get_entries(&ui, cb, arg);
+       return get_entries(&ui, cb, arg, max_stack);
 }
index ec0c71a2ca2e22f2c78ef90726d0e9afe623b43c..d5966f49e22cc24fb91e8f53307504cfed7e290d 100644 (file)
@@ -18,7 +18,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
                        struct machine *machine,
                        struct thread *thread,
                        u64 sample_uregs,
-                       struct perf_sample *data);
+                       struct perf_sample *data, int max_stack);
 int unwind__arch_reg_id(int regnum);
 #else
 static inline int
@@ -27,7 +27,8 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
                    struct machine *machine __maybe_unused,
                    struct thread *thread __maybe_unused,
                    u64 sample_uregs __maybe_unused,
-                   struct perf_sample *data __maybe_unused)
+                   struct perf_sample *data __maybe_unused,
+                   int max_stack __maybe_unused)
 {
        return 0;
 }
index fe702076ca46cc2d3d02bab818446c9d15f8c392..9d77f13c2d2548934293662e314828a817d16144 100644 (file)
@@ -2,7 +2,7 @@
  * turbostat -- show CPU frequency and C-state residency
  * on modern Intel turbo-capable processors.
  *
- * Copyright (c) 2012 Intel Corporation.
+ * Copyright (c) 2013 Intel Corporation.
  * Len Brown <len.brown@intel.com>
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -47,6 +47,8 @@ unsigned int skip_c1;
 unsigned int do_nhm_cstates;
 unsigned int do_snb_cstates;
 unsigned int do_c8_c9_c10;
+unsigned int do_slm_cstates;
+unsigned int use_c1_residency_msr;
 unsigned int has_aperf;
 unsigned int has_epb;
 unsigned int units = 1000000000;       /* Ghz etc */
@@ -81,6 +83,8 @@ double rapl_joule_counter_range;
 #define RAPL_DRAM      (1 << 3)
 #define RAPL_PKG_PERF_STATUS   (1 << 4)
 #define RAPL_DRAM_PERF_STATUS  (1 << 5)
+#define RAPL_PKG_POWER_INFO    (1 << 6)
+#define RAPL_CORE_POLICY       (1 << 7)
 #define        TJMAX_DEFAULT   100
 
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -96,7 +100,7 @@ struct thread_data {
        unsigned long long tsc;
        unsigned long long aperf;
        unsigned long long mperf;
-       unsigned long long c1;  /* derived */
+       unsigned long long c1;
        unsigned long long extra_msr64;
        unsigned long long extra_delta64;
        unsigned long long extra_msr32;
@@ -266,7 +270,7 @@ void print_header(void)
                outp += sprintf(outp, "           MSR 0x%03X", extra_msr_offset64);
        if (do_nhm_cstates)
                outp += sprintf(outp, "    %%c1");
-       if (do_nhm_cstates)
+       if (do_nhm_cstates && !do_slm_cstates)
                outp += sprintf(outp, "    %%c3");
        if (do_nhm_cstates)
                outp += sprintf(outp, "    %%c6");
@@ -280,9 +284,9 @@ void print_header(void)
 
        if (do_snb_cstates)
                outp += sprintf(outp, "   %%pc2");
-       if (do_nhm_cstates)
+       if (do_nhm_cstates && !do_slm_cstates)
                outp += sprintf(outp, "   %%pc3");
-       if (do_nhm_cstates)
+       if (do_nhm_cstates && !do_slm_cstates)
                outp += sprintf(outp, "   %%pc6");
        if (do_snb_cstates)
                outp += sprintf(outp, "   %%pc7");
@@ -480,7 +484,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
        if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
                goto done;
 
-       if (do_nhm_cstates)
+       if (do_nhm_cstates && !do_slm_cstates)
                outp += sprintf(outp, " %6.2f", 100.0 * c->c3/t->tsc);
        if (do_nhm_cstates)
                outp += sprintf(outp, " %6.2f", 100.0 * c->c6/t->tsc);
@@ -499,9 +503,9 @@ int format_counters(struct thread_data *t, struct core_data *c,
 
        if (do_snb_cstates)
                outp += sprintf(outp, " %6.2f", 100.0 * p->pc2/t->tsc);
-       if (do_nhm_cstates)
+       if (do_nhm_cstates && !do_slm_cstates)
                outp += sprintf(outp, " %6.2f", 100.0 * p->pc3/t->tsc);
-       if (do_nhm_cstates)
+       if (do_nhm_cstates && !do_slm_cstates)
                outp += sprintf(outp, " %6.2f", 100.0 * p->pc6/t->tsc);
        if (do_snb_cstates)
                outp += sprintf(outp, " %6.2f", 100.0 * p->pc7/t->tsc);
@@ -648,17 +652,24 @@ delta_thread(struct thread_data *new, struct thread_data *old,
        }
 
 
-       /*
-        * As counter collection is not atomic,
-        * it is possible for mperf's non-halted cycles + idle states
-        * to exceed TSC's all cycles: show c1 = 0% in that case.
-        */
-       if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc)
-               old->c1 = 0;
-       else {
-               /* normal case, derive c1 */
-               old->c1 = old->tsc - old->mperf - core_delta->c3
+       if (use_c1_residency_msr) {
+               /*
+                * Some models have a dedicated C1 residency MSR,
+                * which should be more accurate than the derivation below.
+                */
+       } else {
+               /*
+                * As counter collection is not atomic,
+                * it is possible for mperf's non-halted cycles + idle states
+                * to exceed TSC's all cycles: show c1 = 0% in that case.
+                */
+               if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc)
+                       old->c1 = 0;
+               else {
+                       /* normal case, derive c1 */
+                       old->c1 = old->tsc - old->mperf - core_delta->c3
                                - core_delta->c6 - core_delta->c7;
+               }
        }
 
        if (old->mperf == 0) {
@@ -872,13 +883,21 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
                if (get_msr(cpu, extra_msr_offset64, &t->extra_msr64))
                        return -5;
 
+       if (use_c1_residency_msr) {
+               if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1))
+                       return -6;
+       }
+
        /* collect core counters only for 1st thread in core */
        if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
                return 0;
 
-       if (do_nhm_cstates) {
+       if (do_nhm_cstates && !do_slm_cstates) {
                if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3))
                        return -6;
+       }
+
+       if (do_nhm_cstates) {
                if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6))
                        return -7;
        }
@@ -898,7 +917,7 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
        if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
                return 0;
 
-       if (do_nhm_cstates) {
+       if (do_nhm_cstates && !do_slm_cstates) {
                if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3))
                        return -9;
                if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6))
@@ -977,7 +996,7 @@ void print_verbose_header(void)
                ratio, bclk, ratio * bclk);
 
        get_msr(0, MSR_IA32_POWER_CTL, &msr);
-       fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E: %sabled)\n",
+       fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n",
                msr, msr & 0x2 ? "EN" : "DIS");
 
        if (!do_ivt_turbo_ratio_limit)
@@ -1046,25 +1065,28 @@ print_nhm_turbo_ratio_limits:
 
        switch(msr & 0x7) {
        case 0:
-               fprintf(stderr, "pc0");
+               fprintf(stderr, do_slm_cstates ? "no pkg states" : "pc0");
                break;
        case 1:
-               fprintf(stderr, do_snb_cstates ? "pc2" : "pc0");
+               fprintf(stderr, do_slm_cstates ? "no pkg states" : do_snb_cstates ? "pc2" : "pc0");
                break;
        case 2:
-               fprintf(stderr, do_snb_cstates ? "pc6-noret" : "pc3");
+               fprintf(stderr, do_slm_cstates ? "invalid" : do_snb_cstates ? "pc6-noret" : "pc3");
                break;
        case 3:
-               fprintf(stderr, "pc6");
+               fprintf(stderr, do_slm_cstates ? "invalid" : "pc6");
                break;
        case 4:
-               fprintf(stderr, "pc7");
+               fprintf(stderr, do_slm_cstates ? "pc4" : "pc7");
                break;
        case 5:
-               fprintf(stderr, do_snb_cstates ? "pc7s" : "invalid");
+               fprintf(stderr, do_slm_cstates ? "invalid" : do_snb_cstates ? "pc7s" : "invalid");
+               break;
+       case 6:
+               fprintf(stderr, do_slm_cstates ? "pc6" : "invalid");
                break;
        case 7:
-               fprintf(stderr, "unlimited");
+               fprintf(stderr, do_slm_cstates ? "pc7" : "unlimited");
                break;
        default:
                fprintf(stderr, "invalid");
@@ -1460,6 +1482,8 @@ int has_nehalem_turbo_ratio_limit(unsigned int family, unsigned int model)
        case 0x3F:      /* HSW */
        case 0x45:      /* HSW */
        case 0x46:      /* HSW */
+       case 0x37:      /* BYT */
+       case 0x4D:      /* AVN */
                return 1;
        case 0x2E:      /* Nehalem-EX Xeon - Beckton */
        case 0x2F:      /* Westmere-EX Xeon - Eagleton */
@@ -1532,14 +1556,33 @@ int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 #define        RAPL_POWER_GRANULARITY  0x7FFF  /* 15 bit power granularity */
 #define        RAPL_TIME_GRANULARITY   0x3F /* 6 bit time granularity */
 
+double get_tdp(model)
+{
+       unsigned long long msr;
+
+       if (do_rapl & RAPL_PKG_POWER_INFO)
+               if (!get_msr(0, MSR_PKG_POWER_INFO, &msr))
+                       return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units;
+
+       switch (model) {
+       case 0x37:
+       case 0x4D:
+               return 30.0;
+       default:
+               return 135.0;
+       }
+}
+
+
 /*
  * rapl_probe()
  *
- * sets do_rapl
+ * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units
  */
 void rapl_probe(unsigned int family, unsigned int model)
 {
        unsigned long long msr;
+       unsigned int time_unit;
        double tdp;
 
        if (!genuine_intel)
@@ -1555,11 +1598,15 @@ void rapl_probe(unsigned int family, unsigned int model)
        case 0x3F:      /* HSW */
        case 0x45:      /* HSW */
        case 0x46:      /* HSW */
-               do_rapl = RAPL_PKG | RAPL_CORES | RAPL_GFX;
+               do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_GFX | RAPL_PKG_POWER_INFO;
                break;
        case 0x2D:
        case 0x3E:
-               do_rapl = RAPL_PKG | RAPL_CORES | RAPL_DRAM | RAPL_PKG_PERF_STATUS | RAPL_DRAM_PERF_STATUS;
+               do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_PKG_PERF_STATUS | RAPL_DRAM_PERF_STATUS | RAPL_PKG_POWER_INFO;
+               break;
+       case 0x37:      /* BYT */
+       case 0x4D:      /* AVN */
+               do_rapl = RAPL_PKG | RAPL_CORES ;
                break;
        default:
                return;
@@ -1570,19 +1617,22 @@ void rapl_probe(unsigned int family, unsigned int model)
                return;
 
        rapl_power_units = 1.0 / (1 << (msr & 0xF));
-       rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F));
-       rapl_time_units = 1.0 / (1 << (msr >> 16 & 0xF));
+       if (model == 0x37)
+               rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000;
+       else
+               rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F));
 
-       /* get TDP to determine energy counter range */
-       if (get_msr(0, MSR_PKG_POWER_INFO, &msr))
-               return;
+       time_unit = msr >> 16 & 0xF;
+       if (time_unit == 0)
+               time_unit = 0xA;
 
-       tdp = ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units;
+       rapl_time_units = 1.0 / (1 << (time_unit));
 
-       rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp;
+       tdp = get_tdp(model);
 
+       rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp;
        if (verbose)
-               fprintf(stderr, "RAPL: %.0f sec. Joule Counter Range\n", rapl_joule_counter_range);
+               fprintf(stderr, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, tdp);
 
        return;
 }
@@ -1668,7 +1718,6 @@ int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 {
        unsigned long long msr;
        int cpu;
-       double local_rapl_power_units, local_rapl_energy_units, local_rapl_time_units;
 
        if (!do_rapl)
                return 0;
@@ -1686,23 +1735,13 @@ int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p)
        if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr))
                return -1;
 
-       local_rapl_power_units = 1.0 / (1 << (msr & 0xF));
-       local_rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F));
-       local_rapl_time_units = 1.0 / (1 << (msr >> 16 & 0xF));
-
-       if (local_rapl_power_units != rapl_power_units)
-               fprintf(stderr, "cpu%d, ERROR: Power units mis-match\n", cpu);
-       if (local_rapl_energy_units != rapl_energy_units)
-               fprintf(stderr, "cpu%d, ERROR: Energy units mis-match\n", cpu);
-       if (local_rapl_time_units != rapl_time_units)
-               fprintf(stderr, "cpu%d, ERROR: Time units mis-match\n", cpu);
-
        if (verbose) {
                fprintf(stderr, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx "
                        "(%f Watts, %f Joules, %f sec.)\n", cpu, msr,
-                       local_rapl_power_units, local_rapl_energy_units, local_rapl_time_units);
+                       rapl_power_units, rapl_energy_units, rapl_time_units);
        }
-       if (do_rapl & RAPL_PKG) {
+       if (do_rapl & RAPL_PKG_POWER_INFO) {
+
                if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr))
                        return -5;
 
@@ -1714,6 +1753,9 @@ int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p)
                        ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units,
                        ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units);
 
+       }
+       if (do_rapl & RAPL_PKG) {
+
                if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr))
                        return -9;
 
@@ -1749,12 +1791,16 @@ int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
                print_power_limit_msr(cpu, msr, "DRAM Limit");
        }
-       if (do_rapl & RAPL_CORES) {
+       if (do_rapl & RAPL_CORE_POLICY) {
                if (verbose) {
                        if (get_msr(cpu, MSR_PP0_POLICY, &msr))
                                return -7;
 
                        fprintf(stderr, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF);
+               }
+       }
+       if (do_rapl & RAPL_CORES) {
+               if (verbose) {
 
                        if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr))
                                return -9;
@@ -1813,10 +1859,48 @@ int has_c8_c9_c10(unsigned int family, unsigned int model)
 }
 
 
+int is_slm(unsigned int family, unsigned int model)
+{
+       if (!genuine_intel)
+               return 0;
+       switch (model) {
+       case 0x37:      /* BYT */
+       case 0x4D:      /* AVN */
+               return 1;
+       }
+       return 0;
+}
+
+#define SLM_BCLK_FREQS 5
+double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0};
+
+double slm_bclk(void)
+{
+       unsigned long long msr = 3;
+       unsigned int i;
+       double freq;
+
+       if (get_msr(0, MSR_FSB_FREQ, &msr))
+               fprintf(stderr, "SLM BCLK: unknown\n");
+
+       i = msr & 0xf;
+       if (i >= SLM_BCLK_FREQS) {
+               fprintf(stderr, "SLM BCLK[%d] invalid\n", i);
+               msr = 3;
+       }
+       freq = slm_freq_table[i];
+
+       fprintf(stderr, "SLM BCLK: %.1f Mhz\n", freq);
+
+       return freq;
+}
+
 double discover_bclk(unsigned int family, unsigned int model)
 {
        if (is_snb(family, model))
                return 100.00;
+       else if (is_slm(family, model))
+               return slm_bclk();
        else
                return 133.33;
 }
@@ -1873,7 +1957,7 @@ int set_temperature_target(struct thread_data *t, struct core_data *c, struct pk
                fprintf(stderr, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n",
                        cpu, msr, target_c_local);
 
-       if (target_c_local < 85 || target_c_local > 120)
+       if (target_c_local < 85 || target_c_local > 127)
                goto guess;
 
        tcc_activation_temp = target_c_local;
@@ -1970,6 +2054,7 @@ void check_cpuid()
        do_smi = do_nhm_cstates;
        do_snb_cstates = is_snb(family, model);
        do_c8_c9_c10 = has_c8_c9_c10(family, model);
+       do_slm_cstates = is_slm(family, model);
        bclk = discover_bclk(family, model);
 
        do_nehalem_turbo_ratio_limit = has_nehalem_turbo_ratio_limit(family, model);
@@ -2331,7 +2416,7 @@ int main(int argc, char **argv)
        cmdline(argc, argv);
 
        if (verbose)
-               fprintf(stderr, "turbostat v3.4 April 17, 2013"
+               fprintf(stderr, "turbostat v3.5 April 26, 2013"
                        " - Len Brown <lenb@kernel.org>\n");
 
        turbostat_init();